1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:32
- */
- namespace common\models;
- //use yii\db\ActiveRecord;
- //use yii\behaviors\TimestampBehavior;
- class Developers extends Common
- {
- public function rules()
- {
- return [
- ['name','required','message'=>'不能为空'],
- ['name', 'unique', 'targetClass' => 'common\models\Developers','on'=>['add']],
- ['info','string','max'=>200],
- ['logo','string','max'=>50],
- ['allow','in','range'=>[1,2]],
- ['is_del','in','range'=>[1,2]]
- ];
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function getList($input,$select = null)
- {
- $query = self::find();
- $query->select($select);
- $query = $this->WhereFocus($query);
- if (!empty($input['name'])){
- $query->andWhere(['like','name',$input['name']]);
- }
- if(!empty($input['page']))
- {
- $query->offset = ($input['page'] - 1) * $input['limit'];
- $query->limit = $input['limit'];
- }
- return $query->orderBy(['create_at'=>SORT_DESC])->asArray()->all();
- }
- public function Total($input)
- {
- $query = self::find();
- $query = $this->WhereFocus($query);
- if (!empty($input['name'])){
- $query->andWhere(['like','name',$input['name']]);
- }
- return $query->count();
- }
- public function WhereFocus($query)
- {
- $query->andFilterWhere(['name'=>$this->name]);
- $query->andWhere(['is_del'=>$this->setDel]);
- return $query;
- }
- }
|