do boys,girls,kids,lifestyle page recom maylike product
Showing
5 changed files
with
167 additions
and
34 deletions
@@ -57,16 +57,6 @@ class AbstractAction extends Controller_Abstract | @@ -57,16 +57,6 @@ class AbstractAction extends Controller_Abstract | ||
57 | { | 57 | { |
58 | return $this->_request->getPost($key, $default); | 58 | return $this->_request->getPost($key, $default); |
59 | } | 59 | } |
60 | - | ||
61 | - /** | ||
62 | - * 关闭模板自动渲染 | ||
63 | - * | ||
64 | - * @return void | ||
65 | - */ | ||
66 | - protected function disableView() | ||
67 | - { | ||
68 | - Dispatcher::getInstance()->autoRender(false); | ||
69 | - } | ||
70 | 60 | ||
71 | /** | 61 | /** |
72 | * 使用Memcache缓存 | 62 | * 使用Memcache缓存 |
@@ -83,5 +73,54 @@ class AbstractAction extends Controller_Abstract | @@ -83,5 +73,54 @@ class AbstractAction extends Controller_Abstract | ||
83 | return Cache::memcached($node, $childNode); | 73 | return Cache::memcached($node, $childNode); |
84 | } | 74 | } |
85 | } | 75 | } |
76 | + | ||
77 | + /** | ||
78 | + * 关闭模板自动渲染 | ||
79 | + * | ||
80 | + * @return void | ||
81 | + */ | ||
82 | + protected function disableView() | ||
83 | + { | ||
84 | + Dispatcher::getInstance()->autoRender(false); | ||
85 | + } | ||
86 | + | ||
87 | + /** | ||
88 | + * 输出JSON数据到浏览器 | ||
89 | + * | ||
90 | + * @return void | ||
91 | + */ | ||
92 | + protected function echoJson($json) | ||
93 | + { | ||
94 | + headers_sent() || header('Content-Type: application/json; charset=utf-8;'); | ||
95 | + | ||
96 | + echo $json; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * 返回JSON数据 | ||
101 | + * | ||
102 | + * @param int $code 状态编码 | ||
103 | + * @param string $message 提示信息 | ||
104 | + * @param mixed $data 数据内容 | ||
105 | + * @return json | ||
106 | + */ | ||
107 | + protected function returnJson($code, $message, $data) | ||
108 | + { | ||
109 | + return json_encode(array( | ||
110 | + 'code' => $code, | ||
111 | + 'message' => $message, | ||
112 | + 'data' => $data, | ||
113 | + )); | ||
114 | + } | ||
115 | + | ||
116 | + /** | ||
117 | + * 判断是不是AJAX请求 | ||
118 | + * | ||
119 | + * @return bool | ||
120 | + */ | ||
121 | + protected function isAjax() | ||
122 | + { | ||
123 | + return $this->_request->isXmlHttpRequest(); | ||
124 | + } | ||
86 | 125 | ||
87 | } | 126 | } |
@@ -87,10 +87,11 @@ class Yohobuy | @@ -87,10 +87,11 @@ class Yohobuy | ||
87 | * | 87 | * |
88 | * @param string $url 接口URL | 88 | * @param string $url 接口URL |
89 | * @param array $data 参数列表 | 89 | * @param array $data 参数列表 |
90 | + * @param bool $returnJson 控制是否返回json格式数据 | ||
90 | * @param int $timeout 超时时间 | 91 | * @param int $timeout 超时时间 |
91 | * @return mixed | 92 | * @return mixed |
92 | */ | 93 | */ |
93 | - public static function get($url, $data = array(), $timeout = 5) | 94 | + public static function get($url, $data = array(), $returnJson = false, $timeout = 5) |
94 | { | 95 | { |
95 | if (isset($data['private_key'])) { | 96 | if (isset($data['private_key'])) { |
96 | unset($data['private_key']); | 97 | unset($data['private_key']); |
@@ -104,7 +105,7 @@ class Yohobuy | @@ -104,7 +105,7 @@ class Yohobuy | ||
104 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | 105 | curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
105 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | 106 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
106 | $result = curl_exec($ch); | 107 | $result = curl_exec($ch); |
107 | - if (!empty($result)) { | 108 | + if (!$returnJson && !empty($result)) { |
108 | $result = json_decode($result, true); | 109 | $result = json_decode($result, true); |
109 | } | 110 | } |
110 | curl_close($ch); | 111 | curl_close($ch); |
@@ -118,12 +119,13 @@ class Yohobuy | @@ -118,12 +119,13 @@ class Yohobuy | ||
118 | * | 119 | * |
119 | * @param string $url 接口URL | 120 | * @param string $url 接口URL |
120 | * @param array $data 参数列表 | 121 | * @param array $data 参数列表 |
122 | + * @param bool $returnJson 控制是否返回json格式数据 | ||
121 | * @param int $timeout 超时时间 | 123 | * @param int $timeout 超时时间 |
122 | * @param array $header | 124 | * @param array $header |
123 | * @param array $cookie | 125 | * @param array $cookie |
124 | * @return mixed | 126 | * @return mixed |
125 | */ | 127 | */ |
126 | - public static function post($url, $data = array(), $timeout = 5, $header = array(), $cookie = array()) | 128 | + public static function post($url, $data = array(), $returnJson = false, $timeout = 5, $header = array(), $cookie = array()) |
127 | { | 129 | { |
128 | $ch = curl_init($url); | 130 | $ch = curl_init($url); |
129 | 131 | ||
@@ -151,7 +153,7 @@ class Yohobuy | @@ -151,7 +153,7 @@ class Yohobuy | ||
151 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); | 153 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
152 | } | 154 | } |
153 | $result = curl_exec($ch); | 155 | $result = curl_exec($ch); |
154 | - if (!empty($result)) { | 156 | + if (!$returnJson && !empty($result)) { |
155 | $result = json_decode($result, true); | 157 | $result = json_decode($result, true); |
156 | } | 158 | } |
157 | curl_close($ch); | 159 | curl_close($ch); |
@@ -16,7 +16,7 @@ use Api\Yohobuy; | @@ -16,7 +16,7 @@ use Api\Yohobuy; | ||
16 | class RecomData | 16 | class RecomData |
17 | { | 17 | { |
18 | /** | 18 | /** |
19 | - * 你可能喜欢的商品列表 | 19 | + * 你可能喜欢的BOYS或GIRLS的商品列表 |
20 | * | 20 | * |
21 | * @param string $gender "1,3"表示男, "2,3"表示女 | 21 | * @param string $gender "1,3"表示男, "2,3"表示女 |
22 | * @param string $channel 1表示男, 2表示女 | 22 | * @param string $channel 1表示男, 2表示女 |
@@ -34,7 +34,45 @@ class RecomData | @@ -34,7 +34,45 @@ class RecomData | ||
34 | $param['yh_channel'] = $channel; | 34 | $param['yh_channel'] = $channel; |
35 | $param['client_secret'] = Sign::getSign($param); | 35 | $param['client_secret'] = Sign::getSign($param); |
36 | 36 | ||
37 | - return Yohobuy::get(Yohobuy::API_URL, $param); | 37 | + return Yohobuy::get(Yohobuy::API_URL, $param, true); |
38 | + } | ||
39 | + | ||
40 | + /** | ||
41 | + * 你可能喜欢的潮童的商品列表 | ||
42 | + * | ||
43 | + * @param int $page 分页第几页, 默认第1页 | ||
44 | + * @param int $limit 查询返回的最大限制数, 默认为50 | ||
45 | + * @return array | ||
46 | + */ | ||
47 | + public static function mayLikeKids($page = 1, $limit = 50) | ||
48 | + { | ||
49 | + $param = Yohobuy::param(); | ||
50 | + $param['method'] = 'app.search.kids'; | ||
51 | + $param['page'] = $page; | ||
52 | + $param['limit'] = $limit; | ||
53 | + $param['yh_channel'] = '3'; | ||
54 | + $param['client_secret'] = Sign::getSign($param); | ||
55 | + | ||
56 | + return Yohobuy::get(Yohobuy::API_URL, $param, true); | ||
57 | + } | ||
58 | + | ||
59 | + /** | ||
60 | + * 你可能喜欢的创意生活的新品到着和人气单品列表 | ||
61 | + * | ||
62 | + * @param int $page 分页第几页, 默认第1页 | ||
63 | + * @param int $limit 查询返回的最大限制数, 默认为50 | ||
64 | + * @return array | ||
65 | + */ | ||
66 | + public static function mayLikeLifestyle($page = 1, $limit = 50) | ||
67 | + { | ||
68 | + $param = Yohobuy::param(); | ||
69 | + $param['method'] = 'app.search.lifeStyle'; | ||
70 | + $param['page'] = $page; | ||
71 | + $param['limit'] = $limit; | ||
72 | + $param['yh_channel'] = '4'; | ||
73 | + $param['client_secret'] = Sign::getSign($param); | ||
74 | + | ||
75 | + return Yohobuy::get(Yohobuy::API_URL, $param, true); | ||
38 | } | 76 | } |
39 | 77 | ||
40 | } | 78 | } |
@@ -49,14 +49,14 @@ class Bootstrap extends Bootstrap_Abstract | @@ -49,14 +49,14 @@ class Bootstrap extends Bootstrap_Abstract | ||
49 | Loader::getInstance()->registerLocalNameSpace(explode(',', $this->_config->application->namespaces)); | 49 | Loader::getInstance()->registerLocalNameSpace(explode(',', $this->_config->application->namespaces)); |
50 | } | 50 | } |
51 | 51 | ||
52 | - /** | ||
53 | - * 初始化插件 | ||
54 | - * @param Yaf_Dispatcher $dispatcher | ||
55 | - */ | ||
56 | - public function _initPlugin(Dispatcher $dispatcher) | ||
57 | - { | ||
58 | - | ||
59 | - } | 52 | +// /** |
53 | +// * 初始化插件 | ||
54 | +// * @param Yaf_Dispatcher $dispatcher | ||
55 | +// */ | ||
56 | +// public function _initPlugin(Dispatcher $dispatcher) | ||
57 | +// { | ||
58 | +// | ||
59 | +// } | ||
60 | 60 | ||
61 | /** | 61 | /** |
62 | * 初始化路由 | 62 | * 初始化路由 |
@@ -87,15 +87,15 @@ class Bootstrap extends Bootstrap_Abstract | @@ -87,15 +87,15 @@ class Bootstrap extends Bootstrap_Abstract | ||
87 | } | 87 | } |
88 | } | 88 | } |
89 | 89 | ||
90 | - /** | ||
91 | - * 初始化第三方包 | ||
92 | - * @param Dispatcher $dispatcher | ||
93 | - */ | ||
94 | - public function _initPackage(Dispatcher $dispatcher) | ||
95 | - { | ||
96 | - if ($this->_config->composer->autoload == 1) { | ||
97 | - require $this->_config->composer->path . '/vendor/autoload.php'; | ||
98 | - } | ||
99 | - } | 90 | +// /** |
91 | +// * 初始化第三方包 | ||
92 | +// * @param Dispatcher $dispatcher | ||
93 | +// */ | ||
94 | +// public function _initPackage(Dispatcher $dispatcher) | ||
95 | +// { | ||
96 | +// if ($this->_config->composer->autoload == 1) { | ||
97 | +// require $this->_config->composer->path . '/vendor/autoload.php'; | ||
98 | +// } | ||
99 | +// } | ||
100 | 100 | ||
101 | } | 101 | } |
1 | +<?php | ||
2 | + | ||
3 | +use Action\AbstractAction; | ||
4 | +use LibModels\Wap\Product\RecomData; | ||
5 | + | ||
6 | +/** | ||
7 | + * 商品推荐相关 | ||
8 | + * | ||
9 | + * @name RecomController | ||
10 | + * @package Product | ||
11 | + * @copyright yoho.inc | ||
12 | + * @version 1.0 (2015-10-8 14:43:52) | ||
13 | + * @author fei.hong <fei.hong@yoho.cn> | ||
14 | + */ | ||
15 | +class RecomController extends AbstractAction | ||
16 | +{ | ||
17 | + | ||
18 | + /** | ||
19 | + * 你可能喜欢的 | ||
20 | + * | ||
21 | + * 备注: | ||
22 | + * 调用位于男生(BOYS),女生(GIRLS),潮童(KIDS),创意生活(LifeStyle)页面的底部. | ||
23 | + * 调用方式为AJAX,需要用JS遍历该数据集,替换图片URL地址中的{width},{height},{mode}. | ||
24 | + * JS替换示例: str.replace("{width}", 300).replace("{height}", 300).replace("{mode}", 2); | ||
25 | + * | ||
26 | + * @param string gender "1,3"表示男, "2,3"表示女, 当channel为3时该参数可不传 | ||
27 | + * @param string channel 1表示男, 2表示女, 3表示潮童 | ||
28 | + * @return json | ||
29 | + */ | ||
30 | + public function maylikeAction() | ||
31 | + { | ||
32 | + if ($this->isAjax()) { | ||
33 | + $data = ''; | ||
34 | + $gender = $this->get('gender', '1,3'); | ||
35 | + $channel = $this->get('channel', '1'); | ||
36 | + | ||
37 | + switch (strval($channel)) { | ||
38 | + case '1': // 男(Boys) | ||
39 | + case '2': // 女(Girls) | ||
40 | + $data = RecomData::mayLike($gender, $channel); | ||
41 | + break; | ||
42 | + case '3': // 潮童(Kids) | ||
43 | + $data = RecomData::mayLikeKids(); | ||
44 | + break; | ||
45 | + case '4': // 创意生活(LifeStyle) | ||
46 | + $data = RecomData::mayLikeLifestyle(); | ||
47 | + break; | ||
48 | + } | ||
49 | + | ||
50 | + $this->echoJson($data); | ||
51 | + } | ||
52 | + } | ||
53 | + | ||
54 | +} |
-
Please register or login to post a comment