Browse Source

Merge remote-tracking branch 'origin/master' into master

dev
xubinxcode 3 years ago
parent
commit
15fbc73d12
7 changed files with 592 additions and 121 deletions
  1. +56
    -0
      application/admin/controller/OrderMain.php
  2. +81
    -34
      application/admin/service/OrderHotelDao.php
  3. +78
    -28
      application/admin/service/OrderItemDao.php
  4. +57
    -32
      application/admin/service/OrderMainDao.php
  5. +175
    -14
      application/admin/service/OrderMainService.php
  6. +94
    -8
      application/admin/service/PurchaseDao.php
  7. +51
    -5
      application/admin/service/PurchasePriceDao.php

+ 56
- 0
application/admin/controller/OrderMain.php View File

@@ -3,6 +3,7 @@
namespace app\admin\controller;

use app\admin\model\Area;
use app\admin\service\OrderMainService;
use app\common\controller\Backend;
use think\Db;
use think\exception\PDOException;
@@ -221,6 +222,61 @@ class OrderMain extends Backend
return json($result);
}

/**
* 订单页面保存接口
* @return \think\response\Json
*/
public function save(){
$params=$this->request->post();
$orderMainService = new OrderMainService();
Db::startTrans();
$result = $orderMainService->saveOrder($params);
if (!$result['flag']) {
Db::rollback();
} else {
Db::commit();
}
return json($result);
}

/**
* 子订单保存接口
* @return \think\response\Json
*/
public function subOrderSave(){
$params=$this->request->post();
$orderMainService = new OrderMainService();
Db::startTrans();
$result = $orderMainService->subOrderSave($params);
if (!$result['flag']) {
Db::rollback();
} else {
Db::commit();
}
return json($result);
}

/**
* 删除子订单
* @return \think\response\Json
*/
public function delSubOrder(){
$params=$this->request->post();
$orderMainService = new OrderMainService();
$result = $orderMainService->delSubOrder($params);
return json($result);
}

/**
* 获取订单详情
* @return \think\response\Json
*/
public function getShowInfo(){
$params=$this->request->post();
$orderMainService = new OrderMainService();
$result = $orderMainService->getOrderInfo($params['id']);
return json($result);
}

