|
|
@@ -72,21 +72,40 @@ class OrderMainDao |
|
|
|
try { |
|
|
|
$itemModel = new OrderItem(); |
|
|
|
$hotelModel = new OrderHotel(); |
|
|
|
$itemList = $itemModel->where(["order_id" => $orderId])->select()->toArray(); |
|
|
|
$hotelList = $hotelModel->where(["order_id" => $orderId])->select()->toArray(); |
|
|
|
$itemList = $itemModel->where(["order_id" => $orderId,"del_flag"=>0])->select()->toArray(); |
|
|
|
$hotelList = $hotelModel->where(["order_id" => $orderId,"del_flag"=>0])->select()->toArray(); |
|
|
|
$amount = 0; |
|
|
|
$cost = 0; |
|
|
|
//状态数量统计 用于统计当前订单的状态 |
|
|
|
$statusList = [ |
|
|
|
1=>0, |
|
|
|
2=>0, |
|
|
|
3=>0, |
|
|
|
4=>0, |
|
|
|
"isPayment"=>0 |
|
|
|
]; |
|
|
|
$cnt = count($itemList)+count($hotelList); |
|
|
|
foreach ($itemList as $item) { |
|
|
|
$amount += $item['total_price']; |
|
|
|
$cost += $item['total_cost']; |
|
|
|
$statusList[$item['confirm_status']]++; |
|
|
|
if ($item['payment_order_status'] ==2) { |
|
|
|
$statusList['isPayment']++; |
|
|
|
} |
|
|
|
} |
|
|
|
foreach ($hotelList as $hotel) { |
|
|
|
$amount += $hotel['total_price']; |
|
|
|
$cost += $hotel["total_cost"]; |
|
|
|
$statusList[$hotel['confirm_status']]++; |
|
|
|
if ($hotel['payment_order_status'] ==2) { |
|
|
|
$statusList['isPayment']++; |
|
|
|
} |
|
|
|
} |
|
|
|
$orderInfo = $this->getInfoById($orderId); |
|
|
|
$orderStatus = $this->getStatus($cnt,$statusList,$orderInfo); |
|
|
|
//更新金额 |
|
|
|
$orderMain = new OrderMain(); |
|
|
|
$orderMain->save(["total_amount" => $amount, "cost_amount" => $cost,"profit_amount"=>$amount-$cost],["id" => $orderId]); |
|
|
|
$orderMain->save(["total_amount" => $amount, "cost_amount" => $cost,"profit_amount"=>$amount-$cost,"order_status"=>$orderStatus],["id" => $orderId]); |
|
|
|
return Util::returnArrSu(); |
|
|
|
}catch (Exception $e){ |
|
|
|
return Util::returnArrEr("更新主表订单金额失败:".$e->getMessage()); |
|
|
@@ -94,6 +113,44 @@ class OrderMainDao |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取订单状态 |
|
|
|
* @param $cnt |
|
|
|
* @param $statusList |
|
|
|
* @param $orderInfo |
|
|
|
* @return int |
|
|
|
*/ |
|
|
|
public function getStatus($cnt,$statusList,$orderInfo){ |
|
|
|
//资源单状态 1、未发单/ 2已发单、3已确认、4已取消 |
|
|
|
//订单状态0待处理 1已确认 2部分取消 3处理中 10已完成 11已取消 |
|
|
|
|
|
|
|
//已完成:订单已完成付款、已完成收款(无视子订单状态) |
|
|
|
if ($orderInfo['receipt_order_status'] ==2 && $statusList['isPayment'] == $cnt) { |
|
|
|
return 10; |
|
|
|
} |
|
|
|
//全部未发单 待处理:子订单全部未发单 |
|
|
|
if ($statusList[1] == $cnt) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
//全部已确认 已确认:子订单全部已确认 |
|
|
|
if ($statusList[3] == $cnt) { |
|
|
|
return 1; |
|
|
|
} |
|
|
|
//全部已取消 已取消:订单中所有子订单已取消 |
|
|
|
if ($statusList[4] == $cnt) { |
|
|
|
return 11; |
|
|
|
} |
|
|
|
//部分取消:订单中有子订单取消,其他子订单已确认 |
|
|
|
if (($statusList[3]+$statusList[4]) == $cnt ) { |
|
|
|
return 2; |
|
|
|
} |
|
|
|
//处理中:非以上状态,即部分子订单确认、或者部分子订单在已发单,或部分子订单在未发单。 |
|
|
|
return 3; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 根据ID获取详情 |
|
|
|
* @param $id |
|
|
|
* @return array |
|
|
|