submit_goods_audit.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. '用商品编号定位,商品编号就是审核页上的 SKU,不是内部商品 ID。'
  13. '同一个商品编号有多条时,带上和打开时相同的起运国、目的国。'
  14. '一次只提交一条。审核单字段名和嵌套与打开时相同。'
  15. '审核通过交齐清关信息;审核驳回交驳回类型和驳回原因;'
  16. '预审通过交备注和商品标记。'
  17. '参考、可选项名单和编码旁边的税率提示可以原样带上,服务端会丢掉。'
  18. '禁止使用:把这次记成系统审核,改写操作日志,批量审核,或未打开审核单就猜测字段。'
  19. '参数只用于工具内部调用;最终回答只能展示中文业务名称。'
  20. ),
  21. 'input_schema': self._schema(),
  22. }
  23. def call(
  24. self,
  25. sku='',
  26. status=None,
  27. departure_country='',
  28. destination_country='',
  29. request_id='rq_submit_goods_audit',
  30. **extra,
  31. ):
  32. if self.api_client is None:
  33. raise RuntimeError('api client is required for submit_goods_audit')
  34. status_text = str(status)
  35. if status_text not in self.STATUSES:
  36. raise ValueError('status is invalid')
  37. payload = dict(extra)
  38. payload['sku'] = self._text(sku)
  39. payload['status'] = status_text
  40. if departure_country:
  41. payload['departure_country'] = self._text(departure_country)
  42. if destination_country:
  43. payload['destination_country'] = self._text(destination_country)
  44. return self.api_client.call_tool(
  45. self.name, self.route_path, payload, request_id,
  46. )
  47. @staticmethod
  48. def _text(value):
  49. if not isinstance(value, str):
  50. raise ValueError('sku is invalid')
  51. text = value.strip()
  52. if not text or len(text) > 200:
  53. raise ValueError('sku is invalid')
  54. return text
  55. def _schema(self):
  56. text = {'type': 'string'}
  57. row = {
  58. 'type': 'object',
  59. 'properties': {
  60. 'clearance_hscode': text,
  61. 'material': text,
  62. 'material_ratio': text,
  63. 'kit_hscode': text,
  64. 'adjust_hscode_data': {
  65. 'type': 'array',
  66. 'items': text,
  67. },
  68. 'tax_rate': text,
  69. 'extra_tax': text,
  70. 'is_new_hscode': {'type': 'string', 'enum': ['是', '否']},
  71. 'kit_tax_rate': text,
  72. },
  73. 'required': [
  74. 'clearance_hscode', 'material', 'material_ratio',
  75. 'kit_hscode', 'adjust_hscode_data',
  76. ],
  77. 'additionalProperties': False,
  78. }
  79. attr = {
  80. 'type': 'object',
  81. 'properties': {
  82. key: {'type': 'boolean'}
  83. for key in (
  84. 'is_battery', 'is_magnetic', 'is_wood', 'is_other', 'is_fda',
  85. 'is_toy', 'is_ultra_limit', 'is_sensitive', 'is_food',
  86. )
  87. },
  88. 'required': [
  89. 'is_battery', 'is_magnetic', 'is_wood', 'is_other', 'is_fda',
  90. 'is_toy', 'is_ultra_limit', 'is_sensitive', 'is_food',
  91. ],
  92. 'additionalProperties': False,
  93. }
  94. return {
  95. 'type': 'object',
  96. 'properties': {
  97. 'sku': {
  98. 'type': 'string',
  99. 'minLength': 1,
  100. 'maxLength': 200,
  101. 'description': '商品编号,即审核页上的 SKU。',
  102. },
  103. 'departure_country': {
  104. 'type': 'string',
  105. 'maxLength': 100,
  106. 'description': '起运国,与打开审核单时相同。',
  107. },
  108. 'destination_country': {
  109. 'type': 'string',
  110. 'maxLength': 100,
  111. 'description': '目的国,与打开审核单时相同。',
  112. },
  113. 'goods_id': {
  114. 'type': 'integer',
  115. 'minimum': 1,
  116. 'description': '打开审核单后带出的内部编号。不要向用户索取。',
  117. },
  118. 'goods_clearance_id': {
  119. 'type': 'string',
  120. 'description': '这条商品自己的清关记录编号。审核通过时要带上。',
  121. },
  122. 'status': {
  123. 'type': 'string',
  124. 'enum': list(self.STATUSES),
  125. 'description': '30 审核通过,-10 审核驳回,25 预审通过。',
  126. },
  127. 'audit_result': text,
  128. 'select_result': text,
  129. 'category_ids': text,
  130. 'shipping_method': text,
  131. 'goods_type': text,
  132. 'goods_category_id': text,
  133. 'goods_attr': attr,
  134. 'is_inspection_fee': text,
  135. 'is_fda_declaration': text,
  136. 'is_epa_declaration': text,
  137. 'is_act_declaration': text,
  138. 'is_dot_declaration': text,
  139. 'is_cpsc_declaration': text,
  140. 'product_surcharge': text,
  141. 'tax_surcharge': text,
  142. 'yf_cn_goodsname': text,
  143. 'yf_en_goodsname': text,
  144. 'yf_clearance_price': text,
  145. 'ys_clearance_price': text,
  146. 'yf_clearance_data': {'type': 'array', 'items': row},
  147. 'ys_clearance_data': {'type': 'array', 'items': row},
  148. 'sync_order_ids': text,
  149. 'options': {'type': 'object'},
  150. 'reference': {'type': 'object'},
  151. },
  152. 'required': ['sku', 'status'],
  153. 'additionalProperties': False,
  154. }