Room.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <?php
  2. namespace app\index\controller;
  3. use think\Db;
  4. class Room extends Base
  5. {
  6. public function lists(){
  7. $page = input('page/d',1);
  8. $length = input('size/d',10);
  9. $start = ($page - 1) * $length;
  10. $map['org_id'] = $this->orgId;
  11. $map['status'] = 2;
  12. $map['advanced'] = 6;
  13. $lists = Db::name('apply')
  14. ->where($map)
  15. ->field('id,apply_sn,title,form_json,create_time')
  16. ->limit($start,$length)
  17. ->order('id desc')
  18. ->select();
  19. $lists = $lists?$lists:[];
  20. foreach ($lists as $k=>$v){
  21. $formJson = json_decode($v['form_json'],true);
  22. $date = '';
  23. $startTime = '';
  24. $endTime = '';
  25. $room = '';
  26. $sn = '';
  27. $dep = '';
  28. $user = '';
  29. $phone = '';
  30. $nums = '';
  31. foreach ($formJson as $kk=>$vv){
  32. if($vv['componentName'] == 'ddmeetingroomfield'){
  33. foreach ($vv['components'] as $kkk=>$vvv){
  34. if($vvv['idx'] === 4){
  35. $startTime = $vvv['values2'][0];
  36. $endTime = $vvv['values2'][0];
  37. } else if($vvv['idx'] === 6){
  38. $room = $vvv['values'];
  39. } else if($vvv['idx'] === 0){
  40. $sn = $vvv['values'];
  41. } else if($vvv['idx'] === 1){
  42. $dep = $vvv['values'];
  43. } else if($vvv['idx'] === 2){
  44. $phone = $vvv['values'];
  45. } else if($vvv['idx'] === 3){
  46. $date = $vvv['values'];
  47. } else if($vvv['idx'] === 5){
  48. $nums = $vvv['values'];
  49. }
  50. }
  51. break;
  52. }
  53. }
  54. $lists[$k]['date'] = $date;
  55. $lists[$k]['yytime'] = $date.' '.$startTime.'~'.$date.' '.$endTime;
  56. $lists[$k]['room'] = $room;
  57. $lists[$k]['sn'] = $sn;
  58. $lists[$k]['user'] = $user;
  59. $lists[$k]['phone'] = $phone;
  60. $lists[$k]['nums'] = $nums;
  61. $lists[$k]['dep'] = $dep;
  62. unset($lists[$k]['form_json']);
  63. }
  64. $total = Db::name('apply')->where($map)->count();
  65. $data = [
  66. 'total' => $total,
  67. 'list' => $lists?$lists:[]
  68. ];
  69. ajax_return_ok($data);
  70. }
  71. public function book(){
  72. $applys = $this->getApplyList(6,1);
  73. $date = input('date','','trim');
  74. if(!$date){
  75. $date = date('Y-m-d');
  76. }
  77. $days = $this->getDays($date);
  78. $prev = date('Y-m-d',strtotime($date) - 7*24*60*60);
  79. $next = date('Y-m-d',strtotime($date) + 7*24*60*60);
  80. $data1 = [
  81. 'title' => '会议室',
  82. 'day1' => [['id' => 0,'title' => $days[0].' '.$this->getWeek($days[0])]],
  83. 'day2' => [['id' => 0,'title' => $days[1].' '.$this->getWeek($days[1])]],
  84. 'day3' => [['id' => 0,'title' => $days[2].' '.$this->getWeek($days[2])]],
  85. 'day4' => [['id' => 0,'title' => $days[3].' '.$this->getWeek($days[3])]],
  86. 'day5' => [['id' => 0,'title' => $days[4].' '.$this->getWeek($days[4])]],
  87. 'day6' => [['id' => 0,'title' => $days[5].' '.$this->getWeek($days[5])]],
  88. 'day7' => [['id' => 0,'title' => $days[6].' '.$this->getWeek($days[6])]],
  89. ];
  90. $data2 = [
  91. 'title' => '大会议室',
  92. 'day1' => [],
  93. 'day2' => [],
  94. 'day3' => [],
  95. 'day4' => [],
  96. 'day5' => [],
  97. 'day6' => [],
  98. 'day7' => [],
  99. ];
  100. $data3 = [
  101. 'title' => '小会议室',
  102. 'day1' => [],
  103. 'day2' => [],
  104. 'day3' => [],
  105. 'day4' => [],
  106. 'day5' => [],
  107. 'day6' => [],
  108. 'day7' => [],
  109. ];
  110. foreach ($applys as $k=>$v){
  111. $d = [
  112. 'id' => $v['id'],
  113. 'title' => '['.$v['startTime'].'~'.$v['endTime'].']'.$v['title']
  114. ];
  115. if($v['room'] === $data2['title']){
  116. if($v['date'] == $days[0]){
  117. $data2['day1'][] = $d;
  118. } else if($v['date'] == $days[1]){
  119. $data2['day2'][] = $d;
  120. } else if($v['date'] == $days[2]){
  121. $data2['day3'][] = $d;
  122. } else if($v['date'] == $days[3]){
  123. $data2['day4'][] = $d;
  124. } else if($v['date'] == $days[4]){
  125. $data2['day5'][] = $d;
  126. } else if($v['date'] == $days[5]){
  127. $data2['day6'][] = $d;
  128. } else if($v['date'] == $days[6]){
  129. $data2['day7'][] = $d;
  130. }
  131. }else if($v['room'] === $data3['title']){
  132. if($v['date'] == $days[0]){
  133. $data3['day1'][] = $d;
  134. } else if($v['date'] == $days[1]){
  135. $data3['day2'][] = $d;
  136. } else if($v['date'] == $days[2]){
  137. $data3['day3'][] = $d;
  138. } else if($v['date'] == $days[3]){
  139. $data3['day4'][] = $d;
  140. } else if($v['date'] == $days[4]){
  141. $data3['day5'][] = $d;
  142. } else if($v['date'] == $days[5]){
  143. $data3['day6'][] = $d;
  144. } else if($v['date'] == $days[6]){
  145. $data3['day7'][] = $d;
  146. }
  147. }
  148. }
  149. $json = [
  150. 'prev' => $prev,
  151. 'next' => $next,
  152. 'list' => [$data1,$data2,$data3]
  153. ];
  154. ajax_return_ok($json);
  155. }
  156. private function getWeek($date){
  157. $weeks = ['周日','周一','周二','周三','周四','周五','周六'];
  158. $time = strtotime($date);
  159. $w = date('w',$time);
  160. return $weeks[$w];
  161. }
  162. private function getDays($date){
  163. $curTime = strtotime($date);
  164. $days = [];
  165. $days[] = $date;
  166. for ($i=1;$i<7;$i++){
  167. $days[] = date('Y-m-d',$curTime + $i*24*60*60);
  168. }
  169. return $days;
  170. }
  171. public function checktime(){
  172. $startTime = input('start','','trim');
  173. $endTime = input('end','','trim');
  174. $room = input('room','','trim');
  175. $date = input('date','','trim');
  176. $lists = $this->getApplyList(6);
  177. $flag = true;
  178. foreach ($lists as $k=>$v){
  179. if($v['room'] == $room && $v['date'] === $date){
  180. if($v['startTime'] <= $startTime && $v['endTime'] > $startTime){
  181. $flag = false;
  182. break;
  183. }else if($v['startTime'] <= $endTime && $v['startTime'] >= $startTime){
  184. $flag = false;
  185. break;
  186. }
  187. }
  188. }
  189. if(!$flag){
  190. ajax_return_error('该时间段已有预约');
  191. }else{
  192. ajax_return_ok([],'可预约');
  193. }
  194. }
  195. private function getApplyList($advanced,$type=0){
  196. if($type == 1){
  197. $status = '2';
  198. }else{
  199. $status = '1,2';
  200. }
  201. $lists = Db::name('apply')
  202. ->where('status','in',$status)
  203. ->where('advanced',$advanced)
  204. ->where('org_id',$this->orgId)
  205. ->field('id,title,apply_sn,form_json')
  206. ->select();
  207. $lists = $lists?$lists:[];
  208. foreach ($lists as $k=>$v){
  209. $formJson = json_decode($v['form_json'],true);
  210. $startTime = '';
  211. $endTime = '';
  212. $room = '';
  213. $date = '';
  214. foreach ($formJson as $kk=>$vv){
  215. if($vv['componentName'] == 'ddmeetingroomfield'){
  216. foreach ($vv['components'] as $kkk=>$vvv){
  217. if($vvv['idx'] === 4){
  218. $startTime = $vvv['values2'][0];
  219. $endTime = $vvv['values2'][1];
  220. } else if($vvv['idx'] === 6){
  221. $room = $vvv['values'];
  222. } else if($vvv['idx'] === 3){
  223. $date = $vvv['values'];
  224. }
  225. }
  226. break;
  227. }
  228. }
  229. $lists[$k]['startTime'] = $startTime;
  230. $lists[$k]['endTime'] = $endTime;
  231. $lists[$k]['room'] = $room;
  232. $lists[$k]['date'] = $date;
  233. unset($lists[$k]['form_json']);
  234. }
  235. return $lists;
  236. }
  237. }