ticketsConfirm.js 4.15 KB
'use strict';

const helpers = global.yoho.helpers;
const _ = require('lodash');

// 展览票(单日票)skn
const SINGLE_TICKETS_SKN = 51335912;

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

    checkTickets(param) {
        return this.get({data: {
            method: 'app.shopping.ticket',
            uid: param.uid,
            product_sku: param.productSku,
            buy_number: param.buyNumber,
            use_yoho_coin: param.useYohoCoin || 0,
            gift_card_code: param.gift_card_code || null,
            yoho_coin_mode: param.yohoCoinMode ? param.yohoCoinMode : 0
        }}).then((result) => {
            return result;
        });
    }

    yohoCoinCompute(orderCompute) {
        let $yohoCoinData = {
            totalYohoCoinNum: 0,
            yohoCoin: 0,
            useYohoCoin: 0,
            yohoCoinClick: 0,
            yohoCoinMsg: '',
            yoho_coin_pay_rule: []
        };

        if (!orderCompute || !orderCompute.yoho_coin_pay_rule) {
            return $yohoCoinData;
        }

        $yohoCoinData = {
            totalYohoCoinNum: orderCompute.total_yoho_coin_num ? orderCompute.total_yoho_coin_num : 0,
            yohoCoin: orderCompute.yoho_coin ? orderCompute.yoho_coin : 0,
            useYohoCoin: orderCompute.use_yoho_coin ? orderCompute.use_yoho_coin : 0,
            yohoCoinClick: 0,
            yohoCoinMsg: '',
            yoho_coin_pay_rule: orderCompute.yoho_coin_pay_rule
        };

        if ($yohoCoinData.totalYohoCoinNum < 100) {
            $yohoCoinData.yohoCoinMsg = '共' + $yohoCoinData.totalYohoCoinNum +
            '有货币,满' + orderCompute.yoho_coin_pay_rule.num_limit + '可用';
        } else if ($yohoCoinData.useYohoCoin > 0 || $yohoCoinData.yohoCoin > 0) {
            let yohoCoin = parseInt($yohoCoinData.useYohoCoin > 0 ?
                $yohoCoinData.useYohoCoin : $yohoCoinData.yohoCoin, 10).toFixed(2);

            $yohoCoinData.yohoCoinMsg = '可抵¥' + yohoCoin;
            $yohoCoinData.yohoCoinClick = 1;
        } else {
            $yohoCoinData.yohoCoinMsg = '不满足有货币使用条件';
        }

        return $yohoCoinData;
    }

    ticketsConfirm(param) {
        return Promise.all([
            this.checkTickets(param)
        ]).then((result) => {
            let resu = {
                goods: [],
                productSku: param.productSku,
                buyNumber: param.buyNumber,
                orderEnsurePage: true
            };

            if (_.get(result, '[0].data.goods_list', false)) {
                let bulid = [];

                result[0].data.goods_list.forEach((val) => {
                    bulid.push({
                        tickets: true,
                        id: val.product_sku,
                        thumb: helpers.image(val.goods_images, 120, 160),
                        name: val.product_name,
                        color: val.color_name,
                        size: val.product_skn === SINGLE_TICKETS_SKN ? '' : val.size_name,
                        count: val.buy_number,
                        price: parseInt(val.last_price, 10).toFixed(2)
                    });
                    resu.goods = bulid;
                });
                resu.cartPayData = result[0].data.shopping_cart_data.promotion_formula_list;
                resu.price = parseInt(result[0].data.shopping_cart_data.last_order_amount, 10).toFixed(2);
                resu.yohoCoinCompute = this.yohoCoinCompute(result[0].data.shopping_cart_data);
                resu.orderCompute = _.get(result[0], 'data');
            }
            return resu;
        });
    }


    // 门票下单
    submitTicket(param) {
        return this.get({data: {
            method: 'app.shopping.submitTicket',
            uid: param.uid,
            product_sku: param.productSku,
            buy_number: param.buyNumber,
            mobile: param.mobile,
            use_yoho_coin: param.useYohoCoin,
            gift_card_code: param.gift_card_code || null,
            qhy_union: '',
            udid: param.udid
        }}).then((result) => {
            return result;
        });
    }
}

module.exports = ticketsConfirmModel;