闲来无事 自己琢磨了一下三三复制大公排 开始没有思路根据群友的思路大致改了一下

群友的代码

        $x = 1;
        $y = 0;
        $h =    1;
        for($y;$y<4;$y++){
            $s = $h - pow(3,$y-1);
            for($x;$x<$h + pow(3,$y);$x++){
                if($h > 1){
                    if(($x-$h > 0) && ($x - $h)%3 == 0){
                        $s ++;
                    }
                    echo $s.'->'.$x.'&nbsp';
                }else{
                    echo $x.'&nbsp';
                }
            }
            $h = $x;
            echo '</br>';
        }

自己写的

//取余数

function Kmod($bn, $sn)
{
 return intval(fmod(floatval($bn), $sn));
}

//添加会员 自动匹配位置根据图谱升级

function sadd(){
     
    $sid = 0;
    $slevel = 0;
     
    $count = Db::name('gongpai')->count();  
     
    if($count > 0){
         
        $count++;
        $yu = Kmod($count,3);
        if($yu == 0){
            $sid = $count/3;
        }elseif($yu == 1){
            $sid = ($count-1)/3;
        }elseif($yu == 2){
            $sid = ($count+1)/3;
        }
         
        $whr['id'] = $sid;
        $slevel = Db::name('gongpai')->where($whr)->find();
         
        $data['fatherid'] = $sid;
        $data['level'] = $slevel['level']+1;
        $data['dengji'] = 0;
        if($slevel['level'] < 9){
            Db::name('gongpai')->insert($data);
            svipup($sid);
        }
    }else{
         
        $data['fatherid'] = 0;
        $data['level'] = 1;
        $data['dengji'] = 0;
        Db::name('gongpai')->insert($data);
    }
      
}
 
//siv升级
function svipup($sid){
     
    $whr['id'] = $sid;
    $sinfo = Db::name('gongpai')->where($whr)->find();
     
    $whrs['fatherid'] = $sinfo['id'];
    $whrs['dengji'] = $sinfo['dengji'];
    $sons = Db::name('gongpai')->where($whrs)->count();
     
    if($sons > 2){
         
        //公排等级更新
        $data['dengji'] = $sinfo['dengji']+1;
        $whrup['id'] = $sinfo['id'];
        Db::name('gongpai')->where($whrup)->update($data);
         
        //会员svip等级更新
         
        if($sinfo['fatherid'] > 0){
            svipup($sinfo['fatherid']);
        }
         
    }else{
         
        if($sinfo['fatherid'] > 0){
            svipup($sinfo['fatherid']);
        }
         
    }
     
}

上效果

 

以上仅限学习使用!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