123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\cron;
- use think\Db;
- use yunwuxin\cron\Task;
- //更新打卡状态
- class Attendance extends Task
- {
- public function configure()
- {
- $this->dailyAt('01:00');
- }
- /**
- * 执行任务
- * @return mixed
- */
- protected function execute()
- {
- try{
- $yday = date('Y-m-d',time() - 86400);
- // 昨天不跨天进行中的状态改为已完成
- $map1[] = ['day','=',$yday];
- $map1[] = ['next','=',0];
- $map1[] = ['status','=',0];
- $yyday = date('Y-m-d',time() - 2*86400);
- // 昨天跨天进行中的状态改为已完成
- $map2[] = ['day','=',$yyday];
- $map2[] = ['next','=',1];
- $map2[] = ['status','=',0];
- $lists = Db::name('attendance_user_class')
- ->whereOr([ $map1, $map2 ])
- ->field('id,content')
- ->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $dates = json_decode($v['content'],true);
- foreach ($dates as $kk=>$vv){
- $dates[$kk]['sstatus'] = 1;
- $dates[$kk]['estatus'] = 1;
- }
- Db::name('attendance_user_class')->where('id',$v['id'])->update([
- 'content' => json_encode($dates),
- 'status' => 1,
- 'update_time' => date('Y-m-d H:i:s')
- ]);
- }
- }catch (\Exception $e){
- trace($e->getMessage());
- }
- trace('attendance');
- }
- }
|