NewsServer.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/22
  6. * Time: 下午6:20
  7. */
  8. namespace frontend\server;
  9. use Yii;
  10. use common\models\News;
  11. use common\models\CategoryNews;
  12. use common\models\PushNews;
  13. use common\models\PushCharacteristic;
  14. use common\models\House;
  15. class NewsServer
  16. {
  17. /*
  18. * 新闻资讯首页-推送部分
  19. * */
  20. public function Pushinfo($type)
  21. {
  22. $pushModel = new PushNews();
  23. $pushModel->type = $type;
  24. switch ($type)
  25. {
  26. case 1:
  27. $limit = 3; //
  28. break;
  29. case 2:
  30. $limit = 5;
  31. break;
  32. case 3:
  33. $limit = 2;
  34. break;
  35. default:
  36. return false;
  37. break;
  38. }
  39. $arr = $pushModel->Homegetlist($limit);
  40. return $arr;
  41. }
  42. /*
  43. * 资讯首页- 资讯栏目 and 资讯栏目所属资讯
  44. * */
  45. public function ColumnInfo()
  46. {
  47. $model = new CategoryNews();
  48. return $model->getList([],['news_name','id'],1);
  49. }
  50. /*
  51. * 热点直达
  52. * */
  53. public function hotArrive()
  54. {
  55. $ctype = new \common\models\PushCharacteristic();
  56. return $ctype->Homegetlist(10);
  57. }
  58. /*
  59. * 点击量 -- 热文
  60. * */
  61. public function clickList($num)
  62. {
  63. $model = new News();
  64. return $model->Clicks($num);
  65. }
  66. /*
  67. * 资讯详情
  68. * */
  69. public function NewsDetails($input)
  70. {
  71. $model = new News();
  72. if(is_numeric($input['nid']))
  73. {
  74. $info = $model->FindById($input['nid']);
  75. if(!empty($info))
  76. {
  77. $ip = new IpServer();
  78. $ipaddress = $ip->add();
  79. if($ipaddress === true)
  80. {
  81. $info->true_click = ++$info->true_click;
  82. $info->clicks = ++$info->clicks;
  83. $info->save(false);
  84. }
  85. return $info;
  86. }
  87. }
  88. }
  89. /*
  90. * 相关资讯
  91. * */
  92. public function Relevant($category)
  93. {
  94. $model = new News();
  95. $model->category = $category;
  96. return $model->Clicks(4);
  97. }
  98. /*
  99. * 根据区域,随机推荐楼盘
  100. * */
  101. public function NewsCityHouse($city)
  102. {
  103. $model = new House();
  104. $model->city = $city;
  105. return $model->randList(4);
  106. }
  107. /*
  108. * 获取最新资讯
  109. */
  110. public function GetNews($limit)
  111. {
  112. $model = new News();
  113. $query = $model::find();
  114. $query->select(['pfg_news.id','pfg_news.subject','pfg_news.create_at','pfg_category_news.news_name']);
  115. $query->andWhere(['pfg_news.del'=>1,'pfg_news.state'=>1]);
  116. $query->leftJoin('pfg_category_news','pfg_news.category = pfg_category_news.id');
  117. $query->limit = $limit;
  118. $query->orderBy(['pfg_news.create_at'=>SORT_DESC,'pfg_news.id'=>SORT_DESC]);
  119. return $query->asArray()->all();
  120. }
  121. }