继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

递归统计团队奖, 计算每个人下线的业绩(pid)

小陈vlog
关注TA
已关注
手记 24
粉丝 16
获赞 81
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,阅读手记
2人推荐
发表评论
随时随地看视频慕课网APP