pull/1/head
limu 1 year ago
parent f994e3a56c
commit 799eb79db0
  1. 9
      app/api/controller/StoreKeeper.php
  2. 25
      app/store/model/goods/GoodsPrice.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('添加成功');
}
}

@ -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;
}

Loading…
Cancel
Save