Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
starsw001
ShopXO
提交
4e1af35b
ShopXO
项目概览
starsw001
/
ShopXO
与 Fork 源项目一致
Fork自
纵之格 / ShopXO
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ShopXO
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
4e1af35b
编写于
6月 11, 2021
作者:
D
Devil
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
读取商品分类条件一维数组改为二维数组
上级
ee2992f8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
46 addition
and
12 deletion
+46
-12
application/admin/controller/Site.php
application/admin/controller/Site.php
+10
-2
application/service/GoodsService.php
application/service/GoodsService.php
+32
-9
application/service/SearchService.php
application/service/SearchService.php
+4
-1
未找到文件。
application/admin/controller/Site.php
浏览文件 @
4e1af35b
...
...
@@ -92,7 +92,11 @@ class Site extends Common
// 网站设置
case
'siteset'
:
// 获取商品一级分类
$where
=
[
'pid'
=>
0
,
'is_home_recommended'
=>
1
,
'is_enable'
=>
1
];
$where
=
[
[
'pid'
,
'='
,
0
],
[
'is_home_recommended'
,
'='
,
1
],
[
'is_enable'
,
'='
,
1
],
];
$category
=
GoodsService
::
GoodsCategoryList
([
'where'
=>
$where
]);
if
(
!
empty
(
$category
))
{
...
...
@@ -103,7 +107,11 @@ class Site extends Common
foreach
(
$category
as
&
$c
)
{
// 获取二级分类
$c
[
'items'
]
=
GoodsService
::
GoodsCategoryList
([
'where'
=>
[
'pid'
=>
$c
[
'id'
],
'is_enable'
=>
1
]]);
$where
=
[
[
'pid'
,
'='
,
$c
[
'id'
]],
[
'is_enable'
,
'='
,
1
],
];
$c
[
'items'
]
=
GoodsService
::
GoodsCategoryList
([
'where'
=>
$where
]);
// 配置的关键字
$c
[
'config_keywords'
]
=
array_key_exists
(
$c
[
'id'
],
$floor_keywords
)
?
$floor_keywords
[
$c
[
'id'
]]
:
''
;
...
...
application/service/GoodsService.php
浏览文件 @
4e1af35b
...
...
@@ -69,7 +69,10 @@ class GoodsService
if
(
empty
(
$data
)
||
config
(
'app_debug'
))
{
// 获取分类
$params
[
'where'
]
=
[
'pid'
=>
0
,
'is_enable'
=>
1
];
$params
[
'where'
]
=
[
[
'pid'
,
'='
,
0
],
[
'is_enable'
,
'='
,
1
],
];
$data
=
self
::
GoodsCategory
(
$params
);
// 存储缓存
...
...
@@ -90,19 +93,33 @@ class GoodsService
public
static
function
GoodsCategory
(
$params
=
[])
{
// 获取分类
$where
=
empty
(
$params
[
'where'
])
?
[
'pid'
=>
0
,
'is_enable'
=>
1
]
:
$params
[
'where'
];
if
(
empty
(
$params
[
'where'
]))
{
$where
=
[
[
'pid'
,
'='
,
0
],
[
'is_enable'
,
'='
,
1
],
];
}
else
{
$where
=
$params
[
'where'
];
}
$data
=
self
::
GoodsCategoryList
([
'where'
=>
$where
]);
if
(
!
empty
(
$data
))
{
// 基础条件、去除pid
$where_base
=
$where
;
$temp_column
=
array_column
(
$where
,
0
);
if
(
in_array
(
'pid'
,
$temp_column
))
{
unset
(
$where_base
[
array_search
(
'pid'
,
$temp_column
)]);
sort
(
$where_base
);
}
foreach
(
$data
as
&
$v
)
{
$where
[
'pid'
]
=
$v
[
'id'
];
$v
[
'items'
]
=
self
::
GoodsCategoryList
([
'where'
=>
$where
]);
$v
[
'items'
]
=
self
::
GoodsCategoryList
([
'where'
=>
array_merge
(
$where_base
,
[[
'pid'
,
'='
,
$v
[
'id'
]]])]);
if
(
!
empty
(
$v
[
'items'
]))
{
// 一次性查出所有二级下的三级、再做归类、避免sql连接超多
$where
[
'pid'
]
=
array_column
(
$v
[
'items'
],
'id'
);
$itemss
=
self
::
GoodsCategoryList
([
'where'
=>
$where
]);
$itemss
=
self
::
GoodsCategoryList
([
'where'
=>
array_merge
(
$where_base
,
[[
'pid'
,
'in'
,
array_column
(
$v
[
'items'
],
'id'
)]])]);
if
(
!
empty
(
$itemss
))
{
foreach
(
$v
[
'items'
]
as
&
$vs
)
...
...
@@ -135,7 +152,9 @@ class GoodsService
{
// 条件、附加必须启用状态
$where
=
empty
(
$params
[
'where'
])
?
[]
:
$params
[
'where'
];
$where
[
'is_enable'
]
=
1
;
// 增加启用条件
$where
[]
=
[
'is_enable'
,
'='
,
1
];
// 数量、默认0,0则全部
$m
=
isset
(
$params
[
'm'
])
?
intval
(
$params
[
'm'
])
:
0
;
...
...
@@ -197,7 +216,11 @@ class GoodsService
if
(
empty
(
$data
)
||
config
(
'app_debug'
))
{
// 商品大分类
$where
=
[
'pid'
=>
0
,
'is_home_recommended'
=>
1
,
'is_enable'
=>
1
];
$where
=
[
[
'pid'
,
'='
,
0
],
[
'is_home_recommended'
,
'='
,
1
],
[
'is_enable'
,
'='
,
1
],
];
$data
=
self
::
GoodsCategoryList
([
'where'
=>
$where
]);
if
(
!
empty
(
$data
))
{
...
...
@@ -287,7 +310,7 @@ class GoodsService
// 楼层左侧分类
if
(
!
empty
(
$floor_left_top_category
)
&&
!
empty
(
$floor_left_top_category
[
$v
[
'id'
]]))
{
$v
[
'items'
]
=
self
::
GoodsCategoryList
([
'where'
=>
[
'id'
=>
explode
(
','
,
$floor_left_top_category
[
$v
[
'id'
]])
],
'm'
=>
0
,
'n'
=>
0
]);
$v
[
'items'
]
=
self
::
GoodsCategoryList
([
'where'
=>
[
[
'id'
,
'in'
,
explode
(
','
,
$floor_left_top_category
[
$v
[
'id'
]])]
],
'm'
=>
0
,
'n'
=>
0
]);
}
else
{
$v
[
'items'
]
=
[];
}
...
...
application/service/SearchService.php
浏览文件 @
4e1af35b
...
...
@@ -466,7 +466,10 @@ class SearchService
if
(
MyC
(
'home_search_is_category'
,
0
)
==
1
)
{
$pid
=
empty
(
$params
[
'category_id'
])
?
0
:
intval
(
$params
[
'category_id'
]);
$data
=
GoodsService
::
GoodsCategoryList
([
'where'
=>
[
'pid'
=>
$pid
],
'field'
=>
'id,name'
]);
$where
=
[
[
'pid'
,
'='
,
$pid
],
];
$data
=
GoodsService
::
GoodsCategoryList
([
'where'
=>
$where
,
'field'
=>
'id,name'
]);
}
return
$data
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录