notify.js 1.3 KB

var $ = require('yoho-jquery');

function statusAsync(sku) {
    var uid = getUid();

    if (!uid) {
        return $.Deferred().reject({}).promise(); // eslint-disable-line
    }

    if (!sku) {
        return $.Deferred().reject({   // eslint-disable-line
            code: 403,
            message: '商品错误'
        }).promise();
    }

    return $.getJSON('/product/detail/notify/status', {sku: sku})
                .then(function(result) {
                    if (result.code === 200) {
                        result.data.sku = sku;
                        return result;
                    } else {
                        return $.Deferred().reject(result).promise(); // eslint-disable-line
                    }
                });
}

function addAsync(skn, sku) {
    var uid = getUid();

    if (!uid) {
        return $.Deferred().reject({ // eslint-disable-line
            code: 400,
            data: {
                refer: window.signinUrl()
            }
        }).promise();
    }

    if (skn && sku) {
        return $.post('/product/detail/notify/add', {skn: skn, sku: sku});
    } else {
        return $.Deferred().reject({ // eslint-disable-line
            code: 403,
            message: '商品错误'
        }).promise();
    }
}

module.exports = {
    statusAsync,
    addAsync
};