mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-06 15:37:26 +08:00
@@ -447,31 +447,31 @@ def edit_char():
|
||||
c.execute(
|
||||
'''select exists(select * from character where character_id=:a)''', {'a': character_id})
|
||||
if c.fetchone() == (1,):
|
||||
if not level and not frag and not prog and not overdrive and not skill_id and not skill_id_uncap:
|
||||
if level is None and frag is None and prog is None and overdrive is None and skill_id is None and skill_id_uncap is None:
|
||||
error = '无修改 No change.'
|
||||
else:
|
||||
|
||||
sql = '''update character set level_exp=25000'''
|
||||
sql_dict = {'character_id': character_id}
|
||||
if level:
|
||||
if level is not None:
|
||||
sql += ', level = :level'
|
||||
sql_dict['level'] = level
|
||||
if frag:
|
||||
if frag is not None:
|
||||
sql += ', frag = :frag'
|
||||
sql_dict['frag'] = frag
|
||||
if prog:
|
||||
if prog is not None:
|
||||
sql += ', prog = :prog'
|
||||
sql_dict['prog'] = prog
|
||||
if overdrive:
|
||||
if overdrive is not None:
|
||||
sql += ', overdrive = :overdrive'
|
||||
sql_dict['overdrive'] = overdrive
|
||||
if skill_id:
|
||||
if skill_id is not None:
|
||||
sql += ', skill_id = :skill_id'
|
||||
if skill_id == 'No_skill':
|
||||
sql_dict['skill_id'] = ''
|
||||
else:
|
||||
sql_dict['skill_id'] = skill_id
|
||||
if skill_id_uncap:
|
||||
if skill_id_uncap is not None:
|
||||
sql += ', skill_id_uncap = :skill_id_uncap'
|
||||
if skill_id_uncap == 'No_skill':
|
||||
sql_dict['skill_id_uncap'] = ''
|
||||
@@ -520,12 +520,42 @@ def edit_user():
|
||||
# 修改用户数据
|
||||
|
||||
error = None
|
||||
name = request.form['name']
|
||||
user_code = request.form['user_code']
|
||||
flag = True
|
||||
name = None
|
||||
user_code = None
|
||||
try:
|
||||
ticket = request.form['ticket']
|
||||
if ticket:
|
||||
ticket = int(ticket)
|
||||
else:
|
||||
ticket = None
|
||||
except:
|
||||
error = '数据错误 Wrong data.'
|
||||
flash(error)
|
||||
return redirect(url_for('index.change_user'))
|
||||
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
|
||||
# 全修改
|
||||
if 'name' not in request.form and 'user_code' not in request.form:
|
||||
flag = False
|
||||
if not ticket:
|
||||
error = '无修改 No change.'
|
||||
else:
|
||||
sql = '''update user set ticket = :ticket'''
|
||||
sql_dict = {'ticket': ticket}
|
||||
c.execute(sql, sql_dict)
|
||||
flash("全部用户信息修改成功 Successfully edit all the users' information.")
|
||||
|
||||
else:
|
||||
name = request.form['name']
|
||||
user_code = request.form['user_code']
|
||||
|
||||
# 指定修改
|
||||
|
||||
if name or user_code:
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
|
||||
if user_code:
|
||||
c.execute('''select user_id from user where user_code=:a''', {
|
||||
'a': user_code})
|
||||
@@ -537,16 +567,6 @@ def edit_user():
|
||||
posts = []
|
||||
if user_id:
|
||||
user_id = user_id[0]
|
||||
try:
|
||||
ticket = request.form['ticket']
|
||||
if ticket:
|
||||
ticket = int(ticket)
|
||||
else:
|
||||
ticket = None
|
||||
except:
|
||||
error = '数据错误 Wrong data.'
|
||||
flash(error)
|
||||
return redirect(url_for('index.change_user'))
|
||||
|
||||
if not ticket:
|
||||
error = '无修改 No change.'
|
||||
@@ -560,12 +580,190 @@ def edit_user():
|
||||
error = '玩家不存在 The player does not exist.'
|
||||
|
||||
else:
|
||||
error = '输入为空 Null Input.'
|
||||
if flag:
|
||||
error = '输入为空 Null Input.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
if error:
|
||||
flash(error)
|
||||
|
||||
return redirect(url_for('index.change_user'))
|
||||
|
||||
|
||||
@bp.route('/changeuserpurchase', methods=['GET'])
|
||||
@login_required
|
||||
def change_user_purchase():
|
||||
# 修改用户购买
|
||||
|
||||
return render_template('web/changeuserpurchase.html')
|
||||
|
||||
|
||||
@bp.route('/changeuserpurchase/edituser', methods=['POST'])
|
||||
@login_required
|
||||
def edit_user_purchase():
|
||||
# 修改用户购买
|
||||
|
||||
error = None
|
||||
flag = True
|
||||
name = None
|
||||
user_code = None
|
||||
try:
|
||||
method = request.form['method']
|
||||
except:
|
||||
flash('输入为空 Null Input.')
|
||||
return redirect(url_for('index.change_user_purchase'))
|
||||
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
|
||||
# 全修改
|
||||
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)
|
||||
else:
|
||||
c.execute('''delete from user_item''')
|
||||
|
||||
flash("全部用户购买信息修改成功 Successfully edit all the users' purchase information.")
|
||||
|
||||
else:
|
||||
name = request.form['name']
|
||||
user_code = request.form['user_code']
|
||||
|
||||
# 指定修改
|
||||
if name or user_code:
|
||||
|
||||
if user_code:
|
||||
c.execute('''select user_id from user where user_code=:a''', {
|
||||
'a': user_code})
|
||||
else:
|
||||
c.execute(
|
||||
'''select user_id from user where name=:a''', {'a': name})
|
||||
|
||||
user_id = c.fetchone()
|
||||
posts = []
|
||||
if user_id:
|
||||
user_id = user_id[0]
|
||||
|
||||
if method == '0':
|
||||
web.system.unlock_user_item(c, user_id)
|
||||
else:
|
||||
c.execute('''delete from user_item where user_id=:a''', {
|
||||
'a': user_id})
|
||||
flash('用户购买信息修改成功 Successfully edit the user purchase information.')
|
||||
|
||||
else:
|
||||
error = '玩家不存在 The player does not exist.'
|
||||
|
||||
else:
|
||||
if flag:
|
||||
error = '输入为空 Null Input.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
if error:
|
||||
flash(error)
|
||||
|
||||
return redirect(url_for('index.change_user_purchase'))
|
||||
|
||||
|
||||
@bp.route('/allitem', methods=['GET'])
|
||||
@login_required
|
||||
def all_item():
|
||||
# 所有购买数据
|
||||
|
||||
error = None
|
||||
posts = web.system.get_all_item()
|
||||
if not posts:
|
||||
error = '没有购买数据 No item data.'
|
||||
|
||||
if error:
|
||||
flash(error)
|
||||
return redirect(url_for('index.all_item'))
|
||||
else:
|
||||
return render_template('web/allitem.html', posts=posts)
|
||||
|
||||
|
||||
@bp.route('/changeitem', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def change_item():
|
||||
# 修改购买信息
|
||||
|
||||
error = None
|
||||
if request.method == 'POST':
|
||||
try:
|
||||
item_id = request.form['item_id']
|
||||
item_type = request.form['type']
|
||||
price = request.form['price']
|
||||
orig_price = request.form['orig_price']
|
||||
discount_from = request.form['discount_from']
|
||||
discount_to = request.form['discount_to']
|
||||
try:
|
||||
is_available = request.form['is_available']
|
||||
if is_available:
|
||||
is_available = int(is_available)
|
||||
else:
|
||||
is_available = None
|
||||
except:
|
||||
is_available = None
|
||||
|
||||
if price:
|
||||
price = int(price)
|
||||
else:
|
||||
price = None
|
||||
if orig_price:
|
||||
orig_price = int(orig_price)
|
||||
else:
|
||||
orig_price = None
|
||||
if discount_from:
|
||||
discount_from = int(time.mktime(time.strptime(discount_from, "%Y-%m-%dT%H:%M"))) * 1000
|
||||
else:
|
||||
discount_from = None
|
||||
if discount_to:
|
||||
discount_to = int(time.mktime(time.strptime(discount_to, "%Y-%m-%dT%H:%M"))) * 1000
|
||||
else:
|
||||
discount_to = None
|
||||
except:
|
||||
error = '数据错误 Wrong data.'
|
||||
flash(error)
|
||||
return redirect(url_for('index.change_item'))
|
||||
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute(
|
||||
'''select exists(select * from item where item_id=:a and type=:b)''', {'a': item_id, 'b': item_type})
|
||||
if c.fetchone() == (1,):
|
||||
if is_available is None and price is None and orig_price is None and not discount_from and not discount_to:
|
||||
error = '无修改 No change.'
|
||||
else:
|
||||
sql = '''update item set type=:type'''
|
||||
sql_dict = {'item_id': item_id, 'type': item_type}
|
||||
if price is not None:
|
||||
sql += ', price = :price'
|
||||
sql_dict['price'] = price
|
||||
if orig_price is not None:
|
||||
sql += ', orig_price = :orig_price'
|
||||
sql_dict['orig_price'] = orig_price
|
||||
if discount_from is not None:
|
||||
sql += ', discount_from = :discount_from'
|
||||
sql_dict['discount_from'] = discount_from
|
||||
if discount_to is not None:
|
||||
sql += ', discount_to = :discount_to'
|
||||
sql_dict['discount_to'] = discount_to
|
||||
if is_available is not None:
|
||||
sql += ', is_available = :is_available'
|
||||
sql_dict['is_available'] = is_available
|
||||
|
||||
sql += ' where item_id = :item_id and type = :type'
|
||||
c.execute(sql, sql_dict)
|
||||
flash('购买项目修改成功 Successfully edit the item.')
|
||||
else:
|
||||
error = '购买项目不存在 The item does not exist.'
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
if error:
|
||||
flash(error)
|
||||
|
||||
return render_template('web/changeitem.html')
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import os
|
||||
import sqlite3
|
||||
import time
|
||||
|
||||
|
||||
def int2b(x):
|
||||
# int与布尔值转换
|
||||
if x is None or x == 0:
|
||||
return False
|
||||
else:
|
||||
return True
|
||||
|
||||
|
||||
def get_table_info(c, table_name):
|
||||
@@ -76,6 +85,13 @@ def get_sql_insert_table(table_name, field, value):
|
||||
|
||||
def update_one_table(c1, c2, table_name):
|
||||
# 从c1向c2更新数据表,c2中存在的信息不变
|
||||
c1.execute(
|
||||
'''select * from sqlite_master where type = 'table' and name = :a''', {'a': table_name})
|
||||
c2.execute(
|
||||
'''select * from sqlite_master where type = 'table' and name = :a''', {'a': table_name})
|
||||
if not c1.fetchone() or not c2.fetchone():
|
||||
return 'error'
|
||||
|
||||
db1_pk, db1_name = get_table_info(c1, table_name)
|
||||
db2_pk, db2_name = get_table_info(c2, table_name)
|
||||
if db1_pk != db2_pk:
|
||||
@@ -124,7 +140,7 @@ def update_user_char(c):
|
||||
|
||||
def update_database():
|
||||
# 将old数据库不存在数据加入到新数据库上,并删除old数据库
|
||||
# 对于arcaea_datebase.db,更新best_score,friend,recent30,user,user_world并用character数据更新user_char
|
||||
# 对于arcaea_datebase.db,更新best_score,friend,recent30,user,user_world, user_item并用character数据更新user_char
|
||||
# 对于arcsong.db,更新songs
|
||||
if os.path.isfile("database/old_arcaea_database.db") and os.path.isfile("database/arcaea_database.db"):
|
||||
conn1 = sqlite3.connect('./database/old_arcaea_database.db')
|
||||
@@ -137,6 +153,7 @@ def update_database():
|
||||
update_one_table(c1, c2, 'best_score')
|
||||
update_one_table(c1, c2, 'recent30')
|
||||
update_one_table(c1, c2, 'user_world')
|
||||
update_one_table(c1, c2, 'user_item')
|
||||
|
||||
update_user_char(c2)
|
||||
|
||||
@@ -160,3 +177,69 @@ def update_database():
|
||||
conn2.commit()
|
||||
conn2.close()
|
||||
os.remove('database/old_arcsong.db')
|
||||
|
||||
|
||||
def unlock_all_user_item(c):
|
||||
# 解锁所有用户购买
|
||||
|
||||
c.execute('''select user_id from user''')
|
||||
x = c.fetchall()
|
||||
c.execute('''select item_id, type from item''')
|
||||
y = c.fetchall()
|
||||
c.execute('''delete from user_item''')
|
||||
if x and y:
|
||||
for i in x:
|
||||
for j in y:
|
||||
c.execute('''insert into user_item values(:a,:b,:c)''', {
|
||||
'a': i[0], 'b': j[0], 'c': j[1]})
|
||||
|
||||
return
|
||||
|
||||
|
||||
def unlock_user_item(c, user_id):
|
||||
# 解锁用户购买
|
||||
|
||||
c.execute('''select item_id, type from 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,):
|
||||
c.execute('''insert into user_item values(:a,:b,:c)''', {
|
||||
'a': user_id, 'b': j[0], 'c': j[1]})
|
||||
|
||||
return
|
||||
|
||||
|
||||
def get_all_item():
|
||||
# 所有购买数据查询
|
||||
conn = sqlite3.connect('./database/arcaea_database.db')
|
||||
c = conn.cursor()
|
||||
c.execute('''select * from item''')
|
||||
x = c.fetchall()
|
||||
re = []
|
||||
if x:
|
||||
for i in x:
|
||||
discount_from = None
|
||||
discount_to = None
|
||||
|
||||
if i[5] and i[5] >= 0:
|
||||
discount_from = time.strftime(
|
||||
"%Y-%m-%d %H:%M:%S", time.localtime(int(i[5])/1000))
|
||||
if i[6] and i[6] >= 0:
|
||||
discount_to = time.strftime(
|
||||
"%Y-%m-%d %H:%M:%S", time.localtime(int(i[6])//1000))
|
||||
|
||||
re.append({'item_id': i[0],
|
||||
'type': i[1],
|
||||
'is_available': int2b(i[2]),
|
||||
'price': i[3],
|
||||
'orig_price': i[4],
|
||||
'discount_from': discount_from,
|
||||
'discount_to': discount_to
|
||||
})
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return re
|
||||
|
||||
Reference in New Issue
Block a user