增加视频广告上报接口
This commit is contained in:
parent
fbe60aff85
commit
afd7197329
18
docs/api.md
18
docs/api.md
@ -630,7 +630,25 @@
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 24. 视频广告上报
|
||||||
|
|
||||||
|
1. Method: POST
|
||||||
|
2. URI: /api/:accountid/adresult
|
||||||
|
|
||||||
|
| 字段 | 说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
| accountid | 帐号id |
|
||||||
|
|
||||||
|
3. Response: JSON
|
||||||
|
|
||||||
|
```js
|
||||||
|
[ //物品列表
|
||||||
|
{
|
||||||
|
"id": 0, //道具id
|
||||||
|
"count": 0, //道具数量
|
||||||
|
},
|
||||||
|
]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +121,6 @@ export default class AccountController extends BaseController {
|
|||||||
async cardlist(req: any) {
|
async cardlist(req: any) {
|
||||||
let account = req.user
|
let account = req.user
|
||||||
let result: Card[] = [...account.cardMap.values()].map(o => o.toJson())
|
let result: Card[] = [...account.cardMap.values()].map(o => o.toJson())
|
||||||
//TODO:: 添加限免英雄和免费英雄
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
21
src/controllers/AdController.ts
Normal file
21
src/controllers/AdController.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import BaseController from '../common/base.controller'
|
||||||
|
import { router } from '../decorators/router'
|
||||||
|
import { AdRecord } from '../models/AdRecord'
|
||||||
|
|
||||||
|
export default class AdController extends BaseController {
|
||||||
|
/**
|
||||||
|
* 观看视频广告后的上报, 添加奖励物品
|
||||||
|
* @param req
|
||||||
|
* @return {Promise<{}>}
|
||||||
|
*/
|
||||||
|
@router('post /api/:accountid/adresult')
|
||||||
|
async drawCard(req: any) {
|
||||||
|
let { accountid } = req.params
|
||||||
|
let day = (new Date()).format('yyyy-MM-dd', true)
|
||||||
|
let record = (await AdRecord.findOrCreate({accountid, day})).doc
|
||||||
|
record.count += 1
|
||||||
|
//TODO:: 读取配置, 查看次数是否达到上限, 添加物品
|
||||||
|
await record.save()
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
@ -96,7 +96,6 @@ export default class CardController extends BaseController {
|
|||||||
}
|
}
|
||||||
if (cards) {
|
if (cards) {
|
||||||
let datas: Card[] = []
|
let datas: Card[] = []
|
||||||
//TODO:: 设置真实的卡牌信息
|
|
||||||
for (let cardid of cards) {
|
for (let cardid of cards) {
|
||||||
let card = new Card()
|
let card = new Card()
|
||||||
card.cardid = cardid
|
card.cardid = cardid
|
||||||
|
@ -17,7 +17,6 @@ export default class HeroController extends BaseController {
|
|||||||
for (let [, hero] of account.heros) {
|
for (let [, hero] of account.heros) {
|
||||||
heros.push(hero.toJson())
|
heros.push(hero.toJson())
|
||||||
}
|
}
|
||||||
//TODO:: 添加限免英雄和免费英雄
|
|
||||||
return heros
|
return heros
|
||||||
}
|
}
|
||||||
|
|
||||||
|
42
src/models/AdRecord.ts
Normal file
42
src/models/AdRecord.ts
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
import { dbconn } from '../decorators/dbconn'
|
||||||
|
import {
|
||||||
|
getModelForClass,
|
||||||
|
index,
|
||||||
|
modelOptions,
|
||||||
|
plugin,
|
||||||
|
prop
|
||||||
|
} from '@typegoose/typegoose'
|
||||||
|
import {
|
||||||
|
Base,
|
||||||
|
FindOrCreate,
|
||||||
|
TimeStamps
|
||||||
|
} from '@typegoose/typegoose/lib/defaultClasses'
|
||||||
|
// @ts-ignore
|
||||||
|
import findOrCreate from 'mongoose-findorcreate'
|
||||||
|
|
||||||
|
|
||||||
|
interface AdRecordClass extends Base<string>, TimeStamps {
|
||||||
|
}
|
||||||
|
|
||||||
|
@dbconn()
|
||||||
|
@index({ 'accountid': 1 , 'day': 1}, { unique: true })
|
||||||
|
@plugin(findOrCreate)
|
||||||
|
@modelOptions({
|
||||||
|
schemaOptions:
|
||||||
|
{ collection: 'ad_record', timestamps: true }
|
||||||
|
})
|
||||||
|
class AdRecordClass extends FindOrCreate {
|
||||||
|
@prop()
|
||||||
|
public accountid: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public day: string
|
||||||
|
|
||||||
|
@prop({ default: 0 })
|
||||||
|
public count: number
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export const AdRecord = getModelForClass(AdRecordClass,
|
||||||
|
// @ts-ignore
|
||||||
|
{ existingConnection: AdRecordClass['db'] })
|
Loading…
x
Reference in New Issue
Block a user