pay-process.js 1.33 KB
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;

// 支付方式
const PAYMENTS = {
    ALIPAY: 18,
    WECHAT: 22
};

/**
 * 支付相关的数据处理函数
 */
const payTool = {

    /**
     * 支持的支付方式列表
     * @returns {[*,*]}
     */
    payAppInfo(orderCode) {
        return [{
            appIcon: '',
            payLink: helpers.urlFormat('/cart/index/new/pay', {
                payment: PAYMENTS.ALIPAY + '_platform',
                order_code: orderCode
            }),
            appId: 'alipay',
            app: '支付宝支付',
            hint: '支付宝钱包支付',
            subHint: '推荐支付宝用户使用'
        }, {
            appIcon: '',
            payLink: '',
            appId: 'weixin',
            app: '微信支付',
            hint: '推荐使用',
            subHint: ''
        }];
    },

    /**
     * 计算购买商品总数量
     * @param goodsArray
     * @returns {number}
     * @private
     */
    calBuyNumCount(goodsArray) {
        let buyNumCount = 0;

        if (_.isArray(goodsArray)) {
            _.forEach(goodsArray, value => {
                buyNumCount = value.buy_number ? parseInt(value.buy_number, 10) : 0;
            });
        }

        return buyNumCount;
    }
};

module.exports = {
    PAYMENTS,
    payTool
};