2020-11-25 01:07:06 +00:00
|
|
|
<?php
|
|
|
|
namespace app\widget;
|
|
|
|
|
|
|
|
use think\facade\{View, Cache};
|
|
|
|
use app\model\Category;
|
|
|
|
|
|
|
|
class Menu
|
|
|
|
{
|
|
|
|
public function index($categoryId)
|
|
|
|
{
|
2020-11-25 10:48:29 +00:00
|
|
|
$menus = Cache::get('front_menus');
|
2020-11-25 12:15:51 +00:00
|
|
|
$menus = null;
|
2020-11-25 01:07:06 +00:00
|
|
|
if(empty($menus)){
|
|
|
|
$menus = Category::getListForFrontMenu();
|
2020-11-25 10:48:29 +00:00
|
|
|
Cache::set('front_menus', $menus, 3600 * 12);
|
2020-11-25 01:07:06 +00:00
|
|
|
}
|
|
|
|
$currentFirstId = 0;
|
|
|
|
if (is_numeric($categoryId) && $categoryId > 0) {
|
|
|
|
$currentFirstId = Category::firstGradeById($categoryId);
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'categoryId' => $categoryId,
|
|
|
|
'menus' => $menus,
|
2020-11-25 02:32:42 +00:00
|
|
|
'currentFirstId' => $currentFirstId,
|
2020-11-25 01:07:06 +00:00
|
|
|
];
|
|
|
|
return View::assign($data)->fetch('public/menu');
|
|
|
|
}
|
|
|
|
}
|