新增患者个人中心-详情接口
This commit is contained in:
@@ -3,13 +3,149 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user