{php} use app\model\Category; // 一级栏目的banner $firstCategoryId = Category::firstGradeId($category['path'], $category['id']); if ($firstCategoryId == $category['id']) { $bg_pc = $category['bg']; $bg_mobile = $category['bg_mobile']; } else { $firstCategory = Category::where('id', $firstCategoryId)->field('id,title,bg,bg_mobile')->find(); $bg_pc = $firstCategory['bg']; $bg_mobile = $firstCategory['bg_mobile']; } $bgImg = $isMobile? $bg_mobile : $bg_pc; $bgImg = trim($bgImg); $defaultBg = request()->controller() == 'Index' ? '' : '/static/web/images/public/header-bg.jpg'; $bgImg = $bgImg ?: $defaultBg; {/php}