feat: 备货单车辆明细支持 attachment 附件字段

按前端对接文档,stock_order_items 每辆车支持附件 [{url,original_name}]:
- 模型 StockOrderItems:fillable 增加 attachment,新增 $casts=['attachment'=>'array']
  (写自动 json_encode 落库、读自动 decode 回显)
- processVehicleItems:create 前归一化 attachment 为数组(store/update 共用此路径)
- generateVehicleUniqueId:排除 attachment,避免附件影响车辆去重/数量

show/detail 经模型 items 关系 + cast 自动回显 attachment;字段已由前端在库表就绪。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
mzl
2026-08-06 15:01:03 +08:00
parent 6e2e8e1cc6
commit 06b0647fc4
2 changed files with 11 additions and 2 deletions
+8 -1
View File
@@ -45,7 +45,14 @@ class StockOrderItems extends Model
'id', 'order_id', 'product_code', 'sku_id', 'sku_snapshot', 'id', 'order_id', 'product_code', 'sku_id', 'sku_snapshot',
'model_snapshot', 'quantity', 'color_interior_code', 'color_interior_snapshot', 'model_snapshot', 'quantity', 'color_interior_code', 'color_interior_snapshot',
'color_exterior_code', 'color_exterior_snapshot', 'remark', 'vin', 'created_at', 'updated_at', 'color_exterior_code', 'color_exterior_snapshot', 'remark', 'vin', 'created_at', 'updated_at',
'mileage', 'unique_id' 'mileage', 'unique_id', 'attachment'
];
/**
* 字段类型转换:attachment 以 JSON 数组存取(写自动 json_encode、读自动 decode)
*/
protected $casts = [
'attachment' => 'array',
]; ];
/** /**
+3 -1
View File
@@ -644,6 +644,8 @@ class StockOrdersService
foreach ($vehList as $veh) { foreach ($vehList as $veh) {
$veh['order_id'] = $order->id; $veh['order_id'] = $order->id;
$veh['unique_id'] = $this->generateVehicleUniqueId($veh); $veh['unique_id'] = $this->generateVehicleUniqueId($veh);
// 车辆附件:归一化数组(由模型 attachment=>'array' cast 自动序列化为 JSON 落库)
$veh['attachment'] = is_array($veh['attachment'] ?? null) ? array_values($veh['attachment']) : [];
$item = StockOrderItems::create($veh); $item = StockOrderItems::create($veh);
@@ -667,7 +669,7 @@ class StockOrdersService
*/ */
private function generateVehicleUniqueId(array $veh): string private function generateVehicleUniqueId(array $veh): string
{ {
$keysToRemove = ['remark', 'modify_list', 'order_id']; $keysToRemove = ['remark', 'modify_list', 'order_id', 'attachment'];
$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);