调整备货单

This commit is contained in:
mzl
2025-10-24 10:43:36 +08:00
parent 448d151106
commit 4326bcd68b
+8 -49
View File
@@ -330,33 +330,25 @@ class StockOrdersService
$data = $this->preProcess('Store', $data, $request); $data = $this->preProcess('Store', $data, $request);
$dl = $this->getDataLimitFromRequest($request); $dl = $this->getDataLimitFromRequest($request);
$created = $this->logicCreate($data, $dl); $created = $this->logicCreate($data, $dl);
// 添加金额 // 添加金额
$created->addMoney('cif_total', $data['cif_total']['currency'], $data['cif_total']['amount'], $data['cif_total']['rate'], '合计到岸价'); $created->addMoney('cif_total', $data['cif_total']['currency'], $data['cif_total']['amount'], $data['cif_total']['rate'], '合计到岸价');
// 处理车辆和账户信息 // 处理车辆和账户信息
$this->processOrderItems($created, $data); $this->processOrderItems($created, $data);
// 处理文件附件 // 处理文件附件
$this->processOrderFiles($created, $data); $this->processOrderFiles($created, $data);
return $this->postProcess('Store', $created); return $this->postProcess('Store', $created);
}); });
} }
protected function onlyFillableData(Model|string $model, array $data, array $extraWhitelist = []): array protected function onlyFillableData(Model|string $model, array $data, array $extraWhitelist = []): array
{ {
// 兼容传类名或实例
$m = \is_string($model) ? new $model : $model; $m = \is_string($model) ? new $model : $model;
// 1) 优先使用 fillable
$keys = $m->getFillable(); $keys = $m->getFillable();
// 2) 若没配置 fillable(常见:用 guarded),回退到完整表字段,避免误伤
if (empty($keys)) { if (empty($keys)) {
$keys = $m->getConnection() $keys = $m->getConnection()
->getSchemaBuilder() ->getSchemaBuilder()
->getColumnListing($m->getTable()); ->getColumnListing($m->getTable());
} }
// 3) 允许额外白名单(如虚拟字段、JSON映射字段)
if ($extraWhitelist) { if ($extraWhitelist) {
$keys = array_merge($keys, $extraWhitelist); $keys = array_merge($keys, $extraWhitelist);
} }
@@ -413,11 +405,13 @@ class StockOrdersService
// 过滤掉非库字段 // 过滤掉非库字段
$dbData = $this->onlyFillableData($config['model'], $data); $dbData = $this->onlyFillableData($config['model'], $data);
// 更新主表 // 更新主表
$updated = $this->logicUpdateBy($config, $dbData); $this->logicUpdateBy($config, $dbData);
// 获取更新后的数据 // 获取更新后的数据
$order = $this->logicShow($config); $order = $this->logicShow($config);
// 处理车辆和账户信息 // 处理车辆和账户信息
$this->processOrderItems($order, $data, true); $this->processOrderItems($order, $data, true);
// 添加金额
$order->addMoney('cif_total', $data['cif_total']['currency'], $data['cif_total']['amount'], $data['cif_total']['rate'], '合计到岸价');
// 处理文件附件 // 处理文件附件
$this->processOrderFiles($order, $data, true); $this->processOrderFiles($order, $data, true);
return $this->postProcess('Update', $order); return $this->postProcess('Update', $order);
@@ -436,10 +430,8 @@ class StockOrdersService
if ($isUpdate) { if ($isUpdate) {
$this->clearExistingOrderItems($order->id); $this->clearExistingOrderItems($order->id);
} }
// 处理车辆项 // 处理车辆项
$this->processVehicleItems($order, $data['veh_list'] ?? []); $this->processVehicleItems($order, $data['veh_list'] ?? []);
// 处理账户项 // 处理账户项
$this->processAccountItems($order, $data['account_list'] ?? []); $this->processAccountItems($order, $data['account_list'] ?? []);
} }
@@ -552,7 +544,6 @@ class StockOrdersService
$this->processVehiclePrices($item, $veh); $this->processVehiclePrices($item, $veh);
// 累计到岸价 // 累计到岸价
// $cifTotalAmount += $veh['total_price']['amount'] ?? 0;
$profitCurrency === '' ? $profitCurrency = $veh['profit']['currency'] ?? '' : ''; $profitCurrency === '' ? $profitCurrency = $veh['profit']['currency'] ?? '' : '';
$profitRate === 0 ? $profitRate = $veh['profit']['rate'] ?? 0 : ''; $profitRate === 0 ? $profitRate = $veh['profit']['rate'] ?? 0 : '';
$profitTotalAmount += $veh['profit']['amount'] ?? 0; $profitTotalAmount += $veh['profit']['amount'] ?? 0;
@@ -572,7 +563,6 @@ class StockOrdersService
$keysToRemove = ['vin', 'remark', 'modify_list', 'order_id']; $keysToRemove = ['vin', 'remark', 'modify_list', 'order_id'];
$array = array_diff_key($veh, array_flip($keysToRemove)); $array = array_diff_key($veh, array_flip($keysToRemove));
$uniqueIdStr = json_encode($array); $uniqueIdStr = json_encode($array);
return md5($uniqueIdStr); return md5($uniqueIdStr);
} }
@@ -600,6 +590,7 @@ class StockOrdersService
// retention_price 留款/挂账 // retention_price 留款/挂账
// car_price 车价 // car_price 车价
// accessory_price 配件费 // accessory_price 配件费
// increase_price 加价
// 基础费用 // 基础费用
$priceFields = [ $priceFields = [
@@ -617,7 +608,8 @@ class StockOrdersService
'profit' => '利润', 'profit' => '利润',
'retention_price' => '挂账', 'retention_price' => '挂账',
'car_price' => '车价', 'car_price' => '车价',
'accessory_price' => '配件费' 'accessory_price' => '配件费',
'increase_price' => '加价'
]; ];
foreach ($priceFields as $field => $description) { foreach ($priceFields as $field => $description) {
@@ -771,12 +763,10 @@ class StockOrdersService
{ {
$vehList = []; $vehList = [];
$index = 0; $index = 0;
$currencyInfo = $this->getCurrencyInfo($item->settlement_currency);
foreach ($item->items as $v) { foreach ($item->items as $v) {
// 如果已存在相同车辆,增加数量 // 如果已存在相同车辆,增加数量
if (isset($vehList[$v->unique_id])) { if (isset($vehList[$v->unique_id])) {
$this->incrementVehicleCount($vehList[$v->unique_id], $currencyInfo); $this->incrementVehicleCount($vehList[$v->unique_id]);
// 拼接 remark 值 // 拼接 remark 值
if (!empty($v->remark)) { if (!empty($v->remark)) {
if (!empty($vehList[$v->unique_id]['remark'])) { if (!empty($vehList[$v->unique_id]['remark'])) {
@@ -787,17 +777,9 @@ class StockOrdersService
} }
continue; continue;
} }
$index++; $index++;
// 处理金额信息 // 处理金额信息
$moneyValues = $this->processItemMoneyValues($v); $moneyValues = $this->processItemMoneyValues($v);
// 处理改装信息
// $modificationText = $this->getModificationText($v->options);
// 利润
// $itemProfit = empty($moneyValues['profit']['amount']) ? 0 : $moneyValues['profit']['amount'];
// 构建车辆信息 // 构建车辆信息
$vehList[$v->unique_id] = [ $vehList[$v->unique_id] = [
'index' => $index, 'index' => $index,
@@ -805,19 +787,10 @@ class StockOrdersService
'color_interior_snapshot' => $v->color_interior_snapshot, 'color_interior_snapshot' => $v->color_interior_snapshot,
'color_exterior_snapshot' => $v->color_exterior_snapshot, 'color_exterior_snapshot' => $v->color_exterior_snapshot,
'num' => 1, 'num' => 1,
// 'modify' => $modificationText,
'mileage' => $v->mileage, 'mileage' => $v->mileage,
'remark' => $v->remark, 'remark' => $v->remark,
] + $moneyValues; ] + $moneyValues;
// var_dump($vehList[$v->unique_id]);
// 添加利润信息
// $vehList[$v->unique_id]['profit'] = [
// 'currency' => $item->settlement_currency,
// 'amount' => $itemProfit,
// 'currency_info' => $currencyInfo['currency_symbol'] . number_format($itemProfit, 2, '.', ',')
// ];
} }
return ['list' => $vehList]; return ['list' => $vehList];
} }
@@ -853,23 +826,9 @@ class StockOrdersService
/** /**
* 增加车辆数量并更新相关金额显示 * 增加车辆数量并更新相关金额显示
*/ */
private function incrementVehicleCount(array &$vehicleData, array $currencyInfo): void private function incrementVehicleCount(array &$vehicleData): void
{ {
$vehicleData['num'] += 1; $vehicleData['num'] += 1;
// // 更新总价显示
// if (isset($vehicleData['total_price']['amount'])) {
// $totalAmount = $vehicleData['total_price']['amount'] * $vehicleData['num'];
// $vehicleData['total_price']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($totalAmount, 2, '.', ',');
// }
// // 更新利润显示
// if (isset($vehicleData['profit']['amount'])) {
// $profitAmount = $vehicleData['profit']['amount'] * $vehicleData['num'];
// $vehicleData['profit']['currency_info'] = $currencyInfo['currency_symbol'] . number_format($profitAmount, 2, '.', ',');
// }
// var_dump($vehicleData);
$fieldList = [ $fieldList = [
'fob_transport_fee', 'fob_transport_fee',