12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\cron;
- use app\common\util\AppMsg;
- use think\Db;
- use yunwuxin\cron\Task;
- class DeviceTask extends Task
- {
- public function configure()
- {
- $this->everyMinute(); //每分钟执行一次
- }
- /**
- * 执行任务
- * @return mixed
- */
- protected function execute()
- {
- try{
- $this->device();
- $this->addDeviceTask();
- $this->deviceStart();
- $this->deviceTaskRemind();
- }catch (\Exception $e){
- trace($e->getMessage());
- }
- }
- //处理已超时设备台账任务,并从任务栏删除
- public function device(){
- (new \app\common\model\DeviceTask())->timer_action();
- }
- //近12个小时的设备台账任务加入到任务栏
- public function addDeviceTask(){
- (new \app\common\model\DeviceTask())->addDeviceTask();
- }
- // 设备台账任务将要开始提醒 每分钟执行一次
- public function deviceStart(){
- $curTime = date('Y-m-d H:i').':00';
- $users = Db::name('device_task_user')
- ->alias('ptu')
- ->join('device_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_DEVICE_TASK,'您有新的设备台账任务将要开始,请及时执行。');
- }
- }
- //提前五分钟提醒
- public function deviceTaskRemind(){
- $curStr= time() - 60*5;
- $date = date('Y-m-d H:i',$curStr).':00';
- $users = Db::name('device_task_user')
- ->alias('ptu')
- ->join('device_task pt','pt.id = ptu.task_id')
- ->where('pt.del',0)
- ->where('pt.status',0)
- ->where('pt.start_time',$date)
- ->column('ptu.user_id');
- if($users){
- send_jpush($users,AppMsg::PUSH_DEVICE_TASK,'您有新的设备维保任务将要开始,请及时执行。');
- }
- }
- }
|