调整备货单
This commit is contained in:
@@ -103,20 +103,65 @@ class StockOrdersService
|
||||
// $profit = 0;
|
||||
foreach ($data['veh_list'] as $veh) {
|
||||
$veh['order_id'] = $created->id;
|
||||
|
||||
// 唯一标识
|
||||
$uniqueIdStr = "";
|
||||
$uniqueIdStr .= $veh['sku_id'];
|
||||
$uniqueIdStr .= $veh['model_snapshot'];
|
||||
$uniqueIdStr .= $veh['color_interior_code'];
|
||||
$uniqueIdStr .= $veh['color_exterior_code'];
|
||||
$uniqueIdStr .= $veh['mileage'];
|
||||
$uniqueIdStr .= json($veh['modify_list']);
|
||||
$veh['unique_id'] = md5($uniqueIdStr);
|
||||
$item = StockOrderItems::create($veh); // 表2
|
||||
|
||||
// 金额 // 表3
|
||||
$item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价');
|
||||
$item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价');
|
||||
$item->addMoney('unit_price', $veh['unit_price']['currency'], $veh['unit_price']['amount'], $veh['unit_price']['rate'], '单价');
|
||||
$item->addMoney('total_price', $veh['total_price']['currency'], $veh['total_price']['amount'], $veh['total_price']['rate'], '总价');
|
||||
$item->addMoney('handling_fee', $veh['handling_fee']['currency'], $veh['handling_fee']['amount'], $veh['handling_fee']['rate'], '手续费');
|
||||
$item->addMoney('fob_transport_fee', $veh['fob_transport_fee']['currency'], $veh['fob_transport_fee']['amount'], $veh['fob_transport_fee']['rate'], 'FOB运输费');
|
||||
$item->addMoney('port_misc_fee', $veh['port_misc_fee']['currency'], $veh['port_misc_fee']['amount'], $veh['port_misc_fee']['rate'], '港杂');
|
||||
$item->addMoney('retrofit_fee', $veh['retrofit_fee']['currency'], $veh['retrofit_fee']['amount'], $veh['retrofit_fee']['rate'], '改装费');
|
||||
// $item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价');
|
||||
// $item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价');
|
||||
if ($veh['unit_price']['amount']) {
|
||||
$item->addMoney('unit_price', $veh['unit_price']['currency'], $veh['unit_price']['amount'], $veh['unit_price']['rate'], '单价');
|
||||
}
|
||||
if ($veh['total_price']['amount']) {
|
||||
$item->addMoney('total_price', $veh['total_price']['currency'], $veh['total_price']['amount'], $veh['total_price']['rate'], '总价');
|
||||
}
|
||||
if ($veh['handling_fee']['amount']) {
|
||||
$item->addMoney('handling_fee', $veh['handling_fee']['currency'], $veh['handling_fee']['amount'], $veh['handling_fee']['rate'], '手续费');
|
||||
}
|
||||
if ($veh['fob_transport_fee']['amount']) {
|
||||
$item->addMoney('fob_transport_fee', $veh['fob_transport_fee']['currency'], $veh['fob_transport_fee']['amount'], $veh['fob_transport_fee']['rate'], 'FOB运输费');
|
||||
}
|
||||
if ($veh['port_misc_fee']['amount']) {
|
||||
$item->addMoney('port_misc_fee', $veh['port_misc_fee']['currency'], $veh['port_misc_fee']['amount'], $veh['port_misc_fee']['rate'], '港杂');
|
||||
}
|
||||
if ($veh['retrofit_fee']['amount']) {
|
||||
$item->addMoney('retrofit_fee', $veh['retrofit_fee']['currency'], $veh['retrofit_fee']['amount'], $veh['retrofit_fee']['rate'], '改装费');
|
||||
}
|
||||
|
||||
// 二手车 or 新车
|
||||
if ($veh['mileage'] > 0) {
|
||||
if ($veh['listing_price']['amount']) {
|
||||
$item->addMoney('listing_price', $veh['listing_price']['currency'], $veh['listing_price']['amount'], $veh['listing_price']['rate'], '二手挂牌价');
|
||||
}
|
||||
if ($veh['reduction_price']['amount']) {
|
||||
$item->addMoney('reduction_price', $veh['reduction_price']['currency'], $veh['reduction_price']['amount'], $veh['reduction_price']['rate'], '二手减价');
|
||||
}
|
||||
|
||||
$ttPrice = ($veh['listing_price']['amount'] / $created->contract_exchange_rate);
|
||||
$ddPrice = $veh['reduction_price']['amount'];
|
||||
} else {
|
||||
if ($veh['official_price']['amount']) {
|
||||
$item->addMoney('official_price', $veh['official_price']['currency'], $veh['official_price']['amount'], $veh['official_price']['rate'], '官方指导价');
|
||||
}
|
||||
if ($veh['discount_price']['amount'] ) {
|
||||
$item->addMoney('discount_price', $veh['discount_price']['currency'], $veh['discount_price']['amount'], $veh['discount_price']['rate'], '优惠价');
|
||||
}
|
||||
|
||||
$ttPrice = ($veh['official_price']['amount'] / $created->contract_exchange_rate);
|
||||
$ddPrice = $veh['discount_price']['amount'];
|
||||
}
|
||||
|
||||
// 利润
|
||||
$profit = $veh['unit_price']['amount'] - ($veh['official_price']['amount'] / $created->contract_exchange_rate) - $veh['discount_price']['amount'] - $veh['handling_fee']['amount'] - $veh['fob_transport_fee']['amount'] - $veh['port_misc_fee']['amount'] - $veh['retrofit_fee']['amount'];
|
||||
$profit = (float)$veh['unit_price']['amount'] - (float)$ttPrice - (float)$ddPrice - (float)$veh['handling_fee']['amount'] - (float)$veh['fob_transport_fee']['amount'] - (float)$veh['port_misc_fee']['amount'] - (float)$veh['retrofit_fee']['amount'];
|
||||
$item->addMoney('profit', $veh['unit_price']['currency'], $profit, $veh['unit_price']['rate'], '利润');
|
||||
|
||||
// cif_total_amount
|
||||
@@ -193,8 +238,8 @@ class StockOrdersService
|
||||
$pdfBin = $driver->htmlToPdf($html);
|
||||
|
||||
// 存储
|
||||
$dir = public_path('pdf');
|
||||
$fileName = '/'.($pdfData['order_no'] ?? date('YmdHis')) . '.pdf';
|
||||
$dir = public_path('pdf').'/';
|
||||
$fileName = ($pdfData['order_no'] ?? date('YmdHis')) . '.pdf';
|
||||
|
||||
// 本地保存
|
||||
$filePath = \app\common\utils\pdf\service\PdfStorage::saveBinary(
|
||||
@@ -209,7 +254,11 @@ class StockOrdersService
|
||||
// 'Content-Disposition' => 'inline; filename="stock-order.pdf"',
|
||||
// ], $pdfBin);
|
||||
|
||||
return ['file_url' => $dir.$fileName];
|
||||
$url = [
|
||||
'file_name' => $fileName,
|
||||
'file_url' => getenv('MAIN_DOMAIN').'/pdf/'.$fileName
|
||||
];
|
||||
return $url;
|
||||
}
|
||||
|
||||
|
||||
@@ -219,10 +268,10 @@ class StockOrdersService
|
||||
$index = 0;
|
||||
foreach ($item->items as $k => $v) {
|
||||
// 存在则数量加1
|
||||
if (count($vehList) > 0 && isset($vehList[$v->sku_id])) {
|
||||
$vehList[$v->sku_id]['num'] += 1;
|
||||
$vehList[$v->sku_id]['total_price'] += $vehList[$v->sku_id]['unit_price'];
|
||||
$vehList[$v->sku_id]['total_price_text'] = $vehList[$v->sku_id]['total_price_symbol'].number_format($vehList[$v->sku_id]['total_price'], 2, '.', ',');
|
||||
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, '.', ',');
|
||||
continue;
|
||||
}
|
||||
$index += 1;
|
||||
@@ -232,7 +281,7 @@ class StockOrdersService
|
||||
$mv[$money->field] = [
|
||||
'currency' => $money->currency,
|
||||
'amount' => $money->amount,
|
||||
'rate' => $money->rate,
|
||||
'rate' => $money->exchange_rate,
|
||||
'currency_symbol' => SysCurrency::where('currency_code', $money->currency)->value('currency_symbol'),
|
||||
];
|
||||
}
|
||||
@@ -243,29 +292,42 @@ class StockOrdersService
|
||||
}
|
||||
|
||||
// 处理结果集
|
||||
$vehList[$v->sku_id] = [
|
||||
$vehList[$v->unique_id] = [
|
||||
'index' => $index,
|
||||
'model_snapshot' => $v->model_snapshot,
|
||||
'color_interior_snapshot' => $v->color_interior_snapshot,
|
||||
'color_exterior_snapshot' => $v->color_exterior_snapshot,
|
||||
'num' => 1,
|
||||
'modify' => $mfy,
|
||||
|
||||
'mileage' => $v->mileage,
|
||||
'unit_price' => $mv['unit_price']['amount'],
|
||||
'total_price' => $mv['total_price']['amount'],
|
||||
'official_price' => $mv['official_price']['amount'],
|
||||
'discount_price' => $mv['discount_price']['amount'],
|
||||
|
||||
'unit_price_symbol' => $mv['unit_price']['currency_symbol'],
|
||||
'total_price_symbol' => $mv['total_price']['currency_symbol'],
|
||||
'official_price_symbol' => $mv['official_price']['currency_symbol'],
|
||||
'discount_price_symbol' => $mv['discount_price']['currency_symbol'],
|
||||
|
||||
'unit_price_text' => $mv['unit_price']['currency_symbol'].number_format($mv['unit_price']['amount'], 2, '.', ','),
|
||||
'total_price_text' => $mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ','),
|
||||
'official_price_text' => $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ','),
|
||||
'discount_price_text' => $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ','),
|
||||
'total_price_text' => $mv['total_price']['currency_symbol'].number_format($mv['total_price']['amount'], 2, '.', ',')
|
||||
];
|
||||
|
||||
// 根据里程处理 新车or二手车
|
||||
if ($v->mileage > 0) {
|
||||
if (isset($mv['reduction_price'])) {
|
||||
$vehList[$v->unique_id]['reduction_price'] = $mv['reduction_price']['amount'];
|
||||
$vehList[$v->unique_id]['reduction_price_symbol'] = $mv['reduction_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['reduction_price_text'] = $mv['reduction_price']['currency_symbol'].number_format($mv['reduction_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
$vehList[$v->unique_id]['listing_price'] = $mv['listing_price']['amount'];
|
||||
$vehList[$v->unique_id]['listing_price_symbol'] = $mv['listing_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['listing_price_text'] = $mv['listing_price']['currency_symbol'].number_format($mv['listing_price']['amount'], 2, '.', ',');
|
||||
} else {
|
||||
if (isset($mv['discount_price'])) {
|
||||
$vehList[$v->unique_id]['discount_price'] = $mv['discount_price']['amount'];
|
||||
$vehList[$v->unique_id]['discount_price_symbol'] = $mv['discount_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['discount_price_text'] = $mv['discount_price']['currency_symbol'].number_format($mv['discount_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
$vehList[$v->unique_id]['official_price'] = $mv['official_price']['amount'];
|
||||
$vehList[$v->unique_id]['official_price_symbol'] = $mv['official_price']['currency_symbol'];
|
||||
$vehList[$v->unique_id]['official_price_text'] = $mv['official_price']['currency_symbol'].number_format($mv['official_price']['amount'], 2, '.', ',');
|
||||
}
|
||||
}
|
||||
|
||||
$accList = [];
|
||||
@@ -283,6 +345,12 @@ class StockOrdersService
|
||||
$accIndex += 1;
|
||||
}
|
||||
|
||||
$cifTotalAmount = 0.00;
|
||||
if ($item->moneyValues) {
|
||||
$cifTotalAmountSysboml = SysCurrency::where('currency_code', $item->moneyValues->currency)->value('currency_symbol');
|
||||
$cifTotalAmount = $cifTotalAmountSysboml.sprintf("%.2f", $item->moneyValues->amount, $item->moneyValues->exchange_rate);
|
||||
}
|
||||
|
||||
$veh = [
|
||||
'order_no' => $item->order_no,
|
||||
'salesperson_snapshot' => $item->salesperson_snapshot,
|
||||
@@ -310,7 +378,8 @@ class StockOrdersService
|
||||
|
||||
// 账户
|
||||
'account_list' => $accList,
|
||||
'acc_index' => $accIndex
|
||||
'acc_index' => $accIndex,
|
||||
'cif_total_amount' => $cifTotalAmount
|
||||
];
|
||||
|
||||
return $veh;
|
||||
|
||||
Reference in New Issue
Block a user