Bladeren bron

先充值,再销账

shish 1 jaar geleden
bovenliggende
commit
0bd6d53cf1

+ 2 - 1
app-hd/controllers/BaseController.php

@@ -17,7 +17,7 @@ class BaseController extends PublicController
 {
 
     public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
-    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdmin;
+    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdminName, $shopAdmin;
     public $appId;
     public $isWx = false;
     public $isLogin = false;
@@ -77,6 +77,7 @@ class BaseController extends PublicController
             }
             $this->shopAdmin = $shopAdmin;
             $this->shopAdminId = $shopAdmin->id ?? 0;
+            $this->shopAdminName = $shopAdmin->name ?? '';
             $sjId = $shop->sjId;
             $this->sjId = $sjId;
             $sj = SjClass::getById($sjId, true);

+ 70 - 0
app-hd/controllers/SettleController.php

@@ -2,9 +2,13 @@
 
 namespace hd\controllers;
 
+use bizHd\custom\classes\CustomClass;
+use bizHd\custom\classes\HdClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\SettleClass;
+use bizHd\recharge\classes\RechargeClass;
 use common\components\dict;
+use common\components\orderSn;
 use common\components\util;
 use Yii;
 
@@ -24,11 +28,77 @@ class SettleController extends BaseController
             $staff = $this->shopAdmin;
             $payWay = $post['payWay'] ?? dict::getDict('payWay', 'wxPay');
             $id = $post['id'] ?? '';
+            $customId = $post['customId'] ?? 0;
+            $custom = CustomClass::getLockById($customId);
+            if (empty($custom)) {
+                util::fail('没有找到客户');
+            }
+            $hdId = $custom->hdId ?? 0;
+            $hd = HdClass::getlockById($hdId);
+            if (empty($hd)) {
+                util::fail('客户信息缺失');
+            }
+
+            //1、先充值
+            $rechargeAmount = 0;
             if (is_numeric($id)) {
                 $order = OrderClass::getById($id, true);
                 if (empty($order)) {
                     util::fail('没有找到订单');
                 }
+                $rechargeAmount = $order->remainDebtPrice ?? 0;
+            } else {
+                $idArr = json_decode($id, true);
+                $ids = array_column($idArr, 'id');
+                $orderList = OrderClass::getAllByCondition(['id' => ['in', $ids]], null, '*', null, true);
+                if (!empty($orderList)) {
+                    foreach ($orderList as $order) {
+                        $remainDebtPrice = $order->remainDebtPrice ?? 0;
+                        $rechargeAmount = bcadd($rechargeAmount, $remainDebtPrice, 2);
+                    }
+                }
+            }
+            if (empty($rechargeAmount)) {
+                util::fail('不需要销账');
+            }
+            $staffId = $this->shopAdminId;
+            $staffName = $this->shopAdminName;
+            $customName = $custom->name ?? '';
+            $hdName = $hd->name;
+            $shopId = $this->shopId;
+            $mainId = $this->mainId;
+            $orderSn = orderSn::getRechargeSn();
+            $rechargeData = [
+                'orderSn' => $orderSn,
+                'modPrice' => 1,
+                'payWay' => $payWay,
+                'shopId' => $shopId,
+                'mainId' => $mainId,
+                'hdId' => $hdId,
+                'hdName' => $hdName,
+                'onlinePay' => 1,
+                'amount' => $rechargeAmount,
+                'staffId' => $staffId,
+                'staffName' => $staffName,
+                'payStatus' => 0,
+                'payTime' => '0000-00-00 00:00:00',
+                'status' => 0,
+                'remark' => '',
+                'customId' => $customId,
+                'customName' => $customName,
+            ];
+            $respond = RechargeClass::addRecharge($rechargeData);
+            $id = $respond->id;
+            $recharge = RechargeClass::getLockById($id);
+            $params = [
+                'onlinePay' => 1,
+                'side' => 0,
+            ];
+            RechargeClass::complete($recharge, $payWay, $params);
+
+            //2、再销账
+            if (is_numeric($id)) {
+                $order = OrderClass::getById($id, true);
                 OrderClass::valid($order, $this->mainId);
                 SettleClass::confirmSettle($order, $payWay, $staff);
             } else {

+ 34 - 31
biz-hd/recharge/classes/RechargeClass.php

@@ -92,38 +92,41 @@ class RechargeClass extends BaseClass
         $shop = ShopClass::getById($shopId, true);
         $rechargeWeal = $shop->rechargeWeal ?? 0;
         $addGiveAmount = 0;
-        if ($rechargeWeal == 1 || $rechargeWeal == 2) {
-            $weal = MemberWealClass::getAllByCondition(['shopId' => $shopId], null, '*');
-            if (!empty($weal)) {
-                $weal = arrayUtil::arraySort($weal, 'level', SORT_ASC);
-                if ($rechargeWeal == 1) {
-                    //充值升级会员
-                    $newLevel = 0;
-                    foreach ($weal as $k => $v) {
-                        $thisRecharge = $v['recharge'] ?? 0;
-                        $thisLevel = $v['level'] ?? 0;
-                        if ($amount >= $thisRecharge) {
-                            $newLevel = $thisLevel;
+        //如果客户有本身有欠款,充值不享受任何福利
+        if ($custom->balance > 0) {
+            if ($rechargeWeal == 1 || $rechargeWeal == 2) {
+                $weal = MemberWealClass::getAllByCondition(['shopId' => $shopId], null, '*');
+                if (!empty($weal)) {
+                    $weal = arrayUtil::arraySort($weal, 'level', SORT_ASC);
+                    if ($rechargeWeal == 1) {
+                        //充值升级会员
+                        $newLevel = 0;
+                        foreach ($weal as $k => $v) {
+                            $thisRecharge = $v['recharge'] ?? 0;
+                            $thisLevel = $v['level'] ?? 0;
+                            if ($amount >= $thisRecharge) {
+                                $newLevel = $thisLevel;
+                            }
                         }
-                    }
-                    $params = [
-                        'style' => 0,
-                        'rechargeAmount' => floatval($amount),
-                        'onlinePay' => $onlinePay,
-                    ];
-                    if ($newLevel > $oldLevel) {
-                        CustomClass::levelChange($oldLevel, $newLevel, $shop, $custom, $hd, $params);
-                    }
-                } else {
-                    //充多少送多少
-                    foreach ($weal as $k => $v) {
-                        $thisRecharge = $v['recharge'] ?? 0;
-                        $thisGive = $v['give'] ?? 0;
-                        if ($amount >= $thisRecharge) {
-                            $recharge->giveAmount = $thisGive;
-                            $recharge->save();
-                            //增加赠送的金额
-                            $addGiveAmount = $thisGive;
+                        $params = [
+                            'style' => 0,
+                            'rechargeAmount' => floatval($amount),
+                            'onlinePay' => $onlinePay,
+                        ];
+                        if ($newLevel > $oldLevel) {
+                            CustomClass::levelChange($oldLevel, $newLevel, $shop, $custom, $hd, $params);
+                        }
+                    } else {
+                        //充多少送多少
+                        foreach ($weal as $k => $v) {
+                            $thisRecharge = $v['recharge'] ?? 0;
+                            $thisGive = $v['give'] ?? 0;
+                            if ($amount >= $thisRecharge) {
+                                $recharge->giveAmount = $thisGive;
+                                $recharge->save();
+                                //增加赠送的金额
+                                $addGiveAmount = $thisGive;
+                            }
                         }
                     }
                 }