save($param); if (!$addOrderMain["flag"]) { return $addOrderMain; } $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) { /** * 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); /** * 2.1添加子订单下的采购单 */ $purchaseDao = new PurchaseDao(); if ($subOrderParam['prod_type'] == 'hotel') { $addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo); } else { $addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo); } if (!$addPurchase['flag']) { return $addPurchase; } $purchaseId = $addPurchase['id']; /** * 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); } }