添加一个用于开始匹配的接口

This commit is contained in:
zhl 2021-01-22 11:05:02 +08:00
parent 902a41ea16
commit 7d79d7b2b6
3 changed files with 56 additions and 1 deletions

View File

@ -478,6 +478,29 @@
```
### 18. 开始比赛
1. Method: POST
2. URI: /api/:accountid/beginmatch
| 字段 | 说明 |
| -------- | -------------------------------------- |
| accountid | 帐号id |
> POST参数
| 字段 | 说明 |
| -------- | -------------------------------------- |
| matchid |10_match.xlsx里的id |
3. Response: JSON
```js
```

View File

@ -111,6 +111,7 @@ export default class AccountController extends BaseController {
return items.map(o => o.toJson())
}
@router('post /svr/:accountid/useitem')
@router('post /api/:accountid/useitem')
async userItem(req: any) {
let { accountid, itemid, count } = req.params
@ -169,7 +170,7 @@ export default class AccountController extends BaseController {
}
}
@router('post /api/:accountid/additem')
@router('post /svr/:accountid/additem')
async addItem(req: any) {
let { itemid, count, accountid } = req.params
let itemInfo = ItemCtrl.findItem(itemid)

View File

@ -0,0 +1,31 @@
import BaseController from '../common/base.controller'
import { router } from '../decorators/router'
import { BaseConst } from '../constants/BaseConst'
import { ZError } from '../common/ZError'
import { MatchCfg } from '../cfg/parsers/MatchCfg'
import { BagItem } from '../models/BagItem'
export default class MatchController extends BaseController {
@router('post /api/:accountid/beginmatch')
async beginMatch(req: any) {
let {accountid, matchid} = req.params
let cfg: MatchCfg = global.$cfg.get(BaseConst.MATCH).get(matchid << 0)
if (!cfg || !cfg.consume) {
throw new ZError(10, 'match not found')
}
let itemObj = cfg.consume.split(':')
let itemid: number = parseInt(itemObj[0])
let count: number = parseInt(itemObj[1])
let record = await BagItem.findOne({
accountid,
itemid
})
if (!record || record.count < count) {
throw new ZError(11, 'not enough ticket')
}
record.count -= count
await record.save()
return {}
}
}