From 8299b9b428d50b164e279b4a319cf0c122bdf463 Mon Sep 17 00:00:00 2001 From: liu <1873441552@qq.com> Date: Sat, 8 Jun 2024 09:59:25 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E6=AC=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../logic/store_order/StoreOrderLogic.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/app/common/logic/store_order/StoreOrderLogic.php b/app/common/logic/store_order/StoreOrderLogic.php index dc4fe74f9..ae108de1c 100644 --- a/app/common/logic/store_order/StoreOrderLogic.php +++ b/app/common/logic/store_order/StoreOrderLogic.php @@ -11,6 +11,9 @@ use app\common\model\store_order_cart_info\StoreOrderCartInfo; use app\common\model\store_product\StoreProduct; use app\common\model\store_product_unit\StoreProductUnit; use app\common\model\user\UserAddress; +use app\common\service\pay\PayService; +use Exception; +use support\Cache; use think\facade\Db; class StoreOrderLogic extends BaseLogic @@ -165,4 +168,47 @@ class StoreOrderLogic extends BaseLogic return StoreOrder::where($where)->sum('pay_price'); } + + /** + * 退款 + * @param $order_sn + * @param $refund_money + * @param $total + * @return bool + * @throws Exception + */ + public function refund($order_sn,$refund_money,$total) + { + try { + $wechat = new PayService(1); + $time = time(); + $order = [ + 'out_trade_no' => $order_sn, + 'out_refund_no' => 'BO'.$time, + 'amount' => [ + 'refund' => $refund_money, + 'total' => $total, + 'currency' => 'CNY', + ], + // '_action' => 'jsapi', // jsapi 退款,默认 + // '_action' => 'app', // app 退款 + // '_action' => 'combine', // 合单退款 + // '_action' => 'h5', // h5 退款 + // '_action' => 'miniapp', // 小程序退款 + // '_action' => 'native', // native 退款 + + ]; + + $res = $wechat->wechat->refund($order); + if($res['status'] == 'PROCESSING'){ + return true; + } + return false; + } catch (Exception $e) { + \support\Log::info($e->extra['message']?? $e->getMessage()); + throw new \Exception($e->extra['message']?? $e->getMessage()); + } + + } + }