Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ic_welfare_api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
caec796c
authored
Sep 29, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
解决分享的bug
parent
cd830dc7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
54 additions
and
4 deletions
app/Http/Controllers/ShareController.php
app/Http/Controllers/ShareController.php
View file @
caec796c
...
...
@@ -6,6 +6,8 @@ namespace App\Http\Controllers;
use
App\Services\OfferService
;
use
App\Services\ShareService
;
use
Carbon\Carbon
;
use
Common\Model\RedisModel
;
use
Illuminate\Http\Request
;
class
ShareController
extends
Controller
...
...
@@ -22,17 +24,64 @@ class ShareController extends Controller
public
function
store
(
Request
$request
)
{
//点击分享的用户id
$clickUserId
=
$request
->
user
->
user_id
;
//分享人的user_id
$userId
=
$request
->
get
(
'user_id'
);
$integralId
=
self
::
INTEGRAL_TYPE_SHARE
;
$map
=
[
//这个userId是点击人的用户id
'user_id'
=>
$userId
,
'integral_id'
=>
$integralId
,
];
$result
=
$this
->
service
->
addShare
(
$map
);
if
(
$result
[
'errcode'
]
===
self
::
SUCCESS
)
{
return
$this
->
Export
(
0
,
'ok'
);
//要检测分享,分享是每天每个用户,同一个用户不能够点击自己分享多次
//自己也不能点击自己的分享
if
(
$this
->
checkCanShare
(
$userId
,
$clickUserId
))
{
$result
=
$this
->
service
->
addShare
(
$map
);
if
(
$result
[
'errcode'
]
===
self
::
SUCCESS
)
{
return
$this
->
Export
(
0
,
'ok'
);
}
else
{
return
$this
->
Export
(
self
::
SHARE_FAIL
);
}
}
return
$this
->
Export
(
0
,
'ok'
);
}
//检测是否能够分享
private
function
checkCanShare
(
$userId
,
$clickUserId
)
{
//自己不能点击分享
if
(
$userId
==
$clickUserId
)
{
return
false
;
}
//首先去判断分享缓存是否存在
$redis
=
new
RedisModel
();
$date
=
date
(
'Ymd'
);
$hashKey
=
'ic_welfare_share_'
.
$date
;
$shareList
=
$redis
->
hget
(
$hashKey
,
$userId
);
$shareList
=
json_decode
(
$shareList
,
true
);
//分享历史
if
(
!
$shareList
)
{
//不存在的话,建立一个新的
$shareList
=
[
$clickUserId
];
$redis
->
hset
(
$hashKey
,
$userId
,
json_encode
(
$shareList
));
$endTime
=
Carbon
::
now
()
->
endOfDay
()
->
timestamp
;
$redis
->
expireAt
(
$hashKey
,
$endTime
);
//因为都没有对应的值,那就是代表没有分享过,直接返回可以分享
return
true
;
}
else
{
return
$this
->
Export
(
self
::
SHARE_FAIL
);
//如果在里面,代表已经分享过,返回不能分享了
if
(
in_array
(
$clickUserId
,
$shareList
))
{
return
false
;
}
//不在里面代表今天还没有对该用户的分享链接点击,返回可分享
array_push
(
$shareList
,
$clickUserId
);
$redis
->
hset
(
$hashKey
,
$userId
,
json_encode
(
$shareList
));
return
true
;
}
}
}
\ No newline at end of file
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