Przeglądaj źródła

修复批发客户累计消费统计

shizhongqi 7 miesięcy temu
rodzic
commit
02f48d639f

+ 30 - 0
app-ghs/controllers/CustomController.php

@@ -1248,4 +1248,34 @@ class CustomController extends BaseController
         util::complete('修改成功');
     }
 
+    public function actionRefreshBuyamount()
+    {
+        $customId = intval(Yii::$app->request->get('customId'));
+        if ($customId <= 0) {
+            util::fail('客户ID参数错误');
+        }
+
+        $custom = CustomClass::getById($customId, true);
+        CustomClass::valid($custom, $this->shopId);
+        $ghsId = $custom->ghsId ?? 0;
+        $ghs = GhsClass::getById($ghsId, true);
+        if (empty($ghs)) {
+            util::fail('客户信息有问题');
+        }
+        $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, actPrice');
+        $buyAmount = 0;
+        if (!empty($orderList)) {
+            foreach ($orderList as $order) {
+                $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
+            }
+        }
+        
+        $custom->buyAmount = $buyAmount;
+        $custom->save();
+
+        $ghs->expendAmount = $buyAmount;
+        $ghs->save();
+
+        util::success(['buyAmount' => $buyAmount]);
+    }
 }

+ 0 - 3
app-hd/controllers/RefundController.php

@@ -6,14 +6,11 @@ use biz\shop\classes\ShopExtClass;
 use bizHd\custom\classes\CustomClass;
 use bizHd\hb\classes\HbClass;
 use bizHd\order\classes\OrderClass;
-use bizHd\order\classes\OrderGoodsClass;
-use bizHd\order\classes\OrderItemClass;
 use bizHd\order\services\OrderService;
 use bizHd\refund\classes\HdRefundClass;
 use bizHd\refund\classes\HdRefundGoodsClass;
 use bizHd\refund\classes\HdRefundItemClass;
 use bizHd\refund\services\HdRefundService;
-use common\components\noticeUtil;
 use Yii;
 use common\components\util;
 

+ 5 - 0
biz-ghs/order/classes/RefundOrderClass.php

@@ -249,6 +249,11 @@ class RefundOrderClass extends BaseClass
         if (empty($custom)) {
             util::fail('没有找到客户');
         }
+        // 根据 $refundPrice 更新累计消费 buyAmount
+        $buyAmount = bcsub($custom->buyAmount, $refundPrice, 2);
+        $custom->buyAmount = $buyAmount;
+        $custom->save();
+
 
         if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
             //退款流程

+ 5 - 0
biz-hd/cg/classes/CgRefundClass.php

@@ -248,6 +248,11 @@ class CgRefundClass extends BaseClass
         if (empty($ghs)) {
             util::fail('没有找到供货商');
         }
+        // 根据 $refundPrice 更新消费金额 expendAmount
+        $expendAmount = bcsub($ghs->expendAmount, $refundPrice, 2);
+        $ghs->expendAmount = $expendAmount;
+        $ghs->save();
+
 
         if ($onlinePay == dict::getDict('onlinePay', 'yes')) {
             if ($payWay == dict::getDict('payWay', 'wxPay') || $payWay == dict::getDict('payWay', 'alipay')) {