178 lines
5.4 KiB
PHP
178 lines
5.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Constants\HttpEnumCode;
|
|
use App\Model\Coupon;
|
|
use App\Model\OrderInquiry;
|
|
use App\Model\UserCoupon;
|
|
use App\Model\UserPatient;
|
|
use App\Utils\Mask;
|
|
|
|
/**
|
|
* 患者
|
|
*/
|
|
class UserPatientService extends BaseService
|
|
{
|
|
/**
|
|
* 获取患者个人中心数据
|
|
* @return array
|
|
*/
|
|
public function getPatientCenter(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
// 获取患者信息
|
|
$fields = [
|
|
'patient_id',
|
|
'user_id',
|
|
'user_name',
|
|
'avatar',
|
|
];
|
|
$params = array();
|
|
$params['patient_id'] = $user_info['client_user_id'];
|
|
$user_patient = UserPatient::getOne($params,$fields);
|
|
if (empty($user_patient)){
|
|
return fail(HttpEnumCode::HTTP_ERROR, "非法用户");
|
|
}
|
|
|
|
// 获取福利数据
|
|
$coupon = $this->getPatientAvailableCouponList($user_patient['user_id'],1);
|
|
|
|
// 获取问诊数量-待支付
|
|
$InquiryService = new InquiryService();
|
|
$order_inquiry_count = $InquiryService->getPatientInquiryWithStatus($user_patient['patient_id'],1);
|
|
|
|
// 获取处方数量-未使用
|
|
$OrderPrescriptionService = new OrderPrescriptionService();
|
|
$order_prescription_count = $OrderPrescriptionService->getPatientPrescriptionWithStatus($user_patient['patient_id'],3);
|
|
|
|
// 获取药品数量-待支付
|
|
$OrderProductService = new OrderProductService();
|
|
$order_product_count = $OrderProductService->getPatientProductWithStatus($user_patient['patient_id'],1);
|
|
|
|
// 处理头像
|
|
$user_patient['avatar'] = addAliyunOssWebsite($user_patient['avatar']);
|
|
|
|
$result = array();
|
|
$result['patient_id'] = $user_patient['patient_id'];
|
|
$result['avatar'] = $user_patient['avatar'];
|
|
$result['user_name'] = $user_patient['user_name'];
|
|
$result['coupon'] = empty($coupon);
|
|
$result['order_inquiry_count'] = $order_inquiry_count;
|
|
$result['order_prescription_count'] = $order_prescription_count;
|
|
$result['order_product_count'] = $order_product_count;
|
|
return success($result);
|
|
}
|
|
|
|
/**
|
|
* 获取患者信息
|
|
* @return array
|
|
*/
|
|
public function getPatientCenterInfo(): array
|
|
{
|
|
$user_info = $this->request->getAttribute("userInfo") ?? [];
|
|
|
|
// 获取患者信息
|
|
$fields = [
|
|
'patient_id',
|
|
'user_id',
|
|
'user_name',
|
|
'mobile',
|
|
'avatar',
|
|
];
|
|
$params = array();
|
|
$params['patient_id'] = $user_info['client_user_id'];
|
|
$user_patient = UserPatient::getOne($params,$fields);
|
|
if (empty($user_patient)){
|
|
return fail(HttpEnumCode::HTTP_ERROR, "非法用户");
|
|
}
|
|
|
|
// 手机号
|
|
$user_patient['mobile'] = Mask::maskPhoneStr($user_patient['mobile']);
|
|
|
|
// 头像
|
|
$user_patient['avatar'] = addAliyunOssWebsite($user_patient['avatar']);
|
|
|
|
return success($user_patient->toArray());
|
|
}
|
|
|
|
/**
|
|
* 获取用户可领取优惠卷
|
|
* @param string|int $user_id
|
|
* @param int $coupon_client
|
|
* @return array
|
|
*/
|
|
public function getPatientAvailableCouponList(string|int $user_id,int $coupon_client): array
|
|
{
|
|
// 获取全部优惠卷
|
|
$params = array();
|
|
$params['coupon_client'] = $coupon_client;
|
|
$params['coupon_status'] = 1;
|
|
$params['is_display'] = 1;
|
|
$coupon = Coupon::getList($params);
|
|
if (empty($coupon)){
|
|
return [];
|
|
}
|
|
|
|
// 处理优惠卷
|
|
$result = array();
|
|
foreach ($coupon as $item){
|
|
if ($item['coupon_count'] <= $item['coupon_take_count']){
|
|
// 已发放完毕
|
|
continue;
|
|
}
|
|
|
|
if ($item['valid_type'] == 1){
|
|
// 绝对时效
|
|
$date = date('Y-m-d H:i:s',time());
|
|
if ($item['valid_end_time'] < $date){
|
|
// 超出结束使用时间
|
|
continue;
|
|
}
|
|
}
|
|
|
|
// 检测当前优惠卷是否被用户领取
|
|
$params = array();
|
|
$params['user_id'] = $user_id;
|
|
$params['coupon_id'] = $item['coupon_id'];
|
|
$user_coupon = UserCoupon::getOne($params);
|
|
if (empty($user_coupon)){
|
|
// 未被领取
|
|
$result[] = $item;
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 获取患者未完成订单
|
|
* @param string $patient_id
|
|
* @param string $family_id
|
|
* @return string
|
|
*/
|
|
public function getNotFinishedOrdeInquiry(string $patient_id = '',string $family_id = ''): string
|
|
{
|
|
$params = array();
|
|
if (!empty($patient_id)){
|
|
$params[] = ['patient_id','=',$patient_id];
|
|
}
|
|
|
|
if (!empty($family_id)){
|
|
$params[] = ['family_id','=',$family_id];
|
|
}
|
|
|
|
$params[] = ['inquiry_mode','=',1];
|
|
$params[] = ['inquiry_refund_status','=',0];
|
|
$order_inquiry = OrderInquiry::getOne($params);
|
|
if (!empty($order_inquiry)) {
|
|
// 1:待支付 2:待分配 3:待接诊 4:已接诊
|
|
if (in_array($order_inquiry['inquiry_status'], [2, 3, 4])) {
|
|
return $order_inquiry['order_inquiry_id'];
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
} |