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
0ffc8533
authored
Aug 28, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加用户邀请用户统计信息
parent
4f4c8fa3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
6 deletions
app/Http/Controllers/InvitesController.php
app/Models/Invite.php
app/Http/Controllers/InvitesController.php
View file @
0ffc8533
...
...
@@ -21,7 +21,7 @@ class InvitesController extends Controller
* @param Request $request
* @param Invite $invite
* @param InviteFilter $filter
* @return
false|string
* @return
array
*/
public
function
index
(
Request
$request
,
Invite
$invite
,
InviteFilter
$filter
)
{
...
...
@@ -33,19 +33,34 @@ class InvitesController extends Controller
return
$this
->
Export
(
0
,
'ok'
,
$invites
);
}
/**
* 用户邀请情况(用户邀请获得的金额,还有邀请的人数)
* @param Request $request
* @param Invite $invite
* @return array
*/
public
function
info
(
Request
$request
,
Invite
$invite
)
{
$userId
=
$request
->
get
(
'user_id'
);
$info
=
$invite
->
getInviteInfo
(
$userId
);
return
$this
->
Export
(
0
,
'ok'
,
[
'data'
=>
$info
]);
}
/**
* 添加邀请好友记录
* @param Request $request
* @param Invite $invite
* @param Integral $integral
* @return
false|string
* @return
array
*/
public
function
store
(
Request
$request
,
Invite
$invite
,
Integral
$integral
)
{
$data
=
[
'user_id'
=>
$request
->
get
(
'user_id'
),
'invited_user_id'
=>
$request
->
get
(
'invited_user_id'
),
'add_time'
=>
time
(),
'user_id'
=>
$request
->
get
(
'user_id'
),
'invited_user_id'
=>
$request
->
get
(
'invited_user_id'
),
'add_time'
=>
time
(),
];
$canInvite
=
$integral
->
checkIntegralLimit
(
$data
[
'user_id'
],
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
);
if
(
$canInvite
)
{
...
...
app/Models/Invite.php
View file @
0ffc8533
...
...
@@ -47,8 +47,10 @@ class Invite extends Model
}
//使用异步任务去添加流水
//好友邀请部分,是需要同时添加两个人的流水的
$integralId
=
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
;
$integralBill
=
new
IntegralBill
();
$data
[
'integral_id'
]
=
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
;
$data
[
'integral_id'
]
=
$integralId
;
$userId
=
$data
[
'user_id'
];
$result
=
$integralBill
->
createIntegralBill
(
$data
);
if
(
$result
)
{
//这个是被邀请人的流水添加
...
...
@@ -57,6 +59,11 @@ class Invite extends Model
$result
=
$integralBill
->
createIntegralBill
(
$data
);
if
(
!
$result
)
{
return
false
;
}
else
{
$result
=
$this
->
saveInviteInfoToRedis
(
$integralId
,
$userId
);
if
(
!
$result
)
{
return
false
;
}
}
}
...
...
@@ -65,4 +72,35 @@ class Invite extends Model
return
$result
;
}
private
function
saveInviteInfoToRedis
(
$integralId
,
$userId
)
{
//同时把邀请人数和邀请获得的金额缓存起来,要给前端展示当前用户的邀请情况
$redis
=
new
RedisModel
();
//先获取该次申请可以获得的金额
$integral
=
json_decode
(
$redis
->
hget
(
'ic_welfare_integrals'
,
$integralId
),
true
);
$amount
=
array_get
(
$integral
,
'amount'
);
//然后可以对该用户的邀请金额叠加,邀请人数加一
$inviteInfo
=
json_decode
(
$redis
->
hget
(
'ic_welfare_invites'
,
$userId
),
true
);
if
(
$inviteInfo
)
{
$inviteInfo
[
'amount'
]
+=
$amount
;
$inviteInfo
[
'count'
]
++
;
}
else
{
$inviteInfo
=
[
'amount'
=>
$amount
,
'count'
=>
1
,
];
}
$result
=
$redis
->
hset
(
'ic_welfare_invites'
,
$userId
,
json_encode
(
$inviteInfo
));
return
$result
!==
false
?
true
:
false
;
}
public
function
getInviteInfo
(
$userId
)
{
$redis
=
new
RedisModel
();
$info
=
json_decode
(
$redis
->
hget
(
'ic_welfare_invites'
,
$userId
),
true
);
return
$info
;
}
}
\ 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