酒店预订平台
Não pode escolher mais do que 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.
 
 
 
 
 
 

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