将分解卡改为同时分解多个卡
This commit is contained in:
parent
6b1b9f7f58
commit
26f59b13b2
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"redis": "redis://127.0.0.1:6379/15",
|
"redis": "redis://127.0.0.1:6379/15",
|
||||||
"db_main": "mongodb://192.168.100.24/card-development",
|
"db_main": "mongodb://127.0.0.1/card-development",
|
||||||
"port": 2987
|
"port": 2987
|
||||||
}
|
}
|
||||||
|
@ -431,10 +431,10 @@
|
|||||||
> POST参数
|
> POST参数
|
||||||
|
|
||||||
|
|
||||||
| 字段 | 说明 |
|
| 字段 | | 说明 |
|
||||||
| -------- | -------------------------------------- |
|
| -------- |--| -------------------------------------- |
|
||||||
| cardid |卡牌id |
|
|cards |cardid |卡牌id |
|
||||||
| count |使用数量 |
|
| |count |使用数量 |
|
||||||
|
|
||||||
3. Response: JSON
|
3. Response: JSON
|
||||||
|
|
||||||
@ -443,7 +443,6 @@
|
|||||||
{
|
{
|
||||||
"id": 0, //道具id
|
"id": 0, //道具id
|
||||||
"count": 0, //道具数量
|
"count": 0, //道具数量
|
||||||
"type": 1 //道具类型
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -231,30 +231,49 @@ export default class CardController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@router('post /api/:accountid/card/destory')
|
@router('post /api/:accountid/card/destory')
|
||||||
async destoryCard(req: any) {
|
async destoryCards(req: any) {
|
||||||
let { cardid, count, accountid } = req.params
|
let {cards, accountid} = req.params
|
||||||
let record = await BagItem.findOne({
|
let resultMap: Map<number, number> = new Map()
|
||||||
accountid,
|
let typeMap: Map<number, number> = new Map()
|
||||||
itemid: cardid,
|
let records: any[] = []
|
||||||
itemtype: ItemType.CARD
|
for (let card of cards) {
|
||||||
})
|
let record = await BagItem.findOne({
|
||||||
if (!record) {
|
accountid,
|
||||||
throw new ZError(11, 'item not found')
|
itemid: card.cardid,
|
||||||
|
itemtype: ItemType.CARD
|
||||||
|
})
|
||||||
|
if (!record) {
|
||||||
|
throw new ZError(11, 'item not found')
|
||||||
|
}
|
||||||
|
if (record.count < card.count) {
|
||||||
|
throw new ZError(12, 'not enough item')
|
||||||
|
}
|
||||||
|
record.count -= card.count
|
||||||
|
let data = ItemCtrl.decomposeItemCard(card.cardid, card.count)
|
||||||
|
for (let obj of data) {
|
||||||
|
resultMap.inc(obj.id, obj.count)
|
||||||
|
typeMap.set(obj.id, obj.type)
|
||||||
|
}
|
||||||
|
records.push(record)
|
||||||
|
|
||||||
}
|
}
|
||||||
if (record.count < count) {
|
let result: any = []
|
||||||
throw new ZError(12, 'not enough item')
|
for (let [id, count] of resultMap) {
|
||||||
}
|
|
||||||
let data = ItemCtrl.decomposeItemCard(cardid, count)
|
|
||||||
for (let obj of data) {
|
|
||||||
let item = (await BagItem.findOrCreate({
|
let item = (await BagItem.findOrCreate({
|
||||||
accountid,
|
accountid,
|
||||||
itemid: obj.id,
|
itemid: id,
|
||||||
itemtype: obj.type
|
itemtype: typeMap.get(id)
|
||||||
})).doc
|
})).doc
|
||||||
item.count += obj.count
|
item.count += count
|
||||||
|
result.push({
|
||||||
|
id, count
|
||||||
|
})
|
||||||
await item.save()
|
await item.save()
|
||||||
}
|
}
|
||||||
await record.save()
|
for (let record of records) {
|
||||||
return data
|
await record.save()
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user