alipay.service.js
1.29 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
const alipayRepository = require('./alipay.repository');
const { logger } = global.yoho;
const AlertAgent = require('../../utils/alert-manager');
/**
* dingtalk 告警
*/
const AlertType = {
MySQL: 0,
Knex: 1,
};
const alipayAlert = new AlertAgent('alipay', {
[AlertType.MySQL]: 'mysql error',
[AlertAgent.Knex]: 'knex insert error'
}, ['1735697170', '15210602915']);
async function create({ uid, alipayAccount, alipayName }) {
try {
const result = await alipayRepository.insert({
uid, alipayAccount, alipayName
});
if (!result) {
alipayAlert.send(AlertType.Knex);
return {
error: {
code: 500,
message: '服务器出错,请稍候再来提交'
}
};
}
return {
code: 200,
message: '提交成功'
};
} catch (e) {
if (e.code === 'ER_DUP_ENTRY') {
// 重复的情况
return {
error: {
code: 404,
message: '您已提交过支付宝信息,请不要重复提交!'
}
};
} else {
logger.error('mysql error =>', e);
alipayAlert.send(AlertType.MySQL, e.message);
return {
error: {
code: 500,
message: '服务器出错,请稍候再来提交'
}
};
}
}
}
module.exports = {
create
};