diff --git a/vendor/antgoods/goods/src/controllers/AttributeController.php b/vendor/antgoods/goods/src/controllers/AttributeController.php index 27216a7..719fea2 100644 --- a/vendor/antgoods/goods/src/controllers/AttributeController.php +++ b/vendor/antgoods/goods/src/controllers/AttributeController.php @@ -69,8 +69,16 @@ class AttributeController extends Controller $model->sort_order = 0; $model->cat_id = 0; - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect('index'); + if ($model->load(Yii::$app->request->post())) { + $model->value = str_replace(',', ',', $model->value); + $array = explode(',', $model->value); + if (count($array) != count(array_unique($array))) { + \Yii::$app->getSession()->setFlash('error', '不能有相同的属性值'); + return $this->render('create', ['model' => $model]); + } + if ($model->save()) { + return $this->redirect(['index']); + } } return $this->render('create', [ @@ -89,7 +97,16 @@ class AttributeController extends Controller { $model = $this->findModel($id); - if ($model->load(Yii::$app->request->post()) && $model->save()) { + if ($model->load(Yii::$app->request->post())) { + $model->value = str_replace(',', ',', $model->value); + $array = explode(',', $model->value); + if (count($array) != count(array_unique($array))) { + \Yii::$app->getSession()->setFlash('error', '不能有相同的属性值'); + return $this->render('create', ['model' => $model]); + } + if ($model->save()) { + return $this->redirect(['index']); + } return $this->redirect('index'); } diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index aef9c16..dba1178 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -135,11 +135,13 @@ class GoodsController extends Controller $attributeModel = GoodsManager::getAttribute($id); $checkAttr = GoodsManager::getSkuInfo($id); $filterAttributeModel = GoodsManager::getFilterAttribute($id); + $judgeGoodsCategory = GoodsManager::judgeGoodsCategory($model); return $this->render('update', [ 'model' => $model, 'attributeModel' => $attributeModel, 'attrValue' => $checkAttr, 'filterAttributeModel' => $filterAttributeModel, + 'judgeGoodsCategory' => $judgeGoodsCategory, ]); } diff --git a/vendor/antgoods/goods/src/controllers/ShopCategoryController.php b/vendor/antgoods/goods/src/controllers/ShopCategoryController.php index e42d37e..cae33a1 100644 --- a/vendor/antgoods/goods/src/controllers/ShopCategoryController.php +++ b/vendor/antgoods/goods/src/controllers/ShopCategoryController.php @@ -80,6 +80,7 @@ class ShopCategoryController extends Controller { $model = new ShopCategory(); $model->is_show = ShopCategory::IS_SHOW_HIDE; + $model->sort_order = 0; if ($model->load(Yii::$app->request->post())) { if ($model->filter_attr != null && is_array($model->filter_attr)) { diff --git a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php index e1f8f6e..bcd3344 100644 --- a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php +++ b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php @@ -549,4 +549,24 @@ class GoodsManager } return $goodsFilterAttributeModel; } + + /** + * @param $goodsModel + * @return bool + * + */ + public static function judgeGoodsCategory($goodsModel) + { + $skus = GoodsSku::find()->where(['goods_id' => $goodsModel->id, 'is_delete' => GoodsSku::IS_DELETE_NO])->all(); + $attrId = []; + foreach ($skus as $sku) { + $attrId = array_merge(explode(',', $sku->goods_attr), $attrId); + } + $goodsAttr = array_unique(GoodsAttr::find()->select(['attr_id'])->where(['id' => $attrId, 'is_delete' => GoodsAttr::IS_DELETE_NO])->andWhere(['!=', 'attr_id', 0])->column()); + $attrArr = array_unique(Attribute::find()->select(['cat_id'])->where(['is_delete' => Attribute::IS_DELETE_NO, 'id' => $goodsAttr])->column()); + if (in_array($goodsModel->cat_id, $attrArr)) { + return true; //存在,则返回true,表示后台分类不得修改 + } + return false; //否则返回false,表示后台分类可以修改 + } } \ No newline at end of file diff --git a/vendor/antgoods/goods/src/views/goods/create.php b/vendor/antgoods/goods/src/views/goods/create.php index 0c58e77..608d117 100644 --- a/vendor/antgoods/goods/src/views/goods/create.php +++ b/vendor/antgoods/goods/src/views/goods/create.php @@ -24,7 +24,8 @@ Yii::$app->params['bsVersion'] = '4.x'; [ 'label' => ' 基本信息', 'content' => $this->render('goods', ['model' => $model, - 'form' => $form + 'form' => $form, + 'judgeGoodsCategory' => false, //表示后台分类可以修改 ]), ], [ diff --git a/vendor/antgoods/goods/src/views/goods/goods.php b/vendor/antgoods/goods/src/views/goods/goods.php index 6446f87..4a253b5 100644 --- a/vendor/antgoods/goods/src/views/goods/goods.php +++ b/vendor/antgoods/goods/src/views/goods/goods.php @@ -10,7 +10,7 @@ use linyao\widgets\Select2; /* @var $model antgoods\goods\models\ars\Goods */ /* @var $form yii\widgets\ActiveForm */ ?> -field($model, 'cat_id')->dropDownList(Category::modelColumn(), ['prompt' => '请选择']) ?> +field($model, 'cat_id')->dropDownList(Category::modelColumn(), ['prompt' => '请选择', 'disabled' => $judgeGoodsCategory]) ?> field($model, 'brand_id')->dropDownList(Brand::modelColumn(), ['prompt' => '请选择']) ?> diff --git a/vendor/antgoods/goods/src/views/goods/update.php b/vendor/antgoods/goods/src/views/goods/update.php index 6ecb99c..264780b 100644 --- a/vendor/antgoods/goods/src/views/goods/update.php +++ b/vendor/antgoods/goods/src/views/goods/update.php @@ -25,7 +25,8 @@ Yii::$app->params['bsVersion'] = '4.x'; 'label' => ' 基本信息', 'content' => $this->render('goods', [ 'model' => $model, - 'form' => $form + 'form' => $form, + 'judgeGoodsCategory' => $judgeGoodsCategory ]), ], [