Commit d298318a by 杨树贤

分类数据放到商城头部

parent 327cda48
......@@ -2,7 +2,14 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change afterPath="$PROJECT_DIR$/app/Http/ViewComposers/ClassificationViewComposer.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Services/ClassService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/ClassService.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/ViewComposers/MallHeaderClassViewComposer.php" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/app/Providers/AppServiceProvider.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Providers/AppServiceProvider.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/app.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/app.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/config/field.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/field.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/common/mallHeaderTop.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/common/mallHeaderTop.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/app/public/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/app/public/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/storage/framework/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/storage/framework/.gitignore" afterDir="false" />
......
<?php
namespace App\Http\Services;
class BrandService
{
//获取首页需要的所有分类,没有英文名称的不要
public static function getClassificationForHome()
{
$classification = [];
//先获取所有分类
$topClassMapping = config('field.top_class_mapping');
foreach ($topClassMapping as $key=>$mapping) {
$classification[$key] = [];
}
}
}
......@@ -2,7 +2,50 @@
namespace App\Http\Services;
use Illuminate\Support\Facades\Redis;
class ClassService
{
//获取首页需要的所有分类,没有英文名称的不要
public static function getClassificationForHome()
{
//先获取所有分类
$classCache = Redis::hgetall('pool_class_info');
$topClassList = [];
foreach ($classCache as $key => &$class) {
$class = json_decode($class, true);
if (!$class['parent_id']) {
$topClassList[] = $class;
}
}
unset($class);
foreach ($classCache as $key => $class) {
if (!$class['parent_id']) {
continue;
}
foreach ($topClassList as &$topClass) {
if ($topClass['class_id'] == $class['parent_id']) {
$topClass['children'][] = $class;
}
}
unset($topClass);
}
$topClassMapping = config('field.top_class_mapping');
$topFields = array_map(function ($value){
return [
'class_name' => $value,
];
},$topClassMapping);
foreach ($topClassMapping as $key => $mapping) {
foreach ($topClassList as $topClass) {
if (in_array($topClass['class_id'], $topClassMapping[$key])) {
$topFields[$key]['children'][] = $topClass;
}
}
}
return array_values($topFields);
}
}
<?php
namespace App\Http\Services;
class DataService
{
}
......@@ -2,12 +2,14 @@
namespace App\Http\ViewComposers;
use App\Http\Services\ClassService;
use Illuminate\View\View;
class MallHeaderClassViewComposer
class ClassificationViewComposer
{
public function compose(View $view)
{
// $view->with('foo', 'bar');
$classification = ClassService::getClassificationForHome();
$view->with('classification', $classification);
}
}
......@@ -25,6 +25,5 @@ class AppServiceProvider extends ServiceProvider
public function boot()
{
//
View::share ('public',config('field.public_url'));
}
}
<?php
namespace App\Providers;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;
class ViewServiceProvider extends ServiceProvider
{
/**
* 注册任何应用服务
*
* @return void
*/
public function register()
{
//
}
/**
* 引导任何应用服务
*
* @return void
*/
public function boot()
{
View::share('public', config('field.public_url'));
View::composer(
['common.mallHeaderTop'],
'App\Http\ViewComposers\ClassificationViewComposer'
);
}
}
File mode changed
File mode changed
......@@ -174,6 +174,7 @@ return [
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\ViewServiceProvider::class,
],
......
......@@ -7,5 +7,12 @@ return [
-1 => 'Closed',
0 => 'Pending',
1 => 'Replied',
],
//顶级分类和具体分类的映射,目前是写死的
'top_class_mapping' => [
'Actives' => [13396, 13782, 13359, 13287, 13482, 13488],
'Passives' => [13693, 13799, 13706, 13586, 13626, 13883],
'Modules & Devices & Products' => [13550, 13449, 13821, 13734, 13757, 13762],
]
];
......@@ -5,4 +5,4 @@
GRAND OPENING OF SEMOUR ELECTRONICS ONLINE STORE. CLICK TO VISIT.
</div>
</div>
@endempty
\ No newline at end of file
@endempty
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment