|
@@ -104,6 +104,50 @@ class Hotel extends Api
|
|
|
return $this->success('success', $info);
|
|
|
}
|
|
|
|
|
|
+ public function order_page()
|
|
|
+ {
|
|
|
+ $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['num'])) {
|
|
|
+ return $this->error('参数缺失');
|
|
|
+ }
|
|
|
+ $model = new HotelRoomModel();
|
|
|
+ $info = $model->getDetail(
|
|
|
+ params: ['id' => $params['room_id']],
|
|
|
+ with: [
|
|
|
+ 'hotel'=>function ($query) {
|
|
|
+ $query->field(['id','name','image','images','price','original_price']);
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ );
|
|
|
+ if (!$info) {
|
|
|
+ return $this->error('房间不存在');
|
|
|
+ }
|
|
|
+ if (empty($info['hotel'])) {
|
|
|
+ return $this->error('酒店信息有误');
|
|
|
+ }
|
|
|
+ $days = (int)((strtotime($params['end_date']) - strtotime($params['start_date'])) / 86400);
|
|
|
+ $pay_amount = bcmul(bcmul($info['price'], $days, 2),$params['num'],2);
|
|
|
+ return $this->success('获取成功', [
|
|
|
+ 'info' => $info,
|
|
|
+ 'order' => [
|
|
|
+ 'room_id' => $params['room_id'],
|
|
|
+ 'start_date' => $params['start_date'],
|
|
|
+ 'end_date' => $params['end_date'],
|
|
|
+ 'days' => $days,
|
|
|
+ 'pay_amount' => $pay_amount,
|
|
|
+ ]
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
public function apply()
|
|
|
{
|
|
|
$params = $this->request->param();
|
|
@@ -126,11 +170,15 @@ class Hotel extends Api
|
|
|
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['room_id'])->where('status',1)->find();
|
|
|
+ $model = new HotelRoomModel();
|
|
|
+ $info = $model->getDetail(
|
|
|
+ params: ['id' => $params['room_id']],
|
|
|
+ with: [
|
|
|
+ 'hotel'=>function ($query) {
|
|
|
+ $query->field(['id','name','image','images','price','original_price']);
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ );
|
|
|
if (!$info) {
|
|
|
return $this->error('房间不存在');
|
|
|
}
|
|
@@ -151,14 +199,17 @@ class Hotel extends Api
|
|
|
'days' => $days,
|
|
|
'order_no' => createUniqueNo('H', $user_id),
|
|
|
'pay_amount' => bcmul(bcmul($info['price'], $days, 2),$params['num'],2),
|
|
|
- 'status' => 1,
|
|
|
'create_time' => time()
|
|
|
];
|
|
|
if (!Db::name('hotel_order')->insertGetId($data)) {
|
|
|
return $this->error('订单创建失败');
|
|
|
}
|
|
|
|
|
|
- return $this->success('提交成功');
|
|
|
+ return $this->success('提交成功',[
|
|
|
+ 'order_no' => $data['order_no'],
|
|
|
+ 'pay_amount' => $data['pay_amount'],
|
|
|
+ 'order_type' => 'hotel_order',
|
|
|
+ ]);
|
|
|
}
|
|
|
|
|
|
// 订单列表
|