TimestampBehavior::className(), // 'attributes' => [ // # 创建之前 // ActiveRecord::EVENT_BEFORE_INSERT => ['create_at', 'update_at'], // # 修改之前 // ActiveRecord::EVENT_BEFORE_UPDATE => ['update_at'] // ], // #设置默认值 // 'value' => $_SERVER['REQUEST_TIME'] // ] // ]; // } public function rules() { return [ ['name','required','message'=>'不能为空'], ['name', 'unique', 'targetClass' => 'common\models\Sysmenu','on'=>['add']], [['pid','sort'],'number'], ['sort','default','value'=>0], ['url','string','min'=>1], ['path','string','max'=>100], ['icon','string','max'=>50], ['status','in', 'range' => [1, 2, 3]], ]; } public function Authenticator($input) { $this->load($input,''); if(!$this->validate()) return $this->errors; return $this; } public function FindById() { return self::findOne($this->id); } public function OneFind() { $query = self::find(); $query = $this->ManyWhere($query); return $query->one(); } public function MultipleConditionQuery($select = null) { $query = self::find()->select($select); $query = $this->ManyWhere($query); return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all(); } private function ManyWhere($query) { $query->andFilterWhere(['pid'=>$this->pid]); $query->andFilterWhere(['id'=>$this->id]); $query->andFilterWhere(['status'=>$this->status]); // $query->andFilterWhere(['del'=>$this->setDel]); return $query; } public function getList($data) { $query = self::find(); $query->andFilterWhere(['status'=>$this->status]); $count = $query->count(); $query->select(['id','name','icon','url','pid',"CONCAT(path,id,',') as paths",'status','sort']); $query->orderBy('paths,create_at'); if(!empty($data['page'])) { $query->offset = ($data['page'] - 1) * $data['limit']; $query->limit = $data['limit']; } $arr['count'] = $count; $arr['data'] = $query->asArray()->all();; return $arr; } public function PidList($id = 0) { $query = self::find(); $query->select(['name as title','id as value','pid','id']); $query->andWhere(['status'=>$this->setDel]); $query->andFilterWhere(['pid'=>$id]); return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all(); } }