Browse Source

自动关闭超过时间的活动

master
wanghongjun 3 weeks ago
parent
commit
cfca94b33a
  1. 34
      app/Console/Commands/AutomaticallyStartActivity.php

34
app/Console/Commands/AutomaticallyStartActivity.php

@ -45,6 +45,7 @@ class AutomaticallyStartActivity extends Command
{
$now_times = time();
$now_time = date("Y-m-d H:i:s", $now_times);
$this->endActivity($now_time);
// 结束活动,调整为默认模式
$where = [
['status', '=', 1]
@ -104,4 +105,37 @@ class AutomaticallyStartActivity extends Command
}
}
}
// 超过当前时间的活动全部结束
protected function endActivity($now_time)
{
$model = EventCalendar::query()->where('end_time', '<=', $now_time)
->where('status', 0)->select();
if ($model) {
$oldValue = $model->get()->toArray();
if (!$oldValue) {
return ;
}
$updated_at = date("Y-m-d H:i:s", time());
$model->update([
'status' => 2,
'admin_user_id' => $this->user_id,
'updated_at' => $updated_at
]);
$newValue = [];
foreach ($oldValue as $value) {
$value['status'] = 2;
$value['admin_user_id'] = $this->user_id;
$value['updated_at'] = $updated_at;
$newValue[] = $value;
}
// 记录日志
$this->logService->logUpdatedData(
new EventCalendar(),
$oldValue,
'event_calendar.update',
$newValue
);
}
}
}

Loading…
Cancel
Save