Blame view

apps/cart/models/ticketsConfirm.js 4.15 KB
lijing authored
1 2 3
'use strict';

const helpers = global.yoho.helpers;
李靖 authored
4
const _ = require('lodash');
lijing authored
5 6 7 8

// 展览票(单日票)skn
const SINGLE_TICKETS_SKN = 51335912;
郭成尧 authored
9 10 11
class ticketsConfirmModel extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
lijing authored
12 13
    }
郭成尧 authored
14 15 16 17 18 19 20
    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,
郭成尧 authored
21
            gift_card_code: param.gift_card_code || null,
郭成尧 authored
22 23 24 25
            yoho_coin_mode: param.yohoCoinMode ? param.yohoCoinMode : 0
        }}).then((result) => {
            return result;
        });
lijing authored
26 27
    }
郭成尧 authored
28 29 30 31 32 33 34 35
    yohoCoinCompute(orderCompute) {
        let $yohoCoinData = {
            totalYohoCoinNum: 0,
            yohoCoin: 0,
            useYohoCoin: 0,
            yohoCoinClick: 0,
            yohoCoinMsg: '',
            yoho_coin_pay_rule: []
lijing authored
36 37
        };
郭成尧 authored
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
        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 = '不满足有货币使用条件';
lijing authored
62
        }
郭成尧 authored
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

        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);
郭成尧 authored
97
                resu.orderCompute = _.get(result[0], 'data');
郭成尧 authored
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
            }
            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,
郭成尧 authored
113
            gift_card_code: param.gift_card_code || null,
郭成尧 authored
114 115
            qhy_union: '',
            udid: param.udid
郭成尧 authored
116 117 118 119 120 121 122
        }}).then((result) => {
            return result;
        });
    }
}

module.exports = ticketsConfirmModel;