Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYWAP
·
Commits
Go to a project
GitLab
Go to group
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
Rock Zhang
9 years ago
Commit
5ab84f4aab36218bfcd326dc8b344cb0c2f25bb1
1 parent
ce14b675
添加新品到着有关代码
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
197 additions
and
9 deletions
library/Api/Yohobuy.php
library/LibModels/Wap/Channel/NewsaleData.php
library/Plugin/Helpers.php
template/m.yohobuy.com/actions/channel/newsale/new.phtml
yohobuy/m.yohobuy.com/application/modules/Channel/controllers/Newsale.php
library/Api/Yohobuy.php
View file @
5ab84f4
...
...
@@ -167,7 +167,7 @@ class Yohobuy
* @param array $options CURL设置项
* @return array
*/
public
function
loop
(
$urlList
=
array
(),
$options
=
array
())
public
static
function
getMulti
(
$urlList
=
array
(),
$options
=
array
())
{
$result
=
array
();
$response
=
array
();
...
...
library/LibModels/Wap/Channel/NewsaleData.php
View file @
5ab84f4
<?php
namespace
LibModels\wap\Channel
;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
use
Api\Yohobuy
;
use
Api\Sign
;
use
Plugin\Helpers
;
/**
* 新品到着接口操作类
*
* @name NewsaleData
* @package Library/LibModels/Channel
* @copyright yoho.inc
* @version 1.0 (2015-10-8)
* @author gtskk <rocky.zhang@yoho.cn>
*/
class
NewsaleData
{
/**
* 获取新品到着焦点图数据
* @param string $contentCode 内容位置码
* @return array 新品到着焦点图有关数据
*/
public
static
function
getNewsaleFocus
(
$contentCode
)
{
// 构建必传参数
$param
=
Yohobuy
::
param
();
$param
[
'content_code'
]
=
$contentCode
;
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
return
Yohobuy
::
get
(
Yohobuy
::
SERVICE_URL
.
'operations/api/v5/resource/get'
,
$param
);
}
/**
* 获取新品到着商品数据
*
* @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* @param string $channel 1表示男, 2表示女
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 新品到着商品数据
*/
public
static
function
getNewsaleProducts
(
$gender
,
$channel
,
$limit
=
50
,
$page
=
1
)
{
$param
=
Yohobuy
::
param
();
$param
[
'method'
]
=
'app.search.newProduct'
;
$param
[
'gender'
]
=
$gender
;
$param
[
'page'
]
=
$page
;
$param
[
'limit'
]
=
$limit
;
$param
[
'yh_channel'
]
=
$channel
;
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
// 构建url地址列表
$urlList
=
array
();
$param
[
'dayLimit'
]
=
1
;
$urlList
[
'new'
]
=
Yohobuy
::
httpBuildQuery
(
Yohobuy
::
API_URL
,
$param
);
$param
[
'dayLimit'
]
=
2
;
$urlList
[
'week'
]
=
Yohobuy
::
httpBuildQuery
(
Yohobuy
::
API_URL
,
$param
);
$param
[
'dayLimit'
]
=
3
;
$urlList
[
'sale'
]
=
Yohobuy
::
httpBuildQuery
(
Yohobuy
::
API_URL
,
$param
);
// var_dump($urlList);exit;
return
Yohobuy
::
getMulti
(
$urlList
);
}
/**
* 筛选新品到着商品
*
* @param
* @param array $selectParams 筛选条件参数,可传递的条件参数有:
* string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* integer brand 品牌Id
* integer sort 品类Id
* integer color 颜色Id
* integer size 尺码Id
* string price 价格
* string p_d 折扣
* @param string $channel 1表示男, 2表示女
* @param integer $dayLimit 限制读取多少天,默认为1天
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 筛选出来的新品到着商品
*/
public
static
function
selectNewsaleProducts
(
array
$selectParams
,
$channel
,
$dayLimit
=
1
,
$limit
=
50
,
$page
=
1
)
{
$selectItems
=
array
(
'gender'
,
'brand'
,
'sort'
,
'color'
,
'size'
,
'price'
,
'p_d'
);
$param
=
Yohobuy
::
param
();
$param
[
'method'
]
=
'app.search.newProduct'
;
$param
[
'dayLimit'
]
=
$dayLimit
;
$param
[
'page'
]
=
$page
;
$param
[
'limit'
]
=
$limit
;
$param
[
'yh_channel'
]
=
$channel
;
// 拉取筛选参数
$queriedParams
=
Helpers
::
array_get
(
$selectParams
,
$selectItems
);
$param
=
array_merge
(
$param
,
$queriedParams
);
$param
[
'client_secret'
]
=
Sign
::
getSign
(
$param
);
return
Yohobuy
::
get
(
Yohobuy
::
API_URL
,
$param
);
}
}
...
...
library/Plugin/Helpers.php
0 → 100644
View file @
5ab84f4
<?php
namespace
Plugin
;
/**
* 辅助类
*/
class
Helpers
{
/**
* 根据尺寸获得图片url
* @param string $fileName 文件名
* @param integer $width 图片宽度
* @param integer $height 图片高度
* @param integer $mode 模式
* @return string 图片地址
*/
public
static
function
getImageUrl
(
$fileName
,
$width
,
$height
,
$mode
=
1
){
return
str_replace
(
'{width}'
,
$width
,
str_replace
(
'{height}'
,
$height
,
str_replace
(
'{mode}'
,
$mode
,
$fileName
)));
}
/**
* 从数组中中获取指定键值对应的元素
* @param array $array 需要获取的数组
* @param array|string $keys 指定键值,数组或者字符串
* @return array 获取的数据
*/
public
static
function
array_get
(
$array
,
$keys
)
{
return
array_intersect_key
(
$array
,
array_flip
((
array
)
$keys
));
}
}
\ No newline at end of file
...
...
template/m.yohobuy.com/actions/channel/newsale/new.phtml
View file @
5ab84f4
{
{>layout/header
}
}
<code>
{
{#focus
}
}
<ul>
{
{#each
data
}
}
{
{#data
}
}
<li><img
src=
"{{src}}"
alt=
"{{title}}"
></li>
{
{/data
}
}
{
{/each
}
}
</ul>
{
{/focus
}
}
</code>
{
{>layout/footer
}
}
\ No newline at end of file
...
...
yohobuy/m.yohobuy.com/application/modules/Channel/controllers/Newsale.php
View file @
5ab84f4
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
use
Action\AbstractAction
;
use
LibModels\wap\Channel\NewsaleData
as
Newsale
;
use
Plugin\Helpers
;
/**
* 新品到着
*/
class
NewsaleController
extends
AbstractAction
{
public
function
indexAction
()
{
$this
->
_view
->
assign
(
'title'
,
'新品到着'
);
// 新品到着顶部焦点图
$focusData
=
Newsale
::
getNewsaleFocus
(
'a7989369aa86681c678bc40f171b8f1d'
);
// 新品到着商品数据
$productsData
=
Newsale
::
getNewsaleProducts
(
'1,3'
,
1
,
60
);
var_dump
(
$productsData
);
// 处理返回的数据
$focus
=
array
();
$products
=
array
();
if
(
$focusData
[
'code'
]
===
200
)
{
foreach
(
$focusData
[
'data'
][
'data'
]
as
$single
)
{
$single
[
'src'
]
=
Helpers
::
getImageUrl
(
$val
[
'src'
],
375
,
667
,
1
);
$focus
[]
=
$single
;
}
}
if
(
$productsData
[
'code'
]
===
200
)
{
$products
=
$productsData
[
'data'
];
foreach
(
$products
[
'product_list'
]
as
&
$val
)
{
$val
[
'default_images'
]
=
Helpers
::
getImageUrl
(
$val
[
'default_images'
],
290
,
386
);
}
}
var_dump
(
$products
);
exit
;
$this
->
_view
->
display
(
'new'
,
compact
(
'focus'
,
'products'
));
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment