740 lines
29 KiB
PHP
740 lines
29 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Constants\DoctorTitleCode;
|
||
use App\Constants\HttpEnumCode;
|
||
use App\Model\DiseaseClassExpertise;
|
||
use App\Model\DoctorConfigFollowPackage;
|
||
use App\Model\DoctorConfigFollowPackageItem;
|
||
use App\Model\DoctorConfigHealthPackage;
|
||
use App\Model\DoctorExpertise;
|
||
use App\Model\DoctorInquiryConfig;
|
||
use App\Model\DoctorInquiryConfig as DoctorInquiryConfigModel;
|
||
use App\Model\Hospital;
|
||
use App\Model\OrderEvaluation;
|
||
use App\Model\OrderInquiry;
|
||
use App\Model\OrderInquiryCase;
|
||
use App\Model\PatientFollow;
|
||
use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel;
|
||
use App\Model\SystemInquiryConfig;
|
||
use App\Model\SystemInquiryTime;
|
||
use App\Model\User;
|
||
use App\Model\UserDoctor;
|
||
use App\Model\UserDoctor as UserDoctorModel;
|
||
use Hyperf\DbConnection\Db;
|
||
|
||
class PatientDoctorService extends BaseService
|
||
{
|
||
/**
|
||
* 获取问诊医生列表
|
||
* 专家问诊-公益问诊共用
|
||
* @return array
|
||
*/
|
||
public function getInquiryDoctorList(): array
|
||
{
|
||
$expertise_id = $this->request->input('expertise_id');
|
||
$province_id = $this->request->input('province_id');
|
||
$city_id = $this->request->input('city_id');
|
||
$sort_order = $this->request->input('sort_order',1);
|
||
$keyword = $this->request->input('keyword',"");
|
||
$inquiry_type = $this->request->input('inquiry_type',[]); // 接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||
$inquiry_mode = $this->request->input('inquiry_mode',[]); // 接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员 6:疑难会诊)
|
||
$is_first_online = $this->request->input('is_first_online',0); // 是否优先在线(1:是)
|
||
$page = $this->request->input('page',1);
|
||
$per_page = $this->request->input('per_page',10);
|
||
|
||
// 组合条件
|
||
$hospital_params = array();// 医院搜索
|
||
$doctor_params = array();// 医生搜索
|
||
$doctor_expertise_params = array();// 医生专长搜索
|
||
|
||
// 省市区
|
||
if (!empty($province_id)) {
|
||
if (empty($city_id)) {
|
||
// 省份存在时需和城市在一块
|
||
return fail(HttpEnumCode::CLIENT_HTTP_ERROR);
|
||
}
|
||
$hospital_params[] = ['province_id', '=', $province_id];
|
||
$hospital_params[] = ['city_id', '=', $city_id];
|
||
}
|
||
|
||
// 医生专长
|
||
if (!empty($expertise_id)) {
|
||
$doctor_expertise_params['expertise_id'] = $expertise_id;
|
||
}
|
||
|
||
if (!empty($inquiry_type)){
|
||
$inquiry_type = explode(',',$inquiry_type);
|
||
$inquiry_mode = explode(',',$inquiry_mode);
|
||
}
|
||
|
||
// 固定医生查询条件
|
||
$doctor_params['status'] = 1; // 状态(0:禁用 1:正常 2:删除)
|
||
|
||
$doctor_params["iden_auth_status"] = 1;// 身份认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||
$doctor_params["is_bind_bank"] = 1;// 是否已绑定结算银行卡(0:否 1:是)
|
||
|
||
$fields = [
|
||
"user_doctor.doctor_id",
|
||
"user_id",
|
||
"user_name",
|
||
"multi_point_status",
|
||
"is_bind_bank",
|
||
"is_recommend",
|
||
"avatar",
|
||
"doctor_title",
|
||
"department_custom_id",
|
||
"department_custom_name",
|
||
"hospital_id",
|
||
"served_patients_num",
|
||
"praise_rate",
|
||
"avg_response_time",
|
||
"number_of_fans",
|
||
"be_good_at",
|
||
];
|
||
|
||
$user_doctors = UserDoctor::getInquiryDoctorPage($keyword,$hospital_params, $doctor_params,$doctor_expertise_params,$inquiry_type,$inquiry_mode,$is_first_online, $sort_order, $fields,$page,$per_page);
|
||
|
||
if (!empty($user_doctors['data'])) {
|
||
foreach ($user_doctors['data'] as &$user_doctor) {
|
||
$user_doctor['doctor_title_name'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 处理医生专长
|
||
if (!empty($user_doctor['DoctorExpertise'])) {
|
||
foreach ($user_doctor['DoctorExpertise'] as &$data) {
|
||
if (!empty($data['DiseaseClassExpertise'])) {
|
||
$data['expertise_name'] = $data['DiseaseClassExpertise']['expertise_name'];
|
||
}
|
||
unset($data['DiseaseClassExpertise']);
|
||
}
|
||
}
|
||
|
||
// 处理可处方字段
|
||
$userDoctorService = new UserDoctorService();
|
||
$user_doctor['multi_point_enable'] = $userDoctorService->getDoctorMultiPointEnable($user_doctor["doctor_id"]);
|
||
|
||
// 好评率-超过5个已结束的订单后展示
|
||
$user_doctor['praise_rate'] = floor($user_doctor['praise_rate'] * 0.05 * 100) / 100;
|
||
// 响应时间-超过5个已结束的订单后展示
|
||
$user_doctor['avg_response_time'] = (float)floor($user_doctor['avg_response_time'] * 10) / 10;
|
||
|
||
//
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$params['inquiry_status'] = 6; // 已结束
|
||
$inquiry_order_count = OrderInquiry::getCount($params);
|
||
if (empty($inquiry_order_count) || $inquiry_order_count == 0) {
|
||
$user_doctor['is_display_score'] = false;
|
||
} else {
|
||
$user_doctor['is_display_score'] = true;
|
||
}
|
||
|
||
// 头像
|
||
$user_doctor['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
|
||
// 问诊配置
|
||
foreach ($user_doctor['DoctorInquiryConfig'] as $key => $doctor_inquiry_config){
|
||
// 随访包
|
||
if ($doctor_inquiry_config['inquiry_type'] == 1 && $doctor_inquiry_config['inquiry_mode'] == 9){
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_inquiry_config['doctor_id'];
|
||
$doctor_config_follow_package = DoctorConfigFollowPackage::getOne($params);
|
||
if (!empty($doctor_config_follow_package)) {
|
||
$params = array();
|
||
$params['follow_package_id'] = $doctor_config_follow_package['follow_package_id'];
|
||
$doctor_config_follow_package_items = DoctorConfigFollowPackageItem::getList($params);
|
||
if (!empty($doctor_config_follow_package_items)) {
|
||
foreach ($doctor_config_follow_package_items as $k => $doctor_config_follow_package_item){
|
||
if ($k == 0){
|
||
$user_doctor['DoctorInquiryConfig'][$key]['inquiry_price'] = $doctor_config_follow_package_item['service_price'];
|
||
continue;
|
||
}
|
||
|
||
if ($doctor_config_follow_package_item['service_price'] < $user_doctor['DoctorInquiryConfig'][$key]['inquiry_price']){
|
||
$user_doctor['DoctorInquiryConfig'][$key]['inquiry_price'] = $doctor_config_follow_package_item['service_price'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
// 健康包
|
||
if ($doctor_inquiry_config['inquiry_type'] == 1 && $doctor_inquiry_config['inquiry_mode'] == 8){
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_inquiry_config['doctor_id'];
|
||
$doctor_config_health_package = DoctorConfigHealthPackage::getOne($params);
|
||
if (!empty($doctor_config_health_package)){
|
||
$user_doctor['DoctorInquiryConfig'][$key]['inquiry_price'] = $doctor_config_health_package['service_price'];
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
return success($user_doctors);
|
||
}
|
||
|
||
/**
|
||
* 医生详情简介-详情中的简介
|
||
* @return array
|
||
*/
|
||
public function getDoctorProfile(): array
|
||
{
|
||
$doctor_id = $this->request->route('doctor_id');
|
||
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$fields = [
|
||
"doctor_id",
|
||
"user_id",
|
||
"user_name",
|
||
"status",
|
||
"iden_auth_status",
|
||
"avatar",
|
||
"doctor_title",
|
||
"department_custom_name",
|
||
"hospital_id",
|
||
"be_good_at",
|
||
"brief_introduction",
|
||
];
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_id;
|
||
$params['status'] = 1; // 状态(0:禁用 1:正常 2:删除)
|
||
$params["iden_auth_status"] = 1;// 身份认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::CLIENT_HTTP_ERROR);
|
||
}
|
||
|
||
$user_doctor = $user_doctor->toArray();
|
||
|
||
$user_doctor['doctor_title_name'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 获取医生医院数据
|
||
$fields = [
|
||
'hospital_id',
|
||
'hospital_name',
|
||
'hospital_level_name',
|
||
];
|
||
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params, $fields);
|
||
if (!empty($hospital)) {
|
||
$user_doctor['hospital'] = $hospital;
|
||
}
|
||
|
||
// 获取医生已选择专长
|
||
$UserDoctorService = new UserDoctorService();
|
||
$user_doctor['doctor_expertise'] = $UserDoctorService->getDoctorSelectedExpertise($doctor_id);
|
||
|
||
return success($user_doctor);
|
||
}
|
||
|
||
/**
|
||
* 检测是否可以接诊
|
||
* @return array
|
||
*/
|
||
public function getDoctorInquiryCheck(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$inquiry_type = $this->request->input('inquiry_type');
|
||
$inquiry_mode = $this->request->input('inquiry_mode');
|
||
$doctor_id = $this->request->input('doctor_id','');
|
||
|
||
$result = array();
|
||
$result['data'] = [];
|
||
$result['message'] = "可接诊";
|
||
$result['status'] = 1;
|
||
|
||
try {
|
||
// 检测是否存在同类型未完成的问诊订单
|
||
$PatientOrderService = new PatientOrderService();
|
||
$order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry($inquiry_type,$inquiry_mode,$user_info['client_user_id']);
|
||
if (!empty($order_inquiry_id)){
|
||
$result['status'] = 2;
|
||
$result['data']['order_inquiry_id'] = $order_inquiry_id;
|
||
$result['message'] = "存在未完成的问诊订单";
|
||
return success($result);
|
||
}
|
||
|
||
// 检测是否检测医生
|
||
if (!empty($doctor_id)){
|
||
// 获取医生信息
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_id;
|
||
|
||
$fields = [
|
||
'doctor_id',
|
||
'user_name',
|
||
'iden_auth_status',
|
||
'idcard_status',
|
||
'multi_point_status',
|
||
'avatar',
|
||
'is_bind_bank',
|
||
];
|
||
$user_doctor = UserDoctor::getOne($params, $fields);
|
||
if (empty($user_doctor)) {
|
||
return fail(HttpEnumCode::HTTP_ERROR, "非法医生");
|
||
}
|
||
|
||
// 检测医生身份认证
|
||
if ($user_doctor['iden_auth_status'] != 1) {
|
||
return fail(HttpEnumCode::HTTP_ERROR,"医生暂不可接诊");
|
||
}
|
||
|
||
if ($user_doctor['idcard_status'] != 1) {
|
||
return fail(HttpEnumCode::HTTP_ERROR,"医生暂不可接诊");
|
||
}
|
||
|
||
// 获取医生问诊配置
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$params['inquiry_type'] = $inquiry_type;
|
||
$params['inquiry_mode'] = $inquiry_mode;
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||
if (empty($doctor_inquiry_config)){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"医生暂不可接诊");
|
||
}
|
||
|
||
if ($doctor_inquiry_config['is_enable'] == 0){
|
||
return fail(HttpEnumCode::HTTP_ERROR,"医生暂不可接诊");
|
||
}
|
||
|
||
// 检测当前医生是否和患者存在未完成问诊订单
|
||
$InquiryService = new InquiryService();
|
||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($user_info['client_user_id'],$doctor_id);
|
||
if (!empty($order_inquiry)){
|
||
$result['status'] = 2;
|
||
$result['data']['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||
$result['message'] = "您和当前医生存在问诊中订单,无法再次发起问诊";
|
||
return success($result);
|
||
}
|
||
|
||
// 获取医生每日最大接诊数量
|
||
$UserDoctorService = new UserDoctorService();
|
||
$max_work_num_day = $UserDoctorService->getDoctorInquiryDayMaxNum($doctor_id,$inquiry_type,$inquiry_mode);
|
||
|
||
// 获取医生当日有效问诊数量
|
||
$inquiryService = new InquiryService();
|
||
$order_inquiry_count = $inquiryService->getDoctorDayInquiryCount($doctor_id, $inquiry_type);
|
||
|
||
// 计算剩余未接诊数量 = 最大数量-
|
||
$access_inquiry_num = $max_work_num_day - $order_inquiry_count;
|
||
if ($access_inquiry_num <= 0){
|
||
$result['status'] = 3;
|
||
$result['data'] = "";
|
||
$result['message'] = "当前医生已无每日问诊次数,请选择其他医生";
|
||
return success($result);
|
||
}
|
||
}
|
||
|
||
// 公益问诊
|
||
if ($inquiry_type == 3){
|
||
// 检测公益问诊-当前患者问诊次数(24小时内两次公益问诊)
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['inquiry_type'] = $inquiry_type;
|
||
$params['inquiry_mode'] = $inquiry_mode;
|
||
|
||
$inquiry_status_params = [1,2,3,4];
|
||
$inquiry_count = OrderInquiry::getInquiryStatusCount($params,$inquiry_status_params);
|
||
if ($inquiry_count >= 2){
|
||
$result['status'] = 3;
|
||
$result['data'] = "";
|
||
$result['message'] = "您还有未完成的公益问诊,完成之后才可以重新问诊";
|
||
return success($result);
|
||
}
|
||
}
|
||
|
||
// 问诊购药
|
||
$is_system_time_pass = false;
|
||
if ($inquiry_type == 4){
|
||
// 检测当前是否符合系统问诊时间
|
||
$inquiryService = new InquiryService();
|
||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($inquiry_type);
|
||
if (!$is_system_time_pass){
|
||
// 非坐班时间
|
||
// 问诊购药非坐班时间不允许接诊
|
||
$result['status'] = 3;
|
||
$result['data'] = "";
|
||
$result['message'] = "温馨提示:当前非接诊时间,请您在接诊时间内在进行问诊";
|
||
return success($result);
|
||
}
|
||
}
|
||
|
||
// 检测快速、购药问诊是否有可分配医生
|
||
if ($inquiry_type == 2 || $inquiry_type == 4){
|
||
$UserDoctorService = new UserDoctorService();
|
||
$doctor_id = $UserDoctorService->getInquiryAssignDoctor($inquiry_type,$user_info['client_user_id'],$is_system_time_pass);
|
||
|
||
if (empty($doctor_id)){
|
||
// 无合适医生
|
||
$result['status'] = 3;
|
||
$result['data'] = "";
|
||
$result['message'] = "暂无可接诊医生,请选择其他服务入口进行问诊";
|
||
return success($result);
|
||
}
|
||
}
|
||
}catch(\Throwable $e){
|
||
// 错误不做处理,此处只是检测
|
||
return success($result);
|
||
}
|
||
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 获取我的问诊、关注医生列表
|
||
* @return array
|
||
*/
|
||
public function getDoctorList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$my_doctor_type = $this->request->input('my_doctor_type'); // 医生类型(1:问诊 2:关注)
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
if ($my_doctor_type == 1){
|
||
// 问诊
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['history_status'] = 1;
|
||
$result = PatientHistoryInquiryModel::getPage($params,['*'],$page,$per_page);
|
||
}else{
|
||
// 关注
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$result = PatientFollow::getPage($params,['*'],$page,$per_page);
|
||
}
|
||
|
||
// 处理数据
|
||
if (!empty($result['data'])) {
|
||
foreach ($result['data'] as &$item) {
|
||
$data = array();
|
||
|
||
// 医生专长
|
||
if (!empty($item['DoctorExpertise'])) {
|
||
foreach ($item['DoctorExpertise'] as &$doctor_expertise) {
|
||
if (!empty($doctor_expertise['DiseaseClassExpertise'])) {
|
||
$doctor_expertise['expertise_name'] = $doctor_expertise['DiseaseClassExpertise']['expertise_name'];
|
||
}
|
||
unset($doctor_expertise['DiseaseClassExpertise']);
|
||
}
|
||
}
|
||
$data['doctor_expertise'] = $item['DoctorExpertise'];
|
||
|
||
// 医生数据
|
||
$data['user_doctor'] = $item['UserDoctor'];
|
||
|
||
// 头像
|
||
$data['user_doctor']['avatar'] = addAliyunOssWebsite($data['user_doctor']['avatar']);
|
||
|
||
// 职称
|
||
$data['user_doctor']['doctor_title_name'] = empty($data['user_doctor']['doctor_title']) ? "" : DoctorTitleCode::getMessage($data['user_doctor']['doctor_title']);
|
||
|
||
// 医生问诊配置-问诊购药
|
||
$data['user_doctor']['multi_point_enable'] = 0;
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $data['user_doctor']['doctor_id'];
|
||
$params['inquiry_type'] = 4;
|
||
$params['inquiry_mode'] = 1;
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getOne($params);
|
||
if (!empty($doctor_inquiry_config)){
|
||
if ($doctor_inquiry_config['is_enable'] == 1){
|
||
$data['user_doctor']['multi_point_enable'] = 1;
|
||
}
|
||
}
|
||
|
||
$item = $data;
|
||
}
|
||
}
|
||
|
||
return success($result);
|
||
|
||
}
|
||
|
||
/**
|
||
* 获取首页推荐医生
|
||
* 限制条数
|
||
* @return array
|
||
*/
|
||
public function getIndexRecommendDoctorLimit(): array
|
||
{
|
||
$results = array();
|
||
|
||
// 推荐医生
|
||
$fields = [
|
||
"doctor_id",
|
||
"user_id",
|
||
"user_name",
|
||
"status",
|
||
"multi_point_status",
|
||
"avatar",
|
||
"doctor_title",
|
||
"department_custom_name",
|
||
"hospital_id",
|
||
"be_good_at",
|
||
];
|
||
|
||
$recommend_doctors = UserDoctorModel::getIndexRecommendDoctor($fields);
|
||
if (empty($recommend_doctors)) {
|
||
return success();
|
||
}
|
||
|
||
$userDoctorService = new UserDoctorService();
|
||
foreach ($recommend_doctors as $recommend_doctor) {
|
||
$data = array();
|
||
$data['doctor_id'] = $recommend_doctor['doctor_id'];
|
||
$data['user_id'] = $recommend_doctor['user_id'];
|
||
$data['user_name'] = $recommend_doctor['user_name'];
|
||
$data['status'] = $recommend_doctor['status'];
|
||
$data['multi_point_status'] = $recommend_doctor['multi_point_status']; // 医生多点执业认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||
$data['avatar'] = addAliyunOssWebsite($recommend_doctor['avatar']);
|
||
$data['doctor_title'] = empty($recommend_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($recommend_doctor['doctor_title']);
|
||
$data['department_custom_name'] = $recommend_doctor['department_custom_name'];
|
||
$data['be_good_at'] = $recommend_doctor['be_good_at'];
|
||
$data['hospital_name'] = $recommend_doctor['Hospital']['hospital_name'] ?? "";
|
||
$data['hospital_level_name'] = $recommend_doctor['Hospital']['hospital_level_name'] ?? "";
|
||
|
||
if (!empty($recommend_doctor['user'])){
|
||
$data['is_online'] = $recommend_doctor['user']['is_online'];
|
||
}
|
||
|
||
// 是否开启问诊购药
|
||
$data['multi_point_enable'] = $userDoctorService->getDoctorMultiPointEnable("",$recommend_doctor['DoctorInquiryConfig']);
|
||
|
||
$data['doctor_inquiry_config'] = $recommend_doctor['DoctorInquiryConfig'];
|
||
|
||
$results[] = $data;
|
||
|
||
unset($data);
|
||
}
|
||
return success($results);
|
||
}
|
||
|
||
/**
|
||
* 获取医生评价
|
||
* @return array
|
||
*/
|
||
public function getDoctorEvaluationList(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$doctor_id = $this->request->route('doctor_id');
|
||
$page = $this->request->input('page', 1);
|
||
$per_page = $this->request->input('per_page', 10);
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_id;
|
||
|
||
$order_evaluation = OrderEvaluation::getPage($params, ['*'],$page,$per_page);
|
||
if (!empty($order_evaluation['data'])) {
|
||
foreach ($order_evaluation['data'] as &$item) {
|
||
$item['reply_quality'] = floor($item['reply_quality'] * 0.05);
|
||
$item['service_attitude'] = floor($item['service_attitude'] * 0.05);
|
||
$item['reply_progress'] = floor($item['reply_progress'] * 0.05);
|
||
$item['avg_score'] = floor($item['avg_score'] * 0.05);
|
||
|
||
$item['inquiry_type'] = $item['OrderInquiry']['inquiry_type'];
|
||
$item['inquiry_mode'] = $item['OrderInquiry']['inquiry_mode'];
|
||
|
||
// 获取问诊病例
|
||
$params = array();
|
||
$params['order_inquiry_id'] = $item['OrderInquiry']['order_inquiry_id'];
|
||
$order_inquiry_case = OrderInquiryCase::getOne($params);
|
||
if (!empty($order_inquiry_case)){
|
||
$item['disease_class_name'] = $order_inquiry_case['disease_class_name'];
|
||
}
|
||
|
||
unset($item['OrderInquiry']);
|
||
}
|
||
}
|
||
return success($order_evaluation);
|
||
}
|
||
|
||
/**
|
||
* 新增关注医生
|
||
* @return array
|
||
*/
|
||
public function addDoctorFollow(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$doctor_id = $this->request->route('doctor_id');
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['doctor_id'] = $doctor_id;
|
||
$res = PatientFollow::getExists($params);
|
||
if ($res){
|
||
// 已关注,重复请求
|
||
return success();
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try{
|
||
$data = array();
|
||
$data['patient_id'] = $user_info['client_user_id'];
|
||
$data['doctor_id'] = $doctor_id;
|
||
$patient_follow = PatientFollow::addPatientFollow($data);
|
||
if (empty($patient_follow)){
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR);
|
||
}
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_id;
|
||
UserDoctor::inc($params,"number_of_fans");
|
||
|
||
Db::commit();
|
||
return success();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 取消关注医生
|
||
* @return array
|
||
*/
|
||
public function deleteDoctorFollow(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
$doctor_id = $this->request->route('doctor_id');
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['doctor_id'] = $doctor_id;
|
||
$res = PatientFollow::getExists($params);
|
||
if (!$res){
|
||
// 未关注,执行取消关注
|
||
return success();
|
||
}
|
||
|
||
Db::beginTransaction();
|
||
try{
|
||
$params = array();
|
||
$params['patient_id'] = $user_info['client_user_id'];
|
||
$params['doctor_id'] = $doctor_id;
|
||
PatientFollow::deletePatientFollow($params);
|
||
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor_id;
|
||
UserDoctor::dec($params,"number_of_fans");
|
||
|
||
Db::commit();
|
||
return success();
|
||
} catch (\Exception $e) {
|
||
Db::rollBack();
|
||
return fail(HttpEnumCode::SERVER_ERROR, $e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 获取首页服务过患者的医生
|
||
* 限制条数
|
||
* @param string $patient_id
|
||
* @return array
|
||
*/
|
||
public function getIndexPatientDoctorLimit(string $patient_id): array
|
||
{
|
||
$results = array();
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $patient_id;
|
||
$params['history_status'] = 1;
|
||
$patient_history_doctors = PatientHistoryInquiryModel::getListOrder($params);
|
||
if (!empty($patient_history_doctors)) {
|
||
$userDoctorService = new UserDoctorService();
|
||
|
||
foreach ($patient_history_doctors as $patient_history_doctor) {
|
||
if (count($results) >= 5){
|
||
break;
|
||
}
|
||
|
||
foreach ($results as $item){
|
||
if ($patient_history_doctor['doctor_id'] == $item['doctor_id']){
|
||
continue 2;
|
||
}
|
||
}
|
||
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $patient_history_doctor['doctor_id'];
|
||
$user_doctor = UserDoctor::getOne($params);
|
||
if (empty($user_doctor)){
|
||
continue;
|
||
}
|
||
|
||
// 获取用户数据
|
||
$params = array();
|
||
$params['user_id'] = $user_doctor['user_id'];
|
||
$user = User::getOne($params);
|
||
if (empty($user)){
|
||
continue;
|
||
}
|
||
|
||
// 获取医生问诊配置
|
||
$params = array();
|
||
$params['doctor_id'] = $user_doctor['doctor_id'];
|
||
$doctor_inquiry_config = DoctorInquiryConfig::getInquiryConfigList($params);
|
||
if (empty($doctor_inquiry_config)){
|
||
continue;
|
||
}
|
||
|
||
// 获取医生医院
|
||
$hospital_name = "";
|
||
$hospital_level_name = "";
|
||
if (!empty($user_doctor['hospital_id'])){
|
||
$params = array();
|
||
$params['hospital_id'] = $user_doctor['hospital_id'];
|
||
$hospital = Hospital::getOne($params);
|
||
if (!empty($hospital)){
|
||
$hospital_name = $hospital['hospital_name'];
|
||
$hospital_level_name = $hospital['hospital_level_name'] ?? "";
|
||
}
|
||
}
|
||
|
||
// 组合数据
|
||
$data = array();
|
||
$data['doctor_id'] = $user_doctor['doctor_id'];
|
||
$data['user_name'] = $user_doctor['user_name'];
|
||
$data['avatar'] = addAliyunOssWebsite($user_doctor['avatar']);
|
||
$data['hospital_name'] = $hospital_name;
|
||
$data['hospital_level_name'] = $hospital_level_name;
|
||
$data['be_good_at'] = $user_doctor['be_good_at'];
|
||
$data['department_custom_name'] = $user_doctor['department_custom_name'];
|
||
$data['doctor_title'] = empty($user_doctor['doctor_title']) ? "" : DoctorTitleCode::getMessage($user_doctor['doctor_title']);
|
||
|
||
// 按照天来计算,当日为1,前一天为2 未服务过为0
|
||
if (empty($patient_history_doctor['created_at'])) {
|
||
$data['days'] = 0;
|
||
} else {
|
||
$data['days'] = ceil((strtotime(date('Y-m-d', strtotime('+1 day'))) - strtotime($patient_history_doctor['created_at'])) / 86400);
|
||
}
|
||
|
||
// 在线状态
|
||
$data['is_online'] = $user['is_online'];
|
||
|
||
$data['multi_point_status'] = $user_doctor['multi_point_status']; // 医生多点执业认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||
|
||
// 是否开启问诊购药
|
||
$data['multi_point_enable'] = $userDoctorService->getDoctorMultiPointEnable("",$doctor_inquiry_config);
|
||
|
||
$results[] = $data;
|
||
|
||
unset($data);
|
||
}
|
||
}
|
||
|
||
|
||
return $results;
|
||
}
|
||
} |