Browse Source

封装

dev
nizongfeng 3 years ago
parent
commit
42b99161e8
5 changed files with 103 additions and 21 deletions
  1. +19
    -1
      application/admin/service/OrderHotelDao.php
  2. +20
    -2
      application/admin/service/OrderItemDao.php
  3. +1
    -1
      application/admin/service/OrderMainDao.php
  4. +61
    -15
      application/admin/service/OrderMainService.php
  5. +2
    -2
      application/admin/service/PurchaseDao.php

+ 19
- 1
application/admin/service/OrderHotelDao.php View File

@@ -133,7 +133,7 @@ class OrderHotelDao
* @param int $subOrderId
* @return array
*/
public static function setSubOrderAmount( int $subOrderId) {
public function setSubOrderAmount( int $subOrderId) {
try{
$purchaseModel = new Purchase();
$purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select();
@@ -152,4 +152,22 @@ class OrderHotelDao
}

}

/**
* 获取详情
* @param $id
* @return array
*/
public function getInfoById($id) {
try {
$model = new OrderHotel();
$result = $model->where(["id" => $id])->find();
if ($result == null) {
return Util::returnArrEr("获取子订单信息失败" . $id);
}
return Util::returnArrSu($result);
} catch (Exception $e) {
return Util::returnArrEr("获取子订单信息失败" . $id);
}
}
}

+ 20
- 2
application/admin/service/OrderItemDao.php View File

@@ -16,7 +16,7 @@ use app\admin\model\OrderItem;
use app\admin\model\Purchase;
use think\Exception;

class OrderHotelDao
class OrderItemDao
{
/**
* 添加失败
@@ -82,7 +82,7 @@ class OrderHotelDao
* @param int $subOrderId
* @return array
*/
public static function setSubOrderAmount( int $subOrderId) {
public function setSubOrderAmount( int $subOrderId) {
try{
$purchaseModel = new Purchase();
$purchaseList = $purchaseModel->where(["order_detail_id"=>$subOrderId,"del_flag"=>0])->select();
@@ -104,4 +104,22 @@ class OrderHotelDao

}

/**
* 获取详情
* @param $id
* @return array
*/
public function getInfoById($id) {
try {
$model = new OrderItem();
$result = $model->where(["id" => $id])->find();
if ($result == null) {
return Util::returnArrEr("获取子订单信息失败" . $id);
}
return Util::returnArrSu($result);
} catch (Exception $e) {
return Util::returnArrEr("获取子订单信息失败" . $id);
}
}

}

+ 1
- 1
application/admin/service/OrderMainDao.php View File

@@ -77,7 +77,7 @@ class OrderMainDao
* @param int $orderId
* @return array
*/
public static function setOrderAmount(int $orderId){
public function setOrderAmount(int $orderId){
try {
$itemModel = new OrderItem();
$hotelModel = new OrderHotel();


+ 61
- 15
application/admin/service/OrderMainService.php View File

@@ -8,6 +8,7 @@ use app\admin\model\OrderMain;
use app\admin\model\Purchase;
use app\admin\model\PurchasePrice;
use think\Exception;
use think\Url;

/**
* Created by PhpStorm.
@@ -21,32 +22,77 @@ class OrderMainService

public function createOrder($param) {
/**
* todo 1.添加主订单
* 1.添加主订单
*/

/**
* todo 2.添加子订单
*/

$orderMainDao = new OrderMainDao();
$addOrderMain = $orderMainDao->addMain($param);
if (!$addOrderMain["flag"]) {
return $addOrderMain;
}
$orderId = $addOrderMain['data'];
foreach ($param['subOrderList'] as $subOrderParam) {
/**
* todo 2.1添加子订单下的采购单
* 2.添加子订单
*/
if ($subOrderParam['prodType'] == 'hotel') {
$subOrderDao = new OrderHotelDao();
}else {
$subOrderDao = new OrderItemDao();
}
$addSubOrder = $subOrderDao->addInfo($subOrderParam,$orderId);
if (!$addSubOrder['flag']) {
return $addSubOrder;
}
$subOrderId =$addSubOrder['data'];
$subOrderInfo = $subOrderDao->getInfoById($subOrderId);

/**
* todo 2.1.1添加采购单的每日价格
*/
/**
* 2.1添加子订单下的采购单
*/
$purchaseDao = new PurchaseDao();
if ($subOrderParam['prod_type'] == 'hotel') {
$addPurchase = $purchaseDao->addHotelPurchase($subOrderParam,$subOrderInfo);
} else {
$addPurchase = $purchaseDao->addItemPurchase($subOrderParam,$subOrderInfo);
}
if (!$addPurchase['flag']) {
return $addPurchase;
}
$purchaseId = $addPurchase['id'];

/**
* todo 2.1.2 计算更新 采购单总金额、成本、产品数量
*/
/**
* 2.1.1添加采购单的每日价格
*/
$purchasePriceDao = new PurchasePriceDao();
$addPurchasePrice = $purchasePriceDao->addList($subOrderParam['purchasePriceList'],$orderId,$subOrderParam['prod_type'],$subOrderId,$purchaseId);
if (!$addPurchasePrice['flag']) {
return $addPurchasePrice;
}

/**
* todo 2.2 计算更新 子订单成本、金额、产品数量
* 2.1.2 计算更新 采购单总金额、成本、产品数量
*/
$setPurchaseRe = $purchaseDao->setPurchaseAmount($purchaseId);
if (!$setPurchaseRe['flag']) {
return $setPurchaseRe;
}

/**
* 2.2 计算更新 子订单成本、金额、产品数量
*/
$setSubOrderRe = $subOrderDao->setSubOrderAmount($subOrderId);
if (!$setSubOrderRe['flag']) {
return $setSubOrderRe;
}
}
/**
* todo 3 计算更新 主订单成本、金额、产品数量
* 3 计算更新 主订单成本、金额、产品数量
*/
$setOrderMainRe = $orderMainDao->setOrderAmount($orderId);
if (!$setOrderMainRe['flag']) {
return $setOrderMainRe;
}
return Util::returnArrSu($orderId);
}

}

+ 2
- 2
application/admin/service/PurchaseDao.php View File

@@ -52,7 +52,7 @@ class PurchaseDao
* @param $itemOrder
* @return array
*/
public function addItemInfo($param, $itemOrder):array {
public function addItemPurchase($param, $itemOrder):array {
try {
$data = [
"order_id" => $itemOrder['order_id'],
@@ -82,7 +82,7 @@ class PurchaseDao
* @param $purchaseId
* @return array
*/
public function setPurchase(int $purchaseId){
public function setPurchaseAmount(int $purchaseId){
try{
$purchasePrice = new PurchasePrice();
$purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray();


Loading…
Cancel
Save