| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace api\modules\v1\controllers\goods;
- use api\controllers\OnAuthController;
- use common\enums\StatusEnum;
- use common\models\goods\GoodsCate;
- use Yii;
- /**
- * Class GoodsCateController
- * @package api\modules\goods\controllers
- */
- class GoodsCateController extends OnAuthController
- {
- public $modelClass = '';
- /**
- *
- * 不用进行登录验证的方法
- *
- * 例如: ['index', 'update', 'create', 'view', 'delete']
- * 默认全部需要验证
- *
- * @var array
- */
- protected $authOptional = ['index','child-cate-list', 'child', 'tree'];
- /**
- * 分类列表
- * @return mixed|void
- */
- public function actionIndex()
- {
- $params = \Yii::$app->request->get();
- $params['where'] = [['mall_id'=>$this->mall_id,'parent_id'=>empty($params['cate_id'])?0:$params['cate_id'],'mch_id'=>0,'is_show'=>1,'status'=>StatusEnum::ENABLED]];
- $params['select'] = 'id,name,pic';
- $params['order'] = 'sort asc';
- $cate_list['list'] = GoodsCate::lists($params);
- $cats_third_style = "{\"aLevelBgColor\":\"#fff\",\"bLevelBgColor\":\"#fff\",\"cLevelBgColor\":\"#fff\",\"fontColor\":\"#000\",\"fontSize\":\"14\",\"fontWeight\":\"normal\",\"bFontColor\":\"#000\",\"cFontColor\":\"#000\"}";
- // 类目风格
- $default = [
- 'cat_style' => 1,
- 'recommend_count' => 3,
- 'cat_goods_count' => 1,
- 'cat_goods_cols' => 1,
- 'cats_third_style' => $cats_third_style
- ];
- $cate_setting = Yii::$app->services->setting->mall->get($this->mall_id,'cate_setting',null,true);
- if(is_array($cate_setting)){
- foreach($default as $key => $val){
- if(isset($cate_setting[$key]) && !empty($cate_setting[$key])){
- $default[$key] = $cate_setting[$key];
- }
- }
- }
- is_string($default['cats_third_style']) && $default['cats_third_style'] = json_decode($default['cats_third_style'], true);
- // 处理后面添加的字段
- foreach(json_decode($cats_third_style) as $key => $val){
- if(!isset($default['cats_third_style'][$key])){
- $default['cats_third_style'][$key] = $val;
- }
- }
- $cate_list['config'] = $default;
- return $this->success('操作成功',$cate_list);
- }
- /**
- * 二级分类列表
- * @return mixed|void
- */
- public function actionChildCateList()
- {
- $params = \Yii::$app->request->get();
- $params['where'] = [['mall_id'=>$this->mall_id,'parent_id'=>0,'mch_id'=>0,'is_show'=>1,'status'=>StatusEnum::ENABLED]];
- $params['select'] = 'id,name,pic';
- $params['order'] = 'sort asc';
- $parent_list= GoodsCate::lists($params);
- $list=array_column($parent_list,'id');
- $params['where'] = [['mall_id'=>$this->mall_id,'parent_id'=>$list,'mch_id'=>0,'is_show'=>1,'status'=>StatusEnum::ENABLED]];
- $child_list= GoodsCate::lists($params);
- return $this->success('操作成功',$child_list);
- }
- public function actionChild()
- {
- $params = \Yii::$app->request->get();
- $res = \Yii::$app->services->validate->validate($params, [
- [['pid'], 'required', 'message' => 'pid必传'],
- [['pid'], 'integer']
- ]);
- if ($res === false) return $this->error(\Yii::$app->services->validate->getErrorMessage());
- $params['where'] = [['mall_id'=>$this->mall_id,'parent_id'=> $params['pid'],'mch_id'=>0,'is_show'=>1,'status'=>StatusEnum::ENABLED]];
- $params['select'] = 'id,name,pic';
- $child_list= GoodsCate::lists($params);
- return $this->success('操作成功',$child_list);
- }
- /**
- * @return mixed|null
- */
- public function actionTree()
- {
- $cats = GoodsCate::lists([
- 'where' => [
- ['mall_id' => $this->mall_id],
- ['status' => StatusEnum::ENABLED],
- ['mch_id' => StatusEnum::DISABLED],
- ],
- 'select'=> 'id, parent_id, pic, name'
- ]);
- return $this->success('操作成功', GoodsCate::getTreeCate($cats));
- }
- }
|