12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- namespace app\cron;
- use app\common\model\PatrolTask;
- use app\common\util\AppMsg;
- use think\Db;
- use yunwuxin\cron\Task;
- class PatrolPlan extends Task
- {
- public function configure()
- {
- $this->everyMinute(); //每分钟执行一次
- }
- /**
- * 执行任务
- * @return mixed
- */
- protected function execute()
- {
- try {
- $this->patrol();
- $this->addPatrolTask();
- $this->patrolStart();
- $this->patrolPlan();
- } catch (\Exception $e) {
- trace($e->getMessage());
- }
- }
- public function patrol(){
- set_time_limit(0);
- ini_set("memory_limit","1024M");
- (new PatrolTask())->timer_action();
- }
- //近12个小时的巡更任务加入到任务栏
- public function addPatrolTask(){
- (new PatrolTask())->addPatrolTask();
- }
- // 巡更任务将要开始提醒 每分钟执行一次
- public function patrolStart(){
- $curTime = date('Y-m-d H:i').':00';
- $users = Db::name('patrol_task_user')
- ->alias('ptu')
- ->join('patrol_task pt','pt.id = ptu.patrol_task_id')
- ->where('pt.del',0)
- ->where('pt.status',0)
- ->where('pt.start_time',$curTime)
- ->field('ptu.user_id,patrol_mode')
- ->select();
- $userids1 = $userids2 = $userids3 = $userids4 = [];
- foreach ($users as $k=>$v){
- if($v['patrol_mode'] == 1 && !in_array($v['user_id'],$userids1)){
- $userids1[] = $v['user_id'];
- }else if($v['patrol_mode'] == 2 && !in_array($v['user_id'],$userids2)){
- $userids2[] = $v['user_id'];
- }else if($v['patrol_mode'] == 3 && !in_array($v['user_id'],$userids3)){
- $userids3[] = $v['user_id'];
- }else if($v['patrol_mode'] == 4 && !in_array($v['user_id'],$userids4)){
- $userids4[] = $v['user_id'];
- }
- }
- if($userids1){
- send_jpush($userids1,AppMsg::PUSH_PATROL,'您有新的巡更任务将要开始,请及时执行。');
- }
- if($userids2){
- send_jpush($userids2,AppMsg::PUSH_PATROL,'您有新的巡视任务将要开始,请及时执行。');
- }
- if($userids3){
- send_jpush($userids3,AppMsg::PUSH_PATROL,'您有新的巡查任务将要开始,请及时执行。');
- }
- if($userids4){
- send_jpush($userids4,AppMsg::PUSH_PATROL,'您有新的巡检任务将要开始,请及时执行。');
- }
- }
- // 修改巡更计划状态 1分钟执行一次
- public function patrolPlan(){
- $curDay = date('Y-m-d');
- Db::name('patrol_plan')
- ->where('del',0)
- ->where('status',0)
- ->where('start_time','<=',$curDay)
- ->update(['status'=>1,'update_time'=>date('Y-m-d H:i:s')]);
- Db::name('patrol_plan')
- ->where('del',0)
- ->where('status','in',[0,1])
- ->where('end_time','<',$curDay)
- ->update(['status'=>2,'update_time'=>date('Y-m-d H:i:s')]);
- }
- }
|