Commit 620a9687 authored by clone's avatar clone

保存redis看铺记录到数据库中

parent d60fee15
...@@ -30,7 +30,7 @@ class LookShopService ...@@ -30,7 +30,7 @@ class LookShopService
public function __construct() public function __construct()
{ {
$this->redis = RedisExt::getRedis(); $this->redis = RedisExt::getRedis();
$this->nowTime = date("Y-m-d", time()); $this->nowTime = date("Y-m-d", time());
$this->gHousesToAgentsModel = new GHousesToAgents(); $this->gHousesToAgentsModel = new GHousesToAgents();
$this->agentsModel = new AAgents(); $this->agentsModel = new AAgents();
...@@ -53,7 +53,7 @@ class LookShopService ...@@ -53,7 +53,7 @@ class LookShopService
// todo 4.判断是否到达上限,if 上限 return false else return true // todo 4.判断是否到达上限,if 上限 return false else return true
//redis服务挂掉,都可以看 //redis服务挂掉,都可以看
if(!$this->redis){ if (!$this->redis) {
return []; return [];
} }
//todo 过滤掉店长以上的经纪人 //todo 过滤掉店长以上的经纪人
...@@ -76,6 +76,7 @@ class LookShopService ...@@ -76,6 +76,7 @@ class LookShopService
$lookShopNum = $this->isLookShop($agent_id); $lookShopNum = $this->isLookShop($agent_id);
if ($lookShopNum > 0 && !$isExist && !$isPanParty) { if ($lookShopNum > 0 && !$isExist && !$isPanParty) {
$this->redis->sAdd(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id);//存入楼盘信息 $this->redis->sAdd(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id);//存入楼盘信息
$this->redis->set(self::LOOK_SHOP . $this->nowTime . $agent_id . "_" . $house_id, time());//存入看铺时间
$this->incrementLookNum($agent_id); $this->incrementLookNum($agent_id);
} }
$totalNum = $this->redis->hGet(self::LOOK_UP_NUM . $this->nowTime, $agent_id) * $this->redis->get("lookNum"); $totalNum = $this->redis->hGet(self::LOOK_UP_NUM . $this->nowTime, $agent_id) * $this->redis->get("lookNum");
...@@ -92,7 +93,7 @@ class LookShopService ...@@ -92,7 +93,7 @@ class LookShopService
public function isLooked(int $agent_id, int $house_id): bool public function isLooked(int $agent_id, int $house_id): bool
{ {
//redis服务挂掉,都可以看 //redis服务挂掉,都可以看
if(!$this->redis){ if (!$this->redis) {
return false; return false;
} }
$isExist = $this->redis->sIsMember(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id); $isExist = $this->redis->sIsMember(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id);
...@@ -128,7 +129,7 @@ class LookShopService ...@@ -128,7 +129,7 @@ class LookShopService
public function isLookShop(int $agent_id): int public function isLookShop(int $agent_id): int
{ {
//redis服务挂掉,不显示升级按钮 数量不能为0 //redis服务挂掉,不显示升级按钮 数量不能为0
if(!$this->redis){ if (!$this->redis) {
return 1; return 1;
} }
$lookNum = 50;//默认50看铺数量 $lookNum = 50;//默认50看铺数量
...@@ -164,7 +165,7 @@ class LookShopService ...@@ -164,7 +165,7 @@ class LookShopService
*/ */
public function setLookNum(int $num): bool public function setLookNum(int $num): bool
{ {
if(!$this->redis){ if (!$this->redis) {
return false; return false;
} }
$this->redis->set("lookNum", $num); $this->redis->set("lookNum", $num);
...@@ -178,11 +179,11 @@ class LookShopService ...@@ -178,11 +179,11 @@ class LookShopService
*/ */
public function setAgentLookNum(int $agent_id): bool public function setAgentLookNum(int $agent_id): bool
{ {
if(!$this->redis){ if (!$this->redis) {
return false; return false;
} }
$agentUpNum = $this->redis->hGet(self::LOOK_UP_NUM . $this->nowTime, $agent_id); $agentUpNum = $this->redis->hGet(self::LOOK_UP_NUM . $this->nowTime, $agent_id);
$upLookNum = (int)$agentUpNum + 1; $upLookNum = (int)$agentUpNum + 1;
$this->redis->hSet(self::LOOK_UP_NUM . $this->nowTime, $agent_id, $upLookNum); $this->redis->hSet(self::LOOK_UP_NUM . $this->nowTime, $agent_id, $upLookNum);
return true; return true;
} }
......
...@@ -359,6 +359,28 @@ class AAgents extends BaseModel ...@@ -359,6 +359,28 @@ class AAgents extends BaseModel
->select(); ->select();
} }
/**
* 获取经纪人列表--排掉店子和总监
*
* @param int $pageNo
* @param int $pageSize
* @param string $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsListByLookShop($pageNo = 1, $pageSize = 15, $field = "id")
{
$where["level"] = 10;
return Db::table($this->table)
->field($field)
->where($where)
->limit($pageSize)
->page($pageNo)
->select();
}
/** /**
* 获取经纪人总数 * 获取经纪人总数
* @return int|string * @return int|string
......
<?php
namespace app\model;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/7/30
* Time : 13:27
* Intro:
*/
use think\Db;
use think\Model;
class TLookShopModel extends Model
{
protected $table = "t_look_shop";
private $db_;
function __construct()
{
$this->db_ = Db::name($this->table);
}
public function addLookShop($params)
{
Db::startTrans();
try {
$this->db_->insertAll($params);
Db::commit();
return 1;
} catch (\Exception $e) {
Db::rollback();
return 0;
}
}
}
\ No newline at end of file
...@@ -234,7 +234,7 @@ Route::group('index', [ ...@@ -234,7 +234,7 @@ Route::group('index', [
'checkOver' => [ 'index/Finance/checkOver', [ 'method' => 'POST' ] ], //财务结单 'checkOver' => [ 'index/Finance/checkOver', [ 'method' => 'POST' ] ], //财务结单
'delPartialCommission' => [ 'index/Finance/delPartialCommission', [ 'method' => 'POST' ] ], //删除分佣方 'delPartialCommission' => [ 'index/Finance/delPartialCommission', [ 'method' => 'POST' ] ], //删除分佣方
'delTaxes' => [ 'index/Finance/delTaxes', [ 'method' => 'POST' ] ], //删除开票税费 'delTaxes' => [ 'index/Finance/delTaxes', [ 'method' => 'POST' ] ], //删除开票税费
'getBargainCommission' => [ 'index/Finance/getBargainCommission', [ 'method' => 'GET|POST' ] ], //获取成交报告分佣方佣金和修改 'getBargainCommission' => [ 'index/Finance/getBargainCommission', [ 'method' => 'GET|POST' ] ], //获取成交报告分佣方佣金和修改
'addReceiptImg' => [ 'index/Collection/addReceiptImg', [ 'method' => 'post|get' ] ],//收款图片信息保存 'addReceiptImg' => [ 'index/Collection/addReceiptImg', [ 'method' => 'post|get' ] ],//收款图片信息保存
'deleteReceiptImg' => [ 'index/Collection/deleteReceiptImg', [ 'method' => 'post|get' ] ],//删除收款图片 'deleteReceiptImg' => [ 'index/Collection/deleteReceiptImg', [ 'method' => 'post|get' ] ],//删除收款图片
'receiptImgList' => [ 'index/Collection/receiptImgList', [ 'method' => 'post|get' ] ],//收款列表-收款图片列表 'receiptImgList' => [ 'index/Collection/receiptImgList', [ 'method' => 'post|get' ] ],//收款列表-收款图片列表
...@@ -375,6 +375,8 @@ Route::group('task', [ ...@@ -375,6 +375,8 @@ Route::group('task', [
'updateStatusByTime' => [ 'task/updateShopStatusTask/updateStatusByTime', [ 'method' => 'get' ] ], //修改上下架 'updateStatusByTime' => [ 'task/updateShopStatusTask/updateStatusByTime', [ 'method' => 'get' ] ], //修改上下架
'updateStatusByNum' => [ 'task/updateShopStatusTask/updateStatusByNum', [ 'method' => 'get' ] ], //修改下架根据数量 'updateStatusByNum' => [ 'task/updateShopStatusTask/updateStatusByNum', [ 'method' => 'get' ] ], //修改下架根据数量
'saveLookShop' => [ 'task/SaveLookShopHistoryTask/saveLookShop', [ 'method' => 'get' ] ], //保存看铺记录
'totalAgentResults_new' => [ 'task/ResultsSummaryTask/totalAgentResults', [ 'method' => 'get' ] ], //业绩统计 'totalAgentResults_new' => [ 'task/ResultsSummaryTask/totalAgentResults', [ 'method' => 'get' ] ], //业绩统计
......
...@@ -3,7 +3,11 @@ ...@@ -3,7 +3,11 @@
namespace app\task\controller; namespace app\task\controller;
use app\extra\RedisExt; use app\extra\RedisExt;
use app\model\AAgents;
use app\model\TLookShopModel;
use RedisException; use RedisException;
use think\Exception;
use think\Log;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
...@@ -16,24 +20,106 @@ class SaveLookShopHistoryTask ...@@ -16,24 +20,106 @@ class SaveLookShopHistoryTask
{ {
private $redis; private $redis;
private $date_; private $yesterday;
private $agentsModel;
private $tLookShopModel;
const LOOK_SHOP = "look_shop_";//存入已看的楼盘id const LOOK_SHOP = "look_shop_";//存入已看的楼盘id
const LOOK_TOTAL = "look_total_";//记录每个经纪人的看铺总数 const LOOK_UP_NUM = "look_up_num_";//记录每个经纪人的看铺升级次数
function __construct() function __construct()
{ {
try { $this->redis = RedisExt::getRedis();
$this->redis = RedisExt::getRedis(); $this->yesterday = date("Y-m-d", strtotime("-1 day"));
} catch (RedisException $exception) { $this->agentsModel = new AAgents();
$this->redis = false; $this->tLookShopModel = new TLookShopModel();
}
$this->date_ = date("Y-m-d", strtotime("-1 day"));
} }
public function saveLookShop(){ /**
* 查询经纪人列表
* @return bool
*/
public function saveLookShop()
{
if (!$this->redis) {
return false;
}
$day = date("Y-m-d", time());
if ($this->redis->get("run_save_look" . $day)) {
return false;
}
$this->redis->set("run_save_look" . $day, 1, 24 * 3600);
//todo 1.拿到每个经纪人的看铺记录 2.根据看铺记录统计出已看铺数量,3.根据经纪人id 拿到可看铺总数 //todo 1.拿到每个经纪人的看铺记录 2.根据看铺记录统计出已看铺数量,3.根据经纪人id 拿到可看铺总数
//$this->redis->sAdd(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id);//存入楼盘信息 $total = $this->agentsModel->getAgentsCountByTask();
$pageSize = 100;
$pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$resultArr = $this->agentsModel->getAgentsListByLookShop($pageNo, $pageSize, "id,name,phone");
$this->executeSave($resultArr);
unset($resultArr);
}
}
/**
* 保存看铺记录 清空redis缓存
* @param $resultArr
*/
private function executeSave($resultArr)
{
$list = [];
foreach ($resultArr as $key => $value) {
$agent_id = $value["id"];
$selectKey = self::LOOK_SHOP . $this->yesterday . $agent_id;
$collection = $this->redis->sMembers($selectKey);//存入楼盘信息
foreach ($collection as $item) {
$getLookTimeKey = $selectKey . "_" . $item;
$lookTime = $this->redis->get($getLookTimeKey);
if ($lookTime) {
$lookTime = date("Y-m-d H:i:s", $lookTime);
}
array_push($list, $this->tLookShopBin($agent_id, $value["name"], $value["phone"], $item, $lookTime));
//删除redis缓存
$this->redis->sRem($selectKey, $item);
$this->redis->del($getLookTimeKey);
$this->redis->hDel($this->yesterday, $agent_id);
$this->redis->hDel(self::LOOK_UP_NUM . $this->yesterday, $agent_id);
}
try {
$is_insert = -1;
if (!empty($list)) {
$is_insert = $this->tLookShopModel->addLookShop($list);
}
if ($is_insert == 0) {
Log::record("SaveLookShopHistoryTask--111----executeSave---save error", "info");
}
} catch (Exception $exception) {
Log::record("SaveLookShopHistoryTask---222---executeSave---save error" . $exception, "info");
}
$list = [];
}
unset($list);
}
private function tLookShopBin($agent_id, $agent_name, $agent_phone, $house_id, $look_time)
{
$arrBin = [];
$arrBin["agent_id"] = $agent_id;
$arrBin["agent_name"] = $agent_name;
$arrBin["agent_phone"] = $agent_phone;
$arrBin["house_id"] = $house_id;
$arrBin["look_time"] = $look_time;
$arrBin["create_time"] = date("Y-m-d H:i:s", time());
$arrBin["update_time"] = date("Y-m-d H:i:s", time());
return $arrBin;
} }
} }
\ 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