LeaveBj.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class LeaveBj extends Model
  7. {
  8. public function add($data){
  9. $data['days'] = calculate_leave($data['start'],$data['end'],0);
  10. $starts = explode(' ',$data['start']);
  11. if($starts[1] == '上午'){
  12. $data['start_time'] = $starts[0].' 00:00:00';
  13. }else{
  14. $data['start_time'] = $starts[0].' 12:00:00';
  15. }
  16. $ends = explode(' ',$data['end']);
  17. if($ends[1] == '上午'){
  18. $data['end_time'] = $ends[0].' 11:59:59';
  19. }else{
  20. $data['end_time'] = $ends[0].' 23:59:59';
  21. }
  22. unset($data['start']);
  23. unset($data['end']);
  24. $data['create_time'] = date('Y-m-d H:i:s');
  25. $ret = Db::name('leave_bj')->insert($data);
  26. return $ret?true:false;
  27. }
  28. public function advancedStartLeaveBj($id,$orgId,$userId,$formJson){
  29. $formJson = json_decode($formJson,true);
  30. $data = [
  31. 'org_id' => $orgId,
  32. 'user_id' => $userId,
  33. 'apply_id' => $id,
  34. 'type' => 2,
  35. ];
  36. foreach ($formJson as $k=>$v){
  37. if($v['componentName'] == 'ddleavebjfield'){
  38. foreach ($v['components'] as $key=>$val){
  39. switch ($val['idx']){
  40. case '0':
  41. $data['start'] = $val['values'];
  42. break;
  43. case '1':
  44. $data['end'] = $val['values'];
  45. break;
  46. case '2':
  47. $data['address'] = isset($val['values'])?$val['values']:'';
  48. break;
  49. }
  50. }
  51. break;
  52. }
  53. }
  54. $ret = $this->add($data);
  55. return $ret?true:false;
  56. }
  57. public function advancedEndLeaveBj($id,$orgId,$userId,$formJson){
  58. $data = [
  59. 'update_time' => date('Y-m-d H:i:s'),
  60. 'status' => 1
  61. ];
  62. $ret = Db::name('leave_bj')->where('apply_id',$id)->update($data);
  63. return $ret?true:false;
  64. }
  65. public function advancedDisagreeLeaveBj($applyId){
  66. $data = [
  67. 'update_time' => date('Y-m-d H:i:s'),
  68. 'status' => 2
  69. ];
  70. $ret = Db::name('leave_bj')->where('apply_id',$applyId)->update($data);
  71. return $ret?true:false;
  72. }
  73. public function lists($page,$size,$name,$type,$orgId,$userId=0){
  74. $map[] = ['al.status','=',1];
  75. $map[] = ['al.org_id','=',$orgId];
  76. if($name){
  77. $map[] = ['ui.name','like','%'.$name.'%'];
  78. }
  79. if($type > 0){
  80. $map[] = ['al.leave_type','=',$type];
  81. }
  82. if($userId > 0){
  83. $map[] = ['al.user_id','=',$userId];
  84. }
  85. $lists = Db::name('leave_bj')
  86. ->alias('al')
  87. ->join('user_info ui','ui.user_id = al.user_id')
  88. ->where($map)
  89. ->field('al.*,ui.name as userName')
  90. ->page($page,$size)
  91. ->order('al.id desc')
  92. ->select();
  93. $lists = $lists?$lists:[];
  94. foreach ($lists as $k=>$v){
  95. $startday = date('Y-m-d',strtotime($v['start_time']));
  96. if($startday.' 12:00:00' > $v['start_time']){
  97. $lists[$k]['start_time'] = $startday.' 上午';
  98. } else {
  99. $lists[$k]['start_time'] = $startday.' 下午';
  100. }
  101. $endday = date('Y-m-d',strtotime($v['end_time']));
  102. if($endday.' 12:00:00' > $v['end_time']){
  103. $lists[$k]['end_time'] = $endday.' 上午';
  104. } else {
  105. $lists[$k]['end_time'] = $endday.' 下午';
  106. }
  107. }
  108. $total = Db::name('leave_bj')
  109. ->alias('al')
  110. ->join('user_info ui','ui.user_id = al.user_id')
  111. ->where($map)->count();
  112. $data = [
  113. 'total' => $total,
  114. 'list' => $lists?$lists:[]
  115. ];
  116. return $data;
  117. }
  118. }