NewsRenovationcontent.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/3/4
  6. * Time: 上午9:42
  7. */
  8. namespace common\models;
  9. class NewsRenovationcontent extends Common
  10. {
  11. public function rules()
  12. {
  13. return [
  14. ['label_id', 'unique', 'targetClass' => 'common\models\NewsRenovationcontent','on'=>['add'],'message'=>'该栏目已存在','filter'=>function($query){
  15. $query->andWhere(['del'=>$this->setDel]);
  16. $query->andWhere(['label_id'=>$this->label_id]);
  17. $query->andWhere(['nid'=>$this->nid]);
  18. return $query;
  19. }],
  20. [['nid','content','label_id'],'required','message'=>'{attribute}不能为空'],
  21. ['sort','number'],
  22. ['is_show','in','range'=>[1,2]],
  23. ['del','in','range'=>[1,2]],
  24. ];
  25. }
  26. public function attributeLabels()
  27. {
  28. return [
  29. 'nid'=>'装修品鉴标题',
  30. 'label_id'=>'栏目',
  31. 'content'=>'内容',
  32. ];
  33. }
  34. public function FindById($id)
  35. {
  36. return self::findOne($id);
  37. }
  38. public function Authenticator($input)
  39. {
  40. $this->load($input,'');
  41. if($this->validate()) return $this;
  42. return $this->errors;
  43. }
  44. public function getList($page)
  45. {
  46. $query = self::find();
  47. $query->select(['pfg_category_label.name','pfg_news_renovationcontent.sort','pfg_news_renovationcontent.create_at','pfg_news_renovationcontent.is_show','pfg_news_renovationcontent.id']);
  48. $query->andWhere(['pfg_news_renovationcontent.del'=>$this->setDel]);
  49. $query->andWhere(['pfg_news_renovationcontent.nid'=>$this->nid]);
  50. if(!empty($page['page']))
  51. {
  52. $query->offset = ($page['page'] - 1) * $page['limit'];
  53. $query->limit = $page['limit'];
  54. }
  55. $query->leftJoin('pfg_category_label','pfg_news_renovationcontent.label_id = pfg_category_label.id');
  56. return $query->orderBy(['pfg_news_renovationcontent.sort'=>SORT_DESC])->asArray()->all();
  57. }
  58. public function PcLabel()
  59. {
  60. $query = self::find();
  61. $query->select(['pfg_news_renovationcontent.id','pfg_category_label.name','pfg_category_label.img','pfg_category_label.img1','pfg_news_renovationcontent']);
  62. $query->andWhere(['pfg_news_renovationcontent.del'=>1]);
  63. $query->andWhere(['pfg_news_renovationcontent.is_show'=>1]);
  64. $query->andWhere(['pfg_category_label.del'=>1]);
  65. $query->andWhere(['pfg_news_renovationcontent.nid'=>$this->nid]);
  66. $query->leftJoin('pfg_category_label','pfg_news_renovationcontent.label_id = pfg_category_label.id');
  67. $query->orderBy(['pfg_category_label.sort'=>SORT_DESC]);
  68. return $query->asArray()->all();
  69. }
  70. public function getListTotal()
  71. {
  72. $query = self::find();
  73. $query->andWhere(['pfg_news_renovationcontent.del'=>$this->setDel]);
  74. $query->andWhere(['pfg_news_renovationcontent.nid'=>$this->nid]);
  75. return $query->count();
  76. }
  77. public function MLabel()
  78. {
  79. $query = self::find();
  80. $query->select(['pfg_news_renovationcontent.id','pfg_category_label.name','pfg_category_label.img','pfg_category_label.img1','pfg_news_renovationcontent.content']);
  81. $query->andWhere(['pfg_news_renovationcontent.del'=>1]);
  82. $query->andWhere(['pfg_news_renovationcontent.is_show'=>1]);
  83. $query->andWhere(['pfg_category_label.del'=>1]);
  84. $query->andWhere(['pfg_news_renovationcontent.nid'=>$this->nid]);
  85. $query->leftJoin('pfg_category_label','pfg_news_renovationcontent.label_id = pfg_category_label.id');
  86. $query->orderBy(['pfg_category_label.sort'=>SORT_DESC]);
  87. return $query->asArray()->all();
  88. }
  89. public function Total()
  90. {
  91. $query = self::find();
  92. $query->andWhere(['nid'=>$this->nid]);
  93. $query->andWhere(['del'=>$this->setDel]);
  94. return $query->count();
  95. }
  96. /**
  97. *
  98. */
  99. public function RecordClick()
  100. {
  101. }
  102. }