shish il y a 11 mois
Parent
commit
b5f83ca0b8

+ 0 - 1
app-mall/controllers/ShopController.php

@@ -38,7 +38,6 @@ class ShopController extends BaseController
         $custom = [];
         if (!empty($user)) {
             if (empty($hdId)) {
-                $shop = $this->shop;
                 $respond = CustomClass::buildRelation($shop, $user);
                 $hd = $respond['hd'];
                 $custom = $respond['custom'];

+ 7 - 7
app-mall/controllers/UserController.php

@@ -67,27 +67,27 @@ class UserController extends BaseController
             util::fail('农历没有31号');
         }
         $user = $this->user;
+        $userId = $this->userId;
         if ($user->birthdaySet == 1) {
             util::fail('你已经设置过了');
         }
-
-        $calendar = new Calendar();
         if ($lunar == 1) {
             try {
+                //农历转阳历,有多处使用,需要同步修改,关键词change_my_birthday
+                $calendar = new Calendar();
                 $result = $calendar->lunar(date("Y"), $birthdayMonth, $birthdayDate);
+                $month = $result['gregorian_month'] ?? 1;
+                $date = $result['gregorian_day'] ?? 1;
+                $birthday = date("Y") . '-' . $month . '-' . $date;
             } catch (\InvalidArgumentException $e) {
                 $msg = $e->getMessage();
+                $birthday = '0000-00-00 00:00:00';
                 util::fail($msg);
             }
-            $month = $result['gregorian_month'] ?? 1;
-            $date = $result['gregorian_day'] ?? 1;
-            $birthday = date("Y") . '-' . $month . '-' . $date;
         } else {
             $birthday = date("Y") . '-' . $birthdayMonth . '-' . $birthdayDate;
         }
         $birthdayTime = strtotime($birthday);
-
-
         $user->lunar = $lunar;
         $user->birthdayDate = $birthdayDate;
         $user->birthdayMonth = $birthdayMonth;

+ 27 - 2
biz-hd/custom/classes/CustomClass.php

@@ -14,8 +14,10 @@ use bizHd\order\classes\SettleClass;
 use bizHd\shop\classes\ShopClass;
 use common\components\dict;
 use common\components\imgUtil;
+use common\components\noticeUtil;
 use common\components\stringUtil;
 use common\components\util;
+use Overtrue\ChineseCalendar\Calendar;
 use Yii;
 use bizHd\base\classes\BaseClass;
 
@@ -673,17 +675,40 @@ class CustomClass extends BaseClass
             ];
             $birthdaySet = $user->birthdaySet ?? 0;
             if ($birthdaySet == 1) {
-                //如果当年的生日时间没有更新,则需要给更新
-
                 //如果用户自己设置过了生日,则生日给传过去
+                $lunar = $user->lunar ?? 0;
                 $birthday = $user->birthday ?? '';
                 $birthdayTime = $user->birthdayTime ?? 0;
                 $birthdayMonth = $user->birthdayMonth ?? 0;
                 $birthdayDate = $user->birthdayDate ?? 0;
+                //如果当年的生日时间没有更新,则需要给更新
+                $year = date("Y", strtotime($birthday));
+                $thisYear = date("Y");
+                if ($year != $thisYear) {
+                    if ($lunar == 1) {
+                        try {
+                            //农历转阳历,有多处使用,需要同步修改,关键词change_my_birthday
+                            $calendar = new Calendar();
+                            $result = $calendar->lunar(date("Y"), $birthdayMonth, $birthdayDate);
+                            $month = $result['gregorian_month'] ?? 1;
+                            $date = $result['gregorian_day'] ?? 1;
+                            $birthday = date("Y") . '-' . $month . '-' . $date;
+                            CustomClass::updateByCondition(['userId' => $userId], ['birthday' => $birthday]);
+                        } catch (\InvalidArgumentException $e) {
+                            $msg = $e->getMessage();
+                            noticeUtil::push("更新生日出错了,userId:" . $userId . ' ' . $msg, '15280215347');
+                            $birthday = '0000-00-00 00:00:00';
+                        }
+                    } else {
+                        $birthday = date("Y") . '-' . $birthdayMonth . '-' . $birthdayDate;
+                        CustomClass::updateByCondition(['userId' => $userId], ['birthday' => $birthday]);
+                    }
+                }
                 $data['birthday'] = $birthday;
                 $data['birthdayTime'] = $birthdayTime;
                 $data['birthdayMonth'] = $birthdayMonth;
                 $data['birthdayDate'] = $birthdayDate;
+                $data['lunar'] = $lunar;
             }
             $custom = self::addCustom($data);
             $isNewCustom = 1;