新增邀请注册id

main
limu 11 months ago
parent 3e42a81eba
commit 8d5bc01206
  1. 41
      app/common/repositories/user/UserRepository.php
  2. 16
      app/controller/api/Auth.php

@ -939,36 +939,43 @@ class UserRepository extends BaseRepository
* @author xaboy * @author xaboy
* @day 2020/6/22 * @day 2020/6/22
*/ */
public function bindSpread(User $user, int $spreadUid) public function bindSpread(User $user, int $spreadUid,$is_new = false)
{ {
if ($spreadUid && !$user->spread_uid && $user->uid != $spreadUid && ($spread = $this->dao->get($spreadUid)) && $spread->spread_uid != $user->uid && !$spread->cancel_time) { 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']); $config = systemConfig(['extension_limit', 'extension_limit_day', 'integral_user_give']);
event('user.spread.before', compact('user', 'spreadUid')); event('user.spread.before', compact('user', 'spreadUid'));
Db::transaction(function () use ($spread, $spreadUid, $user, $config) { Db::transaction(function () use ($spread, $spreadUid, $user, $config,$is_new) {
$user->spread_uid2 = $spreadUid; if(!empty($is_new)){
$user->spread_uid2 = $spreadUid;
}else{
$user->spread_uid = $spreadUid;
}
$user->spread_time = date('Y-m-d H:i:s'); $user->spread_time = date('Y-m-d H:i:s');
if ($config['extension_limit'] && $config['extension_limit_day']) { if ($config['extension_limit'] && $config['extension_limit_day']) {
$user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day')); $user->spread_limit = date('Y-m-d H:i:s', strtotime('+ ' . $config['extension_limit_day'] . ' day'));
} }
$spread->spread_count++; $spread->spread_count++;
if ($user->isNew) { if(!empty($is_new)){
//加到log日志 if ($user->isNew) {
ValueContributionLog::getDB()->insert([ //加到log日志
'type' => 2, ValueContributionLog::getDB()->insert([
'types_of' => 1, 'type' => 2,
'num' => 100, 'types_of' => 1,
'ctime' => date('Y-m-d H:i:s'), 'num' => 100,
'memo' => '邀请好友获得100品宣积分', 'ctime' => date('Y-m-d H:i:s'),
'user_id' => $user->spread_uid, 'memo' => '邀请好友获得100品宣积分',
]); 'user_id' => $user->spread_uid,
]);
}
$user2 = userModel::where('uid', $user->spread_uid)->find();
$user2->brand_integral += 100;
$user2->save();
} }
$user2 = userModel::where('uid', $user->spread_uid)->find();
$user2->brand_integral += 100;
$user2->save();
if ($config['integral_user_give'] > 0 && $user->isNew) { if ($config['integral_user_give'] > 0 && $user->isNew) {
$integral = (int)$config['integral_user_give']; $integral = (int)$config['integral_user_give'];
$spread->integral += $integral; $spread->integral += $integral;

@ -107,7 +107,7 @@ class Auth extends BaseController
} }
$user = $repository->mainUser($user); $user = $repository->mainUser($user);
$pid = $this->request->param('spread', 0); $pid = $this->request->param('spread', 0);
$repository->bindSpread($user, intval($pid)); $repository->bindSpread($user, intval($pid),1);
$tokenInfo = $repository->createToken($user); $tokenInfo = $repository->createToken($user);
$repository->loginAfter($user); $repository->loginAfter($user);
@ -153,7 +153,7 @@ class Auth extends BaseController
*/ */
public function userInfo() public function userInfo()
{ {
$user = $this->request->userInfo()->hidden(['label_id', 'group_id', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_uid', 'spread_time', 'real_name', 'birthday', 'brokerage_price']); $user = $this->request->userInfo()->hidden(['label_id', 'group_id', 'pwd', 'addres', 'card_id', 'last_time', 'last_ip', 'create_time', 'mark', 'status', 'spread_time', 'real_name', 'birthday', 'brokerage_price']);
$user->append(['service', 'topService', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread', 'total_recharge', 'lock_integral', 'total_integral']); $user->append(['service', 'topService', 'total_collect_product', 'total_collect_store', 'total_coupon', 'total_visit_product', 'total_unread', 'total_recharge', 'lock_integral', 'total_integral']);
$data = $user->toArray(); $data = $user->toArray();
$data['total_consume'] = $user['pay_price']; $data['total_consume'] = $user['pay_price'];
@ -229,7 +229,7 @@ class Auth extends BaseController
$pid = $this->request->param('spread', 0); $pid = $this->request->param('spread', 0);
$userRepository->bindSpread($user[1], intval($pid)); $userRepository->bindSpread($user[1], intval($pid),1);
$tokenInfo = $userRepository->createToken($user[1]); $tokenInfo = $userRepository->createToken($user[1]);
$userRepository->loginAfter($user[1]); $userRepository->loginAfter($user[1]);
@ -301,7 +301,7 @@ class Auth extends BaseController
if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) { if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) {
$data['spread_spid'] = $info['third_id']; $data['spread_spid'] = $info['third_id'];
} }
$userRepository->bindSpread($user[1], intval($data['spread_spid'])); $userRepository->bindSpread($user[1], intval($data['spread_spid']),1);
$tokenInfo = $userRepository->createToken($user[1]); $tokenInfo = $userRepository->createToken($user[1]);
$userRepository->loginAfter($user[1]); $userRepository->loginAfter($user[1]);
@ -376,7 +376,7 @@ class Auth extends BaseController
$repository->syncBaseAuth($auth, $user); $repository->syncBaseAuth($auth, $user);
} }
$user = $repository->mainUser($user); $user = $repository->mainUser($user);
$repository->bindSpread($user, intval($data['spread'])); $repository->bindSpread($user, intval($data['spread']),1);
$tokenInfo = $repository->createToken($user); $tokenInfo = $repository->createToken($user);
$repository->loginAfter($user); $repository->loginAfter($user);
@ -434,7 +434,7 @@ class Auth extends BaseController
$repository->syncBaseAuth($auth, $user); $repository->syncBaseAuth($auth, $user);
} }
$user = $repository->mainUser($user); $user = $repository->mainUser($user);
$repository->bindSpread($user, intval($data['spread'])); $repository->bindSpread($user, intval($data['spread']),1);
$tokenInfo = $repository->createToken($user); $tokenInfo = $repository->createToken($user);
$repository->loginAfter($user); $repository->loginAfter($user);
@ -587,7 +587,7 @@ class Auth extends BaseController
} }
if ($auth['auth']['spread'] ?? 0) { if ($auth['auth']['spread'] ?? 0) {
$userRepository->bindSpread($user, (int)($auth['auth']['spread'])); $userRepository->bindSpread($user, (int)($auth['auth']['spread']),1);
} }
$tokenInfo = $userRepository->createToken($user); $tokenInfo = $userRepository->createToken($user);
$userRepository->loginAfter($user); $userRepository->loginAfter($user);
@ -722,7 +722,7 @@ class Auth extends BaseController
$user->account = $phone; $user->account = $phone;
$user->save(); $user->save();
if ($auth['spread']) { if ($auth['spread']) {
$userRepository->bindSpread($user, $auth['spread']); $userRepository->bindSpread($user, $auth['spread'],1);
} }
} }
$tokenInfo = $userRepository->createToken($user); $tokenInfo = $userRepository->createToken($user);

Loading…
Cancel
Save