PushCityprice.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/5/21
  6. * Time: 下午5:18
  7. */
  8. namespace common\models;
  9. class PushCityprice extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['city_id', 'unique', 'targetClass' => 'common\models\PushCityprice','on'=>['add'],'message'=>'该楼盘已存在','filter'=>function($query){
  15. $query->andWhere(['del'=>$this->setDel]);
  16. return $query->andWhere(['type'=>$this->type]);
  17. }],
  18. // ['city_id','number','message'=>'请选择区域'],
  19. ['city_id','each','rule'=>['integer'],'message'=>'请输入正确的区域信息'],
  20. ['sort','number','message'=>'排序只能是数字'],
  21. ['sort','number','max'=>10000],
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'city_id'=>'楼盘名称',
  28. 'sort'=>'排序',
  29. ];
  30. }
  31. public function Authenticator($input)
  32. {
  33. $this->load($input,'');
  34. if(!$this->validate()) return $this->errors;
  35. return $this;
  36. }
  37. public function FindById($id)
  38. {
  39. return self::findOne($id);
  40. }
  41. public function getList($input)
  42. {
  43. $query = self::find();
  44. $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']);
  45. $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
  46. $query->andWhere(['pfg_push_cityprice.type'=>$this->type]);
  47. if(!empty($input['city_name']))
  48. {
  49. $query->andWhere(['like','pfg_category_city.city_name',$input['city_name']]);
  50. }
  51. // if(!empty($input['city_id']))
  52. // {
  53. // $query->andWhere(['pfg_push_cityprice.city_id'=>$input['city_id']]);
  54. // }
  55. $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
  56. if(!empty($input['page']))
  57. {
  58. $query->limit = $input['limit'];
  59. $query->offset = ($input['page']-1 )* $input['limit'];
  60. }
  61. return $query->orderBy(['pfg_push_cityprice.create_at'=>SORT_DESC])->asArray()->all();
  62. }
  63. public function WhereColumn($query)
  64. {
  65. }
  66. public function Total()
  67. {
  68. $query = self::find();
  69. $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
  70. $query->andWhere(['pfg_push_cityprice.type'=>$this->type]);
  71. $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
  72. return $query->count();
  73. }
  74. public function Homegetlist($limit = 10)
  75. {
  76. $query = self::find();
  77. $query->select(['pfg_category_city.id','pfg_category_city.city_name']);
  78. $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
  79. $query->andFilterWhere(['pfg_push_cityprice.city_id'=>$this->city_id]);
  80. $query->andWhere(['pfg_push_cityprice.is_show'=>1]);
  81. $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
  82. $query->orderBy(['pfg_push_cityprice.sort'=>SORT_DESC]);
  83. $query->limit = $limit;
  84. return $query->asArray()->all();
  85. }
  86. /**
  87. *
  88. */
  89. public function CityRecordPrice()
  90. {
  91. $query = self::find();
  92. $query->select(['pfg_pricetrends.price','UNIX_TIMESTAMP(pfg_pricetrends.price_at) as price_at','pfg_category_city.city_name']);
  93. $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
  94. $query->andWhere(['pfg_push_cityprice.is_show'=>1]);
  95. $query->andWhere(['pfg_pricetrends.is_show'=>1]);
  96. $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
  97. $query->andWhere(['pfg_push_cityprice.city_id'=>$this->city_id]);
  98. $query->leftJoin('pfg_pricetrends','pfg_push_cityprice.city_id=pfg_pricetrends.city_id');
  99. $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
  100. $query->orderBy(['price_at'=>SORT_ASC]);
  101. return $query->asArray()->all();
  102. }
  103. /**
  104. * 分组
  105. */
  106. public function FindCityRecordPrice()
  107. {
  108. $query = self::find();
  109. $query->select(['pfg_pricetrends.price','pfg_pricetrends.price_at','pfg_category_city.city_name','pfg_pricetrends.contrast','pfg_pricetrends.trend']);
  110. $query->andWhere(['pfg_push_cityprice.del'=>$this->setDel]);
  111. $query->andWhere(['pfg_push_cityprice.is_show'=>1]);
  112. $query->andWhere(['pfg_pricetrends.is_show'=>1]);
  113. $query->andWhere(['pfg_pricetrends.del'=>$this->setDel]);
  114. $query->andWhere(['pfg_push_cityprice.city_id'=>$this->city_id]);
  115. $query->leftJoin('pfg_pricetrends','pfg_push_cityprice.city_id=pfg_pricetrends.city_id');
  116. $query->leftJoin('pfg_category_city','pfg_push_cityprice.city_id=pfg_category_city.id');
  117. $query->orderBy(['pfg_pricetrends.price_at'=>SORT_DESC]);
  118. // $query->orderBy("str_to_date(pfg_pricetrends.price_at,'%Y-%m-%d') desc");
  119. return $query->asArray()->one();
  120. }
  121. }