Authored by 毕凯

Merge branch 'feature/ordersub' into 'release/6.0.2'

下单跳出问题优化



See merge request !864
... ... @@ -53,6 +53,14 @@ exports.orderEnsure = (req, res, next) => {
}
let orderPromise;
let params = {
uid: uid,
cartType: cartType,
orderInfo: orderInfo,
sku: sku,
skn: skn,
buyNumber: buyNumber,
};
if (req.query.cartType === 'bundle') {
if (!req.cookies._cartType) {
... ... @@ -60,9 +68,11 @@ exports.orderEnsure = (req, res, next) => {
}
let activityInfo = JSON.parse(req.cookies['activity-info']);
orderPromise = cartModel.cartPay(uid, cartType, orderInfo, null, sku, skn, buyNumber, activityInfo);
orderPromise = cartModel.cartPay(_.assign(params, {
activityInfo: activityInfo
}));
} else {
orderPromise = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber);
orderPromise = cartModel.cartPay(params);
}
let allPromise = [
... ... @@ -155,13 +165,27 @@ exports.orderCompute = (req, res, next) => {
if (req.body.cartType === 'bundle') {
let activityInfo = JSON.parse(req.cookies['activity-info']);
cartModel.orderCompute(uid, cartType, deliveryId, paymentType,
couponCode, yohoCoin, null, activityInfo).then(result => {
cartModel.orderCompute({
uid: uid,
cartType: cartType,
deliveryWay: deliveryId,
paymentType: paymentType,
couponCode: couponCode,
yohoCoin: yohoCoin,
activityInfo: activityInfo
}).then(result => {
res.json(result);
}).catch(next);
} else {
cartModel.orderCompute(uid, cartType, deliveryId, paymentType,
couponCode, yohoCoin, skuList).then(result => {
cartModel.orderCompute({
uid: uid,
cartType: cartType,
deliveryWay: deliveryId,
paymentType: paymentType,
couponCode: couponCode,
yohoCoin: yohoCoin,
skuList: skuList
}).then(result => {
res.json(result);
}).catch(next);
}
... ... @@ -233,11 +257,19 @@ exports.orderSub = (req, res, next) => {
return co(function* () {
let result;
// 接口需要的其他参数
let otherParams = {
isPrintPrice: isPrintPrice,
unionKey: unionInfo.unionKey, // 友盟数据
let params = {
uid: uid,
address_id: addressId,
delivery_time: deliveryTimeId,
delivery_way: deliveryId,
invoices: invoices,
payment_id: paymentTypeId,
payment_type: paymentType,
remark: msg,
coupon_code: couponCode,
use_yoho_coin: yohoCoin,
is_print_price: isPrintPrice,
qhy_union: unionInfo.unionKey, // 友盟数据
userAgent: unionInfo.userAgent,
isWechat: req.yoho.isWechat,
ip: req.yoho.clientIp,
... ... @@ -248,13 +280,16 @@ exports.orderSub = (req, res, next) => {
if (req.body.cartType === 'bundle') {
let activityInfo = JSON.parse(req.cookies['activity-info']);
result = yield cartModel.orderSub(uid, addressId, 'bundle', deliveryTimeId,
deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
yohoCoin, null, times, activityInfo, otherParams);
result = yield cartModel.orderSub(_.assign(params, {
cart_type: 'bundle',
times: times,
activityInfo: activityInfo
}));
} else {
result = yield cartModel.orderSub(uid, addressId, cartType, deliveryTimeId,
deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
yohoCoin, skuList, null, null, otherParams);
result = yield cartModel.orderSub(_.assign(params, {
cart_type: cartType,
product_sku_list: skuList
}));
}
// 提交成功清除Cookie
... ...
... ... @@ -22,50 +22,59 @@ const payModel = require('../models/pay');
* @param bool $isAjax 是否是异步请求
* @return array 接口返回的数据
*/
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, activityInfo) => {
exports.cartPay = (params) => {
let result = {};
let skuList = [];
let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品
let isLimitGoods = params.skn && params.sku && params.buyNumber; // 存在sku, skn 和buyNumber时为限购商品
let orderComputeAPI = null;
if (isLimitGoods) {
skuList.push({
type: 'limitcode',
limitproductcode: limitProductCode,
buy_number: buyNumber,
skn,
sku
limitproductcode: params.limitProductCode,
buy_number: params.buyNumber,
skn: params.skn,
sku: params.sku
});
result.isLimit = true;
}
// cookie保存的数据
if (orderInfo && !_.isEmpty(orderInfo)) {
orderInfo.paymentType = orderInfo.paymentType ? orderInfo.paymentType : '';
orderComputeAPI = shoppingAPI.orderComputeAPI(
uid,
cartType,
orderInfo.deliveryId,
orderInfo.paymentType,
orderInfo.couponCode,
orderInfo.yohoCoin, skuList, activityInfo
);
if (params.orderInfo && !_.isEmpty(params.orderInfo)) {
params.orderInfo.paymentType = params.orderInfo.paymentType ? params.orderInfo.paymentType : '';
orderComputeAPI = shoppingAPI.orderComputeAPI({
uid: params.uid,
cart_type: params.cartType,
delivery_way: params.orderInfo.deliveryId,
payment_type: params.orderInfo.paymentType,
coupon_code: params.orderInfo.couponCode,
use_yoho_coin: params.orderInfo.yohoCoin,
product_sku_list: skuList,
activityInfo: params.activityInfo
});
}
// 区分套餐量贩和普通商品
let cartPayAPI;
let cartPayAPIParams = {
uid: params.uid,
cart_type: params.cartType,
product_sku_list: skuList
};
if (activityInfo) {
cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList, activityInfo);
if (params.activityInfo) {
cartPayAPI = shoppingAPI.cartPayAPI(_.assign(cartPayAPIParams, {
activityInfo: params.activityInfo
}));
} else {
cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList);
cartPayAPI = shoppingAPI.cartPayAPI(cartPayAPIParams);
}
return Promise.all([
cartPayAPI, // 0. 订单数据
orderComputeAPI,
shoppingAPI.getValidCouponCount(uid) // 2. 有效优惠券
shoppingAPI.getValidCouponCount(params.uid) // 2. 有效优惠券
]).then(res => {
let pay = res[0];
let orderCompute = _.get(res[1], 'data', {});
... ... @@ -87,10 +96,10 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
result = Object.assign(
result,
paymentProcess.tranformPayment(pay.data, orderInfo, cartType, skuList, orderCompute),
paymentProcess.tranformPayment(pay.data, params.orderInfo, params.cartType, skuList, orderCompute),
{
coupon: paymentProcess.coupon(validCouponCount, orderInfo, orderCompute)
coupon: paymentProcess.coupon(validCouponCount, params.orderInfo, orderCompute)
}
);
... ... @@ -110,9 +119,17 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
exports.orderCompute = (uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList, activityInfo) => {
return shoppingAPI.orderComputeAPI(uid, cartType, deliveryWay, paymentType,
couponCode, yohoCoin, skuList, activityInfo).then(result => {
exports.orderCompute = (params) => {
return shoppingAPI.orderComputeAPI({
uid: params.uid,
cart_type: params.cartType,
delivery_way: params.deliveryWay,
payment_type: params.paymentType,
coupon_code: params.couponCode,
use_yoho_coin: params.yohoCoin,
product_sku_list: params.skuList,
activityInfo: params.activityInfo
}).then(result => {
if (result && result.data) {
result.data.use_yoho_coin = paymentProcess.transPrice(result.data.use_yoho_coin);
result.data.yohoCoinCompute = paymentProcess.yohoCoinCompute(result.data);
... ... @@ -162,40 +179,36 @@ exports.ticketsOrderCompute = (uid, productSku, buyNumber, yohoCoin) => {
* @param otherParams 其他参数
* @return array 接口返回的数据
*/
exports.orderSub = (uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType, remark,
couponCode, yohoCoin, skuList, times, activityInfo, otherParams) => {
if (!otherParams.unionKey) {
otherParams.unionKey = '';
exports.orderSub = (params) => {
if (!params.qhy_union) {
params.qhy_union = '';
}
if (!otherParams.userAgent) {
otherParams.userAgent = null;
if (!params.userAgent) {
params.userAgent = null;
}
if (!times) {
times = 1;
if (!params.times) {
params.times = 1;
}
if (!activityInfo) {
activityInfo = null;
if (!params.activityInfo) {
params.activityInfo = null;
}
if (!addressId) {
if (!params.address_id) {
return Promise.resolve({code: 401, message: '配送地址不能为空'});
}
if (!deliveryTime) {
if (!params.delivery_time) {
return Promise.resolve({code: 402, message: '请选择配送时间'});
}
if (!deliveryWay) {
if (!params.delivery_way) {
return Promise.resolve({code: 403, message: '请选择配送方式'});
}
return shoppingAPI.orderSub(uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType,
remark, couponCode, yohoCoin, skuList, times, activityInfo, otherParams).then(orderSubRes => {
return shoppingAPI.orderSub(params).then(orderSubRes => {
let finalResult = {};
if (orderSubRes && orderSubRes.data && orderSubRes.data.is_hint === 'Y') {
... ... @@ -330,24 +343,23 @@ exports.jitDetailData = (uid, cartType, skuList, orderCode, sessionKey,
if (deliveryId) {
// 购物车选择改变字段,重新运算订单数据
return shoppingAPI.orderComputeAPI(
uid,
cartType,
deliveryId,
paymentType,
couponCode,
yohoCoin,
skuList
).then(result => {
return shoppingAPI.orderComputeAPI({
uid: uid,
cart_type: cartType,
delivery_way: deliveryId,
payment_type: paymentType,
coupon_code: couponCode,
use_yoho_coin: yohoCoin,
product_sku_list: skuList
}).then(result => {
return paymentProcess.transformJit(_.get(result, 'data.package_list', []));
});
} else {
return shoppingAPI.cartPayAPI(
uid,
cartType,
0,
skuList
).then(result => {
return shoppingAPI.cartPayAPI({
uid: uid,
cart_type: cartType,
product_sku_list: skuList
}).then(result => {
return paymentProcess.transformJit(_.get(result, 'data.shopping_cart_data.package_list', []));
});
}
... ...
... ... @@ -11,28 +11,28 @@ const api = global.yoho.API;
* @param string $skuList 购买限购商品时需要传递的参数
* @return see doc
*/
exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => {
if (!activityInfo) {
activityInfo = null;
exports.cartPayAPI = (params) => {
if (!params.activityInfo) {
params.activityInfo = null;
}
let param = {
method: activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
method: params.activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
enable_red_envelopes: 0, // h5不返回红包
cart_type: cartType,
yoho_coin_mode: isUseYohoCoin,
uid: uid
cart_type: params.cart_type,
yoho_coin_mode: params.yoho_coin_mode,
uid: params.uid
};
// 购买限购商品时需要传递product_sku_list参数
if (!_.isEmpty(skuList)) {
param.product_sku_list = JSON.stringify(skuList);
if (!_.isEmpty(params.product_sku_list)) {
param.product_sku_list = JSON.stringify(params.product_sku_list);
}
// 购买套装和量贩商品时数据处理
if (activityInfo) {
param.activity_id = activityInfo.activity_id;
param.product_sku_list = JSON.stringify(activityInfo.product_sku_list);
if (params.activityInfo) {
param.activity_id = params.activityInfo.activity_id;
param.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
}
return api.get('', param, {cache: false});
... ... @@ -56,38 +56,34 @@ exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => {
* 2. 除非同时调用app.Shopping.payment 与该接口,用改接口的data值替换app.Shopping.payment相关值,
* 显示调用utils/payment-process.js@tranformPayment(他会帮你调yohoCoinCompute)处理payment的data;
*/
exports.orderComputeAPI = (uid, cartType, deliveWay, paymentType, couponCode, yohoCoin, skuList, activityInfo) => {
if (!activityInfo) {
activityInfo = null;
}
let param = {
method: activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute',
cart_type: cartType,
delivery_way: deliveWay,
payment_type: paymentType,
uid: uid
exports.orderComputeAPI = (params) => {
let finalParams = {
method: params.activityInfo ? 'app.Shopping.easyCompute' : 'app.Shopping.compute',
cart_type: params.cart_type,
delivery_way: params.delivery_way,
payment_type: params.payment_type,
uid: params.uid
};
if (couponCode) {
param.coupon_code = couponCode;
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
if (yohoCoin) {
param.use_yoho_coin = yohoCoin;
if (params.use_yoho_coin) {
finalParams.use_yoho_coin = params.use_yoho_coin;
}
if (!_.isEmpty(skuList) && !activityInfo) {
param.product_sku_list = JSON.stringify(skuList);
if (!_.isEmpty(params.product_sku_list) && !params.activityInfo) {
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
}
// 购买套餐商品需要的数据
if (activityInfo) {
param.activity_id = activityInfo.activity_id;
param.product_sku_list = JSON.stringify(activityInfo.product_sku_list);
if (params.activityInfo) {
finalParams.activity_id = params.activityInfo.activity_id;
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list);
}
return api.get('', param, {code: 200});
return api.get('', finalParams, {code: 200});
};
/**
... ... @@ -147,97 +143,91 @@ exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) =
* @param @param otherParams 其他参数
* @return array 接口返回的数据
*/
exports.orderSub = (uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType, remark, couponCode,
yohoCoin, skuList, times, activityInfo, otherParams) => {
if (!activityInfo) {
activityInfo = null;
}
let params = {
method: activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
address_id: addressId,
cart_type: cartType,
delivery_time: deliveryTime,
delivery_way: deliveryWay,
payment_id: paymentId,
payment_type: paymentType,
remark: remark,
uid: uid,
udid: otherParams.udid,
is_print_price: otherParams.isPrintPrice
exports.orderSub = (params) => {
let finalParams = {
method: params.activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
address_id: params.address_id,
cart_type: params.cart_type,
delivery_time: params.delivery_time,
delivery_way: params.delivery_way,
payment_id: params.payment_id,
payment_type: params.payment_type,
remark: params.remark,
uid: params.uid,
udid: params.udid,
is_print_price: params.is_print_price
};
/* tar add 161130 结算优化 */
if (times === 2 || times === '2') {
params.is_continue_buy = 'Y';
if (params.times === 2 || params.times === '2') {
finalParams.is_continue_buy = 'Y';
} else {
params.is_continue_buy = 'N';
finalParams.is_continue_buy = 'N';
}
// 发票内容写死明细
if (invoices.invoices_type_id) {
params.invoice_content = 12;
if (params.invoices.invoices_type_id) {
finalParams.invoice_content = 12;
}
// 发票类型 纸质 1 ,电子 2
if (invoices.invoices_type) {
params.invoices_type = invoices.invoices_type;
if (params.invoices.invoices_type) {
finalParams.invoices_type = params.invoices.invoices_type;
}
// 发票类型:个人 1, 企业 2
if (invoices.invoice_payable_type) {
params.invoice_payable_type = invoices.invoice_payable_type;
if (params.invoices.invoice_payable_type) {
finalParams.invoice_payable_type = params.invoices.invoice_payable_type;
}
// 收票人手机号码
if (invoices.receiverMobile) {
params.receiverMobile = invoices.receiverMobile;
if (params.invoices.receiverMobile) {
finalParams.receiverMobile = params.invoices.receiverMobile;
}
// 发票抬头
if (invoices.invoices_title) {
params.invoices_title = invoices.invoices_title;
if (params.invoices.invoices_title) {
finalParams.invoices_title = params.invoices.invoices_title;
}
// 购买方纳税人识别号,需要开具电子发票且发票抬头为单位信息时为必填项
if (invoices.buyerTaxNumber) {
params.buyerTaxNumber = invoices.buyerTaxNumber;
if (params.invoices.buyerTaxNumber) {
finalParams.buyerTaxNumber = params.invoices.buyerTaxNumber;
}
if (couponCode) {
params.coupon_code = couponCode;
if (params.coupon_code) {
finalParams.coupon_code = params.coupon_code;
}
if (yohoCoin) {
params.use_yoho_coin = yohoCoin;
if (params.use_yoho_coin) {
finalParams.use_yoho_coin = params.use_yoho_coin;
}
// 购买限购商品时需要传递product_sku_list参数
if (skuList && !activityInfo) {
params.product_sku_list = JSON.stringify(skuList);
if (params.product_sku_list && !params.activityInfo) {
finalParams.product_sku_list = JSON.stringify(params.product_sku_list);
}
// 购买套餐商品需要的数据
if (activityInfo) {
params.activity_id = activityInfo.activity_id;
params.product_sku_list = JSON.stringify(activityInfo.product_sku_list); // TODO 检查 JSON 是否正常
if (params.activityInfo) {
finalParams.activity_id = params.activityInfo.activity_id;
finalParams.product_sku_list = JSON.stringify(params.activityInfo.product_sku_list); // TODO 检查 JSON 是否正常
}
// 友盟有关信息的传递
if (otherParams.unionKey) {
params.qhy_union = otherParams.unionKey;
if (params.qhy_union) {
finalParams.qhy_union = params.qhy_union;
}
// 是否是微信商城
if (otherParams.isWechat) {
params.client_type = 'wechat';
if (params.isWechat) {
finalParams.client_type = 'wechat';
}
return api.post('', params, {
return api.post('', finalParams, {
headers: {
'X-Forwarded-For': otherParams.ip || '',
'User-Agent': otherParams.userAgent
'X-Forwarded-For': params.ip || '',
'User-Agent': params.userAgent
}
});
};
... ...
... ... @@ -34,6 +34,12 @@
<span {{#if isSupportMessage}}data-message="{{isSupportMessage}}"{{/if}}>{{name}}</span>
<i class="right iconfont {{#if recommend}}icon-cb-radio{{else}}icon-radio{{/if}}" data-id="{{id}}" data-payment-type="{{paymentType}}"></i>
</li>
{{^}}
<li class="no-support">
<span class="tip" title="{{isSupportMessage}}" data-message="{{isSupportMessage}}">{{name}}({{isSupportMessage}}</span>
<span>)</span>
<i class="right iconfont icon-radio"></i>
</li>
{{/if}}
{{/each}}
</ul>
... ...
... ... @@ -11,8 +11,8 @@ const isProduction = process.env.NODE_ENV === 'production';
const isTest = process.env.NODE_ENV === 'test';
const domains = {
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
global: 'http://global-test-soa.yohops.com:9999',
liveApi: 'http://testapi.live.yohops.com:9999/',
... ...
... ... @@ -8,6 +8,7 @@ const $ = require('yoho-jquery');
const lazyLoad = require('yoho-jquery-lazyload');
const cookie = require('yoho-cookie');
const qs = require('yoho-qs');
const OrderEnsure = require('./cartbuynow/order-ensure');
let tip = require('plugin/tip'),
loading = require('plugin/loading'),
... ... @@ -27,9 +28,6 @@ let $invoice = $('.invoice'),
isSubmiting,
dispatchInfo,
total,
isTickets = $('#ticketsPage').val(),
productSku = $('#productSku').val(),
buyNumber = $('#buyNumber').val(),
headerTop = $('#yoho-header').outerHeight(),
isYohoCoinClick = $coinLi.data('yoho-coin-click') * 1, // 判断有货币是否可以单击
addressTop = $('.address-wrap').outerHeight(),
... ... @@ -37,8 +35,7 @@ let $invoice = $('.invoice'),
delivery = 0,
$noPrintPrice = $('.no-print-price');
let $invoiceType = $('.invoice-type');
let $userMobile = $('.user-mobile');
new OrderEnsure(order);
require('common');
... ... @@ -47,78 +44,6 @@ lazyLoad();
// 存 COOKIE
orderInfo('product_sku', qs.product_sku);
function getQueryParam() {
let queryArray = location.search.substr(1).split('&'),
i,
subArr = [],
obj = {};
for (i = 0; i < queryArray.length; i++) {
subArr = queryArray[i].split('=');
obj[subArr[0]] = subArr[1];
subArr = [];
}
return obj;
}
function isLimitGood() {
return getQueryParam().limitproductcode;
}
// 电子票下单
function _ticketsConfirm() {
let data = {
productSku: productSku,
buyNumber: buyNumber,
mobile: $ticketsMobile.val(),
useYohoCoin: orderInfo('use_yoho_coin')
};
if (!$ticketsMobile.val()) {
tip.show('手机号必填');
return;
}
$.ajax({
url: '/cart/index/submitTicket',
type: 'POST',
dataType: 'json',
data: data,
success: function(ticket) {
// 下单成功调整支付页面
if (ticket.code === 200) {
window.location.href = '/home/orders/paynew?order_code=' + ticket.data.order_code;
} else {
tip.show(ticket.message);
}
},
error: function() {
tip.show('网络异常~');
}
});
}
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
}
isLimitGood() && (function() {
let a = [];
let data = getQueryParam();
data.type = 'limitcode';
a.push(data);
orderInfo('skuList', JSON.stringify(a));
orderInfo('limitUrlSufix', location.search);
}());
if (queryString.cartType || queryString.carttype || !orderInfo('cartType')) {
orderInfo('cartType', queryString.cartType || queryString.carttype || 'ordinary');
}
... ... @@ -140,32 +65,6 @@ $('.checkbox').on('touchstart', function(e) {
}
});
/**
* 是否需要开发票
*/
$invoice.on('touchend', '.checkbox', function(e) {
let $this = $(this);
orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
$invoice.addClass('focus');
$invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
orderInfo('receiverMobile', $userMobile.val());
orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
$invoice.removeClass('focus');
$invoiceType.html('');
orderInfo('invoices_title', null);
orderInfo('invoices_type', null);
orderInfo('receiverMobile', null);
orderInfo('buyerTaxNumber', null);
}
e.preventDefault();
e.stopPropagation();
});
function updateDeliverWay(deliver_way) {
let $moreJit = $('.more-jit a').get(0),
url;
... ... @@ -193,8 +92,7 @@ function orderCompute() {
delivery_way: orderInfo('delivery_way'),
payment_type: orderInfo('payment_type'),
coupon_code: orderInfo('coupon_code'),
use_yoho_coin: use_yoho_coin,
skuList: isLimitGood() ? orderInfo('skuList') : void 0
use_yoho_coin: use_yoho_coin
};
loading.showLoadingMask();
... ... @@ -500,11 +398,6 @@ $subBlock.on('touchstart', 'li', function() {
$('.bill a').on('touchstart', function() {
let $paymentType;
if (isTickets) {
_ticketsConfirm();
return;
}
$paymentType = $('.payment-type .icon-cb-radio');
orderInfo('payment_id', $paymentType.data('id')); // 支付方式id
orderInfo('payment_type', $paymentType.data('payment-type')); // 支付方式
... ...
// import qs from 'yoho-qs';
class OrderEnsure {
constructor(order) { // 参数为使用哪个 cookie
this.order = order;
this.orderInfo = order.orderInfo;
this.selector = {
invoice: $('.invoice'),
invoiceType: $('.invoice-type'),
userMobile: $('.user-mobile')
};
this.init();
this.bindEvents();
}
init() {
if (window.getUid() !== this.orderInfo('uid')) {
this.order.init();
window.location.reload();
}
}
bindEvents() {
this.selector.invoice.on('click', '.checkbox', this.needInvoice.bind(this));
}
/**
* 是否需要开发票
*/
needInvoice(event) {
let $this = $(event.currentTarget);
this.orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
this.selector.invoice.addClass('focus');
this.selector.invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
this.orderInfo('receiverMobile', this.selector.userMobile.val());
this.orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
this.selector.invoice.removeClass('focus');
this.selector.invoiceType.html('');
this.orderInfo('invoices_title', null);
this.orderInfo('invoices_type', null);
this.orderInfo('receiverMobile', null);
this.orderInfo('buyerTaxNumber', null);
}
event.preventDefault();
event.stopPropagation();
}
}
module.exports = OrderEnsure;
... ...
... ... @@ -4,9 +4,11 @@
* @date: 2015/11/12
*/
require('cart/order-ensure.page.css');
let $ = require('yoho-jquery'),
lazyLoad = require('yoho-jquery-lazyload'),
cookie = require('yoho-cookie');
const $ = require('yoho-jquery');
const lazyLoad = require('yoho-jquery-lazyload');
const cookie = require('yoho-cookie');
const qs = require('yoho-qs');
const OrderEnsure = require('./cartbuynow/order-ensure');
let tip = require('plugin/tip'),
loading = require('plugin/loading'),
... ... @@ -33,39 +35,16 @@ let $invoice = $('.invoice'),
isYohoCoinClick = $coinLi.data('yoho-coin-click') * 1, // 判断有货币是否可以单击
addressTop = $('.address-wrap').outerHeight(),
$message = $('#msg'),
delivery = 0,
$noPrintPrice = $('.no-print-price');
let $invoiceType = $('.invoice-type');
let $userMobile = $('.user-mobile');
new OrderEnsure(order);
require('common');
lazyLoad();
function getQueryParam() {
let queryArray = location.search.substr(1).split('&'),
i,
subArr = [],
obj = {};
for (i = 0; i < queryArray.length; i++) {
subArr = queryArray[i].split('=');
obj[subArr[0]] = subArr[1];
subArr = [];
}
return obj;
}
function isLimitGood() {
return getQueryParam().limitproductcode;
}
if (window.getUid() !== orderInfo('uid')) {
order.init();
window.location.reload();
return qs.limitproductcode;
}
// 来自购物车的链接默认不使用优惠券
... ... @@ -78,7 +57,7 @@ if (document.referrer && document.referrer.indexOf('/cart/index/index') !== -1)
isLimitGood() && (function() {
let a = [];
let data = getQueryParam();
let data = qs;
data.type = 'limitcode';
... ... @@ -108,31 +87,6 @@ $('.checkbox').on('touchstart', function(e) {
}
});
/**
* 是否需要开发票
*/
$invoice.on('touchend', '.checkbox', function(e) {
let $this = $(this);
orderInfo('invoice', $this.hasClass('icon-cb-radio'));
if ($this.hasClass('icon-cb-radio')) {
$invoice.addClass('focus');
$invoiceType.html('电子发票(个人)<i class="iconfont">&#xe614;</i>');
orderInfo('receiverMobile', $userMobile.val());
orderInfo('invoices_type', 2);
}
if ($this.hasClass('icon-radio')) {
$invoice.removeClass('focus');
$invoiceType.html('');
orderInfo('invoices_title', null);
orderInfo('invoices_type', null);
orderInfo('receiverMobile', null);
orderInfo('buyerTaxNumber', null);
}
e.preventDefault();
e.stopPropagation();
});
function updateDeliverId(id) {
let $moreJit = $('.more-jit a').get(0),
url;
... ... @@ -307,6 +261,13 @@ function submitOrder() {
window.location.href = url;
} else if (res.code === 409) {
richTip.show(res.message, res.buttons);
} else if (res.code === 440) {
dialog.show({
dialogText: res.message,
hasFooter: {
centerBtnText: '我知道了'
}
});
} else if (res.message) {
tip.show(res.message);
}
... ... @@ -436,26 +397,21 @@ $subBlock.on('touchstart', 'li', function() {
}
if ($(this).hasClass('no-support')) {
return false;
}
$.each($(this).parents('ul').find('i'), function() {
$(this).parents('ul').find('i').removeClass('icon-cb-radio').addClass('icon-radio');
});
let self = $(this);
if (self.find('span').data('message') && delivery === 0) {
dialog.showDialog({
hasHeader: '温馨提示',
dialogText: self.find('span').data('message'),
dialogText: $(this).find('span').data('message'),
hasFooter: {
centerBtnText: '我知道了'
}
});
delivery = 1;
return false;
}
$.each($(this).parents('ul').find('i'), function() {
$(this).parents('ul').find('i').removeClass('icon-cb-radio').addClass('icon-radio');
});
let self = $(this);
setTimeout(function() {
self.parents('ul').hide();
}, 300);
... ...
... ... @@ -222,6 +222,18 @@
.no-support {
color: #b0b0b0;
}
.no-support > span {
display: block;
float: left;
}
.no-support > .tip {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 600px;
}
}
}
}
... ...
... ... @@ -220,18 +220,17 @@ function tranformPayment(data, orderInfo, cartType, skuList, orderComputeData) {
if (data.payment_way) {
let payway = data.payment_way;
payway = payway.filter(obj => obj.is_support === 'Y')
.map(way => {
let obj = {};
obj.id = way.payment_id;
obj.paymentType = way.payment_type;
obj.name = way.payment_type_name;
obj.isSupport = way.is_support === 'Y';
obj.isSupportMessage = way.payment_type === 2 ? _.get(way, 'is_support_message', false) : false;
return obj;
});
payway = payway.map(way => {
let obj = {};
obj.id = way.payment_id;
obj.paymentType = way.payment_type;
obj.name = way.payment_type_name;
obj.isSupport = way.is_support === 'Y';
obj.isSupportMessage = way.payment_type === 2 ? _.get(way, 'is_support_message', false) : false;
return obj;
});
payway.some(way => {
let bool = way.paymentType === orderInfo.paymentType;
... ...