guochao.js
1.95 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
/* eslint-disable array-callback-return */
const {actGuochaoShop} = require('../../../db');
class Guochao extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
async checkFavs(uid, ids, type) {
try {
let result = await this.get({data: {
method: 'app.favorite.batchCheckIsFavorite',
favIds: ids,
uid: uid,
type: type }
});
if (result.code === 200) {
let obj = {};
result.data.map((value)=>{
obj[value.id] = value.favorite;
});
return Promise.resolve({code: 200, result: true, data: obj});
} else {
return Promise.resolve(result);
}
} catch (e) {
return Promise.resolve({code: 202, result: false, errorMsg: e});
}
}
async addFavAsync(uid, id, type) {
try {
let checkFlag = await this.get({ data: {
method: 'app.favorite.isFavorite',
id: id,
uid: uid,
type: type
}});
if (checkFlag.data) {
return Promise.resolve({code: 203, result: true, data: '已经收藏过'});
}
await this.get({
data: {
method: 'app.favorite.add',
id: id,
uid: uid,
type: type
}
});
let item = await actGuochaoShop.findOne({where: {shop_id: id}});
let result = await item.increment('collect_count');
return Promise.resolve({code: 200, result: true, data: result});
} catch (e) {
return Promise.resolve({code: 202, result: false, errorMsg: e});
}
}
async list() {
return actGuochaoShop.findAll({order: [['sort', 'desc']]});
}
}
module.exports = Guochao;