request->post(); $store = Store::findOne(\Yii::$app->store); if(!$store)throw new Exception('门店不存在'); $DoctorInfo= DoctorInfo::find() ->where(['su_id' => \Yii::$app->user->identity->id]) ->with(['title', 'hospital','depart','user']) ->one(); $DoctorIdentity= DoctorIdentity::find() ->where(['su_id' => \Yii::$app->user->identity->id]) ->one(); $DoctorPracticing= DoctorPracticing::find() ->where(['su_id' => \Yii::$app->user->identity->id]) ->one(); if(!$DoctorInfo || !$DoctorIdentity || !$DoctorPracticing){ throw new Exception('医生信息错误'); } $storeDoctor = StoreDoctor::find()->where([ 'su_id' => \Yii::$app->user->identity->getId(), 'store_id' => \Yii::$app->store ])->one(); if(!$storeDoctor)throw new Exception('非该门店医生'); //门店医生小程序码 if(!$storeDoctor->qr_code){ $response = WechatService::getInstance()->app->app_code->getUnlimit('su_id='.\Yii::$app->user->identity->getId().'&store_id='.\Yii::$app->store, [ 'page' => 'subPackages/doctor/doctor-detail', 'check_path' => false, ]); if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { $path = 'uploads/doctor_code/' . date('Ymd'); $filename = $response->save('uploads/doctor_code/' . date('Ymd'), 'doctor_code_' . $DoctorInfo->su_id.\Yii::$app->store); $realpath = FuncHelper::getRealFilepath('service', $path . '/' . $filename); $uploadService = new UploadService(); $url = $uploadService->saveFile($realpath); $storeDoctor->qr_code = $url; $storeDoctor->save(); } } //门店医生在线状态 if($storeDoctor->is_online != 1){ StoreDoctor::updateAll(['is_online' => 0],['su_id' => \Yii::$app->user->identity->getId(), 'is_online' => 1]); $storeDoctor->is_online = 1; $storeDoctor->last_login_time = time(); $storeDoctor->save(); } $relates = $DoctorInfo->getRelatedRecords(); $DoctorInfo = $DoctorInfo->toArray(); $DoctorInfo = array_merge($DoctorInfo, $relates); $wait_accept=Register::find()->where([ 'service_user_id'=> \Yii::$app->user->identity->id, 'store_id'=> $post['store_id'], 'status'=>RegisterEnum::WAIT, 'is_pay'=>1, 'type' => 0, 'is_cancel'=>0, 'is_delete'=>0 ])->count(); $accepting = Register::find()->where([ 'service_user_id'=> \Yii::$app->user->identity->id, 'store_id'=> $post['store_id'], 'status'=>RegisterEnum::ACCEPTING, 'is_pay'=>1, 'is_cancel'=>0, 'is_delete'=>0 ])->count(); // TODO 这里 $idcard= DoctorInfo::find()->select(['idcard'])->where(['su_id'=>\Yii::$app->user->id])->one(); $number = substr($idcard['idcard'], strlen($idcard['idcard']) - 2, 1); $sex=$number % 2 == 0?'女':'男'; #医生开通的服务 $doctor_service = DoctorService::find()->where(['su_id' => \Yii::$app->user->identity->id])->asArray()->one(); $DoctorInfo['qr_code'] = $storeDoctor->qr_code; $ServiceUser=ServiceUser::find()->select(['reason','status'])->where(['id'=>\Yii::$app->user->identity->id])->one(); return [ 'store'=>[ 'store_id' => $store->id, 'store' => [ 'id' => $store->id, 'name' => $store->name, 'see_rate'=>$store->see_rate, ] ], 'DoctorInfo'=>$DoctorInfo, 'doctor_service'=>$doctor_service, 'DoctorIdentity'=>$DoctorIdentity, 'DoctorPracticing'=>$DoctorPracticing, 'wait_accept'=>$wait_accept, 'accepting'=>$accepting, 'sex'=>$sex, 'ServiceUser'=>$ServiceUser ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), 'data' => [ 'line' => $e->getLine(), ] ]; } } /** * @doc-name 我的评价基础信息(医生端) */ public function actionCommentMain() { $allCount = (int)UserComment::find() ->where([ 'su_id' => \Yii::$app->user->identity->id, ]) ->count(); $highCount = (int)UserComment::find() ->where(['>=', 'score', 4]) ->where([ 'su_id' => \Yii::$app->user->identity->id, ]) ->count(); $lowCount = (int)UserComment::find() ->where(['<=', 'score', 2]) ->where([ 'su_id' => \Yii::$app->user->identity->id, ]) ->count(); $scoreAvg = UserComment::find() ->where([ 'su_id' => \Yii::$app->user->identity->id, ]) ->average('score'); $scoreAvg = ceil($scoreAvg * 2) / 2; return [ 'all_count' => $allCount, 'high_count' => $highCount, 'low_count' => $lowCount, 'score_avg' => $scoreAvg, ]; } /** * @doc-name 我的评价(医生端) * @doc-param string type high高分low低分 * @doc-return mixed @List{score-int-分数,comment-string-评价内容,created_at-string-评价时间,nickname-string-用户隐私姓名} 评价信息 * @doc-return mixed @Pagination{total-int-总数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息 */ public function actionComments() { $type = \Yii::$app->request->post('type'); $query = UserComment::find() ->select(['id', 'u_id', 'score', 'comment', 'created_at']) ->with(['user']) ->orderBy(['created_at' => SORT_DESC]) ->where([ 'su_id' => \Yii::$app->user->identity->id, ]); if ($type == 'high') { $query->andWhere(['>=', 'score', 4]); } elseif ($type == 'low') { $query->andWhere(['<=', 'score', 2]); } $this->field = [ UserComment::class => [ 'id', 'u_id', 'score', 'comment', 'created_at', 'nickname' => function (UserComment $comment) { $user = User::find() ->select(['id', 'nickname']) ->where(['id' => $comment->u_id]) ->one(); $nickname = $user->nickname ?? '微信用户'; if ($nickname) { $nickname = StringHelper::string_hide_cut($nickname); } return $nickname; }, 'avatar'=>function($m){ $avatar= UserPatient::find()->where([ 'id'=>$m->u_id, // 'user_id'=>$m->user_id ])->select('avatar')->one(); return $avatar??'https://tenfei03.cfp.cn/creative/vcg/veer/1600water/veer-105516317.jpg'; } ], ]; return $this->create($query,$type); } /** * @doc-name 收入明细 * @doc-return string name 患者姓名 / optional * @doc-return mixed @List{id-int-挂号id,avatar-string-头像,name-string-名字,price-float-金额,pay_time-string-收款时间} 信息 * @doc-return mixed @Pagination{total-int-总数据,totalPage-int-总页数,pageSize-int-每页多少条} 分页信息 */ public function actionIncomeDetail() { $post=\Yii::$app->request->post(); $query=Register::find()->where([ 'store_id'=>\Yii::$app->store, 'is_pay'=>0, 'service_user_id'=>\Yii::$app->user->id ])->with('patient'); if (!empty($post['name'])){ $name=$post['name']; $query->joinWith(['patient' => function ($p) use ($name) { $p->alias('p'); $p->andWhere(['like', 'p.name', $name]); }]); } $this->field=[ Register::class=>[ 'id','avatar'=>'patient.avatar', 'name'=>'patient.name', 'price','pay_time' ] ]; return $this->create($query,$post); } /** * @doc-name 编辑资料 * @doc-param string avatar 头像 / optional */ public function actionEditInfo() { $post = \Yii::$app->request->post(); $DoctorInfo=DoctorInfo::find()->where([ 'su_id'=>\Yii::$app->user->id ])->one(); if (!$DoctorInfo) throw new Exception('医生信息不存在'); $DoctorInfo->avatar=$post['avatar']; if (!$DoctorInfo->saveOrFail()){ throw new Exception('编辑失败'); } return ['编辑成功']; } }