Commit 548c4d55 authored by zw's avatar zw

看铺数量控制

parent 3d3083c6
......@@ -546,14 +546,10 @@ class OrderLog extends Basic
$insert_data['scale'] = empty($this->params['scale']) ? 0 : $this->params['scale'];
$data['data']['id'] = $bargain->insertBargain($insert_data);
if ($data['data']['id'] == 0) {
if ($data['data'] == 0) {
$data['code'] = 101;
$data['msg'] = 'Add the failure.';
}
//新增分佣推送
$push = new PushMessageService();
$push->pushBargainCommissionMessage($bargain_data['submit_agent_name'], $this->params['agent_id'], $bargain_data['order_id']);
}
return $this->response($data['code'], $data['msg'], $data['data']);
......
......@@ -31,8 +31,6 @@ class Shop extends Basic
$this->gHousesModel = new GHouses();
$this->gHousesImgModel = new GHousesImgs();
$this->attentionModel = new AttentionModel();
Log::record('info ----shop---------' . $this->agentId, "info");
}
/**
......@@ -211,13 +209,7 @@ class Shop extends Basic
return $this->response("101", "请求来源错误");
}
$lookShopService_ = new LookShopService();
//todo 判断看铺数量是否上限
Log::record('info ----shopdetail-------' . $this->agentId, "info");
if($lookShopService_->isLookShop((int)$this->agentId) == 0){
return $this->response("101", "您今天的看铺数量已达上限!");
}
if ($params['site_area'] == 1) {
$field = "a.id,a.external_title as title,a.external_address as address,a.city,a.disc,a.business_district_id,a.status,
......@@ -279,9 +271,16 @@ class Shop extends Basic
$verify = new VerifyService();
$agentId = $verify->getPanpartyAgentsByHouseId($params["id"]);
$result["panParty"] = $agentId;
$lookShopService_ = new LookShopService();
//todo 计数开始
if($params["site_area"] == 3 && $result){
$lookShopArr = $lookShopService_->countLookShopNum((int)$this->agentId,(int)$params["id"]);
if($lookShopArr["residue_num"] == 0 && !$lookShopArr["isExist"]){
//todo 判断看铺数量是否上限
return $this->response("101", "您今天的看铺数量已达上限!");
}
$result["lookShopArr"] = $lookShopArr;
}
return $this->response("200", 'request success', $result);
......
......@@ -41,7 +41,6 @@ class Basic extends Controller
'broker/login',
'broker/token',
'broker/getShopList',
'broker/getShopDetail',
'broker/getRegions',
'broker/getAddress',
'broker/getBroker',
......
......@@ -3,6 +3,7 @@
namespace app\api_broker\service;
use app\extra\RedisExt;
use think\Log;
/**
* Created by PhpStorm.
......@@ -30,14 +31,32 @@ class LookShopService
{
//todo 1.取读控制里面的看铺数量,2.取出此经济人已看数量和商铺 3.判断时间,每天刷新看铺数量
// todo 4.判断是否到达上限,if 上限 return false else return true
//判断楼盘是否看过,看过了则不判断数量
$isExist = $this->isLooked($agent_id,$house_id);
$lookShopNum = $this->isLookShop($agent_id);
if ($lookShopNum > 0) {
if ($lookShopNum > 0 && !$isExist) {
$this->redis->sAdd(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id);//存入楼盘信息
$this->incrementLookNum($agent_id);
}
$totalNum = $this->redis->hGet(self::LOOK_TOTAL . $this->nowTime, $agent_id);
return [ "total_num" => $totalNum, "residue_num" => $lookShopNum ];
return [ "total_num" => $totalNum, "residue_num" => $lookShopNum ,"isExist"=>$isExist];
}
/**
* 判断是否已经看过,看过返回true 否则 false
* @param int $agent_id
* @param int $house_id
* @return bool
*/
public function isLooked(int $agent_id, int $house_id) : bool {
$isExist = $this->redis->sIsMember(self::LOOK_SHOP . $this->nowTime . $agent_id, $house_id);
if($isExist){
return true;
}else{
return false;
}
}
/**
......@@ -47,8 +66,9 @@ class LookShopService
*/
private function incrementLookNum(int $agent_id): bool
{
$residueNum = $this->redis->hGet($this->nowTime, $agent_id);
$residueNum = (int)$this->redis->hGet($this->nowTime, $agent_id);
$residueNum += 1;
Log::record('info ----look residueNum-------' . $residueNum, "info");
$this->redis->hSet($this->nowTime, $agent_id, $residueNum);
return true;
}
......@@ -60,17 +80,23 @@ class LookShopService
*/
public function isLookShop(int $agent_id): int
{
$lookNum = 0;
if (!$this->redis->get("lookNum")) {
$lookNum = 5;//数据库查询
$this->redis->set("lookNum", $lookNum);
}else{
$lookNum = $this->redis->get("lookNum");
}
if (!$this->redis->hExists($this->nowTime, $agent_id)) { //设置每个经纪人的看铺总数
$this->redis->hSet($this->nowTime, $agent_id, 0); //开始计数
$this->redis->hSet(self::LOOK_TOTAL . $this->nowTime, $agent_id, $lookNum);//总数
}
$agentLookNum = $this->redis->hGet($this->nowTime, $agent_id);
$totalNum = $this->redis->hGet(self::LOOK_TOTAL . $this->nowTime, $agent_id);
$agentLookNum = (int)$this->redis->hGet($this->nowTime, $agent_id);
$totalNum = (int)$this->redis->hGet(self::LOOK_TOTAL . $this->nowTime, $agent_id);
Log::record('info ----look agentLookNum-------' . $agentLookNum, "info");
Log::record('info ----look totalNum-------' . $totalNum, "info");
if ($agentLookNum >= $totalNum) { //如果数量为大于等于总数 证明看铺达到上限
return 0;
}
......
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