request->isAjax) { $keyword = Yii::$app->request->get('keyword',''); $where = [['mall_id' => $this->mall['id'],'parent_id' => 0,'status' => [StatusEnum::ENABLED,StatusEnum::DISABLED]]]; $keyword && $where[] = ['like','name',$keyword.'%',false]; $order = 'sort asc,created_at desc'; $with = ['child','child.child']; $params = compact('where','order','with'); $list = PurchaseCate::lists($params); if($list === false) return $this->error(PurchaseCate::getStaticError()); return $this->success('ok',compact('list')); } return $this->render($this->action->id); } /** * 商品分类排序 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionSortEdit(){ if (Yii::$app->request->isAjax) { $post = Yii::$app->request->post(); $res = PurchaseCate::sort($post); if($res === false) return $this->error(PurchaseCate::getStaticError()); return $this->success(); } } /** * 商品样式设置 * @Author bing * @DateTime 2021-08-23 09:55:11 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionStyle(){ if (Yii::$app->request->isAjax) { $default = [ 'cat_style' => 3, 'recommend_count' => 3, 'cat_goods_count' => 1, 'cat_goods_cols' => 1 ]; if(Yii::$app->request->isGet){ Yii::$app->services->setting->mall->get(); $cate_setting = Yii::$app->services->setting->mall->get($this->mall_id,'cate_setting',null,true); $setting = array_merge($default,$cate_setting); $this->success('ok',compact('setting')); }else{ $post = Yii::$app->request->post(); $res = Yii::$app->services->validate->validate($post,[ [['cat_style'], 'required'], [['recommend_count','cat_goods_count','cat_goods_cols'], 'integer'], ]); if($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $cate_setting = array_merge($default,$post); $res = Yii::$app->services->setting->mall->set($this->mall_id,compact('cate_setting')); $this->success('保存成功'); } } } /** * 商品分类 * @Author bing * @DateTime 2021-08-20 14:49:55 * @copyright: Copyright (c) 2020 广东七件事集团 * @return void */ public function actionEdit(){ if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { // 数据获取 $get = Yii::$app->request->get(); $res = Yii::$app->services->validate->validate($get, [[['id'], 'integer'],[['keyword'], 'string']]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $detail = []; // 传了id参数并且无分类搜索则获取分类详细信息 if(isset($get['id']) && empty($get['keyword'])){ $detail = PurchaseCate::getOne([['id' => $get['id'], 'mall_id' => $this->mall_id]], true,['parent.parent']); if(empty($detail)) return $this->error('不存在此分类'); $detail['parents'] = []; if(isset($detail['parent'])) $detail['parents'][] = $detail['parent']; if(isset($detail['parent']['parent'])) $detail['parents'][] = $detail['parent']['parent']; } $cond = [['mall_id' => $this->mall_id]]; isset($get['keyword']) && $cond[] = ['like', 'name', $get['keyword'] . '%', false]; $cates = PurchaseCate::getCates($cond,[],true,'id,name,parent_id'); $cates = PurchaseCate::getTreeCate($cates); return $this->success('操作成功',compact('detail','cates')); } else { // 编辑分类 $form = Yii::$app->request->post('form'); $res = Yii::$app->services->validate->validate($form, [ [['id'], 'integer'], [['name','sort','pic','big_pic_url','advert_pic','advert_url','parent_id','status','is_show','advert_open_type','advert_params'],'safe'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $form['parent_id'] = empty($form['parent_id']) ? 0 : $form['parent_id']; $form['mall_id'] = $this->mall['id']; unset($form['advert_params']); $res = PurchaseCate::setData($form); if ($res === false) return $this->error(PurchaseCate::getStaticError()); return $this->success('操作成功'); } } return $this->render($this->action->id); } public function actionTree(){ if (Yii::$app->request->isAjax) { if (Yii::$app->request->isGet) { $cond = [['mall_id' => $this->mall_id]]; $list = PurchaseCate::getCates($cond,[],true,'id,name,parent_id'); $list = PurchaseCate::getTreeCate($list); return $this->success('操作成功',compact('list')); } } } /** * @desc:删除商品分类 * @Author: hua * @Date: 2021/11/4 * @Time: 14:20 * @Copyright: copyright (c) 2021 广东七件事集团 * @return mixed|void */ public function actionDelete(){ $params = Yii::$app->request->post(); $params['status'] = StatusEnum::DELETE; $params['mall_id'] = $this->mall_id; $res = Yii::$app->services->validate->validate($form, [ [['id'], 'integer'], ]); if ($res === false) return $this->error(Yii::$app->services->validate->getErrorMessage()); $res = PurchaseGoodsCateRelate::findOne(['cate_id'=>$params['id']]); // if (!empty($res)) return $this->error('该分类关联了商品,不能删除!'); $res = PurchaseCate::setData($params); if ($res === false) return $this->error('删除失败!'); return $this->success('操作成功',[]); } }