Commit e567922c by 杨树贤

标准品牌输出

parent 5ebfdcd9
......@@ -19,7 +19,7 @@ QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=192.168.1.235
REDIS_HOST=192.168.1.234
REDIS_PASSWORD=icDb29mLy2s
REDIS_PORT=6379
......
......@@ -2,13 +2,13 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="fb90add0-1393-48c2-9f26-72365d42cd03" name="变更" comment="">
<change beforePath="$PROJECT_DIR$/.env" beforeDir="false" afterPath="$PROJECT_DIR$/.env" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Providers/ViewServiceProvider.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Providers/ViewServiceProvider.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Controllers/BrandController.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Controllers/BrandController.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/Http/Services/BrandService.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/Http/Services/BrandService.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/app/helpers.php" beforeDir="false" afterPath="$PROJECT_DIR$/app/helpers.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bootstrap/app.php" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/app.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/bootstrap/cache/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/bootstrap/cache/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/common/header.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/common/header.blade.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/common/headerNav.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/common/headerNav.php" afterDir="false" />
<change beforePath="$PROJECT_DIR$/resources/views/common/mallHeaderNav.blade.php" beforeDir="false" afterPath="$PROJECT_DIR$/resources/views/common/mallHeaderNav.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" />
......
......@@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Http\Services\BrandService;
use Illuminate\Http\Request;
class BrandController extends Controller
......@@ -23,7 +24,8 @@ class BrandController extends Controller
*/
public function map()
{
return view('brand.map');
$brandList = BrandService::getStandardBrandList();
return view('brand.map',compact('brandList'));
}
public function list()
{
......
......@@ -2,20 +2,41 @@
namespace App\Http\Services;
use Illuminate\Support\Facades\Redis;
class BrandService
{
//获取首页需要的所有分类,没有英文名称的不要
public static function getClassificationForHome()
//获取品牌页的数据(标准品牌)
public static function getStandardBrandList()
{
$classification = [];
//先获取所有分类
$topClassMapping = config('field.top_class_mapping');
foreach ($topClassMapping as $key=>$mapping) {
$classification[$key] = [];
$redisKey = 'semour_standard_brand_map';
$standardBrandList = Redis::get($redisKey);
if ($standardBrandList) {
return $standardBrandList;
}
$standardBrandCache = Redis::hgetall('standard_brand');
$standardBrandCache = array_map(function ($value) {
return json_decode($value, true);
}, $standardBrandCache);
$letters = generate_letters();
$standardBrandList = [];
foreach ($standardBrandCache as $standardBrand) {
$matchLetter = false;
foreach ($letters as $letter) {
if (start_with(strtoupper($standardBrand['brand_name']),$letter)) {
$standardBrandList[$letter][] = $standardBrand;
$matchLetter = true;
}
}
if (!$matchLetter) {
$standardBrandList['#'][] = $standardBrand;
}
}
$data = [];
ksort($standardBrandList);
Redis::set($redisKey, json_encode($standardBrandList), 60);
return $standardBrandList;
}
}
<?php
function test_helper() {
function test_helper()
{
return 'OK';
}
if (!function_exists('start_with')) {
function start_with($str, $pattern)
{
return strpos($str, $pattern) === 0;
}
}
if (!function_exists('generate_letters')) {
function generate_letters($upper = true)
{
$letters = [];
for ($i = 65; $i < 91; $i++) {
$letters[] = $upper ? strtoupper(chr($i)) : strtolower(chr($i));
}
return $letters;
}
}
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