123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- from flask import jsonify
- import TokenUtils
- from data import MySQLTool
- from returnTemp import get_template, get_error_message
- class MoneyRecord:
- def __init__(self, action, data, logger):
- self.action = action
- self.data = data
- self.logger = logger
- def money_record_router(self):
- if self.action == "insert":
- return self.insert()
- elif self.action == "check":
- return self.check()
- else:
- return self.test()
- def insert(self):
- print("---insert---")
- return insert(self.data)
- def check(self):
- print("---check----")
- return check(self.data)
- def insert(data):
- # 检查参数是否存在
- required_fields = ['cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid']
- missing_fields = [field for field in required_fields if field not in data]
- if missing_fields:
- return get_template(2000, get_error_message(2000), {})
- token = data["token"]
- uid = data["uid"]
- mount = data["mount"]
- if token == "" or uid == "" or mount == "":
- # 三个值必须存在
- template = get_template(2000, get_error_message(2000), {})
- return template
- if not TokenUtils.verify_jwt_token(uid, token):
- return get_template(2001, get_error_message(2001), {})
- # 获取支付信息
- kind = data["kind"]
- mount = data["mount"]
- des = data["des"]
- paytime = data["paytime"]
- cash_type = data["cash_type"]
- location = data["location"]
- # 插入数据
- mysql_tool.connect()
- columns = ['cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid']
- values = [cash_type, des, kind, location, mount, paytime, uid]
- insert_result = mysql_tool.insert(table='cash', columns=columns, values=values)
- print(insert_result)
- mysql_tool.disconnect()
- return get_template(0, "记录成功", {})
- mysql_tool = MySQLTool(host='localhost', user='root', password='wyt615115@', database='apiserver')
- def check(data):
- # 检查参数是否存在
- required_fields = ['token', 'uid', 'start', 'end', 'type']
- missing_fields = [field for field in required_fields if field not in data]
- if missing_fields:
- return get_template(2000, get_error_message(2000), {})
- token = data["token"]
- uid = data["uid"]
- start = data["start"]
- end = data["end"]
- kindtype = data["type"]
- if token == "" or uid == "" or start == "" or end == "" or kindtype == "":
- # 三个值必须存在
- template = get_template(2000, get_error_message(2000), {})
- return template
- if not TokenUtils.verify_jwt_token(uid, token):
- return get_template(2001, get_error_message(2001), {})
- # 组装查询参数
- mysql_tool.connect()
- conditions = {}
- if kindtype != 0:
- conditions['kind'] = kindtype
- conditions['uid'] = uid
- result = mysql_tool.select(table='cash', columns='*', conditions=conditions)
- final_result = []
- i_start = int(start)
- i_end = int(end)
- required_fields = ['id','cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid']
- for r in result:
- if i_start <= r[6] <= i_end:
- temp = {}
- for inx, val in enumerate(r):
- temp[required_fields[inx]] = val
- final_result.append(temp)
- mysql_tool.disconnect()
- return get_template(0, get_error_message(0), {"record": final_result})
|