notify.js
1.63 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
var $ = require('yoho-jquery');
exports.statusAsync = function(sku) {
var uid = window.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 = window.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(); // eslint-disable-line
} else {
return $.Deferred().reject(result).promise(); // eslint-disable-line
}
});
} else {
return $.Deferred().reject({ // eslint-disable-line
code: 403,
message: '商品错误'
}).promise();
}
};