Authored by uedxwg

Merge branch 'develop' of http://git.dev.yoho.cn/web/yohobuy into develop

@@ -139,7 +139,7 @@ class Yohobuy @@ -139,7 +139,7 @@ class Yohobuy
139 if (!empty($data)) { 139 if (!empty($data)) {
140 $url = self::httpBuildQuery($url, $data); 140 $url = self::httpBuildQuery($url, $data);
141 } 141 }
142 - 142 + var_dump($url);
143 /* 开启缓存的情况 */ 143 /* 开启缓存的情况 */
144 if ($cache && USE_CACHE) { 144 if ($cache && USE_CACHE) {
145 // 先尝试获取一级缓存(master), 有数据则直接返回. 145 // 先尝试获取一级缓存(master), 有数据则直接返回.
@@ -212,7 +212,16 @@ class Yohobuy @@ -212,7 +212,16 @@ class Yohobuy
212 unset($data['private_key']); 212 unset($data['private_key']);
213 } 213 }
214 if (!empty($data)) { 214 if (!empty($data)) {
215 - curl_setopt($ch, CURLOPT_POSTFIELDS, $data); 215 + // 新加支持application/x-www-form-urlencoded调用方式
  216 + $str = '';
  217 + foreach ($data as $key => $val) {
  218 + $str .= $key . '=' . $val . '&';
  219 + }
  220 +
  221 + $str = rtrim($str, '&');
  222 +
  223 +// curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  224 + curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
216 } 225 }
217 $result = curl_exec($ch); 226 $result = curl_exec($ch);
218 if (!$returnJson && !empty($result)) { 227 if (!$returnJson && !empty($result)) {
@@ -65,9 +65,11 @@ class LoginData @@ -65,9 +65,11 @@ class LoginData
65 // 构建必传参数 65 // 构建必传参数
66 $param = Yohobuy::param(); 66 $param = Yohobuy::param();
67 67
  68 + $param['v'] = '4'; // 只有早期的V4版本才有直接生成UID
68 $param['method'] = 'app.passport.signinByOpenID'; 69 $param['method'] = 'app.passport.signinByOpenID';
69 $param['openId'] = $openId; 70 $param['openId'] = $openId;
70 $param['source_type'] = $sourceType; 71 $param['source_type'] = $sourceType;
  72 + $param['nickname'] = $nickname;
71 $param['client_secret'] = Sign::getSign($param); 73 $param['client_secret'] = Sign::getSign($param);
72 74
73 return Yohobuy::get(Yohobuy::API_URL, $param); 75 return Yohobuy::get(Yohobuy::API_URL, $param);
@@ -165,7 +165,7 @@ class RegData @@ -165,7 +165,7 @@ class RegData
165 $param['password'] = $password; 165 $param['password'] = $password;
166 $param['client_secret'] = Sign::getSign($param); 166 $param['client_secret'] = Sign::getSign($param);
167 167
168 - return Yohobuy::post(Yohobuy::API_URL, $param, true); 168 + return Yohobuy::post(Yohobuy::API_URL, $param);
169 } 169 }
170 170
171 } 171 }
@@ -542,5 +542,20 @@ class Helpers @@ -542,5 +542,20 @@ class Helpers
542 542
543 return $vipLevel; 543 return $vipLevel;
544 } 544 }
  545 +
  546 + /**
  547 + * 同步用户的会话
  548 + *
  549 + * 转向老的PHP服务器上处理, 因购物车相关的操作会依赖SESSION
  550 + *
  551 + * @param int $uid 用户ID
  552 + * @param string $refer 访问来源
  553 + * @param string $callback 回调方法名
  554 + * @return string
  555 + */
  556 + public static function syncUserSession($uid, $refer = '', $callback='call')
  557 + {
  558 + return 'http://m1.yohobuy.com/Passport/session/index?callback=' . $callback . '&uid=' . $uid . '&go=' . $refer;
  559 + }
