增加用户统计信息相关接口

This commit is contained in:
zhl 2021-06-17 19:50:44 +08:00
parent 2915c6301c
commit 17bc00a42f
4 changed files with 83 additions and 17 deletions

View File

@ -19,3 +19,5 @@ DB_MAIN=mongodb://188.88.0.2/pyxis-production
DB_SECOND=mongodb://188.88.0.2/pyxis2-production DB_SECOND=mongodb://188.88.0.2/pyxis2-production
REDIS=redis://127.0.0.1:6379/14 REDIS=redis://127.0.0.1:6379/14
SUSU_HOST = http://10.10.3.10:8010

View File

@ -12,6 +12,7 @@ import { UserCoupon } from '../../models/user/UserCoupon'
import { ShareCfgClass, ShopCfg } from '../../models/shop/ShopCfg' import { ShareCfgClass, ShopCfg } from '../../models/shop/ShopCfg'
import { Coupon } from '../../models/shop/Coupon' import { Coupon } from '../../models/shop/Coupon'
import { getCouponUrl } from '../../services/File' import { getCouponUrl } from '../../services/File'
import { abilityMap, totalStatic } from '../../services/SusuSvr'
class GameUserController extends BaseController { class GameUserController extends BaseController {
// TODO:: 增加返回未使用的券 // TODO:: 增加返回未使用的券
@ -37,25 +38,40 @@ class GameUserController extends BaseController {
//TODO:: 根据真实的配表获取数据 //TODO:: 根据真实的配表获取数据
@role('anon') @role('anon')
@router('post /api/:accountid/stats') @router('post /api/:accountId/stats')
async userStatic(req: any) { async userStatic(req: any) {
const data: any = { const { accountId } = req.params
map: [ let result: any = {
{ id: 0, name: '知识面', score: getRandom(20), max: 20 }, rightCount: 0,
{ id: 1, name: '知识深度', score: getRandom(20), max: 20 }, errorCount: 0,
{ id: 2, name: '反应能力', score: getRandom(20), max: 20 }, singleCount: 0,
{ id: 3, name: '毅力', score: getRandom(20), max: 20 }, singleWin: 0,
{ id: 4, name: '其他', score: getRandom(20), max: 20 }, singleLose: 0,
], activityCount: 0,
rightCount: 100, examCount: 0,
errorCount: 100,
singleCount: 20,
singleWin: 15,
singleLose: 5,
activityCount: 20,
examCount: 21,
} }
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') @role('anon')

View File

@ -37,6 +37,7 @@ let baseConfig = {
db_main: process.env.DB_MAIN, db_main: process.env.DB_MAIN,
db_second: process.env.DB_SECOND, db_second: process.env.DB_SECOND,
redis: process.env.REDIS, redis: process.env.REDIS,
susuHost: process.env.SUSU_HOST,
} }
export default baseConfig export default baseConfig

47
src/services/SusuSvr.ts Normal file
View 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场数
}
})
}