Authored by htoooth

fix

... ... @@ -7,6 +7,7 @@
const headerModel = require('../../../doraemon/models/simple-header');
const ticketService = require('../models/ticket-service');
const _ = require('lodash');
const stepper = [
{ name: '填写订单', focus: true },
... ... @@ -23,9 +24,6 @@ const ticketEnsure = (req, res, next) => {
result.stepper = stepper;
// 限定发售&套餐不支持优惠券
result.notUseCoupon = false;
res.render('ticket-ensure', {
title: '填写订单 | ' + (res.locals.title || ''),
page: 'ticket',
... ... @@ -37,20 +35,47 @@ const ticketEnsure = (req, res, next) => {
};
const ticketSubmit = (req, res, next) => {
let remoteIp = req.ip;
let uid = req.user.uid;
let params = req.body;
let sku = req.body.sku || 0;
let count = req.body.count || 0;
let mobile = req.body.mobile || 0;
let yohoCoin = req.body.yohoCoin || 0;
if (!uid) {
return next();
if (!sku || !count || !mobile) {
return res.json({
code: 410,
message: '参数错误'
});
}
ticketService.submitTicket(uid, 'ordinary', params, remoteIp).then(result => {
res.json(result);
ticketService.submitTicket(uid, sku, count, mobile, yohoCoin).then(result => {
return res.json(result);
}).catch(next);
};
const ticketCompute = (req, res, next) => {
let uid = req.user.uid;
let sku = req.body.sku || 0;
let buyNumber = req.body.count || 0;
let yohoCoin = req.body.coin || 0;
ticketService.addTicket(uid, sku, buyNumber, yohoCoin).then(result => {
if (_.isEmpty(result)) {
return res.json({
code: 401,
message: '不成功'
});
}
return res.json({
code: 200,
data: result
});
}).catch(next);
};
module.exports = {
ticketSubmit,
ticketEnsure
ticketEnsure,
ticketCompute
};
... ...
... ... @@ -3,13 +3,59 @@
*/
const api = require('./ticket-api');
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const _handleUseYhoCoin = require('./order-ensure-handle').handleUseYohoCoin;
const addTicket = (uid, sku, count, yohoCoin) => {
return api.add(uid, sku, count, yohoCoin);
};
function _handleGoodsList(list) {
return list.map((i) => {
i.linkToGoods = helpers.getUrlBySkc(i.product_skn);
i.productPrice = i.sales_price;
return i;
});
}
const submitTicket = () => {
};
function _handleAmount(info) {
return _.get(info, 'data.shopping_cart_data.last_order_amount', 0);
}
const addTicket = co(function * (uid, sku, count, yohoCoin) {
let ticketInfo = yield api.add(uid, sku, count, yohoCoin);
let result = {};
if (ticketInfo.code !== 200) {
return result;
}
result.goodsList = _handleGoodsList(_.get(ticketInfo, 'data.goods_list', []));
result.last_order_amount = _handleAmount(ticketInfo);
Object.assign(result, _handleUseYhoCoin(_.get(ticketInfo, 'data.shopping_cart_data', {})));
return result;
});
const submitTicket = co(function * (uid, sku, count, mobile, yohoCoin) {
let result = yield api.submit(uid, sku, count, mobile, yohoCoin);
if (result.code !== 200) {
return {
code: 410,
message: '提交失败'
};
}
return {
code: 200,
message: '提交成功',
data: {
refer: helpers.urlFormat('/shopping/newpay', {
ordercode: result.data.order_code
})
}
};
});
module.exports = {
addTicket,
... ...
... ... @@ -39,6 +39,7 @@ router.post('/easypay/submit', auth, easypay.submit); // 限购商品订单提
router.post('/ticketEnsure', auth, ticket.ticketEnsure);
router.post('/ticketSubmit', auth, ticket.ticketSubmit);
router.post('/ticketCompute', auth, ticket.ticketCompute);
router.get('/cart', cart.cart);
router.post('/cart/select', cart.selectProduct);
... ...
... ... @@ -7,24 +7,21 @@
<div class="address-wrap">
<div class="block-title">请填写并核对以下信息</div>
<div class="order-content">
<div class="ticket-selection">
<h2>支付及发劵时间:</h2>
<ul class="modity-pay-info">
<li>付款方式:<span>在线支付</span></li>
<li>发劵时间:<span>自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。</span></li>
<li>手机号:
<span class="show-ticket-mobile hide">
<span class="ticket-mobile"></span><span class="ticket-modify-btn">[修改]</span>
</span>
<span class="set-ticket-mobile">
<input type="text" value="" class="ticket-mobile-input"/>
<input type="button" value="确定" class="ticket-mobile-btn"/>
<span class="ticket-mobile-tip">请填写正确手机号以便于接收票条信息</span>
</span>
</li>
</ul>
</div>
<div class="ticket-selection">
<div class="title">支付及发劵时间:</div>
<ul class="modity-pay-info">
<li>付款方式:<span>在线支付</span></li>
<li>发劵时间:<span>自动发货 - 在您支付成功后,系统将立即为您发放二维码,您可以在您的订单中查看。</span></li>
<li>手机号:
<span class="show-ticket-mobile hide">
<span class="ticket-mobile"></span><span class="ticket-modify-btn">[修改]</span>
</span>
<span class="set-ticket-mobile">
<input type="text" value="" class="ticket-mobile-input"/>
<span class="ticket-mobile-tip">请填写正确手机号以便于接收票条信息</span>
</span>
</li>
</ul>
</div>
</div>
... ... @@ -52,7 +49,6 @@
<p class="name">
{{product_name}}
</p>
{{#isY is_limit_skn}}<p class="special-limit-7day">不支持7天无理由退换</p>{{/isY}}
</a>
</td>
<td class="border-top color-size">
... ... @@ -61,15 +57,6 @@
</td>
<td class="border-top price">
<p class="red">¥ {{round productPrice 2}}</p>
{{#if linePrice}}
<p class="line-through">¥ {{round linePrice 2}}</p>
{{/if}}
{{#isVipPrice}}
<p class="tip-message">(VIP)</p>
{{/isVipPrice}}
{{#isStuPrice}}
<p class="tip-message">(学生价)</p>
{{/isStuPrice}}
</td>
<td class="border-top">× {{buy_number}}</td>
<td{{#if @first}} class="border-top"{{/if}}></td>
... ... @@ -79,34 +66,34 @@
</table>
</div>
<div class="extra-wrap">
<div class="extra-wrap ticket-wrapper">
<dl>
<dt><span class="locker-switch"></span>使用有货币</dt>
<dd id="yoho-coin-box" class="yoho-coin-box" data-coin="{{usedCoinNum}}"
data-max={{canUseCoinNum}} data-total="{{total_yoho_coin_num}}">
<div class="outer-view">
<p class="coin-err-tip">{{coinErrorTip}}</p>
<p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span
class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
<i class="help-icon"></i>
<div class="coin-tip-help">
<p>有货币使用提示:</p>
<p>
1.订单金额大于20元(含20元)<br>
2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>
3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}
</p>
<p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</div>
<div class="coin-main-view">
<p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span>
</p>
<p class="grey fw300">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span
class="red">{{canUseCoinNum}}</span></p>
<label class="coin-cancel-btn fw300">取消使用</label>
<label class="coin-use-btn">确定</label>
</div>
<p class="coin-err-tip">{{coinErrorTip}}</p>
<p>有货币满<span class="red">{{yoho_coin_pay_rule.num_limit}}</span>个即可使用,每次使用有货币为<span
class="red">{{yoho_coin_pay_rule.num_limit}}</span>的整数倍</p>
<i class="help-icon"></i>
<div class="coin-tip-help">
<p>有货币使用提示:</p>
<p>
1.订单金额大于20元(含20元)<br>
2.有货币数量大于{{yoho_coin_pay_rule.num_limit}}个(含{{yoho_coin_pay_rule.num_limit}}个) <br>
3.有货币支付上限为每笔订单应付金额的{{yoho_coin_pay_rule.max_pay_rate_desc}}
</p>
<p class="rs-text">备注:使用有货币数量为{{yoho_coin_pay_rule.num_limit}}的整数倍,100有货币抵1元</p>
</div>
</div>
<div class="coin-main-view">
<p>本次使用有货币<span class="red">{{canUseCoinNum}}</span>个,抵扣 <span class="red">¥{{yoho_coin}}</span>
</p>
<p class="grey fw300">您当前共有有货币 <span class="red">{{total_yoho_coin_num}}</span> 个,可用 <span
class="red">{{canUseCoinNum}}</span></p>
<label class="coin-cancel-btn fw300">取消使用</label>
<label class="coin-use-btn">确定</label>
</div>
</dd>
</dl>
... ...
... ... @@ -4,3 +4,143 @@
var $ = require('jquery');
var yas = require('../common/data-yas'),
dialog = require('../common/dialog');
var $orderPrice = $('#order-price');
var order = {};
var yohoCoin;
var submitting = false;
function validateUserInfo(info) {
var errTip = '';
if (!info.mobile) {
errTip = '您还没有填写手机号';
}
if (errTip) {
new dialog.Alert((errTip)).show();
return false;
}
return true;
}
function handleOrderInfo(info) {
var $goods = $('.goods-item');
info.sku = $goods.data('sku');
info.count = $goods.data('num');
info.mobile = $('.ticket-mobile-input').val();
return info;
}
function compute(coin) {
var req;
order = handleOrderInfo(order);
req = $.extend({}, order, {
coin: coin || 0
});
$.ajax({
type: 'POST',
url: '/cart/ticketcompute',
data: req
}).then((result) => {
if (result.code === 200) {
order.coin = result.data.usedCoinNum;
yohoCoin.maxCoin = result.data.canUseCoinNum;
$orderPrice.html('¥ ' + result.data.last_order_amount);
}
});
}
// 有货币
yohoCoin = {
$el: $('#yoho-coin-box'),
init: function() {
var data;
if (!this.$el.length) {
return;
}
data = this.$el.data();
if (data) {
order.coin = data.coin || 0;
this.maxCoin = data.max;
this.totalCoin = data.total;
}
this.eventBind();
},
eventBind: function() {
var that = this;
this.$el.on('click', '.coin-use-btn', function() {
if (order.coin * 1 !== this.maxCoin * 1) {
compute(that.maxCoin);
}
that.close();
}).on('click', '.coin-cancel-btn', function() {
if (order.coin * 1 !== 0) {
order.coin = 0;
compute();
}
that.close();
});
},
close: function() {
this.$el.prev().children('.locker-switch').trigger('click');
}
};
$('.locker-switch').click(function() {
var $this = $(this),
$par = $this.parent();
$par.toggleClass('open');
});
$('#order-submit').on('click', function() {
if (submitting) {
return;
}
order = handleOrderInfo(order);
if (!validateUserInfo(order)) {
return;
}
submitting = true;
$.ajax({
type: 'POST',
url: '/cart/ticketSubmit',
data: order
}).then(function(data) {
if (data.code === 200) {
window.location.href = data.data.refer;
}
}).always(function() {
submitting = false;
});
});
yohoCoin.init();
// 获取用户是否新客(品众统计)写cookie
$.ajax({type: 'GET', url: '/home/newuser'});
// 订单确认页默认埋点
yas.givePoint('YB_SC_ORDER_ENSURE');
... ...
... ... @@ -818,6 +818,44 @@
}
}
.ticket-wrapper {
border-bottom-color: #e8e8e8;
border-top-color: #fff;
}
.ticket-selection {
font-size: 15px;
line-height: 1.5;
.title {
line-height: 40px;
font-size: 16px;
padding-left: 25px;
font-weight: bold;
margin-top: 10px;
}
.modity-pay-info {
li {
padding-left: 30px;
margin-bottom: 15px;
.ticket-mobile-input {
width: 208px;
border: 1px solid #b0b0b0;
padding: 5px;
margin-right: 10px;
font-size: 14px;
}
.ticket-mobile-tip {
color: #da0045;
margin-left: 15px;
}
}
}
}
.use-coupons {
.tip-box {
width: 60%;
... ...