save($param); if (!$addOrderMain["flag"]) { return $addOrderMain; } if (!isset($param['subOrderList']) || count($param['subOrderList'])==0) { return Util::returnArrSu("成功",$addOrderMain['data']); } $orderId = $addOrderMain['data']; //所有子订单设置为删除 $orderHotelDao = new OrderHotelDao(); $orderHotelDao->delete($orderId); $orderItemDao = new OrderItemDao(); $orderItemDao->delete($orderId); $purchasePriceDao = new PurchasePriceDao(); $purchasePriceDao->delete($orderId); //循环子订单 foreach ($param['subOrderList'] as $subOrderParam) { $subOrderParam['group_id'] = $param['group_id']; /** * 2.添加子订单 有则激活更新、无则添加 */ if ($subOrderParam['prod_type'] == 'hotel') { $subOrderDao = $orderHotelDao; } else { $subOrderDao = $orderItemDao; } $addSubOrder = $subOrderDao->modify($subOrderParam, $orderId); if (!$addSubOrder['flag']) { return $addSubOrder; } $subOrderId = $addSubOrder['data']; $subOrderInfo = $subOrderDao->getInfoById($subOrderId); if (!$subOrderInfo['flag']) { return $subOrderInfo; } /** * 2.1添加子订单下的采购单 有则更新激活、无则添加 */ $purchaseDao = new PurchaseDao(); if ($subOrderParam['prod_type'] == 'hotel') { $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']); } else { $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']); } if (!$addPurchase['flag']) { return $addPurchase; } $purchaseId = $addPurchase['data']; /** * 2.1.1添加采购单的每日价格 先删除、后添加激活 */ $purchasePriceDao = new PurchasePriceDao(); $addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId); if (!$addPurchasePrice['flag']) { return $addPurchasePrice; } /** * 2.1.2 计算更新 采购单总金额、成本、产品数量 */ $setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId); if (!$setPurchaseRe['flag']) { return $setPurchaseRe; } /** * 2.2 计算更新 子订单成本、金额、产品数量 */ $setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId); if (!$setSubOrderRe['flag']) { return $setSubOrderRe; } } /** * 3 计算更新 主订单成本、金额、产品数量 */ $setOrderMainRe = $orderMainDao->setOrderAmount($orderId); if (!$setOrderMainRe['flag']) { return $setOrderMainRe; } return Util::returnArrSu("成功",$orderId); } /** * 保存子订单 * @param $subOrderParam * @return array */ public function subOrderSave($subOrderParam) { $orderId = $subOrderParam['order_id']; $orderMainDao = new OrderMainDao(); /** * 2.添加子订单 */ if ($subOrderParam['prod_type'] == 'hotel') { $subOrderDao = new OrderHotelDao(); } else { $subOrderDao = new OrderItemDao(); } $addSubOrder = $subOrderDao->modify($subOrderParam, $orderId); if (!$addSubOrder['flag']) { return $addSubOrder; } $subOrderId = $addSubOrder['data']; $subOrderInfo = $subOrderDao->getInfoById($subOrderId); if (!$subOrderInfo['flag']) { return $subOrderInfo; } /** * 2.1添加子订单下的采购单 */ $purchaseDao = new PurchaseDao(); if ($subOrderParam['prod_type'] == 'hotel') { $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']); } else { $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']); } if (!$addPurchase['flag']) { return $addPurchase; } $purchaseId = $addPurchase['data']; /** * 2.1.1添加采购单的每日价格 */ $purchasePriceDao = new PurchasePriceDao(); $addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId); if (!$addPurchasePrice['flag']) { return $addPurchasePrice; } /** * 2.1.2 计算更新 采购单总金额、成本、产品数量 */ $setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId); if (!$setPurchaseRe['flag']) { return $setPurchaseRe; } /** * 2.2 计算更新 子订单成本、金额、产品数量 */ $setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId); if (!$setSubOrderRe['flag']) { return $setSubOrderRe; } /** * 3 计算更新 主订单成本、金额、产品数量 */ $setOrderMainRe = $orderMainDao->setOrderAmount($orderId); if (!$setOrderMainRe['flag']) { return $setOrderMainRe; } return Util::returnArrSu("保存成功",$subOrderId); } /** * 删除子订单 * @param $param * @return array */ public function delSubOrder($param){ try { if ($param['prod_type'] == 'hotel') { $subOrderDao = new OrderHotelDao(); } else { $subOrderDao = new OrderItemDao(); } $subOrderRe = $subOrderDao->getInfoById($param['id']); if (!$subOrderRe['flag']) { return $subOrderRe; } $subOrderDao->delById($param['id']); //删除采购单 $purchaseDao = new PurchaseDao(); $purchaseDao->deleteBySubOrderId($param['id']); //删除每日采购单价格 $purchasePriceDao = new PurchasePriceDao(); $purchasePriceDao->deleteBySubOrderId($param['id']); //重新计算订单总金额 $orderMainDao = new OrderMainDao(); $orderMainDao->setOrderAmount($subOrderRe['data']['order_id']); return Util::returnArrSu("成功"); }catch (\Exception $e){ return Util::returnArrEr("删除子订单失败:".$e->getMessage()); } } /** * 获取订单详情 * @param $id * @return array */ public function getOrderInfo($id){ $orderMainDao = new OrderMainDao(); $orderMainRe = $orderMainDao->getInfoById($id); if (!$orderMainRe['flag']) { return $orderMainRe; } $orderMain = $orderMainRe['data']; //获取采购单金额列表 $purchasePriceDao = new PurchasePriceDao(); $purchasePriceRe = $purchasePriceDao->getPurchasePriceListByOrderId($id); if (!$purchasePriceRe['flag']) { return $purchasePriceRe; } //获取采购单列表 $purchaseDao = new PurchaseDao(); $purchaseRe = $purchaseDao->getListByOrderId($id); if (!$purchaseRe['flag']) { return $purchaseRe; } //设置采购单展示数据 $purchaseShow = $purchaseDao->setPurchaseShow($purchaseRe['data'],$purchasePriceRe['data']); if (!$purchaseShow['flag']) { return $purchaseShow; } //获取子订单列表 $orderHotelDao = new OrderHotelDao(); $orderHotelRe = $orderHotelDao->getListByOrderId($id); if (!$orderHotelRe['flag']) { return $orderHotelRe; } $orderItemDao = new OrderItemDao(); $orderItemRe = $orderItemDao->getListByOrderId($id); if (!$orderItemRe['flag']) { return $orderItemRe; } //设置子订单列表 $subOrderList = $orderMainDao->setSubOrderShow($purchaseShow['data'],$orderHotelRe['data'],$orderItemRe['data']); if (!$subOrderList['flag']) { return $subOrderList; } $orderMain["subOrderList"]=$subOrderList['data']; return Util::returnArrSu("成功",$orderMain); } /** * 获取订单列表 * @param $param * @return array */ public function getOrderList($param){ $orderMainDao = new OrderMainDao(); $where = ["id"=>["neq",""]]; if (!empty($param['order_id'])) { $where["id"]=$param['order_id']; } if (!empty($param['channel_id'])) { $where['channel_id'] = $param['channel_id']; } if ($param['order_status'] != '') { $where['order_status'] = $param['order_status']; } if (!empty($param['commissioner_id'])) { $where['commissioner_id'] = $param['commissioner_id']; } if (!empty($param['user_name'])) { $where['user_name'] = ["like","'%".$param['user_name']."%'"]; } if (!empty($param['user_phone'])) { $where['user_phone'] = $param['user_phone']; } if (!empty($param['create_id'])) { $where['create_id'] = $param['create_id']; } //金额区间查询 if (!empty($param['startMoney'])&& empty($param['endMoney'])) { $where['total_amount'] = [">=",$param['startMoney']]; } if (!empty($param['endMoney']) && empty($param['startMoney'])) { $where['total_amount'] = ["<=",$param['endMoney']]; } if (!empty($param['endMoney']) && !empty($param['startMoney'])) { $where['total_amount'] = ["between",[$param['startMoney'],$param['endMoney']]]; } //时间区间查询 if (!empty($param['startTime']) && empty($param['endTime'])) { $where['create_time'] = [">=",$param['startTime']." 00:00:00"]; } if (!empty($param['endTime'])&& empty($param['startTime'])) { $where['create_time'] = ["<=",$param['endTime']." 23:59:59"]; } if(!empty($param['endTime'])&& !empty($param['startTime'])){ $where['create_time'] = ["between",[$param['startTime']." 00:00:00",$param['endTime']." 23:59:59"]]; } if ($param['receipt_order_status'] !== '') { $where['receipt_order_status'] = $param['receipt_order_status']; } if ($param['receipt_order_id'] !== '') { $where['receipt_order_id'] = $param['receipt_order_id']; } if ($param['channel_order_no'] != '') { $where['channel_order_no'] = $param['channel_order_no']; } $result = $orderMainDao->getOrderListByWhere($where,$param); if (!$result['flag'] || $result['data']['total']==0) { return $result; } //获取主订单ID $ids = []; foreach ($result['data']['list'] as $info){ $ids[] = $info['id']; } //获取子订单列表 $orderHotelDao = new OrderHotelDao(); $orderItemDao = new OrderItemDao(); $orderHotelList = $orderHotelDao->getOrderListByOrderIds($ids); $orderItemList = $orderItemDao->getOrderListByOrderIds($ids); //设置主订单列表 $orderMainList = []; foreach ($result['data']['list'] as $order) { $order['subOrder']=[]; foreach ($orderHotelList as $hotel){ if ($hotel['order_id'] == $order['id']) { $hotel["type"]="酒店"; $order['subOrder'][] = $hotel; } } foreach ($orderItemList as $item){ if ($item['order_id'] == $order['id']) { $item["type"]="附加项目"; $order['subOrder'][] = $item; } } $orderMainList[] = $order; } $result['data']['list'] = $orderMainList; return $result; } }