From 0ce5c98e4bdfe8b54c217b8c1bd4dadcc85eb9d1 Mon Sep 17 00:00:00 2001 From: fengxinyhyl Date: Tue, 23 Apr 2024 11:18:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=95=86=E5=93=81=E7=BC=96?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/admin/store/StoreProduct.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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('编辑成功'); }