Authored by 周少峰

Merge branch 'develop' of git.dev.yoho.cn:web/yohobuy into feature/web-list

Showing 38 changed files with 2989 additions and 1504 deletions

Too many changes to show.

To preserve performance only 38 of 38+ files are displayed.

... ... @@ -518,7 +518,7 @@ class AbstractAction extends Controller_Abstract
* @param type $notModifiedExit 是否在没有修改时返回304状态
* @return void
*/
public static function setLastModified($modifiedTime, $notModifiedExit = true)
public function setLastModified($modifiedTime, $notModifiedExit = true)
{
$modifiedTime = date('D, d M Y H:i:s ', $modifiedTime) . 'GMT';
if ($notModifiedExit && isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $modifiedTime == $_SERVER['HTTP_IF_MODIFIED_SINCE']) {
... ... @@ -534,11 +534,36 @@ class AbstractAction extends Controller_Abstract
* @param int $seconds 单位是秒
* @return void
*/
public static function setExpires($seconds = 180)
public function setExpires($seconds = 180)
{
$time = date('D, d M Y H:i:s ', time() + $seconds) . 'GMT';
header('Expires: ' . $time);
}
/**
* JS 跳转并提示
*
* @param String $message 提示信息
* @param String $expression 附加的JS
* @return void
*/
protected function helpJsRedirect($message = '', $expression = "history.back()")
{
header("content-type: text/html; charset=utf-8");
if ($message != '') {
$message = strtr(addslashes($message), array('\n' => '\\n'));
echo "<script language=\"javascript\">";
echo "alert(\"{$message}\");";
echo "</script>";
}
if ($expression != '') {
echo "<script language=\"javascript\">\n";
echo $expression . "\n";
echo "</script>";
}
exit();
}
}
... ...
... ... @@ -457,7 +457,7 @@ class WebAction extends Controller_Abstract
header('Expires: ' . $time);
}
/**
/**
* 设置头部
*
* @param string $channel (默认不设置)
... ... @@ -465,13 +465,11 @@ class WebAction extends Controller_Abstract
*/
protected function setWebNavHeader($channel = '')
{
//TODO
if(empty($channel)) {
$channel = \Index\HomeModel::getSwitchChannel();
}
// else {//设置频道
// \Index\HomeModel::setSwitchToCookie($channel);
// }
if(!empty($channel)) {//设置频道
\Index\HomeModel::setSwitchToCookie($channel);
} else {
$channel = \Index\HomeModel::getSwitchChannel();
}
$header = array(
'navbars'=> \Index\HomeModel::getNavBars($channel),
'gobytype'=> 'gobuy'.$channel,
... ...
... ... @@ -300,4 +300,7 @@ class ChannelConfig
'sale_index' => array('domain' =>'sale','module' => 's'),//sale.yohobuy.com
);
//左侧广告默认图片-passport相关页面
public static $leftDefaultImg = 'http://img12.static.yhbimg.com/yhb-img01/2015/12/01/07/020a0b6e7ff908d0c2bc4045b4fef42b9f.png?imageView/2/w/252/h/190';
}
\ No newline at end of file
... ...
... ... @@ -109,9 +109,8 @@ class OrderData
/*
* 支付页面的资源位
* To change this template file, choose Tools | Templates
*/
public static function paymentData($gender, $yh_channel, $code)
{
//构建必传参数
... ... @@ -141,21 +140,27 @@ class OrderData
//调用接口获得数据
return Yohobuy::get(Yohobuy::SERVICE_URL . '/operations/api/v5/resource/get', $param);
}
/*
* 微信支付签名
/**
* 更新订单的支付方式
*
* @param int $orderCode 订单号
* @param int $payment 支付方式
* @param int $uid 用户ID
* @return array
*/
public static function weixinPaySign($orderCode)
public static function updateOrderPayment($orderCode, $payment, $uid)
{
//构建必传参数
$param['private_key'] = 'adbf5a778175ee757c34d0eba4e932bc';
$param['order_code'] = $orderCode;
$param['payment_code'] = 19;
$param['app_key'] = 'adbf5a778175ee75';
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'app.SpaceOrders.updateOrdersPaymentByCode';
$param['order_code'] = (int) $orderCode;
$param['payment'] = $payment;
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
//调用接口获得数据
return Yohobuy::get('http://pay.yohobuy.com/payment/data.html', $param);
// 调用接口获得数据
return Yohobuy::post(Yohobuy::API_URL, $param);
}
}
... ...
... ... @@ -22,7 +22,7 @@ class IndexData
$params = array('parent_id'=>'','platform'=>'web',
'status'=> $status,'fields'=> $fields
);
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_CATEGORY,'getCategory', $params, 3600);
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_CATEGORY,'getCategory', $params);
}
/**
... ... @@ -40,7 +40,7 @@ class IndexData
$params['client_type'] = $client_type;
$params['private_key'] = Yohobuy::$privateKeyList[$client_type];
$params['client_secret'] = Sign::getSign($params);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_RESOURCE_GET, $params, 3600);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URL_OPERATIONS_RESOURCE_GET, $params);
}
/**
... ...
... ... @@ -105,7 +105,7 @@ class BrandData
}
/*
* 品牌一览资源位banner
* 品牌一览资源位banner-PC
* @param string $contentCode 获取广告资源需要的位置码
* @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
* @return array(
... ... @@ -113,12 +113,13 @@ class BrandData
* "brandList": "按字母'A-Z'分组的品牌列表数据"
* )
*/
public static function getTopBanner($contentCode,$channel)
public static function getTopBanner($contentCode, $channel,$clientType='web')
{
/* 顶部的轮翻广告及热门品牌数据 */
$param = Yohobuy::param();
$param['content_code'] = $contentCode;
$param['client_type'] = $clientType;
$param['private_key'] = Yohobuy::$privateKeyList[$clientType];
$param['client_secret'] = Sign::getSign($param);
$urlList['brandTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_BRAND_TOPPOS, $param);
... ... @@ -128,9 +129,8 @@ class BrandData
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
$urlList['brandList'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
return Yohobuy::getMulti($urlList, array(), 3600); // 有缓存1小时
return Yohobuy::getMulti($urlList,array(),3600);
}
}
... ...
<?php
namespace Plugin\Pay\aliwap;
class AliwapConfig
{
var $pay_url = "http://wappaygw.alipay.com/service/rest.htm?";
/**
* 服务名,即时到帐为alipay.wap.trade.create. direct
* Enter description here ...
* @var String
*/
var $service = "alipay.wap.trade.create.direct";
/**
* 合作伙伴在支付宝的用户ID
* Enter description here ...
* @var string
*/
var $partner = "2088701661478015";
/**
* 编码
* Enter description here ...
* @var String
*/
var $input_charset = "utf-8";
/**
* 通知url,(用于后台提交)
* Enter description here ...
* @var String
*/
var $notify_url = 'http://testservice.yoho.cn:28077/payment/alipay_notify';//"http://m.yohobuy.com/shopping/pay/aliwapnotice";
/**
* 浏览器的返回
* Enter description here ...
* @var string
*/
var $return_url = "http://m.yohobuy.com/shopping/pay/aliwapreturn";
/**
* 签名方式
* Enter description here ...
* @var String
*/
var $sign_type = "MD5";
/**
* 支付类型,1为购买
* Enter description here ...
* @var Integer
*/
var $payment_type = "1";
/**
* Key
* Enter description here ...
* @var String
*/
var $alipay_key = "kcxawi9bb07mzh0aq2wcirsf9znusobw";
/**
* 销售者mail
* Enter description here ...
* @var String
*/
var $sellerMail = "zfb@yoho.cn";
/**
* 支付不成功跳转的页面
* @var string
*/
var $merchant_url = 'http://m.yohobuy.com/home/orders/detail?order_code=';
/**
* ca证书
* @var unknown
*/
var $cacert = 'cacert.pem';
}
... ...
<?php
namespace Plugin\Pay\aliwap;
use Plugin\Pay\aliwap\AliwapReqparams;
interface AliwapInterface
{
/**
* 获取支付请求的url
* Enter description here ...
* @param Array $params
*/
function getPayRequestPars(AliwapReqparams $params);
/**
* 解析返回的参数
* Enter description here ...
* @param Array $arrResponse
* @return QPay_Utils_Rspparams
*/
function parseResponse(Array $arrResponse);
}
\ No newline at end of file
... ...
<?php
namespace Plugin\Pay\aliwap;
/**
* 请求付款的参数类
*/
class AliwapReqparams
{
public function __construct($_orderCode, $_totalFee, $_goodName, $client_ip, $_orderTime, $_paymentParameter="", $_isTest=false)
{
$this->orderCode = $_orderCode;
$this->totalFee = $_totalFee;
$this->goodsName = $_goodName;
$this->spbill_create_ip = $client_ip;
$this->orderTime = $_orderTime;
$this->paymentParameter = $_paymentParameter;
$this->isTest = $_isTest;
}
/**
* 订单Code
* Enter description here ...
* @var Integer
*/
var $orderCode = 0;
/**
* 付款金额,统一采用分为单位
* Enter description here ...
* @var double
*/
var $totalFee = 0;
/**
* 商品名称
* Enter description here ...
* @var String
*/
var $goodsName = "";
/**
* 客户的ip
* Enter description here ...
* @var Integer
*/
var $spbill_create_ip = "";
/**
* 订单时间
* Enter description here ...
* @var unknown_type
*/
var $orderTime = "";
/**
* 支付方式参数
* Enter description here ...
* @var string
*/
var $paymentParameter = "";
/**
* 是否为测试
* Enter description here ...
* @var bool
*/
var $isTest = false;
}
\ No newline at end of file
... ...
<?php
namespace Plugin\Pay\aliwap;
/**
* 回复参数
*/
class AliwapRspparams
{
/**
* 支付结果,0为成功,1为失败
* Enter description here ...
* @var Integer
*/
var $payResult;
/**
* 付款时间
* Enter description here ...
* @var Integer
*/
var $payTime;
/**
* 订单Code
* Enter description here ...
* @var unknown_type
*/
var $orderCode;
/**
* 支付的总金额
* Enter description here ...
* @var unknown_type
*/
var $totalFee;
/**
* 银行名称,中文名
* Enter description here ...
* @var String
*/
var $bankName = "";
/**
* 银行代码
* Enter description here ...
* @var string
*/
var $bankCode = "";
/**
* 结果信息
* Enter description here ...
* @var string
*/
var $resultMsg;
}
... ...
<?php
namespace Plugin\Pay\aliwap;
use Plugin\Pay\aliwap\AliwapConfig;
use Plugin\Pay\aliwap\AliwapReqparams;
use Plugin\Pay\aliwap\AliwapRspparams;
/**
* 支付宝手机网页支付
*/
class AliwapService
{
var $config;
var $alipay_config;
public function __construct()
{
$this->logProjectPrefix = 'aliwap';
$this->config = new AliwapConfig();
$this->alipay_config = array(
'partner' => $this->config->partner,
'key' => $this->config->alipay_key,
'sign_type' => 'MD5',
'input_charset' => 'utf-8',
'cacert' => dirname(__FILE__) . '/cacert.pem',
'transport' => 'http'
);
require_once("lib/alipay_core.function.php");
require_once("lib/alipay_rsa.function.php");
require_once("lib/alipay_md5.function.php");
require_once("lib/alipay_notify.class.php");
require_once("lib/alipay_submit.class.php");
}
/**
* 构造请求参数
* @see QPay_Utils_Interface::getPayRequestPars()
*/
public function getPayRequestPars(AliwapReqparams $params)
{
$para_token = array(
'service' => 'alipay.wap.trade.create.direct',
'partner' => $this->config->partner,
'sec_id' => $this->config->sign_type,
'format' => 'xml',
'v' => '2.0',
'req_id' => date('Ymdhis') . $params->orderCode,
'req_data' => $this->getTokenReqData($params->orderCode, $params->goodsName, $params->totalFee / 100),
'_input_charset' => $this->config->input_charset
);
//建立请求
$alipaySubmit = new \AlipaySubmit($this->alipay_config);
$html_text = $alipaySubmit->buildRequestHttp($para_token);
//URLDECODE返回的信息
$html_text_decode = urldecode($html_text);
//解析远程模拟提交后返回的信息
$para_html_text = $alipaySubmit->parseResponse($html_text_decode);
if (empty($para_html_text) || empty($para_html_text['request_token'])) {
return false;
// error_log("token获取失败:" . var_export($para_token, true) . "\n" . '返回结果:' . $html_text, 3, '/tmp/aliwap.log');
// throw new Exception('支付系统繁忙,请稍后再试');
}
//获取request_token
$request_token = $para_html_text['request_token'];
//业务详细
$req_data = '<auth_and_execute_req><request_token>' . $request_token . '</request_token></auth_and_execute_req>';
//必填
//构造要请求的参数数组,无需改动
$parameter = array(
"service" => "alipay.wap.auth.authAndExecute",
'partner' => $this->config->partner,
'sec_id' => $this->config->sign_type,
"format" => 'xml',
"v" => '2.0',
"req_id" => date('Ymdhis') . $params->orderCode,
"req_data" => $req_data,
"_input_charset" => $this->config->input_charset
);
//建立请求
$alipaySubmit = new \AlipaySubmit($this->alipay_config);
$strUrl = $alipaySubmit->buildRequestUrl($parameter);
return array(
'pay_url' => $this->config->pay_url,
'pars' => $strUrl,
'reqType' => 'get'
);
}
/**
* 解析结果
*
* @see AliwapInterface::parseResponse()
*/
public function parseResponse(Array $arrResponse)
{
$rsp = new AliwapRspparams();
if ($arrResponse['type'] == 'return') {
//return 返回
$alipayNotify = new \AlipayNotify($this->alipay_config);
$verify_result = $alipayNotify->verifyReturn();
if ($verify_result) {
//商户订单号
$rsp->orderCode = $_GET['out_trade_no'];
$rsp->payResult = 200;
//支付宝交易号
$trade_no = $_GET['trade_no'];
} else {
$rsp->payResult = 400;
}
} else {
//服务器返回
$alipayNotify = new \AlipayNotify($this->alipay_config);
$verify_result = $alipayNotify->verifyNotify();
if ($verify_result) {
//解密(如果是RSA签名需要解密,如果是MD5签名则下面一行清注释掉)
// $notify_data = $alipayNotify->decrypt($_POST['notify_data']);
//解析notify_data
//注意:该功能PHP5环境及以上支持,需开通curl、SSL等PHP配置环境。建议本地调试时使用PHP开发软件
$doc = new \DOMDocument();
$doc->loadXML($_POST['notify_data']);
if (!empty($doc->getElementsByTagName("notify")->item(0)->nodeValue)) {
//商户订单号
$out_trade_no = $doc->getElementsByTagName("out_trade_no")->item(0)->nodeValue;
//支付宝交易号
$trade_no = $doc->getElementsByTagName("trade_no")->item(0)->nodeValue;
//交易状态
$trade_status = $doc->getElementsByTagName("trade_status")->item(0)->nodeValue;
if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') {
$rsp->orderCode = $out_trade_no;
$rsp->payResult = 200;
} else {
$rsp->payResult = 400;
}
}
} else {
$rsp->payResult = 401;
}
}
return $rsp;
}
private function getTokenReqData($out_trade_no, $subject, $total_fee)
{
return '<direct_trade_create_req><notify_url>' . $this->config->notify_url .
'</notify_url><call_back_url>' . $this->config->return_url .
'</call_back_url><seller_account_name>' . $this->config->sellerMail .
'</seller_account_name><out_trade_no>' . $out_trade_no . '</out_trade_no><subject>' . 'yoho order:' . $out_trade_no .
'</subject><total_fee>' . $total_fee . '</total_fee><merchant_url>' . $this->config->merchant_url . $out_trade_no .
'</merchant_url></direct_trade_create_req>';
}
}
... ...
This diff could not be displayed because it is too large.
<?php
/* *
* 支付宝接口公用函数
* 详细:该类是请求、通知返回两个文件所调用的公用函数核心处理文件
* 版本:3.3
* 日期:2012-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstring($para)
{
$arg = "";
while (list ($key, $val) = each($para)) {
$arg.=$key . "=" . $val . "&";
}
//去掉最后一个&字符
$arg = substr($arg, 0, count($arg) - 2);
//如果存在转义字符,那么去掉转义
if (get_magic_quotes_gpc()) {
$arg = stripslashes($arg);
}
return $arg;
}
/**
* 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
* @param $para 需要拼接的数组
* return 拼接完成以后的字符串
*/
function createLinkstringUrlencode($para)
{
$arg = "";
while (list ($key, $val) = each($para)) {
$arg.=$key . "=" . urlencode($val) . "&";
}
//去掉最后一个&字符
$arg = substr($arg, 0, count($arg) - 2);
//如果存在转义字符,那么去掉转义
if (get_magic_quotes_gpc()) {
$arg = stripslashes($arg);
}
return $arg;
}
/**
* 除去数组中的空值和签名参数
* @param $para 签名参数组
* return 去掉空值与签名参数后的新签名参数组
*/
function paraFilter($para)
{
if (isset($para['q'])) {
unset($para['q']);
}
$para_filter = array();
while (list ($key, $val) = each($para)) {
if ($key == "sign" || $key == "sign_type" || $val == "")
continue;
else
$para_filter[$key] = $para[$key];
}
return $para_filter;
}
/**
* 对数组排序
* @param $para 排序前的数组
* return 排序后的数组
*/
function argSort($para)
{
ksort($para);
reset($para);
return $para;
}
/**
* 写日志,方便测试(看网站需求,也可以改成把记录存入数据库)
* 注意:服务器需要开通fopen配置
* @param $word 要写入日志里的文本内容 默认值:空值
*/
function logResult($word = '')
{
error_log("执行日期:" . strftime("%Y%m%d%H%M%S", time()) . "\n" . $word . "\n", 3, '/tmp/aliwap.log');
}
/**
* 远程获取数据,POST模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* @param $para 请求的数据
* @param $input_charset 编码格式。默认值:空值
* return 远程输出的数据
*/
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '')
{
if (trim($input_charset) != '') {
$url = $url . "_input_charset=" . $input_charset;
}
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); //SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //严格认证
curl_setopt($curl, CURLOPT_CAINFO, $cacert_url); //证书地址
curl_setopt($curl, CURLOPT_HEADER, 0); // 过滤HTTP头
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果
curl_setopt($curl, CURLOPT_POST, true); // post传输数据
curl_setopt($curl, CURLOPT_POSTFIELDS, $para); // post传输数据
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close($curl);
return $responseText;
}
/**
* 远程获取数据,GET模式
* 注意:
* 1.使用Crul需要修改服务器中php.ini文件的设置,找到php_curl.dll去掉前面的";"就行了
* 2.文件夹中cacert.pem是SSL证书请保证其路径有效,目前默认路径是:getcwd().'\\cacert.pem'
* @param $url 指定URL完整路径地址
* @param $cacert_url 指定当前工作目录绝对路径
* return 远程输出的数据
*/
function getHttpResponseGET($url, $cacert_url)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, 0); // 过滤HTTP头
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); //SSL证书认证
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2); //严格认证
curl_setopt($curl, CURLOPT_CAINFO, $cacert_url); //证书地址
$responseText = curl_exec($curl);
//var_dump( curl_error($curl) );//如果执行curl过程中出现异常,可打开此开关,以便查看异常内容
curl_close($curl);
return $responseText;
}
/**
* 实现多种字符编码方式
* @param $input 需要编码的字符串
* @param $_output_charset 输出的编码格式
* @param $_input_charset 输入的编码格式
* return 编码后的字符串
*/
function charsetEncode($input, $_output_charset, $_input_charset)
{
$output = "";
if (!isset($_output_charset))
$_output_charset = $_input_charset;
if ($_input_charset == $_output_charset || $input == null) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input, $_output_charset, $_input_charset);
} elseif (function_exists("iconv")) {
$output = iconv($_input_charset, $_output_charset, $input);
} else
die("sorry, you have no libs support for charset change.");
return $output;
}
/**
* 实现多种字符解码方式
* @param $input 需要解码的字符串
* @param $_output_charset 输出的解码格式
* @param $_input_charset 输入的解码格式
* return 解码后的字符串
*/
function charsetDecode($input, $_input_charset, $_output_charset)
{
$output = "";
if (!isset($_input_charset))
$_input_charset = $_input_charset;
if ($_input_charset == $_output_charset || $input == null) {
$output = $input;
} elseif (function_exists("mb_convert_encoding")) {
$output = mb_convert_encoding($input, $_output_charset, $_input_charset);
} elseif (function_exists("iconv")) {
$output = iconv($_input_charset, $_output_charset, $input);
} else
die("sorry, you have no libs support for charset changes.");
return $output;
}
?>
\ No newline at end of file
... ...
<?php
/* *
* MD5
* 详细:MD5加密
* 版本:3.3
* 日期:2012-07-19
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* 签名字符串
* @param $prestr 需要签名的字符串
* @param $key 私钥
* return 签名结果
*/
function md5Sign($prestr, $key)
{
$prestr = $prestr . $key;
return md5($prestr);
}
/**
* 验证签名
* @param $prestr 需要签名的字符串
* @param $sign 签名结果
* @param $key 私钥
* return 签名结果
*/
function md5Verify($prestr, $sign, $key)
{
$prestr = $prestr . $key;
$mysgin = md5($prestr);
if ($mysgin == $sign) {
return true;
} else {
return false;
}
}
?>
\ No newline at end of file
... ...
<?php
/* *
* 类名:AlipayNotify
* 功能:支付宝通知处理类
* 详细:处理支付宝各接口通知返回
* 版本:3.2
* 日期:2011-03-25
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考
* ************************注意*************************
* 调试通知返回时,可查看或改写log日志的写入TXT里的数据,来检查通知返回是否正常
*/
require_once("alipay_core.function.php");
require_once("alipay_rsa.function.php");
require_once("alipay_md5.function.php");
class AlipayNotify
{
/**
* HTTPS形式消息验证地址
*/
var $https_verify_url = 'https://mapi.alipay.com/gateway.do?service=notify_verify&';
/**
* HTTP形式消息验证地址
*/
var $http_verify_url = 'http://notify.alipay.com/trade/notify_query.do?';
var $alipay_config;
function __construct($alipay_config)
{
$this->alipay_config = $alipay_config;
}
function AlipayNotify($alipay_config)
{
$this->__construct($alipay_config);
}
/**
* 针对notify_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyNotify()
{
if (empty($_POST)) {//判断POST来的数组是否为空
return false;
} else {
//对notify_data解密
$decrypt_post_para = $_POST;
if ($this->alipay_config['sign_type'] == '0001') {
$decrypt_post_para['notify_data'] = rsaDecrypt($decrypt_post_para['notify_data'], $this->alipay_config['private_key_path']);
}
//notify_id从decrypt_post_para中解析出来(也就是说decrypt_post_para中已经包含notify_id的内容)
$doc = new DOMDocument();
$doc->loadXML($decrypt_post_para['notify_data']);
$notify_id = $doc->getElementsByTagName("notify_id")->item(0)->nodeValue;
//生成签名结果
return $this->getSignVeryfy($decrypt_post_para, $_POST["sign"], false);
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "responseTxt=".$responseTxt."\n notify_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_POST);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
}
}
/**
* 针对return_url验证消息是否是支付宝发出的合法消息
* @return 验证结果
*/
function verifyReturn()
{
if (empty($_GET)) {//判断GET来的数组是否为空
return false;
} else {
//生成签名结果
$isSign = $this->getSignVeryfy($_GET, $_GET["sign"], true);
//写日志记录
//if ($isSign) {
// $isSignStr = 'true';
//}
//else {
// $isSignStr = 'false';
//}
//$log_text = "return_url_log:isSign=".$isSignStr.",";
//$log_text = $log_text.createLinkString($_GET);
//logResult($log_text);
//验证
//$responsetTxt的结果不是true,与服务器设置问题、合作身份者ID、notify_id一分钟失效有关
//isSign的结果不是true,与安全校验码、请求时的参数格式(如:带自定义参数等)、编码格式有关
if ($isSign) {
return true;
} else {
return false;
}
}
}
/**
* 解密
* @param $input_para 要解密数据
* @return 解密后结果
*/
function decrypt($prestr)
{
return rsaDecrypt($prestr, trim($this->alipay_config['private_key_path']));
}
/**
* 异步通知时,对参数做固定排序
* @param $para 排序前的参数组
* @return 排序后的参数组
*/
function sortNotifyPara($para)
{
$para_sort['service'] = $para['service'];
$para_sort['v'] = $para['v'];
$para_sort['sec_id'] = $para['sec_id'];
$para_sort['notify_data'] = $para['notify_data'];
return $para_sort;
}
/**
* 获取返回时的签名验证结果
* @param $para_temp 通知返回来的参数数组
* @param $sign 返回的签名结果
* @param $isSort 是否对待签名数组排序
* @return 签名验证结果
*/
function getSignVeryfy($para_temp, $sign, $isSort)
{
//除去待签名参数数组中的空值和签名参数
$para = paraFilter($para_temp);
//对待签名参数数组排序
if ($isSort) {
$para = argSort($para);
} else {
$para = $this->sortNotifyPara($para);
}
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para);
$isSgin = false;
switch (strtoupper(trim($this->alipay_config['sign_type']))) {
case "MD5" :
$isSgin = md5Verify($prestr, $sign, $this->alipay_config['key']);
break;
case "RSA" :
$isSgin = rsaVerify($prestr, trim($this->alipay_config['ali_public_key_path']), $sign);
break;
case "0001" :
$isSgin = rsaVerify($prestr, trim($this->alipay_config['ali_public_key_path']), $sign);
break;
default :
$isSgin = false;
}
return $isSgin;
}
/**
* 获取远程服务器ATN结果,验证返回URL
* @param $notify_id 通知校验ID
* @return 服务器ATN结果
* 验证结果集:
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
* true 返回正确信息
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
*/
function getResponse($notify_id)
{
$transport = strtolower(trim($this->alipay_config['transport']));
$partner = trim($this->alipay_config['partner']);
$veryfy_url = '';
if ($transport == 'https') {
$veryfy_url = $this->https_verify_url;
} else {
$veryfy_url = $this->http_verify_url;
}
$veryfy_url = $veryfy_url . "partner=" . $partner . "&notify_id=" . $notify_id;
$responseTxt = getHttpResponseGET($veryfy_url, $this->alipay_config['cacert']);
return $responseTxt;
}
}
?>
... ...
<?php
/* *
* 支付宝接口RSA函数
* 详细:RSA签名、验签、解密
* 版本:3.3
* 日期:2012-07-23
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
/**
* RSA签名
* @param $data 待签名数据
* @param $private_key_path 商户私钥文件路径
* return 签名结果
*/
function rsaSign($data, $private_key_path)
{
$priKey = file_get_contents($private_key_path);
$res = openssl_get_privatekey($priKey);
openssl_sign($data, $sign, $res);
openssl_free_key($res);
//base64编码
$sign = base64_encode($sign);
return $sign;
}
/**
* RSA验签
* @param $data 待签名数据
* @param $ali_public_key_path 支付宝的公钥文件路径
* @param $sign 要校对的的签名结果
* return 验证结果
*/
function rsaVerify($data, $ali_public_key_path, $sign)
{
$pubKey = file_get_contents($ali_public_key_path);
$res = openssl_get_publickey($pubKey);
$result = (bool) openssl_verify($data, base64_decode($sign), $res);
openssl_free_key($res);
return $result;
}
/**
* RSA解密
* @param $content 需要解密的内容,密文
* @param $private_key_path 商户私钥文件路径
* return 解密后内容,明文
*/
function rsaDecrypt($content, $private_key_path)
{
$priKey = file_get_contents($private_key_path);
$res = openssl_get_privatekey($priKey);
//用base64将内容还原成二进制
$content = base64_decode($content);
//把需要解密的内容,按128位拆开解密
$result = '';
for ($i = 0; $i < strlen($content) / 128; $i++) {
$data = substr($content, $i * 128, 128);
openssl_private_decrypt($data, $decrypt, $res);
$result .= $decrypt;
}
openssl_free_key($res);
return $result;
}
?>
\ No newline at end of file
... ...
<?php
/* *
* 类名:AlipaySubmit
* 功能:支付宝各接口请求提交类
* 详细:构造支付宝各接口表单HTML文本,获取远程HTTP数据
* 版本:3.3
* 日期:2012-07-23
* 说明:
* 以下代码只是为了方便商户测试而提供的样例代码,商户可以根据自己网站的需要,按照技术文档编写,并非一定要使用该代码。
* 该代码仅供学习和研究支付宝接口使用,只是提供一个参考。
*/
require_once("alipay_core.function.php");
require_once("alipay_rsa.function.php");
require_once("alipay_md5.function.php");
class AlipaySubmit
{
var $alipay_config;
/**
* 支付宝网关地址
*/
//var $alipay_gateway_new = 'https://mapi.alipay.com/gateway.do?';
var $alipay_gateway_new = 'http://wappaygw.alipay.com/service/rest.htm?';
function __construct($alipay_config)
{
$this->alipay_config = $alipay_config;
}
function AlipaySubmit($alipay_config)
{
$this->__construct($alipay_config);
}
/**
* 生成签名结果
* @param $para_sort 已排序要签名的数组
* return 签名结果字符串
*/
function buildRequestMysign($para_sort)
{
//把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
$prestr = createLinkstring($para_sort);
$mysign = "";
switch (strtoupper(trim($this->alipay_config['sign_type']))) {
case "MD5" :
$mysign = md5Sign($prestr, $this->alipay_config['key']);
break;
case "RSA" :
$mysign = rsaSign($prestr, $this->alipay_config['private_key_path']);
break;
case "0001" :
$mysign = rsaSign($prestr, $this->alipay_config['private_key_path']);
break;
default :
$mysign = "";
}
return $mysign;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组
*/
function buildRequestPara($para_temp)
{
//除去待签名参数数组中的空值和签名参数
$para_filter = paraFilter($para_temp);
//对待签名参数数组排序
$para_sort = argSort($para_filter);
//生成签名结果
$mysign = $this->buildRequestMysign($para_sort);
//签名结果与签名方式加入请求提交参数组中
$para_sort['sign'] = $mysign;
if ($para_sort['service'] != 'alipay.wap.trade.create.direct' && $para_sort['service'] != 'alipay.wap.auth.authAndExecute') {
$para_sort['sign_type'] = strtoupper(trim($this->alipay_config['sign_type']));
}
return $para_sort;
}
/**
* 生成要请求给支付宝的参数数组
* @param $para_temp 请求前的参数数组
* @return 要请求的参数数组字符串
*/
function buildRequestParaToString($para_temp)
{
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
//把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码
$request_data = createLinkstringUrlencode($para);
return $request_data;
}
/**
* 建立请求,以表单HTML形式构造(默认)
* @param $para_temp 请求参数数组
* @param $method 提交方式。两个值可选:post、get
* @param $button_name 确认按钮显示文字
* @return 提交表单HTML文本
*/
function buildRequestUrl($para_temp)
{
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
$urlArr = array();
foreach ($para as $k => $v) {
$urlArr[] = $k . '=' . $v;
}
return implode('&', $urlArr);
}
/**
* 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果
* @param $para_temp 请求参数数组
* @return 支付宝处理结果
*/
function buildRequestHttp($para_temp)
{
$sResult = '';
//待请求参数数组字符串
$request_data = $this->buildRequestPara($para_temp);
//远程获取数据
$sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'], $request_data, trim(strtolower($this->alipay_config['input_charset'])));
return $sResult;
}
/**
* 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果,带文件上传功能
* @param $para_temp 请求参数数组
* @param $file_para_name 文件类型的参数名
* @param $file_name 文件完整绝对路径
* @return 支付宝返回处理结果
*/
function buildRequestHttpInFile($para_temp, $file_para_name, $file_name)
{
//待请求参数数组
$para = $this->buildRequestPara($para_temp);
$para[$file_para_name] = "@" . $file_name;
//远程获取数据
$sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->alipay_config['cacert'], $para, trim(strtolower($this->alipay_config['input_charset'])));
return $sResult;
}
/**
* 解析远程模拟提交后返回的信息
* @param $str_text 要解析的字符串
* @return 解析结果
*/
function parseResponse($str_text)
{
//以“&”字符切割字符串
$para_split = explode('&', $str_text);
//把切割后的字符串数组变成变量与数值组合的数组
foreach ($para_split as $item) {
//获得第一个=字符的位置
$nPos = strpos($item, '=');
//获得字符串长度
$nLen = strlen($item);
//获得变量名
$key = substr($item, 0, $nPos);
//获得数值
$value = substr($item, $nPos + 1, $nLen - $nPos - 1);
//放入数组中
$para_text[$key] = $value;
}
if (!empty($para_text['res_data'])) {
//解析加密部分字符串
if ($this->alipay_config['sign_type'] == '0001') {
$para_text['res_data'] = rsaDecrypt($para_text['res_data'], $this->alipay_config['private_key_path']);
}
//token从res_data中解析出来(也就是说res_data中已经包含token的内容)
$doc = new DOMDocument();
$doc->loadXML($para_text['res_data']);
$para_text['request_token'] = $doc->getElementsByTagName("request_token")->item(0)->nodeValue;
}
return $para_text;
}
/**
* 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数
* 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件
* return 时间戳字符串
*/
function query_timestamp()
{
$url = $this->alipay_gateway_new . "service=query_timestamp&partner=" . trim(strtolower($this->alipay_config['partner'])) . "&_input_charset=" . trim(strtolower($this->alipay_config['input_charset']));
$encrypt_key = "";
$doc = new DOMDocument();
$doc->load($url);
$itemEncrypt_key = $doc->getElementsByTagName("encrypt_key");
$encrypt_key = $itemEncrypt_key->item(0)->nodeValue;
return $encrypt_key;
}
}
?>
\ No newline at end of file
... ...
... ... @@ -34,7 +34,7 @@ class WxPayConfig
const JS_API_CALL_URL = 'http://m.yohobuy.com/shopping/pay/wechatwap';
//=======【异步通知url设置】===================================
//异步通知url,商户根据实际开发过程设定
const NOTIFY_URL = 'http://pay.yohobuy.com/notify/wechatwap';
const NOTIFY_URL = 'http://testservice.yoho.cn:28077/payment/wechatwap_notify';//'http://pay.yohobuy.com/notify/wechatwap';
//=======【证书路径设置】=====================================
/**
* TODO:设置商户证书路径
... ...
<?php
namespace WebPlugin\DataProcess;
use WebPlugin\Images;
use WebPlugin\Helpers;
use WebPlugin\Cache;
use Configs\CacheConfig;
use LibModels\Web\Product\SearchData;
/**
* web版通用处理器
*/
class Process
{
/**
*
* @param array $data
* @param string $type (boys, girls, kids, lifestyle)
*/
public static function getContent(array &$data, $type = '')
{
// 组合处理数据
$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) {
$val['img'] = Images::getImageUrl($val['img'], 185, 76, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['keyword'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
foreach ($data['menuNav']['list'] as $val) {
if (empty($val['name']) && empty($val['url'])) {
continue;
}
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['category'][] = array(
'name' => $val['name'],
'href' => $val['url']
);
}
foreach ($data['imgs'] as $key => $val) {
$val['url'] = Helpers::transUrl($val['url'], $type);
if ($key == 0) {
$val['img'] = Images::getImageUrl($val['img'], 377, 504, 1); // 大图
$temp['tplrecommend']['brands'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
} else {
$val['img'] = Images::getImageUrl($val['img'], 185, 504, 1); // 小图
$temp['tplrecommend']['types'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
}
$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();
$width = 1150;
$height = 450;
if ($data['focus_type'] == 1) {
foreach ($data['data'] as $val) {
$ret = array();
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$ret = array (
'href' => $val['url'],
'img' => $val['src'],
);
if(!empty($val['bgColor'])) {
$ret['bgColor'] = $val['bgColor'];
}
$temp[] = $ret;
}
$result['slide']['list'] = $temp;
}
return $result;
}
/**
* boys焦点图处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function recommend_content_three(array $data, $type)
{
$result = array();
$temp = array();
if ($data['template_name'] == 'recommend_content_three') {
foreach ($data['data']['big_image'] as $val) {
$width = 1150;
$height = 450;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['list'][] = array(
'href' => $val['url'],
'img' => $val['src'],
// 'bgColor'=> $val[]
);
}
foreach ($data['data']['list'] as $val) {
$width = 138;
$height = 54;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['pagination'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
$result['slide'] = $temp;
}
return $result;
}
/**
* 广告位
*
* @param array $data
* @param string $type
* @return array
*/
public static function single_image(array $data, $type)
{
$result = array();
$temp = array();
if ($data['template_name'] == 'single_image') {
$temp = array(
'href' => '',
'img' => '',
'name' => ''
);
if (isset($data['data'][0])) {
$val = $data['data'][0];
$temp['img'] = Images::getImageUrl($val['src'], 1150, 129, 1);
$temp['href'] = $val['url'];
$temp['name'] = $val['title'];
$result['adbanner'] = $temp;
}
}
return $result;
}
/**
* 左右banner
*
* @param array $data
* @param string $type
*/
public static function debrisSlider(array $data, $type)
{
$data = $data['data'];
$result = array(
'debrisSlider' => array(
'left' => array(),
'center' => array(),
'right' => array()
)
);
foreach ($data['left'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 280, 265, 1);
$result['debrisSlider']['left'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
foreach ($data['center'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 570, 633, 1);
$result['debrisSlider']['center'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
foreach ($data['right'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 280, 449, 1);
$result['debrisSlider']['right'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
return $result;
}
/**
* 组合数据处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeProcess(array &$data, $type)
{
$result = array();
$mergeProcessList = array(
'mergeSinglehotData',
'mergePreferenceBrandsData',
'mergeAccordionData',
'mergeCategoryData',
'mergeNewReportData',
'mergeSinglehotData2',
'mergeHotCategoryData',
'mergeGirlkidsData',
'mergeHotBrandsData'
);
foreach ($data as $key => $val) {
foreach ($mergeProcessList as $merge) {
if (isset($data[$key])) {
$temp = self::$merge($key, $data, $type);
if (! empty($temp)) {
$result[$key] = $temp;
}
}
}
}
return $result;
}
/**
* 组合人气单品 [
* template: text & textNav & goods & floor ||
* textNav & goods & floor ||
* text & textNav & goods & app_icon_list
* ]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeSinglehotData($key, array &$data, $type)
{
$result = array();
if ((isset($data[$key]) && isset($data[$key + 2])) || (isset($data[$key]) && isset($data[$key + 3])))
{
$title = '';
$source = $goods = $floor = array();
if ($data[$key]['template_name'] == 'textNav' && $data[$key + 1]['template_name'] == 'goods'
&& $data[$key + 2]['template_name'] == 'floor')
{
$title = '人气单品 TOP100';
$source = $data[$key];
$goods = $data[$key + 1];
$floor = $data[$key + 2];
unset($data[$key], $data[$key + 1], $data[$key + 2]);
} else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'floor')
{
$title = $data[$key]['data']['text'];
$source = $data[$key + 1];
$goods = $data[$key + 2];
$floor = $data[$key + 3];
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
} else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'app_icon_list')
{
$title = $data[$key]['data']['text'];
$source = $data[$key + 1];
$goods = $data[$key + 2];
$floor = $data[$key + 3];
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
}
if (! empty($source) && ! empty($floor))
{
$result = array(
'singlehot' => array(
'name' => '',
'imgHot' => array(),
'brands' => array(),
'navs'=> array(),
)
);
// text模版
$result['singlehot']['name'] = $title;
//textNav模版
$result['singlehot']['navs'] = self::mergeNavProcess($source, $type);
// goods模版
$result['singlehot']['imgHot'] = self::mergeGoodsProcess($goods, $type);
// floor模版
foreach ($floor['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 185, 86, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['singlehot']['brands'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
}
}
return $result;
}
/**
* 组合人气单品 [template: text & small_pic & floor ]
*
* @return array
*/
public static function mergeSinglehotData2($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'small_pic'
&& $data[$key + 2]['template_name'] == 'floor')
{
$result = array(
'singlehot' => array(
'name' => '',
'imgHot' => array()
)
);
// text
$result['singlehot']['name'] = $data[$key]['data']['text'];
$len = 10;
$list = array();
// small_pic
foreach ($data[$key + 1]['data'] as &$val) {
$w = 378;
$h = 248;
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
}
//floor
foreach ($data[$key + 2]['data'] as &$val)
{
$w = 185;
$h = 248;
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
}
for ($i = 0; $i < $len; $i ++)
{
$pos = $i;
if ($i == 1)
{
$val = $data[$key + 1]['data'][0]; // 第二个是大图
}
else if ($i == $len - 1)
{
$val = $data[$key + 1]['data'][1]; // 最后一个是大图
}
else
{
if ($pos > 1) // 小图
{
$pos = $pos - 1;
}
$val = $data[$key + 2]['data'][$pos];
}
$result['singlehot']['imgHot'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['alt']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合优选品牌数据 [ template: text & focus & floor]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergePreferenceBrandsData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'focus'
&& ($data[$key + 2]['template_name'] == 'floor' ||
$data[$key + 2]['template_name'] == 'app_icon_list'))
{
$result = array(
'preferenceBrands' => array(
'name' => '',
'imgBrand' => array(),
'brandUrl' => ''
)
);
// text模版
$result['preferenceBrands']['name'] = $data[$key]['data']['text'];
// focus模版
foreach ($data[$key + 1]['data'] as $val) {
if($type == 'boys') {
$width = 378; $height = 175;
} else{
$width = 320;$height = 430;
}
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['preferenceBrands']['imgBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
// floor模版
$floor = array(
'logoBrand' => '',
'moreBrand' => ''
);
foreach ($data[$key + 2]['data'] as $val) {
$width = 185;
$height = 86;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$floor['logoBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
// textNav模版
if (isset($data[$key + 3]['data'][0]['url']) && $data[$key + 3]['template_name'] == 'textNav') {
$floor['moreBrand'] = $data[$key + 3]['data'][0]['url'];
unset($data[$key + 3]);
}
$type_key = sprintf("%s_%s", $type, $key + 2);
$cacheKey = sprintf("%s_%s", CacheConfig::KEY_INDEX_BRANDS_LIST_DATA, $type_key);
Cache::set($cacheKey, $floor, 7200);
$result['preferenceBrands']['brandUrl'] = '/common/getIndexResourceBrand?type=' . $type_key;
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合girlkids数据 [ template: text & textNav & goods]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeGirlkidsData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 2]['template_name'] == 'goods')
{
$result = array(
'girlkids' => array(
'name' => '',
'imgHot' => array()
)
);
// text
$result['girlkids']['name'] = $data[$key]['data']['text'];
// goods
$result['girlkids']['imgHot'] = self::mergeGoodsProcess($data[$key + 2], $type);
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合accordion数据 [ template: text & textNav & focus ]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeAccordionData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'focus')
{
$result = array(
'accordion' => array(
'name' => '',
'navs' => array(),
'slide' => array()
)
);
$result['accordion']['name'] = $data[$key]['data']['text'];
// textNav模版
if (! empty($data[$key + 1]['data'])) {
$result['accordion']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// focus模版
foreach ($data[$key + 2]['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 650, 400, 1);
$result['accordion']['slide'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合boys最新速报数据 [ template: text & single_image & floor & single_image]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeNewReportData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 3]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'single_image'
&& $data[$key + 2]['template_name'] == 'floor' &&
$data[$key + 3]['template_name'] == 'single_image')
{
$result = array(
'newReport' => array(
'name' => '',
'list' => array()
)
);
// text
$result['newReport']['name'] = $data[$key]['data']['text'];
// single_image & floor & single_image
$list = array_merge($data[$key + 1]['data'], array_slice($data[$key + 2]['data'], 0, 6), $data[$key + 3]['data']);
foreach ($list as $listKey => $val) {
$width = 185;
$height = 248;
$w = 377;
$h = 504;
if ($listKey == 0 || $listKey == 7) {
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
$result['newReport']['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
} else {
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$result['newReport']['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
}
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
}
}
return $result;
}
/**
* 组合category数据 [template: text & textNav & floor ]
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeCategoryData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'floor') {
$result = array(
'category' => array(
'name' => '',
'navs' => array(),
'list' => array()
)
);
// text模版
$result['category']['name'] = $data[$key]['data']['text'];
// textNav模版
if (! empty($data[$key + 1]['data'])) {
$result['category']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// floor模版
foreach ($data[$key + 2]['data'] as $pos => $val) {
$width = 185; $height = 510;
if($pos == 1) {
$width = 377; $height = 504;
}
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['category']['list'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合HotCategory数据 [template: hotCategory & floor] 首页使用
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeHotCategoryData($key, &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 1]))
{
if ($data[$key]['template_name'] == 'hotCategory' && $data[$key + 1]['template_name'] == 'floor')
{
$result = array(
'name' => '',
'navs' => array(),
'tplrecommend' => array(
'keyword' => array(),
'category' => array(),
'brands' => array(),
'types' => array(),
'products' => array()
)
);
// hotCategory模版
$temp = self::hotCategory($data[$key], $type);
$temp = $temp['recommend'];
$result['name'] = $temp['name'];
$result['navs'] = $temp['navs'];
$result['tplrecommend']['keyword'] = $temp['tplrecommend']['keyword'];
$result['tplrecommend']['category'] = $temp['tplrecommend']['category'];
foreach ($data[$key]['data']['imgs'] as $key2 => $val)
{
$val['url'] = Helpers::transUrl($val['url'], $type);
if ($key2 == 0 || $key2 == 4) // 两个大图
{
$val['img'] = Images::getImageUrl($val['img'], 378, 248, 1); // 大图
$result['tplrecommend']['brands'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
} else {
$val['img'] = Images::getImageUrl($val['img'], 185, 248, 1); // 小图
$result['tplrecommend']['types'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
}
// floor模版
foreach ($data[$key + 1]['data'] as $val)
{
$val['src'] = Images::getImageUrl($val['src'], 222, 298, 1); // 小图
$result['tplrecommend']['products'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['src']
);
}
unset($data[$key], $data[$key + 1]);
$result = array(
'recommend' => $result
);
}
}
return $result;
}
/**
* 组合之nav处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeNavProcess(array $data, $type)
{
$result = array();
foreach ($data['data'] as $val) {
if (empty($val))
continue;
$result[] = array(
'href' => $val['url'],
'name' => $val['name']
);
}
return $result;
}
/**
* 组合之商品处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeGoodsProcess(array $data, $type)
{
$result = array();
$skns = '';
foreach ($data['data'] as $val) {
$skns .= $val['id'] . ' ';
}
$params = array(
'query' => rtrim($skns),
'client_type' => 'web'
);
$goodsList = SearchData::searchElasticByCondition($params, false);
$goodsList = $goodsList['data']['product_list'];
$pos = 0;
foreach ($goodsList as $goods)
{
$oneGoods = array();
$pos ++;
if ($pos > 12) {
break;
}
if (empty($goods)) {
continue;
}
$oneGoods['img'] = Images::getImageUrl($goods['goods_list'][0]['images_url'], 280, 373, 1);
$oneGoods['name'] = $goods['product_name'];
$oneGoods['price'] = $goods['sales_price'];
$url = 'http://item.yohobuy.com/product/pro_' .
$goods['product_id'] . '_' . $goods['goods_list'][0]['goods_id']
. '/' . $goods['cn_alphabet'] . '.html';
$oneGoods['href'] = Helpers::transUrl($url, $type);
$result[$goods['product_skn']] = $oneGoods;
}
// 排序
uksort($result, function ($a, $b) use($skns) {
$skn_arr = explode(' ', $skns);
return array_search($a, $skn_arr) > array_search($b, $skn_arr);
});
$pos = 1;
//添加TOP标示
foreach($result as &$val) {
if($pos < 4) {
$val['tip'] = 'TOP'.$pos;
}
else {
break;
}
$pos ++;
}
return $result;
}
/**
* 热门品牌数据处理
*
* @param array $data
* @param string $type
*/
public static function mergeHotBrandsData($key,array &$data,$type)
{
$result = array();
$temp = array();
if ($data[$key]['template_name'] == 'custom_brands')
{
$result = array(
'hotBrands' => array(
'name' => '',
'brandUrl' => ''
)
);
// text模版
$result['hotBrands']['name'] = '热门品牌';
//floor模板
$floor = array(
'logoBrand' => '',
'moreBrand' => ''
);
$brands = $data[$key]['data']['list'];
foreach ($brands as $val)
{
$width = 185;
$height = 86;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$floor['logoBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
$floor['moreBrand'] = 'http://yohobuy.com/brands';
$type_key = sprintf("%s_%s", $type, $key);
$cacheKey = sprintf("%s_%s", CacheConfig::KEY_INDEX_BRANDS_LIST_DATA, $type_key);
Cache::set($cacheKey, $floor, 7200);
$result['hotBrands']['brandUrl'] = '/common/getIndexResourceBrand?type=' . $type_key;
}
return $result;
}
<?php
namespace WebPlugin\DataProcess;
use WebPlugin\Images;
use WebPlugin\Helpers;
use WebPlugin\Cache;
use Configs\CacheConfig;
use LibModels\Web\Product\SearchData;
/**
* web版通用处理器
*/
class Process
{
/**
*
* @param array $data
* @param string $type (boys, girls, kids, lifestyle)
*/
public static function getContent(array &$data, $type = '')
{
// 组合处理数据
$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']
);
}
$len = count($data['menuNav']['blocks']);
foreach ($data['menuNav']['blocks'] as $key => $val) {
if($len <= 2 && $key == 0) {
$val['img'] = Images::getImageUrl($val['img'], 185, 152, 1);
}
$val['img'] = Images::getImageUrl($val['img'], 185, 76, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['keyword'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
foreach ($data['menuNav']['list'] as $val) {
if (empty($val['name']) && empty($val['url'])) {
continue;
}
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['tplrecommend']['category'][] = array(
'name' => $val['name'],
'href' => $val['url']
);
}
foreach ($data['imgs'] as $key => $val) {
$val['url'] = Helpers::transUrl($val['url'], $type);
if ($key == 0) {
$val['img'] = Images::getImageUrl($val['img'], 377, 504, 1); // 大图
$temp['tplrecommend']['brands'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
} else {
$val['img'] = Images::getImageUrl($val['img'], 185, 504, 1); // 小图
$temp['tplrecommend']['types'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
}
$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();
$width = 1150;
$height = 450;
if ($data['focus_type'] == 1) {
foreach ($data['data'] as $val) {
$ret = array();
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$ret = array (
'href' => $val['url'],
'img' => $val['src'],
);
if(!empty($val['bgColor'])) {
$ret['bgColor'] = $val['bgColor'];
}
$temp[] = $ret;
}
$result['slide']['list'] = $temp;
}
return $result;
}
/**
* boys焦点图处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function recommend_content_three(array $data, $type)
{
$result = array();
$temp = array();
if ($data['template_name'] == 'recommend_content_three') {
foreach ($data['data']['big_image'] as $val) {
$width = 1150;
$height = 450;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['list'][] = array(
'href' => $val['url'],
'img' => $val['src'],
// 'bgColor'=> $val[]
);
}
foreach ($data['data']['list'] as $val) {
$width = 138;
$height = 54;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$temp['pagination'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
$result['slide'] = $temp;
}
return $result;
}
/**
* 广告位
*
* @param array $data
* @param string $type
* @return array
*/
public static function single_image(array $data, $type)
{
$result = array();
$temp = array();
if ($data['template_name'] == 'single_image') {
$temp = array(
'href' => '',
'img' => '',
'name' => ''
);
if (isset($data['data'][0])) {
$val = $data['data'][0];
$temp['img'] = Images::getImageUrl($val['src'], 1150, 129, 1);
$temp['href'] = $val['url'];
$temp['name'] = $val['title'];
$result['adbanner'] = $temp;
}
}
return $result;
}
/**
* 左右banner
*
* @param array $data
* @param string $type
*/
public static function debrisSlider(array $data, $type)
{
$data = $data['data'];
$result = array(
'debrisSlider' => array(
'left' => array(),
'center' => array(),
'right' => array()
)
);
foreach ($data['left'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 280, 265, 1);
$result['debrisSlider']['left'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
foreach ($data['center'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 570, 633, 1);
$result['debrisSlider']['center'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
foreach ($data['right'] as $val) {
$val['img'] = Images::getImageUrl($val['img'], 280, 449, 1);
$result['debrisSlider']['right'][] = array(
'img' => $val['img'],
'href' => $val['url'],
'name' => $val['title']
);
}
return $result;
}
/**
* 组合数据处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeProcess(array &$data, $type)
{
$result = array();
$mergeProcessList = array(
'mergeSinglehotData',
'mergePreferenceBrandsData',
'mergeAccordionData',
'mergeCategoryData',
'mergeNewReportData',
'mergeSinglehotData2',
'mergeHotCategoryData',
'mergeGirlkidsData',
'mergeHotBrandsData'
);
foreach ($data as $key => $val) {
foreach ($mergeProcessList as $merge) {
if (isset($data[$key])) {
$temp = self::$merge($key, $data, $type);
if (! empty($temp)) {
$result[$key] = $temp;
}
}
}
}
return $result;
}
/**
* 组合人气单品 [
* template: text & textNav & goods & floor ||
* textNav & goods & floor ||
* text & textNav & goods & app_icon_list
* ]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeSinglehotData($key, array &$data, $type)
{
$result = array();
if ((isset($data[$key]) && isset($data[$key + 2])) || (isset($data[$key]) && isset($data[$key + 3])))
{
$title = '';
$source = $goods = $floor = array();
if ($data[$key]['template_name'] == 'textNav' && $data[$key + 1]['template_name'] == 'goods'
&& $data[$key + 2]['template_name'] == 'floor')
{
$title = '人气单品 TOP100';
$source = $data[$key];
$goods = $data[$key + 1];
$floor = $data[$key + 2];
unset($data[$key], $data[$key + 1], $data[$key + 2]);
} else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'floor')
{
$title = $data[$key]['data']['text'];
$source = $data[$key + 1];
$goods = $data[$key + 2];
$floor = $data[$key + 3];
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
} else if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'goods' && $data[$key + 3]['template_name'] == 'app_icon_list')
{
$title = $data[$key]['data']['text'];
$source = $data[$key + 1];
$goods = $data[$key + 2];
$floor = $data[$key + 3];
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
}
if (! empty($source) && ! empty($floor))
{
$result = array(
'singlehot' => array(
'name' => '',
'imgHot' => array(),
'brands' => array(),
'navs'=> array(),
)
);
// text模版
$result['singlehot']['name'] = $title;
//textNav模版
$result['singlehot']['navs'] = self::mergeNavProcess($source, $type);
// goods模版
$result['singlehot']['imgHot'] = self::mergeGoodsProcess($goods, $type);
// floor模版
foreach ($floor['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 185, 86, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['singlehot']['brands'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
}
}
return $result;
}
/**
* 组合人气单品 [template: text & small_pic & floor ]
*
* @return array
*/
public static function mergeSinglehotData2($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'small_pic'
&& $data[$key + 2]['template_name'] == 'floor')
{
$result = array(
'singlehot' => array(
'name' => '',
'imgHot' => array()
)
);
// text
$result['singlehot']['name'] = $data[$key]['data']['text'];
$len = 10;
$list = array();
// small_pic
foreach ($data[$key + 1]['data'] as &$val) {
$w = 378;
$h = 248;
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
}
//floor
foreach ($data[$key + 2]['data'] as &$val)
{
$w = 185;
$h = 248;
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
}
for ($i = 0; $i < $len; $i ++)
{
$pos = $i;
if ($i == 1)
{
$val = $data[$key + 1]['data'][0]; // 第二个是大图
}
else if ($i == $len - 1)
{
$val = $data[$key + 1]['data'][1]; // 最后一个是大图
}
else
{
if ($pos > 1) // 小图
{
$pos = $pos - 1;
}
$val = $data[$key + 2]['data'][$pos];
}
$result['singlehot']['imgHot'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['alt']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合优选品牌数据 [ template: text & focus & floor]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergePreferenceBrandsData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'focus'
&& ($data[$key + 2]['template_name'] == 'floor' ||
$data[$key + 2]['template_name'] == 'app_icon_list'))
{
$result = array(
'preferenceBrands' => array(
'name' => '',
'imgBrand' => array(),
'brandUrl' => ''
)
);
// text模版
$result['preferenceBrands']['name'] = $data[$key]['data']['text'];
// focus模版
foreach ($data[$key + 1]['data'] as $val) {
if($type == 'boys') {
$width = 378; $height = 175;
} else{
$width = 320;$height = 430;
}
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['preferenceBrands']['imgBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
// floor模版
$floor = array(
'logoBrand' => '',
'moreBrand' => ''
);
foreach ($data[$key + 2]['data'] as $val) {
$width = 185;
$height = 86;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$floor['logoBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
// textNav模版
if (isset($data[$key + 3]['data'][0]['url']) && $data[$key + 3]['template_name'] == 'textNav') {
$floor['moreBrand'] = $data[$key + 3]['data'][0]['url'];
unset($data[$key + 3]);
}
$type_key = sprintf("%s_%s", $type, $key + 2);
$cacheKey = sprintf("%s_%s", CacheConfig::KEY_INDEX_BRANDS_LIST_DATA, $type_key);
Cache::set($cacheKey, $floor, 86400);
$result['preferenceBrands']['brandUrl'] = '/common/getIndexResourceBrand?type=' . $type_key;
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合girlkids数据 [ template: text & textNav & goods]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeGirlkidsData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 2]['template_name'] == 'goods')
{
$result = array(
'girlkids' => array(
'name' => '',
'imgHot' => array()
)
);
// text
$result['girlkids']['name'] = $data[$key]['data']['text'];
// goods
$result['girlkids']['imgHot'] = self::mergeGoodsProcess($data[$key + 2], $type);
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合accordion数据 [ template: text & textNav & focus ]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeAccordionData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'focus')
{
$result = array(
'accordion' => array(
'name' => '',
'navs' => array(),
'slide' => array()
)
);
$result['accordion']['name'] = $data[$key]['data']['text'];
// textNav模版
if (! empty($data[$key + 1]['data'])) {
$result['accordion']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// focus模版
foreach ($data[$key + 2]['data'] as $val) {
$val['src'] = Images::getImageUrl($val['src'], 650, 400, 1);
$result['accordion']['slide'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合boys最新速报数据 [ template: text & single_image & floor & single_image]
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeNewReportData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 3]))
{
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'single_image'
&& $data[$key + 2]['template_name'] == 'floor' &&
$data[$key + 3]['template_name'] == 'single_image')
{
$result = array(
'newReport' => array(
'name' => '',
'list' => array()
)
);
// text
$result['newReport']['name'] = $data[$key]['data']['text'];
// single_image & floor & single_image
$list = array_merge($data[$key + 1]['data'], array_slice($data[$key + 2]['data'], 0, 6), $data[$key + 3]['data']);
foreach ($list as $listKey => $val) {
$width = 185;
$height = 248;
$w = 377;
$h = 504;
if ($listKey == 0 || $listKey == 7) {
$val['src'] = Images::getImageUrl($val['src'], $w, $h, 1);
$result['newReport']['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
} else {
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 1);
$result['newReport']['list'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
}
unset($data[$key], $data[$key + 1], $data[$key + 2], $data[$key + 3]);
}
}
return $result;
}
/**
* 组合category数据 [template: text & textNav & floor ]
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeCategoryData($key, array &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 2])) {
if ($data[$key]['template_name'] == 'text' && $data[$key + 1]['template_name'] == 'textNav'
&& $data[$key + 2]['template_name'] == 'floor') {
$result = array(
'category' => array(
'name' => '',
'navs' => array(),
'list' => array()
)
);
// text模版
$result['category']['name'] = $data[$key]['data']['text'];
// textNav模版
if (! empty($data[$key + 1]['data'])) {
$result['category']['navs'] = self::mergeNavProcess($data[$key + 1], $type);
}
// floor模版
foreach ($data[$key + 2]['data'] as $pos => $val) {
$width = 185; $height = 510;
if($pos == 1) {
$width = 377; $height = 504;
}
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$result['category']['list'][] = array(
'href' => $val['url'],
'img' => $val['src'],
'name' => $val['title']
);
}
unset($data[$key], $data[$key + 1], $data[$key + 2]);
}
}
return $result;
}
/**
* 组合HotCategory数据 [template: hotCategory & floor] 首页使用
*
* @param string $key
* @param array $data
* @param string $type
* @return array
*/
public static function mergeHotCategoryData($key, &$data, $type)
{
$result = array();
if (isset($data[$key]) && isset($data[$key + 1]))
{
if ($data[$key]['template_name'] == 'hotCategory' && $data[$key + 1]['template_name'] == 'floor')
{
$result = array(
'name' => '',
'navs' => array(),
'tplrecommend' => array(
'keyword' => array(),
'category' => array(),
'brands' => array(),
'types' => array(),
'products' => array()
)
);
// hotCategory模版
$temp = self::hotCategory($data[$key], $type);
$temp = $temp['recommend'];
$result['name'] = $temp['name'];
$result['navs'] = $temp['navs'];
$result['tplrecommend']['keyword'] = $temp['tplrecommend']['keyword'];
$result['tplrecommend']['category'] = $temp['tplrecommend']['category'];
foreach ($data[$key]['data']['imgs'] as $key2 => $val)
{
$val['url'] = Helpers::transUrl($val['url'], $type);
if ($key2 == 0 || $key2 == 4) // 两个大图
{
$val['img'] = Images::getImageUrl($val['img'], 378, 248, 1); // 大图
$result['tplrecommend']['brands'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
} else {
$val['img'] = Images::getImageUrl($val['img'], 185, 248, 1); // 小图
$result['tplrecommend']['types'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['img']
);
}
}
// floor模版
foreach ($data[$key + 1]['data'] as $val)
{
$val['src'] = Images::getImageUrl($val['src'], 222, 298, 1); // 小图
$result['tplrecommend']['products'][] = array(
'href' => $val['url'],
'name' => $val['title'],
'img' => $val['src']
);
}
unset($data[$key], $data[$key + 1]);
$result = array(
'recommend' => $result
);
}
}
return $result;
}
/**
* 组合之nav处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeNavProcess(array $data, $type)
{
$result = array();
foreach ($data['data'] as $val) {
if (empty($val))
continue;
$result[] = array(
'href' => $val['url'],
'name' => $val['name']
);
}
return $result;
}
/**
* 组合之商品处理
*
* @param array $data
* @param string $type
* @return array
*/
public static function mergeGoodsProcess(array $data, $type)
{
$result = array();
$skns = '';
foreach ($data['data'] as $val) {
$skns .= $val['id'] . ' ';
}
$params = array(
'query' => rtrim($skns),
'client_type' => 'web'
);
$goodsList = SearchData::searchElasticByCondition($params, false);
$goodsList = $goodsList['data']['product_list'];
$pos = 0;
foreach ($goodsList as $goods)
{
$oneGoods = array();
$pos ++;
if ($pos > 12) {
break;
}
if (empty($goods)) {
continue;
}
$oneGoods['img'] = Images::getImageUrl($goods['goods_list'][0]['images_url'], 280, 373, 1);
$oneGoods['name'] = $goods['product_name'];
$oneGoods['price'] = $goods['sales_price'];
$url = Helpers::getUrlBySkc($goods['product_id'], $goods['goods_list'][0]['goods_id'], $goods['cn_alphabet']);
$oneGoods['href'] = Helpers::transUrl($url, $type);
$result[$goods['product_skn']] = $oneGoods;
}
// 排序
uksort($result, function ($a, $b) use($skns) {
$skn_arr = explode(' ', $skns);
return array_search($a, $skn_arr) > array_search($b, $skn_arr);
});
$pos = 1;
//添加TOP标示
foreach($result as &$val) {
if($pos < 4) {
$val['tip'] = 'TOP'.$pos;
}
else {
break;
}
$pos ++;
}
return $result;
}
/**
* 热门品牌数据处理
*
* @param array $data
* @param string $type
*/
public static function mergeHotBrandsData($key,array &$data,$type)
{
$result = array();
$temp = array();
if ($data[$key]['template_name'] == 'custom_brands')
{
$result = array(
'hotBrands' => array(
'name' => '',
'brandUrl' => ''
)
);
// text模版
$result['hotBrands']['name'] = '热门品牌';
//floor模板
$floor = array(
'logoBrand' => '',
'moreBrand' => ''
);
$brands = $data[$key]['data']['list'];
foreach ($brands as $val)
{
$width = 185;
$height = 86;
$val['src'] = Images::getImageUrl($val['src'], $width, $height, 2);
$val['url'] = Helpers::transUrl($val['url'], $type);
$floor['logoBrand'][] = array(
'href' => $val['url'],
'img' => $val['src']
);
}
$floor['moreBrand'] = 'http://yohobuy.com/brands';
$type_key = sprintf("%s_%s", $type, $key);
$cacheKey = sprintf("%s_%s", CacheConfig::KEY_INDEX_BRANDS_LIST_DATA, $type_key);
Cache::set($cacheKey, $floor, 86400);
$result['hotBrands']['brandUrl'] = '/common/getIndexResourceBrand?type=' . $type_key;
}
return $result;
}
}
\ No newline at end of file
... ...
... ... @@ -247,7 +247,7 @@ class Helpers
$result['is_soon_sold_out'] = ($productData['is_soon_sold_out'] === 'Y');
$result['url'] = self::url('/product/pro_' . $productData['product_id'] . '_'
. $productData['goods_list'][0]['goods_id']
. '/' . $productData['cn_alphabet'] . '.html');
. '/' . $productData['cn_alphabet'] . '.html', 'item');
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
if ($isApp) {
... ...
... ... @@ -372,6 +372,16 @@ server
proxy_set_header Accept-Encoding "gzip";
}
## since 2016/01/23
location ^~ /shopping/pay/alipay {
proxy_redirect off;
proxy_pass http://yohobuy;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding "gzip";
}
location / {
proxy_redirect off;
proxy_pass http://119.254.81.245;
... ...
... ... @@ -5,7 +5,7 @@
{{/if}}
{{#if preEnv}}
<script src="http://cdn.yoho.cn/yohobuy/{{version}}/lib.js"></script>
<script src="http://cdn.yoho.cn/yohobuy/{{version}}/index.js"></script>
<script src="http://cdn.yoho.cn/yohobuy/{{version}}/index-debug.js"></script>
{{/if}}
{{#if testEnv}}
<script src="http://static.buy.test.yoho.cn/dist/yohobuy/{{version}}/lib.js"></script>
... ...
... ... @@ -320,6 +320,98 @@ if ($('.simple-header').size() > 0) {
$(this).find('.tool-select').fadeOut();
});
}
/**
* 格式化用户名
* @return {[type]} [description]
*/
function formatUsernName(userName) {
var name,
char,
_num = 0,
_length = 0,
t;
for (t = 0; t < userName.length; t++) {
char = userName.substr(t, 1);
if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
_length += 2;
} else {
_length += 1;
}
}
if (_length <= 10) {
name = userName;
} else {
_num = 0;
name = '';
for (t = 0; t < userName.length; t++) {
if (_num < 10) {
char = userName.substr(t, 1);
if (char !== '*') {
if (/.*[\u4e00-\u9fa5]+.*$/.test(char)) {
_num += 2;
} else {
_num += 1;
}
}
name += char;
}
}
if (name.length < userName.length) {
name += '...';
}
}
return name;
}
/**
* 设置简单头部登陆状态
* @return {[type]} [description]
*/
function setLoginStatus(_data) {
var loginHtml,
name;
if (_data && _data.href && _data.href.user) {
name = formatUsernName(_data.href.user);
loginHtml = '<span>Hi~</span><a href="">' +
name + '</a>&nbsp;<a href="' + _data.href.logout + '">[退出]</a>';
} else {
name = formatUsernName(_data.user);
loginHtml = '<span>Hi~</span><a href="">' +
name + '</a>&nbsp;<a href="http://www.yohobuy.com/signin.html">[请登录]</a>' +
'<a href="http://www.yohobuy.com/reg.html">[免费注册]</a>';
}
$('.header-tool li').eq(0).html(loginHtml);
}
/**
* 获取登录信息
* @return {[type]} [description]
*/
function actionLoginInfo() {
$.ajax({
type: 'GET',
url: '/common/getSimpleHeader',
data: {},
success: function(data) {
if (data.code === 200) {
setLoginStatus(data.data);
}
}
});
}
/**
* 初始化函数
* @return {[type]} [description]
*/
function init() {
actionLoginInfo(); //获取登录信息
}
init();
});
define("js/header", ["jquery","handlebars","source-map","index"], function(require, exports, module){
/**
... ... @@ -643,10 +735,26 @@ function JsonPCallBack(data) {
if (+data.code === 200) {
if (typeof data.data === 'object') {
topbanner = '<a target="_blank" href="' + data.data.url + '" class="page-top-banner"' +
'style="height:50px;border:none;background-image:url(' + window.unescape(data.data.src) + ');' +
'background-position: center;display:block;background-color:#ff5409;">&nbsp;</a>';
$('body').prepend(topbanner);
if(data.data.url !== ''){
topbanner = '<a target="_blank" href="' + data.data.url + '" class="page-top-banner"' +
'style="height:36px;border:none;background-image:url(' + window.unescape(data.data.src) + ');' +
'background-position: center;display:block;background-size:contain">&nbsp;</a>';
}else{
topbanner = '<div class="noticewrapper">' +
'<div class="noticecontainer">' +
'<h1 class="noticetitle">关于系统升级的公告</h1>' +
'<div class="noticecontent">' +
'<p class="tips">尊敬的顾客:</p>' +
'<p class="detail">您好!为了向您提供更优质的服务,目前系统正在升级,请耐心等待。</p>' +
'<p class="detail">' +
'系统升级期间,部分地区用户体验会有暂时中断,如遇紧急事宜,欢迎垂询客服热线:400-889-9646 09:00-22:30(周一至周日)。稍后系统将恢复正常' +
'</p>' +
'<p class="detail">使用,欢迎您继续光顾YOHO!BUY有货!带来不便之处深表歉意,请您谅解!</p>' +
'</div>' +
'</div>' +
'</div>';
}
$('body').prepend(topbanner);
}
}
}
... ... @@ -1872,362 +1980,364 @@ require("js/product/latest-walk");
require("js/product/product");
});
define("js/product/filter", ["jquery","handlebars","source-map"], function(require, exports, module){
/**
* 商品筛选逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/4
*/
var $ = require("jquery"),
Handlebars = require("handlebars");
var checkUnicode = {
unchecked: '&#xe613;',
checked: '&#xe612;'
},
moreUnicode = {
up: '&#xe610;',
down: '&#xe600;'
};
//品牌相关变量
var $brandDefault = $('.brand .default'),
$brandPanel = $('.brand .brand-panel'),
$brandAttrs = $brandPanel.find('.attr'),
$brandMore = $('#brand-more'),
$brandMulti = $('#brand-multi');
var $brandMoreTxt, $brandMoreIcon;
//价格相关变量
var $udPrice = $('.ud-price-range'),
interReg = /^\d+$/,
$limit, $min, $max, $btn;
//分类相关变量
var $sortSub = $('.sort-sub-wrap');
//高级选项相关变量
var $seniorSubWrap = $('.senior-sub-wrap'),
$seniorAttrWrap = $('.senior-attr-wrap');
var seniorHoverTime, hoveredIndex;
// 尺寸 handlebars 模板
var sizeTmpl = '{{# size}}<a class="attr {{#if checked}}checked{{/if}}" href="{{href}}">{{name}}</a>{{/ size}}',
sizeCache = {}, // 缓存一下尺寸信息
$sizeWrap = $('.filter-box .size');
sizeTmpl = Handlebars.compile(sizeTmpl);
//清除checkbox选中状态
function clearChecked($checkbox) {
$checkbox.removeClass('checked').html(checkUnicode.unchecked);
}
//显示更多品牌面板
function brandShowMore() {
$brandDefault.addClass('hide');
$brandPanel.removeClass('hide');
}
//隐藏更多品牌面板
function brandHideMore() {
$brandPanel.addClass('hide');
$brandDefault.removeClass('hide');
}
//url构造&跳转
function uriLoc(attr, val) {
var href = decodeURIComponent(window.location.search),
query = attr + '=' + val,
newHref;
if (href === '') {
newHref = '?' + query;
} else {
newHref = href + '&' + query;
}
window.location.href = newHref;
}
//隐藏高级选项面板
function hideSeniorPanel(index) {
$seniorSubWrap.children('.senior-sub:eq(' + hoveredIndex + ')').addClass('hide');
$seniorAttrWrap.children('.attr:eq(' + hoveredIndex + ')').removeClass('hover');
hoveredIndex = -1;
}
//屏蔽筛选项双击文字选中
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
return false;
});
//【分类】
$('.sort-pre').on('click', 'li', function() {
var $this = $(this),
index = $this.index(),
id = $this.data('id');
if ($this.hasClass('active')) {
// 选中时,再次点击取消选中
$this.removeClass('active');
$sortSub.children(':eq(' + index + ')').addClass('hide');
$sizeWrap.addClass('hide');
return;
}
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$sortSub.children(':not(.hide)').addClass('hide');
$sortSub.children(':eq(' + index + ')').removeClass('hide');
if (sizeCache[id]) {
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$.ajax({
url: '/product/search/sortSize',
data: {
msort: id
}
}).then(function(res) {
if ($.type(res) === 'array' && res.length) {
sizeCache[id] = sizeTmpl({
size: res
});
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$sizeWrap.addClass('hide');
}
});
}
});
//【品牌】
if ($brandMore.length > 0) {
$brandMoreTxt = $brandMore.children('em');
$brandMoreIcon = $brandMore.children('.iconfont');
}
//【品牌】多选
$brandMulti.click(function() {
if ($brandPanel.css('display') === 'none') {
//显示品牌面板
$brandMore.trigger('click');
}
$brandPanel.addClass('multi'); //显示出checkbox
$(this).addClass('hide');
});
//【品牌】更多
$brandMore.click(function() {
var $this = $(this);
if ($this.hasClass('more')) {
brandHideMore();
$brandMoreTxt.text('更多');
$brandMoreIcon.html(moreUnicode.down);
} else {
brandShowMore();
$brandMoreTxt.text('收起');
$brandMoreIcon.html(moreUnicode.up);
}
$(this).toggleClass('more');
});
//【品牌】索引
$('.brands-index').on('mouseenter', 'span', function() {
var $this = $(this),
index = $this.data('index');
if ($this.hasClass('hover')) {
return;
}
$this.siblings('span.hover').removeClass('hover');
$this.addClass('hover');
if ($this.index() === 0) {
//全部
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
}
});
//【品牌】搜索
$('#brand-search-input').keyup(function() {
var val = $(this).val().toLowerCase();
if (val === '') {
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-key*="' + val + '"]').removeClass('hide');
}
});
//【品牌】多选确定
$('#brand-multi-ok').click(function() {
var val = '';
if ($(this).hasClass('dis')) {
return;
}
$brandPanel.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc('brand', val);
});
//【品牌/高级选项】多选取消
$('.multi-select-cancel').click(function() {
var $panel = $(this).closest('.multi');
if ($panel.hasClass('brand-panel')) {
$brandMulti.removeClass('hide'); //显示多选按钮
$brandMore.trigger('click');
}
$panel.removeClass('multi');
clearChecked($panel.find('.checkbox.checked')); //清除选中状态
});
//【品牌/高级选项】checkbox
$('.check-container').on('click', '.attr', function() {
var $this = $(this),
$check = $this.find('.checkbox'),
$btnOk = $this.closest('.brand-panel, .senior-sub').find('.multi-select-ok');
$check.toggleClass('checked');
if ($check.hasClass('checked')) {
$check.html(checkUnicode.checked);
} else {
$check.html(checkUnicode.unchecked);
}
//更新按钮状态
if ($check.hasClass('checked') ||
$this.siblings('.attr').find('.checked').length > 0) {
$btnOk.removeClass('dis');
} else {
$btnOk.addClass('dis');
}
});
//【品牌/高级选项】当多选时阻止链接默认跳转
$('.brand, .senior').on('click', '.attr > a', function(e) {
if ($(this).closest('.multi').length > 0) {
e.preventDefault();
}
});
//【价格】用户定义价格处理
if ($udPrice.length > 0) {
$limit = $udPrice.find('.limit');
$min = $limit.filter('.min');
$max = $limit.filter('.max');
$btn = $udPrice.find('.price-sure');
//【价格】输入
$limit.keyup(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
isMinInt = interReg.test(min),
isMaxInt = interReg.test(max);
if (isMaxInt && (min === '' || isMinInt) ||
isMinInt && (max === '' || isMaxInt)
) {
$btn.removeClass('hide');
} else {
$btn.addClass('hide');
}
});
//【价格】多项查询
$btn.click(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
tmp;
//对于min大于max的情况,交换位置
if (min !== '' && max !== '' && +min > +max) {
tmp = max;
max = min;
min = tmp;
}
uriLoc('price', min + ',' + max);
});
}
//【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this);
var index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
var $this = $(this),
index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
hoveredIndex = index;
seniorHoverTime = setTimeout(function() {
hideSeniorPanel();
}, 100);
});
//【高级选项】多选
$('.senior-sub').on('click', '.multi-select', function() {
$(this).closest('.senior-sub').addClass('multi');
}).on('click', '.multi-select-ok', function() {
var $btn = $(this),
$sub = $btn.closest('.senior-sub'),
val = '';
if ($btn.hasClass('dis')) {
return;
}
$sub.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc($sub.data('attr'), val);
}).on('mouseenter', function() {
clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
hideSeniorPanel();
});
/**
* 商品筛选逻辑
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/12/4
*/
var $ = require("jquery"),
Handlebars = require("handlebars");
var checkUnicode = {
unchecked: '&#xe613;',
checked: '&#xe612;'
},
moreUnicode = {
up: '&#xe610;',
down: '&#xe600;'
};
//品牌相关变量
var $brandDefault = $('.brand .default'),
$brandPanel = $('.brand .brand-panel'),
$brandAttrs = $brandPanel.find('.attr'),
$brandMore = $('#brand-more'),
$brandMulti = $('#brand-multi');
var $brandMoreTxt, $brandMoreIcon;
//价格相关变量
var $udPrice = $('.ud-price-range'),
interReg = /^\d+$/,
$limit, $min, $max, $btn;
//分类相关变量
var $sortSub = $('.sort-sub-wrap');
//高级选项相关变量
var $seniorSubWrap = $('.senior-sub-wrap'),
$seniorAttrWrap = $('.senior-attr-wrap');
var seniorHoverTime, hoveredIndex;
// 尺寸 handlebars 模板
var sizeTmpl = '{{# size}}<a class="attr {{#if checked}}checked{{/if}}" href="{{href}}">{{name}}</a>{{/ size}}',
sizeCache = {}, // 缓存一下尺寸信息
$sizeWrap = $('.filter-box .size');
sizeTmpl = Handlebars.compile(sizeTmpl);
//清除checkbox选中状态
function clearChecked($checkbox) {
$checkbox.removeClass('checked').html(checkUnicode.unchecked);
}
//显示更多品牌面板
function brandShowMore() {
$brandDefault.addClass('hide');
$brandPanel.removeClass('hide');
}
//隐藏更多品牌面板
function brandHideMore() {
$brandPanel.addClass('hide');
$brandDefault.removeClass('hide');
}
//url构造&跳转
function uriLoc(attr, val) {
var href = decodeURIComponent(window.location.search),
query = attr + '=' + val,
newHref;
if (href === '') {
newHref = '?' + query;
} else {
newHref = href + '&' + query;
}
window.location.href = newHref;
}
//隐藏高级选项面板
function hideSeniorPanel(index) {
$seniorSubWrap.children('.senior-sub:eq(' + hoveredIndex + ')').addClass('hide');
$seniorAttrWrap.children('.attr:eq(' + hoveredIndex + ')').removeClass('hover');
hoveredIndex = -1;
}
//屏蔽筛选项双击文字选中
$('.filter-box').on('selectstart', '.attr, .brands-index span', function() {
return false;
});
//【分类】
$('.sort-pre').on('click', 'li', function() {
var $this = $(this),
index = $this.index(),
id = $this.data('id');
if ($this.hasClass('active')) {
// 选中时,再次点击取消选中
$this.removeClass('active');
$sortSub.children(':eq(' + index + ')').addClass('hide');
$sizeWrap.addClass('hide');
return;
}
$this.siblings('.active').removeClass('active');
$this.addClass('active');
$sortSub.children(':not(.hide)').addClass('hide');
$sortSub.children(':eq(' + index + ')').removeClass('hide');
if (!$sizeWrap.data('load')) {
if (sizeCache[id]) {
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$.ajax({
url: '/product/search/sortSize',
data: {
msort: id
}
}).then(function(res) {
if ($.type(res) === 'array' && res.length) {
sizeCache[id] = sizeTmpl({
size: res
});
$sizeWrap.find('.attr-content').html(sizeCache[id]);
$sizeWrap.removeClass('hide');
} else {
$sizeWrap.addClass('hide');
}
});
}
}
});
//【品牌】
if ($brandMore.length > 0) {
$brandMoreTxt = $brandMore.children('em');
$brandMoreIcon = $brandMore.children('.iconfont');
}
//【品牌】多选
$brandMulti.click(function() {
if ($brandPanel.css('display') === 'none') {
//显示品牌面板
$brandMore.trigger('click');
}
$brandPanel.addClass('multi'); //显示出checkbox
$(this).addClass('hide');
});
//【品牌】更多
$brandMore.click(function() {
var $this = $(this);
if ($this.hasClass('more')) {
brandHideMore();
$brandMoreTxt.text('更多');
$brandMoreIcon.html(moreUnicode.down);
} else {
brandShowMore();
$brandMoreTxt.text('收起');
$brandMoreIcon.html(moreUnicode.up);
}
$(this).toggleClass('more');
});
//【品牌】索引
$('.brands-index').on('mouseenter', 'span', function() {
var $this = $(this),
index = $this.data('index');
if ($this.hasClass('hover')) {
return;
}
$this.siblings('span.hover').removeClass('hover');
$this.addClass('hover');
if ($this.index() === 0) {
//全部
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-index=' + index + ']').removeClass('hide');
}
});
//【品牌】搜索
$('#brand-search-input').keyup(function() {
var val = $(this).val().toLowerCase();
if (val === '') {
$brandAttrs.removeClass('hide');
} else {
$brandAttrs.addClass('hide').filter('[data-key*="' + val + '"]').removeClass('hide');
}
});
//【品牌】多选确定
$('#brand-multi-ok').click(function() {
var val = '';
if ($(this).hasClass('dis')) {
return;
}
$brandPanel.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc('brand', val);
});
//【品牌/高级选项】多选取消
$('.multi-select-cancel').click(function() {
var $panel = $(this).closest('.multi');
if ($panel.hasClass('brand-panel')) {
$brandMulti.removeClass('hide'); //显示多选按钮
$brandMore.trigger('click');
}
$panel.removeClass('multi');
clearChecked($panel.find('.checkbox.checked')); //清除选中状态
});
//【品牌/高级选项】checkbox
$('.check-container').on('click', '.attr', function() {
var $this = $(this),
$check = $this.find('.checkbox'),
$btnOk = $this.closest('.brand-panel, .senior-sub').find('.multi-select-ok');
$check.toggleClass('checked');
if ($check.hasClass('checked')) {
$check.html(checkUnicode.checked);
} else {
$check.html(checkUnicode.unchecked);
}
//更新按钮状态
if ($check.hasClass('checked') ||
$this.siblings('.attr').find('.checked').length > 0) {
$btnOk.removeClass('dis');
} else {
$btnOk.addClass('dis');
}
});
//【品牌/高级选项】当多选时阻止链接默认跳转
$('.brand, .senior').on('click', '.attr > a', function(e) {
if ($(this).closest('.multi').length > 0) {
e.preventDefault();
}
});
//【价格】用户定义价格处理
if ($udPrice.length > 0) {
$limit = $udPrice.find('.limit');
$min = $limit.filter('.min');
$max = $limit.filter('.max');
$btn = $udPrice.find('.price-sure');
//【价格】输入
$limit.keyup(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
isMinInt = interReg.test(min),
isMaxInt = interReg.test(max);
if (isMaxInt && (min === '' || isMinInt) ||
isMinInt && (max === '' || isMaxInt)
) {
$btn.removeClass('hide');
} else {
$btn.addClass('hide');
}
});
//【价格】多项查询
$btn.click(function() {
var min = $.trim($min.val()),
max = $.trim($max.val()),
tmp;
//对于min大于max的情况,交换位置
if (min !== '' && max !== '' && +min > +max) {
tmp = max;
max = min;
min = tmp;
}
uriLoc('price', min + ',' + max);
});
}
//【高级选项】鼠标移入显示子项
$seniorAttrWrap.on('mouseenter', '.attr', function() {
var $this = $(this);
var index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
$this.addClass('hover').siblings().removeClass('hover');
$seniorSubWrap.children('.senior-sub:eq(' + index + ')').removeClass('hide').siblings().addClass('hide');
}).on('mouseleave', '.attr', function() {
var $this = $(this),
index = $this.index();
if ($this.hasClass('no-sub')) {
return;
}
hoveredIndex = index;
seniorHoverTime = setTimeout(function() {
hideSeniorPanel();
}, 100);
});
//【高级选项】多选
$('.senior-sub').on('click', '.multi-select', function() {
$(this).closest('.senior-sub').addClass('multi');
}).on('click', '.multi-select-ok', function() {
var $btn = $(this),
$sub = $btn.closest('.senior-sub'),
val = '';
if ($btn.hasClass('dis')) {
return;
}
$sub.find('.checked').each(function() {
var id = $(this).data('id');
val += (val === '') ? id : (',' + id);
});
uriLoc($sub.data('attr'), val);
}).on('mouseenter', function() {
clearTimeout(seniorHoverTime);
}).on('mouseleave', function() {
hideSeniorPanel();
});
});
define("js/product/sort-pager", ["jquery"], function(require, exports, module){
... ... @@ -2396,6 +2506,14 @@ exports.init = function(num) {
};
}
function removeHtmlFn() {
$goodInfoMain.html('');
$goodSelectColor.html('');
$goodItemWrapper.css({
display: 'none'
});
}
productList.addHandler('MouseEnter', function(event) {
var itemMr = 10, //list的右边距
itemMb = 35, //list的下边距
... ... @@ -2409,6 +2527,11 @@ exports.init = function(num) {
wrapperPt, //鼠标移入时弹层的上内边距
containerPt; //商品列表容器的上内边距
// 获取图片之前,先把获取上一张图片的ajax请求取消。 网络差的时候会出现错误
// if (getProductAjax && getProductAjax.readyState!= 4) {
// getProductAjax.abort();
// }
$.ajax({
type: 'POST',
url: '/product/list/getProductPic',
... ... @@ -2418,11 +2541,8 @@ exports.init = function(num) {
}
}).then(function(data) {
//setTimeout(function () {
removeHtmlFn();
ulStr = createColorList(data.pics).colorListStr; //ajax请求的颜色列表
ulNum = createColorList(data.pics).ulNum;//ajax请求的颜色的数量
... ... @@ -2465,23 +2585,14 @@ exports.init = function(num) {
if (data.pics[0] && data.pics[0].src) {
$goodInfoMain.find('.good-thumb img').attr('src', data.pics[0].src);
}
//}, 1000);
});
});
$goodItemWrapper.mouseleave(function() {
// removeHtmlFn();
removeHtmlFn();
});
function removeHtmlFn() {
$goodInfoMain.html('');
$goodSelectColor.html('');
$goodItemWrapper.css({
display: 'none'
});
}
};
//鼠标放在颜色列表上效果
... ... @@ -2495,6 +2606,11 @@ $(document).on('hover', '.good-select-color li', function() {
$goodInfoMain.on('click', '.col-btn', function() {
var $this = $(this);
if (!window.getUid()) {
location.href = '/signin.html?refer=' + encodeURIComponent(location.href);
return;
}
$.ajax({
type: 'POST',
url: '/product/list/changeFavorite',
... ... @@ -2636,40 +2752,40 @@ module.exports = function($o, rowWidth) {
};
});
define("js/product/brand", ["jquery"], function(require, exports, module){
/**
* 品牌页面
* @auhtor: bikai<kai.bi@yoho.cn>
* @date: 2016/1/21
*/
var $ = require("jquery");
$('#brand-favor').on('click', function() {
var $this = $(this),
uid = window.getUid();
if (!uid) {
location.href = '/signin.html?refer=' + location.href;
return;
}
$.ajax({
type: 'post',
url: '/product/index/favoriteBrand',
data: {
uid: uid,
brandId: $this.data('id')
}
}).then(function(res) {
if (res.code === 200) {
if (res.message === 'add') {
$this.find('i').addClass('coled');
} else {
$this.find('i').removeClass('coled');
}
}
});
});
/**
* 品牌页面
* @auhtor: bikai<kai.bi@yoho.cn>
* @date: 2016/1/21
*/
var $ = require("jquery");
$('#brand-favor').on('click', function() {
var $this = $(this),
uid = window.getUid();
if (!uid) {
location.href = '/signin.html?refer=' + encodeURIComponent(location.href);
return;
}
$.ajax({
type: 'post',
url: '/product/index/favoriteBrand',
data: {
uid: uid,
brandId: $this.data('id')
}
}).then(function(res) {
if (res.code === 200) {
if (res.message === 'add') {
$this.find('i').addClass('coled');
} else {
$this.find('i').removeClass('coled');
}
}
});
});
});
define("js/product/hotrank", ["jquery","handlebars","source-map","lazyload"], function(require, exports, module){
... ... @@ -3134,6 +3250,10 @@ var $ = require("jquery"),
var brandTpl,
brandHtml;
if (!data || data.length === 0) {
return;
}
that._createHelper();
brandHtml = '\{{#brandList logoBrand}}' +
'<a href="\{{href}}" target="_blank"><img class="lazy" data-original="\{{img}}" alt=""></a>' +
... ... @@ -5827,10 +5947,13 @@ function pwdKeyupEvt() {
} else {
if (pwd.length < 6 || pwd.length > 20) {
hasNoErrPw = false;
$pwdTip1.removeClass('default yes').addClass('no red');
$pwdTip1.text('密码只支持6-20位字符').removeClass('default yes').addClass('no red');
} else if (!/[0-9a-zA-Z]{6,20}$/.test(pwd)) {
hasNoErrPw = false;
$pwdTip1.text('不能包含特殊字符').removeClass('default yes').addClass('no red');
} else {
hasNoErrPw = true;
$pwdTip1.removeClass('default no red').addClass('yes');
$pwdTip1.text('密码只支持6-20位字符').removeClass('default no red').addClass('yes');
}
//提示2不做验证
... ... @@ -6042,132 +6165,132 @@ $('#captcha').keyup(function() {
});
});
define("js/passport/thirdlogin", ["jquery"], function(require, exports, module){
/**
* 登录
* @author: wq
* @date: 2016/1/21
*/
var $ = require("jquery");
function chooseProtocol() {
$('.choosetag').on('change', function() {
if ($(this).attr('checked')) {
$('.choosewrapper').css({
'background-image': 'url("http://webstatic.dev.yohobuy.com/img/passport/choosed.png")'
});
} else {
$('.choosewrapper').css({
'background-image': 'none'
});
}
});
}
function chooseAreaToogle() {
$('.optionshow').on('click', function() {
$('.optionslist').toggleClass('hide');
});
}
function cancelChooseArea() {
$(document).on('click', 'body', function(e) {
var $target = $(e.target);
if ($target.hasClass('yohoselectarea') ||
$target.hasClass('yohoselectarea') ||
$target.hasClass('areaname') ||
$target.hasClass('righttag') ||
$target.hasClass('optionslist') ||
$target.hasClass('optionitem')) {
return;
} else {
$('.optionslist').addClass('hide');
}
});
}
function chooseArea() {
$('.optionitem').on('click', function() {
var $option = $(this);
var areanum = $option.attr('areanum');
var areaname = $option.text();
$('#areaname').text(areaname);
$('#areanum').text(areanum);
$('#areacode').val(areanum);
$('.optionslist').addClass('hide');
});
}
function isagree() {
return $('.choosetag').attr('checked');
}
function closeMask() {
var $target;
$(document).on('click', '#alreayregist', function(e) {
$target = $(e.target);
if ($target.hasClass('mask') || $target.hasClass('backdrop')) {
$('#alreayregist').hide();
}
})
}
function nextStep() {
var openId = '';
var sourceType = '';
var mobile = '';
var areaCode = '';
$('#bindfirststep').on('click', function(e) {
e.preventDefault();
mobile = $('.phonenum').val();
areaCode = $('.areanum').text();
if (mobile === '') {
alert('手机号码不能为空');
return;
}
if (!isagree()) {
alert('请先同意我们的协议');
return;
}
openId = $('#openId').val() || '29803EC6D4AAC3AAB8ABDB6AE829D579';
sourceType = $('#sourceType').val() || 'qq';
$.ajax({
type: 'post',
url: '/passport/autouserinfo/bindCheck',
data: {
mobile: mobile,
area: areaCode,
openId: openId,
sourceType: sourceType
},
dataType: 'json',
success: function(data) {
if (data.code === 200) {
if (data.data.isReg === 0) {
$('#bindmobileform').attr('action', '/passport/thirdlogin/noregist');
$('#bindmobileform').submit();
} else {
$('#alreayregist').show();
}
} else {
alert(data.message);
}
}
});
});
}
function init() {
chooseProtocol();
chooseArea();
chooseAreaToogle();
cancelChooseArea();
nextStep();
closeMask();
}
/**
* 登录
* @author: wq
* @date: 2016/1/21
*/
var $ = require("jquery");
function chooseProtocol() {
$('.choosetag').on('change', function() {
if ($(this).attr('checked')) {
$('.choosewrapper').css({
'background-image': 'url("http://webstatic.dev.yohobuy.com/img/passport/choosed.png")'
});
} else {
$('.choosewrapper').css({
'background-image': 'none'
});
}
});
}
function chooseAreaToogle() {
$('.optionshow').on('click', function() {
$('.optionslist').toggleClass('hide');
});
}
function cancelChooseArea() {
$(document).on('click', 'body', function(e) {
var $target = $(e.target);
if ($target.hasClass('yohoselectarea') ||
$target.hasClass('yohoselectarea') ||
$target.hasClass('areaname') ||
$target.hasClass('righttag') ||
$target.hasClass('optionslist') ||
$target.hasClass('optionitem')) {
return;
} else {
$('.optionslist').addClass('hide');
}
});
}
function chooseArea() {
$('.optionitem').on('click', function() {
var $option = $(this);
var areanum = $option.attr('areanum');
var areaname = $option.text();
$('#areaname').text(areaname);
$('#areanum').text(areanum);
$('#areacode').val(areanum);
$('.optionslist').addClass('hide');
});
}
function isagree() {
return $('.choosetag').attr('checked');
}
function closeMask() {
var $target;
$(document).on('click', '#alreayregist', function(e) {
$target = $(e.target);
if ($target.hasClass('mask') || $target.hasClass('backdrop')) {
$('#alreayregist').hide();
}
});
}
function nextStep() {
var openId = '';
var sourceType = '';
var mobile = '';
var areaCode = '';
$('#bindfirststep').on('click', function(e) {
e.preventDefault();
mobile = $('.phonenum').val();
areaCode = $('.areanum').text();
if (mobile === '') {
alert('手机号码不能为空');
return;
}
if (!isagree()) {
alert('请先同意我们的协议');
return;
}
openId = $('#openId').val() || '29803EC6D4AAC3AAB8ABDB6AE829D579';
sourceType = $('#sourceType').val() || 'qq';
$.ajax({
type: 'post',
url: '/passport/autouserinfo/bindCheck',
data: {
mobile: mobile,
area: areaCode,
openId: openId,
sourceType: sourceType
},
dataType: 'json',
success: function(data) {
if (data.code === 200) {
if (data.data.isReg === 0) {
$('#bindmobileform').attr('action', '/passport/thirdlogin/noregist');
$('#bindmobileform').submit();
} else {
$('#alreayregist').show();
}
} else {
alert(data.message);
}
}
});
});
}
function init() {
chooseProtocol();
chooseArea();
chooseAreaToogle();
cancelChooseArea();
nextStep();
closeMask();
}
init();
});
... ...
This diff could not be displayed because it is too large.
... ... @@ -319,10 +319,26 @@ function JsonPCallBack(data) {
if (+data.code === 200) {
if (typeof data.data === 'object') {
topbanner = '<a target="_blank" href="' + data.data.url + '" class="page-top-banner"' +
'style="height:50px;border:none;background-image:url(' + window.unescape(data.data.src) + ');' +
'background-position: center;display:block;background-color:#ff5409;">&nbsp;</a>';
$('body').prepend(topbanner);
if(data.data.url !== ''){
topbanner = '<a target="_blank" href="' + data.data.url + '" class="page-top-banner"' +
'style="height:36px;border:none;background-image:url(' + window.unescape(data.data.src) + ');' +
'background-position: center;display:block;background-size:contain">&nbsp;</a>';
}else{
topbanner = '<div class="noticewrapper">' +
'<div class="noticecontainer">' +
'<h1 class="noticetitle">关于系统升级的公告</h1>' +
'<div class="noticecontent">' +
'<p class="tips">尊敬的顾客:</p>' +
'<p class="detail">您好!为了向您提供更优质的服务,目前系统正在升级,请耐心等待。</p>' +
'<p class="detail">' +
'系统升级期间,部分地区用户体验会有暂时中断,如遇紧急事宜,欢迎垂询客服热线:400-889-9646 09:00-22:30(周一至周日)。稍后系统将恢复正常' +
'</p>' +
'<p class="detail">使用,欢迎您继续光顾YOHO!BUY有货!带来不便之处深表歉意,请您谅解!</p>' +
'</div>' +
'</div>' +
'</div>';
}
$('body').prepend(topbanner);
}
}
}
... ...
... ... @@ -828,7 +828,7 @@ class HomeController extends AbstractAction
'payAppInfo' => array(
0 => array(
'appIcon' => '',
'payLink' => Helpers::url('/shopping/pay/index', array('order_code' => $orderCode, 'payment_type' => 18)),
'payLink' => Helpers::url('/shopping/pay/alipay', array('order_code' => $orderCode, 'payment_type' => 18)),
'appId' => 'alipay',
'app' => '支付宝支付',
'hint' => '支付宝钱包支付',
... ...
<?php
use Action\AbstractAction;
use Plugin\Helpers;
use LibModels\Wap\Home\OrderData;
use Plugin\Pay\weixin\JsApiPay;
use Plugin\Pay\weixin\lib\WxPayUnifiedOrder;
use Plugin\Pay\weixin\lib\WxPayApi;
use Plugin\Pay\weixin\lib\WxPayConfig;
use Plugin\Pay\aliwap\AliwapReqparams;
use Plugin\Pay\aliwap\AliwapService;
/**
* 支付相关的控制器
*
* @name PayController
* @package Shopping
* @copyright yoho.inc
* @version 1.0 (2016-1-23 13:12:40)
* @author fei.hong <fei.hong@yoho.cn>
*/
class PayController extends AbstractAction
{
/**
* 支付宝跳转页
*
* @param int order_code 订单号
*/
public function alipayAction()
{
do {
/* 判断是否有订单号参数 */
$orderCode = $this->get('order_code');
if (empty($orderCode)) {
break;
}
/* 判断用户是否登录 */
$uid = $this->getUid(true);
if (!$uid) {
$this->go( Helpers::url('/signin.html', array('refer' => $this->_request->server('HTTP_REFERER'))) );
break;
}
/* 判断订单信息是否存在 */
$orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
if (empty($orderDetail['data'])) {
$this->helpJsRedirect('没有找到该订单');
break;
}
/* 判断订单是否已取消 */
if (isset($orderDetail['data']['is_cancel']) && $orderDetail['data']['is_cancel'] === 'Y') {
$this->helpJsRedirect('订单已经取消', 'window.location="' . Helpers::url('/home/orders/detail', array('order_code' => $orderCode)) .'";');
break;
}
$totalFee = $orderDetail['data']['payment_amount'] * 100;
$reqParams = new AliwapReqparams($orderCode, $totalFee, '有货订单号:' . $orderCode, '', $orderDetail['data']['create_time'], '', false);
$aliwapService = new AliwapService();
$payRequestPars = $aliwapService->getPayRequestPars($reqParams);
if (empty($payRequestPars)) {
$this->helpJsRedirect('支付系统繁忙,请稍后再试');
break;
}
// 记录或修改支付方式 说明:由于在web站没有支付宝手机支付的选项,这里就记录支付方式就按照web端支付宝的支付方式平台号为2
// 此处是咨询过JAVA开发任明明,按照老代码的实现方式判断,更新支付方式
$paymentRecod = OrderData::updateOrderPayment($orderCode, 2, $uid);
if (empty($paymentRecod) || $paymentRecod['code'] != 200) {
$this->helpJsRedirect('系统繁忙,请稍后再试');
break;
}
$this->go($payRequestPars['pay_url'] . $payRequestPars['pars']);
}
while (false);
}
/**
* 微信支付 - 获取JSAPI参数
*
* @param int order_code 订单号
* @return json | void
*/
public function wechatwapapiAction()
{
do {
if (!$this->isAjax()) {
break;
}
$uid = $this->getUid(true);
if (!$uid) {
break;
}
$orderCode = $this->get('order_code');
if (empty($orderCode)) {
break;
}
/* 判断订单信息不存在 */
$orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
if (empty($orderDetail['data'])) {
break;
}
$totalFee = strval($orderDetail['data']['payment_amount'] * 100);
$openId = $this->getSession('weixinOpenId');
if (empty($openId)) {
break;
}
//统一下单
$tools = new JsApiPay();
$input = new WxPayUnifiedOrder();
$input->SetBody('有货订单号:' . $orderCode);
$input->SetOut_trade_no('YOHOBuy_' . $orderCode); // 商户订单号
$input->SetTotal_fee($totalFee);
$input->SetTime_start(date("YmdHis", (int) $orderDetail['data']['create_time']));
$input->SetTime_expire(date("YmdHis", (int) $orderDetail['data']['create_time'] + 7200));
$input->SetNotify_url(WxPayConfig::NOTIFY_URL);
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openId);
$order = WxPayApi::unifiedOrder($input);
$jsApiParameters = $tools->GetJsApiParameters($order);
$this->echoJson(array('code' => 200, 'data' => array('jsApiParameters' => json_decode($jsApiParameters))));
} while (false);
}
}
... ...
... ... @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;模块配置
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart"
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
... ...
... ... @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart"
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
... ...
... ... @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart"
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
... ...
... ... @@ -4,7 +4,7 @@ application.directory = APPLICATION_PATH "/application"
;;website library
application.library = ROOT_PATH "/library"
;;默认模块
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart"
application.modules = "Index,Category,Channel,Guang,Passport,Product,Cart,Shopping"
;;加载
application.bootstrap = APPLICATION_PATH "/application/Bootstrap.php"
;;view文件的扩展名
... ...
... ... @@ -162,11 +162,11 @@ routes.cart.route.controller = Home
routes.cart.route.action = Orderdetail
; 微信支付接口
routes.weixinapi.type = "rewrite"
routes.weixinapi.match = "/shopping/pay/wechatwapapi$"
routes.weixinapi.route.module = Index
routes.weixinapi.route.controller = Home
routes.weixinapi.route.action = Weixinapi
;routes.weixinapi.type = "rewrite"
;routes.weixinapi.match = "/shopping/pay/wechatwapapi$"
;routes.weixinapi.route.module = Index
;routes.weixinapi.route.controller = Home
;routes.weixinapi.route.action = Weixinapi
; 支付中心 (微信中配置的目录)
routes.pay.type = "rewrite"
... ...
... ... @@ -2,6 +2,8 @@
use Action\WebAction;
use Product\BrandsModel;
use LibModels\Web\Product\SearchData;
use Plugin\Helpers;
/**
* 品牌首页
... ... @@ -12,7 +14,8 @@ class BrandsController extends WebAction
public function brandsAction()
{
//品牌一览头部
$channel = $this->getCookie("_Channel") ? $this->getCookie("_Channel") : 'boys';
$channelStr = $this->getCookie("_Channel");
$channel = empty($channelStr) ? 'boys': $channelStr;
$this->setWebNavHeader($channel);
//banner-list
... ... @@ -32,8 +35,7 @@ class BrandsController extends WebAction
/**
* 品牌接口数据
*
* @param
* string id 获取品牌ID
* @param string brandId 获取品牌ID
* @return json
*/
public function brandinfoAction()
... ...
... ... @@ -9,7 +9,9 @@ class GirlsController extends WebAction
public function indexAction()
{
$this->setTitle('女生');
$this->setTitle('女生|时尚潮流女装,日韩女装,潮牌女装全球购|YOHO!BUY有货 100%正品保证', false);
$this->setKeywords('女生服饰,时尚潮流女装,日韩女装,女装正品购物网站,女装全球购');
$this->setDescription('YOHO!BUY有货官网女生频道汇集了全球女装潮流时尚,提供时尚潮流女装,日版女装,韩版女装,潮牌女装正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。');
$this->setWebNavHeader(HomeModel::COOKIE_NAME_GIRLS);
$data = array(
'boysHomePage' => true,
... ...
... ... @@ -10,7 +10,9 @@ class KidsController extends WebAction
public function indexAction()
{
$this->setTitle('潮童');
$this->setTitle('潮童|男童装,女童装,韩版童装,儿童服装服饰|YOHO!BUY有货 100%正品保证', false);
$this->setKeywords('潮童,男童装,女童装,韩版童装,儿童服装服饰');
$this->setDescription('YOHO!BUY有货官网潮童频道汇集了全球潮童潮流时尚,提供新款男童装,女童装,韩版童装,儿童服装服饰正品全球购。YOHO!BUY有货购物100%正品保证,支持货到付款。');
$this->setWebNavHeader(HomeModel::COOKIE_NAME_KIDS);
$data = array(
'boysHomePage' => true,
... ...
... ... @@ -10,7 +10,9 @@ class LifestyleController extends WebAction
public function indexAction()
{
$this->setTitle('创意生活');
$this->setTitle('创意生活|创意生活馆,潮流创意家居,家居生活用品|YOHO!BUY有货 100%正品保证', false);
$this->setKeywords('创意生活,创意生活馆,潮流家居,潮流创意家居,家居生活用品,YOHO!有货');
$this->setDescription('YOHO!BUY有货官网创意生活频道汇集了创意生活馆,潮流创意家居,家居生活用品等正品网购,给您的生活带来更多创意。YOHO!BUY有货购物100%正品保证,支持货到付款。');
$this->setWebNavHeader(HomeModel::COOKIE_NAME_LIFESTYLE);
$data = array(
'boysHomePage' => true,
... ...
... ... @@ -3,6 +3,7 @@ use Action\WebAction;
use WebPlugin\Cache;
use Configs\CacheConfig;
use WebPlugin\AuthCode;
use Index\HomeModel;
class ToolsController extends WebAction
{
public function init()
... ... @@ -31,10 +32,11 @@ class ToolsController extends WebAction
{
//频道=>key
$channels = array(
'男生首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_boys',
'女生首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_girls',
'kids首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_kids',
'lifestyle首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_lifestyle',
'导航' => CacheConfig::KEY_WEB_HOME_NAVBAR_DATA,
'男生首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_BOYS_CHANNEL,
'女生首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_GIRLS_CHANNEL,
'kids首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_KIDS_CHANNEL,
'lifestyle首页'=> CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.HomeModel::CODE_LIFESTYLE_CHANNEL,
);
$html = '';
foreach ($channels as $key => $val) {
... ... @@ -53,9 +55,17 @@ class ToolsController extends WebAction
{
$key = $this->get('key');
if(!empty($key)) {
AuthCode::decode($key, 'yohobuy');
$key = AuthCode::decode($key, 'yohobuy');
if(!empty($key)) {
Cache::delete($key);
//导航清除
if($key == CacheConfig::KEY_WEB_HOME_NAVBAR_DATA) {
$list = array(HomeModel::COOKIE_NAME_BOYS, HomeModel::COOKIE_NAME_GIRLS, HomeModel::COOKIE_NAME_KIDS, HomeModel::COOKIE_NAME_LIFESTYLE);
foreach ($list as $val) {
Cache::delete($key.'_'.$val);
}
} else {
Cache::delete($key);
}
echo '清除成功';
}
}
... ...
... ... @@ -58,18 +58,19 @@ class HomeModel
*/
public static function getNavBars($channel = 'boys')
{
$data = IndexData::getNavData();
if (empty($data)) {
return array();
}
$menu = array();
$key = sprintf('%s_%s_%s',CacheConfig::KEY_WEB_HOME_NAVBAR_DATA, md5(serialize($data)), $channel);
$key = CacheConfig::KEY_WEB_HOME_NAVBAR_DATA.'_'.$channel;
$menu = Cache::get($key);
if(empty($menu)) {
$item = array();
$index_main = 0;
foreach ($data['data'] as $val) {
$item = array(
$data = array();
if(empty($menu)) {//数据缓存不存在
$data = IndexData::getNavData();
//接口存在数据
if(!empty($data['data'])) {
$item = array();
$index_main = 0;
foreach ($data['data'] as $val) {
$item = array(
'name_cn' => $val['sort_name'], // 父级
'name_en' => $val['sort_name_en'],
'link' => $val['sort_url'],
... ... @@ -80,10 +81,10 @@ class HomeModel
'is_hot' => $val['is_hot'] == 'Y' ? true : false,
'is_new' => $val['is_new'] == 'Y' ? true : false,
// 'subnav' => array()
);
$index_sub = 0;
foreach ($val['sub'] as $sub) { // 二级
$subnav = array(
);
$index_sub = 0;
foreach ($val['sub'] as $sub) { // 二级
$subnav = array(
'name' => $sub['sort_name'],
'name_en' => $sub['sort_name_en'],
'link' => $sub['sort_url'],
... ... @@ -92,35 +93,41 @@ class HomeModel
'content_code' => $sub['content_code'],
// 'thirdnav' => array(),
'index_sub' => $index_sub ++
);
if (isset($sub['sub'])) {
foreach ($sub['sub'] as $thirdsub) { // 三级
$thirdnav = array(
);
if (isset($sub['sub'])) {
foreach ($sub['sub'] as $thirdsub) { // 三级
$thirdnav = array(
'title' => $thirdsub['sort_name'],
'name_en' => $thirdsub['sort_name_en'],
'link' => $thirdsub['sort_url'],
'content_code' => $thirdsub['content_code'],
// 'branditems' => array()
);
if (isset($thirdsub['sub'])) {
foreach ($thirdsub['sub'] as $fourthnav) { // 四级
$thirdnav['branditems'][] = array(
);
if (isset($thirdsub['sub'])) {
foreach ($thirdsub['sub'] as $fourthnav) { // 四级
$thirdnav['branditems'][] = array(
'brandname' => $fourthnav['sort_name'],
'link' => $fourthnav['sort_url'],
'hot' => $fourthnav['is_hot'] == 'Y' ? 'hot' : ''
);
);
}
}
$subnav['thirdnav'][] = $thirdnav;
}
$subnav['thirdnav'][] = $thirdnav;
}
$item['subnav'][] = $subnav;
}
$item['subnav'][] = $subnav;
$menu[] = $item;
}
$menu[] = $item;
Cache::set($key, $menu, 3600);
}
Cache::set($key, $menu, 3600);
}
//数据缓存和接口都空的,取二级数据
if(empty($menu) && empty($data)) {
$menu = Cache::get($key,'slave');
}
return $menu;
}
... ... @@ -157,11 +164,12 @@ class HomeModel
public static function getSwitchChannel()
{
$channel = self::COOKIE_NAME_BOYS;
if (empty($_COOKIE['_Channel'])) {
if (empty($_COOKIE['_Channel'])) {
self::setSwitchToCookie(self::COOKIE_NAME_BOYS);
} else {
$channel = $_COOKIE['_Channel'];
}
return $channel;
}
... ... @@ -174,17 +182,24 @@ class HomeModel
*/
public static function getChannelResource($channel, $content_code)
{
$key = sprintf(CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.$channel);
$key = CacheConfig::KEY_WEB_HOME_CHANNEL_DATA.'_'.$content_code;
$data = Cache::get($key);
$resource = array();
if(empty($data)) {
$resource = IndexData::getResourceData($content_code);
// 格式化数据
$data = ChannelProcess::getFormat($channel, $resource['data']);
Cache::set($key, $data, 3600);
if(isset($resource['data']) && !empty($resource['data']) && $resource['code'] == 200) {
//格式化数据
$data = ChannelProcess::getFormat($channel, $resource['data']);
Cache::set($key, $data, 3600);//设置master,slave
}
}
//master没有数据,资源位没有数据, 取二层缓存
if(empty($data) && (empty($resource) || !isset($resource['data']))) {
$data = Cache::get($key, 'slave');
}
return $data;
}
/**
* 获取lifesytle频道资源
*
... ...