Files
addons
app_download_files
extend
hyhproject
admin
app
common
conf
controller
Alipays.php
Appport.php
Areas.php
Articles.php
Auth.php
Base.php
Brands.php
Carts.php
Cashconfigs.php
Cashdraws.php
Chain3.php
Chain3base.php
Ect.php
Ectwallets.php
Error.php
Favorites.php
Goods.php
Goodsappraises.php
Goodscats.php
Goodsconsult.php
Index.php
Invoices.php
Juhui.php
Logmoneys.php
Messages.php
News.php
Note.php
Ordercomplains.php
Orderrefunds.php
Orders.php
Position.php
Qlgpay.php
Shoporders.php
Shopping.php
Shops.php
Switchs.php
Tag.php
Tags.php
Tmp.php
TradeRule.php
Unionpays.php
UserLevel.php
Useraddress.php
Users.php
Userscores.php
Uservouchers.php
Wallets.php
Weixinpays.php
model
validate
common
home
home2
mobile2
wechat2
.htaccess
command.php
mobile
oss
static
thinkphp
upload
vendor
wxtmp
.gitignore
.htaccess
.user.ini
404.html
H5436787D.wgt
admin.php
app-release.apk
app_download.html
cash.lock
demo.php
get_startup.php
get_version.php
get_version_new.php
index.html
index.php
reg.lock
robots.txt
qlg.tsgz.moe/hyhproject/app/controller/Areas.php
2019-09-06 23:53:10 +08:00

104 lines
3.6 KiB
PHP
Executable File

<?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;
}
}