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
8b51d701
authored
Oct 17, 2019
by
叶明星
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
邀请好友通过审核
parent
068a2a29
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
83 additions
and
2 deletions
app/Http/Controllers/InvitesController.php
app/Models/Invite.php
routes/web.php
app/Http/Controllers/InvitesController.php
View file @
8b51d701
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
...
@@ -5,6 +5,7 @@ namespace App\Http\Controllers;
use
App\Http\Filters\InviteFilter
;
use
App\Http\Filters\InviteFilter
;
use
App\Models\IntegralBill
;
use
App\Models\Invite
;
use
App\Models\Invite
;
use
App\Models\Integral
;
use
App\Models\Integral
;
use
Illuminate\Http\Request
;
use
Illuminate\Http\Request
;
...
@@ -49,7 +50,7 @@ class InvitesController extends Controller
...
@@ -49,7 +50,7 @@ class InvitesController extends Controller
}
}
/**
/**
* 添加邀请好友记录
* 添加邀请好友记录
(流水)
* @param Request $request
* @param Request $request
* @param Invite $invite
* @param Invite $invite
* @param Integral $integral
* @param Integral $integral
...
@@ -74,4 +75,39 @@ class InvitesController extends Controller
...
@@ -74,4 +75,39 @@ class InvitesController extends Controller
return
$this
->
Export
(
0
,
'ok'
);
return
$this
->
Export
(
0
,
'ok'
);
}
}
/**
* 被邀请人认证通过
* @param Request $request
* @param Invite $invite
* @param Integral $integral
* @return array
*/
public
function
authAdopt
(
Request
$request
,
Invite
$invite
,
Integral
$integral
)
{
$data
=
[
'invited_user_id'
=>
$request
->
get
(
'invited_user_id'
),
'add_time'
=>
time
(),
];
//先查找邀请人生成的流水
$findInvite
=
$invite
->
where
(
'invited_user_id'
,
'='
,
$request
->
get
(
'invited_user_id'
))
->
select
(
'id'
,
'user_id'
,
'status'
)
->
first
();
if
(
!
$findInvite
)
return
$this
->
Export
(
ErrorCode
(
19
,
5
),
'没有邀请记录'
);
if
(
$findInvite
[
'status'
]
!==
1
)
return
$this
->
Export
(
ErrorCode
(
19
,
5
),
'红包已经发放'
);
$data
[
'id'
]
=
$findInvite
[
'id'
];
$data
[
'user_id'
]
=
$findInvite
[
'user_id'
];
$res
=
$invite
->
saveInvite
(
$data
);
if
(
$res
)
{
return
$this
->
Export
();
}
else
{
return
$this
->
Export
(
ErrorCode
(
19
,
5
),
'修改邀请好友记录失败'
);
}
}
}
}
\ No newline at end of file
app/Models/Invite.php
View file @
8b51d701
...
@@ -39,7 +39,7 @@ class Invite extends Model
...
@@ -39,7 +39,7 @@ class Invite extends Model
return
[
'data'
=>
$invites
,
'count'
=>
$count
];
return
[
'data'
=>
$invites
,
'count'
=>
$count
];
}
}
//添加
签到
记录
//添加
邀请
记录
public
function
addInvite
(
$data
)
public
function
addInvite
(
$data
)
{
{
$result
=
DB
::
transaction
(
function
()
use
(
$data
)
{
$result
=
DB
::
transaction
(
function
()
use
(
$data
)
{
...
@@ -54,6 +54,49 @@ class Invite extends Model
...
@@ -54,6 +54,49 @@ class Invite extends Model
}
}
//使用异步任务去添加流水
//使用异步任务去添加流水
//好友邀请部分,是需要同时添加两个人的流水的
//好友邀请部分,是需要同时添加两个人的流水的
//业务变更,需要被邀请人认证后才能添加红包
// $integralId = Integral::INTEGRAL_TYPE_INVITE_FRIEND;
// $integralBill = new IntegralBill();
// $data['integral_id'] = $integralId;
// $userId = $data['user_id'];
// $result = $integralBill->createIntegralBill($data);
// if ($result) {
// //这个是被邀请人的流水添加
// //因为流水的异步任务是根据user_id来添加的,所以把第二次的user_id改成受邀人的user_id就可以了
// $data['user_id'] = $data['invited_user_id'];
// $result = $integralBill->createIntegralBill($data);
// if (!$result) {
// return false;
// } else {
// $result = $this->saveInviteInfoToRedis($integralId, $userId);
// if (!$result) {
// return false;
// }
// }
// }
return
true
;
});
return
$result
;
}
//被邀请人通过认证
public
function
saveInvite
(
$data
)
{
$result
=
DB
::
transaction
(
function
()
use
(
$data
)
{
//还要去获取此时邀请能获得的金额,因为以后邀请这类操作的金额可能会变动
$amount
=
DB
::
table
(
'integrals'
)
->
where
(
'id'
,
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
)
->
value
(
'amount'
);
$data
[
'status'
]
=
2
;
$data
[
'amount'
]
=
$amount
;
$result
=
DB
::
table
(
'invites'
)
->
where
(
'id'
,
'='
,
$data
[
'id'
])
->
update
(
$data
);
if
(
!
$result
)
{
return
false
;
}
//使用异步任务去添加流水
//好友邀请部分,是需要同时添加两个人的流水的
$integralId
=
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
;
$integralId
=
Integral
::
INTEGRAL_TYPE_INVITE_FRIEND
;
$integralBill
=
new
IntegralBill
();
$integralBill
=
new
IntegralBill
();
$data
[
'integral_id'
]
=
$integralId
;
$data
[
'integral_id'
]
=
$integralId
;
...
...
routes/web.php
View file @
8b51d701
...
@@ -75,6 +75,7 @@ $router->post('/rob/exchange/quota', 'UserExchangesController@create');
...
@@ -75,6 +75,7 @@ $router->post('/rob/exchange/quota', 'UserExchangesController@create');
//邀请好友
//邀请好友
$router
->
post
(
'/invites/list'
,
'InvitesController@index'
);
$router
->
post
(
'/invites/list'
,
'InvitesController@index'
);
$router
->
post
(
'/invites/add'
,
'InvitesController@store'
);
$router
->
post
(
'/invites/add'
,
'InvitesController@store'
);
$router
->
post
(
'/invites/save'
,
'InvitesController@authAdopt'
);
$router
->
post
(
'/invites/info'
,
'InvitesController@info'
);
$router
->
post
(
'/invites/info'
,
'InvitesController@info'
);
//红包码兑换(添加)
//红包码兑换(添加)
...
...
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