Explorar o código

结账消费余额

shish %!s(int64=2) %!d(string=hai) anos
pai
achega
149d891329

+ 85 - 2
biz-ghs/custom/classes/CustomClass.php

@@ -63,8 +63,89 @@ class CustomClass extends BaseClass
         self::LEVEL_ZS => 'zsAddPrice',
     ];
 
+    //消费余额 ssh 20240311
+    public static function clearConsumeBalance($amount, $custom, $ghs, $shop, $staff, $clear)
+    {
+        $customId = $custom->id ?? 0;
+        $ghsId = $ghs->id ?? 0;
+        $relateId = $clearInfo->id ?? 0;
+        $staffId = $staff->id ?? 0;
+        $staffName = $staff->name ?? '';
+        $clearSn = $clear->orderSn;
+        $mainId = $shop->mainId ?? 0;
+        $shopId = $shop->id ?? 0;
+        $sjId = $shop->sjId ?? 0;
+
+        $newGhsBalance = bcsub($ghs->balance, $amount, 2);
+        $ghs->balance = $newGhsBalance;
+        $ghs->save();
+
+        $newCustomBalance = bcsub($custom->balance, $amount, 2);
+        $custom->balance = $newCustomBalance;
+        $custom->save();
+
+        if ($newGhsBalance < 0) {
+            util::fail('余额有问题哦..');
+        }
+        if (floatval($newGhsBalance) != floatval($newCustomBalance)) {
+            util::fail('余额有问题...');
+        }
+
+        $capitalType = dict::getDict('capitalType', 'ghsHelpCustomUseBalanceClear', 'id');
+        $fromType = dict::getDict('fromType', 'shop');
+        $cbData = [
+            'customId' => $customId,
+            'relateId' => $relateId,
+            'onlinePay' => 1,
+            'ptStyle' => 2,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $newCustomBalance,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'io' => 0,
+            'side' => 0,
+            'payWay' => 0,
+            'fromType' => $fromType,
+            'event' => '结账 ' . $clearSn,
+            'mainId' => $mainId,
+            'shopId' => $shopId,
+            'sjId' => $sjId,
+            'remark' => '',
+        ];
+        CustomBalanceChangeClass::add($cbData, true);
+
+        $customShopId = $custom->shopId ?? 0;
+        $customShop = ShopClass::getById($customShopId, true);
+        if (empty($customShop)) {
+            util::fail('没有找到客户门店呢..');
+        }
+        $customShopSjId = $customShop->sjId ?? 0;
+        $customShopMainId = $customShop->mainId ?? 0;
+        $capitalType = dict::getDict('capitalType', 'customAskGhsUseBalanceClear', 'id');
+        $gbData = [
+            'ghsId' => $ghsId,
+            'relateId' => $relateId,
+            'ptStyle' => 2,
+            'capitalType' => $capitalType,
+            'amount' => $amount,
+            'balance' => $newGhsBalance,
+            'io' => 0,
+            'side' => 0,
+            'onlinePay' => 1,
+            'payWay' => 0,
+            'fromType' => $fromType,
+            'event' => '结账 ' . $clearSn,
+            'sjId' => $customShopSjId,
+            'mainId' => $customShopMainId,
+            'shopId' => $customShopId,
+            'remark' => '',
+        ];
+        GhsBalanceChangeClass::add($gbData, true);
+    }
+
     //充值金额 ssh 20240310
-    public static function rechargeAmount($custom, $amount, $shop, $staff)
+    public static function rechargeBalance($custom, $amount, $shop, $staff)
     {
         $ghsId = $custom->ghsId ?? 0;
         $ghsInfo = GhsClass::getLockById($ghsId);
@@ -128,6 +209,7 @@ class CustomClass extends BaseClass
             'staffId' => $staffId,
             'staffName' => $staffName,
             'io' => 1,
+            'side' => 0,
             'payWay' => 0,
             'fromType' => $fromType,
             'event' => '充值',
@@ -165,7 +247,7 @@ class CustomClass extends BaseClass
         ];
         $gRecharge = GhsRechargeClass::add($gData, true);
         $gRechargeId = $gRecharge->id ?? 0;
-        $capitalType = dict::getDict('capitalType', 'ghsCustomRecharge', 'id');
+        $capitalType = dict::getDict('capitalType', 'customAskGhsRecharge', 'id');
         $gbData = [
             'ghsId' => $ghsId,
             'relateId' => $gRechargeId,
@@ -174,6 +256,7 @@ class CustomClass extends BaseClass
             'amount' => $amount,
             'balance' => $ghsInfo->balance,
             'io' => 1,
+            'side' => 0,
             'onlinePay' => 1,
             'payWay' => 0,
             'fromType' => $fromType,

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

@@ -17,7 +17,7 @@ class CustomService extends BaseService
     //充值和结账 ssh 20240309
     public static function rechargeClear($custom, $amount, $shop, $staff)
     {
-        $respond = CustomClass::rechargeAmount($custom, $amount, $shop, $staff);
+        $respond = CustomClass::rechargeBalance($custom, $amount, $shop, $staff);
         $custom = $respond['custom'] ?? [];
         $ghs = $respond['ghs'] ?? [];
         if (empty($custom)) {

+ 2 - 3
biz-ghs/order/classes/OrderClearClass.php

@@ -84,9 +84,8 @@ class OrderClearClass extends BaseClass
             'complete' => 1,
         ];
         $clearInfo = self::clear($clearData, $idText, $sjId, $shopId);
-
-
-
+        //结账消费余额
+        CustomClass::clearConsumeBalance($totalAmount, $custom, $ghs, $shop, $staff, $clearInfo);
     }
 
     //订单结算 ssh 2021.3.14

+ 8 - 2
common/components/dict.php

@@ -341,8 +341,12 @@ class dict
             'ghsClearExpend' => ['id' => 61, 'name' => 'ghsClearExpend'],
             //供货商帮客户充值
             'ghsHelpCustomRecharge' => ['id' => 62, 'name' => 'ghsHelpCustomRecharge'],
-            //供货商的客户自行充值
-            'ghsCustomRecharge' => ['id' => 63, 'name' => 'ghsCustomRecharge'],
+            //客户让供货商帮忙充值
+            'customAskGhsRecharge' => ['id' => 63, 'name' => 'customAskGhsRecharge'],
+            //供货商帮客户用余额结账
+            'ghsHelpCustomUseBalanceClear' => ['id' => 64, 'name' => 'ghsHelpCustomUseBalanceClear'],
+            //客户请供货商帮忙用余额结账
+            'customAskGhsUseBalanceClear' => ['id' => 65, 'name' => 'customAskGhsUseBalanceClear'],
         ],
         "capitalTypeList" => [//流水类型的对应链接,后台收支明细查看时跳转的链接
             0 => ['link' => '/capital/order-detail', 'name' => '网店', 'orderLink' => '/order/detail', 'id' => 0,],
@@ -379,6 +383,8 @@ class dict
             61 => ['link' => '', 'name' => '结账支出', 'id' => 61,],
             62 => ['link' => '', 'name' => '充值', 'id' => 62,],
             63 => ['link' => '', 'name' => '充值', 'id' => 63,],
+            64 => ['link' => '', 'name' => '结账', 'id' => 64,],
+            65 => ['link' => '', 'name' => '结账', 'id' => 65,],
         ],
 
         //用户来源