shish 10 luni în urmă
părinte
comite
44e99fafad
1 a modificat fișierele cu 33 adăugiri și 34 ștergeri
  1. 33 34
      app-mall/controllers/UserController.php

+ 33 - 34
app-mall/controllers/UserController.php

@@ -116,6 +116,39 @@ class UserController extends BaseController
     {
         $user = $this->user;
         if (!empty($user)) {
+            $birthday = $user->birthday ?? '';
+            //如果当年的生日时间没有更新,则需要给更新
+            $year = date("Y", strtotime($birthday));
+            $thisYear = date("Y");
+            if ($year != $thisYear) {
+                $lunar = $user->lunar ?? 0;
+                $userId = $this->userId;
+                $birthdayMonth = $user->birthdayMonth ?? 0;
+                $birthdayDate = $user->birthdayDate ?? 0;
+                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;
+                        $user->birthday = $birthday;
+                        $user->save();
+                        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;
+                    $user->birthday = $birthday;
+                    $user->save();
+                    CustomClass::updateByCondition(['userId' => $userId], ['birthday' => $birthday]);
+                }
+            }
+
             // 将 $user 转换为数组,然后添加 hasMap 属性(字典中的 hasMap)
             $user = $user->toArray();
             $shortAvatar = $user['avatar'] ?? '';
@@ -126,40 +159,6 @@ class UserController extends BaseController
             $user['shortAvatar'] = $shortAvatar;
         }
 
-        $birthday = $user->birthday ?? '';
-        //如果当年的生日时间没有更新,则需要给更新
-        $year = date("Y", strtotime($birthday));
-        $thisYear = date("Y");
-        if ($year != $thisYear) {
-            $lunar = $user->lunar ?? 0;
-            $userId = $this->userId;
-            $birthdayMonth = $user->birthdayMonth ?? 0;
-            $birthdayDate = $user->birthdayDate ?? 0;
-            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;
-                    $user->birthday = $birthday;
-                    $user->save();
-                    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;
-                $user->birthday = $birthday;
-                $user->save();
-                CustomClass::updateByCondition(['userId' => $userId], ['birthday' => $birthday]);
-            }
-        }
-
-
         $hasMap = dict::getDict('hasMap');
         $user['hasMap'] = $hasMap;
         util::success(['info' => $user]);