HomeDiscount.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 201901
  5. * Date: 2020/7/7
  6. * Time: 9:19
  7. */
  8. namespace common\models;
  9. class HomeDiscount extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['hid', 'required', 'message' => '{attribute}不能为空'],
  15. ['hid', 'unique', 'targetClass' => 'common\models\HomeDiscount', 'on' => ['add', 'edit'], 'message' => '该楼盘已存在'],
  16. ['title', 'string', 'max' => 255],
  17. ['sort', 'number', 'message' => '排序只能是数字'],
  18. ['sort', 'number', 'max' => 10000],
  19. ];
  20. }
  21. public function attributeLabels()
  22. {
  23. return [
  24. 'hid' => '楼盘',
  25. ];
  26. }
  27. public function Authenticator($input)
  28. {
  29. $this->load($input, '');
  30. if (!$this->validate()) return $this->errors;
  31. return $this;
  32. }
  33. public function FindById($id)
  34. {
  35. return self::findOne($id);
  36. }
  37. public function getList($input)
  38. {
  39. $query = self::find();
  40. $query->select(['pfg_home_discount.id', 'pfg_home_discount.create_at', 'pfg_home_discount.is_show', 'pfg_home_discount.sort', 'pfg_home_discount.title', 'pfg_house.name']);
  41. $query->innerJoin('pfg_house', 'pfg_home_discount.hid = pfg_house.id');
  42. if (!empty($input['page'])) {
  43. $query->limit = $input['limit'];
  44. $query->offset = ($input['page'] - 1) * $input['limit'];
  45. }
  46. return $query->orderBy(['pfg_home_discount.is_show' => SORT_ASC, 'pfg_home_discount.sort' => SORT_DESC, 'pfg_home_discount.id' => SORT_DESC])->asArray()->all();
  47. }
  48. public function Total($input)
  49. {
  50. $query = self::find();
  51. $query->innerJoin('pfg_house', 'pfg_home_discount.hid = pfg_house.id');
  52. return $query->count();
  53. }
  54. public static function getDiscount($limit)
  55. {
  56. $query = self::find();
  57. $query->andWhere(['pfg_home_discount.is_show' => 1]);
  58. $query->select(['pfg_home_discount.hid', 'pfg_home_discount.title', 'pfg_house.name']);
  59. $query->innerJoin('pfg_house', 'pfg_home_discount.hid = pfg_house.id');
  60. $query->limit = $limit;
  61. return $query->orderBy(['pfg_home_discount.sort' => SORT_DESC, 'pfg_home_discount.id' => SORT_DESC])->asArray()->all();
  62. }
  63. }