12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:40
- */
- namespace common\models;
- //use yii\db\ActiveRecord;
- //use yii\behaviors\TimestampBehavior;
- class HousesPrice extends Common
- {
- // 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 [
- ['price','required','message'=>'价格不能为空'],
- ['price_short','required','message'=>'短标不能为空'],
- ['state','in','range'=>[1,2]],
- ['del','in','range'=>[1,2]],
- ];
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function getList($input,$arr = null)
- {
- $query = self::find();
- $query->select($arr);
- $query = $this->WhereFouse($query);
- 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 WhereFouse($query)
- {
- $query->andFilterWhere(['del'=>$this->setDel]);
- $query->andFilterWhere(['price'=>$this->price]);
- return $query;
- }
- public function Total()
- {
- $query = self::find();
- $query = $this->WhereFouse($query);
- return $query->count();
- }
- }
|