|
|
@@ -36,7 +36,7 @@ class AddAccount extends API {
|
|
|
}
|
|
|
|
|
|
async onRequest(req, res) {
|
|
|
- let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notes } = req.body
|
|
|
+ let { uuid, session, student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notice_type, notes } = req.body
|
|
|
|
|
|
if ([uuid, session, student_num, email, auto_time, target_count, auto_day].some(value => value === '' || value === null || value === undefined))
|
|
|
return res.json({
|
|
|
@@ -50,19 +50,21 @@ class AddAccount extends API {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- if (!this.emailRegex.test(email)) {
|
|
|
- return res.json({
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
- msg: '请检查邮箱格式是否正确'
|
|
|
- })
|
|
|
- }
|
|
|
+ if (notice_type === 'email') {
|
|
|
+ if (!this.emailRegex.test(email)) {
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: '请检查邮箱格式是否正确'
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
- const emailDomain = email.split('@')[1].toLowerCase()
|
|
|
- if (this.banEmailList.includes(emailDomain))
|
|
|
- return res.json({
|
|
|
- ...BaseStdResponse.ERR,
|
|
|
- msg: `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
|
|
|
- })
|
|
|
+ const emailDomain = email.split('@')[1].toLowerCase()
|
|
|
+ if (this.banEmailList.includes(emailDomain))
|
|
|
+ return res.json({
|
|
|
+ ...BaseStdResponse.ERR,
|
|
|
+ msg: `暂不支持使用 ${emailDomain} 域名的邮箱,请更换其他邮箱后重试`
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
if (auto_run === 1 && (!Array.isArray(auto_day) || !auto_day.every(v => Number.isInteger(v) && v >= 0 && v <= 6)))
|
|
|
return res.json({
|
|
|
@@ -76,6 +78,18 @@ class AddAccount extends API {
|
|
|
})
|
|
|
|
|
|
let countSql = 'SELECT id, create_user, total_num FROM lepao_account WHERE student_num = ?'
|
|
|
+ countSql = `
|
|
|
+ SELECT
|
|
|
+ a.id, a.create_user, a.total_num, e.bind_code, e.bot_account
|
|
|
+ FROM
|
|
|
+ lepao_account a
|
|
|
+ LEFT JOIN
|
|
|
+ lepao_extra e
|
|
|
+ ON
|
|
|
+ a.student_num = e.student_num
|
|
|
+ WHERE
|
|
|
+ a.student_num = ?
|
|
|
+ `
|
|
|
let countRows = await db.query(countSql, [student_num])
|
|
|
|
|
|
if (!countRows)
|
|
|
@@ -101,14 +115,14 @@ class AddAccount extends API {
|
|
|
|
|
|
if (!id) {
|
|
|
if (countRows.length !== 0) {
|
|
|
- sql = 'UPDATE lepao_account SET create_user = ?, email = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, update_time = ?, notes = ?, auto_day = ? WHERE id = ?'
|
|
|
- r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, time, notes ?? '', JSON.stringify(auto_day), countRows[0].id])
|
|
|
+ sql = 'UPDATE lepao_account SET create_user = ?, email = ?, area = ?, auto_time = ?, auto_run = ?, target_count = ?, create_time = ?, update_time = ?, notes = ?, auto_day = ?, notice_type = ? WHERE id = ?'
|
|
|
+ r = await db.query(sql, [uuid, email, area, auto_time, auto_run, target_count, time, time, notes ?? '', JSON.stringify(auto_day), notice_type, countRows[0].id])
|
|
|
}
|
|
|
else {
|
|
|
const bind_code = await this.generateCode()
|
|
|
|
|
|
- sql = 'INSERT INTO lepao_account (student_num, email, area, auto_time, auto_run, target_count, create_user, create_time, notes, auto_day) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
|
|
- r = await db.query(sql, [student_num, email, area, auto_time, auto_run, target_count, uuid, time, notes ?? '', JSON.stringify(auto_day)])
|
|
|
+ sql = 'INSERT INTO lepao_account (student_num, email, area, auto_time, auto_run, target_count, create_user, create_time, notes, auto_day, notice_type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)'
|
|
|
+ r = await db.query(sql, [student_num, email, area, auto_time, auto_run, target_count, uuid, time, notes ?? '', JSON.stringify(auto_day), notice_type])
|
|
|
|
|
|
let faceSql = 'INSERT INTO lepao_extra (student_num, bind_code) VALUES (?, ?)'
|
|
|
let faceRows = await db.query(faceSql, [student_num, bind_code])
|
|
|
@@ -116,15 +130,20 @@ class AddAccount extends API {
|
|
|
return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
|
|
|
}
|
|
|
} else {
|
|
|
- sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, auto_run = ?, notes = ?, auto_day = ?, update_time = ? WHERE id = ?'
|
|
|
- r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', JSON.stringify(auto_day), time, id])
|
|
|
+ sql = 'UPDATE lepao_account SET student_num = ?, email = ?, area = ?, auto_time = ?, target_count = ?, auto_run = ?, notes = ?, auto_day = ?, update_time = ?, notice_type = ? WHERE id = ?'
|
|
|
+ r = await db.query(sql, [student_num, email, area, auto_time, target_count, auto_run, notes ?? '', JSON.stringify(auto_day), time, notice_type, id])
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
if (r && r.affectedRows > 0) {
|
|
|
res.json({
|
|
|
...BaseStdResponse.OK,
|
|
|
- id: r.insertId
|
|
|
+ id: r.insertId,
|
|
|
+ data: {
|
|
|
+ student_num, email, id, area, auto_time, auto_run, target_count, auto_day, notice_type, notes,
|
|
|
+ bind_code: countRows.length !== 0 ? countRows[0].bind_code : undefined,
|
|
|
+ bot_account: countRows.length !== 0 ? countRows[0].bot_account : undefined
|
|
|
+ }
|
|
|
})
|
|
|
} else {
|
|
|
return res.json({ ...BaseStdResponse.ERR, msg: '添加乐跑账号失败!数据库错误' })
|