渠道协议后台

This commit is contained in:
luying
2022-08-29 20:15:23 +08:00
parent 01b9fd9b43
commit 63a7b0f266
5 changed files with 81 additions and 3 deletions

View File

@@ -1,3 +1,4 @@
import { UpdateChannelParam } from '@domain/backEndField/params';
import { Controller } from 'egg';
export default class GameController extends Controller {
@@ -56,6 +57,21 @@ export default class GameController extends Controller {
return
}
public async getChannelInfo() {
const { ctx } = this;
ctx.body = await ctx.service.game.getChannelInfo();
return
}
public async updateChannel() {
const { ctx } = this;
const obj = ctx.request.body;
let param = new UpdateChannelParam(obj?.values||{});
ctx.body = await ctx.service.game.updateChannel(param);
return
}
public async getOnlineUsersByServer() {
const { ctx } = this;
ctx.body = await ctx.service.game.getOnlineUsersByServer();

View File

@@ -54,6 +54,8 @@ export default (app: Application) => {
router.post('/api/game/switchserverreview', tokenParser, controller.game.switchServerReview);
router.post('/api/game/getorderlist', tokenParser, controller.game.getOrderlist);
router.post('/api/game/getsurveylist', tokenParser, controller.game.getSurveylist);
router.post('/api/game/getchannelinfo', controller.game.getChannelInfo);
router.post('/api/game/updatechannel', controller.game.updateChannel);
router.post('/api/dic/getdicgoods', tokenParser, controller.game.getDicGoods);
router.post('/api/dic/getdichero', tokenParser, controller.game.getDicHero);

View File

@@ -16,10 +16,11 @@ import { WhiteListModel } from '@db/RegionWhiteList';
import { RoleModel } from '@db/Role';
import { SearchMarqueeParam, SearchOrderParam, SearchSurveyParam } from '@domain/backEndField/search';
import { DicServerName } from '@pubUtils/dictionary/DicServerName';
import { CreateRegionParam } from '@domain/backEndField/params';
import { CreateRegionParam, UpdateChannelParam } from '@domain/backEndField/params';
import { UserOrderModel } from '@db/UserOrder';
import { SurveyModel } from '@db/Survery';
import { RedisClient } from 'redis';
import { ChannelInfoModel } from '@db/ChannelInfo';
/**
* Test Service
@@ -61,6 +62,24 @@ export default class Game extends Service {
});
}
public async getChannelInfo() {
const { ctx } = this;
const list = await ChannelInfoModel.findAll();
return ctx.service.utils.resResult(STATUS.SUCCESS, {
list
});
}
public async updateChannel(param: UpdateChannelParam) {
const { ctx } = this;
if(!param.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
await ChannelInfoModel.updateChannel(param.code, param);
return ctx.service.utils.resResult(STATUS.SUCCESS);
}
public async getOnlineUsersByServer() {
const { ctx } = this;
let redisClient: RedisClient = ctx.app.context.redisClient;

View File

@@ -1,5 +1,7 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, modelOptions, ReturnModelType, mongoose } from '@typegoose/typegoose';
import { UpdateChannelParam } from '../domain/backEndField/params';
import { genCode } from '@pubUtils/util';
/**
* 私聊信息
@@ -28,7 +30,7 @@ export default class ChannelInfo extends BaseModel {
privacyPolicyLink: string; // 隐私协议
public static async findAll() {
const result: ChannelInfoType[] = await ChannelInfoModel.find().lean();
const result: ChannelInfoType[] = await ChannelInfoModel.find({}).select({ _id: false }).lean();
return result
}
@@ -36,6 +38,15 @@ export default class ChannelInfo extends BaseModel {
const result: ChannelInfoType = await ChannelInfoModel.findOne({ platform }).lean();
return result
}
public static async updateChannel(code: string, values: UpdateChannelParam) {
if(code == 'new') {
code = genCode(6);
}
delete values.code;
const result: ChannelInfoType = await ChannelInfoModel.findOneAndUpdate({ code }, values, { new: true, upsert: true }).lean();
return result
}
}
export let ChannelInfoModel: ReturnModelType<typeof ChannelInfo, {}>;

View File

@@ -4,7 +4,7 @@ import ServerStategy, { GMMail } from "../../db/ServerStategy";
import { RegionType } from "../../db/Region";
import { RewardInter } from "../../pubUtils/interface";
import { isTimestamp } from '../../pubUtils/util';
import { isDate } from "util";
import { isBoolean, isDate } from "util";
export class UpdateMailParams {
hasGoods: boolean = false; // 是否有道具
@@ -405,3 +405,33 @@ export class UpdateActivityParam {
return true;
}
}
export class UpdateChannelParam {
code: string; // 渠道标识
platform: string; // 渠道标识
desc: string; // 渠道描述
isDefaultPolicy: boolean; // 是否使用默认协议
userPolicyLink: string; // 用户协议
privacyPolicyLink: string; // 隐私协议
constructor(obj?: any) {
if(!obj) return;
this.code = obj.code;
this.platform = obj.platform;
this.desc = obj.desc;
this.isDefaultPolicy = obj.isDefaultPolicy;
this.userPolicyLink = obj.userPolicyLink;
this.privacyPolicyLink = obj.privacyPolicyLink;
}
checkParams() {
if(!this.code || !isString(this.code)) return false;
if(!this.platform || !isString(this.platform)) return false;
if(this.desc && !isString(this.desc)) return false;
if(!isBoolean(this.isDefaultPolicy)) return false;
if(this.userPolicyLink && !isString(this.userPolicyLink)) return false;
if(this.privacyPolicyLink && !isString(this.privacyPolicyLink)) return false;
return true;
}
}