Commit eebf3b2a by Aeolus

update

parent 3d3d292f
......@@ -164,7 +164,6 @@ class DrawDetail(Base):
open_id = Column(String(40, 'utf8mb4_unicode_ci'), nullable=False)
draw_no = Column(VARCHAR(40), nullable=False, index=True)
payment_no = Column(VARCHAR(40), nullable=False)
business_id = Column(INTEGER(11), nullable=False)
draw_month = Column(VARCHAR(7))
total = Column(INTEGER(11))
real_total = Column(INTEGER(11))
......@@ -177,18 +176,15 @@ class DrawDetail(Base):
class DrawRecord(Base):
__tablename__ = 'draw_record'
__table_args__ = (
Index('unique4draw_record_user_month', 'user_id', 'draw_month', 'business_id', unique=True),
Index('unique4draw_record_user_month', 'user_id', 'bill_date', unique=True),
)
id = Column(INTEGER(10), primary_key=True)
user_id = Column(INTEGER(11), nullable=False)
user_no = Column(String(25, 'utf8mb4_unicode_ci'), nullable=False)
draw_no = Column(VARCHAR(40), nullable=False, index=True)
business_id = Column(INTEGER(11))
draw_month = Column(VARCHAR(7))
total = Column(INTEGER(11))
bill_date = Column(VARCHAR(20))
real_total = Column(INTEGER(11))
rate = Column(INTEGER(3))
draw_time = Column(TIMESTAMP)
status = Column(TINYINT(1), nullable=False, server_default=text("'0'"))
created_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP"))
......
......@@ -356,23 +356,92 @@ def run_month_bill():
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@rent_route.route("apply_draw", methods=["POST"])
def run_apply_draw():
@rent_route.route("day_bill", methods=["POST"])
def run_day_bill():
"""
:return:
"""
json_data = request.get_json()
draw_data = json_data["draw_data"]
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
start_date = json_data.get("startDate", None)
end_date = json_data.get("endDate", None)
now = datetime.datetime.now().date()
select_sql = " SELECT sum(real_total) as real_total, bill_date "
count_sql = " select count(1) as total_count"
from_sql = """
FROM
(SELECT
SUM(total * rate/100) AS real_total,
rent.business_id,
DATE_FORMAT(rent.created_at, '%Y-%m-%d') AS bill_date,
admin_business.rate AS rate,
business.business_name AS business_name
FROM
rent
LEFT JOIN admin_business ON admin_business.business_id = rent.business_id
LEFT JOIN business ON business.id = rent.business_id
WHERE
0 = 0
AND rent.created_at < '{}'
AND admin_business.user_id = '{}'
AND admin_business.status = 1
AND admin_business.rate > 0
GROUP BY DATE_FORMAT(rent.created_at, '%Y-%m-%d') , rent.business_id) AS tab1
""".format(now.strftime("%Y-%m-%d %H:%M:%S"), g.user.id)
where_sql = """
where real_total > '0'
"""
if start_date is not None:
where_sql += " and bill_date >= '{}'".format(start_date)
if end_date is not None:
where_sql += " and bill_date <= '{}'".format(end_date)
group_sql = """group by tab1.bill_date """
order_sql = " ORDER BY tab1.bill_date DESC "
limit_sql = " LIMIT {offset} , {page_size}".format(offset=(page - 1) * page_size, page_size=page_size)
print(count_sql + from_sql + where_sql + group_sql)
count_result = db.session.execute(count_sql + from_sql + where_sql).fetchone()
if not count_result:
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else:
total_count = count_result.total_count
print(select_sql + from_sql + where_sql + group_sql + order_sql + limit_sql)
result = db.session.execute(select_sql + from_sql + where_sql + group_sql + order_sql + limit_sql).fetchall()
return_data = []
if result:
for info in result:
tmp = {
"total": int(info.real_total), "bill_date": info.bill_date, "total2": info.real_total,
}
return_data.append(tmp)
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@rent_route.route("day_bill_detail", methods=["POST"])
def run_day_bill_detail():
"""
:return:
"""
json_data = request.get_json()
page = json_data.get("page", 1)
page_size = json_data.get("pageSize", 10)
business_id = json_data.get("business_id", None)
bill_date = json_data["bill_date"]
for data in draw_data:
business_id = int(data["business_id"])
month = datetime.datetime.strptime(data["month"], "%Y-%M")
select_sql = """
select sum(rent.real_total) as total, rent.business_id,
DATE_FORMAT(rent.created_at,"%Y-%m") as rent_month,
DATE_FORMAT(rent.created_at,"%Y-%m-%d") as bill_date,
admin_business.rate as rate, business.business_name as business_name
"""
count_sql = " select count(1) as total_count from ("
from_sql = """
FROM
......@@ -381,26 +450,86 @@ def run_apply_draw():
left join business on business.id = rent.business_id
"""
where_sql = """ WHERE rent.business_id = '{}' and DATE_FORMAT(rent.created_at,"%Y-%m") = '{}' """.format(
business_id, data["month"])
where_sql = """ WHERE 0=0 and DATE_FORMAT(rent.created_at,"%Y-%m-%d") = '{}'""".format(bill_date)
if business_id is not None:
where_sql += " and rent.business_id = '{}'".format(business_id)
where_sql += """ and admin_business.user_id = '{}' and admin_business.status = 1 and admin_business.rate > 0
""".format(g.user.id)
group_sql = """ group by DATE_FORMAT(rent.created_at,"%Y-%m-%d") , rent.business_id """
order_sql = " ORDER BY rent.created_at DESC"
limit_sql = " LIMIT {offset} , {page_size}".format(offset=(page - 1) * page_size, page_size=page_size)
result = db.session.execute(select_sql + from_sql + where_sql).fetchone()
count_result = db.session.execute(count_sql + select_sql + from_sql + where_sql + group_sql + ") as ttb").fetchone()
if not count_result:
return BaseResponse(data={"list": [], "page": page, "pageSize": page_size, "total_count": 0})
else:
total_count = count_result.total_count
result = db.session.execute(select_sql + from_sql + where_sql + group_sql + order_sql + limit_sql).fetchall()
return_data = []
if result:
for info in result:
tmp = {
"total": int(info.total), "business_id": info.business_id, "bill_date": info.bill_date,
"rate": info.rate, "business_name": info.business_name,
}
return_data.append(tmp)
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
@rent_route.route("apply_draw", methods=["POST"])
def run_apply_draw():
"""
:return:
"""
json_data = request.get_json()
draw_data = json_data["draw_data"]
for data in draw_data:
bill_date = datetime.datetime.strptime(data["bill_date"], "%Y-%m-%d").strftime("%Y-%m-%d")
sql = """
SELECT
sum(real_total) as real_total, bill_date
FROM
(SELECT
SUM(total * rate / 100) AS real_total,
rent.business_id,
DATE_FORMAT(rent.created_at, '%Y-%m-%d') AS bill_date,
admin_business.rate AS rate,
business.business_name AS business_name
FROM
rent
LEFT JOIN admin_business ON admin_business.business_id = rent.business_id
LEFT JOIN business ON business.id = rent.business_id
WHERE
0 = 0
AND rent.created_at < '2022-02-24 00:00:00'
AND admin_business.user_id = '2'
AND admin_business.status = 1
AND admin_business.rate > 0
GROUP BY DATE_FORMAT(rent.created_at, '%Y-%m-%d') , rent.business_id) AS tab1
WHERE
real_total > '0'
and bill_date = '{}'
""".format(bill_date)
result = db.session.execute(sql).fetchone()
if result:
tmp = DrawRecord.query.filter_by(user_id=g.user.id, business_id=result["business_id"],
draw_month=result["rent_month"]).first()
tmp = DrawRecord.query.filter_by(user_id=g.user.id, bill_date=result["bill_date"]).first()
if tmp:
continue
model = DrawRecord()
model.user_id = g.user.id
model.user_no = g.user.user_no
model.business_id = result["business_id"]
model.draw_month = result["rent_month"]
model.total = result["total"]
model.real_total = result["total"] * result["rate"] / 100
model.rate = result["rate"]
model.bill_date = result["bill_date"]
model.real_total = int(result["real_total"])
model.status = 0
model.draw_no = RentService.create_order_no(prefix="DR")
db.session.add(model)
......@@ -429,7 +558,7 @@ def run_draw_list():
select_sql = """
select draw_record.draw_no,
draw_record.business_id,
draw_record.draw_month,
draw_record.bill_date,
draw_record.total,
draw_record.real_total,
draw_record.rate,
......@@ -452,9 +581,9 @@ def run_draw_list():
where_sql = " WHERE draw_record.status <> '-1' "
if start_date is not None:
where_sql += " and draw_record.draw_month > '{}'".format(start_date)
where_sql += " and draw_record.bill_date > '{}'".format(start_date)
if end_date is not None:
where_sql += " and draw_record.draw_month <= '{}'".format(end_date)
where_sql += " and draw_record.bill_date <= '{}'".format(end_date)
if status is not None:
where_sql += " and draw_record.status = '{}'".format(status)
......@@ -483,7 +612,7 @@ def run_draw_list():
if result:
for info in result:
tmp = {
"business_id": info.business_id, "draw_month": info.draw_month, "total": info.total,
"business_id": info.business_id, "bill_date": info.bill_date, "total": info.total,
"real_total": info.real_total, "rate": info.rate, "status": info.status,
"business_name": info.business_name, "id": info.id,
"create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
......@@ -532,7 +661,7 @@ def run_approve_draw():
"user_id": open_id,
"amount": draw_money,
"out_trade_no": RentService.create_order_no(prefix="DR"),
"desc": draw_record.draw_month + "月份个人提现",
"desc": draw_record.bill_date + "个人提现",
"real_name": real_name
}
result = WeChatPayService(app_id=platform_appid_config_list[2],
......@@ -550,7 +679,6 @@ def run_approve_draw():
dd.draw_no = result["partner_trade_no"]
dd.payment_no = result["payment_no"]
dd.payment_time = result["payment_time"]
dd.business_id = draw_record.business_id
dd.draw_month = draw_record.draw_month
dd.total = draw_record.real_total
dd.real_total = draw_money
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment