From f1e807ab299a11d990b8d1a430304927171aa366 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Mon, 24 Jun 2024 10:41:18 +0800 Subject: [PATCH] =?UTF-8?q?=E7=8E=B0=E9=87=91=E9=80=80=E6=AC=BE=E7=9B=B8?= =?UTF-8?q?=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store_order/StoreOrderController.php | 7 +- app/common/logic/PayNotifyLogic.php | 72 ++++++++++++++++++- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/app/admin/controller/store_order/StoreOrderController.php b/app/admin/controller/store_order/StoreOrderController.php index 3fea23aac..47e6d6ff9 100644 --- a/app/admin/controller/store_order/StoreOrderController.php +++ b/app/admin/controller/store_order/StoreOrderController.php @@ -116,7 +116,7 @@ class StoreOrderController extends BaseAdminController if(empty($detail)){ return $this->fail('无该订单请检查'); } - +// d($detail); //微信支付 if(in_array($detail['pay_type'],[PayEnum::WECHAT_PAY_MINI,PayEnum::WECHAT_PAY_BARCODE])){ $money = (int)bcmul($detail['pay_price'],100); @@ -144,6 +144,11 @@ class StoreOrderController extends BaseAdminController return $this->success(); } + //现金支付 + if($detail['pay_type'] = PayEnum::CASH_PAY){ + PayNotifyLogic::cash_refund($params['order_id']); + return $this->success(); + } //支付包支付 return $this->fail('退款失败'); diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index 086d2d840..892b39853 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -6,10 +6,12 @@ use app\api\logic\order\OrderLogic; use app\common\enum\OrderEnum; use app\common\enum\PayEnum; use app\common\enum\user\UserShipEnum; +use app\common\enum\YesNoEnum; use app\common\model\dict\DictType; use app\common\model\finance\PayNotifyLog; use app\common\model\pay\PayNotify; use app\common\model\store_branch_product\StoreBranchProduct; +use app\common\model\store_cash_finance_flow\StoreCashFinanceFlow; use app\common\model\store_finance_flow\StoreFinanceFlow; use app\common\model\store_order\StoreOrder; use app\common\model\store_order_cart_info\StoreOrderCartInfo; @@ -266,13 +268,14 @@ class PayNotifyLogic extends BaseLogic $order->save(); //加用户余额,采购款, 日志记录 加数量 if (in_array($order['pay_type'],[PayEnum::BALANCE_PAY,PayEnum::PURCHASE_FUNDS])){ + $deal_money = bcdiv($extra['amount']['refund'], 100, 2); $user = User::where('id', $order['uid'])->findOrEmpty(); if($order['pay_type'] == PayEnum::BALANCE_PAY){ - $user->now_money = bcadd($user->now_money, $extra['amount']['refund'], 2); + $user->now_money = bcadd($user->now_money, $deal_money, 2); $user->save(); } if($order['pay_type'] == PayEnum::PURCHASE_FUNDS){ - $user->purchase_funds = bcadd($user->purchase_funds, $extra['amount']['refund'], 2); + $user->purchase_funds = bcadd($user->purchase_funds, $deal_money, 2); $user->save(); } @@ -281,6 +284,40 @@ class PayNotifyLogic extends BaseLogic // self::afterPay($order,$extra['transaction_id']); } + /** + * 现金退款相关 + * @param $orderSn + * @param $extra + * @return true + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function cash_refund($orderSn, $extra = []) + { + $order = StoreOrder::where('order_id', $orderSn)->findOrEmpty(); + if ($order->isEmpty() || $order->status == OrderEnum::REFUND_PAY) { + return true; + } + $order->refund_status = OrderEnum::REFUND_STATUS_FINISH; + $order->refund_price = $order->pay_price; + $order->refund_reason_time = time(); + $order->refund_num += 1; + $order->save(); + //日志记录 + $model = new StoreCashFinanceFlow(); + $model->store_id = $order['store_id']??0; + $model->cash_price = $order->pay_price; + $model->receivable = $order->pay_price; + $model->remark = '退款'; + $model->type = 1; + $model->status = YesNoEnum::YES; + $model->save(); + //增加数量 + self::addStock($order['id']); + return true; + } + /** * 充值 */ @@ -778,4 +815,35 @@ class PayNotifyLogic extends BaseLogic (new StoreBranchProduct())->saveAll($updateData); } + + /** + * 加库存 + * @param $oid + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + */ + public static function addStock($oid) + { + $updateData = []; + $goods_list = StoreOrderCartInfo::where('oid', $oid)->select()->toArray(); + foreach ($goods_list as $v) { + $StoreBranchProduct = StoreBranchProduct::where( + [ + 'store_id' => $v['store_id'], + 'product_id' => $v['product_id'], + ] + )->withTrashed()->find(); + if ($StoreBranchProduct) { + $updateData[] = [ + 'id' => $StoreBranchProduct['id'], + 'stock' => $StoreBranchProduct['stock'] + $v['cart_num'], +// 'sales' => ['inc', $v['cart_num']] + ]; + } + } + + (new StoreBranchProduct())->saveAll($updateData); + } }