|
|
var $ = require('yoho-jquery');
|
|
|
|
|
|
module.exports.getFavNum = function(sid, bid) {
|
|
|
return $.getJSON('/product/index/favnum', {sid: sid, bid: bid});
|
|
|
};
|
|
|
|
|
|
module.exports.addFav = function(sid, bid) {
|
|
|
if (!getUid()) {
|
|
|
return window.jumpUrl(window.signinUrl());
|
|
|
}
|
|
|
|
|
|
if (sid) {
|
|
|
return $.post('/product/shop/togglecollect', {
|
|
|
isFavorite: 0,
|
|
|
shopId: sid
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
return $.Deferred().resolve().promise(); //eslint-disable-line
|
|
|
} if (result.code === 401) {
|
|
|
return window.jumpUrl(window.signinUrl());
|
|
|
} else {
|
|
|
return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (bid) {
|
|
|
return $.post('/product/index/favoriteBrand', {
|
|
|
type: 'add',
|
|
|
brandId: bid
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
return $.Deferred().resolve().promise();//eslint-disable-line
|
|
|
} else if (result.code === 403) {
|
|
|
return window.jumpUrl(window.signinUrl());
|
|
|
} else {
|
|
|
return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports.cancelFav = function(sid, bid) {
|
|
|
if (!getUid()) {
|
|
|
return window.jumpUrl(window.signinUrl());
|
|
|
}
|
|
|
|
|
|
if (sid) {
|
|
|
return $.post('/product/shop/togglecollect', {
|
|
|
isFavorite: 1,
|
|
|
shopId: sid
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
return $.Deferred().resolve().promise();//eslint-disable-line
|
|
|
}
|
|
|
if (result.code === 401) {
|
|
|
return window.jumpUrl(window.signinUrl());
|
|
|
} else {
|
|
|
return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (bid) {
|
|
|
return $.post('/product/index/favoriteBrand', {
|
|
|
type: 'cancel',
|
|
|
brandId: bid
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
return $.Deferred().resolve().promise();//eslint-disable-line
|
|
|
} else if (result.code === 403) {
|
|
|
return window.jumpUrl(window.signinUrl());
|
|
|
} else {
|
|
|
return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports.statusFav = function(sid, bid) {
|
|
|
if (sid) {
|
|
|
return $.post('/product/index/isFavoriteShop', {
|
|
|
shopId: sid
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
return $.Deferred().resolve().promise();//eslint-disable-line
|
|
|
} else {
|
|
|
return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
|
|
|
if (bid) {
|
|
|
return $.getJSON('/product/index/isfav', {
|
|
|
brandId: bid
|
|
|
}).then(function(result) {
|
|
|
if (result.code === 200) {
|
|
|
return $.Deferred().resolve().promise();//eslint-disable-line
|
|
|
} else {
|
|
|
return $.Deferred().reject().promise();//eslint-disable-line
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
|
...
|
...
|
|