Authored by 陈轩

save

  1 +'use strict';
  2 +const _ = require('lodash');
  3 +const helpers = global.yoho.helpers;
  4 +const cartModel = require('../models/cart');
  5 +
  6 +
  7 +exports.orderEnsure = (req, res, next) => {
  8 + let uid = req.user.uid;
  9 + let returnUrl = helpers.urlFormat('/cart/index/new');
  10 + let cartType = req.query.cartType;
  11 +
  12 + let orderInfo;
  13 + try {
  14 + orderInfo = JSON.parse(req.cookies['order-info']);
  15 + } catch (e) {
  16 + orderInfo = {};
  17 + }
  18 +
  19 + // 如果传递了code, skn, sku, buy_number 就代表限购商品
  20 + let limitProductCode = req.query.limitproductcode || '';
  21 + let sku = req.query.sku || '';
  22 + let skn = req.query.skn || '';
  23 + let buyNumber = req.query.buy_number || 1;
  24 +
  25 + if (limitProductCode) {
  26 + returnUrl = req.get('Referer') || returnUrl;
  27 + }
  28 +
  29 + cartModel.cartPay(uid, cartType, orderInfo, limitProductCode)
  30 +
  31 + res.send('todo: orderEnsure');
  32 +};
  1 +'use strict';
  2 +
  3 +const api = global.yoho.api;
  4 +
  5 +/**
  6 + * 购物车结算
  7 + *
  8 + * @param int uid 用户ID
  9 + * @param string cartType 购物车类型,ordinary表示普通购物车
  10 + * @param int isUseYohoCoin 是否使用有货币,0不使用, 1使用
  11 + * @param string skuList 购买限购商品时需要传递的参数
  12 + * @return array 接口返回的数据
  13 + */
  14 +exports.cartPay = (uid, cartType, isUseYohoCoin, skuList) => {
  15 + let param = {
  16 + method: 'app.Shopping.payment',
  17 + enable_red_envelopes: 0, // h5不返回红包
  18 + cart_type: cartType,
  19 + yoho_coin_mode: isUseYohoCoin,
  20 + uid: uid
  21 + };
  22 +
  23 + if (skuList) {
  24 + param.product_sku_list = skuList;
  25 + }
  26 +
  27 + return api.get('', param);
  28 +};