where([ 'pid' => 0, ])->with('child')->asArray()->all(); return $list; } /** * @doc-name 医生列表 * @doc-param string keyword 关键词 / optional * @doc-param json depart_id 科室id,多选["科室id1","科室id2"] [] optional * @doc-param json title_id 职称,多选["id1","id2"] [] optional * @doc-param int sort 1综合排序2问诊量3接诊率4综合评分 1 optional * @doc-param int page 页码 1 optional * @doc-param int page_size 每页条数 20 optional * @doc-return mixed @List{ServiceUser{id,avatar-string-医生头像,name-string-医生姓名,depart-string-医生科室,store-string-门店,title-string-职称,good_at-string-擅长,accept_percent-string-接诊率,inquiry_num-int-问诊量,overall_score-int-综合评分,@Service{DoctorService{register_status,register_price}}}} 医生列表 * @doc-return mixed @Pagination{total_count-int-总数量,page_count-int-总页数,current_page-int-当前页,per_page-int-每页条数} 分页数据 */ public function actionAllList() { $post = \Yii::$app->request->post(); $keyword = $post['keyword']; $store_id = \Yii::$app->store; $su_id = StoreDoctor::find()->select('su_id')->where([ 'store_id' => $store_id, 'is_delete' => 0 ])->column() ; $query = ServiceUser::find()->alias('su')->where([ 'su.role' => UserRoleEnum::DOCTOR, 'su.status' => UserStatusEnum::OK, 'su.is_delete' => 0 ])->andWhere([ 'in', 'su.id', $su_id ]); $depart_arr = json_decode(ArrayHelper::getValue($post, 'depart_id', "[]"), true); $title_arr = json_decode(ArrayHelper::getValue($post, 'title_id', "[]"), true); // $sort = ArrayHelper::getValue($post, 'sort', 0); $departs = Department::find()->select('id,name')->where(['<>', 'id', 0])->asArray()->all(); $id = 0; foreach ($departs as $v) { if (in_array($keyword, $v) == true) { $id = $v['id']; } } $query->joinWith(['docInfo' => function ($q) use ($id, $keyword, $depart_arr, $title_arr) { $q->alias('i'); //搜索框搜索姓名和科室 if (!empty($keyword)) { $q->andWhere([ 'or', ['like', 'i.name', $keyword], ['i.depart_id' => $id] ]); } //科室搜索 if (!empty($depart_arr)) { $q->andWhere([ 'i.depart_id' => $depart_arr ]); } //职称搜索 if (!empty($title_arr)) { $q->andWhere([ 'i.title_id' => $title_arr ]); } }]); $query->joinWith(['docIdentity' => function ($q) { $q->alias('it'); }]); if (!empty($post['sort'])){ switch ($post['sort']) { case 1://综合排序 $query->orderBy('i.id desc'); break; case 2://问诊量 $query->orderBy('i.inquiries desc'); break; case 3://接诊率 $query->orderBy('i.reception_rate desc'); break; case 4://综合评分 $query->orderBy('i.grade desc'); break; default: return ['参数错误']; } } $this->field = [ ServiceUser::class => [ 'id', 'avatar' => 'docIdentity.work_avator', 'name' => 'docInfo.name', 'depart' => 'docInfo.depart.name', 'store' => function () use($store_id){ $store = Store::findOne(['id' => $store_id]); return $store->name; }, 'title' => 'docInfo.title.name', 'good_at' => 'docInfo.good_at', 'accept_percent' => function ($model) { $accept_num = Order::find()->where([ 'su_id' => $model->id, 'is_pay' => 1, 'accept_status' => [OrderAcceptEnum::ACCEPTING, OrderAcceptEnum::OVER], ])->count(); $all_num = Order::find()->where([ 'su_id' => $model->id, 'is_pay' => 1, 'accept_status' => [OrderAcceptEnum::TIMEOUT_ACCEPT, OrderAcceptEnum::REFUSED, OrderAcceptEnum::ACCEPTING, OrderAcceptEnum::OVER], ])->count(); $accept_percent= $all_num == 0 ? 100 : round(($accept_num / $all_num) * 100, 2) ; $DoctorInfo= DoctorInfo::find()->where([ 'su_id'=>$model->id ])->one(); if ($DoctorInfo){ $DoctorInfo->su_id=$model->id; $DoctorInfo->reception_rate=$accept_percent; $DoctorInfo->saveOrFail(); } return $accept_percent; }, 'inquiry_num' => function($model){ $count=Register::find()->where([ 'service_user_id' => $model->id, 'is_pay' => 1, 'is_cancel'=>0 ])->count(); $DoctorInfo= DoctorInfo::find()->where([ 'su_id'=>$model->id ])->one(); if ($DoctorInfo){ $DoctorInfo->inquiries=$count; $DoctorInfo->saveOrFail(); } return $count; }, 'overall_score' => function($m){ $score= UserComment::find()->select('score')->where([ 'su_id'=>$m->id ])->column(); $allnum=UserComment::find()->where([ 'su_id'=>$m->id ])->count(); $sum_score=array_sum($score); $overall_score= $allnum == 0 ? '5' : round(($sum_score / $allnum) , 2) ; $DoctorInfo= DoctorInfo::find()->where([ 'su_id'=>$m->id ])->one(); if ($DoctorInfo){ $DoctorInfo->su_id=$m->id; $DoctorInfo->grade=$overall_score; $DoctorInfo->saveOrFail(); } return $overall_score; }, 'service' => 'docService' ], DoctorService::class => [ 'register_status', 'register_price' ] ]; return $this->create($query, $post); } /** * @doc-name 医生详情 * @doc-param int doctor_id 医生id * @doc-return mixed ServiceUser{id,avatar-string-医生头像,name-string-医生姓名,depart-string-医生科室,store-string-门店,title-string-职称,good_at-string-擅长,intro-string-简介,accept_percent-string-接诊率,inquiry_num-int-问诊量,overall_score-float-综合评分,status-int-状态1为关注其他返回均为未关注,@Service{DoctorService{*}}} 医生详情 */ public function actionDetail() { $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['doctor_id', 'required'] ]); $store_id = \Yii::$app->store; $su_id = StoreDoctor::find()->select('su_id')->where([ 'store_id' => $store_id, 'su_id'=>$post['doctor_id'], 'is_delete' => 0 ])->column() ; $doctor = ServiceUser::find()->alias('su')->where([ 'su.id' => $su_id, 'su.role' => UserRoleEnum::DOCTOR, 'su.status' => UserStatusEnum::OK, 'id' => $post['doctor_id'], 'is_delete' => 0 ])->with('docService')->one(); if (!$doctor) throw new Exception('医生不存在'); return ArrayHelper::toArray($doctor, [ ServiceUser::class => [ 'id', 'avator' => 'docIdentity.work_avator', 'name' => 'docInfo.name', 'depart' => 'docInfo.depart.name', 'store' => function () use($store_id){ $store = Store::findOne(['id' => $store_id]); return $store->name; }, 'title' => 'docInfo.title.name', 'good_at' => 'docInfo.good_at', 'intro' => 'docInfo.intro', 'accept_percent' => function ($model) { $accept_num = Order::find()->where([ 'su_id' => $model->id, 'is_pay' => 1, 'accept_status' => [OrderAcceptEnum::ACCEPTING, OrderAcceptEnum::OVER], ])->count(); $all_num = Order::find()->where([ 'su_id' => $model->id, 'is_pay' => 1, 'accept_status' => [OrderAcceptEnum::TIMEOUT_ACCEPT, OrderAcceptEnum::REFUSED, OrderAcceptEnum::ACCEPTING, OrderAcceptEnum::OVER], ])->count(); return $all_num == 0 ? '100%' : round(($accept_num / $all_num) * 100, 2) . '%'; }, 'inquiry_num' => function ($model) { $count=Register::find()->where([ 'service_user_id' => $model->id, 'is_pay' => 1, 'is_cancel'=>0 ])->count(); $DoctorInfo= DoctorInfo::find()->where([ 'su_id'=>$model->id ])->one(); if ($DoctorInfo){ $DoctorInfo->inquiries=$count; $DoctorInfo->saveOrFail(); } return $count; }, 'overall_score' => function($m){ $score= UserComment::find()->select('score')->where([ 'su_id'=>$m->id ])->column(); $allnum=UserComment::find()->where([ 'su_id'=>$m->id ])->count(); $sum_score=array_sum($score); return $allnum == 0 ? '5' : round(($sum_score / $allnum) , 2) ; }, 'service' => 'docService', 'status' => function ($model) { $status = FollowDoctor::find()->select('status') ->where([ 'su_id' => $model->id, 'user_id' => \Yii::$app->user->identity->id ])->column(); if (empty($status)) { return 0;//未关注 } return $status; }, ], ]); } /** * @doc-name 患者评论的顶部 * @doc-param int su_id 医生id * @doc-return int all_num 全部 * @doc-return int high_score 高分 * @doc-return int low_score 低分 * @doc-return string patient_score 患者评分 */ public function actionTop() { $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['su_id', 'required'] ]); $doctor = ServiceUser::find()->alias('su')->where([ 'su.role' => UserRoleEnum::DOCTOR, 'su.status' => UserStatusEnum::OK, 'id' => $post['su_id'], 'is_delete' => 0 ])->all(); if (!$doctor) throw new \yii\db\Exception('医生不存在'); $all_num = UserComment::find()->where([ 'su_id' => $post['su_id'] ])->count(); $high_score = UserComment::find()->where([ '>=', 'score', 4, ])->andWhere(['su_id' => $post['su_id']])->count(); $low_score = UserComment::find()->where([ '<=', 'score', 3, ])->andWhere(['su_id' => $post['su_id']])->count(); return [ 'all_num' => $all_num, 'high_score' => $high_score, 'low_score' => $low_score, 'patient_score' => '5.0', ]; } /** * @doc-name 评价列表 * @doc-param int keyword 筛选1全部2高分3低分 * @doc-param int su_id 医生id * @doc-return mixed @List{id-int-评论id,comment-string-评论,score-int-评分,created_at-int-发布时间,nickname-string-昵称,avatarurl-string-头像} 评价信息 * @doc-return mixed @Pagination{total-int-总数据,totalPage-int-页数,pageSize-int-每页数据} 分页信息 */ public function actionCommentList() { $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['su_id', 'required'] ]); $doctor = ServiceUser::find()->alias('su')->where([ 'su.role' => UserRoleEnum::DOCTOR, 'su.status' => UserStatusEnum::OK, 'id' => $post['su_id'], 'is_delete' => 0 ])->all(); if (!$doctor) throw new \yii\db\Exception('医生不存在'); $query = UserComment::find()->where([ 'su_id' => $post['su_id'] ]); switch ($post['keyword']) { case 1://全部 $query->all(); break; case 2: $query->andWhere(['>=', 'score', 4,]); break; case 3://低分 $query->andWhere(['<=', 'score', 3,]); break; } $this->field = [ UserComment::class => [ 'id', 'score', 'comment', 'created_at', 'avator'=>function($u){ return $u->userPatient->avatar??'https://tenfei03.cfp.cn/creative/vcg/veer/1600water/veer-105516317.jpg'; }, 'nickname'=>function($m){ return StringHelper::string_hide_cut($m->userPatient->name); }, ], ]; return $this->create($query, $post); } /** * @doc-name 医生文章列表 * @doc-param int id 医生id * @doc-return mixed @List{id-int-文章id,cover-string-封面,title-string-标题,created_at-int-发布时间} 文章信息 * @doc-return mixed @Pagination{total-int-总数据,totalPage-int-总页数,pageSize-int-每页数据} 分页信息 */ public function actionArticleList() { $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['id', 'required'] ]); $query = DoctorArticle::find()->where([ 'su_id' => $post['id'], 'is_draft' => 0, 'is_delete' => 0, ]); $this->field = [ DoctorArticle::class => [ 'id', 'title', 'created_at', 'cover' => function ($model) { if (empty($model->cover)) { return 'https://yanydy.oss-cn-hangzhou.aliyuncs.com/uploads/20221130/e52920ceb880e422de5f8b040daa03ab.jpg'; } return $model->cover; } ] ]; return $this->create($query, $post); } /** * @doc-name 问诊记录列表 * @doc-param string keyword 搜索疾病或症状 / optional * @doc-param int id 医生id * @doc-return mixed @List{type-int-0用户问1医生回复} */ public function actionAskList() { $post = \Yii::$app->request->post(); $this->requestValidate($post, [ ['id', 'required'] ]); $query= ImMessage::find()->where([ 'service_id'=>$post['id'], 'is_delete'=>0 ])->addSelect('content,type')->groupBy('ims_id')->orderBy('id desc'); $this->field=[ 'id','content','type' ]; return $this->create($query,$post); } }