Commit 355c1f79 by 杨树贤

修改添加流水的异步任务和邀请用户的逻辑

parent 584382ea
......@@ -44,7 +44,7 @@ class InvitesController extends Controller
{
$data = [
'user_id' => $request->get('user_id'),
'invited_user_Id' => $request->get('invited_user_id'),
'invited_user_id' => $request->get('invited_user_id'),
'add_time' => time(),
];
$canInvite = $integral->checkIntegralLimit($data['user_id'], Integral::INTEGRAL_TYPE_INVITE_FRIEND);
......
......@@ -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;
}
}
......
......@@ -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;
});
......
......@@ -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) {
//抛出致命错误日志
......
14931
\ No newline at end of file
16308
\ No newline at end of file
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