后台:问卷
This commit is contained in:
@@ -294,8 +294,6 @@ export async function sendSurveyMail(code: string) {
|
||||
let survey = await SurveyModel.findBySurveyId(rec.surveyId);
|
||||
if(!survey) return false;
|
||||
|
||||
let reward = parseGoodStr(survey.reward);
|
||||
|
||||
await sendMailByContent(MAIL_TYPE.SEND_MAIL, rec.roleId, { goods: reward, params: [survey.mailContent] });
|
||||
await sendMailByContent(MAIL_TYPE.SEND_MAIL, rec.roleId, { goods: survey.reward, params: [survey.mailContent] });
|
||||
rec = await SurveyRecModel.send(rec.code);
|
||||
}
|
||||
@@ -114,6 +114,27 @@ export default class GameController extends Controller {
|
||||
return
|
||||
}
|
||||
|
||||
public async getSurveylist() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
ctx.body = await ctx.service.game.getSurveylist(page, pageSize, sortField, sortOrder, form);
|
||||
return
|
||||
}
|
||||
|
||||
public async updateSurvey() {
|
||||
const { ctx } = this;
|
||||
const param = ctx.request.body;
|
||||
ctx.body = await ctx.service.game.updateSurvey(param);
|
||||
return
|
||||
}
|
||||
|
||||
public async deleteSurvey() {
|
||||
const { ctx } = this;
|
||||
const param = ctx.request.body;
|
||||
ctx.body = await ctx.service.game.deleteSurvey(param.code);
|
||||
return
|
||||
}
|
||||
|
||||
public async getAccuse() {
|
||||
const { ctx } = this;
|
||||
const { page, pageSize, sortField, sortOrder, form } = ctx.request.body;
|
||||
|
||||
@@ -51,6 +51,9 @@ export default (app: Application) => {
|
||||
router.post('/api/game/stopserverregister', tokenParser, controller.game.stopServerRegister);
|
||||
router.post('/api/game/swicthserverstatus', tokenParser, controller.game.switchServerStatus);
|
||||
router.post('/api/game/getorderlist', tokenParser, controller.game.getOrderlist);
|
||||
router.post('/api/game/getsurveylist', controller.game.getSurveylist);
|
||||
router.post('/api/game/updatesurvey', controller.game.updateSurvey);
|
||||
router.post('/api/game/deletesurvey', controller.game.deleteSurvey)
|
||||
|
||||
router.post('/api/dic/getdicgoods', tokenParser, controller.game.getDicGoods);
|
||||
router.post('/api/dic/getdichero', tokenParser, controller.game.getDicHero);
|
||||
|
||||
@@ -15,10 +15,11 @@ import { ActivityGroupModel } from '@db/ActivityGroup';
|
||||
import { nowSeconds } from '@pubUtils/timeUtil';
|
||||
import { WhiteListModel } from '@db/RegionWhiteList';
|
||||
import { RoleModel } from '@db/Role';
|
||||
import { SearchMarqueeParam, SearchOrderParam } from '@domain/backEndField/search';
|
||||
import { SearchMarqueeParam, SearchOrderParam, SearchSurveyParam } from '@domain/backEndField/search';
|
||||
import { DicServerName } from '@pubUtils/dictionary/DicServerName';
|
||||
import { CreateRegionParam } from '@domain/backEndField/params';
|
||||
import { UserOrderModel } from '@db/UserOrder';
|
||||
import { SurveyModel } from '@db/Survery';
|
||||
|
||||
/**
|
||||
* Test Service
|
||||
@@ -251,4 +252,34 @@ export default class Game extends Service {
|
||||
list, total
|
||||
});
|
||||
}
|
||||
|
||||
public async getSurveylist(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchSurveyParam) {
|
||||
const { ctx } = this;
|
||||
const list = await SurveyModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await SurveyModel.countByCondition( form )
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list: list.map(cur => {
|
||||
return { ...cur, env: this.app.config.realEnv }
|
||||
}), total
|
||||
});
|
||||
}
|
||||
|
||||
public async updateSurvey(param: any) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let reward = JSON.parse(param.goods);
|
||||
|
||||
let result = await SurveyModel.updateSurvey(param.code, {...param, reward});
|
||||
if(!result) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
} catch(e) {
|
||||
return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
}
|
||||
|
||||
public async deleteSurvey(code: string) {
|
||||
const { ctx } = this;
|
||||
await SurveyModel.deleteSurvey(code);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
|
||||
import { SearchSurveyParam } from '../domain/backEndField/search';
|
||||
import { Reward } from '../domain/battleField/pvp';
|
||||
import { genCode } from '../pubUtils/util';
|
||||
|
||||
@index({ id: 1 })
|
||||
@index({ seasonNum: 1 })
|
||||
export default class Survey extends BaseModel {
|
||||
|
||||
@prop({ required: true })
|
||||
code: string; // 唯一id
|
||||
|
||||
@prop({ required: true })
|
||||
surveyId: string; // 问卷id
|
||||
|
||||
@prop({ required: true })
|
||||
surveyName: string; // 问卷id
|
||||
surveyName: string; // 问卷标题
|
||||
|
||||
@prop({ required: true })
|
||||
roleIndex: number; // 问卷id
|
||||
roleIndex: number; // 玩家
|
||||
|
||||
@prop({ required: true })
|
||||
reward: string; // 奖励
|
||||
@prop({ required: true, type: Reward, _id: false })
|
||||
reward: Reward[]; // 奖励
|
||||
|
||||
@prop({ required: true })
|
||||
mailContent: string; // 邮件文字
|
||||
@@ -24,9 +30,49 @@ export default class Survey extends BaseModel {
|
||||
let rec: SurveyType = await SurveyModel.findOne({ surveyId }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async updateSurvey(code: string, param: SurveyUpdate) {
|
||||
if(code == 'new') code = genCode(6);
|
||||
let rec: SurveyType = await SurveyModel.findOneAndUpdate({ code }, { $set: {...param, code} }, {new: true, upsert: true}).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async deleteSurvey(code: string) {
|
||||
let rec: SurveyType = await SurveyModel.deleteMany({ code }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
private static getSearchObj(form: SearchSurveyParam) {
|
||||
let searchObj = {};
|
||||
if (form.surveyName) searchObj['roleName'] = { $regex: new RegExp(form.surveyName.toString(), 'i') };
|
||||
return searchObj
|
||||
}
|
||||
|
||||
public static async findByCondition(page: number, pageSize: number, sortField: string = 'updatedAt', sortOrder: string = 'descend', form: SearchSurveyParam = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
let sort = {};
|
||||
if (sortField && sortOrder) {
|
||||
if (sortOrder == 'ascend') {
|
||||
sort[sortField] = 1;
|
||||
} else if (sortOrder == 'descend') {
|
||||
sort[sortField] = -1;
|
||||
}
|
||||
}
|
||||
const result: SurveyType[] = await SurveyModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
public static async countByCondition(form: SearchSurveyParam = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await SurveyModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const SurveyModel = getModelForClass(Survey);
|
||||
|
||||
export interface SurveyType extends Pick<DocumentType<Survey>, keyof Survey> {};
|
||||
export interface SurveyType extends Pick<DocumentType<Survey>, keyof Survey> { };
|
||||
export type SurveyUpdate = Partial<SurveyType>; // 将所有字段变成可选项
|
||||
|
||||
@@ -108,4 +108,8 @@ export interface SearchOrderParam {
|
||||
state?: number; // 订单状态
|
||||
createTimeStart?: number;
|
||||
createTimeEnd?: number;
|
||||
}
|
||||
}
|
||||
|
||||
export interface SearchSurveyParam {
|
||||
surveyName?: string; // 问卷名
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user