增加统一的事件完成接口
This commit is contained in:
parent
5ba40b2716
commit
20fbd7a5aa
10
docs/api.md
10
docs/api.md
@ -630,14 +630,20 @@
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### 24. 视频广告上报
|
### 24. 事件上报
|
||||||
|
|
||||||
1. Method: POST
|
1. Method: POST
|
||||||
2. URI: /api/:accountid/adresult
|
2. URI: /api/:accountid/update_event
|
||||||
|
|
||||||
| 字段 | 说明 |
|
| 字段 | 说明 |
|
||||||
| -------- | -------------------------------------- |
|
| -------- | -------------------------------------- |
|
||||||
| accountid | 帐号id |
|
| accountid | 帐号id |
|
||||||
|
> POST参数
|
||||||
|
|
||||||
|
|
||||||
|
| 字段 |说明 |
|
||||||
|
| -------- | -------------------------------------- |
|
||||||
|
|id |事件id |
|
||||||
|
|
||||||
3. Response: JSON
|
3. Response: JSON
|
||||||
|
|
||||||
|
13
package-lock.json
generated
13
package-lock.json
generated
@ -1002,6 +1002,19 @@
|
|||||||
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz",
|
"resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.20.tgz",
|
||||||
"integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw=="
|
"integrity": "sha512-a1cQNyczgKbLX9jwbS/+d7W8fX/RfgYR7lVWwWOGIPNgK2m0MWvrGF6/m4kk6U3QcFMnZf3RIhL0v2Jgh/0Uxw=="
|
||||||
},
|
},
|
||||||
|
"node": {
|
||||||
|
"version": "14.15.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/node/-/node-14.15.1.tgz",
|
||||||
|
"integrity": "sha512-BeTf2muiTEC7o3w0sUJ83GHORQ+FLNZCouQUM3VJk3LKf1keQ6ldghELrOo6nBUNZBBS5I++pgDSYPhHWcpp8w==",
|
||||||
|
"requires": {
|
||||||
|
"node-bin-setup": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node-bin-setup": {
|
||||||
|
"version": "1.0.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/node-bin-setup/-/node-bin-setup-1.0.6.tgz",
|
||||||
|
"integrity": "sha512-uPIxXNis1CRbv1DwqAxkgBk5NFV3s7cMN/Gf556jSw6jBvV7ca4F9lRL/8cALcZecRibeqU+5dFYqFFmzv5a0Q=="
|
||||||
|
},
|
||||||
"npm-run-path": {
|
"npm-run-path": {
|
||||||
"version": "4.0.1",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/npm-run-path/-/npm-run-path-4.0.1.tgz",
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
"mongoose": "5.10.3",
|
"mongoose": "5.10.3",
|
||||||
"mongoose-findorcreate": "^3.0.0",
|
"mongoose-findorcreate": "^3.0.0",
|
||||||
"nanoid": "^3.1.20",
|
"nanoid": "^3.1.20",
|
||||||
|
"node": "^14.15.1",
|
||||||
"redis": "^2.8.0",
|
"redis": "^2.8.0",
|
||||||
"tracer": "^1.1.4",
|
"tracer": "^1.1.4",
|
||||||
"urlencode": "^1.1.0"
|
"urlencode": "^1.1.0"
|
||||||
|
@ -9,6 +9,7 @@ import { MatchCfg } from '../cfg/parsers/MatchCfg'
|
|||||||
import { ItemFuncCfg } from '../cfg/parsers/ItemFuncCfg'
|
import { ItemFuncCfg } from '../cfg/parsers/ItemFuncCfg'
|
||||||
import ItemCtrl from "../logic/ItemCtrl";
|
import ItemCtrl from "../logic/ItemCtrl";
|
||||||
import { EffectCardCfg } from '../cfg/parsers/EffectCardCfg'
|
import { EffectCardCfg } from '../cfg/parsers/EffectCardCfg'
|
||||||
|
import { IncomeCfg } from '../cfg/parsers/IncomeCfg'
|
||||||
|
|
||||||
|
|
||||||
export function initData() {
|
export function initData() {
|
||||||
@ -21,6 +22,7 @@ export function initData() {
|
|||||||
rP(BaseConst.ITEMCARD, ItemCardCfg);
|
rP(BaseConst.ITEMCARD, ItemCardCfg);
|
||||||
rP(BaseConst.MATCH, MatchCfg);
|
rP(BaseConst.MATCH, MatchCfg);
|
||||||
rP(BaseConst.ITEMFUNC, ItemFuncCfg);
|
rP(BaseConst.ITEMFUNC, ItemFuncCfg);
|
||||||
|
rP(BaseConst.INCOME, IncomeCfg);
|
||||||
DataParser.loadAll();
|
DataParser.loadAll();
|
||||||
ItemCtrl.initItems();
|
ItemCtrl.initItems();
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,7 @@ export class BaseConst {
|
|||||||
public static readonly ITEMCARD = "itemcard";
|
public static readonly ITEMCARD = "itemcard";
|
||||||
public static readonly MATCH = "match";
|
public static readonly MATCH = "match";
|
||||||
public static readonly ITEMFUNC = "itemfunc";
|
public static readonly ITEMFUNC = "itemfunc";
|
||||||
|
public static readonly INCOME = "income";
|
||||||
/**
|
/**
|
||||||
* 缓存的机器人信息在redis中的key
|
* 缓存的机器人信息在redis中的key
|
||||||
*/
|
*/
|
||||||
|
48
src/controllers/ActivityController.ts
Normal file
48
src/controllers/ActivityController.ts
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import BaseController from '../common/base.controller'
|
||||||
|
import { router } from '../decorators/router'
|
||||||
|
import { ActRecord } from '../models/ActRecord'
|
||||||
|
import { BaseConst } from '../constants/BaseConst'
|
||||||
|
import { ZError } from '../common/ZError'
|
||||||
|
import { ItemInfo } from '../logic/ItemDef'
|
||||||
|
import ItemCtrl from '../logic/ItemCtrl'
|
||||||
|
import { BagItem } from '../models/BagItem'
|
||||||
|
|
||||||
|
export default class ActivityController extends BaseController {
|
||||||
|
|
||||||
|
@router('post /api/:accountid/update_event')
|
||||||
|
async generalEvent(req: any) {
|
||||||
|
let { id,accountid } = req.params
|
||||||
|
let cfgMap = global.$cfg.get(BaseConst.INCOME)
|
||||||
|
id = +id
|
||||||
|
if (!cfgMap.has(id)) {
|
||||||
|
throw new ZError(11, 'no cfg found')
|
||||||
|
}
|
||||||
|
let cfg = cfgMap.get(id)
|
||||||
|
let day
|
||||||
|
if (cfg.repeat) {
|
||||||
|
day = (new Date()).format('yyyy-MM-dd', true)
|
||||||
|
} else {
|
||||||
|
day = (new Date(0)).format('yyyy-MM-dd', true)
|
||||||
|
}
|
||||||
|
let record = (await ActRecord.findOrCreate({accountid, day})).doc
|
||||||
|
if (!cfg.repeat && record.count > 0) {
|
||||||
|
throw new ZError(12, 'already goted')
|
||||||
|
}
|
||||||
|
if (cfg.repeat && record.count >= cfg.frequency ) {
|
||||||
|
throw new ZError(13, 'reach today max count')
|
||||||
|
}
|
||||||
|
if (cfg.interval && (Date.now() - record.lasttime) < cfg.interval) {
|
||||||
|
throw new ZError(14, '操作太快了')
|
||||||
|
}
|
||||||
|
if (cfg.id == 9003 && record.count == 0) {
|
||||||
|
cfg = cfg.get(9004)
|
||||||
|
}
|
||||||
|
record.count += 1
|
||||||
|
record.lasttime = Date.now()
|
||||||
|
await record.save()
|
||||||
|
const itemInfos: ItemInfo[] = ItemCtrl.getItemsByInfo(cfg.income)
|
||||||
|
await BagItem.addItems(accountid, itemInfos)
|
||||||
|
await record.save()
|
||||||
|
return itemInfos
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,5 @@
|
|||||||
import BaseController from '../common/base.controller'
|
import BaseController from '../common/base.controller'
|
||||||
import { router } from '../decorators/router'
|
|
||||||
import { AdRecord } from '../models/AdRecord'
|
|
||||||
|
|
||||||
export default class AdController extends BaseController {
|
export default class AdController extends BaseController {
|
||||||
/**
|
/**
|
||||||
@ -8,14 +7,14 @@ export default class AdController extends BaseController {
|
|||||||
* @param req
|
* @param req
|
||||||
* @return {Promise<{}>}
|
* @return {Promise<{}>}
|
||||||
*/
|
*/
|
||||||
@router('post /api/:accountid/adresult')
|
// @router('post /api/:accountid/adresult')
|
||||||
async drawCard(req: any) {
|
// async drawCard(req: any) {
|
||||||
let { accountid } = req.params
|
// let { accountid } = req.params
|
||||||
let day = (new Date()).format('yyyy-MM-dd', true)
|
// let day = (new Date()).format('yyyy-MM-dd', true)
|
||||||
let record = (await AdRecord.findOrCreate({accountid, day})).doc
|
// let record = (await AdRecord.findOrCreate({accountid, day})).doc
|
||||||
record.count += 1
|
// record.count += 1
|
||||||
//TODO:: 读取配置, 查看次数是否达到上限, 添加物品
|
// //TODO:: 读取配置, 查看次数是否达到上限, 添加物品
|
||||||
await record.save()
|
// await record.save()
|
||||||
return {}
|
// return {}
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
@ -15,28 +15,34 @@ import {
|
|||||||
import findOrCreate from 'mongoose-findorcreate'
|
import findOrCreate from 'mongoose-findorcreate'
|
||||||
|
|
||||||
|
|
||||||
interface AdRecordClass extends Base<string>, TimeStamps {
|
interface ActRecordClass extends Base<string>, TimeStamps {
|
||||||
}
|
}
|
||||||
|
|
||||||
@dbconn()
|
@dbconn()
|
||||||
@index({ 'accountid': 1 , 'day': 1}, { unique: true })
|
@index({ 'accountid': 1 , actid: 1, 'day': 1}, { unique: true })
|
||||||
@plugin(findOrCreate)
|
@plugin(findOrCreate)
|
||||||
@modelOptions({
|
@modelOptions({
|
||||||
schemaOptions:
|
schemaOptions:
|
||||||
{ collection: 'ad_record', timestamps: true }
|
{ collection: 'act_record', timestamps: true }
|
||||||
})
|
})
|
||||||
class AdRecordClass extends FindOrCreate {
|
class ActRecordClass extends FindOrCreate {
|
||||||
@prop()
|
@prop()
|
||||||
public accountid: string
|
public accountid: string
|
||||||
|
|
||||||
|
@prop()
|
||||||
|
public actid: string
|
||||||
|
|
||||||
@prop()
|
@prop()
|
||||||
public day: string
|
public day: string
|
||||||
|
|
||||||
@prop({ default: 0 })
|
@prop({ default: 0 })
|
||||||
public count: number
|
public count: number
|
||||||
|
|
||||||
|
@prop({default: Date.now()})
|
||||||
|
public lasttime: number
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AdRecord = getModelForClass(AdRecordClass,
|
export const ActRecord = getModelForClass(ActRecordClass,
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
{ existingConnection: AdRecordClass['db'] })
|
{ existingConnection: ActRecordClass['db'] })
|
Loading…
x
Reference in New Issue
Block a user