首先注册时:
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′];//上级的id作为邀请码if(!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,"密码为6−16位数字、字母、下划线组合");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 ′ ) − > w h e r e ( ′ i d ′ , ′ < > ′ , 1 ) − > w h e r e ( ′ p i d ′ , child_one=Db::name('user')->where('id','<>',1)->where('pid', 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 ′ ) − > w h e r e ( ′ i d ′ , ′ < > ′ , 1 ) − > w h e r e I n ( ′ p i d ′ , child_two=Db::name('user')->where('id','<>',1)->whereIn('pid', 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 ′ ) − > w h e r e ( ′ i d ′ , ′ < > ′ , 1 ) − > w h e r e I n ( ′ p i d ′ , child_three=Db::name('user')->where('id','<>',1)->whereIn('pid', 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 ( " u s e r " ) − > w h e r e ( " i d " , path = Db::name("user")->where("id", path=Db::name("user")−>where("id",id)->value(“path”);
$path = p a t h . " , " . path.",". path.",".id;
i d s = D b : : n a m e ( " u s e r " ) − > w h e r e ( " p a t h " , ids = Db::name("user")->where("path", 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 ′ ) − > w h e r e ( ′ i d ′ , ′ i n ′ , total_person=Db::name('user')->where('id','in', totalperson=Db::name(′user′)−>where(′id′,′in′,ids)->count();