123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/3/4
- * Time: 上午9:44
- */
- namespace common\models;
- class Pricetrends extends Common
- {
- public function rules()
- {
- return [
- [['city_id','price','price_at','trend','contrast'], 'filter', 'filter' => 'trim', 'skipOnArray' => true],
- [['city_id','price','price_at'],'required','message'=>'{attribute}不能为空'],
- ['price_at','date', 'format'=>'yyyy-mm-dd','message'=>'时间格式为:1990-01-01'],
- ['price','number','message'=>'价格请输入数字','max'=>200000],
- ['trend','in','range'=>[1,2]],
- ['contrast','string','max'=>50],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'city_id'=>'区域',
- 'price'=>'价格',
- 'price_at'=>'时间',
- 'trend'=>'趋势',
- 'contrast'=>'价格对比',
- ];
- }
- public function FindById($id)
- {
- return self::findOne($id);
- }
- public function Authenticator($input)
- {
- $this->load($input,'');
- if($this->validate()) return $this;
- return $this->errors;
- }
- //后台区域分组数据显示
- public function getList($page)
- {
- $query = self::find();
- $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
- $query->andFilterWhere(['pfg_pricetrends.city_id'=>$this->city_id]);
- $query->select(['pfg_category_city.city_name','pfg_pricetrends.city_id','pfg_pricetrends.price','pfg_pricetrends.price_at','pfg_pricetrends.id','pfg_pricetrends.create_at']);
- $query->leftJoin('pfg_category_city','pfg_pricetrends.city_id = pfg_category_city.id');
- $query->groupBy('pfg_pricetrends.city_id');
- if(!empty($page['page']))
- {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- return $query->asArray()->all();
- }
- //后台显示数据条数
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
- $query->andFilterWhere(['pfg_pricetrends.city_id'=>$this->city_id]);
- $query->leftJoin('pfg_category_city','pfg_pricetrends.city_id = pfg_category_city.id');
- $query->groupBy('pfg_pricetrends.city_id');
- return $query->count();
- }
- //单个区域数据显示
- public function getCityList($page)
- {
- $query = self::find();
- $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
- $query->andFilterWhere(['pfg_pricetrends.city_id'=>$this->city_id]);
- $query->select(['pfg_category_city.city_name','pfg_pricetrends.city_id','pfg_pricetrends.price','pfg_pricetrends.price_at','pfg_pricetrends.id','pfg_pricetrends.create_at','pfg_pricetrends.contrast','pfg_pricetrends.trend']);
- $query->leftJoin('pfg_category_city','pfg_pricetrends.city_id = pfg_category_city.id');
- $query->orderBy(['pfg_pricetrends.price_at'=>SORT_DESC]);
- if(!empty($page['page']))
- {
- $query->offset = ($page['page'] - 1) * $page['limit'];
- $query->limit = $page['limit'];
- }
- return $query->asArray()->all();
- }
- //单个区域数据条数
- public function cityTotal()
- {
- $query = self::find();
- $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
- $query->andFilterWhere(['pfg_pricetrends.city_id'=>$this->city_id]);
- $query->leftJoin('pfg_category_city','pfg_pricetrends.city_id = pfg_category_city.id');
- $query->groupBy('pfg_pricetrends.city_id');
- return $query->count();
- }
-
- public function CityRecordPrice()
- {
- $query = self::find();
- $query->select(['pfg_pricetrends.price', 'UNIX_TIMESTAMP(pfg_pricetrends.price_at) as price_at', 'pfg_category_city.city_name']);
- $query->andWhere(['pfg_pricetrends.is_show' => 1]);
- $query->andWhere(['pfg_pricetrends.del' => $this->setDel]);
- $query->andWhere(['pfg_pricetrends.city_id' => $this->city_id]);
- $query->leftJoin('pfg_category_city', 'pfg_pricetrends.city_id=pfg_category_city.id');
- $query->orderBy(['price_at' => SORT_ASC]);
- return $query->asArray()->all();
- }
- }
|