PushRotation.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 PushRotation extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. [['hid', 'title', 'url'], 'required', 'message' => '{attribute}不能为空'],
  15. ['url', 'url', 'defaultScheme' => 'http', 'message' => '请输入正确的地址'],
  16. ['title', 'string', 'max' => 50],
  17. ['city', 'number'],
  18. ['hid', 'number', 'message' => '请选择楼盘'],
  19. ['sort', 'number', 'message' => '排序只能是数字'],
  20. ['sort', 'number', 'max' => 10000],
  21. ['expiration_date', 'string']
  22. ];
  23. }
  24. public function attributeLabels()
  25. {
  26. return [
  27. 'hid' => '楼盘名称',
  28. 'url' => '地址',
  29. 'title' => '标题',
  30. 'city' => '区域',
  31. ];
  32. }
  33. public function Authenticator($input)
  34. {
  35. $this->load($input, '');
  36. if (!$this->validate()) return $this->errors;
  37. return $this;
  38. }
  39. public function FindById($id)
  40. {
  41. return self::findOne($id);
  42. }
  43. public function getList($input)
  44. {
  45. $query = self::find();
  46. $query->select(['pfg_category_city.city_name', 'pfg_house.name', 'pfg_push_rotation.id', 'pfg_push_rotation.hid',
  47. 'pfg_push_rotation.img', 'pfg_push_rotation.url', 'pfg_push_rotation.title', 'pfg_push_rotation.create_at',
  48. 'pfg_push_rotation.is_show', 'pfg_push_rotation.sort', 'pfg_push_rotation.expiration_date', 'pfg_push_rotation.universal']);
  49. $query->andWhere(['pfg_push_rotation.del' => $this->setDel]);
  50. $query->leftJoin('pfg_house', 'pfg_push_rotation.hid=pfg_house.id');
  51. $query->leftJoin('pfg_category_city', 'pfg_push_rotation.city=pfg_category_city.id');
  52. if (!empty($input['title'])) {
  53. $query->andWhere(['like', 'pfg_push_rotation.title', $input['title']]);
  54. }
  55. if (!empty($input['city'])) {
  56. $query->andFilterWhere(['pfg_push_rotation.city' => $input['city']]);
  57. }
  58. if (!empty($input['page'])) {
  59. $query->limit = $input['limit'];
  60. $query->offset = ($input['page'] - 1) * $input['limit'];
  61. }
  62. return $query->orderBy(['pfg_push_rotation.is_show' => SORT_ASC, 'pfg_push_rotation.sort' => SORT_DESC, 'pfg_push_rotation.id' => SORT_DESC])->asArray()->all();
  63. }
  64. public function WhereColumn($query)
  65. {
  66. }
  67. public function Total($input)
  68. {
  69. $query = self::find();
  70. $query->andWhere(['pfg_push_rotation.del' => $this->setDel]);
  71. if (!empty($input['title'])) {
  72. $query->andWhere(['like', 'pfg_push_rotation.title', $input['title']]);
  73. }
  74. if (!empty($input['city'])) {
  75. $query->andFilterWhere(['pfg_push_rotation.city' => $input['city']]);
  76. }
  77. $query->leftJoin('pfg_house', 'pfg_push_rotation.hid=pfg_house.id');
  78. return $query->count();
  79. }
  80. public function HomeGetList()
  81. {
  82. $query = self::find();
  83. $query->select(['img', 'url', 'title', 'expiration_date']);
  84. $query->andWhere(['del' => $this->setDel]);
  85. $query->andFilterWhere(['city' => $this->city]);
  86. $query->andWhere(['is_show' => 1]);
  87. $query->orderBy(['sort' => SORT_ASC]);
  88. $query->limit = 8;
  89. return $query->all();
  90. }
  91. /*
  92. * 2020.7.20 lyy 增加公共轮播图获取
  93. * */
  94. public function HomeGetListP()
  95. {
  96. $p_list = $this->getPublicRotation();
  97. $query = self::find();
  98. $query->select(['id','img', 'url', 'title', 'expiration_date']);
  99. $query->andWhere(['del' => $this->setDel]);
  100. $query->andFilterWhere(['city' => $this->city]);
  101. $query->andWhere(['is_show' => 1]);
  102. if(!empty($p_list)){
  103. $query->andWhere(['not','id=:id']);
  104. $query->addParams([':id' => $p_list['id']]);
  105. $query->limit = 7;
  106. }else{
  107. $query->limit = 8;
  108. }
  109. $query->orderBy(['sort' => SORT_ASC]);
  110. $data_list = $query->asArray()->all();
  111. if(!empty($p_list)){
  112. array_unshift($data_list,$p_list);
  113. }
  114. return $data_list;
  115. }
  116. public function getRoationChart($limit)
  117. {
  118. $p_list = $this->getPublicRotation();
  119. $query = self::find();
  120. $query->select(['id','img', 'url', 'title', 'expiration_date']);
  121. $query->andWhere(['del' => $this->setDel]);
  122. $query->andFilterWhere(['city' => $this->city]);
  123. $query->andWhere(['is_show' => 1]);
  124. if(!empty($p_list)){
  125. $query->andWhere(['not','id=:id']);
  126. $query->addParams([':id' => $p_list['id']]);
  127. }
  128. $query->limit = $limit;
  129. $query->orderBy(['sort' => SORT_ASC]);
  130. $data_list = $query->asArray()->all();
  131. if(!empty($p_list)){
  132. array_unshift($data_list,$p_list);
  133. }
  134. return $data_list;
  135. }
  136. public function getPublicRotation()
  137. {
  138. $query = self::find();
  139. $query->select(['id','img', 'url', 'title', 'expiration_date']);
  140. $query->andWhere(['del' => $this->setDel]);
  141. $query->andWhere(['universal' => 1]);
  142. $query->andWhere(['is_show' => 1]);
  143. $query->orderBy(['sort' => SORT_ASC]);
  144. $query->limit = 1;
  145. return $query->asArray()->one();
  146. }
  147. }