+86
initialize(); // 获取当前域名 $host = $_SERVER['HTTP_HOST'] ?? ''; // 查询域名对应的租户ID $tenantDomain = TenantDomain::where('full_domain', $host) ->where('status', 1) ->whereNull('delete_time') ->find(); $tid = $tenantDomain ? (int)$tenantDomain['tid'] : 0; // 获取 Banner 数据 $banners = []; if ($tid > 0) { $banners = Banner::where('tid', $tid) ->whereNull('delete_time') ->order('sort', 'asc') ->order('id', 'desc') ->select() ->toArray(); // 处理图片路径 foreach ($banners as &$banner) { if (!empty($banner['image'])) { if (!preg_match('/^https?:\/\//', $banner['image'])) { $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $banner['image'] = $scheme . '://' . $host . (strpos($banner['image'], '/') === 0 ? '' : '/') . $banner['image']; } } } } // 获取新闻数据 $articles = []; if ($tid > 0) { $articles = Articles::where('tid', $tid) ->where('delete_time', null) ->where('status', 2) ->order('publish_date', 'desc') ->limit(8) ->select() ->toArray(); // 处理图片:如果文章image为空,则取分类的image foreach ($articles as &$article) { if (empty($article['image']) && !empty($article['cate'])) { $category = ArticlesCategory::where('id', $article['cate']) ->where('delete_time', null) ->find(); if ($category && !empty($category['image'])) { $article['image'] = $category['image']; } } // 处理图片路径 if (!empty($article['image']) && !preg_match('/^https?:\/\//', $article['image'])) { $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $article['image'] = $scheme . '://' . $host . (strpos($article['image'], '/') === 0 ? '' : '/') . $article['image']; } if (!empty($article['thumb']) && !preg_match('/^https?:\/\//', $article['thumb'])) { $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $article['thumb'] = $scheme . '://' . $host . (strpos($article['thumb'], '/') === 0 ? '' : '/') . $article['thumb']; } } } // 获取企业联系信息 $companyInfo = []; if ($tid > 0) { $companyInfo = Tenant::where('id', $tid) ->where('delete_time', null) ->field('contact_phone, contact_email, address, worktime') ->find(); }else{ $companyInfo = [ 'contact_phone' => '-', 'contact_email' => '-', 'address' => '-', 'worktime' => '-' ]; } // 辅助函数:去除 HTML 标签 function stripHtml($html) { if (empty($html)) return ''; $text = preg_replace('/<[^>]+>/', ' ', $html); $text = preg_replace('/\s+/', ' ', $text); return trim($text); } ?>
Stop wasting time and money designing and managing a website that doesn’t get results. Happiness guaranteed,
Stop wasting time and money designing and managing a website that doesn’t get results. Happiness guaranteed!Stop wasting time and money designing and managing a website that doesn’t get results. Happiness guaranteed!
如果您有任何需求,欢迎联系我们!
+86