Browse Source

Merge branch 'zhongqi-optimize' into zhongqi-itemUpdate

shish 3 tháng trước cách đây
mục cha
commit
7fc3bdd501

+ 3 - 3
app-ghs/controllers/TestController.php

@@ -822,10 +822,10 @@ class TestController extends BaseController
 
     public function actionClearQuery()
     {
-        $shopId = 10649;
+        $shopId = 31805;
         $shop = ShopClass::getById($shopId, true);
         if (empty($shop)) {
-            util::stop('没有找到门店20');
+            util::stop('没有找到门店信息呢');
         }
         $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
         $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
@@ -838,7 +838,7 @@ class TestController extends BaseController
             'lklCertificatePath' => $lklCertificatePath,
         ];
         $laResource = new Lakala($params);
-        $orderSn = 'CL29336665';
+        $orderSn = 'CL29366459';
         $queryParams = [
             'orderSn' => $orderSn,
             //'tradeNo' => '66222923861204',

+ 12 - 13
app-hd/controllers/CustomController.php

@@ -170,7 +170,7 @@ class CustomController extends BaseController
         util::complete('修改成功');
     }
 
-    //客户vip切换
+    //会员权限开关
     public function actionChangeVip()
     {
         $post = Yii::$app->request->post();
@@ -182,16 +182,15 @@ class CustomController extends BaseController
             util::fail('没有找到客户信息');
         }
         if ($custom->shopId != $this->shopId) {
-            util::fial('无权限修改');
+            util::fial('你不能操作');
         }
-        if (isset($this->shopAdmin->founder) == false || $this->shopAdmin->founder != 2) {
-            util::fail('管理员才能操作');
+        if (!isset($this->shopAdmin->founder) || $this->shopAdmin->founder != 2) {
+            util::fail('管才能操作');
         }
-
         $custom->vip = $vip;
         $custom->save();
-
-        util::complete('修改成功');
+        $hint = $vip == 1 ? '已开启' : '已关闭';
+        util::complete($hint);
     }
 
     //修改名称 ssh 2022096
@@ -279,7 +278,7 @@ class CustomController extends BaseController
             //已经删除的客户
             $sort = 'id ASC';
             $where['delStatus'] = 1;
-        }  else if ($type == 5) {
+        } else if ($type == 5) {
             //只显示VIP用户
             $sort = 'id ASC';
             $where['vip'] = 1;
@@ -310,8 +309,8 @@ class CustomController extends BaseController
         $list['balance'] = $all; //余额排行的总人数
         $list['buyAmount'] = $all; //消费排行的总人数
         $list['birth'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['birthdayTime>' => 0])); //有设置生日的总人数
-        $list['deleted']   = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['delStatus' => 1])); //被删除的总人数
-        $list['vip']   = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['vip' => 1])); //是vip的总人数
+        $list['deleted'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['delStatus' => 1])); //被删除的总人数
+        $list['vip'] = CustomClass::getCount(array_merge(['shopId' => $this->shopId], ['vip' => 1])); //是vip的总人数
 
         util::success($list);
     }
@@ -756,7 +755,7 @@ class CustomController extends BaseController
         // 1.重新统计客户的消费总额
         $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, forward, actPrice');
 
