Commit 38209ab0 by 魏强

update;

parent c4838fbd
......@@ -38,6 +38,8 @@ def rent_list():
spot_id = json_data['spot_id'] if 'spot_id' in json_data else 0
data_type = json_data['data_type'] if 'data_type' in json_data else 0 # 0:今日 1:昨日 2:近7天 3 所有
action_type = json_data['action_type'] if 'action_type' in json_data else 0 # 0:全部 1:未归还 2:已归还 3:无效 4:退款
page = json_data['page'] if 'page' in json_data else 0
limit = json_data['limit'] if 'limit' in json_data else 10
......@@ -46,28 +48,86 @@ def rent_list():
if data_type == 0:
start_time, end_time = Helper.getTodayDate()
info, total_count = RentService.get_rent_production_info(spot_id, start_time, end_time, page, limit)
if action_type == 1:
# 未归还
info, total_count = RentService.get_not_return_production(spot_id, start_time, end_time, action_type, page)
elif action_type == 2:
# 已归还
info, total_count = RentService.get_already_returned_rent_production_info(spot_id, start_time, end_time,
page, limit)
elif action_type == 3:
# 无效
info, total_count = RentService.get_invalid_rent_production_info(spot_id, start_time, end_time, page, limit)
elif action_type == 4:
# 退款
info, total_count = RentService.get_refund_rent_production_info(spot_id, start_time, end_time, page, limit)
else:
# 全部
info, total_count = RentService.get_rent_production_info(spot_id, start_time, end_time, page, limit)
total_income, total_rent = IndexService.get_total_production(spot_id, start_time, end_time)
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, 'detail': {'total_income': total_income, 'total_rent': total_rent}})
elif data_type == 1:
start_time, end_time = Helper.getYesterdayDate()
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
if action_type == 1:
# 未归还
info, total_count = RentService.get_not_return_production(spot_id, start_time, end_time, action_type, page)
elif action_type == 2:
# 已归还
info, total_count = RentService.get_already_returned_rent_production_info(spot_id, start_time, end_time,
page, limit)
elif action_type == 3:
# 无效
info, total_count = RentService.get_invalid_rent_production_info(spot_id, start_time, end_time, page, limit)
elif action_type == 4:
# 退款
info, total_count = RentService.get_refund_rent_production_info(spot_id, start_time, end_time, page, limit)
else:
# 全部
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
total_income, total_rent = IndexService.get_total_production(spot_id, start_time, end_time)
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, 'detail': {'total_income': total_income, 'total_rent': total_rent}})
elif data_type == 2:
start_time, end_time = Helper.getSevenDate()
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
if action_type == 1:
# 未归还
info, total_count = RentService.get_not_return_production(spot_id, start_time, end_time, action_type, page)
elif action_type == 2:
# 已归还
info, total_count = RentService.get_already_returned_rent_production_info(spot_id, start_time, end_time,
page, limit)
elif action_type == 3:
# 无效
info, total_count = RentService.get_invalid_rent_production_info(spot_id, start_time, end_time, page, limit)
elif action_type == 4:
# 退款
info, total_count = RentService.get_refund_rent_production_info(spot_id, start_time, end_time, page, limit)
else:
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
total_income, total_rent = IndexService.get_total_production(spot_id, start_time, end_time)
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, 'detail': {'total_income': total_income, 'total_rent': total_rent}})
else:
start_time, end_time = Helper.getMonthDate()
info, total_count = RentService.get_not_return_production(spot_id, start_time, end_time, page, limit)
if action_type == 1:
# 未归还
info, total_count = RentService.get_not_return_production(spot_id, start_time, end_time, action_type, page)
elif action_type == 2:
# 已归还
info, total_count = RentService.get_already_returned_rent_production_info(spot_id, start_time, end_time,
page, limit)
elif action_type == 3:
# 无效
info, total_count = RentService.get_invalid_rent_production_info(spot_id, start_time, end_time, page, limit)
elif action_type == 4:
# 退款
info, total_count = RentService.get_refund_rent_production_info(spot_id, start_time, end_time, page, limit)
else:
info, total_count = RentService.get_rent_production_all(spot_id, start_time, end_time, page, limit)
return jsonify(
{'error_code': 200, 'error_message': 'Success', 'data': info, 'total_count': total_count, 'page': page,
'limit': limit, })
......
......@@ -71,6 +71,97 @@ class RentService():
data.append(tmp)
return data, total_count
'''
已归还
'''
@staticmethod
def get_already_returned_rent_production_info(spot_id, start_time, end_time, page, limit):
where = {
Rent.spot_id == spot_id,
Production.is_out == 1,
Production.is_return == 1,
Production.total > 0,
Production.created_at >= start_time,
Production.created_at <= end_time
}
total_count = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).count()
rent_info = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).order_by(Production.created_at.desc()).slice(page * limit, (page + 1) * limit).all()
data = []
for info in rent_info:
cur_info = {}
cur_info['rent_no'] = info.Rent.rent_no
cur_info['hatch_no'] = info.Production.rent_hatch_no
cur_info['total'] = 0 if info.Production.agent_total is None else info.Production.agent_total
cur_info['status'] = 1
data.append(cur_info)
return data, total_count
'''
无效
'''
@staticmethod
def get_invalid_rent_production_info(spot_id, start_time, end_time, page, limit):
where = {
Rent.spot_id == spot_id,
Production.is_out == 1,
Production.is_return == 1,
Production.total <= 0,
Production.return_hatch_no < 127,
Production.created_at >= start_time,
Production.created_at <= end_time
}
total_count = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).count()
rent_info = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).order_by(Production.created_at.desc()).slice(page * limit, (page + 1) * limit).all()
data = []
for info in rent_info:
cur_info = {}
cur_info['rent_no'] = info.Rent.rent_no
cur_info['hatch_no'] = info.Production.rent_hatch_no
cur_info['total'] = 0 if info.Production.agent_total is None else info.Production.agent_total
cur_info['status'] = 2
data.append(cur_info)
return data, total_count
@staticmethod
def get_refund_rent_production_info(spot_id, start_time, end_time, page, limit):
where = {
Rent.spot_id == spot_id,
Production.is_out == 1,
Production.is_return == 1,
Production.total <= 0,
Production.return_hatch_no == 127,
Production.created_at >= start_time,
Production.created_at <= end_time
}
total_count = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).count()
rent_info = db.session.query(Rent, Production).join(Production, Production.rent_id == Rent.id).filter(
*where).order_by(Production.created_at.desc()).slice(page * limit, (page + 1) * limit).all()
data = []
for info in rent_info:
cur_info = {}
cur_info['rent_no'] = info.Rent.rent_no
cur_info['hatch_no'] = info.Production.rent_hatch_no
cur_info['total'] = 0 if info.Production.agent_total is None else info.Production.agent_total
cur_info['status'] = 3
data.append(cur_info)
return data, total_count
@staticmethod
def get_rent_production_info(spot_id, start_time, end_time, page, limit):
where = {
......
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