ticket-api.js 1.37 KB
/**
 * Created by TaoHuang on 2017/6/22.
 */

const api = global.yoho.API;

/**
 * 电子票下单
 * @param uid 用户id
 * @param sku 商品sku
 * @param count 购买数量 1-4
 * @param mobile 手机号码
 * @param yohoCoin 有货币
 */
function submit(uid, sku, count, mobile, yohoCoin, other = {}) {
    let params = {
        method: 'app.shopping.submitTicket',
        uid,
        product_sku: sku,
        buy_number: count,
        mobile: mobile
    };

    if (yohoCoin) {
        params.use_yoho_coin = yohoCoin / 100;
    }

    if (other.giftCard) {
        Object.assign(params, {
            gift_card_code: other.giftCard
        });
    }

    if (other.udid) {
        Object.assign(params, {
            udid: other.udid
        });
    }

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

/**
 * 电子票添加和查询
 * @param uid 用户 id
 * @param sku 商品sku
 * @param count 购买数量 1-4
 * @param yohoCoin 有货币
 */
function add(uid, sku, count, yohoCoin, other = {}) {
    let params = {
        method: 'app.shopping.ticket',
        uid,
        product_sku: sku,
        buy_number: count
    };

    if (yohoCoin) {
        params.use_yoho_coin = yohoCoin / 100;
    }

    if (other.giftCard) {
        Object.assign(params, {
            gift_card_code: other.giftCard
        });
    }

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

module.exports = {
    submit,
    add
};