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
1fa3d745
Commit
1fa3d745
authored
Apr 03, 2019
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
缓存
parent
6ed484d5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
200 additions
and
1 deletion
+200
-1
RedisCacheService.php
application/api_broker/service/RedisCacheService.php
+195
-0
HouseService.php
application/index/service/HouseService.php
+0
-1
ADistrict.php
application/model/ADistrict.php
+5
-0
No files found.
application/api_broker/service/RedisCacheService.php
0 → 100644
View file @
1fa3d745
<?php
/**
* Created by PhpStorm.
* User: 43897
* Date: 2019/4/3
* Time: 10:11
*/
namespace
app\api_broker\service
;
use
app\extra\RedisExt
;
use
app\model\AAgents
;
use
app\model\ADistrict
;
use
app\model\AStore
;
use
app\model\AuthGroup
;
use
app\model\AuthRule
;
use
app\model\Users
;
class
RedisCacheService
{
private
$redis_ext
;
private
$user_key
=
'cache_user_'
;
private
$agent_key
=
'cache_agent_'
;
private
$group_key
=
'cache_group_'
;
private
$rule_key
=
'cache_rule_'
;
private
$time
;
public
function
__construct
()
{
$this
->
redis_ext
=
RedisExt
::
getRedis
();
$this
->
time
=
604800
;
//7天
}
/**
* @param $key
* @param $value
* @param int $time
* @return mixed
*/
public
function
setRedisCache
(
$key
,
$value
,
$time
=
0
)
{
$value
=
json_encode
(
$value
);
$key
=
$this
->
key_string
.
$key
;
if
(
!
$time
)
{
$time
=
$this
->
time
;
}
return
$this
->
redis_ext
->
set
(
$key
,
$value
,
$time
);
}
/**
* @param $key
* @param $value
* @param int $time
* @return mixed
*/
public
function
setRedisHashCache
(
$key
,
$value
,
$time
=
0
)
{
$value
=
json_encode
(
$value
);
$key
=
$this
->
key_string
.
$key
;
if
(
!
$time
)
{
$time
=
$this
->
time
;
}
return
$this
->
redis_ext
->
set
(
$key
,
$value
,
$time
);
}
/**
* 缓存用户信息
*
* @param $user_id
* @return array|false|\PDOStatement|string|\think\Model
*/
public
function
userCache
(
$user_id
)
{
$m_user
=
new
Users
();
$field
=
'id,user_nick,user_name,user_phone,user_pic,other_pic,sex,protect_time,site_ids,agent_id,referrer_id,referrer_source'
;
$field
.=
',is_open,industry_type,price_demand,area_demand,status,source,user_status,registration_time,vip,create_time,first_login_time'
;
$field
.=
',source_intro'
;
$user_data
=
$m_user
->
findByOne
(
$field
,
[
'id'
=>
$user_id
]);
if
(
!
empty
(
$user_data
))
{
$this
->
setRedisCache
(
$this
->
user_key
.
$user_id
,
$user_data
);
}
return
$user_data
;
}
/**
* 缓存经纪人信息
*
* @param $agent_id
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
agentCache
(
$agent_id
)
{
$m_agent
=
new
AAgents
();
$field
=
'id,store_id,auth_group_id,district_id,level,name,phone,img,status,admin_off,site_id'
;
$data
=
$m_agent
->
getAgentInfo
(
$field
,
$agent_id
);
if
(
$data
[
'district_id'
])
{
$m_district
=
new
ADistrict
();
$data
[
'district_name'
]
=
$m_district
->
getDistrictKeyById
(
'district_name'
,
[
'id'
=>
$data
[
'district_id'
]]);
}
else
{
$data
[
'district_name'
]
=
''
;
}
if
(
$data
[
'store_id'
])
{
$m_district
=
new
AStore
();
$data
[
'store_name'
]
=
$m_district
->
getStoreKeyById
(
'store_name'
,
[
'id'
=>
$data
[
'store_id'
]]);
}
else
{
$data
[
'store_name'
]
=
''
;
}
if
(
!
empty
(
$data
))
{
$this
->
setRedisCache
(
$this
->
agent_key
.
$agent_id
,
$data
);
}
return
$data
;
}
public
function
groupCache
(
$group_id
)
{
$m_auth_group
=
new
AuthGroup
();
$field
=
'id,title,rules'
;
$data
=
$m_auth_group
->
getList2
(
'id asc'
,
$field
,
[
'status'
=>
0
,
'id'
=>
$group_id
]);
if
(
!
empty
(
$data
))
{
$this
->
setRedisCache
(
$this
->
group_key
.
$group_id
,
$data
[
0
]);
}
return
$data
;
}
public
function
authCache
(
$rule_id
)
{
$m_auth_rule
=
new
AuthRule
();
$field
=
'id,name,title,pid,is_menu'
;
$data
=
$m_auth_rule
->
getRule
(
$field
,
[
'id'
=>
$rule_id
,
'status'
=>
0
]);
if
(
!
empty
(
$data
))
{
$this
->
setRedisCache
(
$this
->
rule_key
.
$rule_id
,
$data
[
0
]);
}
return
$data
;
}
/**
* @param $type
* @param $id
* @return array|bool|false|mixed|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
getRedisCache
(
$type
,
$id
)
{
if
(
empty
(
$id
))
{
return
false
;
}
switch
(
$type
)
{
case
1
:
$result
=
$this
->
redis_ext
->
get
(
$this
->
user_key
.
$id
);
if
(
empty
(
$result
))
{
$result
=
$this
->
userCache
(
$id
);
}
else
{
$result
=
json_decode
(
$result
,
true
);
}
break
;
case
2
:
$result
=
$this
->
redis_ext
->
get
(
$this
->
agent_key
.
$id
);
if
(
empty
(
$result
))
{
$result
=
$this
->
agentCache
(
$id
);
}
else
{
$result
=
json_decode
(
$result
,
true
);
}
break
;
case
3
:
$result
=
$this
->
redis_ext
->
get
(
$this
->
group_key
.
$id
);
if
(
empty
(
$result
))
{
$result
=
$this
->
groupCache
(
$id
);
}
else
{
$result
=
json_decode
(
$result
,
true
);
}
break
;
case
4
:
$result
=
$this
->
redis_ext
->
get
(
$this
->
rule_key
.
$id
);
if
(
empty
(
$result
))
{
$result
=
$this
->
authCache
(
$id
);
}
else
{
$result
=
json_decode
(
$result
,
true
);
}
break
;
default
:
$result
=
false
;
}
return
$result
;
}
}
\ No newline at end of file
application/index/service/HouseService.php
View file @
1fa3d745
...
...
@@ -733,7 +733,6 @@ die('11111');
$update_data
[
$k
][
'phone'
]
=
$v
[
'phone'
];
$edit_phone
[]
=
substr_replace
(
$phone
,
'****'
,
3
,
4
)
.
'修改为;'
.
substr_replace
(
$v
[
'phone'
],
'****'
,
3
,
4
);
$new_phone
[]
=
$phone
;
$new_phone
[]
=
$old_landlord
[
$v
[
'id'
]];
}
}
else
{
$insert_data
[
$key
][
'phone'
]
=
$v
[
'phone'
];
...
...
application/model/ADistrict.php
View file @
1fa3d745
...
...
@@ -197,8 +197,13 @@ class ADistrict extends BaseModel
/**
* 获取部门
*
* @param $params
* @param $field
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
getDistrict
(
$params
,
$field
)
{
...
...
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