AttendanceLeave.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. class AttendanceLeave extends Base{
  5. public function updates(){
  6. $data = request()->post();
  7. $result = validate('AttendanceLeave')->check($data,[],'');
  8. if(true !== $result){
  9. $this->error = validate('AttendanceLeave')->getError();
  10. return false;
  11. }
  12. if($data['start_time'] > $data['end_time']){
  13. $this->error = '开始时间不能小于结束时间';
  14. return false;
  15. }
  16. //当天上午
  17. if($data['start_time'] == $data['start_time'] && $data['apm1']== $data['apm2'] && $data['apm1']==1){
  18. $start_time = $data['start_time'].' 00:00:00';
  19. $end_time = $data['end_time'].' 11:59:59';
  20. }
  21. //当天下午
  22. if($data['start_time'] == $data['start_time'] && $data['apm1']== $data['apm2'] && $data['apm1']==2){
  23. $start_time = $data['start_time'].' 12:00:00';
  24. $end_time = $data['end_time'].' 23:59:59';
  25. }
  26. //当天
  27. if($data['start_time'] == $data['start_time']&& $data['apm1'] != $data['apm2']){
  28. $start_time = $data['start_time'].' 00:00:00';
  29. $end_time = $data['end_time'].' 23:59:59';
  30. }
  31. //跨天上午
  32. if($data['start_time'] < $data['end_time'] && $data['apm1'] == $data['apm2'] && $data['apm1']==1){
  33. $start_time = $data['start_time'].' 00:00:00';
  34. $end_time = $data['end_time'].' 11:59:59';
  35. }
  36. //跨天下午
  37. if($data['start_time'] < $data['end_time'] && $data['apm1'] == $data['apm2'] && $data['apm1']==2){
  38. $start_time = $data['start_time'].' 12:00:00';
  39. $end_time = $data['end_time'].' 23:59:59';
  40. }
  41. //跨天整天
  42. if($data['start_time'] < $data['end_time'] && $data['apm1'] != $data['apm2']){
  43. $start_time = $data['start_time'].' 00:00:00';
  44. $end_time = $data['end_time'].' 23:59:59';
  45. }
  46. $startdate = strtotime($start_time);
  47. $enddate = strtotime($end_time);
  48. $curDays = round(($enddate-$startdate)/3600/24,1) ;
  49. $curData = [
  50. 'user_id'=>$data['user_id'],
  51. 'org_id'=>cur_org_id(),
  52. 'start_time'=>$start_time,
  53. 'end_time'=>$end_time,
  54. 'leave_type'=>$data['leave_type'],
  55. 'days'=>$data['days'],
  56. 'cur_days'=>$curDays,
  57. 'status'=>0,
  58. ];
  59. $id = $data['id'];
  60. unset($data['id']);
  61. if($id > 0){
  62. $curData['update_time'] = date('Y-m-d H:i:s');
  63. $ret = $this->allowField(true)->save($curData,['id'=>$id]);
  64. }else{
  65. $curData['create_time'] = date('Y-m-d H:i:s');
  66. $ret = $this->allowField(true)->save($curData);
  67. }
  68. if(!$ret){
  69. $this->error = '操作失败';
  70. return false;
  71. }
  72. return true;
  73. }
  74. }