Explorar o código

Merge branch 'master' of http://git.huxiukeji.com/lizhen/xiaoshan

lizhen_gitee hai 3 meses
pai
achega
90397f9bef

+ 42 - 7
application/api/controller/Hotel.php

@@ -116,6 +116,9 @@ class Hotel extends Api
         if (empty($params['end_date'])) {
             return $this->error('参数缺失');
         }
+        if (empty($params['num'])) {
+            return $this->error('参数缺失');
+        }
         if (empty($params['name'])) {
             return $this->error('参数缺失');
         }
@@ -134,19 +137,20 @@ class Hotel extends Api
         if (empty($info['hotel'])) {
             return $this->error('酒店信息有误');
         }
-
+        $days = (int)((strtotime($params['end_date']) - strtotime($params['start_date'])) / 86400);
         // 开始报名
         $data = [
             'hotel_id' => $info['hotel_id'],
             'room_id' => $info['id'],
             'user_id' => $user_id,
+            'num' => $params['num'],
             'name' => $params['name'],
             'phone' => $params['phone'],
             'start_date' => $params['start_date'],
             'end_date' => $params['end_date'],
-            'days' => (int)((strtotime($params['end_date']) - strtotime($params['start_date'])) / 86400),
+            'days' => $days,
             'order_no' => createUniqueNo('H', $user_id),
-            'pay_amount' => bcmul($info['price'], 1, 2),
+            'pay_amount' => bcmul(bcmul($info['price'], $days, 2),$params['num'],2),
             'status' => 1,
             'create_time' => time()
         ];
@@ -171,10 +175,10 @@ class Hotel extends Api
 
         switch ($params['status']){
             case 1:
-                $query->where('start_date','<',date('Y-m-d'))->where('status',1);
+                $query->where('start_date','>',date('Y-m-d'))->where('status',1);
                 break;
             case 2:
-                $query->where('start_date','>=',date('Y-m-d'))->where('status',1);
+                $query->where('start_date','<',date('Y-m-d'))->where('status',1);
                 break;
             case 3:
                 $query->where('status',0);
@@ -186,18 +190,49 @@ class Hotel extends Api
         $list = $query->order('id','desc')->autopage()->select();
         foreach ($list as $key=>$val){
             if ($val['status'] == 1){
-                if ($val['start_date'] < date('Y-m-d')){
+                if ($val['start_date'] > date('Y-m-d')){
+                    $list[$key]['status_code'] = 1;
                     $list[$key]['status_txt'] = '待入住';
                 }else{
+                    $list[$key]['status_code'] = 2;
                     $list[$key]['status_txt'] = '已入住';
                 }
             }else{
+                $list[$key]['status_code'] = 3;
                 $list[$key]['status_txt'] = '已取消';
             }
         }
         return $this->success('获取成功',$list);
     }
 
+    // 订单详情
+    public function myApplyInfo()
+    {
+        $params = $this->request->param();
+        $user_id = $this->auth->id;
+
+        $query = HotelOrderModel::with([
+            'room'=>function ($query) {
+                $query->field(['id','name','image']);
+            }
+        ])->where('id',$params['id'])->where('user_id',$user_id);
+
+        $info = $query->find();
+        if ($info['status'] == 1){
+            if ($info['start_date'] > date('Y-m-d')){
+                $info['status_code'] = 1;
+                $info['status_txt'] = '待入住';
+            }else{
+                $info['status_code'] = 2;
+                $info['status_txt'] = '已入住';
+            }
+        }else{
+            $info['status_code'] = 3;
+            $info['status_txt'] = '已取消';
+        }
+        return $this->success('获取成功',$info);
+    }
+
     // 订单取消
     public function applyCancel()
     {
@@ -208,7 +243,7 @@ class Hotel extends Api
         if (!$order){
             return $this->error('订单不存在或已取消');
         }
-        if (date('Y-m-d H:i:s') > ($order['start_date'] . ' 12:00:00')){
+        if (time() > strtotime($order['start_date'] . ' 12:00:00')){
             return $this->error('订单已入住,无法取消');
         }
         if (!HotelOrderModel::where('user_id',$user_id)->where('id',$params['order_id'])->where('status',1)->update(['status'=>0])){

+ 38 - 3
application/api/controller/HotelCanteen.php

@@ -157,10 +157,10 @@ class HotelCanteen extends Api
 
         switch ($params['status']){
             case 1:
-                $query->where('get_to_time','<',time())->where('status',1);
+                $query->where('get_to_time','>',time())->where('status',1);
                 break;
             case 2:
-                $query->where('get_to_time','>=',time())->where('status',1);
+                $query->where('get_to_time','<=',time())->where('status',1);
                 break;
             case 3:
                 $query->where('status',0);
@@ -172,12 +172,15 @@ class HotelCanteen extends Api
         $list = $query->order('id','desc')->autopage()->select();
         foreach ($list as $key=>$val){
             if ($val['status'] == 1){
-                if ($val['get_to_time'] < time()){
+                if ($val['get_to_time'] > time()){
+                    $list[$key]['status_code'] = 1;
                     $list[$key]['status_txt'] = '待用餐';
                 }else{
+                    $list[$key]['status_code'] = 2;
                     $list[$key]['status_txt'] = '已完成';
                 }
             }else{
+                $list[$key]['status_code'] = 3;
                 $list[$key]['status_txt'] = '已取消';
             }
             $list[$key]['get_to_time'] = date('Y-m-d H:i');
@@ -185,6 +188,38 @@ class HotelCanteen extends Api
         return $this->success('获取成功',$list);
     }
 
+    // 订单详情
+    public function myApplyInfo()
+    {
+        $params = $this->request->param();
+        $user_id = $this->auth->id;
+
+        $query = HotelCanteenOrderModel::with([
+            'canteen'=>function ($query) {
+                $query->field(['id','name','image']);
+            },
+            'room'=>function ($query) {
+                $query->field(['id','name','image']);
+            }
+        ])->where('id',$params['id'])->where('user_id',$user_id);
+
+        $info = $query->find();
+        if ($info['status'] == 1){
+            if ($info['get_to_time'] > time()){
+                $info['status_code'] = 1;
+                $info['status_txt'] = '待用餐';
+            }else{
+                $info['status_code'] = 2;
+                $info['status_txt'] = '已完成';
+            }
+        }else{
+            $info['status_code'] = 3;
+            $info['status_txt'] = '已取消';
+        }
+        $info['get_to_time'] = date('Y-m-d H:i');
+        return $this->success('获取成功',$info);
+    }
+
     // 订单取消
     public function applyCancel()
     {