Commit 0639410a by Aeolus

update

parent 248b7566
......@@ -155,6 +155,24 @@ class Business(Base):
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class DrawRecord(Base):
__tablename__ = 'draw_record'
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(10))
draw_month = Column(VARCHAR(7))
total = Column(INTEGER(11))
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"))
updated_at = Column(TIMESTAMP, server_default=text("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"))
class Hatch(Base):
__tablename__ = 'hatch'
__table_args__ = (
......
......@@ -8,6 +8,7 @@ author:Aeolus
@function:
@modify:
"""
import datetime
import logging
from flask import Blueprint, g, request, jsonify
......@@ -15,7 +16,7 @@ from sqlalchemy.exc import SQLAlchemyError
from config.wechat_config import platform_appid_config_list, pay_config_list
from models.base_model import db
from models.models import Rent, RentDetail, WxUser, Machine, RentRefund
from models.models import Rent, RentDetail, WxUser, Machine, RentRefund, DrawRecord
from service.rent_service import RentService
from service.wechat_service import WeChatPayService
from utils.error_code import OPERATE_LEVEL_ERROR, ACTION_CODE_ERROR, REFUND_NOT_PRODUCTION_INFO, Param_Invalid_Error, \
......@@ -273,3 +274,216 @@ def rent_money_refund_new():
return BaseResponse()
else:
return BaseResponse(error_code=-1, error_message='refund failed')
@rent_route.route("month_bill", methods=["POST"])
def run_month_bill():
"""
:return:
"""
json_data = request.get_json()
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)
business_id = json_data.get("business_id", None)
is_pay = json_data.get("is_pay", None)
select_sql = """
select sum(rent.real_total) as total, rent.business_id,DATE_FORMAT(rent.created_at,"%Y-%m") as rent_month,
admin_business.rate as rate, business.business_name as business_name
"""
count_sql = " select count(1) as total_count from ("
from_sql = """
FROM
rent
left join admin_business on admin_business.business_id = rent.business_id
left join business on business.id = rent.business_id
"""
where_sql = " WHERE 0=0 "
if start_date is not None:
where_sql += " and rent.created_at > '{}'".format(start_date)
if end_date is not None:
where_sql += " and rent.created_at <= '{}'".format(end_date)
if is_pay is not None:
where_sql += " and rent.is_pay = '{}'".format(is_pay)
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 MONTH(rent.created_at), rent.business_id "
order_sql = " ORDER BY rent.created_at DESC, rent.created_at desc"
limit_sql = " LIMIT {offset} , {page_size}".format(offset=(page - 1) * page_size, page_size=page_size)
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": info.total, "business_id": info.business_id, "rent_month": info.rent_month,
"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:
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,
admin_business.rate as rate, business.business_name as business_name
"""
from_sql = """
FROM
rent
left join admin_business on admin_business.business_id = rent.business_id
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 += """ and admin_business.user_id = '{}' and admin_business.status = 1 and admin_business.rate > 0
""".format(g.user.id)
result = db.session.execute(select_sql + from_sql + where_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()
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.status = 0
model.draw_no = RentService.create_order_no(prefix="DR")
db.session.add(model)
db.session.commit()
return BaseResponse()
@rent_route.route("draw_list", methods=["POST"])
def run_draw_list():
"""
:return:
"""
json_data = request.get_json()
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)
business_id = json_data.get("business_id", None)
status = json_data.get("status", None)
if g.user.level not in (1, 2, 4, 5):
return jsonify(OPERATE_LEVEL_ERROR)
select_sql = """
select draw_record.draw_no,
draw_record.business_id,
draw_record.draw_month,
draw_record.total,
draw_record.real_total,
draw_record.rate,
draw_record.status,
draw_record.draw_time,
draw_record.created_at,
draw_record.updated_at,
business.business_name
"""
count_sql = " select count(draw_record.id) as total_count "
from_sql = """
FROM
draw_record
LEFT JOIN
business ON draw_record.business_id = business.id
"""
where_sql = " WHERE draw_record.status <> '-1' "
if start_date is not None:
where_sql += " and draw_record.draw_month > '{}'".format(start_date)
if end_date is not None:
where_sql += " and draw_record.draw_month <= '{}'".format(end_date)
if status is not None:
where_sql += " and draw_record.status = '{}'".format(status)
if business_id is not None:
where_sql += " and draw_record.business_id = '{}'".format(business_id)
if g.user.level != 1:
where_sql += """ and draw_record.business_id in (
select business_id from admin_business where user_id = '{}' and status = 1)
""".format(g.user.id)
order_sql = " ORDER BY draw_record.created_at DESC, draw_record.status asc"
limit_sql = " LIMIT {offset} , {page_size}".format(offset=(page - 1) * page_size, page_size=page_size)
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
result = db.session.execute(select_sql + from_sql + where_sql + order_sql + limit_sql).fetchall()
return_data = []
if result:
for info in result:
"""
draw_record.draw_no,
draw_record.business_id,
draw_record.draw_month,
draw_record.total,
draw_record.real_total,
draw_record.rate,
draw_record.status,
business.business_name
"""
tmp = {
"business_id": info.business_id, "draw_month": info.draw_month, "total": info.total,
"real_total": info.real_total, "rate": info.rate, "status": info.status,
"business_name": info.business_name,
"create_time": info.created_at.strftime("%Y-%m-%d %H:%M:%S"),
"draw_time": info.draw_time.strftime("%Y-%m-%d %H:%M:%S") if info.draw_time else "",
}
return_data.append(tmp)
return BaseResponse({"list": return_data, "page": page, "pageSize": page_size, "total_count": total_count})
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