处理模块链接

This commit is contained in:
Edward Yang 2022-07-18 11:24:42 +08:00
parent 2770fe5de2
commit 0a3f26c7c7
2 changed files with 44 additions and 2 deletions

View File

@ -11,6 +11,8 @@
namespace Beike\Services;
use Beike\Models\Product;
use Beike\Repositories\ProductRepo;
use Illuminate\Support\Str;
class DesignService
@ -42,8 +44,47 @@ class DesignService
}
private static function handleSlideShow($content)
/**
* 处理 SlideShow 模块
*
* @param $content
* @return array
* @throws \Exception
*/
private static function handleSlideShow($content): array
{
foreach ($content['images'] as $index => $image) {
$content['images'][$index]['image'] = image_resize($image[current_language_code()] ?? '');
$link = $image['link'];
if (empty($link)) {
continue;
}
$type = $link['type'] ?? '';
$value = (int)$link['value'] ?? 0;
if ($type && $value) {
$content['images'][$index]['link']['link'] = self::handleLink($type, $value);
}
}
return $content;
}
/**
* 处理链接
*
* @param $type
* @param $value
* @return string
*/
private static function handleLink($type, $value): string
{
if ($type == 'product') {
return shop_route('products.show', ['product' => $value]);
}
if ($type == 'category') {
return shop_route('categories.show', ['category' => $value]);
}
return '';
}
}

View File

@ -18,6 +18,8 @@ class ShopServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__ . '/../Routes/shop.php');
$uri = request()->getRequestUri();
load_settings();
@ -25,7 +27,6 @@ class ShopServiceProvider extends ServiceProvider
return;
}
$this->loadRoutesFrom(__DIR__ . '/../Routes/shop.php');
$this->mergeConfigFrom(__DIR__ . '/../../Config/beike.php', 'beike');
$this->registerGuard();