PushNews.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 PushNews extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['nid', 'unique', 'targetClass' => 'common\models\PushNews','on'=>['add'],'message'=>'该资讯已存在','filter'=>function($query){
  15. $query->andWhere(['del'=>$this->setDel]);
  16. return $query->andWhere(['type'=>$this->type]);
  17. }],
  18. // ['']
  19. ['nid','required','message'=>'请选择资讯'],
  20. ['type','number'],
  21. ['cid','number'],
  22. ['sort','number','message'=>'排序只能是数字'],
  23. ['sort','number','max'=>10000],
  24. ];
  25. }
  26. public function attributeLabels()
  27. {
  28. return [
  29. 'nid'=>'资讯名称',
  30. 'sort'=>'排序',
  31. ];
  32. }
  33. public function Authenticator($input)
  34. {
  35. $this->load($input,'');
  36. if(!$this->validate()) return $this->errors;
  37. return $this;
  38. }
  39. public function FindById($id)
  40. {
  41. return self::findOne($id);
  42. }
  43. public function getList($input)
  44. {
  45. $query = self::find();
  46. $query->select(['pfg_push_news.cid','pfg_push_news.id','pfg_news.subject','pfg_push_news.create_at','pfg_push_news.is_show','pfg_push_news.sort','pfg_push_news.img']);
  47. $query->andWhere(['pfg_push_news.del'=>$this->setDel]);
  48. $query->andWhere(['pfg_push_news.type'=>$this->type]);
  49. $query->andFilterWhere(['pfg_push_news.cid'=>$this->cid]);
  50. $query->leftJoin('pfg_news','pfg_push_news.nid=pfg_news.id');
  51. if(!empty($input['page']))
  52. {
  53. $query->limit = $input['limit'];
  54. $query->offset = ($input['page']-1 )* $input['limit'];
  55. }
  56. return $query->orderBy(['pfg_push_news.sort'=>SORT_DESC,'pfg_push_news.id'=>SORT_DESC])->asArray()->all();
  57. }
  58. public function Total()
  59. {
  60. $query = self::find();
  61. $query->andWhere(['pfg_push_news.del'=>$this->setDel]);
  62. $query->andWhere(['pfg_push_news.type'=>$this->type]);
  63. $query->andFilterWhere(['pfg_push_news.cid'=>$this->cid]);
  64. $query->leftJoin('pfg_news','pfg_push_news.nid=pfg_news.id');
  65. return $query->count();
  66. }
  67. public function Homegetlist($limit)
  68. {
  69. $query = self::find();
  70. $query->select(['pfg_news.id','pfg_news.subject','pfg_push_news.img','pfg_news.abstract','pfg_news.short_subject','pfg_news.thumb']);
  71. $query->andWhere(['pfg_push_news.del'=>$this->setDel]);
  72. $query->andWhere(['pfg_push_news.is_show'=>1]);
  73. $query->andWhere(['pfg_push_news.type'=>$this->type]);
  74. $query->leftJoin('pfg_news','pfg_push_news.nid=pfg_news.id');
  75. $query->limit = $limit;
  76. return $query->orderBy(['pfg_push_news.sort'=>SORT_DESC,'pfg_push_news.id'=>SORT_DESC])->asArray()->all();
  77. }
  78. public function getPushNewscolumn()
  79. {
  80. return $this->hasMany(PushNewscolumn::className(),['cid'=>'id']);
  81. }
  82. }