游戏列表页

This commit is contained in:
yulixing 2019-09-27 14:04:01 +08:00
parent ad93e4d2df
commit 1f8aa44747
4 changed files with 126 additions and 1 deletions

View File

@ -0,0 +1,104 @@
/* 推广系统-广告专用 */
import {Router} from 'express'
import GameList from '../../models/admin/GameList'
import cors from 'cors'
const router = new Router()
// 获取游戏列表
router.get('/', async (req, res, next) => {
try {
const query = req.query
const currentPage = parseInt(query.currentPage)
const pageSize = parseInt(query.pageSize)
const platform_id = parseInt(query.platform_id)
const offset = (currentPage - 1) * pageSize
const limit = pageSize
const opt = {}
if (platform_id) opt.platform_id = platform_id
const result = await GameList.find(opt)
.skip(offset)
.limit(limit)
.sort({createdAt: 'desc'})
const total = await GameList.find(opt).countDocuments()
res.send({
errcode: 0,
result,
total,
})
} catch (err) {
next(err)
}
})
// 添加游戏
router.post('/', async (req, res, next) => {
try {
const body = req.body
const game_name = body.game_name
const platform_id = body.platform_id
const appid = body.appid
const newGameList = new GameList({
game_name,
platform_id,
appid,
})
const result = await newGameList.save()
res.send({
errcode: 0,
})
} catch (err) {
next(err)
}
})
// 修改游戏
router.put('/', async (req, res, next) => {
try {
const body = req.body
const _id = body._id
const game_name = body.game_name
const platform_id = body.platform_id
const appid = body.appid
const result = await GameList.updateOne(
{_id},
{
game_name,
platform_id,
appid,
}
)
res.send({
errcode: 0,
})
} catch (err) {
next(err)
}
})
// 删除游戏
router.delete('/', async (req, res, next) => {
try {
const body = req.body
const _id = body._id
const result = await GameList.deleteOne({_id})
res.send({
errcode: 0,
})
} catch (err) {
next(err)
}
})
export default router

View File

@ -6,6 +6,7 @@ import promotionRouter from './promotion'
import gamesRouter from './games'
import adUidRouter from './ad-uid'
import jumpRouter from './jump'
import gameListRouter from './game-list'
const router = new Router()
@ -14,6 +15,7 @@ router.use('/promotion', promotionRouter)
router.use('/games', gamesRouter)
router.use('/ad-uid', adUidRouter)
router.use('/jump', jumpRouter)
router.use('/game-list', gameListRouter)
export default router

View File

@ -2,7 +2,7 @@
import mongoose from 'mongoose'
/**
* 游戏信息
* 游戏跳转信息推广系统专用
*/
const GameJump = new mongoose.Schema(
{

View File

@ -0,0 +1,19 @@
'use strict'
import mongoose from 'mongoose'
/**
* 游戏列表推广系统专用
*/
const GameList = new mongoose.Schema(
{
game_name: {type: String},
appid: {type: String},
platform_id: {type: Number},
},
{
collection: 'game_list',
timestamps: true,
}
)
export default mongoose.model('GameList', GameList)