Browse Source

接口优化

dev
nizongfeng 3 years ago
parent
commit
7e3e33c49b
7 changed files with 141 additions and 114 deletions
  1. +17
    -4
      application/admin/controller/OrderMain.php
  2. +44
    -34
      application/admin/service/OrderHotelDao.php
  3. +41
    -28
      application/admin/service/OrderItemDao.php
  4. +9
    -32
      application/admin/service/OrderMainDao.php
  5. +6
    -7
      application/admin/service/OrderMainService.php
  6. +17
    -6
      application/admin/service/PurchaseDao.php
  7. +7
    -3
      application/admin/service/PurchasePriceDao.php

+ 17
- 4
application/admin/controller/OrderMain.php View File

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

use app\admin\model\Area;
use app\admin\service\OrderMainDao;
use app\admin\service\OrderMainService;
use app\common\controller\Backend;
use think\Db;
@@ -224,13 +223,27 @@ class OrderMain extends Backend
}

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

public function newAdd(){
$params=$this->request->post();
$hotelMain = $params["orderMain"];
$this->insertOrderMain($hotelMain);
return ;
}

private function insertOrderMain($params){


+ 44
- 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,48 @@ 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']
];
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']);
}
}catch (Exception $e){
return Util::returnArrEr("更新酒店子订单失败".$e->getMessage());
}
}

/**


+ 41
- 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']
];
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']);
}
}catch (Exception $e){
return Util::returnArrEr("更新附加项目子订单失败".$e->getMessage());
}

}

/**


+ 9
- 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());
}


+ 6
- 7
application/admin/service/OrderMainService.php View File

@@ -20,12 +20,12 @@ use think\Url;
class OrderMainService
{

public function createOrder($param) {
public function saveOrder($param) {
/**
* 1.添加主订单
*/
$orderMainDao = new OrderMainDao();
$addOrderMain = $orderMainDao->addMain($param);
$addOrderMain = $orderMainDao->save($param);
if (!$addOrderMain["flag"]) {
return $addOrderMain;
}
@@ -39,7 +39,7 @@ class OrderMainService
}else {
$subOrderDao = new OrderItemDao();
}
$addSubOrder = $subOrderDao->addInfo($subOrderParam,$orderId);
$addSubOrder = $subOrderDao->modify($subOrderParam,$orderId);
if (!$addSubOrder['flag']) {
return $addSubOrder;
}
@@ -51,9 +51,9 @@ class OrderMainService
*/
$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;
@@ -64,7 +64,7 @@ class OrderMainService
* 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;
}
@@ -94,5 +94,4 @@ class OrderMainService
}
return Util::returnArrSu($orderId);
}

}

+ 17
- 6
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'],
@@ -39,8 +40,13 @@ class PurchaseDao
"purchase_user" => $param['purchase_user']
];
$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 +58,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'],
@@ -70,8 +76,13 @@ class PurchaseDao
"purchase_user" => $param['purchase_user']
];
$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());
}


+ 7
- 3
application/admin/service/PurchasePriceDao.php View File

@@ -25,7 +25,7 @@ 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 {
foreach ($param as $value) {
$data = [
@@ -39,11 +39,15 @@ class PurchasePriceDao
"cost" => $value['cost']
];
$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());
return Util::returnArrEr("添加/更新采购单每日价格失败".$e->getMessage());
}
}
}

Loading…
Cancel
Save