credit.js
3.03 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
* Created by Tommy Huang on 18/03/21.
*/
const config = require('config-lite')({
config_basedir: __dirname,
config_dir: 'config'
})
const axios = require('axios')
const moment = require('moment')
const qs = require('querystring')
const uuid = require('uuid')
const Task = require('../models').Task
const User = require('../models').User
const Credit = require('../models').Credit
exports.submitTaskId = async (req, res) => {
try {
const id = req.user.userId
const taskId = req.body.taskId || ''
const userId = req.body.userId || ''
if (!userId || !taskId) throw new Error('参数不全')
if (id !== userId) throw new Error('token check fail')
const task = await Task.findOne({where: {
taskId: taskId,
userId: userId
}})
if (!task) {
const result = await Task.create({
id: uuid(),
taskId: taskId,
userId: userId
})
}
res.json({
success: 0
})
} catch (e) {
console.log(e)
res.json({
success: 0,
msg: e.message
})
}
}
exports.submitBaseInfo = async (req, res) => {
try {
const id = req.user.userId
const {wechatId, userId, area, address, contactAName, contactAPhone, contactARole, contactBName, contactBPhone, contactBRole} = req.body
if (!wechatId || !userId || !area || !address || !contactAName || !contactAPhone || !contactARole || !contactBName || !contactBPhone || !contactBRole) throw new Error('参数错误')
if (id !== userId) throw new Error('token验证失败')
const item = {
wechatAccount: wechatId,
area: area,
address: address,
contactA: contactAName,
contactAPhone: contactAPhone,
contactARole: contactARole,
contactB: contactBName,
contactBPhone: contactBPhone,
contactBRole: contactBRole,
baseCreatedTime: moment().format()
}
const record = await Credit.findOne({where: {userId: userId}})
if (record) {
const update = await record.update(item)
res.json({
success: 1
})
return
}
const user = await User.findOne({where: {id: userId}})
item.id = uuid()
item.name = user.name
item.idNo = user.idNo
item.userId = user.id
item.phone = user.phone
const create = await Credit.create(item)
res.json({
success: 1
})
} catch (e) {
console.log(e)
res.json({
success: 0,
msg: e.message
})
}
}
exports.getStatus = async (req, res) => {
try {
const id = req.user.userId
const userId = req.query.userId
if (id !== userId) throw new Error('token验证失败')
const info = await Credit.findOne({where: {userId: userId}})
let status = {
base: {
status: '未填写'
},
mobile: {
status: '未采集'
}
}
if (info) {
status.base.status = '已填写'
status.base.time = moment(info.baseCreatedTime).format('YYYY-MM-DD')
}
res.json({
success: 1,
status: status
})
} catch (e) {
console.log(e)
res.json({
success: 0,
msg: e.message
})
}
}