Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
b584613e
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
18
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b584613e
编写于
9月 06, 2016
作者:
R
root
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
category left fileter sub category
上级
d030e8d4
变更
11
显示空白变更内容
内联
并排
Showing
11 changed file
with
344 addition
and
45 deletion
+344
-45
app/appfront/modules/Catalog/block/category/Index.php
app/appfront/modules/Catalog/block/category/Index.php
+44
-0
app/appfront/theme/base/front/assets/css/style.css
app/appfront/theme/base/front/assets/css/style.css
+16
-5
app/appfront/theme/base/front/assets/images/checkbox.png
app/appfront/theme/base/front/assets/images/checkbox.png
+0
-0
app/appfront/theme/base/front/catalog/category/index.php
app/appfront/theme/base/front/catalog/category/index.php
+26
-15
app/appfront/theme/base/front/catalog/category/index/filter/attr.php
...t/theme/base/front/catalog/category/index/filter/attr.php
+10
-4
app/appfront/theme/base/front/catalog/category/index/filter/price.php
.../theme/base/front/catalog/category/index/filter/price.php
+11
-4
app/appfront/theme/base/front/catalog/category/index/filter/subcategory.php
.../base/front/catalog/category/index/filter/subcategory.php
+19
-0
app/appfront/theme/base/front/cms/article/index.php
app/appfront/theme/base/front/cms/article/index.php
+7
-4
app/appfront/theme/base/front/site/helper/error.php
app/appfront/theme/base/front/site/helper/error.php
+15
-12
services/Category.php
services/Category.php
+3
-1
services/category/CategoryMongodb.php
services/category/CategoryMongodb.php
+193
-0
未找到文件。
app/appfront/modules/Catalog/block/category/Index.php
浏览文件 @
b584613e
...
@@ -53,10 +53,54 @@ class Index {
...
@@ -53,10 +53,54 @@ class Index {
'query_item'
=>
$this
->
getQueryItem
(),
'query_item'
=>
$this
->
getQueryItem
(),
'product_page'
=>
$this
->
getProductPage
(),
'product_page'
=>
$this
->
getProductPage
(),
'filter_price'
=>
$this
->
getFilterPrice
(),
'filter_price'
=>
$this
->
getFilterPrice
(),
'filter_category'
=>
$this
->
getFilterCategoryHtml
(),
//'content' => Yii::$service->store->getStoreAttrVal($this->_category['content'],'content'),
//'content' => Yii::$service->store->getStoreAttrVal($this->_category['content'],'content'),
//'created_at' => $this->_category['created_at'],
//'created_at' => $this->_category['created_at'],
];
];
}
}
/**
* 得到子分类,如果子分类不存在,则返回同级分类。
*/
protected
function
getFilterCategory
(){
$category_id
=
$this
->
_primaryVal
;
$parent_id
=
$this
->
_category
[
'parent_id'
];
$filter_category
=
Yii
::
$service
->
category
->
getFilterCategory
(
$category_id
,
$parent_id
);
return
$filter_category
;
}
protected
function
getFilterCategoryHtml
(
$filter_category
=
''
){
$str
=
''
;
if
(
!
$filter_category
){
$filter_category
=
$this
->
getFilterCategory
();
}
//var_dump($filter_category);
//exit;
if
(
is_array
(
$filter_category
)
&&
!
empty
(
$filter_category
)){
$str
.
=
'<ul>'
;
foreach
(
$filter_category
as
$cate
){
//var_dump($cate);
//echo '<br><br>';
//continue;
$name
=
Yii
::
$service
->
store
->
getStoreAttrVal
(
$cate
[
'name'
],
'name'
);
$url
=
Yii
::
$service
->
url
->
getUrl
(
$cate
[
'url_key'
]);
$current
=
''
;
if
(
isset
(
$cate
[
'current'
])
&&
$cate
[
'current'
]){
$current
=
'class="current"'
;
}
$str
.
=
'<li '
.
$current
.
'><a href="'
.
$url
.
'">'
.
$name
.
'</a>'
;
if
(
isset
(
$cate
[
'child'
])
&&
is_array
(
$cate
[
'child'
]
)
&&
!
empty
(
$cate
[
'child'
])){
$str
.
=
$this
->
getFilterCategoryHtml
(
$cate
[
'child'
]);
}
$str
.
=
'</li>'
;
}
$str
.
=
'</ul>'
;
}
//exit;
return
$str
;
}
protected
function
getProductPage
(){
protected
function
getProductPage
(){
$spaceShowNum
=
4
;
$spaceShowNum
=
4
;
...
...
app/appfront/theme/base/front/assets/css/style.css
浏览文件 @
b584613e
...
@@ -3,7 +3,7 @@ body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset,
...
@@ -3,7 +3,7 @@ body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset,
body
{
color
:
#333
;
font
:
1em
/
1.55
Verdana
,
Arial
,
Helvetica
,
sans-serif
;}
body
{
color
:
#333
;
font
:
1em
/
1.55
Verdana
,
Arial
,
Helvetica
,
sans-serif
;}
a
{
color
:
#666
;
text-decoration
:
none
;}
a
{
color
:
#666
;
text-decoration
:
none
;}
ol
,
ul
{
list-style
:
outside
none
none
;}
ol
,
ul
{
list-style
:
outside
none
none
;}
ul
li
{
height
:
32px
;}
#top_nav
{
background-color
:
#000
;
font-size
:
0.75em
;
height
:
40px
;
line-height
:
40px
;
width
:
100%
;}
#top_nav
{
background-color
:
#000
;
font-size
:
0.75em
;
height
:
40px
;
line-height
:
40px
;
width
:
100%
;}
.top_nav_inner
{
height
:
100%
;
width
:
1200px
;}
.top_nav_inner
{
height
:
100%
;
width
:
1200px
;}
...
@@ -185,7 +185,7 @@ a:active, a:link {
...
@@ -185,7 +185,7 @@ a:active, a:link {
position
:
relative
;
position
:
relative
;
}
}
.main.container
{
width
:
1200px
;
margin
:
auto
;
min-height
:
5
00px
;}
.main.container
{
width
:
1200px
;
margin
:
auto
;
min-height
:
4
00px
;}
.t_hidden
{
.t_hidden
{
font
:
0px
/
0
Verdana
;
font
:
0px
/
0
Verdana
;
...
@@ -194,7 +194,7 @@ a:active, a:link {
...
@@ -194,7 +194,7 @@ a:active, a:link {
.topSeachForm
.seachBtn
{
.topSeachForm
.seachBtn
{
cursor
:
pointer
;
cursor
:
pointer
;
}
}
.col-main
.site-error
h1
{
font-size
:
22px
;
margin-bottom
:
20px
;}
#nav
{
#nav
{
margin
:
0
auto
;
margin
:
0
auto
;
...
@@ -650,8 +650,19 @@ input.input-text {
...
@@ -650,8 +650,19 @@ input.input-text {
.breadcrumbs
span
{
font-size
:
0.85em
;}
.breadcrumbs
span
{
font-size
:
0.85em
;}
.breadcrumbs
{
margin
:
0
0
10px
0
}
.breadcrumbs
{
margin
:
0
0
10px
0
}
.filter_attr_info
a
{
background
:
rgba
(
0
,
0
,
0
,
0
)
url("../images/checkbox.png")
no-repeat
scroll
-69px
3px
;
padding
:
0
0
0
16px
;
font-size
:
0.8em
;
}
.filter_attr_info
a
.checked
{
background-position
:
-50px
-17px
;
}
.filter_attr_title
{
font-size
:
0.9em
;
text-transform
:
uppercase
;
}
.filter_attr
{
margin
:
0
0
20px
0
}
...
...
app/appfront/theme/base/front/assets/images/checkbox.png
0 → 100644
浏览文件 @
b584613e
1.5 KB
app/appfront/theme/base/front/catalog/category/index.php
浏览文件 @
b584613e
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
<?=
$description
?>
<?=
$description
?>
</div>
</div>
<div
class=
"panelBar"
>
<div
class=
"panelBar"
>
<?php
if
(
is_array
(
$products
)
&&
!
empty
(
$products
)){
?>
<?php
<?php
$parentThis
=
[
$parentThis
=
[
'query_item'
=>
$query_item
,
'query_item'
=>
$query_item
,
...
@@ -32,9 +33,10 @@
...
@@ -32,9 +33,10 @@
$toolbar
=
Yii
::
$service
->
page
->
widget
->
renderContent
(
'category_toolbar'
,
$config
,
$parentThis
);
$toolbar
=
Yii
::
$service
->
page
->
widget
->
renderContent
(
'category_toolbar'
,
$config
,
$parentThis
);
echo
$toolbar
;
echo
$toolbar
;
?>
?>
<?php
}
?>
</div>
</div>
<div
class=
"category_product"
>
<div
class=
"category_product"
>
<?php
if
(
is_array
(
$products
)){
?>
<?php
if
(
is_array
(
$products
)
&&
!
empty
(
$products
)
){
?>
<?php
$i
=
0
;
foreach
(
$products
as
$product
){
?>
<?php
$i
=
0
;
foreach
(
$products
as
$product
){
?>
<?php
if
(
$i
%
$count
==
0
){
?>
<?php
if
(
$i
%
$count
==
0
){
?>
<ul>
<ul>
...
@@ -72,12 +74,22 @@
...
@@ -72,12 +74,22 @@
</div>
</div>
<div
class=
"clear"
></div>
<div
class=
"clear"
></div>
<div
class=
"panelBar"
>
<div
class=
"panelBar"
>
<?php
if
(
is_array
(
$products
)
&&
!
empty
(
$products
)){
?>
<?php
echo
$toolbar
;
?>
<?php
echo
$toolbar
;
?>
<?php
}
?>
</div>
</div>
</div>
</div>
</div>
</div>
<div
class=
"col-left "
>
<div
class=
"col-left "
>
<?php
$parentThis
=
[
'filter_category'
=>
$filter_category
,
];
$config
=
[
'view'
=>
'catalog/category/index/filter/subcategory.php'
,
];
echo
Yii
::
$service
->
page
->
widget
->
renderContent
(
'category_product_filter_sub_category'
,
$config
,
$parentThis
);
?>
<?php
<?php
$parentThis
=
[
$parentThis
=
[
'filters'
=>
$filter_info
,
'filters'
=>
$filter_info
,
...
@@ -88,7 +100,6 @@
...
@@ -88,7 +100,6 @@
echo
Yii
::
$service
->
page
->
widget
->
renderContent
(
'category_product_filter_attr'
,
$config
,
$parentThis
);
echo
Yii
::
$service
->
page
->
widget
->
renderContent
(
'category_product_filter_attr'
,
$config
,
$parentThis
);
?>
?>
<?php
<?php
$parentThis
=
[
$parentThis
=
[
'filter_price'
=>
$filter_price
,
'filter_price'
=>
$filter_price
,
];
];
...
...
app/appfront/theme/base/front/catalog/category/index/filter/attr.php
浏览文件 @
b584613e
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
* @license http://www.fecshop.com/license/
* @license http://www.fecshop.com/license/
*/
*/
?>
?>
<div
class=
"category_left_filter"
>
<?php
<?php
//var_dump($parentThis);
//var_dump($parentThis);
//echo 1;
//echo 1;
...
@@ -15,16 +16,21 @@ if(isset($parentThis['filters']) && !empty($parentThis['filters']) && is_array($
...
@@ -15,16 +16,21 @@ if(isset($parentThis['filters']) && !empty($parentThis['filters']) && is_array($
foreach
(
$parentThis
[
'filters'
]
as
$attr
=>
$filter
){
foreach
(
$parentThis
[
'filters'
]
as
$attr
=>
$filter
){
$attrUrlStr
=
Yii
::
$service
->
url
->
category
->
attrValConvertUrlStr
(
$attr
);
$attrUrlStr
=
Yii
::
$service
->
url
->
category
->
attrValConvertUrlStr
(
$attr
);
if
(
is_array
(
$filter
)
&&
!
empty
(
$filter
)){
if
(
is_array
(
$filter
)
&&
!
empty
(
$filter
)){
echo
$attr
.
'<br/>'
;
echo
'<div class="filter_attr">'
;
echo
'<div class="filter_attr_title">'
.
$attr
.
'</div>'
;
echo
'<div class="filter_attr_info">'
;
foreach
(
$filter
as
$item
){
foreach
(
$filter
as
$item
){
$val
=
$item
[
'_id'
];
$val
=
$item
[
'_id'
];
$count
=
$item
[
'count'
];
$count
=
$item
[
'count'
];
$urlInfo
=
Yii
::
$service
->
url
->
category
->
getFilterChooseAttrUrl
(
$attrUrlStr
,
$val
,
'p'
);
$urlInfo
=
Yii
::
$service
->
url
->
category
->
getFilterChooseAttrUrl
(
$attrUrlStr
,
$val
,
'p'
);
$url
=
$urlInfo
[
'url'
];
$url
=
$urlInfo
[
'url'
];
$selected
=
$urlInfo
[
'selected'
];
$selected
=
$urlInfo
[
'selected'
]
?
'class="checked"'
:
''
;
echo
'<a href="'
.
$url
.
'">'
.
$val
.
'('
.
$count
.
')</a><br/>'
;
echo
'<a
'
.
$selected
.
'
href="'
.
$url
.
'">'
.
$val
.
'('
.
$count
.
')</a><br/>'
;
}
}
echo
'</div>'
;
echo
'</div>'
;
}
}
}
}
}
}
?>
?>
</div>
\ No newline at end of file
app/appfront/theme/base/front/catalog/category/index/filter/price.php
浏览文件 @
b584613e
...
@@ -7,6 +7,7 @@
...
@@ -7,6 +7,7 @@
* @license http://www.fecshop.com/license/
* @license http://www.fecshop.com/license/
*/
*/
?>
?>
<div
class=
"category_left_filter"
>
<?php
<?php
//var_dump($parentThis['filter_price']);
//var_dump($parentThis['filter_price']);
//echo 1;
//echo 1;
...
@@ -14,17 +15,23 @@
...
@@ -14,17 +15,23 @@
if
(
isset
(
$parentThis
[
'filter_price'
])
&&
!
empty
(
$parentThis
[
'filter_price'
])
&&
is_array
(
$parentThis
[
'filter_price'
])){
if
(
isset
(
$parentThis
[
'filter_price'
])
&&
!
empty
(
$parentThis
[
'filter_price'
])
&&
is_array
(
$parentThis
[
'filter_price'
])){
foreach
(
$parentThis
[
'filter_price'
]
as
$attr
=>
$filter
){
foreach
(
$parentThis
[
'filter_price'
]
as
$attr
=>
$filter
){
//var_dump($filter);
echo
$attr
.
'<br/>'
;
$attrUrlStr
=
Yii
::
$service
->
url
->
category
->
attrValConvertUrlStr
(
$attr
);
$attrUrlStr
=
Yii
::
$service
->
url
->
category
->
attrValConvertUrlStr
(
$attr
);
if
(
is_array
(
$filter
)
&&
!
empty
(
$filter
)){
if
(
is_array
(
$filter
)
&&
!
empty
(
$filter
)){
echo
'<div class="filter_attr">'
;
echo
'<div class="filter_attr_title">'
.
$attr
.
'</div>'
;
echo
'<div class="filter_attr_info">'
;
foreach
(
$filter
as
$item
){
foreach
(
$filter
as
$item
){
$val
=
$item
[
'val'
];
$val
=
$item
[
'val'
];
$url
=
$item
[
'url'
];
$url
=
$item
[
'url'
];
$selected
=
$item
[
'selected'
]
?
'class="checked"'
:
''
;
$selected
=
$item
[
'selected'
]
?
'class="checked"'
:
''
;
if
(
$val
&&
$url
){
echo
'<a '
.
$selected
.
' href="'
.
$url
.
'">'
.
$val
.
'</a><br/>'
;
echo
'<a '
.
$selected
.
' href="'
.
$url
.
'">'
.
$val
.
'</a><br/>'
;
}
}
}
}
echo
'</div>'
;
echo
'</div>'
;
}
}
}
}
}
?>
?>
</div>
\ No newline at end of file
app/appfront/theme/base/front/catalog/category/index/filter/subcategory.php
浏览文件 @
b584613e
<style>
.category_left_filter_category
ul
li
{
}
.category_left_filter_category
ul
li
.current
>
a
{
color
:
#cc0000
;
}
.category_left_filter_category
ul
{
margin-left
:
20px
;
}
</style>
<div
class=
"category_left_filter_category"
>
<?php
echo
$parentThis
[
'filter_category'
];
?>
<?php
//exit;
?>
</div>
<div
class=
"clear"
></div>
\ No newline at end of file
app/appfront/theme/base/front/cms/article/index.php
浏览文件 @
b584613e
...
@@ -7,8 +7,11 @@
...
@@ -7,8 +7,11 @@
* @license http://www.fecshop.com/license/
* @license http://www.fecshop.com/license/
*/
*/
?>
?>
<h1>
<?=
$title
?>
</h1>
<div
class=
"main container one-column"
>
<div>
<div
class=
"col-main"
>
<?=
$content
?>
<h1>
<?=
$title
?>
</h1>
<div>
<?=
$content
?>
</div>
</div>
</div>
</div>
\ No newline at end of file
app/appfront/theme/base/front/site/helper/error.php
浏览文件 @
b584613e
...
@@ -9,7 +9,9 @@ use yii\helpers\Html;
...
@@ -9,7 +9,9 @@ use yii\helpers\Html;
$this
->
title
=
$name
;
$this
->
title
=
$name
;
?>
?>
<div
class=
"site-error"
>
<div
class=
"main container one-column"
>
<div
class=
"col-main"
>
<div
class=
"site-error"
>
<h1>
<?=
Html
::
encode
(
$this
->
title
)
?>
</h1>
<h1>
<?=
Html
::
encode
(
$this
->
title
)
?>
</h1>
...
@@ -24,4 +26,5 @@ $this->title = $name;
...
@@ -24,4 +26,5 @@ $this->title = $name;
Please contact us if you think this is a server error. Thank you.
Please contact us if you think this is a server error. Thank you.
</p>
</p>
</div>
</div>
</div>
\ No newline at end of file
services/Category.php
浏览文件 @
b584613e
...
@@ -98,7 +98,9 @@ class Category extends Service
...
@@ -98,7 +98,9 @@ class Category extends Service
}
}
protected
function
actionGetFilterCategory
(
$category_id
,
$parent_id
){
return
$this
->
_category
->
getFilterCategory
(
$category_id
,
$parent_id
);
}
...
...
services/category/CategoryMongodb.php
浏览文件 @
b584613e
...
@@ -195,6 +195,199 @@ class CategoryMongodb implements CategoryInterface
...
@@ -195,6 +195,199 @@ class CategoryMongodb implements CategoryInterface
return
$parent_category
;
return
$parent_category
;
}
}
}
}
/**
* 得到分类的侧栏过滤信息
*/
/*
[
['name' => 'xxx','url_key'=>'xxx'],
[
'name' => 'xxx',
'url_key'=>'xxx',
'child' => [
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
[
'name' => 'xxx',
'url_key'=>'xxx',
'current' => true,
'child' => [
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
]
],
]
],
['name' => 'xxx','url_key'=>'xxx'],
['name' => 'xxx','url_key'=>'xxx'],
]
*/
public
function
getParentCategory
(
$parent_id
){
if
(
$parent_id
===
'0'
){
return
[];
}
$category
=
Category
::
find
()
->
asArray
()
->
where
([
'_id'
=>
new
\
mongoId
(
$parent_id
)])
->
one
();
if
(
isset
(
$category
[
'_id'
])
&&
!
empty
(
$category
[
'_id'
])
){
$currentUrlKey
=
$category
[
'url_key'
];
$currentName
=
$category
[
'name'
];
$currentId
=
$category
[
'_id'
]
->
{
'$id'
};
$currentCategory
[]
=
[
'_id'
=>
$currentId
,
'name'
=>
$currentName
,
'url_key'
=>
$currentUrlKey
,
'parent_id'
=>
$category
[
'parent_id'
],
];
$parentCategory
=
$this
->
getParentCategory
(
$category
[
'parent_id'
]);
return
array_merge
(
$parentCategory
,
$currentCategory
);
}
else
{
return
[];
}
}
public
function
getFilterCategory
(
$category_id
,
$parent_id
){
# 1.如果level为一级,那么title部分为当前的分类,子分类位一级分类下的二级分类
# 2.如果level为二级,那么将所有的二级分类列出,当前的二级分类,列出来子分类
# 3.如果level为三级,那么将所有的二级分类列出。
# 当前二级分类的所有子分类列出,当前三级分类如果有子分类,则列出
//echo $category_id.'##';
//echo $parent_id;
$returnData
=
[];
$primaryKey
=
$this
->
getPrimaryKey
();
$currentCategory
=
Category
::
findOne
(
$category_id
);
$currentUrlKey
=
$currentCategory
[
'url_key'
];
$currentName
=
$currentCategory
[
'name'
];
$currentId
=
$currentCategory
[
'_id'
]
->
{
'$id'
};
//var_dump($currentCategory);exit;
$returnData
[
'current'
]
=
[
'_id'
=>
$currentId
,
'name'
=>
$currentName
,
'url_key'
=>
$currentUrlKey
,
'parent_id'
=>
$currentCategory
[
'parent_id'
],
];
//echo $currentCategory['parent_id'];
//exit;
if
(
$currentCategory
[
'parent_id'
]){
$allParent
=
$this
->
getParentCategory
(
$currentCategory
[
'parent_id'
]);
$allParent
[]
=
$returnData
[
'current'
];
$data
=
$this
->
getAllParentCate
(
$allParent
);
}
else
{
// 点击的是一级分类的时候
$data
=
$this
->
getOneLevelCateChild
(
$returnData
[
'current'
]);
}
//$data = $this->getChildCate($currentId);
//var_dump($data);exit;
return
$data
;
}
public
function
getOneLevelCateChild
(
$category
){
//'_id' => $currentId,
//'name' => $currentName,
//'url_key' => $currentUrlKey,
$data
[
0
]
=
$category
;
$_id
=
$category
[
'_id'
];
$name
=
$category
[
'name'
];
$url_key
=
$category
[
'url_key'
];
$cate
=
Category
::
find
()
->
asArray
()
->
where
([
'parent_id'
=>
$_id
,
])
->
all
();
if
(
is_array
(
$cate
)
&&
!
empty
(
$cate
)){
foreach
(
$cate
as
$one
){
$c_id
=
$one
[
'_id'
]
->
{
'$id'
};
$data
[
0
][
'child'
][
$c_id
]
=
[
'name'
=>
$one
[
'name'
],
'url_key'
=>
$one
[
'url_key'
],
'parent_id'
=>
$one
[
'parent_id'
],
];
}
}
return
$data
;
}
public
function
getAllParentCate
(
$allParent
){
//var_dump($allParent);exit;
$d
=
$allParent
;
$data
=
[];
if
(
is_array
(
$allParent
)
&&
!
empty
(
$allParent
)){
foreach
(
$allParent
as
$k
=>
$category
){
unset
(
$d
[
$k
]);
$category_id
=
$category
[
'_id'
];
$parent_id
=
$category
[
'parent_id'
];
if
(
$parent_id
){
$cate
=
Category
::
find
()
->
asArray
()
->
where
([
'parent_id'
=>
$parent_id
,
])
->
all
();
//var_dump($cate);
//echo '$$$$$$$$$$';
if
(
is_array
(
$cate
)
&&
!
empty
(
$cate
)){
//echo '**********';
foreach
(
$cate
as
$one
){
$c_id
=
$one
[
'_id'
]
->
{
'$id'
};
$data
[
$c_id
]
=
[
'name'
=>
$one
[
'name'
],
'url_key'
=>
$one
[
'url_key'
],
'parent_id'
=>
$one
[
'parent_id'
],
];
//echo $category_id;
//echo '&&&'.$c_id;
if
((
$c_id
==
$category_id
)
&&
!
empty
(
$d
)){
$data
[
$c_id
][
'child'
]
=
$this
->
getAllParentCate
(
$d
);
}
if
((
$c_id
==
$category_id
)
&&
empty
(
$d
)){
$child_cate
=
$this
->
getChildCate
(
$c_id
);
$data
[
$c_id
][
'current'
]
=
true
;
if
(
!
empty
(
$child_cate
)){
$data
[
$c_id
][
'child'
]
=
$child_cate
;
}
}
}
}
break
;
}
}
}
return
$data
;
}
public
function
getChildCate
(
$category_id
){
//echo $category_id;
$data
=
Category
::
find
()
->
asArray
()
->
where
([
'parent_id'
=>
$category_id
,
])
->
all
();
$arr
=
[];
if
(
is_array
(
$data
)
&&
!
empty
(
$data
)){
foreach
(
$data
as
$one
){
$currentUrlKey
=
$one
[
'url_key'
];
$currentName
=
$one
[
'name'
];
$currentId
=
$one
[
'_id'
]
->
{
'$id'
};
$arr
[
$currentId
]
=
[
//'_id' => $currentId,
'name'
=>
$currentName
,
'url_key'
=>
$currentUrlKey
,
'parent_id'
=>
$one
[
'parent_id'
],
];
}
}
return
$arr
;
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录