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

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

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

Loading…
Cancel
Save