Commit 685a6fa0 by Aeolus

同一笔订单退款需要间隔60s

parent 6735f2ba
...@@ -34,6 +34,9 @@ WX_ACCESS_TOKEN = "W_A_T_" ...@@ -34,6 +34,9 @@ WX_ACCESS_TOKEN = "W_A_T_"
# 微信公众号access_token过期时间 # 微信公众号access_token过期时间
WX_ACCESS_TOKEN_EXPIRE = "W_A_T_E_" WX_ACCESS_TOKEN_EXPIRE = "W_A_T_E_"
# 订单退款锁
RENT_REFUND_LOCK = "R_R_L_"
LOGIN_TYPE = { LOGIN_TYPE = {
'code_login': 1, 'code_login': 1,
'token_login': 2, 'token_login': 2,
......
...@@ -10,17 +10,20 @@ author:Aeolus ...@@ -10,17 +10,20 @@ author:Aeolus
""" """
import datetime import datetime
import logging import logging
import time
from flask import Blueprint, g, request, jsonify from flask import Blueprint, g, request, jsonify
from sqlalchemy.exc import SQLAlchemyError from sqlalchemy.exc import SQLAlchemyError
from config.commen_config import RENT_SALE_LOCK
from config.wechat_config import platform_appid_config_list, pay_config_list from config.wechat_config import platform_appid_config_list, pay_config_list
from models.base_model import db from models.base_model import db
from models.models import Rent, RentDetail, WxUser, Machine, RentRefund, DrawRecord from models.models import Rent, RentDetail, WxUser, Machine, RentRefund, DrawRecord
from service.rent_service import RentService from service.rent_service import RentService
from service.wechat_service import WeChatPayService from service.wechat_service import WeChatPayService
from utils.error_code import OPERATE_LEVEL_ERROR, ACTION_CODE_ERROR, REFUND_NOT_PRODUCTION_INFO, Param_Invalid_Error, \ from utils.error_code import OPERATE_LEVEL_ERROR, ACTION_CODE_ERROR, REFUND_NOT_PRODUCTION_INFO, Param_Invalid_Error, \
REFUND_MONEY_IS_ZERO, REFUND_MONEY_ERROR REFUND_MONEY_IS_ZERO, REFUND_MONEY_ERROR, REFUND_LOCK_ERROR
from utils.my_redis_cache import redis_client
from utils.my_response import BaseResponse from utils.my_response import BaseResponse
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -206,17 +209,20 @@ def rent_money_refund_new(): ...@@ -206,17 +209,20 @@ def rent_money_refund_new():
cause = json_data['cause'] cause = json_data['cause']
comment = json_data['comment'] if 'comment' in json_data else '' comment = json_data['comment'] if 'comment' in json_data else ''
rent_info = db.session.query(RentDetail, Rent, WxUser, Machine lock_res = redis_client.set(RENT_SALE_LOCK + str(rent_no) + "_" + str(rent_detail_id),
).join(Rent, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), ex=60,
Rent.rent_no == RentDetail.rent_no nx=True)
).join(WxUser, WxUser.id == Rent.user_id if lock_res:
).filter(RentDetail.id == rent_detail_id, pass
Rent.rent_no == rent_no).first() else:
return jsonify(REFUND_LOCK_ERROR)
if not rent_info:
return jsonify(REFUND_NOT_PRODUCTION_INFO)
rent = Rent.query.filter_by(rent_no=rent_no).with_for_update().first() rent = Rent.query.filter_by(rent_no=rent_no).with_for_update().first()
if not rent:
return jsonify(REFUND_NOT_PRODUCTION_INFO)
rent_detail = RentDetail.query.filter_by(rent_no=rent_no, id=rent_detail_id).with_for_update().first() rent_detail = RentDetail.query.filter_by(rent_no=rent_no, id=rent_detail_id).with_for_update().first()
if not rent_detail:
return jsonify(REFUND_NOT_PRODUCTION_INFO)
wx_user = WxUser.query.filter_by(id=rent.user_id).first() wx_user = WxUser.query.filter_by(id=rent.user_id).first()
refund_count = int(json_data["refund_count"]) refund_count = int(json_data["refund_count"])
...@@ -240,7 +246,7 @@ def rent_money_refund_new(): ...@@ -240,7 +246,7 @@ def rent_money_refund_new():
# 退款操作 # 退款操作
data = { data = {
"out_refund_no": RentService.create_refund_no(), "out_refund_no": RentService.create_refund_no(),
"out_trade_no": rent_info.Rent.rent_no, "out_trade_no": rent_no,
"total_fee": rent.total, "total_fee": rent.total,
"refund_fee": refund_money "refund_fee": refund_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