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