<?php
namespace app\cron;

use app\common\model\CleanTask;
use app\common\util\AppMsg;
use think\Db;
use yunwuxin\cron\Task;

class CleanStart extends Task
{
    public function configure()
    {
        $this->dailyAt('06:00');
    }

    /**
     * 执行任务
     * @return mixed
     */
    protected function execute()
    {
        try{
            // 专项保洁任务将要开始提醒 每天早上6点执行一次
            $curTime = date('Y-m-d');
            $users = Db::name('clean_task_user')
                ->alias('ptu')
                ->join('clean_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_CLEAN,'您有新的专项保洁任务将要开始,请及时执行。');
            }
        }catch (\Exception $e){
            trace($e->getMessage());
        }

    }
}