Commit 0cc68515 authored by zw's avatar zw

看铺数量控制

parent f99df0c5
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
namespace app\api_broker\controller; namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\service\LookShopService;
use app\api_broker\service\VerifyService; use app\api_broker\service\VerifyService;
use app\model\AttentionModel; use app\model\AttentionModel;
use app\model\GHouses; use app\model\GHouses;
...@@ -207,6 +208,12 @@ class Shop extends Basic ...@@ -207,6 +208,12 @@ class Shop extends Basic
return $this->response("101", "请求来源错误"); return $this->response("101", "请求来源错误");
} }
$lookShopService_ = new LookShopService();
//todo 判断看铺数量是否上限
if($lookShopService_->isLookShop($this->agentId) == 0){
return $this->response("101", "您今天的看铺数量已达上限!");
}
if ($params['site_area'] == 1) { 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, $field = "a.id,a.external_title as title,a.external_address as address,a.city,a.disc,a.business_district_id,a.status,
a.industry_type,a.shop_area_start,a.shop_area_end,a.shop_type,a.residue_num,a.shop_sign,a.is_carefully_chosen,a.rent_type, a.industry_type,a.shop_area_start,a.shop_area_end,a.shop_type,a.residue_num,a.shop_sign,a.is_carefully_chosen,a.rent_type,
...@@ -221,13 +228,15 @@ class Shop extends Basic ...@@ -221,13 +228,15 @@ class Shop extends Basic
a.rent_price,a.management_fee,a.slotting_fee,a.total,a.market_area,a.is_has_gas,a.file_path,a.longitude,a.latitude, a.rent_price,a.management_fee,a.slotting_fee,a.total,a.market_area,a.is_has_gas,a.file_path,a.longitude,a.latitude,
b.enter_num,b.internal_item_advantage as item_advantage,b.sign_rule,b.do_business_date, b.opening_date,b.traffic, b.enter_num,b.internal_item_advantage as item_advantage,b.sign_rule,b.do_business_date, b.opening_date,b.traffic,
b.auditorium,b.tiny_brochure_url,b.start_business_date,a.upload_id,b.fee_rule"; b.auditorium,b.tiny_brochure_url,b.start_business_date,a.upload_id,b.fee_rule";
} }
$conditions['a.id'] = array( "eq", $params["id"] ); $conditions['a.id'] = array( "eq", $params["id"] );
$result = $this->gHousesModel->getHouseDetailById($field, $conditions); $result = $this->gHousesModel->getHouseDetailById($field, $conditions);
if(count($result) <= 0){
return $this->response("101", '此楼盘不存在');
}
if ($result["start_business_date"] == "0000-00-00 00:00:00" || empty($result["start_business_date"])) { if ($result["start_business_date"] == "0000-00-00 00:00:00" || empty($result["start_business_date"])) {
$result["start_business_date"] = ""; $result["start_business_date"] = "";
...@@ -265,7 +274,11 @@ class Shop extends Basic ...@@ -265,7 +274,11 @@ class Shop extends Basic
$verify = new VerifyService(); $verify = new VerifyService();
$agentId = $verify->getPanpartyAgentsByHouseId($params["id"]); $agentId = $verify->getPanpartyAgentsByHouseId($params["id"]);
$result["panParty"] = $agentId; $result["panParty"] = $agentId;
//todo 计数开始
if($params["site_area"] == 3 && $result){
$lookShopArr = $lookShopService_->countLookShopNum($this->agentId,$params["id"]);
$result["lookShopArr"] = $lookShopArr;
}
return $this->response("200", 'request success', $result); return $this->response("200", 'request success', $result);
} }
......
<?php
namespace app\api_broker\service;
use app\extra\RedisExt;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/5/7
* Time : 上午10:28
* Intro:
*/
class LookShopService
{
private $redis;
private $nowTime;
const LOOK_SHOP = "look_shop_";//存入已看的楼盘id
const LOOK_TOTAL = "look_total_";//记录每个经纪人的看铺总数
public function __construct()
{
$this->redis = RedisExt::getRedis();
$this->nowTime = date("Y-m-d", time());
}
public function countLookShopNum(int $agent_id, int $house_id): array
{
//todo 1.取读控制里面的看铺数量,2.取出此经济人已看数量和商铺 3.判断时间,每天刷新看铺数量
// todo 4.判断是否到达上限,if 上限 return false else return true
$lookShopNum = $this->isLookShop($agent_id);
if ($lookShopNum > 0) {
$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 ];
}
/**
* look shop num +1
* @param int $agent_id
* @return bool
*/
private function incrementLookNum(int $agent_id): bool
{
$residueNum = $this->redis->hGet($this->nowTime, $agent_id);
$residueNum += 1;
$this->redis->hSet($this->nowTime, $agent_id, $residueNum);
return true;
}
/**
* 判断是否可以继续看铺,返回剩余数量
* @param int $agent_id
* @return int
*/
public function isLookShop(int $agent_id): int
{
$lookNum = 0;
if (!$this->redis->get("lookNum")) {
$lookNum = 5;//数据库查询
$this->redis->set("lookNum", $lookNum);
}
if (!$this->redis->hGet($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);
if ($agentLookNum >= $totalNum) { //如果数量为大于等于总数 证明看铺达到上限
return 0;
}
return $totalNum - $agentLookNum;//返回剩余看铺数
}
/**
* 后台修改看铺数量配置,则更改redis数量
* @param int $num
* @return bool
*/
public function setLookNum(int $num): bool
{
$this->redis->set("lookNum", $num);
return true;
}
/**
* 升级经纪人看铺数量
* @param int $agent_id
* @return bool
*/
public function setAgentLookNum(int $agent_id): bool
{
$agentNum = $this->redis->hGet(self::LOOK_TOTAL . $this->nowTime, $agent_id);
$lookNum = $this->redis->get("lookNum");
$upLookNum = (int)$lookNum + (int)$agentNum;
$this->redis->hSet(self::LOOK_TOTAL . $this->nowTime, $agent_id, $upLookNum);
return true;
}
}
\ No newline at end of file
...@@ -9,7 +9,6 @@ namespace app\extra; ...@@ -9,7 +9,6 @@ namespace app\extra;
* Time : 13:49 * Time : 13:49
* Intro: * Intro:
*/ */
use think\cache\driver\Redis;
class RedisExt class RedisExt
{ {
...@@ -27,7 +26,13 @@ class RedisExt ...@@ -27,7 +26,13 @@ class RedisExt
'persistent' => false, 'persistent' => false,
'prefix' => '', 'prefix' => '',
]; ];
self::$_instance = new Redis($config);
self::$_instance = new \Redis();
self::$_instance->connect(
$config["host"],
$config["port"],
$config["timeout"]
);
} }
public static function getRedis() public static function getRedis()
......
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