Toggle navigation
Toggle navigation
This project
Loading...
Sign in
wangshusheng
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to dashboard
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
0
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
whb
9 years ago
Commit
5b054c4ced07ea27389322d7c67d4fcc3812cdae
1 parent
d41736e1
频道页处理
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
211 additions
and
1 deletions
library/Plugin/DataProcess/WebChannel/Channel.php
library/Plugin/DataProcess/WebChannel/Channel/AbstractChannel.php
library/Plugin/DataProcess/WebChannel/Channel/Kids.php
library/Plugin/DataProcess/WebChannel/Process.php
yohobuy/www.yohobuy.com/application/models/Index/Home.php
library/Plugin/DataProcess/WebChannel/Channel.php
0 → 100644
View file @
5b054c4
<?php
namespace
Plugin\DataProcess\WebChannel
;
class
Channel
{
public
static
$formatChannel
=
array
(
'boys'
=>
'\Plugin\DataProcess\WebChannel\Channel\Kids'
,
'girls'
=>
'\Plugin\DataProcess\WebChannel\Channel\Girls'
,
'kids'
=>
'\Plugin\DataProcess\WebChannel\Channel\Kids'
);
public
static
function
getFormat
(
$channel
,
$data
)
{
//通用处理器
$result
=
Process
::
getContent
(
$data
,
$channel
);
$channelResult
=
array
();
if
(
isset
(
self
::
$formatChannel
[
$channel
]))
{
$class
=
self
::
$formatChannel
[
$channel
];
$channelResult
=
$class
::
format
(
$data
);
}
//组合数据
$result
=
$result
+
$channelResult
;
ksort
(
$result
);
return
array_values
(
$result
);
}
}
...
...
library/Plugin/DataProcess/WebChannel/Channel/AbstractChannel.php
0 → 100644
View file @
5b054c4
<?php
namespace
Plugin\DataProcess\WebChannel\Channel
;
abstract
class
AbstractChannel
{
/***
* 处理数据
* @param array $resource
* @return array[以key方式存储数据]
*/
public
static
function
format
(
$resource
){}
}
\ No newline at end of file
...
...
library/Plugin/DataProcess/WebChannel/Channel/Kids.php
0 → 100644
View file @
5b054c4
<?php
namespace
Plugin\DataProcess\WebChannel\Channel
;
class
Kids
extends
AbstractChannel
{
/**
* {@inheritDoc}
* @see \Plugin\DataProcess\WebChannel\Channel\AbstractChannel::format()
*/
public
static
function
format
(
$resource
)
{
$data
=
array
();
foreach
(
$resource
as
$key
=>
$val
)
{
}
return
$data
;
}
}
\ No newline at end of file
...
...
library/Plugin/DataProcess/WebChannel/Process.php
0 → 100644
View file @
5b054c4
<?php
namespace
Plugin\DataProcess\WebChannel
;
/**
* web版通用处理器
*/
class
Process
{
public
static
function
getContent
(
array
&
$data
,
$type
=
1
)
{
//组合处理数据
$result
=
self
::
mergeProcess
(
$data
,
$type
);
foreach
(
$data
as
$key
=>
$val
)
{
$fun
=
$val
[
'template_name'
];
if
(
empty
(
$val
[
'data'
])
||
!
is_callable
(
"self::
$fun
"
))
{
continue
;
}
//单个处理数据
$build
=
self
::
$fun
(
$val
,
$type
);
if
(
!
empty
(
$build
))
{
$result
[
$key
]
=
$build
;
}
unset
(
$data
[
$key
]);
}
return
$result
;
}
/**
* 热门分类处理
*
* @param array $data
* @param string $type
* @return array
*/
public
static
function
hotCategory
(
array
$data
,
$type
)
{
$data
=
$data
[
'data'
];
$result
=
$temp
=
array
();
$temp
=
array
(
'name'
=>
$data
[
'name'
],
'navs'
=>
array
(),
'tplrecommend'
=>
array
());
foreach
(
$data
[
'navs'
][
'list'
]
as
$val
)
{
$temp
[
'navs'
][]
=
array
(
'id'
=>
''
,
'href'
=>
$val
[
'url'
],
'name'
=>
$val
[
'name'
]
);
}
foreach
(
$data
[
'menuNav'
][
'blocks'
]
as
$val
)
{
$temp
[
'tplrecommend'
][
'keyword'
][]
=
array
(
'href'
=>
$val
[
'url'
],
'name'
=>
$val
[
'title'
],
'img'
=>
[
'src'
]);
}
foreach
(
$data
[
'menuNav'
][
'list'
]
as
$val
)
{
$temp
[
'tplrecommend'
][
'category'
][]
=
array
(
'name'
=>
$val
[
'name'
],
'url'
=>
$val
[
'url'
]);
}
foreach
(
$data
[
'imgs'
]
as
$val
)
{
$temp
[
'tplrecommend'
][
'types'
][]
=
array
(
'href'
=>
$val
[
'url'
],
'name'
=>
$val
[
'title'
],
'img'
=>
[
'src'
]);
}
$result
[
'recommend'
]
=
$temp
;
return
$result
;
}
/**
* banner处理
*
* @param array $data
* @param string $type
* @return array
*/
public
static
function
focus
(
array
$data
,
$type
)
{
$result
=
array
();
$temp
=
array
();
if
(
$data
[
'focus_type'
]
==
1
)
{
foreach
(
$data
[
'data'
]
as
$val
)
{
$temp
[]
=
array
(
'href'
=>
$val
[
'url'
],
'img'
=>
$val
[
'src'
]);
}
$result
[
'slide'
][
'list'
]
=
$temp
;
}
return
$result
;
}
/**
* 组合数据处理
*
* @param array $data
* @param string $type
* @return array
*/
public
static
function
mergeProcess
(
array
&
$data
,
$type
)
{
$result
=
array
();
foreach
(
$data
as
$key
=>
$val
)
{
if
(
isset
(
$data
[
$key
])
&&
isset
(
$data
[
$key
+
3
]))
//人气单品[template: text & textNav & goods & floor]
{
$temp
=
array
(
'singlehot'
=>
array
(
'name'
=>
''
,
'imgHot'
=>
array
(),
'brands'
=>
array
()));
if
(
$data
[
$key
][
'template_name'
]
==
'text'
&&
$data
[
$key
+
1
][
'template_name'
]
==
'textNav'
&&
$data
[
$key
+
2
][
'template_name'
]
==
'goods'
&&
$data
[
$key
+
3
][
'template_name'
]
==
'floor'
)
{
$temp
[
'singlehot'
][
'name'
]
=
$val
[
'data'
][
'text'
];
foreach
(
$data
[
$key
+
2
][
'data'
]
as
$val
)
//TODO
{
$temp
[
'singlehot'
][
'imgHot'
][]
=
array
(
'href'
=>
''
,
//$val['url'],
'name'
=>
''
,
'price'
=>
''
);
}
foreach
(
$data
[
$key
+
3
][
'data'
]
as
$val
)
{
$temp
[
'singlehot'
][
'brands'
][]
=
array
(
'href'
=>
$val
[
'url'
],
'img'
=>
$val
[
'src'
],
'name'
=>
$val
[
'title'
]);
}
$result
[
$key
]
=
$temp
;
unset
(
$data
[
$key
],
$data
[
$key
+
1
],
$data
[
$key
+
2
],
$data
[
$key
+
3
]);
}
}
if
(
isset
(
$data
[
$key
])
&&
isset
(
$data
[
$key
+
1
]))
//优选品牌 [ template: text & focus]
{
$temp
=
array
(
'preferenceBrands'
=>
array
(
'name'
=>
''
,
'slider'
=>
array
()));
if
(
$data
[
$key
][
'template_name'
]
==
'text'
&&
$data
[
$key
+
1
][
'template_name'
]
==
'focus'
)
{
$temp
[
'preferenceBrands'
][
'name'
]
=
$val
[
'data'
][
'text'
];
foreach
(
$data
[
$key
+
1
][
'data'
]
as
$val
)
{
$temp
[
'preferenceBrands'
][
'slider'
][]
=
array
(
'href'
=>
$val
[
'url'
],
'img'
=>
$val
[
'src'
]);
}
$result
[
$key
]
=
$temp
;
unset
(
$data
[
$key
],
$data
[
$key
+
1
]);
}
}
if
(
isset
(
$data
[
$key
])
&&
isset
(
$data
[
$key
+
2
]))
//girlkids[ template: text & textNav & goods]
{
$temp
=
array
(
'girlkids'
=>
array
(
'name'
=>
''
,
'imgHot'
=>
array
()));
if
(
$data
[
$key
][
'template_name'
]
==
'text'
&&
$data
[
$key
+
2
][
'template_name'
]
==
'goods'
)
{
$temp
[
'girlkids'
][
'name'
]
=
$val
[
'data'
][
'text'
];
foreach
(
$data
[
$key
+
2
][
'data'
]
as
$val
)
//TODO
{
$temp
[
'girlkids'
][
'imgHot'
][]
=
array
(
'href'
=>
''
,
//$val['url'],
'name'
=>
''
,
'price'
=>
''
);
}
$result
[
$key
]
=
$temp
;
unset
(
$data
[
$key
],
$data
[
$key
+
1
],
$data
[
$key
+
2
]);
}
}
}
return
$result
;
}
}
\ No newline at end of file
...
...
yohobuy/www.yohobuy.com/application/models/Index/Home.php
View file @
5b054c4
...
...
@@ -6,6 +6,7 @@ use Plugin\Helpers;
use
Plugin\Cache
;
use
LibModels\Web\Home\IndexData
;
use
LibModels\Web\Product\SearchData
;
use
Plugin\DataProcess\WebChannel\Channel
as
ChannelProcess
;
/**
* web首页模板数据模型
*
...
...
@@ -131,13 +132,19 @@ class HomeModel
/**
* 获取频道资源
*
* @param string $channel
* @param string $content_code
* @return array
*/
public
static
function
getChannelResource
(
$content_code
)
{
$data
=
IndexData
::
getResourceData
(
$content_code
);
$resource
=
IndexData
::
getResourceData
(
$content_code
);
header
(
'Content-Type:text/html;charset=utf-8 '
);
//格式化数据
$data
=
ChannelProcess
::
getFormat
(
'kids'
,
$resource
[
'data'
]);
print_r
(
$data
);
exit
();
return
$data
;
}
/**
...
...
Please
register
or
login
to post a comment