commit 9dfdc36c968797624d3fe1fee6f897e2f5939147
Author: jefferyzhao <375696853@qq.com>
Date: Thu Jul 31 15:48:55 2025 +0800
first commit
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..a25e513
Binary files /dev/null and b/.DS_Store differ
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..081b737
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# 数据源本地存储已忽略文件
+/dataSources/
+/dataSources.local.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/
diff --git a/.idea/enterprise-wechat-payment-push.iml b/.idea/enterprise-wechat-payment-push.iml
new file mode 100644
index 0000000..f936df0
--- /dev/null
+++ b/.idea/enterprise-wechat-payment-push.iml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a2e120d
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..4adf23a
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/1.py b/1.py
new file mode 100644
index 0000000..d134ffe
--- /dev/null
+++ b/1.py
@@ -0,0 +1,11 @@
+from utils import *
+import os, _thread, urllib
+
+# res = filter_jdy_ht("130128198607190013")
+# print(res)
+#
+# data = {"pay_amount": 600, "id": "130128198607190013",
+# "fs": res[1], "jg": res[0], "name": res[4],
+# "fsfz": res[6],"shfid": res[7],
+# "hphm": res[5]}
+# add_payment(data,1)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
diff --git a/__pycache__/app.cpython-37.pyc b/__pycache__/app.cpython-37.pyc
new file mode 100644
index 0000000..d216b80
Binary files /dev/null and b/__pycache__/app.cpython-37.pyc differ
diff --git a/__pycache__/config.cpython-37.pyc b/__pycache__/config.cpython-37.pyc
new file mode 100644
index 0000000..b577bd1
Binary files /dev/null and b/__pycache__/config.cpython-37.pyc differ
diff --git a/__pycache__/glapp.cpython-37.pyc b/__pycache__/glapp.cpython-37.pyc
new file mode 100644
index 0000000..04e0512
Binary files /dev/null and b/__pycache__/glapp.cpython-37.pyc differ
diff --git a/__pycache__/utils.cpython-37.pyc b/__pycache__/utils.cpython-37.pyc
new file mode 100644
index 0000000..e5ab95b
Binary files /dev/null and b/__pycache__/utils.cpython-37.pyc differ
diff --git a/config.py b/config.py
new file mode 100644
index 0000000..01f7ec4
--- /dev/null
+++ b/config.py
@@ -0,0 +1,48 @@
+'''
+coding:utf-8
+@Time:2023/3/28 5:02 PM
+@Author:dyq
+'''
+
+# 调用域名
+base_path = 'https://www.jiyuankeshang.com'
+# 企微应用id 应用ID
+corpid = 'wwc276f7a0347c310b'
+SECRET = '8jSj7EF1J6P1zzDeqzMxc-1c4EV3tTGyB5yljB2RWtk'
+# 商户号
+#mchid = '1640957093'
+# APIv3密钥
+v3_SECRET = '20230626yinjian13370189887jiyuan'
+# 服务器IP
+ip = '101.43.208.145'
+# 商户号证书序列号
+#serial_no = '22E0F3EA849ABD1E687C82D43D26190C46DA5834'
+# 未收付应用id
+# pay_app = '628eeaace7f28c00089a60cc'
+pay_app = "667cc6dbaa923599ad735201"
+# 已收表单Id
+#received_id = '645b617ee5c2b50009c9dbea'
+received_id = '667cd24ceb38767eb218820b'
+# 未收表单Id
+#uncollected_id = '645b48ab5c72e30008fd9999'
+uncollected_id = '667cd24a2e0bccca52d98851'
+# 充值明细
+pay_details_id = '645b57e9f3523f0008ba6c23'
+# 个人账户
+accout_id = '645b5af630488a0007259b55'
+# 增减项app
+# hz_app = '628eeaace7f28c00089a60cc'
+hz_app = '667cc6dbaa923599ad735201'
+# 增减项表单
+hz_id = '66a36c9fa47877121a7cee8b'
+# 合同信息表单
+ht_id = '62b80148c6c1af0007f8a824'
+# apikey
+apikey = '82bl1lhsgjzhd9ahBYvaMNVAncYYRkbE'
+# 辅助表单(查询驾驶员身份证号)
+# fu_app = '628eeaace7f28c00089a60cc'
+fu_app = '667cc6dbaa923599ad735201'
+fu_id = '667ccd162e0bccca52d91e66'
+# rule_sort = {"社保": 0, "承包金": 1, "调度费": 2, "保养费": 3}
+rule_sort = {"社保": 1, "承包金": 1, "调度费": 1, "保养费": 1}
+
diff --git a/glapp.py b/glapp.py
new file mode 100644
index 0000000..63bae94
--- /dev/null
+++ b/glapp.py
@@ -0,0 +1,123 @@
+from flask import Flask, request, redirect, abort, session
+from utils import *
+import os, _thread, urllib
+
+
+app = Flask(__name__)
+app.config['SECRET_KEY'] = os.urandom(24)
+
+
+
+@app.route('/queryUserId', methods=['GET'])
+def queryUserId():
+ # 获取支付明细
+ try:
+ code = request.args.get('code')
+ data = query_wx_userid(code)
+ if len(data) <= 11:
+ res = query_wx_fj_info(data)
+ data = res
+ print(f'http://web.jiyuankeshang.com/?user={data}')
+ return redirect(f'http://web.jiyuankeshang.com/?user={data}')
+ except Exception as e:
+ return {}
+
+
+@app.route('/queryUser', methods=['GET'])
+def queryUserApi():
+ # 获取支付明细
+ try:
+ id = request.args.get('user')
+ data = queryUser(id)
+ return data
+ except Exception as e:
+ return {}
+
+
+@app.route('/getPaymentDetails', methods=['GET'])
+def getPaymentDetails():
+ try:
+ id = request.args.get('user','')
+
+ id = id.replace(" ", "")
+
+ if not id:
+ return {}
+ data = query_pay_details(id)
+ return data
+ except Exception as e:
+ print(e)
+ return {}
+
+
+
+@app.route('/test', methods=['POST'])
+def test():
+ # 新增未收付明细 {"pay_amount": 20000, "id": "18515367096"}
+ try:
+ data = request.data.decode("utf-8")
+ print(data)
+ return {}
+ except Exception as e:
+ print(e)
+ return {}
+
+
+
+
+@app.route('/addUnPayment', methods=['POST'])
+def addUnPayment():
+ # 新增未收付明细 {"pay_amount": 20000, "id": "18515367096"}
+ try:
+ data = request.data.decode("utf-8")
+ data = data.replace("null", "None")
+ data = eval(data)
+ data = data['data']
+ print("开始========", data)
+ if data['shifoudikou'] != "是":
+ return {data}
+ res = filter_jdy_ht(data['sijishenfenzhenghao'])
+ data1 = {"pay_amount": 0, "id": data['sijishenfenzhenghao'],
+ "fs": data['fs'], "jg": data['company_jc'], "name": data['sijixingming'],
+ "fsfz": data['fs_p'],"shfid": data['shfid'],
+ "hphm": data['license_plate']}
+ print(data1)
+ _thread.start_new_thread(add_payment, (data1, 1))
+
+ return data
+ except Exception as e:
+ print("addUnPayment",e, res)
+ return {}
+
+
+@app.route('/addPayment', methods=['POST'])
+def addPayment():
+ # 新增充值明细 {"pay_amount": 20000, "id": "18515367096"}
+ try:
+ data = request.data.decode("utf-8")
+ print(data)
+ data = data.replace("null", "None")
+ data = eval(data)
+ data = data['data']
+ # res = filter_jdy_ht(data['id_card'])
+ if not data['price']:
+ data['price'] = 0
+ # if not res:
+ # # 合同表单未有数据
+ fsfz = data['fsfz']['dept_no'] if data['fsfz'] else ""
+ _thread.start_new_thread(add_payment, ({"pay_amount": data['price'], "id": data['id_card'],
+ "fs": data['fs'], "jg": data['jg'], "name": data['name'],
+ "fsfz": fsfz, "hphm": data['hphm']}, 1))
+ # else:
+ # _thread.start_new_thread(add_payment, ({"pay_amount": data['price'], "id": data['id_card'],
+ # "fs": res[1], "jg": res[0], "name": res[4],
+ # "fsfz": res[6],"shfid": res[7],
+ # "hphm": res[5]}, 1))
+ return {}
+ except Exception as e:
+ print("addPayment",e, data)
+ return {}
+
+
+if __name__ == '__main__':
+ app.run(host="0.0.0.0", port=3007, processes=True)
diff --git a/utils.py b/utils.py
new file mode 100644
index 0000000..743856a
--- /dev/null
+++ b/utils.py
@@ -0,0 +1,667 @@
+import requests, time, json, uuid, datetime
+from config import *
+from dateutil.relativedelta import relativedelta
+import threading
+import urllib3
+from Crypto.Cipher import AES
+from base64 import b64encode, b64decode
+
+urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
+
+lock = threading.Lock()
+
+
+def format_uct(origin_date_str):
+ origin_date_str = origin_date_str.split('.')[0]
+ utc_date = datetime.datetime.strptime(origin_date_str, "%Y-%m-%dT%H:%M:%S")
+ local_date = utc_date + datetime.timedelta(hours=8)
+ local_date_str = datetime.datetime.strftime(local_date, '%Y-%m-%d %H:%M:%S')
+ return local_date_str
+
+
+def filter_jdy_ht(id):
+ """筛选简道云合同表单中驾驶员对应信息"""
+ url = f'{base_path}/api/v5/app/entry/data/list'
+ filter_data = {
+ "app_id": pay_app,
+ "entry_id": ht_id,
+ "limit": 100,
+ "filter": {
+ "rel": "and",
+ "cond": [
+ {
+ "field": "shfzhh",
+ "method": "eq",
+ "value": [id]
+ }
+ ]
+ }
+ }
+ ht_detail = turn_page(url, filter_data)
+ if not ht_detail:
+ return []
+ ht_detail = ht_detail[0]
+ # 机构
+ jg = ht_detail['jg']
+ # 分司
+ fs = ht_detail['fs']
+ # 商户号
+ sh = ht_detail['sh']
+ # 商户号证书
+ shzs = ht_detail['shxl']
+ # 姓名
+ name = ht_detail['name']
+ # 车牌号
+ hphm = ht_detail['hphm']
+ # 分司负责人
+ fsfz = ht_detail['fsfz']['dept_no'] if ht_detail['fsfz'] else ""
+ # 身份ID
+ shfid = ht_detail['shfid']
+ return [jg, fs, sh, shzs, name, hphm, fsfz, shfid]
+
+
+def queryUser(id):
+ # 查询充值明细
+ # user = get_user_info(id)
+ url = f'{base_path}/api/v5/app/entry/data/list'
+ filter_data = {
+ "app_id": fu_app,
+ "entry_id": pay_details_id,
+ "limit": 100,
+ "filter": {
+ "rel": "and",
+ "cond": [
+ {
+ "field": "pay_type",
+ "method": "eq",
+ "value": ["微信支付"]
+ },
+ {
+ "field": "id_card",
+ "method": "eq",
+ "value": [id]
+ }
+ ]
+ }
+ }
+ pay_detail = turn_page(url, filter_data)
+ for i in pay_detail:
+ i['time'] = format_uct(i['time'])
+ # 查询个人余额
+ info = {
+ "app_id": pay_app,
+ "entry_id": accout_id,
+ "filter": {"rel": "and",
+ "cond": [
+ {
+ "field": "id_card",
+ "method": "eq",
+ "value": [id]
+ },
+ {
+ "field": "date",
+ "method": "empty",
+
+ }
+ ]}
+ }
+ # 查询个人余额账户表 没有新增,有更新
+ res = req_tool_jdy(url, info)
+ balance = 0
+ if res['data']:
+ balance = res['data'][0]['balance']
+ balance = float("%.2f" % balance)
+ return {"balance": balance, "pay_detail": pay_detail}
+
+
+def get_last_8_hour():
+ _time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() - 8 * 60 * 60))
+ return _time
+
+
+def turn_page(url, data):
+ """翻页查询"""
+ info = []
+ while 1:
+ try:
+ res = req_tool_jdy(url, data)
+ info += res['data']
+ if len(res['data']) < 100:
+ return info
+ data["data_id"] = res["data"][-1]["_id"]
+ except Exception as e:
+ print("turn_page", e, res)
+
+
+def get_user_info(id, type=None):
+ """获取用户信息"""
+ url = f'{base_path}/api/v5/app/entry/data/list'
+ if type:
+ filter_data = {
+ "app_id": fu_app,
+ "entry_id": fu_id,
+ "filter": {
+ "rel": "and",
+ "cond": [
+ {
+ "field": "shfzhh",
+ "method": "eq",
+ "value": [id]
+ }
+ ]
+ }
+ }
+ else:
+ filter_data = {
+ "app_id": fu_app,
+ "entry_id": fu_id,
+ "filter": {
+ "rel": "and",
+ "cond": [
+ {
+ "field": "shfzhh",
+ "method": "eq",
+ "value": [id]
+ }
+ ]
+ }
+ }
+ res = req_tool_jdy(url, filter_data)
+ if res['data']:
+ return res['data'][0]
+ return ''
+
+
+def query_pay_details(id):
+ # 查询某人未收付明细
+ url = f'{base_path}/api/v5/app/entry/data/list'
+ filter_data = {
+ "app_id": pay_app,
+ "entry_id": uncollected_id,
+ "limit": 100,
+ "filter": {
+ "rel": "and",
+ "cond": [
+ {
+ "field": "sijishenfenzhenghao",
+ "method": "eq",
+ "value": [id]
+ },
+ {
+ "field": "unpay",
+ "method": "eq",
+ "value": [id]
+ },
+ ]
+ }
+ }
+
+ uncollected_data = turn_page(url, filter_data)
+ #按业务编码后13位数字添加排序号
+ def extract_and_sort(code):
+ extracted = int(code[-13:])
+ return extracted
+ _data = []
+ for i in uncollected_data:
+ # flag = False
+ # for j in ["承包金", "调度费", "保养费", "社保个人费额"]:
+ # if j == i['fukuanshiyou']:
+ # flag = True
+ # break
+ # if not flag:
+ # continue
+
+ # flag = False
+ # if "预收承包金" not in i['fukuanshiyou'] and i['type'] == "收款" and "违约金" not in i['fukuanshiyou'] and "维修费" not in i['fukuanshiyou']:
+ # flag = True
+ # if not flag:
+ # continue
+ # if "保证金" in i['fukuanshiyou'] or i['type'] != "收款":
+ if i['type'] != "收款" or i['shifoudikou'] != "是":
+ continue
+ i['jine'] = float("%.2f" % i['jine']) if i['jine'] else 0
+ i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
+ i['unpay'] = float("%.2f" % i['unpay']) if i['unpay'] != None and i['unpay'] != '' else 0
+ i['sort'] = 9999
+ # for j in rule_sort:
+ # if j in i['fukuanshiyou']:
+ i['sort'] = extract_and_sort(i['code'])
+ _data.append(i)
+ uncollected_data = _data
+ # uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
+ uncollected_data = sorted(uncollected_data, key=lambda x: x['sort'], reverse=False)
+ # 过滤已结清数据
+ uncollected_data = [i for i in uncollected_data if i['jine'] != i['pay']]
+ undata = {}
+ # 按月份归类 uncollected_data
+ for un in uncollected_data:
+ if un['yuefen'] in undata.keys():
+ undata[un['yuefen']]['data'].append(un)
+ else:
+ undata[un['yuefen']] = {"data": []}
+ undata[un['yuefen']]['data'] = [un]
+ # 按月查询增减项 flowState结束
+ amount = 0
+ for un in undata:
+ _th_amount = 0
+ del_list = []
+ filter_data = {
+ "app_id": hz_app,
+ "entry_id": hz_id,
+ "limit": 100,
+ "filter": {
+ "rel": "and",
+ "cond": [
+ {
+ "field": "id_card",
+ "method": "eq",
+ "value": [id]
+ },
+ {
+ "field": "month",
+ "method": "eq",
+ "value": [un]
+ },
+ ]
+ }
+ }
+ hz_data_list = turn_page(url, filter_data)
+ # 应付总额 承包金定额=应收承包金-增减项
+ zj_sum = sum(item['jine'] for item in hz_data_list)
+ for index, j in enumerate(undata[un]['data']):
+ j['unpay'] = j['unpay'] if j['unpay'] else j['jine']
+
+ if '费税' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
+ if j['pay'] - zj_sum == j['jine']:
+ del_list.append(index)
+ continue
+ # 定额 de = 表单中的金额-增减
+ # 应付金额 jine = 表单中的金额
+ # 未付金额 unpay = 应付金额-增减-已付金额
+ j['pay'] = j['pay'] if j['pay'] else 0
+
+ undata[un]['de'] = j['jine'] - zj_sum
+ # j['jine'] = undata[un]['de'] + zj_sum
+ j['unpay'] = j['jine'] - j['pay']
+ amount += j['unpay'] if j['unpay'] else j['jine']
+ _th_amount += j['unpay'] if j['unpay'] else j['jine']
+ undata[un]['_th_amount'] = _th_amount
+ undata[un]['hz'] = hz_data_list
+ for d in del_list:
+ undata[un]['data'].pop(d)
+ undata['amount'] = float("%.2f" % amount)
+ for i in list(undata.keys()):
+ if i != 'amount' and not undata[i]['data']:
+ del undata[i]
+ return undata
+
+
+def req_tool_jdy(url, data):
+ headers = {"Authorization": f"Bearer {apikey}"}
+ while 1:
+ try:
+ res = requests.post(url, headers=headers, json=data, timeout=10, verify=False).json()
+ if "code" in res.keys():
+ print("req_tool_jdy", res)
+ time.sleep(2)
+ continue
+ return res
+ except Exception as e:
+ print(e)
+
+
+def req_tool_vx(url, data=None, flag=None):
+ while 1:
+ try:
+ if not flag:
+ res = requests.post(url, json=data, timeout=10, verify=False).json()
+ else:
+ res = requests.get(url, timeout=10, verify=False).json()
+ return res
+ except Exception as e:
+ print(e)
+
+
+def update_unpay(data,now_time):
+ """更新未收付,添加已收付明细"""
+ url = f'{base_path}/api/v5/app/entry/data/update'
+ add_url = f'{base_path}/api/v5/app/entry/data/create'
+ del_url = f'{base_path}/api/v1/app/{pay_app}/entry/{uncollected_id}/data_delete'
+ for i in data:
+ if 'amount' == i:
+ continue
+ for j in data[i]['data']:
+ info = {
+ "app_id": pay_app,
+ "entry_id": uncollected_id,
+ "data_id": j['_id'],
+ "is_start_trigger": True,
+ "is_start_workflow": True,
+ "data": {
+ "pay": {"value": j['pay']},
+ "unpay": {"value": j['unpay']},
+ }
+ }
+ req_tool_jdy(url, info)
+ # 新增已收付明细
+ if 'flag' in j.keys() and float(j['flag_m']):
+ if not j['flag_m'] or not float(j['flag_m']):
+ continue
+ fs_p = j['fs_p']['dept_no'] if j['fs_p'] else ""
+ add_info = {
+ "app_id": pay_app,
+ "entry_id": received_id,
+ "is_start_trigger": True,
+ "is_start_workflow": True,
+ "data": {
+ "code": {"value": j['code']}, "type": {"value": "收款"},
+ "fukuanshiyou": {"value": j['fukuanshiyou']}, "month": {"value": j['yuefen']},
+ "yewubiaodanmingcheng": {"value": j['yewubiaodanmingcheng']},
+ "yewubiaodanbianma": {"value": j['yewubiaodanbianma']},
+ "sijixingming": {"value": j['sijixingming']},"date": {"value": j['date']},
+ "shfid": {"value": j['shfid']},"yyfs": {"value": j['yyfs']},"yyfs2": {"value": j['yyfs2']},
+ "sijishenfenzhenghao": {"value": j['sijishenfenzhenghao']},"jc": {"value": j['jc']},
+ "company_jc": {"value": j['company_jc']}, "xd": {"value": j['xd']},
+ "sijisuozaigongsi": {"value": j['sijisuozaigongsi']}, "fs": {"value": j['fs']},
+ "license_plate": {"value": j['license_plate']}, "jine": {"value": j['jine']},
+ "pay": {"value": j['flag_m']}, "hz_month": {"value": j['hz_month']},
+ "fs_p": {"value": fs_p}, "bj": {"value": j['bj']}, "status1": {"value": "已清缴"},
+ "sy": {"value": "个人账户抵扣"}, "status": {"value": "已收款"},
+ "ys": {"value": j['ys']},"pay_date": {"value": now_time}
+ }
+ }
+ req_tool_jdy(add_url, add_info)
+ print("shachu=========", j['pay'], j['jine'])
+ if j['sijixingming'] == '姓名':
+ print(j)
+ if j['pay'] == j['jine']:
+ # 未收付已清缴,删除未收付明细
+ j['sy'] = "个人账户抵扣"
+ del_info = {
+ "data_id": j["_id"],
+ "is_start_trigger": True
+ }
+ req_tool_jdy(del_url, del_info)
+
+
+def update_info(cz, _balcace, balance, user_info):
+ # 余额 = 累计充值金额-累计抵扣金额
+ # 本次抵扣=本次充值+本次余额-剩余金额
+ di = cz + balance - _balcace
+ """更新个人账户余额"""
+ # if pay_amount:
+ # # 支付完有剩余余额可直接更新
+ # amount = pay_amount
+ # else:
+ # # 查询未收付历史数据
+ # details = query_pay_details(user_info['user']['username'])
+ # amount = details['amount']
+ # amount *= -1
+ url = f'{base_path}/api/v5/app/entry/data/list'
+ info = {
+ "app_id": pay_app,
+ "entry_id": accout_id,
+ "filter": {"rel": "and",
+ "cond": [
+ {
+ "field": "id_card",
+ "method": "eq",
+ "value": [user_info['id']]
+ },
+ {
+ "field": "date",
+ "method": "empty"
+ },
+ ]}
+ }
+ # 查询个人余额账户表 没有新增,有更新
+ res = req_tool_jdy(url, info)
+ if res['data']:
+ # 更新
+ url = f'{base_path}/api/v5/app/entry/data/update'
+ pay = res['data'][-1]['pay'] + cz
+ di = di + (res['data'][-1]['deduction'] if res['data'][-1]['deduction'] else 0)
+ amount = pay - di # 累计充值-累计抵扣
+ info = {
+ "app_id": pay_app,
+ "entry_id": accout_id,
+ "data_id": res['data'][-1]["_id"],
+ "is_start_workflow": True,
+ "is_start_trigger": True,
+ "data": {
+ "pay": {"value": pay}, "balance": {"value": amount},
+ "deduction": {"value": di}
+ }
+ }
+ else:
+ # 新增
+ amount = cz - di # 本次充值-本次抵扣
+ if 'name' in user_info.keys():
+ name = user_info['name']
+ else:
+ name = ""
+ url = f'{base_path}/api/v5/app/entry/data/create'
+ info = {
+ "app_id": pay_app,
+ "entry_id": accout_id,
+ "is_start_workflow": True,
+ "is_start_trigger": True,
+ "data": {
+ "id_card": {"value": user_info['id']},
+ "name": {"value": name},
+ "pay": {"value": cz},
+ "deduction": {"value": di},
+ "balance": {"value": amount},
+ "jg": {"value": user_info['jg']},
+ "fs": {"value": user_info['fs']},
+ "fsfz": {"value": user_info['fsfz']},
+ "shfid": {"value": user_info['shfid']},
+ "hphm": {"value": user_info['hphm']}
+ }
+ }
+ req_tool_jdy(url, info)
+
+
+def add_payment(data, type=None):
+ lock.acquire()
+ print("开始========", data)
+ print(data, type)
+ # user = get_user_info(data['id'])
+ # 充值成功后 回写充值明细
+ now_month = datetime.datetime.now().strftime("%Y-%m")
+ now_time = get_last_8_hour()
+ url = f'{base_path}/api/v5/app/entry/data/create'
+ if not type:
+ info = {
+ "app_id": fu_app,
+ "entry_id": pay_details_id,
+ "is_start_workflow": True,
+ "is_start_trigger": True,
+ "data": {
+ "id_card": {"value": data['id']}, "name": {"value": data['name']},
+ "price": {"value": data['pay_amount']}, "pay_type": {"value": "微信支付"},
+ "coll_type": {"value": "网银"}, "month": {"value": now_month},
+ "jg": {"value": data['jg']}, "fs": {"value": data['fs']},
+ "hphm": {"value": data['hphm']},"shfid": {"value": data['shfid']},
+ "time": {"value": now_time}, "transactionid": {"value": data['transaction_id']}
+ }
+ }
+ if data['fsfz']:
+ info['data']["fsfz"] = {"value": data['fsfz']}
+ req_tool_jdy(url, info)
+
+ details = query_pay_details(data['id'])
+ dates = list(details.keys())
+ dates.sort()
+ dates.remove('amount')
+ pay_amount = data['pay_amount']
+ # 查询余额
+ balance = queryUser(data['id'])
+ pay_amount += balance['balance']
+ if pay_amount <= 0:
+ print("余额为0结束========", data)
+ lock.release()
+ return
+ print("执行add_payment", data)
+ # next_month = (datetime.datetime.now().date() - relativedelta(months=-1)).strftime("%Y-%m")
+ # 先抵扣承包金
+ if now_month in dates:
+ _tmp = details[now_month]['data']
+ _tmp = sorted(_tmp, key=lambda x: x['sort'])
+ for i in _tmp:
+ if pay_amount:
+ i['flag'] = 1
+ if '保证金尾款' in i['fukuanshiyou']:
+ i['flag_m'] = 0
+ continue
+ if '费税' in i['fukuanshiyou']:
+ # 承包金实际需要缴纳的
+ if pay_amount < i['jine'] - i['pay']:
+ # 修改 i['pay'] 充值金额,推送修改
+ i['pay'] += pay_amount
+ i['unpay'] = i['jine'] - i['pay']
+ i['flag_m'] = pay_amount
+ pay_amount = 0
+ else:
+ pay_amount -= (i['jine'] - i['pay'])
+ i['flag_m'] = (i['jine'] - i['pay'])
+ i['pay'] = i['jine']
+ i['unpay'] = 0
+ for i in dates:
+ if i == now_month:
+ continue
+ _tmp = details[i]['data']
+ _tmp = sorted(_tmp, key=lambda x: x['sort'])
+ for j in _tmp:
+ if pay_amount:
+ j['flag'] = 1
+ if '保证金尾款' in j['fukuanshiyou']:
+ j['flag_m'] = 0
+ continue
+ if '费税' in j['fukuanshiyou']:
+ # 承包金实际需要缴纳的
+ if pay_amount < j['jine'] - j['pay']:
+ # 修改 i['pay'] 充值金额,推送修改
+ j['pay'] += pay_amount
+ j['unpay'] = j['jine'] - j['pay']
+ j['flag_m'] = pay_amount
+ pay_amount = 0
+
+ else:
+ pay_amount -= (j['jine'] - j['pay'])
+ j['flag_m'] = (j['jine'] - j['pay'])
+ j['pay'] = j['jine']
+ j['unpay'] = 0
+ # 再抵扣其他
+ if now_month in dates:
+ _tmp = details[now_month]['data']
+ _tmp = sorted(_tmp, key=lambda x: x['sort'])
+ for i in _tmp:
+ if pay_amount:
+ i['flag'] = 1
+ if '保证金尾款' in i['fukuanshiyou']:
+ i['flag_m'] = 0
+ continue
+ if '费税' in i['fukuanshiyou']:
+ # 承包金实际需要缴纳的
+ continue
+ else:
+ if i['jine'] != i['pay']:
+ # 根据未支付的金额,扣除总金额
+ df = i['jine'] - i['pay']
+ if pay_amount < df:
+ # 修改 i['pay'] 充值金额,推送修改
+ i['pay'] += pay_amount
+ i['unpay'] = i['jine'] - i['pay']
+ i['flag_m'] = pay_amount
+ pay_amount = 0
+ else:
+ pay_amount -= df
+ i['pay'] = i['jine']
+ i['unpay'] = 0
+ i['flag_m'] = df
+ for i in dates:
+ if i == now_month:
+ continue
+ _tmp = details[i]['data']
+ _tmp = sorted(_tmp, key=lambda x: x['sort'])
+ for j in _tmp:
+ if pay_amount:
+ j['flag'] = 1
+ if '保证金尾款' in j['fukuanshiyou']:
+ j['flag_m'] = 0
+ continue
+ if '费税' in j['fukuanshiyou']:
+ # 承包金实际需要缴纳的
+ continue
+
+
+ else:
+ if j['jine'] != j['pay']:
+ # 根据未支付的金额,扣除总金额
+ df = j['jine'] - j['pay']
+ if pay_amount < df:
+ # 修改 i['pay'] 充值金额,推送修改
+ j['pay'] += pay_amount
+ j['unpay'] = j['jine'] - j['pay']
+ j['flag_m'] = pay_amount
+ pay_amount = 0
+
+ else:
+ pay_amount -= df
+ j['pay'] = j['jine']
+ j['unpay'] = 0
+ j['flag_m'] = df
+ # 根据抵扣规则,更新未支付的数据,将清缴数据新增至已收付明细
+ print("更新未收付", details)
+ update_unpay(details,now_time)
+ # 未收付更新完后,更新个人账户余额update_info
+ print("更新个人账户余额update_info")
+ update_info(data['pay_amount'], pay_amount, balance['balance'], data)
+ lock.release()
+ print("结束========")
+
+
+def decode_notify_data(res_json):
+ try:
+ ciphertext = res_json['resource']['ciphertext']
+ nonce = res_json['resource']['nonce']
+ associated_data = res_json['resource']['associated_data']
+ cipher = AES.new(v3_SECRET.encode(), AES.MODE_GCM, nonce=nonce.encode())
+ cipher.update(associated_data.encode())
+ en_data = b64decode(ciphertext.encode('utf-8'))
+ auth_tag = en_data[-16:]
+ _en_data = en_data[:-16]
+ plaintext = cipher.decrypt_and_verify(_en_data, auth_tag)
+ decodejson = json.loads(plaintext.decode())
+ except Exception as e:
+ print(f"解密回调失败:{e}")
+ return None
+ return decodejson
+
+
+def get_wx_token():
+ url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={corpid}&corpsecret={SECRET}'
+ res = req_tool_vx(url, flag=1)
+ return res['access_token']
+
+
+def query_wx_fj_info(id):
+ """查询企微中的附加信息"""
+ token = get_wx_token()
+ url = f'https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token={token}&userid={id}'
+ res = req_tool_vx(url, flag=1)
+ val = ""
+ print("query_wx_fj_info", res, id)
+ for i in res['extattr']['attrs']:
+ if i['name'] == '附加信息':
+ val = i['value']
+ return val
+
+
+def query_wx_userid(code):
+ """查询企微中的userid"""
+ token = get_wx_token()
+ url = f'https://qyapi.weixin.qq.com/cgi-bin/auth/getuserinfo?access_token={token}&code={code}'
+ res = req_tool_vx(url, flag=1)
+ return res['userid']