123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/5/21
- * Time: 下午5:18
- */
- namespace common\models;
- class PushCityprice extends Common
- {
- public function rules()
- {
- return [
- ['city_id', 'unique', 'targetClass' => 'common\models\PushCityprice','on'=>['add'],'message'=>'该楼盘已存在','filter'=>function($query){
- $query->andWhere(['del'=>$this->setDel]);
- return $query->andWhere(['type'=>$this->type]);
- }],
- // ['city_id','number','message'=>'请选择区域'],
- ['city_id','each','rule'=>['integer'],'message'=>'请输入正确的区域信息'],
- ['sort','number','message'=>'排序只能是数字'],
- ['sort','number','max'=>10000],
- ];
- }
- public function attributeLabels()
- {
- return [
- 'city_id'=>'楼盘名称',
- 'sort'=>'排序',
- ];
- }
- 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 getList($input)
- {
- $query = self::find();
- $query->select(['pfg_push_cityprice.id','pfg_category_city.city_name','pfg_push_cityprice.create_at','pfg_push_cityprice.is_show','pfg_push_cityprice.sort','pfg_push_cityprice.city_id']);
- $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_cityprice.type'=>$this->type]);
- if(!empty($input['city_name']))
- {
- $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
- }
- // if(!empty($input['city_id']))
- // {
- // $query->andWhere(['pfg_push_cityprice.city_id'=>$input['city_id']]);
- // }
- $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
- if(!empty($input['page']))
- {
- $query->limit = $input['limit'];
- $query->offset = ($input['page']-1 )* $input['limit'];
- }
- return $query->orderBy(['pfg_push_cityprice.create_at'=>SORT_DESC])->asArray()->all();
- }
- public function WhereColumn($query)
- {
- }
- public function Total()
- {
- $query = self::find();
- $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_cityprice.type'=>$this->type]);
- $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
- return $query->count();
- }
- public function Homegetlist($limit = 10)
- {
- $query = self::find();
- $query->select(['pfg_category_city.id','pfg_category_city.city_name']);
- $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
- $query->andFilterWhere(['pfg_push_cityprice.city_id'=>$this->city_id]);
- $query->andWhere(['pfg_push_cityprice.is_show'=>1]);
- $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
- $query->orderBy(['pfg_push_cityprice.sort'=>SORT_DESC]);
- $query->limit = $limit;
- return $query->asArray()->all();
- }
- /**
- *
- */
- 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_push_cityprice.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_cityprice.is_show'=>1]);
- $query->andWhere(['pfg_pricetrends.is_show'=>1]);
- $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_cityprice.city_id'=>$this->city_id]);
- $query->leftJoin('pfg_pricetrends','pfg_push_cityprice.city_id=pfg_pricetrends.city_id');
- $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
- $query->orderBy(['price_at'=>SORT_ASC]);
- return $query->asArray()->all();
- }
- /**
- * 分组
- */
- public function FindCityRecordPrice()
- {
- $query = self::find();
- $query->select(['pfg_pricetrends.price','pfg_pricetrends.price_at','pfg_category_city.city_name','pfg_pricetrends.contrast','pfg_pricetrends.trend']);
- $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_cityprice.is_show'=>1]);
- $query->andWhere(['pfg_pricetrends.is_show'=>1]);
- $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
- $query->andWhere(['pfg_push_cityprice.city_id'=>$this->city_id]);
- $query->leftJoin('pfg_pricetrends','pfg_push_cityprice.city_id=pfg_pricetrends.city_id');
- $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
- $query->orderBy(['pfg_pricetrends.price_at'=>SORT_DESC]);
- // $query->orderBy("str_to_date(pfg_pricetrends.price_at,'%Y-%m-%d') desc");
- return $query->asArray()->one();
- }
- }
|