notify.js 1.57 KB

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

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

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

    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({data:{sku:sku}}).promise(); // eslint-disable-line
                    }
                });
};

exports.addAsync = function(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})
            .then(function(result) {
                if (result.code === 200) {
                    return $.Deferred().resolve().promise();
                } else {
                    return $.Deferred().reject(result).promise();
                }
            });
    } else {
        return $.Deferred().reject({ // eslint-disable-line
            code: 403,
            message: '商品错误'
        }).promise();
    }
};