shish 1 an în urmă
părinte
comite
61fc6bec05

+ 1 - 1
app-ghs/controllers/ConsoleController.php

@@ -242,7 +242,7 @@ class ConsoleController extends BaseController
 
         $warning = '';
         $warningUrl = '';
-        //$warning = '注意开小单位(支)将会扣库存 点击了解';
+        //$warning = '开小单位(支)会减库存';
         //$warningUrl = '/admin/notice/warning';
 
         util::success([

+ 44 - 5
app-ghs/controllers/OrderController.php

@@ -9,6 +9,7 @@ use bizGhs\ghs\classes\GhsClass;
 use bizGhs\order\classes\OrderItemClass;
 use bizGhs\order\classes\RefundOrderClass;
 use bizHd\purchase\classes\PurchaseClass;
+use bizHd\purchase\classes\PurchaseItemClass;
 use bizHd\purchase\services\PurchaseService;
 use bizHd\wx\classes\WxOpenClass;
 use bizGhs\custom\classes\CustomClass;
@@ -23,6 +24,7 @@ use common\components\dirUtil;
 use common\components\freight;
 use common\components\httpUtil;
 use common\components\noticeUtil;
+use common\components\orderSn;
 use common\components\oss;
 use common\components\payUtil;
 use common\components\printUtil;
@@ -671,10 +673,43 @@ class OrderController extends BaseController
             $msg = '没有找到采购单';
             util::success(['returnStatus' => 'FAILURE'], $msg);
         }
+
+
+        $codePayErrorKey = 'code_pay_error_' . $id;
+        $hasFailPay = Yii::$app->redis->executeCommand('GET', [$codePayErrorKey]);
+        //前面有付失败过,要重新生成单号
+        if (!empty($hasFailPay)) {
+            $oldOrderSn = $orderSn;
+            $orderSn = orderSn::getPurchaseSn();
+            $cg->orderSn = $orderSn;
+            $cg->save();
+            noticeUtil::push("重新扫码,成功更换单号 {$oldOrderSn} {$orderSn}", '15280215347');
+            PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
+        }
+
+
+        $shop = $this->shop;
+        $sj = $shop->merchantName;
+        $shopName = $shop->shopName;
+        $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
+
         //付款码
         $authCode = (string)$get['authCode'] ?? '';
+        $authCode = trim($authCode);
         if (empty($authCode)) {
-            $msg = '没有付款码';
+            $msg = '没有扫到付款码';
+            $remind = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
+            noticeUtil::push($remind . ' 编号001', '15280215347');
+            util::success(['returnStatus' => 'FAILURE'], $msg);
+        }
+        //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
+        $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
+        //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
+        $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
+        if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
+            $msg = '付款码有问题';
+            $remind = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
+            noticeUtil::push($remind . ' 编号002', '15280215347');
             util::success(['returnStatus' => 'FAILURE'], $msg);
         }
 
