统一物品的返回格式

This commit is contained in:
zhl 2021-01-22 13:39:05 +08:00
parent f92af1cd1f
commit 5baf4ddeb5
3 changed files with 27 additions and 21 deletions

View File

@ -338,8 +338,9 @@
```js ```js
[ //附件列表 [ //附件列表
{ {
"itemid": 0, //道具id "id": 0, //道具id
"itemnum": 0, //道具数量 "count": 0, //道具数量
"type": 1 //道具类型
}, },
] ]
@ -365,9 +366,10 @@
```js ```js
[ //物品列表 [ //物品列表
{ {
"itemid": 0, //道具id "id": 0, //道具id
"itemnum": 0, //道具数量 "count": 0, //道具数量
}, "type": 1 //道具类型
}
] ]
``` ```
@ -392,8 +394,9 @@
```js ```js
[ //物品列表 [ //物品列表
{ {
"itemid": 0, //道具id "id": 0, //道具id
"itemnum": 0, //道具数量 "count": 0, //道具数量
"type": 1 //道具类型
}, },
] ]
@ -468,8 +471,9 @@
```js ```js
[ //物品列表 [ //物品列表
{ {
"itemid": 0, //道具id "id": 0, //道具id
"itemnum": 0, //道具数量 "count": 0, //道具数量
"type": 1 //道具类型
}, },
] ]

View File

@ -3,6 +3,8 @@ import { router } from '../decorators/router'
import { getAttachment } from '../service/mail' import { getAttachment } from '../service/mail'
import { ZError } from '../common/ZError' import { ZError } from '../common/ZError'
import { BagItem, getItemType } from '../models/BagItem' import { BagItem, getItemType } from '../models/BagItem'
import ItemCtrl from '../logic/ItemCtrl'
import { ItemInfo } from '../logic/ItemDef'
export default class MailController extends BaseController { export default class MailController extends BaseController {
@ -13,19 +15,18 @@ export default class MailController extends BaseController {
if (data.errcode) { if (data.errcode) {
throw new ZError(data.errcode, data.errmsg) throw new ZError(data.errcode, data.errmsg)
} }
let items: ItemInfo[] = []
if (data.attachments && data.attachments.length > 0) { if (data.attachments && data.attachments.length > 0) {
for (let obj of data.attachments) { let itemStr = ''
let itemType = getItemType(obj.itemid << 0) for (let i = 0; i < data.attachments.length; i++) {
let item = (await BagItem.findOrCreate({ const obj = data.attachments[i]
accountid, if (i > 0) itemStr += '|'
itemid: obj.itemid, itemStr += `${obj.itemid}:${obj.itemnum}`
itemtype: itemType
})).doc
item.count += obj.itemnum
await item.save()
} }
items = ItemCtrl.getItemsByInfo(itemStr)
await BagItem.addItems(accountid, items)
} }
return data.attachments return items
} }
} }

View File

@ -89,8 +89,9 @@ class BagItemClass extends FindOrCreate {
public toJson() { public toJson() {
return { return {
itemid: this.itemid, id: this.itemid,
itemnum: this.count count: this.count,
type: this.itemtype
} }
} }
} }