public function income() {
$id = $this->request->request('user_id');
$page = $this->request->request('page');
$pageSize = 10;
$offset = ($page -1)*$pageSize;
$push_users = Db::name('user')->where(array('promote_id' => $id))->count();
$usersDeclarationZones = Db::name('declarations_log')->where(array('user_id'=>$id,'is_del'=>0,'status'=>1))->column('declarations_id');
$down_users = array();
foreach ($usersDeclarationZones as $declarationZone){
$currentZoneDowns = $this->getUser($id,0,$declarationZone);
$down_users = array_merge($down_users,$currentZoneDowns);
}
$tmp_arr = array();
foreach($down_users as $k => $v)
{
if(in_array($v['user_id'], $tmp_arr))
//搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true
{
unset($down_users[$k]);
//删除掉数组($arr)里相同ID的数组
}
else {
$tmp_arr[] = $v['user_id'];
//记录已有的id
}
}
$down_num = count($tmp_arr);
$incomeLog = Db::name('user_income_log')->where(array('user_id'=>$id,))->order('createtime DESC')->limit($offset,$pageSize)->select();
foreach ($incomeLog as &$item) {
$item['createtime'] = date('y-m-d H:i',$item['createtime']);
$userInfo = Db::name('user')->where('id',$item['provide_id'])->find();
if($userInfo['is_true']==1){
$item['name'] = $userInfo['username'];
}else{
$item['name'] = 'Id'.$userInfo['id'];
}
}
$data = array(
'push_num' => $push_users,
'down_num' => $down_num,
'income_log' => $incomeLog
);
$this->success('请求成功', $data);
} |
public function income() {
$id = $this->request->request('user_id');
$page = $this->request->request('page');
$pageSize = 10;
$offset = ($page -1)*$pageSize;
$push_users = Db::name('user')->where(array('promote_id' => $id))->count();
$usersDeclarationZones = Db::name('declarations_log')->where(array('user_id'=>$id,'is_del'=>0,'status'=>1))->column('declarations_id');
$down_users = array();
foreach ($usersDeclarationZones as $declarationZone){
$currentZoneDowns = $this->getUser($id,0,$declarationZone);
$down_users = array_merge($down_users,$currentZoneDowns);
}
$tmp_arr = array();
foreach($down_users as $k => $v)
{
if(in_array($v['user_id'], $tmp_arr))
//搜索$v[$key]是否在$tmp_arr数组中存在,若存在返回true
{
unset($down_users[$k]);
//删除掉数组($arr)里相同ID的数组
}
else {
$tmp_arr[] = $v['user_id'];
//记录已有的id
}
}
$down_num = count($tmp_arr);
$incomeLog = Db::name('user_income_log')->where(array('user_id'=>$id,))->order('createtime DESC')->limit($offset,$pageSize)->select();
foreach ($incomeLog as &$item) {
$item['createtime'] = date('y-m-d H:i',$item['createtime']);
$userInfo = Db::name('user')->where('id',$item['provide_id'])->find();
if($userInfo['is_true']==1){
$item['name'] = $userInfo['username'];
}else{
$item['name'] = 'Id'.$userInfo['id'];
}
}
$data = array(
'push_num' => $push_users,
'down_num' => $down_num,
'income_log' => $incomeLog
);
$this->success('请求成功', $data);
}
public function getUser($id, $num,$declarationZone) {
static $layer = array();
/* if ($num === 11) {
$totalDowns = $layer;
unset($layer);
return $totalDowns;
}*/
$data = Db::name('declarations_log')->field('id,user_id,pid')
// ->where(array('pid' => $id,))
->where(array('pid' => $id,'declarations_id'=>$declarationZone))
->select();
$num++;
foreach ($data as $v) {
//if($v['is_true']==1){
if(true){
$layer[] = $v;
}
$this->getUser($v['user_id'], $num,$declarationZone); //查询下级的下级用户
}
return $layer;
} |
public function getUser($id, $num,$declarationZone) {
static $layer = array();
/* if ($num === 11) {
$totalDowns = $layer;
unset($layer);
return $totalDowns;
}*/
$data = Db::name('declarations_log')->field('id,user_id,pid')
// ->where(array('pid' => $id,))
->where(array('pid' => $id,'declarations_id'=>$declarationZone))
->select();
$num++;
foreach ($data as $v) {
//if($v['is_true']==1){
if(true){
$layer[] = $v;
}
$this->getUser($v['user_id'], $num,$declarationZone); //查询下级的下级用户
}
return $layer;
}