request->param(); $params['sort_type'] = !empty($params['sort_type']) ? $params['sort_type'] : 1; $field = ['id','name','image','price','original_price','tags','lat','lng']; if (!empty($params['lng']) && !empty($params['lng'])){ $field[] = "(st_distance(point ({$params['lng']}, {$params['lat']}),point(lng,lat))*111195) as distance"; } $query = HotelModel::field($field); if (!empty($params['lng']) && !empty($params['lng']) && $params['sort_type'] == 1){ $query->order('distance asc'); } if ($params['sort_type'] == 2){ $query->order('price asc'); } $list = $query->where('status', 1) ->order('weigh desc') ->order('id desc') ->autopage() ->select(); foreach ($list as $k => $v) { // 计算距离 $list[$k]['distance'] = distance_ext($v['distance'] ?? -1); } return $this->success('success', $list); } // 详情 public function info() { $params = $this->request->param(); $field = ['id','name','image','images','price','original_price','tags','lat','lng','address']; if (!empty($params['lng']) && !empty($params['lng'])){ $field[] = "(st_distance(point ({$params['lng']}, {$params['lat']}),point(lng,lat))*111195) as distance"; } $query = HotelModel::field($field); $query->where('id', $params['id']); $info = $query->where('status', 1)->find(); if (!$info){ return $this->error('信息不存在'); } // 计算距离 $info['distance'] = distance_ext($info['distance'] ?? -1); // 房间列表 $info['room_list'] = HotelRoomModel::where('hotel_id',$info['id'])->where('status',1)->order('weigh desc')->order('id desc')->select(); return $this->success('success', $info); } // 详情 public function room_info() { $params = $this->request->param(); $info = HotelRoomModel::where('id',$params['id'])->where('status',1)->find(); return $this->success('success', $info); } public function apply() { $params = $this->request->param(); if (empty($params['room_id'])) { return $this->error('参数缺失'); } if (empty($params['start_date'])) { return $this->error('参数缺失'); } if (empty($params['end_date'])) { return $this->error('参数缺失'); } if (empty($params['name'])) { return $this->error('参数缺失'); } if (empty($params['phone'])) { return $this->error('参数缺失'); } $user_id = $this->auth->id; $info = HotelRoomModel::with([ 'hotel'=>function ($query) { $query->field(['id','name','image','images','price','original_price']); } ])->where('id',$params['id'])->where('status',1)->find(); if (!$info) { return $this->error('房间不存在'); } if (!empty($info['hotel'])) { return $this->error('酒店信息有误'); } // 开始报名 $data = [ 'hotel_id' => $info['hotel_id'], 'room_id' => $info['id'], 'user_id' => $user_id, '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), 'order_no' => createUniqueNo('H', $user_id), 'pay_amount' => bcmul($info['price'], 1, 2), 'status' => 1, 'create_time' => time() ]; if (!Db::name('hotel_order')->insertGetId($data)) { return $this->error('订单创建失败'); } return $this->success('提交成功'); } public function applyList() { $user_id = $this->auth->id; $query = Db::name('university_event_apply')->where('user_id',$user_id); } }