MeetingRoom.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\helper\Time;
  6. use think\Model;
  7. use think\response\Json;
  8. class MeetingRoom extends Model
  9. {
  10. public function add(){
  11. $data = [
  12. 'id' => input('id/d',0),
  13. 'title' => input('title','','trim'),
  14. 'remark' => input('remark','','trim'),
  15. 'org_id' => input('orgId/d',0),
  16. 'enable' => input('enable/d',1),
  17. ];
  18. $logdata = json_encode($data);
  19. $result = validate('MeetingRoom')->check($data,[],'');
  20. if(true !== $result){
  21. HelpHander::error(validate('MeetingRoom')->getError());
  22. }
  23. $id = $data['id'];
  24. unset($data['id']);
  25. if($id > 0){
  26. $data['update_time'] = date('Y-m-d H:i:s');
  27. $ret = $this->allowField(true)->save($data,['id'=>$id]);
  28. }else{
  29. $data['create_time'] = date('Y-m-d H:i:s');
  30. $ret = $this->allowField(true)->save($data);
  31. }
  32. if(!$ret){
  33. HelpHander::error('操作失败');
  34. }
  35. if($id > 0){
  36. $content = '修改会议室';
  37. }else{
  38. $content = '添加会议室';
  39. }
  40. model('ActionLog')->add(9,$content,0,$logdata);
  41. return true;
  42. }
  43. public function info($id){
  44. $info = $this->where('id',$id)->find();
  45. if(!$info){
  46. HelpHander::error('数据不存在');
  47. }
  48. return $info->toArray();
  49. }
  50. public function lists($page,$size,$title,$orgId){
  51. $map[] = ['del','=',0];
  52. $map[] = ['org_id','=',$orgId];
  53. if($title != ''){
  54. $map[] = ['title','like','%'.$title.'%'];
  55. }
  56. $lists = $this
  57. ->where($map)
  58. ->page($page,$size)
  59. ->order('id desc')
  60. ->select();
  61. $total = $this->where($map)->count();
  62. $data = [
  63. 'total' => $total,
  64. 'list' => $lists?$lists->toArray():[]
  65. ];
  66. return $data;
  67. }
  68. public function all($orgId){
  69. $map[] = ['del','=',0];
  70. $map[] = ['org_id','=',$orgId];
  71. $lists = $this
  72. ->where($map)
  73. ->field('id,title')
  74. ->order('id desc')
  75. ->select();
  76. return $lists?$lists->toArray():[];
  77. }
  78. public function del($id){
  79. $ret = $this->where('id',$id)->setField('del',1);
  80. if(!$ret){
  81. HelpHander::error('删除失败');
  82. }
  83. $logdata = json_encode(['id' => $id]);
  84. model('ActionLog')->add(9,'删除会议室',0,$logdata);
  85. return true;
  86. }
  87. public function createSn($formJson){
  88. $formJson = json_decode($formJson,true);
  89. foreach ($formJson as $k=>$v){
  90. if($v['componentName'] == 'ddmeetingroomfield'){
  91. foreach ($v['components'] as $key=>$val){
  92. switch ($val['idx']){
  93. case '0':
  94. $sn = isset($val['values'])?$val['values']:'';
  95. if(!$sn){
  96. list($start,$end) = Time::month();
  97. $startDate = date('Y-m-d H:i:s',$start);
  98. $endDate = date('Y-m-d H:i:s',$end);
  99. $sn = Db::name('meeting_room_book')
  100. ->where('sn','like',date('Ym').'%')
  101. ->where('create_time','>=',$startDate)
  102. ->where('create_time','<=',$endDate)
  103. ->order('id desc')
  104. ->value('sn');
  105. if(is_numeric($sn)){
  106. $sn = $sn?$sn+1:date('Ym').'0001';
  107. }else{
  108. $sn = date('Ym').'0001';
  109. }
  110. if(mb_strlen($sn) == 12){
  111. $sn = date('Ym').'0001';
  112. }
  113. }
  114. $formJson[$k]['components'][$key]['values'] = "{$sn}";
  115. break;
  116. }
  117. }
  118. break;
  119. }
  120. }
  121. return json_encode($formJson,JSON_UNESCAPED_UNICODE);
  122. }
  123. public function advancedStartMeetingRoom($id,$orgId,$userId,$formJson,$extra){
  124. $formJson = json_decode($formJson,true);
  125. $data = [
  126. 'org_id' => $orgId,
  127. 'user_id' => $userId,
  128. 'apply_id' => $id,
  129. 'dep_id' => $extra['depId'],
  130. 'create_time' => date('Y-m-d H:i:s'),
  131. 'status' => 0,
  132. ];
  133. foreach ($formJson as $k=>$v){
  134. if($v['componentName'] == 'ddmeetingroomfield'){
  135. foreach ($v['components'] as $key=>$val){
  136. $val['values2'] = isset($val['values2'])?$val['values2']:[];
  137. $val['values'] = isset($val['values'])?$val['values']:'';
  138. switch ($val['idx']){
  139. case '0':
  140. $data['sn'] = isset($val['values'])?$val['values']:'';
  141. break;
  142. case '1':
  143. $d = json_decode($val['values'],true);
  144. $data['meeting_room_id'] = $d['id'];
  145. break;
  146. case '2':
  147. $data['start_time'] = date('Y-m-d H:i:s',strtotime($val['values2'][0]));
  148. $data['end_time'] = date('Y-m-d H:i:s',strtotime($val['values2'][1]));
  149. break;
  150. case '3':
  151. $data['nums'] = $val['values'];
  152. break;
  153. case '4':
  154. $data['leader'] = $val['values'];
  155. break;
  156. case '5':
  157. $data['participants'] = $val['values'];
  158. break;
  159. case '6':
  160. $data['service'] = implode(',',$val['values2']);
  161. break;
  162. case '7':
  163. $data['banner'] = $val['values'];
  164. break;
  165. case '8':
  166. $data['remark'] = $val['values'];
  167. break;
  168. case '9':
  169. $data['projection'] = $val['values'];
  170. break;
  171. }
  172. }
  173. break;
  174. }
  175. }
  176. $ret = Db::name('meeting_room_book')->insert($data);
  177. return $ret?true:false;
  178. }
  179. public function advancedEndMeetingRoom($id,$orgId,$userId,$formJson){
  180. $data = [
  181. 'update_time' => date('Y-m-d H:i:s'),
  182. 'status' => 1
  183. ];
  184. $ret = Db::name('meeting_room_book')->where('apply_id',$id)->update($data);
  185. return $ret?true:false;
  186. }
  187. public function advancedDisagreeMeetingRoom($id){
  188. $data = [
  189. 'update_time' => date('Y-m-d H:i:s'),
  190. 'status' => 2
  191. ];
  192. $ret = Db::name('meeting_room_book')->where('apply_id',$id)->update($data);
  193. return $ret?true:false;
  194. }
  195. public function books($page,$size,$meetingRoomId,$orgId){
  196. $map[] = ['status','=',1];
  197. $map[] = ['org_id','=',$orgId];
  198. if($meetingRoomId > 0){
  199. $map[] = ['meeting_room_id','=',$meetingRoomId];
  200. }
  201. $lists = Db::name('meeting_room_book')
  202. ->where($map)
  203. ->page($page,$size)
  204. ->order('id desc')
  205. ->select();
  206. $lists = $lists?$lists:[];
  207. foreach ($lists as $k=>$v){
  208. $lists[$k]['userPhone'] = Db::name('user')->where('id',$v['user_id'])->value('phone');
  209. $lists[$k]['userName'] = Db::name('user_info')->where('user_id',$v['user_id'])->value('name');
  210. $lists[$k]['meetingRoom'] = Db::name('meeting_room')->where('id',$v['meeting_room_id'])->value('title');
  211. $lists[$k]['depName'] = Db::name('dep')->where('id',$v['dep_id'])->value('name');
  212. }
  213. $total = Db::name('meeting_room_book')->where($map)->count();
  214. $data = [
  215. 'total' => $total,
  216. 'list' => $lists?$lists:[]
  217. ];
  218. return $data;
  219. }
  220. public function curbooks($meetingRoomId,$orgId){
  221. $map[] = ['status','=',1];
  222. $map[] = ['enable','=',1];
  223. $map[] = ['org_id','=',$orgId];
  224. if($meetingRoomId > 0){
  225. $map[] = ['meeting_room_id','=',$meetingRoomId];
  226. }
  227. $curDate = date('Y-m-d H:i:s');
  228. // $map[] = ['start_time','<=',$curDate];
  229. $map[] = ['end_time','>=',$curDate];
  230. $lists = Db::name('meeting_room_book')
  231. ->where($map)
  232. ->field('id,start_time,end_time')
  233. ->order('start_time desc')
  234. ->select();
  235. return $lists = $lists?$lists:[];
  236. }
  237. public function cancel($id){
  238. $info = Db::name('meeting_room_book')->where('id',$id)->find();
  239. if(!$info||$info['status']!=1){
  240. HelpHander::error('记录不存在');
  241. }
  242. if($info['enable'] == 0){
  243. HelpHander::error('已取消');
  244. }
  245. $ret = Db::name('meeting_room_book')->where('id',$id)->setField('enable',0);
  246. if(!$ret){
  247. HelpHander::error('取消失败');
  248. }
  249. return true;
  250. }
  251. }