添加一个用于开始匹配的接口
This commit is contained in:
parent
902a41ea16
commit
7d79d7b2b6
23
docs/api.md
23
docs/api.md
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ export default class AccountController extends BaseController {
|
|||||||
return items.map(o => o.toJson())
|
return items.map(o => o.toJson())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@router('post /svr/:accountid/useitem')
|
||||||
@router('post /api/:accountid/useitem')
|
@router('post /api/:accountid/useitem')
|
||||||
async userItem(req: any) {
|
async userItem(req: any) {
|
||||||
let { accountid, itemid, count } = req.params
|
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) {
|
async addItem(req: any) {
|
||||||
let { itemid, count, accountid } = req.params
|
let { itemid, count, accountid } = req.params
|
||||||
let itemInfo = ItemCtrl.findItem(itemid)
|
let itemInfo = ItemCtrl.findItem(itemid)
|
||||||
|
31
src/controllers/MatchController.ts
Normal file
31
src/controllers/MatchController.ts
Normal 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 {}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user