Blame view

apps/cart/models/easypay-api.js 4.9 KB
yyq authored
1 2 3 4 5 6 7 8 9
/**
 * address api
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/11/04
 */
'use strict';

const api = global.yoho.API;
yyq authored
10 11
const getEasyPaymentAsync = (uid, goods, activity) => {
    let param = {
yyq authored
12 13 14 15 16 17
        method: 'app.Shopping.easyPayment',
        uid: uid,
        cart_type: 'ordinary',
        product_sku_list: goods,
        yoho_coin_mode: 0,
        is_support_apple_pay: 'N'
yyq authored
18 19 20 21 22 23 24
    };

    if (activity) {
        param.activity_id = activity;
    }

    return api.get('', param, {code: 200});
yyq authored
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
};


/**
 * 订单计算API
 * @param uid [number] uid
 * @param cartType [string] 购物车类型,ordinary表示普通, advance表示预售
 * @param paymentType [number] 支付方式,1表示在线支付,2表示货到付款
 * @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
 * @param coin [number] 使用的有货币
 * @param useRedEnvelops [number] 红包
 * @param couponCode [string] 优惠券码
 * @param promotionCode [string] 优惠码
 * @param productSkuList [string] 限购商品

 */
const getEasypayComputeAsync = (uid, cartType, paymentType, deliveryWay, other) => {
    let param = {
yyq authored
43
        method: 'app.Shopping.easyCompute',
yyq authored
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        uid: uid,
        cart_type: cartType || 'ordinary',
        payment_type: paymentType,
        delivery_way: deliveryWay
    };

    // 其他可选参数
    if (other) {
        if (other.coin) {
            Object.assign(param, {
                use_yoho_coin: other.coin / 100
            });
        }

        if (other.useRedEnvelops) {
            Object.assign(param, {
                use_red_envelopes: other.useRedEnvelops
            });
        }

        if (other.couponCode) {
            Object.assign(param, {
                coupon_code: other.couponCode
            });
        }

        if (other.promotionCode) {
            Object.assign(param, {
                promotion_code: other.promotionCode
            });
        }

        if (other.productSkuList) {
            Object.assign(param, {
                product_sku_list: other.productSkuList
            });
yyq authored
80 81 82 83 84 85

            if (other.bundle) {
                Object.assign(param, {
                    activity_id: other.bundle
                });
            }
yyq authored
86
        }
yyq authored
87
yyq authored
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
    }

    return api.get('', param);
};

/**
 * 订单提交API
 * @param uid [number] uid
 * @param cartType [String] 购物车类型,ordinary表示普通, advance表示预售
 * @param addressId [String] 地址
 * @param deliveryTime [number] 寄送时间类型
 * @param deliveryWay [number] 配送方式,1表示普通快递,2表示顺丰速运
 * @param invoicesType [number] 发票类型
 * @param invoicesTitle [string] 发票抬头
 * @param invoicesContent [int] 发票类型
 * @param receiverMobile [string] 发票收人电话
 * @param coin [number] 使用的有货币金额
 * @param redEnvelopes [number] 使用的红包
 * @param paymentId [number] 支付id
 * @param paymentType [number] 支付类型
 * @param remark [string] 备注
 * @param couponCode [string] 优惠券码
 * @param printPrice [string] 是否打印价格
 */
yyq authored
112
const easypayOrderSubmitAsync = (uid, cartType, addressId, deliveryTime, deliveryWay, paymentType, paymentId, printPrice, other, remoteIp) => { // eslint-disable-line
yyq authored
113
    let param = {
yyq authored
114
        method: 'app.Shopping.easySubmit',
yyq authored
115 116 117 118 119 120 121 122 123 124 125 126 127 128
        uid: uid,
        cart_type: cartType || 'ordinary',
        address_id: addressId,
        delivery_time: deliveryTime,
        delivery_way: deliveryWay,
        payment_type: paymentType,
        payment_id: paymentId,
        is_print_price: printPrice
    };

    // 发票
    if (other.invoicesType) {
        Object.assign(param, {
            invoices_type: other.invoicesType,
yyq authored
129
            invoices_title: other.invoicesTitle,
yyq authored
130
            invoice_content: other.invoicesContent,
yyq authored
131
            receiverMobile: other.receiver
yyq authored
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        });
    }

    // 有货币
    if (other.coin) {
        Object.assign(param, {
            use_yoho_coin: other.coin / 100 // 有货币稀释
        });
    }

    // 红包
    if (other.redEnvelopes) {
        Object.assign(param, {
            use_red_envelopes: other.redEnvelopes
        });
    }

    // 备注
    if (other.remark) {
        Object.assign(param, {
            remark: other.remark
        });
    }

    // 优惠券码
    if (other.couponCode) {
        Object.assign(param, {
            coupon_code: other.couponCode
        });
    }

    if (other.productSkuList) {
        Object.assign(param, {
            product_sku_list: other.productSkuList
        });
yyq authored
167 168 169 170 171 172

        if (other.bundle) {
            Object.assign(param, {
                activity_id: other.bundle
            });
        }
yyq authored
173 174
    }
yyq authored
175 176 177 178 179 180
    if (other.udid) {
        Object.assign(param, {
            udid: other.udid
        });
    }
yyq authored
181
    return api.get('', param, {
yyq authored
182
        headers: {'X-Forwarded-For': remoteIp || ''}
yyq authored
183
    });
yyq authored
184 185 186 187 188 189 190
};

module.exports = {
    getEasyPaymentAsync,
    getEasypayComputeAsync,
    easypayOrderSubmitAsync
};