magazine.js 1.59 KB
const _ = require('lodash');

class magazineModel extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }
    getMagazinePayment(uid, { sku, buyNumber }) {
        return this.get({data: {
            method: 'app.Shopping.virtual.ebook.payment',
            product_sku: sku,
            uid: uid,
            buy_number: buyNumber || 1
        }}).then((data) => {
            if (data.code === 200) {
                data = data.data;

                let totalPrice = '';
                let prices = _.forEach(_.get(data, 'eBook.prices'), val => {
                    if (val.select === 'Y') {
                        val.className = 'active';
                        totalPrice = val.price;
                    }
                });

                return {
                    goodsList: data.goods_list || [],
                    maxBuyNumber: _.get(data, 'eBook.maxBuyNumber'),
                    prices,
                    totalPrice,
                };
            }

            return {};
        });
    }
    computeMagazineOrder(uid, { sku, buyNumber }) {
        return this.post({data: {
            method: 'app.Shopping.virtual.ebook.compute',
            product_sku: sku,
            uid: uid,
            buy_number: buyNumber || 1
        }});
    }
    submitMagazineOrder(uid, { sku, buyNumber }) {
        return this.post({data: {
            method: 'app.Shopping.virtual.ebook.submit',
            product_sku: sku,
            uid: uid,
            help_uid: uid.toString(),
            buy_number: buyNumber || 1
        }});
    }
}

module.exports = magazineModel;