123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/28
- * Time: 下午2:47
- */
- namespace common\models;
- //use yii\db\ActiveRecord;
- //use yii\behaviors\TimestampBehavior;
- class HousePriceRecord 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 [
- [['create_time','price'],'required','message'=>'{attribute}不能为空'],
- ['create_time','date', 'format'=>'yyyy-mm-dd'],
- ['min_price','string','max'=>30],
- ['explain','string','max'=>200],
- ['hid','number'],
- ['price','number'],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'price'=>'价格',
- 'create_time'=>'添加时间',
- 'min_price'=>'最低价格',
- 'explain'=>'价格说明',
- ];
- }
- public function Authenticator($input)
- {
- $this->load($input,'');
- if(!$this->validate()) return $this->errors;
- return $this;
- }
- public function getList($page)
- {
- $query = self::find();
- $query = $this->SetWheres($query);
- if(!empty($page['page']))
- {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- return $query->orderBy(['create_time'=>SORT_DESC])->asArray()->all();
- }
- public function Total()
- {
- $query = self::find();
- $query = $this->SetWheres($query);
- return $query->count();
- }
- private function SetWheres($query)
- {
- $query->andWhere(['del'=>$this->setDel]);
- $query->andFilterWhere(['hid'=>$this->hid]);
- return $query;
- }
- // public function FindOneRecord()
- // {
- // $query = $this->newFind();
- // $query = $this->SetWheres($query);
- // return $query->one();
- // }
- private function newFind()
- {
- return self::find();
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function GetPrice($Id)
- {
- $query = self::find();
- $query->andWhere(['del'=>$this->setDel]);
- $query->andFilterWhere(['hid'=>$Id]);
- return $query->orderBy('create_time')->asArray()->all();
- }
- }
|