浏览代码

会议室

chenhao 4 年之前
父节点
当前提交
55399a9a55
共有 3 个文件被更改,包括 275 次插入55 次删除
  1. 4 4
      application/admin/view/meeting/add.html
  2. 4 4
      application/admin/view/meeting/edit.html
  3. 267 47
      application/api/controller/Meeting.php

+ 4 - 4
application/admin/view/meeting/add.html

@@ -82,15 +82,15 @@
         </div>
     </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Gongziri')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Gongziri')}(元/每60分钟):</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-gongziri" data-rule="required" class="form-control" name="row[gongziri]" type="text">
+            <input id="c-gongziri" data-rule="required" class="form-control" name="row[gongziri]" type="number">
         </div>
     </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Xiuxiri')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Xiuxiri')}(元/每60分钟):</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-xiuxiri" data-rule="required" class="form-control" name="row[xiuxiri]" type="text">
+            <input id="c-xiuxiri" data-rule="required" class="form-control" name="row[xiuxiri]" type="number">
         </div>
     </div>
     <div class="form-group">

+ 4 - 4
application/admin/view/meeting/edit.html

@@ -79,15 +79,15 @@
             </div>
         </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Gongziri')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Gongziri')}(元/每60分钟):</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-gongziri" data-rule="required" class="form-control" name="row[gongziri]" type="text" value="{$row.gongziri|htmlentities}">
+            <input id="c-gongziri" data-rule="required" class="form-control" name="row[gongziri]" type="number" value="{$row.gongziri|htmlentities}">
         </div>
     </div>
     <div class="form-group">
-        <label class="control-label col-xs-12 col-sm-2">{:__('Xiuxiri')}:</label>
+        <label class="control-label col-xs-12 col-sm-2">{:__('Xiuxiri')}(元/每60分钟):</label>
         <div class="col-xs-12 col-sm-8">
-            <input id="c-xiuxiri" data-rule="required" class="form-control" name="row[xiuxiri]" type="text" value="{$row.xiuxiri|htmlentities}">
+            <input id="c-xiuxiri" data-rule="required" class="form-control" name="row[xiuxiri]" type="number" value="{$row.xiuxiri|htmlentities}">
         </div>
     </div>
     <div class="form-group">

+ 267 - 47
application/api/controller/Meeting.php

