KnowledgebaseController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?php
  2. namespace wechat\controllers;
  3. use common\models\NewKnowledgelabel;
  4. use common\models\NewsKnowledge;
  5. use common\models\News;
  6. use common\models\PushHousesale;
  7. use wechat\base\CommonController;
  8. use wechat\server\HouseServer;
  9. use Yii;
  10. use yii\widgets\LinkPager;
  11. use yii\helpers\ArrayHelper;
  12. use wechat\base\Help;
  13. class KnowledgebaseController extends CommonController
  14. {
  15. public function actionIndex()
  16. {
  17. $model = new NewKnowledgelabel();
  18. $model->pid =0;
  19. $result =$model->getList([],'id,pid,name',2);
  20. $result = ArrayHelper::toArray($result);
  21. foreach($result as $k=>$v){
  22. $model->pid =$v['id'];
  23. $arr =$model->getList([],'id,pid,name',1);
  24. $arr = ArrayHelper::toArray($arr);
  25. $result[$k]['child']=$arr;
  26. }
  27. return $this->render('index',['result'=>$result]);
  28. }
  29. //列表
  30. public function actionList()
  31. {
  32. $model = new NewKnowledgelabel();
  33. $model->pid =0;
  34. $result =$model->getList([],'id,pid,name',2);
  35. $result = ArrayHelper::toArray($result);
  36. foreach($result as $k=>$v){
  37. $model->pid =$v['id'];
  38. $arr =$model->getList([],'id,pid,name',1);
  39. $arr = ArrayHelper::toArray($arr);
  40. $result[$k]['child']=$arr;
  41. }
  42. return $this->render('list',['result'=>$result]);
  43. }
  44. //获取数据
  45. public function actionGetlist()
  46. {
  47. $model = new NewsKnowledge();
  48. if(Yii::$app->request->get('id') != 0)
  49. {
  50. $model->label_id = Yii::$app->request->get('id');
  51. }
  52. $knowData=$model->getMtitle(Yii::$app->request->get(),'pfg_news_knowledge.id,pfg_news_knowledge.abstract,pfg_news_knowledge.subject,pfg_news_knowledge.thumb,pfg_news_knowledge.abstract,pfg_news_knowledge.source,pfg_news_knowledge.clicks,pfg_news_knowledge.create_at,pfg_new_knowledgelabel.name',1);
  53. foreach($knowData as $k=>$v){
  54. $knowData[$k]['thumb']=json_decode($v['thumb'],true);
  55. $knowData[$k]['create_at']=date("Y-m-d",$v['create_at']);
  56. }
  57. if(!empty($knowData)){
  58. return Help::JsonCode(Help::SUCCESS,'成功',$knowData);
  59. }
  60. return Help::JsonCode(Help::ERROR,'失败');
  61. }
  62. /*获取到导航*/
  63. public function actionGetnav()
  64. {
  65. $model = new NewKnowledgelabel();
  66. if(Yii::$app->request->get('id') != 0)
  67. {
  68. $model->pid = Yii::$app->request->get('id');
  69. }
  70. $result =$model->getList([],'id,pid,name',1);
  71. $result = ArrayHelper::toArray($result);
  72. /* foreach($result as $k=>$v){
  73. $model->pid =$v['id'];
  74. $arr =$model->getList([],'id,pid,name',1);
  75. $arr = ArrayHelper::toArray($arr);
  76. $result[$k]['child']=$arr;
  77. }*/
  78. if(!empty($result)){
  79. return Help::JsonCode(Help::SUCCESS,'成功',$result);
  80. }
  81. return Help::JsonCode(Help::ERROR,'失败');
  82. }
  83. public function actionDetails()
  84. {
  85. $input = Yii::$app->request->get();
  86. $model= new NewsKnowledge();
  87. $row = $model->NewsKnowledgeDetails($input);
  88. if(empty($row)) return $this->goBack();
  89. $newsModel= new News();
  90. $newsClick = $newsModel->Clicks(10);
  91. $hotHouse = $this->HotHouse();
  92. $prev=$this->prev($input);
  93. $next=$this->next($input);
  94. return $this->render('details',['row'=>$row,'newsClick'=>$newsClick,'hotHouse'=>$hotHouse,'prev'=>$prev,'next'=>$next]);
  95. }
  96. /*上一篇*/
  97. public function prev($input)
  98. {
  99. $model= new NewsKnowledge();
  100. $input['mark']='>';
  101. return $model->getPage($input);
  102. }
  103. /*下一篇*/
  104. public function next($input)
  105. {
  106. $model= new NewsKnowledge();
  107. $input['mark']='<';
  108. return $model->getPage($input);
  109. }
  110. private function HotHouse()
  111. {
  112. $model = new PushHousesale();
  113. $model->type = 1;
  114. if(Yii::$app->hostserver->hostId != 0)
  115. {
  116. $model->city = Yii::$app->hostserver->hostId;
  117. }
  118. $rows = $model->Homegetlist(4);
  119. if($rows != null)
  120. {
  121. $zhuti = new \frontend\server\HouseServer();
  122. foreach ($rows as &$val)
  123. {
  124. $val['characteristic'] = $zhuti->Subject( json_decode($val['characteristic']),2);
  125. $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses']. $val['thumb'];
  126. }
  127. return $rows;
  128. }
  129. }
  130. public function actionTools()
  131. {
  132. echo 123456;
  133. exit;
  134. //return $this->render('tools');
  135. }
  136. }