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

254 linhas
8.2 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: nizongfeng
  5. * Date: 2021/11/17
  6. * Time: 17:29
  7. */
  8. namespace app\admin\service;
  9. use app\admin\command\Util;
  10. use app\admin\dao\OrderHotelDao;
  11. use app\admin\dao\OrderItemDao;
  12. use app\admin\dao\OrderMainDao;
  13. use app\admin\dao\PaymentOrderDao;
  14. use think\Db;
  15. class PaymentOrderService
  16. {
  17. /**
  18. * 保存详情
  19. * @param $param
  20. * @return array
  21. */
  22. public function save($param){
  23. //保存
  24. $dao = new PaymentOrderDao();
  25. $addRe = $dao->save($param);
  26. if (!$addRe['flag']) {
  27. return $addRe;
  28. }
  29. return Util::returnArrSu();
  30. }
  31. /**
  32. * 获取列表
  33. * @param $param
  34. * @return array
  35. */
  36. public function getList($param){
  37. $dao = new PaymentOrderDao();
  38. return $dao->getList($param);
  39. }
  40. /**
  41. * 设置状态
  42. * @param $id
  43. * @param $status
  44. * @return array
  45. */
  46. public function setStatus($id,$status) {
  47. Db::startTrans();
  48. //1.设置收购单状态
  49. $dao = new PaymentOrderDao();
  50. $statusRe = $dao->setStatus($id,$status);
  51. if (!$statusRe['flag']) {
  52. Db::rollback();
  53. return$statusRe;
  54. }
  55. //2.设置所有订单表的状态
  56. $hotelDao = new OrderHotelDao();
  57. $hotelRe = $hotelDao->setPaymentOrderStatus($id,$status);
  58. if (!$hotelRe['flag']) {
  59. Db::rollback();
  60. return $hotelRe;
  61. }
  62. $itemDao = new OrderItemDao();
  63. $itemRe = $itemDao->setPaymentOrderStatus($id,$status);
  64. if (!$itemRe['flag']) {
  65. Db::rollback();
  66. return $itemRe;
  67. }
  68. //3.获取所有子订单对应的主订单ID
  69. $hotelIds = $hotelDao->getOrderMainIdByPayment($id);
  70. $itemIds = $itemDao->getOrderMainIdByPayment($id);
  71. $orderMainIds = array_unique(array_merge($hotelIds,$itemIds));
  72. $orderMainDao = new OrderMainDao();
  73. foreach ($orderMainIds as $orderId) {
  74. $setRe = $orderMainDao->setOrderAmount($orderId);
  75. if (!$setRe['flag']) {
  76. Db::rollback();
  77. return $setRe;
  78. }
  79. }
  80. Db::commit();
  81. return Util::returnArrSu();
  82. }
  83. /**
  84. * 添加子订单到付款单
  85. * @param $param
  86. * @return array
  87. */
  88. public function addSubOrder($param){
  89. $model = new PaymentOrderDao();
  90. $infoRe = $model->getInfoById($param['id']);
  91. if (!$infoRe['flag']) {
  92. return $infoRe;
  93. }
  94. if (isset($param['hotel_id']) && count($param['hotel_id'])>0) {
  95. $orderMainDao = new OrderHotelDao();
  96. $addRe = $orderMainDao->addSubOrderInPayment($infoRe['data'],$param['hotel_id']);
  97. if (!$addRe['flag']) {
  98. return $addRe;
  99. }
  100. }
  101. if (isset($param['item_id']) && count($param['item_id'])>0) {
  102. $orderMainDao = new OrderItemDao();
  103. $addRe = $orderMainDao->addSubOrderInPayment($infoRe['data'],$param['item_id']);
  104. if (!$addRe['flag']) {
  105. return $addRe;
  106. }
  107. }
  108. return Util::returnArrSu();
  109. }
  110. /**
  111. * 移除子订单
  112. * @param $param
  113. * @return array
  114. */
  115. public function removeSubOrder($param){
  116. if (isset($param['hotel_id']) && count($param['hotel_id'])>0) {
  117. $orderMainDao = new OrderHotelDao();
  118. $addRe = $orderMainDao->removeSubOrderFormPayment($param['hotel_id']);
  119. if (!$addRe['flag']) {
  120. return $addRe;
  121. }
  122. }
  123. if (isset($param['item_id']) && count($param['item_id'])>0) {
  124. $orderMainDao = new OrderItemDao();
  125. $addRe = $orderMainDao->removeSubOrderFormPayment($param['item_id']);
  126. if (!$addRe['flag']) {
  127. return $addRe;
  128. }
  129. }
  130. return Util::returnArrSu("");
  131. }
  132. /**
  133. * 获取子订单列表
  134. * @param $param
  135. * @return array
  136. */
  137. public function getSubOrderList($param){
  138. $dao = new PaymentOrderDao();
  139. $item_where_arr = ["d.del_flag=0","a.del_flag=0","a.group_id = {$param['group_id']}"];
  140. $hotel_where_arr = ["c.del_flag=0","b.del_flag=0","b.group_id = {$param['group_id']}"];
  141. $where_arr = [];
  142. if ($param['prod_type']=='hotel'){
  143. $item_where_arr[] = " a.id = 0 ";
  144. }else{
  145. $hotel_where_arr[]=" b.id = 0 ";
  146. }
  147. if (!empty($param['sub_order_id'])) {
  148. $item_where_arr[] = " a.id = {$param["sub_order_id"]} ";
  149. $hotel_where_arr[]=" b.id = {$param['sub_order_id']} ";
  150. }
  151. if (!empty($param['order_id'])) {
  152. $item_where_arr[] = " a.order_id = {$param["order_id"]} ";
  153. $hotel_where_arr[]=" b.order_id = {$param['order_id']} ";
  154. }
  155. if (!empty($param['supplier_id'])) {
  156. $item_where_arr[] = " d.supplier_id = {$param["supplier_id"]} ";
  157. $hotel_where_arr[]=" c.supplier_id = {$param['supplier_id']} ";
  158. }
  159. if (!empty($param['confirm_status'])) {
  160. $item_where_arr[] = " a.confirm_status = {$param["confirm_status"]} ";
  161. $hotel_where_arr[]=" b.confirm_status = {$param['confirm_status']} ";
  162. }
  163. if (!empty($param['customer_name'])) {
  164. $item_where_arr[] = " a.customer_name like '%{$param["customer_name"]}%' ";
  165. $hotel_where_arr[]=" b.customer_name like '%{$param['customer_name']}%' ";
  166. }
  167. if (!empty($param['item_id'])) {
  168. $item_where_arr[] = " a.item_id = {$param["item_id"]} ";
  169. }
  170. if (!empty($param['hotel_id'])) {
  171. $hotel_where_arr[] = " b.hotel_id = {$param["hotel_id"]} ";
  172. }
  173. switch ($param['inPayment']) {
  174. case 1:
  175. $item_where_arr[] = " a.payment_order_id = {$param["payment_order_id"]} ";
  176. $hotel_where_arr[]=" b.payment_order_id = {$param['payment_order_id']} ";
  177. break;
  178. case 2:
  179. $item_where_arr[] = " a.payment_order_id != {$param["payment_order_id"]} ";
  180. $hotel_where_arr[]=" b.payment_order_id != {$param['payment_order_id']} ";
  181. break;
  182. case 3:
  183. $item_where_arr[] = " a.payment_order_id = '' ";
  184. $hotel_where_arr[]=" b.payment_order_id = '' ";
  185. }
  186. //金额区间查询
  187. if (!empty($param['startMoney'])) {
  188. $item_where_arr[] = " a.total_cost >= {$param["startMoney"]} ";
  189. $hotel_where_arr[]=" b.total_cost >= {$param['startMoney']} ";
  190. }
  191. if (!empty($param['endMoney'])) {
  192. $item_where_arr[] = " a.total_cost <= {$param["endMoney"]} ";
  193. $hotel_where_arr[]=" b.total_cost <= {$param['endMoney']} ";
  194. }
  195. //时间区间查询
  196. if (!empty($param['startTime']) ) {
  197. $item_where_arr[] = " a.check_in_date >= '{$param["startTime"]} 00:00:00' ";
  198. $hotel_where_arr[]=" b.check_in_date >= '{$param['startTime']} 00:00:00' ";
  199. }
  200. if (!empty($param['endTime'])) {
  201. $item_where_arr[] = " a.check_in_date <= '{$param["endTime"]} 23:59:59' ";
  202. $hotel_where_arr[]=" b.check_in_date <= '{$param['endTime']} 23:59:59' ";
  203. }
  204. return $dao->getSubOrderListByWhere(join(" and ",$hotel_where_arr),join(" and ",$item_where_arr),join(" and ",$where_arr),$param);
  205. }
  206. /**
  207. * 删除付款单
  208. * @param $id
  209. * @return array
  210. */
  211. public function delAll($id){
  212. Db::startTrans();
  213. //1.删除付款单下的附加项目订单
  214. $itemDao = new OrderItemDao();
  215. $itemRe = $itemDao->delPaymentOrder($id);
  216. if (!$itemRe['flag']) {
  217. Db::rollback();
  218. return $itemRe;
  219. }
  220. //1.删除付款单下的酒店订单
  221. $hotelDao = new OrderHotelDao();
  222. $hotelRe = $hotelDao->delPaymentOrder($id);
  223. if (!$hotelRe['flag']) {
  224. Db::rollback();
  225. return $hotelRe;
  226. }
  227. //2.删除付款单
  228. $model = new PaymentOrderDao();
  229. $delRe = $model->del($id);
  230. if (!$delRe['flag']) {
  231. Db::rollback();
  232. return $delRe;
  233. }
  234. Db::commit();
  235. return Util::returnArrSu();
  236. }
  237. }