@@ -689,9 +724,8 @@ class OrderController extends BaseController
         $connection = Yii::$app->db;
         $transaction = $connection->beginTransaction();
         try {
-            $subject = '购买花材';
+            $subject = '购买花材 '.$orderSn;
             $capitalType = dict::getDict('capitalType', 'xhPurchase', 'id');
-            $shop = $this->shop;
             $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
             $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
             $params = [
@@ -777,10 +811,15 @@ class OrderController extends BaseController
                 }
                 util::success(['returnStatus' => 'SUCCESS']);
             } else {
+
+                //标记有没付成功的次数,原因有可能是余额不足等
+                Yii::$app->redis->executeCommand('SETEX', [$codePayErrorKey, 1200, 'hasFail']);
+
                 $msg = $response['msg'] ?? '';
                 $retCode = $response['code'] ?? '';
-                noticeUtil::push($msg . ' ' . $retCode . ' 编号145539', '15280215347');
-                util::success(['returnStatus' => 'FAILURE'], $msg);
+                $fullMsg = $msg . "(付款码:{$authCode})" . '(' . $name . ')';
+                noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号007', '15280215347');
+                util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
             }
         } catch (\Exception $e) {
             $transaction->rollBack();

+ 25 - 0
app-ghs/controllers/RefundController.php

@@ -9,6 +9,7 @@ use bizGhs\shop\classes\ShopClass;
 use bizHd\cg\classes\CgRefundClass;
 use bizHd\cg\classes\CgRefundItemClass;
 use bizHd\notice\classes\NoticeClass;
+use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseClearClass;
 use common\components\dateUtil;
 use common\components\imgUtil;
@@ -24,6 +25,30 @@ use bizGhs\order\classes\StockWastageOrderClass;
 class RefundController extends BaseController
 {
 
+    //取消的订单退钱,特殊情况的操作:商家取消订单时,客户同时付款成功了,造成的流程冲突,需要退钱 ssh 20250429
+    public function actionRefundMoney()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order->mainId != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $shop = $this->shop;
+        $purchaseId = $order->purchaseId ?? 0;
+        $cg = PurchaseClass::getById($purchaseId, true);
+        if (empty($cg)) {
+            util::fail('没有找到订单');
+        }
+        $respond = CgRefundClass::onlyRefundMoney($shop, $cg);
+        $status = $respond['status'];
+        $msg = $respond['msg'];
+        util::success(['status' => $status], $msg);
+    }
+
     //修改金额 ssh 20240412
     public function actionModifyAmount()
     {

+ 1 - 1
app-ghs/controllers/ShopController.php

@@ -336,7 +336,7 @@ class ShopController extends BaseController
         if (getenv('YII_ENV') == 'production') {
             //安海恋善指定人不能切换门店
             if (in_array($mainId, [44759, 56314, 56315, 56452])) {
-                if (in_array($adminId, [54629, 54630, 54723])) {
+                if (in_array($adminId, [54630, 54723])) {
                     util::fail('不能切换门店,原因是容易误操作或收银机登录使用');
                 }
             }

+ 15 - 0
app-hd/controllers/NoticeController.php

@@ -493,6 +493,21 @@ class NoticeController extends PublicController
                     }
                 }
             }
+
+            //散客下单买花,回调通知后,播报声音提示,这个方法本来不能写在这边要写在app-mall里的
+            if ($capitalType == dict::getDict('capitalType', 'xhOrder', 'id')) {
+                $cacheKey = 'hd_shop_order_pay_' . $orderSn;
+                $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
+                if (empty($has)) {
+                    Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 300, 'has']);
+                    $newOrder = \bizHd\order\classes\OrderClass::getByCondition(['orderSn' => $orderSn], true);
+                    if ($newOrder->onlinePay == 2) {
+                        //语音播报
+                        ShopExtClass::hdGatheringReport($newOrder);
+                    }
+                }
+            }
+
         } catch (\Exception $e) {
             $transaction->rollBack();
             Yii::error("失败原因:" . $e->getMessage());

+ 52 - 6
app-hd/controllers/OrderController.php

@@ -9,6 +9,7 @@ use bizHd\custom\classes\CustomClass;
 use bizHd\goods\classes\GoodsClass;
 use bizHd\merchant\services\ShopService;
 use bizHd\order\classes\OrderClass;
+use bizHd\order\classes\OrderItemClass;
 use bizHd\order\classes\OrderSendClass;
 use bizHd\order\services\OrderService;
 use bizHd\product\classes\ProductClass;
@@ -20,6 +21,8 @@ use bizHd\work\classes\WorkClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\dateUtil;
+use common\components\noticeUtil;
+use common\components\orderSn;
 use common\components\payUtil;
 use common\services\xhPayToolService;
 use Yii;
@@ -267,15 +270,53 @@ class OrderController extends BaseController
         header("Content-type: text/html; charset=utf-8");
         $get = Yii::$app->request->get();
         $id = isset($get['id']) ? $get['id'] : 0;
+        $version = $get['version'] ?? 0;
         $order = OrderClass::getById($id, true);
         OrderClass::valid($order, $this->mainId);
+
+        $shop = $this->shop;
+        $sj = $shop->merchantName;
+        $shopName = $shop->shopName;
+        $name = $shopName == '首店' ? $sj : $sj . '-' . $shopName;
+
         $authCode = (string)$get['authCode'] ?? '';
-        if (empty($authCode)) {
-            util::fail('没有获取到支付码');
-        }
+        if ($version > 0) {
+            if (empty($authCode)) {
+                $msg = '没有扫到付款码';
+                $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
+                noticeUtil::push($remind . ' 编号005', '15280215347');
+                util::success(['returnStatus' => 'FAILURE'], $msg);
+            }
+            //微信文档说明 https://pay.weixin.qq.com/doc/v2/merchant/4011936234
+            $wxPattern = '/^(10|11|12|13|14|15)\d{16}$/';
+            //支付宝文档说明 https://opendocs.alipay.com/open/194/106039/
+            $aliPattern = '/^(25|26|27|28|29|30)\d{14,22}$/';
+            if (!preg_match($wxPattern, $authCode) && !preg_match($aliPattern, $authCode)) {
+                $msg = '付款码有问题';
+                $remind = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
+                noticeUtil::push($remind . ' 编号009', '15280215347');
+                util::success(['returnStatus' => 'FAILURE'], $msg);
+            }
 
+        } else {
+            if (empty($authCode)) {
+                util::fail('没有获取到支付码');
+            }
+        }
         $orderSn = $order->orderSn ?? '';
-        $subject = '购买花材';
+
+        $lsCodePayErrorKey = 'ls_code_pay_error_' . $id;
+        $hasFailPay = Yii::$app->redis->executeCommand('GET', [$lsCodePayErrorKey]);
+        //前面有付失败过,要重新生成单号
+        if (!empty($hasFailPay)) {
+            $oldOrderSn = $order->orderSn;
+            $orderSn = orderSn::getOrderSn();
+            $order->orderSn = $orderSn;
+            $order->save();
+            OrderItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $orderSn]);
+        }
+
+        $subject = '购买花材 ' . $orderSn;
         $totalFee = $order->mainPay ?? 0;
         $capitalType = dict::getDict('capitalType', 'xhOrder', 'id');
 
