修改数据库 -> pikachu 新增平台管理API 修改游戏信息API
This commit is contained in:
parent
553fdadc84
commit
ee4eb8b4a7
@ -5,9 +5,6 @@ source /etc/profile
|
||||
npm install --prefer-offline --loglevel info --unsafe-perm=true --allow-root >> boundle.log
|
||||
echo 'copy node_modules to /data/publish/node_packages' >> boundle.log
|
||||
|
||||
npm run clear
|
||||
npm run init:roles
|
||||
|
||||
gulp
|
||||
|
||||
rm -rf ./src
|
||||
|
@ -1,136 +0,0 @@
|
||||
const path = require('path');
|
||||
|
||||
const rootPath = path.normalize(__dirname + '/..');
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
|
||||
const config = {
|
||||
development: {
|
||||
root: rootPath,
|
||||
app: {
|
||||
name: 'garfield'
|
||||
},
|
||||
host: 'http://192.168.199.210:3000',
|
||||
port: process.env.PORT || 2333,
|
||||
secret: 'garfield_sd*3,Jd32-xd..q(jd,vHdklx2z;3',
|
||||
session_name: 'sessionId_garfield',
|
||||
|
||||
special_sid: '58c939a11c2c7cf2653d7f07',
|
||||
empty_user: '000000000000000000000000',
|
||||
db_admin: 'mongodb://localhost/garfield-development',
|
||||
db_snoopy: 'mongodb://localhost/snoopy-development',
|
||||
db_dalmatian: 'mongodb://localhost/dalmatian-development',
|
||||
db_beagle: 'mongodb://localhost/beagle-development',
|
||||
db_ghost: 'mongodb://localhost/ghost-development',
|
||||
upload_to: rootPath + '/public/uploads',
|
||||
upload_prefix: '/uploads',
|
||||
short_url_base: 'https://wechat-test.kingsome.cn/s/',
|
||||
redis: {
|
||||
port: 6379,
|
||||
host: '127.0.0.1',
|
||||
password: ''
|
||||
},
|
||||
redisPublish: {
|
||||
port: 6379,
|
||||
host: '192.144.140.87',
|
||||
password: ''
|
||||
},
|
||||
cos: {
|
||||
SecretId: 'AKIDufGerr0GfssfTBiy3vZzEF4f3C8rfb3K',
|
||||
SecretKey: 'B7mDPL3WlobBgy4xgDUXO0NVP3ScWBcn'
|
||||
},
|
||||
cos_cdn: {
|
||||
SecretId: 'AKIDvmW8mNvCQVt9GEnd3JNH5lHKI8oJnv46',
|
||||
SecretKey: 'd6QZhgT7alnhR3VghWAg3FF4c2JMG1c2'
|
||||
},
|
||||
pay_weapp: {
|
||||
app_id: 'wxaf55c10d3fa61c40',
|
||||
app_secret: 'c081f58f46a3d599751235a7b393db01',
|
||||
message_template_id: 'BzyvfyHRic_prj7tYvzpfx5q_fAqgJRMN9iiuGiExxI',
|
||||
schedule_send_time: '0 30 19 * * *',
|
||||
message_value1: '晚间轻松一刻',
|
||||
message_value2: '邀新人玩游戏,赚零花钱',
|
||||
message_value3: '可以在小程序底部进入游戏哦'
|
||||
},
|
||||
youme: {
|
||||
baseUrl: 'https://api.youme.im/v1/im/',
|
||||
identifier: 'admin',
|
||||
app_key: 'YOUME4E2394D4CE21BAAFF95831701696A885A3372F6F',
|
||||
app_secret:
|
||||
'3vHmwZkDGHXsURalxCvg51ns11aCULY4HiGcQZQ4PG0vDJMZwTgK4oFOgo9dZJ/wsyHIT7lDQk8JMohNa6RqhmiwZ0Mo9yq0B3Glu/3yv+YYkqQbKXU/xHDEug6tiOTIf7Cz/GlZXxB5VuPyx2CgLCtNz8XUYAUrpnUM8yrAGkcBAAE='
|
||||
},
|
||||
ldap: {
|
||||
url: 'ldap://ldap.kingsome.cn:389',
|
||||
user: 'cn=admin,dc=kingsome,dc=cn',
|
||||
password: 'milesQWE321'
|
||||
},
|
||||
jwtSecret: 'OA3A$0X6*OsD*6oE',
|
||||
pay_record: 'http://192.168.100.23:7051/webapp/index.php',
|
||||
logs_path: '/Users/zhl/Documents/logs/garfield'
|
||||
},
|
||||
|
||||
production: {
|
||||
root: rootPath,
|
||||
app: {
|
||||
name: 'garfield'
|
||||
},
|
||||
host: 'http://192.168.199.210:3000',
|
||||
port: process.env.PORT || 3000,
|
||||
secret: 'garfield_sd*3,Jd32-xd..q(jd,vHdklx2z;3',
|
||||
session_name: 'sessionId_garfield',
|
||||
|
||||
special_sid: '58c939a11c2c7cf2653d7f07',
|
||||
empty_user: '000000000000000000000000',
|
||||
db_admin: 'mongodb://localhost/garfield-production',
|
||||
db_snoopy: 'mongodb://localhost/snoopy-production',
|
||||
db_dalmatian: 'mongodb://localhost/dalmatian-production',
|
||||
db_beagle: 'mongodb://localhost/beagle-production',
|
||||
db_ghost: 'mongodb://localhost/ghost-production',
|
||||
upload_to: rootPath + '/public/uploads',
|
||||
upload_prefix: '/uploads',
|
||||
short_url_base: 'https://wechat-test.kingsome.cn/s/',
|
||||
redis: {
|
||||
port: 6379,
|
||||
host: '127.0.0.1',
|
||||
password: ''
|
||||
},
|
||||
redisPublish: {
|
||||
port: 6379,
|
||||
host: '192.144.140.87',
|
||||
password: ''
|
||||
},
|
||||
cos: {
|
||||
SecretId: 'AKIDufGerr0GfssfTBiy3vZzEF4f3C8rfb3K',
|
||||
SecretKey: 'B7mDPL3WlobBgy4xgDUXO0NVP3ScWBcn'
|
||||
},
|
||||
cos_cdn: {
|
||||
SecretId: 'AKIDvmW8mNvCQVt9GEnd3JNH5lHKI8oJnv46',
|
||||
SecretKey: 'd6QZhgT7alnhR3VghWAg3FF4c2JMG1c2'
|
||||
},
|
||||
pay_weapp: {
|
||||
app_id: 'wxaf55c10d3fa61c40',
|
||||
app_secret: 'c081f58f46a3d599751235a7b393db01',
|
||||
message_template_id: 'BzyvfyHRic_prj7tYvzpfx5q_fAqgJRMN9iiuGiExxI',
|
||||
schedule_send_time: '0 30 19 * * *',
|
||||
message_value1: '晚间轻松一刻',
|
||||
message_value2: '邀新人玩游戏,赚零花钱',
|
||||
message_value3: '可以在小程序底部进入游戏哦'
|
||||
},
|
||||
youme: {
|
||||
baseUrl: 'https://api.youme.im/v1/im/',
|
||||
identifier: 'admin',
|
||||
app_key: 'YOUME4E2394D4CE21BAAFF95831701696A885A3372F6F',
|
||||
app_secret:
|
||||
'3vHmwZkDGHXsURalxCvg51ns11aCULY4HiGcQZQ4PG0vDJMZwTgK4oFOgo9dZJ/wsyHIT7lDQk8JMohNa6RqhmiwZ0Mo9yq0B3Glu/3yv+YYkqQbKXU/xHDEug6tiOTIf7Cz/GlZXxB5VuPyx2CgLCtNz8XUYAUrpnUM8yrAGkcBAAE='
|
||||
},
|
||||
ldap: {
|
||||
url: 'ldap://ldap.kingsome.cn:389',
|
||||
user: 'cn=admin,dc=kingsome,dc=cn',
|
||||
password: 'milesQWE321'
|
||||
},
|
||||
jwtSecret: 'OA3A$0X6*OsD*6oE',
|
||||
pay_record: 'http://192.168.100.23:7051/webapp/index.php',
|
||||
logs_path: '/var/logs'
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = config[env];
|
63
fixtures/platforms.js
Normal file
63
fixtures/platforms.js
Normal file
@ -0,0 +1,63 @@
|
||||
const ObjectId = require('pow-mongodb-fixtures').createObjectId;
|
||||
const ISODate = function(dateStr) {
|
||||
return new Date(dateStr);
|
||||
};
|
||||
|
||||
exports.platforms = [
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e886378d'),
|
||||
name: '内部测试',
|
||||
name_en: 'test',
|
||||
platform_id: '6000',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e886378e'),
|
||||
name: '微信',
|
||||
name_en: 'weixin',
|
||||
platform_id: '6001',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e886378f'),
|
||||
name: 'QQ 玩一玩',
|
||||
name_en: 'qq',
|
||||
platform_id: '6002',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e8863790'),
|
||||
name: 'OPPO 小游戏',
|
||||
name_en: 'oppo',
|
||||
platform_id: '6003',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e8863791'),
|
||||
name: 'VIVO 快游戏',
|
||||
name_en: 'vivo',
|
||||
platform_id: '6004',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e8863792'),
|
||||
name: '百度',
|
||||
name_en: 'baidu',
|
||||
platform_id: '6005',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e8863793'),
|
||||
name: '抖音',
|
||||
name_en: 'douyin',
|
||||
platform_id: '6006',
|
||||
comment: ''
|
||||
},
|
||||
{
|
||||
_id: ObjectId('5ceb909ef204f241e8863794'),
|
||||
name: 'Facebook 小游戏',
|
||||
name_en: 'facebook',
|
||||
platform_id: '6501',
|
||||
comment: ''
|
||||
}
|
||||
];
|
112
fixtures/system_dics.js
Normal file
112
fixtures/system_dics.js
Normal file
@ -0,0 +1,112 @@
|
||||
const ObjectId = require('pow-mongodb-fixtures').createObjectId;
|
||||
const ISODate = function(dateStr) {
|
||||
return new Date(dateStr);
|
||||
};
|
||||
|
||||
exports.system_dics = [
|
||||
/* 1 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f396'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': '6000',
|
||||
'value': '内部测试',
|
||||
'type': 'platform',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 2 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f397'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': '6001',
|
||||
'value': '微信',
|
||||
'type': 'platform',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 3 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f398'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': '6002',
|
||||
'value': 'QQ玩一玩',
|
||||
'type': 'platform',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 4 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f399'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': 'reborn',
|
||||
'value': {title: '复活', type: 'bool'},
|
||||
'type': 'game_cfg',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 5 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f3a0'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': 'share_reward',
|
||||
'value': {title: '开启分享', type: 'bool'},
|
||||
'type': 'game_cfg',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 6 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f3a1'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': 'exchange_reward',
|
||||
'value': {title: '交易', type: 'bool'},
|
||||
'type': 'game_cfg',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 7 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f3a2'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': 'version',
|
||||
'value': {title: '版本', type: 'string'},
|
||||
'type': 'game_cfg',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
/* 8 */
|
||||
{
|
||||
'_id': ObjectId('572f646972fbeed78781f3a3'),
|
||||
'updatedAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'createdAt': ISODate('2018-10-17T20:20:53.609Z'),
|
||||
'key': 'ggl',
|
||||
'value': {title: '开启活动', type: 'bool'},
|
||||
'type': 'game_cfg',
|
||||
'createdBy': '572f646972fbeed78781f396',
|
||||
'lastModifiedBy': '572f646972fbeed78781f396',
|
||||
'deleted': false,
|
||||
'__v': 0,
|
||||
},
|
||||
|
||||
];
|
18
init-data.js
Normal file
18
init-data.js
Normal file
@ -0,0 +1,18 @@
|
||||
const pmf = require('pow-mongodb-fixtures');
|
||||
const config = require('./config/config');
|
||||
const path = require('path');
|
||||
|
||||
const fixtures = pmf.connect(config.db_admin);
|
||||
const fixturesDir = path.join(config.root, '/fixtures');
|
||||
|
||||
const platforms = require('./fixtures/platforms');
|
||||
|
||||
// fixtures.load(__dirname + '/fixtures/platforms.js', function(err) {
|
||||
// if (err) throw err;
|
||||
// });
|
||||
// fixtures.load(__dirname + '/fixtures/roles.js', function(err) {
|
||||
// if (err) throw err;
|
||||
// });
|
||||
fixtures.load(__dirname + '/fixtures/system_dics.js', function(err) {
|
||||
if (err) throw err;
|
||||
});
|
@ -6,7 +6,7 @@ const fixtures = pmf.connect(config.db_admin);
|
||||
const fixturesDir = path.join(config.root, '/fixtures');
|
||||
|
||||
fixtures.clearAndLoad(fixturesDir, function(err) {
|
||||
if (err) console.log(err);
|
||||
if (err) throw err;
|
||||
console.log('roles 数据加载完毕!');
|
||||
process.exit(0);
|
||||
});
|
||||
|
@ -120,19 +120,19 @@ app.use(
|
||||
);
|
||||
app.use(expressValidator());
|
||||
app.use(cookieParser(config.secret));
|
||||
app.use(
|
||||
session({
|
||||
secret: config.secret,
|
||||
resave: false,
|
||||
saveUninitialized: false,
|
||||
name: config.session_name,
|
||||
store: new MongoStore({
|
||||
url: config.db_admin,
|
||||
autoReconnect: true,
|
||||
collection: 'garfield_sessions'
|
||||
})
|
||||
})
|
||||
);
|
||||
// app.use(
|
||||
// session({
|
||||
// secret: config.secret,
|
||||
// resave: false,
|
||||
// saveUninitialized: false,
|
||||
// name: config.session_name,
|
||||
// store: new MongoStore({
|
||||
// url: config.db_admin,
|
||||
// autoReconnect: true,
|
||||
// collection: 'garfield_sessions'
|
||||
// })
|
||||
// })
|
||||
// );
|
||||
app.use(flash());
|
||||
app.use(expressUtils());
|
||||
app.use(methodOverride());
|
||||
|
@ -1,139 +1,167 @@
|
||||
import GameInfo from '../../models/snoopy/GameInfo';
|
||||
// import GameInfo from '../../models/snoopy/GameInfo';
|
||||
import GameInfo from '../../models/admin/GameInfo';
|
||||
import { Router } from 'express';
|
||||
|
||||
const router = new Router();
|
||||
|
||||
router.get('/list', async function gameListCtrl(req, res, next) {
|
||||
const query = req.query || {};
|
||||
query.deleted = false;
|
||||
// router.get('/list', async function gameListCtrl(req, res, next) {
|
||||
// const query = req.query || {};
|
||||
// query.deleted = false;
|
||||
|
||||
try {
|
||||
let result = await GameInfo.find(query).populate('linked_games');
|
||||
// 获取虚拟字段数据
|
||||
result = result.map(item => {
|
||||
const game = JSON.parse(JSON.stringify(item));
|
||||
game.status_show = item.status_show;
|
||||
game.show_type = item.show_type;
|
||||
game.platform_show = item.platform_show;
|
||||
return game;
|
||||
});
|
||||
res.send({
|
||||
errcode: 0,
|
||||
gameList: result
|
||||
});
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// try {
|
||||
// let result = await GameInfo.find(query).populate('linked_games');
|
||||
// // 获取虚拟字段数据
|
||||
// result = result.map(item => {
|
||||
// const game = JSON.parse(JSON.stringify(item));
|
||||
// game.status_show = item.status_show;
|
||||
// game.show_type = item.show_type;
|
||||
// game.platform_show = item.platform_show;
|
||||
// return game;
|
||||
// });
|
||||
// res.send({
|
||||
// errcode: 0,
|
||||
// gameList: result
|
||||
// });
|
||||
// } catch (err) {
|
||||
// next(err);
|
||||
// }
|
||||
// });
|
||||
|
||||
router.get('/type', async function gameTypeCtrl(req, res, next) {
|
||||
const gameType = GameInfo.all_type();
|
||||
const result = [];
|
||||
for (const key in gameType) {
|
||||
if ({}.hasOwnProperty.call(gameType, key)) {
|
||||
result.push({
|
||||
value: key,
|
||||
name: gameType[key]
|
||||
});
|
||||
}
|
||||
}
|
||||
res.send({
|
||||
errcode: 0,
|
||||
gameType: result
|
||||
});
|
||||
});
|
||||
// router.get('/type', async function gameTypeCtrl(req, res, next) {
|
||||
// const gameType = GameInfo.all_type();
|
||||
// const result = [];
|
||||
// for (const key in gameType) {
|
||||
// if ({}.hasOwnProperty.call(gameType, key)) {
|
||||
// result.push({
|
||||
// value: key,
|
||||
// name: gameType[key]
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// res.send({
|
||||
// errcode: 0,
|
||||
// gameType: result
|
||||
// });
|
||||
// });
|
||||
|
||||
router.get('/platform', async function platformCtrl(req, res, next) {
|
||||
const platform = GameInfo.all_platform();
|
||||
const result = [];
|
||||
for (const key in platform) {
|
||||
if ({}.hasOwnProperty.call(platform, key)) {
|
||||
result.push({
|
||||
value: key,
|
||||
name: platform[key]
|
||||
});
|
||||
}
|
||||
}
|
||||
res.send({
|
||||
errcode: 0,
|
||||
platform: result
|
||||
});
|
||||
});
|
||||
// router.get('/platform', async function platformCtrl(req, res, next) {
|
||||
// const platform = GameInfo.all_platform();
|
||||
// const result = [];
|
||||
// for (const key in platform) {
|
||||
// if ({}.hasOwnProperty.call(platform, key)) {
|
||||
// result.push({
|
||||
// value: key,
|
||||
// name: platform[key]
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// res.send({
|
||||
// errcode: 0,
|
||||
// platform: result
|
||||
// });
|
||||
// });
|
||||
|
||||
router.get('/status', async function statusCtrl(req, res, next) {
|
||||
const platform = GameInfo.status_list();
|
||||
res.send({
|
||||
errcode: 0,
|
||||
statusList: platform
|
||||
});
|
||||
});
|
||||
// router.get('/status', async function statusCtrl(req, res, next) {
|
||||
// const platform = GameInfo.status_list();
|
||||
// res.send({
|
||||
// errcode: 0,
|
||||
// statusList: platform
|
||||
// });
|
||||
// });
|
||||
|
||||
router.post('/edit', async function gameEditCtrl(req, res, next) {
|
||||
// router.post('/edit', async function gameEditCtrl(req, res, next) {
|
||||
// const body = req.body;
|
||||
// try {
|
||||
// const searchResult = await GameInfo.findOne({
|
||||
// _id: body._id,
|
||||
// deleted: false
|
||||
// });
|
||||
// if (searchResult) {
|
||||
// const saveResult = await GameInfo.updateOne({ _id: body._id }, body);
|
||||
// res.send({
|
||||
// errcode: 0
|
||||
// });
|
||||
// } else {
|
||||
// res.send({
|
||||
// errcode: 1,
|
||||
// errmsg: '该游戏已被删除,无法编辑!'
|
||||
// });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// next(err);
|
||||
// }
|
||||
// });
|
||||
|
||||
// router.post('/add', async function gameAddCtrl(req, res, next) {
|
||||
// const body = req.body;
|
||||
// try {
|
||||
// const searchResult = await GameInfo.findOne({
|
||||
// game_id: body.game_id,
|
||||
// deleted: false
|
||||
// });
|
||||
// if (searchResult) {
|
||||
// res.send({
|
||||
// errcode: 1,
|
||||
// errmsg: '游戏 ID 已存在!'
|
||||
// });
|
||||
// } else {
|
||||
// const newGame = new GameInfo(body);
|
||||
// const saveResult = await newGame.save();
|
||||
// res.send({
|
||||
// errcode: 0,
|
||||
// userInfo: saveResult
|
||||
// });
|
||||
// }
|
||||
// } catch (err) {
|
||||
// next(err);
|
||||
// }
|
||||
// });
|
||||
|
||||
// router.post('/del', async function gameDelCtrl(req, res, next) {
|
||||
// const body = req.body;
|
||||
// const gameList = body.gameList;
|
||||
// try {
|
||||
// for (let i = 0; i < gameList.length; i++) {
|
||||
// const delResult = await GameInfo.updateOne(
|
||||
// { _id: gameList[i]._id },
|
||||
// {
|
||||
// deleted: true
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// res.send({
|
||||
// errcode: 0
|
||||
// });
|
||||
// } catch (err) {
|
||||
// next(err);
|
||||
// }
|
||||
// });
|
||||
|
||||
router.post('/save', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
try {
|
||||
const searchResult = await GameInfo.findOne({
|
||||
_id: body._id,
|
||||
deleted: false
|
||||
const search = await GameInfo.findOne({
|
||||
$or: [
|
||||
{ game_id: body.game_id },
|
||||
{ game_name: body.game_name },
|
||||
{ game_name_en: body.game_name_en }
|
||||
]
|
||||
});
|
||||
if (searchResult) {
|
||||
const saveResult = await GameInfo.updateOne({ _id: body._id }, body);
|
||||
if (search) {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '游戏已存在!'
|
||||
});
|
||||
} else {
|
||||
const newGameInfo = new GameInfo(body);
|
||||
const result = await newGameInfo.save();
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '该游戏已被删除,无法编辑!'
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/add', async function gameAddCtrl(req, res, next) {
|
||||
const body = req.body;
|
||||
try {
|
||||
const searchResult = await GameInfo.findOne({
|
||||
game_id: body.game_id,
|
||||
deleted: false
|
||||
});
|
||||
if (searchResult) {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '游戏 ID 已存在!'
|
||||
});
|
||||
} else {
|
||||
const newGame = new GameInfo(body);
|
||||
const saveResult = await newGame.save();
|
||||
res.send({
|
||||
errcode: 0,
|
||||
userInfo: saveResult
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/del', async function gameDelCtrl(req, res, next) {
|
||||
const body = req.body;
|
||||
const gameList = body.gameList;
|
||||
try {
|
||||
for (let i = 0; i < gameList.length; i++) {
|
||||
const delResult = await GameInfo.updateOne(
|
||||
{ _id: gameList[i]._id },
|
||||
{
|
||||
deleted: true
|
||||
}
|
||||
);
|
||||
}
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Router } from 'express';
|
||||
import gamesRouter from './games'
|
||||
import settingsRouter from './settings'
|
||||
import platformsRouter from './platforms'
|
||||
|
||||
|
||||
|
||||
@ -10,6 +11,7 @@ const router = new Router();
|
||||
|
||||
router.use('/', gamesRouter);
|
||||
router.use('/settings', settingsRouter);
|
||||
router.use('/platforms', platformsRouter);
|
||||
|
||||
|
||||
|
||||
|
72
src/controllers/games/platforms.js
Normal file
72
src/controllers/games/platforms.js
Normal file
@ -0,0 +1,72 @@
|
||||
import Platform from '../../models/admin/Platform';
|
||||
import { Router } from 'express';
|
||||
|
||||
const router = new Router();
|
||||
// 获取平台列表
|
||||
router.get('/list', async (req, res, next) => {
|
||||
try {
|
||||
const result = await Platform.find({});
|
||||
res.send({
|
||||
errcode: 0,
|
||||
platformList: result
|
||||
});
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// 新增平台
|
||||
router.post('/save', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
try {
|
||||
const search = await Platform.findOne({
|
||||
$or: [
|
||||
{ name: body.name },
|
||||
{ name_en: body.name_en },
|
||||
{ platform_id: body.platform_id }
|
||||
]
|
||||
});
|
||||
if (search) {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '平台名称或平台 ID 已存在!'
|
||||
});
|
||||
} else {
|
||||
const newPlatform = new Platform(body);
|
||||
const result = await newPlatform.save();
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
// 编辑平台信息
|
||||
router.post('/edit', async (req, res, next) => {
|
||||
const body = req.body;
|
||||
try {
|
||||
const search = await Platform.findOne({ platform_id: body.platform_id });
|
||||
console.log(search);
|
||||
if (search) {
|
||||
const result = await Platform.updateOne(
|
||||
{ platform_id: body.platform_id },
|
||||
{
|
||||
name: body.name,
|
||||
comment: body.comment
|
||||
}
|
||||
);
|
||||
res.send({
|
||||
errcode: 0
|
||||
});
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
errmsg: '平台不存在,修改失败!'
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
next(err);
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
22
src/models/admin/GameInfo.js
Normal file
22
src/models/admin/GameInfo.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
/**
|
||||
* 游戏信息
|
||||
*/
|
||||
const GameInfo = new mongoose.Schema(
|
||||
{
|
||||
game_name: { type: String },
|
||||
game_name_en: { type: String },
|
||||
game_id: { type: String },
|
||||
game_type: { type: String },
|
||||
game_icon: { type: String },
|
||||
platforms: [{type: Object}]
|
||||
},
|
||||
{
|
||||
collection: 'game_info',
|
||||
timestamps: true
|
||||
}
|
||||
);
|
||||
|
||||
export default mongoose.model('GameInfo', GameInfo);
|
20
src/models/admin/Platform.js
Normal file
20
src/models/admin/Platform.js
Normal file
@ -0,0 +1,20 @@
|
||||
'use strict';
|
||||
import mongoose from 'mongoose';
|
||||
|
||||
/**
|
||||
* 平台信息
|
||||
*/
|
||||
const Plateform = new mongoose.Schema(
|
||||
{
|
||||
name: { type: String },
|
||||
name_en: { type: String },
|
||||
platform_id: { type: String },
|
||||
comment: { type: String }
|
||||
},
|
||||
{
|
||||
collection: 'platforms',
|
||||
timestamps: true
|
||||
}
|
||||
);
|
||||
|
||||
export default mongoose.model('Plateform', Plateform);
|
Loading…
x
Reference in New Issue
Block a user