Commit 10bbc3d0 authored by hujun's avatar hujun

同步修改开盘缓存

parent 72fb6e35
...@@ -29,6 +29,7 @@ class RedisCacheService ...@@ -29,6 +29,7 @@ class RedisCacheService
private $group_key = 'cache_group_'; private $group_key = 'cache_group_';
private $rule_key = 'cache_rule_'; private $rule_key = 'cache_rule_';
private $site_city_key = 'cache_site_city_'; private $site_city_key = 'cache_site_city_';
private $site_city_all_key = 'cache_site_city_all';
private $label_call_key = 'cache_label_call'; private $label_call_key = 'cache_label_call';
private $group_site_key = 'cache_group_site_'; private $group_site_key = 'cache_group_site_';
private $time; private $time;
...@@ -246,7 +247,7 @@ class RedisCacheService ...@@ -246,7 +247,7 @@ class RedisCacheService
} }
/** /**
* 缓存城市 * 根据id缓存城市
* *
* @param $id * @param $id
* @return false|\PDOStatement|string|\think\Collection * @return false|\PDOStatement|string|\think\Collection
...@@ -261,6 +262,27 @@ class RedisCacheService ...@@ -261,6 +262,27 @@ class RedisCacheService
return $name; return $name;
} }
/**
* 缓存所有城市站点
*
* @return bool|false|mixed|\PDOStatement|string|\think\Collection
* User HuJun
* Date 19-5-9 上午10:00
*/
public function siteAllCityCache()
{
$result = $this->redis_ext->get($this->site_city_all_key);
if (empty($result)) {
$m_auth_rule = new ASite();
$result = $m_auth_rule->getSiteList();
$this->setRedisCache($this->site_city_all_key, $result);
} else {
$result = json_decode($result, true);
}
return $result;
}
/** /**
* 缓存电话标签 * 缓存电话标签
* *
......
...@@ -15,8 +15,8 @@ class SquareSortService ...@@ -15,8 +15,8 @@ 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 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_";
...@@ -40,7 +40,7 @@ class SquareSortService ...@@ -40,7 +40,7 @@ class SquareSortService
//todo 设置排序按评论时间,每次薪的评论进来,先删除掉存在的,插入新的 //todo 设置排序按评论时间,每次薪的评论进来,先删除掉存在的,插入新的
//删除不管key存不存在 //删除不管key存不存在
$look_num = $this->redis->zScore(self::LOOK_NUM_KEY . $site_id, $s_id); $look_num = $this->redis->zScore(self::LOOK_NUM_KEY, $s_id);
$this->redis->zRem(self::SORT_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); $this->redis->zRem(self::SORT_KEY_CREAM . $site_id, $s_id);
if ($look_num > 3) { if ($look_num > 3) {
...@@ -110,13 +110,14 @@ class SquareSortService ...@@ -110,13 +110,14 @@ class SquareSortService
/** /**
* 每个开盘最后评论时间 * 每个开盘最后评论时间
* *
* @param $site_id
* @return array * @return array
* User HuJun * User HuJun
* Date 19-5-7 下午4:38 * Date 19-5-9 上午9:37
*/ */
public function getCommentData() public function getCommentData($site_id)
{ {
$comment_time = $this->redis->zRange(self::SORT_KEY, 0, -1, true); $comment_time = $this->redis->zRange(self::SORT_KEY.$site_id, 0, -1, true);
return $comment_time; return $comment_time;
} }
......
...@@ -94,4 +94,24 @@ class ASite extends BaseModel ...@@ -94,4 +94,24 @@ class ASite extends BaseModel
return $return; return $return;
} }
/**
* @param string $fields
* @param array $where
* @return bool|false|\PDOStatement|string|\think\Collection
* User HuJun
* Date 19-5-9 上午10:00
*/
public function getSiteList($fields = 'id,name,city', $where = [])
{
if (!isset($where['is_del'])) {
$where['is_del'] = 0;
}
try {
$result = $this->field($fields)->where($where)->select();
} catch (\Exception $e) {
$result = false;
}
return $result;
}
} }
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
namespace app\task\controller; namespace app\task\controller;
use app\api_broker\service\RedisCacheService;
use app\api_broker\service\SquareSortService; use app\api_broker\service\SquareSortService;
use app\model\BSquare; use app\model\BSquare;
use app\model\BSquareSort; use app\model\BSquareSort;
...@@ -26,9 +27,17 @@ class SquareTask ...@@ -26,9 +27,17 @@ class SquareTask
* Date 19-5-8 上午10:09 * Date 19-5-8 上午10:09
*/ */
public function squareBackUp() { public function squareBackUp() {
$save_data = $square_id = []; $square_id = $comment_array = [];
$sort_service = new SquareSortService(); $sort_service = new SquareSortService();
$redis_service = new RedisCacheService();
$site_data = $redis_service->siteAllCityCache();
if (empty($site_data)) {
Log::write('获取城市站点失败', 'redis_backUp_square_task'); //记录日志
return ;
}
$look_num = $sort_service->getLookData(); //看盘数量 $look_num = $sort_service->getLookData(); //看盘数量
if ($look_num) { if ($look_num) {
foreach ($look_num as $k=>$v) { foreach ($look_num as $k=>$v) {
...@@ -36,13 +45,29 @@ class SquareTask ...@@ -36,13 +45,29 @@ class SquareTask
} }
} }
$comment = $sort_service->getCommentData();//最后评论时间 foreach ($site_data as $k=>$v) {
if ($comment) { $comment = $sort_service->getCommentData($v['id']);//最后评论时间
foreach ($comment as $k=>$v) { foreach ($comment as $kk=>$vv) {
$square_id[] = $k; $comment_array[$kk]['time'] = $vv;
$comment_array[$kk]['site_id'] = $v['id'];
$square_id[] = $kk;
} }
} }
$this->saveData($square_id, $look_num, $comment_array);
}
/**
* 保存数据
*
* @param $square_id
* @param array $look_num
* @param array $comment_array
* User HuJun
* Date 19-5-9 上午10:39
*/
private function saveData($square_id, $look_num = [], $comment_array = [])
{
if (empty($square_id)) { if (empty($square_id)) {
return ; return ;
} }
...@@ -51,10 +76,12 @@ class SquareTask ...@@ -51,10 +76,12 @@ class SquareTask
sort($square_id); sort($square_id);
try { try {
foreach ($square_id as $k=>$v) { foreach ($square_id as $k=>$v) {
$save_data = [];
if (isset($look_num[$v])) { if (isset($look_num[$v])) {
$save_data['browse_number'] = $look_num[$v]; $save_data['browse_number'] = $look_num[$v];
if ($look_num[$v] >= 500) { // if ($look_num[$v] >= 500) {
if ($look_num[$v] >= 3) {
$square_data = $this->m_square->getSquare('id,is_cream',['id'=>$v]); $square_data = $this->m_square->getSquare('id,is_cream',['id'=>$v]);
//是否是精华帖 0普通 1精华 //是否是精华帖 0普通 1精华
if ($square_data[0]['is_cream'] == 0) { if ($square_data[0]['is_cream'] == 0) {
...@@ -62,11 +89,14 @@ class SquareTask ...@@ -62,11 +89,14 @@ class SquareTask
} }
} }
} }
if (isset($comment[$v])) { if (isset($comment_array[$v])) {
$save_data['last_reply_time'] = date('Y-m-d H:i:s', $comment[$v]); $save_data['last_reply_time'] = date('Y-m-d H:i:s', $comment_array[$v]['time']);
$save_data['site_id'] = $comment_array[$v]['site_id'];
} }
$num = $this->m_sort->getList(1, 1, '', 'id',['square_id'=>$v, 'is_del'=>0]); $where['square_id'] = $v;
$where['is_del'] = 0;
$num = $this->m_sort->getList(1, 1, '', 'id', $where);
if ($num) { if ($num) {
$this->m_sort->updateData($save_data, $num[0]['id']); $this->m_sort->updateData($save_data, $num[0]['id']);
} else { } else {
......
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