|
|
|
@ -946,25 +946,27 @@ class UserRepository extends BaseRepository |
|
|
|
|
*/ |
|
|
|
|
public function bindSpread(User $user, int $spreadUid,$is_new = false) |
|
|
|
|
{ |
|
|
|
|
try{ |
|
|
|
|
if ($spreadUid && !$user->spread_uid && $user->uid != $spreadUid && ($spread = $this->dao->get($spreadUid)) && $spread->spread_uid != $user->uid && !$spread->cancel_time) { |
|
|
|
|
$config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give'])??[]; |
|
|
|
|
event('user.spread.before', compact('user', 'spreadUid')); |
|
|
|
|
Db::transaction(function () use ($spread, $spreadUid, $user, $config,$is_new) { |
|
|
|
|
if(!empty($is_new)){ |
|
|
|
|
$user->spread_uid2 = $spreadUid; |
|
|
|
|
}else{ |
|
|
|
|
$user->spread_uid = $spreadUid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$user->spread_time = date('Y-m-d H:i:s'); |
|
|
|
|
if ($config['extension_limit'] && $config['extension_limit_day']) { |
|
|
|
|
$user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day')); |
|
|
|
|
} |
|
|
|
|
$spread->spread_count++; |
|
|
|
|
|
|
|
|
|
if ($spreadUid && !$user->spread_uid && $user->uid != $spreadUid && ($spread = $this->dao->get($spreadUid)) && $spread->spread_uid != $user->uid && !$spread->cancel_time) { |
|
|
|
|
$config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give']); |
|
|
|
|
event('user.spread.before', compact('user', 'spreadUid')); |
|
|
|
|
Db::transaction(function () use ($spread, $spreadUid, $user, $config,$is_new) { |
|
|
|
|
if(!empty($is_new)){ |
|
|
|
|
$user->spread_uid2 = $spreadUid; |
|
|
|
|
}else{ |
|
|
|
|
$user->spread_uid = $spreadUid; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$user->spread_time = date('Y-m-d H:i:s'); |
|
|
|
|
if ($config['extension_limit'] && $config['extension_limit_day']) { |
|
|
|
|
$user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day')); |
|
|
|
|
} |
|
|
|
|
$spread->spread_count++; |
|
|
|
|
|
|
|
|
|
if(!empty($is_new)){ |
|
|
|
|
if ($user->isNew) { |
|
|
|
|
if(!empty($is_new)){ |
|
|
|
|
|
|
|
|
|
//加到log日志 |
|
|
|
|
ValueContributionLog::getDB()->insert([ |
|
|
|
|
'type' => 2, |
|
|
|
@ -974,37 +976,41 @@ class UserRepository extends BaseRepository |
|
|
|
|
'memo' => '邀请好友获得100品宣积分', |
|
|
|
|
'user_id' => $user->spread_uid, |
|
|
|
|
]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$user2 = userModel::where('uid', $user->spread_uid)->find(); |
|
|
|
|
$user2->brand_integral += 100; |
|
|
|
|
$user2->save(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($config['integral_user_give'] > 0 && $user->isNew) { |
|
|
|
|
$integral = (int)$config['integral_user_give']; |
|
|
|
|
$spread->integral += $integral; |
|
|
|
|
app()->make(UserBillRepository::class)->incBill($spreadUid, 'integral', 'spread', [ |
|
|
|
|
'link_id' => $user->uid, |
|
|
|
|
'status' => 1, |
|
|
|
|
'title' => '邀请好友', |
|
|
|
|
'number' => $integral, |
|
|
|
|
'mark' => '邀请好友奖励' . $integral . '积分', |
|
|
|
|
'balance' => $spread->integral |
|
|
|
|
]); |
|
|
|
|
$user2 = userModel::where('uid', $user->spread_uid)->find(); |
|
|
|
|
$user2->brand_integral += 100; |
|
|
|
|
$user2->save(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
$spread->save(); |
|
|
|
|
$user->save(); |
|
|
|
|
//TODO 推广人月榜 |
|
|
|
|
Cache::zincrby('s_top_' . date('Y-m'), 1, $spreadUid); |
|
|
|
|
//TODO 推广人周榜 |
|
|
|
|
Cache::zincrby('s_top_' . monday(), 1, $spreadUid); |
|
|
|
|
}); |
|
|
|
|
Queue::push(UserBrokerageLevelJob::class, ['uid' => $spreadUid, 'type' => 'spread_user', 'inc' => 1]); |
|
|
|
|
app()->make(UserBrokerageRepository::class)->incMemberValue($user->uid, 'member_share_num', 0); |
|
|
|
|
event('user.spread', compact('user', 'spreadUid')); |
|
|
|
|
if ($config['integral_user_give'] > 0 && $user->isNew) { |
|
|
|
|
$integral = (int)$config['integral_user_give']; |
|
|
|
|
$spread->integral += $integral; |
|
|
|
|
app()->make(UserBillRepository::class)->incBill($spreadUid, 'integral', 'spread', [ |
|
|
|
|
'link_id' => $user->uid, |
|
|
|
|
'status' => 1, |
|
|
|
|
'title' => '邀请好友', |
|
|
|
|
'number' => $integral, |
|
|
|
|
'mark' => '邀请好友奖励' . $integral . '积分', |
|
|
|
|
'balance' => $spread->integral |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
$spread->save(); |
|
|
|
|
$user->save(); |
|
|
|
|
//TODO 推广人月榜 |
|
|
|
|
Cache::zincrby('s_top_' . date('Y-m'), 1, $spreadUid); |
|
|
|
|
//TODO 推广人周榜 |
|
|
|
|
Cache::zincrby('s_top_' . monday(), 1, $spreadUid); |
|
|
|
|
}); |
|
|
|
|
Queue::push(UserBrokerageLevelJob::class, ['uid' => $spreadUid, 'type' => 'spread_user', 'inc' => 1]); |
|
|
|
|
app()->make(UserBrokerageRepository::class)->incMemberValue($user->uid, 'member_share_num', 0); |
|
|
|
|
event('user.spread', compact('user', 'spreadUid')); |
|
|
|
|
} |
|
|
|
|
}catch (\Exception $e){ |
|
|
|
|
print_r($e->getTrace());exit; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function userPosition($key, $uid) |
|
|
|
|