NewsRenovation.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. use yii\data\Pagination;
  10. class NewsRenovation extends Common
  11. {
  12. public function rules()
  13. {
  14. return [
  15. [['type','title','source','describe'],'required','message'=>'{attribute}不能为空'],
  16. ['title','string','max'=>100],
  17. ['author','string','max'=>10],
  18. ['source','string','max'=>50],
  19. ['describe','string','max'=>255],
  20. ['click','number'],
  21. ['type','number'],
  22. ['hid','number','message'=>'请输入正确的楼盘名称'],
  23. ['click_true','number'],
  24. ['is_show','in','range'=>[1,2]],
  25. ['del','in','range'=>[1,2]],
  26. ];
  27. }
  28. public function attributeLabels()
  29. {
  30. return [
  31. 'hid'=>'楼盘名称',
  32. 'img'=>'缩略图',
  33. 'title'=>'标题',
  34. 'describe'=>'描述',
  35. 'author'=>'作者',
  36. 'click'=>'点击数',
  37. 'source'=>'来源',
  38. 'type'=>'装修风格',
  39. ];
  40. }
  41. public function Clickadd($id)
  42. {
  43. $query = self::findOne($id);
  44. $query->click = ++$query->click;
  45. $query->click_true = ++$query->click_true;
  46. return $query->save();
  47. }
  48. public function FindById($id)
  49. {
  50. return self::findOne($id);
  51. }
  52. public function Authenticator($input)
  53. {
  54. $this->load($input,'');
  55. if($this->validate()) return $this;
  56. return $this->errors;
  57. }
  58. public function getList($page)
  59. {
  60. $query = self::find();
  61. // 'count(pfg_news_renovationcontent.nid) as count',
  62. $query->select(['pfg_house.name','pfg_news_renovation.hid','pfg_news_renovation.title','pfg_news_renovation.is_show','pfg_news_renovation.create_at','pfg_news_renovation.id','pfg_news_renovation.click','pfg_news_renovation.click_true']);
  63. $query->andWhere(['pfg_news_renovation.del'=>$this->setDel]);
  64. $query->andFilterWhere(['like','pfg_news_renovation.title',$this->title]);
  65. if(!empty($page['page']))
  66. {
  67. $query->offset = ($page['page'] - 1) * $page['limit'];
  68. $query->limit = $page['limit'];
  69. }
  70. $query->leftJoin('pfg_house','pfg_news_renovation.hid = pfg_house.id');
  71. // $query->leftJoin('pfg_news_renovationcontent','pfg_news_renovation.id = pfg_news_renovationcontent.nid');
  72. return $query->orderBy(['pfg_news_renovation.create_at'=>SORT_DESC])->asArray()->all();
  73. }
  74. public function getListTotal()
  75. {
  76. $query = self::find();
  77. $query->andWhere(['pfg_news_renovation.del'=>$this->setDel]);
  78. $query->andFilterWhere(['like','pfg_news_renovation.title',$this->title]);
  79. return $query->count();
  80. }
  81. public function PcgetList($page)
  82. {
  83. $query = self::find();
  84. $query->andWhere(['del'=>$this->setDel]);
  85. $query->andWhere(['is_show'=>1]);
  86. $query->select(['title','id','img','click','type']);
  87. if(is_object($page))
  88. {
  89. $query->offset($page->offset);
  90. $query->limit($page->limit);
  91. }
  92. $query->orderBy(['create_at'=>SORT_DESC,'click'=>SORT_DESC,'sort'=>SORT_DESC]);
  93. return $query->asArray()->all();
  94. }
  95. public function PcgetListTotal()
  96. {
  97. $query = self::find();
  98. $query->andWhere(['del'=>$this->setDel]);
  99. $query->andWhere(['is_show'=>1]);
  100. return $query->count();
  101. }
  102. public function RandList($limit,$sele = null)
  103. {
  104. $query = self::find();
  105. $query->andWhere(['del'=>$this->setDel]);
  106. $query->andWhere(['is_show'=>1]);
  107. $query->select($sele);
  108. $query->limit = $limit;
  109. $query->orderBy('RAND()');
  110. return $query->asArray()->all();
  111. }
  112. public function MgetList($page)
  113. {
  114. $query = self::find();
  115. $query->andWhere(['del'=>$this->setDel]);
  116. $query->andWhere(['is_show'=>1]);
  117. $query->select(['title','id','img','click','type']);
  118. if(!empty($page['page']))
  119. {
  120. $query->offset = ($page['page'] - 1) * $page['limit'];
  121. $query->limit = $page['limit'];
  122. }
  123. $query->orderBy(['create_at'=>SORT_DESC,'click'=>SORT_DESC,'sort'=>SORT_DESC]);
  124. return $query->asArray()->all();
  125. }
  126. }