From ffeda6b0d8c8bc51df67b1af76cfc27e7674ef31 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 8 Apr 2024 20:38:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=A2=E5=8D=95=20=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Command/MoveOrderCommand.php | 586 +++++++++++++++++++++++++++++++ app/Common/Common.php | 21 +- 2 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 app/Command/MoveOrderCommand.php diff --git a/app/Command/MoveOrderCommand.php b/app/Command/MoveOrderCommand.php new file mode 100644 index 0000000..6bddb37 --- /dev/null +++ b/app/Command/MoveOrderCommand.php @@ -0,0 +1,586 @@ +setDescription('迁移历史订单'); + } + + public function handle() + { + $this->line("开始"); + + // 处理问诊订单 +// $this->handleOrderInquiry(); + + // 处理问诊订单退款 +// $this->handleOrderInquiryRefund(); + + // 处理问诊订单优惠卷 +// $this->handleOrderInquiryCoupon(); + + // 处理药品订单 +// $this->handleOrderProduct(); + + // 处理药品订单退款 +// $this->handleOrderProductRefund(); + + // 处理药品订单优惠卷 +// $this->handleOrderProductCoupon(); + + // 处理检测订单 +// $this->handleOrderDetection(); + + // 处理检测订单退款 +// $this->handleOrderDetectionRefund(); + } + + /** + * 处理问诊订单 + * @return void + */ + public function handleOrderInquiry(): void + { + $params = array(); + $order_inquirys = OrderInquiry::getList($params); + if (empty($order_inquirys)){ + $this->line("无问诊订单需要执行"); + return; + } + + foreach ($order_inquirys as $order_inquiry){ + if (!empty($order_inquiry['order_id'])){ + // 已存在订单id,跳过 + continue; + } + + $params = array(); + $params['order_no'] = $order_inquiry['inquiry_no']; + $order = Order::getOne($params); + if (!empty($order)){ + // 已存在订单,跳过 + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['user_id'] = $order_inquiry['user_id']; + $data['patient_id'] = $order_inquiry['patient_id']; + if (!empty($order_inquiry['doctor_id'])){ + $data['doctor_id'] = $order_inquiry['doctor_id']; + } + $data['order_type'] = 1; + $data['is_delete'] = $order_inquiry['is_delete']; // 删除状态(0:否 1:是) + $data['pay_channel'] = $order_inquiry['inquiry_pay_channel']; + $data['pay_status'] = $order_inquiry['inquiry_pay_status']; + $data['pay_time'] = $order_inquiry['pay_time']; + $data['refund_status'] = $order_inquiry['inquiry_refund_status']; + $data['order_no'] = $order_inquiry['inquiry_no']; + $data['escrow_trade_no'] = $order_inquiry['escrow_trade_no']; + $data['amount_total'] = $order_inquiry['amount_total']; + $data['coupon_amount_total'] = $order_inquiry['coupon_amount_total']; + $data['payment_amount_total'] = $order_inquiry['payment_amount_total']; + if ($order_inquiry['inquiry_status'] == 7){ + $data['cancel_status'] = 1; + } + $data['cancel_time'] = $order_inquiry['cancel_time']; + if (!empty($order_inquiry['cancel_reason'])){ + $data['cancel_remarks'] = inquiryCancelReasonToString($order_inquiry['cancel_reason']); + } + $order = Order::addOrder($data); + if (empty($order)) { + Db::rollBack(); + $this->line("添加问诊订单失败"); + } + + // 修改问诊订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + + $params = array(); + $params['inquiry_no'] = $order['order_no']; + OrderInquiry::edit($params,$data); + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理问诊订单退款 + * @return void + */ + public function handleOrderInquiryRefund(): void + { + $params = array(); + $order_inquiry_refunds = OrderInquiryRefund::getList($params); + if (empty($order_inquiry_refunds)){ + $this->line("无问诊退款订单需要执行"); + return; + } + + foreach ($order_inquiry_refunds as $order_inquiry_refund){ + $params = array(); + $params['order_no'] = $order_inquiry_refund['inquiry_no']; + $order_refund = OrderRefund::getOne($params); + if (!empty($order_refund)){ + // 已存在订单,跳过 + continue; + } + + // 获取订单数据 + $params = array(); + $params['order_no'] = $order_inquiry_refund['inquiry_no']; + $order = Order::getOne($params); + if (empty($order)){ + // 已存在订单,跳过 + $this->line("无对应订单数据"); + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + $data['patient_id'] = $order_inquiry_refund['patient_id']; + $data['order_no'] = $order['order_no']; + $data['refund_no'] = $order_inquiry_refund['inquiry_refund_no']; + $data['refund_id'] = $order_inquiry_refund['refund_id']; + $data['refund_status'] = $order_inquiry_refund['inquiry_refund_status']; + $data['refund_total'] = $order_inquiry_refund['refund_total']; + $data['refund_reason'] = $order_inquiry_refund['refund_reason']; + $data['success_time'] = $order_inquiry_refund['success_time']; + $order_refund = OrderRefund::addOrderRefund($data); + if (empty($order_refund)) { + Db::rollBack(); + $this->line("添加问诊退款订单失败"); + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理问诊订单优惠卷 + * @return void + */ + public function handleOrderInquiryCoupon(): void + { + $params = array(); + $order_inquiry_coupons = OrderInquiryCoupon::getList($params); + if (empty($order_inquiry_coupons)){ + $this->line("无问诊订单优惠卷需要执行"); + return; + } + + foreach ($order_inquiry_coupons as $order_inquiry_coupon){ + // 获取问诊订单详情 + $params = array(); + $params['order_inquiry_id'] = $order_inquiry_coupon['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)){ + $this->line("问诊订单数据错误"); + continue; + } + + // 获取订单数据 + $params = array(); + $params['order_no'] = $order_inquiry['inquiry_no']; + $order = Order::getOne($params); + if (empty($order)){ + $this->line("无对应订单数据"); + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + $data['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id']; + $data['coupon_name'] = $order_inquiry_coupon['coupon_name']; + $data['coupon_use_price'] = $order_inquiry_coupon['coupon_use_price']; + $order_coupon = OrderCoupon::addOrderCoupon($data); + if (empty($order_coupon)) { + Db::rollBack(); + $this->line("添加问诊订单优惠卷失败"); + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理药品订单 + * @return void + */ + public function handleOrderProduct(): void + { + $params = array(); + $order_products = OrderProduct::getList($params); + if (empty($order_products)){ + $this->line("无药品订单需要执行"); + return; + } + + foreach ($order_products as $order_product){ + if (!empty($order_product['order_id'])){ + // 已存在订单id,跳过 + continue; + } + + $params = array(); + $params['order_no'] = $order_product['order_product_no']; + $order = Order::getOne($params); + if (!empty($order)){ + // 已存在订单,跳过 + continue; + } + + // 获取问诊订单数据 + $params = array(); + $params['order_inquiry_id'] = $order_product['order_inquiry_id']; + $order_inquiry = OrderInquiry::getOne($params); + if (empty($order_inquiry)){ + $this->line("无问诊订单数据"); + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['user_id'] = $order_inquiry['user_id']; + $data['patient_id'] = $order_product['patient_id']; + $data['doctor_id'] = $order_product['doctor_id']; + $data['order_type'] = 2; + $data['is_delete'] = $order_product['is_delete']; // 删除状态(0:否 1:是) + $data['pay_channel'] = $order_product['pay_channel']; + $data['pay_status'] = $order_product['pay_status']; + $data['pay_time'] = $order_product['pay_time']; + $data['refund_status'] = $order_product['refund_status']; + $data['order_no'] = $order_product['order_product_no']; + $data['escrow_trade_no'] = $order_product['escrow_trade_no']; + $data['amount_total'] = $order_product['amount_total']; + $data['coupon_amount_total'] = $order_product['coupon_amount_total']; + $data['payment_amount_total'] = $order_product['payment_amount_total']; + if ($order_inquiry['order_product_status'] == 5){ + $data['cancel_status'] = 1; + } + $data['cancel_time'] = $order_product['cancel_time']; + $data['cancel_remarks'] = $order_product['cancel_remarks']; + $order = Order::addOrder($data); + if (empty($order)) { + Db::rollBack(); + $this->line("添加药品订单失败"); + } + + // 修改药品订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + + $params = array(); + $params['order_product_no'] = $order['order_no']; + OrderProduct::edit($params,$data); + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理药品订单退款 + * @return void + */ + public function handleOrderProductRefund(): void + { + $params = array(); + $order_product_refunds = OrderProductRefund::getList($params); + if (empty($order_product_refunds)){ + $this->line("无问诊退款订单需要执行"); + return; + } + + foreach ($order_product_refunds as $order_product_refund){ + $params = array(); + $params['order_no'] = $order_product_refund['order_product_no']; + $order_refund = OrderRefund::getOne($params); + if (!empty($order_refund)){ + // 已存在订单,跳过 + continue; + } + + // 获取订单数据 + $params = array(); + $params['order_no'] = $order_product_refund['order_product_no']; + $order = Order::getOne($params); + if (empty($order)){ + // 已存在订单,跳过 + $this->line("无对应订单数据"); + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + $data['patient_id'] = $order_product_refund['patient_id']; + $data['order_no'] = $order['order_no']; + $data['refund_no'] = $order_product_refund['order_product_no']; + $data['refund_id'] = $order_product_refund['refund_id']; + $data['refund_status'] = $order_product_refund['product_refund_status']; + $data['refund_total'] = $order_product_refund['refund_total']; + $data['refund_reason'] = $order_product_refund['refund_reason']; + $data['success_time'] = $order_product_refund['success_time']; + $order_refund = OrderRefund::addOrderRefund($data); + if (empty($order_refund)) { + Db::rollBack(); + $this->line("添加药品退款订单失败"); + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理药品订单优惠卷 + * @return void + */ + public function handleOrderProductCoupon(): void + { + $params = array(); + $order_product_coupons = OrderProductCoupon::getList($params); + if (empty($order_product_coupons)){ + $this->line("无药品订单优惠卷需要执行"); + return; + } + + foreach ($order_product_coupons as $order_product_coupon){ + // 获取问诊订单详情 + $params = array(); + $params['order_product_id'] = $order_product_coupon['order_product_id']; + $order_product = OrderProduct::getOne($params); + if (empty($order_product)){ + $this->line("药品订单数据错误"); + continue; + } + + // 获取订单数据 + $params = array(); + $params['order_no'] = $order_product['order_product_no']; + $order = Order::getOne($params); + if (empty($order)){ + $this->line("无对应订单数据"); + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + $data['user_coupon_id'] = $order_product_coupon['user_coupon_id']; + $data['coupon_name'] = $order_product_coupon['coupon_name']; + $data['coupon_use_price'] = $order_product_coupon['coupon_use_price']; + $order_coupon = OrderCoupon::addOrderCoupon($data); + if (empty($order_coupon)) { + Db::rollBack(); + $this->line("添加问诊订单优惠卷失败"); + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理检测订单 + * @return void + */ + public function handleOrderDetection(): void + { + $params = array(); + $order_detections = OrderDetection::getList($params); + if (empty($order_detections)){ + $this->line("无检测订单需要执行"); + return; + } + + foreach ($order_detections as $order_detection){ + if (!empty($order_detection['order_id'])){ + // 已存在订单id,跳过 + continue; + } + + $params = array(); + $params['order_no'] = $order_detection['detection_no']; + $order = Order::getOne($params); + if (!empty($order)){ + // 已存在订单,跳过 + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['user_id'] = $order_detection['user_id']; + $data['patient_id'] = $order_detection['patient_id']; + $data['doctor_id'] = $order_detection['doctor_id']; + $data['order_type'] = 3; + $data['is_delete'] = $order_detection['is_delete']; // 删除状态(0:否 1:是) + $data['pay_channel'] = $order_detection['detection_pay_channel']; + $data['pay_status'] = $order_detection['detection_pay_status']; + $data['pay_time'] = $order_detection['pay_time']; + $data['refund_status'] = $order_detection['detection_refund_status']; + $data['order_no'] = $order_detection['detection_no']; + $data['escrow_trade_no'] = $order_detection['escrow_trade_no']; + $data['amount_total'] = $order_detection['amount_total']; + $data['coupon_amount_total'] = $order_detection['coupon_amount_total']; + $data['payment_amount_total'] = $order_detection['payment_amount_total']; + if ($order_detection['detection_status'] == 5){ + $data['cancel_status'] = 1; + } + $data['cancel_time'] = $order_detection['cancel_time']; + if (!empty($order_detection['cancel_reason'])){ + $data['cancel_remarks'] = detectionCancelReasonToString($order_detection['cancel_reason']); + } + + $order = Order::addOrder($data); + if (empty($order)) { + Db::rollBack(); + $this->line("添加检测订单失败"); + } + + // 修改检测订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + + $params = array(); + $params['detection_no'] = $order['order_no']; + OrderDetection::editOrderDetection($params,$data); + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + + /** + * 处理检测订单退款 + * @return void + */ + public function handleOrderDetectionRefund(): void + { + $params = array(); + $order_detection_refunds = OrderDetectionRefund::getList($params); + if (empty($order_detection_refunds)){ + $this->line("无检测退款订单需要执行"); + return; + } + + foreach ($order_detection_refunds as $order_detection_refund){ + $params = array(); + $params['order_no'] = $order_detection_refund['detection_no']; + $order_refund = OrderRefund::getOne($params); + if (!empty($order_refund)){ + // 已存在订单,跳过 + continue; + } + + // 获取订单数据 + $params = array(); + $params['order_no'] = $order_detection_refund['detection_no']; + $order = Order::getOne($params); + if (empty($order)){ + // 已存在订单,跳过 + $this->line("无对应订单数据"); + continue; + } + + Db::beginTransaction(); + try { + // 生成订单表 + $data = array(); + $data['order_id'] = $order['order_id']; + $data['patient_id'] = $order_detection_refund['patient_id']; + $data['order_no'] = $order['order_no']; + $data['refund_no'] = $order_detection_refund['detection_refund_no']; + $data['refund_id'] = $order_detection_refund['refund_id']; + $data['refund_status'] = $order_detection_refund['detection_refund_status']; + $data['refund_total'] = $order_detection_refund['refund_total']; + $data['refund_reason'] = $order_detection_refund['refund_reason']; + $data['success_time'] = $order_detection_refund['success_time']; + $order_refund = OrderRefund::addOrderRefund($data); + if (empty($order_refund)) { + Db::rollBack(); + $this->line("添加检测退款订单失败"); + } + + Db::commit(); + }catch (\Throwable $e){ + Db::rollBack(); + $this->line($e->getMessage()); + } + } + } + +} diff --git a/app/Common/Common.php b/app/Common/Common.php index 2340160..8e29ab4 100644 --- a/app/Common/Common.php +++ b/app/Common/Common.php @@ -196,7 +196,7 @@ function inquiryCancelReasonToString(int|string $cancel_reason): string } elseif ($cancel_reason == 5) { $result = "支付超时"; } else { - $result = "未知"; + $result = NULL; } return $result; } @@ -245,6 +245,25 @@ function productCancelReasonToString(int|string $cancel_reason): string return $result; } +/** + * 转换检测订单取消原因-字符串 + * @param int|string $cancel_reason 取消订单原因(1:主动取消 2:客服取消 3:支付超时) + * @return string + */ +function detectionCancelReasonToString(int|string $cancel_reason): string +{ + if ($cancel_reason == 1) { + $result = "主动取消"; + } elseif ($cancel_reason == 2) { + $result = "客服取消"; + } elseif ($cancel_reason == 3) { + $result = "支付超时"; + } else { + $result = ""; + } + return $result; +} + /** * 转换性别至字符串 * @param string|int $sex