From 6689b7af00b6f77f4262d1b7a152e2d8f6330466 Mon Sep 17 00:00:00 2001 From: XingQue Date: Fri, 10 Jul 2026 23:21:23 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=89=B9=E9=87=8F=E9=80=80=E6=AC=BE?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=BAID=E9=BB=98=E8=AE=A4138377=EF=BC=8C?= =?UTF-8?q?=E9=99=90=E5=88=B6chuliid=E6=9C=80=E9=95=BF11=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit batch_20260710 超长导致762单全部失败;与客服手机号字段一致。 Co-authored-by: Cursor --- .../batch_approve_xq_merchant_refunds.py | 7 ++++--- orders/services/merchant_refund_approve.py | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/orders/management/commands/batch_approve_xq_merchant_refunds.py b/orders/management/commands/batch_approve_xq_merchant_refunds.py index affb600..fc94764 100644 --- a/orders/management/commands/batch_approve_xq_merchant_refunds.py +++ b/orders/management/commands/batch_approve_xq_merchant_refunds.py @@ -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']) diff --git a/orders/services/merchant_refund_approve.py b/orders/services/merchant_refund_approve.py index d17006a..08958a8 100644 --- a/orders/services/merchant_refund_approve.py +++ b/orders/services/merchant_refund_approve.py @@ -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)')