Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
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
bp
goods
Commits
4a42c6bb
Commit
4a42c6bb
authored
Jun 24, 2021
by
luhongguang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update:商品类型接口调整
parent
9c167523
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
13 deletions
+23
-13
Goods.php
application/modules/Goods/controllers/Goods.php
+2
-1
CategoryService.php
application/services/goods/CategoryService.php
+21
-12
No files found.
application/modules/Goods/controllers/Goods.php
View file @
4a42c6bb
...
...
@@ -22,7 +22,8 @@ class GoodsController extends Base
*/
public
function
get_goods_category_listAction
()
{
$categoryList
=
CategoryService
::
getCategoryList
();
$name
=
empty
(
$this
->
params
[
"category_name"
])
?
""
:
$this
->
params
[
"category_name"
];
$categoryList
=
CategoryService
::
getCategoryList
(
$name
);
$this
->
success
([
"result"
=>
$categoryList
]);
}
...
...
application/services/goods/CategoryService.php
View file @
4a42c6bb
...
...
@@ -8,25 +8,34 @@ class CategoryService
{
/**
* 商品分类列表数据
* @param string $name
* @return array
*/
public
static
function
getCategoryList
()
public
static
function
getCategoryList
(
$name
=
""
)
{
//todo::加上redis
$allCategoryList
=
Category
::
getRecordList
([],
[
'category_id'
,
'parent_category_id'
,
'name'
,
'level'
]);
$where
=
[];
if
(
!
empty
(
$name
))
{
$where
[
"name[~]"
]
=
"%"
.
$name
.
"%"
;
$where
[
"level"
]
=
Category
::
LEVEL_2
;
}
$allCategoryList
=
Category
::
getRecordList
(
$where
,
[
'category_id'
,
'parent_category_id'
,
'name'
,
'level'
]);
$data
=
[];
if
(
!
empty
(
$allCategoryList
))
{
$levelOneIdKeys
=
[];
foreach
(
$allCategoryList
as
$caregory
)
{
if
(
$caregory
[
"level"
]
==
Category
::
LEVEL_1
)
{
$data
[]
=
[
"category_id"
=>
$caregory
[
"category_id"
],
"name"
=>
$caregory
[
"name"
],
];
}
$levelOneIdKeys
[
$caregory
[
"parent_category_id"
]]
=
1
;
}
foreach
(
$data
as
$key
=>
$item
)
{
foreach
(
$allCategoryList
as
$caregory
)
{
if
(
$caregory
[
"level"
]
==
Category
::
LEVEL_2
&&
$caregory
[
"parent_category_id"
]
==
$item
[
"category_id"
])
{
$levelOneIds
=
array_keys
(
$levelOneIdKeys
);
$levelOneCategoryList
=
Category
::
getRecordList
([
"category_id"
=>
$levelOneIds
],
[
'category_id'
,
'parent_category_id'
,
'name'
,
'level'
]);
foreach
(
$levelOneCategoryList
as
$key
=>
$levelOneCategory
)
{
$data
[]
=
[
"category_id"
=>
$levelOneCategory
[
"category_id"
],
"name"
=>
$levelOneCategory
[
"name"
],
];
}
foreach
(
$allCategoryList
as
$caregory
)
{
foreach
(
$data
as
$key
=>
$item
)
{
if
(
$item
[
"category_id"
]
==
$caregory
[
"parent_category_id"
]
&&
$caregory
[
"level"
]
!=
Category
::
LEVEL_1
)
{
$data
[
$key
][
"sub_list"
][]
=
[
"category_id"
=>
$caregory
[
"category_id"
],
"name"
=>
$caregory
[
"name"
],
...
...
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