酒店预订平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

221 regels
6.9 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\CfHotelInfo;
  11. use app\admin\model\CfRoomInfo;
  12. use app\admin\model\CfRoomPlan;
  13. use app\admin\model\OrderHotel;
  14. use app\admin\model\Purchase;
  15. use think\Exception;
  16. class OrderHotelDao
  17. {
  18. /**
  19. * 更新记录
  20. * @param $param
  21. * @param $orderId
  22. * @return array|string
  23. */
  24. public function modify($param, $orderId)
  25. {
  26. $hotelInfo = $this->getHotelInfo($param['hotel_id']);
  27. if (!$hotelInfo['flag']){
  28. return $hotelInfo;
  29. }
  30. $roomInfo = $this->getRoomInfo($param['room_id']);
  31. if (!$roomInfo['flag']){
  32. return $roomInfo;
  33. }
  34. $roomPlan = $this->getRoomPlan($param['plan_id']);
  35. if (!$roomPlan['flag']) {
  36. return $roomPlan;
  37. }
  38. try {
  39. //设置入参
  40. $data = [
  41. "order_id" => $orderId,
  42. "hotel_id" => $param['hotel_id'],
  43. "hotel_name" => $hotelInfo['data']['hotel_name'],
  44. "hotel_phone" => $hotelInfo['data']['hotel_phone'],
  45. "province_name" => $hotelInfo['data']['province_name'],
  46. "city_name" => $hotelInfo['data']['city_name'],
  47. "area_name" => $hotelInfo['data']['area_name'],
  48. "detail_address" => $hotelInfo['data']['detail_address'],
  49. //房型
  50. "room_id" => $param['room_id'],
  51. "room_name" => $roomInfo['data']['room_name'],
  52. "room_memo" => $roomInfo['data']['room_memo'],
  53. //价格方案
  54. "plan_id" => $param['plan_id'],
  55. "plan_name" => $roomPlan['data']['plan_name'],
  56. "plan_memo" => $roomPlan['data']['plan_memo'],
  57. //其他
  58. "check_in_date" => $param['check_in_date'],
  59. "check_out_date" => $param['check_out_date'],
  60. "confirm_status" => $param['confirm_status'],
  61. "confirm_no" => $param['confirm_no'],
  62. "customer_name" => $param['customer_name'],
  63. "customer_comments" => empty($param['customer_comments'])?"":$param['customer_comments'],
  64. "trade_order_number" => $param['trade_order_number'],
  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 CfHotelInfo();
  88. $result = $model->where(["id" => $id])->find();
  89. if ($result == null) {
  90. return Util::returnArrEr("获取酒店信息失败:" . $id);
  91. }
  92. return Util::returnArrSu("",$result->toArray());
  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->toArray());
  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 CfRoomPlan();
  124. $result = $model->where(["id" => $id])->find();
  125. if ($result == null) {
  126. return Util::returnArrEr("获取价格方案信息失败:" . $id);
  127. }
  128. return Util::returnArrSu("",$result->toArray());
  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()->toArray();
  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 = new OrderHotel();
  151. $orderHotel->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count, "profit"=>$amount-$cost],["id"=>$subOrderId]);
  152. return Util::returnArrSu();
  153. }catch (Exception $e){
  154. return Util::returnArrEr("更新酒店订单子表金额失败:".$subOrderId);
  155. }
  156. }
  157. /**
  158. * 获取详情
  159. * @param $id
  160. * @return array
  161. */
  162. public function getInfoById($id) {
  163. try {
  164. $model = new OrderHotel();
  165. $result = $model->where(["id" => $id])->find();
  166. if ($result == null) {
  167. return Util::returnArrEr("获取子订单信息失败:" . $id);
  168. }
  169. return Util::returnArrSu("",$result->toArray());
  170. } catch (Exception $e) {
  171. return Util::returnArrEr("获取子订单信息失败:" . $id);
  172. }
  173. }
  174. /**
  175. * 删除记录
  176. * @param $order_id
  177. */
  178. public function delete($order_id){
  179. $model = new OrderHotel();
  180. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  181. }
  182. /**
  183. * 删除记录
  184. * @param $id
  185. */
  186. public function delById($id) {
  187. $model = new OrderHotel();
  188. $model->save(["del_flag"=>1],["id"=>$id]);
  189. }
  190. /**
  191. * 获取酒店子订单列表
  192. * @param $orderId
  193. * @return array
  194. */
  195. public function getListByOrderId($orderId){
  196. $subOrderModel = new OrderHotel();
  197. try {
  198. $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  199. if (null == $subOrderList) {
  200. return Util::returnArrSu("",[]);
  201. }
  202. return Util::returnArrSu("", $subOrderList);
  203. }catch (Exception $e) {
  204. return Util::returnArrEr("获取酒店订单列表异常:".$e->getMessage());
  205. }
  206. }
  207. }