|
|
@@ -106,37 +106,42 @@ class CustomController extends Controller
|
|
|
|
|
|
}
|
|
|
|
|
|
- //每天凌晨2点执行,取出所有 lunar==1 的 且 birthdayTime 小于当前时间的客户,然后把他们的阴历转阳历,然后更新他们的 birthdayTime
|
|
|
+ //每天凌晨3点35分执行,取出所有 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++;
|
|
|
+ try{
|
|
|
+ $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
|
|
|
+ ]);
|
|
|
}
|
|
|
- $custom->birthday = $birthday;
|
|
|
- $custom->birthdayTime = strtotime($birthday);
|
|
|
- $custom->save();
|
|
|
-
|
|
|
- UserClass::updateById($custom->userId, [
|
|
|
- 'birthday' => $birthday,
|
|
|
- 'birthdayTime' => $custom->birthdayTime
|
|
|
- ]);
|
|
|
+ Yii::info('阴历转阳历脚本成功执行');
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Yii::error('阴历转阳历脚本执行失败,原因:'.$e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
|