PushRecommend.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace common\models;
  3. class PushRecommend extends Common
  4. {
  5. public function rules()
  6. {
  7. return [
  8. ['title','required','message'=>'不能为空','on'=>'add'],
  9. ['title', 'unique', 'targetClass' => 'common\models\PushRecommend','on'=>'add','message'=>'栏目名称已经存在'],
  10. [['title'],'trim'],
  11. ['title','string','max'=>15],
  12. [['city','sort'],'number'],
  13. ['city','default','value'=>0],
  14. ];
  15. }
  16. public function attributeLabels()
  17. {
  18. return [
  19. 'title'=>'栏目名称',
  20. ];
  21. }
  22. public function Authenticator($input)
  23. {
  24. $this->load($input,'');
  25. if(!$this->validate()) return $this->errors;
  26. return $this;
  27. }
  28. public function FindById($id)
  29. {
  30. return self::findOne($id);
  31. }
  32. /**后台栏目显示*/
  33. public function getList()
  34. {
  35. $query = self::find();
  36. $query->select(['pfg_push_recommend.del as isdel','pfg_push_recommend.id as cat_id','pfg_category_city.city_name','pfg_category_city.id','pfg_push_recommend.title','pfg_push_recommend.city','pfg_push_recommend.create_at','pfg_push_recommend.is_show','pfg_push_recommend.sort']);
  37. $query->leftJoin('pfg_category_city','pfg_push_recommend.city=pfg_category_city.id');
  38. $query->andWhere(['pfg_push_recommend.del'=>1]);
  39. $query->andWhere(['pfg_push_recommend.is_show'=>1]);
  40. $query->andWhere(['pfg_category_city.state'=>1]);
  41. if(!empty($input['page']))
  42. {
  43. $query->limit = $input['limit'];
  44. $query->offset = ($input['page']-1 )* $input['limit'];
  45. }
  46. return $query->orderBy(['pfg_push_recommend.sort'=>SORT_ASC])->asArray()->all();
  47. }
  48. public function adminList()
  49. {
  50. $query = self::find();
  51. $query->select(['pfg_push_recommend.del as isdel','pfg_push_recommend.id as cat_id','pfg_category_city.city_name','pfg_category_city.id','pfg_push_recommend.title','pfg_push_recommend.city','pfg_push_recommend.create_at','pfg_push_recommend.is_show','pfg_push_recommend.sort']);
  52. $query->leftJoin('pfg_category_city','pfg_push_recommend.city=pfg_category_city.id');
  53. $query->andWhere(['pfg_push_recommend.del'=>1]);
  54. $query->andWhere(['pfg_category_city.state'=>1]);
  55. if(!empty($input['page']))
  56. {
  57. $query->limit = $input['limit'];
  58. $query->offset = ($input['page']-1 )* $input['limit'];
  59. }
  60. return $query->orderBy(['pfg_push_recommend.sort'=>SORT_ASC])->asArray()->all();
  61. }
  62. /**前台栏目显示*/
  63. public function getCatList($input)
  64. {
  65. $query = self::find();
  66. $query->select(['id','title','city','create_at','is_show','sort']);
  67. $query->andWhere(['del'=>$this->setDel]);
  68. $query->andWhere(['is_show'=>1]);
  69. $query->andFilterWhere(['city'=>0]);
  70. if(!empty($input['page']))
  71. {
  72. $query->limit = $input['limit'];
  73. $query->offset = ($input['page']-1 )* $input['limit'];
  74. }
  75. return $query->orderBy(['sort'=>SORT_ASC])->asArray()->all();
  76. }
  77. public function getCatOne($input)
  78. {
  79. $query = self::find();
  80. $query->select(['id','title','city','create_at','is_show','sort']);
  81. $query->andWhere(['del'=>$this->setDel]);
  82. $query->andWhere(['is_show'=>1]);
  83. $query->andFilterWhere(['city'=>$input]);
  84. $query->limit =1;
  85. return $query->orderBy(['sort'=>SORT_DESC])->asArray()->all();
  86. }
  87. public function Total()
  88. {
  89. $query = self::find();
  90. $query->andWhere(['del'=>$this->setDel]);
  91. // $query->leftJoin('pfg_push_recommend','pfg_push_news.nid=pfg_news.id');
  92. return $query->count();
  93. }
  94. }