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.

39 lines
1.2 KiB

6 months ago
import random
import time
import pymysql
class Make_Bill():
def __init__(self, Num, stt, val, Mnum):
self.Num = Num
self.stt = stt
self.val = val
self.Mnum = Mnum
self.Make(self.Num)
def makeid(self):
return int(random.uniform(10000001, 10999999))
def Make(self, Num):
sql = "SELECT card类型,Card_Number FROM card WHERE Card_Number = %s" % (self.Num)
db = pymysql.connect(host="localhost", user="root",
password="lwh20021210...", db="atm", port=3306)
cur = db.cursor()
try:
cur.execute(sql) # 执行sql语句
results = cur.fetchall()
print(type(results))
YH = results[0][0]
YC = results[0][1]
tim = time.strftime('%Y-%m-%d %H:%M:%S ', time.localtime(time.time()))
sql2 = "INSERT INTO bill VALUES ('%s',%s, '%s','%s', %s,'%s','%s')" % (
tim, self.makeid(), YH, self.stt, self.val, YC, self.Mnum)
cur.execute(sql2)
db.commit()
except Exception as e:
db.rollback()
finally:
db.close() # 关闭连接
# MM=Make_Bill("62155504510128","转账",1000,"62155504510112")