new-user.js
891 Bytes
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
/**
* Created by TaoHuang on 2017/2/17.
*/
'use strict';
const _ = require('lodash');
const config = global.yoho.config;
const newUserService = require('../models/new-user-service');
const check = (req, res, next) => {
let uid = req.user.uid;
if (_.has(req.cookies, '__NEW_USER')) {
return res.json({
code: 200,
message: '已设置过新客'
});
}
newUserService.check(uid).then((result) => {
if (_.isEmpty(result)) {
return res.json({
code: 500,
message: '服务器错误'
});
}
res.cookie('__NEW_USER', (result.isNew ? 1 : 0), {domain: config.cookieDomain});
return res.json({
code: 200,
data: result,
message: '设置成功新客'
});
}).catch(next);
};
module.exports = {
check
};