From 76cbcff76ad61e192ffd8af8273a69a53fb9b70b Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Fri, 3 Mar 2023 21:03:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=82=A3=E8=80=85=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E4=B8=AD=E5=BF=83-=E8=AF=A6=E6=83=85=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/UserPatientController.php | 21 ++++ app/Model/Coupon.php | 4 +- app/Model/OrderPrescription.php | 13 ++- app/Model/OrderProduct.php | 13 ++- app/Services/BasicDataService.php | 1 + app/Services/InquiryService.php | 14 +++ app/Services/OrderPrescriptionService.php | 15 +++ app/Services/OrderProductService.php | 22 ++++ app/Services/UserDoctorService.php | 1 + app/Services/UserPatientService.php | 136 ++++++++++++++++++++++ config/routes.php | 10 ++ 11 files changed, 246 insertions(+), 4 deletions(-) create mode 100644 app/Services/OrderProductService.php diff --git a/app/Controller/UserPatientController.php b/app/Controller/UserPatientController.php index 52b74c7..0b955a7 100644 --- a/app/Controller/UserPatientController.php +++ b/app/Controller/UserPatientController.php @@ -3,6 +3,7 @@ namespace App\Controller; use App\Request\UserPatientRequest; +use App\Services\UserPatientService; use Psr\Container\ContainerExceptionInterface; use Psr\Container\NotFoundExceptionInterface; use Psr\Http\Message\ResponseInterface; @@ -12,5 +13,25 @@ use Psr\Http\Message\ResponseInterface; */ class UserPatientController extends AbstractController { + /** + * 获取患者个人中心数据 + * @return ResponseInterface + */ + public function getPatientCenter(): ResponseInterface + { + $UserPatientService = new UserPatientService(); + $data = $UserPatientService->getPatientCenter(); + return $this->response->json($data); + } + /** + * 获取患者信息 + * @return ResponseInterface + */ + public function getPatientCenterInfo(): ResponseInterface + { + $UserPatientService = new UserPatientService(); + $data = $UserPatientService->getPatientCenterInfo(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Model/Coupon.php b/app/Model/Coupon.php index aabf2b2..717bb83 100644 --- a/app/Model/Coupon.php +++ b/app/Model/Coupon.php @@ -43,12 +43,12 @@ class Coupon extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['coupon_id', 'coupon_name', 'coupon_icon', 'coupon_client', 'coupon_type', 'coupon_status', 'distribution_object', 'application_scope', 'is_display', 'distribution_with_day', 'coupon_count', 'coupon_take_count', 'coupon_ used_count', 'coupon_price', 'with_amount', 'valid_type', 'valid_days', 'valid_start_time', 'valid_end_time', 'created_at', 'updated_at']; + protected array $fillable = ['coupon_id', 'coupon_name', 'coupon_icon', 'coupon_client', 'coupon_type', 'coupon_status', 'distribution_object', 'application_scope', 'is_display', 'distribution_with_day', 'coupon_count', 'coupon_take_count', 'coupon_used_count', 'coupon_price', 'with_amount', 'valid_type', 'valid_days', 'valid_start_time', 'valid_end_time', 'created_at', 'updated_at']; /** * The attributes that should be cast to native types. */ - protected array $casts = ['coupon_id' => 'string', 'coupon_client' => 'integer', 'coupon_type' => 'integer', 'coupon_status' => 'integer', 'distribution_object' => 'integer', 'application_scope' => 'integer', 'is_display' => 'integer', 'distribution_with_day' => 'integer', 'coupon_count' => 'integer', 'coupon_take_count' => 'integer', 'coupon_ used_count' => 'integer', 'valid_type' => 'integer', 'valid_days' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; + protected array $casts = ['coupon_id' => 'string', 'coupon_client' => 'integer', 'coupon_type' => 'integer', 'coupon_status' => 'integer', 'distribution_object' => 'integer', 'application_scope' => 'integer', 'is_display' => 'integer', 'distribution_with_day' => 'integer', 'coupon_count' => 'integer', 'coupon_take_count' => 'integer', 'coupon_used_count' => 'integer', 'valid_type' => 'integer', 'valid_days' => 'integer', 'created_at' => 'datetime', 'updated_at' => 'datetime']; protected string $primaryKey = "coupon_id"; diff --git a/app/Model/OrderPrescription.php b/app/Model/OrderPrescription.php index 1e26870..fa8dba6 100644 --- a/app/Model/OrderPrescription.php +++ b/app/Model/OrderPrescription.php @@ -16,6 +16,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $order_prescription_id 主键id * @property int $order_inquiry_id 订单-问诊id * @property int $doctor_id 医生id + * @property int $patient_id 患者id * @property int $pharmacist_id 药师id * @property int $prescription_status 处方状态(1:待审核 3:待使用 4:已失效 5:已使用) * @property int $pharmacist_audit_status 药师审核状态(0:审核中 1:审核成功 2:审核驳回) @@ -46,7 +47,7 @@ class OrderPrescription extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_reason', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'prescription_img', 'doctor_advice', 'created_at', 'updated_at']; + protected array $fillable = ['order_prescription_id', 'order_inquiry_id', 'doctor_id', 'patient_id', 'pharmacist_id', 'prescription_status', 'pharmacist_audit_status', 'pharmacist_fail_reason', 'platform_audit_status', 'platform_fail_reason', 'is_delete', 'prescription_code', 'doctor_name', 'patient_name', 'patient_sex', 'patient_age', 'prescription_img', 'doctor_advice', 'created_at', 'updated_at']; protected string $primaryKey = "order_prescription_id"; @@ -157,4 +158,14 @@ class OrderPrescription extends Model return self::create($data); } + /** + * 获取数量 + * @param array $params + * @return int + */ + public static function getCount(array $params): int + { + return self::where($params)->count(); + } + } diff --git a/app/Model/OrderProduct.php b/app/Model/OrderProduct.php index 8b2b5a4..d1f890b 100644 --- a/app/Model/OrderProduct.php +++ b/app/Model/OrderProduct.php @@ -14,6 +14,7 @@ use Hyperf\Snowflake\Concern\Snowflake; * @property int $order_inquiry_id 订单-问诊id * @property int $order_prescription_id 订单-处方id * @property int $doctor_id 医生id + * @property int $patient_id 患者id * @property string $order_product_no 订单编号 * @property string $escrow_trade_no 第三方支付流水号 * @property int $order_product_status 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已完成 6:已取消) @@ -55,7 +56,7 @@ class OrderProduct extends Model /** * The attributes that are mass assignable. */ - protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'cancel_reason', 'amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'pay_time', 'remarks', 'refund_status', 'cancel_remarks', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at']; + protected array $fillable = ['order_product_id', 'order_inquiry_id', 'order_prescription_id', 'doctor_id', 'patient_id', 'order_product_no', 'escrow_trade_no', 'order_product_status', 'pay_channel', 'pay_status', 'cancel_reason', 'amount_total', 'payment_amount_total', 'logistics_fee', 'logistics_no', 'pay_time', 'remarks', 'refund_status', 'cancel_remarks', 'province_id', 'province', 'city_id', 'city', 'county_id', 'county', 'address', 'address_mask', 'consignee_name', 'consignee_name_mask', 'consignee_tel', 'consignee_tel_mask', 'created_at', 'updated_at']; protected string $primaryKey = "order_product_id"; @@ -90,4 +91,14 @@ class OrderProduct extends Model { return self::where($params)->exists(); } + + /** + * 获取数量 + * @param array $params + * @return int + */ + public static function getCount(array $params): int + { + return self::where($params)->count(); + } } diff --git a/app/Services/BasicDataService.php b/app/Services/BasicDataService.php index c9c50e2..dc1c65c 100644 --- a/app/Services/BasicDataService.php +++ b/app/Services/BasicDataService.php @@ -203,6 +203,7 @@ class BasicDataService extends BaseService $fields = [ 'product_id', 'product_name', + 'product_price', 'product_cover_img', 'product_spec', 'manufacturer', diff --git a/app/Services/InquiryService.php b/app/Services/InquiryService.php index b37e01c..ef626d1 100644 --- a/app/Services/InquiryService.php +++ b/app/Services/InquiryService.php @@ -435,4 +435,18 @@ class InquiryService extends BaseService return $amount_total_sum ?: 0; } + + /** + * 获取患者某一状态下的问诊订单数量 + * @param string $patient_id 患者id + * @param int $inquiry_status 问诊订单状态(1:待支付 2:待分配 3:待接诊 4:已接诊 5:已完成 6:已结束 7:已取消) + * @return int + */ + public function getPatientInquiryWithStatus(string $patient_id,int $inquiry_status): int + { + $params = array(); + $params['patient_id'] = $patient_id; + $params['inquiry_status'] = $inquiry_status; + return OrderInquiry::getCount($params); + } } \ No newline at end of file diff --git a/app/Services/OrderPrescriptionService.php b/app/Services/OrderPrescriptionService.php index 2e8cd9e..9c51bf7 100644 --- a/app/Services/OrderPrescriptionService.php +++ b/app/Services/OrderPrescriptionService.php @@ -96,4 +96,19 @@ class OrderPrescriptionService extends BaseService return $result; } + + /** + * 获取患者某一状态下的处方数量 + * @param string $patient_id 患者id + * @param int $prescription_status 处方状态(1:待审核 3:待使用 4:已失效 5:已使用) + * @return int + */ + public function getPatientPrescriptionWithStatus(string $patient_id,int $prescription_status): int + { + $params = array(); + $params['patient_id'] = $patient_id; + $params['prescription_status'] = $prescription_status; + $params['pharmacist_audit_status'] = 1; + return OrderPrescription::getCount($params); + } } \ No newline at end of file diff --git a/app/Services/OrderProductService.php b/app/Services/OrderProductService.php new file mode 100644 index 0000000..fa645c7 --- /dev/null +++ b/app/Services/OrderProductService.php @@ -0,0 +1,22 @@ +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 diff --git a/config/routes.php b/config/routes.php index c0b3518..bebbeb8 100644 --- a/config/routes.php +++ b/config/routes.php @@ -174,6 +174,16 @@ Router::addGroup('/patient', function () { // 首页 Router::get('/index', [IndexController::class, 'patientIndex']); + // 个人中心 + Router::addGroup('/center', function () { + // 获取患者个人中心数据 + Router::get('', [UserPatientController::class, 'getPatientCenter']); + + // 获取患者信息 + Router::get('/info', [UserPatientController::class, 'getPatientCenterInfo']); + }); + + // 个人中心-我的医生 Router::addGroup('/my_doctor', function () { // 删除我的医生