Kaynağa Gözat

Merge branch 'dev' of http://git.huaml.com/zhh/huahuibao into dev

shish 2 ay önce
ebeveyn
işleme
afc7447d66

+ 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]);
     }
-}
+}

+ 44 - 19
biz-hd/birthday/classes/BirthdayGiftClass.php

@@ -9,10 +9,8 @@ use bizHd\member\classes\MemberLevelClass;
 use bizHd\shop\classes\ShopClass;
 use bizHd\shop\classes\ShopExtClass;
 use common\components\noticeUtil;
-use common\components\orderSn;
 use common\components\printUtil;
 use common\components\ChuanglanSmsApi;
-use common\components\stringUtil;
 use common\components\util;
 use PhpAmqpLib\Wire\AMQPTable;
 use Yii;
@@ -26,10 +24,9 @@ class BirthdayGiftClass extends BaseClass
     const STATUS_NO_BIRTHDAY = 0;    // 0未填写
     const STATUS_PENDING_NOTIFY = 1; // 1待通知
     const STATUS_PENDING_CLAIM = 2;  // 2待领取
-    const STATUS_COLLECTED = 3;      // 3已领取
-    const STATUS_EXPIRED = 4;        // 4超时放弃
-
-    const EXPIRE_SECONDS = 86400;
+    const STATUS_PICKING_UP = 3;     // 3领取中
+    const STATUS_COLLECTED = 4;      // 4已领取
+    const STATUS_EXPIRED = 5;        // 5超时放弃
 
     public static function getStatusMap()
     {
@@ -37,6 +34,7 @@ class BirthdayGiftClass extends BaseClass
             self::STATUS_NO_BIRTHDAY => '未填写',
             self::STATUS_PENDING_NOTIFY => '待通知',
             self::STATUS_PENDING_CLAIM => '待领取',
+            self::STATUS_PICKING_UP => '领取中',
             self::STATUS_COLLECTED => '已领取',
             self::STATUS_EXPIRED => '超时放弃',
         ];
@@ -326,6 +324,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
@@ -412,20 +427,29 @@ class BirthdayGiftClass extends BaseClass
                     continue;
                 }
                 $custom = $customMap[$customId];
-                if ($statusFilter >= 0 && intval($gift->status) != $statusFilter) {
-                    continue;
+                // 兼容前端"待领取" 映射后端"待领取"与"领取中"两个状态
+                if ($statusFilter >= 0) {
+                    if ($statusFilter == self::STATUS_PENDING_CLAIM) {
+                        // "待领取"tab,需要包含“待领取”与“领取中”两个状态
+                        if (intval($gift->status) != self::STATUS_PENDING_CLAIM && intval($gift->status) != self::STATUS_PICKING_UP) {
+                            continue;
+                        }
+                    } else {
+                        if (intval($gift->status) != $statusFilter) {
+                            continue;
+                        }
+                    }
                 }
+     
                 if ($statusFilter < 0 && intval($gift->status) == self::STATUS_NO_BIRTHDAY) {
                     // 全部 Tab 也展示未填写
                 }
                 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,13 +504,14 @@ 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']++;
                 if ($st == self::STATUS_PENDING_NOTIFY) {
                     $counts['pendingNotify']++;
-                } elseif ($st == self::STATUS_PENDING_CLAIM) {
+                } elseif ($st == self::STATUS_PENDING_CLAIM || $st == self::STATUS_PICKING_UP) { // 前端的"待领取"是由后端的 待领取与领取中 组合而来
                     $counts['pendingClaim']++;
                 } elseif ($st == self::STATUS_COLLECTED) {
                     $counts['collected']++;
@@ -528,7 +553,7 @@ class BirthdayGiftClass extends BaseClass
                 $st = intval($gift->status);
                 if ($st == self::STATUS_PENDING_NOTIFY) {
                     $pending[$name] = ($pending[$name] ?? 0) + 1;
-                } elseif ($st == self::STATUS_PENDING_CLAIM || $st == self::STATUS_COLLECTED) {
+                } elseif (in_array($st, [self::STATUS_PENDING_CLAIM, self::STATUS_PENDING_CLAIM, self::STATUS_COLLECTED])) {
                     $collected[$name] = ($collected[$name] ?? 0) + 1;
                 }
             }
@@ -854,11 +879,11 @@ class BirthdayGiftClass extends BaseClass
             util::fail('请选择领取时间');
         }
         $status = intval($gift->status);
-        if ($status == self::STATUS_COLLECTED) {
+        if ($status == self::STATUS_PICKING_UP) {
             if ($idempotent) {
                 return $gift;
             }
-            util::fail('已领取,请勿重复操作');
+            util::fail('已领取,请勿重复操作');
         }
         if ($status == self::STATUS_EXPIRED) {
             util::fail('领取时间已过,已自动放弃权益');
@@ -872,7 +897,7 @@ class BirthdayGiftClass extends BaseClass
         }
         $gift->pickupTime = $pickupTime;
         $gift->collectTime = date('Y-m-d H:i:s');
-        $gift->status = self::STATUS_COLLECTED;
+        $gift->status = self::STATUS_PICKING_UP;
         $gift->save();
         self::printReceipt($gift);
         return $gift;

+ 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'=>''];
     }
-}
+}