新增订单接口
This commit is contained in:
parent
ce14b0da11
commit
5335b092a3
@ -45,11 +45,13 @@
|
|||||||
"mongoose": "^5.5.7",
|
"mongoose": "^5.5.7",
|
||||||
"morgan": "^1.9.1",
|
"morgan": "^1.9.1",
|
||||||
"multer": "^1.4.1",
|
"multer": "^1.4.1",
|
||||||
|
"mysql2": "^1.6.5",
|
||||||
"node-schedule": "^1.3.2",
|
"node-schedule": "^1.3.2",
|
||||||
"nodemon": "^1.19.0",
|
"nodemon": "^1.19.0",
|
||||||
"pow-mongodb-fixtures": "^0.14.0",
|
"pow-mongodb-fixtures": "^0.14.0",
|
||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
|
"sequelize": "^5.16.0",
|
||||||
"serve-favicon": "^2.5.0",
|
"serve-favicon": "^2.5.0",
|
||||||
"ssha": "^1.0.1",
|
"ssha": "^1.0.1",
|
||||||
"yargs": "^13.2.4"
|
"yargs": "^13.2.4"
|
||||||
|
@ -299,25 +299,5 @@ router.get('/record', async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/* 添加兑换记录 */
|
|
||||||
router.post('/record', async (req, res, next) => {
|
|
||||||
const body = req.body
|
|
||||||
try {
|
|
||||||
const list = new GiftRecord({
|
|
||||||
user_id: body.user_id,
|
|
||||||
game_id: body.game_id,
|
|
||||||
platform_id: body.platform_id,
|
|
||||||
gift_id: body.gift_id,
|
|
||||||
gift_info: body.gift_info,
|
|
||||||
code: body.code,
|
|
||||||
})
|
|
||||||
const result = await list.save()
|
|
||||||
res.send({
|
|
||||||
errcode: 0,
|
|
||||||
})
|
|
||||||
} catch (err) {
|
|
||||||
next(err)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
@ -9,6 +9,7 @@ import adRouter from './ad';
|
|||||||
import itemRouter from './item';
|
import itemRouter from './item';
|
||||||
import dataRouter from './data';
|
import dataRouter from './data';
|
||||||
import giftRouter from './gift';
|
import giftRouter from './gift';
|
||||||
|
import orderRouter from './order';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ router.use('/ad', adRouter);
|
|||||||
router.use('/item', itemRouter);
|
router.use('/item', itemRouter);
|
||||||
router.use('/data', dataRouter);
|
router.use('/data', dataRouter);
|
||||||
router.use('/gift', giftRouter);
|
router.use('/gift', giftRouter);
|
||||||
|
router.use('/order', orderRouter);
|
||||||
router.use('/', gamesRouter);
|
router.use('/', gamesRouter);
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
92
src/controllers/games/order.js
Normal file
92
src/controllers/games/order.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
import {Router} from 'express'
|
||||||
|
import sequelize from 'sequelize'
|
||||||
|
import logger from '../../utils/logger'
|
||||||
|
import OrderInfo from '../../models/paydb/OrderInfo'
|
||||||
|
const router = new Router()
|
||||||
|
|
||||||
|
// 查询订单详情
|
||||||
|
router.get('/', async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const query = req.query
|
||||||
|
const gameid = parseInt(query.game_id)
|
||||||
|
const channel = parseInt(query.platform_id)
|
||||||
|
const currentPage = parseInt(query.currentPage)
|
||||||
|
const pageSize = parseInt(query.pageSize)
|
||||||
|
const offset = (currentPage - 1) * pageSize
|
||||||
|
const limit = pageSize
|
||||||
|
const opt = {
|
||||||
|
gameid,
|
||||||
|
channel,
|
||||||
|
}
|
||||||
|
|
||||||
|
// 可选查询条件
|
||||||
|
if (query.orderid) opt.orderid = query.orderid
|
||||||
|
if (query.accountid) opt.accountid = query.accountid
|
||||||
|
if (query.itemid) opt.itemid = parseInt(query.itemid)
|
||||||
|
if (query.sp_orderid) opt.sp_orderid = query.sp_orderid
|
||||||
|
|
||||||
|
console.log(opt)
|
||||||
|
|
||||||
|
const result = await OrderInfo.findAll({
|
||||||
|
offset,
|
||||||
|
limit,
|
||||||
|
where: opt,
|
||||||
|
})
|
||||||
|
let total = await OrderInfo.findAll({
|
||||||
|
where: opt,
|
||||||
|
})
|
||||||
|
total = total.length
|
||||||
|
res.send({
|
||||||
|
errcode: 0,
|
||||||
|
total,
|
||||||
|
result,
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err)
|
||||||
|
next(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// 状态切换
|
||||||
|
router.patch('/', async (req, res, next) => {
|
||||||
|
// 权限判断
|
||||||
|
const hasPerm =
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-edit`) ||
|
||||||
|
req.user.permissions.includes(`${req.body.uid}-publish`) ||
|
||||||
|
req.user.permissions.includes(`games-writeable`)
|
||||||
|
if (!hasPerm) {
|
||||||
|
res.status(403).send({
|
||||||
|
errcode: 1,
|
||||||
|
errmsg: '用户无权限!',
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const body = req.body
|
||||||
|
const gameid = parseInt(body.game_id)
|
||||||
|
const channel = parseInt(body.platform_id)
|
||||||
|
const idx = body.idx
|
||||||
|
const status = body.status
|
||||||
|
const result = await OrderInfo.update(
|
||||||
|
{
|
||||||
|
status,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
idx,
|
||||||
|
gameid,
|
||||||
|
channel,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
res.send({
|
||||||
|
errcode: 0,
|
||||||
|
result,
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
next(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
export default router
|
79
src/models/paydb/OrderInfo.js
Normal file
79
src/models/paydb/OrderInfo.js
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
import Sequelize from 'sequelize'
|
||||||
|
import config from '../../../config/config'
|
||||||
|
|
||||||
|
const payDb = config.pay_db
|
||||||
|
|
||||||
|
const sequelize = new Sequelize(payDb.db_name, payDb.username, payDb.password, {
|
||||||
|
host: payDb.host,
|
||||||
|
|
||||||
|
dialect: 'mysql',
|
||||||
|
timezone: '+08:00',
|
||||||
|
})
|
||||||
|
|
||||||
|
const OrderInfo = sequelize.define(
|
||||||
|
'orderinfo',
|
||||||
|
{
|
||||||
|
idx: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
},
|
||||||
|
minigame_appid: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
minigame_accountid: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
orderid: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
accountid: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
channel: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
gameid: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
openid: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
itemid: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
price: {
|
||||||
|
type: Sequelize.DOUBLE,
|
||||||
|
},
|
||||||
|
ipv4: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
confirmtime: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
createtime: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
sp_orderid: {
|
||||||
|
type: Sequelize.CHAR,
|
||||||
|
},
|
||||||
|
sp_amount: {
|
||||||
|
type: Sequelize.DOUBLE,
|
||||||
|
},
|
||||||
|
sp_confirm_time: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
sp_pay_result: {
|
||||||
|
type: Sequelize.INTEGER,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
tableName: 'orderinfo',
|
||||||
|
timestamps: false,
|
||||||
|
freezeTableName: true,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
export default OrderInfo
|
Loading…
x
Reference in New Issue
Block a user