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