ai客服
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
6.0 KiB

1 month ago
  1. with open('/Users/getmind/ds/kf/erp_automation.py', 'r') as f:
  2. lines = f.readlines()
  3. insert_idx = -1
  4. for i, line in enumerate(lines):
  5. if "✅ 已付款待审核订单处理完成" in line:
  6. insert_idx = i + 1
  7. break
  8. new_block = """
  9. # E7: 点击转正常单
  10. print(" -> 点击'转正常单'...")
  11. unquestion_clicked = False
  12. for frame in page.frames:
  13. try:
  14. btn = frame.locator("span#UnQuestions:has-text('转正常单'), span._jt_tool:has-text('转正常单')").first
  15. if btn.count() > 0 and btn.is_visible():
  16. btn.click(force=True, timeout=3000)
  17. time.sleep(1)
  18. print(" ✅ 已点击'转正常单'")
  19. unquestion_clicked = True
  20. break
  21. except:
  22. continue
  23. if not unquestion_clicked:
  24. print(" ⚠️ 未找到'转正常单'按钮。")
  25. time.sleep(2)
  26. # 处理转正常单可能的提示弹窗(比如只有异常单才可以转正常单的提示)
  27. close_msg_dialog("转正常单结果提示")
  28. time.sleep(1)
  29. # E8: 设快递
  30. print(" -> 点击'设快递'...")
  31. kuaidi_clicked = False
  32. for frame in page.frames:
  33. try:
  34. btn = frame.locator("span._db_txt:text-is('设快递'), span:text-is('设快递')").first
  35. if btn.count() > 0 and btn.is_visible():
  36. btn.click(force=True, timeout=3000)
  37. time.sleep(1)
  38. print(" ✅ 已点击'设快递'")
  39. kuaidi_clicked = True
  40. break
  41. except:
  42. continue
  43. if not kuaidi_clicked:
  44. print(" ⚠️ 未找到'设快递'按钮。")
  45. time.sleep(2)
  46. if kuaidi_clicked:
  47. print(" -> 选择'让系统自动计算'...")
  48. sys_selected = False
  49. for frame in page.frames:
  50. try:
  51. radio = frame.locator("input#SYS[name='lc']").first
  52. if radio.count() > 0:
  53. radio.click(force=True, timeout=3000)
  54. time.sleep(1)
  55. print(" ✅ 已选择'让系统自动计算'")
  56. sys_selected = True
  57. break
  58. except:
  59. continue
  60. if not sys_selected:
  61. # 兜底通过 label 点击
  62. for frame in page.frames:
  63. try:
  64. lbl = frame.locator("label[for='SYS']").first
  65. if lbl.count() > 0:
  66. lbl.click(force=True, timeout=3000)
  67. time.sleep(1)
  68. print(" ✅ 已选择'让系统自动计算' (通过 label)。")
  69. sys_selected = True
  70. break
  71. except:
  72. continue
  73. if not sys_selected:
  74. print(" ⚠️ 未找到'让系统自动计算'选项。")
  75. time.sleep(1)
  76. # 点击设快递的确认按钮(可能有2次)
  77. for confirm_round in range(2):
  78. print(f" -> 点击确认设快递 (第{confirm_round+1}次)...")
  79. time.sleep(2)
  80. click_confirmed = False
  81. for frame in page.frames:
  82. if click_confirmed:
  83. break
  84. try:
  85. # 优先找 input#confirm_confirm, span#confirmBtn
  86. btn = frame.locator("input#confirm_confirm, span#confirmBtn, .layui-layer-btn0, a:text-is('确定'), button:text-is('确定')").first
  87. if btn.count() > 0:
  88. btn.click(force=True, timeout=3000)
  89. time.sleep(1)
  90. print(f" ✅ 已点击确认按钮 (第{confirm_round+1}次)。")
  91. click_confirmed = True
  92. except:
  93. continue
  94. if not click_confirmed:
  95. print(f" ℹ️ 第{confirm_round+1}次确认弹窗未出现。")
  96. break
  97. time.sleep(2)
  98. # 处理设快递可能出现的成功提示弹窗
  99. close_msg_dialog("设快递结果提示")
  100. time.sleep(1)
  101. # E9: 审核
  102. print(" -> 点击'审核'...")
  103. audit_clicked = False
  104. for frame in page.frames:
  105. try:
  106. # class 包含 ding_db_txt 且文本为 审核
  107. btn = frame.locator("span.ding_db_txt:has-text('审核'), span:text-is('审核')").first
  108. if btn.count() > 0 and btn.is_visible():
  109. btn.click(force=True, timeout=3000)
  110. time.sleep(1)
  111. print(" ✅ 已点击'审核'")
  112. audit_clicked = True
  113. break
  114. except:
  115. continue
  116. if not audit_clicked:
  117. print(" ⚠️ 未找到'审核'按钮。")
  118. time.sleep(2)
  119. # 处理审核结果弹窗
  120. close_msg_dialog("审核结果提示")
  121. """
  122. lines = lines[:insert_idx] + [new_block] + lines[insert_idx:]
  123. with open('/Users/getmind/ds/kf/erp_automation.py', 'w') as f:
  124. f.writelines(lines)