game-data game-info
This commit is contained in:
parent
de05274bdc
commit
b9c94823d7
@ -1,37 +1,37 @@
|
||||
import express from 'express';
|
||||
import expressValidator from 'express-validator';
|
||||
import flash from 'express-flash';
|
||||
import session from 'express-session';
|
||||
import bodyParser from 'body-parser';
|
||||
import cookieParser from 'cookie-parser';
|
||||
import compress from 'compression';
|
||||
import methodOverride from 'method-override';
|
||||
import helmet from 'helmet';
|
||||
import express from 'express'
|
||||
import expressValidator from 'express-validator'
|
||||
import flash from 'express-flash'
|
||||
import session from 'express-session'
|
||||
import bodyParser from 'body-parser'
|
||||
import cookieParser from 'cookie-parser'
|
||||
import compress from 'compression'
|
||||
import methodOverride from 'method-override'
|
||||
import helmet from 'helmet'
|
||||
// import favicon from 'serve-favicon';
|
||||
import FileStreamRotator from 'file-stream-rotator';
|
||||
import morgan from 'morgan';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import logger from './../utils/logger';
|
||||
import expressUtils from './../utils/express-utils';
|
||||
import config from './../../config/config';
|
||||
import connectMongo from 'connect-mongo';
|
||||
import routes from './../router/index';
|
||||
import FileStreamRotator from 'file-stream-rotator'
|
||||
import morgan from 'morgan'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import logger from './../utils/logger'
|
||||
import expressUtils from './../utils/express-utils'
|
||||
import config from './../../config/config'
|
||||
import connectMongo from 'connect-mongo'
|
||||
import routes from './../router/index'
|
||||
|
||||
const app = express();
|
||||
const MongoStore = connectMongo(session);
|
||||
const env = process.env.NODE_ENV || 'development';
|
||||
const isDev = env === 'development';
|
||||
app.locals.ENV = env;
|
||||
app.locals.ENV_DEVELOPMENT = isDev;
|
||||
const app = express()
|
||||
const MongoStore = connectMongo(session)
|
||||
const env = process.env.NODE_ENV || 'development'
|
||||
const isDev = env === 'development'
|
||||
app.locals.ENV = env
|
||||
app.locals.ENV_DEVELOPMENT = isDev
|
||||
|
||||
app.use(helmet());
|
||||
app.use(helmet())
|
||||
|
||||
app.disable('x-powered-by');
|
||||
app.disable('x-powered-by')
|
||||
// app.use(favicon(config.root + '/public/img/favicon/favicon.ico'));
|
||||
|
||||
const logDir = config.logs_path;
|
||||
fs.existsSync(logDir) || fs.mkdirSync(logDir);
|
||||
const logDir = config.logs_path
|
||||
fs.existsSync(logDir) || fs.mkdirSync(logDir)
|
||||
|
||||
/**
|
||||
* 记录除favicon之外的所有请求
|
||||
@ -40,8 +40,8 @@ const accessLogStream = FileStreamRotator.getStream({
|
||||
date_format: 'YYYYMMDD',
|
||||
filename: logDir + '/' + config.app.name + '-access-%DATE%.log',
|
||||
frequency: 'daily',
|
||||
verbose: false
|
||||
});
|
||||
verbose: false,
|
||||
})
|
||||
/**
|
||||
* 仅记录失败的请求
|
||||
*/
|
||||
@ -49,8 +49,8 @@ const errorLogStream = FileStreamRotator.getStream({
|
||||
date_format: 'YYYYMMDD',
|
||||
filename: logDir + '/' + config.app.name + '-error-%DATE%.log',
|
||||
frequency: 'daily',
|
||||
verbose: false
|
||||
});
|
||||
verbose: false,
|
||||
})
|
||||
/**
|
||||
* 记录非静态文件请求
|
||||
*/
|
||||
@ -58,8 +58,8 @@ const requestLogStream = FileStreamRotator.getStream({
|
||||
date_format: 'YYYYMMDD',
|
||||
filename: logDir + '/' + config.app.name + '-request-%DATE%.log',
|
||||
frequency: 'daily',
|
||||
verbose: false
|
||||
});
|
||||
verbose: false,
|
||||
})
|
||||
|
||||
morgan.token('remote-addr', function(req, res) {
|
||||
const ip =
|
||||
@ -67,10 +67,10 @@ morgan.token('remote-addr', function(req, res) {
|
||||
req.ip ||
|
||||
req._remoteAddress ||
|
||||
(req.connection && req.connection.remoteAddress) ||
|
||||
undefined;
|
||||
req._remoteAddress = ip;
|
||||
return ip;
|
||||
});
|
||||
undefined
|
||||
req._remoteAddress = ip
|
||||
return ip
|
||||
})
|
||||
|
||||
if (isDev) {
|
||||
// app.use(morgan('dev' ));
|
||||
@ -79,50 +79,47 @@ app.use(
|
||||
morgan('combined', {
|
||||
stream: accessLogStream,
|
||||
skip: function(req, res) {
|
||||
return req.method === 'HEAD';
|
||||
}
|
||||
return req.method === 'HEAD'
|
||||
},
|
||||
})
|
||||
);
|
||||
)
|
||||
app.use(
|
||||
morgan('combined', {
|
||||
stream: errorLogStream,
|
||||
skip: function(req, res) {
|
||||
return res.statusCode < 400;
|
||||
}
|
||||
return res.statusCode < 400
|
||||
},
|
||||
})
|
||||
);
|
||||
)
|
||||
|
||||
app.get('/robots.txt', function(req, res) {
|
||||
res.type('text/plain');
|
||||
res.send('User-agent: *\nDisallow: /agent/');
|
||||
});
|
||||
|
||||
|
||||
|
||||
res.type('text/plain')
|
||||
res.send('User-agent: *\nDisallow: /agent/')
|
||||
})
|
||||
|
||||
// -- We don't want to serve sessions for static resources
|
||||
// -- Save database write on every resources
|
||||
app.use(compress());
|
||||
app.use(express.static(config.root + '/public'));
|
||||
app.use(compress())
|
||||
app.use(express.static(config.root + '/public'))
|
||||
app.use(
|
||||
morgan('combined', {
|
||||
stream: requestLogStream,
|
||||
skip: function(req, res) {
|
||||
return req.method === 'HEAD';
|
||||
}
|
||||
return req.method === 'HEAD'
|
||||
},
|
||||
})
|
||||
);
|
||||
)
|
||||
|
||||
app.use(bodyParser.json({ limit: '5mb' }));
|
||||
app.use(bodyParser.json({limit: '5mb'}))
|
||||
app.use(
|
||||
bodyParser.urlencoded({
|
||||
limit: '5mb',
|
||||
parameterLimit: 50000,
|
||||
extended: true
|
||||
extended: true,
|
||||
})
|
||||
);
|
||||
app.use(expressValidator());
|
||||
app.use(cookieParser(config.secret));
|
||||
)
|
||||
app.use(expressValidator())
|
||||
app.use(cookieParser(config.secret))
|
||||
// app.use(
|
||||
// session({
|
||||
// secret: config.secret,
|
||||
@ -136,41 +133,47 @@ app.use(cookieParser(config.secret));
|
||||
// })
|
||||
// })
|
||||
// );
|
||||
app.use(flash());
|
||||
app.use(expressUtils());
|
||||
app.use(methodOverride());
|
||||
app.use(flash())
|
||||
app.use(expressUtils())
|
||||
app.use(methodOverride())
|
||||
app.use(function(req, res, next) {
|
||||
res.locals.user = req.user;
|
||||
next();
|
||||
});
|
||||
res.locals.user = req.user
|
||||
next()
|
||||
})
|
||||
|
||||
app.all('/uploads', function(req, res, next) {
|
||||
res.header('Access-Control-Allow-Origin', '*');
|
||||
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS');
|
||||
res.header('Access-Control-Allow-Headers', 'X-Requested-With');
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type');
|
||||
next();
|
||||
});
|
||||
app.use('/api', routes);
|
||||
res.header('Access-Control-Allow-Origin', '*')
|
||||
res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS')
|
||||
res.header('Access-Control-Allow-Headers', 'X-Requested-With')
|
||||
res.header('Access-Control-Allow-Headers', 'Content-Type')
|
||||
next()
|
||||
})
|
||||
app.use('/api', routes)
|
||||
|
||||
app.use(function(req, res, next) {
|
||||
const err = new Error('未找到您要访问的页面 (´・_・`)');
|
||||
err.status = 404;
|
||||
const err = new Error('未找到您要访问的页面 (´・_・`)')
|
||||
err.status = 404
|
||||
// next(err);
|
||||
err.status = err.status || 500;
|
||||
err.status = err.status || 500
|
||||
if (err.status !== 404) {
|
||||
logger.error(err);
|
||||
logger.error(err)
|
||||
}
|
||||
next(err);
|
||||
});
|
||||
next(err)
|
||||
})
|
||||
app.use(function(err, req, res, next) {
|
||||
logger.error({
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
err_status: err.status,
|
||||
err_message: err.message
|
||||
});
|
||||
res.json({ errcode: 10, errmsg: err.message });
|
||||
err_message: err.message,
|
||||
})
|
||||
|
||||
if (err.errmsg) {
|
||||
res.json({errcode: 10, errmsg: err.errmsg})
|
||||
} else {
|
||||
res.json({errcode: 10, errmsg: err.message})
|
||||
}
|
||||
|
||||
// if (req.path.startsWith('/api')) {
|
||||
|
||||
// } else {
|
||||
@ -182,6 +185,6 @@ app.use(function(err, req, res, next) {
|
||||
// title: err.status
|
||||
// });
|
||||
// }
|
||||
});
|
||||
})
|
||||
|
||||
export default app;
|
||||
export default app
|
||||
|
156
src/controllers/games/data.js
Normal file
156
src/controllers/games/data.js
Normal file
@ -0,0 +1,156 @@
|
||||
// 获取单个游戏广告位
|
||||
import {Router} from 'express'
|
||||
import axios from 'axios'
|
||||
import config from '../../../config/config'
|
||||
|
||||
const router = new Router()
|
||||
|
||||
const gameReportApiUrl = config.game_report
|
||||
|
||||
// 获取游戏日报
|
||||
router.get('/report', async (req, res, next) => {
|
||||
// 权限判断
|
||||
const hasPerm =
|
||||
req.user.permissions.includes(`${req.query.uid}-readable`) ||
|
||||
req.user.permissions.includes(`${req.query.uid}-edit`) ||
|
||||
req.user.permissions.includes(`${req.query.uid}-publish`) ||
|
||||
req.user.permissions.includes(`games-writeable`)
|
||||
if (!hasPerm) {
|
||||
res.status(403).send({
|
||||
errcode: 1,
|
||||
errmsg: '用户无此游戏数据查看权限!',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const query = req.query
|
||||
const game_id = parseInt(query.game_id)
|
||||
const platform_id = parseInt(query.platform_id)
|
||||
const date = query.date
|
||||
const isNew = parseInt(query.isNew)
|
||||
|
||||
console.log(query)
|
||||
|
||||
try {
|
||||
const categoryRes = await axios({
|
||||
url: gameReportApiUrl,
|
||||
method: 'get',
|
||||
params: {
|
||||
c: 'Ops',
|
||||
a: 'descField',
|
||||
body: JSON.stringify({
|
||||
gameid: game_id,
|
||||
channel: platform_id,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
console.log(categoryRes.data)
|
||||
|
||||
if (categoryRes.data.errcode === 0) {
|
||||
const categoryInfo = categoryRes.data.result
|
||||
const category = []
|
||||
for (const key in categoryInfo) {
|
||||
if (categoryInfo.hasOwnProperty(key)) {
|
||||
category.push(key)
|
||||
}
|
||||
}
|
||||
|
||||
console.log('category', category)
|
||||
console.log('categoryInfo', categoryInfo)
|
||||
|
||||
if (category.length === 0) {
|
||||
res.send({
|
||||
errcode: 404,
|
||||
errmsg: '暂无数据!',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const getDataArr = []
|
||||
|
||||
category.map(item => {
|
||||
getDataArr.push(
|
||||
getCategoryData(item, date, isNew, game_id, platform_id)
|
||||
)
|
||||
})
|
||||
|
||||
console.log(getDataArr)
|
||||
|
||||
const dataArr = await Promise.all(getDataArr)
|
||||
const allData = Object.assign(...dataArr)
|
||||
const result = {}
|
||||
|
||||
for (const key in categoryInfo) {
|
||||
if (categoryInfo.hasOwnProperty(key)) {
|
||||
const cate = categoryInfo[key]
|
||||
result[key] = []
|
||||
|
||||
for (let i = 0; i < cate.length; i++) {
|
||||
const field = cate[i]
|
||||
const fieldName = field.name
|
||||
field.value = allData[fieldName]
|
||||
if (field.value) {
|
||||
result[key].push(field)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
res.send({
|
||||
errcode: 0,
|
||||
result: result,
|
||||
})
|
||||
} else {
|
||||
res.send({
|
||||
errcode: categoryRes.errcode,
|
||||
errmsg: categoryRes.errmsg,
|
||||
})
|
||||
return
|
||||
}
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
next(err)
|
||||
}
|
||||
})
|
||||
|
||||
function getCategoryData(cateName, date, is_new, game_id, platform_id) {
|
||||
console.log(
|
||||
JSON.stringify({
|
||||
gameid: game_id,
|
||||
channel: platform_id,
|
||||
times: date,
|
||||
is_new: is_new,
|
||||
category: cateName,
|
||||
})
|
||||
)
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const dataRes = await axios({
|
||||
url: gameReportApiUrl,
|
||||
method: 'get',
|
||||
params: {
|
||||
c: 'Ops',
|
||||
a: 'gameReport',
|
||||
body: JSON.stringify({
|
||||
gameid: game_id,
|
||||
channel: platform_id,
|
||||
times: date,
|
||||
is_new: is_new,
|
||||
category: cateName,
|
||||
}),
|
||||
},
|
||||
})
|
||||
|
||||
if (dataRes.data.errcode === 0) {
|
||||
const data = dataRes.data.result
|
||||
resolve(data)
|
||||
} else {
|
||||
reject({
|
||||
errcode: 404,
|
||||
errmsg: '数据获取失败,暂无数据!',
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export default router
|
@ -146,6 +146,8 @@ router.post('/update', async (req, res, next) => {
|
||||
}
|
||||
|
||||
const body = req.body
|
||||
const method = body.method
|
||||
const platformIndex = body.platformIndex
|
||||
|
||||
try {
|
||||
const search = await GameInfo.findOne({
|
||||
@ -153,16 +155,15 @@ router.post('/update', async (req, res, next) => {
|
||||
deleted: false,
|
||||
})
|
||||
if (search) {
|
||||
if (body.info) {
|
||||
const info = body.info
|
||||
const platformInfo = search.platforms[info.platformIndex]
|
||||
const curStatus = platformInfo ? platformInfo.status : ''
|
||||
delete body.platforms[info.platformIndex].newPlatform
|
||||
delete body.info
|
||||
const platforms = search.platforms
|
||||
|
||||
// 状态变更会新增平台 发送通知
|
||||
if (curStatus !== info.status || !platformInfo) {
|
||||
if (method === 'savePlatform') {
|
||||
const curPlatform = body.platform
|
||||
const prePlatform = platforms[platformIndex] || {}
|
||||
|
||||
if (curPlatform.status !== prePlatform.status) {
|
||||
const token = await getOpsToken()
|
||||
|
||||
const statusRes = await axios({
|
||||
url: config.minigame.api + 'minigame/',
|
||||
method: 'post',
|
||||
@ -172,11 +173,10 @@ router.post('/update', async (req, res, next) => {
|
||||
game: search.game_name,
|
||||
game_name: search.game_name_en,
|
||||
game_id: search.game_id,
|
||||
platform: body.platforms[info.platformIndex].platform.name_en,
|
||||
platform_name: body.platforms[info.platformIndex].platform.name,
|
||||
platform_id:
|
||||
body.platforms[info.platformIndex].platform.platform_id,
|
||||
status_id: info.status,
|
||||
platform: curPlatform.platform.name_en,
|
||||
platform_name: curPlatform.platform.name,
|
||||
platform_id: curPlatform.platform.platform_id,
|
||||
status_id: curPlatform.status,
|
||||
},
|
||||
},
|
||||
headers: {
|
||||
@ -192,18 +192,43 @@ router.post('/update', async (req, res, next) => {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const result = await GameInfo.updateOne(
|
||||
{
|
||||
_id: body._id,
|
||||
deleted: false,
|
||||
},
|
||||
body
|
||||
)
|
||||
res.send({
|
||||
errcode: 0,
|
||||
})
|
||||
platforms[platformIndex] = curPlatform
|
||||
|
||||
const result = await GameInfo.updateOne(
|
||||
{
|
||||
_id: body._id,
|
||||
deleted: false,
|
||||
},
|
||||
{platforms, platforms}
|
||||
)
|
||||
res.send({
|
||||
errcode: 0,
|
||||
})
|
||||
} else if (method === 'delPlatform') {
|
||||
platforms.splice(platformIndex, 1)
|
||||
const result = await GameInfo.updateOne(
|
||||
{
|
||||
_id: body._id,
|
||||
deleted: false,
|
||||
},
|
||||
{platforms, platforms}
|
||||
)
|
||||
res.send({
|
||||
errcode: 0,
|
||||
})
|
||||
} else {
|
||||
const result = await GameInfo.updateOne(
|
||||
{
|
||||
_id: body._id,
|
||||
deleted: false,
|
||||
},
|
||||
body
|
||||
)
|
||||
res.send({
|
||||
errcode: 0,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
res.send({
|
||||
errcode: 1,
|
||||
|
@ -6,6 +6,7 @@ import shareRouter from './share';
|
||||
import rewardRouter from './reward';
|
||||
import libRouter from './lib';
|
||||
import adRouter from './ad';
|
||||
import dataRouter from './data';
|
||||
|
||||
|
||||
|
||||
@ -21,6 +22,7 @@ router.use('/mp_share', mpShareRouter);
|
||||
router.use('/reward', rewardRouter);
|
||||
router.use('/lib', libRouter);
|
||||
router.use('/ad', adRouter);
|
||||
router.use('/data', dataRouter);
|
||||
router.use('/', gamesRouter);
|
||||
|
||||
export default router;
|
||||
|
Loading…
x
Reference in New Issue
Block a user