修改上报功能
This commit is contained in:
parent
b84907d029
commit
fe0eace046
@ -5,10 +5,11 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"dev:api": "ts-node -r tsconfig-paths/register src/api.ts",
|
||||
"prod:api": "NODE_ENV=production NODE_PATH=./dist node dist/api.js",
|
||||
"test": "ts-node -r tsconfig-paths/register src/test.ts",
|
||||
"dev:monitor": "ts-node -r tsconfig-paths/register src/google.monitor.ts",
|
||||
"prod:monitor": "NODE_ENV=production NODE_PATH=./dist node dist/google.monitor.js",
|
||||
"build": "tsc",
|
||||
"prod:api": "NODE_ENV=production NODE_PATH=./dist node dist/api.js",
|
||||
"lint": "eslint --ext .ts src/**",
|
||||
"format": "eslint --ext .ts src/** --fix"
|
||||
},
|
||||
|
@ -1 +1,2 @@
|
||||
pm2 start npm --name "pay-svr-release" --log-date-format "YYYY-MM-DD HH:mm:ss" -- run "prod:api"
|
||||
# pm2 start npm --name "google-monitor-release" --log-date-format "YYYY-MM-DD HH:mm:ss" -- run "prod:monitor"
|
||||
|
@ -18,7 +18,7 @@ export class ReportQueueClass extends BaseModule {
|
||||
// 渠道: alchemy, google, apple
|
||||
@prop()
|
||||
public channel: string
|
||||
// 本地记录id
|
||||
// 渠道返回的订单id
|
||||
@prop()
|
||||
public recordId: string
|
||||
// 游戏服订单id
|
||||
@ -61,6 +61,10 @@ export class ReportQueueClass extends BaseModule {
|
||||
txhash: this.txhash || '',
|
||||
}
|
||||
}
|
||||
|
||||
public static async findUnfinishedRecords(this: ReturnModelType<typeof ReportQueueClass>) {
|
||||
return this.find({ reportStatus: 0 }).exec()
|
||||
}
|
||||
}
|
||||
|
||||
export const ReportQueue = getModelForClass(ReportQueueClass, { existingConnection: ReportQueueClass.db })
|
||||
|
16
src/reqport.queue.ts
Normal file
16
src/reqport.queue.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import * as dotenv from 'dotenv'
|
||||
import logger from 'logger/logger'
|
||||
const envFile = process.env.NODE_ENV && process.env.NODE_ENV === 'production' ? `.env.production` : '.env.development'
|
||||
dotenv.config({ path: envFile })
|
||||
|
||||
import 'common/Extend'
|
||||
import PayReportSchedule from 'schedule/payreport.schedule'
|
||||
|
||||
async function main() {
|
||||
setInterval(function () {
|
||||
new PayReportSchedule().parseAllRecord()
|
||||
}, 60 * 60 * 1000)
|
||||
new PayReportSchedule().parseAllRecord()
|
||||
}
|
||||
|
||||
main()
|
@ -6,7 +6,7 @@ import { RedisClient } from 'redis/RedisClient'
|
||||
import { GooglePaySvr } from 'service/googlepay.svr'
|
||||
|
||||
/**
|
||||
* 定时更新发送邮件验证码的过期状态
|
||||
* 定时查询 google voided purchase
|
||||
*
|
||||
* * * * * *
|
||||
┬ ┬ ┬ ┬ ┬ ┬
|
||||
|
50
src/schedule/payreport.schedule.ts
Normal file
50
src/schedule/payreport.schedule.ts
Normal file
@ -0,0 +1,50 @@
|
||||
import { singleton } from 'decorators/singleton'
|
||||
import logger from 'logger/logger'
|
||||
import { ReportQueue } from 'modules/ReportQueue'
|
||||
import * as schedule from 'node-schedule'
|
||||
import { reportApplePurchaseResult, reportGooglePurchaseResult } from 'service/game.svr'
|
||||
|
||||
/**
|
||||
* 定时查询加密货币购买和内购上报失败的记录, 并重试
|
||||
*
|
||||
* * * * * *
|
||||
┬ ┬ ┬ ┬ ┬ ┬
|
||||
│ │ │ │ │ │
|
||||
│ │ │ │ │ └ day of week (0 - 7) (0 or 7 is Sun)
|
||||
│ │ │ │ └───── month (1 - 12)
|
||||
│ │ │ └────────── day of month (1 - 31)
|
||||
│ │ └─────────────── hour (0 - 23)
|
||||
│ └──────────────────── minute (0 - 59)
|
||||
└───────────────────────── second (0 - 59, OPTIONAL)
|
||||
*/
|
||||
@singleton
|
||||
export default class PayReportSchedule {
|
||||
async parseAllRecord() {
|
||||
try {
|
||||
let records = await ReportQueue.findUnfinishedRecords()
|
||||
for (let record of records) {
|
||||
logger.info(`parse record: ${record.id}, channel: ${record.channel}`)
|
||||
switch (record.channel) {
|
||||
case 'google':
|
||||
await reportGooglePurchaseResult([record.toInAppData()])
|
||||
break
|
||||
case 'apple':
|
||||
await reportApplePurchaseResult([record.toInAppData()])
|
||||
break
|
||||
case 'alchemy':
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logger.info('error query unfinished report records', err.message || err)
|
||||
}
|
||||
}
|
||||
scheduleAll() {
|
||||
const job = schedule.scheduleJob('1 * * * *', async () => {
|
||||
await this.parseAllRecord()
|
||||
})
|
||||
this.parseAllRecord()
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user