增加用户统计信息相关接口
This commit is contained in:
parent
2915c6301c
commit
17bc00a42f
@ -19,3 +19,5 @@ DB_MAIN=mongodb://188.88.0.2/pyxis-production
|
||||
DB_SECOND=mongodb://188.88.0.2/pyxis2-production
|
||||
|
||||
REDIS=redis://127.0.0.1:6379/14
|
||||
|
||||
SUSU_HOST = http://10.10.3.10:8010
|
||||
|
@ -12,6 +12,7 @@ import { UserCoupon } from '../../models/user/UserCoupon'
|
||||
import { ShareCfgClass, ShopCfg } from '../../models/shop/ShopCfg'
|
||||
import { Coupon } from '../../models/shop/Coupon'
|
||||
import { getCouponUrl } from '../../services/File'
|
||||
import { abilityMap, totalStatic } from '../../services/SusuSvr'
|
||||
|
||||
class GameUserController extends BaseController {
|
||||
// TODO:: 增加返回未使用的券
|
||||
@ -37,25 +38,40 @@ class GameUserController extends BaseController {
|
||||
|
||||
//TODO:: 根据真实的配表获取数据
|
||||
@role('anon')
|
||||
@router('post /api/:accountid/stats')
|
||||
@router('post /api/:accountId/stats')
|
||||
async userStatic(req: any) {
|
||||
const data: any = {
|
||||
map: [
|
||||
{ id: 0, name: '知识面', score: getRandom(20), max: 20 },
|
||||
{ id: 1, name: '知识深度', score: getRandom(20), max: 20 },
|
||||
{ id: 2, name: '反应能力', score: getRandom(20), max: 20 },
|
||||
{ id: 3, name: '毅力', score: getRandom(20), max: 20 },
|
||||
{ id: 4, name: '其他', score: getRandom(20), max: 20 },
|
||||
],
|
||||
rightCount: 100,
|
||||
errorCount: 100,
|
||||
singleCount: 20,
|
||||
singleWin: 15,
|
||||
singleLose: 5,
|
||||
activityCount: 20,
|
||||
examCount: 21,
|
||||
const { accountId } = req.params
|
||||
let result: any = {
|
||||
rightCount: 0,
|
||||
errorCount: 0,
|
||||
singleCount: 0,
|
||||
singleWin: 0,
|
||||
singleLose: 0,
|
||||
activityCount: 0,
|
||||
examCount: 0,
|
||||
}
|
||||
return data
|
||||
const mapArr = await abilityMap(accountId)
|
||||
const statData = await totalStatic(accountId)
|
||||
Object.assign(result, statData)
|
||||
result.map = mapArr
|
||||
return result
|
||||
// const data: any = {
|
||||
// map: [
|
||||
// { id: 0, name: '知识面', score: getRandom(20), max: 20 },
|
||||
// { id: 1, name: '知识深度', score: getRandom(20), max: 20 },
|
||||
// { id: 2, name: '反应能力', score: getRandom(20), max: 20 },
|
||||
// { id: 3, name: '毅力', score: getRandom(20), max: 20 },
|
||||
// { id: 4, name: '其他', score: getRandom(20), max: 20 },
|
||||
// ],
|
||||
// rightCount: 100,
|
||||
// errorCount: 100,
|
||||
// singleCount: 20,
|
||||
// singleWin: 15,
|
||||
// singleLose: 5,
|
||||
// activityCount: 20,
|
||||
// examCount: 21,
|
||||
// }
|
||||
// return data
|
||||
}
|
||||
|
||||
@role('anon')
|
||||
|
@ -37,6 +37,7 @@ let baseConfig = {
|
||||
db_main: process.env.DB_MAIN,
|
||||
db_second: process.env.DB_SECOND,
|
||||
redis: process.env.REDIS,
|
||||
susuHost: process.env.SUSU_HOST,
|
||||
}
|
||||
|
||||
export default baseConfig
|
||||
|
47
src/services/SusuSvr.ts
Normal file
47
src/services/SusuSvr.ts
Normal file
@ -0,0 +1,47 @@
|
||||
// 10.10.3.10
|
||||
import config from 'config/config'
|
||||
import axios from 'axios'
|
||||
|
||||
const MAP_NAME = ['准确率', '反应力', '爆发力', '毅力', '亲和力']
|
||||
const MAP_ID = [99081, 99082, 99083, 99084, 99085]
|
||||
const MAX_NUM = 100
|
||||
/**
|
||||
* 获取5纬图数据
|
||||
* @param {string} accountId
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
export async function abilityMap(accountId: string) {
|
||||
const url = `${config.susuHost}/item_info?account_id=${accountId}`
|
||||
return axios.get(url).then(res => {
|
||||
const { data } = res
|
||||
const { msg } = data
|
||||
const results: any[] = []
|
||||
let i = 0
|
||||
for (const id of MAP_ID) {
|
||||
let val = msg[`item_${id}`] || 0
|
||||
results.push({ id: i, name: MAP_NAME[i++], score: val, max: MAX_NUM })
|
||||
}
|
||||
return results
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取总的统计数据
|
||||
* @param {string} accountId
|
||||
* @return {Promise<void>}
|
||||
*/
|
||||
export async function totalStatic(accountId: string) {
|
||||
const url = `${config.susuHost}/fight_info?account_id=${accountId}`
|
||||
return axios.get(url).then(res => {
|
||||
const { data } = res
|
||||
const { msg } = data
|
||||
const countTotal = msg['total_answer'] || 0
|
||||
const countRight = msg['win'] || 0
|
||||
const total = msg['total_session'] || 0
|
||||
return {
|
||||
rightCount: countRight, // 对的
|
||||
errorCount: countTotal - countRight, // 错误
|
||||
singleCount: total, //total场数
|
||||
}
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user