后台:礼包码
This commit is contained in:
@@ -21,7 +21,9 @@ import { CreateHeroes, deletRole } from '@pubUtils/roleUtil';
|
||||
import { RScriptRecordModel } from '@db/RScriptRecord';
|
||||
import { DicWar } from '@pubUtils/dictionary/DicWar';
|
||||
import { SkinModel } from '@db/Skin';
|
||||
import { SearchEquipParam, SearchHeroParam, SearchUserParam } from '@domain/backEndField/search';
|
||||
import { SearchEquipParam, SearchHeroParam, SearchUserParam, SearchGiftCodeParam } from '@domain/backEndField/search';
|
||||
import { CreateGiftCode, UpdateGiftCode } from '@domain/backEndField/params';
|
||||
import { isNumber } from 'util';
|
||||
|
||||
// import { resResult } from '@pubUtils/util';
|
||||
|
||||
@@ -624,70 +626,65 @@ export default class GMUsers extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
public async getGiftCodeList(page: number, pageSize: number, sortField: string, sortOrder: string, form: { name?: string, current?: boolean, } = {}) {
|
||||
public async getGiftCodeList(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchGiftCodeParam = {}) {
|
||||
const { ctx } = this;
|
||||
|
||||
const list = await GiftCodeModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GiftCodeModel.countByCondition( form )
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list: list.map(cur => {
|
||||
return { ...cur, beginTime: cur.beginTime.getTime(), endTime: cur.endTime.getTime() }
|
||||
}), total
|
||||
list: list.map(cur => ({...cur, env: ctx.app.config.realEnv })), total
|
||||
});
|
||||
}
|
||||
|
||||
public async updateGiftCode(id: string|number, params: any) {
|
||||
public async createAndGenerateGift(obj: any, count: number = 1) {
|
||||
const { ctx } = this;
|
||||
if(params.beginTime) params.beginTime = new Date(params.beginTime);
|
||||
if(params.endTime) params.endTime = new Date(params.endTime);
|
||||
let params = new CreateGiftCode(obj);
|
||||
if(!isNumber(count) || !params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let giftCode = await GiftCodeModel.createData(params);
|
||||
await GiftCodeDetailModel.generateMany(giftCode, count, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
public async updateGiftCode(id: number, obj: any) {
|
||||
const { ctx } = this;
|
||||
let params = new UpdateGiftCode(id, obj);
|
||||
if(!params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
try{
|
||||
params.goods = JSON.parse(params.goods);
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
return ctx.body = ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
const result = await GiftCodeModel.updateData(id, params, ctx.user?.uid);
|
||||
if(!result) return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
|
||||
public async generateGiftCode(id: number, generateType: 1|2, code: string, generateNum: number, codeLen: number = 8) {
|
||||
public async generateGiftCode(id: number, count: number) {
|
||||
const { ctx } = this;
|
||||
|
||||
let giftCode = await GiftCodeModel.findData(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
if(!isNumber(id) || !isNumber(count)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let length = 0, isLimit = false, count = 0, generateCode = '';
|
||||
if(generateType == 1) {
|
||||
let generateResult = await GiftCodeDetailModel.generateMany(giftCode, generateNum, codeLen, ctx.user?.uid);
|
||||
length = generateResult.length;
|
||||
isLimit = true;
|
||||
count = 1;
|
||||
} else if (generateType == 2) {
|
||||
let generateResult = await GiftCodeDetailModel.generateOne(giftCode, code, ctx.user?.uid);
|
||||
length = generateResult.length;
|
||||
generateCode = code;
|
||||
}
|
||||
if(length <= 0) return ctx.service.utils.resResult(STATUS.INTERNAL_ERR);
|
||||
giftCode = await GiftCodeModel.updateData(id, { generateCnt: giftCode.generateCnt + length, generateType, isLimit, count, generateCode }, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, { giftCode })
|
||||
let giftCode = await GiftCodeModel.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
await GiftCodeDetailModel.generateMany(giftCode, count, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
public async getGiftCodeDetails(id: number) {
|
||||
public async cancelGiftCode(id: number, isEnable: boolean) {
|
||||
const { ctx } = this;
|
||||
if(!isNumber(id)) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let giftCode = await GiftCodeModel.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
await GiftCodeModel.updateData(id, { isEnable }, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
public async getGiftCodeDetailFile(id: number) {
|
||||
const { ctx } = this;
|
||||
|
||||
let giftCode = await GiftCodeModel.findData(id);
|
||||
let giftCode = await GiftCodeModel.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let { generateCnt } = giftCode;
|
||||
let limit = 1000;
|
||||
let n = Math.ceil(generateCnt / limit);
|
||||
let codes: string[] = [];
|
||||
for(let i = 0; i < n; i++) {
|
||||
let giftCodeDetails = await GiftCodeDetailModel.findByGiftCode(giftCode);
|
||||
for(let {code} of giftCodeDetails) {
|
||||
codes.push(code);
|
||||
}
|
||||
let giftCodeDetails = await GiftCodeDetailModel.findAllCodeByGiftId(giftCode.id, giftCode.generateCnt);
|
||||
for(let {code} of giftCodeDetails) {
|
||||
codes.push(code);
|
||||
}
|
||||
console.log(id, codes.join())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user