酒店预订平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

436 Zeilen
16 KiB

  1. <?php
  2. namespace app\admin\service;
  3. use app\admin\command\Util;
  4. use app\admin\dao\AdminDao;
  5. use app\admin\dao\CfSuplierInfoDao;
  6. use app\admin\dao\OrderHotelDao;
  7. use app\admin\dao\OrderItemDao;
  8. use app\admin\dao\OrderMainDao;
  9. use app\admin\dao\PurchaseDao;
  10. use app\admin\dao\PurchasePriceDao;
  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. //1.获取负责人昵称
  49. $adminDao = new AdminDao();
  50. $adminRe = $adminDao->getInfoById($subOrderParam['purchase_user_id']);
  51. if (!$adminRe['flag']) {
  52. return $adminRe;
  53. }
  54. $subOrderParam['purchase_user'] = $adminRe['data']['nickname'];
  55. //2.获取供应商名称
  56. $suplierDao = new CfSuplierInfoDao();
  57. $suplierRe = $suplierDao->getInfoById($subOrderParam['supplier_id']);
  58. if (!$suplierRe['flag']) {
  59. return $suplierRe;
  60. }
  61. $subOrderParam['supplier_name'] = $suplierRe['data']['supplier_name'];
  62. /**
  63. * 2.添加子订单 有则激活更新、无则添加
  64. */
  65. if ($subOrderParam['prod_type'] == 'hotel') {
  66. $subOrderDao = $orderHotelDao;
  67. } else {
  68. $subOrderDao = $orderItemDao;
  69. }
  70. $addSubOrder = $subOrderDao->modify($subOrderParam, $orderId);
  71. if (!$addSubOrder['flag']) {
  72. return $addSubOrder;
  73. }
  74. $subOrderId = $addSubOrder['data'];
  75. $subOrderInfo = $subOrderDao->getInfoById($subOrderId);
  76. if (!$subOrderInfo['flag']) {
  77. return $subOrderInfo;
  78. }
  79. /**
  80. * 2.1添加子订单下的采购单 有则更新激活、无则添加
  81. */
  82. $purchaseDao = new PurchaseDao();
  83. if ($subOrderParam['prod_type'] == 'hotel') {
  84. $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']);
  85. } else {
  86. $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']);
  87. }
  88. if (!$addPurchase['flag']) {
  89. return $addPurchase;
  90. }
  91. $purchaseId = $addPurchase['data'];
  92. /**
  93. * 2.1.1添加采购单的每日价格 先删除、后添加激活
  94. */
  95. $purchasePriceDao = new PurchasePriceDao();
  96. $addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId);
  97. if (!$addPurchasePrice['flag']) {
  98. return $addPurchasePrice;
  99. }
  100. /**
  101. * 2.1.2 计算更新 采购单总金额、成本、产品数量
  102. */
  103. $setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId);
  104. if (!$setPurchaseRe['flag']) {
  105. return $setPurchaseRe;
  106. }
  107. /**
  108. * 2.2 计算更新 子订单成本、金额、产品数量
  109. */
  110. $setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId);
  111. if (!$setSubOrderRe['flag']) {
  112. return $setSubOrderRe;
  113. }
  114. }
  115. /**
  116. * 3 计算更新 主订单成本、金额、产品数量
  117. */
  118. $setOrderMainRe = $orderMainDao->setOrderAmount($orderId);
  119. if (!$setOrderMainRe['flag']) {
  120. return $setOrderMainRe;
  121. }
  122. return Util::returnArrSu("成功",$orderId);
  123. }
  124. /**
  125. * 保存子订单
  126. * @param $subOrderParam
  127. * @return array
  128. */
  129. public function subOrderSave($subOrderParam)
  130. {
  131. $orderId = $subOrderParam['order_id'];
  132. $orderMainDao = new OrderMainDao();
  133. //1.获取负责人昵称
  134. $adminDao = new AdminDao();
  135. $adminRe = $adminDao->getInfoById($subOrderParam['purchase_user_id']);
  136. if (!$adminRe['flag']) {
  137. return $adminRe;
  138. }
  139. $subOrderParam['purchase_user'] = $adminRe['data']['nickname'];
  140. //2.获取供应商名称
  141. $suplierDao = new CfSuplierInfoDao();
  142. $suplierRe = $suplierDao->getInfoById($subOrderParam['supplier_id']);
  143. if (!$suplierRe['flag']) {
  144. return $suplierRe;
  145. }
  146. $subOrderParam['supplier_name'] = $suplierRe['data']['supplier_name'];
  147. /**
  148. * 2.添加子订单
  149. */
  150. if ($subOrderParam['prod_type'] == 'hotel') {
  151. $subOrderDao = new OrderHotelDao();
  152. } else {
  153. $subOrderDao = new OrderItemDao();
  154. }
  155. $addSubOrder = $subOrderDao->modify($subOrderParam, $orderId);
  156. if (!$addSubOrder['flag']) {
  157. return $addSubOrder;
  158. }
  159. $subOrderId = $addSubOrder['data'];
  160. $subOrderInfo = $subOrderDao->getInfoById($subOrderId);
  161. if (!$subOrderInfo['flag']) {
  162. return $subOrderInfo;
  163. }
  164. /**
  165. * 2.1添加子订单下的采购单
  166. */
  167. $purchaseDao = new PurchaseDao();
  168. if ($subOrderParam['prod_type'] == 'hotel') {
  169. $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']);
  170. } else {
  171. $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']);
  172. }
  173. if (!$addPurchase['flag']) {
  174. return $addPurchase;
  175. }
  176. $purchaseId = $addPurchase['data'];
  177. /**
  178. * 2.1.1添加采购单的每日价格
  179. */
  180. $purchasePriceDao = new PurchasePriceDao();
  181. $addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId);
  182. if (!$addPurchasePrice['flag']) {
  183. return $addPurchasePrice;
  184. }
  185. /**
  186. * 2.1.2 计算更新 采购单总金额、成本、产品数量
  187. */
  188. $setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId);
  189. if (!$setPurchaseRe['flag']) {
  190. return $setPurchaseRe;
  191. }
  192. /**
  193. * 2.2 计算更新 子订单成本、金额、产品数量
  194. */
  195. $setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId);
  196. if (!$setSubOrderRe['flag']) {
  197. return $setSubOrderRe;
  198. }
  199. /**
  200. * 3 计算更新 主订单成本、金额、产品数量
  201. */
  202. $setOrderMainRe = $orderMainDao->setOrderAmount($orderId);
  203. if (!$setOrderMainRe['flag']) {
  204. return $setOrderMainRe;
  205. }
  206. return Util::returnArrSu("保存成功",$subOrderId);
  207. }
  208. /**
  209. * 删除子订单
  210. * @param $param
  211. * @return array
  212. */
  213. public function delSubOrder($param){
  214. try {
  215. if ($param['prod_type'] == 'hotel') {
  216. $subOrderDao = new OrderHotelDao();
  217. } else {
  218. $subOrderDao = new OrderItemDao();
  219. }
  220. $subOrderRe = $subOrderDao->getInfoById($param['id']);
  221. if (!$subOrderRe['flag']) {
  222. return $subOrderRe;
  223. }
  224. $subOrderDao->delById($param['id']);
  225. //删除采购单
  226. $purchaseDao = new PurchaseDao();
  227. $purchaseDao->deleteBySubOrderId($param['id']);
  228. //删除每日采购单价格
  229. $purchasePriceDao = new PurchasePriceDao();
  230. $purchasePriceDao->deleteBySubOrderId($param['id']);
  231. //重新计算订单总金额
  232. $orderMainDao = new OrderMainDao();
  233. $orderMainDao->setOrderAmount($subOrderRe['data']['order_id']);
  234. return Util::returnArrSu("成功");
  235. }catch (\Exception $e){
  236. return Util::returnArrEr("删除子订单失败:".$e->getMessage());
  237. }
  238. }
  239. /**
  240. * 获取订单详情
  241. * @param $id
  242. * @return array
  243. */
  244. public function getOrderInfo($id){
  245. $orderMainDao = new OrderMainDao();
  246. $orderMainRe = $orderMainDao->getInfoById($id);
  247. if (!$orderMainRe['flag']) {
  248. return $orderMainRe;
  249. }
  250. $orderMain = $orderMainRe['data'];
  251. //获取采购单金额列表
  252. $purchasePriceDao = new PurchasePriceDao();
  253. $purchasePriceRe = $purchasePriceDao->getPurchasePriceListByOrderId($id);
  254. if (!$purchasePriceRe['flag']) {
  255. return $purchasePriceRe;
  256. }
  257. //获取采购单列表
  258. $purchaseDao = new PurchaseDao();
  259. $purchaseRe = $purchaseDao->getListByOrderId($id);
  260. if (!$purchaseRe['flag']) {
  261. return $purchaseRe;
  262. }
  263. //设置采购单展示数据
  264. $purchaseShow = $purchaseDao->setPurchaseShow($purchaseRe['data'],$purchasePriceRe['data']);
  265. if (!$purchaseShow['flag']) {
  266. return $purchaseShow;
  267. }
  268. //获取子订单列表
  269. $orderHotelDao = new OrderHotelDao();
  270. $orderHotelRe = $orderHotelDao->getListByOrderId($id);
  271. if (!$orderHotelRe['flag']) {
  272. return $orderHotelRe;
  273. }
  274. $orderItemDao = new OrderItemDao();
  275. $orderItemRe = $orderItemDao->getListByOrderId($id);
  276. if (!$orderItemRe['flag']) {
  277. return $orderItemRe;
  278. }
  279. //设置子订单列表
  280. $subOrderList = $orderMainDao->setSubOrderShow($purchaseShow['data'],$orderHotelRe['data'],$orderItemRe['data']);
  281. if (!$subOrderList['flag']) {
  282. return $subOrderList;
  283. }
  284. $orderMain["subOrderList"]=$subOrderList['data'];
  285. return Util::returnArrSu("成功",$orderMain);
  286. }
  287. /**
  288. * 获取订单列表
  289. * @param $param
  290. * @return array
  291. */
  292. public function getOrderList($param){
  293. $orderMainDao = new OrderMainDao();
  294. $where = [" a.del_flag = 0 "];
  295. if (!empty($param['order_id'])) {
  296. $where[] =" a.id = {$param['order_id']} ";
  297. }
  298. if (!empty($param['channel_id'])) {
  299. $where[] = " a.channel_id = {$param['channel_id']} ";
  300. }
  301. if ($param['order_status'] != '') {
  302. $where[] = " a.order_status = {$param['order_status']} ";
  303. }
  304. if (!empty($param['commissioner_id'])) {
  305. $where[] = " a.commissioner_id = {$param['commissioner_id']} ";
  306. }
  307. if (!empty($param['user_name'])) {
  308. $where[] = " a.user_name like '%{$param['user_name']}%' ";
  309. }
  310. if (!empty($param['user_phone'])) {
  311. $where[] = " a.user_phone = '{$param['user_phone']}' ";
  312. }
  313. if (!empty($param['create_id'])) {
  314. $where[] = " a.create_id = {$param['create_id']} ";
  315. }
  316. //金额区间查询
  317. if (!empty($param['startMoney'])) {
  318. $where[] = " a.total_amount >= {$param['startMoney']} ";
  319. }
  320. if (!empty($param['endMoney']) ) {
  321. $where[] = " a.total_amount <= {$param['endMoney']} ";
  322. }
  323. //成本区间查询
  324. if (!empty($param['startCost'])) {
  325. $where[] = " a.cost_amount >= {$param['startCost']} ";
  326. }
  327. if (!empty($param['endCost']) ) {
  328. $where[] = " a.cost_amount <= {$param['endCost']} ";
  329. }
  330. //利润区间查询
  331. if (!empty($param['startProfit'])) {
  332. $where[] = " a.profit_amount >= {$param['startProfit']} ";
  333. }
  334. if (!empty($param['endProfit']) ) {
  335. $where[] = " a.profit_amount <= {$param['endProfit']} ";
  336. }
  337. //时间区间查询
  338. if (!empty($param['startTime'])) {
  339. $where[] = " a.create_time >= '{$param['startTime']} 00:00:00' ";
  340. }
  341. if (!empty($param['endTime']) ) {
  342. $where[] = " a.create_time <= '{$param['endTime']} 23:59:59' ";
  343. }
  344. if ($param['receipt_order_status'] !== '') {
  345. $where[] = " a.receipt_order_status = {$param['receipt_order_status']} ";
  346. }
  347. if ($param['receipt_order_id'] !== '') {
  348. $where[] = " a.receipt_order_id = {$param['receipt_order_id']} ";
  349. }
  350. if ($param['channel_order_no'] != '') {
  351. $where[] = " a.channel_order_no = '{$param['channel_order_no']}' ";
  352. }
  353. //子订单查询条件 入住时间
  354. if (!empty($param['startInDate']) && empty($param['endInDate'])) {
  355. $where[] = " (b.check_in_date >= '{$param['startInDate']} 00:00:00' or c.check_in_date >= '{$param['startInDate']} 00:00:00' )";
  356. }
  357. if (!empty($param['endInDate']) && empty($param['startInDate']) ) {
  358. $where[] = " (b.check_in_date <= '{$param['endInDate']} 23:59:59' or c.check_in_date <= '{$param['endInDate']} 23:59:59' ) ";
  359. }
  360. if (!empty($param['startInDate']) && !empty($param['endInDate']) ) {
  361. $where[] = " (
  362. (b.check_in_date >= '{$param['startInDate']} 00:00:00' and b.check_in_date <= '{$param['endInDate']} 23:59:59')
  363. or
  364. (c.check_in_date >= '{$param['startInDate']} 00:00:00' and c.check_in_date <= '{$param['endInDate']} 23:59:59')
  365. ) ";
  366. }
  367. //供应商
  368. if (!empty($param['supplier_id'])) {
  369. $where[] = "(b.supplier_id = {$param['supplier_id']} or c.supplier_id = {$param['supplier_id']})";
  370. }
  371. if (!empty($param['customer_name'])) {
  372. $where[] = "(b.customer_name like '%{$param['customer_name']}%' or c.customer_name like '%{$param['customer_name']}%')";
  373. }
  374. //子订单查询条件 离店时间
  375. if (!empty($param['startOutDate'])) {
  376. $where[] = " b.check_out_date >= '{$param['startOutDate']} 00:00:00' ";
  377. }
  378. if (!empty($param['endOutDate']) ) {
  379. $where[] = " b.check_out_date <= '{$param['endOutDate']} 23:59:59' ";
  380. }
  381. $result = $orderMainDao->getOrderListByWhereStr(join(" and ",$where),$param);
  382. if (!$result['flag'] || $result['data']['total']==0) {
  383. return $result;
  384. }
  385. //获取主订单ID
  386. $ids = [];
  387. foreach ($result['data']['list'] as $info){
  388. $ids[] = $info['id'];
  389. }
  390. //获取子订单列表
  391. $orderHotelDao = new OrderHotelDao();
  392. $orderItemDao = new OrderItemDao();
  393. $orderHotelList = $orderHotelDao->getOrderListByOrderIds($ids);
  394. $orderItemList = $orderItemDao->getOrderListByOrderIds($ids);
  395. //设置主订单列表
  396. $orderMainList = [];
  397. foreach ($result['data']['list'] as $order) {
  398. $order['subOrder']=[];
  399. foreach ($orderHotelList as $hotel){
  400. if ($hotel['order_id'] == $order['id']) {
  401. $hotel["type"]="酒店";
  402. $order['subOrder'][] = $hotel;
  403. }
  404. }
  405. foreach ($orderItemList as $item){
  406. if ($item['order_id'] == $order['id']) {
  407. $item["type"]="附加项目";
  408. $order['subOrder'][] = $item;
  409. }
  410. }
  411. $orderMainList[] = $order;
  412. }
  413. $result['data']['list'] = $orderMainList;
  414. return $result;
  415. }
  416. }