@@ -283,7 +324,6 @@ class OrderController extends BaseController
         $transaction = $connection->beginTransaction();
         try {
 
-            $shop = $this->shop;
             $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
             $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
             $params = [
@@ -341,8 +381,14 @@ class OrderController extends BaseController
 
                 util::success(['returnStatus' => 'SUCCESS']);
             } else {
+                //标记有没付成功的次数,原因有可能是余额不足等
+                Yii::$app->redis->executeCommand('SETEX', [$lsCodePayErrorKey, 1200, 'hasFail']);
+
                 $msg = $response['msg'] ?? '';
-                util::success(['returnStatus' => 'FAILURE'], $msg);
+                $retCode = $response['code'] ?? '';
+                $fullMsg = $msg . "(零售端付款码:{$authCode})" . '(' . $name . ')';
+                noticeUtil::push($fullMsg . ' ' . $retCode . ' 编号008', '15280215347');
+                util::success(['returnStatus' => 'FAILURE', 'returnCode' => $retCode], $msg);
             }
 
         } catch (\Exception $e) {

+ 0 - 18
app-hd/controllers/PurchaseController.php

@@ -978,19 +978,10 @@ class PurchaseController extends BaseController
             }
 
             $newOrderSn = orderSn::getPurchaseSn();
-            $newGhsOrderSn = orderSn::getGhsOrderSn();
             $orderSn = $newOrderSn;
             $order->orderSn = $newOrderSn;
             $order->save();
             PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
-            $saleId = $order->saleId ?? 0;
-            $sale = OrderClass::getById($saleId, true);
-            if (!empty($sale)) {
-                $oldSaleOrderSn = $sale->orderSn ?? '';
-                $sale->orderSn = $newGhsOrderSn;
-                $sale->save();
-                OrderItemClass::updateByCondition(['orderSn' => $oldSaleOrderSn], ['orderSn' => $newGhsOrderSn]);
-            }
         }
         $order->changePrice = 2;
         $order->save();
@@ -1115,19 +1106,10 @@ class PurchaseController extends BaseController
             }
 
             $newOrderSn = orderSn::getPurchaseSn();
