Authored by 陈峰

Merge branch 'feature/cart' of http://git.yoho.cn/fe/yohobuywap-node into feature/cart

@@ -7,7 +7,7 @@ const headerModel = require('../../../doraemon/models/header'); @@ -7,7 +7,7 @@ const headerModel = require('../../../doraemon/models/header');
7 const userModel = require('../../serverAPI/user'); 7 const userModel = require('../../serverAPI/user');
8 const addressModel = require('../../serverAPI/user/address'); 8 const addressModel = require('../../serverAPI/user/address');
9 const orderModel = require('../models/order'); 9 const orderModel = require('../models/order');
10 - 10 +const crypt = global.yoho.crypt;
11 11
12 exports.orderEnsure = (req, res, next) => { 12 exports.orderEnsure = (req, res, next) => {
13 let headerData = headerModel.setNav({ 13 let headerData = headerModel.setNav({
@@ -42,14 +42,20 @@ exports.orderEnsure = (req, res, next) => { @@ -42,14 +42,20 @@ exports.orderEnsure = (req, res, next) => {
42 headerData.backUrl = req.get('Referer') || returnUrl; 42 headerData.backUrl = req.get('Referer') || returnUrl;
43 } 43 }
44 44
45 - let order = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, req.xhr);  
46 - let userProfile = userModel.queryProfile(uid);  
47 - let address = addressModel.addressData(uid); 45 + let orderPromise = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber);
  46 + let userProfilePromise = userModel.queryProfile(uid);
  47 + let addressPromise = addressModel.addressData(uid);
  48 +
  49 + if (req.query.activityType === 'bundle') {
  50 + let activityInfo = JSON.parse(req.cookies['activity-info']);
  51 +
  52 + orderPromise = cartModel.cartPay(uid, cartType, orderInfo, sku, skn, buyNumber, activityInfo);
  53 + }
48 54
49 - return Promise.all([order, userProfile, address]).then(result => {  
50 - order = result[0];  
51 - userProfile = result[1];  
52 - address = result[2]; 55 + return Promise.all([orderPromise, userProfilePromise, addressPromise]).then(result => {
  56 + let order = result[0];
  57 + let userProfile = result[1];
  58 + let address = result[2];
53 59
54 if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX? 60 if (order.cartUrl) { // TODO? 普通或者预售商品为空时, BUT WHEN AJAX?
55 return res.redirect(order.cartUrl); 61 return res.redirect(order.cartUrl);
@@ -74,21 +80,146 @@ exports.orderEnsure = (req, res, next) => { @@ -74,21 +80,146 @@ exports.orderEnsure = (req, res, next) => {
74 orderEnsurePage: true, 80 orderEnsurePage: true,
75 isOrdinaryCart: cartType !== 'advance', 81 isOrdinaryCart: cartType !== 'advance',
76 orderEnsure: order, 82 orderEnsure: order,
77 - userMobile: mobile 83 + userMobile: mobile,
  84 + pageHeader: headerData,
  85 + pageFooter: true,
  86 + module: 'cart',
  87 + page: 'order-ensure',
  88 + width750: true,
  89 + title: '确认订单',
78 }; 90 };
79 91
80 - viewData.pageHeader = headerData;  
81 - viewData.pageFooter = true;  
82 - viewData.module = 'cart';  
83 - viewData.page = 'order-ensure';  
84 - viewData.width750 = true;  
85 - viewData.title = '确认订单';  
86 -  
87 res.render('order-ensure', viewData); 92 res.render('order-ensure', viewData);
88 }).catch(next); 93 }).catch(next);
89 }; 94 };
90 95
91 /** 96 /**
  97 + * 购物车选择改变字段,重新运算订单数据
  98 + */
  99 +exports.orderCompute = (req, res, next) => {
  100 + let cartType = req.body.cartType || 'ordinary';
  101 + let deliveryId = req.body.deliveryId || 1;
  102 + let paymentTypeId = req.body.paymentTypeId || 1;
  103 + let couponCode = req.body.couponCode || null;
  104 + let yohoCoin = req.body.yohoCoin || null;
  105 + let productSku = req.body.productSku || null;
  106 + let buyNumber = req.body.buyNumber || null;
  107 + let uid = req.user.uid;
  108 + let skuList = req.body.skuList;
  109 + let type = req.body.type;
  110 +
  111 + if (type !== 'tickets') {
  112 + cartModel.orderCompute(uid, cartType, deliveryId, paymentTypeId, couponCode, yohoCoin, skuList).then(result => {
  113 + res.json(result);
  114 + }).catch(next);
  115 + } else {
  116 + cartModel.ticketsOrderCompute(uid, productSku, buyNumber, yohoCoin).then(result => {
  117 + res.json(result);
  118 + }).catch(next);
  119 + }
  120 +};
  121 +
  122 +/**
  123 + * 确认结算订单
  124 + */
  125 +exports.orderSub = (req, res) => {
  126 + let uid = req.user.uid;
  127 + let addressId = crypt.decrypt('', req.body.addressId);
  128 + let cartType = req.body.cartType || 'ordinary';
  129 + let deliveryTimeId = req.body.deliveryTimeId || 1;
  130 + let deliveryId = req.body.deliveryId || 1;
  131 + let paymentTypeId = req.body.paymentTypeId || 15;
  132 + let paymentType = req.body.paymentType || 1;
  133 + let msg = req.body.msg || null;
  134 + let couponCode = req.body.couponCode || null;
  135 + let yohoCoin = req.body.yohoCoin || 1;
  136 + let skuList = req.body.skuList || '';
  137 + let orderInfo;
  138 +
  139 + try {
  140 + orderInfo = JSON.parse(req.cookies['order-info']);
  141 + } catch (e) {
  142 + orderInfo = {};
  143 + }
  144 +
  145 + let times = req.body.times || 1;
  146 +
  147 + // 电子发票信息数组
  148 + let invoices = {};
  149 +
  150 + if (orderInfo) {
  151 + invoices = {
  152 + invoices_type_id: orderInfo.invoiceType,
  153 + invoices_type: orderInfo.invoicesType,
  154 + receiverMobile: orderInfo.receiverMobile,
  155 + invoices_title: orderInfo.invoiceText ? orderInfo.invoiceText : '个人'
  156 + };
  157 + }
  158 +
  159 + /* 判断是否是友盟过来的用户 */
  160 + let userAgent = null;
  161 + let unionKey = '';
  162 + let unionInfo = {};
  163 +
  164 + if (req.cookies.mkt_code || req.cookies._QYH_UNION) {
  165 +
  166 + /* tar modified 161108 添加新的联盟数据处理逻辑,兼容原有联盟数据处理,
  167 + 区别是旧的北京写 cookie 加密过来,新的 node 写 cookie,没有加密 */
  168 + if (req.cookies._QYH_UNION) {
  169 + let encryData = decodeURI(req.cookies._QYH_UNION);
  170 + let testQyhUnion = JSON.parse(encryData);
  171 +
  172 + if (testQyhUnion.client_id) {
  173 + unionKey = encryData;
  174 + } else {
  175 + // unionKey = helpers.unionDecode(req.cookies._QYH_UNION, 'q_union_yohobuy'); // TODO 这个方法没有
  176 + }
  177 + } else {
  178 + unionKey = '{"client_id":' + req.cookies.mkt_code + '}';
  179 + }
  180 +
  181 + /* 检查联盟参数是否有效 */
  182 + unionInfo = unionKey ? JSON.parse(unionKey) : {};
  183 +
  184 + /* 模拟APP的User-Agent */
  185 + userAgent = unionInfo.client_id ? 'YOHO!Buy/3.8.2.259(Model/PC;Channel/' +
  186 + unionInfo.client_id + ';uid/' + uid + ')' : null;
  187 + }
  188 +
  189 + return co(function* () {
  190 + let result;
  191 +
  192 + /* tar modified 161206 套餐 */
  193 + if (req.body.activityType === 'bundle') {
  194 + let activityInfo = JSON.parse(req.cookies['activity-info']);
  195 +
  196 + result = yield cartModel.orderSub(uid, addressId, 'bundle', deliveryTimeId,
  197 + deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
  198 + yohoCoin, null, unionKey, userAgent, times, activityInfo);
  199 + } else {
  200 + result = yield cartModel.orderSub(uid, addressId, cartType, deliveryTimeId,
  201 + deliveryId, invoices, paymentTypeId, paymentType, msg, couponCode,
  202 + yohoCoin, skuList, unionKey, userAgent);
  203 + }
  204 +
  205 + if (unionInfo) {
  206 + result.data.unionCookie = unionInfo;
  207 + }
  208 +
  209 + // 提交成功清除Cookie
  210 + res.cookie('order-info', null, {
  211 + domain: 'yohobuy.com'
  212 + });
  213 +
  214 + if (result.code === 409) {
  215 + return res.json(decodeURI(result));
  216 + } else {
  217 + return res.json(result);
  218 + }
  219 + })();
  220 +};
  221 +
  222 +/**
92 * 下单流程 选择优惠券 223 * 下单流程 选择优惠券
93 */ 224 */
94 exports.selectCoupon = (req, res) => { 225 exports.selectCoupon = (req, res) => {
@@ -164,7 +295,7 @@ exports.selectAddress = (req, res, next) => { @@ -164,7 +295,7 @@ exports.selectAddress = (req, res, next) => {
164 req.session.addressMore = moreUrl; // TODO: 注意cookie-session 295 req.session.addressMore = moreUrl; // TODO: 注意cookie-session
165 } 296 }
166 297
167 - moreUrl = req.session.addressMore; 298 + // moreUrl = req.session.addressMore;
168 299
169 let headerData = headerModel.setNav({ 300 let headerData = headerModel.setNav({
170 navTitle: '选择地址', 301 navTitle: '选择地址',
@@ -6,6 +6,57 @@ const paymentProcess = require(global.utils + '/payment-process'); @@ -6,6 +6,57 @@ const paymentProcess = require(global.utils + '/payment-process');
6 const shoppingAPI = require('../../serverAPI/order/shopping'); 6 const shoppingAPI = require('../../serverAPI/order/shopping');
7 7
8 /** 8 /**
  9 + * 转换价格
  10 + *
  11 + * @param float|string $price 价格
  12 + * @param boolean $isSepcialZero 是否需要特殊的0,默认否
  13 + * @return float|string 转换之后的价格
  14 + */
  15 +const transPrice = (price, isSepcialZero) => {
  16 + if (!isSepcialZero) {
  17 + isSepcialZero = false;
  18 + }
  19 +
  20 + return price;
  21 +};
  22 +
  23 +/**
  24 + *有货币使用前端方案显示及是否可单击判断
  25 + */
  26 +const _yohoCoinCompute = (orderCompute) => {
  27 + let yohoCoinData = {
  28 + totalYohoCoinNum: 0,
  29 + yohoCoin: 0,
  30 + useYohoCoin: 0,
  31 + yohoCoinClick: 0,
  32 + yohoCoinMsg: '',
  33 + yoho_coin_pay_rule: []
  34 + };
  35 +
  36 + if (!orderCompute || !orderCompute.yoho_coin_pay_rule) {
  37 + return yohoCoinData;
  38 + }
  39 +
  40 + _.assign(yohoCoinData, {
  41 + totalYohoCoinNum: orderCompute.total_yoho_coin_num ? parseInt(orderCompute.total_yoho_coin_num, 10) : 0,
  42 + yohoCoin: orderCompute.yoho_coin ? transPrice(orderCompute.yoho_coin) : 0,
  43 + useYohoCoin: orderCompute.use_yoho_coin ? transPrice(orderCompute.use_yoho_coin) : 0,
  44 + yoho_coin_pay_rule: orderCompute.yoho_coin_pay_rule
  45 + });
  46 +
  47 + if (yohoCoinData.totalYohoCoinNum < 100) {
  48 + yohoCoinData.yohoCoinMsg = `共${yohoCoinData.totalYohoCoinNum}有货币,满${orderCompute.yoho_coin_pay_rule.num_limit}可用`;
  49 + } else if (yohoCoinData.useYohoCoin > 0 || yohoCoinData.yohoCoin > 0) {
  50 + yohoCoinData.yohoCoinMsg = '可抵¥' + (yohoCoinData.useYohoCoin > 0 ? yohoCoinData.useYohoCoin : yohoCoinData.yohoCoin);
  51 + yohoCoinData.yohoCoinClick = 1;
  52 + } else {
  53 + yohoCoinData.yohoCoinMsg = '不满足有货币使用条件';
  54 + }
  55 +
  56 + return yohoCoinData;
  57 +};
  58 +
  59 +/**
9 * 调用购物车结算接口返回的数据处理 60 * 调用购物车结算接口返回的数据处理
10 * 61 *
11 * 62 *
@@ -20,9 +71,7 @@ const shoppingAPI = require('../../serverAPI/order/shopping'); @@ -20,9 +71,7 @@ const shoppingAPI = require('../../serverAPI/order/shopping');
20 * @param bool $isAjax 是否是异步请求 71 * @param bool $isAjax 是否是异步请求
21 * @return array 接口返回的数据 72 * @return array 接口返回的数据
22 */ 73 */
23 -exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, isAjax) => {  
24 - isAjax = isAjax || false;  
25 - 74 +exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumber, activityInfo) => {
26 let result = {}; 75 let result = {};
27 let skuList = []; 76 let skuList = [];
28 let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品 77 let isLimitGoods = skn && sku && buyNumber; // 存在sku, skn 和buyNumber时为限购商品
@@ -53,8 +102,15 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb @@ -53,8 +102,15 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
53 ); 102 );
54 } 103 }
55 104
  105 + // 区分套餐量贩和普通商品
  106 + let cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList);
  107 +
  108 + if (activityInfo) {
  109 + cartPayAPI = shoppingAPI.cartPayAPI(uid, cartType, 0, skuList, activityInfo);
  110 + }
  111 +
56 return Promise.all([ 112 return Promise.all([
57 - shoppingAPI.cartPayAPI(uid, cartType, 0, skuList), // 0. 订单数据 113 + cartPayAPI, // 0. 订单数据
58 orderComputeAPI, 114 orderComputeAPI,
59 shoppingAPI.getValidCouponCount(uid) // 2. 有效优惠券 115 shoppingAPI.getValidCouponCount(uid) // 2. 有效优惠券
60 ]).then(res => { 116 ]).then(res => {
@@ -89,6 +145,143 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb @@ -89,6 +145,143 @@ exports.cartPay = (uid, cartType, orderInfo, limitProductCode, sku, skn, buyNumb
89 }; 145 };
90 146
91 /** 147 /**
  148 + * 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
  149 + *
  150 + * @param int $uid 用户ID
  151 + * @param string $cartType 购物车类型,ordinary表示普通购物车
  152 + * @param int $deliveryWay 配送方式,1表示普通快递,2表示顺丰速运
  153 + * @param int $paymentType 支付方式,1表示在线支付,2表示货到付款
  154 + * @param string $couponCode 优惠券码
  155 + * @param mixed $yohoCoin 使用的有货币数量
  156 + * @param string $skuList 购买限购商品时需要传递的参数
  157 + * @return array 接口返回的数据
  158 + */
  159 +exports.orderCompute = (uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList) => {
  160 + return shoppingAPI.orderComputeAPI(uid, cartType, deliveryWay, paymentType, couponCode, yohoCoin, skuList).then(result => {
  161 + if (result && result.data) {
  162 + result.data.use_yoho_coin = transPrice(result.data.use_yoho_coin);
  163 + result.data.yohoCoinCompute = _yohoCoinCompute(result.data);
  164 + return result.data;
  165 + } else {
  166 + return {};
  167 + }
  168 + });
  169 +};
  170 +
  171 +
  172 +exports.ticketsOrderCompute = (uid, productSku, buyNumber, yohoCoin) => {
  173 + return shoppingAPI.checkTickets(uid, productSku, buyNumber, yohoCoin).then(result => {
  174 + if (result && result.data) {
  175 + result.data.shopping_cart_data.use_yoho_coin = transPrice(result.data.shopping_cart_data.use_yoho_coin);
  176 + result.data.yohoCoinCompute = _.yohoCoinCompute(result.data.shopping_cart_data);
  177 +
  178 + return result.data;
  179 + } else {
  180 + return {};
  181 + }
  182 + });
  183 +};
  184 +
  185 +/**
  186 + * 购物车结算--提交结算信息
  187 + *
  188 + * @param int $uid 用户ID
  189 + * @param int $addressId 地址ID
  190 + * @param int $cartType 购物车类型ID
  191 + * @param int $deliveryTime 寄送时间ID
  192 + * @param int $deliveryWay 寄送方式ID
  193 + * @param array $invoices 发票参数数组
  194 + * @param int $paymentId 支付方式ID
  195 + * @param int $paymentType 支付类型ID
  196 + * @param string $remark 留言
  197 + * @param string $couponCode 优惠券码
  198 + * @param mixed $yohoCoin 使用的有货币数量或为空
  199 + * @param string $skuList 购买限购商品时需要传递的参数
  200 + * @param string $qhyUnio 友盟有关信息
  201 + * @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
  202 + * @param int $times
  203 + * @param null $activityInfo 套餐数据
  204 + * @return array 接口返回的数据
  205 + */
  206 +exports.orderSub = (uid, addressId, cartType, deliveryTime,
  207 + deliveryWay, invoices, paymentId, paymentType, remark,
  208 + couponCode, yohoCoin, skuList, qhyUnio = '',
  209 + userAgent, times, activityInfo = null) => {
  210 +
  211 + if (!userAgent) {
  212 + userAgent = null;
  213 + }
  214 +
  215 + if (!times) {
  216 + times = 1;
  217 + }
  218 +
  219 + if (!activityInfo) {
  220 + activityInfo = null;
  221 + }
  222 +
  223 + if (!addressId) {
  224 + return Promise.resolve({code: 401, message: '配送地址不能为空'});
  225 + }
  226 +
  227 + if (!deliveryTime) {
  228 + return Promise.resolve({code: 402, message: '请选择配送时间'});
  229 + }
  230 +
  231 + if (!deliveryWay) {
  232 + return Promise.resolve({code: 403, message: '请选择配送方式'});
  233 + }
  234 +
  235 + return shoppingAPI.orderSub(uid, addressId, cartType, deliveryTime,
  236 + deliveryWay, invoices, paymentId, paymentType,
  237 + remark, couponCode, yohoCoin, skuList, qhyUnio,
  238 + userAgent, times, activityInfo).then(orderSubRes => {
  239 + let finalResult = {};
  240 +
  241 + if (orderSubRes && orderSubRes.data && orderSubRes.data.is_hint === 'Y') {
  242 + finalResult.code = 409;
  243 +
  244 + if (orderSubRes.data.hintInfo) {
  245 + let productName = _.get('orderSubRes', 'data.hintInfo.productName', '');
  246 +
  247 + if (productName.length > 50) { // TODO 需要检查长度是否正确
  248 + orderSubRes.data.hintInfo.productName =
  249 + productName.substring(0, 47) + '...';
  250 + }
  251 +
  252 + finalResult.message = [
  253 + encodeURI(productName + _.get(orderSubRes, 'data.hintInfo.suffix', '')),
  254 + encodeURI(_.get(orderSubRes, 'data.hintInfo.lastLine', ''))
  255 + ];
  256 + }
  257 +
  258 + finalResult.buttons = [
  259 + {
  260 + href: helpers.urlFormat('/cart/index/index'),
  261 + text: '重新选择商品',
  262 + class: ''
  263 + },
  264 + {
  265 + href: '',
  266 + text: '继续结算',
  267 + class: 'order-tip-btnred'
  268 + }
  269 + ];
  270 + } else if (orderSubRes && orderSubRes.code) {
  271 + finalResult = orderSubRes;
  272 + } else {
  273 + finalResult = {
  274 + code: 400,
  275 + message: '出错啦'
  276 + };
  277 + }
  278 +
  279 + return finalResult;
  280 + });
  281 +
  282 +};
  283 +
  284 +/**
92 * 处理优惠券列表数据 285 * 处理优惠券列表数据
93 * 286 *
94 * @param int $uid 用户ID 287 * @param int $uid 用户ID
@@ -32,6 +32,8 @@ router.get('/index/new/pay', authMW, payController.pay);// 统一支付 URL, @@ -32,6 +32,8 @@ router.get('/index/new/pay', authMW, payController.pay);// 统一支付 URL,
32 router.get('/index/new/pay/alipayresult', authMW, payController.payAli);// 支付宝付款支付成功 32 router.get('/index/new/pay/alipayresult', authMW, payController.payAli);// 支付宝付款支付成功
33 33
34 router.get('/index/new/orderEnsure', authMW, order.orderEnsure); // 订单结算 34 router.get('/index/new/orderEnsure', authMW, order.orderEnsure); // 订单结算
  35 +router.post('/index/new/orderCompute', authMW, order.orderCompute); // 结算页参数改变,重新运算
  36 +router.post('/index/new/orderSub', authMW, order.orderSub); // 结算页参数改变,重新运算
35 router.get('/index/new/selectCoupon', authMW, order.selectCoupon); // 选择优惠券 页面 37 router.get('/index/new/selectCoupon', authMW, order.selectCoupon); // 选择优惠券 页面
36 router.get('/index/new/couponList', order.couponList); // [ajax]获取优惠券列表 38 router.get('/index/new/couponList', order.couponList); // [ajax]获取优惠券列表
37 router.post('/index/new/couponSearch', order.couponSearch); // [ajax]购物车输入优惠券码使用优惠券 39 router.post('/index/new/couponSearch', order.couponSearch); // [ajax]购物车输入优惠券码使用优惠券
@@ -42,7 +42,7 @@ exports.address = (req, res, next) => { @@ -42,7 +42,7 @@ exports.address = (req, res, next) => {
42 */ 42 */
43 exports.addressAct = (req, res, next) => { 43 exports.addressAct = (req, res, next) => {
44 addressModel.address({ 44 addressModel.address({
45 - id: decodeURIComponent(req.query.id), 45 + id: req.query.id ? decodeURIComponent(req.query.id) : null,
46 uid: req.user.uid 46 uid: req.user.uid
47 }).then(result => { 47 }).then(result => {
48 let responseData = { 48 let responseData = {
@@ -53,7 +53,7 @@ exports.addressAct = (req, res, next) => { @@ -53,7 +53,7 @@ exports.addressAct = (req, res, next) => {
53 navBtn: false, 53 navBtn: false,
54 backUrl: false 54 backUrl: false
55 }), 55 }),
56 - title: result.navTitle 56 + title: result && result.navTitle
57 }; 57 };
58 58
59 res.render('address/address-act', Object.assign(responseData, result)); 59 res.render('address/address-act', Object.assign(responseData, result));
@@ -2,6 +2,14 @@ @@ -2,6 +2,14 @@
2 const _ = require('lodash'); 2 const _ = require('lodash');
3 const api = global.yoho.API; 3 const api = global.yoho.API;
4 4
  5 +const privateKeyList = {
  6 + android: 'fd4ad5fcfa0de589ef238c0e7331b585',
  7 + iphone: 'a85bb0674e08986c6b115d5e3a4884fa',
  8 + ipad: 'ad9fcda2e679cf9229e37feae2cdcf80',
  9 + web: '0ed29744ed318fd28d2c07985d3ba633',
  10 + h5: 'fd4ad5fcfa0de589ef238c0e7331b585'
  11 +};
  12 +
5 /** 13 /**
6 * 购物车结算 14 * 购物车结算
7 * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md 15 * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md
@@ -11,9 +19,13 @@ const api = global.yoho.API; @@ -11,9 +19,13 @@ const api = global.yoho.API;
11 * @param string $skuList 购买限购商品时需要传递的参数 19 * @param string $skuList 购买限购商品时需要传递的参数
12 * @return see doc 20 * @return see doc
13 */ 21 */
14 -exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList) => { 22 +exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList, activityInfo) => {
  23 + if (!activityInfo) {
  24 + activityInfo = null;
  25 + }
  26 +
15 let param = { 27 let param = {
16 - method: 'app.Shopping.payment', 28 + method: activityInfo ? 'app.Shopping.easyPayment' : 'app.Shopping.payment',
17 enable_red_envelopes: 0, // h5不返回红包 29 enable_red_envelopes: 0, // h5不返回红包
18 cart_type: cartType, 30 cart_type: cartType,
19 yoho_coin_mode: isUseYohoCoin, 31 yoho_coin_mode: isUseYohoCoin,
@@ -25,10 +37,15 @@ exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList) => { @@ -25,10 +37,15 @@ exports.cartPayAPI = (uid, cartType, isUseYohoCoin, skuList) => {
25 param.product_sku_list = skuList; 37 param.product_sku_list = skuList;
26 } 38 }
27 39
  40 + // 购买套装和量贩商品时数据处理
  41 + if (activityInfo) {
  42 + param.activity_id = activityInfo.activity_id;
  43 + param.product_sku_list = activityInfo.product_sku_list;
  44 + }
  45 +
28 return api.get('', param); 46 return api.get('', param);
29 }; 47 };
30 48
31 -  
32 /** 49 /**
33 * 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理 50 * 购物车结算--支付方式和配送方式选择以及是否使用有货币接口返回的数据处理
34 * doc: http://git.yoho.cn/yoho-documents/api-interfaces/blob/master/订单/shopping.md 51 * 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 @@ -67,7 +84,139 @@ exports.orderComputeAPI = (uid, cartType, deliveWay, paymentType, couponCode, yo
67 param.product_sku_list = skuList; 84 param.product_sku_list = skuList;
68 } 85 }
69 86
70 - return api.get('', param); 87 + return api.get('', param, {code: 200});
  88 +};
  89 +
  90 +/**
  91 + * 校验电子票
  92 + * @param int $uid
  93 + * @param int $productSku
  94 + * @param int $buyNumber
  95 + * @param int $useYohoCoin
  96 + * @param bool|int $yohoCoinMode 1:使用有货币;0:不使用有货币
  97 + * @return array
  98 + * @author sefon 2016-7-2 18:12:30
  99 + */
  100 +exports.checkTickets = (uid, productSku, buyNumber, useYohoCoin, yohoCoinMode) => {
  101 + if (!useYohoCoin) {
  102 + useYohoCoin = 0;
  103 + }
  104 +
  105 + if (!yohoCoinMode) {
  106 + yohoCoinMode = true;
  107 + }
  108 +
  109 + let params = {
  110 + method: 'app.shopping.ticket',
  111 + uid: uid,
  112 + product_sku: productSku,
  113 + buy_number: buyNumber,
  114 + use_yoho_coin: useYohoCoin
  115 + };
  116 +
  117 + if (!yohoCoinMode) {
  118 + _.assign(params, {
  119 + yoho_coin_mode: 0
  120 + });
  121 + }
  122 +
  123 + return api.get('', params, {code: 200});
  124 +};
  125 +
  126 +/**
  127 + * 购物车结算--提交结算信息
  128 + *
  129 + * @param int $uid 用户ID
  130 + * @param int $addressId 地址ID
  131 + * @param int $cartType 购物车类型ID
  132 + * @param int $deliveryTime 寄送时间ID
  133 + * @param int $deliveryWay 寄送方式ID
  134 + * @param array $invoices 发票参数数组
  135 + * @param int $paymentId 支付方式ID
  136 + * @param int $paymentType 支付类型ID
  137 + * @param string $remark 留言
  138 + * @param string $couponCode 优惠券码
  139 + * @param mixed $yohoCoin 使用的有货币数量或为空
  140 + * @param string $skuList 购买限购商品时需要传递的参数
  141 + * @param string $qhyUnion 友盟有关信息
  142 + * @param string|null $userAgent 联盟过来用户下单时需要的User-Agent信息
  143 + * @param $times
  144 + * @param null $activityInfo 套餐信息
  145 + * @return array 接口返回的数据
  146 + */
  147 +exports.orderSub = (uid, addressId, cartType, deliveryTime,
  148 + deliveryWay, invoices, paymentId, paymentType, remark, couponCode,
  149 + yohoCoin, skuList, qhyUnion, userAgent, times, activityInfo) => {
  150 + if (!activityInfo) {
  151 + activityInfo = null;
  152 + }
  153 +
  154 + let params = {
  155 + debug: 'Y',
  156 + private_key: privateKeyList.h5,
  157 + method: activityInfo ? 'app.Shopping.easySubmit' : 'app.Shopping.submit',
  158 + address_id: addressId,
  159 + cart_type: cartType,
  160 + delivery_time: deliveryTime,
  161 + delivery_way: deliveryWay,
  162 + payment_id: paymentId,
  163 + payment_type: paymentType,
  164 + remark: remark,
  165 + uid: uid
  166 + };
  167 +
  168 + /* tar add 161130 结算优化 */
  169 + if (times === 2 || times === '2') {
  170 + params.is_continue_buy = 'Y';
  171 + } else {
  172 + params.is_continue_buy = 'N';
  173 + }
  174 +
  175 + if (invoices.invoices_type_id) {
  176 + // 发票内容id--图书:1
  177 + params.invoice_content = invoices.invoices_type_id;
  178 + }
  179 +
  180 + if (invoices.invoices_type) {
  181 + // 数字类型 发票类型 纸质 1 ,电子 2
  182 + params.invoices_type = invoices.invoices_type;
  183 + }
  184 +
  185 + if (invoices.receiverMobile) {
  186 + // 发票人手机
  187 + params.receiverMobile = invoices.receiverMobile;
  188 + }
  189 +
  190 + if (invoices.invoices_title) {
  191 + // 发票抬头 OR 填写单位名称,这二个是一个意思,只是叫法不一样
  192 + params.invoices_title = invoices.invoices_title;
  193 + }
  194 +
  195 + if (couponCode) {
  196 + params.coupon_code = couponCode;
  197 + }
  198 +
  199 + if (yohoCoin) {
  200 + params.use_yoho_coin = yohoCoin;
  201 + }
  202 +
  203 + // 购买限购商品时需要传递product_sku_list参数
  204 + if (skuList && !activityInfo) {
  205 + params.product_sku_list = skuList;
  206 + }
  207 +
  208 + // 购买套餐商品需要的数据
  209 + if (activityInfo) {
  210 + params.activity_id = activityInfo.activity_id;
  211 + params.product_sku_list = activityInfo.product_sku_list; // TODO 检查 JSON 是否正常
  212 + }
  213 +
  214 + // 友盟有关信息的传递
  215 + if (qhyUnion) {
  216 + params.qhy_union = qhyUnion;
  217 + }
  218 +
  219 + return api.get('', params);
71 }; 220 };
72 221
73 222
@@ -18,14 +18,14 @@ module.exports = { @@ -18,14 +18,14 @@ module.exports = {
18 testCode: 'yoho4946abcdef#$%&!@', 18 testCode: 'yoho4946abcdef#$%&!@',
19 domains: { 19 domains: {
20 api: 'http://api-test3.yohops.com:9999/', 20 api: 'http://api-test3.yohops.com:9999/',
21 - // service: 'http://service-test3.yohops.com:9999/',  
22 - // liveApi: 'http://testapi.live.yohops.com:9999/',  
23 - // singleApi: 'http://api-test3.yohops.com:9999/', 21 + service: 'http://service-test3.yohops.com:9999/',
  22 + liveApi: 'http://testapi.live.yohops.com:9999/',
  23 + singleApi: 'http://api-test3.yohops.com:9999/',
24 24
25 // api: 'http://dev-api.yohops.com:9999/', 25 // api: 'http://dev-api.yohops.com:9999/',
26 - service: 'http://service.yoho.cn/',  
27 - liveApi: 'http://api.live.yoho.cn/',  
28 - singleApi: 'http://single.yoho.cn/', 26 + // service: 'http://dev-service.yohops.com:9999/',
  27 + // liveApi: 'http://api.live.yoho.cn/',
  28 + // singleApi: 'http://single.yoho.cn/',
29 29
30 imSocket: 'wss://imsocket.yohobuy.com:443', 30 imSocket: 'wss://imsocket.yohobuy.com:443',
31 imCs: 'https://imhttp.yohobuy.com/api', 31 imCs: 'https://imhttp.yohobuy.com/api',
@@ -207,7 +207,7 @@ function orderCompute() { @@ -207,7 +207,7 @@ function orderCompute() {
207 loading.showLoadingMask(); 207 loading.showLoadingMask();
208 $.ajax({ 208 $.ajax({
209 method: 'POST', 209 method: 'POST',
210 - url: '/cart/index/orderCompute', 210 + url: '/cart/index/new/orderCompute',
211 data: data 211 data: data
212 }).then(function(res) { 212 }).then(function(res) {
213 if ($.type(res) !== 'object') { 213 if ($.type(res) !== 'object') {
@@ -276,7 +276,7 @@ function submitOrder() { @@ -276,7 +276,7 @@ function submitOrder() {
276 isSubmiting = true; 276 isSubmiting = true;
277 $.ajax({ 277 $.ajax({
278 method: 'POST', 278 method: 'POST',
279 - url: '/cart/index/orderSub', 279 + url: '/cart/index/new/orderSub',
280 data: { 280 data: {
281 addressId: orderInfo('addressId'), 281 addressId: orderInfo('addressId'),
282 cartType: orderInfo('cartType') || 'ordinary', 282 cartType: orderInfo('cartType') || 'ordinary',