Commit ef263373 by Aeolus

Merge remote-tracking branch 'origin/dev_aeolus'

parents 45909203 f728af7b
...@@ -306,10 +306,8 @@ def rent_money_refund(): ...@@ -306,10 +306,8 @@ def rent_money_refund():
rent_total = rent_info.Rent.total - rent_info.Production.total rent_total = rent_info.Rent.total - rent_info.Production.total
rent_real_total = rent_info.Rent.real_total - real_single_refund rent_real_total = rent_info.Rent.real_total - real_single_refund
rent_agent_total = rent_info.Rent.agent_total - real_single_refund
rent_info.Rent.total = rent_total if rent_total > 0 else 0 rent_info.Rent.total = rent_total if rent_total > 0 else 0
rent_info.Rent.real_total = rent_real_total if rent_real_total > 0 else 0 rent_info.Rent.real_total = rent_real_total if rent_real_total > 0 else 0
rent_info.Rent.agent_total = rent_agent_total if rent_agent_total > 0 else 0
data = { data = {
"out_refund_no": rent_refund_no, "out_refund_no": rent_refund_no,
...@@ -329,7 +327,6 @@ def rent_money_refund(): ...@@ -329,7 +327,6 @@ def rent_money_refund():
rent_refund.updated_at = datetime.datetime.now() rent_refund.updated_at = datetime.datetime.now()
rent_info.Production.total = 0 rent_info.Production.total = 0
rent_info.Production.agent_total = 0
db.session.add(rent_refund) db.session.add(rent_refund)
db.session.add(rent_info.Rent) db.session.add(rent_info.Rent)
...@@ -343,6 +340,101 @@ def rent_money_refund(): ...@@ -343,6 +340,101 @@ def rent_money_refund():
return jsonify(BASE_RESPONSE(error_code=-1, error_message='refund failed').to_dict()) return jsonify(BASE_RESPONSE(error_code=-1, error_message='refund failed').to_dict())
@route_rent.route('/rent_money_refund_new', methods=['GET', 'POST'])
def rent_money_refund_new():
json_data = request.get_json()
action_pwd = json_data['action_pwd'] if 'action_pwd' in json_data else ''
if action_pwd != ACTION_PWD:
return jsonify(ACTION_CODE_ERROR)
rent_no = json_data['rent_no'] if 'rent_no' in json_data else ''
hatch_no = json_data['hatch_no'] if 'hatch_no' in json_data else ''
comment = json_data['comment'] if 'comment' in json_data else ''
time_price = json_data['time_price'] if 'time_price' in json_data else []
if not rent_no or not hatch_no or not comment or not time_price:
return jsonify(PARAMETER_ERROR)
rent_info = db.session.query(Production, Rent).join(Rent, Rent.id == Production.rent_id).filter(
Production.rent_hatch_no == hatch_no, Rent.rent_no == rent_no).first()
if not rent_info:
return jsonify(REFUND_NOT_PRODUCTION_INFO)
rent = rent_info.Rent
production = rent_info.Production
new_total = int(time_price[-1])
if production.is_return:
refund_money = production.total - new_total
else:
refund_money = rent.deposit - new_total
if refund_money <= 0:
return jsonify(REFUND_MONEY_IS_ZERO)
# 重新计算订单对应所有讲解器总收入,退款金额
rent_total = 0
rent_real_total = 0
rent_agent_total = 0
productions = Production.query.filter_by(rent_id=rent.id).all()
for tmp in productions:
if tmp.id == production.id:
rent_total += new_total
rent_real_total += new_total
rent_agent_total += new_total
else:
rent_total += tmp.total if tmp.total is not None else 0
rent_real_total += tmp.total if tmp.total is not None else 0
rent_agent_total += tmp.agent_total if tmp.agent_total is not None else 0
rent_back_money = rent.deposit * rent.number - rent_total
# 退款操作
data = {
"out_refund_no": RentService.create_refund_no(),
"out_trade_no": rent_info.Rent.rent_no,
"total_fee": rent_info.Rent.deposit * rent_info.Rent.number,
"refund_fee": refund_money
}
result = WeChatService().refund(data)
if result:
try:
rent_refund = RentRefund()
rent_refund.refund_no = data["out_refund_no"]
rent_refund.production_id = rent_info.Production.id
rent_refund.fee = refund_money
rent_refund.comment = comment
rent.total = rent_total
rent.real_total = rent_real_total
rent.agent_total = rent_agent_total
rent.back_money = rent_back_money
rent.is_over = 1
production.total = new_total
production.agent_total = new_total
if not production.is_return:
production.is_return = 1
production.return_time = datetime.datetime.now()
production.return_hatch_no = production.rent_hatch_no
production.return_machine_id = production.rent_machine_id
if not production.is_refund:
production.is_refund = 1
production.refund_time = datetime.datetime.now()
production.refund_no = data["out_refund_no"]
db.session.add(rent_refund)
db.session.add(rent)
db.session.add(production)
db.session.commit()
except SQLAlchemyError as e:
db.session.rollback()
raise e
return jsonify(BASE_RESPONSE().to_dict())
else:
return jsonify(BASE_RESPONSE(error_code=-1, error_message='refund failed').to_dict())
@route_rent.route('/force_refund', methods=['GET', 'POST']) @route_rent.route('/force_refund', methods=['GET', 'POST'])
def force_refund(): def force_refund():
json_data = request.get_json() json_data = request.get_json()
......
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