优化商品编辑

main
fengxinyhyl 7 months ago
parent e34116ce95
commit 0ce5c98e4b
  1. 9
      app/controller/admin/store/StoreProduct.php

@ -165,16 +165,23 @@ class StoreProduct extends BaseController
public function update($id, validate $validate)
{
$data = $this->checkParams($validate);
$this->repository->adminUpdate($id, $data);
$productAttrRepository = \app(ProductAttrValueRepository::class);
$attrValue = Request::post('attrValue');
if($attrValue){
foreach ($attrValue as $item){
if($item['price'] < $item['cost'])
return app('json')->fail("成本不能高于价格");
$productAttrRepository->update($item['value_id'], array('price' => $item['price'],'cost' => $item['cost']));
}
$data['price'] = min(array_column($attrValue, 'price'));
$data['cost'] = max(array_column($attrValue, 'cost'));
}
$this->repository->adminUpdate($id, $data);
return app('json')->success('编辑成功');
}

Loading…
Cancel
Save