diff --git a/app/Controller/PatientOrderController.php b/app/Controller/PatientOrderController.php index ebbfaaf..f0c7403 100644 --- a/app/Controller/PatientOrderController.php +++ b/app/Controller/PatientOrderController.php @@ -184,4 +184,26 @@ class PatientOrderController extends AbstractController $data = $PatientOrderService->getPatientPrescriptionOrderInfo(); return $this->response->json($data); } + + /** + * 获取处方订单支付页详情 + * @return ResponseInterface + */ + public function getPatientPrescriptionOrderPayInfo(): ResponseInterface + { + $PatientOrderService = new PatientOrderService(); + $data = $PatientOrderService->getPatientPrescriptionOrderPayInfo(); + return $this->response->json($data); + } + + /** + * 删除处方订单记录 + * @return ResponseInterface + */ + public function deletePatientPrescriptionOrder(): ResponseInterface + { + $PatientOrderService = new PatientOrderService(); + $data = $PatientOrderService->deletePatientPrescriptionOrder(); + return $this->response->json($data); + } } \ No newline at end of file diff --git a/app/Model/OrderPrescriptionProduct.php b/app/Model/OrderPrescriptionProduct.php index 793c87a..db8fa34 100644 --- a/app/Model/OrderPrescriptionProduct.php +++ b/app/Model/OrderPrescriptionProduct.php @@ -134,4 +134,19 @@ class OrderPrescriptionProduct extends Model { return self::create($data); } + + /** + * 获取信息-单条 + * @param array $params + * @param array $fields + * @return object|null + */ + public static function getWithProductList(array $params, array $fields = ['*']): object|null + { + return self::with([ + 'Product' + ]) + ->where($params)->first($fields); + + } } diff --git a/app/Model/UserShipAddress.php b/app/Model/UserShipAddress.php new file mode 100644 index 0000000..bf8953e --- /dev/null +++ b/app/Model/UserShipAddress.php @@ -0,0 +1,93 @@ +first($fields); + } + + /** + * 获取数据-多 + * @param array $params + * @param array $fields + * @return Collection|array + */ + public static function getList(array $params = [], array $fields = ['*']): Collection|array + { + return self::where($params)->get($fields); + } + + /** + * 获取是否存在 + * @param array $params + * @return bool + */ + public static function getExists(array $params): bool + { + 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/PatientDoctorService.php b/app/Services/PatientDoctorService.php index 94205ff..12f58e7 100644 --- a/app/Services/PatientDoctorService.php +++ b/app/Services/PatientDoctorService.php @@ -253,8 +253,13 @@ class PatientDoctorService extends BaseService $result['doctor_inquiry_config'] = $doctor_inquiry_config; } + // 获取医生已选择专长 + $UserDoctorService = new UserDoctorService(); + $result['doctor_expertise'] = $UserDoctorService->getDoctorSelectedExpertise($user_doctor['doctor_id']); + // 好评率-超过5个已结束的订单后展示 $result['praise_rate'] = ceil($user_doctor['praise_rate'] * 0.05 * 100) / 100; + // 响应时间-超过5个已结束的订单后展示 $result['avg_response_time'] = ceil($user_doctor['avg_response_time'] * 0.05 * 100) / 100 * 60; diff --git a/app/Services/PatientOrderService.php b/app/Services/PatientOrderService.php index 90bc761..c7bd541 100644 --- a/app/Services/PatientOrderService.php +++ b/app/Services/PatientOrderService.php @@ -8,9 +8,11 @@ use App\Model\Hospital; use App\Model\OrderInquiry; use App\Model\OrderInquiryCase; use App\Model\OrderPrescription; +use App\Model\OrderPrescriptionProduct; use App\Model\OrderProduct; use App\Model\OrderProductItem; use App\Model\UserDoctor; +use App\Model\UserShipAddress; use Extend\Wechat\WechatPay; use Hyperf\DbConnection\Db; use Psr\Container\ContainerExceptionInterface; @@ -734,7 +736,12 @@ class PatientOrderService extends BaseService return success($order_prescription); } - public function getPatientPrescriptionOrderInfo(){ + /** + * 获取处方订单详情 + * @return array + */ + public function getPatientPrescriptionOrderInfo(): array + { $user_info = $this->request->getAttribute("userInfo") ?? []; $order_prescription_id = $this->request->route('order_prescription_id'); @@ -743,6 +750,7 @@ class PatientOrderService extends BaseService $fields = [ 'order_prescription_id', 'prescription_status', + 'prescription_img', ]; $params = array(); $params['order_prescription_id'] = $order_prescription_id; @@ -750,6 +758,102 @@ class PatientOrderService extends BaseService $params['pharmacist_audit_status'] = 1; $params['platform_audit_status'] = 1; $params['is_delete'] = 0; - $order_prescription = OrderPrescription::getWithOne($params); + $order_prescription = OrderPrescription::getOne($params,$fields); + if (empty($order_prescription)){ + return fail(); + } + + $order_prescription['prescription_img'] = addAliyunOssWebsite($order_prescription['prescription_img']); + + return success($order_prescription->toArray()); + } + + /** + * 获取处方订单支付页详情 + * 我这边一直到6-7月份才能走得开。目前这几个月项目都正在开发中,没办法离开,也不好。 + * @return array + */ + public function getPatientPrescriptionOrderPayInfo(): array + { + $user_info = $this->request->getAttribute("userInfo") ?? []; + + $order_prescription_id = $this->request->route('order_prescription_id'); + + $fields = [ + "order_prescription_id" + ]; + + $params = array(); + $params['order_prescription_id'] = $order_prescription_id; + $params['patient_id'] = $user_info['client_user_id']; + $params['is_delete'] = 0; + $order_prescription = OrderPrescription::getOne($params,$fields); + if (empty($order_prescription)){ + return fail(); + } + + // 验证处方状态 + if ($order_prescription['prescription_status'] == 1){ + return fail(HttpEnumCode::HTTP_ERROR,"处方未审核"); + } + + if ($order_prescription['prescription_status'] == 3){ + return fail(HttpEnumCode::HTTP_ERROR,"处方已失效"); + } + + if ($order_prescription['prescription_status'] == 4){ + return fail(HttpEnumCode::HTTP_ERROR,"处方已使用"); + } + + // 获取处方药品信息 + $params = array(); + $params['order_prescription_id'] = $order_prescription['order_prescription_id']; + $order_prescription_product = OrderPrescriptionProduct::getWithProductList($params); + if (empty($order_prescription_product)){ + return fail(HttpEnumCode::SERVER_ERROR); + } + + $amount_total = 0; + $coupon_amount_total = 0; + $logistics_fee = 0; // 运费金额 + foreach ($order_prescription_product as $item){ + if (!empty($item['Product']['product_price'])){ + $amount_total += $item['Product']['product_price']; + } + } + + // 获取运费金额 + + // 实际支付金额 + $payment_amount_total = $amount_total + $logistics_fee; + + // 获取收货地址 + $params = array(); + $params['user_id'] = $user_info['user_id']; + $user_ship_addresss = UserShipAddress::getList($params); + + foreach ($user_ship_addresss as $item){ + if ($item['is_default'] == 1){ + $user_ship_address = $item; + } + } + + // 无默认地址,选择第一个 + if (empty($user_ship_address)){ + $user_ship_address = $user_ship_addresss[0] ?? []; + } + + $result = array(); + $result['amount_total'] = $amount_total; + $result['coupon_amount_total'] = $coupon_amount_total; + $result['payment_amount_total'] = $payment_amount_total; + $result['logistics_fee'] = $logistics_fee; + $result['user_ship_address'] = $user_ship_address; + + return success($result); + } + + public function deletePatientPrescriptionOrder(){ + } } \ No newline at end of file diff --git a/config/routes.php b/config/routes.php index 9029418..160603b 100644 --- a/config/routes.php +++ b/config/routes.php @@ -320,11 +320,11 @@ Router::addGroup('/patient', function () { // 获取处方订单详情 Router::get('/{order_prescription_id:\d+}', [PatientOrderController::class, 'getPatientPrescriptionOrderInfo']); - // 获取处方订单支付页详情-处方管理 - Router::post('/16', [PatientOrderController::class, 'imCallBack']); + // 获取处方订单支付页详情 + Router::get('/pay/{order_prescription_id:\d+}', [PatientOrderController::class, 'getPatientPrescriptionOrderPayInfo']); - // 删除处方订单记录-处方管理 - Router::post('/18', [PatientOrderController::class, 'imCallBack']); + // 删除处方订单记录 + Router::delete('/{order_prescription_id:\d+}', [PatientOrderController::class, 'deletePatientPrescriptionOrder']); }); // 获取患者订单支付数据