feat(store_product): 编辑商品信息逻辑优化

This commit is contained in:
mkm 2024-08-26 11:50:28 +08:00
parent bd9a7c5e14
commit f3a502cd3f
2 changed files with 20 additions and 24 deletions

View File

@ -60,6 +60,8 @@ class StoreProductController extends BaseAdminController
public function edit() public function edit()
{ {
$params = (new StoreProductValidate())->post()->goCheck('edit'); $params = (new StoreProductValidate())->post()->goCheck('edit');
d($params);
$result = StoreProductLogic::edit($params); $result = StoreProductLogic::edit($params);
if (true === $result) { if (true === $result) {
return $this->success('编辑成功', [], 1, 1); return $this->success('编辑成功', [], 1, 1);

View File

@ -41,14 +41,14 @@ class StoreProductLogic extends BaseLogic
'store_name' => $params['store_name'], 'store_name' => $params['store_name'],
'image' => $params['image'], 'image' => $params['image'],
'store_info' => $params['store_info'] ?? '', 'store_info' => $params['store_info'] ?? '',
'bar_code' => $params['bar_code'] ?? '', 'bar_code' =>$params['product_arr'][0] ?? '',
'cate_id' => $params['cate_id'], 'cate_id' => $params['cate_id'],
'unit' => $params['unit'], 'unit' => $params['product_arr'][0]['unit'],
'stock' => 0, 'stock' => 0,
'price' => $params['price'], 'price' => $params['product_arr'][0]['price'],
'vip_price' => $params['vip_price'], 'vip_price' => $params['product_arr'][0]['cost'],
'cost' => $params['cost'], 'cost' => $params['product_arr'][0]['cost'],
'purchase' => $params['purchase'], 'purchase' => $params['product_arr'][0]['purchase'],
'rose' => $params['rose'], 'rose' => $params['rose'],
'is_return' => $params['is_return'], 'is_return' => $params['is_return'],
'manufacturer_information' => $params['manufacturer_information'] ?? '', 'manufacturer_information' => $params['manufacturer_information'] ?? '',
@ -56,26 +56,20 @@ class StoreProductLogic extends BaseLogic
'batch' => $params['batch'] ?? 0, 'batch' => $params['batch'] ?? 0,
'store_batch' => $params['store_batch'] ?? 1, 'store_batch' => $params['store_batch'] ?? 1,
'product_type' => $params['product_type'] ?? 0, 'product_type' => $params['product_type'] ?? 0,
'spec_type' => $params['spec_type'] ?? 0,
]; ];
// if ($params['rose'] > 0) {
// $rose_price = bcmul($params['cost'], $params['rose'], 2);
// $data['price'] = bcadd($params['cost'], $rose_price, 2);
// } else {
// $data['price'] = 0;
// }
$res = StoreProduct::create($data); $res = StoreProduct::create($data);
StoreProductAttrValue::create([ $arr=[];
"bar_code" => $params["bar_code"] ?? '', foreach($params['product_arr'] as $k=>$v){
"image" => $params["image"] ?? '', $arr[$k]['sku_name']=$v['sku_name'];
"price" => $params['price'], $arr[$k]['bar_code']=$v['bar_code'];
'vip_price' => $params['vip_price'], $arr[$k]['price']=$v['price'];
"cost" => $params['cost'], $arr[$k]['cost']=$v['cost'];
"purchase" => $params['purchase'], $arr[$k]['purchase']=$v['purchase'];
"unit" => $params["unit"], $arr[$k]['unit']=$v['unit'];
"stock" => 0, $arr[$k]['product_id']=$res['id'];
"product_id" => $res['id'], }
'sales' => 0, (new StoreProductAttrValue())->saveAll($arr);
]);
Db::commit(); Db::commit();
if ($params['is_store_all'] == 1) { if ($params['is_store_all'] == 1) {