AttendanceClass.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class AttendanceClass extends Base{
  5. public function updates(){
  6. $data = request()->post();
  7. $id = $data['id'];
  8. unset($data['id']);
  9. $result = validate('AttendanceClass')->check($data,[],'');
  10. if(true !== $result){
  11. $this->error = validate('AttendanceClass')->getError();
  12. return false;
  13. }
  14. $curData = $this->checkForm($data);
  15. if(!$curData){
  16. $this->error = "参数错误";
  17. return false;
  18. }
  19. $content = [
  20. 'type' => $data['type'],
  21. 'dates' => $curData
  22. ];
  23. $sdata = [
  24. 'name' => $data['name'],
  25. 'content' => json_encode($content),
  26. 'org_id'=>cur_org_id()
  27. ];
  28. if($id < 1){
  29. $check = db('attendance_class')->where('name',$data['name'])->where('del',0)->where('org_id',cur_org_id())->find();
  30. if($check){
  31. $this->error = '已存在相同内容';
  32. return false;
  33. }
  34. }
  35. if($id > 0){
  36. $sdata['update_time'] = date('Y-m-d H:i:s');
  37. $ret = $this->allowField(true)->save($sdata,['id'=>$id]);
  38. }else{
  39. $sdata['create_time'] = date('Y-m-d H:i:s');
  40. $ret = $this->allowField(true)->save($sdata);
  41. }
  42. if(!$ret){
  43. $this->error = '操作失败';
  44. return false;
  45. }
  46. return true;
  47. }
  48. private function checkFormold($data){
  49. $type = $data['type'];
  50. $timeOne = [$data['start1'],$data['end1']];
  51. $timeTwo = [isset($data['start2'])?$data['start2']:'',isset($data['end2'])?$data['end2']:''];
  52. $timeThree = [isset($data['start3'])?$data['start3']:'',isset($data['end3'])?$data['end3']:''];
  53. // $timeOne = explode(',',$data['start1']);
  54. // $timeTwo = isset($data['start2'])&&!empty($data['start2'])?explode(',',$data['start2']):[];
  55. // $timeThree = isset($data['start3'])&&!empty($data['start3'])?explode(',',$data['start3']):[];
  56. if($timeOne[0] == $timeOne[1]){
  57. $this->error = '上班时间和下班时间不能一样';
  58. return false;
  59. }
  60. $dates = [];
  61. if($type == 1){
  62. $dates1 = [
  63. 'stime' => $timeOne[0],
  64. 'etime' => $timeOne[1],
  65. 'snext' => 0,
  66. 'enext' => 0
  67. ];
  68. if($timeOne[0] > $timeOne[1]){
  69. $dates1['enext'] = 1;
  70. }
  71. $dates[] = $dates1;
  72. }elseif ($type == 2){
  73. $dates1 = [
  74. 'stime' => $timeOne[0],
  75. 'etime' => $timeOne[1],
  76. 'snext' => 0,
  77. 'enext' => 0
  78. ];
  79. if($timeOne[0] > $timeOne[1]){
  80. $dates1['enext'] = 1;
  81. }
  82. $dates[] = $dates1;
  83. if(!$timeTwo[0] || !$timeTwo[1]){
  84. $this->error = '第2次上班时间和下班时间不能为空';
  85. return false;
  86. }
  87. if($timeTwo[0]== $timeTwo[1]){
  88. $this->error = '第2次上班时间和下班时间不能一样';
  89. return false;
  90. }
  91. if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
  92. $this->error = '第2次时间段设置错误';
  93. return false;
  94. }
  95. if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
  96. $this->error = '第2次时间段设置错误';
  97. return false;
  98. }
  99. $dates2 = [
  100. 'stime' => $timeTwo[0],
  101. 'etime' => $timeTwo[1],
  102. 'snext' => 0,
  103. 'enext' => 0
  104. ];
  105. if($dates1['enext'] == 1){
  106. $dates2['snext'] = 1;
  107. $dates2['enext'] = 1;
  108. }else{
  109. if($timeTwo[0] < $timeOne[1]){
  110. $dates2['snext'] = 1;
  111. $dates2['enext'] = 1;
  112. }else{
  113. $dates2['snext'] = 0;
  114. if($timeTwo[0] > $timeTwo[1]){
  115. $dates2['enext'] = 0;
  116. }
  117. }
  118. }
  119. $dates[] = $dates2;
  120. }elseif ($type == 3){
  121. $dates1 = [
  122. 'stime' => $timeOne[0],
  123. 'etime' => $timeOne[1],
  124. 'snext' => 0,
  125. 'enext' => 0
  126. ];
  127. if($timeOne[0] > $timeOne[1]){
  128. $dates1['enext'] = 1;
  129. }
  130. $dates[] = $dates1;
  131. if(!$timeTwo[0] || !$timeTwo[1]){
  132. $this->error = '第2次上班时间和下班时间不能为空';
  133. return false;
  134. }
  135. if($timeTwo[0]== $timeTwo[1]){
  136. $this->error = '第2次上班时间和下班时间不能一样';
  137. return false;
  138. }
  139. if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
  140. $this->error = '第2次时间段设置错误';
  141. return false;
  142. }
  143. if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
  144. $this->error = '第2次时间段设置错误';
  145. return false;
  146. }
  147. $dates2 = [
  148. 'stime' => $timeTwo[0],
  149. 'etime' => $timeTwo[1],
  150. 'snext' => 0,
  151. 'enext' => 0
  152. ];
  153. if($dates1['enext'] == 1){
  154. $dates2['snext'] = 1;
  155. $dates2['enext'] = 1;
  156. }else{
  157. if($timeTwo[0] < $timeOne[1]){
  158. $dates2['snext'] = 1;
  159. $dates2['enext'] = 1;
  160. }else{
  161. $dates2['snext'] = 0;
  162. if($timeTwo[0] > $timeTwo[1]){
  163. $dates2['enext'] = 0;
  164. }
  165. }
  166. }
  167. $dates[] = $dates2;
  168. if(!$timeThree[0] || !$timeThree[1]) {
  169. $this->error = '第3次上班时间和下班时间不能为空';
  170. return false;
  171. }
  172. if($timeThree[0] == $timeThree[1]){
  173. $this->error = '第3次上班时间和下班时间不能一样';
  174. return false;
  175. }
  176. if($timeThree[0] < $timeThree[1] && $dates2['enext'] == 1){
  177. $this->error = '第3次上班时间和下班时间不能一样';
  178. return false;
  179. }
  180. if($timeThree[0] > $timeThree[1] && $dates2['enext'] == 1){
  181. $this->error = '第3次时间段设置错误';
  182. return false;
  183. }
  184. $dates3 = [
  185. 'stime' => $timeThree[0],
  186. 'etime' => $timeThree[1],
  187. 'snext' => 0,
  188. 'enext' => 0
  189. ];
  190. if($dates2['enext'] == 1){
  191. $dates3['snext'] = 1;
  192. $dates3['enext'] = 1;
  193. }else{
  194. if($timeThree[0] < $timeTwo[1]){
  195. $dates3['snext'] = 1;
  196. $dates3['enext'] = 1;
  197. }else{
  198. $dates3['snext'] = 0;
  199. if($timeThree[0] > $timeThree[1]){
  200. $dates3['enext'] = 0;
  201. }
  202. }
  203. }
  204. $dates[] = $dates3;
  205. }
  206. return $dates;
  207. }
  208. private function checkForm($data){
  209. $type = $data['type'];
  210. $timeOne = [$data['start1'],$data['end1']];
  211. $timeTwo = [isset($data['start2'])?$data['start2']:'',isset($data['end2'])?$data['end2']:''];
  212. $timeThree = [isset($data['start3'])?$data['start3']:'',isset($data['end3'])?$data['end3']:''];
  213. // $type = $data['type'];
  214. // $timeOne = explode(',',$data['start1']);
  215. // $timeTwo = isset($data['start2'])&&!empty($data['start2'])?explode(',',$data['start2']):[];
  216. // $timeThree = isset($data['start3'])&&!empty($data['start3'])?explode(',',$data['start3']):[];
  217. if($timeOne[0] == $timeOne[1]){
  218. $this->error = '上班时间和下班时间不能一样';
  219. return false;
  220. }
  221. $dates = [];
  222. if($type == 1){
  223. $dates1 = [
  224. 'stime' => $timeOne[0],
  225. 'etime' => $timeOne[1],
  226. 'snext' => 0,
  227. 'enext' => 0
  228. ];
  229. if($timeOne[0] > $timeOne[1]){
  230. $dates1['enext'] = 1;
  231. }
  232. $dates[] = $dates1;
  233. }elseif ($type == 2){
  234. $dates1 = [
  235. 'stime' => $timeOne[0],
  236. 'etime' => $timeOne[1],
  237. 'snext' => 0,
  238. 'enext' => 0
  239. ];
  240. if($timeOne[0] > $timeOne[1]){
  241. $dates1['enext'] = 1;
  242. }
  243. $dates[] = $dates1;
  244. if(!$timeTwo[0] || !$timeTwo[1]){
  245. $this->error = '第2次上班时间和下班时间不能为空';
  246. return false;
  247. }
  248. if($timeTwo[0]== $timeTwo[1]){
  249. $this->error = '第2次上班时间和下班时间不能一样';
  250. return false;
  251. }
  252. // if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
  253. // $this->error = '第2次时间段设置错误';
  254. // return false;
  255. // }
  256. // if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
  257. // $this->error = '第2次时间段设置错误';
  258. // return false;
  259. // }
  260. if($dates1['enext'] == 1 && $timeTwo[0] > $timeTwo[1]){
  261. $this->error = '班次时间不能跨越2天';
  262. return false;
  263. }
  264. $dates2 = [
  265. 'stime' => $timeTwo[0],
  266. 'etime' => $timeTwo[1],
  267. 'snext' => 0,
  268. 'enext' => 0
  269. ];
  270. if($dates1['enext'] == 1){
  271. $dates2['snext'] = 1;
  272. $dates2['enext'] = 1;
  273. }else{
  274. if($timeTwo[0] < $timeOne[1]){
  275. $dates2['snext'] = 1;
  276. $dates2['enext'] = 1;
  277. }else{
  278. $dates2['snext'] = 0;
  279. if($timeTwo[0] > $timeTwo[1]){
  280. $dates2['enext'] = 1;
  281. }
  282. }
  283. }
  284. $dates[] = $dates2;
  285. }elseif ($type == 3){
  286. $dates1 = [
  287. 'stime' => $timeOne[0],
  288. 'etime' => $timeOne[1],
  289. 'snext' => 0,
  290. 'enext' => 0
  291. ];
  292. if($timeOne[0] > $timeOne[1]){
  293. $dates1['enext'] = 1;
  294. }
  295. $dates[] = $dates1;
  296. if(!$timeTwo[0] || !$timeTwo[1]){
  297. $this->error = '第2次上班时间和下班时间不能为空';
  298. return false;
  299. }
  300. if($timeTwo[0]== $timeTwo[1]){
  301. $this->error = '第2次上班时间和下班时间不能一样';
  302. return false;
  303. }
  304. // if($timeTwo[0] < $timeOne[1] && $dates1['enext'] == 1){
  305. // $this->error = '第2次时间段设置错误';
  306. // return false;
  307. // }
  308. // if($timeTwo[0] > $timeTwo[1] && $dates1['enext'] == 1){
  309. // $this->error = '第2次时间段设置错误';
  310. // return false;
  311. // }
  312. if($dates1['enext'] == 1 && $timeTwo[0] > $timeTwo[1]){
  313. $this->error = '班次时间不能跨越2天';
  314. return false;
  315. }
  316. $dates2 = [
  317. 'stime' => $timeTwo[0],
  318. 'etime' => $timeTwo[1],
  319. 'snext' => 0,
  320. 'enext' => 0
  321. ];
  322. if($dates1['enext'] == 1){
  323. $dates2['snext'] = 1;
  324. $dates2['enext'] = 1;
  325. }else{
  326. if($timeTwo[0] < $timeOne[1]){
  327. $dates2['snext'] = 1;
  328. $dates2['enext'] = 1;
  329. }else{
  330. $dates2['snext'] = 0;
  331. if($timeTwo[0] > $timeTwo[1]){
  332. $dates2['enext'] = 1;
  333. }
  334. }
  335. }
  336. $dates[] = $dates2;
  337. if(!$timeThree[0] || !$timeThree[1]) {
  338. $this->error = '第3次上班时间和下班时间不能为空';
  339. return false;
  340. }
  341. if($timeThree[0] == $timeThree[1]){
  342. $this->error = '第3次上班时间和下班时间不能一样';
  343. return false;
  344. }
  345. // if($timeThree[0] < $timeThree[1] && $dates2['enext'] == 1){
  346. // $this->error = '第3次上班时间和下班时间不能一样';
  347. // return false;
  348. // }
  349. //
  350. // if($timeThree[0] > $timeThree[1] && $dates2['enext'] == 1){
  351. // $this->error = '第3次时间段设置错误';
  352. // return false;
  353. // }
  354. if($dates2['enext'] == 1 && $timeThree[0] > $timeThree[1]){
  355. $this->error = '班次时间不能跨越2天';
  356. return false;
  357. }
  358. $dates3 = [
  359. 'stime' => $timeThree[0],
  360. 'etime' => $timeThree[1],
  361. 'snext' => 0,
  362. 'enext' => 0
  363. ];
  364. if($dates2['enext'] == 1){
  365. $dates3['snext'] = 1;
  366. $dates3['enext'] = 1;
  367. }else{
  368. if($timeThree[0] < $timeTwo[1]){
  369. $dates3['snext'] = 1;
  370. $dates3['enext'] = 1;
  371. }else{
  372. $dates3['snext'] = 0;
  373. if($timeThree[0] > $timeThree[1]){
  374. $dates3['enext'] = 1;
  375. }
  376. }
  377. }
  378. $dates[] = $dates3;
  379. }
  380. return $dates;
  381. }
  382. }