public function newAdd(){
$params=$this->request->post();


+ 81
- 34
application/admin/service/OrderHotelDao.php View File

@@ -18,12 +18,12 @@ use think\Exception;
class OrderHotelDao
{
/**
* 添加失败
* 更新记录
* @param $param
* @param $orderId
* @return array|string
*/
public function addInfo($param, $orderId)
public function modify($param, $orderId)
{
$hotelInfo = $this->getHotelInfo($param['hotel_id']);
if (!$hotelInfo['flag']){
@@ -37,38 +37,49 @@ class OrderHotelDao
if (!$roomPlan['flag']) {
return $roomPlan;
}
//设置入参
$data = [
"order_id" => $orderId,
"hotel_id" => $param['hotel_id'],
"hotel_name" => $hotelInfo['data']['hotel_name'],
"hotel_phone" => $hotelInfo['data']['hotel_phone'],
"country_name" => $hotelInfo['data']['country_name'],
"province_name" => $hotelInfo['data']['province_name'],
"city_name" => $hotelInfo['data']['city_name'],
"detail_address" => $hotelInfo['data']['detail_address'],
//房型
"room_id" => $param['data']['room_id'],
"room_name" => $roomInfo['data']['room_name'],
"room_memo" => $roomInfo['data']['room_memo'],
//价格方案
"plan_id" => $param['data']['plan_id'],
"plan_name" => $roomPlan['data']['plan_name'],
"plan_memo" => $roomPlan['data']['plan_memo'],
//其他
"check_in_date" => $param['check_in_date'],
"check_out_date" => $param['check_out_date'],
"confirm_status" => $param['confirm_status'],
"confirm_no" => $param['confirm_no'],
"customer_name" => $param['customer_name'],
"customer_comments" => $param['customer_comments'],
"trade_order_number" => $param['trade_order_number'],
"res_person" => $param['res_person'],
"res_person_id" => $param['res_person_id']
];
$orderHotelModel = new OrderHotel();
$id = $orderHotelModel->insertGetId($data);
return Util::returnArrSu($id);
try {
//设置入参
$data = [
"order_id" => $orderId,
"hotel_id" => $param['hotel_id'],
"hotel_name" => $hotelInfo['data']['hotel_name'],
"hotel_phone" => $hotelInfo['data']['hotel_phone'],
"country_name" => $hotelInfo['data']['country_name'],
"province_name" => $hotelInfo['data']['province_name'],
"city_name" => $hotelInfo['data']['city_name'],
"detail_address" => $hotelInfo['data']['detail_address'],
//房型
"room_id" => $param['data']['room_id'],
"room_name" => $roomInfo['data']['room_name'],
"room_memo" => $roomInfo['data']['room_memo'],
//价格方案
"plan_id" => $param['data']['plan_id'],
"plan_name" => $roomPlan['data']['plan_name'],
"plan_memo" => $roomPlan['data']['plan_memo'],
//其他
"check_in_date" => $param['check_in_date'],
"check_out_date" => $param['check_out_date'],
"confirm_status" => $param['confirm_status'],
"confirm_no" => $param['confirm_no'],
"customer_name" => $param['customer_name'],
"customer_comments" => $param['customer_comments'],
"trade_order_number" => $param['trade_order_number'],
"res_person" => $param['res_person'],
"res_person_id" => $param['res_person_id'],
"del_flag"=>0
];
$orderHotelModel = new OrderHotel();
if (empty($param['id'])) {

$id = $orderHotelModel->insertGetId($data);
return Util::returnArrSu($id);
}else {
$orderHotelModel->save($data, ["id" => $param['id']]);
return Util::returnArrSu($param['id']);
}
}catch (Exception $e){
return Util::returnArrEr("更新酒店子订单失败".$e->getMessage());
}
}

/**
@@ -170,4 +181,40 @@ 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]);
}

/**
* 删除记录
* @param $id
*/
public function delById($id) {
$model = new OrderHotel();
$model->save(["del_flag"=>1],["id"=>$id]);
}

/**
* 获取酒店子订单列表
* @param $orderId
* @return array
*/
public function getListByOrderId($orderId){
$subOrderModel = new OrderHotel();
try {
$subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select();
if (null == $subOrderList) {
return Util::returnArrEr([]);
}
return Util::returnArrSu($subOrderList);
}catch (Exception $e) {
return Util::returnArrEr("获取酒店订单列表异常".$e->getMessage());
}
}
}

+ 78
- 28
application/admin/service/OrderItemDao.php View File

@@ -18,44 +18,57 @@ use think\Exception;

class OrderItemDao
{


/**
* 添加失败
* 新增、更新记录
* @param $param
* @param $orderId
* @return array|string
*/
public function addInfo($param, $orderId)
public function modify($param, $orderId)
{
$itemInfo = $this->getItemInfo($param['item_id']);
if (!$itemInfo['flag']){
return $itemInfo;
}
//设置入参
$data = [
"order_id" => $orderId,
//附加项目
"item_id"=>$itemInfo['data']['id'],
"item_type"=>$itemInfo['data']['item_type'],
"item_name"=>$itemInfo['data']['item_name'],
"item_memo"=>$itemInfo['data']['item_memo'],
"item_unit"=>$itemInfo['data']['item_unit'],
"country_name" => $itemInfo['data']['country_name'],
"province_name" => $itemInfo['data']['province_name'],
"city_name" => $itemInfo['data']['city_name'],
"detail_address" => $itemInfo['data']['detail_address'],
//其他
"check_in_date" => $param['check_in_date'],
"confirm_status" => $param['confirm_status'],
"confirm_no" => $param['confirm_no'],
"customer_name" => $param['customer_name'],
"customer_comments" => $param['customer_comments'],
"trade_order_number" => $param['trade_order_number'],
"res_person" => $param['res_person'],
"res_person_id" => $param['res_person_id']
];
$orderHotelModel = new OrderHotel();
$id = $orderHotelModel->insertGetId($data);
return Util::returnArrSu($id);
try{
//设置入参
$data = [
"order_id" => $orderId,
//附加项目
"item_id"=>$itemInfo['data']['id'],
"item_type"=>$itemInfo['data']['item_type'],
"item_name"=>$itemInfo['data']['item_name'],
"item_memo"=>$itemInfo['data']['item_memo'],
"item_unit"=>$itemInfo['data']['item_unit'],
"country_name" => $itemInfo['data']['country_name'],
"province_name" => $itemInfo['data']['province_name'],
"city_name" => $itemInfo['data']['city_name'],
"detail_address" => $itemInfo['data']['detail_address'],
//其他
"check_in_date" => $param['check_in_date'],
"confirm_status" => $param['confirm_status'],
"confirm_no" => $param['confirm_no'],
"customer_name" => $param['customer_name'],
"customer_comments" => $param['customer_comments'],
"trade_order_number" => $param['trade_order_number'],
"res_person" => $param['res_person'],
"res_person_id" => $param['res_person_id'],
"del_flag"=>0
];
$orderHotelModel = new OrderHotel();
if (empty($param['id'])) {
$id = $orderHotelModel->insertGetId($data);
return Util::returnArrSu($id);
}else {
$orderHotelModel->save($data,["id"=>$param['id']]);
return Util::returnArrSu($param['id']);
}
}catch (Exception $e){
return Util::returnArrEr("更新附加项目子订单失败".$e->getMessage());
}

}

/**
@@ -122,4 +135,41 @@ class OrderItemDao
}
}

/**
* 删除记录
* @param $order_id
*/
public function delete($order_id){
$model = new OrderItem();
$model->save(["del_flag"=>1],["order_id"=>$order_id]);
}

/**
* 删除记录
* @param $id
*/
public function delById($id) {
$model = new OrderItem();
$model->save(["del_flag"=>1],["id"=>$id]);
}

/**
* 获取附加项目子订单列表
* @param $orderId
* @return array
*/
public function getListByOrderId($orderId){
$subOrderModel = new OrderItem();
try {
$subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select();
if (null == $subOrderList) {
return Util::returnArrEr([]);
}
return Util::returnArrSu($subOrderList);
}catch (Exception $e) {
return Util::returnArrEr("获取附加项目订单列表异常".$e->getMessage());
}
}


}

+ 57
- 32
application/admin/service/OrderMainDao.php View File

@@ -17,41 +17,13 @@ use think\Exception;

class OrderMainDao
{
/**
* 添加订单信息
* @param $param
* @return array
*/
public function addMain ($param){
try{
$data = [
"commissioner_id"=>$param['commissioner_id'],
"commissioner"=>$param["commissioner"],
"channel_id"=>$param["channel_id"],
"channel_name"=>$param["channel_name"],
"channel_order_no"=>$param["channel_order_no"],
"user_name"=>$param["user_name"],
"user_phone"=>$param["user_phone"],
"order_memo"=>$param["order_memo"]
];
$orderMain = new OrderMain();
$id = $orderMain->insertGetId($data);
if (!is_numeric($id)) {
return Util::returnArrEr("新增失败");
}
return Util::returnArrSu($id);
}catch (Exception $e){
return Util::returnArrEr("新增主订单失败".$e->getMessage());
}

}

/**
* 更新订单信息
* 添加、更新订单信息
* @param $param
* @return array
*/
public function edit($param) {
public function save($param) {
try{
$data = [
"commissioner_id"=>$param['commissioner_id'],
@@ -64,8 +36,13 @@ class OrderMainDao
"order_memo"=>$param["order_memo"]
];
$orderMain = new OrderMain();
$orderMain->save($data,['id'=>$param['id']]);
return Util::returnArrSu();
if (empty($param['id'])) {
$id = $orderMain->insertGetId($data);
return Util::returnArrSu($id);
} else {
$orderMain->save($data,['id'=>$param['id']]);
return Util::returnArrSu($param['id']);
}
}catch (Exception $e){
return Util::returnArrEr("更新主订单失败".$e->getMessage());
}
@@ -100,4 +77,52 @@ class OrderMainDao
return Util::returnArrEr("更新主表订单金额失败".$orderId);
}
}

/**
* 根据ID获取详情
* @param $id
* @return array
*/
public function getInfoById($id) {
try {
$orderMainModel = new OrderMain();
$orderMain = $orderMainModel->where(["id" => $id])->find();
if (null == $orderMain) {
return Util::returnArrEr("订单查询失败".$id);
}
return Util::returnArrSu($orderMain);
}catch (Exception $e) {
return Util::returnArrEr("订单查询失败".$e->getMessage());
}
}

/**
* 子订单展示
* @param $purchaseShow
* @param $orderHotel
* @param $orderItem
* @return array
*/
public function setSubOrderShow($purchaseShow,$orderHotel,$orderItem){
$result = [];
foreach ($orderItem as $item) {
$item['prod_type'] = 'item';
foreach ($purchaseShow as $key=> $purchase) {
if ($item['id'] == $key) {
array_merge($item,$purchase);
}
}
$result[] = $item;
}
foreach ($orderHotel as $hotel) {
$hotel['prod_type'] = 'hotel';
foreach ($purchaseShow as $key=> $purchase) {
if ($hotel['id'] == $key) {
array_merge($hotel,$purchase);
}
}
$result[] = $hotel;
}
return Util::returnArrSu($result);
}
}

+ 175
- 14
application/admin/service/OrderMainService.php View File

@@ -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 createOrder($param) {
/**
* 保存主订单
* @param $param
* @return array
*/
public function saveOrder($param)
{
/**
* 1.添加主订单
*/
$orderMainDao = new OrderMainDao();
$addOrderMain = $orderMainDao->addMain($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->addInfo($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->addHotelPurchase($subOrderParam,$subOrderInfo);
$addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo);
} else {
$addPurchase = $purchaseDao->addItemPurchase($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->addList($subOrderParam['purchasePriceList'],$orderId,$subOrderParam['prod_type'],$subOrderId,$purchaseId);
$addPurchasePrice = $purchasePriceDao->saveList($subOrderParam['purchasePriceList'], $orderId, $subOrderParam['prod_type'], $subOrderId, $purchaseId);
if (!$addPurchasePrice['flag']) {
return $addPurchasePrice;
}
@@ -95,4 +110,150 @@ 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);
}

/**
* 删除子订单
* @param $param
* @return array
*/
public function delSubOrder($param){
try {
if ($param['prodType'] == 'hotel') {
$subOrderDao = new OrderHotelDao();
} else {
$subOrderDao = new OrderItemDao();
}
$subOrderDao->delById($param['id']);
//删除采购单
$purchaseDao = new PurchaseDao();
$purchaseDao->deleteBySubOrderId($param['id']);
//删除每日采购单价格
$purchasePriceDao = new PurchasePriceDao();
$purchasePriceDao->deleteBySubOrderId($param['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);
}
}

+ 94
- 8
application/admin/service/PurchaseDao.php View File

@@ -11,6 +11,7 @@ namespace app\admin\service;

use app\admin\command\Util;
use app\admin\model\Purchase;
use app\admin\model\PurchasePrice;
use think\Exception;

class PurchaseDao
@@ -21,7 +22,7 @@ class PurchaseDao
* @param $hotelOrder
* @return array
*/
public function addHotelPurchase($param,$hotelOrder):array {
public function saveHotelPurchase($param,$hotelOrder):array {
try {
$data = [
"order_id" => $hotelOrder['order_id'],
@@ -36,11 +37,17 @@ 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();
$id = $model->insertGetId($data);
return Util::returnArrSu($id);
if (empty($param['purchase_id'])) {
$id = $model->insertGetId($data);
return Util::returnArrSu($id);
}else {
$model->save($data,["id"=>$param['purchase_id']]);
return Util::returnArrSu($param['purchase_id']);
}
}catch (Exception $e){
return Util::returnArrEr("新增采购都失败".$e->getMessage());
}
@@ -52,7 +59,7 @@ class PurchaseDao
* @param $itemOrder
* @return array
*/
public function addItemPurchase($param, $itemOrder):array {
public function saveItemPurchase($param, $itemOrder):array {
try {
$data = [
"order_id" => $itemOrder['order_id'],
@@ -67,11 +74,17 @@ 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();
$id = $model->insertGetId($data);
return Util::returnArrSu($id);
if (empty($param['purchase_id'])) {
$id = $model->insertGetId($data);
return Util::returnArrSu($id);
}else {
$model->save($data,["id"=>$param['purchase_id']]);
return Util::returnArrSu($param['purchase_id']);
}
}catch (Exception $e){
return Util::returnArrEr("新增采购都失败".$e->getMessage());
}
@@ -101,4 +114,77 @@ class PurchaseDao
}

}

/**
* 删除记录
* @param $order_id
*/
public function delete($order_id){
$model = new Purchase();
$model->save(["del_flag"=>1],["order_id"=>$order_id]);
}

/**
* 删除子订单
* @param $subOrderId
*/
public function deleteBySubOrderId($subOrderId) {
$model = new Purchase();
$model->save(["del_flag"=>1],["order_detail_id"=>$subOrderId]);
}

/**
* 获取采购单列表
* @param $orderId
* @return array
*/
public function getListByOrderId($orderId) {
$model = new Purchase();
try {
$list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select();
if (null == $list) {
return Util::returnArrSu([]);
}
return Util::returnArrSu($list);
}catch (Exception $e) {
return Util::returnArrEr("获取订单的采购单列表失败".$e->getMessage());
}
}

/**
* 设置
* @param $purchaseList
* @param $purchasePriceList
* @return array
*/
public function setPurchaseShow($purchaseList,$purchasePriceList){
$result = [];
foreach ($purchaseList as $purchase) {
$purchaseShow=[
"purchase_id"=>$purchase['id'],
"purchase_user_id"=>$purchase['purchase_user_id'],
"purchase_user"=>$purchase['purchase_user'],
"supplier_id"=>$purchase['supplier_id'],
"supplier_name" =>$purchase['supplier_name'],
"purchasePriceList"=>[]
];
foreach ($purchasePriceList as $price) {
if ($price['purchase_id'] == $purchase['id']) {
$priceShow = [
"id"=>$price['id'],
"run_date"=>$price['run_date'],
"count"=>$price['count'],
"price"=>$price['price'],
"cost"=>$price['cost']
];
$purchaseShow["purchasePriceList"][]=$priceShow;
}
}
if (null == $result[$purchase['order_detail_id']]) {
$result[$purchase['order_detail_id']] = [];
}
$result[$purchase['order_detail_id']][]= $purchaseShow;
}
return Util::returnArrSu($result);
}
}

+ 51
- 5
application/admin/service/PurchasePriceDao.php View File

@@ -25,8 +25,12 @@ class PurchasePriceDao
* @param int $purchase_id
* @return array
*/
public function addList($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,14 +40,56 @@ 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();
$model->insertGetId($data);
if (empty($value['id'])) {
$model->insertGetId($data);
} else {
$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]);
}

/**
* 删除子订单对于的每日价格
* @param $subOrderId
*/
public function deleteBySubOrderId($subOrderId) {
$model = new PurchasePrice();
$model->save(["del_flag" => 1], ["order_detail_id" => $subOrderId]);
}

/**
* 获取采购单金额
* @param $orderId
* @return array
*/
public function getPurchasePriceListByOrderId($orderId) {
$model = new PurchasePrice();
try {
$list = $model->where(["order_id" => $orderId, "del_flag" => $orderId])->select();
if (null == $list) {
return Util::returnArrSu([]);
}
return Util::returnArrSu($list);
}catch (Exception $e) {
return Util::returnArrEr("获取采购单金额异常".$e->getMessage());
}
}
}

Loading…
Cancel
Save