-        $buyAmount= 0;
+        $buyAmount = 0;
         if (!empty($orderList)) {
             foreach ($orderList as $order) {
                 if ($order['forward'] == 0) { //0 常规订单
@@ -774,8 +773,8 @@ class CustomController extends BaseController
         $c->save();
 
         // 2.更新此客户所对应花店的消费金额 expendAmount ---- xhHd -> expendAmount
-        HdClass::updateById($c->hdId, ['expendAmount'=>$buyAmount]);
+        HdClass::updateById($c->hdId, ['expendAmount' => $buyAmount]);
 
-        util::success(['customId'=>$customId, 'buyAmount'=>$buyAmount]);
+        util::success(['customId' => $customId, 'buyAmount' => $buyAmount]);
     }
 }

+ 2 - 2
app-hd/controllers/MemberLevelController.php

@@ -24,7 +24,7 @@ class MemberLevelController extends BaseController
             $member = [];
             if (!empty($list)) {
                 foreach ($list as $k => $val) {
-                    $name = $val['name'] ?? '普通会员';
+                    $name = $val['name'] ?? '会员';
                     $levelSn = $val['levelSn'] ?? 'general';
                     $level = $val['level'] ?? 1;
                     $amount = $val['amount'] ?? 0;
@@ -68,7 +68,7 @@ class MemberLevelController extends BaseController
             foreach ($data as $k => $v) {
                 $levelSn = $v['levelSn'] ?? 'general';
                 $level = $v['level'] ?? 1;
-                $name = $v['name'] ?? '普通会员';
+                $name = $v['name'] ?? '会员';
                 $amount = $v['amount'] ?? 0;
                 $it = [
                     'mainId' => $mainId,

+ 1 - 1
app-hd/controllers/OrderController.php

@@ -730,6 +730,7 @@ class OrderController extends BaseController
             //解决重复提交
             util::checkRepeatCommit($this->adminId . '_' . $dealPrice, 3);
 
+            $totalNum = 0;
             if ($dealPrice == 0) {
                 $productIds = [];
                 $hsIds = [];
@@ -754,7 +755,6 @@ class OrderController extends BaseController
                 $priceMap = \bizGhs\custom\classes\CustomClass::$levelPriceKeyMap;
                 $addPriceMap = \bizGhs\custom\classes\CustomClass::$levelAddPriceKeyMap;
                 $level = 0;
-                $totalNum = 0;
                 foreach ($productList as $currentProduct) {
                     $property = $currentProduct['property'] ?? 0;
                     $currentPrice = $currentProduct['unitPrice'] ?? 0;

+ 2 - 2
app-hd/controllers/ShopController.php

@@ -561,10 +561,10 @@ class ShopController extends BaseController
         $data = Yii::$app->request->post();
         $rechargeWeal = intval($data['rechargeRule']);
         $isVipMember = intval($data['isVipMember']);
-        if ($isVipMember == 1 && $data['vipAmount'] >= 0) {
+        if ($isVipMember == 1 && $data['vipAmount'] >= 0.01) {
             $reachVip = floatval($data['vipAmount']);
         } else {
-            $reachVip = -1;
+            $reachVip = 0;
         }
         $hbPayable = intval($data['hbPayable']);
         if ($rechargeWeal == 2 && $hbPayable == 0) {

+ 16 - 8
biz-ghs/order/classes/OrderClass.php

@@ -93,7 +93,6 @@ class OrderClass extends BaseClass
     const SEND_STATUS_COMPLETED = 2; //已送达
     const SEND_STATUS_CANCEL = 3; //取消
 
-
     //订单总流程数
     const TOTAL_FLOW = 3;
 
@@ -3135,21 +3134,30 @@ XL;
         // 排序并去重
         sort($ids);
         $ids = array_unique($ids);
+        
+        // 限制最多 90 单,避免 someTimeIds 过长(兼容原先业务逻辑限制)
+        if (count($ids) > 90) {
+            $ids = array_slice($ids, 0, 90);
+        }
+        
         $sameTimeIdsStr = implode(',', $ids);
         // 更新所有相关订单
-        if (!empty($ids)) {
+        if (!empty($ids) && in_array($id, $ids)) {
             self::updateByIds($ids, ['sameTimeIds' => $sameTimeIdsStr]);
         }
 
         //从原先同天内的订单中删除此次要改变的订单的订单号$id
-        $oldSameTimeIdsArr = explode(',', $oldSameTimeIds);
-        if (in_array($id, $oldSameTimeIdsArr)) {
-            $oldSameTimeIdsArr = array_diff($oldSameTimeIdsArr, [$id]);
-            $oldSameTimeIdsStr = implode(',', $oldSameTimeIdsArr);
-            if (!empty($oldSameTimeIdsArr)) {
-                self::updateByIds($oldSameTimeIdsArr, ['sameTimeIds' => $oldSameTimeIdsStr]);
+        if (!empty($oldSameTimeIds) && $oldSameTimeIds != $sameTimeIdsStr) {
+            $oldSameTimeIdsArr = explode(',', $oldSameTimeIds);
+            if (in_array($id, $oldSameTimeIdsArr)) {
+                $oldSameTimeIdsArr = array_diff($oldSameTimeIdsArr, [$id]);
+                $oldSameTimeIdsStr = implode(',', $oldSameTimeIdsArr);
+                if (!empty($oldSameTimeIdsArr)) {
+                    self::updateByIds($oldSameTimeIdsArr, ['sameTimeIds' => $oldSameTimeIdsStr]);
+                }
             }
         }
+        //noticeUtil::push("orderIds = {$sameTimeIdsStr}, sameTimeIdsStr: {$sameTimeIdsStr}");
     }
 
 }

+ 20 - 33
biz-ghs/order/services/OrderService.php

@@ -263,8 +263,19 @@ class OrderService extends BaseService
             $purchaseData['modifyPrice'] = $data['modifyPrice'];
         }
         $purchase = PurchaseClass::addPurchase($purchaseData, $ghs);
-        $purchaseId = $purchase->id ?? 0;
 
+        //开历史订单
+        $historyDate = $data['historyDate'] ?? '';
+        if (!empty($historyDate)) {
+            $currentPayTime = $historyDate . ' 12:00:00';
+            $returnOrder->payTime = $currentPayTime;
+
+            $purchase->payTime = $currentPayTime;
+            $purchase->save();
+            CustomDebtChangeClass::updateByCondition(['capitalType' => 10, 'relateId' => $returnOrder->id], ['payTime' => $currentPayTime]);
+        }
+
+        $purchaseId = $purchase->id ?? 0;
         $returnOrder->purchaseId = $purchaseId;
         $returnOrder->save();
 
@@ -295,18 +306,13 @@ class OrderService extends BaseService
             self::payAfter($returnOrder, $payWay);
 
             //开历史订单
-            $historyDate = $data['historyDate'] ?? '';
             if (!empty($historyDate)) {
-                $currentPayTime = $historyDate . ' 12:00:00';
-                $purchase->payTime = $currentPayTime;
-                $purchase->save();
-                $returnOrder->payTime = $currentPayTime;
-                $returnOrder->save();
+                //$returnOrder->payTime = $currentPayTime;
+                //$returnOrder->save();
                 //有修改账单日期需要更新到欠款变动明细,财务好对账,多个地方要同步修改,关键词 to_change_custom_debt_pay_time
-                CustomDebtChangeClass::updateByCondition(['capitalType' => 10, 'relateId' => $returnOrder->id], ['payTime' => $currentPayTime]);
 
                 //找到当前订单客户的账单日期为 $date 的所有订单,然后更新同天内的所有订单的 sameTimeIds(加此次要改变的订单的订单号$id),有多处调用,关键词 update_same_ids
-                OrderClass::updateSameTimeIds($returnOrder, $historyDate);
+                //OrderClass::updateSameTimeIds($returnOrder, $historyDate);
             }
 
             //不是预订单,并且供货商不是源花汇、小明鲜花、淄博花超、云漫梦金鹏、海翔,则订单直接完成掉。是预订单,则确认发货时直接完成掉。有多个地方要修改,请搜索关键词zjFinish
@@ -861,7 +867,9 @@ class OrderService extends BaseService
             $order->debtPrice = $order->orderPrice ?? 0;
         }
         $order->payStatus = 1;
-        $order->payTime = date("Y-m-d H:i:s");
+        if (!isset($order->payTime) || $order->payTime == '0000-00-00 00:00:00') {
+            $order->payTime = date("Y-m-d H:i:s");
+        }
         $order->save();
 
         //新订单进入队列,用于花材的销量统计
@@ -898,28 +906,7 @@ class OrderService extends BaseService
         StatKhCgClass::replace($order, $amount);
 
         //当天同个人同地址的订单汇总
-        $sameDate = date("Y_m_d");
-        $sameAddress = $order->showAddress ?? '';
-        $addressMd5 = md5($sameAddress);
-        $sameKey = $customId . '_' . $addressMd5 . '_' . $sameDate;
-        $sameString = Yii::$app->redis->executeCommand('GET', [$sameKey]);
-        if (!empty($sameString)) {
-            $newString = $sameString . ',' . $orderId;
-            $newIdsArray = explode(',', $newString);
-            if (count($newIdsArray) <= 90) {
-                Yii::$app->redis->executeCommand('SETEX', [$sameKey, 186400, $newString]);
-                foreach ($newIdsArray as $currentOrderId) {
-                    OrderClass::updateById($currentOrderId, ['sameTimeIds' => $newString]);
-                }
-                //noticeUtil::push($sameKey . '' . $sameAddress . " 当天汇总ids:" . $newString, '15280215347');
-            }
-        } else {
-            Yii::$app->redis->executeCommand('SETEX', [$sameKey, 186400, $orderId]);
-            $order->sameTimeIds = $orderId;
-            $order->save();
-            //noticeUtil::push($sameKey . '' . $sameAddress . " 当天汇总ids:" . $orderId, '15280215347');
-        }
-
+        OrderClass::updateSameTimeIds($order, substr($order->payTime, 0, 10));
     }
 
     //发起退款
@@ -1005,4 +992,4 @@ class OrderService extends BaseService
         return $saleRefund;
     }
 
-}
+}

+ 1 - 0
biz-hd/custom/classes/CustomClass.php

@@ -244,6 +244,7 @@ class CustomClass extends BaseClass
 
         //成长值变动记录
          $growthData = [
+             'shopId' => $shopId,
              'userId' => $custom->userId,
              'userName' => $custom->name,
              'event' => "管理员变更{$memberName}级,成长值从{$oldGrowth}变更为{$growth}",

+ 7 - 0
biz-hd/custom/models/Custom.php

@@ -12,6 +12,13 @@ class Custom extends Base
      */
     public $listend = true;
 
+    /**
+     * xhCustom 的 $notRecordGrowthAndIntegral 是否执行记录成功值与积分
+     *
+     * @var bool
+     */
+    public $recordGrowthAndIntegral = true;
+
     /**
      * mainId(运行时临时属性,不入库)。
      * 传递必要参数 mainId

+ 6 - 1
biz-hd/custom/observers/BuyAmountObserver.php

@@ -24,7 +24,7 @@ class BuyAmountObserver extends Behavior
 	{
 		/** @var ActiveRecord $model */
 		$model = $this->owner;
-		if ($model->listend === false) { //根据总开关判断是否执行记录积分与成长值变动
+		if ($model->listend === false) { //根据总开关判断是否执行记录
 		    return;
         }
 
@@ -59,6 +59,11 @@ class BuyAmountObserver extends Behavior
 		];
 		UserBuyAmountClass::add($consumeData);
 
+		// 判断是否执行记录成功值与积分
+		if ($model->recordGrowthAndIntegral === false) {
+		    return;
+        }
+
 		$oldGrowth = array_key_exists('growth', $event->changedAttributes)
 			? $event->changedAttributes['growth']
 			: $model->getAttribute('growth'); // changedAttributes 里没有 growth 时,说明这次更新没改 growth,这时直接取模型当前值即可(它就等于旧值)。

+ 3 - 0
biz-hd/order/classes/OrderClass.php

@@ -492,6 +492,9 @@ class OrderClass extends BaseClass
             if ($order->forward == 0) { //0 常规订单
                 $myCustom->recentExpend = date("Y-m-d H:i:s");
                 $myCustom->visitTime = date("Y-m-d H:i:s");
+                if ($payWay == dict::getDict('payWay', 'balancePay')) {
+                    $myCustom->recordGrowthAndIntegral = false;
+                }
                 $myCustom->buyAmount = bcadd($myCustom->buyAmount, $order->realPrice, 2);
                 $myCustom->eventRemark = trim($eventPrefix . '下单' . $orderSnText);
             } elseif ($order->forward == 1) { //1 售后付款单(红冲)

+ 53 - 0
biz-hd/recharge/classes/RechargeClass.php

@@ -15,6 +15,8 @@ use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\SettleClass;
 use bizHd\shop\classes\ShopExtClass;
 use bizHd\shop\classes\MainClass;
+use bizHd\user\classes\UserGrowthClass;
+use bizHd\user\classes\UserIntegralClass;
 use common\components\dict;
 use common\components\lakala\Lakala;
 use common\components\noticeUtil;
@@ -264,12 +266,27 @@ class RechargeClass extends BaseClass
             $hd->balanceGive = bcadd($hd->balanceGive, $balanceGive, 2);
         }
         //充值的余额
+        $beforeBalancePay = $custom->balancePay;
         $custom->balancePay = bcadd($custom->balancePay, $balancePay, 2);
         $hd->balancePay = bcadd($hd->balancePay, $balancePay, 2);
         //总余额
         $totalBalance = bcadd($balancePay, $balanceGive, 2);
         $custom->balance = bcadd($custom->balance, $totalBalance, 2);
         $hd->balance = bcadd($hd->balance, $totalBalance, 2);
+        $changeAmount = bccomp($beforeBalancePay, 0, 2) === -1 ? $custom->balancePay : $balancePay;  // 根据余额欠款,计算变化金额,用于计算积分与成长值
+        $addIntegralAndGrowth = bccomp($changeAmount, 0, 2) === 1; // 如果变化金额大于0,则计算积分与成长值
+        if ($addIntegralAndGrowth) {
+            //积分与成长值
+            $custom->integral = bcadd($custom->integral, $changeAmount);
+            $custom->growth = bcadd($custom->growth, $changeAmount);
+
+            // 由于没有更新 buyAmount,所以得额外添加更新等级
+            $memberData = CustomClass::getCustomExpenseLevel($custom->growth, $mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+            CustomClass::updateById($customId, [
+                'member' => (int) ($memberData['level'] ?? 0),
+                'memberName' => (string) ($memberData['name'] ?? ''),
+            ]);
+        }
         $custom->save();
         $hd->save();
 
@@ -464,6 +481,42 @@ class RechargeClass extends BaseClass
                 ShopMoneyClass::skRecharge($cashData, $main);
             }
         }
+
+        if ($addIntegralAndGrowth) {
+            $createTime = date('Y-m-d H:i:s');
+            //成长值变动记录
+            $growthData = [
+                'shopId' => $shopId,
+                'userId' => $custom->userId,
+                'userName' => $custom->name,
+                'event' => $event,
+                'relateId' => $relateId,
+                'relateType' => 0,
+                'num' => $changeAmount,
+                'growth' => $custom->growth,
+                'staffId' => $staffId, //操作人(员工id)
+                'staffName' => $staffName, //员工名称
+                'createTime' => $createTime,
+            ];
+            UserGrowthClass::add($growthData);
+
+            //积分变动记录
+            $integralData = [
+                'shopId' => $shopId,
+                'userId' => $custom->userId,
+                'userName' => $custom->name,
+                'event' => $event,
+                'relateId' => $relateId,
+                'relateType' => 0,
+                'num' => $changeAmount,
+                'integral' => $custom->integral,
+                'staffId' => $staffId, //操作人(员工id)
+                'staffName' => $staffName, //员工名称
+                'createTime' => $createTime,
+            ];
+            UserIntegralClass::add($integralData);
+        }
+
         return $returnChange;
     }
 

+ 1 - 1
biz-hd/user/services/UserService.php

@@ -149,7 +149,7 @@ class UserService extends BaseService
         }
     }
 
-    //注册成为普通会员(非VIP),并更新用户相关信息 ssh 2019.9.7
+    //注册成为会员,并更新用户相关信息 ssh 2019.9.7
     public static function becomeMember($user, $merchant, $data)
     {
         //合并店长后台添加的客户

+ 1 - 1
biz-mall/user/services/UserService.php

@@ -141,7 +141,7 @@ class UserService extends BaseService
 		}
 	}
 	
