You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
101 lines
4.9 KiB
101 lines
4.9 KiB
|
1 week ago
|
import pymysql
|
||
|
|
from pymysql.cursors import DictCursor
|
||
|
|
import datetime
|
||
|
|
from dh2ec.config import *
|
||
|
|
|
||
|
|
db_config = {
|
||
|
|
'host': '192.168.55.97',
|
||
|
|
'database': 'quan_list',
|
||
|
|
'user': 'dbadmin',
|
||
|
|
'password': 'fXMSR37mLP7w88ji'
|
||
|
|
}
|
||
|
|
check_result_config = {
|
||
|
|
'host': global_data['basic_data']['ip'],
|
||
|
|
'database': 'cine',
|
||
|
|
'user': 'dbadmin',
|
||
|
|
'password': 'fXMSR37mLP7w88ji'
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
class DB:
|
||
|
|
def __init__(self):
|
||
|
|
self.db_conn = pymysql.Connect(**db_config)
|
||
|
|
self.cursor = self.db_conn.cursor(DictCursor)
|
||
|
|
self.db_conn_result = pymysql.Connect(**check_result_config)
|
||
|
|
self.cursor_result = self.db_conn_result.cursor(DictCursor)
|
||
|
|
|
||
|
|
# 6, 12, 21, 32
|
||
|
|
def get_cases(self):
|
||
|
|
# self.cursor.execute("SELECT * FROM multi_cards_pay_test WHERE id IN (85, 86, 87);")
|
||
|
|
self.cursor.execute("SELECT * FROM multi_cards_pay_test WHERE id IN (93);")
|
||
|
|
# self.cursor.execute("SELECT * FROM multi_cards_pay_test WHERE last_runtime < '2023-11-25 20:16:18';")
|
||
|
|
# self.cursor.execute("SELECT * FROM multi_cards_pay_test;")
|
||
|
|
# self.cursor.execute("SELECT * FROM multi_cards_pay_test WHERE use_cards = 1;")
|
||
|
|
cases = self.cursor.fetchall()
|
||
|
|
return cases
|
||
|
|
|
||
|
|
def mark_run(self, _id, tickets, code, run_time):
|
||
|
|
self.cursor.execute(
|
||
|
|
"UPDATE multi_cards_pay_test SET result_tickets_no = %s, take_ticket_code = %s, run_times = run_times+1,last_runtime = %s WHERE id = %s",
|
||
|
|
(tickets, code, run_time, _id))
|
||
|
|
self.db_conn.commit()
|
||
|
|
|
||
|
|
def pay_result(self, pay_detail, _ip, _case_id):
|
||
|
|
for ticket_num, ticket in pay_detail.items():
|
||
|
|
now_str = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
|
||
|
|
for pay_type, detail in ticket.items():
|
||
|
|
ticket_f, service_f, handle_f = 0.0, 0.0, 0.0
|
||
|
|
if pay_type == '储值卡':
|
||
|
|
for card_num, card_detail in detail.items():
|
||
|
|
total_f, handle_f, service_f, ticket_f = self.gen_result_val(card_detail)
|
||
|
|
sql_str = """INSERT INTO multi_cards_pay_result
|
||
|
|
(ticket_num, pay_type, pay_card_no, total_pay, ticket, service_fee, handle_fee, case_id, test_on, add_time)
|
||
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
|
||
|
|
self.cursor.execute(sql_str,
|
||
|
|
(ticket_num, pay_type, card_num, total_f, ticket_f, service_f, handle_f,
|
||
|
|
_case_id, _ip, now_str))
|
||
|
|
elif pay_type == '影票计次卡':
|
||
|
|
for card_num, card_detail in detail.items():
|
||
|
|
total_f, handle_f, service_f, ticket_f = self.gen_result_val(card_detail)
|
||
|
|
sql_str = """INSERT INTO multi_cards_pay_result
|
||
|
|
(ticket_num, pay_type, times_card_no, total_pay, ticket, service_fee, handle_fee, case_id, test_on, add_time)
|
||
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"""
|
||
|
|
self.cursor.execute(sql_str,
|
||
|
|
(ticket_num, pay_type, card_num, total_f, ticket_f, service_f, handle_f,
|
||
|
|
_case_id, _ip, now_str))
|
||
|
|
else:
|
||
|
|
total_f, handle_f, service_f, ticket_f = self.gen_result_val(detail)
|
||
|
|
sql_str = """INSERT INTO multi_cards_pay_result
|
||
|
|
(ticket_num, pay_type, total_pay, ticket, service_fee, handle_fee, case_id, test_on, add_time)
|
||
|
|
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)"""
|
||
|
|
self.cursor.execute(sql_str,
|
||
|
|
(ticket_num, pay_type, total_f, ticket_f, service_f, handle_f, _case_id, _ip,
|
||
|
|
now_str))
|
||
|
|
self.db_conn.commit()
|
||
|
|
|
||
|
|
@staticmethod
|
||
|
|
def gen_result_val(_detail):
|
||
|
|
print(_detail)
|
||
|
|
ticket_f, service_f, handle_f = 0.0, 0.0, 0.0
|
||
|
|
for _pay in _detail:
|
||
|
|
if _pay['type'] == '手续费':
|
||
|
|
handle_f = float(_pay['value'])
|
||
|
|
if _pay['type'] == '服务费':
|
||
|
|
service_f = float(_pay['value'])
|
||
|
|
if _pay['type'] == '票房':
|
||
|
|
ticket_f = float(_pay['value'])
|
||
|
|
total_value = handle_f + service_f + ticket_f
|
||
|
|
total_f = '{:.2f}'.format(total_value)
|
||
|
|
handle_f = '{:.2f}'.format(handle_f)
|
||
|
|
service_f = '{:.2f}'.format(service_f)
|
||
|
|
ticket_f = '{:.2f}'.format(ticket_f)
|
||
|
|
return total_f, handle_f, service_f, ticket_f
|
||
|
|
|
||
|
|
# 检查结果相关
|
||
|
|
def get_refund_params(self, t_id):
|
||
|
|
sql_str = """
|
||
|
|
SELECT transaction_id, out_id FROM cinema_transaction WHERE transaction_id = (SELECT cinema_transaction_id FROM cinema_sell_log WHERE cinema_sell_id = %s);
|
||
|
|
"""
|
||
|
|
self.cursor_result.execute(sql_str, (t_id,))
|
||
|
|
return self.cursor_result.fetchall()
|