Authored by 周少峰

Merge branch 'master' into feature/students

... ... @@ -150,14 +150,16 @@ class Yohobuy
{
$isApi = false;
$isService = false;
$urlBack = $url;
if (USE_INTER_FACE_SHUNT) {
if (strpos($url, 'api.')) {
$isApi = true;
$url = self::_getUrl($url, $data);
} else if (strpos($url, 'service.')) {
$isService = true;
$url = self::_getUrl($url, $data);
}
$url = self::_getUrl($url, $data);
}
// 销毁私钥参数
... ... @@ -199,6 +201,14 @@ class Yohobuy
}
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
//如果分流执行失败,则走原来的逻辑
if (USE_INTER_FACE_SHUNT && $httpCode !== 200) {
curl_close($ch);
return self::_get($urlBack, $data, $cache, $returnJson, $timeout, $userAgent, $useGzip);
}
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
... ... @@ -221,6 +231,63 @@ class Yohobuy
return $result;
}
private static function _get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5, $userAgent = null, $useGzip = true)
{
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
}
if (!empty($data)) {
$url = self::httpBuildQuery($url, $data);
} //echo $url;
/* 开启缓存的情况 */
if ($cache && USE_CACHE) {
// 先尝试获取一级缓存(master), 有数据则直接返回.
$result = Cache::get($url, 'master');
if (!empty($result)) {
return $result;
}
}
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($useGzip) {
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
}
if (!empty($userAgent)) {
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
}
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
curl_close($ch);
$data = array();
/* 开启缓存的情况 */
if ($cache && USE_CACHE) {
// 接口调用异常时, 不害怕,从我们的二级缓存(slave)里再取数据.
if (empty($result)) {
$result = Cache::get($url, 'slave');
}
// 接口调用成功时,这里会设置一级(master)和二级(slave)的缓存数据.
else {
Cache::set($url, $result, $cache);
}
}
return $result;
}
/**
* post提交数据
*
... ... @@ -236,14 +303,16 @@ class Yohobuy
{
$isApi = false;
$isService = false;
$urlBack = $url;
if (USE_INTER_FACE_SHUNT) {
if (strpos($url, 'api.')) {
$isApi = true;
$url = self::_getUrl($url, $data);
} else if (strpos($url, 'service.')) {
$isService = true;
$url = self::_getUrl($url, $data);
}
$url = self::_getUrl($url, $data);
}
$ch = curl_init($url);
... ... @@ -282,6 +351,55 @@ class Yohobuy
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
}
$result = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//如果分流执行失败,则走原来的逻辑
if (USE_INTER_FACE_SHUNT && $httpCode !== 200) {
curl_close($ch);
return self::_post($urlBack, $data, $returnJson, $timeout, $header, $cookie);
}
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
curl_close($ch);
$data = array();
return $result;
}
public static function _post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
} else {
curl_setopt($ch, CURLOPT_HEADER, 0);
}
if (!empty($cookie)) {
$cookie_str = array();
foreach ($cookie as $key => $val) {
$cookie_str[] = urlencode($key) . '=' . urlencode($val);
}
curl_setopt($ch, CURLOPT_COOKIE, implode(';', $cookie_str));
}
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.122 YOHOWEB');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
}
if (!empty($data)) {
$str = http_build_query($data, null, '&');
// 新加支持application/x-www-form-urlencoded调用方式
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_POSTFIELDS, $str);
}
$result = curl_exec($ch);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
... ... @@ -568,23 +686,25 @@ class Yohobuy
$mod = 0;
if (isset($param['uid'])) {
$uid = $param['uid'];
$mod = $param['uid'] % 1024;
$uid = intval($param['uid']);
$mod = $uid % 1024;
}
if ($mod > 128 || $uid === 0) {
$paseUrl = parse_url($url);
if (strpos($url, 'api.')) {
$url = 'http://' . self::$interfaceShunt['awsServers']['api'] . $paseUrl['path']. '/';
$url = 'http://' . self::$interfaceShunt['awsServers']['api'] . rtrim($paseUrl['path'], '/') . '/';
} else if (strpos($url, 'service.')) {
$url = 'http://' . self::$interfaceShunt['awsServers']['service'] . $paseUrl['path']. '/';
$url = 'http://' . self::$interfaceShunt['awsServers']['service'] . rtrim($paseUrl['path'], '/') . '/';
}
} else {
$paseUrl = parse_url($url);
if (strpos($url, 'api.')) {
$url = 'http://' . array_rand(self::$interfaceShunt['tencentServers']['api']) . $paseUrl['path'] . '/';
$num = array_rand(self::$interfaceShunt['tencentServers']['api']);
$url = 'http://' . self::$interfaceShunt['tencentServers']['api'][$num] . rtrim($paseUrl['path'], '/') . '/';
} else if (strpos($url, 'service.')) {
$url = 'http://' . array_rand(self::$interfaceShunt['tencentServers']['service']) . $paseUrl['path']. '/';
$num = array_rand(self::$interfaceShunt['tencentServers']['service']);
$url = 'http://' . self::$interfaceShunt['tencentServers']['service'][$num] . rtrim($paseUrl['path'], '/') . '/';
}
}
... ...
... ... @@ -269,8 +269,10 @@
<div class="row">
{{#if virtualGoods}}
{{!-- 电子门票按钮 --}}
<form name="ticket-form" action="/cart/index/ticketEnsure" method="POST" class="hide"></form>
<span id="buy-ticket" class="buy-ticket buy-now item-buy{{#if dis}} dis{{/if}}" >立即购买</span>
{{#if isVirtualBtn}}
<form name="ticket-form" action="/cart/index/ticketEnsure" method="POST" class="hide"></form>
<span id="buy-ticket" class="buy-ticket buy-now item-buy{{#if dis}} dis{{/if}}" >立即购买</span>
{{/if}}
{{^}}
{{!-- 各颜色下所有尺码均售罄则只显示售罄按钮 --}}
{{#unless soldOut}}
... ...
{
"name": "web-yohobuy",
"version": "4.8.12",
"version": "4.8.13",
"description": "web yohobuy static",
"keywords": [],
"homepage": "",
... ...
... ... @@ -174,6 +174,11 @@ class ItemModel
$virtualGoods = $baseInfo['attribute'] == 3;//虚拟商品
//是否展览票
$goodsInfo['isTicket'] = $goodsInfo['skn'] * 1 === EXHIBITION_TICKET;
$goodsInfo['virtualGoods'] = $virtualGoods;//是否是虚拟商品
if ($goodsInfo['virtualGoods']) {
//是否显示虚拟商品,立即购买按钮
$goodsInfo['isVirtualBtn'] = $soldOut ? false : true;
}
if (!$soldOut && !$notForSale && !$virtualGoods) {
$goodsInfo['addToCart'] = true;
... ... @@ -196,7 +201,6 @@ class ItemModel
else if ($virtualGoods) {
$goodsInfo['buyNow'] = true;//是否立即购买
$goodsInfo['buyNowBase'] = Helpers::url('/ticket', array(), 'shopping');
$goodsInfo['virtualGoods'] = $virtualGoods;
if (isset($goodsInfo['salePrice'])) {
$goodsInfo['advancePrice'] = $goodsInfo['salePrice'];//先行价格
unset($goodsInfo['salePrice']);
... ...
... ... @@ -50,7 +50,7 @@ application.template.ext = ".phtml"
application.assets.path = ROOT_PATH "/assets/web"
; 应用的版本号
application.version = "4.8.12"
application.version = "4.8.13"
; 网站SEO信息
application.seo.title = "YOHO!BUY 有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证"
... ...
... ... @@ -50,7 +50,7 @@ application.template.ext = ".phtml"
application.assets.path = ROOT_PATH "/assets/web"
; 应用的版本号
application.version = "4.8.12"
application.version = "4.8.13"
; 网站SEO信息
application.seo.title = "YOHO!BUY 有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证"
... ...
... ... @@ -50,7 +50,7 @@ application.template.ext = ".phtml"
application.assets.path = ROOT_PATH "/assets/web"
; 应用的版本号
application.version = "4.8.12"
application.version = "4.8.13"
; 网站SEO信息
application.seo.title = "YOHO!BUY 有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证"
... ...
... ... @@ -50,7 +50,7 @@ application.template.ext = ".phtml"
application.assets.path = ROOT_PATH "/assets/web"
; 应用的版本号
application.version = "4.8.12"
application.version = "4.8.13"
; 网站SEO信息
application.seo.title = "YOHO!BUY 有货 | 年轻人潮流购物中心,中国潮流购物风向标,官方授权正品保证"
... ...