PushmNews.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 PushmNews extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['nid', 'unique', 'targetClass' => 'common\models\PushmNews','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_pushm_news.id','pfg_news.subject','pfg_pushm_news.create_at','pfg_pushm_news.is_show','pfg_pushm_news.sort','pfg_pushm_news.img']);
  47. $query->andWhere(['pfg_pushm_news.del'=>$this->setDel]);
  48. $query->andWhere(['pfg_pushm_news.type'=>$this->type]);
  49. $query->leftJoin('pfg_news','pfg_pushm_news.nid=pfg_news.id');
  50. if(!empty($input['page']))
  51. {
  52. $query->limit = $input['limit'];
  53. $query->offset = ($input['page']-1 )* $input['limit'];
  54. }
  55. return $query->orderBy(['pfg_pushm_news.create_at'=>SORT_DESC])->asArray()->all();
  56. }
  57. public function WhereColumn($query)
  58. {
  59. }
  60. public function Total()
  61. {
  62. $query = self::find();
  63. $query->andWhere(['pfg_pushm_news.del'=>$this->setDel]);
  64. $query->andWhere(['pfg_pushm_news.type'=>$this->type]);
  65. $query->leftJoin('pfg_news','pfg_pushm_news.nid=pfg_news.id');
  66. return $query->count();
  67. }
  68. public function Homegetlist($limit)
  69. {
  70. $query = self::find();
  71. $query->select(['pfg_news.id','pfg_news.subject','pfg_pushm_news.img','pfg_news.short_subject','pfg_news.thumb','pfg_news.open_time','pfg_news.clicks']);
  72. $query->andWhere(['pfg_pushm_news.del'=>$this->setDel]);
  73. $query->andWhere(['pfg_pushm_news.is_show'=>1]);
  74. $query->andWhere(['pfg_pushm_news.type'=>$this->type]);
  75. $query->leftJoin('pfg_news','pfg_pushm_news.nid=pfg_news.id');
  76. $query->limit = $limit;
  77. return $query->orderBy(['pfg_pushm_news.sort'=>SORT_ASC])->asArray()->all();
  78. }
  79. public function getPushNewscolumn()
  80. {
  81. return $this->hasMany(PushNewscolumn::className(),['cid'=>'id']);
  82. }
  83. }