Ver Fonte

更新:
1.订单根据forward进行不同处理
2.客户级别的评定变量修改为使用 xhCustom表的 growth(原先是 bugAmount)
3.补积分记录:把 xhCustom表的 integral 字段变动加上
4. 新增定时脚本:把客户的阴历日期转换为阳历日期
5.新增临时接口 actionRefreshCustomData:把所有客户的累计消费和成长值、积分都刷新一下

shizhongqi há 5 meses atrás
pai
commit
4f26e06a51

+ 59 - 9
app-hd/controllers/CustomController.php

@@ -10,6 +10,7 @@ use biz\sj\services\MerchantAssetService;
 use biz\sj\services\MerchantRemarkService;
 use bizHd\member\classes\MemberLevelClass;
 use bizHd\order\classes\OrderClass;
+use bizHd\shop\classes\ShopClass;
 use bizHd\stat\classes\StatVisitClass;
 use bizHd\user\services\UserAssetService;
 use bizHd\user\services\UserGrowthService;
@@ -709,31 +710,80 @@ class CustomController extends BaseController
     {
         $post = Yii::$app->request->post();
         $customId = $post['customId'];
-        $mainId = $this->mainId;
 
         $c = CustomClass::getLockById($customId);
 
         // 1.重新统计客户的消费总额
-        $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, actPrice');
+        $orderList = OrderClass::getAllByCondition(['customId' => $customId], null, 'id, forward, actPrice');
 
         $buyAmount= 0;
         if (!empty($orderList)) {
             foreach ($orderList as $order) {
-                $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
+                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('订单类型不存在');
+                    continue;
+                }
             }
         }
         $c->buyAmount = $buyAmount;
-
-        // 根据 byuAmount 设置等级
-        $memberData = CustomClass::getCustomExpenseLevel($buyAmount, $mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
-        $c->member = $memberData['level'];
-        $c->memberName = $memberData['name'];
         $c->save();
 
-
         // 2.更新此客户所对应花店的消费金额 expendAmount ---- xhHd -> expendAmount
         HdClass::updateById($c->hdId, ['expendAmount'=>$buyAmount]);
 
         util::success(['customId'=>$customId, 'buyAmount'=>$buyAmount]);
     }
+
+    // 把所有客户的累计消费和成长值、积分都刷新一下
+    public function actionRefreshCustomData()
+    {
+        // 1. 查询 xhShop 表,获取所有 ptStyle = 1 的门店数据
+        $allShops = ShopClass::getAllByCondition(['ptStyle'=>1, 'status'=>1], 'id ASC', 'id, mainId');
+        // 2. 把每个门店下的所有用户进行遍历,刷新他们的累计消费和成长值、积分
+        if (!empty($allShops)) {
+            foreach ($allShops as $shop) {
+                $shopId = $shop['id'];
+                $mainId = $shop['mainId'];
+                $customs = CustomClass::getAllByCondition(['shopId' => $shopId], null, 'id, userId, buyAmount, 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 = 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('订单类型不存在');
+                                    continue;
+                                }
+                            }
+                        }
+                        $c->buyAmount = $buyAmount;
+                        $c->growth = intval($buyAmount);
+                        $c->integral = intval($buyAmount);
+
+                        // 根据 growth 设置等级
+                        $memberData = CustomClass::getCustomExpenseLevel($c->growth, $mainId, $levelDatas); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+                        $c->member = $memberData['level'];
+                        $c->memberName = $memberData['name'];
+                        $c->save();
+
+                        // 更新客户所对应花店的消费金额
+                        HdClass::updateByCondition(['shopId'=>$shopId, 'userId'=>$c->userId], ['expendAmount'=>$buyAmount]);
+                    }
+                }
+            }
+        }
+        
+        util::complete();
+    }
 }

+ 4 - 2
app-hd/controllers/RefundController.php

@@ -263,11 +263,13 @@ class RefundController extends BaseController
             }
             $transaction->commit();
 
