@@ -16,6 +16,7 @@ use think\exception\ValidateException; | |||
*/ | |||
class OrderMain extends Backend | |||
{ | |||
protected $noNeedLogin = ['save']; | |||
/** | |||
* OrderMain模型对象 | |||
@@ -10,7 +10,9 @@ namespace app\admin\service; | |||
use app\admin\command\Util; | |||
use app\admin\model\CfHotelInfo; | |||
use app\admin\model\CfRoomInfo; | |||
use app\admin\model\CfRoomPlan; | |||
use app\admin\model\OrderHotel; | |||
use app\admin\model\Purchase; | |||
use think\Exception; | |||
@@ -44,16 +46,16 @@ class OrderHotelDao | |||
"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'], | |||
"area_name" => $hotelInfo['data']['area_name'], | |||
"detail_address" => $hotelInfo['data']['detail_address'], | |||
//房型 | |||
"room_id" => $param['data']['room_id'], | |||
"room_id" => $param['room_id'], | |||
"room_name" => $roomInfo['data']['room_name'], | |||
"room_memo" => $roomInfo['data']['room_memo'], | |||
//价格方案 | |||
"plan_id" => $param['data']['plan_id'], | |||
"plan_id" => $param['plan_id'], | |||
"plan_name" => $roomPlan['data']['plan_name'], | |||
"plan_memo" => $roomPlan['data']['plan_memo'], | |||
//其他 | |||
@@ -62,23 +64,23 @@ class OrderHotelDao | |||
"confirm_status" => $param['confirm_status'], | |||
"confirm_no" => $param['confirm_no'], | |||
"customer_name" => $param['customer_name'], | |||
"customer_comments" => $param['customer_comments'], | |||
"customer_comments" => empty($param['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" => empty($param['res_person_id'])?0:$param['res_person_id'], | |||
"del_flag"=>0 | |||
]; | |||
$orderHotelModel = new OrderHotel(); | |||
if (empty($param['id'])) { | |||
$id = $orderHotelModel->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
return Util::returnArrSu("", $id); | |||
}else { | |||
$orderHotelModel->save($data, ["id" => $param['id']]); | |||
return Util::returnArrSu($param['id']); | |||
return Util::returnArrSu("", $param['id']); | |||
} | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新酒店子订单失败".$e->getMessage()); | |||
return Util::returnArrEr("更新酒店子订单失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -90,14 +92,14 @@ class OrderHotelDao | |||
public function getHotelInfo($id) | |||
{ | |||
try { | |||
$model = new OrderHotel(); | |||
$model = new CfHotelInfo(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取酒店信息失败" . $id); | |||
return Util::returnArrEr("获取酒店信息失败:" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("",$result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取酒店信息失败" . $id); | |||
return Util::returnArrEr("获取酒店信息失败:" . $id); | |||
} | |||
} | |||
@@ -112,11 +114,11 @@ class OrderHotelDao | |||
$model = new CfRoomInfo(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取房型信息失败" . $id); | |||
return Util::returnArrEr("获取房型信息失败:" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("", $result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取房型信息失败" . $id); | |||
return Util::returnArrEr("获取房型信息失败:" . $id); | |||
} | |||
} | |||
@@ -128,14 +130,14 @@ class OrderHotelDao | |||
public function getRoomPlan($id) | |||
{ | |||
try { | |||
$model = new CfRoomInfo(); | |||
$model = new CfRoomPlan(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取价格方案信息失败" . $id); | |||
return Util::returnArrEr("获取价格方案信息失败:" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("",$result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取价格方案信息失败" . $id); | |||
return Util::returnArrEr("获取价格方案信息失败:" . $id); | |||
} | |||
} | |||
@@ -156,10 +158,11 @@ class OrderHotelDao | |||
$amount += $purchase['total_price']; | |||
$count += $purchase['count']; | |||
} | |||
OrderHotel::update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]); | |||
$orderHotel = new OrderHotel(); | |||
$orderHotel->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count, "profit"=>$amount-$cost],["id"=>$subOrderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新酒店订单子表金额失败".$subOrderId); | |||
return Util::returnArrEr("更新酒店订单子表金额失败:".$subOrderId); | |||
} | |||
} | |||
@@ -174,11 +177,11 @@ class OrderHotelDao | |||
$model = new OrderHotel(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取子订单信息失败" . $id); | |||
return Util::returnArrEr("获取子订单信息失败:" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("",$result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取子订单信息失败" . $id); | |||
return Util::returnArrEr("获取子订单信息失败:" . $id); | |||
} | |||
} | |||
@@ -210,11 +213,11 @@ class OrderHotelDao | |||
try { | |||
$subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select(); | |||
if (null == $subOrderList) { | |||
return Util::returnArrEr([]); | |||
return Util::returnArrSu("",[]); | |||
} | |||
return Util::returnArrSu($subOrderList); | |||
return Util::returnArrSu("", $subOrderList); | |||
}catch (Exception $e) { | |||
return Util::returnArrEr("获取酒店订单列表异常".$e->getMessage()); | |||
return Util::returnArrEr("获取酒店订单列表异常:".$e->getMessage()); | |||
} | |||
} | |||
} |
@@ -42,7 +42,7 @@ class OrderItemDao | |||
"item_name"=>$itemInfo['data']['item_name'], | |||
"item_memo"=>$itemInfo['data']['item_memo'], | |||
"item_unit"=>$itemInfo['data']['item_unit'], | |||
"country_name" => $itemInfo['data']['country_name'], | |||
"area_name" => $itemInfo['data']['area_name'], | |||
"province_name" => $itemInfo['data']['province_name'], | |||
"city_name" => $itemInfo['data']['city_name'], | |||
"detail_address" => $itemInfo['data']['detail_address'], | |||
@@ -60,13 +60,13 @@ class OrderItemDao | |||
$orderHotelModel = new OrderHotel(); | |||
if (empty($param['id'])) { | |||
$id = $orderHotelModel->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
return Util::returnArrSu("",$id); | |||
}else { | |||
$orderHotelModel->save($data,["id"=>$param['id']]); | |||
return Util::returnArrSu($param['id']); | |||
return Util::returnArrSu("",$param['id']); | |||
} | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新附加项目子订单失败".$e->getMessage()); | |||
return Util::returnArrEr("更新附加项目子订单失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -82,11 +82,11 @@ class OrderItemDao | |||
$model = new CfItem(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取附加项目信息失败" . $id); | |||
return Util::returnArrEr("获取附加项目信息失败:" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("",$result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取附加项目信息失败" . $id); | |||
return Util::returnArrEr("获取附加项目信息失败:" . $id); | |||
} | |||
} | |||
@@ -109,10 +109,10 @@ class OrderItemDao | |||
} | |||
//更新数据 | |||
$oderItem = new OrderItem(); | |||
$oderItem->update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$count])->where(["id"=>$subOrderId]); | |||
$oderItem->save(["total_price"=>$amount,"total_cost"=>$cost,"prod_num"=>$count,"profit"=>$amount-$cost])->where(["id"=>$subOrderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新附加项目订单子表金额失败".$subOrderId); | |||
return Util::returnArrEr("更新附加项目订单子表金额失败:".$subOrderId); | |||
} | |||
} | |||
@@ -127,11 +127,11 @@ class OrderItemDao | |||
$model = new OrderItem(); | |||
$result = $model->where(["id" => $id])->find(); | |||
if ($result == null) { | |||
return Util::returnArrEr("获取子订单信息失败" . $id); | |||
return Util::returnArrEr("获取子订单信息失败:" . $id); | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("", $result); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("获取子订单信息失败" . $id); | |||
return Util::returnArrEr("获取子订单信息失败:" . $id); | |||
} | |||
} | |||
@@ -163,9 +163,9 @@ class OrderItemDao | |||
try { | |||
$subOrderList = $subOrderModel->where(["order_id" => $orderId, "del_flag" => 0])->select(); | |||
if (null == $subOrderList) { | |||
return Util::returnArrEr([]); | |||
return Util::returnArrSu("",[]); | |||
} | |||
return Util::returnArrSu($subOrderList); | |||
return Util::returnArrSu("", $subOrderList); | |||
}catch (Exception $e) { | |||
return Util::returnArrEr("获取附加项目订单列表异常".$e->getMessage()); | |||
} | |||
@@ -26,7 +26,7 @@ class OrderMainDao | |||
public function save($param) { | |||
try{ | |||
$data = [ | |||
"commissioner_id"=>$param['commissioner_id'], | |||
"commissioner_id"=>empty($param['commissioner_id'])?0:$param['commissioner_id'], | |||
"commissioner"=>$param["commissioner"], | |||
"channel_id"=>$param["channel_id"], | |||
"channel_name"=>$param["channel_name"], | |||
@@ -38,13 +38,13 @@ class OrderMainDao | |||
$orderMain = new OrderMain(); | |||
if (empty($param['id'])) { | |||
$id = $orderMain->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
return Util::returnArrSu("", $id); | |||
} else { | |||
$orderMain->save($data,['id'=>$param['id']]); | |||
return Util::returnArrSu($param['id']); | |||
return Util::returnArrSu("", $param['id']); | |||
} | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新主订单失败".$e->getMessage()); | |||
return Util::returnArrEr("更新主订单失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -71,10 +71,11 @@ class OrderMainDao | |||
$cost += $hotel["total_cost"]; | |||
} | |||
//更新金额 | |||
OrderMain::update(["total_amount" => $amount, "cost_amount" => $cost])->where(["id" => $orderId]); | |||
$orderMain = new OrderMain(); | |||
$orderMain->save(["total_amount" => $amount, "cost_amount" => $cost],["id" => $orderId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新主表订单金额失败".$orderId); | |||
return Util::returnArrEr("更新主表订单金额失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -88,11 +89,11 @@ class OrderMainDao | |||
$orderMainModel = new OrderMain(); | |||
$orderMain = $orderMainModel->where(["id" => $id])->find(); | |||
if (null == $orderMain) { | |||
return Util::returnArrEr("订单查询失败".$id); | |||
return Util::returnArrEr("订单查询失败:".$id); | |||
} | |||
return Util::returnArrSu($orderMain); | |||
return Util::returnArrSu("",$orderMain); | |||
}catch (Exception $e) { | |||
return Util::returnArrEr("订单查询失败".$e->getMessage()); | |||
return Util::returnArrEr("订单查询失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -123,6 +124,6 @@ class OrderMainDao | |||
} | |||
$result[] = $hotel; | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("",$result); | |||
} | |||
} |
@@ -48,7 +48,7 @@ class OrderMainService | |||
/** | |||
* 2.添加子订单 有则激活更新、无则添加 | |||
*/ | |||
if ($subOrderParam['prodType'] == 'hotel') { | |||
if ($subOrderParam['prod_type'] == 'hotel') { | |||
$subOrderDao = $orderHotelDao; | |||
} else { | |||
$subOrderDao = $orderItemDao; | |||
@@ -59,21 +59,22 @@ class OrderMainService | |||
} | |||
$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); | |||
$addPurchase = $purchaseDao->saveHotelPurchase($subOrderParam, $subOrderInfo['data']); | |||
} else { | |||
$addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo); | |||
$addPurchase = $purchaseDao->saveItemPurchase($subOrderParam, $subOrderInfo['data']); | |||
} | |||
if (!$addPurchase['flag']) { | |||
return $addPurchase; | |||
} | |||
$purchaseId = $addPurchase['id']; | |||
$purchaseId = $addPurchase['data']; | |||
/** | |||
* 2.1.1添加采购单的每日价格 先删除、后添加激活 | |||
@@ -107,7 +108,7 @@ class OrderMainService | |||
if (!$setOrderMainRe['flag']) { | |||
return $setOrderMainRe; | |||
} | |||
return Util::returnArrSu($orderId); | |||
return Util::returnArrSu("",$orderId); | |||
} | |||
/** | |||
@@ -122,7 +123,7 @@ class OrderMainService | |||
/** | |||
* 2.添加子订单 | |||
*/ | |||
if ($subOrderParam['prodType'] == 'hotel') { | |||
if ($subOrderParam['prod_type'] == 'hotel') { | |||
$subOrderDao = new OrderHotelDao(); | |||
} else { | |||
$subOrderDao = new OrderItemDao(); | |||
@@ -180,7 +181,7 @@ class OrderMainService | |||
if (!$setOrderMainRe['flag']) { | |||
return $setOrderMainRe; | |||
} | |||
return Util::returnArrSu($subOrderId); | |||
return Util::returnArrSu("",$subOrderId); | |||
} | |||
/** | |||
@@ -190,7 +191,7 @@ class OrderMainService | |||
*/ | |||
public function delSubOrder($param){ | |||
try { | |||
if ($param['prodType'] == 'hotel') { | |||
if ($param['prod_type'] == 'hotel') { | |||
$subOrderDao = new OrderHotelDao(); | |||
} else { | |||
$subOrderDao = new OrderItemDao(); | |||
@@ -204,7 +205,7 @@ class OrderMainService | |||
$purchasePriceDao->deleteBySubOrderId($param['id']); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("删除子订单失败".$e->getMessage()); | |||
return Util::returnArrEr("删除子订单失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -254,6 +255,6 @@ class OrderMainService | |||
return $subOrderList; | |||
} | |||
$orderMain["subOrderList"]=$subOrderList['data']; | |||
return Util::returnArrSu($orderMain); | |||
return Util::returnArrSu("",$orderMain); | |||
} | |||
} |
@@ -28,28 +28,29 @@ class PurchaseDao | |||
"order_id" => $hotelOrder['order_id'], | |||
"prod_type" => 'hotel', | |||
"order_detail_id" => $hotelOrder['id'], | |||
"group_id" => $param['group_id'], | |||
"group_id" => empty($param['group_id']), | |||
"pro_name" => $hotelOrder['hotel_name'], | |||
"item_name" => $hotelOrder['room_name'], | |||
"item_unit" => $hotelOrder['plan_name'], | |||
"check_in_date" => $param['check_in_date'], | |||
"check_out_date" => $param['check_out_date'], | |||
"supplier_id" => $param['supplier_id'], | |||
"supplier_name" => $param['supplier_name'], | |||
"purchase_user_id" => $param['purchase_user_id'], | |||
"purchase_user" => $param['purchase_user'], | |||
"supplier_id" => empty($param['supplier_id'])?0:$param['supplier_id'], | |||
"supplier_name" => empty($param['supplier_name'])?"":$param['supplier_name'], | |||
"purchase_user_id" => empty($param['purchase_user_id'])?0:$param['purchase_user_id'], | |||
"purchase_user" => empty($param['purchase_user'])?"":$param['purchase_user'], | |||
"del_flag"=>0 | |||
]; | |||
$model = new Purchase(); | |||
if (empty($param['purchase_id'])) { | |||
$id = $model->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
return Util::returnArrSu("", $id); | |||
}else { | |||
$model->save($data,["id"=>$param['purchase_id']]); | |||
return Util::returnArrSu($param['purchase_id']); | |||
return Util::returnArrSu("", $param['purchase_id']); | |||
} | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("新增采购都失败".$e->getMessage()); | |||
return Util::returnArrEr("新增采购单失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -80,13 +81,13 @@ class PurchaseDao | |||
$model = new Purchase(); | |||
if (empty($param['purchase_id'])) { | |||
$id = $model->insertGetId($data); | |||
return Util::returnArrSu($id); | |||
return Util::returnArrSu("", $id); | |||
}else { | |||
$model->save($data,["id"=>$param['purchase_id']]); | |||
return Util::returnArrSu($param['purchase_id']); | |||
return Util::returnArrSu("", $param['purchase_id']); | |||
} | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("新增采购都失败".$e->getMessage()); | |||
return Util::returnArrEr("新增采购都失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -98,19 +99,20 @@ class PurchaseDao | |||
public function setPurchaseAmount(int $purchaseId){ | |||
try{ | |||
$purchasePrice = new PurchasePrice(); | |||
$purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select()->toArray(); | |||
$purchasePriceList = $purchasePrice->where(["purchase_id"=>$purchaseId,"del_flag"=>0])->select(); | |||
$cost = 0; | |||
$amount = 0; | |||
$cnt = 0; | |||
foreach ($purchasePriceList as $price) { | |||
$cost += $price['cost'] * $price["cnt"]; | |||
$amount += $price['price'] * $price["cnt"]; | |||
$cnt += $price['cnt']; | |||
$cost += $price['cost'] * $price["count"]; | |||
$amount += $price['price'] * $price["count"]; | |||
$cnt += $price['count']; | |||
} | |||
Purchase::update(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt])->where(["id"=>$purchaseId]); | |||
$purchase = new Purchase(); | |||
$purchase->save(["total_price"=>$amount,"total_cost"=>$cost,"count"=>$cnt],["id"=>$purchaseId]); | |||
return Util::returnArrSu(); | |||
}catch (Exception $e){ | |||
return Util::returnArrEr("更新采购单金额失败".$e->getMessage()); | |||
return Util::returnArrEr("更新采购单金额失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -143,11 +145,11 @@ class PurchaseDao | |||
try { | |||
$list = $model->where(["order_id" => $orderId, "del_flag" => 0])->select(); | |||
if (null == $list) { | |||
return Util::returnArrSu([]); | |||
return Util::returnArrSu("",[]); | |||
} | |||
return Util::returnArrSu($list); | |||
return Util::returnArrSu("",$list); | |||
}catch (Exception $e) { | |||
return Util::returnArrEr("获取订单的采购单列表失败".$e->getMessage()); | |||
return Util::returnArrEr("获取订单的采购单列表失败:".$e->getMessage()); | |||
} | |||
} | |||
@@ -185,6 +187,6 @@ class PurchaseDao | |||
} | |||
$result[$purchase['order_detail_id']][]= $purchaseShow; | |||
} | |||
return Util::returnArrSu($result); | |||
return Util::returnArrSu("", $result); | |||
} | |||
} |
@@ -52,7 +52,7 @@ class PurchasePriceDao | |||
} | |||
return Util::returnArrSu(); | |||
} catch (Exception $e) { | |||
return Util::returnArrEr("添加/更新采购单每日价格失败" . $e->getMessage()); | |||
return Util::returnArrEr("添加/更新采购单每日价格失败:" . $e->getMessage()); | |||
} | |||
} | |||
@@ -85,9 +85,9 @@ class PurchasePriceDao | |||
try { | |||
$list = $model->where(["order_id" => $orderId, "del_flag" => $orderId])->select(); | |||
if (null == $list) { | |||
return Util::returnArrSu([]); | |||
return Util::returnArrSu("", []); | |||
} | |||
return Util::returnArrSu($list); | |||
return Util::returnArrSu("", $list); | |||
}catch (Exception $e) { | |||
return Util::returnArrEr("获取采购单金额异常".$e->getMessage()); | |||
} | |||