This commit is contained in:
aozhiwei 2022-04-16 21:15:33 +08:00
parent ddba7238ac
commit 61d36d414c

View File

@ -1,17 +1,77 @@
const app = require('j7/app');
const BaseService = require('./baseservice'); const BaseService = require('./baseservice');
const metaFactory = require('../metadata/factory'); const metaFactory = require('../metadata/factory');
class Present extends BaseService { class Present extends BaseService {
async init() { 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']; const presentList = metaFactory.getMetaByKey('PresentList', '0')['list'];
for (let i in presentList) { for (let i in presentList) {
const name = presentList[i]; const name = presentList[i];
const list = [];
metaFactory.traverseMetaList('Present' + name, (item) => { 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; module.exports = Present;