2023-05-08 05:11:29 +08:00
|
|
|
|
import BaseModel from './BaseModel.js'
|
|
|
|
|
|
|
|
|
|
const { Types } = BaseModel
|
|
|
|
|
|
|
|
|
|
const COLUMNS = {
|
|
|
|
|
// 用户ID,qq为数字
|
|
|
|
|
ltuid: {
|
|
|
|
|
type: Types.INTEGER,
|
|
|
|
|
primaryKey: true
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// MysUser类型,mys / hoyolab
|
|
|
|
|
type: {
|
|
|
|
|
type: Types.STRING,
|
|
|
|
|
defaultValue: 'mys',
|
|
|
|
|
notNull: true
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// CK
|
|
|
|
|
ck: Types.STRING,
|
|
|
|
|
device: Types.STRING,
|
2023-05-10 05:55:21 +08:00
|
|
|
|
uids: {
|
|
|
|
|
type: Types.STRING,
|
|
|
|
|
get () {
|
|
|
|
|
let data = this.getDataValue('uids')
|
|
|
|
|
let ret = {}
|
|
|
|
|
try {
|
|
|
|
|
ret = JSON.parse(data)
|
|
|
|
|
} catch (e) {
|
|
|
|
|
ret = {}
|
|
|
|
|
}
|
|
|
|
|
return ret
|
|
|
|
|
},
|
|
|
|
|
set (uids) {
|
|
|
|
|
this.setDataValue('uids', JSON.stringify(uids))
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-08 05:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class MysUserDB extends BaseModel {
|
|
|
|
|
static async find (ltuid = '', create = false) {
|
|
|
|
|
// DB查询
|
|
|
|
|
let mys = await MysUserDB.findByPk(ltuid)
|
|
|
|
|
if (!mys && create) {
|
|
|
|
|
mys = await MysUserDB.build({
|
|
|
|
|
ltuid
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return mys || false
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-09 11:03:38 +08:00
|
|
|
|
async saveDB (mys) {
|
|
|
|
|
if (!mys.ck || !mys.device || !mys.db) {
|
|
|
|
|
return false
|
2023-05-08 05:11:29 +08:00
|
|
|
|
}
|
2023-05-09 11:03:38 +08:00
|
|
|
|
let db = this
|
|
|
|
|
this.ck = mys.ck
|
|
|
|
|
this.type = mys.type
|
|
|
|
|
this.device = mys.device
|
2023-05-10 05:55:21 +08:00
|
|
|
|
this.uids = mys.uids
|
2023-05-09 11:03:38 +08:00
|
|
|
|
await db.save()
|
2023-05-08 05:11:29 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BaseModel.initDB(MysUserDB, COLUMNS)
|
|
|
|
|
await MysUserDB.sync()
|
|
|
|
|
|
|
|
|
|
export default MysUserDB
|