alipay.controller.js
1.37 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
const InfluxSender = require('influx-batch-sender');
const alipayService = require('./alipay.service');
const { logger, config } = global.yoho;
/**
* 统计成功注册的用户数, 使用 APM db
*/
const monitor = new InfluxSender({
...config.report,
measurement: 'alipay-register-count',
duration: 1 * 60 * 1000, // 1m
immediate: false,
});
monitor.on('sendError', e => {
logger.error('alipay send monitor info', e);
});
monitor.on('failed', statusCode => {
logger.warn('alipay send monitor info', statusCode);
});
// monitor tags
const tags = {
appName: config.appName,
host: require('os').hostname(),
pid: process.pid,
};
function submit(req, res, next) {
const { alipayAccount, alipayName } = req.body;
const uid = req.user.uid;
if (!alipayAccount || !alipayName) {
return res.json({
code: 404,
message: '用户名或帐号不能为空,请重新填写'
});
}
alipayService.create({ uid, alipayAccount, alipayName }).then(result => {
if (result.error) {
return res.json(result.error);
}
try {
monitor.addMessage({
tags,
fields: {
uid,
ip: req.yoho.clientIp,
udid: req.yoho.udid
}
});
} catch (e) {
logger.error('alipay send monitor info, addMessage', e);
}
return res.json(result);
}).catch(next);
}
module.exports = {
submit
};