| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 | 
							- <?php
 
- namespace app\common\model;
 
- use think\Db;
 
- class AttendanceClass extends Base{
 
-     public function updates(){
 
-         $data = request()->post();
 
-         $id = $data['id'];
 
-         unset($data['id']);
 
-         $result = validate('AttendanceClass')->check($data,[],'');
 
-         if(true !== $result){
 
-             $this->error = validate('AttendanceClass')->getError();
 
-             return false;
 
-         }
 
-         $curData = $this->checkForm($data);
 
-         if(!$curData){
 
-             $this->error = "参数错误";
 
-             return false;
 
-         }
 
-         $content = [
 
-             'type' => $data['type'],
 
-             'dates' => $curData
 
-         ];
 
-         $sdata = [
 
-             'name' => $data['name'],
 
-             'content' => json_encode($content),
 
-             'org_id'=>cur_org_id()
 
-         ];
 
-         if($id < 1){
 
-             $check = db('attendance_class')->where('name',$data['name'])->where('del',0)->where('org_id',cur_org_id())->find();
 
-             if($check){
 
-                 $this->error = '已存在相同内容';
 
-                 return false;
 
-             }
 
-         }
 
-         if($id > 0){
 
-             $sdata['update_time'] = date('Y-m-d H:i:s');
 
-             $ret = $this->allowField(true)->save($sdata,['id'=>$id]);
 
-         }else{
 
-             $sdata['create_time'] = date('Y-m-d H:i:s');
 
-             $ret = $this->allowField(true)->save($sdata);
 
-         }
 
-         if(!$ret){
 
-             $this->error = '操作失败';
 
-             return false;
 
-         }
 
-         return true;
 
-     }
 
-     private function checkFormold($data){
 
-         $type = $data['type'];
 
-         $timeOne = [$data['start1'],$data['end1']];
 
-         $timeTwo = [isset($data['start2'])?$data['start2']:'',isset($data['end2'])?$data['end2']:''];
 
-         $timeThree = [isset($data['start3'])?$data['start3']:'',isset($data['end3'])?$data['end3']:''];
 
- //        $timeOne = explode(',',$data['start1']);
 
- //        $timeTwo = isset($data['start2'])&&!empty($data['start2'])?explode(',',$data['start2']):[];
 
- //        $timeThree = isset($data['start3'])&&!empty($data['start3'])?explode(',',$data['start3']):[];
 
-         if($timeOne[0] == $timeOne[1]){
 
-             $this->error = '上班时间和下班时间不能一样';
 
-             return  false;
 
-         }
 
-         $dates = [];
 
-         if($type == 1){
 
-             $dates1 = [
 
-                 'stime' => $timeOne[0],
 
-                 'etime' => $timeOne[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($timeOne[0] > $timeOne[1]){
 
-                 $dates1['enext'] = 1;
 
-             }
 
-             $dates[] = $dates1;
 
-         }elseif ($type == 2){
 
-             $dates1 = [
 
-                 'stime' => $timeOne[0],
 
-                 'etime' => $timeOne[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($timeOne[0] > $timeOne[1]){
 
-                 $dates1['enext'] = 1;
 
-             }
 
-             $dates[] = $dates1;
 
-             if(!$timeTwo[0] || !$timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能为空';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0]== $timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
 
-                 $this->error = '第2次时间段设置错误';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
 
-                 $this->error = '第2次时间段设置错误';
 
-                 return false;
 
-             }
 
-             $dates2 = [
 
-                 'stime' => $timeTwo[0],
 
-                 'etime' => $timeTwo[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($dates1['enext'] == 1){
 
-                 $dates2['snext'] = 1;
 
-                 $dates2['enext'] = 1;
 
-             }else{
 
-                 if($timeTwo[0] < $timeOne[1]){
 
-                     $dates2['snext'] = 1;
 
-                     $dates2['enext'] = 1;
 
-                 }else{
 
-                     $dates2['snext'] = 0;
 
-                     if($timeTwo[0] > $timeTwo[1]){
 
-                         $dates2['enext'] = 0;
 
-                     }
 
-                 }
 
-             }
 
-             $dates[] = $dates2;
 
-         }elseif ($type == 3){
 
-             $dates1 = [
 
-                 'stime' => $timeOne[0],
 
-                 'etime' => $timeOne[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($timeOne[0] > $timeOne[1]){
 
-                 $dates1['enext'] = 1;
 
-             }
 
-             $dates[] = $dates1;
 
-             if(!$timeTwo[0] || !$timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能为空';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0]== $timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
 
-                 $this->error = '第2次时间段设置错误';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
 
-                 $this->error = '第2次时间段设置错误';
 
-                 return false;
 
-             }
 
-             $dates2 = [
 
-                 'stime' => $timeTwo[0],
 
-                 'etime' => $timeTwo[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($dates1['enext'] == 1){
 
-                 $dates2['snext'] = 1;
 
-                 $dates2['enext'] = 1;
 
-             }else{
 
-                 if($timeTwo[0] < $timeOne[1]){
 
-                     $dates2['snext'] = 1;
 
-                     $dates2['enext'] = 1;
 
-                 }else{
 
-                     $dates2['snext'] = 0;
 
-                     if($timeTwo[0] > $timeTwo[1]){
 
-                         $dates2['enext'] = 0;
 
-                     }
 
-                 }
 
-             }
 
-             $dates[] = $dates2;
 
-             if(!$timeThree[0] || !$timeThree[1]) {
 
-                 $this->error = '第3次上班时间和下班时间不能为空';
 
-                 return false;
 
-             }
 
-             if($timeThree[0] == $timeThree[1]){
 
-                 $this->error = '第3次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
-             if($timeThree[0] < $timeThree[1] && $dates2['enext'] == 1){
 
-                 $this->error = '第3次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
-             if($timeThree[0] > $timeThree[1] && $dates2['enext'] == 1){
 
-                 $this->error = '第3次时间段设置错误';
 
-                 return false;
 
-             }
 
-             $dates3 = [
 
-                 'stime' => $timeThree[0],
 
-                 'etime' => $timeThree[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($dates2['enext'] == 1){
 
-                 $dates3['snext'] = 1;
 
-                 $dates3['enext'] = 1;
 
-             }else{
 
-                 if($timeThree[0] < $timeTwo[1]){
 
-                     $dates3['snext'] = 1;
 
-                     $dates3['enext'] = 1;
 
-                 }else{
 
-                     $dates3['snext'] = 0;
 
-                     if($timeThree[0] > $timeThree[1]){
 
-                         $dates3['enext'] = 0;
 
-                     }
 
-                 }
 
-             }
 
-             $dates[] = $dates3;
 
-         }
 
-         return $dates;
 
-     }
 
-     private function checkForm($data){
 
-         $type = $data['type'];
 
-         $timeOne = [$data['start1'],$data['end1']];
 
-         $timeTwo = [isset($data['start2'])?$data['start2']:'',isset($data['end2'])?$data['end2']:''];
 
-         $timeThree = [isset($data['start3'])?$data['start3']:'',isset($data['end3'])?$data['end3']:''];
 
- //        $type = $data['type'];
 
- //        $timeOne = explode(',',$data['start1']);
 
- //        $timeTwo = isset($data['start2'])&&!empty($data['start2'])?explode(',',$data['start2']):[];
 
- //        $timeThree = isset($data['start3'])&&!empty($data['start3'])?explode(',',$data['start3']):[];
 
-         if($timeOne[0] == $timeOne[1]){
 
-             $this->error = '上班时间和下班时间不能一样';
 
-             return  false;
 
-         }
 
-         $dates = [];
 
-         if($type == 1){
 
-             $dates1 = [
 
-                 'stime' => $timeOne[0],
 
-                 'etime' => $timeOne[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($timeOne[0] > $timeOne[1]){
 
-                 $dates1['enext'] = 1;
 
-             }
 
-             $dates[] = $dates1;
 
-         }elseif ($type == 2){
 
-             $dates1 = [
 
-                 'stime' => $timeOne[0],
 
-                 'etime' => $timeOne[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($timeOne[0] > $timeOne[1]){
 
-                 $dates1['enext'] = 1;
 
-             }
 
-             $dates[] = $dates1;
 
-             if(!$timeTwo[0] || !$timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能为空';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0]== $timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
- //            if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
 
- //                $this->error = '第2次时间段设置错误';
 
- //                return false;
 
- //            }
 
- //            if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
 
- //                $this->error = '第2次时间段设置错误';
 
- //                return false;
 
- //            }
 
-             if($dates1['enext'] == 1 && $timeTwo[0] > $timeTwo[1]){
 
-                 $this->error = '班次时间不能跨越2天';
 
-                 return false;
 
-             }
 
-             $dates2 = [
 
-                 'stime' => $timeTwo[0],
 
-                 'etime' => $timeTwo[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($dates1['enext'] == 1){
 
-                 $dates2['snext'] = 1;
 
-                 $dates2['enext'] = 1;
 
-             }else{
 
-                 if($timeTwo[0] < $timeOne[1]){
 
-                     $dates2['snext'] = 1;
 
-                     $dates2['enext'] = 1;
 
-                 }else{
 
-                     $dates2['snext'] = 0;
 
-                     if($timeTwo[0] > $timeTwo[1]){
 
-                         $dates2['enext'] = 1;
 
-                     }
 
-                 }
 
-             }
 
-             $dates[] = $dates2;
 
-         }elseif ($type == 3){
 
-             $dates1 = [
 
-                 'stime' => $timeOne[0],
 
-                 'etime' => $timeOne[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($timeOne[0] > $timeOne[1]){
 
-                 $dates1['enext'] = 1;
 
-             }
 
-             $dates[] = $dates1;
 
-             if(!$timeTwo[0] || !$timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能为空';
 
-                 return false;
 
-             }
 
-             if($timeTwo[0]== $timeTwo[1]){
 
-                 $this->error = '第2次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
- //            if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
 
- //                $this->error = '第2次时间段设置错误';
 
- //                return false;
 
- //            }
 
- //            if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
 
- //                $this->error = '第2次时间段设置错误';
 
- //                return false;
 
- //            }
 
-             if($dates1['enext'] == 1 && $timeTwo[0] > $timeTwo[1]){
 
-                 $this->error = '班次时间不能跨越2天';
 
-                 return false;
 
-             }
 
-             $dates2 = [
 
-                 'stime' => $timeTwo[0],
 
-                 'etime' => $timeTwo[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($dates1['enext'] == 1){
 
-                 $dates2['snext'] = 1;
 
-                 $dates2['enext'] = 1;
 
-             }else{
 
-                 if($timeTwo[0] < $timeOne[1]){
 
-                     $dates2['snext'] = 1;
 
-                     $dates2['enext'] = 1;
 
-                 }else{
 
-                     $dates2['snext'] = 0;
 
-                     if($timeTwo[0] > $timeTwo[1]){
 
-                         $dates2['enext'] = 1;
 
-                     }
 
-                 }
 
-             }
 
-             $dates[] = $dates2;
 
-             if(!$timeThree[0] || !$timeThree[1]) {
 
-                 $this->error = '第3次上班时间和下班时间不能为空';
 
-                 return false;
 
-             }
 
-             if($timeThree[0] == $timeThree[1]){
 
-                 $this->error = '第3次上班时间和下班时间不能一样';
 
-                 return false;
 
-             }
 
- //            if($timeThree[0] < $timeThree[1] && $dates2['enext'] == 1){
 
- //                $this->error = '第3次上班时间和下班时间不能一样';
 
- //                return false;
 
- //            }
 
- //
 
- //            if($timeThree[0] > $timeThree[1] && $dates2['enext'] == 1){
 
- //                $this->error = '第3次时间段设置错误';
 
- //                return false;
 
- //            }
 
-             if($dates2['enext'] == 1 && $timeThree[0] > $timeThree[1]){
 
-                 $this->error = '班次时间不能跨越2天';
 
-                 return false;
 
-             }
 
-             $dates3 = [
 
-                 'stime' => $timeThree[0],
 
-                 'etime' => $timeThree[1],
 
-                 'snext' => 0,
 
-                 'enext' => 0
 
-             ];
 
-             if($dates2['enext'] == 1){
 
-                 $dates3['snext'] = 1;
 
-                 $dates3['enext'] = 1;
 
-             }else{
 
-                 if($timeThree[0] < $timeTwo[1]){
 
-                     $dates3['snext'] = 1;
 
-                     $dates3['enext'] = 1;
 
-                 }else{
 
-                     $dates3['snext'] = 0;
 
-                     if($timeThree[0] > $timeThree[1]){
 
-                         $dates3['enext'] = 1;
 
-                     }
 
-                 }
 
-             }
 
-             $dates[] = $dates3;
 
-         }
 
-         return $dates;
 
-     }
 
- }
 
 
  |