diff --git a/app/controller/admin/store/StoreProduct.php b/app/controller/admin/store/StoreProduct.php index 847a9e8..a77fdb4 100755 --- a/app/controller/admin/store/StoreProduct.php +++ b/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('编辑成功'); }