1329 lines
50 KiB
Python
1329 lines
50 KiB
Python
from datetime import datetime
|
||
from Crypto.PublicKey import RSA
|
||
import base64
|
||
from Crypto.Cipher import PKCS1_v1_5
|
||
import requests, time, json, uuid, datetime
|
||
from flask import jsonify
|
||
from config import *
|
||
from dateutil.relativedelta import relativedelta
|
||
import threading
|
||
import urllib3
|
||
from Crypto.Cipher import AES
|
||
from base64 import b64encode, b64decode
|
||
import logging
|
||
|
||
logger = logging.getLogger(__name__)
|
||
|
||
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": fu_app,
|
||
"entry_id": ht_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id",
|
||
"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['ssbm']
|
||
# 商户号
|
||
sh = ht_detail['sh']
|
||
# 商户号证书
|
||
shzs = '38C5F89F06EC667D54936A4FF0DC93A227BFC128'
|
||
|
||
# 姓名
|
||
name = ht_detail['name']
|
||
# 车牌号
|
||
hphm = ht_detail['hphm']
|
||
# 分司负责人
|
||
fsfz = ht_detail['fsfz']['dept_no'] if ht_detail['fsfz'] else ""
|
||
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": pay_app,
|
||
"entry_id": pay_details_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "pay_type",
|
||
"method": "in",
|
||
"value": ["微信支付","支付宝支付","云闪付支付"]
|
||
},
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
filter_data_lw = {
|
||
"app_id": lw_pay_app,
|
||
"entry_id": lw_pay_details_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "pay_type",
|
||
"method": "in",
|
||
"value": ["微信支付","支付宝支付","云闪付支付"]
|
||
},
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
pay_detail1 = turn_page(url, filter_data)
|
||
pay_detail2 = turn_page(url, filter_data_lw)
|
||
pay_detail = pay_detail1 + pay_detail2
|
||
for i in pay_detail:
|
||
i['charge_time'] = format_uct(i['charge_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 querydpUser(id):
|
||
# 查询充值明细
|
||
# user = get_user_info(id)
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data = {
|
||
"app_id": pay_app,
|
||
"entry_id": pay_details_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "pay_type",
|
||
"method": "in",
|
||
"value": ["微信支付","支付宝支付","云闪付支付"]
|
||
},
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
pay_detail = turn_page(url, filter_data)
|
||
for i in pay_detail:
|
||
i['charge_time'] = format_uct(i['charge_time'])
|
||
# 查询个人余额
|
||
info = {
|
||
"app_id": pay_app,
|
||
"entry_id": accout_id,
|
||
"filter": {"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ['DP']
|
||
},
|
||
{
|
||
"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:
|
||
logger.error(f"turn_page,e{e}, res{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": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
else:
|
||
filter_data = {
|
||
"app_id": fu_app,
|
||
"entry_id": fu_id,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "user",
|
||
"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": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "bill_type",
|
||
"method": "eq",
|
||
"value": "个人账单"
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
filter_data_lw = {
|
||
"app_id": lw_pay_app,
|
||
"entry_id": lw_uncollected_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
|
||
uncollected_data1 = turn_page(url, filter_data)
|
||
for i in uncollected_data1:
|
||
flag = False
|
||
if i['bill_type'] == "个人账单":
|
||
flag = True
|
||
break
|
||
uncollected_data2 = turn_page(url, filter_data_lw)
|
||
uncollected_data = uncollected_data1 + uncollected_data2
|
||
_data = []
|
||
for i in uncollected_data:
|
||
flag = False
|
||
for j in ["收预收承包金", "承包金", "调度费", "保养费", "营运服务费", "费税收取-其他", "维修费", "违约金", "驾驶员履约服务费", "发票罚款", "停车费", "交通违法扣款", "车辆管理费"]:
|
||
if j == i['fukuanshiyou']:
|
||
flag = True
|
||
break
|
||
if not flag:
|
||
continue
|
||
i['money'] = float("%.2f" % i['money']) if i['money'] else 0
|
||
i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
|
||
i['no_money'] = float("%.2f" % i['no_money']) if i['no_money'] != None and i['no_money'] != '' else 0
|
||
i['sort'] = 9999
|
||
for j in rule_sort:
|
||
if j in i['fukuanshiyou']:
|
||
i['sort'] = rule_sort[j]
|
||
_data.append(i)
|
||
uncollected_data = _data
|
||
uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
|
||
# 过滤已结清数据
|
||
uncollected_data = [i for i in uncollected_data if i['money'] != i['pay']]
|
||
undata = {}
|
||
# 按月份归类 uncollected_data
|
||
for un in uncollected_data:
|
||
if un['month1'] in undata.keys():
|
||
undata[un['month1']]['data'].append(un)
|
||
else:
|
||
undata[un['month1']] = {"data": []}
|
||
undata[un['month1']]['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": "month1",
|
||
"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['no_money'] = j['no_money'] if j['no_money'] else j['money']
|
||
|
||
if '承包金' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
|
||
if j['pay'] - zj_sum == j['money']:
|
||
del_list.append(index)
|
||
continue
|
||
# 定额 de = 表单中的金额-增减
|
||
# 应付金额 money = 表单中的金额
|
||
# 未付金额 no_money = 应付金额-增减-已付金额
|
||
j['pay'] = j['pay'] if j['pay'] else 0
|
||
|
||
undata[un]['de'] = j['money'] - zj_sum
|
||
# j['money'] = undata[un]['de'] + zj_sum
|
||
j['no_money'] = j['money'] - j['pay']
|
||
amount += j['no_money'] if j['no_money'] else j['money']
|
||
_th_amount += j['no_money'] if j['no_money'] else j['money']
|
||
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 query_dp_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": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "mode_type",
|
||
"method": "eq",
|
||
"value": ['DP']
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
logger.info(f"开始查询未收付明细, id_card: {id},filter_data: {filter_data} ")
|
||
uncollected_data = turn_page(url, filter_data)
|
||
_data = []
|
||
for i in uncollected_data:
|
||
flag = False
|
||
for j in ["收预收承包金", "承包金", "调度费", "保养费", "营运服务费", "费税收取-其他", "维修费", "违约金", "驾驶员履约服务费", "发票罚款", "停车费", "交通违法扣款", "车辆管理费"]:
|
||
if j == i['fukuanshiyou']:
|
||
if i['bill_type'] == "个人账单":
|
||
flag = True
|
||
break
|
||
if not flag:
|
||
continue
|
||
i['money'] = float("%.2f" % i['money']) if i['money'] else 0
|
||
i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
|
||
i['no_money'] = float("%.2f" % i['no_money']) if i['no_money'] != None and i['no_money'] != '' else 0
|
||
i['sort'] = 9999
|
||
for j in rule_sort:
|
||
if j in i['fukuanshiyou']:
|
||
i['sort'] = rule_sort[j]
|
||
_data.append(i)
|
||
uncollected_data = _data
|
||
uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
|
||
# 过滤已结清数据
|
||
uncollected_data = [i for i in uncollected_data if i['money'] != i['pay']]
|
||
undata = {}
|
||
# 按月份归类 uncollected_data
|
||
for un in uncollected_data:
|
||
if un['month1'] in undata.keys():
|
||
undata[un['month1']]['data'].append(un)
|
||
else:
|
||
undata[un['month1']] = {"data": []}
|
||
undata[un['month1']]['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": "mode_type",
|
||
"method": "eq",
|
||
"value": ['DP']
|
||
},
|
||
{
|
||
"field": "month1",
|
||
"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['no_money'] = j['no_money'] if j['no_money'] else j['money']
|
||
|
||
if '承包金' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
|
||
if j['pay'] - zj_sum == j['money']:
|
||
del_list.append(index)
|
||
continue
|
||
# 定额 de = 表单中的金额-增减
|
||
# 应付金额 money = 表单中的金额
|
||
# 未付金额 no_money = 应付金额-增减-已付金额
|
||
j['pay'] = j['pay'] if j['pay'] else 0
|
||
|
||
undata[un]['de'] = j['money'] - zj_sum
|
||
# j['money'] = undata[un]['de'] + zj_sum
|
||
j['no_money'] = j['money'] - j['pay']
|
||
amount += j['no_money'] if j['no_money'] else j['money']
|
||
_th_amount += j['no_money'] if j['no_money'] else j['money']
|
||
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 query_lw_pay_details(id):
|
||
# 查询某人未收付明细
|
||
url = f'{base_path}/api/v5/app/entry/data/list'
|
||
filter_data_lw = {
|
||
"app_id": lw_pay_app,
|
||
"entry_id": lw_uncollected_id,
|
||
"limit": 100,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "id_card",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
{
|
||
"field": "no_money",
|
||
"method": "eq",
|
||
"value": [id]
|
||
},
|
||
]
|
||
}
|
||
}
|
||
|
||
uncollected_data = turn_page(url, filter_data_lw)
|
||
_data = []
|
||
for i in uncollected_data:
|
||
flag = False
|
||
for j in ["收预收承包金", "承包金", "调度费", "保养费", "营运服务费", "费税收取-其他", "维修费", "违约金", "驾驶员履约服务费", "交通违法扣款"]:
|
||
if j == i['fukuanshiyou']:
|
||
flag = True
|
||
break
|
||
if not flag:
|
||
continue
|
||
i['money'] = float("%.2f" % i['money']) if i['money'] else 0
|
||
i['pay'] = float("%.2f" % i['pay']) if i['pay'] != None and i['pay'] != '' else 0
|
||
i['no_money'] = float("%.2f" % i['no_money']) if i['no_money'] != None and i['no_money'] != '' else 0
|
||
i['sort'] = 9999
|
||
for j in rule_sort:
|
||
if j in i['fukuanshiyou']:
|
||
i['sort'] = rule_sort[j]
|
||
_data.append(i)
|
||
uncollected_data = _data
|
||
uncollected_data = sorted(uncollected_data, key=lambda x: x['createTime'], reverse=True)
|
||
# 过滤已结清数据
|
||
uncollected_data = [i for i in uncollected_data if i['money'] != i['pay']]
|
||
undata = {}
|
||
# 按月份归类 uncollected_data
|
||
for un in uncollected_data:
|
||
if un['month1'] in undata.keys():
|
||
undata[un['month1']]['data'].append(un)
|
||
else:
|
||
undata[un['month1']] = {"data": []}
|
||
undata[un['month1']]['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": "month1",
|
||
"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['no_money'] = j['no_money'] if j['no_money'] else j['money']
|
||
|
||
if '承包金' in j['fukuanshiyou'] and j['yewubiaodanmingcheng'] == '费税计划':
|
||
if j['pay'] - zj_sum == j['money']:
|
||
del_list.append(index)
|
||
continue
|
||
# 定额 de = 表单中的金额-增减
|
||
# 应付金额 money = 表单中的金额
|
||
# 未付金额 no_money = 应付金额-增减-已付金额
|
||
j['pay'] = j['pay'] if j['pay'] else 0
|
||
|
||
undata[un]['de'] = j['money'] - zj_sum
|
||
# j['money'] = undata[un]['de'] + zj_sum
|
||
j['no_money'] = j['money'] - j['pay']
|
||
amount += j['no_money'] if j['no_money'] else j['money']
|
||
_th_amount += j['no_money'] if j['no_money'] else j['money']
|
||
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=20, verify=False).json()
|
||
if "code" in res.keys():
|
||
logger.info(f"req_tool_jdy{res}")
|
||
time.sleep(2)
|
||
continue
|
||
return res
|
||
except Exception as e:
|
||
logger.error(f"error, {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:
|
||
logger.error(f"error, {e}")
|
||
|
||
|
||
def update_no_money(data):
|
||
"""更新未收付,添加已收付明细"""
|
||
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']:
|
||
if j['fukuanshiyou'] == '驾驶员履约服务费':
|
||
continue
|
||
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']},
|
||
"no_money": {"value": j['no_money']}
|
||
}
|
||
}
|
||
req_tool_jdy(url, info)
|
||
now_time = get_last_8_hour()
|
||
# 新增已收付明细
|
||
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['month']},
|
||
"month1": {"value": j['month1']},"yewubiaodanmingcheng": {"value": j['yewubiaodanmingcheng']},
|
||
"yewubiaodanbianma": {"value": j['yewubiaodanbianma']},
|
||
"sijixingming": {"value": j['sijixingming']},"shfid": {"value": j['shfid']},
|
||
"id_card": {"value": j['id_card']},"pay_time": {"value": now_time},
|
||
"company_jc": {"value": j['company_jc']}, "xd": {"value": j['xd']},
|
||
"sijisuozaigongsi": {"value": j['sijisuozaigongsi']}, "fs": {"value": j['fs']},
|
||
"license_plate": {"value": j['license_plate']}, "money": {"value": j['money']},
|
||
"pay": {"value": j['flag_m']}, "hz_month": {"value": j['hz_month']}, "zjin_status": {"value": "未结算"},
|
||
"fs_p": {"value": fs_p}, "shgid": {"value": j['shgid']}, "mode_type": {"value": j['mode_type']},
|
||
"sy": {"value": "个人账户抵扣"},"ys": {"value": j['ys']},"lydunjiao": {"value": j['lydunjiao']},"bill_type": {"value": j['bill_type']},
|
||
"car_dept": {"value": j['car_dept']},"contract_num": {"value": j['contract_num']}
|
||
}
|
||
}
|
||
logger.info(f"新增已收========={add_info}")
|
||
req_tool_jdy(add_url, add_info)
|
||
logger.info(f"删除========={j['pay']}, {j['money']}" )
|
||
if j['sijixingming'] == '姓名':
|
||
logger.info(f"j,{j}")
|
||
if j['pay'] == j['money']:
|
||
# 未收付已清缴,删除未收付明细
|
||
del_info = {
|
||
"data_id": j["_id"],
|
||
"is_start_trigger": True
|
||
}
|
||
# 新增劳务佣金
|
||
# today_str = datetime.datetime.now().strftime('%Y-%m-%d')
|
||
# if j['name'] == "承包金":
|
||
# add_info = {
|
||
# "app_id": pay_app,
|
||
# "entry_id": uncollected_id,
|
||
# "is_start_trigger": True,
|
||
# "is_start_workflow": True,
|
||
# "data": {
|
||
# "type": {"value": "付款"},
|
||
# "name": {"value": "劳务佣金"}, "month": {"value": j['month']},
|
||
# "yewubiaodanmingcheng": {"value": "已收付表单"},
|
||
# "yewubiaodanbianma": {"value": j['yewubiaodanbianma']},
|
||
# "sijixingming": {"value": j['sijixingming']},
|
||
# "id_card": {"value": j['id_card']},
|
||
# "sijisuozaigongsi": {"value": j['sijisuozaigongsi']}, "fs": {"value": j['fs']},
|
||
# "_widget_1704357037281": {"value": j['_widget_1704357037281']},
|
||
# "abbreviation": {"value": j['abbreviation']}, "money": {"value": j['lw_money']},
|
||
# "pay": {"value": 0}, "no_money": {"value": j['lw_money']},
|
||
# "fs_p": {"value": fs_p}, "status1": {"value": "已清缴"},
|
||
# "lw_money": {"value": j['lw_money']},"hz_month": {"value": j['hz_month']},
|
||
# "ys": {"value": today_str}, "month1": {"value": j['month1']},
|
||
# "bill_type": {"value": "劳务"}
|
||
# }
|
||
# }
|
||
# req_tool_jdy(add_url, add_info)
|
||
logger.info(f"===========================未收付已清缴,删除未收付明细===============================")
|
||
req_tool_jdy(del_url, del_info)
|
||
|
||
def update_lw_no_money(data):
|
||
"""更新未收付,添加已收付明细"""
|
||
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/{lw_pay_app}/entry/{lw_uncollected_id}/data_delete'
|
||
for i in data:
|
||
if 'amount' == i:
|
||
continue
|
||
for j in data[i]['data']:
|
||
if j['fukuanshiyou'] != '驾驶员履约服务费':
|
||
continue
|
||
info = {
|
||
"app_id": lw_pay_app,
|
||
"entry_id": lw_uncollected_id,
|
||
"data_id": j['_id'],
|
||
"is_start_trigger": True,
|
||
"is_start_workflow": True,
|
||
"data": {
|
||
"pay": {"value": j['pay']},
|
||
"no_money": {"value": j['no_money']},
|
||
}
|
||
}
|
||
logger.info(f"更新未收{info}")
|
||
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": lw_pay_app,
|
||
"entry_id": lw_received_id,
|
||
"is_start_trigger": True,
|
||
"is_start_workflow": True,
|
||
"data": {
|
||
"code": {"value": j['code']}, "type": {"value": "收款"},
|
||
"fukuanshiyou": {"value": j['fukuanshiyou']}, "month": {"value": j['month']},
|
||
"yewubiaodanmingcheng": {"value": j['yewubiaodanmingcheng']},
|
||
"yewubiaodanbianma": {"value": j['yewubiaodanbianma']},
|
||
"sijixingming": {"value": j['sijixingming']},
|
||
"sijishenfenzhenghao": {"value": j['id_card']},"shfid": {"value": j['shfid']},
|
||
"sijisuozaigongsi": {"value": j['sijisuozaigongsi']}, "fs": {"value": j['fs']},
|
||
"license_plate": {"value": j['car_num']},"abbreviation": {"value": j['abbreviation']}, "jine": {"value": j['money']},
|
||
"pay": {"value": j['flag_m']},
|
||
"fs_p": {"value": fs_p}, "status1": {"value": "已清缴"},
|
||
"status": {"value": "已收款"}, "month1": {"value": j['month1']}
|
||
}
|
||
}
|
||
logger.info(f"=====================新增已收付{data}")
|
||
req_tool_jdy(add_url, add_info)
|
||
logger.info(f"删除========={j['pay']}, {j['money']}")
|
||
if j['sijixingming'] == '姓名':
|
||
logger.info(f"j,{j}")
|
||
if j['pay'] == j['money']:
|
||
# 未收付已清缴,删除未收付明细
|
||
del_info = {
|
||
"data_id": j["_id"],
|
||
"is_start_trigger": True
|
||
}
|
||
logger.info(f"===========================履约服务费已清缴,删除未收付明细===============================")
|
||
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},
|
||
"account_type": {"value": "预收款"},
|
||
"balance": {"value": amount},
|
||
"jg": {"value": user_info['jg']},
|
||
"mode_type": {"value": "DP"},
|
||
"car_dept": {"value": "DP"},
|
||
"fs": {"value": user_info['fs']},
|
||
"fsfz": {"value": user_info['fsfz']},
|
||
"hphm": {"value": user_info['hphm']},
|
||
"shfid": {"value": user_info['shfid']},
|
||
}
|
||
}
|
||
req_tool_jdy(url, info)
|
||
|
||
|
||
def add_payment(data, type=None):
|
||
lock.acquire()
|
||
logger.info(f"开始========data{data}, type{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:
|
||
# 查询是否已存在
|
||
query_url = f'{base_path}/api/v5/app/entry/data/list'
|
||
_query_tmp = {
|
||
"app_id": pay_app,
|
||
"entry_id": pay_details_id,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "transactionid",
|
||
"method": "eq",
|
||
"value": [data['transaction_id']]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
res = req_tool_jdy(query_url, _query_tmp)
|
||
if res['data']:
|
||
logger.info(f"充值明细已存在========{data['transaction_id']}")
|
||
lock.release()
|
||
return
|
||
info = {
|
||
"app_id": pay_app,
|
||
"entry_id": pay_details_id,
|
||
"is_start_workflow": True,
|
||
"is_start_trigger": True,
|
||
"data": {
|
||
"id_card": {"value": data['id']}, "name": {"value": data['name']},
|
||
"charge_amount": {"value": data['pay_amount']}, "pay_type": {"value": data['pay_type']},
|
||
"coll_type": {"value": "网银"}, "month": {"value": now_month},"fsfz": {"value": data['fsfz']},
|
||
"jg": {"value": data['jg']}, "fs": {"value": data['fs']},"mode_type": {"value": "DP"},"collect_pos": {"value": data['jg']},
|
||
"hphm": {"value": data['hphm']},"shfid":{"value": data['shfid']},"zhtype": {"value": "预收款"},"type": {"value": "转入"},
|
||
"charge_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_dp_pay_details(data['id'])
|
||
dates = list(details.keys())
|
||
dates.sort()
|
||
dates.remove('amount')
|
||
pay_amount = data['pay_amount']
|
||
# 查询余额
|
||
balance = querydpUser(data['id'])
|
||
pay_amount += balance['balance']
|
||
if pay_amount <= 0:
|
||
logger.info(f"余额为0结束========{data}")
|
||
lock.release()
|
||
return
|
||
logger.info(f"执行承包金add_payment{data}")
|
||
next_month = (datetime.datetime.now().date() - relativedelta(months=-1)).strftime("%Y-%m")
|
||
if next_month in dates:
|
||
_tmp = details[next_month]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if '承包金' in i['fukuanshiyou']:
|
||
# 承包金实际需要缴纳的
|
||
if pay_amount < i['money'] - i['pay']:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= (i['money'] - i['pay'])
|
||
i['flag_m'] = (i['money'] - i['pay'])
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
|
||
else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
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']:
|
||
# 承包金实际需要缴纳的
|
||
if pay_amount < i['money'] - i['pay']:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= (i['money'] - i['pay'])
|
||
i['flag_m'] = (i['money'] - i['pay'])
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
|
||
else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
for i in dates:
|
||
if i == next_month or i == now_month:
|
||
continue
|
||
_tmp = details[i]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
if '承包金' in i['fukuanshiyou']:
|
||
# 承包金实际需要缴纳的
|
||
if pay_amount < i['money'] - i['pay']:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
|
||
else:
|
||
pay_amount -= (i['money'] - i['pay'])
|
||
i['flag_m'] = (i['money'] - i['pay'])
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
|
||
else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
|
||
else:
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
# 根据抵扣规则,更新未支付的数据,将清缴数据新增至已收付明细
|
||
logger.info(f"更新未收付{details}")
|
||
update_no_money(details)
|
||
# 未收付更新完后,更新个人账户余额update_info
|
||
logger.info(f"更新个人账户余额update_info")
|
||
update_info(data['pay_amount'], pay_amount, balance['balance'], data)
|
||
lock.release()
|
||
logger.info(f"结束========")
|
||
|
||
def add_payment_lw(data, type=None):
|
||
lock.acquire()
|
||
logger.info(f"开始========{data}")
|
||
logger.info(f"data{data}, type{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:
|
||
# 查询是否已存在
|
||
query_url = f'{base_path}/api/v5/app/entry/data/list'
|
||
_query_tmp = {
|
||
"app_id": lw_pay_app,
|
||
"entry_id": lw_pay_details_id,
|
||
"filter": {
|
||
"rel": "and",
|
||
"cond": [
|
||
{
|
||
"field": "transactionid",
|
||
"method": "eq",
|
||
"value": [data['transaction_id']]
|
||
}
|
||
]
|
||
}
|
||
}
|
||
res = req_tool_jdy(query_url, _query_tmp)
|
||
if res['data']:
|
||
logger.info(f"充值明细已存在========{data}"['transaction_id'])
|
||
lock.release()
|
||
return
|
||
info = {
|
||
"app_id": lw_pay_app,
|
||
"entry_id": lw_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": data['pay_type']},
|
||
"month": {"value": now_month},"shfid": {"value": data['shfid']},
|
||
"jg": {"value": data['jg']}, "fs": {"value": data['fs']},
|
||
"hphm": {"value": data['hphm']},"pay_status": {"value": "付款成功"},
|
||
"charge_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_lw_pay_details(data['id'])
|
||
dates = list(details.keys())
|
||
dates.sort()
|
||
dates.remove('amount')
|
||
pay_amount = float(data['pay_amount'])
|
||
|
||
logger.info(f"执行履约服务费add_payment{data}")
|
||
next_month = (datetime.datetime.now().date() - relativedelta(months=-1)).strftime("%Y-%m")
|
||
# if next_month in dates:
|
||
# _tmp = details[next_month]['data']
|
||
# _tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
# for i in _tmp:
|
||
# if pay_amount:
|
||
# i['flag'] = 1
|
||
# if '承包金' in i['name']:
|
||
# # 承包金实际需要缴纳的
|
||
# if pay_amount < i['money'] - i['pay']:
|
||
# # 修改 i['pay'] 充值金额,推送修改
|
||
# i['pay'] += pay_amount
|
||
# i['no_money'] = i['money'] - i['pay']
|
||
# i['flag_m'] = pay_amount
|
||
# pay_amount = 0
|
||
# else:
|
||
# pay_amount -= (i['money'] - i['pay'])
|
||
# i['flag_m'] = (i['money'] - i['pay'])
|
||
# i['pay'] = i['money']
|
||
# i['no_money'] = 0
|
||
#
|
||
# else:
|
||
# if i['money'] != i['pay']:
|
||
# # 根据未支付的金额,扣除总金额
|
||
# df = i['money'] - i['pay']
|
||
# if pay_amount < df:
|
||
# # 修改 i['pay'] 充值金额,推送修改
|
||
# i['pay'] += pay_amount
|
||
# i['no_money'] = i['money'] - i['pay']
|
||
# i['flag_m'] = pay_amount
|
||
# pay_amount = 0
|
||
# else:
|
||
# pay_amount -= df
|
||
# i['pay'] = i['money']
|
||
# i['no_money'] = 0
|
||
# i['flag_m'] = df
|
||
# 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['name']:
|
||
# # 承包金实际需要缴纳的
|
||
# if pay_amount < i['money'] - i['pay']:
|
||
# # 修改 i['pay'] 充值金额,推送修改
|
||
# i['pay'] += pay_amount
|
||
# i['no_money'] = i['money'] - i['pay']
|
||
# i['flag_m'] = pay_amount
|
||
# pay_amount = 0
|
||
# else:
|
||
# pay_amount -= (i['money'] - i['pay'])
|
||
# i['flag_m'] = (i['money'] - i['pay'])
|
||
# i['pay'] = i['money']
|
||
# i['no_money'] = 0
|
||
#
|
||
# else:
|
||
# if i['money'] != i['pay']:
|
||
# # 根据未支付的金额,扣除总金额
|
||
# df = i['money'] - i['pay']
|
||
# if pay_amount < df:
|
||
# # 修改 i['pay'] 充值金额,推送修改
|
||
# i['pay'] += pay_amount
|
||
# i['no_money'] = i['money'] - i['pay']
|
||
# i['flag_m'] = pay_amount
|
||
# pay_amount = 0
|
||
# else:
|
||
# pay_amount -= df
|
||
# i['pay'] = i['money']
|
||
# i['no_money'] = 0
|
||
# i['flag_m'] = df
|
||
for i in dates:
|
||
# if i == next_month or i == now_month:
|
||
# continue
|
||
_tmp = details[i]['data']
|
||
_tmp = sorted(_tmp, key=lambda x: x['sort'])
|
||
for i in _tmp:
|
||
if pay_amount:
|
||
i['flag'] = 1
|
||
# if '承包金' in i['name']:
|
||
# # 承包金实际需要缴纳的
|
||
# if pay_amount < i['money'] - i['pay']:
|
||
# # 修改 i['pay'] 充值金额,推送修改
|
||
# i['pay'] += pay_amount
|
||
# i['no_money'] = i['money'] - i['pay']
|
||
# i['flag_m'] = pay_amount
|
||
# pay_amount = 0
|
||
#
|
||
# else:
|
||
# pay_amount -= (i['money'] - i['pay'])
|
||
# i['flag_m'] = (i['money'] - i['pay'])
|
||
# i['pay'] = i['money']
|
||
# i['no_money'] = 0
|
||
#
|
||
# else:
|
||
if i['money'] != i['pay']:
|
||
# 根据未支付的金额,扣除总金额
|
||
df = i['money'] - i['pay']
|
||
if pay_amount < df:
|
||
# 修改 i['pay'] 充值金额,推送修改
|
||
logger.info(f"==========================================================支付小于待付")
|
||
i['pay'] += pay_amount
|
||
i['no_money'] = i['money'] - i['pay']
|
||
i['flag_m'] = pay_amount
|
||
pay_amount = 0
|
||
else:
|
||
logger.info(f"==========================================================支付不小于待付")
|
||
pay_amount -= df
|
||
i['pay'] = i['money']
|
||
i['no_money'] = 0
|
||
i['flag_m'] = df
|
||
# 根据抵扣规则,更新未支付的数据,将清缴数据新增至已收付明细
|
||
logger.info(f"更新未收付{details}")
|
||
update_lw_no_money(details)
|
||
lock.release()
|
||
logger.info(f"结束========")
|
||
|
||
def rsa_long_decrypt(priv_key, msg, length=256):
|
||
"""
|
||
1024bit的证书用128,2048bit证书用256位
|
||
"""
|
||
try:
|
||
privobj = PKCS1_v1_5.new(priv_key)
|
||
res = []
|
||
b64_msg = base64.b64decode(msg)
|
||
for i in range(0, len(b64_msg), length):
|
||
chunk = b64_msg[i:i + length]
|
||
decrypted_chunk = privobj.decrypt(chunk, 'xyz').decode('GBK')
|
||
res.append(decrypted_chunk)
|
||
logger.info(f"解密回调完成:{res}")
|
||
except Exception as e:
|
||
logger.error(f"解密回调失败:{e}")
|
||
return jsonify(error=str(e)), 500
|
||
return "".join(res)
|
||
|
||
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:
|
||
logger.error(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 get_zy_wx_token():
|
||
url = f'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={zy_corpid}&corpsecret={ZY_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 = ""
|
||
logger.info(f"query_wx_fj_info,res{res},id{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']
|
||
|
||
def query_zy_wx_fj_info(id):
|
||
"""查询企微中的附加信息"""
|
||
token = get_zy_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 = ""
|
||
logger.info(f"query_wx_fj_info{res},{id}")
|
||
for i in res['extattr']['attrs']:
|
||
if i['name'] == '附加信息':
|
||
val = i['value']
|
||
return val
|
||
|
||
|
||
def query_zy_wx_userid(code):
|
||
"""查询企微中的userid"""
|
||
token = get_zy_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']
|