Commit 57e817f3 authored by hujun's avatar hujun

开盘redis

parent 5515a564
......@@ -35,10 +35,9 @@ class SquareSortService
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, $time_, $s_id);
$this->redis->zAdd(self::SORT_KEY, time(), $s_id);
return true;
}
......@@ -82,4 +81,28 @@ class SquareSortService
return true;
}
}
/**
* 每个开盘浏览统计(UV)
*
* @return array
* User HuJun
* Date 19-5-7 下午4:37
*/
public function getLookData() {
$look_num = $this->redis->zRange(self::LOOK_NUM_KEY, 0, -1,true);
return $look_num;
}
/**
* 每个开盘最后评论时间
*
* @return array
* User HuJun
* Date 19-5-7 下午4:38
*/
public function getCommentData() {
$comment_time = $this->redis->zRange(self::SORT_KEY, 0, -1, true);
return $comment_time;
}
}
\ No newline at end of file
<?php
namespace app\model;
use think\Db;
class BSquareSort extends BaseModel
{
protected $table = "b_square_sort";
private $db_;
public function __construct()
{
$this->db_ = Db::name($this->table);
}
/**
* 更新数据
*
* @param $data
* @param $id
* @param array $where
* @return mixed
* User HuJun
* Date 19-5-7 下午5:54
*/
public function updateData($data, $id, $where = []) {
if ($id > 0) {
$where['id'] = $id;
}
return $this->db_->where($where)->upate($data);
}
/**
* 插入数据
*
* @param $data
* @return int|string
* User HuJun
* Date 19-5-7 下午5:54
*/
public function insertData($data) {
return $this->db_->insert($data);
}
}
\ No newline at end of file
......@@ -633,6 +633,7 @@ Route::group('task', [
'moveFollowUpList' => ['task/FollowUpTask/moveFollowUpList', ['method' => 'get']],
'frostAgent' => ['task/FrostAgentTask/frostAgent', ['method' => 'get']],
'squareBackUp' => ['task/squareBackUp/readRedis', ['method' => 'get']],
'updateActivityStatus' => ['task/UpdateActivityTask/updateActivityStatus', ['method' => 'get']],
......
<?php
namespace app\task\controller;
use app\api_broker\service\SquareSortService;
use app\model\BSquare;
use app\model\BSquareSort;
class SquareTask
{
private $m_sort;
private $m_square;
public function __construct()
{
$this->m_sort = new BSquareSort();
$this->m_square = new BSquare();
}
public function squareBackUp() {
$save_data = $square_id = [];
$sort_service = new SquareSortService();
$look_num = $sort_service->getLookData(); //看盘数量
foreach ($look_num as $k=>$v) {
$square_id[] = $k;
}
$comment = $sort_service->getCommentData();//最后评论时间
foreach ($comment as $k=>$v) {
$square_id[] = $k;
}
if (empty($square_id)) {
return ;
}
$square_id = array_unique($square_id);
sort($square_id);
foreach ($square_id as $k=>$v) {
if (isset($look_num[$v])) {
$save_data['browse_number'] = $look_num[$v];
if ($look_num[$v] >= 500) {
$square_data = $this->m_square->getSquare('id,is_cream',['id'=>$v]);
//是否是精华帖 0普通 1精华
if ($square_data[0]['is_cream'] == 0) {
$this->m_square->updateStatus(['id'=>$v], ['is_cream'=>1]);
}
}
}
if (isset($comment[$v])) {
$save_data['last_reply_time'] = date('Y-m-d H:i:s', $comment[$v]);
}
$num = $this->m_sort->getList(1, 1, '', 'id',['square_id'=>$v, 'is_del'=>0]);
if ($num) {
$this->m_sort->updateData($save_data, $num[0]['id']);
} else {
$save_data['square_id'] = $v;
$this->m_sort->insertData($save_data);
}
}
}
}
\ 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