Commit a44b7af4 authored by clone's avatar clone

1

parent c2e04aab
...@@ -5,6 +5,7 @@ namespace app\api_broker\controller; ...@@ -5,6 +5,7 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\service\SquareService; use app\api_broker\service\SquareService;
use app\api_broker\service\SquareSortService; use app\api_broker\service\SquareSortService;
use app\model\BSquare;
class Square extends Basic class Square extends Basic
...@@ -62,6 +63,27 @@ class Square extends Basic ...@@ -62,6 +63,27 @@ class Square extends Basic
} }
} }
public function getSquareSortList()
{
$params = $this->params;
/* $params = array(
"page_no" => 1,
"page_size" => 15,
"site_id" => 1,
);*/
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
$siteId = empty($params['site_id']) ? 10001 : $params['site_id'];
$squareSort = new SquareSortService();
$list = $squareSort->getCommentByPage($pageNo, $pageSize, $siteId);
if (count($list) <= 0) {
return $this->response("200", "request null");
}
$result = $this->s_square->getSquareSortList($list);
return $this->response("200", "success", $result);
}
/** /**
* 评论列表 * 评论列表
* @return \think\Response * @return \think\Response
...@@ -113,31 +135,37 @@ class Square extends Basic ...@@ -113,31 +135,37 @@ class Square extends Basic
public function addComment() public function addComment()
{ {
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"level" => 1,//不传是主评论 1是主评论第一级回复 2是第一级回复的回复 "level" => 1,//不传是主评论 1是主评论第一级回复 2是第一级回复的回复
"comment_id" => 1, //主评论ID "comment_id" => 1, //主评论ID
"agent_id_b" => 1, //被回复人的id "agent_id_b" => 1, //被回复人的id
"square_id" => 1, // 开盘id "square_id" => 1, // 开盘id
"author_id" => 1, // 主要做推送 "author_id" => 1, // 主要做推送
);*/ "square_site_id" => 10001,
);*/
$square_id = $params['square_id']; $square_id = $params['square_id'];
$comment = $params['comment']; $comment = $params['comment'];
if (!$square_id || $square_id <= 0 || !$comment) { if (!$square_id || $square_id <= 0 || !$comment) {
return $this->response("101", "开盘编号或评论不能为空"); return $this->response("101", "开盘编号或评论不能为空");
} }
$squareModel = new BSquare();
$square_data = $squareModel->getSquare('id,site_id', ['id' => $square_id]);
if (count($square_data) <= 0) {
return $this->response("101", "不存在此开盘广场");
}
$level = isset($params['level']) ? 0 : $params['level']; $level = isset($params['level']) ? 0 : $params['level'];
switch ($level) { switch ($level) {
case 0: case 0:
if ( !isset($params['author_id'])) { if (!isset($params['author_id'])) {
return $this->response("101", "参数不全"); return $this->response("101", "参数不全");
} }
$result = $this->s_square->addBComment($square_id, $comment, $this->agentId, $this->params['author_id'], $this->agentName); $result = $this->s_square->addBComment($square_id, $comment, $this->agentId, $this->params['author_id'], $this->agentName);
break; break;
case 1: case 1:
case 2: case 2:
if (!isset($params['comment_id']) || !isset($params['agent_id_b']) ) { if (!isset($params['comment_id']) || !isset($params['agent_id_b'])) {
return $this->response("101", "参数不全"); return $this->response("101", "参数不全");
} }
$result = $this->s_square->addBCommentExt($params['comment_id'], $this->agentId, $params['agent_id_b'], $result = $this->s_square->addBCommentExt($params['comment_id'], $this->agentId, $params['agent_id_b'],
...@@ -149,7 +177,7 @@ class Square extends Basic ...@@ -149,7 +177,7 @@ class Square extends Basic
if ($result) { if ($result) {
$squareSort = new SquareSortService(); $squareSort = new SquareSortService();
$squareSort->setSortSquareSort($square_id); $squareSort->setSortSquareSort($square_id, $square_data[0]["site_id"]);
return $this->response("200", "成功", $result); return $this->response("200", "成功", $result);
} else { } else {
return $this->response("101", "保存失败"); return $this->response("101", "保存失败");
......
...@@ -135,6 +135,14 @@ class SquareService ...@@ -135,6 +135,14 @@ class SquareService
return ['data' => $res, 'total' => $res_total]; return ['data' => $res, 'total' => $res_total];
} }
public function getSquareSortList($list)
{
dump($list);
// $square_data = $this->m_square->getSquare('id,is_cream',['id'=>$v]);
// return $result;
}
/** /**
* 评论列表 * 评论列表
* @param $params * @param $params
......
...@@ -15,6 +15,7 @@ class SquareSortService ...@@ -15,6 +15,7 @@ class SquareSortService
private $redis; private $redis;
private $nowTime; private $nowTime;
const SORT_KEY = "sort_by_time_square"; const SORT_KEY = "sort_by_time_square";
const SORT_KEY_CREAM = "sort_by_time_square_cream";
const LOOK_NUM_KEY = "look_num_square"; const LOOK_NUM_KEY = "look_num_square";
const LOOK_AGENT_KEY = "_look_agent_square_"; const LOOK_AGENT_KEY = "_look_agent_square_";
...@@ -27,17 +28,25 @@ class SquareSortService ...@@ -27,17 +28,25 @@ class SquareSortService
/** /**
* 评论的时候调用 根据评论时间排序 * 评论的时候调用 根据评论时间排序
* @param $s_id * @param $s_id
* @param $site_id
* @return bool * @return bool
*/ */
public function setSortSquareSort($s_id) public function setSortSquareSort($s_id, $site_id)
{ {
if (!$s_id || $s_id <= 0) { if (!$s_id || $s_id <= 0) {
return false; return false;
} }
//todo 设置排序按评论时间,每次薪的评论进来,先删除掉存在的,插入新的 //todo 设置排序按评论时间,每次薪的评论进来,先删除掉存在的,插入新的
$this->redis->zRem(self::SORT_KEY, $s_id);//删除不管key存不存在 //删除不管key存不存在
//todo 新增key
$this->redis->zAdd(self::SORT_KEY, time(), $s_id); $look_num = $this->redis->zScore(self::LOOK_NUM_KEY . $site_id, $s_id);
$this->redis->zRem(self::SORT_KEY . $site_id, $s_id);
$this->redis->zRem(self::SORT_KEY_CREAM . $site_id, $s_id);
if ($look_num > 500) {
$this->redis->zAdd(self::SORT_KEY_CREAM . $site_id, time(), $s_id);
} else {
$this->redis->zAdd(self::SORT_KEY . $site_id, time(), $s_id);
}
return true; return true;
} }
...@@ -89,8 +98,9 @@ class SquareSortService ...@@ -89,8 +98,9 @@ class SquareSortService
* User HuJun * User HuJun
* Date 19-5-7 下午4:37 * Date 19-5-7 下午4:37
*/ */
public function getLookData() { public function getLookData()
$look_num = $this->redis->zRange(self::LOOK_NUM_KEY, 0, -1,true); {
$look_num = $this->redis->zRange(self::LOOK_NUM_KEY, 0, -1, true);
return $look_num; return $look_num;
} }
...@@ -101,8 +111,46 @@ class SquareSortService ...@@ -101,8 +111,46 @@ class SquareSortService
* User HuJun * User HuJun
* Date 19-5-7 下午4:38 * Date 19-5-7 下午4:38
*/ */
public function getCommentData() { public function getCommentData()
{
$comment_time = $this->redis->zRange(self::SORT_KEY, 0, -1, true); $comment_time = $this->redis->zRange(self::SORT_KEY, 0, -1, true);
return $comment_time; return $comment_time;
} }
/**
* 分页查询开盘广场列表
* @param $page_no
* @param $page_size
* @param $site_id
* @return array
*/
public function getCommentByPage($page_no, $page_size, $site_id)
{
//todo 先查精华的总数,再查普通的总数 当总数和不足size 则返回全部,精华总数多余size则分页查,不足分页计算出剩余数目
$cream_num = $this->redis->zCard(self::SORT_KEY_CREAM . $site_id);
$num = $this->redis->zCard(self::SORT_KEY . $site_id);
$total = $cream_num + $num;
$index_min = ($page_no - 1) * $page_size;
$index_max = $page_no * $page_size;
$result = [];
if ($total <= $page_size) {
$cream_list = $this->redis->zRange(self::SORT_KEY_CREAM . $site_id, 0, -1, true);
$list = $this->redis->zRange(self::SORT_KEY . $site_id, 0, -1, true);
$result = array_merge($cream_list, $list);
} elseif ($index_min <= $cream_num && $index_max <= $cream_num) {
$cream_list = $this->redis->zRange(self::SORT_KEY_CREAM . $site_id, $index_min, $page_size, true);
$result = $cream_list;
} elseif ($index_min <= $cream_num && $index_max > $cream_num) {
$residue = $index_max - $cream_num;
$cream_list = $this->redis->zRange(self::SORT_KEY_CREAM . $site_id, $index_min, -1, true);
$list = $this->redis->zRange(self::SORT_KEY . $site_id, 0, $residue, true);
$result = array_merge($cream_list, $list);
} elseif ($index_min > $cream_num) {
$index_ = $index_min - $cream_num;
$list = $this->redis->zRange(self::SORT_KEY . $site_id, $index_, $page_size, true);
$result = $list;
}
return $result;
}
} }
\ No newline at end of file
...@@ -888,6 +888,7 @@ Route::group('broker', [ ...@@ -888,6 +888,7 @@ Route::group('broker', [
'editCommenSort' => [ 'api_broker/Square/editCommenSort', [ 'method' => 'GET|POST' ] ], 'editCommenSort' => [ 'api_broker/Square/editCommenSort', [ 'method' => 'GET|POST' ] ],
'getDistrictLable' => [ 'api_broker/Square/getDistrictLable', [ 'method' => 'GET|POST' ] ], 'getDistrictLable' => [ 'api_broker/Square/getDistrictLable', [ 'method' => 'GET|POST' ] ],
'delSquare' => [ 'api_broker/Square/delSquare', [ 'method' => 'GET|POST' ] ], 'delSquare' => [ 'api_broker/Square/delSquare', [ 'method' => 'GET|POST' ] ],
'getSquareSortList' => [ 'api_broker/Square/getSquareSortList', [ 'method' => 'GET|POST' ] ],
'getAgentDistrictId' => [ 'api_broker/Broker/getAgentDistrictId', [ 'method' => 'GET|POST' ] ], 'getAgentDistrictId' => [ 'api_broker/Broker/getAgentDistrictId', [ 'method' => 'GET|POST' ] ],
......
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