You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
103
hyhproject/app/controller/Areas.php
Executable file
103
hyhproject/app/controller/Areas.php
Executable file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
namespace wstmart\app\controller;
|
||||
use wstmart\common\model\Areas as M;
|
||||
use think\Db;
|
||||
/**
|
||||
* ============================================================================
|
||||
* 地区控制器
|
||||
*/
|
||||
class Areas extends Base{
|
||||
/**
|
||||
* 列表查询
|
||||
*/
|
||||
public function listQuery(){
|
||||
$m = new M();
|
||||
$rs = $m->listQuery();
|
||||
exit(jsonReturn('', 1,$rs));
|
||||
}
|
||||
// CREATE TABLE `hyh_user_trees` (
|
||||
// `id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
// `uid` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
|
||||
// `pid` int(11) NOT NULL DEFAULT '0' COMMENT '父ID',
|
||||
// `bid` int(11) NOT NULL DEFAULT '0' COMMENT '家族ID',
|
||||
// `lft` int(11) NOT NULL DEFAULT '1' COMMENT '左节点',
|
||||
// `rgt` int(11) NOT NULL DEFAULT '2' COMMENT '右节点',
|
||||
// `t_level` smallint(6) NOT NULL DEFAULT '0' COMMENT '层级',
|
||||
// `update_time` int(10) NOT NULL DEFAULT '0' COMMENT '时间',
|
||||
// PRIMARY KEY (`id`)
|
||||
// ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT;
|
||||
public function tmp(){
|
||||
return;
|
||||
set_time_limit(0);
|
||||
$user_list = Db::table('rd_users')->where('1=1')->field('user_id,first_leader,shop_id')->order('user_id asc')->select();
|
||||
foreach ($user_list as $v) {
|
||||
$u_info = Db::table('rd_users')->where('user_id='.$v['user_id'])->field('user_id,first_leader,shop_id')->find();
|
||||
$userId = $u_info['shop_id'];
|
||||
if($userId){
|
||||
if($u_info['first_leader']){
|
||||
$p_info = Db::table('rd_users')->where('user_id='.$u_info['first_leader'])->field('user_id,shop_id')->find();
|
||||
$pid = $p_info['shop_id'];
|
||||
}else{
|
||||
$pid = 0;
|
||||
}
|
||||
ectLog($userId,10,1,'注册送ect',['userECT'=>['exp','userECT+10']]);
|
||||
if($pid){
|
||||
ectLog($pid,5,1,'推荐送ect',['userECT'=>['exp','userECT+5']]);
|
||||
}
|
||||
$this->create_tree($userId,$pid,0);
|
||||
}
|
||||
|
||||
}
|
||||
die('ok');
|
||||
}
|
||||
function create_tree($uid,$pid){
|
||||
if(!$uid) return;
|
||||
if(Db::name('user_trees')->where(array('uid'=>$uid))->find()) return;//树里有
|
||||
if($pid){
|
||||
$p_info = Db::name('user_trees')->where(array('uid'=>$pid))->field('bid,t_level')->find();
|
||||
if($p_info['t_level']){
|
||||
$t_level = $p_info['t_level'] + 1;
|
||||
}else{
|
||||
$t_level = 2;
|
||||
}
|
||||
if($p_info['bid']){
|
||||
$bid = $p_info['bid'];
|
||||
}else{
|
||||
$bid = $pid;
|
||||
}
|
||||
|
||||
}else{
|
||||
$bid = $uid;
|
||||
$t_level = 1;
|
||||
}
|
||||
$set = array(
|
||||
'uid'=>$uid,
|
||||
'pid'=>$pid,
|
||||
'bid'=>$bid,
|
||||
't_level'=>$t_level,
|
||||
'update_time'=>time()
|
||||
);
|
||||
Db::name('user_trees')->insert($set);
|
||||
//获取家族树最顶级节点,重建树
|
||||
$this->rebuild_tree($bid,1);//重建树,建立有左右值的数据表,对整个结构重新进行一次编号
|
||||
|
||||
}
|
||||
function rebuild_tree($root, $left) {
|
||||
// the right value of this node is the left value + 1
|
||||
$right = $left+1;
|
||||
// get all children of this node
|
||||
$trees = Db::name('user_trees')->where(array('pid'=>$root))->field('uid')->select();
|
||||
if($trees){
|
||||
foreach ($trees as $k => $v) {
|
||||
$right = $this->rebuild_tree($v['uid'], $right);
|
||||
}
|
||||
}
|
||||
$set = array(
|
||||
'lft' => $left,
|
||||
'rgt' => $right,
|
||||
);
|
||||
Db::name('user_trees')->where(array('uid'=>$root))->update($set);
|
||||
// return the right value of this node + 1
|
||||
return $right + 1;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user