255], [['status'], 'default', 'value' => 1], [['is_delete','cat_id'], 'default', 'value' => 0] ]; } public function list(){ $query = IntelligentScene::find()->where(['store_id'=>get_store_id(),'is_delete'=>0]); if($this->keyword){ $query->andWhere(['like','name',$this->keyword]); } if($this->cat_id > 0){ $query->andWhere(['cat_id'=>$this->cat_id]); } $data = pagination_make($query); foreach($data['list'] as &$item){ $item['cat_id_arr'] = $this->getCat($item['cat_id']); } return [ 'code' => 0, 'msg' => 'success', 'data' => [ 'data' => $data['list'], 'pageNo' => $data['pageNo'], 'totalCount' => $data['totalCount'] ] ]; } private function getCat($catId){ $item = IntelligentMatchCat::findOne($catId); if($item['parent_id'] == 0){ return [(string)$item['id']]; } $item2 = IntelligentMatchCat::findOne($item['parent_id']); if($item2['parent_id'] == 0){ return [(string)$item2['id'],(string)$item['id']]; } $item3 = IntelligentMatchCat::findOne($item2['parent_id']); return [(string)$item3['id'],(string)$item2['id'],(string)$item['id']]; } /** * 保存场景 * @return array */ public function save() { $this->model->status = $this->status; $this->model->name = $this->name; $this->model->pic_url = $this->pic_url; $this->model->store_id = get_store_id(); $this->model->cat_id = $this->cat_id; if ($this->model->save()) { return [ 'code' => 0, 'msg' => '提交成功' ]; } else { return [ 'code' => 0, 'msg' => '保存失败' ]; } } }