Attendance.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\cron;
  3. use think\Db;
  4. use yunwuxin\cron\Task;
  5. //更新打卡状态
  6. class Attendance extends Task
  7. {
  8. public function configure()
  9. {
  10. $this->dailyAt('01:00');
  11. }
  12. /**
  13. * 执行任务
  14. * @return mixed
  15. */
  16. protected function execute()
  17. {
  18. try{
  19. $yday = date('Y-m-d',time() - 86400);
  20. // 昨天不跨天进行中的状态改为已完成
  21. $map1[] = ['day','=',$yday];
  22. $map1[] = ['next','=',0];
  23. $map1[] = ['status','=',0];
  24. $yyday = date('Y-m-d',time() - 2*86400);
  25. // 昨天跨天进行中的状态改为已完成
  26. $map2[] = ['day','=',$yyday];
  27. $map2[] = ['next','=',1];
  28. $map2[] = ['status','=',0];
  29. $lists = Db::name('attendance_user_class')
  30. ->whereOr([ $map1, $map2 ])
  31. ->field('id,content')
  32. ->select();
  33. $lists = $lists?$lists:[];
  34. foreach ($lists as $k=>$v){
  35. $dates = json_decode($v['content'],true);
  36. foreach ($dates as $kk=>$vv){
  37. $dates[$kk]['sstatus'] = 1;
  38. $dates[$kk]['estatus'] = 1;
  39. }
  40. Db::name('attendance_user_class')->where('id',$v['id'])->update([
  41. 'content' => json_encode($dates),
  42. 'status' => 1,
  43. 'update_time' => date('Y-m-d H:i:s')
  44. ]);
  45. }
  46. }catch (\Exception $e){
  47. trace($e->getMessage());
  48. }
  49. trace('attendance');
  50. }
  51. }