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)); } }