-            $newGhsOrderSn = orderSn::getGhsOrderSn();
             $orderSn = $newOrderSn;
             $order->orderSn = $newOrderSn;
             $order->save();
             PurchaseItemClass::updateByCondition(['orderSn' => $oldOrderSn], ['orderSn' => $newOrderSn]);
-            $saleId = $order->saleId ?? 0;
-            $sale = OrderClass::getById($saleId, true);
-            if (!empty($sale)) {
-                $oldSaleOrderSn = $sale->orderSn ?? '';
-                $sale->orderSn = $newGhsOrderSn;
-                $sale->save();
-                OrderItemClass::updateByCondition(['orderSn' => $oldSaleOrderSn], ['orderSn' => $newGhsOrderSn]);
-            }
         }
 
         $id = $order->id;

+ 19 - 0
app-hd/controllers/RefundController.php

@@ -17,6 +17,25 @@ use common\components\util;
 class RefundController extends BaseController
 {
 
+    //取消的订单退钱,特殊情况的操作:商家取消订单时,客户同时付款成功了,造成的流程冲突,需要退钱 ssh 20250429
+    public function actionRefundAmount()
+    {
+        $get = Yii::$app->request->get();
+        $id = $get['id'] ?? '';
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order->mainId != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $shop = $this->shop;
+        $respond = HdRefundClass::onlyRefundAmount($shop, $order);
+        $status = $respond['status'];
+        $msg = $respond['msg'];
+        util::success(['status' => $status], $msg);
+    }
+
     //列表
     public function actionList()
     {

+ 41 - 0
biz-hd/cg/classes/CgRefundClass.php

@@ -3,6 +3,7 @@
 namespace bizHd\cg\classes;
 
 use biz\shop\classes\ShopCapitalClass;
+use biz\shop\classes\ShopExtClass;
 use bizHd\ghs\classes\GhsClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseItemClass;
@@ -35,6 +36,46 @@ class CgRefundClass extends BaseClass
     const REFUND_TYPE_MONEY_GOOD = 1; //退款退货
     const REFUND_TYPE_MONEY = 2; // 仅退款
 
+    public static function onlyRefundMoney($ghsShop, $cg)
+    {
+        $refundOrderSn = orderSn::getCgRefundSn();
+        $refundPrice = $cg->actPrice ?? 0;
+        $orderSn = $cg->orderSn ?? '';
+        $refundFee = bcmul($refundPrice, 100);
+        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
+        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
+        $params = [
+            'appid' => 'OP00002119',
+            'serial_no' => '018b08cfddbd',
+            'merchant_no' => $ghsShop->lklSjNo,
+            'term_no' => $ghsShop->lklScanTermNo,
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $refundReason = '';
+        $aliParams = [
+            'refundSn' => $refundOrderSn,
+            'orderSn' => $orderSn,
+            'refundAmount' => $refundFee,
+            'refundReason' => $refundReason,
+        ];
+        $response = $laResource->refund($aliParams);
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
+            $errMsg = $response['msg'] ?? '';
+            return ['status' => 0, 'msg' => $errMsg];
+        } else {
+            $ghsShopId = $ghsShop->id;
+            ShopExtClass::orderCancelBackMoneyReport($ghsShopId);
+            $sjName = $ghsShop->merchantName;
+            $shopName = $ghsShop->shopName;
+            $name = $shopName == '首店' ? $sjName : $sjName . '-' . $shopName;
+            noticeUtil::push("订单取消,客户还付款成功,钱已经原路退回 success {$orderSn} {$name}", '15280215347');
+            return ['status' => 1, 'msg' => '退款成功'];
+        }
+    }
+
+
     //审核通过 ssh 20230811
     public static function passRefund($cgRefund, $cg)
     {

+ 14 - 8
biz-hd/order/classes/OrderClass.php

@@ -20,6 +20,7 @@ use bizGhs\stock\classes\StockRecordClass;
 use bizGhs\ws\services\WsService;
 use bizHd\custom\classes\CustomClass;
 use bizHd\merchant\classes\SjClass;
+use bizHd\refund\classes\HdRefundClass;
 use bizHd\shop\classes\MainClass;
 use bizHd\shop\classes\ShopMoneyChangeClass;
 use bizHd\stat\classes\StatIncomeClass;
@@ -260,11 +261,16 @@ class OrderClass extends BaseClass
         }
         $orderSn = $order->orderSn ?? '';
         if ($order->status == self::ORDER_STATUS_CANCEL) {
-            noticeUtil::push('特别注意,零售订单:' . $orderSn . ',付款成功但订单是取消状态', '15280215347');
-            util::fail('订单已取消');
+            $shopId = $order->shopId;
+            $shop = ShopClass::getById($shopId, true);
+            if (!empty($shop)) {
+                HdRefundClass::onlyRefundAmount($shop, $order);
+            }
+            noticeUtil::push('注意,散客订单:' . $orderSn . ',付款成功但订单已取消,关键词 cancel_get_money', '15280215347');
+            util::stop("SUCCESS");
         }
         if ($order->payStatus == 1) {
-            noticeUtil::push('特别注意,零售订单:' . $orderSn . ',已经付过款了,无需重复请求和操作', '15280215347');
+            noticeUtil::push('注意散客订单:' . $orderSn . ',已经付过款了,无需重复请求和操作', '15280215347');
             util::fail('订单已经付过款了');
         }
 
@@ -605,15 +611,15 @@ class OrderClass extends BaseClass
                 $content .= '<B>到店自取</B><BR><BR>';
             }
         } else {
-            if($order->sendType == 0){
+            if ($order->sendType == 0) {
                 $content .= '<B>送货上门</B><BR><BR>';
-            }else if($order->sendType == 2){
+            } else if ($order->sendType == 2) {
                 $content .= '<B>跑腿到付</B><BR><BR>';
-            }else if($order->sendType == 3){
+            } else if ($order->sendType == 3) {
                 $content .= '<B>物流到付</B><BR><BR>';
-            }else if($order->sendType == 4){
+            } else if ($order->sendType == 4) {
                 $content .= '<B>快递到付</B><BR><BR>';
-            }else{
+            } else {
                 $content .= '';
             }
             if (isset($order->reachDate) && !empty($order->reachDate) && $order->reachDate != '0000-00-00') {

+ 1 - 1
biz-hd/purchase/classes/PurchaseClass.php

@@ -205,7 +205,7 @@ class PurchaseClass extends BaseClass
         $purchaseItem = PurchaseItemClass::getAllByCondition(['orderSn' => $orderSn], null, "*");
         foreach ($purchaseItem as $v) {
             //小单位库存不考虑入库 ssh 202310
-            $itemNum = intval($v['itemNum']);
+            $itemNum = $v['itemNum'];
             if ($itemNum > 0) {
                 $productId = $v['productId'];
                 $stockInfo = ProductClass::addStockByItemNum($v['productId'], $itemNum);

+ 13 - 5
biz-hd/purchase/services/PurchaseService.php

@@ -20,6 +20,7 @@ use bizGhs\stock\classes\StockRecordClass;
 use bizGhs\ws\services\WsService;
 use bizHd\admin\classes\ShopAdminClass;
 use bizHd\base\services\BaseService;
+use bizHd\cg\classes\CgRefundClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\classes\PurchaseItemClass;
 use bizHd\shop\classes\MainClass;
@@ -280,7 +281,7 @@ class PurchaseService extends BaseService
     {
         $info = self::getByCondition(['orderSn' => $orderSn], true);
         if (empty($info)) {
-            noticeUtil::push('花店采购,付款成功,支付回调,单号:' . $orderSn . ',没有找到订单 '.$attach, '15280215347');
+            noticeUtil::push('花店采购,付款成功,支付回调,单号:' . $orderSn . ',没有找到订单 ' . $attach, '15280215347');
             $msg = "没有找到订单 orderSn:{$orderSn}";
             Yii::info($msg);
             util::fail($msg);
@@ -331,13 +332,20 @@ class PurchaseService extends BaseService
             util::fail('没有找到订单状态');
         }
         if ($info->status == PurchaseClass::STATUS_CANCEL) {
-            noticeUtil::push('重点注意,采购单:' . $orderSn . ',客户付钱了但订单取消状态', '15280215347');
-            sms::send('15280215347,' . $orderSn, '重点注意,采购单:{$var},客户付钱了但订单取消状态');
-            util::fail('订单已取消');
+            noticeUtil::push('注意花店采购单:' . $orderSn . ',客户付款了但订单已取消,关键词 cancel_get_money', '15280215347');
+            $saleId = $info->saleId;
+            $sale = OrderClass::getById($saleId, true);
+            if (!empty($sale)) {
+                $ghsShopId = $sale->shopId;
+                $ghsShop = ShopClass::getById($ghsShopId, true);
+                if (!empty($ghsShop)) {
+                    CgRefundClass::onlyRefundMoney($ghsShop, $info);
+                }
+            }
+            util::stop("SUCCESS");
         }
 
         if (isset($info->payStatus) && $info->payStatus == 1) {
-            //noticeUtil::push('重点注意,采购单:' . $orderSn . ',已经付过款了,重复请求', '15280215347');
             util::fail('订单已经付过款了');
         }
 

+ 43 - 0
biz-hd/refund/classes/HdRefundClass.php

@@ -2,8 +2,12 @@
 
 namespace bizHd\refund\classes;
 
+use biz\shop\classes\ShopExtClass;
+use common\components\noticeUtil;
+use common\components\orderSn;
 use Yii;
 use bizHd\base\classes\BaseClass;
+use common\components\lakala\Lakala;
 
 class HdRefundClass extends BaseClass
 {
@@ -16,6 +20,45 @@ class HdRefundClass extends BaseClass
     const STATUS_UN_COMPLETE = 0; //退款处理中
     const STATUS_COMPLETE = 1; //已完成
 
+    public static function onlyRefundAmount($shop, $order)
+    {
+        $refundSn = orderSn::getHdRefundSn();
+        $xsOrderSn = $order->orderSn ?? '';
+        $refundPrice = $order->actPrice ?? 0;
+        $refundFee = bcmul($refundPrice, 100);
+        $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
+        $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
+        $params = [
+            'appid' => 'OP00002119',
+            'serial_no' => '018b08cfddbd',
+            'merchant_no' => $shop->lklSjNo,
+            'term_no' => $shop->lklScanTermNo,
+            'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
+            'lklCertificatePath' => $lklCertificatePath,
+        ];
+        $laResource = new Lakala($params);
+        $refundReason = '';
+        $aliParams = [
+            'refundSn' => $refundSn,
+            'orderSn' => $xsOrderSn,
+            'refundAmount' => $refundFee,
+            'refundReason' => $refundReason,
+        ];
+        $response = $laResource->refund($aliParams);
+        if (!isset($response['code']) || $response['code'] != 'BBS00000') {
+            $errMsg = $response['msg'] ?? '';
+            return ['status' => 0, 'msg' => $errMsg];
+        } else {
+            $shopId = $shop->id;
+            ShopExtClass::orderCancelBackMoneyReport($shopId);
+            $sjName = $shop->merchantName;
+            $shopName = $shop->shopName;
+            $name = $shopName == '首店' ? $sjName : $sjName . '-' . $shopName;
+            noticeUtil::push("零售订单取消,客户还付款成功,钱已经原路退回 success {$xsOrderSn} {$name}", '15280215347');
+            return ['status' => 1, 'msg' => '退款成功'];
+        }
+    }
+
     // 订单列表
     public static function getOrderList($where)
     {

+ 12 - 0
biz/shop/classes/ShopExtClass.php

@@ -334,6 +334,18 @@ class ShopExtClass extends BaseClass
         }
     }
 
+    //订单取消,钱原路退回,提醒客户
+    public static function orderCancelBackMoneyReport($shopId)
+    {
+        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
+        if (!empty($shopExt->lbSn)) {
+            $sound = "订单已取消,付款已原路退回,请稍等几秒重新付款";
+            $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version={$shopExt->lbVersion}&message=" . $sound;
+            $curl = new curl\Curl();
+            $curl->get($url);
+        }
+    }
+
     //清除所有小菊
     public static function clearXjALl($shopId)
     {