酒店预订平台
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.
 
 
 
 
 
 

344 lines
11 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\dao;
  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. "purchase_user_id" => $param['purchase_user_id'],
  66. "purchase_user" => $param['purchase_user'],
  67. "supplier_id" => $param['supplier_id'],
  68. "supplier_name" => $param['supplier_name'],
  69. "del_flag"=>0
  70. ];
  71. $orderHotelModel = new OrderHotel();
  72. if (empty($param['id'])) {
  73. $id = $orderHotelModel->insertGetId($data);
  74. return Util::returnArrSu("", $id);
  75. }else {
  76. $orderHotelModel->save($data, ["id" => $param['id']]);
  77. return Util::returnArrSu("", $param['id']);
  78. }
  79. }catch (Exception $e){
  80. return Util::returnArrEr("更新酒店子订单失败:".$e->getMessage());
  81. }
  82. }
  83. /**
  84. * 获取酒店信息
  85. * @param $id
  86. * @return array
  87. */
  88. public function getHotelInfo($id)
  89. {
  90. try {
  91. $model = new CfHotelInfo();
  92. $result = $model->where(["id" => $id])->find();
  93. if ($result == null) {
  94. return Util::returnArrEr("获取酒店信息失败:" . $id);
  95. }
  96. return Util::returnArrSu("",$result->toArray());
  97. } catch (Exception $e) {
  98. return Util::returnArrEr("获取酒店信息失败:" . $id);
  99. }
  100. }
  101. /**
  102. * 获取房型详情
  103. * @param $id
  104. * @return array
  105. */
  106. public function getRoomInfo($id)
  107. {
  108. try {
  109. $model = new CfRoomInfo();
  110. $result = $model->where(["id" => $id])->find();
  111. if ($result == null) {
  112. return Util::returnArrEr("获取房型信息失败:" . $id);
  113. }
  114. return Util::returnArrSu("", $result->toArray());
  115. } catch (Exception $e) {
  116. return Util::returnArrEr("获取房型信息失败:" . $id);
  117. }
  118. }
  119. /**
  120. * 获取房型价格方案
  121. * @param $id
  122. * @return array
  123. */
  124. public function getRoomPlan($id)
  125. {
  126. try {
  127. $model = new CfRoomPlan();
  128. $result = $model->where(["id" => $id])->find();
  129. if ($result == null) {
  130. return Util::returnArrEr("获取价格方案信息失败:" . $id);
  131. }
  132. return Util::returnArrSu("",$result->toArray());
  133. } catch (Exception $e) {
  134. return Util::returnArrEr("获取价格方案信息失败:" . $id);
  135. }
  136. }
  137. /**
  138. * 设置子订单金额
  139. * @param int $subOrderId
  140. * @return array
  141. */
  142. public function setSubOrderAmount( int $subOrderId) {
  143. try{
  144. $purchaseModel = new Purchase();
  145. $purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select()->toArray();
  146. $cost = 0;
  147. $amount = 0;
  148. $count = 0;
  149. foreach ($purchaseList as $purchase) {
  150. $cost += $purchase['total_cost'];
  151. $amount += $purchase['total_price'];
  152. $count += $purchase['count'];
  153. }
  154. $orderHotel = new OrderHotel();
  155. $orderHotel->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count, "profit"=>$amount-$cost],["id"=>$subOrderId]);
  156. return Util::returnArrSu();
  157. }catch (Exception $e){
  158. return Util::returnArrEr("更新酒店订单子表金额失败:".$subOrderId);
  159. }
  160. }
  161. /**
  162. * 获取详情
  163. * @param $id
  164. * @return array
  165. */
  166. public function getInfoById($id) {
  167. try {
  168. $model = new OrderHotel();
  169. $result = $model->where(["id" => $id])->find();
  170. if ($result == null) {
  171. return Util::returnArrEr("获取子订单信息失败:" . $id);
  172. }
  173. return Util::returnArrSu("",$result->toArray());
  174. } catch (Exception $e) {
  175. return Util::returnArrEr("获取子订单信息失败:" . $id);
  176. }
  177. }
  178. /**
  179. * 删除记录
  180. * @param $order_id
  181. */
  182. public function delete($order_id){
  183. $model = new OrderHotel();
  184. $model->save(["del_flag"=>1],["order_id"=>$order_id]);
  185. }
  186. /**
  187. * 删除记录
  188. * @param $id
  189. */
  190. public function delById($id) {
  191. $model = new OrderHotel();
  192. $model->save(["del_flag"=>1],["id"=>$id]);
  193. }
  194. /**
  195. * 获取酒店子订单列表
  196. * @param $orderId
  197. * @return array
  198. */
  199. public function getListByOrderId($orderId){
  200. $subOrderModel = new OrderHotel();
  201. try {
  202. $subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select()->toArray();
  203. if (null == $subOrderList) {
  204. return Util::returnArrSu("",[]);
  205. }
  206. return Util::returnArrSu("", $subOrderList);
  207. }catch (Exception $e) {
  208. return Util::returnArrEr("获取酒店订单列表异常:".$e->getMessage());
  209. }
  210. }
  211. /**=====================================**/
  212. /**
  213. * 更新付款单下的状态
  214. * @param $paymentOrderId
  215. * @param $status
  216. * @return array
  217. */
  218. public function setPaymentOrderStatus($paymentOrderId, $status){
  219. try{
  220. $model = new OrderHotel();
  221. $model->save(['payment_order_status'=>$status],['payment_order_id'=>$paymentOrderId]);
  222. return Util::returnArrSu();
  223. }catch (Exception $e){
  224. return Util::returnArrEr("更新收款单下的酒店订单状态失败".$e->getMessage());
  225. }
  226. }
  227. /**
  228. * 添加酒店订单到付款单下
  229. * @param $paymentOrder
  230. * @param $orderIds
  231. * @return array
  232. */
  233. public function addSubOrderInPayment($paymentOrder,$orderIds){
  234. try{
  235. $data = [
  236. "payment_order_id"=>$paymentOrder['id'],
  237. "payment_order_status"=>$paymentOrder['status'],
  238. "payment_order_name"=>$paymentOrder['name']
  239. ];
  240. $model = new OrderHotel();
  241. $model->save($data,["id"=>["in",$orderIds]]);
  242. return Util::returnArrSu();
  243. }catch (Exception $e){
  244. return Util::returnArrEr("添加酒店订单到付款单下失败".$e->getMessage());
  245. }
  246. }
  247. /**
  248. * 将酒店订单从付款单下移除
  249. * @param $orderIds
  250. * @return array
  251. */
  252. public function removeSubOrderFormPayment($orderIds){
  253. try{
  254. $data = [
  255. "payment_order_id"=>0,
  256. "payment_order_status"=>0,
  257. "payment_order_name"=>""
  258. ];
  259. $model = new OrderHotel();
  260. $model->save($data,["id"=>["in",$orderIds]]);
  261. return Util::returnArrSu();
  262. }catch (Exception $e){
  263. return Util::returnArrEr("将酒店订单从付款单下移除失败".$e->getMessage());
  264. }
  265. }
  266. /**
  267. * 删除采购单
  268. * @param $id
  269. * @return array
  270. */
  271. public function delPaymentOrder($id){
  272. try{
  273. $data = [
  274. "payment_order_id"=>0,
  275. "payment_order_status"=>0,
  276. "payment_order_name"=>""
  277. ];
  278. $model = new OrderHotel();
  279. $model->save($data,["payment_order_id"=>$id]);
  280. return Util::returnArrSu();
  281. }catch (Exception $e){
  282. return Util::returnArrEr("将酒店订单从付款单下移除失败".$e->getMessage());
  283. }
  284. }
  285. /**
  286. * 获取主订单ID
  287. * @param $payment_order_id
  288. * @return array
  289. */
  290. public function getOrderMainIdByPayment($payment_order_id){
  291. $subOrderModel = new OrderHotel();
  292. try {
  293. $subOrderList = $subOrderModel->where(["payment_order_id" => $payment_order_id, "del_flag" => 0])->select()->toArray();
  294. if (null == $subOrderList) {
  295. return [];
  296. }
  297. $id = [];
  298. foreach ($subOrderList as $val){
  299. $id[] = $val['order_id'];
  300. }
  301. return array_unique($id);
  302. }catch (Exception $e) {
  303. return [];
  304. }
  305. }
  306. /**
  307. * 获取订单列表
  308. * @param $orderIds
  309. * @return array
  310. */
  311. public function getOrderListByOrderIds($orderIds){
  312. $subOrderModel = new OrderHotel();
  313. try {
  314. $subOrderList = $subOrderModel->where(["order_id" => ["in",$orderIds], "del_flag" => 0])->select()->toArray();
  315. if (null == $subOrderList) {
  316. return [];
  317. }
  318. return $subOrderList;
  319. }catch (Exception $e) {
  320. return [];
  321. }
  322. }
  323. }