feat(home): 首页品牌服务主题轮播与后台可配置
- 首页单张 Banner 改为多张轮播,支持活动促销 / 平台实力 / 服务主题三种主题 - 平台实力卡片接入后端 stats 配置,展示专业师傅、区域覆盖、成功订单与底部数据 - fa_banner 新增 theme / action_text / stats 字段,后台可配置主题、按钮文案、统计数据、排序与上下架 - 默认配置双11活动、平台实力、家电清洗、快至30分钟上门 4 张轮播 - 支持后台配图、跳转链接、关闭活动位;无数据时后端返回兜底轮播 - 新增 schema_phase8.sql 迁移脚本
这个提交包含在:
@@ -187,33 +187,121 @@ class Home extends Base
|
||||
}
|
||||
|
||||
/**
|
||||
* 首页运营位(后台 fa_banner 可管,缺省回落到内置文案)
|
||||
* 首页轮播(后台 fa_banner 可管,支持活动 / 平台实力 / 服务主题)
|
||||
*/
|
||||
protected function banners()
|
||||
{
|
||||
$rows = Db::name('banner')->where('status', 'normal')->order('weigh desc,id desc')->limit(5)->select();
|
||||
$rows = Db::name('banner')
|
||||
->field('id,badge,title,subtitle,date_text,theme,action_text,stats,image,link,weigh')
|
||||
->where('status', 'normal')
|
||||
->order('weigh desc,id desc')
|
||||
->limit(8)
|
||||
->select();
|
||||
if (!$rows) {
|
||||
return [[
|
||||
'id' => 0, 'badge' => '家装季', 'title' => '双11 狂欢大促',
|
||||
'subtitle' => '下单立减 · 满额再返券', 'date_text' => '10.23 - 11.15',
|
||||
'image' => '', 'link' => '',
|
||||
]];
|
||||
return $this->defaultBanners();
|
||||
}
|
||||
|
||||
$themeText = [
|
||||
'promo' => '活动促销',
|
||||
'brand' => '平台实力',
|
||||
'service' => '服务主题',
|
||||
];
|
||||
|
||||
$ret = [];
|
||||
foreach ($rows as $r) {
|
||||
$theme = isset($themeText[$r['theme']]) ? $r['theme'] : 'promo';
|
||||
$stats = $this->parseBannerStats(isset($r['stats']) ? $r['stats'] : '');
|
||||
if ($theme === 'brand' && empty($stats)) {
|
||||
$stats = $this->defaultBrandStats();
|
||||
}
|
||||
$actionText = trim((string)$r['action_text']);
|
||||
if ($actionText === '' && $theme !== 'brand') {
|
||||
$actionText = '立即查看';
|
||||
}
|
||||
$ret[] = [
|
||||
'id' => (int)$r['id'],
|
||||
'badge' => $r['badge'],
|
||||
'title' => $r['title'],
|
||||
'subtitle' => $r['subtitle'],
|
||||
'date_text' => $r['date_text'],
|
||||
'image' => $r['image'],
|
||||
'link' => $r['link'],
|
||||
'id' => (int)$r['id'],
|
||||
'badge' => $r['badge'],
|
||||
'title' => $r['title'],
|
||||
'subtitle' => $r['subtitle'],
|
||||
'date_text' => $r['date_text'],
|
||||
'theme' => $theme,
|
||||
'theme_text' => $themeText[$theme],
|
||||
'action_text' => $actionText,
|
||||
'stats' => $stats,
|
||||
'image' => $r['image'],
|
||||
'link' => $r['link'],
|
||||
];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析平台实力主题的统计 JSON
|
||||
*/
|
||||
protected function parseBannerStats($raw)
|
||||
{
|
||||
$raw = trim((string)$raw);
|
||||
if ($raw === '') {
|
||||
return [];
|
||||
}
|
||||
$decoded = json_decode($raw, true);
|
||||
if (!is_array($decoded)) {
|
||||
return [];
|
||||
}
|
||||
$out = [];
|
||||
foreach ($decoded as $item) {
|
||||
if (!is_array($item) || !isset($item['value']) || !isset($item['label'])) {
|
||||
continue;
|
||||
}
|
||||
$out[] = [
|
||||
'value' => (string)$item['value'],
|
||||
'label' => (string)$item['label'],
|
||||
];
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台实力默认指标
|
||||
*/
|
||||
protected function defaultBrandStats()
|
||||
{
|
||||
return [
|
||||
['value' => '460万+', 'label' => '专业师傅'],
|
||||
['value' => '99.9%', 'label' => '区域覆盖到村镇'],
|
||||
['value' => '1762万', 'label' => '成功订单'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 无后台数据时的兜底轮播
|
||||
*/
|
||||
protected function defaultBanners()
|
||||
{
|
||||
return [
|
||||
[
|
||||
'id' => 0, 'badge' => '家装季', 'title' => '双11 狂欢大促',
|
||||
'subtitle' => '下单立减 · 满额再返券', 'date_text' => '10.23 - 11.15',
|
||||
'theme' => 'promo', 'theme_text' => '活动促销', 'action_text' => '立即抢购',
|
||||
'stats' => [], 'image' => '',
|
||||
'link' => '/pages/service/list?cat_id=1&cat_name=%E5%AE%B6%E5%85%B7',
|
||||
],
|
||||
[
|
||||
'id' => -1, 'badge' => '平台实力', 'title' => '平台实力',
|
||||
'subtitle' => '已有 176276994 个订单找到师傅', 'date_text' => '下单越多 · 越优惠',
|
||||
'theme' => 'brand', 'theme_text' => '平台实力', 'action_text' => '',
|
||||
'stats' => $this->defaultBrandStats(), 'image' => '', 'link' => '',
|
||||
],
|
||||
[
|
||||
'id' => -2, 'badge' => '服务主题', 'title' => '家电清洗季',
|
||||
'subtitle' => '空调 / 洗衣机 / 油烟机深度清洗', 'date_text' => '9.9 折起',
|
||||
'theme' => 'service', 'theme_text' => '服务主题', 'action_text' => '立即预约',
|
||||
'stats' => [], 'image' => '',
|
||||
'link' => '/pages/service/list?cat_id=10&cat_name=%E5%AE%B6%E7%94%B5',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取 fa_config 中的逗号分隔列表
|
||||
*/
|
||||
|
||||
在新工单中引用
屏蔽一个用户