@@ -14,8 +14,9 @@ use think\Db;
  */
 class Meeting extends Api
 {
-    protected $noNeedLogin = ['lists', 'parkLists', 'listInfo', 'qustion', 'qustionInfo', 'buildInfo', 'protable', 'trueTime', 'NoticeInfo', 'GgInfo'];
+    protected $noNeedLogin = ['lists', 'parkLists', 'listInfo', 'qustion', 'qustionInfo', 'buildInfo', 'protable', 'trueTime', 'chooseTime', 'GgInfo'];
     protected $noNeedRight = ['*'];
+
     /**
      * 会议室列表
      * @param string $page 页数
@@ -45,11 +46,11 @@ class Meeting extends Api
 
         if (isset($area_name) && !empty($area_name)) {
 
-            $name = Park::where('name','like','%'.$area_name.'%')->column('id');
+            $name = Park::where('name', 'like', '%' . $area_name . '%')->column('id');
 
-            $idStr = implode(',',$name);
+            $idStr = implode(',', $name);
             if (!empty($idStr)) {
-                $mp['p_id'] = ['in',$idStr];
+                $mp['p_id'] = ['in', $idStr];
             } else {
                 $mp['p_id'] = 0;
             }
@@ -137,13 +138,13 @@ class Meeting extends Api
 
         $data['gongzui_start_time'] = $data['gongzuori_shijina_ids'][0];
 
-        $data['gongzui_start_end'] = $data['gongzuori_shijina_ids'][$count-1];
+        $data['gongzui_start_end'] = $data['gongzuori_shijina_ids'][$count - 1];
 
         $count = count($data['xiuxiri_shijian_ids']);
 
         $data['xiuxi_start_time'] = $data['xiuxiri_shijian_ids'][0];
 
-        $data['xiuxi_start_end'] = $data['xiuxiri_shijian_ids'][$count-1];
+        $data['xiuxi_start_end'] = $data['xiuxiri_shijian_ids'][$count - 1];
 
         $user = $this->auth->getUser();
 
@@ -156,74 +157,111 @@ class Meeting extends Api
         }
     }
     /**
-     * 获取租赁有效时间
-     * @param string $id 会议室id
-     * @param string $date 所选日期 2021-03-11
+     * 会议室选择预约时间
+     * @param string $m_id 会议室id
+     * @param string $make_day 所选日期2021-03-11
      */
-    public function trueTime()
+    public function chooseTime()
     {
-        $id = $this->request->get('id');
-
-        $date = $this->request->get('date');
+        $data = $this->request->get();
 
-        if (!isset($id) || empty($id)) return $this->error('缺少参数101');
+        if (!isset($data['m_id']) || empty($data['m_id'])) return $this->success('参数错误101');
 
-        if (!isset($date) || empty($date)) return $this->error('缺少参数102');
+        if (!isset($data['make_day']) || empty($data['make_day'])) return $this->success('参数错误102');
 
         $meetingModel = new MeetingModel();
 
-        $data = $meetingModel->where('switch', 1)
-            ->where('id', $id)
-            ->order('sort desc')
-            ->find();
-        $count = count($data['gongzuori_shijina_ids']);
+        $meetingOrder = new MeetingOrder();
 
-        $data['gongzui_start_time'] = $data['gongzuori_shijina_ids'][0];
+        $issetTime = $meetingOrder->where('m_id', $data['m_id'])->where('make_day', $data['make_day'])->column('make_time');
 
-        $data['gongzui_start_end'] = $data['gongzuori_shijina_ids'][$count-1];
+        if ($issetTime) {
+            $arr = array();
+            foreach ($issetTime as $v) {
+                $arr = array_merge($arr,explode(',',$v));
+            }
+        }
 
-        $count = count($data['xiuxiri_shijian_ids']);
+        $arr = array_unique($arr);
 
-        $data['xiuxi_start_time'] = $data['xiuxiri_shijian_ids'][0];
+        $meetingData = $meetingModel->where('id', $data['m_id'])->field('id,title,image,address,xiuxiri,gongziri,gongzuori_shijina_ids,xiuxiri_shijian_ids')->find();
 
-        $data['xiuxi_start_end'] = $data['xiuxiri_shijian_ids'][$count-1];
+        $res = [];
+        if (empty($arr)) {
 
-        $orderModel = new MeetingOrder();
+            $week = date('w', strtotime($data['make_day']));
 
-        $order= $orderModel->with(['meeting'])
-            ->where('make_day',$date)
-            ->where('m_id',$id)
-            ->column('make_time');
-        if (empty($order)) {
-            $week = date('w',strtotime($date));
+            if ($week == 6 || $week == 0) {
 
-            if ($week==6|| $week==0) {
-                return $this->success('',$data['xiuxiri_shijian_ids']);
+                $time = explode(',',$meetingData['xiuxiri_shijian_ids']);
+
+                foreach ($time as $k=>$v) {
+                    $time[$k]['value'] = $v;
+                    $time[$k]['status'] = 1;
+                }
             } else {
-                return $this->success('',$data['gongzuori_shijina_ids']);
+
+                $time = explode(',',$meetingData['gongzuori_shijina_ids']);
+
+                foreach ($time as $k=>$v) {
+                    $time[$k]['value'] = $v;
+                    $time[$k]['status'] = 1;
+                }
             }
         } else {
+            $week = date('w', strtotime($data['make_day']));
 
-        }
-        dump($order);die;
+            if ($week == 6 || $week == 0) {
 
 
+                $time = explode(',',$meetingData['xiuxiri_shijian_ids']);
 
+                foreach ($time as $k=>$v) {
 
+                    foreach ($arr as $m=>$n) {
+                        if ($v==$n) {
+                            $res[$k]['value'] = $v;
+                            $res[$k]['status'] = 0;
+                            break;
+                        } else {
+                            $res[$k]['value'] = $v;
+                            $res[$k]['status'] = 1;
+                        }
+                    }
+                }
+            } else {
+                $time = $meetingData['gongzuori_shijina_ids'];
+                foreach ($time as $k=>$v) {
+
+                    foreach ($arr as $m=>$n) {
+                        if ($v==$n) {
+                            $res[$k]['value'] = $v;
+                            $res[$k]['status'] = 0;
+                            break;
+                        } else {
+                            $res[$k]['value'] = $v;
+                            $res[$k]['status'] = 1;
+                        }
+                    }
+                }
+            }
+        }
+        return $this->success('',$res);
     }
 
+
     /**
      * 预约订单信息
      * @ApiMethod (POST)
-     * @param string $m_id  会议室id
-     * @param string $make_day  所选日期2021-03-11
+     * @param string $m_id 会议室id
+     * @param string $make_day 所选日期2021-03-11
      * @param string $make_time 所选时间段多个用,号分割
      */
     public function order()
     {
         $data = $this->request->post();
 
-        if (!isset($data['id']) || empty($data['id'])) return $this->success('参数错误101');
+        if (!isset($data['m_id']) || empty($data['m_id'])) return $this->success('参数错误101');
 
         if (!isset($data['make_day']) || empty($data['make_day'])) return $this->success('参数错误102');
 
@@ -231,23 +269,205 @@ class Meeting extends Api
 
         $meetingModel = new MeetingModel();
 
-        $data['meeting'] = $meetingModel->where('id',$data['id'])->find();
+        $data['meeting'] = $meetingModel->where('id', $data['m_id'])->field('id,title,image,address,xiuxiri,gongziri')->find();
 
-        $week = date('w',strtotime($data['make_day']));
+        $week = date('w', strtotime($data['make_day']));
 
-        $countTime = count(explode(',',$data['make_time']));
+        $countTime = count(explode(',', $data['make_time']));
 
-        $data['langTime'] = (60*$countTime).'分钟';
+        $data['lang_time'] = (60 * $countTime) . '分钟';
 
-        if ($week==6|| $week==0) {
+        if ($week == 6 || $week == 0) {
 
-//            $data['money'] =
+            $data['money'] = $data['meeting']['xiuxiri'] * $countTime;
         } else {
-            return $this->success('',$data['gongzuori_shijina_ids']);
+
+            $data['money'] = $data['meeting']['gongziri'] * $countTime;
         }
 
+        $user = $this->auth->getUser();
+
+        $data['qiye_name'] = $user['company'];
+
+        $data['is_qiye'] = 0;
+
+        if ($user['group_id'] == 2) {
+
+            $data['is_qiye'] = 1;
+
+        }
+
+        if ($user['edu'] >= 60 * $countTime) {
+            $data['money'] = "免费";
+            $time = ($user['edu'] - (60 * $countTime)) / 60;
+            $data['notice'] = "(没有超出免费使用时间,剩余" . $time . "小时)";
+        } else {
+            if ($week == 6 || $week == 0) {
+
+                $data['money'] = $data['meeting']['xiuxiri'] * (((60 * $countTime) - $user['edu']) / 60);
+                $data['notice'] = "(已超出免费时长本次收费)";
+            } else {
+
+                $data['money'] = $data['meeting']['gongziri'] * (((60 * $countTime) - $user['edu']) / 60);
+                $data['notice'] = "(已超出免费时长本次收费)";
+            }
+
+        }
+        return $this->success('', $data);
+
+    }
+
+    /**
+     * 提交预约
+     * @ApiMethod (POST)
+     * @param string $m_id 会议室id
+     * @param string $make_day 所选日期2021-03-11
+     * @param string $make_time 所选时间段多个用,号分割
+     */
+    public function trueTime()
+    {
+        $data = $this->request->post();
+
+        if (!isset($data['m_id']) || empty($data['m_id'])) return $this->success('参数错误101');
+
+        if (!isset($data['make_day']) || empty($data['make_day'])) return $this->success('参数错误102');
+
+        if (!isset($data['make_time']) || empty($data['make_time'])) return $this->success('参数错误103');
+
+        $orderModel = new MeetingOrder();
+
+        $issetTime = $orderModel->where('m_id', $data['m_id'])->where('make_day', $data['make_day'])->column('make_time');
+
+        if ($issetTime) {
+            $arr = array();
+            foreach ($issetTime as $v) {
+                $arr = array_merge($arr,explode(',',$v));
+            }
+        }
+        $arr = array_unique($arr);
+
+        $makeTimeArr = explode(',',$data['make_time']);
+
+
+        $chongfuArr=array_intersect($arr,$makeTimeArr);
+
+        if ($chongfuArr) return $this->error('刚刚有人预约了此时间段,请退出重新选择时间');
+
+        $meetingModel = new MeetingModel();
+
+
+        $data['meeting'] = $meetingModel->where('id', $data['m_id'])->field('id,title,image,address,xiuxiri,gongziri')->find();
+
+        $week = date('w', strtotime($data['make_day']));
+
+        $countTime = count(explode(',', $data['make_time']));
+
+        $data['lang_time'] = (60 * $countTime) . '分钟';
+
+        if ($week == 6 || $week == 0) {
+
+            $data['money'] = $data['meeting']['xiuxiri'] * $countTime;
+        } else {
+
+            $data['money'] = $data['meeting']['gongziri'] * $countTime;
+        }
+
+        $user = $this->auth->getUser();
+
+
+        $data['qiye_name'] = $user['company'];
+
+        $data['is_qiye'] = 0;
+
+        if ($user['group_id'] == 2) {
+
+            $data['is_qiye'] = 1;
+
+        }
+
+        if ($user['edu'] >= 60 * $countTime) {
+            $data['money'] = "免费";
+            $time = ($user['edu'] - (60 * $countTime)) / 60;
+            $data['notice'] = "(没有超出免费使用时间,剩余" . $time . "小时)";
+        } else {
+            if ($week == 6 || $week == 0) {
+
+                $data['money'] = $data['meeting']['xiuxiri'] * (((60 * $countTime) - $user['edu']) / 60);
+                $data['notice'] = "(已超出免费时长本次收费)";
+            } else {
+
+                $data['money'] = $data['meeting']['gongziri'] * (((60 * $countTime) - $user['edu']) / 60);
+                $data['notice'] = "(已超出免费时长本次收费)";
+            }
+
+        }
+
+
+        $year = date('Y', time());
+
+        $month = date('m', time());
+
+        $day = date('d', time());
+
+        $save = [
+            'number'      => $year . $month . $day . 'N' . rand(0, 10000),
+            'm_id'        => $data['m_id'],
+            'u_id'        => $user['id'],
+            'make_day'    => $data['make_day'],
+            'make_time'   => $data['make_time'],
+            'money'       => $data['money'],
+            'long_time'   => $data['lang_time'],
+            'qi_name'     => $user['company'],
+            'notice'      => $data['notice'],
+            'mian_time'      => $user['edu'],
+            'create_time' => date('Y-m-d H:i:s', time())
+        ];
+
+        $save = $orderModel->allowField(true)->save($save);
+
+        if ($save) {
+            $id = $orderModel->getLastInsID();
+
+            if ($user['group_id']==2) {
+
+                if ($user['edu'] >= 60 * $countTime) {
+                    $data['money'] = "免费";
+                    $time = ($user['edu'] - (60 * $countTime)) / 60;
+                    $userTime = $user['edu']-$countTime*60;
+
+                    Db::name('user')->where('id',$user['id'])->update(['edu' => $userTime]);
+                } else {
+                    Db::name('user')->where('id',$user['id'])->update(['edu' => 0]);
+                }
+            }
+            return $this->success('预约成功', ['id' => $id]);
+        } else {
+            return $this->error('预约失败');
+        }
+    }
+
+    /**
+     * 订单详情
+     * @param string $id id
+     *
+     */
+    public function orderInfo()
+    {
+        $id = $this->request->get('id');
+
+        if (!isset($id) || empty($id)) return $this->error('参数错误');
+
+        $orderModel = new MeetingOrder();
+
+        $data = $orderModel->with(['meeting'])
+            ->where('id',$id)
+            ->find();
+        $user = $this->auth->getUser();
 
+        $data['company'] = $user['company'];
 
+        if ($user['group_id'] == 2) $data['is_qiye'] = 1;
 
+        return $this->success('',$data);
     }
 }