123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/3
- * Time: 下午2:24
- */
- namespace common\models;
- //use yii\behaviors\TimestampBehavior;
- //use yii\db\ActiveRecord;
- class SysmenuQ extends Common
- {
- // public $setDel = 1;
- // public function behaviors()
- // {
- // return [
- // [
- // 'class' => 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\SysmenuQ','on'=>['add']],
- ['sort','default','value'=>0],
- ['url','string','max'=>50],
- ['sort','number'],
- ['status','in', 'range' => [1, 2]],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'name'=>'菜单名称',
- 'sort'=>'排序',
- 'url'=>'地址'
- ];
- }
- 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 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(['id'=>$this->id]);
- $query->andFilterWhere(['del'=>$this->setDel]);
- return $query;
- }
- public function getList($data)
- {
- $query = $this->QueryFind();
- $query = $this->ManyWhere($query);
- $query->orderBy('create_at');
- if(!empty($data['page']))
- {
- $query->offset = ($data['page'] - 1) * $data['limit'];
- $query->limit = $data['limit'];
- }
- return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all();;
- }
- public function Total()
- {
- $query = $this->QueryFind();
- $query = $this->ManyWhere($query);
- return $query->count();
- }
- private function QueryFind()
- {
- return self::find();
- }
- }
|