Commit 74c1164a by 魏强

update;

parent dafe918e
...@@ -360,6 +360,7 @@ def force_refund(): ...@@ -360,6 +360,7 @@ def force_refund():
Rent.rent_no == rent_no).first() Rent.rent_no == rent_no).first()
if not rent_info: if not rent_info:
logger.info('no production')
return jsonify(REFUND_NOT_PRODUCTION_INFO) return jsonify(REFUND_NOT_PRODUCTION_INFO)
if refund_type == '1': if refund_type == '1':
...@@ -381,54 +382,152 @@ def force_refund(): ...@@ -381,54 +382,152 @@ def force_refund():
money = RentService.check_fee_liuyuan(rent_info.Rent.pay_time.strftime('%Y-%m-%d %H:%M:%S'), money = RentService.check_fee_liuyuan(rent_info.Rent.pay_time.strftime('%Y-%m-%d %H:%M:%S'),
back_time.strftime('%Y-%m-%d %H:%M:%S'), back_time.strftime('%Y-%m-%d %H:%M:%S'),
rent_info.Rent.one_day_price, rent_info.Rent.free_time) rent_info.Rent.one_day_price, rent_info.Rent.free_time)
elif refund_type == '4': # elif refund_type == '4':
# 退10元 # # 退10元
if not comment: # if not comment:
return jsonify(PARAMETER_ERROR) # return jsonify(PARAMETER_ERROR)
#
# money = 1000
# elif refund_type == '5':
# # 退15元
# if not comment:
# return jsonify(PARAMETER_ERROR)
#
# money = 1500
# elif refund_type == '6':
# # 退25元
# if not comment:
# return jsonify(PARAMETER_ERROR)
#
# money = 2500
else:
return jsonify({'code': -1, 'msg': 'refund type error!'})
production = rent_info.Production
rent = rent_info.Rent
rent_refund_no = RentService.create_refund_no()
data = {
"out_refund_no": rent_refund_no,
"out_trade_no": rent_info.Rent.rent_no,
"total_fee": rent_info.Rent.deposit,
"refund_fee": int(money)
}
result = WeChatService().refund(data)
if result:
try:
rent.total = rent.deposit - int(money)
rent.real_total = rent.deposit - int(money)
rent.is_over = 1
rent.over_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
rent.back_money += int(money)
production.is_return = 1
production.return_machine_id = production.rent_machine_id
production.return_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')
production.total = rent.deposit - int(money)
production.is_refund = 1
production.refund_no = rent_refund_no
production.return_hatch_no = production.rent_hatch_no
rent_refund_log = RentRefund()
rent_refund_log.refund_no = rent_refund_no
rent_refund_log.production_id = production.id
rent_refund_log.fee = int(money)
rent_refund_log.comment = comment
rent_refund_log.created_at = datetime.datetime.now()
rent_refund_log.updated_at = datetime.datetime.now()
db.session.add(rent_refund_log)
db.session.add(production)
db.session.add(rent)
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('/liuyuan_refund', methods=['GET', 'POST'])
def rent_money_liuyuan():
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)
refund_type = json_data.get('type', None)
rent_no = json_data.get('rent_no', None)
comment = json_data.get('comment', None)
logger.info('type')
logger.info(refund_type)
logger.info('rent_no')
logger.info(rent_no)
logger.info('comment')
logger.info(comment)
if not refund_type or not rent_no or not comment:
return jsonify(PARAMETER_ERROR)
rent_info = db.session.query(Production, Rent).join(Rent, Rent.id == Production.rent_id).filter(
Rent.rent_no == rent_no).first()
if not rent_info:
return jsonify(REFUND_NOT_PRODUCTION_INFO)
real_total_consume = rent_info.Rent.deposit * rent_info.Rent.number - rent_info.Rent.back_money
if refund_type == '1':
# 退10元
money = 1000 money = 1000
elif refund_type == '5': elif refund_type == '2':
# 退15元 # 退15元
if not comment:
return jsonify(PARAMETER_ERROR)
money = 1500 money = 1500
elif refund_type == '6': elif refund_type == '3':
# 退25元 # 退25元
if not comment:
return jsonify(PARAMETER_ERROR)
money = 2500 money = 2500
elif refund_type == '4':
# 退5元
money = 500
else: else:
return jsonify({'code': -1, 'msg': 'refund type error!'}) return jsonify({'code': -1, 'msg': 'refund type error!'})
rent_info.Rent.back_money = rent_info.Rent.back_money + int(money) if money > real_total_consume:
rent_info.Rent.total = rent_info.Rent.total - int(money) return jsonify({'code': -1, 'msg': 'refund fee 大于可退金额!'})
rent_info.Rent.real_total = rent_info.Rent.real_total - int(money)
rent_info.Rent.is_over = 1
rent_refund_no = RentService.create_refund_no() rent_refund_no = RentService.create_refund_no()
data = { data = {
"out_refund_no": rent_refund_no, "out_refund_no": rent_refund_no,
"out_trade_no": rent_info.Rent.rent_no, "out_trade_no": rent_info.Rent.rent_no,
"total_fee": rent_info.Rent.deposit, "total_fee": rent_info.Rent.deposit * rent_info.Rent.number,
"refund_fee": int(money) "refund_fee": int(money),
} }
result = WeChatService().refund(data) result = WeChatService().refund(data)
if result: if result:
try: try:
rent_refund = RentRefund() rent_info.Rent.total -= int(money)
rent_refund.refund_no = rent_refund_no rent_info.Rent.real_total -= int(money)
rent_refund.production_id = rent_info.Production.id rent_info.Rent.back_money += int(money)
rent_refund.fee = int(money)
rent_refund.comment = comment
rent_refund.created_at = datetime.datetime.now()
rent_refund.updated_at = datetime.datetime.now()
db.session.add(rent_refund) rent_refund_log = RentRefund()
rent_refund_log.refund_no = rent_refund_no
rent_refund_log.production_id = rent_info.Production.id
rent_refund_log.fee = int(money)
rent_refund_log.comment = comment
rent_refund_log.created_at = datetime.datetime.now()
rent_refund_log.updated_at = datetime.datetime.now()
rent_info.Production.total -= int(money)
db.session.add(rent_refund_log)
db.session.add(rent_info.Rent) db.session.add(rent_info.Rent)
db.session.add(rent_info.Production) db.session.add(rent_info.Production)
db.session.commit() db.session.commit()
...@@ -437,4 +536,4 @@ def force_refund(): ...@@ -437,4 +536,4 @@ def force_refund():
raise e raise e
return jsonify(BASE_RESPONSE().to_dict()) return jsonify(BASE_RESPONSE().to_dict())
else: else:
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())
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