Commit fa4ccfee authored by hujun's avatar hujun

评论列表

parent 13395d74
...@@ -8,9 +8,10 @@ ...@@ -8,9 +8,10 @@
namespace app\api_broker\controller; namespace app\api_broker\controller;
use app\index\extend\Basic; use app\api_broker\extend\Basic;
use app\model\SLabel; use app\model\SLabel;
use app\model\SNews; use app\model\SNews;
use app\model\SNewsComment;
use think\Request; use think\Request;
class News extends Basic class News extends Basic
...@@ -34,10 +35,6 @@ class News extends Basic ...@@ -34,10 +35,6 @@ class News extends Basic
*/ */
public function index() public function index()
{ {
if (!$this->request->isAjax()) {
return view('index');
}
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo']; $pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize']; $pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
...@@ -63,7 +60,7 @@ class News extends Basic ...@@ -63,7 +60,7 @@ class News extends Basic
$field = 'a.id,a.title,a.content,a.create_time,b.name,c.label_name,a.cover_plan'; $field = 'a.id,a.title,a.content,a.create_time,b.name,c.label_name,a.cover_plan';
$where['a.status'] = 0; $where['a.status'] = 0;
$data['list'] = $this->m_news->getListAgent($pageNo, $pageSize, 'id DESC', $field, $where); $data['list'] = $this->m_news->getListAgent($pageNo, $pageSize, 'a.id DESC', $field, $where);
$data['total'] = $this->m_news->getListAgentTotal($where); $data['total'] = $this->m_news->getListAgentTotal($where);
return $this->response(200, "", $data); return $this->response(200, "", $data);
} }
...@@ -82,7 +79,39 @@ class News extends Basic ...@@ -82,7 +79,39 @@ class News extends Basic
return $this->response(101, "Id is null."); return $this->response(101, "Id is null.");
} }
$data = $this->m_news->getNewsInfo('id,title,s_label_id,cover_plan,content'); $comment = new SNewsComment();
$data['news'] = $this->m_news->getNewsInfo('id,title,s_label_id,cover_plan,content');
$field = 'a.id,a.comment_content,a.create_time,b.name,b.img';
$where['a.s_news_id'] = $this->params['id'];
$where['a.status'] = 0;
$data['comment'] = $comment->getListAgent(1, 3, 'a.id DESC', $field, $where);
return $this->response(200, "", $data);
}
/**
* 评论列表
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getComment()
{
if (empty($this->params['news_id'])) {
return $this->response(101, "参数错误");
}
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 10 : $this->params['pageSize'];
$comment = new SNewsComment();
$field = 'a.id,a.comment_content,a.create_time,b.name,b.img';
$where['a.s_news_id'] = $this->params['news_id'];
$where['a.status'] = 0;
$data = $comment->getListAgent($pageNo, $pageSize, 'a.id DESC', $field, $where);
return $this->response(200, "", $data); return $this->response(200, "", $data);
} }
...@@ -94,9 +123,43 @@ class News extends Basic ...@@ -94,9 +123,43 @@ class News extends Basic
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getNewsLabel() { public function getNewsLabel()
{
$label = new SLabel(); $label = new SLabel();
$data = $label->getList(1, 200, '', 'id,label_name', ['status'=>0]); $data = $label->getList(1, 200, '', 'id,label_name', [ 'status' => 0 ]);
return $this->response(200, '', $data); return $this->response(200, '', $data);
} }
/**
* 评论文章
*
* @return \think\Response
*/
public function commentNews()
{
if (empty($this->params['news_id'])) {
return $this->response(101, '文章参数错误');
}
if (empty($this->params['content'])) {
return $this->response(101, '文章内容为空');
}
$data['agent_id'] = $this->agentId;
$data['s_news_id'] = $this->params['news_id'];
$data['comment_content'] = $this->params['comment_content'];
$data['status'] = 0;
$m_new_comment = new SNewsComment();
$num = $m_new_comment->editData($data);
if ($num > 0) {
$news = new SNews();
$news->setCommentNumber($this->params['news_id']);
return $this->response(200, '评论成功');
}
return $this->response(101, '评论失败');
}
} }
\ No newline at end of file
...@@ -72,4 +72,16 @@ class SNews extends BaseModel ...@@ -72,4 +72,16 @@ class SNews extends BaseModel
$data['cover_plan'] = CURRENT_URL . 'static/business_school/' . $data['cover_plan']; $data['cover_plan'] = CURRENT_URL . 'static/business_school/' . $data['cover_plan'];
return $data; return $data;
} }
/**
* 增加评论数
*
* @param $id
* @return int
*/
public function setCommentNumber($id) {
$comment_number = $this->where('id',$id)->value('comment_number');
$comment_number += 1;
return $this->where('id', $id)->setField('comment_number', $comment_number);
}
} }
\ No newline at end of file
<?php
/**
* Created by PhpStorm.
* User: fuju
* Date: 2018/7/3
* Time: 17:35
*/
namespace app\model;
class SNewsComment extends BaseModel
{
/**
* 商学院列表
*
* @param int $pageNo
* @param int $pageSize
* @param string $order_
* @param string $field
* @param string $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getListAgent($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '')
{
$data = $this->field($field)
->alias('a')
->join('a_agents b', 'a.agent_id = b.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
foreach ($data as $k=>$v) {
if (isset($v['img'])) {
$data[$k]['img'] = AGENTHEADERIMGURL . $v['img'];
}
}
return $data;
}
/**
* 商学院列表总数
*
* @param $params
* @return int|string
*/
public function getListAgentTotal($params)
{
return $this->alias('a')
->join('a_agents b', 'a.publisher_id = b.id', 'left')
->where($params)
->count();
}
}
\ No newline at end of file
...@@ -493,7 +493,8 @@ Route::group('broker', [ ...@@ -493,7 +493,8 @@ Route::group('broker', [
'uploadImg' => [ 'api_broker/UploadImg/uploadImg', [ 'method' => 'POST|GET' ] ], //图片上传 'uploadImg' => [ 'api_broker/UploadImg/uploadImg', [ 'method' => 'POST|GET' ] ], //图片上传
'business_school' => [ 'api_broker/news/index', [ 'method' => 'GET' ] ], //商学院资讯列表 'business_school' => [ 'api_broker/news/index', [ 'method' => 'GET' ] ], //商学院资讯列表
'getNewsInfo' => [ 'api_broker/news/getNewsInfo', [ 'method' => 'GET' ] ], //商学院资讯详情 'getNewsInfo' => [ 'api_broker/news/getNewsInfo', [ 'method' => 'GET' ] ], //商学院资讯详情
'getNewsLabel' => [ 'api_broker/news/getNewsLabel', [ 'method' => 'GET' ] ], //商学院资标签 'getNewsLabel' => [ 'api_broker/news/getNewsLabel', [ 'method' => 'GET' ] ], //商学院标签
'getComment' => [ 'api_broker/news/getComment', [ 'method' => 'GET' ] ], //商学院评论列表
]); ]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment