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(); } }