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
355c1f79
authored
Aug 27, 2019
by
杨树贤
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
修改添加流水的异步任务和邀请用户的逻辑
parent
584382ea
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
19 additions
and
29 deletions
app/Http/Controllers/InvitesController.php
app/Models/IntegralBill.php
app/Models/Invite.php
app/Tasks/IntegralBillTask.php
storage/laravels.json
storage/laravels.pid
app/Http/Controllers/InvitesController.php
View file @
355c1f79
...
...
@@ -44,7 +44,7 @@ class InvitesController extends Controller
{
$data
=
[
'user_id'
=>
$request
->
get
(
'user_id'
),
'invited_user_
I
d'
=>
$request
->
get
(
'invited_user_id'
),
'invited_user_
i
d'
=>
$request
->
get
(
'invited_user_id'
),
'add_time'
=>
time
(),
];
$canInvite
=
$integral
->
checkIntegralLimit
(
$data
[
'user_id'
],
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
);
...
...
app/Models/IntegralBill.php
View file @
355c1f79
...
...
@@ -55,28 +55,12 @@ class IntegralBill extends Model
case
Integral
::
INTEGRAL_TYPE_SHARE
:
case
Integral
::
INTEGRAL_TYPE_OFFER
:
case
Integral
::
INTEGRAL_TYPE_CHECK_IN
:
case
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
:
$task
=
new
IntegralBillTask
(
$data
);
$result
=
Task
::
deliver
(
$task
);
return
$result
?
true
:
false
;
break
;
case
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
:
//好友邀请部分,是需要同时添加两个人的流水的
//添加邀请人的红包
$task
=
new
IntegralBillTask
(
$data
);
$result
=
Task
::
deliver
(
$task
);
if
(
$result
)
{
//添加受邀人的红包,把user_id改成受邀者的id即可
$data
[
'user_id'
]
=
$data
[
'invited_user_Id'
];
$task
=
new
IntegralBillTask
(
$data
);
$result
=
Task
::
deliver
(
$task
);
if
(
$result
)
{
return
true
;
}
}
return
false
;
break
;
}
}
...
...
app/Models/Invite.php
View file @
355c1f79
...
...
@@ -46,18 +46,19 @@ class Invite extends Model
return
false
;
}
//使用异步任务去添加流水
//好友邀请部分,是需要同时添加两个人的流水的
$integralBill
=
new
IntegralBill
();
$data
[
'integral_id'
]
=
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
;
$result
=
$integralBill
->
createIntegralBill
(
$data
);
if
(
!
$result
)
{
return
false
;
if
(
$result
)
{
//这个是被邀请人的流水添加
//因为流水的异步任务是根据user_id来添加的,所以把第二次的user_id改成受邀人的user_id就可以了
$data
[
'user_id'
]
=
$data
[
'invited_user_id'
];
$result
=
$integralBill
->
createIntegralBill
(
$data
);
if
(
!
$result
)
{
return
false
;
}
}
//添加流水成功后,要把签到记录放到redis
$date
=
Carbon
::
now
()
->
toDateString
();
$hashKey
=
'ic_welfare_integral_limit_'
.
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
;
$userId
=
$data
[
'user_id'
];
$redis
=
new
RedisModel
();
$redis
->
hincrby
(
$hashKey
,
$userId
,
1
);
return
true
;
});
...
...
app/Tasks/IntegralBillTask.php
View file @
355c1f79
...
...
@@ -73,13 +73,18 @@ class IntegralBillTask extends Task
'integral'
=>
$data
[
'integral'
]
+
$amount
,
'update_time'
=>
time
(),
];
$result
=
$userIntegral
->
updateUserIntegralByUserId
(
$userId
,
$data
);
if
(
!
$result
)
{
throw
new
\Exception
(
"更新用户剩余积分失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
}
}
else
{
throw
new
\Exception
(
"更新redis里ic_user的
integral
失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
throw
new
\Exception
(
"更新redis里ic_user的
红包余额
失败,用户id是
$userId
,兑换类型id是
$integralId
"
);
}
//还要对redis的限制数额那块进行更新
//添加流水成功后,要把对应用户已经对该类型的流水当天操作次数放到redis
$hashKey
=
'ic_welfare_integral_limit_'
.
$integralId
;
$redis
->
hincrby
(
$hashKey
,
$userId
,
1
);
});
}
catch
(
\Exception
$e
)
{
//抛出致命错误日志
...
...
storage/laravels.json
View file @
355c1f79
This diff is collapsed.
Click to expand it.
storage/laravels.pid
View file @
355c1f79
14931
\ No newline at end of file
16308
\ 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