优化优惠券相关接口
This commit is contained in:
parent
17961ce320
commit
f7b28b80b8
@ -51,7 +51,7 @@
|
|||||||
},{
|
},{
|
||||||
"id": "e2far3lj30vwcpe0mf8",
|
"id": "e2far3lj30vwcpe0mf8",
|
||||||
"task": "DiscordJoin",
|
"task": "DiscordJoin",
|
||||||
"title": "Join Discord",
|
"title": "Join Counter Fire Discord",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"desc": "Join Counter Fire’s official Discord server",
|
"desc": "Join Counter Fire’s official Discord server",
|
||||||
"category": "Social Tasks",
|
"category": "Social Tasks",
|
||||||
@ -66,7 +66,7 @@
|
|||||||
}, {
|
}, {
|
||||||
"id": "e2fuah0j30vwcpe0my7",
|
"id": "e2fuah0j30vwcpe0my7",
|
||||||
"task": "TwitterRetweet",
|
"task": "TwitterRetweet",
|
||||||
"title": "Retweet on X",
|
"title": "Retweet a tweet",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"desc": "Retweet specific tweets",
|
"desc": "Retweet specific tweets",
|
||||||
"category": "Social Tasks",
|
"category": "Social Tasks",
|
||||||
@ -81,7 +81,7 @@
|
|||||||
}, {
|
}, {
|
||||||
"id": "e2fuah0j30vwcpe0my9",
|
"id": "e2fuah0j30vwcpe0my9",
|
||||||
"task": "TwitterLike",
|
"task": "TwitterLike",
|
||||||
"title": "Like the tweets on X",
|
"title": "Like a tweet",
|
||||||
"type": 1,
|
"type": 1,
|
||||||
"desc": "Like specific tweets",
|
"desc": "Like specific tweets",
|
||||||
"category": "Social Tasks",
|
"category": "Social Tasks",
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
"fastify-xml-body-parser": "^2.2.0",
|
"fastify-xml-body-parser": "^2.2.0",
|
||||||
"mongodb-extended-json": "^1.11.1",
|
"mongodb-extended-json": "^1.11.1",
|
||||||
"mongoose": "8.2.3",
|
"mongoose": "8.2.3",
|
||||||
"nanoid": "^5.0.7",
|
"nanoid": "^3.1.23",
|
||||||
"node-schedule": "^2.0.0",
|
"node-schedule": "^2.0.0",
|
||||||
"siwe": "^2.1.4",
|
"siwe": "^2.1.4",
|
||||||
"tracer": "^1.1.6",
|
"tracer": "^1.1.6",
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { isValidShareCode, isValidVoucherCode } from 'common/Utils'
|
import { isValidVoucherCode } from 'common/Utils'
|
||||||
import logger from 'logger/logger'
|
import logger from 'logger/logger'
|
||||||
import { ChestStatusEnum } from 'models/ActivityChest'
|
import { ChestStatusEnum } from 'models/ActivityChest'
|
||||||
import { SourceEnum, VoucherRecord, VoucherStatusEnum } from 'models/VoucherRecord'
|
import { SourceEnum, VoucherRecord, VoucherStatusEnum } from 'models/VoucherRecord'
|
||||||
import { generateNewChest } from 'services/game.svr'
|
import { generateNewChest } from 'services/game.svr'
|
||||||
import { SyncLocker, BaseController, router, role, ROLE_ANON, ZError } from 'zutils'
|
import { SyncLocker, BaseController, router, ZError } from 'zutils'
|
||||||
import { customAlphabet } from 'nanoid'
|
import { customAlphabet } from 'nanoid'
|
||||||
import { BASE52_ALPHABET } from 'common/Constants'
|
import { BASE52_ALPHABET } from 'common/Constants'
|
||||||
/**
|
/**
|
||||||
@ -13,7 +13,7 @@ class VoucherController extends BaseController {
|
|||||||
@router('post /api/voucher/generate')
|
@router('post /api/voucher/generate')
|
||||||
async generateTestVoucher(req) {
|
async generateTestVoucher(req) {
|
||||||
logger.db('generate_test_voucher', req)
|
logger.db('generate_test_voucher', req)
|
||||||
if (process.env.NODE_ENV !== 'development') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
throw new ZError(10, 'only support in development')
|
throw new ZError(10, 'only support in development')
|
||||||
}
|
}
|
||||||
const user = req.user
|
const user = req.user
|
||||||
@ -25,6 +25,12 @@ class VoucherController extends BaseController {
|
|||||||
const nanoid = customAlphabet(BASE52_ALPHABET, 8)
|
const nanoid = customAlphabet(BASE52_ALPHABET, 8)
|
||||||
for (let i = 0; i < num; i++) {
|
for (let i = 0; i < num; i++) {
|
||||||
let code = 'test' + nanoid()
|
let code = 'test' + nanoid()
|
||||||
|
// check if code exists
|
||||||
|
let record = await VoucherRecord.findOne({ code })
|
||||||
|
if (record) {
|
||||||
|
i--
|
||||||
|
continue
|
||||||
|
}
|
||||||
let voucher = new VoucherRecord({
|
let voucher = new VoucherRecord({
|
||||||
batch: 'test',
|
batch: 'test',
|
||||||
code,
|
code,
|
||||||
@ -38,7 +44,7 @@ class VoucherController extends BaseController {
|
|||||||
creator: user.id,
|
creator: user.id,
|
||||||
})
|
})
|
||||||
await voucher.save()
|
await voucher.save()
|
||||||
results.push(voucher.id)
|
results.push(voucher.code)
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
}
|
}
|
||||||
|
@ -23,12 +23,12 @@ export enum SourceEnum {
|
|||||||
@index({ user: 1, activity: 1 }, { unique: false })
|
@index({ user: 1, activity: 1 }, { unique: false })
|
||||||
@index({ code: 1, activity: 1 }, { unique: true })
|
@index({ code: 1, activity: 1 }, { unique: true })
|
||||||
@modelOptions({
|
@modelOptions({
|
||||||
schemaOptions: { collection: 'activity_box', timestamps: true },
|
schemaOptions: { collection: 'voucher_record', timestamps: true },
|
||||||
options: { allowMixed: Severity.ALLOW },
|
options: { allowMixed: Severity.ALLOW },
|
||||||
})
|
})
|
||||||
export class VoucherRecordClass extends BaseModule {
|
export class VoucherRecordClass extends BaseModule {
|
||||||
@prop()
|
@prop()
|
||||||
public batch: number
|
public batch: string
|
||||||
@prop()
|
@prop()
|
||||||
public code: string
|
public code: string
|
||||||
// 0 锁定, 1 未发放 2 已发放,待使用 9 已兑换
|
// 0 锁定, 1 未发放 2 已发放,待使用 9 已兑换
|
||||||
|
@ -3317,10 +3317,10 @@ nano-json-stream-parser@^0.1.2:
|
|||||||
resolved "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz"
|
resolved "https://registry.npmjs.org/nano-json-stream-parser/-/nano-json-stream-parser-0.1.2.tgz"
|
||||||
integrity sha512-9MqxMH/BSJC7dnLsEMPyfN5Dvoo49IsPFYMcHw3Bcfc2kN0lpHRBSzlMSVx4HGyJ7s9B31CyBTVehWJoQ8Ctew==
|
integrity sha512-9MqxMH/BSJC7dnLsEMPyfN5Dvoo49IsPFYMcHw3Bcfc2kN0lpHRBSzlMSVx4HGyJ7s9B31CyBTVehWJoQ8Ctew==
|
||||||
|
|
||||||
nanoid@^5.0.7:
|
nanoid@^3.1.23:
|
||||||
version "5.0.7"
|
version "3.3.7"
|
||||||
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-5.0.7.tgz#6452e8c5a816861fd9d2b898399f7e5fd6944cc6"
|
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.7.tgz#d0c301a691bc8d54efa0a2226ccf3fe2fd656bd8"
|
||||||
integrity sha512-oLxFY2gd2IqnjcYyOXD8XGCftpGtZP2AbHbOkthDkvRywH5ayNtPVy9YlOPcHckXzbLTCHpkb7FB+yuxKV13pQ==
|
integrity sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==
|
||||||
|
|
||||||
natural-compare@^1.4.0:
|
natural-compare@^1.4.0:
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user