Browse Source

结账问题

shish 2 months ago
parent
commit
9a77a992dc

+ 8 - 3
app-hd/controllers/CustomRechargeController.php

@@ -35,18 +35,23 @@ class CustomRechargeController extends BaseController
         $totalFee = $actPrice;
         $ghsId = $post['ghsId'] ?? 0;
         $salt = $post['salt'] ?? '';
-        $ghs = GhsClass::getById($ghsId, true);
+        $ghs = GhsClass::getLockById($ghsId);
         if (empty($ghs)) {
             util::fail('没有找到供货商哦!');
         }
         if ($ghs->salt != $salt) {
             util::fail('不是你的供货商哦');
         }
+
         $customId = $ghs->customId ?? 0;
-        $custom = CustomClass::getById($customId, true);
+        $custom = CustomClass::getLockById($customId);
         if (empty($custom)) {
             util::fail('供货商信息不完整那');
         }
+
+        //检查余额是否有问题
+        GhsClass::checkBalance($ghs, $custom);
+
         // 花店自助充值建单前:挂账并入净 balance
         AccountMoneyClass::ensureCustomMoneyReady($custom, true);
         AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
@@ -235,4 +240,4 @@ class CustomRechargeController extends BaseController
         }
     }
 
-}
+}

+ 4 - 3
app-hd/controllers/PurchaseClearController.php

@@ -27,12 +27,10 @@ class PurchaseClearController extends BaseController
         try {
             $post = Yii::$app->request->post();
             $ghsId = $post['ghsId'] ?? 0;
-            $ghs = GhsClass::getById($ghsId, true);
+            $ghs = GhsClass::getLockById($ghsId);
             if (empty($ghs)) {
                 util::fail('没有供货商');
             }
-            // 花店向供货商结账建单前:挂账并入净 balance
-            AccountMoneyClass::ensureGhsMoneyReady($ghs, true);
             //解决重复请求问题
             $staffId = $this->shopAdminId ?? 0;
             $cacheKey = 'hd_clear_order_pay_' . $ghsId . '_' . $staffId;
@@ -42,6 +40,9 @@ class PurchaseClearController extends BaseController
             }
             Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 5, 'has']);
 
+            //检查余额是否有问题
+            \bizHd\ghs\classes\GhsClass::checkBalance($ghs);
+
             //老的没有清的结账单直接过期掉
             $list = PurchaseClearClass::getAllByCondition(['ghsId' => $ghsId, 'status' => PurchaseClearClass::STATUS_AWAIT_PAY], null, '*', null, true);
             if (!empty($list)) {

+ 27 - 0
biz-hd/ghs/classes/GhsClass.php

@@ -8,7 +8,10 @@ namespace bizHd\ghs\classes;
  * 金额与 bizGhs\custom\classes\AccountMoneyClass 一致:写前 ensureGhsMoneyReady(仅行锁);
  * 挂账=balance 减少,结账/退款=balance 增加;只记 GhsBalanceChange,不再新增 GhsDebtChange(历史仍可查)。
  */
+
 use bizGhs\custom\classes\AccountMoneyClass;
+use bizGhs\custom\classes\CustomClass;
+use bizHd\purchase\classes\PurchaseClass;
 use common\components\dict;
 use common\components\noticeUtil;
 use common\components\util;
@@ -20,6 +23,30 @@ class GhsClass extends BaseClass
 
     public static $baseFile = '\bizHd\ghs\models\Ghs';
 
+    public static function checkBalance($ghs, $custom = null)
+    {
+        if (empty($custom)) {
+            $customId = $ghs->customId ?? 0;
+            $ghs = CustomClass::getLockById($customId);
+            if (empty($ghs)) {
+                util::fail('供货商信息缺了哦');
+            }
+        }
+        $ghsName = $ghs->name ?? '';
+        $customName = $custom->name ?? '';
+        if ($ghs->balance != $custom->balance) {
+            noticeUtil::push("账单有异常。 {$ghsName} {$customName}", '15280215347');
+            util::fail('账单有异常,请联系门店');
+        }
+        if ($ghs->balance < 0) {
+            $remain = PurchaseClass::sum(['ghsId' => $ghsId, 'debt' => 1], 'remainDebtPrice');
+            if ($remain != abs($ghs->balance)) {
+                noticeUtil::push("账单有异常哦 {$ghsName} {$customName}", '15280215347');
+                util::fail('账单有异常哦,请联系门店');
+            }
+        }
+    }
+
     /** 采购挂账开单:balance 减少(原 debtAmount 增加) */
     public static function cgDebtAmountAdd($ghs, $order, $bookOrder = false)
     {