-	//注册成为普通会员(非VIP),并更新用户相关信息 ssh 2019.9.7
+	//注册成为会员,并更新用户相关信息 ssh 2019.9.7
 	public static function becomeMember($user, $merchant, $data)
 	{
 		//合并店长后台添加的客户

+ 2 - 2
common/components/dict.php

@@ -272,9 +272,9 @@ class dict
         ],
         //零售会员的等级
         'memberLevel' => ['general' => 1, 'silver' => 2, 'gold' => 3, 'diamond' => 4, 'blackGold' => 5,],
-        'memberLevelName' => [1 => '普通会员', 2 => '白银会员', 3 => '黄金会员', 4 => '钻石会员', 5 => '黑金会员'],
+        'memberLevelName' => [1 => '会员', 2 => '白银会员', 3 => '黄金会员', 4 => '钻石会员', 5 => '黑金会员'],
         'memberLevelMap' => [
-            ['name' => '普通会员', 'level' => 1, 'levelSn' => 'general', 'amount' => 3000,],
+            ['name' => '会员', 'level' => 1, 'levelSn' => 'general', 'amount' => 3000,],
             ['name' => '白银会员', 'level' => 2, 'levelSn' => 'silver', 'amount' => 6000,],
             ['name' => '黄金会员', 'level' => 3, 'levelSn' => 'gold', 'amount' => 10000,],
             ['name' => '钻石会员', 'level' => 4, 'levelSn' => 'diamond', 'amount' => 20000,],

+ 70 - 62
console/controllers/CustomController.php

@@ -9,6 +9,8 @@ use bizHd\custom\classes\CustomClass;
 use bizHd\custom\classes\HdClass;
 use bizHd\member\classes\MemberLevelClass;
 use bizHd\purchase\classes\PurchaseClass;
+use bizHd\shop\models\Shop;
+use common\components\dict;
 use common\components\noticeUtil;
 use common\components\util;
 use bizHd\user\classes\UserClass;
@@ -148,76 +150,82 @@ class CustomController extends Controller
     // 把所有客户的累计消费和成长值、积分都刷新一下
     public function actionRefreshCustomData()
     {
-
-        ini_set('memory_limit', '2045M');
-        set_time_limit(0);
-
-        $redisKey = 'refresh_custom_data_processed_shops';
-
-        // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据,每次取出500个进行处理
-        $query = \bizHd\shop\models\Shop::find()
-            ->select('id, mainId')
-            ->where(['ptStyle' => 1])
-            ->orderBy('id DESC')
-            ->asArray();
-
-        // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
-        foreach ($query->batch(500) as $allShops) {
-            if (!empty($allShops)) {
-                foreach ($allShops as $shop) {
-                    $shopId = $shop['id'];
-                    $mainId = $shop['mainId'];
-
-                    // 判断是否已经执行过,执行过则跳过
-                    $hasProcessed = Yii::$app->redis->executeCommand('SISMEMBER', [$redisKey, $shopId]);
-                    if ($hasProcessed) {
-                        continue;
-                    }
-
-                    $customs = CustomClass::getAllByCondition(['shopId' => $shopId], null, 'id, userId, buyAmount, growth, member, memberName', null, true);
-                    $levelDatas = MemberLevelClass::getAllByCondition(['mainId' => $mainId], 'amount DESC', 'id, name, level, amount');
-                    if (!empty($customs) && !empty($levelDatas)) {
-                        foreach ($customs as $c) {
-                            $buyAmount = 0;
-                            // 获取所有零售订单,计算消费金额
-                            $orderList = \bizHd\order\classes\OrderClass::getAllByCondition(['customId' => $c->id], null, 'id, forward, actPrice');
-                            if (!empty($orderList)) {
-                                foreach ($orderList as $order) {
-                                    if ($order['forward'] == 0) { //0 常规订单
-                                        $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
-                                    } elseif ($order['forward'] == 1) { //1 售后付款单(红冲)
-                                        $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
-                                    } else {
-                                        Yii::info('订单类型不存在,订单ID:' . $order['id']);
-                                        continue;
+        try {
+            ini_set('memory_limit', '2045M');
+            set_time_limit(0);
+
+            // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据,每次取出500个进行处理
+            $query = Shop::find()
+                ->select('id, mainId')
+                ->where(['ptStyle' => 1])
+                ->orderBy('id DESC')
+                ->asArray();
+
+            // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
+            foreach ($query->batch(500) as $allShops) {
+                if (!empty($allShops)) {
+                    foreach ($allShops as $shop) {
+                        $shopId = $shop['id'];
+                        $mainId = $shop['mainId'];
+
+                        echo '门店id:' . $shopId;
+
+                        $customList = CustomClass::getAllByCondition(['shopId' => $shopId], null, 'id, userId, balance, buyAmount, growth, integral, member, memberName', null, true);
+                        $levelData = MemberLevelClass::getAllByCondition(['mainId' => $mainId], 'amount DESC', 'id, name, level, amount');
+                        if (!empty($customList)) {
+                            foreach ($customList as $custom) {
+                                $buyAmount = 0;
+                                // 获取所有零售订单,计算消费金额
+                                $orderList = \bizHd\order\classes\OrderClass::getAllByCondition(['customId' => $custom->id, 'payStatus' => 1], null, 'id, forward, actPrice, payWay');
+                                if (!empty($orderList)) {
+                                    foreach ($orderList as $order) {
+                                        if ($order['forward'] == 0) { //0 常规订单
+                                            $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
+                                        } else { //1 红冲
+                                            $buyAmount = bcsub($buyAmount, $order['actPrice'], 2);
+                                        }
                                     }
                                 }
+                                $custom->buyAmount = $buyAmount;
+                                $balance = $custom->balance ?? 0;
+                                if ($balance > 0) {
+                                    $total = bcadd($balance, $buyAmount, 2);
+                                } else {
+                                    $total = $buyAmount;
+                                }
+                                $custom->growth = $total;
+                                $custom->integral = $total;
+//echo " customId:" . $custom->id;
+                                // 根据 growth 设置等级
+                                $memberData = CustomClass::getCustomExpenseLevel($custom->growth, $mainId, $levelData); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+//echo "--+--- ";
+                                $level = $memberData['level'] ?? 0;
+                                $level = trim($level);
+                                $level = floatval($level);
+                                $memberName = $memberData['name'] ?? '';
+                                $memberName = trim($memberName);
+//echo $level."+".$memberName;
+                                $custom->member = $level;
+                                $custom->memberName = $memberName;
+                                //$custom->listend = false; //关闭对 xhCustom 的 buyAmount 变动监听
+                                $custom->save();
+//echo " 0000 \n";
+                                // 更新客户所对应花店的消费金额
+                                $hdId = $custom->hdId;
+                                if (!empty($hdId)) {
+                                    HdClass::updateById($hdId, ['expendAmount' => $buyAmount]);
+                                }
+
                             }
-                            $c->buyAmount = $buyAmount;
-                            $c->growth = $buyAmount;
-                            $c->integral = $buyAmount;
-
-                            // 根据 growth 设置等级
-                            $memberData = CustomClass::getCustomExpenseLevel($c->growth, $mainId, $levelDatas); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
-                            $c->member = $memberData['level'];
-                            $c->memberName = $memberData['name'];
-                            $c->listend = false; //关闭对 xhCustom 的 buyAmount 变动监听
-                            $c->save();
-
-                            // 更新客户所对应花店的消费金额
-                            HdClass::updateByCondition(['shopId' => $shopId, 'userId' => $c->userId], ['expendAmount' => $buyAmount]);
                         }
+//echo "\n";
                     }
-
-                    // 记录该 shopId 已经执行完成
-                    Yii::$app->redis->executeCommand('SADD', [$redisKey, $shopId]);
                 }
+                echo "end\n";
             }
+        } catch (\Exception $e) {
+            Yii::error('把所有客户的累计消费和成长值、积分都刷新一下脚本执行失败,原因:' . $e->getMessage());
         }
-
-        // 脚本执行完之后,清除缓存
-        Yii::$app->redis->executeCommand('DEL', [$redisKey]);
-
     }
 
     //批量创建客户