Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
0cc68515
Commit
0cc68515
authored
May 07, 2018
by
zw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
看铺数量控制
parent
f99df0c5
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
127 additions
and
4 deletions
+127
-4
Shop.php
application/api_broker/controller/Shop.php
+15
-2
LookShopService.php
application/api_broker/service/LookShopService.php
+105
-0
RedisExt.php
application/extra/RedisExt.php
+7
-2
No files found.
application/api_broker/controller/Shop.php
View file @
0cc68515
...
...
@@ -3,6 +3,7 @@
namespace
app\api_broker\controller
;
use
app\api_broker\extend\Basic
;
use
app\api_broker\service\LookShopService
;
use
app\api_broker\service\VerifyService
;
use
app\model\AttentionModel
;
use
app\model\GHouses
;
...
...
@@ -207,6 +208,12 @@ class Shop extends Basic
return
$this
->
response
(
"101"
,
"请求来源错误"
);
}
$lookShopService_
=
new
LookShopService
();
//todo 判断看铺数量是否上限
if
(
$lookShopService_
->
isLookShop
(
$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,
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
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.auditorium,b.tiny_brochure_url,b.start_business_date,a.upload_id,b.fee_rule"
;
}
$conditions
[
'a.id'
]
=
array
(
"eq"
,
$params
[
"id"
]
);
$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"
]))
{
$result
[
"start_business_date"
]
=
""
;
...
...
@@ -265,7 +274,11 @@ class Shop extends Basic
$verify
=
new
VerifyService
();
$agentId
=
$verify
->
getPanpartyAgentsByHouseId
(
$params
[
"id"
]);
$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
);
}
...
...
application/api_broker/service/LookShopService.php
0 → 100644
View file @
0cc68515
<?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
application/extra/RedisExt.php
View file @
0cc68515
...
...
@@ -9,7 +9,6 @@ namespace app\extra;
* Time : 13:49
* Intro:
*/
use
think\cache\driver\Redis
;
class
RedisExt
{
...
...
@@ -27,7 +26,13 @@ class RedisExt
'persistent'
=>
false
,
'prefix'
=>
''
,
];
self
::
$_instance
=
new
Redis
(
$config
);
self
::
$_instance
=
new
\Redis
();
self
::
$_instance
->
connect
(
$config
[
"host"
],
$config
[
"port"
],
$config
[
"timeout"
]
);
}
public
static
function
getRedis
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment