123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- /**
- * Created by PhpStorm.
- * User: xiaofeng
- * Date: 2018/4/20
- * Time: 上午12:50
- */
- namespace frontend\controllers;
- use common\models\NewKnowledgelabel;
- use common\models\NewsKnowledge;
- use common\models\News;
- use common\models\PushHousesale;
- use frontend\base\CommonController;
- use frontend\server\HouseServer;
- use Yii;
- use yii\widgets\LinkPager;
- use yii\helpers\ArrayHelper;
- use frontend\base\Help;
- use linslin\yii2\curl;
- class KnowledgebaseController extends CommonController
- {
- public function actionIndex()
- {
- // $input = Yii::$app->request->post();
- $model = new NewKnowledgelabel();
- $model->pid =0;
- $result =$model->getList([],'id,pid,name',2);
- $result = ArrayHelper::toArray($result);
- foreach($result as $k=>$v){
- $model->pid =$v['id'];
- $arr =$model->getList([],'id,pid,name',1);
- $arr = ArrayHelper::toArray($arr);
- $result[$k]['child']=$arr;
- }
- return $this->render('index',['result'=>$result]);
- }
- public function actionList()
- {
- $model = new NewKnowledgelabel();
- $model->pid =0;
- $result =$model->getList([],'id,pid,name',2);
- $result = ArrayHelper::toArray($result);
- foreach($result as $k=>$v){
- $model->pid =$v['id'];
- $arr =$model->getList([],'id,pid,name',1);
- $arr = ArrayHelper::toArray($arr);
- $result[$k]['child']=$arr;
- }
- $query = $model::find();
- $query->select('name');
- $query->andWhere(['del'=>1]);
- $query->andFilterWhere(['id'=>Yii::$app->request->get('cid')]);
- $row = $query->asArray()->one();//单个栏目
-
- $models = new NewsKnowledge();
- if(Yii::$app->request->get('cid') != 0)
- {
- $models->label_id = Yii::$app->request->get('cid');
- }
- $knowData=$models->getTitle(Yii::$app->request->get(),'id,subject,thumb,abstract,source,clicks,create_at',1);
- foreach($knowData['data'] as $k=>$v){
- $knowData['data'][$k]['thumb']=json_decode($v['thumb'],true);
- $knowData['data'][$k]['create_at']=date("Y-m-d H:i:s",$v['create_at']);
- }
- $newsModel= new News();
- $newsClick = $newsModel->Clicks(10);
- return $this->render('list',['result'=>$result,'newsClick'=>$newsClick,'knowData'=>$knowData['data'],'page'=>$knowData['page'],'row'=>$row,]);
- }
- public function actionGetlist()
- {
- $model = new NewsKnowledge();
- if(Yii::$app->request->get('id') != 0)
- {
- $model->label_id = Yii::$app->request->get('id');
- }
- $knowData=$model->getTitle([],'id,subject,thumb,abstract,source,clicks,create_at',1);
- foreach($knowData as $k=>$v){
- $knowData[$k]['thumb']=json_decode($v['thumb'],true);
- $knowData[$k]['create_at']=date("Y-m-d H:i:s",$v['create_at']);
- }
- if(!empty($knowData)){
- return Help::JsonCode(Help::SUCCESS,'成功',$knowData);
- }
- return Help::JsonCode(Help::ERROR,'失败');
- }
- public function actionDetails()
- {
- $input = Yii::$app->request->get();
- $model= new NewsKnowledge();
- $row = $model->NewsKnowledgeDetails($input);
- if(empty($row)) return $this->goBack();
- $row['create_at']=date("Y-m-d H:i",$row['create_at']);
- $newsModel= new News();
-
- // $newsClick = $newsModel->Clicks(10);
- $newsClick = $model->RelevantArticle(['id','subject'],10);
- $hotHouse = $this->HotHouse();
- //热度关键词
-
- $participle=$this->Participle();
-
- $prev=$this->prev($input);
- $next=$this->next($input);
- return $this->render('details',['row'=>$row,'newsClick'=>$newsClick,'hotHouse'=>$hotHouse,'participle'=>$participle,'prev'=>$prev,'next'=>$next]);
- }
- /*上一篇*/
- public function prev($input)
- {
- $model= new NewsKnowledge();
- $input['mark']='>';
- return $model->getPage($input);
- }
- /*下一篇*/
- public function next($input)
- {
- $model= new NewsKnowledge();
- $input['mark']='<';
- return $model->getPage($input);
- }
-
- /*分词*/
- private function Participle()
- {
- $model = new NewKnowledgelabel();
- $model->pid !=0;
- return $model->getList([],'id,pid,name',3);
-
- }
- private function HotHouse()
- {
- $model = new PushHousesale();
- $model->type = 1;
- if(Yii::$app->hostserver->hostId != 0)
- {
- $model->city = Yii::$app->hostserver->hostId;
- }
- $rows = $model->Homegetlist(4);
- if($rows != null)
- {
- $zhuti = new \frontend\server\HouseServer();
- foreach ($rows as &$val)
- {
- $val['characteristic'] = $zhuti->Subject( json_decode($val['characteristic']),2);
- $val['thumb'] = Yii::$app->params['httpImg']['hosts'].Yii::$app->params['httpImg']['houses']. $val['thumb'];
- }
- return $rows;
- }
- }
- public function actionTools()
- {
- return $this->render('tools');
- }
- }
|