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

module.exports = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     * 电子票下单
     * @param uid 用户id
     * @param sku 商品sku
     * @param count 购买数量 1-4
     * @param mobile 手机号码
     * @param yohoCoin 有货币
     */
    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 this.get({data: params});
    }

    /**
     * 电子票添加和查询
     * @param uid 用户 id
     * @param sku 商品sku
     * @param count 购买数量 1-4
     * @param yohoCoin 有货币
     */
    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 this.get({data: params});
    }
};