579 lines
25 KiB
Python
579 lines
25 KiB
Python
# 基础函数配置
|
|
import pandas as pd
|
|
import pandas as pd
|
|
import requests
|
|
from pathlib import Path
|
|
from urllib.parse import quote
|
|
import json
|
|
import numpy as np
|
|
import time
|
|
from datetime import date, timedelta
|
|
|
|
ROOT = Path('.').absolute() # 当前工作目录
|
|
|
|
def generateToken() -> str:
|
|
""" 生成 token """
|
|
|
|
token_api = 'https://api.dingtalk.com/v1.0/oauth2/accessToken'
|
|
|
|
# 该信息在钉钉开放应用中
|
|
data = {
|
|
"appKey": "ding5kqocon5s9oph5uq",
|
|
"appSecret": 'HL1jgsIIfLAC0eTH0A1m4mwxUDqbgsiPeCCGGE3ocM6qJBTIW7Ivt9drxF_Z4Kb_'
|
|
}
|
|
|
|
res = requests.post(token_api, json=data)
|
|
token = res.json()['accessToken']
|
|
|
|
return token
|
|
|
|
def transcation(token,FORMID,data_new):
|
|
""" 函数功能:更新表单内容 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
payload = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "2268275546837446", # 曹伟 id
|
|
"language" : "zh_CN",
|
|
"useLatestVersion" : "false",
|
|
"formInstanceId" : FORMID,
|
|
"updateFormDataJson" : json.dumps(data_new, cls=NpEncoder),
|
|
}
|
|
|
|
res = requests.put(api, headers=headers, json=payload)
|
|
|
|
return res.json()
|
|
def aggree_approval(token: str, taskId: str, processInstanceId: str, formData: dict,res_new):
|
|
""" 函数功能:同意审批节点 --F6客户服务 应用 """
|
|
api = f'https://api.dingtalk.com/v1.0/yida/tasks/execute'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
payload = {
|
|
"outResult": "AGREE",
|
|
"appType": "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken": "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"remark": "同意(接口自动)",
|
|
"formDataJson": json.dumps(formData, cls=NpEncoder),
|
|
"processInstanceId": processInstanceId,
|
|
# "userId": "yida_pub_account",
|
|
"userId": res_new,
|
|
"language": "zh_CN",
|
|
"taskId": int(taskId)
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
# print('同意审批节点')
|
|
return res
|
|
def read_instances_new(token, formUuid, page, n):
|
|
""" 函数功能:读取流程表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/processes/instances?pageNumber={page}&pageSize={n}'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType": "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken": "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId": "yida_pub_account", # 超级管理员账号
|
|
"language": "zh_CN",
|
|
"formUuid": formUuid,
|
|
# "searchFieldJson": json.dumps(searchField), # 如果增加上这一项会要求升级宜搭存储
|
|
"instanceStatus": "RUNNING"
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def get_approval_records(token: str, processInstanceId: str):
|
|
""" 函数功能:获取流程表单的审批记录 --F6客户服务 应用 """
|
|
appType = "APP_UYZ0KG6L0CCNV80GZ66O"
|
|
systemToken = "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2"
|
|
userId = "yida_pub_account"
|
|
|
|
api = f'https://api.dingtalk.com/v1.0/yida/processes/operationRecords?appType={appType}&systemToken={systemToken}&userId={userId}&language=zh_CN&processInstanceId={processInstanceId}'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
res = requests.get(api, headers=headers)
|
|
# print('获取流程表单的审批记录')
|
|
return res.json()
|
|
def read_instances(token, formUuid, page, n):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "yida_pub_account",
|
|
"language" : "zh_CN",
|
|
"formUuid" : formUuid,
|
|
"currentPage" : page,
|
|
"pageSize" : n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def read_instances_pt(token, formUuid, page, n):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "yida_pub_account",
|
|
"language" : "zh_CN",
|
|
"formUuid" : formUuid,
|
|
"currentPage" : page,
|
|
"pageSize" : n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def read_processes(token, formUuid, page, n):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType": "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken": "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId": "yida_pub_account", # 超级管理员账号
|
|
"language": "zh_CN",
|
|
"formUuid": formUuid,
|
|
'currentPage':page,
|
|
'pageSize':n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def instances_id(TOKEN,id):
|
|
""" 函数功能:查询表单实例 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/{id}?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=yida_pub_account&language=zh_CN'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
|
|
res = requests.get(api, headers=headers)
|
|
|
|
return res.json()
|
|
def component(FORMID,TOKEN):
|
|
""" 获取组件信息 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/formFields'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
# "formDataJson" : json.dumps(formData, cls=NpEncoder),
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
# "language" : "zh_CN",
|
|
"userId" : "yida_pub_account"
|
|
}
|
|
|
|
res = requests.get(api, headers=headers, json=payload)
|
|
|
|
return res.json()
|
|
def component_id(id,TOKEN):
|
|
api = f'https://api.dingtalk.com/v1.0/yida/processes/instancesInfos/{id}?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=yida_pub_account&language=zh_CN'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
|
|
res = requests.get(api, headers=headers)
|
|
|
|
return res.json()
|
|
def find_indexes(daichuli_mendian_name,i_two):
|
|
indexes = [i for i, x in enumerate(daichuli_mendian_name) if x == i_two]
|
|
return indexes
|
|
def get_staffID(TOKEN: str,ALL_DATA_staff,staff_name):
|
|
res_new = [v['formData']['textField_lfrw3u59'] for v in ALL_DATA_staff if v['formData']['textField_lfrw3u58']== staff_name]
|
|
# print('通过员工名称获取员工id')
|
|
return res_new
|
|
|
|
def component(FORMID,TOKEN):
|
|
""" 获取组件信息 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/formFields'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
# "formDataJson" : json.dumps(formData, cls=NpEncoder),
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
# "language" : "zh_CN",
|
|
"userId" : "yida_pub_account"
|
|
}
|
|
|
|
res = requests.get(api, headers=headers, json=payload)
|
|
|
|
return res.json()
|
|
def delete_in_batches(FORMID,TOKEN,ALL_DATA_instance):
|
|
""" 批量删除表单实例 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/batchRemove'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
|
|
payload = {
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"asynchronousExecution" : "true",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"formInstanceIdList" : json.dumps(ALL_DATA_instance, cls=NpEncoder),
|
|
"userId" : "yida_pub_account",
|
|
"executeExpression" : "false" # 不触发
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
return res.json()
|
|
def delete_in(TOKEN,formInstanceIdList):
|
|
""" 逐条删除表单实例 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances?appType=APP_UYZ0KG6L0CCNV80GZ66O&systemToken=XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2&userId=yida_pub_account&language=zh_CN&formInstanceId={formInstanceIdList}'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
res = requests.delete(api, headers=headers)
|
|
return res.json()
|
|
def Batch_creation(FORMID,TOKEN,ALL_formData):
|
|
""" 获取组件信息 """
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/batchSave'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": TOKEN
|
|
}
|
|
payload = {
|
|
# "formDataJson" : json.dumps(formData, cls=NpEncoder),
|
|
"noExecuteExpression" : "false",
|
|
"formUuid" : FORMID,
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"asynchronousExecution" : "false",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"keepRunningAfterException" : "false",
|
|
"userId" : "2268275546837446",
|
|
"formDataJsonList" : json.dumps(ALL_formData, cls=NpEncoder),
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=payload)
|
|
return res.json()
|
|
# 基础函数配置
|
|
import pandas as pd
|
|
import pandas as pd
|
|
import requests
|
|
from pathlib import Path
|
|
from urllib.parse import quote
|
|
import json
|
|
import numpy as np
|
|
import time
|
|
from datetime import date, timedelta
|
|
|
|
ROOT = Path('.').absolute() # 当前工作目录
|
|
|
|
def generateToken() -> str:
|
|
""" 生成 token """
|
|
|
|
token_api = 'https://api.dingtalk.com/v1.0/oauth2/accessToken'
|
|
|
|
# 该信息在钉钉开放应用中
|
|
data = {
|
|
"appKey": "ding5kqocon5s9oph5uq",
|
|
"appSecret": 'HL1jgsIIfLAC0eTH0A1m4mwxUDqbgsiPeCCGGE3ocM6qJBTIW7Ivt9drxF_Z4Kb_'
|
|
}
|
|
|
|
res = requests.post(token_api, json=data)
|
|
token = res.json()['accessToken']
|
|
|
|
return token
|
|
def read_instances(token, formUuid, page, n,searchFieldJson):
|
|
""" 函数功能:读取普通表单的所有数据 """
|
|
|
|
api = f'https://api.dingtalk.com//v1.0/yida/forms/instances/search'
|
|
|
|
headers = {
|
|
"Content-Type": "application/json",
|
|
"x-acs-dingtalk-access-token": token
|
|
}
|
|
|
|
formData = {
|
|
"appType" : "APP_UYZ0KG6L0CCNV80GZ66O",
|
|
"systemToken" : "XA966F81JAJOFCVVVKO64E9MIIZV1EWE5SFMKJ2",
|
|
"userId" : "yida_pub_account",
|
|
"language" : "zh_CN",
|
|
"formUuid" : formUuid,
|
|
"currentPage" : page,
|
|
"searchFieldJson":json.dumps(searchFieldJson),
|
|
"pageSize" : n
|
|
}
|
|
|
|
res = requests.post(api, headers=headers, json=formData)
|
|
return res.json()
|
|
def split(x):
|
|
try:
|
|
x = x[0].split("(")[0]
|
|
except:
|
|
pass
|
|
return x
|
|
def strftime(x):
|
|
try:
|
|
timestamp = int(x) / 1000 # 将毫秒转换为秒
|
|
dt_object = datetime.fromtimestamp(timestamp)
|
|
formatted_date = dt_object.strftime("%Y-%m-%d")
|
|
except:
|
|
pass
|
|
return formatted_date
|
|
class NpEncoder(json.JSONEncoder):
|
|
def default(self, obj):
|
|
if isinstance(obj, np.integer):
|
|
return int(obj)
|
|
elif isinstance(obj, np.floating):
|
|
return float(obj)
|
|
elif isinstance(obj, np.ndarray):
|
|
return obj.tolist()
|
|
else:
|
|
return super(NpEncoder, self).default(obj)
|
|
|
|
from datetime import datetime
|
|
import datetime
|
|
now_time = datetime.datetime.now()
|
|
today = now_time + datetime.timedelta(days=-1)
|
|
formatted_today = now_time.strftime("%Y%m%d")
|
|
formatted_today_two = today.strftime("%Y%m01")
|
|
formatted_today_one = today.strftime("%Y-%m")
|
|
now_time = datetime.datetime.now()
|
|
yes_time = now_time + datetime.timedelta(days=-1)
|
|
yes_time_nyr = int(yes_time.strftime('%Y%m'))# 获取前一月
|
|
from datetime import datetime
|
|
TOKEN = generateToken()
|
|
json_data = []
|
|
# formatted_today_two = 20230801
|
|
# formatted_today = 20230901
|
|
# formatted_today_one = "2023-08"
|
|
# yes_time_nyr = 202308
|
|
for formatted in range(int(formatted_today_two),int(formatted_today)):
|
|
searchFieldJson = {"textField_xgaye7b":str(formatted)}
|
|
read_data = read_instances(TOKEN, "FORM-GP666M71TNE9GFK57V2O85NLM04I34CSG1TFLC", 1, 100,searchFieldJson)
|
|
PAGES = read_data.get('totalCount')//100 + 1
|
|
print(formatted,read_data.get('totalCount'))
|
|
for a in range(1,PAGES + 1):
|
|
read_data = read_instances(TOKEN, "FORM-GP666M71TNE9GFK57V2O85NLM04I34CSG1TFLC", a, 100,searchFieldJson)
|
|
for i in range(0,len(read_data["data"])):
|
|
json_data.append(read_data["data"][i]['formData'])
|
|
# ALL_read_data.append(read_data["data"][i]['formData'])
|
|
# data_F6.loc[len(data_F6.index)] = read_data["data"][i]['formData']
|
|
data_F6 = pd.DataFrame(json_data)
|
|
data_F6.rename(columns={'textField_j9ljlkf': 'commission_type_1st', 'textField_b0zcpw7': 'commission_type_2nd', 'employeeField_lft1hn2e': 'to_grant_person_X', 'textField_lld2doy7': 'franchise_group_name', 'textField_gkzyime': 'saas_edition_fmt', 'numberField_7soucf9': 'order_trade_amount', 'numberField_vbubqg5': 'amount_real_base', 'dateField_dezcysa': 'pay_date_X', 'textField_9solcme': 'business_type', 'employeeField_lft1hn2f': 'area_manager_X'}, inplace=True)
|
|
data_F6["to_grant_person"] = [split(x) for x in data_F6["to_grant_person_X"]]
|
|
data_F6["area_manager"] = [split(x) for x in data_F6["area_manager_X"]]
|
|
data_F6["pay_date"] = [strftime(x) for x in data_F6["pay_date_X"]]
|
|
data_F6 = data_F6.loc[data_F6["commission_type_1st"] != "续约"]
|
|
data_F6 = data_F6.loc[~data_F6["commission_type_2nd"].isin(["介绍","企业钱包","培训","数据处理","企业钱包新签"])]
|
|
data_F6 = data_F6.loc[~data_F6["to_grant_person"].isin(["孙玉蕾","何钊","金鹏","周聪","武宏超","孙旭亮","刘立","刘光春","时建飞","魏子淇","侯斌","陈博","邹存威","金华斌","吴间锐","崔智杰","黄宗祥","杨挺","霍创业","周鹏飞","邢恒岭","王斌","申晓勇","殷昊","李子晗","肖军"])]
|
|
data_F6 = data_F6.reset_index()
|
|
for i in range(0,len(data_F6)):
|
|
# if data_F6.loc[i,'franchise_group_name']=="修工坊全国运营中心" or data_F6.loc[i,'franchise_group_name']=="CC养车" or data_F6.loc[i,'franchise_group_name']=="金铁橡全国运营中心":
|
|
# if data_F6.loc[i,'saas_edition_fmt'] == "基础版":
|
|
# data_F6.loc[i,'order_trade_amount'] = 500
|
|
# if data_F6.loc[i,'saas_edition_fmt'] == "尊享版":
|
|
# data_F6.loc[i,'order_trade_amount'] = 1500
|
|
# if data_F6.loc[i,'commission_type_1st']=="裂变红包":
|
|
# data_F6.loc[i,'order_trade_amount'] = data_F6.loc[i,'amount_real_base']
|
|
# if data_F6.loc[i,'business_type']=="活动广场":
|
|
# data_F6.loc[i,'order_trade_amount'] = data_F6.loc[i,'amount_real_base']
|
|
# data_F6.loc[i,'commission_type_1st'] = "裂变红包"
|
|
if data_F6.loc[i,'franchise_group_name']!="修工坊全国运营中心" and data_F6.loc[i,'franchise_group_name']!="CC养车" and data_F6.loc[i,'franchise_group_name']!="金铁橡全国运营中心" and data_F6.loc[i,'franchise_group_name']!="":
|
|
data_F6.loc[i,'franchise_group_name'] = ""
|
|
# 当月新签开户
|
|
# df_1 = data_F6.copy()
|
|
# df_1.fillna("", inplace=True)
|
|
# df_1['pay_date'] = df_1['pay_date'].str.slice(0, 4) + df_1['pay_date'].str.slice(5, 7)
|
|
# df_1['条件'] = (df_1['pay_date'] == str(yes_time_nyr)) & (df_1['business_type'] == '新签') & (df_1['franchise_group_name']== '')
|
|
# df_1 = df_1.loc[df_1["条件"] == True]
|
|
# df_1 = df_1.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
# df_1 = df_1.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '当月新签开户'})
|
|
# # 之前新签本月开户
|
|
# df_2 = data_F6.copy()
|
|
# df_2.fillna("", inplace=True)
|
|
# df_2['pay_date'] = df_2['pay_date'].str.slice(0, 4) + df_2['pay_date'].str.slice(5, 7)
|
|
# df_2['条件'] = (df_2['pay_date'] != str(yes_time_nyr)) & (df_2['business_type'] == '新签') & (df_2['franchise_group_name']== '')
|
|
# df_2 = df_2.loc[df_2["条件"] == True]
|
|
# df_2 = df_2.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
# df_2 = df_2.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '之前新签本月开户'})
|
|
# 过期召回
|
|
df_3 = data_F6.copy()
|
|
df_3 = df_3.loc[df_3["business_type"] == "过期召回"]
|
|
df_3 = df_3.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
df_3 = df_3.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '过期召回'})
|
|
# 首年升级
|
|
df_4 = data_F6.copy()
|
|
df_4 = df_4.loc[df_4["business_type"] == "首年升级"]
|
|
df_4 = df_4.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
df_4 = df_4.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '首年升级'})
|
|
# 短信
|
|
df_5 = data_F6.copy()
|
|
df_5 = df_5.loc[df_5["commission_type_2nd"] == "短信"]
|
|
df_5 = df_5.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
df_5 = df_5.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '短信'})
|
|
# 服务包
|
|
df_6 = data_F6.copy()
|
|
df_6 = df_6.loc[df_6["commission_type_2nd"] == "服务跟进"]
|
|
df_6 = df_6.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
df_6 = df_6.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '服务包'})
|
|
# 轻连锁金额
|
|
df_7 = data_F6.copy()
|
|
df_7['条件'] = (df_7['business_type'] == '新签') & (df_7["franchise_group_name"].isin(["金铁橡全国运营中心","CC养车","修工坊全国运营中心"]))
|
|
df_7 = df_7.loc[df_7["条件"] == True]
|
|
df_7 = df_7.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
df_7 = df_7.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '轻连锁金额'})
|
|
# 新签业绩(含轻连锁)
|
|
df_8 = data_F6.copy()
|
|
df_8 = df_8.groupby('to_grant_person')['order_trade_amount'].sum().reset_index()
|
|
df_8 = df_8.rename(columns={'to_grant_person': '小六', 'order_trade_amount': '新签业绩(含轻连锁)'})
|
|
# 战区经理
|
|
df_9 = data_F6.copy()
|
|
df_9 = df_9.drop_duplicates(subset='to_grant_person')
|
|
df_9 = df_9.rename(columns={'to_grant_person': '小六', 'area_manager': '战区经理'})
|
|
df_9 = df_9.loc[:, ['小六', '战区经理']]
|
|
# 红包裂变
|
|
df_10 = data_F6.copy()
|
|
df_10 = df_10.loc[df_10["commission_type_1st"] == "裂变红包"]
|
|
df_10 = df_10.groupby('to_grant_person')['amount_real_base'].sum().reset_index()
|
|
df_10 = df_10.rename(columns={'to_grant_person': '小六', 'amount_real_base': '裂变红包'})
|
|
# 合并内容信息
|
|
my_list = ['刘鑫烨','韩皞','韩磊帅','陈致欣','陈振龙','吕浩杰','潘志强','刘剑桥','许盼盼','柴铁峰','陈晨','郭锦城','陈俊','魏延楠','赵禄军','杨君毅','刘磊','梁柱','严冬延','胡楠','胡仲远','吴宏伟','范启超','邵宝振','李壮壮','丰文祥','王有军','贾宏伟','杜浩','舒晓明','胡冰','陈煜','张宏伟','赵旭伟','王兵帅','王鑫','王云梅','王蔚东','储召强','赵涛','申晨','孙振华','薛昌翔','宋小涛','郭波波','孟祥宇','郭文朔','陈超','李冉','黄环宇','朱宁']
|
|
df0 = pd.DataFrame(my_list, columns=['小六'])
|
|
merged_df = pd.merge(df0, df_1, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_2, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_3, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_4, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_5, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_6, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_7, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_8, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_9, on='小六', how='left')
|
|
merged_df = pd.merge(merged_df, df_10, on='小六', how='left')
|
|
|
|
|
|
# 使用reindex函数调整列的位置
|
|
merged_df = merged_df.reindex(columns=['小六','当月新签开户', '之前新签本月开户', '过期召回', '首年升级', '短信', '服务包', '轻连锁金额','裂变红包', '新签业绩(含轻连锁)', '战区经理','rank'])
|
|
merged_df = merged_df.fillna(0)
|
|
for i_name in ['当月新签开户', '之前新签本月开户', '过期召回', '首年升级', '短信', '服务包', '轻连锁金额','裂变红包', '新签业绩(含轻连锁)','rank']:
|
|
merged_df[i_name] = merged_df[i_name].astype(int)
|
|
# 删除小六列值为0的行
|
|
merged_df = merged_df[merged_df['小六'] != 0]
|
|
# 根据 score 字段为每个值分配一个排名
|
|
merged_df['rank'] = merged_df['新签业绩(含轻连锁)'].rank(ascending=False)
|
|
merged_df = merged_df.sort_values(by='rank', ascending=True)
|
|
merged_df = merged_df.reset_index()
|
|
merged_df.drop('index', axis=1, inplace=True)
|
|
|
|
TOKEN = generateToken()
|
|
'''读取员工对应关系:宜搭员工-ID对应表 '''
|
|
FORMID = "FORM-EA866E715PF9YA7ECCAGSABX91Q72PVA3WRFL6" # 宜搭员工-ID对应表 FORM-EA866E715PF9YA7ECCAGSABX91Q72PVA3WRFL6
|
|
# 读取流程表单数据
|
|
form_data = read_instances_pt(token=TOKEN, formUuid=FORMID, page=1, n=100)
|
|
PAGES = form_data.get('totalCount')//100 + 1
|
|
ALL_DATA_staff = {}
|
|
""" 获取全量数据 """
|
|
for i in range(1, PAGES+1):
|
|
# form_data = read_processes_instances(token=TOKEN, formUuid=FORMID, createFromTimeGMT=CREATE_FROM, createToTimeGMT=CREATE_TO, page=i, n=100, searchField={'textField_l7if5ff9': '否'})
|
|
form_data = read_instances_pt(token=TOKEN, formUuid=FORMID, page=i, n=100)
|
|
for data in form_data.get('data'):
|
|
ALL_DATA_staff[data['formData']['textField_lfrw3u58']]=data['formData']['textField_lfrw3u59']
|
|
|
|
'''批量删除小六提成明细_看板数据'''
|
|
for i in range(0,10):
|
|
default = True
|
|
while default:
|
|
FORMID = "FORM-UP9663719GYD8IA6CS8T4BIX1VZ02MZ6II4ML3"
|
|
form_data = read_instances_pt(token=TOKEN, formUuid=FORMID, page=1, n=100)
|
|
PAGES = form_data.get('totalCount')//100 +1
|
|
print(form_data.get('totalCount'))
|
|
if form_data.get('totalCount')<=0:
|
|
default = False
|
|
for i in range(PAGES, 1,-1):
|
|
ALL_DATA_instance = []
|
|
form_data = read_instances_pt(token=TOKEN, formUuid=FORMID, page=1, n=100)
|
|
for data in form_data.get('data'):
|
|
ALL_DATA_instance.append(data['formInstanceId'])
|
|
print(f'读取到表单中 {len(ALL_DATA_instance)} 条数据!')
|
|
red_delete = delete_in_batches(FORMID,TOKEN,ALL_DATA_instance)
|
|
form_data = read_instances_pt(token=TOKEN, formUuid=FORMID, page=1, n=100)
|
|
for data in form_data.get('data'):
|
|
formInstanceId = data['formInstanceId']
|
|
delete_in(TOKEN,formInstanceId)
|
|
print(f'单条删除 {formInstanceId} 数据!')
|
|
# 遍历数据进行新建
|
|
for i in range(0,len(merged_df["小六"])):
|
|
# 获取主店联系人和主店联系电话
|
|
ALL_formData = []
|
|
formData = {
|
|
'employeeField_lm067t8w':ALL_DATA_staff[merged_df["小六"][i]],#"小六"
|
|
'textField_njdb6oy':merged_df["当月新签开户"][i],#"当月新签开户"
|
|
'textField_zg4ptq6':merged_df["之前新签本月开户"][i],#"之前新签本月开户"
|
|
'textField_d8uep3s':merged_df["过期召回"][i],#"过期召回"
|
|
'textField_kv9fb8l':merged_df["首年升级"][i],#"首年升级"
|
|
'textField_1b34971':merged_df["短信"][i],#"短信"
|
|
'textField_cds6efy':merged_df["服务包"][i],#"服务包"
|
|
'textField_cz1q8tk':merged_df["轻连锁金额"][i],#"轻连锁金额"
|
|
'textField_llxcdpj9':merged_df["裂变红包"][i],#"裂变红包"
|
|
'textField_ifhindg':merged_df["新签业绩(含轻连锁)"][i],#"新签业绩(含轻连锁)"
|
|
'textField_llvzdm60':merged_df["战区经理"][i],#"战区经理"
|
|
'textField_lm4ih07k':merged_df["小六"][i],#"小六名称"
|
|
'textField_lm4ghhmu':formatted_today_one,#"时间分区(月)"
|
|
'numberField_llvzdm61':i + 1 #"rank"
|
|
}
|
|
ALL_formData.append(json.dumps(formData, cls=NpEncoder))
|
|
FORMID = "FORM-UP9663719GYD8IA6CS8T4BIX1VZ02MZ6II4ML3"
|
|
res_new = Batch_creation(FORMID,TOKEN,ALL_formData)
|
|
print(res_new)
|
|
time.sleep(2)
|
|
time.sleep(60)
|
|
# 获取最后一条表单实例id,修改一次数据触发集成自动化保证数据准确性
|
|
res_two = transcation(TOKEN,res_new["result"][0],{"numberField_llvzdm61":i + 1})
|
|
print(res_two,"获取最后一条表单实例id,修改一次数据触发集成自动化保证数据准确性!") |