123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- namespace app\cron;
- use app\common\util\AppMsg;
- use think\Db;
- use yunwuxin\cron\Task;
- class DailyTask extends Task
- {
- public function configure()
- {
- $this->everyMinute(); //每分钟执行一次
- }
- /**
- * 执行任务
- * @return mixed
- */
- protected function execute()
- {
- try{
- $this->daily();
- $this->addDailyTask();
- $this->dailyStart();
- $this->cancelDelay();
- }catch (\Exception $e){
- trace($e->getMessage());
- }
- }
- //处理已超时日常工作任务,并从任务栏删除
- public function daily(){
- (new \app\common\model\DailyTask())->timer_action();
- }
- //近12个小时的日常工作任务加入到任务栏
- public function addDailyTask(){
- (new \app\common\model\DailyTask())->addDailyTask();
- }
- // 日常工作任务将要开始提醒 每分钟执行一次
- public function dailyStart(){
- $curTime = date('Y-m-d H:i').':00';
- $users = Db::name('daily_task_user')
- ->alias('ptu')
- ->join('daily_task pt','pt.id = ptu.task_id')
- ->where('pt.del',0)
- ->where('pt.status',0)
- ->where('pt.start_time',$curTime)
- ->column('ptu.user_id');
- if($users){
- send_jpush($users,AppMsg::PUSH_DAILY_TASK,'您有新的日常工作任务将要开始,请及时执行。');
- }
- }
- // 取消过期的延期申请
- public function cancelDelay(){
- Db::name('device_task_delay')
- ->where('status',0)
- ->where('end_time','<=',date('Y-m-d H:i:s'))
- ->update(['status'=>3,'update_time'=>date('Y-m-d H:i:s')]);
- }
- }
|