Hotel.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <?php
  2. namespace app\api\controller;
  3. use addons\epay\library\Service;
  4. use app\common\controller\Api;
  5. use app\common\model\HotelModel;
  6. use app\common\model\HotelRoomModel;
  7. use app\common\model\PayOrderModel;
  8. use app\common\model\UniversityEventModel;
  9. use app\common\model\Wallet;
  10. use app\utils\CurlUtil;
  11. use app\utils\Service\Tencent\TencentIm;
  12. use think\Db;
  13. /**
  14. * 老年大学 活动板块
  15. */
  16. class Hotel extends Api
  17. {
  18. protected $noNeedLogin = [''];
  19. protected $noNeedRight = ['*'];
  20. // 活动列表
  21. public function list()
  22. {
  23. $params = $this->request->param();
  24. $params['sort_type'] = !empty($params['sort_type']) ? $params['sort_type'] : 1;
  25. $field = ['id','name','image','price','original_price','tags','lat','lng'];
  26. if (!empty($params['lng']) && !empty($params['lng'])){
  27. $field[] = "(st_distance(point ({$params['lng']}, {$params['lat']}),point(lng,lat))*111195) as distance";
  28. }
  29. $query = HotelModel::field($field);
  30. if (!empty($params['lng']) && !empty($params['lng']) && $params['sort_type'] == 1){
  31. $query->order('distance asc');
  32. }
  33. if ($params['sort_type'] == 2){
  34. $query->order('price asc');
  35. }
  36. $list = $query->where('status', 1)
  37. ->order('weigh desc')
  38. ->order('id desc')
  39. ->autopage()
  40. ->select();
  41. foreach ($list as $k => $v) {
  42. // 计算距离
  43. $list[$k]['distance'] = distance_ext($v['distance'] ?? -1);
  44. }
  45. return $this->success('success', $list);
  46. }
  47. // 详情
  48. public function info()
  49. {
  50. $params = $this->request->param();
  51. $field = ['id','name','image','images','price','original_price','tags','lat','lng','address'];
  52. if (!empty($params['lng']) && !empty($params['lng'])){
  53. $field[] = "(st_distance(point ({$params['lng']}, {$params['lat']}),point(lng,lat))*111195) as distance";
  54. }
  55. $query = HotelModel::field($field);
  56. $query->where('id', $params['id']);
  57. $info = $query->where('status', 1)->find();
  58. if (!$info){
  59. return $this->error('信息不存在');
  60. }
  61. // 计算距离
  62. $info['distance'] = distance_ext($info['distance'] ?? -1);
  63. // 房间列表
  64. $info['room_list'] = HotelRoomModel::where('hotel_id',$info['id'])->where('status',1)->order('weigh desc')->order('id desc')->select();
  65. return $this->success('success', $info);
  66. }
  67. // 详情
  68. public function room_info()
  69. {
  70. $params = $this->request->param();
  71. $info = HotelRoomModel::where('id',$params['id'])->where('status',1)->find();
  72. return $this->success('success', $info);
  73. }
  74. public function apply()
  75. {
  76. $params = $this->request->param();
  77. if (empty($params['room_id'])) {
  78. return $this->error('参数缺失');
  79. }
  80. if (empty($params['start_date'])) {
  81. return $this->error('参数缺失');
  82. }
  83. if (empty($params['end_date'])) {
  84. return $this->error('参数缺失');
  85. }
  86. if (empty($params['name'])) {
  87. return $this->error('参数缺失');
  88. }
  89. if (empty($params['phone'])) {
  90. return $this->error('参数缺失');
  91. }
  92. $user_id = $this->auth->id;
  93. $info = HotelRoomModel::with([
  94. 'hotel'=>function ($query) {
  95. $query->field(['id','name','image','images','price','original_price']);
  96. }
  97. ])->where('id',$params['id'])->where('status',1)->find();
  98. if (!$info) {
  99. return $this->error('房间不存在');
  100. }
  101. if (!empty($info['hotel'])) {
  102. return $this->error('酒店信息有误');
  103. }
  104. // 开始报名
  105. $data = [
  106. 'hotel_id' => $info['hotel_id'],
  107. 'room_id' => $info['id'],
  108. 'user_id' => $user_id,
  109. 'name' => $params['name'],
  110. 'phone' => $params['phone'],
  111. 'start_date' => $params['start_date'],
  112. 'end_date' => $params['end_date'],
  113. 'days' => (int)((strtotime($params['end_date']) - strtotime($params['start_date'])) / 86400),
  114. 'order_no' => createUniqueNo('H', $user_id),
  115. 'pay_amount' => bcmul($info['price'], 1, 2),
  116. 'status' => 1,
  117. 'create_time' => time()
  118. ];
  119. if (!Db::name('hotel_order')->insertGetId($data)) {
  120. return $this->error('订单创建失败');
  121. }
  122. return $this->success('提交成功');
  123. }
  124. public function applyList()
  125. {
  126. $user_id = $this->auth->id;
  127. $query = Db::name('university_event_apply')->where('user_id',$user_id);
  128. }
  129. }