AttendanceResult.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace app\cron;
  3. use app\common\model\HouseLease;
  4. use think\Db;
  5. use yunwuxin\cron\Task;
  6. //生成考勤结果
  7. class AttendanceResult extends Task
  8. {
  9. public function configure()
  10. {
  11. $this->everyMinute(); //每分钟执行一次
  12. }
  13. /**
  14. * 执行任务
  15. * @return mixed
  16. */
  17. protected function execute()
  18. {
  19. try{
  20. $lists = Db::name('attendance_user_class')->where('status',1)->where('result',0)->field('id,content')->limit(500)->select();
  21. $lists = $lists?$lists:[];
  22. foreach ($lists as $k=>$v){
  23. $content = json_decode($v['content'],true);
  24. $result = 1;
  25. $count = 0; // 打卡次数
  26. foreach ($content as $kk=>$vv){
  27. if($result != 1){
  28. continue;
  29. }
  30. if($vv['ssign']){
  31. $count++;
  32. if($vv['ssign'] > $vv['stime']){
  33. $result = 2;
  34. }
  35. }
  36. if($vv['esign']){
  37. $count++;
  38. if($vv['esign'] < $vv['etime']){
  39. $result = 2;
  40. }
  41. }
  42. }
  43. if($count == 0){
  44. $result = 3;
  45. }
  46. Db::name('attendance_user_class')->where('id',$v['id'])->update(['result' => $result]);
  47. }
  48. }catch (\Exception $e){
  49. trace($e->getMessage());
  50. }
  51. }
  52. }