Commit 8b51d701 by 叶明星

邀请好友通过审核

parent 068a2a29
...@@ -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
...@@ -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;
......
...@@ -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');
//红包码兑换(添加) //红包码兑换(添加)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment