fix: 批量退款处理人ID默认138377,限制chuliid最长11位
batch_20260710 超长导致762单全部失败;与客服手机号字段一致。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -24,6 +24,7 @@ from orders.models import Order, RefundRecord
|
||||
from orders.services.merchant_refund_approve import (
|
||||
MerchantRefundApproveError,
|
||||
approve_merchant_refund_order,
|
||||
normalize_processor_id,
|
||||
)
|
||||
from users.models import UserShangjia
|
||||
|
||||
@@ -49,8 +50,8 @@ class Command(BaseCommand):
|
||||
help='仅处理商家昵称包含该关键字(可选,如 星阙)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--processor', default='batch_script',
|
||||
help='写入 RefundRecord.ProcessorID / Order.AssignedCS',
|
||||
'--processor', default='138377',
|
||||
help='写入 RefundRecord.ProcessorID(chuliid,最长11位)',
|
||||
)
|
||||
parser.add_argument(
|
||||
'--tuikuan-liyou', default='批量同意退款',
|
||||
@@ -74,7 +75,7 @@ class Command(BaseCommand):
|
||||
min_count = int(options['min_count'] or 0)
|
||||
merchant_id = (options['merchant_id'] or '').strip()
|
||||
merchant_nicheng = (options['merchant_nicheng'] or '').strip()
|
||||
processor = (options['processor'] or 'batch_script').strip()
|
||||
processor = normalize_processor_id((options['processor'] or '').strip())
|
||||
tuikuan_liyou = (options['tuikuan_liyou'] or '').strip()
|
||||
do_execute = bool(options['execute'])
|
||||
force = bool(options['force'])
|
||||
|
||||
@@ -11,6 +11,23 @@ from users.business_models import User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# tuikuanjilu.chuliid / RefundRecord.ProcessorID 数据库列最长 11
|
||||
PROCESSOR_ID_MAX_LEN = 11
|
||||
|
||||
|
||||
def normalize_processor_id(processor_id, *, default='138377'):
|
||||
"""处理人 ID 须 <=11 位(与客服手机号字段一致),超长则截断。"""
|
||||
val = (processor_id or default or '').strip()
|
||||
if not val:
|
||||
val = default
|
||||
if len(val) > PROCESSOR_ID_MAX_LEN:
|
||||
logger.warning(
|
||||
'processor_id 超长已截断: %s -> %s',
|
||||
val, val[:PROCESSOR_ID_MAX_LEN],
|
||||
)
|
||||
val = val[:PROCESSOR_ID_MAX_LEN]
|
||||
return val
|
||||
|
||||
|
||||
class MerchantRefundApproveError(Exception):
|
||||
"""单笔商家退款同意失败。"""
|
||||
@@ -19,7 +36,7 @@ class MerchantRefundApproveError(Exception):
|
||||
def approve_merchant_refund_order(
|
||||
order,
|
||||
*,
|
||||
processor_id='batch_script',
|
||||
processor_id='138377',
|
||||
tuikuan_liyou='',
|
||||
require_status_4=True,
|
||||
):
|
||||
@@ -36,6 +53,7 @@ def approve_merchant_refund_order(
|
||||
返回 (True, 'ok');失败抛 MerchantRefundApproveError。
|
||||
"""
|
||||
dingdan_id = order.OrderID
|
||||
processor_id = normalize_processor_id(processor_id)
|
||||
|
||||
if order.Platform != 2:
|
||||
raise MerchantRefundApproveError(f'订单 {dingdan_id} 不是商家发单(Platform=2)')
|
||||
|
||||
Reference in New Issue
Block a user