0
0

MeetingRoom.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php
  2. namespace app\api\controller\v1;
  3. use app\api\controller\Base;
  4. use app\hander\HelpHander;
  5. class MeetingRoom extends Base
  6. {
  7. //检查审批人
  8. public function checkApprover(){
  9. $ret = model('MeetingRoom')->checkApprover($this->userId,$this->orgId);
  10. if($ret){
  11. HelpHander::success($ret,'操作成功');
  12. }else{
  13. HelpHander::error(model('MeetingRoom')->getError());
  14. }
  15. }
  16. // 根据日期获取其一周的日期数组
  17. public function getWeek(){
  18. $day = input('day');
  19. if(!$day){
  20. HelpHander::error('参数错误');
  21. }
  22. $curday = date('Y-m-d');
  23. $daytime = strtotime($day);
  24. $w = date('w',$daytime);
  25. $weekarray=array("日","一","二","三","四","五","六"); //先
  26. $week = [];
  27. for ($i = 0;$i < 7;$i++){
  28. $wday = date('Y-m-d',$daytime + ($i - $w)*24*60*60);
  29. $today = 0;
  30. if($curday == $wday){
  31. $today = 1;
  32. }
  33. $text = $weekarray[date('w',$daytime + ($i - $w)*24*60*60)];
  34. $week[] = [
  35. 'day' => $wday,
  36. 'today' => $today,
  37. 'text' => $text,
  38. 'date' => date('d',strtotime($wday))
  39. ];
  40. }
  41. HelpHander::success($week,'成功');
  42. }
  43. /*
  44. 会议室预定列表
  45. */
  46. public function rooms(){
  47. $day = input('day');
  48. $ret = model('MeetingRoom')->getRoomByDay($day,$this->orgId);
  49. HelpHander::success($ret);
  50. }
  51. //详情
  52. public function detail(){
  53. $id = input('id/d',0);
  54. $time = input('time');
  55. $info = model('MeetingRoom')->details($id,$time,$this->orgId);
  56. if($info){
  57. HelpHander::success($info);
  58. }else{
  59. HelpHander::error(model('MeetingRoom')->getError());
  60. }
  61. }
  62. //会议室预定
  63. public function book(){
  64. $data = [
  65. 'org_id'=>$this->orgId,
  66. 'user_id'=>$this->userId,
  67. 'meeting_room_id'=>input('meetingRoomId/d',0),
  68. 'nums'=>input('nums/d'),
  69. // 'start_time'=>'',
  70. // 'end_time'=>'',
  71. 'user_ids'=>input('users',''),
  72. 'meeting_devices'=>input('devices','','trim'),
  73. 'banner'=>input('banner','','trim'),
  74. 'theme'=>input('theme','','trim'),
  75. 'dep_id'=>input('depId',0),
  76. ];
  77. // if($data['dep_id'] < 1){
  78. // HelpHander::error('使用部门不能为空');
  79. // }
  80. $times = input('times','','trim');
  81. $times = json_decode($times,true);
  82. if(!$times){
  83. HelpHander::error('未选择时段');
  84. }
  85. $times = list_sort_by($times,'stime', 'asc');
  86. $count = count($times);
  87. for($i=0;$i<$count-1;$i++){
  88. if($times[$i]['etime'] != $times[$i+1]['stime']){
  89. HelpHander::error('请选择相邻时间段');
  90. }
  91. }
  92. $data['start_time'] = $times[0]['stime'];
  93. $data['end_time'] = $times[$count-1]['etime'];
  94. if($data['meeting_room_id'] <= 0){
  95. HelpHander::error('未选择会议室');
  96. }
  97. if(!$data['start_time'] || !$data['end_time']){
  98. HelpHander::error('未选择时段');
  99. }
  100. // if(!$data['theme']){
  101. // $this->error('未填写会议内容');
  102. // }
  103. $curTime = getTime();
  104. if($curTime > $data['start_time']){
  105. HelpHander::error('会议开始时间已过');
  106. }
  107. $data['user_ids'] = format_str($data['user_ids']);
  108. $data['meeting_devices'] = format_str($data['meeting_devices']);
  109. $ret = db('meeting_apply')
  110. ->where('del',0)
  111. ->whereIn('status',[0,1])
  112. ->where('start_time','<=',$data['end_time'])
  113. ->where('end_time','>',$data['start_time'])
  114. ->where('meeting_room_id',$data['meeting_room_id'])
  115. ->where('org_id',$this->orgId)
  116. ->find();
  117. if($ret){
  118. HelpHander::error('该时段已有预定');
  119. }
  120. $res = model('MeetingRoom')->saveBook($data);
  121. if($res){
  122. HelpHander::success($res,'成功');
  123. }else{
  124. HelpHander::error(model('MeetingRoom')->getError());
  125. }
  126. }
  127. }