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)')