Browse Source

1. 未填写生日仅在选择"全部"选项时显示

2. 优化旧的生日修改接口,修改的底层实现放到 biz-hd/custom/classes/CustomClass.php

3. app-hd/controllers/BirthdayGiftController.php 新增修改生日接口 actionModifyBirthday
shizhongqi 2 tháng trước cách đây
mục cha
commit
51dad2abe6

+ 7 - 0
app-hd/controllers/BirthdayGiftController.php

@@ -50,6 +50,13 @@ class BirthdayGiftController extends BaseController
         util::fail('没有需要通知的明日生日客户');
     }
 
+    public function actionModifyBirthday()
+    {
+        $get = Yii::$app->request->get();
+        BirthdayGiftClass::modifyBirthday($this->shop, $get);
+        util::complete('修改成功');
+    }
+
     public function actionPrint()
     {
         $get = Yii::$app->request->get();

+ 2 - 65
app-hd/controllers/CustomController.php

@@ -25,7 +25,6 @@ use biz\sj\services\MerchantExtendService;
 use bizHd\message\services\SmsService;
 use bizHd\user\classes\UserClass;
 use yii\helpers\Json;
-use Overtrue\ChineseCalendar\Calendar;
 
 class CustomController extends BaseController
 {
@@ -35,71 +34,9 @@ class CustomController extends BaseController
     //修改生日 ssh 20250814
     public function actionModifyBirthday()
     {
-        date_default_timezone_set('PRC');
-
         $get = Yii::$app->request->get();
         $customId = $get['customId'];
-        $custom = CustomClass::getById($customId, true);
-        if (empty($custom)) {
-            util::fail('没有找到客户');
-        }
-        $shopId = $this->shopId;
-        if ($custom->shopId != $shopId) {
-            util::fail('不是你的客户');
-        }
-        $lunar = $get['lunar'] ?? 0;
-        $birthdayMonth = $get['birthdayMonth'] ?? 1;
-        if ($birthdayMonth > 12 || $birthdayMonth < 1) {
-            util::fail('月份必须1到12月');
-        }
-        $birthdayDate = $get['birthdayDate'] ?? 1;
-        if ($birthdayDate > 31 || $birthdayDate < 1) {
-            util::fail('日期必须1到31号');
-        }
-
-        $userId = $custom->userId;
-        $user = UserClass::getById($userId, true);
-        if (empty($user)) {
-            util::fail('客户信息缺失');
-        }
-        if ($lunar == 1 && $custom->birthdayDate == 31) {
-            util::fail('农历没有31号');
-        }
-
-        $calendar = new Calendar();
-        if ($lunar == 1) {
-            try {
-                $result = $calendar->lunar(date("Y"), $birthdayMonth, $birthdayDate);
-            } catch (\InvalidArgumentException $e) {
-                $msg = $e->getMessage();
-                util::fail($msg);
-            }
-            //农历转阳历,有多处使用,需要同步修改,关键词 change_my_birthday
-            $month = $result['gregorian_month'] ?? 1;
-            $date = $result['gregorian_day'] ?? 1;
-            $birthday = date("Y") . '-' . $month . '-' . $date;
-        } else {
-            $birthday = date("Y") . '-' . $birthdayMonth . '-' . $birthdayDate;
-        }
-        $birthdayTime = strtotime($birthday);
-
-        if (getenv('YII_ENV') != 'dev' && $user->birthdaySet == 1) {
-            util::fail('客户已填写,不能修改');
-        }
-        //用户自己没有设置过生日,直接改
-        $custom->lunar = $lunar;
-        $custom->birthdayDate = $birthdayDate;
-        $custom->birthdayMonth = $birthdayMonth;
-        $custom->birthday = $birthday;
-        $custom->birthdayTime = $birthdayTime;
-        $custom->save();
-
-        $user->lunar = $lunar;
-        $user->birthdayDate = $birthdayDate;
-        $user->birthdayMonth = $birthdayMonth;
-        $user->birthday = $birthday;
-        $user->birthdayTime = $birthdayTime;
-        $user->save();
+        CustomClass::modifyBirthday($customId, $this->shopId, $get);
         util::complete('修改成功');
     }
 
@@ -777,4 +714,4 @@ class CustomController extends BaseController
 
         util::success(['customId' => $customId, 'buyAmount' => $buyAmount]);
     }
-}
+}

+ 22 - 6
biz-hd/birthday/classes/BirthdayGiftClass.php

@@ -326,6 +326,23 @@ class BirthdayGiftClass extends BaseClass
         return $gift;
     }
 
