PushmNewscolumn.php 2.9 KB

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