545 560
546 } 561 }
@@ -49,8 +49,8 @@ abstract class Factory @@ -49,8 +49,8 @@ abstract class Factory
49 { 49 {
50 // require dirname(__FILE__) . DS . $apiName . DS . 'Call.class.php'; 50 // require dirname(__FILE__) . DS . $apiName . DS . 'Call.class.php';
51 51
52 - $apiNameCase = ucfirst($apiName);  
53 - $apiClass = "Plugin\Partner\\{$apiNameCase}\\Call"; 52 + //$apiNameCase = ucfirst($apiName);
  53 + $apiClass = "Plugin\Partner\\{$apiName}\Call";
54 54
55 self::$apiObjs[$apiName] = new $apiClass(); 55 self::$apiObjs[$apiName] = new $apiClass();
56 self::$apiObjs[$apiName]->apiName = $apiName; 56 self::$apiObjs[$apiName]->apiName = $apiName;
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 defined('SITE_MAIN') || define('SITE_MAIN', $_SERVER['HTTP_HOST']); 2 defined('SITE_MAIN') || define('SITE_MAIN', $_SERVER['HTTP_HOST']);
3 3
4 return array( 4 return array(
5 - 'appId' => '2707954749',  
6 - 'appKey' => '431730e25a8a0983964a740731c3cb7d', 5 + 'appId' => '3739328910',
  6 + 'appKey' => '9d44cded26d048e23089e5e975c93df1',
7 'appCallbackUrl' => SITE_MAIN . '/passport/login/sinacallback', 7 'appCallbackUrl' => SITE_MAIN . '/passport/login/sinacallback',
8 ); 8 );
@@ -12,13 +12,27 @@ var goodsSwiper, @@ -12,13 +12,27 @@ var goodsSwiper,
12 $discountFolder = $('.goodsDiscount .discount-folder'), 12 $discountFolder = $('.goodsDiscount .discount-folder'),
13 $discountArrow = $('.goodsDiscount .first-item span'); 13 $discountArrow = $('.goodsDiscount .first-item span');
14 14
15 -var goodsDiscountHammer = new Hammer(document.getElementById('goodsDiscount')); 15 +var goodsDiscountEl = document.getElementById('goodsDiscount'),
  16 + goodsDiscountHammer = goodsDiscountEl && new Hammer(goodsDiscountEl);
16 17
17 require('./desc'); 18 require('./desc');
18 require('./comments-consults'); 19 require('./comments-consults');
19 20
20 //add extra marign-bottom for footer to show the yoho copyright 21 //add extra marign-bottom for footer to show the yoho copyright
21 -window.reMarginFooter('.cart-bar'); 22 +function showFooter() {
  23 + var $cartBar = $('.cart-bar');
  24 +
  25 + var timer = setInterval(function() {
  26 + if ($cartBar) {
  27 + window.reMarginFooter('.cart-bar');
  28 + clearInterval(timer);
  29 + } else {
  30 + $cartBar = $('.cart-bar');
  31 + }
  32 + }, 200);
  33 +}
  34 +
  35 +showFooter();
22 36
23 lazyLoad($('img.lazy')); 37 lazyLoad($('img.lazy'));
24 38
@@ -29,7 +43,8 @@ goodsSwiper = new Swiper('.banner-swiper', { @@ -29,7 +43,8 @@ goodsSwiper = new Swiper('.banner-swiper', {
29 paginationClickable: true, 43 paginationClickable: true,
30 pagination: '.banner-top .pagination-inner', 44 pagination: '.banner-top .pagination-inner',
31 nextButton: '.my-swiper-button-next', 45 nextButton: '.my-swiper-button-next',
32 - prevButton: '.my-swiper-button-prev' 46 + prevButton: '.my-swiper-button-prev',
  47 + spaceBetween: 3
33 }); 48 });
34 49
35 50
@@ -40,15 +55,18 @@ if (0 === $('.goodsDiscount .discount-folder').children().length) { @@ -40,15 +55,18 @@ if (0 === $('.goodsDiscount .discount-folder').children().length) {
40 } 55 }
41 56
42 //goods-discount下拉按钮点击事件 57 //goods-discount下拉按钮点击事件
43 -goodsDiscountHammer.on('tap', function(e) {  
44 - if ($discountFolder.is(':hidden')) {  
45 - $discountArrow.removeClass('icon-down').addClass('icon-up').html('');  
46 - $discountFolder.slideDown();  
47 - } else {  
48 - $discountArrow.removeClass('icon-up').addClass('icon-down').html('');  
49 - $discountFolder.slideUp();  
50 - }  
51 - return false;  
52 -}); 58 +if (goodsDiscountHammer) {
  59 + goodsDiscountHammer.on('tap', function(e) {
  60 + if ($discountFolder.is(':hidden')) {
  61 + $discountArrow.removeClass('icon-down').addClass('icon-up').html('');
  62 + $discountFolder.slideDown();
  63 + } else {
  64 + $discountArrow.removeClass('icon-up').addClass('icon-down').html('');
  65 + $discountFolder.slideUp();
  66 + }
  67 + return false;
  68 + });
  69 +}
  70 +
53 71
54 require('./like'); 72 require('./like');
@@ -471,6 +471,7 @@ class HomeController extends AbstractAction @@ -471,6 +471,7 @@ class HomeController extends AbstractAction
471 471
472 $service = array( 472 $service = array(
473 'header' => array('title' => '在线客服'), 473 'header' => array('title' => '在线客服'),
  474 + 'pageFooter' => true,
474 'service' => $service 475 'service' => $service
475 ); 476 );
476 477
@@ -23,7 +23,7 @@ class OrderModel @@ -23,7 +23,7 @@ class OrderModel
23 { 23 {
24 $result = array(); 24 $result = array();
25 //调用接口获得数据 25 //调用接口获得数据
26 - $data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, 3444485); 26 + $data = OrderData::getOrderData($type, $page, $limit, $gender, $yh_channel, $uid);
27 // 判断是否还有数据, 没有数据则返回空 27 // 判断是否还有数据, 没有数据则返回空
28 if (isset($data['data']['page_total']) && $page > $data['data']['page_total']) { 28 if (isset($data['data']['page_total']) && $page > $data['data']['page_total']) {
29 return $result; 29 return $result;
@@ -211,9 +211,12 @@ class DetailModel @@ -211,9 +211,12 @@ class DetailModel
211 211
212 // 悬浮的购物车信息 212 // 悬浮的购物车信息
213 $result['cartInfo'] = array( 213 $result['cartInfo'] = array(
214 - 'cartUrl' => Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html'), 214 + 'cartUrl' => Helpers::url('/cart/index/index', null), // 购物车链接
  215 + 'addToCartUrl' => Helpers::url('/product/buy_' . $productId . '_' . $goodsId . '.html'), // 加入购物车链接
215 'numInCart' => 0, 216 'numInCart' => 0,
216 - 'goodsInstore' => $baseInfo['storage'], 217 + 'goodsInstore' => $baseInfo['storage'], // 库存量
  218 + 'soldOut' => $baseInfo['storage'] == 0, // 已售磬
  219 + 'notForSale' => $baseInfo['attribute'] == 2, // 非卖品
217 ); 220 );
218 221
219 // 是否收藏 222 // 是否收藏
@@ -19,8 +19,10 @@ class LoginController extends AbstractAction @@ -19,8 +19,10 @@ class LoginController extends AbstractAction
19 { 19 {
20 $this->setTitle('登录'); 20 $this->setTitle('登录');
21 21
22 - $refer = $this->get('refer', SITE_MAIN . '/?go=1');  
23 - $this->setCookie('refer', $refer); 22 + $refer = $this->get('refer');
  23 + if (!empty($refer)) {
  24 + $this->setCookie('refer', $refer);
  25 + }
24 26
25 $data = array( 27 $data = array(
26 'loginIndex' => true, // 模板中使用JS的标识 28 'loginIndex' => true, // 模板中使用JS的标识
@@ -47,8 +49,10 @@ class LoginController extends AbstractAction @@ -47,8 +49,10 @@ class LoginController extends AbstractAction
47 { 49 {
48 $this->setTitle('国际账号登录'); 50 $this->setTitle('国际账号登录');
49 51
50 - $refer = $this->get('refer', SITE_MAIN . '/?go=1');  
51 - $this->setCookie('refer', $refer); 52 + $refer = $this->get('refer');
  53 + if (!empty($refer)) {
  54 + $this->setCookie('refer', $refer);
  55 + }
52 56
53 $data = array(); 57 $data = array();
54 $data['loginInternational'] = true; // 模板中使用JS的标识 58 $data['loginInternational'] = true; // 模板中使用JS的标识
@@ -70,7 +74,9 @@ class LoginController extends AbstractAction @@ -70,7 +74,9 @@ class LoginController extends AbstractAction
70 { 74 {
71 $this->setCookie('_UID', ''); 75 $this->setCookie('_UID', '');
72 76
73 - headers_sent() || header('Location: /'); 77 + $refer = $this->server('HTTP_REFERER', SITE_MAIN);
  78 +
  79 + $this->go($refer);
74 } 80 }
75 81
76 /** 82 /**
@@ -115,12 +121,11 @@ class LoginController extends AbstractAction @@ -115,12 +121,11 @@ class LoginController extends AbstractAction
115 $refer = $this->getCookie('refer'); 121 $refer = $this->getCookie('refer');
116 if (empty($refer)) { 122 if (empty($refer)) {
117 $refer = SITE_MAIN . '/?go=1'; 123 $refer = SITE_MAIN . '/?go=1';
  124 + } else {
  125 + $refer = rawurldecode($refer);
118 } 126 }
119 - $data['data'] = array(  
120 - // 为了异步调用老系统的SESSION会话  
121 - 'session' => 'http://m1.yohobuy.com/Passport/session/index?callback=call&uid=' . $data['data']['uid'] . '&sign=' . md5($data['data']['uid'] . 'Js8Yn0!EwPM45-ws'),  
122 - 'href' => rawurldecode($refer),  
123 - ); 127 + $data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
  128 + $data['data']['href'] = $refer;
124 } while (false); 129 } while (false);
125 130
126 $this->echoJson($data); 131 $this->echoJson($data);
@@ -131,10 +136,6 @@ class LoginController extends AbstractAction @@ -131,10 +136,6 @@ class LoginController extends AbstractAction
131 */ 136 */
132 public function alipayAction() 137 public function alipayAction()
133 { 138 {
134 - $redirect = $this->_request->getServer('HTTP_REFERER', '');  
135 - if ($redirect != '') {  
136 - $this->setCookie('alipay_redirect', $redirect);  
137 - }  
138 Factory::create('alipay')->getAuthorizeUrl(); 139 Factory::create('alipay')->getAuthorizeUrl();
139 140
140 exit(); 141 exit();
@@ -145,10 +146,6 @@ class LoginController extends AbstractAction @@ -145,10 +146,6 @@ class LoginController extends AbstractAction
145 */ 146 */
146 public function qqAction() 147 public function qqAction()
147 { 148 {
148 - $redirect = $this->_request->getServer('HTTP_REFERER', '');  
149 - if ($redirect != '') {  
150 - $this->setCookie('qq_redirect', $redirect);  
151 - }  
152 Factory::create('qqconnect')->getAuthorizeUrl(); 149 Factory::create('qqconnect')->getAuthorizeUrl();
153 150
154 exit(); 151 exit();
@@ -159,13 +156,7 @@ class LoginController extends AbstractAction @@ -159,13 +156,7 @@ class LoginController extends AbstractAction
159 */ 156 */
160 public function sinaAction() 157 public function sinaAction()
161 { 158 {
162 - $redirect = $this->_request->getServer('HTTP_REFERER', '');  
163 - if ($redirect != '') {  
164 - $this->setCookie('sina_redirect', $redirect);  
165 - }  
166 - header('Location:' . Factory::create('sinaweibo')->getAuthorizeUrl());  
167 -  
168 - exit(); 159 + $this->go(Factory::create('sinaweibo')->getAuthorizeUrl());
169 } 160 }
170 161
171 /** 162 /**
@@ -173,30 +164,27 @@ class LoginController extends AbstractAction @@ -173,30 +164,27 @@ class LoginController extends AbstractAction
173 */ 164 */
174 public function alipaycallbackAction() 165 public function alipaycallbackAction()
175 { 166 {
176 - $nickname = '';  
177 - $alipay = Factory::create('alipay');  
178 - $access = $alipay->getAccessToken();  
179 -  
180 - if (!isset($_GET['real_name'])) {  
181 - /* 获取支付宝用户的详细信息 */  
182 - $userInfo = $alipay->getUserInfo($access);  
183 - if ($userInfo && $userInfo['is_success'] === 'T' && isset($userInfo['response']['user_info']['user_name'])) {  
184 - $nickname = $userInfo['response']['user_info']['user_name'];  
185 - // $alipayEmail = $userInfo['response']['user_info']['email'];  
186 - } 167 + $realName = $this->_request->get('real_name');
  168 + $email = $this->_request->get('email');
  169 + $userId = $this->_request->get('user_id');
  170 +
  171 + $result = array();
  172 + if (isset($realName, $email, $userId)) {
  173 + $result = LoginData::signinByOpenID($realName, $userId, 'alipay');
  174 + }
  175 +
  176 + $refer = $this->getCookie('refer');
  177 + if (empty($refer)) {
  178 + $refer = SITE_MAIN . '/?go=1';
187 } else { 179 } else {
188 - $nickname = $_GET['real_name'];  
189 - // $alipayEmail = isset($_GET['email']) ? $_GET['email'] : ''; 180 + $refer = rawurldecode($refer);
190 } 181 }
191 -  
192 - $result = LoginData::signinByOpenID($nickname, $access['user_id'], 'qq');  
193 -  
194 - if ($result['code'] == 200) {  
195 - $redirect = $this->_request->getCookie('alipay_redirect');  
196 - $redirect && $this->redirect($redirect); 182 +
  183 + if ($result['code'] == 200 && !empty($result['data']['uid'])) {
  184 + $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
  185 + } else {
  186 + $this->go($refer);
197 } 187 }
198 -  
199 - $this->redirect('/');  
200 } 188 }
201 189
202 /** 190 /**
@@ -209,16 +197,23 @@ class LoginController extends AbstractAction @@ -209,16 +197,23 @@ class LoginController extends AbstractAction
209 /* 获取QQ腾讯用户的详细信息 */ 197 /* 获取QQ腾讯用户的详细信息 */
210 $partnerInfo = $qqconnect->getUserInfo($access); 198 $partnerInfo = $qqconnect->getUserInfo($access);
211 199
  200 + $result = array();
212 if ($partnerInfo && is_array($partnerInfo)) { 201 if ($partnerInfo && is_array($partnerInfo)) {
213 - $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');  
214 -  
215 - if ($result['code'] == 200) {  
216 - $redirect = $this->_request->getCookie('qq_redirect');  
217 - $redirect && $this->redirect($redirect);  
218 - } 202 + $result = LoginData::signinByOpenID($partnerInfo['nickname'], $access['openid'], 'qq');
219 } 203 }
220 204
221 - $this->redirect('/'); 205 + $refer = $this->getCookie('refer');
  206 + if (empty($refer)) {
  207 + $refer = SITE_MAIN . '/?go=1';
  208 + } else {
  209 + $refer = rawurldecode($refer);
  210 + }
  211 +
  212 + if ($result['code'] == 200 && !empty($result['data']['uid'])) {
  213 + $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
  214 + } else {
  215 + $this->go($refer);
  216 + }
222 } 217 }
223 218
224 /** 219 /**
@@ -231,16 +226,24 @@ class LoginController extends AbstractAction @@ -231,16 +226,24 @@ class LoginController extends AbstractAction
231 /* 获取QQ腾讯用户的详细信息 */ 226 /* 获取QQ腾讯用户的详细信息 */
232 $partnerInfo = $sina->getUserInfo($access); 227 $partnerInfo = $sina->getUserInfo($access);
233 228
  229 + $result = array();
  230 +
234 if ($partnerInfo && is_array($partnerInfo)) { 231 if ($partnerInfo && is_array($partnerInfo)) {
235 $result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina'); 232 $result = LoginData::signinByOpenID($partnerInfo['screen_name'], $access['uid'], 'sina');
236 -  
237 - if ($result['code'] == 200) {  
238 - $redirect = $this->_request->getCookie('sina_redirect');  
239 - $redirect && $this->redirect($redirect);  
240 - }  
241 } 233 }
242 234
243 - $this->redirect('/'); 235 + $refer = $this->getCookie('refer');
  236 + if (empty($refer)) {
  237 + $refer = SITE_MAIN . '/?go=1';
  238 + } else {
  239 + $refer = rawurldecode($refer);
  240 + }
  241 +
  242 + if ($result['code'] == 200 && !empty($result['data']['uid'])) {
  243 + $this->go(Helpers::syncUserSession($result['data']['uid'], $refer));
  244 + } else {
  245 + $this->go($refer);
  246 + }
244 } 247 }
245 248
246 } 249 }
@@ -133,7 +133,7 @@ class RegController extends AbstractAction @@ -133,7 +133,7 @@ class RegController extends AbstractAction
133 /* 返回跳转到验证页面的链接 */ 133 /* 返回跳转到验证页面的链接 */
134 if ($data['code'] == 200) { 134 if ($data['code'] == 200) {
135 $token = Helpers::makeToken($mobile); 135 $token = Helpers::makeToken($mobile);
136 - $data['data'] = '/passport/reg/code?token=' . $token . '&phoneNum=' . $mobile . '&areaCode=' . $area; 136 + $data['data'] = Helpers::url('/passport/reg/code', array('token' => $token, 'phoneNum' => $mobile, 'areaCode' => $area));
137 } 137 }
138 } while (false); 138 } while (false);
139 139
@@ -176,7 +176,7 @@ class RegController extends AbstractAction @@ -176,7 +176,7 @@ class RegController extends AbstractAction
176 /* 返回跳转到设置密码的链接 */ 176 /* 返回跳转到设置密码的链接 */
177 if ($data['code'] == 200) { 177 if ($data['code'] == 200) {
178 $token = Helpers::makeToken($mobile); 178 $token = Helpers::makeToken($mobile);
179 - $data['data'] = '/passport/reg/password?token=' . $token . '&phoneNum=' . $mobile . '&areaCode=' . $area; 179 + $data['data'] = Helpers::url('/passport/reg/password', array('token' => $token, 'phoneNum' => $mobile, 'areaCode' => $area));
180 } else if ($data['code'] == 404) { 180 } else if ($data['code'] == 404) {
181 $data['message'] = '验证码错误'; //统一验证提示 181 $data['message'] = '验证码错误'; //统一验证提示
182 } 182 }
@@ -259,22 +259,20 @@ class RegController extends AbstractAction @@ -259,22 +259,20 @@ class RegController extends AbstractAction
259 259
260 /* 验证注册的标识码是否有效 */ 260 /* 验证注册的标识码是否有效 */
261 $data = RegData::regMobile($area, $mobile, $password); 261 $data = RegData::regMobile($area, $mobile, $password);
262 - if (!isset($data['code'])) { 262 + if (!isset($data['code']) || $data['code'] != 200) {
263 break; 263 break;
264 } 264 }
265 265
266 /* 返回跳转到来源页面 */ 266 /* 返回跳转到来源页面 */
267 - if ($data['code'] == 200) {  
268 - $refer = $this->getCookie('refer');  
269 - if (empty($refer)) {  
270 - $refer = SITE_MAIN . '/?go=1';  
271 - }  
272 - $data['data'] = array(  
273 - // 为了异步调用老系统的SESSION会话  
274 - 'session' => 'http://m1.yohobuy.com/Passport/session/index?uid=' . $data['data']['uid'] . '&sign=' . md5($data['data']['uid'] . 'Js8Yn0!EwPM45-ws'),  
275 - 'href' => rawurldecode($refer),  
276 - ); 267 + $refer = $this->getCookie('refer');
  268 + if (empty($refer)) {
  269 + $refer = SITE_MAIN . '/?go=1';
  270 + } else {
  271 + $refer = rawurldecode($refer);
277 } 272 }
  273 + $data['data']['session'] = Helpers::syncUserSession($data['data']['uid']);
  274 + $data['data']['href'] = $refer;
  275 +
278 } while (false); 276 } while (false);
279 277
280 $this->echoJson($data); 278 $this->echoJson($data);