| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * 重庆赤晓店信息科技有限公司
- * https://www.chixiaodian.com
- * Copyright (c) 2023 赤店商城 All rights reserved.
- */
- namespace app\modules\admin\models;
- use app\models\IntelligentMatchCat;
- use app\models\IntelligentScene;
- use yii\base\Model;
- class IntelligentSceneForm extends Model
- {
- public $store_id = 1;
- public $name;
- public $pic_url;
- public $status;
- public $model;
- public $keyword = '';
- public $cat_id = 0;
- /**
- * @return array
- */
- public function rules()
- {
- return [
- [[ 'store_id', 'sort'], 'integer'],
- [['name','pic_url','keyword'], 'string', 'max' => 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' => '保存失败'
- ];
- }
- }
- }
|