调整
This commit is contained in:
@@ -71,6 +71,7 @@ class StockOrdersService
|
||||
case 'approval':
|
||||
$config['where']['id'] = $p['id'];
|
||||
break;
|
||||
case 'detail':
|
||||
case 'show':
|
||||
$config['where']['id'] = $p['id'];
|
||||
|
||||
@@ -223,10 +224,10 @@ class StockOrdersService
|
||||
$data['salesperson_snapshot'] = User::where('id', $userId)->value('name') ?? '';
|
||||
$data['approval_status'] = $data['approval_status'] == 1 ? 1 : 0;
|
||||
|
||||
if ($data['is_final'] == 1) {
|
||||
// if ($data['is_final'] == 1) {
|
||||
$data['pick_up_date'] = strtotime($data['pick_up_date']);
|
||||
$data['collect_all_date'] = strtotime($data['collect_all_date']);
|
||||
}
|
||||
// }
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -452,18 +453,45 @@ class StockOrdersService
|
||||
$vehList = [];
|
||||
$index = 0;
|
||||
$totalProfit = 0; // 总利润
|
||||
|
||||
// $priceFields = [
|
||||
// 'official_price', // '官方指导价',
|
||||
// 'discount_price', // '优惠',
|
||||
// 'listing_price', // '二手挂牌价价',
|
||||
// 'reduction_price', // '优惠',
|
||||
|
||||
// 'handling_fee', // '手续费',
|
||||
// 'retrofit_fee', // '改装费',
|
||||
// 'fob_transport_fee', // 'FOB运输费',
|
||||
// 'port_misc_fee', // '港杂',
|
||||
// 'ocean_freight', // '海运费',
|
||||
|
||||
// 'unit_price', // '单价',
|
||||
// 'total_price', // '总价',
|
||||
// // 'profit', // '利润'
|
||||
// ];
|
||||
|
||||
foreach ($item->items as $k => $v) {
|
||||
$currencyInfo = SysCurrency::where('currency_code', $item->settlement_currency)->first(['currency_symbol', 'currency_name'])->toArray();
|
||||
|
||||
// 存在则数量加1
|
||||
if (count($vehList) > 0 && isset($vehList[$v->unique_id])) {
|
||||
$vehList[$v->unique_id]['num'] += 1;
|
||||
$vehList[$v->unique_id]['total_price'] += $vehList[$v->unique_id]['unit_price'];
|
||||
$vehList[$v->unique_id]['total_price_text'] = $vehList[$v->unique_id]['total_price_symbol'].number_format($vehList[$v->unique_id]['total_price'], 2, '.', ',');
|
||||
$vehList[$v->unique_id]['total_price']['currency_info'] = $currencyInfo['currency_symbol'].number_format($vehList[$v->unique_id]['total_price']['amount']*$vehList[$v->unique_id]['num'], 2, '.', ',');
|
||||
$vehList[$v->unique_id]['profit']['currency_info'] = $currencyInfo['currency_symbol'].number_format($vehList[$v->unique_id]['profit']['amount']*$vehList[$v->unique_id]['num'], 2, '.', ',');
|
||||
continue;
|
||||
}
|
||||
|
||||
$index += 1;
|
||||
|
||||
// 合计到岸价
|
||||
// $cifTotalAmount = 0.00;
|
||||
// $cifTotalAmountSymbol = '';
|
||||
// if ($item->moneyValues) {
|
||||
// $cifTotalInfo = SysCurrency::where('currency_code', $item->moneyValues->currency)->select('currency_symbol', 'currency_name')->get()->toArray();
|
||||
// $cifTotalAmount = $currencyInfo['currency_symbol'].sprintf("%.2f", $item->moneyValues->amount);
|
||||
// }
|
||||
|
||||
// 处理金额 (每次循环重新初始化)
|
||||
$mv = [];
|
||||
foreach ($v->moneyValues as $money) {
|
||||
@@ -471,7 +499,8 @@ class StockOrdersService
|
||||
'currency' => $money->currency,
|
||||
'amount' => $money->amount,
|
||||
'rate' => $money->exchange_rate,
|
||||
'currency_symbol' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'),
|
||||
'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol').number_format($money->amount, 2, '.', ','),
|
||||
// 'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -494,52 +523,72 @@ class StockOrdersService
|
||||
'num' => 1,
|
||||
'modify' => $mfy,
|
||||
'mileage' => $v->mileage,
|
||||
'unit_price' => $mv['unit_price']['amount'] ?? 0,
|
||||
'total_price' => $mv['total_price']['amount'] ?? 0,
|
||||
'profit' => $itemProfit, // 单项利润
|
||||
'profit_symbol' => $mv['unit_price']['currency_symbol'] ?? '',
|
||||
'profit_text' => isset($mv['unit_price']['currency_symbol']) ?
|
||||
$mv['unit_price']['currency_symbol'].number_format($itemProfit, 2, '.', ',') : '0.00',
|
||||
'unit_price_symbol' => $mv['unit_price']['currency_symbol'] ?? '',
|
||||
'total_price_symbol' => $mv['total_price']['currency_symbol'] ?? '',
|
||||
'unit_price_text' => isset($mv['unit_price']['currency_symbol']) ?
|
||||
$mv['unit_price']['currency_symbol'].number_format($mv['unit_price']['amount'], 2, '.', ',') : '0.00',
|
||||
'total_price_text' => isset($mv['total_price']['currency_symbol']) ?
|
||||
$mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ',') : '0.00'
|
||||
|
||||
|
||||
// 'unit_price' => $mv['unit_price']['amount'] ?? 0,
|
||||
// 'unit_price_symbol' => $mv['unit_price']['currency_symbol'] ?? '',
|
||||
// 'unit_price_text' => isset($mv['unit_price']['currency_symbol']) ?
|
||||
// $mv['unit_price']['currency_symbol'].number_format($mv['unit_price']['amount'], 2, '.', ',') : '0.00',
|
||||
|
||||
// 'total_price' => $mv['total_price']['amount'] ?? 0,
|
||||
// 'total_price_symbol' => $mv['total_price']['currency_symbol'] ?? '',
|
||||
// 'total_price_text' => isset($mv['total_price']['currency_symbol']) ?
|
||||
// $mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ',') : '0.00',
|
||||
|
||||
|
||||
// 'handling_fee' => $mv['handling_fee']['amount'] ?? 0,
|
||||
// 'handling_fee_symbol' => $mv['handling_fee']['currency_symbol'] ?? '',
|
||||
|
||||
|
||||
// 单项利润
|
||||
// 'profit' => $itemProfit,
|
||||
// 'profit_symbol' => $cifTotalInfo['currency_symbol'],
|
||||
// 'profit_text' => isset($mv['unit_price']['currency_symbol']) ? $cifTotalInfo['currency_symbol'].number_format($itemProfit, 2, '.', ',') : '0.00',
|
||||
];
|
||||
|
||||
// 根据里程处理 新车or二手车
|
||||
if ($v->mileage > 0) {
|
||||
// 二手车
|
||||
if (isset($mv['reduction_price'])) {
|
||||
$vehListItem['reduction_price'] = $mv['reduction_price']['amount'];
|
||||
$vehListItem['reduction_price_symbol'] = $mv['reduction_price']['currency_symbol'];
|
||||
$vehListItem['reduction_price_text'] = $mv['reduction_price']['currency_symbol'].number_format($mv['reduction_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
// if ($v->mileage > 0) {
|
||||
// // 二手车
|
||||
// if (isset($mv['reduction_price'])) {
|
||||
// $vehListItem['reduction_price'] = $mv['reduction_price']['amount'];
|
||||
// $vehListItem['reduction_price_symbol'] = $mv['reduction_price']['currency_symbol'];
|
||||
// $vehListItem['reduction_price_text'] = $mv['reduction_price']['currency_symbol'].number_format($mv['reduction_price']['amount'], 2, '.', ',');
|
||||
// }
|
||||
|
||||
if (isset($mv['listing_price'])) {
|
||||
$vehListItem['listing_price'] = $mv['listing_price']['amount'];
|
||||
$vehListItem['listing_price_symbol'] = $mv['listing_price']['currency_symbol'];
|
||||
$vehListItem['listing_price_text'] = $mv['listing_price']['currency_symbol'].number_format($mv['listing_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
} else {
|
||||
// 新车
|
||||
if (isset($mv['discount_price'])) {
|
||||
$vehListItem['discount_price'] = $mv['discount_price']['amount'];
|
||||
$vehListItem['discount_price_symbol'] = $mv['discount_price']['currency_symbol'];
|
||||
$vehListItem['discount_price_text'] = $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
// if (isset($mv['listing_price'])) {
|
||||
// $vehListItem['listing_price'] = $mv['listing_price']['amount'];
|
||||
// $vehListItem['listing_price_symbol'] = $mv['listing_price']['currency_symbol'];
|
||||
// $vehListItem['listing_price_text'] = $mv['listing_price']['currency_symbol'].number_format($mv['listing_price']['amount'], 2, '.', ',');
|
||||
// }
|
||||
// } else {
|
||||
// // 新车
|
||||
// if (isset($mv['discount_price'])) {
|
||||
// $vehListItem['discount_price'] = $mv['discount_price']['amount'];
|
||||
// $vehListItem['discount_price_symbol'] = $mv['discount_price']['currency_symbol'];
|
||||
// $vehListItem['discount_price_text'] = $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ',');
|
||||
// }
|
||||
|
||||
if (isset($mv['official_price'])) {
|
||||
$vehListItem['official_price'] = $mv['official_price']['amount'];
|
||||
$vehListItem['official_price_symbol'] = $mv['official_price']['currency_symbol'];
|
||||
$vehListItem['official_price_text'] = $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
}
|
||||
// if (isset($mv['official_price'])) {
|
||||
// $vehListItem['official_price'] = $mv['official_price']['amount'];
|
||||
// $vehListItem['official_price_symbol'] = $mv['official_price']['currency_symbol'];
|
||||
// $vehListItem['official_price_text'] = $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ',');
|
||||
// }
|
||||
// }
|
||||
|
||||
$vehList[$v->unique_id] = $vehListItem;
|
||||
$vehList[$v->unique_id] = $vehListItem + $mv;
|
||||
}
|
||||
|
||||
// var_dump($item->moneyValues);
|
||||
$mvs = [];
|
||||
foreach ($item->moneyValues as $moneys) {
|
||||
$mvs[$moneys->field] = [
|
||||
'currency' => $moneys->currency,
|
||||
'amount' => $moneys->amount,
|
||||
'rate' => $moneys->exchange_rate,
|
||||
'currency_info' => SysCurrency::where('currency_code', $moneys->currency)->value('currency_symbol').number_format($moneys->amount, 2, '.', ','),
|
||||
// 'currency_info' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'),
|
||||
];
|
||||
}
|
||||
// var_dump($mvs);
|
||||
$accList = [];
|
||||
foreach ($item->accounts as $k => $v) {
|
||||
$accList[] = [
|
||||
@@ -553,12 +602,7 @@ class StockOrdersService
|
||||
];
|
||||
}
|
||||
|
||||
$cifTotalAmount = 0.00;
|
||||
$cifTotalAmountSymbol = '';
|
||||
if ($item->moneyValues) {
|
||||
$cifTotalAmountSymbol = SysCurrency::where('currency_code', $item->moneyValues->currency)->value('currency_symbol');
|
||||
$cifTotalAmount = $cifTotalAmountSymbol.sprintf("%.2f", $item->moneyValues->amount);
|
||||
}
|
||||
|
||||
|
||||
$veh = [
|
||||
'order_no' => $item->order_no,
|
||||
@@ -578,7 +622,8 @@ class StockOrdersService
|
||||
'veh_list' => array_values($vehList), // 重新索引数组
|
||||
|
||||
'contract_exchange_rate' => $item->contract_exchange_rate,
|
||||
'cif_total_amount' => $item->cif_total_amount,
|
||||
'cif_total_amount' => $mvs['cif_total_amount'],
|
||||
'profit_total' => $mvs['profit_total'],
|
||||
|
||||
'declarant_name' => $item->declarant_name,
|
||||
'eta_ship_date' => date('Y-m-d', $item->eta_ship_date),
|
||||
@@ -594,11 +639,12 @@ class StockOrdersService
|
||||
// 账户
|
||||
'account_list' => $accList,
|
||||
'acc_index' => count($accList)+1,
|
||||
'cif_total_amount' => $cifTotalAmount,
|
||||
'cif_total_amount_symbol' => $cifTotalAmountSymbol,
|
||||
'profit' => number_format($totalProfit, 2, '.', ''),
|
||||
'profit_symbol' => $cifTotalAmountSymbol // 假设利润使用相同货币
|
||||
// 'cif_total_amount' => $cifTotalAmount,
|
||||
// 'cif_total_amount_symbol' => $cifTotalAmountSymbol,
|
||||
// 'profit' => number_format($totalProfit, 2, '.', ''),
|
||||
'currency_symbol' => $item->settlement_currency // 假设利润使用相同货币
|
||||
];
|
||||
// var_dump($veh);
|
||||
return $veh;
|
||||
}
|
||||
|
||||
@@ -613,6 +659,14 @@ class StockOrdersService
|
||||
return $this->postProcess('Print', $item);
|
||||
}
|
||||
|
||||
public function serviceDetail(Request $request)
|
||||
{
|
||||
$config = $this->buildQueryConfig($request, 'detail');
|
||||
$item = $this->logicShow($config);
|
||||
$pdfData = $this->pdfData($item);
|
||||
return $this->postProcess('Detail', $pdfData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 审批
|
||||
*/
|
||||
@@ -783,10 +837,11 @@ class StockOrdersService
|
||||
*/
|
||||
private function processVehicleItems($order, array $vehList): void
|
||||
{
|
||||
$cifTotalAmount = 0;
|
||||
$cifTotalAmountRate = 0;
|
||||
$cifTotalAmountCurrency = 'CNY';
|
||||
$cifTotalAmount = 0.00;
|
||||
// $cifTotalAmountRate = 0;
|
||||
// $cifTotalAmountCurrency = 'CNY';
|
||||
|
||||
$profitTotalAmount = 0.00;
|
||||
foreach ($vehList as $veh) {
|
||||
$veh['order_id'] = $order->id;
|
||||
$veh['unique_id'] = $this->generateVehicleUniqueId($veh);
|
||||
@@ -798,23 +853,27 @@ class StockOrdersService
|
||||
|
||||
// 计算利润
|
||||
$profit = $this->calculateProfit($veh, $order);
|
||||
$item->addMoney('profit', $veh['unit_price']['currency'], $profit, $veh['unit_price']['rate'], '利润');
|
||||
$item->addMoney('profit', $order->settlement_currency, $profit, $order->contract_exchange_rate, '利润');
|
||||
|
||||
// 累计到岸价
|
||||
$cifTotalAmount += $veh['total_price']['amount'] ?? 0;
|
||||
if (isset($veh['retrofit_fee']['rate'])) {
|
||||
$cifTotalAmountRate = $veh['retrofit_fee']['rate'];
|
||||
}
|
||||
if (isset($veh['retrofit_fee']['currency'])) {
|
||||
$cifTotalAmountCurrency = $veh['retrofit_fee']['currency'];
|
||||
}
|
||||
$profitTotalAmount += $profit;
|
||||
|
||||
// if (isset($veh['retrofit_fee']['rate'])) {
|
||||
// $cifTotalAmountRate = $veh['retrofit_fee']['rate'];
|
||||
// }
|
||||
// if (isset($veh['retrofit_fee']['currency'])) {
|
||||
// $cifTotalAmountCurrency = $veh['retrofit_fee']['currency'];
|
||||
// }
|
||||
|
||||
// 处理改装项
|
||||
$this->processModificationItems($item->id, $veh['modify_list'] ?? []);
|
||||
}
|
||||
|
||||
// 保存合计到岸价
|
||||
$order->addMoney('cif_total_amount', $cifTotalAmountCurrency, $cifTotalAmount, $cifTotalAmountRate, '合计到岸价');
|
||||
$order->addMoney('cif_total_amount', $order->settlement_currency, $cifTotalAmount, $order->contract_exchange_rate, '合计到岸价');
|
||||
// 利润
|
||||
$order->addMoney('profit_total', $order->settlement_currency, $profitTotalAmount, $order->contract_exchange_rate, '总利润');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user