酒店预订平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

173 lines
5.4 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/10/27
  6. * Time: 13:36
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\model\CfRoomInfo;
  11. use app\admin\model\OrderHotel;
  12. use app\admin\model\Purchase;
  13. use think\Exception;
  14. class OrderHotelDao
  15. {
  16. /**
  17. * 添加失败
  18. * @param $param
  19. * @param $orderId
  20. * @return array|string
  21. */
  22. public function addInfo($param, $orderId)
  23. {
  24. $hotelInfo = $this->getHotelInfo($param['hotel_id']);
  25. if (!$hotelInfo['flag']){
  26. return $hotelInfo;
  27. }
  28. $roomInfo = $this->getRoomInfo($param['room_id']);
  29. if (!$roomInfo['flag']){
  30. return $roomInfo;
  31. }
  32. $roomPlan = $this->getRoomPlan($param['plan_id']);
  33. if (!$roomPlan['flag']) {
  34. return $roomPlan;
  35. }
  36. //设置入参
  37. $data = [
  38. "order_id" => $orderId,
  39. "hotel_id" => $param['hotel_id'],
  40. "hotel_name" => $hotelInfo['data']['hotel_name'],
  41. "hotel_phone" => $hotelInfo['data']['hotel_phone'],
  42. "country_name" => $hotelInfo['data']['country_name'],
  43. "province_name" => $hotelInfo['data']['province_name'],
  44. "city_name" => $hotelInfo['data']['city_name'],
  45. "detail_address" => $hotelInfo['data']['detail_address'],
  46. //房型
  47. "room_id" => $param['data']['room_id'],
  48. "room_name" => $roomInfo['data']['room_name'],
  49. "room_memo" => $roomInfo['data']['room_memo'],
  50. //价格方案
  51. "plan_id" => $param['data']['plan_id'],
  52. "plan_name" => $roomPlan['data']['plan_name'],
  53. "plan_memo" => $roomPlan['data']['plan_memo'],
  54. //其他
  55. "check_in_date" => $param['check_in_date'],
  56. "check_out_date" => $param['check_out_date'],
  57. "confirm_status" => $param['confirm_status'],
  58. "confirm_no" => $param['confirm_no'],
  59. "customer_name" => $param['customer_name'],
  60. "customer_comments" => $param['customer_comments'],
  61. "trade_order_number" => $param['trade_order_number'],
  62. "res_person" => $param['res_person'],
  63. "res_person_id" => $param['res_person_id']
  64. ];
  65. $orderHotelModel = new OrderHotel();
  66. $id = $orderHotelModel->insertGetId($data);
  67. return Util::returnArrSu($id);
  68. }
  69. /**
  70. * 获取酒店信息
  71. * @param $id
  72. * @return array
  73. */
  74. public function getHotelInfo($id)
  75. {
  76. try {
  77. $model = new OrderHotel();
  78. $result = $model->where(["id" => $id])->find();
  79. if ($result == null) {
  80. return Util::returnArrEr("获取酒店信息失败" . $id);
  81. }
  82. return Util::returnArrSu($result);
  83. } catch (Exception $e) {
  84. return Util::returnArrEr("获取酒店信息失败" . $id);
  85. }
  86. }
  87. /**
  88. * 获取房型详情
  89. * @param $id
  90. * @return array
  91. */
  92. public function getRoomInfo($id)
  93. {
  94. try {
  95. $model = new CfRoomInfo();
  96. $result = $model->where(["id" => $id])->find();
  97. if ($result == null) {
  98. return Util::returnArrEr("获取房型信息失败" . $id);
  99. }
  100. return Util::returnArrSu($result);
  101. } catch (Exception $e) {
  102. return Util::returnArrEr("获取房型信息失败" . $id);
  103. }
  104. }
  105. /**
  106. * 获取房型价格方案
  107. * @param $id
  108. * @return array
  109. */
  110. public function getRoomPlan($id)
  111. {
  112. try {
  113. $model = new CfRoomInfo();
  114. $result = $model->where(["id" => $id])->find();
  115. if ($result == null) {
  116. return Util::returnArrEr("获取价格方案信息失败" . $id);
  117. }
  118. return Util::returnArrSu($result);
  119. } catch (Exception $e) {
  120. return Util::returnArrEr("获取价格方案信息失败" . $id);
  121. }
  122. }
  123. /**
  124. * 设置子订单金额
  125. * @param int $subOrderId
  126. * @return array
  127. */
  128. public function setSubOrderAmount( int $subOrderId) {
  129. try{
  130. $purchaseModel = new Purchase();
  131. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select();
  132. $cost = 0;
  133. $amount = 0;
  134. $count = 0;
  135. foreach ($purchaseList as $purchase) {
  136. $cost += $purchase['total_cost'];
  137. $amount += $purchase['total_price'];
  138. $count += $purchase['count'];
  139. }
  140. OrderHotel::update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]);
  141. return Util::returnArrSu();
  142. }catch (Exception $e){
  143. return Util::returnArrEr("更新酒店订单子表金额失败".$subOrderId);
  144. }
  145. }
  146. /**
  147. * 获取详情
  148. * @param $id
  149. * @return array
  150. */
  151. public function getInfoById($id) {
  152. try {
  153. $model = new OrderHotel();
  154. $result = $model->where(["id" => $id])->find();
  155. if ($result == null) {
  156. return Util::returnArrEr("获取子订单信息失败" . $id);
  157. }
  158. return Util::returnArrSu($result);
  159. } catch (Exception $e) {
  160. return Util::returnArrEr("获取子订单信息失败" . $id);
  161. }
  162. }
  163. }