对于无限极下级以及下三级总量的问题

本文详细解析了用户注册流程,包括手机号验证、密码规则检查、邀请码使用及奖励分配。同时介绍了如何通过邀请码建立上下级关系,并实现对下级用户的无限级追踪。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先注册时:
function register()
{
param=param=param=this->request->param();
$phone = $param[‘phone’];
$password = $param[‘password’];
$verification_code = $param[‘code’];//验证码
$parent = param[′parentid′];//上级的id作为邀请码if(!Str::isvalidphone(param['parent_id'];//上级的id作为邀请码 if (!Str::is_valid_phone(param[parentid];//idif(!Str::isvalidphone(phone) ) {
return return_json([],400, “手机号格式错误” );
}
if (!Str::is_valid_register_pass(password))returnreturnjson([],400,"密码为6−16位数字、字母、下划线组合");if(!User::get(password) ) { return return_json([],400, "密码为6-16位数字、字母、下划线组合" ); } if( !User::get(password))returnreturnjson([],400,"616线");if(!User::get(parent) ){
return return_json([],400, “邀请码不存在” );
}
if (!this−>regnum(this->reg_num(this>regnum(parent)){
return return_json([],400, “该邀请码已超过当日邀请上限” );
}
$reward=Db::name(‘config’)->where(‘name’,‘reg_award’)->value(‘value’);
$user = new User;
Db::startTrans();
try {
sms=newSmsService(sms = new SmsService(sms=newSmsService(phone);
sms−>check(sms->check (sms>check(verification_code);
password=Rsa::decrypt(password=Rsa::decrypt(password=Rsa::decrypt(password);
$user->add( $phone, password,password,password,parent,reward);if(reward); if (reward);if(reward>0)
Db::name(‘reward_log’)->insert([‘uid’=>user−>id,′changenum′=>user->id,'change_num'=>user>id,changenum=>reward,‘flag’=>11,‘time’=>time()]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
return return_json ( [], 400, $e->getMessage());
}

    return $this->returnSuccess([],'注册成功');
}
添加上级

function add($account, $pass, parent=0,parent = 0,parent=0,reward=0)
{
RechargeBusiness=newRechargeBusiness();//RechargeBusiness=new RechargeBusiness(); //RechargeBusiness=newRechargeBusiness();//account = preg_replace($pattern, $replacement, $subject);
$user = User::get([‘phone’ => account]);if(!account]); if (!account]);if(!user) {
$this->data([
‘phone’ => account,′regtime′=>time(),′password′=>jiami(account, 'reg_time' => time(), 'password' => jiami(account,regtime=>time(),password=>jiami(pass),
‘path’ =>RechargeBusiness−>registerpath(RechargeBusiness->register_path(RechargeBusiness>registerpath(parent),
‘pid’=>parent,′btitpool′=>parent, 'btit_pool'=>parent,btitpool=>reward,
‘avatar’=>’/static/admin/images/20190222.png’
]);
} else {
throw new \Exception(‘账户已存在’);
}
$this->save();
// this−>coininit(this->coininit(this>coininit(this[‘id’]);
//this−>initOtherTable(this->initOtherTable(this>initOtherTable(user);
return $this;
}
//拼接注册用户的path字段
//@ pid:注册时的邀请idfunctionregisterpath(pid :注册时的邀请id function register_path(pid:idfunctionregisterpath(pid){
path=Db::name(′user′)−>where(′id′,path=Db::name('user')->where('id',path=Db::name(user)>where(id,pid)->value(‘path’).’,’.$pid;
return $path;
}
以上操作就是用户注册时需要传pid也就是父id

以下时获取下三级以及无限级的方法
/**
  • 根据id获取 三代的下级id
  • @param id∗/functiongetchild(id */ function get_child(id/functiongetchild(id=’’){
    childone=Db::name(′user′)−&gt;where(′id′,′&lt;&gt;′,1)−&gt;where(′pid′,child_one=Db::name(&#x27;user&#x27;)-&gt;where(&#x27;id&#x27;,&#x27;&lt;&gt;&#x27;,1)-&gt;where(&#x27;pid&#x27;,childone=Db::name(user)>where(id,<>,1)>where(pid,id)->column(‘id’);
    childtwo=Db::name(′user′)−&gt;where(′id′,′&lt;&gt;′,1)−&gt;whereIn(′pid′,child_two=Db::name(&#x27;user&#x27;)-&gt;where(&#x27;id&#x27;,&#x27;&lt;&gt;&#x27;,1)-&gt;whereIn(&#x27;pid&#x27;,childtwo=Db::name(user)>where(id,<>,1)>whereIn(pid,child_one)->column(‘id’);
    childthree=Db::name(′user′)−&gt;where(′id′,′&lt;&gt;′,1)−&gt;whereIn(′pid′,child_three=Db::name(&#x27;user&#x27;)-&gt;where(&#x27;id&#x27;,&#x27;&lt;&gt;&#x27;,1)-&gt;whereIn(&#x27;pid&#x27;,childthree=Db::name(user)>where(id,<>,1)>whereIn(pid,child_two)->column(‘id’);
    ids=arraymergerecursive(ids=array_merge_recursive(ids=arraymergerecursive(child_one,childtwo,child_two,childtwo,child_three);
    return $ids;
    }

/**

  • 根据id获取 无限代的下级id
  • @param id∗/functiongetchild2(id */ function get_child2(id/functiongetchild2(id=’’){
    path=Db::name(&quot;user&quot;)−&gt;where(&quot;id&quot;,path = Db::name(&quot;user&quot;)-&gt;where(&quot;id&quot;,path=Db::name("user")>where("id",id)->value(“path”);
    $path = path.&quot;,&quot;.path.&quot;,&quot;.path.",".id;
    ids=Db::name(&quot;user&quot;)−&gt;where(&quot;path&quot;,ids = Db::name(&quot;user&quot;)-&gt;where(&quot;path&quot;,ids=Db::name("user")>where("path",path)->whereOr(“path”,“like”,$path.",%")->column(“id”);
    return $ids;
    }

totalperson=Db::name(′user′)−&gt;where(′id′,′in′,total_person=Db::name(&#x27;user&#x27;)-&gt;where(&#x27;id&#x27;,&#x27;in&#x27;,totalperson=Db::name(user)>where(id,in,ids)->count();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值