PushChoice.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 PushChoice extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. [['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. 'city'=>'区域',
  30. ];
  31. }
  32. public function Authenticator($input)
  33. {
  34. $this->load($input,'');
  35. if(!$this->validate()) return $this->errors;
  36. return $this;
  37. }
  38. public function FindById($id)
  39. {
  40. return self::findOne($id);
  41. }
  42. public function getList($input)
  43. {
  44. $query = self::find();
  45. $query->select(['pfg_house.name','pfg_push_choice.id','pfg_push_choice.hid','pfg_push_choice.img','pfg_push_choice.url',
  46. 'pfg_push_choice.title','pfg_push_choice.create_at','pfg_push_choice.is_show','pfg_push_choice.expiration_date']);
  47. $query->andWhere(['pfg_push_choice.del'=>$this->setDel]);
  48. $query->leftJoin('pfg_house','pfg_push_choice.hid=pfg_house.id');
  49. if(!empty($input['title']))
  50. {
  51. $query->andWhere(['like','pfg_push_choice.title',$input['title']]);
  52. }
  53. if(!empty($input['city']))
  54. {
  55. $query->andWhere(['pfg_push_choice.city'=>$input['city']]);
  56. }
  57. if(!empty($input['page']))
  58. {
  59. $query->limit = $input['limit'];
  60. $query->offset = ($input['page']-1 )* $input['limit'];
  61. }
  62. return $query->orderBy(['pfg_push_choice.is_show'=>SORT_ASC,'pfg_push_choice.create_at'=>SORT_DESC])->asArray()->all();
  63. }
  64. public function WhereColumn($query)
  65. {
  66. }
  67. public function Total($input)
  68. {
  69. $query = self::find();
  70. if(!empty($input['title']))
  71. {
  72. $query->andWhere(['like','pfg_push_choice.title',$input['title']]);
  73. }
  74. if(!empty($input['city']))
  75. {
  76. $query->andWhere(['pfg_push_choice.city'=>$input['city']]);
  77. }
  78. $query->andWhere(['pfg_push_choice.del'=>$this->setDel]);
  79. $query->leftJoin('pfg_house','pfg_push_choice.hid=pfg_house.id');
  80. return $query->count();
  81. }
  82. public function HomeGetList()
  83. {
  84. $query = self::find();
  85. $query->select(['img','url','title','expiration_date']);
  86. $query->andFilterWhere(['city'=>$this->city]);
  87. $query->andWhere(['del'=>$this->setDel]);
  88. $query->andWhere(['is_show'=>1]);
  89. $query->orderBy(['sort'=>SORT_ASC]);
  90. $query->limit = 2;
  91. return $query->all();
  92. }
  93. }