HandleServiceStatus.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php declare(strict_types=1);
  2. namespace app\admin\command;
  3. use app\model\CommonModel;
  4. use app\model\ServiceModel;
  5. use think\console\Command;
  6. use think\console\Input;
  7. use think\console\Output;
  8. use think\facade\Cache;
  9. //处理服务的活动状态
  10. class HandleServiceStatus extends Command
  11. {
  12. protected function configure()
  13. {
  14. // parent::configure(); // TODO: Change the autogenerated stub
  15. $this->setName('HandleServiceStatus')->setDescription('处理服务的活动状态');
  16. }
  17. protected function execute(Input $input, Output $output)
  18. {
  19. $key = 'handle_service_status';
  20. $redis = Cache::store('redis')->get($key);
  21. if (!$redis) {
  22. Cache::set($key, 1, 60);
  23. $date = date('Y-m-d H:i:s');
  24. ServiceModel::where('is_del', CommonModel::$del_normal)
  25. ->where('starttime', '<=', $date)
  26. ->where('endtime', '>', $date)
  27. ->save(['activity_status' => ServiceModel::$activity_status_ing, 'updaterid' => 0, 'updater' => '脚本', 'updatetime' => $date]);
  28. ServiceModel::where('is_del', CommonModel::$del_normal)
  29. ->where('endtime', '<', $date)
  30. ->save(['activity_status' => ServiceModel::$activity_status_end, 'updaterid' => 0, 'updater' => '脚本', 'updatetime' => $date]);
  31. Cache::set($key, 0);
  32. }
  33. }
  34. }