brand-fav.js
3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
var $ = require('yoho-jquery');
exports.getFavNum = function(sid, bid) {
return $.getJSON('/product/index/favnum', {sid: sid, bid: bid})
.then(function(result) {
if (result.code === 200) {
return result.data.count;
} else {
return $.Deferred().reject().promise();// eslint-disable-line
}
});
};
exports.addFav = function(sid, bid) {
if (!getUid()) {// eslint-disable-line
return $.Deferred().reject(window.jumpUrl(window.signinUrl())).promise(); // eslint-disable-line
}
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
}
});
}
};
exports.cancelFav = function(sid, bid) {
if (!getUid()) {// eslint-disable-line
return $.Deferred().reject(window.jumpUrl(window.signinUrl())).promise();// eslint-disable-line
}
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
}
});
}
};
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
}
});
}
return $.Deferred().reject().promise();
};