0
0

MeetingRoom.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\util\ExcelUtil;
  4. use think\Db;
  5. class MeetingRoom extends Auth
  6. {
  7. public function index(){
  8. if(request()->isAjax()){
  9. //分页参数
  10. $length = input('rows',10,'intval'); //每页条数
  11. $page = input('page',1,'intval'); //第几页
  12. $start = ($page - 1) * $length; //分页开始位置
  13. //排序
  14. $sortRow = input('sidx','id','trim'); //排序列
  15. $sort = input('sord','desc','trim'); //排序方式
  16. $order = $sortRow.' '.$sort;
  17. $title = input('title','','trim');
  18. if($title){
  19. $map[] = ['title','like','%'.$title.'%'];
  20. }
  21. $enable = input('enable','','trim');
  22. if($enable != ''){
  23. $map[] = ['enable','=',$enable];
  24. }
  25. $map[] = ['del','=',0];
  26. $map[] = ['org_id','=',cur_org_id()];
  27. $map= empty($map) ? true: $map;
  28. //数据查询
  29. $lists = db('meeting_room')->limit($start,$length)->where($map)->order(['sort'=>'desc','id'=>'desc'])->select();
  30. foreach ($lists as $k=>$v){
  31. $lists[$k]['approverName'] = db('user')->where('id',$v['approver'])->value('real_name');
  32. $lists[$k]['token'] = think_encrypt($v['id']);
  33. }
  34. //数据返回
  35. $totalCount = db('meeting_room')->where($map)->count();
  36. $totalPage = ceil($totalCount/$length);
  37. $result['page'] = $page;
  38. $result['total'] = $totalPage;
  39. $result['records'] = $totalCount;
  40. $result['rows'] = $lists;
  41. return json($result);
  42. }else{
  43. return $this->fetch();
  44. }
  45. }
  46. /**
  47. * 新增/编辑
  48. */
  49. public function add($id=0){
  50. if(request()->isPost()){
  51. $res = model('MeetingRoom')->updates();
  52. if($res){
  53. $this->success('操作成功',url('index'));
  54. }else{
  55. $this->error(model('MeetingRoom')->getError());
  56. }
  57. }else{
  58. $title = '新增';
  59. if($id){
  60. $title = '编辑';
  61. $info = db('meeting_room')->where('id',$id)->find();
  62. $info['meeting_device_ids'] = !empty($info['meeting_device_ids'])?explode(',',$info['meeting_device_ids']):[];
  63. $this->assign('info',$info);
  64. }
  65. $c[] = ['del','=',0];
  66. $c[] = ['enable','=',1];
  67. $c[] = ['org_id','=',cur_org_id()];
  68. $device = db('meeting_device')->where($c)->select();
  69. $approverUser = Db::name('user')
  70. ->alias('u')
  71. ->field('u.*')
  72. ->join('user_org uo','uo.user_id=u.id')
  73. ->where([
  74. 'uo.org_id'=>cur_org_id(),
  75. 'u.enable'=>1,
  76. 'u.del'=>0,
  77. 'u.type'=>0,
  78. ])
  79. ->select();
  80. $this->assign('userList',$approverUser);
  81. $this->assign('deviceList',$device);
  82. $this->assign('title',$title);
  83. return $this->fetch();
  84. }
  85. }
  86. /**
  87. * 删除记录
  88. * @param int $id
  89. */
  90. public function del($id=0){
  91. if(!$id){
  92. $this->error('参数错误');
  93. }
  94. $res = db('meeting_room')->where('id',$id)->setField('del',1);
  95. if($res){
  96. // model('ActionLog')->addlog(is_login(),37,'删除会议室',['id' => $id],cur_org_id());
  97. $this->success('删除成功');
  98. }else{
  99. $this->error('删除失败');
  100. }
  101. }
  102. /**
  103. * 改变字段值
  104. * @param int $fv
  105. * @param string $fn
  106. * @param int $fv
  107. */
  108. public function changeField($id=0,$fn='',$fv=0){
  109. if(!$fn||!$id){
  110. $this->error('参数错误');
  111. }
  112. $res = db('meeting_room')->where('id',$id)->setField($fn,$fv);
  113. if($res){
  114. $content = '';
  115. if($fn == 'enable') {
  116. $content = '会议室列表:禁用';
  117. if ($fv == 1) {
  118. $content = '会议室列表:启用';
  119. }
  120. }
  121. // model('ActionLog')->addlog(is_login(),37,$content,['id' => $id],cur_org_id());
  122. $this->success('操作成功');
  123. }else{
  124. $this->error('操作失败');
  125. }
  126. }
  127. /**
  128. * 排序
  129. * @param int $id
  130. * @param int $sort
  131. */
  132. public function changeSort($id=0,$sort=0){
  133. if($id<0||$sort<0){
  134. $this->error('参数错误');
  135. }
  136. $res = db('meeting_room')->where('id',$id)->update(['sort'=>$sort]);
  137. if($res){
  138. $this->success('操作成功');
  139. }else{
  140. $this->error('操作失败');
  141. }
  142. }
  143. public function screen(){
  144. $token = input('token');
  145. $this->redirect('h5/MeetingScreen/index',['token'=>$token]);
  146. }
  147. public function tj(){
  148. if(request()->isAjax()){
  149. //分页参数
  150. $length = input('rows',10,'intval'); //每页条数
  151. $page = input('page',1,'intval'); //第几页
  152. $start = ($page - 1) * $length; //分页开始位置
  153. //排序
  154. $sortRow = input('sidx','id','trim'); //排序列
  155. $sort = input('sord','desc','trim'); //排序方式
  156. $order = $sortRow.' '.$sort;
  157. $title = input('title','','trim');
  158. if($title){
  159. $map[] = ['title','like','%'.$title.'%'];
  160. }
  161. $map[] = ['del','=',0];
  162. $map[] = ['org_id','=',cur_org_id()];
  163. $map= empty($map) ? true: $map;
  164. $start_time = input('start', '', 'trim');
  165. $end_time = input('end', '', 'trim');
  166. //数据查询
  167. $lists = Db::name('meeting_room')->limit($start,$length)->where($map)->order($order)->select();
  168. foreach ($lists as $k=>$v){
  169. $where[] = ['del','=',0];
  170. // $where[] = ['meeting_room_id','=',$v['id']];
  171. if($start_time){
  172. $where[] = ['end_time','>',$start_time.' 00:00:00'];
  173. }
  174. if($end_time){
  175. $where[] = ['start_time','<',$end_time.' 23:59:59'];
  176. }
  177. $count = Db::name('meeting_apply')->where($where)->where('meeting_room_id',$v['id'])->count();
  178. $lists[$k]['count'] = $count;
  179. $m1 = $where;
  180. $m1[] = ['status','=',0];
  181. $count1 = Db::name('meeting_apply')->where($m1)->where('meeting_room_id',$v['id'])->count();
  182. $lists[$k]['count1'] = $count1;
  183. $m2 = $where;
  184. $m2[] = ['status','=',1];
  185. $count2 = Db::name('meeting_apply')->where($m2)->where('meeting_room_id',$v['id'])->count();
  186. $lists[$k]['count2'] = $count2;
  187. $m3 = $where;
  188. $m3[] = ['status','=',2];
  189. $count3 = Db::name('meeting_apply')->where($m3)->where('meeting_room_id',$v['id'])->count();
  190. $lists[$k]['count3'] = $count3;
  191. $m4 = $where;
  192. $m4[] = ['status','=',3];
  193. $count4 = Db::name('meeting_apply')->where($m4)->where('meeting_room_id',$v['id'])->count();
  194. $lists[$k]['count4'] = $count4;
  195. // 时长
  196. $info = Db::name('meeting_apply')->where($m2)->where('meeting_room_id',$v['id'])->field('TIMESTAMPDIFF(SECOND,start_time,end_time) as seconds')->find();
  197. $lists[$k]['hour'] = $info?second_to_str($info['seconds']):'0';
  198. }
  199. //数据返回
  200. $totalCount = Db::name('meeting_room')->where($map)->count();
  201. $totalPage = ceil($totalCount/$length);
  202. $result['page'] = $page;
  203. $result['total'] = $totalPage;
  204. $result['records'] = $totalCount;
  205. $result['rows'] = $lists;
  206. return json($result);
  207. }else{
  208. return $this->fetch();
  209. }
  210. }
  211. public function tjexport(){
  212. set_time_limit(0);
  213. ini_set("memory_limit","1024M");
  214. $title = input('title','','trim');
  215. if($title){
  216. $map[] = ['title','like','%'.$title.'%'];
  217. }
  218. $map[] = ['del','=',0];
  219. $map[] = ['org_id','=',cur_org_id()];
  220. $map= empty($map) ? true: $map;
  221. $start_time = input('start', '', 'trim');
  222. $end_time = input('end', '', 'trim');
  223. //数据查询
  224. $lists = Db::name('meeting_room')->where($map)->order('id desc')->select();
  225. foreach ($lists as $k=>$v){
  226. $where[] = ['del','=',0];
  227. $where[] = ['meeting_room_id','=',$v['id']];
  228. if($start_time){
  229. $where[] = ['end_time','>',$start_time.' 00:00:00'];
  230. }
  231. if($end_time){
  232. $where[] = ['start_time','<',$end_time.' 23:59:59'];
  233. }
  234. $count = Db::name('meeting_apply')->where($where)->count();
  235. $lists[$k]['count'] = $count;
  236. $m1 = $where;
  237. $m1[] = ['status','=',0];
  238. $count1 = Db::name('meeting_apply')->where($m1)->count();
  239. $lists[$k]['count1'] = $count1;
  240. $m2 = $where;
  241. $m2[] = ['status','=',1];
  242. $count2 = Db::name('meeting_apply')->where($m2)->count();
  243. $lists[$k]['count2'] = $count2;
  244. $m3 = $where;
  245. $m3[] = ['status','=',2];
  246. $count3 = Db::name('meeting_apply')->where($m3)->count();
  247. $lists[$k]['count3'] = $count3;
  248. $m4 = $where;
  249. $m4[] = ['status','=',3];
  250. $count4 = Db::name('meeting_apply')->where($m4)->count();
  251. $lists[$k]['count4'] = $count4;
  252. // 时长
  253. $info = Db::name('meeting_apply')->where($m2)->field('TIMESTAMPDIFF(SECOND,start_time,end_time) as seconds')->find();
  254. $lists[$k]['hour'] = $info?second_to_str($info['seconds']):'0';
  255. }
  256. $header = [
  257. ['title' => '编号', 'name' => 'id','width'=>'10'],
  258. ['title' => '会议室名称', 'name' => 'title','width'=>'20'],
  259. ['title' => '预约总单数', 'name' => 'count','width'=>'20'],
  260. ['title' => '待审核单数', 'name' => 'count1','width'=>'20'],
  261. ['title' => '同意单数', 'name' => 'count2','width'=>'20'],
  262. ['title' => '拒绝单数', 'name' => 'count3','width'=>'20'],
  263. ['title' => '取消单数', 'name' => 'count4','width'=>'20'],
  264. ['title' => '有效时长(已同意)', 'name' => 'hour','width'=>'30'],
  265. ];
  266. $filename = '会议室统计';
  267. ExcelUtil::export($filename,$header,$lists);
  268. }
  269. //二维码
  270. public function qrcode($id = 0) {
  271. $info = Db::name('meeting_room')->where('id', $id)->where('del',0)->find();
  272. if (!$info) {
  273. exit('数据不存在');
  274. }
  275. $code = get_qrcode_str('meeting', $id);
  276. $this->assign('code', $code);
  277. $this->assign('info', $info);
  278. return $this->fetch();
  279. }
  280. }