mirror of
https://gitee.com/liuxioabin/fengketrade.git
synced 2026-04-17 12:57:32 +08:00
邀请码修改
This commit is contained in:
parent
ffdb777390
commit
4876fbcba2
@ -53,30 +53,42 @@ class InviteHelper
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证邀请码
|
||||
* @param string $inviteCode 邀请码
|
||||
* 验证邀请码或手机号
|
||||
* @param string $inviteCode 邀请码或手机号
|
||||
* @return array
|
||||
*/
|
||||
public static function validate($inviteCode)
|
||||
{
|
||||
$inviteCode = strtoupper(trim($inviteCode));
|
||||
$input = trim($inviteCode);
|
||||
|
||||
if (strlen($inviteCode) !== 6) {
|
||||
return ['code' => 0, 'msg' => '邀请码格式错误'];
|
||||
// 判断输入类型:11位纯数字识别为手机号,否则识别为邀请码
|
||||
if (preg_match('/^\d{11}$/', $input)) {
|
||||
// 手机号模式
|
||||
$inviter = UserModel::where('mobile', $input)
|
||||
->where('status', 'normal')
|
||||
->field(['id', 'nickname', 'avatar', 'invite_code', 'mobile'])
|
||||
->find();
|
||||
} else {
|
||||
// 邀请码模式
|
||||
$input = strtoupper($input);
|
||||
|
||||
if (strlen($input) !== 6) {
|
||||
return ['code' => 0, 'msg' => '邀请信息格式错误'];
|
||||
}
|
||||
|
||||
$inviter = UserModel::where('invite_code', $inviteCode)
|
||||
$inviter = UserModel::where('invite_code', $input)
|
||||
->where('status', 'normal')
|
||||
->field(['id', 'nickname', 'avatar', 'invite_code'])
|
||||
->field(['id', 'nickname', 'avatar', 'invite_code', 'mobile'])
|
||||
->find();
|
||||
}
|
||||
|
||||
if (!$inviter) {
|
||||
return ['code' => 0, 'msg' => '邀请码不存在'];
|
||||
return ['code' => 0, 'msg' => '邀请信息无效'];
|
||||
}
|
||||
|
||||
return [
|
||||
'code' => 1,
|
||||
'msg' => '邀请码有效',
|
||||
'msg' => '邀请信息有效',
|
||||
'data' => [
|
||||
'user_id' => $inviter->id,
|
||||
'invite_code' => $inviter->invite_code,
|
||||
@ -91,13 +103,13 @@ class InviteHelper
|
||||
|
||||
/**
|
||||
* 绑定上下级关系
|
||||
* @param string $inviteCode 邀请码
|
||||
* @param string $inviteCode 邀请码或手机号
|
||||
* @param int $userId 被邀请人ID
|
||||
* @return array
|
||||
*/
|
||||
public static function bind($inviteCode, $userId)
|
||||
{
|
||||
$inviteCode = strtoupper(trim($inviteCode));
|
||||
$input = trim($inviteCode);
|
||||
$user = UserModel::find($userId);
|
||||
|
||||
if (!$user) {
|
||||
@ -109,8 +121,8 @@ class InviteHelper
|
||||
return ['code' => 0, 'msg' => '您已有推荐人,无法修改'];
|
||||
}
|
||||
|
||||
// 验证邀请码
|
||||
$validateResult = self::validate($inviteCode);
|
||||
// 验证邀请码或手机号
|
||||
$validateResult = self::validate($input);
|
||||
if ($validateResult['code'] != 1) {
|
||||
return $validateResult;
|
||||
}
|
||||
@ -119,15 +131,17 @@ class InviteHelper
|
||||
|
||||
// 不能邀请自己
|
||||
if ($inviterUserId == $userId) {
|
||||
return ['code' => 0, 'msg' => '不能使用自己的邀请码'];
|
||||
return ['code' => 0, 'msg' => '不能使用自己的邀请信息'];
|
||||
}
|
||||
|
||||
// 绑定
|
||||
$user->parent_user_id = $inviterUserId;
|
||||
$user->invite_code_used = $inviteCode;
|
||||
$user->invite_code_used = $validateResult['data']['invite_code']; // 统一使用邀请码保存
|
||||
$user->save();
|
||||
|
||||
\think\Log::info("邀请码绑定: 邀请人[{$inviterUserId}] -> 被邀请人[{$userId}] 邀请码[{$inviteCode}]");
|
||||
// 判断是手机号还是邀请码用于日志
|
||||
$inputType = preg_match('/^\d{11}$/', $input) ? '手机号' : '邀请码';
|
||||
\think\Log::info("邀请绑定: 邀请人[{$inviterUserId}] -> 被邀请人[{$userId}] {$inputType}[{$input}]");
|
||||
|
||||
// 触发分销业绩统计
|
||||
$agent = new \addons\shopro\service\commission\Agent($userId);
|
||||
|
||||
@ -48,11 +48,11 @@
|
||||
v-if="!userInfo.parent_user_id"
|
||||
class="order-item ss-flex ss-col-center ss-row-between ss-p-x-20 bg-white ss-r-b-20"
|
||||
>
|
||||
<view class="item-title">邀请码</view>
|
||||
<view class="item-title">邀请信息</view>
|
||||
<view class="ss-flex ss-col-center invite-input-box">
|
||||
<uni-easyinput
|
||||
maxlength="6"
|
||||
placeholder="选填(6位大写字母+数字)"
|
||||
maxlength="11"
|
||||
placeholder="选填(邀请码或手机号)"
|
||||
v-model="state.inviteCode"
|
||||
:inputBorder="false"
|
||||
:clearable="true"
|
||||
@ -281,28 +281,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
// 验证邀请码
|
||||
// 验证邀请码或手机号
|
||||
async function onValidateInvite() {
|
||||
const code = state.inviteCode.trim().toUpperCase();
|
||||
const code = state.inviteCode.trim();
|
||||
if (!code) {
|
||||
state.inviteValidated = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (code.length !== 6) {
|
||||
sheep.$helper.toast('邀请码格式错误');
|
||||
state.inviteValidated = false;
|
||||
return;
|
||||
}
|
||||
// 如果不是纯数字(手机号),则转大写(邀请码)
|
||||
const inviteInput = /^\d+$/.test(code) ? code : code.toUpperCase();
|
||||
|
||||
const { code: resCode, msg } = await sheep.$api.invite.checkCode({ invite_code: code });
|
||||
const { code: resCode, msg } = await sheep.$api.invite.checkCode({ invite_code: inviteInput });
|
||||
if (resCode === 1) {
|
||||
state.inviteCode = code;
|
||||
state.inviteCode = inviteInput;
|
||||
state.inviteValidated = true;
|
||||
sheep.$helper.toast('邀请码验证成功');
|
||||
sheep.$helper.toast('邀请信息验证成功');
|
||||
} else {
|
||||
state.inviteValidated = false;
|
||||
sheep.$helper.toast(msg || '邀请码无效');
|
||||
sheep.$helper.toast(msg || '邀请信息无效');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user