|
@@ -3,6 +3,7 @@ from flask import jsonify
|
|
|
import TokenUtils
|
|
|
from data import MySQLTool
|
|
|
from returnTemp import get_template, get_error_message
|
|
|
+import time
|
|
|
|
|
|
|
|
|
class MoneyRecord:
|
|
@@ -16,6 +17,8 @@ class MoneyRecord:
|
|
|
return self.insert()
|
|
|
elif self.action == "check":
|
|
|
return self.check()
|
|
|
+ elif self.action == "delete":
|
|
|
+ return self.deleteSomeItem()
|
|
|
else:
|
|
|
return self.test()
|
|
|
|
|
@@ -27,6 +30,10 @@ class MoneyRecord:
|
|
|
print("---check----")
|
|
|
return check(self.data)
|
|
|
|
|
|
+ def deleteSomeItem(self):
|
|
|
+ print("---deleteSomeItem----")
|
|
|
+ return deleteSomeItem(self.data)
|
|
|
+
|
|
|
|
|
|
def insert(data):
|
|
|
|
|
@@ -52,17 +59,43 @@ def insert(data):
|
|
|
paytime = data["paytime"]
|
|
|
cash_type = data["cash_type"]
|
|
|
location = data["location"]
|
|
|
+ noteid = get_order_code()
|
|
|
|
|
|
mysql_tool.connect()
|
|
|
- columns = ['cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid']
|
|
|
- values = [cash_type, des, kind, location, mount, paytime, uid]
|
|
|
+ columns = ['cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid', 'noteid']
|
|
|
+ values = [cash_type, des, kind, location, mount, paytime, uid, noteid]
|
|
|
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 deleteSomeItem(data):
|
|
|
+ required_fields = ['token', 'uid', 'noteid']
|
|
|
+ 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"]
|
|
|
+ noteid = data["noteid"]
|
|
|
+
|
|
|
+ if token == "" or uid == "" or noteid == "":
|
|
|
+
|
|
|
+ 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()
|
|
|
+ result = mysql_tool.select(table='cash', columns='*', conditions={"uid": uid, "noteid": noteid})
|
|
|
+ if len(result):
|
|
|
+ delete_result = mysql_tool.delete(table='cash', conditions={"uid": uid, "noteid": noteid})
|
|
|
+ if delete_result == 1:
|
|
|
+ return get_template(0, get_error_message(0), {})
|
|
|
+ else:
|
|
|
+ return get_template(2002, get_error_message(2002), {})
|
|
|
+ else:
|
|
|
+ return get_template(1006, get_error_message(1006), {})
|
|
|
|
|
|
|
|
|
def check(data):
|
|
@@ -95,7 +128,7 @@ def check(data):
|
|
|
final_result = []
|
|
|
i_start = int(start)
|
|
|
i_end = int(end)
|
|
|
- required_fields = ['id','cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid']
|
|
|
+ required_fields = ['id', 'cash_type', 'des', 'kind', 'location', 'mount', 'paytime', 'uid']
|
|
|
for r in result:
|
|
|
if i_start <= r[6] <= i_end:
|
|
|
temp = {}
|
|
@@ -104,3 +137,13 @@ def check(data):
|
|
|
final_result.append(temp)
|
|
|
mysql_tool.disconnect()
|
|
|
return get_template(0, get_error_message(0), {"record": final_result})
|
|
|
+
|
|
|
+
|
|
|
+mysql_tool = MySQLTool(host='localhost', user='root', password='wyt615115@', database='apiserver')
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+def get_order_code():
|
|
|
+
|
|
|
+ order_no = str(time.strftime('%Y%m%d%H%M%S', time.localtime(time.time())) + str(time.time()).replace('.', '')[-7:])
|
|
|
+ return order_no
|