DailyTask.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\cron;
  3. use app\common\util\AppMsg;
  4. use think\Db;
  5. use yunwuxin\cron\Task;
  6. class DailyTask extends Task
  7. {
  8. public function configure()
  9. {
  10. $this->everyMinute(); //每分钟执行一次
  11. }
  12. /**
  13. * 执行任务
  14. * @return mixed
  15. */
  16. protected function execute()
  17. {
  18. try{
  19. $this->daily();
  20. $this->addDailyTask();
  21. $this->dailyStart();
  22. $this->cancelDelay();
  23. }catch (\Exception $e){
  24. trace($e->getMessage());
  25. }
  26. }
  27. //处理已超时日常工作任务,并从任务栏删除
  28. public function daily(){
  29. (new \app\common\model\DailyTask())->timer_action();
  30. }
  31. //近12个小时的日常工作任务加入到任务栏
  32. public function addDailyTask(){
  33. (new \app\common\model\DailyTask())->addDailyTask();
  34. }
  35. // 日常工作任务将要开始提醒 每分钟执行一次
  36. public function dailyStart(){
  37. $curTime = date('Y-m-d H:i').':00';
  38. $users = Db::name('daily_task_user')
  39. ->alias('ptu')
  40. ->join('daily_task pt','pt.id = ptu.task_id')
  41. ->where('pt.del',0)
  42. ->where('pt.status',0)
  43. ->where('pt.start_time',$curTime)
  44. ->column('ptu.user_id');
  45. if($users){
  46. send_jpush($users,AppMsg::PUSH_DAILY_TASK,'您有新的日常工作任务将要开始,请及时执行。');
  47. }
  48. }
  49. // 取消过期的延期申请
  50. public function cancelDelay(){
  51. Db::name('device_task_delay')
  52. ->where('status',0)
  53. ->where('end_time','<=',date('Y-m-d H:i:s'))
  54. ->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
  55. }
  56. }