diff --git a/app/api/controller/StoreKeeper.php b/app/api/controller/StoreKeeper.php index 6ff987ac..34a30951 100644 --- a/app/api/controller/StoreKeeper.php +++ b/app/api/controller/StoreKeeper.php @@ -524,5 +524,14 @@ class StoreKeeper extends Controller return $this->renderSuccess('添加成功'); } + public function editPrice(): Json + { + $model = new GoodsPriceModel; + if (!$model->edit($this->request->param())) { + return $this->renderError($model->getError() ?: '添加失败'); + } + return $this->renderSuccess('添加成功'); + } + } \ No newline at end of file diff --git a/app/store/model/goods/GoodsPrice.php b/app/store/model/goods/GoodsPrice.php index 3dfabca6..1e0a16d2 100644 --- a/app/store/model/goods/GoodsPrice.php +++ b/app/store/model/goods/GoodsPrice.php @@ -77,8 +77,13 @@ class GoodsPrice extends GoodsPriceModel //校验是否有冲突的区间 $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->select(); if (!empty($catList)) { + foreach ($catList as $k => $v) { - if ($v->max_price <= $data['min_price'] || $v->min_price >= $data['max_price']) { + if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price ) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + if ( $data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price ) { $this->error = "该分类价格区间冲突,请重新设置价格"; return false; } @@ -95,6 +100,24 @@ class GoodsPrice extends GoodsPriceModel */ public function edit(array $data): bool { + if (empty($data['type']) || empty($data['max_price']) || empty($data['cat_id']) || empty($data['markup_rate']) || empty($data['id'])) { + $this->error = "请补全信息"; + return false; + } + //校验是否有冲突的区间 + $catList = $this->where(['cat_id' => $data['cat_id'], 'type' => $data['type']])->where('id','<>',$data['id'])->select(); + if (!empty($catList)) { + foreach ($catList as $k => $v) { + if ($data['min_price'] >= $v->min_price && $data['min_price'] <= $v->max_price ) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + if ( $data['max_price'] <= $v->max_price && $data['max_price'] >= $v->min_price ) { + $this->error = "该分类价格区间冲突,请重新设置价格"; + return false; + } + } + } return $this->save($data) !== false; }