From 189dc54d5542890570f4674a3b033759f2543cb1 Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Wed, 12 Apr 2023 13:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=94=A8=E6=88=B7=E6=94=B6?= =?UTF-8?q?=E8=B4=A7=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Command/ReportPreProductOrderCommand.php | 65 ++++++++++++++++--- .../getPrescriptionOrderStatusCommand.php | 5 +- app/Request/UserRequest.php | 2 +- app/Services/OrderProductService.php | 6 +- app/Services/UserService.php | 2 +- 5 files changed, 64 insertions(+), 16 deletions(-) diff --git a/app/Command/ReportPreProductOrderCommand.php b/app/Command/ReportPreProductOrderCommand.php index 3876486..eeeceee 100644 --- a/app/Command/ReportPreProductOrderCommand.php +++ b/app/Command/ReportPreProductOrderCommand.php @@ -57,45 +57,72 @@ class ReportPreProductOrderCommand extends HyperfCommand } foreach ($order_product_ids as $item){ + $this->line("本次请求订单号:" . $item['order_product_id']); + Db::beginTransaction(); $redis_key = "ReportPreProductOrder" . $item['order_product_id']; + // 处理超出最大执行次数/退款问题 try { $redis_value = $redis->get($redis_key); + $redis->incr($redis_key); if(!empty($redis_value)){ - // 超出最大执行次数 - if ($redis_value > 2){ + if ($redis_value >= 2){ // 存储上报失败 - $this->savaReportFail($item['order_product_id']); + $this->savaReportFail($item['order_product_id'],"超出最大上报次数"); + + // 修改失败时药品订单数据 + $this->savePreFailedOrderStatus($item['order_product_id'],"复核失败"); // 退款 + $this->line("超出最大执行次数,执行退款"); $OrderProductService = new OrderProductService(); $OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款"); + + // 清空缓存 + $redis->del($redis_key); + + Db::commit(); + continue; } } + Db::commit(); + } catch (\Exception $e) { + Db::rollBack(); + // 记录失败次数 + $this->line("商品订单上报处方平台失败:失败原因" . $e->getMessage()); + } + + // 处理上报处方平台问题 + try { // 上报处方平台 $orderPrescriptionService = new OrderPrescriptionService(); - $orderPrescriptionService->reportPrescription($item['order_product_id']); + $res = $orderPrescriptionService->reportPrescription($item['order_product_id']); + if (!$res){ + // 上报失败 + $this->line("上报失败"); + continue; + } // 存储上报成功 $this->savaReportSuccess($item['order_product_id']); - // 清空缓存 - $redis->del($redis_key); - Db::commit(); } catch (\Exception $e) { Db::rollBack(); // 记录失败次数 $redis->incr($redis_key); - $this->line("商品订单上报处方平台失败:商品单号" . $item['order_product_id'] . " 失败原因:" . $e->getMessage()); - $this->savaReportFail($item['order_product_id'],$e->getMessage()); + $this->line("商品订单上报处方平台失败:失败原因" . $e->getMessage()); } - $this->line("商品订单上报处方平台成功:商品单号" . $item['order_product_id']); + // 清空缓存 + $redis->del($redis_key); + + $this->line("商品订单上报处方平台成功"); } + $this->line("商品订单上报处方平台全部结束"); } /** @@ -157,4 +184,22 @@ class ReportPreProductOrderCommand extends HyperfCommand $data['report_pre_fail_reason'] = ""; // 上报失败原因 置为空 OrderProduct::edit($params,$data); } + + /** + * 修改失败时药品订单数据 + * @param string $order_product_id + * @param string $cancel_remarks + */ + protected function savePreFailedOrderStatus(string $order_product_id,string $cancel_remarks) + { + // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消) + $params = array(); + $params['order_product_id'] = $order_product_id; + + $data['order_product_status'] = 5; + $data['cancel_reason'] = 2; // 订单取消原因(1:主动取消 2:复核失败/库存不足 3:支付超时 4:客服取消) + $data['cancel_time'] = date('Y-m-d H:i:s'); // 订单取消时间 + $data['cancel_remarks'] = $cancel_remarks; // 订单取消备注(自动添加) + OrderProduct::edit($params,$data); + } } diff --git a/app/Command/getPrescriptionOrderStatusCommand.php b/app/Command/getPrescriptionOrderStatusCommand.php index 225c81e..b485537 100644 --- a/app/Command/getPrescriptionOrderStatusCommand.php +++ b/app/Command/getPrescriptionOrderStatusCommand.php @@ -45,8 +45,11 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand $this->line("获取处方平台订单数据结束,无可执行的商品订单"); return; } - +// dump($order_product_ids);die; foreach ($order_product_ids as $item) { + if ($item['order_product_id'] != "504371738743726081"){ + continue; + } Db::beginTransaction(); $this->line("本次请求订单号:" . $item['order_product_id']); diff --git a/app/Request/UserRequest.php b/app/Request/UserRequest.php index bb8aeeb..b8cd5c9 100644 --- a/app/Request/UserRequest.php +++ b/app/Request/UserRequest.php @@ -64,7 +64,7 @@ class UserRequest extends FormRequest 'consignee_name' => 'required', 'consignee_tel' => 'required', 'is_default' => ['required','numeric','min:0','max:1'], -// 'tag' => ['sometimes','required','numeric','min:1','max:4'], + 'tag' => ['sometimes','required','numeric','min:1','max:4'], ]; } diff --git a/app/Services/OrderProductService.php b/app/Services/OrderProductService.php index 9fee55c..1514d8c 100644 --- a/app/Services/OrderProductService.php +++ b/app/Services/OrderProductService.php @@ -207,17 +207,17 @@ class OrderProductService extends BaseService } // 检测商品订单退款状态 - if ($order_product['order_product_status'] == 2){ + if ($order_product['refund_status'] == 2){ // 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) throw new BusinessException("订单退款中"); } - if ($order_product['order_product_status'] == 3){ + if ($order_product['refund_status'] == 3){ // 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) throw new BusinessException("订单已退款成功"); } - if ($order_product['order_product_status'] == 5){ + if ($order_product['refund_status'] == 5){ // 商品订单退款状态(0:无退款 1:申请退款 2:退款中 3:退款成功 4:拒绝退款 5:退款关闭 6:退款异常) throw new BusinessException("订单退款关闭"); } diff --git a/app/Services/UserService.php b/app/Services/UserService.php index 0a76118..f8a5840 100644 --- a/app/Services/UserService.php +++ b/app/Services/UserService.php @@ -367,7 +367,7 @@ class UserService extends BaseService $data['consignee_tel'] = $request_params['consignee_tel']; $data['consignee_tel_mask'] = Mask::maskPhoneStr($request_params['consignee_tel']); $data['is_default'] = $request_params['is_default']; - $data['tag'] = $request_params['tag'] ?? ""; + $data['tag'] = $request_params['tag'] ?? 4; $user_ship_address = UserShipAddress::addUserShipAddress($data); if (empty($user_ship_address)) { Db::rollBack();