null]; if ($id !== 0) { $where['id'] = $id; } if ($platform == 'preview') { $decorate = self::where($where)->order('id asc')->find(); } else { $where['status'] = 'normal'; $where['type'] = 'shop'; $decorate = self::where('find_in_set(:platform,platform)', ['platform' => $platform])->where($where)->order('id asc')->find(); } if (!$decorate) { new Exception('未找到模板'); } $template = self::getDecorateContent($decorate); return $template; } public static function getCustomDecorate($id) { $decorateContent = DecorateContent::all(['decorate_id' => $id]); foreach ($decorateContent as &$v) { $v['content'] = self::getDecorateContentByType($v); } return $decorateContent; } public static function asyncDecorateScreenShot($params) { $decorate = self::get($params['shop_id']); if ($decorate) { $decorate->image = $params['image']; $decorate->save(); } } public static function getDecorateContent($decorate) { $template['home'] = []; //首页 $template['user'] = []; //个人中心 $template['tabbar'] = []; //底部菜单 $template['popup'] = []; //弹出提醒 $template['float-button'] = []; //悬浮按钮 $decorateContent = DecorateContent::all(['decorate_id' => $decorate->id]); foreach ($decorateContent as $k => $v) { $v['content'] = self::getDecorateContentByType($v); $template[$v->category][] = $v; } return $template; } public static function getDecorateContentByType($templateValue) { $content = json_decode($templateValue->content, true); if (!is_array($content)) { $content = []; } switch ($templateValue['type']) { case 'search': case 'coupons': case 'live': case 'seckill': case 'groupon': case 'wallet-card': case 'order-card': case 'rich-text': case 'nav-bg': break; case 'banner': case 'menu': case 'adv': case 'grid-list': case 'popup': case 'nav-list': if (!empty($content['list']) && is_array($content['list'])) { foreach ($content['list'] as &$l) { $l['image'] && $l['image'] = cdnurl($l['image'], true); } unset($l); $content['list'] = array_values(array_filter($content['list'], function ($item) { return !self::isHiddenMenuItem($item); })); } else { $content['list'] = []; } break; case 'user': case 'title-block': case 'goods-list': case 'goods-group': case 'image-goods': $content['image'] && $content['image'] = cdnurl($content['image'], true); break; case 'tabbar': if (isset($content['style']) && $content['style'] < 3 && !empty($content['list']) && is_array($content['list'])) { foreach ($content['list'] as &$l) { $l['image'] && $l['image'] = cdnurl($l['image'], true); $l['activeImage'] && $l['activeImage'] = cdnurl($l['activeImage'], true); } unset($l); } elseif (!isset($content['list']) || !is_array($content['list'])) { $content['list'] = []; } break; case 'float-button': $content['image'] = cdnurl($content['image'], true); if (!empty($content['list']) && is_array($content['list'])) { foreach ($content['list'] as &$l) { if ($l['style'] == 1) { $l['image'] && $l['image'] = cdnurl($l['image'], true); } $l['btnimage'] && $l['btnimage'] = cdnurl($l['btnimage'], true); } unset($l); } else { $content['list'] = []; } break; } return $content; } /** * 已关闭的功能入口,不在前端展示 */ protected static function isHiddenMenuItem($item) { if (!is_array($item)) { return false; } $name = isset($item['name']) ? (string) $item['name'] : ''; $path = isset($item['path']) ? (string) $item['path'] : ''; $hiddenNames = ['我的报修', '门店管理', '我的拼团', '今日必拼']; if (in_array($name, $hiddenNames, true)) { return true; } $hiddenPaths = ['/pages/activity/groupon', '/pages/app/merchant', '/pages/order/after-sale/list']; foreach ($hiddenPaths as $hiddenPath) { if ($path && strpos($path, $hiddenPath) !== false) { return true; } } return false; } }