ticketsConfirm.js 3.58 KB
'use strict';

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

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

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

const 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;
};

const ticketsConfirm = (param) => {
    return api.all([
        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 = yohoCoinCompute(result[0].data.shopping_cart_data);
        }
        return resu;
    });
};


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

module.exports = {
    ticketsConfirm,
    submitTicket,
    checkTickets
};