菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
2896
4

超过俩小时未解决的递归死循环。。求救

原创
05/13 14:22
阅读数 3341
 private function countAllChild($tempCount, $mid, $level = 0)
    {
//        die('死循环阻止');
        $tableShopMember = 'ewei_shop_member';
//        根据uid拿到shopmember对象
        logging_run($mid . '查找等级:' . $level);
        if ($level > 0) {
            if ($mid == null) {
                return;
            }
            $sql = 'select id from ' . tablename($tableShopMember) . ' where agentlevel >= ' . $level . ' and agentid = ' . $mid;
            $childrenDirect = pdo_fetchall($sql);
        } else {
            $childrenDirect = pdo_getall($tableShopMember, ['agentid' => $mid], array('id', 'uid'));// 直接下级
        }

        $childrenDirect ? array_push($this->childrenArray, $childrenDirect) : '';

        $countCurr = count($childrenDirect);

        if ($countCurr > 0) {
            foreach ($childrenDirect as $l) {

                $agentId = $l['id'];
//                logging_run('传入countAllChild' . $agentId);
                $sql = 'select id from ' . tablename($tableShopMember) . ' where agentlevel >= ' . $level . ' and agentid = ' . $agentId;
                $childrenDirect1 = pdo_fetchall($sql);

//                var_dump($childrenDirect1);
                $childrenDirect1 ? array_push($this->childrenArray, $childrenDirect1) : '';

                $countCurr1 = count($childrenDirect1);
                logging_run($agentId . '的下级数量=' . $countCurr1);
//                logging_run($childrenDirect1);

                if ($countCurr1 > 0) {
                    $this->countAllChild($tempCount, $agentId, $level);
                }
            }
        }
    }

发表评论

0/200
2896 点赞
4 评论
收藏
为你推荐 换一批