public function ceshi(){
$this->getTotalteamperformance(4);
}
function getTotalteamperformance($userid){//团队总业绩
$totalteamperformance=0;
// $userid=I('get.id');
$userlist=M('user')->where(array('pid1'=>$userid))->select();
if(count($userlist)>0){
$totalteamperformance=$totalteamperformance+M('user')->where(array('pid1'=>$userid))->sum('total_amount')+M('user')->where(array('pid2'=>$userid))->sum('total_amount');
foreach ($userlist as $k=> $v) {
$totalteamperformance=$totalteamperformance+M('user')->where(array('pid1'=>$user_id))->sum('total_amount');
$userlist1=M('user')->where(array('pid1'=>$v['user_id']))->select();
//dump($userlist1);
if(count($userlist1)>0){
$totalteamperformance=$totalteamperformance+$this->getChildernTotalteamperformance($userlist1);
}
}
}
echo $totalteamperformance;
}
function getChildernTotalteamperformance($user){
$totalteamperformance=0;
foreach ($user as $k=> $v) {
$totalteamperformance=$totalteamperformance+M('user')->where(array('pid1'=>$v['user_id']))->sum('total_amount');
$userlist1=M('user')->where(array('pid1'=>$v['user_id']))->select();
if(count($userlist1)>0){
$totalteamperformance=$totalteamperformance+$this->getChildernTotalteamperformance($userlist1);
}
}
return $totalteamperformance;
}
打开App,阅读手记