PushNewscolumn.php 3.0 KB

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