From 8d5bc0120615020eac7da8a3e4200af90e86e81d Mon Sep 17 00:00:00 2001 From: limu <123456> Date: Thu, 18 Jan 2024 16:57:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E9=82=80=E8=AF=B7=E6=B3=A8?= =?UTF-8?q?=E5=86=8Cid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repositories/user/UserRepository.php | 41 +++++++++++-------- app/controller/api/Auth.php | 16 ++++---- 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/app/common/repositories/user/UserRepository.php b/app/common/repositories/user/UserRepository.php index 654fe47..27dda8a 100644 --- a/app/common/repositories/user/UserRepository.php +++ b/app/common/repositories/user/UserRepository.php @@ -939,36 +939,43 @@ class UserRepository extends BaseRepository * @author xaboy * @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) { $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) { - $user->spread_uid2 = $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 ($user->isNew) { - //加到log日志 - ValueContributionLog::getDB()->insert([ - 'type' => 2, - 'types_of' => 1, - 'num' => 100, - 'ctime' => date('Y-m-d H:i:s'), - 'memo' => '邀请好友获得100品宣积分', - 'user_id' => $user->spread_uid, - ]); + if(!empty($is_new)){ + if ($user->isNew) { + //加到log日志 + ValueContributionLog::getDB()->insert([ + 'type' => 2, + 'types_of' => 1, + 'num' => 100, + 'ctime' => date('Y-m-d H:i:s'), + '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) { $integral = (int)$config['integral_user_give']; $spread->integral += $integral; diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index 4dc3056..3a3a357 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.php @@ -107,7 +107,7 @@ class Auth extends BaseController } $user = $repository->mainUser($user); $pid = $this->request->param('spread', 0); - $repository->bindSpread($user, intval($pid)); + $repository->bindSpread($user, intval($pid),1); $tokenInfo = $repository->createToken($user); $repository->loginAfter($user); @@ -153,7 +153,7 @@ class Auth extends BaseController */ 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']); $data = $user->toArray(); $data['total_consume'] = $user['pay_price']; @@ -229,7 +229,7 @@ class Auth extends BaseController $pid = $this->request->param('spread', 0); - $userRepository->bindSpread($user[1], intval($pid)); + $userRepository->bindSpread($user[1], intval($pid),1); $tokenInfo = $userRepository->createToken($user[1]); $userRepository->loginAfter($user[1]); @@ -301,7 +301,7 @@ class Auth extends BaseController if ($code && ($info = app()->make(RoutineQrcodeRepository::class)->getRoutineQrcodeFindType($code))) { $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]); $userRepository->loginAfter($user[1]); @@ -376,7 +376,7 @@ class Auth extends BaseController $repository->syncBaseAuth($auth, $user); } $user = $repository->mainUser($user); - $repository->bindSpread($user, intval($data['spread'])); + $repository->bindSpread($user, intval($data['spread']),1); $tokenInfo = $repository->createToken($user); $repository->loginAfter($user); @@ -434,7 +434,7 @@ class Auth extends BaseController $repository->syncBaseAuth($auth, $user); } $user = $repository->mainUser($user); - $repository->bindSpread($user, intval($data['spread'])); + $repository->bindSpread($user, intval($data['spread']),1); $tokenInfo = $repository->createToken($user); $repository->loginAfter($user); @@ -587,7 +587,7 @@ class Auth extends BaseController } if ($auth['auth']['spread'] ?? 0) { - $userRepository->bindSpread($user, (int)($auth['auth']['spread'])); + $userRepository->bindSpread($user, (int)($auth['auth']['spread']),1); } $tokenInfo = $userRepository->createToken($user); $userRepository->loginAfter($user); @@ -722,7 +722,7 @@ class Auth extends BaseController $user->account = $phone; $user->save(); if ($auth['spread']) { - $userRepository->bindSpread($user, $auth['spread']); + $userRepository->bindSpread($user, $auth['spread'],1); } } $tokenInfo = $userRepository->createToken($user);