修改问诊购药分配医生
This commit is contained in:
parent
8ff1205e7c
commit
108ce91850
@ -128,9 +128,33 @@ class AssignDoctorConsumer extends ConsumerMessage
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 检测当前是否符合系统问诊时间
|
||||
$inquiryService = new InquiryService();
|
||||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($order_inquiry['inquiry_type']);
|
||||
if (!$is_system_time_pass && $order_inquiry['inquiry_type'] == 4){
|
||||
// 非坐班时间
|
||||
Log::getInstance()->error("分配医生队列执行失败:问诊购药非医生坐班时间,执行退款");
|
||||
|
||||
$InquiryService = new InquiryService();
|
||||
|
||||
// 检测问诊订单执行退款次数
|
||||
Log::getInstance()->info("检测问诊订单执行退款次数");
|
||||
$res = $InquiryService->checkInquiryRefundCount($order_inquiry['order_inquiry_id']);
|
||||
if (!$res){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("分配医生队列执行失败原因:超出最大退款次数");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
$InquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "暂无医生接诊");
|
||||
|
||||
Db::commit();
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 分配医生
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$doctor_id = $UserDoctorService->getInquiryAssignDoctor($order_inquiry['inquiry_type'],$order_inquiry['patient_id']);
|
||||
$doctor_id = $UserDoctorService->getInquiryAssignDoctor($order_inquiry['inquiry_type'],$order_inquiry['patient_id'],$is_system_time_pass);
|
||||
if (empty($doctor_id)){
|
||||
// 无合适医生
|
||||
Db::rollBack();
|
||||
|
||||
@ -309,4 +309,16 @@ class UserDoctor extends Model
|
||||
{
|
||||
return self::where($params)->whereNotIn('doctor_id',$not_in_params)->first($fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据-多
|
||||
* @param array $params
|
||||
* @param array $not_in_params
|
||||
* @param array $fields
|
||||
* @return Collection|array|\Hyperf\Utils\Collection
|
||||
*/
|
||||
public static function getUserDoctorNotInList(array $params = [], array $not_in_params = [],array $fields = ['*']): Collection|array|\Hyperf\Utils\Collection
|
||||
{
|
||||
return self::where($params)->whereNotIn('doctor_id',$not_in_params)->get($fields);
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ use App\Model\PatientFamilyPersonal;
|
||||
use App\Model\PatientFollow;
|
||||
use App\Model\Product;
|
||||
use App\Model\SystemInquiryConfig;
|
||||
use App\Model\SystemInquiryTime;
|
||||
use App\Model\User;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Model\UserDoctor;
|
||||
@ -116,6 +117,13 @@ class InquiryService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
// 检测当前是否符合系统问诊时间
|
||||
$inquiryService = new InquiryService();
|
||||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($request_params['inquiry_type']);
|
||||
if (!$is_system_time_pass && $request_params['inquiry_type'] == 4){
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "当前非医生接诊时间");
|
||||
}
|
||||
|
||||
// 获取问诊价格
|
||||
$DoctorInquiryService = new DoctorInquiryService();
|
||||
$inquiry_price = $DoctorInquiryService->getDoctorInquiryPrice($request_params['inquiry_type'], $request_params['inquiry_mode'], $request_params['doctor_id'] ?: "");
|
||||
@ -849,7 +857,6 @@ class InquiryService extends BaseService
|
||||
return $amount_total_sum ?: 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取医生可提现金额
|
||||
* @param string $doctor_id
|
||||
@ -1209,4 +1216,41 @@ class InquiryService extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测当前是否符合系统问诊时间
|
||||
* @param string $inquiry_type 接诊类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||
* @return bool
|
||||
*/
|
||||
public function checkSystemInquiryTime(string $inquiry_type): bool
|
||||
{
|
||||
// 获取问诊配置
|
||||
$params = array();
|
||||
$params['inquiry_type'] = $inquiry_type;
|
||||
$params['inquiry_mode'] = 1;
|
||||
$system_inquiry_config = SystemInquiryConfig::getOne($params);
|
||||
if (empty($system_inquiry_config)){
|
||||
throw new BusinessException("系统问诊配置错误");
|
||||
}
|
||||
|
||||
// 获取系统工作时间
|
||||
$params = array();
|
||||
$params['system_inquiry_config_id'] = $system_inquiry_config['system_inquiry_config_id'];
|
||||
$system_inquiry_time = SystemInquiryTime::getList($params);
|
||||
if (empty($system_inquiry_time)){
|
||||
throw new BusinessException("系统问诊时间配置错误");
|
||||
}
|
||||
|
||||
// 检测当前是否坐班时间
|
||||
$is_time_pass = false; // 非坐班时间
|
||||
|
||||
foreach ($system_inquiry_time as $item){
|
||||
$now_time = date('H',time()) . date('i',time());
|
||||
if ($item['start_time'] < $now_time && $item['end_time'] > $now_time){
|
||||
// 符合当前时间区间
|
||||
$is_time_pass = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $is_time_pass;
|
||||
}
|
||||
}
|
||||
@ -384,99 +384,120 @@ class PatientDoctorService extends BaseService
|
||||
$result['message'] = "可接诊";
|
||||
$result['status'] = 1;
|
||||
|
||||
// 检测是否存在同类型未完成的问诊订单
|
||||
$PatientOrderService = new PatientOrderService();
|
||||
$order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry($inquiry_type,$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();
|
||||
}
|
||||
|
||||
if ($user_doctor['idcard_status'] != 1) {
|
||||
return fail();
|
||||
}
|
||||
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($user_info['client_user_id'],$doctor_id);
|
||||
if (!empty($order_inquiry)){
|
||||
try {
|
||||
// 检测是否存在同类型未完成的问诊订单
|
||||
$PatientOrderService = new PatientOrderService();
|
||||
$order_inquiry_id = $PatientOrderService->getNotFinishedOrderInquiry($inquiry_type,$user_info['client_user_id']);
|
||||
if (!empty($order_inquiry_id)){
|
||||
$result['status'] = 2;
|
||||
$result['data']['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$result['message'] = "您和当前医生存在问诊中订单,无法再次发起问诊";
|
||||
$result['data']['order_inquiry_id'] = $order_inquiry_id;
|
||||
$result['message'] = "存在未完成的问诊订单";
|
||||
return success($result);
|
||||
}
|
||||
|
||||
// 获取医生每日最大接诊数量
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$max_work_num_day = $UserDoctorService->getDoctorInquiryDayMaxNum($doctor_id,$inquiry_type,$inquiry_mode);
|
||||
// 检测是否检测医生
|
||||
if (!empty($doctor_id)){
|
||||
// 获取医生信息
|
||||
$params = array();
|
||||
$params['doctor_id'] = $doctor_id;
|
||||
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($doctor_id,$inquiry_type,$inquiry_mode);
|
||||
$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, "非法医生");
|
||||
}
|
||||
|
||||
// 计算剩余未接诊数量 = 最大数量-
|
||||
$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 ($user_doctor['iden_auth_status'] != 1) {
|
||||
return fail(HttpEnumCode::HTTP_ERROR,"医生暂不可接诊");
|
||||
}
|
||||
|
||||
if ($user_doctor['idcard_status'] != 1) {
|
||||
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);
|
||||
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($doctor_id,$inquiry_type,$inquiry_mode);
|
||||
|
||||
// 计算剩余未接诊数量 = 最大数量-
|
||||
$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 == 4){
|
||||
// 公益问诊-检测当前患者问诊次数(24小时内两次公益问诊)
|
||||
$params = array();
|
||||
$params['patient_id'] = $user_info['client_user_id'];
|
||||
$params['inquiry_type'] = $inquiry_type;
|
||||
$params['inquiry_mode'] = $inquiry_mode;
|
||||
// 检测公益问诊-当前患者问诊次数(24小时内两次公益问诊)
|
||||
if ($inquiry_type == 4){
|
||||
$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);
|
||||
$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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检测快速、购药问诊是否由可分配医生
|
||||
if ($inquiry_type == 2 || $inquiry_type == 4){
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$doctor_id = $UserDoctorService->getInquiryAssignDoctor($inquiry_type,$user_info['client_user_id']);
|
||||
if (empty($doctor_id)){
|
||||
// 无合适医生
|
||||
$result['status'] = 3;
|
||||
$result['data'] = "";
|
||||
$result['message'] = "目前暂无可接诊医生";
|
||||
return success($result);
|
||||
// 检测当前是否符合系统问诊时间
|
||||
$inquiryService = new InquiryService();
|
||||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($inquiry_type);
|
||||
if (!$is_system_time_pass){
|
||||
// 非坐班时间
|
||||
if ($inquiry_type == 4){
|
||||
// 问诊购药非坐班时间不允许接诊
|
||||
$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);
|
||||
dump($doctor_id);
|
||||
if (empty($doctor_id)){
|
||||
// 无合适医生
|
||||
$result['status'] = 3;
|
||||
$result['data'] = "";
|
||||
$result['message'] = "目前暂无可接诊医生";
|
||||
return success($result);
|
||||
}
|
||||
}
|
||||
}catch(\Exception $e){
|
||||
// 错误不做处理,此处只是检测
|
||||
return success($result);
|
||||
}
|
||||
|
||||
return success($result);
|
||||
|
||||
@ -1216,7 +1216,7 @@ class UserDoctorService extends BaseService
|
||||
return fail();
|
||||
}
|
||||
|
||||
if (in_array($order_inquiry['inquiry_status'], [1, 2, 3, 6, 7])) {
|
||||
if (in_array($order_inquiry['inquiry_status'], [1, 2, 3,5, 6, 7])) {
|
||||
// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
return fail(HttpEnumCode::HTTP_ERROR, "订单无法开具处方");
|
||||
}
|
||||
@ -1868,13 +1868,13 @@ class UserDoctorService extends BaseService
|
||||
$params[] = ['inquiry_mode', '=', 1];
|
||||
$params[] = ['reception_time', '>', $date];
|
||||
|
||||
$inquiry_status_params = array();
|
||||
$inquiry_status_params = [4, 5];// 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消)
|
||||
$order_inquirys = OrderInquiry::getInquiryStatusWithDoctorNotInList($params, $inquiry_status_params,$not_doctor_ids);
|
||||
if (empty($order_inquirys)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$order_inquirys = $order_inquirys->toArray();
|
||||
$result = [];
|
||||
foreach ($order_inquirys as $item){
|
||||
$result[] = $item['UserDoctor'];
|
||||
@ -1887,235 +1887,111 @@ class UserDoctorService extends BaseService
|
||||
* 获取快速、购药问诊可分配医生
|
||||
* @param string $inquiry_type
|
||||
* @param string $patient_id
|
||||
* @param bool $is_system_time_pass 是否系统坐班时间 0:否 1:是
|
||||
* @return string
|
||||
*/
|
||||
public function getInquiryAssignDoctor(string $inquiry_type,string $patient_id): string
|
||||
public function getInquiryAssignDoctor(string $inquiry_type,string $patient_id,bool $is_system_time_pass): string
|
||||
{
|
||||
// 获取问诊配置
|
||||
$params = array();
|
||||
$params['inquiry_type'] = $inquiry_type;
|
||||
$params['inquiry_mode'] = 1;
|
||||
$system_inquiry_config = SystemInquiryConfig::getOne($params);
|
||||
if (empty($system_inquiry_config)){
|
||||
return "";
|
||||
}
|
||||
|
||||
// 获取系统工作时间
|
||||
$params = array();
|
||||
$params['system_inquiry_config_id'] = $system_inquiry_config['system_inquiry_config_id'];
|
||||
$system_inquiry_time = SystemInquiryTime::getList($params);
|
||||
if (empty($system_inquiry_time)){
|
||||
return "";
|
||||
}
|
||||
|
||||
// 检测当前是否坐班时间
|
||||
$is_time_pass = false; // 非坐班时间
|
||||
|
||||
foreach ($system_inquiry_time as $item){
|
||||
$now_time = date('H',time()) . date('i',time());
|
||||
if ($item['start_time'] < $now_time && $item['end_time'] > $now_time){
|
||||
// 符合当前时间区间
|
||||
$is_time_pass = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 不可选择的医生id数组
|
||||
$not_doctor_ids = [];
|
||||
|
||||
while (true){
|
||||
// 系统坐班时间
|
||||
if ($is_time_pass){
|
||||
// 获取坐班时间包含当前时间的深度合作医生
|
||||
$doctor_id = $this->getNowTimePlatDeepCooperationDoctorId($inquiry_type,time(),$not_doctor_ids);
|
||||
if (!empty($doctor_id)){
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$doctor_id);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$not_doctor_ids[] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
if ($is_system_time_pass){
|
||||
// 获取坐班时间包含当前时间的深度合作医生
|
||||
$doctor_ids = $this->getNowTimePlatDeepCooperationDoctorId($inquiry_type,time(),$not_doctor_ids);
|
||||
|
||||
// 不存在未完成的问诊订单
|
||||
break;
|
||||
}
|
||||
// 检测医生是否可被分配
|
||||
$result = $this->checkDoctorCanBeAssigned($doctor_ids,$patient_id,0,$inquiry_type);
|
||||
|
||||
if (!empty($result['doctor_id'])){
|
||||
return $result['doctor_id'];
|
||||
}
|
||||
|
||||
// 获取深度合作的在线医生
|
||||
$params = array();
|
||||
$params['status'] = 1;
|
||||
$params['idcard_status'] = 1;
|
||||
$params['iden_auth_status'] = 1;
|
||||
$params['is_bind_bank'] = 1;
|
||||
$params['is_online'] = 1;
|
||||
if ($inquiry_type == 2){
|
||||
// 快速问诊
|
||||
$params['is_img_quick_reception'] = 1;
|
||||
}elseif ($inquiry_type == 4){
|
||||
// 问诊购药
|
||||
$params['multi_point_status'] = 1;
|
||||
}
|
||||
$params['is_platform_deep_cooperation'] = 1;
|
||||
|
||||
$user_doctor = UserDoctor::getUserDoctorNotInOne($params,$not_doctor_ids);
|
||||
if (!empty($user_doctor)){
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$user_doctor['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$not_doctor_ids[] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
// 不存在未完成的问诊订单
|
||||
$doctor_id = $user_doctor['doctor_id'];
|
||||
break;
|
||||
if (!empty($result['not_doctor_ids'])){
|
||||
$not_doctor_ids = array_merge($not_doctor_ids,$result['not_doctor_ids']);
|
||||
}
|
||||
|
||||
// 获取在线的自由注册医生
|
||||
$params = array();
|
||||
$params['status'] = 1;
|
||||
$params['idcard_status'] = 1;
|
||||
$params['iden_auth_status'] = 1;
|
||||
$params['is_bind_bank'] = 1;
|
||||
$params['is_online'] = 1;
|
||||
if ($inquiry_type == 2){
|
||||
// 快速问诊
|
||||
$params['is_img_quick_reception'] = 1;
|
||||
}elseif ($inquiry_type == 4){
|
||||
// 问诊购药
|
||||
$params['multi_point_status'] = 1;
|
||||
// 问诊购药情况特殊,第一次未匹配到直接返回失败
|
||||
if($inquiry_type == 4){
|
||||
return "";
|
||||
}
|
||||
$user_doctor = UserDoctor::getUserDoctorNotInOne($params,$not_doctor_ids);
|
||||
if (!empty($user_doctor)){
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$user_doctor['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$not_doctor_ids[] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取医生每日最大接诊数量
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$max_work_num_day = $UserDoctorService->getDoctorInquiryDayMaxNum($user_doctor['doctor_id'],$inquiry_type,1);
|
||||
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($user_doctor['doctor_id'],$inquiry_type,1);
|
||||
|
||||
// 计算剩余未接诊数量 = 最大数量-
|
||||
$access_inquiry_num = $max_work_num_day - $order_inquiry_count;
|
||||
|
||||
if ($access_inquiry_num <= 0){
|
||||
// 分配的医生无问诊次数,重新分配
|
||||
$not_doctor_ids[] = $user_doctor['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
// 未超出最大接诊量
|
||||
$doctor_id = $user_doctor['doctor_id'];
|
||||
break;
|
||||
}
|
||||
|
||||
// 检测当前时间5分钟后,坐班时间包含某时间的平台深度合作医生
|
||||
$doctor_id = $this->getNowTimePlatDeepCooperationDoctorId($inquiry_type,strtotime ("+5 minute"),$not_doctor_ids);
|
||||
if (!empty($doctor_id)){
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$doctor_id);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$not_doctor_ids[] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
// 不存在未完成的问诊订单
|
||||
break;
|
||||
}
|
||||
|
||||
// 当前时间10分钟内接诊中医生
|
||||
$doctors = $this->getBeforeCurrentTimeDoctor(10,$inquiry_type,$not_doctor_ids);
|
||||
if (!empty($doctors)){
|
||||
foreach ($doctors as $item){
|
||||
// 自由注册医生检测接诊数量
|
||||
if ($item['is_platform_deep_cooperation'] == 0){
|
||||
// 获取医生每日最大接诊数量
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$max_work_num_day = $UserDoctorService->getDoctorInquiryDayMaxNum($item['doctor_id'],$inquiry_type,1);
|
||||
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($item['doctor_id'],$inquiry_type,1);
|
||||
|
||||
// 计算剩余未接诊数量 = 最大数量-
|
||||
$access_inquiry_num = $max_work_num_day - $order_inquiry_count;
|
||||
|
||||
if ($access_inquiry_num <= 0){
|
||||
// 分配的医生无问诊次数,重新分配
|
||||
$not_doctor_ids[] = $item['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$item['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$not_doctor_ids[] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
$doctor_id = $item['doctor_id'];
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 当前时间10分钟内接诊中医生
|
||||
$doctors = $this->getBeforeCurrentTimeDoctor(30,$inquiry_type,$not_doctor_ids);
|
||||
if (!empty($doctors)){
|
||||
foreach ($doctors as $item){
|
||||
// 自由注册医生检测接诊数量
|
||||
if ($item['is_platform_deep_cooperation'] == 0){
|
||||
// 获取医生每日最大接诊数量
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
$max_work_num_day = $UserDoctorService->getDoctorInquiryDayMaxNum($item['doctor_id'],$inquiry_type,1);
|
||||
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($item['doctor_id'],$inquiry_type,1);
|
||||
|
||||
// 计算剩余未接诊数量 = 最大数量-
|
||||
$access_inquiry_num = $max_work_num_day - $order_inquiry_count;
|
||||
|
||||
if ($access_inquiry_num <= 0){
|
||||
// 分配的医生无问诊次数,重新分配
|
||||
$not_doctor_ids[] = $item['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$item['doctor_id']);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$not_doctor_ids[] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
$doctor_id = $item['doctor_id'];
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
// 医生id归为空
|
||||
$doctor_id = "";
|
||||
break;
|
||||
}
|
||||
|
||||
return $doctor_id;
|
||||
// 获取全部深度合作的在线医生
|
||||
$user_doctor = $this->getOnlineDeepDoctor($inquiry_type,$not_doctor_ids);
|
||||
if (!empty($user_doctor)){
|
||||
$doctor_ids = array_column($user_doctor,'doctor_id');
|
||||
|
||||
// 检测医生是否可被分配
|
||||
$result = $this->checkDoctorCanBeAssigned($doctor_ids,$patient_id,0,$inquiry_type);
|
||||
if (!empty($result['doctor_id'])){
|
||||
return $result['doctor_id'];
|
||||
}
|
||||
|
||||
if (!empty($result['not_doctor_ids'])){
|
||||
$not_doctor_ids = array_merge($not_doctor_ids,$result['not_doctor_ids']);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取在线的自由注册医生
|
||||
$user_doctor = $this->getOnlineDoctor($inquiry_type,$not_doctor_ids);
|
||||
if (!empty($user_doctor)){
|
||||
$doctor_ids = array_column($user_doctor,'doctor_id');
|
||||
|
||||
// 检测医生是否可被分配
|
||||
$result = $this->checkDoctorCanBeAssigned($doctor_ids,$patient_id,1,$inquiry_type);
|
||||
|
||||
if (!empty($result['doctor_id'])){
|
||||
return $result['doctor_id'];
|
||||
}
|
||||
|
||||
if (!empty($result['not_doctor_ids'])){
|
||||
$not_doctor_ids = array_merge($not_doctor_ids,$result['not_doctor_ids']);
|
||||
}
|
||||
}
|
||||
|
||||
// 检测当前时间5分钟后,坐班时间包含某时间的平台深度合作医生
|
||||
$doctor_ids = $this->getNowTimePlatDeepCooperationDoctorId($inquiry_type,strtotime ("+5 minute"),$not_doctor_ids);
|
||||
if (!empty($doctor_ids)){
|
||||
// 检测医生是否可被分配
|
||||
$result = $this->checkDoctorCanBeAssigned($doctor_ids,$patient_id,1,$inquiry_type);
|
||||
if (!empty($result['doctor_id'])){
|
||||
return $result['doctor_id'];
|
||||
}
|
||||
|
||||
if (!empty($result['not_doctor_ids'])){
|
||||
$not_doctor_ids = array_merge($not_doctor_ids,$result['not_doctor_ids']);
|
||||
}
|
||||
}
|
||||
|
||||
// 当前时间10分钟内接诊中医生
|
||||
$doctors = $this->getBeforeCurrentTimeDoctor(10,$inquiry_type,$not_doctor_ids);
|
||||
if (!empty($doctors)){
|
||||
$doctor_ids = array_column($doctors,'doctor_id');
|
||||
|
||||
// 检测医生是否可被分配
|
||||
$result = $this->checkDoctorCanBeAssigned($doctor_ids,$patient_id,1,$inquiry_type);
|
||||
if (!empty($result['doctor_id'])){
|
||||
return $result['doctor_id'];
|
||||
}
|
||||
|
||||
if (!empty($result['not_doctor_ids'])){
|
||||
$not_doctor_ids = array_merge($not_doctor_ids,$result['not_doctor_ids']);
|
||||
}
|
||||
}
|
||||
|
||||
// 当前时间30分钟内接诊中医生
|
||||
$doctors = $this->getBeforeCurrentTimeDoctor(30,$inquiry_type,$not_doctor_ids);
|
||||
if (!empty($doctors)){
|
||||
$doctor_ids = array_column($doctors,'doctor_id');
|
||||
|
||||
// 检测医生是否可被分配
|
||||
$result = $this->checkDoctorCanBeAssigned($doctor_ids,$patient_id,1,$inquiry_type);
|
||||
if (!empty($result['doctor_id'])){
|
||||
return $result['doctor_id'];
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@ -2124,10 +2000,12 @@ class UserDoctorService extends BaseService
|
||||
* @param string $inquiry_type
|
||||
* @param string $time 时间戳
|
||||
* @param array $not_doctor_ids 不可选择的医生id数组
|
||||
* @return string
|
||||
* @return array 医生id
|
||||
*/
|
||||
public function getNowTimePlatDeepCooperationDoctorId(string $inquiry_type,string $time,array $not_doctor_ids = []): string
|
||||
public function getNowTimePlatDeepCooperationDoctorId(string $inquiry_type,string $time,array $not_doctor_ids = []): array
|
||||
{
|
||||
$doctor_ids = [];
|
||||
|
||||
$params = array();
|
||||
$params[] = ['inquiry_type','=',$inquiry_type];
|
||||
$params[] = ['inquiry_mode','=',1];
|
||||
@ -2151,17 +2029,15 @@ class UserDoctorService extends BaseService
|
||||
// 获取当前日期
|
||||
$now_day = date('Y-m-d',time());
|
||||
if ($item['inquiry_date'] == $now_day){
|
||||
return $item['doctor_id'];
|
||||
}else{
|
||||
continue;
|
||||
$doctor_ids[] = $item['doctor_id'];
|
||||
}
|
||||
}else{
|
||||
return $item['doctor_id'];
|
||||
$doctor_ids[] = $item['doctor_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
return $doctor_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2216,6 +2092,129 @@ class UserDoctorService extends BaseService
|
||||
return OrderInquiry::getInquiryStatusCount($params,$inquiry_status_params);
|
||||
}
|
||||
|
||||
// 获取医生已完成订单总额
|
||||
/**
|
||||
* 获取深度合作的在线医生
|
||||
* @param string $inquiry_type 订单类型(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药)
|
||||
* @param array $not_doctor_ids 不可选择的医生id数组
|
||||
* @return array
|
||||
*/
|
||||
public function getOnlineDeepDoctor(string $inquiry_type,array $not_doctor_ids): array
|
||||
{
|
||||
// 获取深度合作的在线医生x
|
||||
$params = array();
|
||||
$params['status'] = 1;
|
||||
$params['idcard_status'] = 1;
|
||||
$params['iden_auth_status'] = 1;
|
||||
$params['is_bind_bank'] = 1;
|
||||
$params['is_online'] = 1;
|
||||
if ($inquiry_type == 2){
|
||||
// 快速问诊
|
||||
$params['is_img_quick_reception'] = 1;
|
||||
}elseif ($inquiry_type == 4){
|
||||
// 问诊购药
|
||||
$params['multi_point_status'] = 1;
|
||||
}
|
||||
$params['is_platform_deep_cooperation'] = 1;
|
||||
|
||||
$user_doctor = UserDoctor::getUserDoctorNotInList($params,$not_doctor_ids);
|
||||
return $user_doctor->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线的自由注册医生
|
||||
* @param string $inquiry_type
|
||||
* @param array $not_doctor_ids
|
||||
* @return array
|
||||
*/
|
||||
public function getOnlineDoctor(string $inquiry_type,array $not_doctor_ids): array
|
||||
{
|
||||
//
|
||||
$params = array();
|
||||
$params['status'] = 1;
|
||||
$params['idcard_status'] = 1;
|
||||
$params['iden_auth_status'] = 1;
|
||||
$params['is_bind_bank'] = 1;
|
||||
$params['is_online'] = 1;
|
||||
if ($inquiry_type == 2){
|
||||
// 快速问诊
|
||||
$params['is_img_quick_reception'] = 1;
|
||||
}elseif ($inquiry_type == 4){
|
||||
// 问诊购药
|
||||
$params['multi_point_status'] = 1;
|
||||
}
|
||||
$user_doctor = UserDoctor::getUserDoctorNotInList($params,$not_doctor_ids);
|
||||
return $user_doctor->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测医生是否可被分配
|
||||
* @param array $doctor_ids
|
||||
* @param string $patient_id
|
||||
* @param string|int $is_check_inquiry_num 是否检测问诊数量 0:否 1:是
|
||||
* @param string $inquiry_type
|
||||
* @return array
|
||||
*/
|
||||
public function checkDoctorCanBeAssigned(array $doctor_ids,string $patient_id,string|int $is_check_inquiry_num,string $inquiry_type): array
|
||||
{
|
||||
$result = array();
|
||||
$result['not_doctor_ids'] = [];
|
||||
$result['doctor_id'] = [];
|
||||
|
||||
if (empty($doctor_ids)){
|
||||
return $result;
|
||||
}
|
||||
|
||||
$doctor = [];
|
||||
foreach ($doctor_ids as $item){
|
||||
// 检测当前医生是否和患者存在未完成问诊订单
|
||||
$InquiryService = new InquiryService();
|
||||
$order_inquiry = $InquiryService->checkPatientDoctorProgressInquiry($patient_id,$item);
|
||||
if (!empty($order_inquiry)){
|
||||
// 存在未完成问诊订单,记录该医生id,重新分配
|
||||
$result['not_doctor_ids'][] = $order_inquiry['doctor_id'];
|
||||
continue;
|
||||
}
|
||||
|
||||
$UserDoctorService = new UserDoctorService();
|
||||
|
||||
// 检测接诊数量
|
||||
if ($is_check_inquiry_num){
|
||||
// 获取医生每日最大接诊数量
|
||||
$max_work_num_day = $UserDoctorService->getDoctorInquiryDayMaxNum($item,$inquiry_type,1);
|
||||
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($item,$inquiry_type,1);
|
||||
|
||||
// 计算剩余未接诊数量 = 最大数量-
|
||||
$access_inquiry_num = $max_work_num_day - $order_inquiry_count;
|
||||
|
||||
if ($access_inquiry_num <= 0){
|
||||
// 分配的医生无问诊次数,重新分配
|
||||
$result['not_doctor_ids'][] = $item;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($order_inquiry_count)){
|
||||
// 获取医生未接诊订单数量(包含未接诊、未支付、已接诊)
|
||||
$order_inquiry_count = $UserDoctorService->getDoctorUnInquiryOrderNum($item,$inquiry_type,1);
|
||||
}
|
||||
|
||||
$data = array();
|
||||
$data['doctor_id'] = $item;
|
||||
$data['order_inquiry_count'] = $order_inquiry_count;
|
||||
$doctor[] = $data;
|
||||
}
|
||||
|
||||
if (!empty($doctor)){
|
||||
$order_inquiry_counts = array_column($doctor,'order_inquiry_count');
|
||||
array_multisort($order_inquiry_counts,SORT_ASC,$doctor);
|
||||
}
|
||||
|
||||
if (isset($doctor[0])){
|
||||
$result['doctor_id'] = $doctor[0]['doctor_id'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user