325 lines
12 KiB
PHP
325 lines
12 KiB
PHP
<?php
|
||
|
||
namespace App\Services;
|
||
|
||
use App\Constants\DoctorTitleCode;
|
||
use App\Constants\HttpEnumCode;
|
||
use App\Model\Banner as BannerModel;
|
||
use App\Model\DoctorInquiryConfig as DoctorInquiryConfigModel;
|
||
use App\Model\Module as ModuleModel;
|
||
use App\Model\PatientHistoryInquiry as PatientHistoryInquiryModel;
|
||
use App\Model\PharmacistAuditStatistic;
|
||
use App\Model\UserDoctor as UserDoctorModel;
|
||
use App\Model\UserPharmacist;
|
||
|
||
/**
|
||
* 首页模块
|
||
*/
|
||
class IndexService extends BaseService
|
||
{
|
||
/**
|
||
* 医生端-首页
|
||
* @return array
|
||
*/
|
||
public function getDoctorIndex(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
// 获取医生数据
|
||
$params = array();
|
||
$params['doctor_id'] = $user_info['client_user_id'];
|
||
|
||
$fields = [
|
||
"doctor_id",
|
||
"user_id",
|
||
"user_name",
|
||
"open_id",
|
||
"status",
|
||
"idcard_status",
|
||
"iden_auth_status",
|
||
"iden_auth_fail_reason",
|
||
"multi_point_status",
|
||
"is_bind_bank",
|
||
"mobile",
|
||
"avatar",
|
||
"praise_rate",
|
||
"avg_response_time",
|
||
"number_of_fans",
|
||
"is_online",
|
||
"is_img_expert_reception",
|
||
];
|
||
|
||
$doctor = UserDoctorModel::getOne($params, $fields);
|
||
if (empty($doctor)) {
|
||
return fail(HttpEnumCode::USER_STATUS_ERROR);
|
||
}
|
||
|
||
if ($doctor['status'] == 0){
|
||
return fail(HttpEnumCode::USER_STATUS_DISABLE);
|
||
}
|
||
|
||
if ($doctor['status'] != 1){
|
||
return fail(HttpEnumCode::USER_STATUS_ERROR);
|
||
}
|
||
|
||
$OrderInquiryService = new OrderInquiryService();
|
||
$OrderPrescriptionService = new OrderPrescriptionService();
|
||
|
||
// 获取未接诊患者个数
|
||
$not_accepted_inquiry_num = $OrderInquiryService->getDoctorNotAcceptedInquiryNum($doctor['doctor_id']);
|
||
|
||
// 获取接诊中患者个数
|
||
$accepting_inquiry_num = $OrderInquiryService->getDoctorAcceptingInquiryNum($doctor['doctor_id']);
|
||
|
||
// 获取被驳回处方数据
|
||
$reject_prescription_number = $OrderPrescriptionService->getDoctorExistsAuditFail($doctor['doctor_id']);
|
||
|
||
// 获取医生问诊价格
|
||
$params = array();
|
||
$params['doctor_id'] = $doctor['doctor_id'];
|
||
$params['inquiry_type'] = 1;// 接诊类型(1:专家问诊 2:快速问诊 3:公益问诊)
|
||
$params['inquiry_mode'] = 1;// 接诊方式(1:图文 2:视频 3:语音 4:电话 5:会员)
|
||
$doctor_inquiry_config = DoctorInquiryConfigModel::getOne($params);
|
||
|
||
// 获取banner
|
||
$params = array();
|
||
$params["app_type"] = 1;
|
||
$params["client_type"] = 2;
|
||
$params["banner_place"] = 1;
|
||
$params["banner_status"] = 1;
|
||
$banner = BannerModel::getList($params);
|
||
|
||
$info = array();
|
||
$info['doctor_id'] = $doctor['doctor_id'];
|
||
$info['user_name'] = $doctor['user_name'];
|
||
$info['status'] = $doctor['status'];
|
||
$info['idcard_status'] = $doctor['idcard_status'];// 实名认证状态(0:未认证 1:认证通过 2:认证失败)
|
||
$info['iden_auth_status'] = $doctor['idcard_status'];// 身份认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||
$info['multi_point_status'] = $doctor['multi_point_status'];// 医生多点执业认证状态(0:未认证 1:认证通过 2:审核中 3:认证失败)
|
||
$info['is_bind_bank'] = $doctor['is_bind_bank'];// 是否已绑定结算银行卡(0:否 1:是)
|
||
$info['avatar'] = $doctor['avatar'];
|
||
$info['is_img_expert_reception'] = $doctor['is_img_expert_reception'];// 是否参加专家图文接诊(0:否 1:是)
|
||
$info['praise_rate'] = $doctor['praise_rate'];// 好评率(百分制。回复质量占4、服务态度占3、回复速度占3。每周计算一次)
|
||
$info['avg_response_time'] = $doctor['avg_response_time'];// 平均响应时间(分钟制)
|
||
$info['number_of_fans'] = $doctor['number_of_fans'];// 被关注数量
|
||
$info['inquiry_price'] = $doctor_inquiry_config['inquiry_price'] ?? "";// 在线问诊价格
|
||
$info['not_accepted_inquiry_num'] = $not_accepted_inquiry_num ?? 0;// 获取未接诊患者个数
|
||
$info['accepting_inquiry_num'] = $accepting_inquiry_num ?? 0;// 获取接诊中患者个数
|
||
$info['reject_prescription_number'] = $reject_prescription_number ?? 0;// 获取被驳回处方数据
|
||
|
||
$data = array();
|
||
$data['banner'] = $banner ?? [];// banner
|
||
$data['info'] = $info;// 医生数据
|
||
|
||
return success($data);
|
||
}
|
||
|
||
/**
|
||
* 患者端-首页
|
||
* @return array
|
||
*/
|
||
public function getPatientIndex(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
// 获取banner
|
||
$params = array();
|
||
$params["app_type"] = 1;
|
||
$params["client_type"] = 1;
|
||
$params["banner_place"] = 1;
|
||
$params["banner_status"] = 1;
|
||
$banner = BannerModel::getList($params);
|
||
|
||
// 获取模块
|
||
$params = array();
|
||
$params["app_type"] = 1;
|
||
$params["client_type"] = 1;
|
||
$params["module_place"] = 1;
|
||
$params["module_status"] = 1;
|
||
$module = ModuleModel::getList($params);
|
||
|
||
// 我的医生
|
||
$my_doctor = [];
|
||
if (!empty($user_info)) {
|
||
$my_doctor = $this->getIndexPatientDoctor($user_info['client_user_id']);
|
||
}
|
||
|
||
// 推荐医生
|
||
$recommend_doctor = $this->getIndexRecommendDoctor();
|
||
|
||
$result = array();
|
||
$result["banner"] = $banner ?? [];// banner
|
||
$result["recommend_doctor"] = $recommend_doctor['data'] ?? []; // 推荐医生
|
||
$result["my_doctor"] = $my_doctor ?? []; // 我的医生
|
||
$result["module"] = $module ?? []; // 首页模块
|
||
return success($result);
|
||
}
|
||
|
||
/**
|
||
* 药师端-首页
|
||
* @return array
|
||
*/
|
||
public function getPharmacistIndex(): array
|
||
{
|
||
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
||
|
||
// 获取药师数据
|
||
$params = array();
|
||
$params['pharmacist_id'] = $user_info['client_user_id'];
|
||
|
||
$fields = [
|
||
"pharmacist_id",
|
||
"user_id",
|
||
"user_name",
|
||
"open_id",
|
||
"status",
|
||
"avatar",
|
||
"is_online",
|
||
];
|
||
|
||
$user_pharmacist = UserPharmacist::getOne($params,$fields);
|
||
if (empty($user_pharmacist)) {
|
||
return fail(HttpEnumCode::USER_STATUS_ERROR);
|
||
}
|
||
|
||
if ($user_pharmacist['status'] == 0){
|
||
return fail(HttpEnumCode::USER_STATUS_DISABLE);
|
||
}
|
||
|
||
if ($user_pharmacist['status'] != 1){
|
||
return fail(HttpEnumCode::USER_STATUS_ERROR);
|
||
}
|
||
|
||
// 获取药师审方数量
|
||
$params = array();
|
||
$params['pharmacist_id'] = $user_pharmacist['pharmacist_id'];
|
||
$params['statistics_date'] = date('Y-m-d',time());
|
||
$audit_number = PharmacistAuditStatistic::getCount($params);
|
||
if (empty($audit_number)){
|
||
$audit_number = 0;
|
||
}
|
||
|
||
// 获取药师待审核处方
|
||
$OrderPrescriptionService = new OrderPrescriptionService();
|
||
$prescription = $OrderPrescriptionService->getPharmacistWaitAuditPage($user_pharmacist['pharmacist_id']);
|
||
|
||
// 组合返回数据
|
||
$data = array();
|
||
$data['pharmacist'] = $user_pharmacist;
|
||
$data['audit_number'] = $audit_number;
|
||
$data['prescription'] = $prescription;
|
||
|
||
return success($data);
|
||
}
|
||
/**
|
||
* 患者端-首页-我的医生-限制条数
|
||
* @param string $patient_id
|
||
* @return array
|
||
*/
|
||
protected function getIndexPatientDoctor(string $patient_id): array
|
||
{
|
||
$results = array();
|
||
|
||
$params = array();
|
||
$params['patient_id'] = $patient_id;
|
||
$params['history_status'] = 1;
|
||
$patient_history_doctors = PatientHistoryInquiryModel::getIndexHistoryDoctorLimit($params);
|
||
if (!empty($patient_history_doctors)) {
|
||
foreach ($patient_history_doctors as $patient_history_doctor) {
|
||
if (empty($patient_history_doctor['userDoctor'])) {
|
||
continue;
|
||
}
|
||
|
||
// 组合数据
|
||
$data = array();
|
||
$data['doctor_id'] = $patient_history_doctor['userDoctor']['doctor_id'];
|
||
$data['user_name'] = $patient_history_doctor['userDoctor']['user_name'];
|
||
$data['avatar'] = $patient_history_doctor['userDoctor']['avatar'];
|
||
$data['hospital_name'] = "";
|
||
if (!empty($patient_history_doctor['userDoctor']['Hospital'])) {
|
||
$data['hospital_name'] = $patient_history_doctor['userDoctor']['Hospital']['hospital_name'];
|
||
}
|
||
|
||
// 按照天来计算,当日为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);
|
||
}
|
||
|
||
$results[] = $data;
|
||
|
||
unset($data);
|
||
}
|
||
}
|
||
return $results;
|
||
}
|
||
|
||
/**
|
||
* 患者端-首页-推荐医生-限制条数
|
||
* @return array
|
||
*/
|
||
protected function getIndexRecommendDoctor(): array
|
||
{
|
||
$results = array();
|
||
|
||
// 推荐医生
|
||
$fields = [
|
||
"doctor_id",
|
||
"user_id",
|
||
"user_name",
|
||
"status",
|
||
"multi_point_status",
|
||
"avatar",
|
||
"doctor_title",
|
||
"department_custom_name",
|
||
"hospital_id",
|
||
"is_online",
|
||
"is_img_expert_reception",
|
||
"be_good_at",
|
||
];
|
||
|
||
$recommend_doctors = UserDoctorModel::getIndexRecommendDoctorLimit(5, $fields);
|
||
if (empty($recommend_doctors)) {
|
||
return success();
|
||
}
|
||
|
||
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'] = $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['is_online'] = $recommend_doctor['is_online'];
|
||
$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'];
|
||
|
||
// 处理接诊价格
|
||
$data['price'] = 0;
|
||
$data['free_clinic_price'] = 0;
|
||
foreach ($recommend_doctor['DoctorInquiryConfig'] as $doctor_inquiry_config) {
|
||
if ($doctor_inquiry_config['inquiry_mode'] == 1){
|
||
if ($doctor_inquiry_config['inquiry_type'] == 1) {
|
||
// 专家问诊
|
||
$data['price'] = $doctor_inquiry_config['inquiry_price'];
|
||
}
|
||
|
||
if ($doctor_inquiry_config['inquiry_type'] == 3) {
|
||
// 公益
|
||
$data['free_clinic_price'] = $doctor_inquiry_config['inquiry_price'];
|
||
}
|
||
}
|
||
}
|
||
|
||
$results[] = $data;
|
||
|
||
unset($data);
|
||
}
|
||
return success($results);
|
||
}
|
||
} |