Browse Source

refactor:完成商品控制器代码优化重构

antshop
linyaostalker 5 years ago
parent
commit
791ecb987d
  1. 12
      backend/modules/goods/controllers/GoodsController.php
  2. 2
      backend/modules/goods/logic/goods/GoodsManager.php

12
backend/modules/goods/controllers/GoodsController.php

@ -7,6 +7,7 @@ use backend\modules\goods\models\ars\FilterAttr;
use backend\modules\goods\models\ars\GoodsAttr;
use backend\modules\shop\logic\ShopManager;
use Exception;
use Throwable;
use Yii;
use backend\modules\goods\models\ars\Goods;
use backend\modules\goods\models\searchs\GoodsSearch;
@ -16,6 +17,7 @@ use yii\filters\VerbFilter;
use backend\modules\goods\logic\goods\GoodsManager;
use backend\modules\file\models\ars\File;
use backend\modules\goods\models\ars\Attribute;
use iron\widget\Excel;
/**
* GoodsController implements the CRUD actions for Goods model.
@ -196,7 +198,7 @@ class GoodsController extends Controller
} else {
$dataProvider = $searchModel->search($params);
}
\iron\widget\Excel::export([
Excel::export([
'models' => $dataProvider->getModels(),
'format' => 'Xlsx',
'asAttachment' => true,
@ -216,6 +218,7 @@ class GoodsController extends Controller
if ($data['status'] == true) {
return FileManager::saveTemFile($fileName, $data);
}
return false;
}
/**
@ -255,7 +258,7 @@ class GoodsController extends Controller
/**
* @return array
* @throws \Throwable
* @throws Throwable
* 添加sku
*/
public function actionAddSku()
@ -290,7 +293,7 @@ class GoodsController extends Controller
$type = Yii::$app->request->get('type');
$id = Yii::$app->request->get('goodsId');
$data['sku'] = GoodsManager::getCreatedSku($id, $type);
$data['attributes'] = GoodsManager::getAttrs($id, $type);
$data['attributes'] = GoodsManager::getAttrs($id);
return $data;
}
@ -301,8 +304,7 @@ class GoodsController extends Controller
public function actionFilterAttribute()
{
$catId = Yii::$app->request->get('catId')??0;
$goodsId = Yii::$app->request->get('goodsId')??0;
$allAttr = Attribute::find()->where(['type' => Attribute::TYPE_ATTR])->andWhere(['cat_id' => [0,$catId]])->asArray()->all();
$allAttr = Attribute::find()->where(['type' => Attribute::TYPE_ATTR, 'is_delete' => Attribute::IS_DELETE_NO])->andWhere(['cat_id' => [0,$catId]])->asArray()->all();
return json_encode($allAttr);
}
}

2
backend/modules/goods/logic/goods/GoodsManager.php

@ -329,7 +329,7 @@ class GoodsManager
$ret['id'] = $attribute->id;
$ret['attrValue'] = GoodsAttr::find()
->select(['id', 'attr_value'])
->where(['goods_id' => $id])
->where(['goods_id' => $id, 'is_delete' => GoodsAttr::IS_DELETE_NO])
->andWhere(['attr_id' => $attribute->id])
->asArray()
->all();

Loading…
Cancel
Save