From 31349fc1efc4d0f5bc8c9800485290fc7661f84c Mon Sep 17 00:00:00 2001 From: luofei <604446095@qq.com> Date: Fri, 2 Feb 2024 11:24:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E9=80=80=E6=AC=BE=EF=BC=8C?= =?UTF-8?q?=E4=BE=9B=E5=BA=94=E9=93=BE=E8=AE=A2=E5=8D=95=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../consumption/StoreConsumptionUserDao.php | 2 +- .../dao/store/order/StoreOrderOtherDao.php | 54 +++++++++++++++++++ .../store/order/StoreRefundOrderOther.php | 41 ++++++++++++++ .../store/order/StoreRefundProductOther.php | 30 +++++++++++ .../order/StoreRefundOrderRepository.php | 5 +- 5 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 app/common/model/store/order/StoreRefundOrderOther.php create mode 100644 app/common/model/store/order/StoreRefundProductOther.php diff --git a/app/common/dao/store/consumption/StoreConsumptionUserDao.php b/app/common/dao/store/consumption/StoreConsumptionUserDao.php index e0613192..328f1ab5 100755 --- a/app/common/dao/store/consumption/StoreConsumptionUserDao.php +++ b/app/common/dao/store/consumption/StoreConsumptionUserDao.php @@ -331,8 +331,8 @@ class StoreConsumptionUserDao extends BaseDao $rate = bcdiv($productPrice, $orderTotalPrice, 5); $realPrice = $this->isLast ? bcsub($orderPayPrice, $realPriceTotal, 2) : ceil(bcmul($orderPayPrice, $rate, 5)); $consumptionAmount = $productPrice - $realPrice; - $realPriceTotal += $realPrice; } + $realPriceTotal += $realPrice; $realPrice = bcdiv($realPrice, 100, 2); $consumptionAmount = bcdiv($consumptionAmount, 100, 2); $realPriceTotal = bcdiv($realPriceTotal, 100, 2); diff --git a/app/common/dao/store/order/StoreOrderOtherDao.php b/app/common/dao/store/order/StoreOrderOtherDao.php index def1eb01..a6b47f68 100755 --- a/app/common/dao/store/order/StoreOrderOtherDao.php +++ b/app/common/dao/store/order/StoreOrderOtherDao.php @@ -19,6 +19,9 @@ use app\common\model\store\order\StoreGroupOrderOther; use app\common\model\store\order\StoreOrderOther; use app\common\model\store\order\StoreOrderProductOther; use app\common\model\store\order\StoreOrderStatusOther; +use app\common\model\store\order\StoreRefundOrder; +use app\common\model\store\order\StoreRefundOrderOther; +use app\common\model\store\order\StoreRefundProductOther; use app\common\repositories\store\order\StoreOrderStatusRepository; use app\common\repositories\store\product\ProductAssistSetRepository; use app\common\repositories\store\product\ProductGroupBuyingRepository; @@ -27,6 +30,7 @@ use think\db\BaseQuery; use think\db\exception\DataNotFoundException; use think\db\exception\DbException; use think\db\exception\ModelNotFoundException; +use think\exception\ValidateException; use think\facade\Db; use think\Model; @@ -764,4 +768,54 @@ class StoreOrderOtherDao extends BaseDao }); })->where('StoreOrderOther.uid', $uid)->count(); } + + public function refund($id) + { + $refundOrder = StoreRefundOrder::where('refund_order_id', $id)->with(['refundProduct.product', 'order'])->find(); + $refundProducts = []; + foreach ($refundOrder->refundProduct->toArray() as $item) { + $refundProducts[$item['product']['product_id']] = ['num' => $item['refund_num']]; + } + $order = StoreOrderOther::where('order_sn', $refundOrder->order['order_sn'])->find(); + $refundOrderArray = $refundOrder->toArray(); + unset($refundOrderArray['return_order_id']); + Db::startTrans(); + try { + $model = new StoreRefundOrderOther(); + $model->setAttrs($refundOrderArray); + $model->order_sn = $refundOrderArray['refund_order_sn']; + $model->order_id = $order['order_id']; + $model->uid = $order['uid']; + $model->mer_id = $order['mer_id']; + $model->save(); + $products = []; + $orderProducts = StoreOrderProductOther::where('order_id', $order['order_id'])->select(); + foreach ($orderProducts as $orderProduct) { + $refundProduct = $refundProducts[$orderProduct['product_id']] ?? []; + if (!empty($refundProduct)) { + $products[] = [ + 'refund_order_id' => $model->refund_order_id, + 'order_product_id' => $orderProduct['order_product_id'], + 'refund_price' => $orderProduct['total_price'], + 'refund_consumption' => 0, + 'platform_refund_price' => 0, + 'refund_postage' => 0, + 'refund_integral' => 0, + 'refund_num' => $refundProduct['num'], + ]; + $orderProduct->refund_num -= $refundProduct['num']; + $orderProduct->is_refund = 1; + $orderProduct->save(); + } + } + if (count($products) > 0) { + StoreRefundProductOther::getDB()->insertAll($products); + } + Db::commit(); + } catch (\Exception $e) { + Db::rollback(); + throw new ValidateException($e->getMessage()); + } + } + } diff --git a/app/common/model/store/order/StoreRefundOrderOther.php b/app/common/model/store/order/StoreRefundOrderOther.php new file mode 100644 index 00000000..23e94330 --- /dev/null +++ b/app/common/model/store/order/StoreRefundOrderOther.php @@ -0,0 +1,41 @@ +hasMany(StoreRefundProductOther::class, 'refund_order_id', 'refund_order_id'); + } + + public function merchant() + { + return $this->hasOne(Merchant::class, 'mer_id', 'mer_id'); + } + + public function user() + { + return $this->hasOne(User::class, 'uid', 'uid'); + } + + public function orders() + { + return $this->hasOne(StoreOrderOther::class, 'order_id', 'order_id'); + } +} diff --git a/app/common/model/store/order/StoreRefundProductOther.php b/app/common/model/store/order/StoreRefundProductOther.php new file mode 100644 index 00000000..4fe8d480 --- /dev/null +++ b/app/common/model/store/order/StoreRefundProductOther.php @@ -0,0 +1,30 @@ +hasOne(StoreOrderProductOther::class,'order_product_id','order_product_id'); + } + + public function refundOrder() + { + return $this->hasOne(StoreRefundOrderOther::class,'refund_order_id','refund_order_id'); + } + +} diff --git a/app/common/repositories/store/order/StoreRefundOrderRepository.php b/app/common/repositories/store/order/StoreRefundOrderRepository.php index 644f952e..af8295c9 100755 --- a/app/common/repositories/store/order/StoreRefundOrderRepository.php +++ b/app/common/repositories/store/order/StoreRefundOrderRepository.php @@ -16,6 +16,7 @@ namespace app\common\repositories\store\order; use app\common\dao\store\consumption\CommissionDao; use app\common\dao\store\consumption\StoreConsumptionUserDao; +use app\common\dao\store\order\StoreOrderOtherDao; use app\common\dao\store\order\StoreRefundOrderDao; use app\common\dao\store\StoreActivityOrderDao; use app\common\model\store\order\StoreGroupOrder; @@ -922,6 +923,7 @@ class StoreRefundOrderRepository extends BaseRepository if ($refund['refund_type'] == 1) { //TODO 退款单同意退款 $refund = $this->doRefundPrice($id, $_refund_price); + (new StoreOrderOtherDao())->refund($id); $data['status'] = 3; $orderStatus['change_message'] = '退款成功'; $orderStatus['change_type'] = $storeOrderStatusRepository::ORDER_STATUS_CREATE; @@ -1382,7 +1384,8 @@ class StoreRefundOrderRepository extends BaseRepository 'number' => $refundRate, ], $res->mer_id); - event('refund.after', compact('id', 'res')); + // 业务流程调整,暂时注释 +// event('refund.after', compact('id', 'res')); return $res; }