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
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function validate($inviteCode)
|
public static function validate($inviteCode)
|
||||||
{
|
{
|
||||||
$inviteCode = strtoupper(trim($inviteCode));
|
$input = trim($inviteCode);
|
||||||
|
|
||||||
if (strlen($inviteCode) !== 6) {
|
// 判断输入类型:11位纯数字识别为手机号,否则识别为邀请码
|
||||||
return ['code' => 0, 'msg' => '邀请码格式错误'];
|
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', $input)
|
||||||
|
->where('status', 'normal')
|
||||||
|
->field(['id', 'nickname', 'avatar', 'invite_code', 'mobile'])
|
||||||
|
->find();
|
||||||
}
|
}
|
||||||
|
|
||||||
$inviter = UserModel::where('invite_code', $inviteCode)
|
|
||||||
->where('status', 'normal')
|
|
||||||
->field(['id', 'nickname', 'avatar', 'invite_code'])
|
|
||||||
->find();
|
|
||||||
|
|
||||||
if (!$inviter) {
|
if (!$inviter) {
|
||||||
return ['code' => 0, 'msg' => '邀请码不存在'];
|
return ['code' => 0, 'msg' => '邀请信息无效'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'code' => 1,
|
'code' => 1,
|
||||||
'msg' => '邀请码有效',
|
'msg' => '邀请信息有效',
|
||||||
'data' => [
|
'data' => [
|
||||||
'user_id' => $inviter->id,
|
'user_id' => $inviter->id,
|
||||||
'invite_code' => $inviter->invite_code,
|
'invite_code' => $inviter->invite_code,
|
||||||
@ -91,13 +103,13 @@ class InviteHelper
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 绑定上下级关系
|
* 绑定上下级关系
|
||||||
* @param string $inviteCode 邀请码
|
* @param string $inviteCode 邀请码或手机号
|
||||||
* @param int $userId 被邀请人ID
|
* @param int $userId 被邀请人ID
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function bind($inviteCode, $userId)
|
public static function bind($inviteCode, $userId)
|
||||||
{
|
{
|
||||||
$inviteCode = strtoupper(trim($inviteCode));
|
$input = trim($inviteCode);
|
||||||
$user = UserModel::find($userId);
|
$user = UserModel::find($userId);
|
||||||
|
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
@ -109,8 +121,8 @@ class InviteHelper
|
|||||||
return ['code' => 0, 'msg' => '您已有推荐人,无法修改'];
|
return ['code' => 0, 'msg' => '您已有推荐人,无法修改'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证邀请码
|
// 验证邀请码或手机号
|
||||||
$validateResult = self::validate($inviteCode);
|
$validateResult = self::validate($input);
|
||||||
if ($validateResult['code'] != 1) {
|
if ($validateResult['code'] != 1) {
|
||||||
return $validateResult;
|
return $validateResult;
|
||||||
}
|
}
|
||||||
@ -119,15 +131,17 @@ class InviteHelper
|
|||||||
|
|
||||||
// 不能邀请自己
|
// 不能邀请自己
|
||||||
if ($inviterUserId == $userId) {
|
if ($inviterUserId == $userId) {
|
||||||
return ['code' => 0, 'msg' => '不能使用自己的邀请码'];
|
return ['code' => 0, 'msg' => '不能使用自己的邀请信息'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// 绑定
|
// 绑定
|
||||||
$user->parent_user_id = $inviterUserId;
|
$user->parent_user_id = $inviterUserId;
|
||||||
$user->invite_code_used = $inviteCode;
|
$user->invite_code_used = $validateResult['data']['invite_code']; // 统一使用邀请码保存
|
||||||
$user->save();
|
$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);
|
$agent = new \addons\shopro\service\commission\Agent($userId);
|
||||||
|
|||||||
@ -48,11 +48,11 @@
|
|||||||
v-if="!userInfo.parent_user_id"
|
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"
|
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">
|
<view class="ss-flex ss-col-center invite-input-box">
|
||||||
<uni-easyinput
|
<uni-easyinput
|
||||||
maxlength="6"
|
maxlength="11"
|
||||||
placeholder="选填(6位大写字母+数字)"
|
placeholder="选填(邀请码或手机号)"
|
||||||
v-model="state.inviteCode"
|
v-model="state.inviteCode"
|
||||||
:inputBorder="false"
|
:inputBorder="false"
|
||||||
:clearable="true"
|
:clearable="true"
|
||||||
@ -281,28 +281,25 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证邀请码
|
// 验证邀请码或手机号
|
||||||
async function onValidateInvite() {
|
async function onValidateInvite() {
|
||||||
const code = state.inviteCode.trim().toUpperCase();
|
const code = state.inviteCode.trim();
|
||||||
if (!code) {
|
if (!code) {
|
||||||
state.inviteValidated = false;
|
state.inviteValidated = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (code.length !== 6) {
|
// 如果不是纯数字(手机号),则转大写(邀请码)
|
||||||
sheep.$helper.toast('邀请码格式错误');
|
const inviteInput = /^\d+$/.test(code) ? code : code.toUpperCase();
|
||||||
state.inviteValidated = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
if (resCode === 1) {
|
||||||
state.inviteCode = code;
|
state.inviteCode = inviteInput;
|
||||||
state.inviteValidated = true;
|
state.inviteValidated = true;
|
||||||
sheep.$helper.toast('邀请码验证成功');
|
sheep.$helper.toast('邀请信息验证成功');
|
||||||
} else {
|
} else {
|
||||||
state.inviteValidated = false;
|
state.inviteValidated = false;
|
||||||
sheep.$helper.toast(msg || '邀请码无效');
|
sheep.$helper.toast(msg || '邀请信息无效');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user