@@ -239,6 +239,19 @@ class OrderMain extends Backend | |||
return json($result); | |||
} | |||
public function sunOrderSave(){ | |||
$params=$this->request->post(); | |||
$orderMainService = new OrderMainService(); | |||
Db::startTrans(); | |||
$result = $orderMainService->subOrderSave($params); | |||
if (!$result['flag']) { | |||
Db::rollback(); | |||
} else { | |||
Db::commit(); | |||
} | |||
return json($result); | |||
} | |||
public function newAdd(){ | |||
$params=$this->request->post(); | |||
$hotelMain = $params["orderMain"]; | |||
@@ -65,14 +65,15 @@ class OrderHotelDao | |||
"customer_comments" => $param['customer_comments'], | |||
"trade_order_number" => $param['trade_order_number'], | |||
"res_person" => $param['res_person'], | |||
"res_person_id" => $param['res_person_id'] | |||
"res_person_id" => $param['res_person_id'], | |||
"del_flag"=>0 | |||
]; | |||
$orderHotelModel = new OrderHotel(); | |||
if (empty($param['id'])) { | |||
$orderHotelModel = new OrderHotel(); | |||
$id = $orderHotelModel->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
}else { | |||
$orderHotelModel = new OrderHotel(); | |||
$orderHotelModel->save($data, ["id" => $param['id']]); | |||
return Util::returnArrSu($param['id']); | |||
} | |||
@@ -180,4 +181,13 @@ class OrderHotelDao | |||
return Util::returnArrEr("获取子订单信息失败" . $id); | |||
} | |||
} | |||
/** | |||
* 删除记录 | |||
* @param $order_id | |||
*/ | |||
public function delete($order_id){ | |||
$model = new OrderHotel(); | |||
$model->save(["del_flag"=>1],["order_id"=>$order_id]); | |||
} | |||
} |
@@ -54,14 +54,14 @@ class OrderItemDao | |||
"customer_comments" => $param['customer_comments'], | |||
"trade_order_number" => $param['trade_order_number'], | |||
"res_person" => $param['res_person'], | |||
"res_person_id" => $param['res_person_id'] | |||
"res_person_id" => $param['res_person_id'], | |||
"del_flag"=>0 | |||
]; | |||
$orderHotelModel = new OrderHotel(); | |||
if (empty($param['id'])) { | |||
$orderHotelModel = new OrderHotel(); | |||
$id = $orderHotelModel->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
}else { | |||
$orderHotelModel = new OrderHotel(); | |||
$orderHotelModel->save($data,["id"=>$param['id']]); | |||
return Util::returnArrSu($param['id']); | |||
} | |||
@@ -135,4 +135,13 @@ class OrderItemDao | |||
} | |||
} | |||
/** | |||
* 删除记录 | |||
* @param $order_id | |||
*/ | |||
public function delete($order_id){ | |||
$model = new OrderItem(); | |||
$model->save(["del_flag"=>1],["order_id"=>$order_id]); | |||
} | |||
} |
@@ -1,4 +1,5 @@ | |||
<?php | |||
namespace app\admin\service; | |||
use app\admin\command\Util; | |||
@@ -16,44 +17,58 @@ use think\Url; | |||
* Date: 2021/10/24 | |||
* Time: 15:55 | |||
*/ | |||
class OrderMainService | |||
{ | |||
public function saveOrder($param) { | |||
/** | |||
* 保存主订单 | |||
* @param $param | |||
* @return array | |||
*/ | |||
public function saveOrder($param) | |||
{ | |||
/** | |||
* 1.添加主订单 | |||
*/ | |||
$orderMainDao = new OrderMainDao(); | |||
$addOrderMain = $orderMainDao->save($param); | |||
$addOrderMain = $orderMainDao->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.添加子订单 | |||
* 2.添加子订单 有则激活更新、无则添加 | |||
*/ | |||
if ($subOrderParam['prodType'] == 'hotel') { | |||
$subOrderDao = new OrderHotelDao(); | |||
}else { | |||
$subOrderDao = new OrderItemDao(); | |||
$subOrderDao = $orderHotelDao; | |||
} else { | |||
$subOrderDao = $orderItemDao; | |||
} | |||
$addSubOrder = $subOrderDao->modify($subOrderParam,$orderId); | |||
$addSubOrder = $subOrderDao->modify($subOrderParam, $orderId); | |||
if (!$addSubOrder['flag']) { | |||
return $addSubOrder; | |||
} | |||
$subOrderId =$addSubOrder['data']; | |||
$subOrderId = $addSubOrder['data']; | |||
$subOrderInfo = $subOrderDao->getInfoById($subOrderId); | |||
/** | |||
* 2.1添加子订单下的采购单 | |||
* 2.1添加子订单下的采购单 有则更新激活、无则添加 | |||
*/ | |||
$purchaseDao = new PurchaseDao(); | |||
if ($subOrderParam['prod_type'] == 'hotel') { | |||
$addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam,$subOrderInfo); | |||
$addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo); | |||
} else { | |||
$addPurchase = $purchaseDao->saveItemPurchase($subOrderParam,$subOrderInfo); | |||
$addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo); | |||
} | |||
if (!$addPurchase['flag']) { | |||
return $addPurchase; | |||
@@ -61,10 +76,10 @@ class OrderMainService | |||
$purchaseId = $addPurchase['id']; | |||
/** | |||
* 2.1.1添加采购单的每日价格 | |||
* 2.1.1添加采购单的每日价格 先删除、后添加激活 | |||
*/ | |||
$purchasePriceDao = new PurchasePriceDao(); | |||
$addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'],$orderId,$subOrderParam['prod_type'],$subOrderId,$purchaseId); | |||
$addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId); | |||
if (!$addPurchasePrice['flag']) { | |||
return $addPurchasePrice; | |||
} | |||
@@ -94,4 +109,77 @@ class OrderMainService | |||
} | |||
return Util::returnArrSu($orderId); | |||
} | |||
/** | |||
* 保存子订单 | |||
* @param $subOrderParam | |||
* @return array | |||
*/ | |||
public function subOrderSave($subOrderParam) | |||
{ | |||
$orderId = $subOrderParam['order_id']; | |||
$orderMainDao = new OrderMainDao(); | |||
/** | |||
* 2.添加子订单 | |||
*/ | |||
if ($subOrderParam['prodType'] == '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); | |||
} | |||
} |
@@ -37,7 +37,8 @@ class PurchaseDao | |||
"supplier_id" => $param['supplier_id'], | |||
"supplier_name" => $param['supplier_name'], | |||
"purchase_user_id" => $param['purchase_user_id'], | |||
"purchase_user" => $param['purchase_user'] | |||
"purchase_user" => $param['purchase_user'], | |||
"del_flag"=>0 | |||
]; | |||
$model = new Purchase(); | |||
if (empty($param['purchase_id'])) { | |||
@@ -73,7 +74,8 @@ class PurchaseDao | |||
"supplier_id" => $param['supplier_id'], | |||
"supplier_name" => $param['supplier_name'], | |||
"purchase_user_id" => $param['purchase_user_id'], | |||
"purchase_user" => $param['purchase_user'] | |||
"purchase_user" => $param['purchase_user'], | |||
"del_flag"=>0 | |||
]; | |||
$model = new Purchase(); | |||
if (empty($param['purchase_id'])) { | |||
@@ -112,4 +114,13 @@ class PurchaseDao | |||
} | |||
} | |||
/** | |||
* 删除记录 | |||
* @param $order_id | |||
*/ | |||
public function delete($order_id){ | |||
$model = new Purchase(); | |||
$model->save(["del_flag"=>1],["order_id"=>$order_id]); | |||
} | |||
} |
@@ -25,8 +25,12 @@ class PurchasePriceDao | |||
* @param int $purchase_id | |||
* @return array | |||
*/ | |||
public function saveList($param,int $order_id,string $prod_type,int $order_detail_id,int $purchase_id){ | |||
public function saveList($param, int $order_id, string $prod_type, int $order_detail_id, int $purchase_id) | |||
{ | |||
try { | |||
//删除记录 | |||
$this->delete($order_detail_id); | |||
//循环添加 | |||
foreach ($param as $value) { | |||
$data = [ | |||
"order_id" => $order_id, | |||
@@ -36,18 +40,29 @@ class PurchasePriceDao | |||
"run_date" => $value['run_date'], | |||
"count" => $value['count'], | |||
"price" => $value['price'], | |||
"cost" => $value['cost'] | |||
"cost" => $value['cost'], | |||
"del_flag" => 0 | |||
]; | |||
$model = new PurchasePrice(); | |||
if (empty($value['id'])) { | |||
$model->insertGetId($data); | |||
} else { | |||
$model->save($data,["id"=>$value['id']]); | |||
$model->save($data, ["id" => $value['id']]); | |||
} | |||
} | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("添加/更新采购单每日价格失败".$e->getMessage()); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("添加/更新采购单每日价格失败" . $e->getMessage()); | |||
} | |||
} | |||
/** | |||
* 删除数据 | |||
* @param $purchase_id | |||
*/ | |||
public function delete($purchase_id) | |||
{ | |||
$model = new PurchasePrice(); | |||
$model->save(["del_flag" => 1], ["purchase_id" => $purchase_id]); | |||
} | |||
} |