Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
fae5729e
Commit
fae5729e
authored
May 09, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
商品分类接口加缓存优化
parent
2b2b18fd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
7 deletions
+26
-7
Category.php
addons/shopro/controller/Category.php
+25
-6
Order.php
addons/shopro/listener/Order.php
+1
-0
.gitkeep
runtime/.gitkeep
+0
-1
No files found.
addons/shopro/controller/Category.php
View file @
fae5729e
...
...
@@ -2,7 +2,9 @@
namespace
addons\shopro\controller
;
use
addons\shopro\service\goods\GoodsService
;
use
app\admin\model\shopro\Category
as
CategoryModel
;
use
app\admin\model\shopro\goods\Goods
as
GoodsModel
;
use
think\Cache
;
class
Category
extends
Common
...
...
@@ -11,8 +13,25 @@ class Category extends Common
protected
$noNeedLogin
=
[
'*'
];
protected
$noNeedRight
=
[
'*'
];
// 缓存键名
const
CACHE_INDEX_KEY
=
'shopro_category_index'
;
// 缓存键名
const
CACHE_LIST_KEY
=
'shopro_category_tree'
;
// 缓存有效期(1小时)
const
CACHE_TTL
=
3600
;
public
function
index
()
{
// 如果不需要刷新缓存,先尝试从缓存获取
$refresh
=
$this
->
request
->
param
(
'refresh'
,
0
);
if
(
!
$refresh
)
{
$cacheData
=
Cache
::
get
(
self
::
CACHE_INDEX_KEY
);
if
(
$cacheData
)
{
$this
->
success
(
'分类详情'
,
$cacheData
);
}
}
$id
=
$this
->
request
->
param
(
'id'
,
0
);
$category
=
CategoryModel
::
where
(
'parent_id'
,
0
)
->
normal
()
->
order
(
'weigh'
,
'desc'
)
->
order
(
'id'
,
'desc'
);
if
(
$id
)
{
...
...
@@ -27,13 +46,13 @@ class Category extends Common
$childrenString
=
$category
->
getChildrenString
(
$category
);
$categories
=
CategoryModel
::
where
(
'id'
,
$category
->
id
)
->
normal
()
->
with
([
$childrenString
])
->
find
();
// 将结果存入缓存
Cache
::
set
(
self
::
CACHE_INDEX_KEY
,
$categories
,
self
::
CACHE_TTL
);
$this
->
success
(
'商城分类'
,
$categories
);
}
// 缓存键名
const
CACHE_KEY
=
'shopro_category_tree'
;
// 缓存有效期(24小时)
const
CACHE_TTL
=
86400
;
/**
* 获取完整分类树(包含二级、三级、四级分类)
...
...
@@ -47,7 +66,7 @@ class Category extends Common
// 如果不需要刷新缓存,先尝试从缓存获取
if
(
!
$refresh
)
{
$cacheData
=
Cache
::
get
(
self
::
CACHE_KEY
);
$cacheData
=
Cache
::
get
(
self
::
CACHE_
LIST_
KEY
);
if
(
$cacheData
)
{
$this
->
success
(
'分类列表'
,
$cacheData
);
}
...
...
@@ -67,7 +86,7 @@ class Category extends Common
unset
(
$category
);
// 将结果存入缓存
Cache
::
set
(
self
::
CACHE_KEY
,
$categories
,
self
::
CACHE_TTL
);
Cache
::
set
(
self
::
CACHE_
LIST_
KEY
,
$categories
,
self
::
CACHE_TTL
);
$this
->
success
(
'分类列表'
,
$categories
);
}
...
...
addons/shopro/listener/Order.php
View file @
fae5729e
...
...
@@ -102,6 +102,7 @@ class Order
// 这里会自动检测订单支付状态
$order
=
$payOper
->
score
(
$order
,
$order
->
deduct_score
);
// TODO 下单成功,增加用户积分,支付金额与积分1:1增加
}
// 删除购物车
...
...
runtime/.gitkeep
deleted
100644 → 0
View file @
2b2b18fd
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment