78 lines
1.8 KiB
JavaScript
78 lines
1.8 KiB
JavaScript
const app = require('j7/app');
|
|
const BaseService = require('./baseservice');
|
|
const metaFactory = require('../metadata/factory');
|
|
|
|
class Present extends BaseService {
|
|
|
|
async init() {
|
|
const {err, conn} = await app.getDbConn('MarketDb0');
|
|
if (!err) {
|
|
throw 'db error:' + err;
|
|
}
|
|
this.conn = conn;
|
|
const presentList = metaFactory.getMetaByKey('PresentList', '0')['list'];
|
|
for (let i in presentList) {
|
|
const name = presentList[i];
|
|
const list = [];
|
|
metaFactory.traverseMetaList('Present' + name, (item) => {
|
|
list.push(item);
|
|
});
|
|
await this.processList(name, list);
|
|
}
|
|
}
|
|
|
|
async processList(name, list) {
|
|
for (let i in list){
|
|
const item = list[i];
|
|
await processOne(name, item);
|
|
}
|
|
}
|
|
|
|
async processOne(name, item) {
|
|
const gameId = 2006;
|
|
const seqId = 0;
|
|
const tokenId = 0;
|
|
const itemId = 0;
|
|
const tokenType = 0;
|
|
const sented = await this.isSented(name, item);
|
|
if (!sented) {
|
|
const nowTime = utils.getUtcTime();
|
|
const {err} = await this.conn.insert(
|
|
't_present',
|
|
[
|
|
['token_id', tokenId]
|
|
['batch_id', name],
|
|
['row_id', item['id']],
|
|
['seq_id', seqId],
|
|
['account', item['account']],
|
|
['game_id', gameId],
|
|
|
|
['bc_mint_itemid', itemId],
|
|
['bc_mint_token_type', tokenType],
|
|
|
|
['createtime', nowTime],
|
|
['modifytime', nowTime],
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
async isSented(name, item, seqId) {
|
|
const {err, row} = await this.conn.ormSelect(
|
|
't_present',
|
|
[
|
|
['batch_id', name],
|
|
['row_id', item['id']],
|
|
['seq_id', seqId],
|
|
]
|
|
);
|
|
if (err) {
|
|
throw err;
|
|
}
|
|
return row ? true : false;
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = Present;
|