PushDiscount.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace common\models;
  3. class PushDiscount extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. ['hid', 'unique', 'targetClass' => 'common\models\PushDiscount', 'message' => '该楼盘已存在', 'filter' => function ($query) {
  9. return $query->andWhere(['type' => $this->type]);
  10. }],
  11. ['url', 'url', 'defaultScheme' => 'http', 'message' => '请输入正确的链接地址'],
  12. [['type', 'sort', 'is_show', 'hid'], 'number'],
  13. ['sort', 'number', 'max' => 10000],
  14. [['is_show'], 'in', 'range' => [1, 2]],
  15. [['title', 'subject'], 'string', 'max' => 255],
  16. ];
  17. }
  18. public function attributeLabels()
  19. {
  20. return [
  21. 'hid' => '楼盘',
  22. 'title' => '标题',
  23. 'subject' => '内容',
  24. 'url' => '跳转链接'
  25. ];
  26. }
  27. /**
  28. * 后台查询数据
  29. * @param $post
  30. * @return array|\yii\db\ActiveRecord[]
  31. */
  32. public function getList($post)
  33. {
  34. $query = self::find();
  35. $query->andWhere(['pfg_push_discount.type' => $post['type']]);
  36. $query->select(['pfg_push_discount.id', 'pfg_push_discount.create_at', 'pfg_push_discount.is_show', 'pfg_push_discount.sort', 'pfg_house.name']);
  37. $query->leftJoin('pfg_house', 'pfg_push_discount.hid = pfg_house.id');
  38. $query->orderBy(['pfg_push_discount.sort' => SORT_DESC, 'pfg_push_discount.id' => SORT_DESC]);
  39. if (!empty($post['page'])) {
  40. $query->limit = $post['limit'];
  41. $query->offset = ($post['page'] - 1) * $post['limit'];
  42. }
  43. return $query->asArray()->all();
  44. }
  45. /**
  46. * 后台统计条数
  47. * @param $post
  48. * @return int|string
  49. */
  50. public function countList($post)
  51. {
  52. $query = self::find();
  53. $query->andWhere(['pfg_push_discount.type' => $post['type']]);
  54. $query->leftJoin('pfg_house', 'pfg_push_discount.hid = pfg_house.id');
  55. return $query->count();
  56. }
  57. /**
  58. * PC前台列表页查询数据
  59. * @param $type
  60. * @param $limit
  61. * @return array|\yii\db\ActiveRecord[]
  62. */
  63. public function getHomeList($type, $limit)
  64. {
  65. $query = self::find();
  66. $query->andWhere(['pfg_push_discount.type' => $type]);
  67. $query->select(['pfg_house.id', 'pfg_house.name', 'pfg_house.sale_price', 'pfg_house_detail.price_unit', 'pfg_push_discount.url', 'pfg_push_discount.title', 'pfg_push_discount.subject']);
  68. $query->leftJoin('pfg_house', 'pfg_push_discount.hid = pfg_house.id');
  69. $query->leftJoin('pfg_house_detail', 'pfg_house.id = pfg_house_detail.hid');
  70. $query->orderBy(['pfg_push_discount.sort' => SORT_DESC, 'pfg_push_discount.id' => SORT_DESC]);
  71. $query->limit = $limit;
  72. return $query->asArray()->all();
  73. }
  74. }