DeviceTask.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace app\cron;
  3. use app\common\util\AppMsg;
  4. use think\Db;
  5. use yunwuxin\cron\Task;
  6. class DeviceTask 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->device();
  20. $this->addDeviceTask();
  21. $this->deviceStart();
  22. $this->deviceTaskRemind();
  23. }catch (\Exception $e){
  24. trace($e->getMessage());
  25. }
  26. }
  27. //处理已超时设备台账任务,并从任务栏删除
  28. public function device(){
  29. (new \app\common\model\DeviceTask())->timer_action();
  30. }
  31. //近12个小时的设备台账任务加入到任务栏
  32. public function addDeviceTask(){
  33. (new \app\common\model\DeviceTask())->addDeviceTask();
  34. }
  35. // 设备台账任务将要开始提醒 每分钟执行一次
  36. public function deviceStart(){
  37. $curTime = date('Y-m-d H:i').':00';
  38. $users = Db::name('device_task_user')
  39. ->alias('ptu')
  40. ->join('device_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_DEVICE_TASK,'您有新的设备台账任务将要开始,请及时执行。');
  47. }
  48. }
  49. //提前五分钟提醒
  50. public function deviceTaskRemind(){
  51. $curStr= time() - 60*5;
  52. $date = date('Y-m-d H:i',$curStr).':00';
  53. $users = Db::name('device_task_user')
  54. ->alias('ptu')
  55. ->join('device_task pt','pt.id = ptu.task_id')
  56. ->where('pt.del',0)
  57. ->where('pt.status',0)
  58. ->where('pt.start_time',$date)
  59. ->column('ptu.user_id');
  60. if($users){
  61. send_jpush($users,AppMsg::PUSH_DEVICE_TASK,'您有新的设备维保任务将要开始,请及时执行。');
  62. }
  63. }
  64. }