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

273 lines
9.2 KiB

  1. <?php
  2. namespace app\admin\service;
  3. use app\admin\command\Util;
  4. use app\admin\model\OrderHotel;
  5. use app\admin\model\OrderItem;
  6. use app\admin\model\OrderMain;
  7. use app\admin\model\Purchase;
  8. use app\admin\model\PurchasePrice;
  9. use think\Exception;
  10. use think\Url;
  11. /**
  12. * Created by PhpStorm.
  13. * User: nizongfeng
  14. * Date: 2021/10/24
  15. * Time: 15:55
  16. */
  17. class OrderMainService
  18. {
  19. /**
  20. * 保存主订单
  21. * @param $param
  22. * @return array
  23. */
  24. public function saveOrder($param)
  25. {
  26. /**
  27. * 1.添加主订单
  28. */
  29. $orderMainDao = new OrderMainDao();
  30. $addOrderMain = $orderMainDao->save($param);
  31. if (!$addOrderMain["flag"]) {
  32. return $addOrderMain;
  33. }
  34. if (!isset($param['subOrderList']) || count($param['subOrderList'])==0) {
  35. return Util::returnArrSu("成功",$addOrderMain['data']);
  36. }
  37. $orderId = $addOrderMain['data'];
  38. //所有子订单设置为删除
  39. $orderHotelDao = new OrderHotelDao();
  40. $orderHotelDao->delete($orderId);
  41. $orderItemDao = new OrderItemDao();
  42. $orderItemDao->delete($orderId);
  43. $purchasePriceDao = new PurchasePriceDao();
  44. $purchasePriceDao->delete($orderId);
  45. //循环子订单
  46. foreach ($param['subOrderList'] as $subOrderParam) {
  47. $subOrderParam['group_id'] = $param['group_id'];
  48. /**
  49. * 2.添加子订单 有则激活更新、无则添加
  50. */
  51. if ($subOrderParam['prod_type'] == 'hotel') {
  52. $subOrderDao = $orderHotelDao;
  53. } else {
  54. $subOrderDao = $orderItemDao;
  55. }
  56. $addSubOrder = $subOrderDao->modify($subOrderParam, $orderId);
  57. if (!$addSubOrder['flag']) {
  58. return $addSubOrder;
  59. }
  60. $subOrderId = $addSubOrder['data'];
  61. $subOrderInfo = $subOrderDao->getInfoById($subOrderId);
  62. if (!$subOrderInfo['flag']) {
  63. return $subOrderInfo;
  64. }
  65. /**
  66. * 2.1添加子订单下的采购单 有则更新激活、无则添加
  67. */
  68. $purchaseDao = new PurchaseDao();
  69. if ($subOrderParam['prod_type'] == 'hotel') {
  70. $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']);
  71. } else {
  72. $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']);
  73. }
  74. if (!$addPurchase['flag']) {
  75. return $addPurchase;
  76. }
  77. $purchaseId = $addPurchase['data'];
  78. /**
  79. * 2.1.1添加采购单的每日价格 先删除、后添加激活
  80. */
  81. $purchasePriceDao = new PurchasePriceDao();
  82. $addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId);
  83. if (!$addPurchasePrice['flag']) {
  84. return $addPurchasePrice;
  85. }
  86. /**
  87. * 2.1.2 计算更新 采购单总金额、成本、产品数量
  88. */
  89. $setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId);
  90. if (!$setPurchaseRe['flag']) {
  91. return $setPurchaseRe;
  92. }
  93. /**
  94. * 2.2 计算更新 子订单成本、金额、产品数量
  95. */
  96. $setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId);
  97. if (!$setSubOrderRe['flag']) {
  98. return $setSubOrderRe;
  99. }
  100. }
  101. /**
  102. * 3 计算更新 主订单成本、金额、产品数量
  103. */
  104. $setOrderMainRe = $orderMainDao->setOrderAmount($orderId);
  105. if (!$setOrderMainRe['flag']) {
  106. return $setOrderMainRe;
  107. }
  108. return Util::returnArrSu("成功",$orderId);
  109. }
  110. /**
  111. * 保存子订单
  112. * @param $subOrderParam
  113. * @return array
  114. */
  115. public function subOrderSave($subOrderParam)
  116. {
  117. $orderId = $subOrderParam['order_id'];
  118. $orderMainDao = new OrderMainDao();
  119. /**
  120. * 2.添加子订单
  121. */
  122. if ($subOrderParam['prod_type'] == 'hotel') {
  123. $subOrderDao = new OrderHotelDao();
  124. } else {
  125. $subOrderDao = new OrderItemDao();
  126. }
  127. $addSubOrder = $subOrderDao->modify($subOrderParam, $orderId);
  128. if (!$addSubOrder['flag']) {
  129. return $addSubOrder;
  130. }
  131. $subOrderId = $addSubOrder['data'];
  132. $subOrderInfo = $subOrderDao->getInfoById($subOrderId);
  133. if (!$subOrderInfo['flag']) {
  134. return $subOrderInfo;
  135. }
  136. /**
  137. * 2.1添加子订单下的采购单
  138. */
  139. $purchaseDao = new PurchaseDao();
  140. if ($subOrderParam['prod_type'] == 'hotel') {
  141. $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']);
  142. } else {
  143. $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']);
  144. }
  145. if (!$addPurchase['flag']) {
  146. return $addPurchase;
  147. }
  148. $purchaseId = $addPurchase['data'];
  149. /**
  150. * 2.1.1添加采购单的每日价格
  151. */
  152. $purchasePriceDao = new PurchasePriceDao();
  153. $addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId);
  154. if (!$addPurchasePrice['flag']) {
  155. return $addPurchasePrice;
  156. }
  157. /**
  158. * 2.1.2 计算更新 采购单总金额、成本、产品数量
  159. */
  160. $setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId);
  161. if (!$setPurchaseRe['flag']) {
  162. return $setPurchaseRe;
  163. }
  164. /**
  165. * 2.2 计算更新 子订单成本、金额、产品数量
  166. */
  167. $setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId);
  168. if (!$setSubOrderRe['flag']) {
  169. return $setSubOrderRe;
  170. }
  171. /**
  172. * 3 计算更新 主订单成本、金额、产品数量
  173. */
  174. $setOrderMainRe = $orderMainDao->setOrderAmount($orderId);
  175. if (!$setOrderMainRe['flag']) {
  176. return $setOrderMainRe;
  177. }
  178. return Util::returnArrSu("保存成功",$subOrderId);
  179. }
  180. /**
  181. * 删除子订单
  182. * @param $param
  183. * @return array
  184. */
  185. public function delSubOrder($param){
  186. try {
  187. if ($param['prod_type'] == 'hotel') {
  188. $subOrderDao = new OrderHotelDao();
  189. } else {
  190. $subOrderDao = new OrderItemDao();
  191. }
  192. $subOrderRe = $subOrderDao->getInfoById($param['id']);
  193. if (!$subOrderRe['flag']) {
  194. return $subOrderRe;
  195. }
  196. $subOrderDao->delById($param['id']);
  197. //删除采购单
  198. $purchaseDao = new PurchaseDao();
  199. $purchaseDao->deleteBySubOrderId($param['id']);
  200. //删除每日采购单价格
  201. $purchasePriceDao = new PurchasePriceDao();
  202. $purchasePriceDao->deleteBySubOrderId($param['id']);
  203. //重新计算订单总金额
  204. $orderMainDao = new OrderMainDao();
  205. $orderMainDao->setOrderAmount($subOrderRe['data']['order_id']);
  206. return Util::returnArrSu("成功");
  207. }catch (Exception $e){
  208. return Util::returnArrEr("删除子订单失败:".$e->getMessage());
  209. }
  210. }
  211. /**
  212. * 获取订单详情
  213. * @param $id
  214. * @return array
  215. */
  216. public function getOrderInfo($id){
  217. $orderMainDao = new OrderMainDao();
  218. $orderMainRe = $orderMainDao->getInfoById($id);
  219. if (!$orderMainRe['flag']) {
  220. return $orderMainRe;
  221. }
  222. $orderMain = $orderMainRe['data'];
  223. //获取采购单金额列表
  224. $purchasePriceDao = new PurchasePriceDao();
  225. $purchasePriceRe = $purchasePriceDao->getPurchasePriceListByOrderId($id);
  226. if (!$purchasePriceRe['flag']) {
  227. return $purchasePriceRe;
  228. }
  229. //获取采购单列表
  230. $purchaseDao = new PurchaseDao();
  231. $purchaseRe = $purchaseDao->getListByOrderId($id);
  232. if (!$purchaseRe['flag']) {
  233. return $purchaseRe;
  234. }
  235. //设置采购单展示数据
  236. $purchaseShow = $purchaseDao->setPurchaseShow($purchaseRe['data'],$purchasePriceRe['data']);
  237. if (!$purchaseShow['flag']) {
  238. return $purchaseShow;
  239. }
  240. //获取子订单列表
  241. $orderHotelDao = new OrderHotelDao();
  242. $orderHotelRe = $orderHotelDao->getListByOrderId($id);
  243. if (!$orderHotelRe['flag']) {
  244. return $orderHotelRe;
  245. }
  246. $orderItemDao = new OrderItemDao();
  247. $orderItemRe = $orderItemDao->getListByOrderId($id);
  248. if (!$orderItemRe['flag']) {
  249. return $orderItemRe;
  250. }
  251. //设置子订单列表
  252. $subOrderList = $orderMainDao->setSubOrderShow($purchaseShow['data'],$orderHotelRe['data'],$orderItemRe['data']);
  253. if (!$subOrderList['flag']) {
  254. return $subOrderList;
  255. }
  256. $orderMain["subOrderList"]=$subOrderList['data'];
  257. return Util::returnArrSu("成功",$orderMain);
  258. }
  259. }