BuyNowModel.js 3.9 KB
/*
 * @Author: Targaryen
 * @Date: 2017-06-21 10:15:45
 * @Last Modified by: Targaryen
 * @Last Modified time: 2017-06-22 15:05:29
 */
const api = global.yoho.API;

class BuyNowModel extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    /**
     * 获取用户可用的优惠券张数
     * @param {*} params
     */
    countUsableCoupon(params) {
        return api.post('', {
            uid: params.uid,
            product_sku: params.product_sku,
            sku_type: params.sku_type || 'I',
            buy_number: params.buy_number
        }, {cache: false});
    }

    /**
     * 获取用户可用和不可用优惠券列表
     * @param {*} params
     */
    listCoupon(params) {
        return api.post('', {
            uid: params.uid,
            product_sku: params.product_sku,
            sku_type: params.sku_type || 'I',
            buy_number: params.buy_number
        }, {cache: false});
    }

    /**
     * 结算页面数据渲染
     * @param {*} params
     */
    payment(params) {
        let finalParams = {
            method: 'app.Buynow.payment',
            uid: params.uid,
            product_sku: params.product_sku,
            sku_type: params.sku_type || 'I',
            buy_number: params.buy_number || 1,
            yoho_coin_mode: params.yoho_coin_mode || 0, // 是否使用有货币
            yoho_bill_term: 0, // H5 不支持分期
            is_support_apple_pay: 'N', // H5 不支持 APPLE PAY
            activity_id: params.activity_id || 0,
            enable_red_envelopes: 0 // H5 不支持使用红包
        };

        return api.post('', finalParams, { cache: false });
    }

    /**
     * 数据改变,重新计算结算数据
     * @param {*} params
     */
    compute(params) {
        let finalParams = {
            method: 'app.Buynow.compute',
            uid: params.uid,
            product_sku: params.product_sku,
            sku_type: params.sku_type || 'I',
            buy_number: params.buy_number || 1,
            payment_type: params.payment_type || 1,
            delivery_way: params.delivery_way || 1,
            use_red_envelopes: 0,
            yoho_bill_term: 0,
            activity_id: params.activity_id || 0
        };

        if (params.use_yoho_coin) {
            finalParams.use_yoho_coin = params.use_yoho_coin;
        }

        if (params.coupon_code) {
            finalParams.coupon_code = params.coupon_code;
        }

        if (params.promotion_code) {
            finalParams.promotion_code = params.promotion_code;
        }

        if (params.coupon_code) {
            finalParams.coupon_code = params.coupon_code;
        }

        return api.post('', finalParams, {cache: false});
    }

    /**
     * 提交订单
     * @param {*} params
     */
    submit(params) {
        let finalParams = {
            method: 'app.Buynow.submit',
            uid: params.uid,
            cart_type: params.cart_type,
            address_id: params.address_id,
            delivery_time: params.delivery_time,
            delivery_way: params.delivery_way,
            use_yoho_coin: params.use_yoho_coin || 0,
            enable_red_envelopes: 0,
            payment_id: params.payment_id,
            payment_type: params.payment_type || 1,
            product_sku_list: JSON.stringify(params.product_sku_list),
            is_print_price: params.is_print_price || 'N',
            qhy_union: params.qhy_union
        };

        if (params.invoices_title) {
            finalParams.invoices_title = params.invoices_title;
        }

        if (params.invoices_type_id) {
            finalParams.invoices_type_id = params.invoices_type_id;
        }

        if (params.remark) {
            finalParams.remark = params.remark;
        }

        if (params.activity_id) {
            finalParams.activity_id = params.activity_id;
        }

        return api.post('', finalParams, {cache: false});
    }
}

module.exports = BuyNowModel;