酒店预订平台
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

193 linhas
6.1 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 modify($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. try {
  37. //设置入参
  38. $data = [
  39. "order_id" => $orderId,
  40. "hotel_id" => $param['hotel_id'],
  41. "hotel_name" => $hotelInfo['data']['hotel_name'],
  42. "hotel_phone" => $hotelInfo['data']['hotel_phone'],
  43. "country_name" => $hotelInfo['data']['country_name'],
  44. "province_name" => $hotelInfo['data']['province_name'],
  45. "city_name" => $hotelInfo['data']['city_name'],
  46. "detail_address" => $hotelInfo['data']['detail_address'],
  47. //房型
  48. "room_id" => $param['data']['room_id'],
  49. "room_name" => $roomInfo['data']['room_name'],
  50. "room_memo" => $roomInfo['data']['room_memo'],
  51. //价格方案
  52. "plan_id" => $param['data']['plan_id'],
  53. "plan_name" => $roomPlan['data']['plan_name'],
  54. "plan_memo" => $roomPlan['data']['plan_memo'],
  55. //其他
  56. "check_in_date" => $param['check_in_date'],
  57. "check_out_date" => $param['check_out_date'],
  58. "confirm_status" => $param['confirm_status'],
  59. "confirm_no" => $param['confirm_no'],
  60. "customer_name" => $param['customer_name'],
  61. "customer_comments" => $param['customer_comments'],
  62. "trade_order_number" => $param['trade_order_number'],
  63. "res_person" => $param['res_person'],
  64. "res_person_id" => $param['res_person_id'],
  65. "del_flag"=>0
  66. ];
  67. $orderHotelModel = new OrderHotel();
  68. if (empty($param['id'])) {
  69. $id = $orderHotelModel->insertGetId($data);
  70. return Util::returnArrSu($id);
  71. }else {
  72. $orderHotelModel->save($data, ["id" => $param['id']]);
  73. return Util::returnArrSu($param['id']);
  74. }
  75. }catch (Exception $e){
  76. return Util::returnArrEr("更新酒店子订单失败".$e->getMessage());
  77. }
  78. }
  79. /**
  80. * 获取酒店信息
  81. * @param $id
  82. * @return array
  83. */
  84. public function getHotelInfo($id)
  85. {
  86. try {
  87. $model = new OrderHotel();
  88. $result = $model->where(["id" => $id])->find();
  89. if ($result == null) {
  90. return Util::returnArrEr("获取酒店信息失败" . $id);
  91. }
  92. return Util::returnArrSu($result);
  93. } catch (Exception $e) {
  94. return Util::returnArrEr("获取酒店信息失败" . $id);
  95. }
  96. }
  97. /**
  98. * 获取房型详情
  99. * @param $id
  100. * @return array
  101. */
  102. public function getRoomInfo($id)
  103. {
  104. try {
  105. $model = new CfRoomInfo();
  106. $result = $model->where(["id" => $id])->find();
  107. if ($result == null) {
  108. return Util::returnArrEr("获取房型信息失败" . $id);
  109. }
  110. return Util::returnArrSu($result);
  111. } catch (Exception $e) {
  112. return Util::returnArrEr("获取房型信息失败" . $id);
  113. }
  114. }
  115. /**
  116. * 获取房型价格方案
  117. * @param $id
  118. * @return array
  119. */
  120. public function getRoomPlan($id)
  121. {
  122. try {
  123. $model = new CfRoomInfo();
  124. $result = $model->where(["id" => $id])->find();
  125. if ($result == null) {
  126. return Util::returnArrEr("获取价格方案信息失败" . $id);
  127. }
  128. return Util::returnArrSu($result);
  129. } catch (Exception $e) {
  130. return Util::returnArrEr("获取价格方案信息失败" . $id);
  131. }
  132. }
  133. /**
  134. * 设置子订单金额
  135. * @param int $subOrderId
  136. * @return array
  137. */
  138. public function setSubOrderAmount( int $subOrderId) {
  139. try{
  140. $purchaseModel = new Purchase();
  141. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select();
  142. $cost = 0;
  143. $amount = 0;
  144. $count = 0;
  145. foreach ($purchaseList as $purchase) {
  146. $cost += $purchase['total_cost'];
  147. $amount += $purchase['total_price'];
  148. $count += $purchase['count'];
  149. }
  150. OrderHotel::update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]);
  151. return Util::returnArrSu();
  152. }catch (Exception $e){
  153. return Util::returnArrEr("更新酒店订单子表金额失败".$subOrderId);
  154. }
  155. }
  156. /**
  157. * 获取详情
  158. * @param $id
  159. * @return array
  160. */
  161. public function getInfoById($id) {
  162. try {
  163. $model = new OrderHotel();
  164. $result = $model->where(["id" => $id])->find();
  165. if ($result == null) {
  166. return Util::returnArrEr("获取子订单信息失败" . $id);
  167. }
  168. return Util::returnArrSu($result);
  169. } catch (Exception $e) {
  170. return Util::returnArrEr("获取子订单信息失败" . $id);
  171. }
  172. }
  173. /**
  174. * 删除记录
  175. * @param $order_id
  176. */
  177. public function delete($order_id){
  178. $model = new OrderHotel();
  179. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  180. }
  181. }