Panda 3 ヶ月 前
コミット
e8021f33aa

+ 60 - 4
application/api/controller/Hotel.php

@@ -5,6 +5,7 @@ namespace app\api\controller;
 use addons\epay\library\Service;
 use app\common\controller\Api;
 use app\common\model\HotelModel;
+use app\common\model\HotelOrderModel;
 use app\common\model\HotelRoomModel;
 use app\common\model\PayOrderModel;
 use app\common\model\UniversityEventModel;
@@ -20,6 +21,12 @@ class Hotel extends Api
 {
     protected $noNeedLogin = [''];
     protected $noNeedRight = ['*'];
+    protected $status = [
+        0 => '全部',
+        1 => '待入住',
+        2 => '已入住',
+        3 => '已取消',
+    ];
 
     // 活动列表
     public function list()
@@ -108,11 +115,11 @@ class Hotel extends Api
             'hotel'=>function ($query) {
                 $query->field(['id','name','image','images','price','original_price']);
             }
-        ])->where('id',$params['id'])->where('status',1)->find();
+        ])->where('id',$params['room_id'])->where('status',1)->find();
         if (!$info) {
             return $this->error('房间不存在');
         }
-        if (!empty($info['hotel'])) {
+        if (empty($info['hotel'])) {
             return $this->error('酒店信息有误');
         }
 
@@ -138,10 +145,59 @@ class Hotel extends Api
         return $this->success('提交成功');
     }
 
-    public function applyList()
+    // 订单列表
+    public function myApply()
     {
+        $params = $this->request->param();
+        $user_id = $this->auth->id;
+
+        $query = HotelOrderModel::with([
+            'room'=>function ($query) {
+                $query->field(['id','name','image']);
+            }
+        ])->where('user_id',$user_id);
+
+        switch ($params['status']){
+            case 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);
+                break;
+            case 3:
+                $query->where('status',0);
+                break;
+            default:
+                break;
+        }
+
+        $list = $query->order('id','desc')->autopage()->select();
+        foreach ($list as $key=>$val){
+            if ($val['status'] == 1){
+
+            }else{
+                $list[$key]['status_txt'] = '已取消';
+            }
+        }
+        return $this->success('获取成功',$list);
+    }
+
+    // 订单取消
+    public function applyCancel()
+    {
+        $params = $this->request->param();
         $user_id = $this->auth->id;
-        $query = Db::name('university_event_apply')->where('user_id',$user_id);
 
+        $order = HotelOrderModel::where('user_id',$user_id)->where('id',$params['order_id'])->where('status',1)->find();
+        if (!$order){
+            return $this->error('订单不存在或已取消');
+        }
+        if (date('Y-m-d H:i:s') > ($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])){
+            return $this->error('操作失败');
+        }
+        return $this->success('操作成功');
     }
 }

+ 40 - 0
application/common/model/HotelOrderModel.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace app\common\model;
+
+use think\Db;
+use think\Model;
+
+/**
+ * 群组
+ */
+class HotelOrderModel extends Model
+{
+    // 表名
+    protected $name = 'hotel_order';
+    // 开启自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    public function getImageAttr($value, $data)
+    {
+        return cdnurl($value);
+    }
+
+    public function getImagesAttr($value, $data)
+    {
+        $value = explode(',',$value);
+        foreach ($value as &$v){
+            $v = cdnurl($v);
+        }
+        return $value;
+    }
+
+    public function room()
+    {
+        return $this->hasOne(HotelRoomModel::class, 'id', 'room_id');
+    }
+}

+ 1 - 1
application/common/model/HotelRoomModel.php

@@ -57,6 +57,6 @@ class HotelRoomModel extends Model
 
     public function hotel()
     {
-        return $this->hasOne(Hotel::class, 'id', 'hotel_id');
+        return $this->hasOne(HotelModel::class, 'id', 'hotel_id');
     }
 }