submit_goods_audit.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. class SubmitGoodsAuditTool:
  2. name = 'submit_goods_audit'
  3. route_path = '/mcp/tools/submitGoodsAudit'
  4. STATUSES = ('30', '-10', '25')
  5. def __init__(self, api_client=None):
  6. self.api_client = api_client
  7. def metadata(self):
  8. return {
  9. 'name': self.name,
  10. 'description': (
  11. '使用场景:用户已经看过 open_goods_audit 返回的审核单,并确认结果后调用。'
  12. '一次只提交一条。字段名和嵌套与打开时的审核单相同。'
  13. '审核通过交齐清关信息;审核驳回交驳回类型和驳回原因;'
  14. '预审通过交备注和商品标记。'
  15. '参考、可选项名单和编码旁边的税率提示可以原样带上,服务端会丢掉。'
  16. '禁止使用:把这次记成系统审核,改写操作日志,批量审核,或未打开审核单就猜测字段。'
  17. '参数只用于工具内部调用;最终回答只能展示中文业务名称。'
  18. ),
  19. 'input_schema': self._schema(),
  20. }
  21. def call(self, goods_id, status, request_id='rq_submit_goods_audit', **extra):
  22. if self.api_client is None:
  23. raise RuntimeError('api client is required for submit_goods_audit')
  24. if not isinstance(goods_id, int) or isinstance(goods_id, bool) or goods_id < 1:
  25. raise ValueError('goods_id is invalid')
  26. status_text = str(status)
  27. if status_text not in self.STATUSES:
  28. raise ValueError('status is invalid')
  29. payload = dict(extra)
  30. payload['goods_id'] = goods_id
  31. payload['status'] = status_text
  32. return self.api_client.call_tool(
  33. self.name, self.route_path, payload, request_id,
  34. )
  35. def _schema(self):
  36. text = {'type': 'string'}
  37. row = {
  38. 'type': 'object',
  39. 'properties': {
  40. 'clearance_hscode': text,
  41. 'material': text,
  42. 'material_ratio': text,
  43. 'kit_hscode': text,
  44. 'adjust_hscode_data': {
  45. 'type': 'array',
  46. 'items': text,
  47. },
  48. 'tax_rate': text,
  49. 'extra_tax': text,
  50. 'is_new_hscode': {'type': 'string', 'enum': ['是', '否']},
  51. 'kit_tax_rate': text,
  52. },
  53. 'required': [
  54. 'clearance_hscode', 'material', 'material_ratio',
  55. 'kit_hscode', 'adjust_hscode_data',
  56. ],
  57. 'additionalProperties': False,
  58. }
  59. attr = {
  60. 'type': 'object',
  61. 'properties': {
  62. key: {'type': 'boolean'}
  63. for key in (
  64. 'is_battery', 'is_magnetic', 'is_wood', 'is_other', 'is_fda',
  65. 'is_toy', 'is_ultra_limit', 'is_sensitive', 'is_food',
  66. )
  67. },
  68. 'required': [
  69. 'is_battery', 'is_magnetic', 'is_wood', 'is_other', 'is_fda',
  70. 'is_toy', 'is_ultra_limit', 'is_sensitive', 'is_food',
  71. ],
  72. 'additionalProperties': False,
  73. }
  74. return {
  75. 'type': 'object',
  76. 'properties': {
  77. 'goods_id': {
  78. 'type': 'integer',
  79. 'minimum': 1,
  80. 'description': '商品编号。',
  81. },
  82. 'goods_clearance_id': {
  83. 'type': 'string',
  84. 'description': '这条商品自己的清关记录编号。审核通过时要带上。',
  85. },
  86. 'status': {
  87. 'type': 'string',
  88. 'enum': list(self.STATUSES),
  89. 'description': '30 审核通过,-10 审核驳回,25 预审通过。',
  90. },
  91. 'audit_result': text,
  92. 'select_result': text,
  93. 'category_ids': text,
  94. 'shipping_method': text,
  95. 'goods_type': text,
  96. 'goods_category_id': text,
  97. 'goods_attr': attr,
  98. 'is_inspection_fee': text,
  99. 'is_fda_declaration': text,
  100. 'is_epa_declaration': text,
  101. 'is_act_declaration': text,
  102. 'is_dot_declaration': text,
  103. 'is_cpsc_declaration': text,
  104. 'product_surcharge': text,
  105. 'tax_surcharge': text,
  106. 'yf_cn_goodsname': text,
  107. 'yf_en_goodsname': text,
  108. 'yf_clearance_price': text,
  109. 'ys_clearance_price': text,
  110. 'yf_clearance_data': {'type': 'array', 'items': row},
  111. 'ys_clearance_data': {'type': 'array', 'items': row},
  112. 'sync_order_ids': text,
  113. 'options': {'type': 'object'},
  114. 'reference': {'type': 'object'},
  115. },
  116. 'required': ['goods_id', 'status'],
  117. 'additionalProperties': False,
  118. }