new
This commit is contained in:
177
main.py
177
main.py
@@ -941,19 +941,35 @@ def checkin_user(checkin_data: CheckinRequest):
|
||||
new_real_id = str(max_id + 1)
|
||||
|
||||
# 2. Insert into gsdh_data first to satisfy Foreign Key
|
||||
insert_user_sql = """
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed)
|
||||
VALUES (%s, %s, %s, %s, '0', 'onsite_checkin', 'TRUE')
|
||||
"""
|
||||
# Use provided company name or default
|
||||
industry_val = checkin_data.company_name or "现场注册"
|
||||
# 先检查 industry_company 列是否存在
|
||||
cur.execute("""
|
||||
SELECT column_name FROM information_schema.columns
|
||||
WHERE table_name = 'gsdh_data' AND column_name = 'industry_company'
|
||||
""")
|
||||
has_industry_col = cur.fetchone() is not None
|
||||
|
||||
cur.execute(insert_user_sql, (
|
||||
new_real_id,
|
||||
checkin_data.name,
|
||||
checkin_data.phone,
|
||||
industry_val
|
||||
))
|
||||
if has_industry_col:
|
||||
insert_user_sql = """
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed)
|
||||
VALUES (%s, %s, %s, %s, '0', 'onsite_checkin', 'TRUE')
|
||||
"""
|
||||
industry_val = checkin_data.company_name or "现场注册"
|
||||
cur.execute(insert_user_sql, (
|
||||
new_real_id,
|
||||
checkin_data.name,
|
||||
checkin_data.phone,
|
||||
industry_val
|
||||
))
|
||||
else:
|
||||
insert_user_sql = """
|
||||
INSERT INTO gsdh_data (new_id, name, phone, fee, payment_channel, is_signed)
|
||||
VALUES (%s, %s, %s, '0', 'onsite_checkin', 'TRUE')
|
||||
"""
|
||||
cur.execute(insert_user_sql, (
|
||||
new_real_id,
|
||||
checkin_data.name,
|
||||
checkin_data.phone
|
||||
))
|
||||
|
||||
# Update ID for subsequent operations
|
||||
final_gsdh_id = new_real_id
|
||||
@@ -1213,18 +1229,38 @@ def add_user_api(user_data: AddUserRequest):
|
||||
max_id = row[0] if row and row[0] is not None else 0
|
||||
new_id = str(max_id + 1)
|
||||
|
||||
insert_sql = """
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, 'FALSE')
|
||||
"""
|
||||
cur.execute(insert_sql, (
|
||||
new_id,
|
||||
user_data.name,
|
||||
user_data.phone,
|
||||
user_data.industry_company,
|
||||
user_data.fee,
|
||||
user_data.payment_channel
|
||||
))
|
||||
# 先检查 industry_company 列是否存在
|
||||
cur.execute("""
|
||||
SELECT column_name FROM information_schema.columns
|
||||
WHERE table_name = 'gsdh_data' AND column_name = 'industry_company'
|
||||
""")
|
||||
has_industry_col = cur.fetchone() is not None
|
||||
|
||||
if has_industry_col:
|
||||
insert_sql = """
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed)
|
||||
VALUES (%s, %s, %s, %s, %s, %s, 'FALSE')
|
||||
"""
|
||||
cur.execute(insert_sql, (
|
||||
new_id,
|
||||
user_data.name,
|
||||
user_data.phone,
|
||||
user_data.industry_company,
|
||||
user_data.fee,
|
||||
user_data.payment_channel
|
||||
))
|
||||
else:
|
||||
insert_sql = """
|
||||
INSERT INTO gsdh_data (new_id, name, phone, fee, payment_channel, is_signed)
|
||||
VALUES (%s, %s, %s, %s, %s, 'FALSE')
|
||||
"""
|
||||
cur.execute(insert_sql, (
|
||||
new_id,
|
||||
user_data.name,
|
||||
user_data.phone,
|
||||
user_data.fee,
|
||||
user_data.payment_channel
|
||||
))
|
||||
|
||||
conn.commit()
|
||||
cur.close()
|
||||
@@ -1423,10 +1459,23 @@ def reset_database():
|
||||
""")
|
||||
|
||||
# Initial Data (Optional - add a test user)
|
||||
# 先检查 industry_company 列是否存在
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed)
|
||||
VALUES ('1', '测试用户', '13800000000', '科技', '0', 'test', 'FALSE');
|
||||
SELECT column_name FROM information_schema.columns
|
||||
WHERE table_name = 'gsdh_data' AND column_name = 'industry_company'
|
||||
""")
|
||||
has_industry_col = cur.fetchone() is not None
|
||||
|
||||
if has_industry_col:
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed)
|
||||
VALUES ('1', '测试用户', '13800000000', '科技', '0', 'test', 'FALSE')
|
||||
""")
|
||||
else:
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, fee, payment_channel, is_signed)
|
||||
VALUES ('1', '测试用户', '13800000000', '0', 'test', 'FALSE')
|
||||
""")
|
||||
|
||||
conn.commit()
|
||||
cur.close()
|
||||
@@ -2152,6 +2201,13 @@ async def create_payment(req: TicketPaymentRequest, request: Request):
|
||||
cur.execute("SELECT new_id, fee FROM gsdh_data WHERE phone = %s", (req.phone,))
|
||||
existing = cur.fetchone()
|
||||
|
||||
# 先检查 industry_company 列是否存在
|
||||
cur.execute("""
|
||||
SELECT column_name FROM information_schema.columns
|
||||
WHERE table_name = 'gsdh_data' AND column_name = 'industry_company'
|
||||
""")
|
||||
has_industry_col = cur.fetchone() is not None
|
||||
|
||||
if existing:
|
||||
user_id = existing[0]
|
||||
current_fee = existing[1]
|
||||
@@ -2163,17 +2219,30 @@ async def create_payment(req: TicketPaymentRequest, request: Request):
|
||||
release_db_connection(conn)
|
||||
return JSONResponse(content={"success": False, "message": "该手机号已完成报名,无需重复支付"}, status_code=400)
|
||||
|
||||
cur.execute("""
|
||||
UPDATE gsdh_data
|
||||
SET name=%s, industry_company=%s, fee='PENDING', payment_channel='wechat_h5_pending', out_trade_no=%s
|
||||
WHERE new_id=%s
|
||||
""", (req.name, req.company_name, out_trade_no, user_id))
|
||||
if has_industry_col:
|
||||
cur.execute("""
|
||||
UPDATE gsdh_data
|
||||
SET name=%s, industry_company=%s, fee='PENDING', payment_channel='wechat_h5_pending', out_trade_no=%s
|
||||
WHERE new_id=%s
|
||||
""", (req.name, req.company_name, out_trade_no, user_id))
|
||||
else:
|
||||
cur.execute("""
|
||||
UPDATE gsdh_data
|
||||
SET name=%s, fee='PENDING', payment_channel='wechat_h5_pending', out_trade_no=%s
|
||||
WHERE new_id=%s
|
||||
""", (req.name, out_trade_no, user_id))
|
||||
else:
|
||||
user_id = new_id
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed, out_trade_no)
|
||||
VALUES (%s, %s, %s, %s, 'PENDING', 'wechat_h5_pending', 'FALSE', %s)
|
||||
""", (user_id, req.name, req.phone, req.company_name, out_trade_no))
|
||||
if has_industry_col:
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed, out_trade_no)
|
||||
VALUES (%s, %s, %s, %s, 'PENDING', 'wechat_h5_pending', 'FALSE', %s)
|
||||
""", (user_id, req.name, req.phone, req.company_name, out_trade_no))
|
||||
else:
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, fee, payment_channel, is_signed, out_trade_no)
|
||||
VALUES (%s, %s, %s, 'PENDING', 'wechat_h5_pending', 'FALSE', %s)
|
||||
""", (user_id, req.name, req.phone, out_trade_no))
|
||||
|
||||
# Also store extra info in checkin_info?
|
||||
# Requirement: "If registration paid then add to gsdh_data"
|
||||
@@ -2250,6 +2319,13 @@ async def create_native_payment(req: TicketPaymentRequest, request: Request):
|
||||
cur.execute("SELECT new_id, fee FROM gsdh_data WHERE phone = %s", (req.phone,))
|
||||
existing = cur.fetchone()
|
||||
|
||||
# 先检查 industry_company 列是否存在
|
||||
cur.execute("""
|
||||
SELECT column_name FROM information_schema.columns
|
||||
WHERE table_name = 'gsdh_data' AND column_name = 'industry_company'
|
||||
""")
|
||||
has_industry_col = cur.fetchone() is not None
|
||||
|
||||
if existing:
|
||||
user_id = existing[0]
|
||||
current_fee = existing[1]
|
||||
@@ -2260,17 +2336,30 @@ async def create_native_payment(req: TicketPaymentRequest, request: Request):
|
||||
release_db_connection(conn)
|
||||
return JSONResponse(content={"success": False, "message": "该手机号已完成报名,无需重复支付"}, status_code=400)
|
||||
|
||||
cur.execute("""
|
||||
UPDATE gsdh_data
|
||||
SET name=%s, industry_company=%s, fee='PENDING', payment_channel='微信线上支付_pending', out_trade_no=%s
|
||||
WHERE new_id=%s
|
||||
""", (req.name, req.company_name, out_trade_no, user_id))
|
||||
if has_industry_col:
|
||||
cur.execute("""
|
||||
UPDATE gsdh_data
|
||||
SET name=%s, industry_company=%s, fee='PENDING', payment_channel='微信线上支付_pending', out_trade_no=%s
|
||||
WHERE new_id=%s
|
||||
""", (req.name, req.company_name, out_trade_no, user_id))
|
||||
else:
|
||||
cur.execute("""
|
||||
UPDATE gsdh_data
|
||||
SET name=%s, fee='PENDING', payment_channel='微信线上支付_pending', out_trade_no=%s
|
||||
WHERE new_id=%s
|
||||
""", (req.name, out_trade_no, user_id))
|
||||
else:
|
||||
user_id = new_id
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed, out_trade_no)
|
||||
VALUES (%s, %s, %s, %s, 'PENDING', '微信线上支付_pending', 'FALSE', %s)
|
||||
""", (user_id, req.name, req.phone, req.company_name, out_trade_no))
|
||||
if has_industry_col:
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, industry_company, fee, payment_channel, is_signed, out_trade_no)
|
||||
VALUES (%s, %s, %s, %s, 'PENDING', '微信线上支付_pending', 'FALSE', %s)
|
||||
""", (user_id, req.name, req.phone, req.company_name, out_trade_no))
|
||||
else:
|
||||
cur.execute("""
|
||||
INSERT INTO gsdh_data (new_id, name, phone, fee, payment_channel, is_signed, out_trade_no)
|
||||
VALUES (%s, %s, %s, 'PENDING', '微信线上支付_pending', 'FALSE', %s)
|
||||
""", (user_id, req.name, req.phone, out_trade_no))
|
||||
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
Reference in New Issue
Block a user