PushBottom.php 6.2 KB

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