[Refactor][Enhance] unlock items & Steps' difficulty restrict

- Refactor some codes about unlocking or locking some users' packs and singles
- Add support for restricting songs' difficulty in the map's steps of world mode
This commit is contained in:
Lost-MSth
2023-01-24 16:45:09 +08:00
parent 88d949fc18
commit 9fbdcd5edb
4 changed files with 96 additions and 49 deletions

View File

@@ -2,7 +2,7 @@ import os
import time
from core.init import FileChecker
from core.operation import RefreshAllScoreRating, RefreshSongFileCache, SaveUpdateScore
from core.operation import RefreshAllScoreRating, RefreshSongFileCache, SaveUpdateScore, UnlockUserItem
from core.rank import RankList
from core.sql import Connect
from core.user import User
@@ -606,7 +606,7 @@ def edit_user_purchase():
if 'name' not in request.form and 'user_code' not in request.form:
flag = False
if method == '0':
web.system.unlock_all_user_item(c)
UnlockUserItem().run()
else:
c.execute(
'''delete from user_item where type in ('pack', 'single')''')
@@ -632,7 +632,9 @@ def edit_user_purchase():
user_id = user_id[0]
if method == '0':
web.system.unlock_user_item(c, user_id)
x = UnlockUserItem()
x.set_params(user_id=user_id)
x.run()
else:
c.execute('''delete from user_item where type in ('pack', 'single') and user_id = :user_id''', {
'user_id': user_id})

View File

@@ -40,41 +40,6 @@ def update_user_char(c):
(j[0], i[0], i[1], exp, i[2], 0))
def unlock_all_user_item(c):
# 解锁所有用户购买
c.execute('''select user_id from user''')
x = c.fetchall()
c.execute('''select item_id, type from purchase_item''')
y = c.fetchall()
if x and y:
for i in x:
for j in y:
c.execute('''select exists(select * from user_item where user_id=:a and item_id=:b and type=:c)''', {
'a': i[0], 'b': j[0], 'c': j[1]})
if c.fetchone() == (0,) and j[1] != 'character':
c.execute('''insert into user_item values(:a,:b,:c,1)''', {
'a': i[0], 'b': j[0], 'c': j[1]})
return
def unlock_user_item(c, user_id):
# 解锁用户购买
c.execute('''select item_id, type from purchase_item''')
y = c.fetchall()
for j in y:
c.execute('''select exists(select * from user_item where user_id=:a and item_id=:b and type=:c)''', {
'a': user_id, 'b': j[0], 'c': j[1]})
if c.fetchone() == (0,) and j[1] != 'character':
c.execute('''insert into user_item values(:a,:b,:c,1)''', {
'a': user_id, 'b': j[0], 'c': j[1]})
return
def get_all_item():
# 所有物品数据查询
with Connect() as c: