Browse Source

开发判断商品表单中后台分类是否可以修改方法,修改相关商品表单逻辑

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
e3d8e70faf
  1. 23
      vendor/antgoods/goods/src/controllers/AttributeController.php
  2. 2
      vendor/antgoods/goods/src/controllers/GoodsController.php
  3. 1
      vendor/antgoods/goods/src/controllers/ShopCategoryController.php
  4. 20
      vendor/antgoods/goods/src/logic/goods/GoodsManager.php
  5. 3
      vendor/antgoods/goods/src/views/goods/create.php
  6. 2
      vendor/antgoods/goods/src/views/goods/goods.php
  7. 3
      vendor/antgoods/goods/src/views/goods/update.php

23
vendor/antgoods/goods/src/controllers/AttributeController.php

@ -69,8 +69,16 @@ class AttributeController extends Controller
$model->sort_order = 0; $model->sort_order = 0;
$model->cat_id = 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', [ return $this->render('create', [
@ -89,7 +97,16 @@ class AttributeController extends Controller
{ {
$model = $this->findModel($id); $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'); return $this->redirect('index');
} }

2
vendor/antgoods/goods/src/controllers/GoodsController.php

@ -135,11 +135,13 @@ class GoodsController extends Controller
$attributeModel = GoodsManager::getAttribute($id); $attributeModel = GoodsManager::getAttribute($id);
$checkAttr = GoodsManager::getSkuInfo($id); $checkAttr = GoodsManager::getSkuInfo($id);
$filterAttributeModel = GoodsManager::getFilterAttribute($id); $filterAttributeModel = GoodsManager::getFilterAttribute($id);
$judgeGoodsCategory = GoodsManager::judgeGoodsCategory($model);
return $this->render('update', [ return $this->render('update', [
'model' => $model, 'model' => $model,
'attributeModel' => $attributeModel, 'attributeModel' => $attributeModel,
'attrValue' => $checkAttr, 'attrValue' => $checkAttr,
'filterAttributeModel' => $filterAttributeModel, 'filterAttributeModel' => $filterAttributeModel,
'judgeGoodsCategory' => $judgeGoodsCategory,
]); ]);
} }

1
vendor/antgoods/goods/src/controllers/ShopCategoryController.php

@ -80,6 +80,7 @@ class ShopCategoryController extends Controller
{ {
$model = new ShopCategory(); $model = new ShopCategory();
$model->is_show = ShopCategory::IS_SHOW_HIDE; $model->is_show = ShopCategory::IS_SHOW_HIDE;
$model->sort_order = 0;
if ($model->load(Yii::$app->request->post())) { if ($model->load(Yii::$app->request->post())) {
if ($model->filter_attr != null && is_array($model->filter_attr)) { if ($model->filter_attr != null && is_array($model->filter_attr)) {

20
vendor/antgoods/goods/src/logic/goods/GoodsManager.php

@ -549,4 +549,24 @@ class GoodsManager
} }
return $goodsFilterAttributeModel; 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,表示后台分类可以修改
}
} }

3
vendor/antgoods/goods/src/views/goods/create.php

@ -24,7 +24,8 @@ Yii::$app->params['bsVersion'] = '4.x';
[ [
'label' => '<i class="fas fa-user"></i> 基本信息', 'label' => '<i class="fas fa-user"></i> 基本信息',
'content' => $this->render('goods', ['model' => $model, 'content' => $this->render('goods', ['model' => $model,
'form' => $form
'form' => $form,
'judgeGoodsCategory' => false, //表示后台分类可以修改
]), ]),
], ],
[ [

2
vendor/antgoods/goods/src/views/goods/goods.php

@ -10,7 +10,7 @@ use linyao\widgets\Select2;
/* @var $model antgoods\goods\models\ars\Goods */ /* @var $model antgoods\goods\models\ars\Goods */
/* @var $form yii\widgets\ActiveForm */ /* @var $form yii\widgets\ActiveForm */
?> ?>
<?= $form->field($model, 'cat_id')->dropDownList(Category::modelColumn(), ['prompt' => '请选择']) ?>
<?= $form->field($model, 'cat_id')->dropDownList(Category::modelColumn(), ['prompt' => '请选择', 'disabled' => $judgeGoodsCategory]) ?>
<?= $form->field($model, 'brand_id')->dropDownList(Brand::modelColumn(), ['prompt' => '请选择']) ?> <?= $form->field($model, 'brand_id')->dropDownList(Brand::modelColumn(), ['prompt' => '请选择']) ?>

3
vendor/antgoods/goods/src/views/goods/update.php

@ -25,7 +25,8 @@ Yii::$app->params['bsVersion'] = '4.x';
'label' => '<i class="fas fa-user"></i> 基本信息', 'label' => '<i class="fas fa-user"></i> 基本信息',
'content' => $this->render('goods', [ 'content' => $this->render('goods', [
'model' => $model, 'model' => $model,
'form' => $form
'form' => $form,
'judgeGoodsCategory' => $judgeGoodsCategory
]), ]),
], ],
[ [

Loading…
Cancel
Save