传销树-如何按级别计算节点并按级别划分佣金

guicsvcw  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(198)

我想把佣金逐级划分。一级完成佣金7%二级完成佣金14%三级完成佣金21%这样
树图像示例
我尝试此代码,但输出=

array(4) {
  [3]=>
  int(0)
  [2]=>
  int(2)
  [1]=>
  int(5)
  [0]=>
  int(8)
}

输出按列计数,但我想按行逐级计数以除以佣金。

$pare01= $rowfeatchdata['usr_id'];
    class LevelDepCount{
    private $level_count=array();
    /**
     * Display all child of an element
     * @return int Count of element
     */
    public function display_children($parent, $level, $isStarted=true) 
    {
    global $con; 
    if($isStarted)
     $this->level_count=array(); // Reset for new ask
    echo $sqlcan="SELECT usr_id FROM register_user WHERE refrenceid='".$parent."'";  
     $result = mysqli_query($con, $sqlcan);
     $count=0; // For the level in the section 
      while ($row = mysqli_fetch_array($result))
       {
        $data=  str_repeat(' ',$level).$row['register_user']."\n";
        $count += 1 + $this->display_children($row['usr_id'], $level+1,false); 
       }
        if(array_key_exists($level, $this->level_count))
            $this->level_count[$level]+=$count;
        else
            $this->level_count[$level]=$count;
            return $count;     
    }

    /**Return the count by level.*/ 
        public function getCountByLevel(){  
        return $this->level_count;
    }
}
$counter=new LevelDepCount();
$counter->display_children($pare01,0);
var_dump($counter->getCountByLevel());

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题