Commit 43a59923 authored by clone's avatar clone

1

parent 140845a4
......@@ -14,6 +14,9 @@ class SquareSort
{
private $redis;
private $nowTime;
const SORT_KEY = "sort_by_time_square";
const LOOK_NUM_KEY = "look_num_square";
const LOOK_AGENT_KEY = "_look_agent_square_";
public function __construct()
{
......@@ -21,7 +24,62 @@ class SquareSort
$this->nowTime = date("Y-m-d", time());
}
public function setSortSquareSort(){
/**
* 评论的时候调用 根据评论时间排序
* @param $s_id
* @return bool
*/
public function setSortSquareSort($s_id)
{
if (!$s_id || $s_id <= 0) {
return false;
}
//todo 设置排序按评论时间,每次薪的评论进来,先删除掉存在的,插入新的
$time_ = date("Y-m-d H:i:s", time());
$this->redis->zRem(self::SORT_KEY, $s_id);//删除不管key存不存在
//todo 新增key
$this->redis->zAdd(self::SORT_KEY, $s_id, $time_);
return true;
}
/**
* 开盘广场浏览人数统计
* @param $s_id
* @param $agent_id
* @return bool
*/
public function setCream($s_id, $agent_id)
{
if (!$this->verifyAgentLookSquare($s_id, $agent_id)) {
return false;
}
if ($this->redis->zScore(self::LOOK_NUM_KEY, $s_id)) {
$this->redis->zIncrBy(self::LOOK_NUM_KEY, 1, $s_id);
} else {
//todo 新增key
$this->redis->zAdd(self::LOOK_NUM_KEY, $s_id, 1);
}
return true;
}
/**
* 验证经纪人是否看过此开盘广场
* @param $s_id
* @param $agent_id
* @return bool
*/
private function verifyAgentLookSquare($s_id, $agent_id)
{
if (!$s_id || $s_id <= 0 || !$agent_id || $agent_id <= 0) {
return false;
}
if ($this->redis->get($s_id . self::LOOK_AGENT_KEY . $agent_id)) {
return false;
} else {
$this->redis->set($s_id . self::LOOK_AGENT_KEY . $agent_id, 1);
return true;
}
}
}
\ No newline at end of file
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