Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
ic_server_welfare
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
584382ea
authored
Aug 27, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修复签到的问题
parent
75e8e44f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
4 additions
and
38 deletions
app/Http/Controllers/CheckInController.php
app/Models/CheckIn.php
app/Http/Controllers/CheckInController.php
View file @
584382ea
...
...
@@ -31,9 +31,7 @@ class CheckInController extends Controller
'add_time'
=>
time
(),
];
$canCheckIn
=
$integral
->
checkIntegralLimit
(
$data
[
'user_id'
],
Integral
::
INTEGRAL_TYPE_CHECK_IN
);
if
(
!
$canCheckIn
)
{
return
$this
->
Export
(
ErrorCode
(
1
,
1
),
'今天已签到,无法再进行签到'
);
}
else
{
if
(
$canCheckIn
)
{
$res
=
$checkIn
->
addCheckIn
(
$data
);
if
(
$res
)
{
return
$this
->
Export
(
0
,
'ok'
);
...
...
@@ -41,5 +39,7 @@ class CheckInController extends Controller
return
$this
->
Export
(
ErrorCode
(
18
,
5
),
'新增签到记录失败'
);
}
}
return
$this
->
Export
(
0
,
'ok'
);
}
}
\ No newline at end of file
app/Models/CheckIn.php
View file @
584382ea
...
...
@@ -53,44 +53,10 @@ class CheckIn extends Model
if
(
!
$result
)
{
return
false
;
}
//添加流水成功后,要把签到记录放到redis
$date
=
Carbon
::
now
()
->
toDateString
();
$hashKey
=
'ic_welfare_integral_limit_'
.
Integral
::
INTEGRAL_TYPE_CHECK_IN
;
$userId
=
$data
[
'user_id'
];
$redis
=
new
RedisModel
();
$redis
->
hincrby
(
$hashKey
,
$userId
,
1
);
return
true
;
});
return
$result
;
}
//判断是否可以签到
public
function
canCheckInFromRedis
(
$userId
)
{
$redis
=
new
RedisModel
();
//先判断 ic_welfare_check_in_日期 在不在,不在的话就添加一个并且给过期时间
$date
=
Carbon
::
now
()
->
toDateString
();
$hashKey
=
'ic_welfare_check_in_'
.
$date
;
$exist
=
$redis
->
exists
(
$hashKey
);
if
(
!
$exist
)
{
//设置晚上12点过期
$todayEndTime
=
Carbon
::
now
()
->
endOfDay
()
->
timestamp
;
$redis
->
expireAt
(
$hashKey
,
$todayEndTime
);
//因为连最基础的键都没有,就代表肯定没有签到过
return
true
;
}
//如果没有,就代表用户今天没有签到
$checkInTime
=
$redis
->
hget
(
$hashKey
,
$userId
);
if
(
!
$checkInTime
)
{
//因为他今天没有签到过,所以本次签到是可以执行的
return
true
;
}
return
false
;
}
}
\ 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