Authored by 王洪广

增加品牌优惠券

... ... @@ -22,35 +22,35 @@ class Yohobuy
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
//java API
// const API_URL = 'http://api.yoho.yohoops.org/';//
// const API_URL2 = 'http://api.yoho.yohoops.org/';//
// const SERVICE_URL = 'http://service.yoho.yohoops.org/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
// const API_OLD = 'http://api2.open.yohobuy.com/';
// 支付回调地址
// const SERVICE_NOTIFY = 'http://service.yoho.cn/';
// const API_URL = 'http://api.yoho.yohoops.org/';//
// const API_URL2 = 'http://api.yoho.yohoops.org/';//
// const SERVICE_URL = 'http://service.yoho.yohoops.org/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
// const API_OLD = 'http://api2.open.yohobuy.com/';
// 支付回调地址
// const SERVICE_NOTIFY = 'http://service.yoho.cn/';
// 测试环境 */
const API_URL = 'http://testapi.yoho.cn:28078/'; // 'http://192.168.102.205:8080/gateway/'
const SERVICE_URL = 'http://testservice.yoho.cn:28077/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
const API_OLD = 'http://test2.open.yohobuy.com/';
// 支付回调地址
const SERVICE_NOTIFY = 'http://testservice.yoho.cn:28077/';
const API_URL = 'http://testapi.yoho.cn:28078/'; // 'http://192.168.102.205:8080/gateway/'
const SERVICE_URL = 'http://testservice.yoho.cn:28077/';
const YOHOBUY_URL = 'http://www.yohobuy.com/';
const API_OLD = 'http://test2.open.yohobuy.com/';
// 支付回调地址
const SERVICE_NOTIFY = 'http://testservice.yoho.cn:28077/';
/* 预览环境 */
// const API_URL = 'http://preapi.yoho.cn/';
// const API_URL2 = 'http://preapi.yoho.cn/';
// const SERVICE_URL = 'http://preservice.yoho.cn/';
// const SERVICE_URLgit = 'http://preservice.yoho.cn/';
// const YOHOBUY_URL = 'http://www.yohobuy.com/';
// const API_OLD = 'http://api2.open.yohobuy.com/';
/**
* 登录老接口Api配置
*/
const API_LOGIN_URL = 'http://api.open.yohobuy.com';
const API_LOGIN_URL_TEST = 'http://test.open.yohobuy.com';
/**
* 私钥列表
*
... ... @@ -63,7 +63,7 @@ class Yohobuy
'web' => '0ed29744ed318fd28d2c07985d3ba633',
'h5' => 'fd4ad5fcfa0de589ef238c0e7331b585',
);
/**
... ... @@ -77,7 +77,7 @@ class Yohobuy
else {
return 'web';
}
// // 苹果设备
// if (strstr($_SERVER['HTTP_USER_AGENT'], 'iPhone')) {
// return 'iphone';
... ... @@ -187,7 +187,7 @@ class Yohobuy
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($useGzip) {
if ($useGzip) {
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
}
if (!empty($userAgent)) {
... ... @@ -230,7 +230,7 @@ class Yohobuy
public static function post($url, $data = array(), $returnJson = false, $timeout = 10, $header = array(), $cookie = array())
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
if (!empty($header)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
... ... @@ -352,7 +352,7 @@ class Yohobuy
continue;
}
$result[$name] = $response['data'];
}
}
else {
$result[$name] = $response;
}
... ... @@ -496,7 +496,7 @@ class Yohobuy
return $result;
}
/**
* 获取用户User-Agent
* @return bool
... ... @@ -508,7 +508,7 @@ class Yohobuy
}
return $_SERVER['HTTP_USER_AGENT'];
}
/**
* 判断是否手机
* @return bool
... ...
... ... @@ -11,12 +11,7 @@
{{> product/shop-sidebar}}
</div>
<div class="list-right pull-right">
{{#if coupon}}
<div class="coupon clearfix">
<div class="coupon-title">
</div>
</div>
{{/if}}
<div class="coupon-wrapper"></div>
{{#if largeSlideImg}}
<div class="slider-wrap clearfix">
<div class="slider-left pull-left">
... ... @@ -83,3 +78,4 @@
</div>
</div>
{{> layout/footer}}
{{> product/brand-coupon-tpl}}
\ No newline at end of file
... ...
<script id="brand_coupon" type="text/html">
<div class="brand-coupon \{{#compare coupons.length '==' 1}}coupons-one\{{/compare}}\{{#compare coupons.length '==' 2}}coupons-two\{{/compare}}\{{#compare coupons.length '>=' 3}}coupons-more\{{/compare}}">
<div class="coupon-slogen"></div>
<div class="coupons">
<ul class="clearfix">
\{{#each coupons}}
<li data-id="\{{coupon_id}}" data-money="\{{money}}" data-couponname="\{{coupon_name}}" data-time="\{{couponValidity}}">
\{{#compare ../coupons.length '==' 1}}
<div class="coupon-box">
<div class="coupon-amount"><i>&yen;</i><span>\{{money}}</span>优惠券</div>
<div class="coupon-limit">
<p>\{{coupon_name}}</p>
<p class="time">有效日期:\{{couponValidity}}</p>
</div>
</div>
\{{/compare}}
\{{#compare ../coupons.length '==' 2}}
<div class="coupon-box">
<p><span class="amount"><i>&yen;</i>\{{money}}</span><span class="limit">\{{coupon_name}}</span></p>
<p class="time">有效日期:\{{couponValidity}}</p>
</div>
\{{/compare}}
\{{#compare ../coupons.length '>=' 3}}
<div class="coupon-box">
<p><span class="amount"><i>&yen;</i>\{{money}}</span></p>
<p class="limit">\{{coupon_name}}</p>
</div>
\{{/compare}}
\{{#compare status '==' 1}}
\{{#compare ../../coupons.length '<' 3}}
<div class="button-receive"><a href="javascript:;">点击领取</a></div>
\{{/compare}}
\{{#compare ../../coupons.length '>=' 3}}
<div class="button-receive"><a href="javascript:;">点击<br>领取</a></div>
\{{/compare}}
\{{/compare}}
\{{#compare status '==' 2}}
<div class="button-receive"><span>已抢光</span></div>
\{{/compare}}
\{{#compare status '==' 3}}
<div class="button-receive"><span>已领取</span></div>
\{{/compare}}
</li>
\{{/each}}
</ul>
</div>
\{{#compare coupons.length '>=' 3}}
<a href="javascript:;" class="trigger-scroll"><i></i></a>
\{{/compare}}
</div>
</script>
\ No newline at end of file
... ...
... ... @@ -6,7 +6,9 @@
var $ = require('yoho.jquery'),
lazyLoad = require('yoho.lazyload'),
product = require('../product/product');
product = require('../product/product'),
Handlebars = require('yoho.handlebars'),
dialog = require('../common/dialog');
var $shopIntro = $('.shop-intro'),
$shopCollect = $('.shop-collect'),
... ... @@ -15,6 +17,8 @@ var $shopIntro = $('.shop-intro'),
$fixedArea = $allGoods.find('.fixed-area'),
fixedAreaTop = $fixedArea.offset() ? $fixedArea.offset().top : 0;
var dialogMessage = '<p class="message-title"><i class="coupon-icon {{messageIcon}}"></i>{{messageTitle}}</p>{{#if money}}<p class="money"><i>&yen;</i>{{money}}</p>{{/if}}<p class="message-summary">{{{messageSummary}}}</p>';
var Dialog = dialog.Dialog;
// Pjax
require('yoho.pjax');
... ... @@ -130,3 +134,204 @@ $(window).on('scroll', function() {
});
}
});
// 注册handlebar
Handlebars.registerHelper('compare', function(lvalue, operator, rvalue, options) {
if (arguments.length < 3)
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
//var operator = options.hash.operator || "==";
var operators = {
'==': function(l,r) { return l == r; },
'===': function(l,r) { return l === r; },
'!=': function(l,r) { return l != r; },
'<': function(l,r) { return l < r; },
'>': function(l,r) { return l > r; },
'<=': function(l,r) { return l <= r; },
'>=': function(l,r) { return l >= r; },
'typeof': function(l,r) { return typeof l == r; }
}
if (!operators[operator])
throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);
var result = operators[operator](lvalue,rvalue);
if( result ) {
return options.fn(this);
} else {
return options.inverse(this);
}
});
// 品牌领券
function getCoupons(){
var id_brand = $('.shop-collect').data('id');
var tpl_coupon = $('#brand_coupon').html();
var template = Handlebars.compile(tpl_coupon);
$.ajax({
url: '/product/get-brand-intro',
data: {
brandId: id_brand
},
success: function(res) {
if (res.code === 200) {
var data = res.data;
var coupons = data.coupons;
var length = coupons.length;
if(length <= 0){
return;
}
var html = template({coupons:coupons});
$('.coupon-wrapper').html(html);
} else if (res.code === 401) {
location.href = res.url;
}
},
complete: function() {
initCoupon();
}
});
// var html = template(
// {
// coupons:[
// {
// couponValidity:'2016.07.14-2016.07.26',
// coupon_id:12022,
// coupon_name:'新客ABLE JEANS品牌优惠券满699减100元',
// money:"100.0",
// status:1
// },
// {
// couponValidity:'2016.07.14-2016.07.26',
// coupon_id:12022,
// coupon_name:'新客ABLE JEANS品牌优惠券满699减100元',
// money:"100.0",
// status:1
// },
// {
// couponValidity:'2016.07.14-2016.07.26',
// coupon_id:12022,
// coupon_name:'新客ABLE JEANS品牌优惠券满699减100元',
// money:"100.0",
// status:1
// },
// {
// couponValidity:'2016.07.14-2016.07.26',
// coupon_id:12022,
// coupon_name:'新客ABLE JEANS品牌优惠券满699减100元',
// money:"100.0",
// status:1
// }
// ]
// });
// $('.coupon-wrapper').html(html);
// initCoupon();
}
function initCoupon(){
var $container = $('.coupons-more');
var li_num = $container.find('li').length;
var click_num = li_num > 3 ? li_num - 3 : 0;
var $ul = $container.find('ul');
var i = 0;
var active;
$container.on('click', '.trigger-scroll', function() {
if (click_num) {
if (i === click_num) {
return;
}
i++;
$ul.animate({left: -250 * i}, 400)
}
})
// 页面暂时没有往前滚动的操作
// $container.on('click', '.trigger-back', function() {
// if (click_num) {
// if (i === 0) {
// return;
// }
// i--;
// $ul.animate({left: -250 * i}, 400)
// }
// })
$('.brand-coupon').on('click', '.button-receive', function(){
var _this = this;
var $parent_li = $(_this).parent();
var id_coupon = $parent_li.data('id');
var coupon_name = $parent_li.data('couponname');
var coupon_money = $parent_li.data('money');
var time = $parent_li.data('time');
$.ajax({
type: 'post',
url: '/product/get-coupon?couponId=' + id_coupon,
success: function(res) {
if (res.code === 200) {
$(_this).html('<span>已领取</span>');
active = showMessgaeDialog({
message_icon: 'icon-success',
money: coupon_money,
message_title: '领取成功',
message_summary: coupon_name+'<br>有效日期:'+time,
confirm : function() {
location.href='//www.yohobuy.com/';
},
cancel : function(){
location.href = '//www.yohobuy.com/home/coupons';
}
});
active.show();
} else if (res.code === 403){
location.href = '/signin.html?refer=' + location.href;
} else {
active = showMessgaeDialog({
message_icon: 'icon-warning',
money: '',
message_title: res.message,
message_summary: '有效日期:'+time,
confirm : function() {
location.href='//www.yohobuy.com/';
},
cancel : function(){
location.href = '//www.yohobuy.com/home/coupons';
}
});
active.show();
}
}
});
})
}
function showMessgaeDialog(opt) {
var template = Handlebars.compile(dialogMessage);
var html = template({messageIcon: opt['message_icon'],money:opt['money'], messageTitle: opt['message_title'], messageSummary: opt['message_summary']});
var options = {
mask: true,
btns: [
{
id: 'goBuy',
name: '去购物啦',
btnClass: ['go-buy'],
cb: function() {
active.close();
opt['confirm'] && opt['confirm']();
}
},
{
id: 'seeCoupons',
name: '查看优惠券',
btnClass: ['see-coupon'],
cb: function() {
active.close();
opt['cancel'] && opt['cancel']();
}
}
],
content: html,
className: 'message-dialog',
};
return new Dialog(options);
}
getCoupons();
\ No newline at end of file
... ...
... ... @@ -115,6 +115,204 @@
background: url(/product/coupon-title.png);
}
}
.brand-coupon{
width: 970px;
margin-bottom:20px;
overflow: hidden;
line-height:1.5;
.coupon-slogen{
float: left;
width: 160px;
height: 80px;
background: resolve(/product/coupon-sprite.png) 0 -31px no-repeat;
}
.coupons{
float: left;
width: 770px;
color: #fff;
overflow: hidden;
ul{
position: relative;
width: 9999em;
}
li{
float: left;
position: relative;
width: 230px;
height: 80px;
margin-left: 20px;
overflow: hidden;
}
.button-receive{
position: absolute;
right: 0;
top: 0;
width: 88px;
height: 60px;
margin-top: 10px;
margin-left: 20px;
line-height: 60px;
text-align: center;
word-wrap: break-word;
border-left: 1px solid rgba(255, 255, 255, .5);
a,span{
display: block;
color: #fff;
font-size: 22px;
}
span{
line-height: 60px;
}
}
}
.coupon-box{
overflow: hidden;
}
.trigger-scroll{
display: block;
float: left;
width: 40px;
height:80px;
background: #d0021b;
text-align: center;
i{
display: inline-block;
width: 18px;
height: 31px;
margin-top: 24px;
background: resolve(/product/coupon-sprite.png) -62px 0 no-repeat;
}
}
}
.coupons-one{
.coupon-slogen{
width: 225px;
height: 80px;
background: resolve(/product/coupon-sprite.png) 0 -112px no-repeat;
}
.coupons {
width: 745px;
li {
width: 725px;
background: resolve(/product/coupon-one.png) no-repeat;
}
.coupon-amount{
float: left;
width: 230px;
padding: 0 20px;
line-height: 80px;
font-size: 35px;
i{
font-family: Arial;
margin-right: 10px;
}
span{
font-size: 42px;
}
}
.coupon-limit{
float: left;
margin-top: 12px;
p{
font-size: 16px;
i{
font-family: Arial;
}
}
.time{
border-top: 1px dotted #fff;
}
}
.button-receive{
width: 148px;
}
}
}
.coupons-two{
.coupons {
width: 810px;
li{
width: 385px;
background: resolve(/product/coupon-two.png) no-repeat;
}
.button-receive{
width: 126px;
}
}
.coupon-box{
width: 232px;
padding-left:15px;
font-size: 13px;
margin-top: -5px;
i{
font-family: Arial;
}
> p:first-child{
position: relative;
}
.amount{
font-size: 40px;
i{
margin-right: 7px;
}
}
.limit{
position: absolute;
right:0;
bottom:10px;
}
.time{
border-top: 1px dotted #fff;
line-height: 20px;
margin-top: -8px;
}
}
}
.coupons-more{
.coupons {
li{
background: resolve(/product/coupon-other.png) no-repeat;
}
.button-receive{
line-height: 30px;
}
}
.coupon-box{
width: 103px;
font-size: 13px;
padding: 0 15px;
i{
font-family: Arial;
}
.amount{
font-size: 36px;
i{
margin-right: 7px;
}
}
.limit{
line-height: 20px;
margin-top: -8px;
}
}
}
.slider-wrap {
height: 360px;
... ... @@ -610,3 +808,82 @@
}
}
}
.message-dialog{
width: 350px;
background: #fff;
padding: 20px 30px 35px 30px;
.message-title{
margin-top: 40px;
margin-bottom: 27px;
font-size: 24px;
font-weight: 700;
}
.money{
text-align: center;
color: #d0021b;
font-size: 36px;
margin-bottom: 20px;
i{
font-family: 'arial';
margin-right: 7px;
}
}
.message-summary{
width: 250px;
margin: 0 auto 22px;
font-size: 14px;
word-wrap: break-word;
line-height: 20px;
}
.btns {
padding: 15px 30px 0;
text-align: center;
.btn {
height: 35px;
font-size: 15px;
line-height: 35px;
margin-left: 0;
}
.go-buy {
width: 130px;
color: #fff;
background: #000;
border: 1px solid #000;
}
.see-coupon{
width: 130px;
color: #000;
background: #fff;
border: 1px solid #000;
}
}
.close{
top: 15px;
right: 15px;
.iconfont{
font-size: 30px;
}
}
}
.coupon-icon{
display: inline-block;
vertical-align: middle;
margin-right: 10px;
background: resolve(/product/coupon-sprite.png);
}
.icon-success{
width: 30px;
height: 30px;
vertical-align: -6px;
background-position: -31px 0;
}
.icon-warning{
width: 30px;
height: 30px;
vertical-align: -6px;
background-position: 0 0 ;
}
... ...