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
5d5627ee
authored
Aug 26, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改签到部分的逻辑
parent
2e21ca92
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
43 additions
and
8 deletions
app/Http/Controllers/CheckInController.php
app/Models/CheckIn.php
app/Models/Integral.php
storage/laravels.json
storage/laravels.pid
app/Http/Controllers/CheckInController.php
View file @
5d5627ee
...
...
@@ -14,7 +14,6 @@ use Illuminate\Support\Facades\DB;
class
CheckInController
extends
Controller
{
public
function
index
(
Request
$request
,
CheckIn
$checkIn
,
CheckInFilter
$filter
)
{
$page
=
$request
->
has
(
'page'
)
?
$request
->
page
:
self
::
DEFAULT_PAGE
;
...
...
@@ -25,13 +24,13 @@ class CheckInController extends Controller
return
$this
->
Export
(
0
,
'ok'
,
$checkIns
);
}
public
function
store
(
Request
$request
,
CheckIn
$checkIn
)
public
function
store
(
Request
$request
,
CheckIn
$checkIn
,
Integral
$integral
)
{
$data
=
[
'user_id'
=>
$request
->
user_id
,
'add_time'
=>
time
(),
];
$canCheckIn
=
$
checkIn
->
canCheckInFromRedis
(
$data
[
'user_id'
]
);
$canCheckIn
=
$
integral
->
checkIntegralLimit
(
$data
[
'user_id'
],
CheckIn
::
INTEGRAL_TYPE_CHECK_IN
);
if
(
!
$canCheckIn
)
{
return
$this
->
Export
(
ErrorCode
(
1
,
1
),
'今天已签到,无法再进行签到'
);
}
else
{
...
...
app/Models/CheckIn.php
View file @
5d5627ee
...
...
@@ -18,7 +18,7 @@ class CheckIn extends Model
protected
$table
=
'check_in'
;
public
$timestamps
=
false
;
const
INTEGRAL_TYPE_CHECK_IN
=
4
;
const
INTEGRAL_TYPE_CHECK_IN
=
1
;
public
function
scopePage
(
$query
,
$page
=
1
,
$pageSize
=
10
)
{
...
...
@@ -57,10 +57,10 @@ class CheckIn extends Model
}
//添加流水成功后,要把签到记录放到redis
$date
=
Carbon
::
now
()
->
toDateString
();
$hashKey
=
'ic_welfare_
check_in_'
.
$date
;
$hashKey
=
'ic_welfare_
integral_limit_'
.
self
::
INTEGRAL_TYPE_CHECK_IN
;
$userId
=
$data
[
'user_id'
];
$redis
=
new
RedisModel
();
$redis
->
h
set
(
$hashKey
,
$userId
,
$data
[
'add_time'
]
);
$redis
->
h
incrby
(
$hashKey
,
$userId
,
1
);
return
true
;
});
...
...
app/Models/Integral.php
View file @
5d5627ee
...
...
@@ -5,9 +5,11 @@ namespace App\Models;
use
App\Http\Filters\QueryFilter
;
use
Carbon\Carbon
;
use
Illuminate\Database\Eloquent\Model
;
use
Illuminate\Support\Facades\DB
;
use
Common\Model\RedisModel
;
use
Illuminate\Support\Facades\Log
;
//活动红包模型
class
Integral
extends
Model
...
...
@@ -207,4 +209,37 @@ class Integral extends Model
return
$res
;
}
//检查当前红包添加的操作是否已经达到限额,比如每个用户每日只能签到一次
public
function
checkIntegralLimit
(
$userId
,
$integralId
)
{
//先去redis取出对应的判断类型,比如我要判断签到是否达到每日限额
//就要去查找ic_integral_limit_{$integralId},里面存储了每个用户每天使用的次数
$key
=
'ic_welfare_integral_limit_'
.
$integralId
;
$redis
=
new
RedisModel
();
//先去判断对应项存不存在,不存在的话要先去添加对应限制项的redis哈希
$exist
=
$redis
->
exists
(
$key
);
if
(
$exist
===
0
)
{
$redis
->
hset
(
$key
,
$userId
,
1
);
//同时给予过期时间(今天晚上12点)
$endTimeOfToday
=
Carbon
::
now
()
->
endOfDay
()
->
timestamp
;
$redis
->
expireAt
(
$key
,
$endTimeOfToday
);
//因为连最基本的key都不存在,所以今天肯定没有人对这个类型操作过,所以可以直接返回可操作
return
true
;
}
$count
=
$redis
->
hget
(
$key
,
$userId
);
$limit
=
0
;
//获取到次数之后,还要去对比该红包id对应的每日限制次数
$integral
=
$redis
->
hget
(
'ic_welfare_integrals'
,
$integralId
);
if
(
$integral
)
{
$integral
=
json_decode
(
$integral
,
true
);
$limit
=
array_get
(
$integral
,
'daily_limit'
);
}
else
{
Log
::
Error
(
'查询不存在的类型限制'
);
}
//如果当前用户每日使用没有超过限制次数,那就可以进行操作
return
$count
<
$limit
?
true
:
false
;
}
}
\ No newline at end of file
storage/laravels.json
View file @
5d5627ee
This diff is collapsed.
Click to expand it.
storage/laravels.pid
View file @
5d5627ee
517
\ No newline at end of file
3352
\ 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