shish 2 лет назад
Родитель
Сommit
b8ca95b9e4
2 измененных файлов с 75 добавлено и 6 удалено
  1. 11 2
      app-ghs/controllers/CustomController.php
  2. 64 4
      biz-ghs/custom/services/CustomService.php

+ 11 - 2
app-ghs/controllers/CustomController.php

@@ -44,8 +44,17 @@ class CustomController extends BaseController
         if ($custom->ownMainId != $this->mainId) {
             util::fail('不是你的客户,无法充值');
         }
-        CustomService::rechargeClear($custom, $amount);
-        util::complete('充值成功');
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $staff = $this->shopAdmin;
+            CustomService::rechargeClear($custom, $amount, $this->shop, $staff);
+            $transaction->commit();
+            util::complete('充值成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            util::fail('充值失败');
+        }
     }
 
     //生成货位号 ssh 20231215

+ 64 - 4
biz-ghs/custom/services/CustomService.php

@@ -4,8 +4,11 @@ namespace bizGhs\custom\services;
 
 use biz\ghs\classes\GhsClass;
 use biz\sj\classes\SjClass;
+use bizGhs\custom\classes\CustomRechargeClass;
+use bizGhs\ghs\classes\GhsRechargeClass;
 use bizHd\base\services\BaseService;
 use bizGhs\custom\classes\CustomClass;
+use common\components\orderSn;
 use common\components\util;
 
 class CustomService extends BaseService
@@ -14,18 +17,75 @@ class CustomService extends BaseService
     public static $baseFile = '\bizGhs\custom\classes\CustomClass';
 
     //充值和结账 ssh 20240309
-    public static function rechargeClear($custom, $amount)
+    public static function rechargeClear($custom, $amount, $shop, $staff)
     {
-        $custom->balance = bcadd($custom->balance, $amount, 2);
-        $custom->save();
-
         $ghsId = $custom->ghsId ?? 0;
         $ghsInfo = GhsClass::getById($ghsId, true);
         if (empty($ghsInfo)) {
             util::fail('没有找到供货商');
         }
+        $ghsShopId = $ghsInfo->shopId ?? 0;
+        $ghsName = $ghsInfo->name ?? '';
+        $customId = $custom->id ?? 0;
+        $customShopId = $custom->shopId ?? 0;
+        $customName = $custom->name ?? '';
+
+        $custom->balance = bcadd($custom->balance, $amount, 2);
+        $custom->save();
+        $orderSn = orderSn::getGhsCustomRechargeSn();
+        $shopId = $shop->id ?? 0;
+        $mainId = $shop->mainId ?? 0;
+        $staffId = $staff->id ?? 0;
+        $staffName = $staff->name ?? '';
+        $cData = [
+            'orderSn' => $orderSn,
+            'onlinePay' => 1,
+            'payWay' => 0,
+            'shopId' => $shopId,
+            'mainId' => $mainId,
+            'amount' => $amount,
+            'balance' => $custom->balance,
+            'side' => 0,
+            'staffId' => $staffId,
+            'staffName' => $staffName,
+            'payStatus' => 1,
+            'status' => 1,
+            'remark' => '',
+            'ghsId' => $ghsId,
+            'ghsShopId' => $ghsShopId,
+            'ghsName' => $ghsName,
+            'customId' => $customId,
+            'customShopId' => $customShopId,
+            'customName' => $customName,
+        ];
+        $cRecharge = CustomRechargeClass::add($cData, true);
+
         $ghsInfo->balance = bcadd($ghsInfo->balance, $amount, 2);
         $ghsInfo->save();
+        $orderSn = orderSn::getGhsRechargeSn();
+        $customMainId = $custom->mainId ?? 0;
+        $gData = [
+            'orderSn' => $orderSn,
+            'onlinePay' => 1,
+            'payWay' => 0,
+            'shopId' => $customShopId,
+            'mainId' => $customMainId,
+            'amount' => $amount,
+            'balance' => $ghsInfo->balance,
+            'side' => 0,
+            'staffId' => 0,
+            'staffName' => '',
+            'payStatus' => 1,
+            'status' => 1,
+            'remark' => '',
+            'ghsId' => $ghsId,
+            'ghsShopId' => $ghsShopId,
+            'ghsName' => $ghsName,
+            'customId' => $customId,
+            'customShopId' => $customShopId,
+            'customName' => $customName,
+        ];
+        $gRecharge = GhsRechargeClass::add($gData, true);
     }
 
     //分享建立客户和供货商关系 ssh 2021.2.28