-            //售后之后,累计消费回退 -- 表:xhCustom -> buyAmount,xhHd -> expendAmount
+            //售后之后,累计消费、积分、成长值回退 -- 表:xhCustom -> buyAmount、integral、growth,xhHd -> expendAmount
             $custom = CustomClass::getLockById($order->customId);
             if (!empty($custom)) {
                 $custom->buyAmount = bcsub($custom->buyAmount, $post['price'], 2);
-                $memberData = CustomClass::getCustomExpenseLevel($custom->buyAmount, $this->mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+                $custom->integral = $custom->integral - intval($post['price']);
+                $custom->growth = $custom->growth - intval(post['price']);
+                $memberData = CustomClass::getCustomExpenseLevel($custom->growth, $this->mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
                 $custom->member = $memberData['level'];
                 $custom->memberName = $memberData['name'];
                 $custom->save();

+ 42 - 20
biz-hd/custom/classes/CustomClass.php

@@ -11,6 +11,7 @@ use bizHd\member\classes\MemberLevelClass;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\SettleClass;
 use bizHd\shop\classes\ShopClass;
+use bizHd\user\services\UserGrowthService;
 use common\components\dict;
 use common\components\imgUtil;
 use common\components\noticeUtil;
@@ -196,11 +197,7 @@ class CustomClass extends BaseClass
         $beforeName = $before['name'] ?? '普通客户';
         $discount = $current['discount'] ?? 1;
         $memberName = $current['name'] ?? '';
-
-        $custom->member = $newLevel;
-        $custom->discount = $discount;
-        $custom->memberName = $memberName;
-        $custom->save();
+        $oldGrowth = $custom->growth;
 
         $hd->member = $newLevel;
         $hd->discount = $discount;
@@ -234,6 +231,32 @@ class CustomClass extends BaseClass
             'staffName' => $staffName,
         ];
         MemberChangeClass::add($change);
+
+        $custom->member = $newLevel;
+        $custom->discount = $discount;
+        $custom->memberName = $memberName;
+        //成长值变更
+        $growth = $current['amount'] ?? 0;
+        $custom->growth = $growth;
+        $custom->save();
+
+        //成长值变动记录
+        $growthData = [
+            'userId' => $custom->userId,
+            'userName' => $custom->name,
+            'sjId' => $custom->sjId,
+            'relateId' => 0,
+            'growth' => $growth,
+            'num' => $custom->growth - $oldGrowth,
+            'io' => 0,
+            'payWay' => 0,
+            'event' => "管理员变更{$memberName}级,成长值从{$oldGrowth}变更为{$growth}",
+            'operatorId' => $staffId,
+            'createTime' => date('Y-m-d H:i:s'),
+            'gainType' => 0,
+            'addTime' => time(),
+        ];
+        UserGrowthService::add($growthData);
     }
 
     //客户采购欠款金额增加,如果有余额时,要进行欠款销账 ssh 20250715
@@ -872,27 +895,26 @@ class CustomClass extends BaseClass
         $mainId = $data['mainId'];
         $customs = self::getAllByCondition(['shopId' => $shopId], null, 'id, userId, buyAmount, member, memberName', null, true);
         $levelDatas = MemberLevelClass::getAllByCondition(['mainId' => $mainId], 'amount DESC', 'id, name, level, amount');
-        if (!empty($customs)) {
+        if (!empty($customs) && !empty($levelDatas)) {
             foreach ($customs as $c) {
-                $buyAmount = 0;
-
-                // 获取所有零售订单,计算消费金额
-                $orderList = \bizHd\order\classes\OrderClass::getAllByCondition(['customId' => $c->id], null, 'id, actPrice');
-                if (!empty($orderList)) {
-                    foreach ($orderList as $order) {
-                        $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
-                    }
-                }
-                $c->buyAmount = $buyAmount;
-
-                // 根据 byuAmount 设置等级
-                $memberData = self::getCustomExpenseLevel($buyAmount, $mainId, $levelDatas); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+                // $buyAmount = 0;
+                // // 获取所有零售订单,计算消费金额
+                // $orderList = \bizHd\order\classes\OrderClass::getAllByCondition(['customId' => $c->id], null, 'id, actPrice');
+                // if (!empty($orderList)) {
+                //     foreach ($orderList as $order) {
+                //         $buyAmount = bcadd($buyAmount, $order['actPrice'], 2);
+                //     }
+                // }
+                // $c->buyAmount = $buyAmount;
+
+                // 根据 growth 设置等级
+                $memberData = self::getCustomExpenseLevel($c->growth, $mainId, $levelDatas); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
                 $c->member = $memberData['level'];
                 $c->memberName = $memberData['name'];
                 $c->save();
 
                 // 更新客户所对应花店的消费金额
-                HdClass::updateByCondition(['shopId'=>$shopId, 'userId'=>$c->userId], ['expendAmount'=>$buyAmount]);
+                // HdClass::updateByCondition(['shopId'=>$shopId, 'userId'=>$c->userId], ['expendAmount'=>$buyAmount]);
             }
         }
         return true;

+ 18 - 5
biz-hd/order/classes/OrderClass.php

@@ -456,18 +456,31 @@ 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");
+                $myCustom->buyAmount = bcadd($myCustom->buyAmount, $order->realPrice, 2);
+                $myCustom->growth = $myCustom->growth + intval($order->realPrice);
+                $myCustom->integral = $myCustom->integral + intval($order->realPrice);
+            } elseif ($order->forward == 1) { //1 售后付款单(红冲)
+                $myCustom->buyAmount = bcsub($myCustom->buyAmount, $order->realPrice, 2);
+                $myCustom->growth = $myCustom->growth - intval($order->realPrice);
+                $myCustom->integral = $myCustom->integral - intval($order->realPrice);
+            } else {
+                util::fail('订单类型不存在');
             }
-            $myCustom->buyAmount = bcadd($myCustom->buyAmount, $order->realPrice, 2);
-            $memberData = CustomClass::getCustomExpenseLevel($myCustom->buyAmount, $order->mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
+            $memberData = CustomClass::getCustomExpenseLevel($myCustom->growth, $order->mainId); // 设置等级多处需要同步修改的,请搜索:getCustomExpenseLevel
             $myCustom->member = $memberData['level'];
             $myCustom->memberName = $memberData['name'];
             $myCustom->save();
 
-            $hdId = $myCustom->hdId;
-            $hd = HdClass::getLockById($hdId);
+            $hd = HdClass::getLockById($myCustom->hdId);
             //$hd = HdClass::getByCondition(['shopId'=>$order->shopId, 'userId'=>$order->userId], true, false, 'id,customId,expendAmount');
             if (!empty($hd)) {
-                $hd->expendAmount = bcadd($hd->expendAmount, $order->realPrice, 2);
+                if ($order->forward == 0) { //0 常规订单
+                    $hd->expendAmount = bcadd($hd->expendAmount, $order->realPrice, 2);
+                } elseif ($order->forward == 1) { //1 售后付款单(红冲)
+                    $hd->expendAmount = bcsub($hd->expendAmount, $order->realPrice, 2);
+                } else {
+                    util::fail('订单类型不存在');
+                }
                 $hd->save();
             }
         }

+ 0 - 15
biz-hd/user/classes/UserGrowthClass.php

@@ -2,24 +2,9 @@
 
 namespace bizHd\user\classes;
 
-use biz\sj\classes\MerchantAssetClass;
-use biz\sj\services\MerchantService;
-use bizHd\message\classes\ChatClass;
-use bizHd\user\services\UserIntegralService;
-use common\components\business;
-use common\components\dict;
-use common\components\util;
-use common\services\ImageService;
-use common\services\xhMerchantExtendService;
-use common\services\xhUserCapitalService;
-use common\services\xhUserIntegralService;
-use common\services\xhUserMergeService;
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class UserGrowthClass extends BaseClass
 {
-	
 	public static $baseFile = '\bizHd\user\models\UserGrowth';
-	
 }

+ 0 - 2
biz-hd/user/models/UserGrowth.php

@@ -6,10 +6,8 @@ use bizHd\base\models\Base;
 
 class UserGrowth extends Base
 {
-	
 	public static function tableName()
 	{
 		return 'xhUserGrowth';
 	}
-	
 }

+ 0 - 14
biz-hd/user/services/UserGrowthService.php

@@ -3,22 +3,8 @@
 namespace bizHd\user\services;
 
 use bizHd\base\services\BaseService;
-use biz\sj\classes\MerchantAssetClass;
-use biz\sj\services\MerchantAssetService;
-use biz\sj\services\MerchantExtendService;
-use bizHd\order\services\OrderService;
-use bizHd\user\classes\UserClass;
-use common\components\util;
-use common\components\validate;
-use common\services\ImageService;
-use common\services\xhMerchantExtendService;
-use common\services\xhMerchantService;
-use Yii;
-use common\components\wxUtil;
 
 class UserGrowthService extends BaseService
 {
-	
 	public static $baseFile = '\bizHd\user\classes\UserGrowthClass';
-	
 }

+ 37 - 10
console/controllers/CustomController.php

@@ -2,23 +2,16 @@
 
 namespace console\controllers;
 
-use biz\ghs\classes\GhsClass;
 use biz\shop\classes\ShopClass;
-use biz\shop\services\ShopAdminService;
-use biz\sj\classes\SjClass;
-use bizGhs\admin\classes\AdminClass;
-use bizGhs\custom\classes\CustomClass;
 use bizGhs\custom\models\Custom;
 use bizGhs\order\classes\OrderClass;
+use bizHd\custom\classes\CustomClass;
 use bizHd\purchase\classes\PurchaseClass;
-use bizHd\saas\classes\ApplyClass;
-use bizHd\saas\services\ApplyService;
-use common\components\dict;
 use common\components\noticeUtil;
-use common\components\stringUtil;
 use common\components\util;
+use bizHd\user\classes\UserClass;
+use Overtrue\ChineseCalendar\Calendar;
 use yii\console\Controller;
-use Yii;
 
 class CustomController extends Controller
 {
@@ -110,6 +103,40 @@ class CustomController extends Controller
 
     }
 
+    //每天凌晨2点执行,取出所有 lunar==1 的 且 birthdayTime 小于当前时间的客户,然后把他们的阴历转阳历,然后更新他们的 birthdayTime
+    public function actionUpdateBirthday()
+    {
+        $calendar = new Calendar();
+        $customList = CustomClass::getAllByCondition(['lunar' => 1, 'birthdayTime<' => time()], null, 'id, userId, birthday, birthdayTime, birthdayMonth, birthdayDate', null, true);
+        foreach ($customList as $custom) {
+            $birthdayMonth = $custom->birthdayMonth;
+            $birthdayDate = $custom->birthdayDate;
+            $year = date("Y");
+            // 农历转公历
+            $result = $calendar->lunar($year, $birthdayMonth, $birthdayDate);
+            $month = $result['gregorian_month'];
+            $day = $result['gregorian_day'];
+            $birthday = $year . '-' . $month . '-' . $day;
+
+            // 如果今年的生日已经过去,则计算明年的生日
+            if (strtotime($birthday) < strtotime(date('Y-m-d'))) {
+                $year++;
+                $result = $calendar->lunar($year, $birthdayMonth, $birthdayDate);
+                $month = $result['gregorian_month'];
+                $day = $result['gregorian_day'];
+                $birthday = $year . '-' . $month . '-' . $day;
+            }
+            $custom->birthday = $birthday;
+            $custom->birthdayTime = strtotime($birthday);
+            $custom->save();
+
+            UserClass::updateById($custom->userId, [
+                'birthday' => $birthday,
+                'birthdayTime' => $custom->birthdayTime
+            ]);
+        }
+    }
+
     //批量创建客户
     private function createCustomer()
     {