客户信息删除代码更新
This commit is contained in:
@@ -59,7 +59,7 @@ def delete_history_background(data: Dict[str, Any], cookies: Dict[str, str], org
|
||||
print('表单已自动提交至下一步')
|
||||
|
||||
|
||||
def delete_customer_background(data: Dict[str, Any], cookies: Dict[str, str], json_data: List[Dict[str, Any]]):
|
||||
def delete_customer_background(data: Dict[str, Any], cookies: Dict[str, str], total:int ):
|
||||
"""
|
||||
删除客户信息后台任务
|
||||
|
||||
@@ -78,9 +78,18 @@ def delete_customer_background(data: Dict[str, Any], cookies: Dict[str, str], js
|
||||
- 8-20点之间每3.5秒删除一条数据,其余时间每1.5秒删除一条数据
|
||||
- 执行结果会更新到简道云表单
|
||||
"""
|
||||
print('开始删除客户信息')
|
||||
success = 0
|
||||
fail = 0
|
||||
|
||||
|
||||
json_data = []
|
||||
total_page = total // 100 + (total % 100 > 0)
|
||||
for page in tqdm(range(1, total_page + 1)):
|
||||
url = f"https://yunxiu.f6car.cn/member/customer/listForPermission?pageSize=100&pageNo={page}"
|
||||
res = requests.get(url, cookies=cookies)
|
||||
json_data.extend(res.json().get('data', {}).get('data',[]))
|
||||
|
||||
# 获取门店ID
|
||||
operate_org_id = get_operate_org_id(cookies)
|
||||
if not operate_org_id:
|
||||
@@ -109,21 +118,56 @@ def delete_customer_background(data: Dict[str, Any], cookies: Dict[str, str], js
|
||||
|
||||
try:
|
||||
url = f"https://yunxiu.f6car.cn/member/customer/{id_customer}" # 客户信息删除url
|
||||
res = requests.delete(url, cookies=cookies) # 客户信息删除
|
||||
res_data = res.json()
|
||||
if res_data.get('success'):
|
||||
res = requests.delete(url, cookies=cookies, timeout=10) # 客户信息删除
|
||||
|
||||
# 检查HTTP状态码
|
||||
if res.status_code != 200:
|
||||
fail += 1
|
||||
error_msg = f"HTTP状态码错误: {res.status_code}"
|
||||
logger.error(f"客户删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
print(f"删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
time.sleep(0.2)
|
||||
continue
|
||||
|
||||
# 解析响应数据
|
||||
try:
|
||||
res_data = res.json()
|
||||
except ValueError as json_error:
|
||||
fail += 1
|
||||
error_msg = f"响应不是有效的JSON格式: {json_error}, 响应内容: {res.text[:200]}"
|
||||
logger.error(f"客户删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
print(f"删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
time.sleep(0.2)
|
||||
continue
|
||||
|
||||
# 检查多种可能的成功标识
|
||||
# 有些API返回 success 字段,有些返回 code=200,有些返回 data 字段
|
||||
is_success = (
|
||||
res_data.get('success') is True or
|
||||
res_data.get('code') == 200 or
|
||||
(res_data.get('code') is None and res_data.get('data') is not None)
|
||||
)
|
||||
|
||||
if is_success:
|
||||
success += 1
|
||||
logger.info(f"客户删除成功: ID={id_customer}, 手机号={phone}")
|
||||
else:
|
||||
fail += 1
|
||||
logger.error(f"客户删除失败: ID={id_customer}, 手机号={phone}, 错误信息: {res_data.get('message')}")
|
||||
error_msg = res_data.get('message') or res_data.get('msg') or '未知错误'
|
||||
error_detail = f"错误信息: {error_msg}, 完整响应: {res_data}"
|
||||
logger.error(f"客户删除失败: ID={id_customer}, 手机号={phone}, {error_detail}")
|
||||
print(f"删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
time.sleep(0.2)
|
||||
except requests.exceptions.RequestException as e:
|
||||
fail += 1
|
||||
error_msg = f"网络请求异常: {str(e)}"
|
||||
print(f"删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
logger.error(f"删除客户时发生网络错误: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
except Exception as e:
|
||||
fail += 1
|
||||
print("删除失败,", item, id_customer, phone, e)
|
||||
logger.error(f"删除客户时发生错误: ID={id_customer}, 手机号={phone}, 错误信息: {e}")
|
||||
if success + fail < len(json_data):
|
||||
continue
|
||||
error_msg = f"未知错误: {str(e)}"
|
||||
print(f"删除失败: ID={id_customer}, 手机号={phone}, {error_msg}")
|
||||
logger.error(f"删除客户时发生错误: ID={id_customer}, 手机号={phone}, {error_msg}", exc_info=True)
|
||||
|
||||
now = datetime.now()
|
||||
if 8 <= now.hour <= 20:
|
||||
|
||||
Reference in New Issue
Block a user