Authored by 陈峰

Merge branch 'feature/cart' into 'release/5.4.1'

Feature/cart



See merge request !214
... ... @@ -7,7 +7,7 @@ const headerModel = require('../../../doraemon/models/header');
const userModel = require('../../serverAPI/user');
const addressModel = require('../../serverAPI/user/address');
const orderModel = require('../models/order');
const crypt = global.yoho.crypt;
exports.orderEnsure = (req, res, next) => {
let headerData = headerModel.setNav({
... ... @@ -42,14 +42,20 @@ exports.orderEnsure = (req, res, next) => {
headerData.backUrl = req.get('Referer') || returnUrl;
}
let order = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, req.xhr);
let userProfile = userModel.queryProfile(uid);
let address = addressModel.addressData(uid);
let orderPromise = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber);
let userProfilePromise = userModel.queryProfile(uid);
let addressPromise = addressModel.addressData(uid);
if (req.query.activityType === 'bundle') {
let activityInfo = JSON.parse(req.cookies['activity-info']);
orderPromise = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, activityInfo);
}
return Promise.all([order, userProfile, address]).then(result => {
order = result[0];
userProfile = result[1];
address = result[2];
return Promise.all([orderPromise, userProfilePromise, addressPromise]).then(result => {
let order = result[0];
let userProfile = result[1];
let address = result[2];
if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX?
return res.redirect(order.cartUrl);
... ... @@ -74,21 +80,146 @@ exports.orderEnsure = (req, res, next) => {
orderEnsurePage: true,
isOrdinaryCart: cartType !== 'advance',
orderEnsure: order,
userMobile: mobile
userMobile: mobile,
pageHeader: headerData,
pageFooter: true,
module: 'cart',
page: 'order-ensure',
width750: true,
title: '确认订单',
};
viewData.pageHeader = headerData;
viewData.pageFooter = true;
viewData.module = 'cart';
viewData.page = 'order-ensure';
viewData.width750 = true;
viewData.title = '确认订单';
res.render('order-ensure', viewData);
}).catch(next);
};
/**
* 购物车选择改变字段,重新运算订单数据
*/
exports.orderCompute = (req, res, next) => {
let cartType = req.body.cartType || 'ordinary';
let deliveryId = req.body.deliveryId || 1;
let paymentTypeId = req.body.paymentTypeId || 1;
let couponCode = req.body.couponCode || null;
let yohoCoin = req.body.yohoCoin || null;
let productSku = req.body.productSku || null;
let buyNumber = req.body.buyNumber || null;
let uid = req.user.uid;
let skuList = req.body.skuList;
let type = req.body.type;
if (type !== 'tickets') {
cartModel.orderCompute(uid, cartType, deliveryId, paymentTypeId, couponCode, yohoCoin, skuList).then(result => {
res.json(result);
}).catch(next);
} else {
cartModel.ticketsOrderCompute(uid, productSku, buyNumber, yohoCoin).then(result => {
res.json(result);
}).catch(next);
}
};
/**
* 确认结算订单
*/
exports.orderSub = (req, res) => {
let uid = req.user.uid;
let addressId = crypt.decrypt('', req.body.addressId);
let cartType = req.body.cartType || 'ordinary';
let deliveryTimeId = req.body.deliveryTimeId || 1;
let deliveryId = req.body.deliveryId || 1;
let paymentTypeId = req.body.paymentTypeId || 15;
let paymentType = req.body.paymentType || 1;
let msg = req.body.msg || null;
let couponCode = req.body.couponCode || null;
let yohoCoin = req.body.yohoCoin || 1;
let skuList = req.body.skuList || '';
let orderInfo;
try {
orderInfo = JSON.parse(req.cookies['order-info']);
} catch (e) {
orderInfo = {};
}
let times = req.body.times || 1;
// 电子发票信息数组
let invoices = {};
if (orderInfo) {
invoices = {
invoices_type_id: orderInfo.invoiceType,
invoices_type: orderInfo.invoicesType,
receiverMobile: orderInfo.receiverMobile,
invoices_title: orderInfo.invoiceText ? orderInfo.invoiceText : '个人'
};
}
/* 判断是否是友盟过来的用户 */
let userAgent = null;
let unionKey = '';
let unionInfo = {};
if (req.cookies.mkt_code || req.cookies._QYH_UNION) {
/* tar modified 161108 添加新的联盟数据处理逻辑,兼容原有联盟数据处理,
区别是旧的北京写 cookie 加密过来,新的 node 写 cookie,没有加密 */
if (req.cookies._QYH_UNION) {
let encryData = decodeURI(req.cookies._QYH_UNION);
let testQyhUnion = JSON.parse(encryData);
if (testQyhUnion.client_id) {
unionKey = encryData;
} else {
// unionKey = helpers.unionDecode(req.cookies._QYH_UNION, 'q_union_yohobuy'); // TODO 这个方法没有
}
} else {
unionKey = '{"client_id":' + req.cookies.mkt_code + '}';
}
/* 检查联盟参数是否有效 */
unionInfo = unionKey ? JSON.parse(unionKey) : {};
/* 模拟APP的User-Agent */
userAgent = unionInfo.client_id ? 'YOHO!Buy/3.8.2.259(Model/PC;Channel/' +
unionInfo.client_id + ';uid/' + uid + ')' : null;
}
return co(function* () {
let result;
/* tar modified 161206 套餐 */
if (req.body.activityType === '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, unionKey, userAgent, times, activityInfo);
} else {
result = yield cartModel.orderSub(uid, addressId, cartType, deliveryTimeId,
deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
yohoCoin, skuList, unionKey, userAgent);
}
if (unionInfo) {
result.data.unionCookie = unionInfo;
}
// 提交成功清除Cookie
res.cookie('order-info', null, {
domain: 'yohobuy.com'
});
if (result.code === 409) {
return res.json(decodeURI(result));
} else {
return res.json(result);
}
})();
};
/**
* 下单流程 选择优惠券
*/
exports.selectCoupon = (req, res) => {
... ... @@ -164,7 +295,7 @@ exports.selectAddress = (req, res, next) => {
req.session.addressMore = moreUrl; // TODO: 注意cookie-session
}
moreUrl = req.session.addressMore;
// moreUrl = req.session.addressMore;
let headerData = headerModel.setNav({
navTitle: '选择地址',
... ...
... ... @@ -6,6 +6,57 @@ const paymentProcess = require(global.utils + '/payment-process');
const shoppingAPI = require('../../serverAPI/order/shopping');
/**
* 转换价格
*
* @param float|string $price 价格
* @param boolean $isSepcialZero 是否需要特殊的0,默认否
* @return float|string 转换之后的价格
*/
const transPrice = (price, isSepcialZero) => {
if (!isSepcialZero) {
isSepcialZero = false;
}
return price;
};
/**
*有货币使用前端方案显示及是否可单击判断
*/
const _yohoCoinCompute = (orderCompute) => {
let yohoCoinData = {
totalYohoCoinNum: 0,
yohoCoin: 0,
useYohoCoin: 0,
yohoCoinClick: 0,
yohoCoinMsg: '',
yoho_coin_pay_rule: []
};
if (!orderCompute || !orderCompute.yoho_coin_pay_rule) {
return yohoCoinData;
}
_.assign(yohoCoinData, {
totalYohoCoinNum: orderCompute.total_yoho_coin_num ? parseInt(orderCompute.total_yoho_coin_num, 10) : 0,
yohoCoin: orderCompute.yoho_coin ? transPrice(orderCompute.yoho_coin) : 0,
useYohoCoin: orderCompute.use_yoho_coin ? transPrice(orderCompute.use_yoho_coin) : 0,
yoho_coin_pay_rule: orderCompute.yoho_coin_pay_rule
});
if (yohoCoinData.totalYohoCoinNum < 100) {
yohoCoinData.yohoCoinMsg = `共${yohoCoinData.totalYohoCoinNum}有货币,满${orderCompute.yoho_coin_pay_rule.num_limit}可用`;
} else if (yohoCoinData.useYohoCoin > 0 || yohoCoinData.yohoCoin > 0) {
yohoCoinData.yohoCoinMsg = '可抵¥' + (yohoCoinData.useYohoCoin > 0 ? yohoCoinData.useYohoCoin : yohoCoinData.yohoCoin);
yohoCoinData.yohoCoinClick = 1;
} else {
yohoCoinData.yohoCoinMsg = '不满足有货币使用条件';
}
return yohoCoinData;
};
/**
* 调用购物车结算接口返回的数据处理
*
*
... ... @@ -20,9 +71,7 @@ const shoppingAPI = require('../../serverAPI/order/shopping');
* @param bool $isAjax 是否是异步请求
* @return array 接口返回的数据
*/
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, isAjax) => {
isAjax = isAjax || false;
exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, activityInfo) => {
let result = {};
let skuList = [];
let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品
... ... @@ -53,8 +102,15 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
);
}
// 区分套餐量贩和普通商品
let cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList);
if (activityInfo) {
cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList, activityInfo);
}
return Promise.all([
shoppingAPI.cartPayAPI(uid, cartType, 0, skuList), // 0. 订单数据
cartPayAPI, // 0. 订单数据
orderComputeAPI,
shoppingAPI.getValidCouponCount(uid) // 2. 有效优惠券
]).then(res => {
... ... @@ -89,6 +145,143 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
};
/**
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
*
* @param int $uid 用户ID
* @param string $cartType 购物车类型,ordinary表示普通购物车
* @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
* @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的有货币数量
* @param string $skuList 购买限购商品时需要传递的参数
* @return array 接口返回的数据
*/
exports.orderCompute = (uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList) => {
return shoppingAPI.orderComputeAPI(uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList).then(result => {
if (result && result.data) {
result.data.use_yoho_coin = transPrice(result.data.use_yoho_coin);
result.data.yohoCoinCompute = _yohoCoinCompute(result.data);
return result.data;
} else {
return {};
}
});
};
exports.ticketsOrderCompute = (uid, productSku, buyNumber, yohoCoin) => {
return shoppingAPI.checkTickets(uid, productSku, buyNumber, yohoCoin).then(result => {
if (result && result.data) {
result.data.shopping_cart_data.use_yoho_coin = transPrice(result.data.shopping_cart_data.use_yoho_coin);
result.data.yohoCoinCompute = _.yohoCoinCompute(result.data.shopping_cart_data);
return result.data;
} else {
return {};
}
});
};
/**
* 购物车结算--提交结算信息
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @param int $cartType 购物车类型ID
* @param int $deliveryTime 寄送时间ID
* @param int $deliveryWay 寄送方式ID
* @param array $invoices 发票参数数组
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的有货币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @param string $qhyUnio 友盟有关信息
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
* @param int $times
* @param null $activityInfo 套餐数据
* @return array 接口返回的数据
*/
exports.orderSub = (uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType, remark,
couponCode, yohoCoin, skuList, qhyUnio = '',
userAgent, times, activityInfo = null) => {
if (!userAgent) {
userAgent = null;
}
if (!times) {
times = 1;
}
if (!activityInfo) {
activityInfo = null;
}
if (!addressId) {
return Promise.resolve({code: 401, message: '配送地址不能为空'});
}
if (!deliveryTime) {
return Promise.resolve({code: 402, message: '请选择配送时间'});
}
if (!deliveryWay) {
return Promise.resolve({code: 403, message: '请选择配送方式'});
}
return shoppingAPI.orderSub(uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType,
remark, couponCode, yohoCoin, skuList, qhyUnio,
userAgent, times, activityInfo).then(orderSubRes => {
let finalResult = {};
if (orderSubRes && orderSubRes.data && orderSubRes.data.is_hint === 'Y') {
finalResult.code = 409;
if (orderSubRes.data.hintInfo) {
let productName = _.get('orderSubRes', 'data.hintInfo.productName', '');
if (productName.length > 50) { // TODO 需要检查长度是否正确
orderSubRes.data.hintInfo.productName =
productName.substring(0, 47) + '...';
}
finalResult.message = [
encodeURI(productName + _.get(orderSubRes, 'data.hintInfo.suffix', '')),
encodeURI(_.get(orderSubRes, 'data.hintInfo.lastLine', ''))
];
}
finalResult.buttons = [
{
href: helpers.urlFormat('/cart/index/index'),
text: '重新选择商品',
class: ''
},
{
href: '',
text: '继续结算',
class: 'order-tip-btnred'
}
];
} else if (orderSubRes && orderSubRes.code) {
finalResult = orderSubRes;
} else {
finalResult = {
code: 400,
message: '出错啦'
};
}
return finalResult;
});
};
/**
* 处理优惠券列表数据
*
* @param int $uid 用户ID
... ...
... ... @@ -32,6 +32,8 @@ router.get('/index/new/pay', authMW, payController.pay);// 统一支付 URL,
router.get('/index/new/pay/alipayresult', authMW, payController.payAli);// 支付宝付款支付成功
router.get('/index/new/orderEnsure', authMW, order.orderEnsure); // 订单结算
router.post('/index/new/orderCompute', authMW, order.orderCompute); // 结算页参数改变,重新运算
router.post('/index/new/orderSub', authMW, order.orderSub); // 结算页参数改变,重新运算
router.get('/index/new/selectCoupon', authMW, order.selectCoupon); // 选择优惠券 页面
router.get('/index/new/couponList', order.couponList); // [ajax]获取优惠券列表
router.post('/index/new/couponSearch', order.couponSearch); // [ajax]购物车输入优惠券码使用优惠券
... ...
... ... @@ -42,7 +42,7 @@ exports.address = (req, res, next) => {
*/
exports.addressAct = (req, res, next) => {
addressModel.address({
id: decodeURIComponent(req.query.id),
id: req.query.id ? decodeURIComponent(req.query.id) : null,
uid: req.user.uid
}).then(result => {
let responseData = {
... ... @@ -53,7 +53,7 @@ exports.addressAct = (req, res, next) => {
navBtn: false,
backUrl: false
}),
title: result.navTitle
title: result && result.navTitle
};
res.render('address/address-act', Object.assign(responseData, result));
... ...
... ... @@ -2,6 +2,14 @@
const _ = require('lodash');
const api = global.yoho.API;
const privateKeyList = {
android: 'fd4ad5fcfa0de589ef238c0e7331b585',
iphone: 'a85bb0674e08986c6b115d5e3a4884fa',
ipad: 'ad9fcda2e679cf9229e37feae2cdcf80',
web: '0ed29744ed318fd28d2c07985d3ba633',
h5: 'fd4ad5fcfa0de589ef238c0e7331b585'
};
/**
* 购物车结算
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
... ... @@ -11,9 +19,13 @@ const api = global.yoho.API;
* @param string $skuList 购买限购商品时需要传递的参数
* @return see doc
*/
exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList) => {
exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => {
if (!activityInfo) {
activityInfo = null;
}
let param = {
method: 'app.Shopping.payment',
method: activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
enable_red_envelopes: 0, // h5不返回红包
cart_type: cartType,
yoho_coin_mode: isUseYohoCoin,
... ... @@ -25,10 +37,15 @@ exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList) => {
param.product_sku_list = skuList;
}
// 购买套装和量贩商品时数据处理
if (activityInfo) {
param.activity_id = activityInfo.activity_id;
param.product_sku_list = activityInfo.product_sku_list;
}
return api.get('', param);
};
/**
* 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
* doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
... ... @@ -67,7 +84,139 @@ exports.orderComputeAPI = (uid, cartType, deliveWay, paymentType, couponCode, yo
param.product_sku_list = skuList;
}
return api.get('', param);
return api.get('', param, {code: 200});
};
/**
* 校验电子票
* @param int $uid
* @param int $productSku
* @param int $buyNumber
* @param int $useYohoCoin
* @param bool|int $yohoCoinMode 1:使用有货币;0:不使用有货币
* @return array
* @author sefon 2016-7-2 18:12:30
*/
exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) => {
if (!useYohoCoin) {
useYohoCoin = 0;
}
if (!yohoCoinMode) {
yohoCoinMode = true;
}
let params = {
method: 'app.shopping.ticket',
uid: uid,
product_sku: productSku,
buy_number: buyNumber,
use_yoho_coin: useYohoCoin
};
if (!yohoCoinMode) {
_.assign(params, {
yoho_coin_mode: 0
});
}
return api.get('', params, {code: 200});
};
/**
* 购物车结算--提交结算信息
*
* @param int $uid 用户ID
* @param int $addressId 地址ID
* @param int $cartType 购物车类型ID
* @param int $deliveryTime 寄送时间ID
* @param int $deliveryWay 寄送方式ID
* @param array $invoices 发票参数数组
* @param int $paymentId 支付方式ID
* @param int $paymentType 支付类型ID
* @param string $remark 留言
* @param string $couponCode 优惠券码
* @param mixed $yohoCoin 使用的有货币数量或为空
* @param string $skuList 购买限购商品时需要传递的参数
* @param string $qhyUnion 友盟有关信息
* @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
* @param $times
* @param null $activityInfo 套餐信息
* @return array 接口返回的数据
*/
exports.orderSub = (uid, addressId, cartType, deliveryTime,
deliveryWay, invoices, paymentId, paymentType, remark, couponCode,
yohoCoin, skuList, qhyUnion, userAgent, times, activityInfo) => {
if (!activityInfo) {
activityInfo = null;
}
let params = {
debug: 'Y',
private_key: privateKeyList.h5,
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
};
/* tar add 161130 结算优化 */
if (times === 2 || times === '2') {
params.is_continue_buy = 'Y';
} else {
params.is_continue_buy = 'N';
}
if (invoices.invoices_type_id) {
// 发票内容id--图书:1
params.invoice_content = invoices.invoices_type_id;
}
if (invoices.invoices_type) {
// 数字类型 发票类型 纸质 1 ,电子 2
params.invoices_type = invoices.invoices_type;
}
if (invoices.receiverMobile) {
// 发票人手机
params.receiverMobile = invoices.receiverMobile;
}
if (invoices.invoices_title) {
// 发票抬头 OR 填写单位名称,这二个是一个意思,只是叫法不一样
params.invoices_title = invoices.invoices_title;
}
if (couponCode) {
params.coupon_code = couponCode;
}
if (yohoCoin) {
params.use_yoho_coin = yohoCoin;
}
// 购买限购商品时需要传递product_sku_list参数
if (skuList && !activityInfo) {
params.product_sku_list = skuList;
}
// 购买套餐商品需要的数据
if (activityInfo) {
params.activity_id = activityInfo.activity_id;
params.product_sku_list = activityInfo.product_sku_list; // TODO 检查 JSON 是否正常
}
// 友盟有关信息的传递
if (qhyUnion) {
params.qhy_union = qhyUnion;
}
return api.get('', params);
};
... ...
... ... @@ -18,14 +18,14 @@ module.exports = {
testCode: 'yoho4946abcdef#$%&!@',
domains: {
api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
// liveApi: 'http://testapi.live.yohops.com:9999/',
// singleApi: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
liveApi: 'http://testapi.live.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://dev-api.yohops.com:9999/',
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/',
// service: 'http://dev-service.yohops.com:9999/',
// liveApi: 'http://api.live.yoho.cn/',
// singleApi: 'http://single.yoho.cn/',
imSocket: 'wss://imsocket.yohobuy.com:443',
imCs: 'https://imhttp.yohobuy.com/api',
... ...
... ... @@ -55,28 +55,38 @@ let cartObj = {
}
},
promoItemClick(e) {
let cartType = window.cookie('cartType') || 'ordinary';
let self = this;
let promotionId = $(e.currentTarget).data('id');
let promotionType = $(e.currentTarget).data('type');
let promotionTitle = encodeURIComponent($(e.currentTarget).data('title'));
self.toPromotionPage({
promotionType,
promotionId,
promotionTitle,
status: $(e.currentTarget).data('status')
});
},
toPromotionPage(opts) {
let cartType = window.cookie('cartType') || 'ordinary';
let title = '促销商品';
if (promotionType === 'Gift') {
if ($(e.currentTarget).data('status') === 30) {
window.location.href = `/cart/index/new/gift?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}&edit=1`;
if (opts.promotionType === 'Gift') {
if (opts.status === 30) {
window.location.href = `/cart/index/new/gift?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}&edit=1`;
} else {
window.location.href = `/cart/index/new/gift?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
window.location.href = `/cart/index/new/gift?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
}
} else if (promotionType === 'Needpaygift') {
if ($(e.currentTarget).data('status') === 30) {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}&edit=1`;
} else if (opts.promotionType === 'Needpaygift') {
if (opts.status === 30) {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}&edit=1`;
} else {
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
window.location.href = `/cart/index/new/advanceBuy?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
}
} else {
window.location.href = `/product/index/index?promotion_id=${promotionId}&title=${title}&intro_text=${promotionTitle}&cartType=${cartType}`;
window.location.href = `/product/index/index?promotion_id=${opts.promotionId}&title=${title}&intro_text=${opts.promotionTitle}&cartType=${cartType}`;
}
},
allGiftBoxClick(e) {
... ... @@ -89,6 +99,7 @@ let cartObj = {
}
},
balanceClick() {
let self = this;
let cartType = window.cookie('cartType') || 'ordinary';
if (window._yas && window._yas.sendCustomInfo) {
... ... @@ -112,7 +123,11 @@ let cartObj = {
tip.show(`所选商品中有${lowStocks}种库存不足的商品`);
return false;
}
if ($('.all-gift-box>.freebie').length) {
if (!$('.good-item.is-checked').length) {
tip.show('请先勾选商品');
return false;
}
if ($('.all-gift-box>.freebie').length || $('.promo-item[data-type="Gift"][data-status="10"]').length) {
dialog.showDialog({
dialogText: '您还未选择赠品,是否去选择赠品',
hasFooter: {
... ... @@ -120,17 +135,33 @@ let cartObj = {
rightBtnText: '去选择'
}
}, function() {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
self.toGiftPromotion(cartType);
}, function() {
window.location.href = '/cart/index/orderEnsure?cartType=' + cartType;
self.toOrderEnsure(cartType);
});
return false;
}
if (!$('.good-item.is-checked').length) {
tip.show('请先勾选商品');
return false;
}
self.toOrderEnsure(cartType);
},
toOrderEnsure(cartType) {
window.location.href = '/cart/index/new/orderEnsure?cartType=' + cartType;
},
toGiftPromotion(cartType) {
let self = this;
let promotionEles = $('.promo-item[data-type="Gift"][data-status="10"]');
if (promotionEles.length) {
let promotionEle = promotionEles.eq(0);
self.toPromotionPage({
promotionType: $(promotionEle).data('type'),
promotionId: $(promotionEle).data('id'),
promotionTitle: encodeURIComponent($(promotionEle).data('title')),
status: $(promotionEle).data('status')
});
} else if ($('.all-gift-box>.freebie').length) {
window.location.href = '/cart/index/new/gift?cartType=' + cartType;
}
}
};
... ...
... ... @@ -346,12 +346,12 @@ let goodObj = {
if (goodNum <= minNumber) {
$(minusEl).addClass('disabled');
} else if ($(minusEl).hasClass('disabled')) {
} else if (minNumber < oldGoodNum && $(minusEl).hasClass('disabled')) {
$(minusEl).removeClass('disabled');
}
if (goodNum >= maxNumber) {
$(plusEl).addClass('disabled');
} else if ($(plusEl).hasClass('disabled')) {
} else if (maxNumber > oldGoodNum && $(plusEl).hasClass('disabled')) {
$(plusEl).removeClass('disabled');
}
... ... @@ -381,16 +381,14 @@ let goodObj = {
},
success: (data) => {
if (data.code !== 200) {
self.handle.posting = false;
tip.show('网络异常');
} else {
goodNum = parseInt($(e.delegateTarget).find('.good-num').val(), 10);
let max = parseInt($(e.delegateTarget).find('.good-num').data('max'), 10);
if (!$(e.delegateTarget).find('.chk.select').hasClass('checked') && goodNum <= max) {
self.selectGood($(e.delegateTarget).find('.chk.select')).then(() => {
self.handle.posting = false;
});
self.selectGood($(e.delegateTarget).find('.chk.select'));
} else {
self.handle.refreshPage().then(() => {
self.handle.posting = false;
... ... @@ -432,7 +430,7 @@ let goodObj = {
data: {
skn: skn,
buy_num: count,
mnum: minNum,
mnum: minNum > 1 ? minNum : undefined,
promotion_id: promotionId
},
type: 'POST',
... ...
... ... @@ -207,7 +207,7 @@ function orderCompute() {
loading.showLoadingMask();
$.ajax({
method: 'POST',
url: '/cart/index/orderCompute',
url: '/cart/index/new/orderCompute',
data: data
}).then(function(res) {
if ($.type(res) !== 'object') {
... ... @@ -276,7 +276,7 @@ function submitOrder() {
isSubmiting = true;
$.ajax({
method: 'POST',
url: '/cart/index/orderSub',
url: '/cart/index/new/orderSub',
data: {
addressId: orderInfo('addressId'),
cartType: orderInfo('cartType') || 'ordinary',
... ...
... ... @@ -104,17 +104,20 @@ const formatCartGoods = (goodData, isAdvanceCart, isValid, inValidLow) => {
count: goodData.buy_number,
promotion_id: _.toNumber(goodData.promotion_id) === 0 ? '' : goodData.promotion_id
};
goodData.storage_number = _.parseInt(goodData.storage_number);
goodData.min_buy_number = _.parseInt(goodData.min_buy_number);
goodData.buy_number = _.parseInt(goodData.buy_number);
if (goodData.min_buy_number && goodData.min_buy_number > 1) {
result.minNumber = parseInt(goodData.min_buy_number, 10);
if (goodData.min_buy_number && goodData.min_buy_number > 0) {
result.minNumber = goodData.min_buy_number;
}
result.maxNumber = parseInt(goodData.storage_number, 10);
result.minSelectNum = parseInt(goodData.buy_number, 10) <= parseInt(goodData.min_buy_number, 10) || parseInt(goodData.buy_number, 10) === 1;
result.maxSelectNum = parseInt(goodData.buy_number, 10) >= parseInt(goodData.storage_number, 10) && goodData.goods_type === 'ordinary';
result.maxNumber = goodData.storage_number;
result.minSelectNum = goodData.buy_number <= goodData.min_buy_number || goodData.buy_number === 1;
result.maxSelectNum = goodData.buy_number >= goodData.storage_number && goodData.goods_type === 'ordinary';
if (isValid) {
// 库存不足
result.lowStocks = (goodData.buy_number > goodData.storage_number);
result.lowStocks = goodData.buy_number > goodData.storage_number;
} else { // 失效商品
result.inValid = true;
result.inValidLow = inValidLow;
... ... @@ -223,7 +226,7 @@ const procGoodsDetail = (productData, num) => {
}
data.num = 1;
if (num) {
data.num = parseInt(num, 10);
data.num = _.parseInt(num);
}
// 商品选择
... ... @@ -258,7 +261,7 @@ const procGoodsDetail = (productData, num) => {
goodsId: val.goods_id,
colorId: val.color_id,
name: one.size_name,
sizeNum: parseInt(one.storage_number, 10),
sizeNum: _.parseInt(one.storage_number, 10),
sizeInfo: one.size_info ? one.size_info : ''
});
... ... @@ -269,9 +272,9 @@ const procGoodsDetail = (productData, num) => {
sizeInfo: one.size_info ? one.size_info : ''
} : allSizeList[sizeName];
colorNum += parseInt(one.storage_number, 10);
colorNum += _.parseInt(one.storage_number, 10);
colorStorageGroup[val.product_skc][sizeName] = parseInt(one.storage_number, 10);
colorStorageGroup[val.product_skc][sizeName] = _.parseInt(one.storage_number, 10);
});
// 颜色分组
... ... @@ -326,7 +329,7 @@ const procGoodsDetail = (productData, num) => {
id: colorArr.id,
skcId: colorArr.skcId,
name: colorArr.name,
colorNum: _.has(colorStorageGroup, `${colorArr.skcId}.${sName}`) ? parseInt(colorStorageGroup[colorArr.skcId][sName], 10) : 0,
colorNum: _.has(colorStorageGroup, `${colorArr.skcId}.${sName}`) ? _.parseInt(colorStorageGroup[colorArr.skcId][sName], 10) : 0,
goodsName: colorArr.goodsName
});
});
... ... @@ -463,7 +466,7 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => {
let goodCount = _.sum(result.goods
.filter(good => good.lowStocks === false)
.map(good => {
return parseInt(good.count, 10);
return _.parseInt(good.count, 10);
})) + // 普通商品
_.sum(result.goodPools
... ... @@ -473,13 +476,13 @@ const procCartData = (data, onlyGift, onlyAdvanceBuy, isAdvanceCart) => {
return _.sum(_.get(subPool, 'goods', [])// 子促销池中的商品
.filter(good => good.lowStocks === false)
.map(good => {
return parseInt(good.count, 10);
return _.parseInt(good.count, 10);
}));
})) +
_.sum(_.get(goodPool, 'goods', []) // 大促销池中的商品
.filter(good => good.lowStocks === false)
.map(good => {
return parseInt(good.count, 10);
return _.parseInt(good.count, 10);
}));
}));
... ...