获取箱子列表时,如果箱子是锁定的, 那么根据条件判断, 满足的话, 自动解锁

This commit is contained in:
CounterFire2023 2024-03-27 17:24:01 +08:00
parent 24efac0604
commit 1ae103eca8

View File

@ -20,9 +20,11 @@ class BoxController extends BaseController {
@router('get /api/chest/list') @router('get /api/chest/list')
async chestList(req) { async chestList(req) {
const user = req.user const user = req.user
const openRecord = await ChestRecord.find({ from: user.address.toLowerCase() }) const openRecords = await ChestRecord.find({ from: user.address.toLowerCase() })
const chestIds = openRecord.map(record => record.chestId) const chestSet = new Set()
const chestSet = new Set(chestIds) openRecords.forEach(record => {
chestSet.add(record.chestId)
})
const chests = await ActivityChest.find({ const chests = await ActivityChest.find({
activity: user.activity, activity: user.activity,
user: user.id, user: user.id,
@ -30,9 +32,18 @@ class BoxController extends BaseController {
}).sort({ }).sort({
level: -1, level: -1,
}) })
for (let chest of chests) {
// TODO:: 待规则确定后, 将符合条件的锁定的箱子解锁
if (chest.status === 0) {
if (user.allTaskFinished()) {
chest.status = 1
await chest.save()
}
}
}
const results = chests.map(chest => chest.toJson()) const results = chests.map(chest => chest.toJson())
for (let result of results) { for (let result of results) {
if (chestSet.has(result.id)) { if (result.stat > 0 && chestSet.has(result.id)) {
result.stat = 2 result.stat = 2
} }
} }