fix(admin): 优化商品信息处理逻辑

- 在处理商品信息时,增加了对各个字段的非空判断,只保存不为空的值
- 修改了采购价的处理逻辑,当没有提供采购价时,从 StoreProduct 表中查询最新的采购价
- 保留了原始逻辑中的注释,以便后续参考
This commit is contained in:
mkm 2024-10-30 14:40:51 +08:00
parent 837d9ed548
commit 1333d13fdf

View File

@ -102,14 +102,30 @@ class BeforehandOrderLogic extends BaseLogic
$datas[$k]['bhoid'] = $order['id'];
$data['id']=$v['product_id'];
$data['marques']=$v['marques'];
$data['store_info']=$v['store_info'];
$data['after_sales']=$v['after_sales'];
$data['package']=$v['package'];
$data['loss']=$v['loss'];
$data['gross_weight']=$v['gross_weight'];
$data['net_weight']=$v['net_weight'];
$data['mark']=$v['mark'];
if($v['marques']){
$data['marques']=$v['marques'];
}
if($v['store_info']){
$data['store_info']=$v['store_info'];
}
if($v['after_sales']){
$data['after_sales']=$v['after_sales'];
}
if($v['package']){
$data['package']=$v['package'];
}
if($v['loss']){
$data['loss']=$v['loss'];
}
if($v['gross_weight']){
$data['gross_weight']=$v['gross_weight'];
}
if($v['net_weight']){
$data['net_weight']=$v['net_weight'];
}
if($v['mark']){
$data['mark']=$v['mark'];
}
$product_arr[]=$data;
}
(new StoreProduct())->saveAll($product_arr);
@ -155,7 +171,9 @@ class BeforehandOrderLogic extends BaseLogic
if (isset($v['purchase']) && $v['purchase'] > 0) {
$purchase = $v['purchase'];
} else {
$purchase = $v['price'];
$purchase = StoreProduct::where('id', $v['product_id'])->withTrashed()->value('purchase');
$find['purchase']=$purchase;
// $purchase = $v['price'];
}
$find->save(['price' => $v['price'], 'vip_price' => $v['price'], 'cost' => $v['price'], 'purchase' => $purchase]);
}