KnowledgebaseController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: xiaofeng
  5. * Date: 2018/4/20
  6. * Time: 上午12:50
  7. */
  8. namespace frontend\controllers;
  9. use common\models\NewKnowledgelabel;
  10. use common\models\NewsKnowledge;
  11. use common\models\News;
  12. use common\models\PushHousesale;
  13. use frontend\base\CommonController;
  14. use frontend\server\HouseServer;
  15. use Yii;
  16. use yii\widgets\LinkPager;
  17. use yii\helpers\ArrayHelper;
  18. use frontend\base\Help;
  19. use linslin\yii2\curl;
  20. class KnowledgebaseController extends CommonController
  21. {
  22. public function actionIndex()
  23. {
  24. // $input = Yii::$app->request->post();
  25. $model = new NewKnowledgelabel();
  26. $model->pid =0;
  27. $result =$model->getList([],'id,pid,name',2);
  28. $result = ArrayHelper::toArray($result);
  29. foreach($result as $k=>$v){
  30. $model->pid =$v['id'];
  31. $arr =$model->getList([],'id,pid,name',1);
  32. $arr = ArrayHelper::toArray($arr);
  33. $result[$k]['child']=$arr;
  34. }
  35. return $this->render('index',['result'=>$result]);
  36. }
  37. public function actionList()
  38. {
  39. $model = new NewKnowledgelabel();
  40. $model->pid =0;
  41. $result =$model->getList([],'id,pid,name',2);
  42. $result = ArrayHelper::toArray($result);
  43. foreach($result as $k=>$v){
  44. $model->pid =$v['id'];
  45. $arr =$model->getList([],'id,pid,name',1);
  46. $arr = ArrayHelper::toArray($arr);
  47. $result[$k]['child']=$arr;
  48. }
  49. $query = $model::find();
  50. $query->select('name');
  51. $query->andWhere(['del'=>1]);
  52. $query->andFilterWhere(['id'=>Yii::$app->request->get('cid')]);
  53. $row = $query->asArray()->one();//单个栏目
  54. $models = new NewsKnowledge();
  55. if(Yii::$app->request->get('cid') != 0)
  56. {
  57. $models->label_id = Yii::$app->request->get('cid');
  58. }
  59. $knowData=$models->getTitle(Yii::$app->request->get(),'id,subject,thumb,abstract,source,clicks,create_at',1);
  60. foreach($knowData['data'] as $k=>$v){
  61. $knowData['data'][$k]['thumb']=json_decode($v['thumb'],true);
  62. $knowData['data'][$k]['create_at']=date("Y-m-d H:i:s",$v['create_at']);
  63. }
  64. $newsModel= new News();
  65. $newsClick = $newsModel->Clicks(10);
  66. return $this->render('list',['result'=>$result,'newsClick'=>$newsClick,'knowData'=>$knowData['data'],'page'=>$knowData['page'],'row'=>$row,]);
  67. }
  68. public function actionGetlist()
  69. {
  70. $model = new NewsKnowledge();
  71. if(Yii::$app->request->get('id') != 0)
  72. {
  73. $model->label_id = Yii::$app->request->get('id');
  74. }
  75. $knowData=$model->getTitle([],'id,subject,thumb,abstract,source,clicks,create_at',1);
  76. foreach($knowData as $k=>$v){
  77. $knowData[$k]['thumb']=json_decode($v['thumb'],true);
  78. $knowData[$k]['create_at']=date("Y-m-d H:i:s",$v['create_at']);
  79. }
  80. if(!empty($knowData)){
  81. return Help::JsonCode(Help::SUCCESS,'成功',$knowData);
  82. }
  83. return Help::JsonCode(Help::ERROR,'失败');
  84. }
  85. public function actionDetails()
  86. {
  87. $input = Yii::$app->request->get();
  88. $model= new NewsKnowledge();
  89. $row = $model->NewsKnowledgeDetails($input);
  90. if(empty($row)) return $this->goBack();
  91. $row['create_at']=date("Y-m-d H:i",$row['create_at']);
  92. $newsModel= new News();
  93. // $newsClick = $newsModel->Clicks(10);
  94. $newsClick = $model->RelevantArticle(['id','subject'],10);
  95. $hotHouse = $this->HotHouse();
  96. //热度关键词
  97. $participle=$this->Participle();
  98. $prev=$this->prev($input);
  99. $next=$this->next($input);
  100. return $this->render('details',['row'=>$row,'newsClick'=>$newsClick,'hotHouse'=>$hotHouse,'participle'=>$participle,'prev'=>$prev,'next'=>$next]);
  101. }
  102. /*上一篇*/
  103. public function prev($input)
  104. {
  105. $model= new NewsKnowledge();
  106. $input['mark']='>';
  107. return $model->getPage($input);
  108. }
  109. /*下一篇*/
  110. public function next($input)
  111. {
  112. $model= new NewsKnowledge();
  113. $input['mark']='<';
  114. return $model->getPage($input);
  115. }
  116. /*分词*/
  117. private function Participle()
  118. {
  119. $model = new NewKnowledgelabel();
  120. $model->pid !=0;
  121. return $model->getList([],'id,pid,name',3);
  122. }
  123. private function HotHouse()
  124. {
  125. $model = new PushHousesale();
  126. $model->type = 1;
  127. if(Yii::$app->hostserver->hostId != 0)
  128. {
  129. $model->city = Yii::$app->hostserver->hostId;
  130. }
  131. $rows = $model->Homegetlist(4);
  132. if($rows != null)
  133. {
  134. $zhuti = new \frontend\server\HouseServer();
  135. foreach ($rows as &$val)
  136. {
  137. $val['characteristic'] = $zhuti->Subject( json_decode($val['characteristic']),2);
  138. $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses']. $val['thumb'];
  139. }
  140. return $rows;
  141. }
  142. }
  143. public function actionTools()
  144. {
  145. return $this->render('tools');
  146. }
  147. }