123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace app\cron;
- use app\common\model\HouseLease;
- use think\Db;
- use yunwuxin\cron\Task;
- //生成考勤结果
- class AttendanceResult extends Task
- {
- public function configure()
- {
- $this->everyMinute(); //每分钟执行一次
- }
- /**
- * 执行任务
- * @return mixed
- */
- protected function execute()
- {
- try{
- $lists = Db::name('attendance_user_class')->where('status',1)->where('result',0)->field('id,content')->limit(500)->select();
- $lists = $lists?$lists:[];
- foreach ($lists as $k=>$v){
- $content = json_decode($v['content'],true);
- $result = 1;
- $count = 0; // 打卡次数
- foreach ($content as $kk=>$vv){
- if($result != 1){
- continue;
- }
- if($vv['ssign']){
- $count++;
- if($vv['ssign'] > $vv['stime']){
- $result = 2;
- }
- }
- if($vv['esign']){
- $count++;
- if($vv['esign'] < $vv['etime']){
- $result = 2;
- }
- }
- }
- if($count == 0){
- $result = 3;
- }
- Db::name('attendance_user_class')->where('id',$v['id'])->update(['result' => $result]);
- }
- }catch (\Exception $e){
- trace($e->getMessage());
- }
- }
- }
|