+    public static function modifyBirthday($shop, $params)
+    {
+        $customId = intval($params['customId'] ?? 0);
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $custom = CustomClass::modifyBirthday($customId, $shop->id, $params);
+            $levelMap = self::getLevelBenefitMap($shop->mainId, $shop->id);
+            $gift = self::getOrCreateYearRecord($shop, $custom, $levelMap);
+            $transaction->commit();
+            return $gift;
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            throw $exception;
+        }
+    }
+
     /**
      * 确保每年都有记录
      * @param $shop
@@ -421,11 +438,9 @@ class BirthdayGiftClass extends BaseClass
                 if (intval($gift->status) != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period, $params)) {
                     continue;
                 }
-                if (intval($gift->status) == self::STATUS_NO_BIRTHDAY && $period != 'week') {
-                    // 未填写仅在较宽范围展示:近一周仍显示
-                    if ($period != 'week') {
-                        continue;
-                    }
+                // 未填写生日仅在选择"全部"选项时显示
+                if (intval($gift->status) == self::STATUS_NO_BIRTHDAY && $period != 'all') {
+                    continue;
                 }
                 if (!empty($searchText)) {
                     $name = $custom->name ?? '';
@@ -480,7 +495,8 @@ class BirthdayGiftClass extends BaseClass
                 if ($st != self::STATUS_NO_BIRTHDAY && !self::matchesPeriod($custom, $period, $params)) {
                     continue;
                 }
-                if ($st == self::STATUS_NO_BIRTHDAY && $period != 'week') {
+                // 未填写生日仅在选择"全部"选项时显示
+                if ($st == self::STATUS_NO_BIRTHDAY && $period != 'all') {
                     continue;
                 }
                 $counts['all']++;

+ 70 - 1
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\classes\UserClass;
 use bizHd\user\classes\UserGrowthClass;
 use common\components\dict;
 use common\components\imgUtil;
@@ -25,6 +26,74 @@ class CustomClass extends BaseClass
 
     public static $baseFile = '\bizHd\custom\models\Custom';
 
+    //修改客户生日 ssh 20250814
+    public static function modifyBirthday($customId, $shopId, $params)
+    {
+        date_default_timezone_set('PRC');
+
+        $custom = self::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        if ($custom->shopId != $shopId) {
+            util::fail('不是你的客户');
+        }
+        $lunar = $params['lunar'] ?? 0;
+        $birthdayMonth = $params['birthdayMonth'] ?? 1;
+        if ($birthdayMonth > 12 || $birthdayMonth < 1) {
+            util::fail('月份必须1到12月');
+        }
+        $birthdayDate = $params['birthdayDate'] ?? 1;
+        if ($birthdayDate > 31 || $birthdayDate < 1) {
+            util::fail('日期必须1到31号');
+        }
+
+        $userId = $custom->userId;
+        $user = UserClass::getById($userId, true);
+        if (empty($user)) {
+            util::fail('客户信息缺失');
+        }
+        if ($lunar == 1 && $birthdayDate == 31) {
+            util::fail('农历没有31号');
+        }
+
+        $calendar = new Calendar();
+        if ($lunar == 1) {
+            try {
+                $result = $calendar->lunar(date("Y"), $birthdayMonth, $birthdayDate);
+            } catch (\InvalidArgumentException $e) {
+                $msg = $e->getMessage();
+                util::fail($msg);
+            }
+            //农历转阳历,有多处使用,需要同步修改,关键词 change_my_birthday
+            $month = $result['gregorian_month'] ?? 1;
+            $date = $result['gregorian_day'] ?? 1;
+            $birthday = date("Y") . '-' . $month . '-' . $date;
+        } else {
+            $birthday = date("Y") . '-' . $birthdayMonth . '-' . $birthdayDate;
+        }
+        $birthdayTime = strtotime($birthday);
+
+        if (getenv('YII_ENV') != 'dev' && $user->birthdaySet == 1) {
+            util::fail('客户已填写,不能修改');
+        }
+        //用户自己没有设置过生日,直接改
+        $custom->lunar = $lunar;
+        $custom->birthdayDate = $birthdayDate;
+        $custom->birthdayMonth = $birthdayMonth;
+        $custom->birthday = $birthday;
+        $custom->birthdayTime = $birthdayTime;
+        $custom->save();
+
+        $user->lunar = $lunar;
+        $user->birthdayDate = $birthdayDate;
+        $user->birthdayMonth = $birthdayMonth;
+        $user->birthday = $birthday;
+        $user->birthdayTime = $birthdayTime;
+        $user->save();
+        return $custom;
+    }
+
     //用余额支付,客户余额减少 ssh 20250410
     public static function payToChangeBalance($order)
     {
@@ -965,4 +1034,4 @@ class CustomClass extends BaseClass
 
         return ['level'=>0, 'name'=>''];
     }
-}
+}