统一物品的返回格式
This commit is contained in:
parent
f92af1cd1f
commit
5baf4ddeb5
22
docs/api.md
22
docs/api.md
@ -338,8 +338,9 @@
|
||||
```js
|
||||
[ //附件列表
|
||||
{
|
||||
"itemid": 0, //道具id
|
||||
"itemnum": 0, //道具数量
|
||||
"id": 0, //道具id
|
||||
"count": 0, //道具数量
|
||||
"type": 1 //道具类型
|
||||
},
|
||||
]
|
||||
|
||||
@ -365,9 +366,10 @@
|
||||
```js
|
||||
[ //物品列表
|
||||
{
|
||||
"itemid": 0, //道具id
|
||||
"itemnum": 0, //道具数量
|
||||
},
|
||||
"id": 0, //道具id
|
||||
"count": 0, //道具数量
|
||||
"type": 1 //道具类型
|
||||
}
|
||||
]
|
||||
|
||||
```
|
||||
@ -392,8 +394,9 @@
|
||||
```js
|
||||
[ //物品列表
|
||||
{
|
||||
"itemid": 0, //道具id
|
||||
"itemnum": 0, //道具数量
|
||||
"id": 0, //道具id
|
||||
"count": 0, //道具数量
|
||||
"type": 1 //道具类型
|
||||
},
|
||||
]
|
||||
|
||||
@ -468,8 +471,9 @@
|
||||
```js
|
||||
[ //物品列表
|
||||
{
|
||||
"itemid": 0, //道具id
|
||||
"itemnum": 0, //道具数量
|
||||
"id": 0, //道具id
|
||||
"count": 0, //道具数量
|
||||
"type": 1 //道具类型
|
||||
},
|
||||
]
|
||||
|
||||
|
@ -3,6 +3,8 @@ import { router } from '../decorators/router'
|
||||
import { getAttachment } from '../service/mail'
|
||||
import { ZError } from '../common/ZError'
|
||||
import { BagItem, getItemType } from '../models/BagItem'
|
||||
import ItemCtrl from '../logic/ItemCtrl'
|
||||
import { ItemInfo } from '../logic/ItemDef'
|
||||
|
||||
export default class MailController extends BaseController {
|
||||
|
||||
@ -13,19 +15,18 @@ export default class MailController extends BaseController {
|
||||
if (data.errcode) {
|
||||
throw new ZError(data.errcode, data.errmsg)
|
||||
}
|
||||
let items: ItemInfo[] = []
|
||||
if (data.attachments && data.attachments.length > 0) {
|
||||
for (let obj of data.attachments) {
|
||||
let itemType = getItemType(obj.itemid << 0)
|
||||
let item = (await BagItem.findOrCreate({
|
||||
accountid,
|
||||
itemid: obj.itemid,
|
||||
itemtype: itemType
|
||||
})).doc
|
||||
item.count += obj.itemnum
|
||||
await item.save()
|
||||
let itemStr = ''
|
||||
for (let i = 0; i < data.attachments.length; i++) {
|
||||
const obj = data.attachments[i]
|
||||
if (i > 0) itemStr += '|'
|
||||
itemStr += `${obj.itemid}:${obj.itemnum}`
|
||||
}
|
||||
items = ItemCtrl.getItemsByInfo(itemStr)
|
||||
await BagItem.addItems(accountid, items)
|
||||
}
|
||||
return data.attachments
|
||||
return items
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -89,8 +89,9 @@ class BagItemClass extends FindOrCreate {
|
||||
|
||||
public toJson() {
|
||||
return {
|
||||
itemid: this.itemid,
|
||||
itemnum: this.count
|
||||
id: this.itemid,
|
||||
count: this.count,
|
||||
type: this.itemtype
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user