Răsfoiți Sursa

充值与通知

shish 2 ani în urmă
părinte
comite
92cd8b286c

+ 17 - 1
app-hd/controllers/NoticeController.php

@@ -4,8 +4,12 @@ namespace hd\controllers;
 
 use biz\shop\classes\ShopClass;
 use biz\notice\classes\NoticeClass;
+use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\classes\CustomRechargeClass;
+use bizGhs\order\classes\OrderClearClass;
 use bizGhs\order\classes\RefundOrderClass;
 use bizHd\cg\classes\CgRefundClass;
+use bizHd\ghs\classes\GhsClass;
 use bizHd\ljh\classes\LjhApplyClass;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\wx\classes\WxOpenClass;
@@ -116,6 +120,18 @@ class NoticeController extends PublicController
             }
             Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 864000, 'has']);
 
+            //客户向供货商充值然后进行清账
+            if ($capitalType == dict::getDict('capitalType', 'customRechargeToGhs', 'id')) {
+                $customRecharge = CustomRechargeClass::getByCondition(['orderSn' => $orderSn], true);
+                $customId = $customRecharge->customId ?? 0;
+                $ghsId = $customRecharge->ghsId ?? 0;
+                $ghs = GhsClass::getLockById($ghsId);
+                $ghsShopId = $ghs->shopId ?? 0;
+                $custom = CustomClass::getLockById($customId);
+                $shop = ShopClass::getById($ghsShopId, true);
+                OrderClearClass::useBalanceClear($custom, $ghs, $shop, null);
+            }
+
             //零售采购结账通知
             if ($capitalType == dict::getDict('capitalType', 'xhPurchase', 'id')) {
                 $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
@@ -309,7 +325,7 @@ class NoticeController extends PublicController
                     if (isset($cg->book) && $cg->book == 0) {
                         $ghsShopId = $order->shopId ?? 0;
                         if (getenv('YII_ENV') == 'production') {
-                            $specialList = [10649, 8042, 16454,21319];
+                            $specialList = [10649, 8042, 16454, 21319];
                         } else {
                             $specialList = [36523];
                         }

+ 1 - 1
biz-ghs/custom/classes/CustomClass.php

@@ -148,7 +148,7 @@ class CustomClass extends BaseClass
         $clear->save();
     }
 
-    //充值金额 ssh 20240310
+    //充值金额,有多个地方要同步修改,请搜索关键词custom_ghs_recharge ssh 20240310
     public static function rechargeBalance($custom, $amount, $shop, $staff, $payWay, $params = [])
     {
         $ghsId = $custom->ghsId ?? 0;

+ 119 - 1
biz-ghs/custom/classes/CustomRechargeClass.php

@@ -2,11 +2,13 @@
 
 namespace bizGhs\custom\classes;
 
+use bizGhs\ghs\classes\GhsRechargeClass;
+use bizHd\ghs\classes\GhsClass;
 use common\components\dict;
-use common\components\imgUtil;
 use common\components\noticeUtil;
 use common\components\util;
 use bizHd\base\classes\BaseClass;
+use bizGhs\ghs\classes\GhsBalanceChangeClass;
 
 class CustomRechargeClass extends BaseClass
 {
@@ -19,4 +21,120 @@ class CustomRechargeClass extends BaseClass
         return $data;
     }
 
+    public static function thirdPay($payWay, $customRechargeSn, $totalFee, $attach, $transactionId)
+    {
+        $customRecharge = self::getByCondition(['orderSn' => $customRechargeSn], true);
+        if (empty($customRecharge)) {
+            noticeUtil::push('充值订单,单号:' . $customRechargeSn . ',没有找到订单', '15280215347');
+            $msg = "没有找到充值订单 orderSn:{$customRechargeSn}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        if ($customRecharge->amount != $totalFee) {
+            noticeUtil::push("充值订单,支付回调错误,零售订单金额与回调通知金额不一致 orderSn:{$customRechargeSn} {$customRecharge->amount} {$totalFee}", '15280215347');
+            $msg = "充值订单金额与回调通知金额不一致 orderSn:{$customRechargeSn} {$customRecharge->amount} {$totalFee}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        if ($customRecharge->payStatus == 1) {
+            noticeUtil::push("充值订单,支付回调错误,已经充值过了 orderSn:{$customRechargeSn}", '15280215347');
+            $msg = "充值订单,支付回调错误,已经充值过了 orderSn:{$customRechargeSn}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        $amount = $totalFee;
+        $id = $customRecharge->id;
+        $customRecharge = self::getLockById($id);
+        $payDate = date("Y-m-d H:i:s");
+        $customRecharge->payTime = $payDate;
+        $customRecharge->payWay = $payWay;
+        $customRecharge->payStatus = 1;
+        $customRecharge->status = 1;
+        $customRecharge->returnCode = $transactionId;
+        $customRecharge->onlinePay = dict::getDict('onlinePay', 'yes');
+        $customRecharge->save();
+
+        $ghsRechargeId = $customRecharge->ghsRechargeId ?? 0;
+        $ghsRecharge = GhsRechargeClass::getById($ghsRechargeId, true);
+        if (empty($ghsRecharge)) {
+            noticeUtil::push("充值订单,支付回调错误,没有找到对应单号 orderSn:{$customRechargeSn}", '15280215347');
+            $msg = "充值订单,支付回调错误,没有找到对应单号 orderSn:{$customRechargeSn}";
+            Yii::info($msg);
+            util::fail($msg);
+        }
+        $ghsRecharge->payTime = $payDate;
+        $ghsRecharge->payWay = $payWay;
+        $ghsRecharge->payStatus = 1;
+        $ghsRecharge->status = 1;
+        $ghsRecharge->onlinePay = dict::getDict('onlinePay', 'yes');
+        $ghsRecharge->save();
+
+        //充值金额,有多个地方要同步修改,请搜索关键词custom_ghs_recharge ssh 20240310
+        $customRechargeId = $customRecharge->id ?? 0;
+        $customId = $customRecharge->customId ?? 0;
+        $ghsId = $customRecharge->ghsId ?? 0;
+        $custom = CustomClass::getLockById($customId);
+        $ghsInfo = GhsClass::getLockById($ghsId);
+        $rechargeEvent = '线上充值';
+        $customMainId = $custom->mainId ?? 0;
+        $customShopId = $custom->shopId ?? 0;
+        $ghsMainId = $ghs->mainId ?? 0;
+        $ghsShopId = $ghs->shopId ?? 0;
+        $customStaffId = $ghsRecharge->staffId ?? 0;
+        $customStaffName = $ghsRecharge->staffName ?? '';
+
+        $custom->balance = bcadd($custom->balance, $amount, 2);
+        $custom->save();
+        $capitalType = dict::getDict('capitalType', 'customRechargeToGhs', 'id');
+        $fromType = dict::getDict('fromType', 'shop');
+        $cbData = [
+            'customId' => $customId,
+            'relateId' => $customRechargeId,
+            'onlinePay' => 2,
+            'ptStyle' => 2,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $custom->balance,
+            'staffId' => 0,
+            'staffName' => '',
+            'io' => 1,
+            'side' => 1,
+            'payWay' => $payWay,
+            'fromType' => $fromType,
+            'event' => $rechargeEvent,
+            'mainId' => $ghsMainId,
+            'shopId' => $ghsShopId,
+            'sjId' => 0,
+            'remark' => '',
+        ];
+        CustomBalanceChangeClass::add($cbData, true);
+
+        $ghsInfo->balance = bcadd($ghsInfo->balance, $amount, 2);
+        $ghsInfo->save();
+
+        $ghsRechargeId = $ghsRecharge->id ?? 0;
+        $capitalType = dict::getDict('capitalType', 'customAskGhsRecharge', 'id');
+        $gbData = [
+            'ghsId' => $ghsId,
+            'relateId' => $ghsRechargeId,
+            'ptStyle' => 2,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $ghsInfo->balance,
+            'staffId' => $customStaffId,
+            'staffName' => $customStaffName,
+            'io' => 1,
+            'side' => 1,
+            'onlinePay' => 2,
+            'payWay' => $payWay,
+            'fromType' => $fromType,
+            'event' => $rechargeEvent,
+            'sjId' => 0,
+            'mainId' => $customMainId,
+            'shopId' => $customShopId,
+            'remark' => '',
+        ];
+        GhsBalanceChangeClass::add($gbData, true);
+    }
+
 }

+ 1 - 1
biz-ghs/custom/services/CustomService.php

@@ -14,7 +14,7 @@ class CustomService extends BaseService
 
     public static $baseFile = '\bizGhs\custom\classes\CustomClass';
 
-    //充值和结账 ssh 20240309
+    //充值和结账,有多个地方要同步修改,请搜索关键词custom_ghs_recharge ssh 20240309
     public static function rechargeClear($custom, $amount, $shop, $staff, $payWay, $params)
     {
         $respond = CustomClass::rechargeBalance($custom, $amount, $shop, $staff, $payWay, $params);

+ 5 - 0
common/components/payUtil.php

@@ -5,6 +5,7 @@ namespace common\components;
 use biz\recharge\classes\RechargeClass;
 use biz\renew\classes\RenewClass;
 use biz\wx\classes\WxMessageClass;
+use bizGhs\custom\classes\CustomRechargeClass;
 use bizHd\ljh\classes\LjhApplyClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\purchase\classes\PurchaseClearClass;
@@ -63,6 +64,10 @@ class payUtil
                 //零交会报名
                 LjhApplyClass::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
                 break;
+            case dict::getDict('capitalType', 'customRechargeToGhs', 'id'):
+                //客户向供货商充值销账
+                CustomRechargeClass::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
+                break;
             default:
         }
     }