| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\controllers;
- use app\models\IntelligentMatchCat;
- use app\models\IntelligentScene;
- use app\modules\admin\models\IntelligentGoodsForm;
- use app\modules\admin\models\IntelligentMatchForm;
- use app\modules\admin\models\IntelligentSceneForm;
- class IntelligentMatchController extends BaseController
- {
- /**
- * 保存分类
- * @return \yii\web\Response
- */
- public function actionCatSave()
- {
- $data = post_params();
- $form = new IntelligentMatchForm();
- $cat = $data['id'] ? (IntelligentMatchCat::findOne($data['id']) ?: new IntelligentMatchCat()) : new IntelligentMatchCat();
- $form->model = $cat;
- $form->attributes = $data;
- $form->store_id = get_store_id();
- return $this->asJson($form->save());
- }
- /**
- * 获取分类列表
- * @return \yii\web\Response
- */
- public function actionCatList()
- {
- $is_show = get_params('is_show',IntelligentMatchCat::IS_SHOW_TRUE);
- $list = IntelligentMatchCat::getCatList(get_store_id(), $is_show);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'list' => $list
- ]
- ]);
- }
- /**
- * 批量修改分类状态
- * @return \yii\web\Response
- */
- public function actionCatStatus()
- {
- $status = get_params('status',1);
- $attributes = $status == 0 || $status == 1 ? ['is_show' => $status] : ['is_delete' => 1];
- $res = IntelligentMatchCat::updateAll($attributes, ['id' => get_params('id',[])]);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'updateCount' => $res
- ]
- ]);
- }
- /**
- * 批量修改分类状态
- * @return \yii\web\Response
- */
- public function actionCatChange()
- {
- $id = get_params('id');
- $parent_id = get_params('parent_id');
- $res = IntelligentMatchCat::updateAll(['parent_id' => $parent_id], ['id' => $id]);
- return $this->asJson([
- 'code' => 0,
- 'data' => [
- 'updateCount' => $res
- ]
- ]);
- }
- /**
- * 删除分类
- * @return \yii\web\Response
- */
- public function actionCatDel()
- {
- $cat = IntelligentMatchCat::findOne(get_params('id'));
- if (empty($cat)) {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '查无此分类'
- ]);
- }
- $cat->is_delete = 1;
- if ($cat->save()) {
- return $this->asJson([
- 'code' => 0,
- 'msg' => '删除成功'
- ]);
- }else {
- return $this->asJson([
- 'code' => 1,
- 'msg' => '删除失败'
- ]);
- }
- }
- /**
- * 获取场景列表信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 09:36
- */
- public function actionIntelligentScene(){
- $form = new IntelligentSceneForm();
- $form->keyword = get_params('search_key','');
- $form->cat_id = get_params('cat_id',0);
- $result = $form->list();
- return $this->asJson($result);
- }
- /**
- * 获取场景信息
- * @param $id
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 09:47
- */
- /*public function actionIntelligentSceneItem($id = 0){
- if($id > 0){
- $model = IntelligentScene::findOne($id);
- }else{
- $model = new IntelligentScene();
- }
- return $this->asJson($model);
- }*/
- /**
- * 保存场景信息
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 09:47
- */
- public function actionIntelligentSceneSave(){
- $data = post_params();
- $form = new IntelligentSceneForm();
- $form->model = $data['id'] ? (IntelligentScene::findOne($data['id']) ?: new IntelligentScene()) : new IntelligentScene();
- $form->attributes = $data;
- $result = $form->save();
- return $this->asJson($result);
- }
- /**
- * 删除场景
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 09:47
- */
- public function actionIntelligentSceneDel(){
- IntelligentScene::updateAll(['is_delete'=>1],['store_id'=>get_store_id(),'id'=>get_params('id')]);
- return $this->asJson(['code'=>0,'msg'=>'删除成功']);
- }
- /**
- * 修改场景状态
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/28 09:47
- */
- public function actionIntelligentSceneStatus(){
- IntelligentScene::updateAll(['status'=>!get_params('status')],['store_id'=>get_store_id(),'id'=>get_params('id')]);
- return $this->asJson(['code'=>0,'msg'=>'修改成功']);
- }
- /**
- * 设置默认场景
- * @return \yii\web\Response
- * User: hankaige
- * DATE TIME: 2023/1/30 14:07
- */
- public function actionIntelligentSceneDefault(){
- $id = get_params('id');
- $item = IntelligentScene::findOne($id);
- if($item->is_default == 0){
- // 要设置为默认
- IntelligentScene::updateAll(['is_default' => 0],['store_id'=>get_store_id(),'is_default'=>1]);
- }
- $item->is_default = $item->is_default ? 0 : 1;
- if($item->save()){
- return $this->asJson(['code'=>0,'msg'=>'修改成功']);
- }else{
- return $this->asJson(['code'=>1,'msg'=>'修改失败','data'=>$item->getErrors()]);
- }
- }
- /*
- * 获取智配商品的图片
- */
- public function actionIntelligentGoodsList() {
- $form = new IntelligentGoodsForm();
- $form->attributes = get_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->list());
- }
- /*
- * 保存智配商品的图片
- */
- public function actionIntelligentGoodsSave() {
- $form = new IntelligentGoodsForm();
- $form->attributes = post_params();
- $form->store_id = get_store_id();
- return $this->asJson($form->save());
- }
- }
|