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

首先注册时:
function register()
{
p a r a m = param= param=this->request->param();
$phone = $param[‘phone’];
$password = $param[‘password’];
$verification_code = $param[‘code’];//验证码
$parent = p a r a m [ ′ p a r e n t i d ′ ] ; / / 上 级 的 i d 作 为 邀 请 码 i f ( ! S t r : : i s v a l i d p h o n e ( 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( p a s s w o r d ) ) r e t u r n r e t u r n j s o n ( [ ] , 400 , " 密 码 为 6 − 16 位 数 字 、 字 母 、 下 划 线 组 合 " ) ; i f ( ! U s e r : : g e t ( password) ) { return return_json([],400, "密码为6-16位数字、字母、下划线组合" ); } if( !User::get( password))returnreturnjson([],400,"616线");if(!User::get(parent) ){
return return_json([],400, “邀请码不存在” );
}
if (! t h i s − > r e g n u m ( 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 {
s m s = n e w S m s S e r v i c e ( sms = new SmsService( sms=newSmsService(phone);
s m s − > c h e c k ( sms->check ( sms>check(verification_code);
p a s s w o r d = R s a : : d e c r y p t ( password=Rsa::decrypt( password=Rsa::decrypt(password);
$user->add( $phone, p a s s w o r d , password, password,parent, r e w a r d ) ; i f ( reward); if ( reward);if(reward>0)
Db::name(‘reward_log’)->insert([‘uid’=> u s e r − > i d , ′ c h a n g e n u m ′ = > 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, p a r e n t = 0 , parent = 0, parent=0,reward=0)
{
R e c h a r g e B u s i n e s s = n e w R e c h a r g e B u s i n e s s ( ) ; / / RechargeBusiness=new RechargeBusiness(); // RechargeBusiness=newRechargeBusiness();//account = preg_replace($pattern, $replacement, $subject);
$user = User::get([‘phone’ => a c c o u n t ] ) ; i f ( ! account]); if (! account]);if(!user) {
$this->data([
‘phone’ => a c c o u n t , ′ r e g t i m e ′ = > t i m e ( ) , ′ p a s s w o r d ′ = > j i a m i ( account, 'reg_time' => time(), 'password' => jiami( account,regtime=>time(),password=>jiami(pass),
‘path’ => R e c h a r g e B u s i n e s s − > r e g i s t e r p a t h ( RechargeBusiness->register_path( RechargeBusiness>registerpath(parent),
‘pid’=> p a r e n t , ′ b t i t p o o l ′ = > parent, 'btit_pool'=> parent,btitpool=>reward,
‘avatar’=>’/static/admin/images/20190222.png’
]);
} else {
throw new \Exception(‘账户已存在’);
}
$this->save();
// t h i s − > c o i n i n i t ( this->coininit( this>coininit(this[‘id’]);
// t h i s − > i n i t O t h e r T a b l e ( this->initOtherTable( this>initOtherTable(user);
return $this;
}
//拼接注册用户的path字段
//@ p i d : 注 册 时 的 邀 请 i d f u n c t i o n r e g i s t e r p a t h ( pid :注册时的邀请id function register_path( pid:idfunctionregisterpath(pid){
p a t h = D b : : n a m e ( ′ u s e r ′ ) − > w h e r e ( ′ i d ′ , path=Db::name('user')->where('id', path=Db::name(user)>where(id,pid)->value(‘path’).’,’.$pid;
return $path;
}
以上操作就是用户注册时需要传pid也就是父id

以下时获取下三级以及无限级的方法
/**
  • 根据id获取 三代的下级id
  • @param i d ∗ / f u n c t i o n g e t c h i l d ( id */ function get_child( id/functiongetchild(id=’’){
    c h i l d o n e = D b : : n a m e ( ′ u s e r ′ ) − &gt; w h e r e ( ′ i d ′ , ′ &lt; &gt; ′ , 1 ) − &gt; w h e r e ( ′ p i d ′ , 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’);
    c h i l d t w o = D b : : n a m e ( ′ u s e r ′ ) − &gt; w h e r e ( ′ i d ′ , ′ &lt; &gt; ′ , 1 ) − &gt; w h e r e I n ( ′ p i d ′ , 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’);
    c h i l d t h r e e = D b : : n a m e ( ′ u s e r ′ ) − &gt; w h e r e ( ′ i d ′ , ′ &lt; &gt; ′ , 1 ) − &gt; w h e r e I n ( ′ p i d ′ , 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’);
    i d s = a r r a y m e r g e r e c u r s i v e ( ids=array_merge_recursive( ids=arraymergerecursive(child_one, c h i l d t w o , child_two, childtwo,child_three);
    return $ids;
    }

/**

  • 根据id获取 无限代的下级id
  • @param i d ∗ / f u n c t i o n g e t c h i l d 2 ( id */ function get_child2( id/functiongetchild2(id=’’){
    p a t h = D b : : n a m e ( &quot; u s e r &quot; ) − &gt; w h e r e ( &quot; i d &quot; , path = Db::name(&quot;user&quot;)-&gt;where(&quot;id&quot;, path=Db::name("user")>where("id",id)->value(“path”);
    $path = p a t h . &quot; , &quot; . path.&quot;,&quot;. path.",".id;
    i d s = D b : : n a m e ( &quot; u s e r &quot; ) − &gt; w h e r e ( &quot; p a t h &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;
    }

t o t a l p e r s o n = D b : : n a m e ( ′ u s e r ′ ) − &gt; w h e r e ( ′ i d ′ , ′ i n ′ , 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、付费专栏及课程。

余额充值