12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace common\models;
- class CategoryAdviser extends Common
- {
- public function rules()
- {
- return [
- [['name','experience'],'required','message'=>'不能为空'],
- ['name', 'unique', 'targetClass' => 'common\models\CategoryAdriser','on'=>['add'],'message'=>'该城市名称已经存在'],
- ['photo','string','max'=>50],
- ['del','default','value'=>1],
- ['del','in','range'=>[1,2]],
- ];
- }
-
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function getList($page,$arr = null)
- {
- $query = self::find();
- $query->select($arr);
- $query = $this->WhereColumn($query);
- if(!empty($page['page']))
- {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- return $query->asArray()->all();
- }
- private function WhereColumn($query)
- {
- $query->andFilterWhere(['name'=>$this->name]);
- $query->andWhere(['del'=>$this->setDel]);
- return $query;
- }
- public function Total()
- {
- $query = self::find();
- $query = $this->WhereColumn($query);
- return $query->count();
- }
- public function GetAdviser()
- {
- $query = self::find();
- $query->select(['id', 'name', 'experience', 'photo']);
- $query->orderBy('RAND()');
- return $query->asArray()->one();
- }
- }
|