PushmRotation.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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 PushmRotation extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. [['title','url'],'required','message'=>'{attribute}不能为空'],
  15. ['url', 'url', 'defaultScheme' => 'http','message'=>'请输入正确的地址'],
  16. ['title','string','max'=>50],
  17. ['img','string','max'=>50],
  18. ['hid','number','message'=>'请选择楼盘'],
  19. ['sort','number','message'=>'排序只能是数字'],
  20. ['city','default','value'=>0],
  21. ['city','number'],
  22. ['sort','number','max'=>10000],
  23. ['expiration_date','string'],
  24. ];
  25. }
  26. public function attributeLabels()
  27. {
  28. return [
  29. 'hid'=>'楼盘名称',
  30. 'url'=>'地址',
  31. 'title'=>'标题',
  32. 'city'=>'区域',
  33. ];
  34. }
  35. public function Authenticator($input)
  36. {
  37. $this->load($input,'');
  38. if(!$this->validate()) return $this->errors;
  39. return $this;
  40. }
  41. public function FindById($id)
  42. {
  43. return self::findOne($id);
  44. }
  45. public function getList($input)
  46. {
  47. $query = self::find();
  48. $query->select(['pfg_category_city.city_name','pfg_house.name','pfg_pushm_rotation.id','pfg_pushm_rotation.hid',
  49. 'pfg_pushm_rotation.img','pfg_pushm_rotation.url','pfg_pushm_rotation.title','pfg_pushm_rotation.create_at',
  50. 'pfg_pushm_rotation.is_show','pfg_pushm_rotation.sort','pfg_pushm_rotation.expiration_date']);
  51. $query->andWhere(['pfg_pushm_rotation.del'=>$this->setDel]);
  52. $query->leftJoin('pfg_house','pfg_pushm_rotation.hid=pfg_house.id');
  53. $query->leftJoin('pfg_category_city','pfg_pushm_rotation.city=pfg_category_city.id');
  54. if(!empty($input['city']))
  55. {
  56. $query->andFilterWhere(['pfg_pushm_rotation.city'=>$input['city']]);
  57. }
  58. if (!empty($input['name'])) {
  59. $query->andWhere(['like','pfg_house.name',$input['name']]);
  60. }
  61. if(!empty($input['page']))
  62. {
  63. $query->limit = $input['limit'];
  64. $query->offset = ($input['page']-1 )* $input['limit'];
  65. }
  66. return $query->orderBy(['pfg_pushm_rotation.is_show'=>SORT_ASC,'pfg_pushm_rotation.sort'=>SORT_DESC,'pfg_pushm_rotation.create_at'=>SORT_DESC])->asArray()->all();
  67. }
  68. public function WhereColumn($query)
  69. {
  70. }
  71. public function Total($input)
  72. {
  73. $query = self::find();
  74. $query->andWhere(['pfg_pushm_rotation.del'=>$this->setDel]);
  75. if(!empty($input['city']))
  76. {
  77. $query->andFilterWhere(['pfg_pushm_rotation.city'=>$input['city']]);
  78. }
  79. if (!empty($input['name'])) {
  80. $query->andWhere(['like','pfg_house.name',$input['name']]);
  81. }
  82. $query->leftJoin('pfg_house','pfg_pushm_rotation.hid=pfg_house.id');
  83. return $query->count();
  84. }
  85. public function HomeGetList()
  86. {
  87. $query = self::find();
  88. $query->select(['img','url','title','expiration_date']);
  89. $query->andWhere(['del'=>$this->setDel]);
  90. $query->andFilterWhere(['city'=>$this->city]);
  91. $query->andWhere(['is_show'=>1]);
  92. $query->orderBy(['sort'=>SORT_ASC]);
  93. $query->limit = 5;
  94. return $query->all();
  95. }
  96. /**不分地区读取全部*/
  97. public function GetAllList()
  98. {
  99. $query = self::find();
  100. $query->select(['img','url','title','expiration_date']);
  101. $query->andWhere(['del'=>$this->setDel]);
  102. $query->andWhere(['is_show'=>1]);
  103. $query->orderBy(['sort'=>SORT_ASC]);
  104. $query->limit = 5;
  105. return $query->all();
  106. }
  107. /**
  108. * 前台获取图片
  109. * @param $type
  110. * @param $limit
  111. * @return array|\yii\db\ActiveRecord[]
  112. */
  113. public function getRoationChart( $limit)
  114. {
  115. $query = self::find();
  116. $query->andWhere(['del' => $this->setDel]);
  117. $query->select(['title', 'url', 'img']);
  118. $query->limit = $limit;
  119. $query->orderBy(['sort' => SORT_DESC, 'id' => SORT_DESC]);
  120. $data = $query->asArray()->all();
  121. if (!empty($data)) {
  122. foreach ($data as &$val) {
  123. $val['img'] = \Yii::$app->params['httpImg']['host'] . \Yii::$app->params['httpImg']['push_lb'] . $val['img'];
  124. }
  125. return $data;
  126. }
  127. }
  128. }