logistics/自动化跟单11.ipynb

1535 lines
59 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T14:28:31.802210Z",
"start_time": "2025-05-16T14:28:31.520519Z"
}
},
"outputs": [],
"source": [
"import pandas as pd \n",
"import requests \n",
"from login_for_cookie import Vc\n",
"import pendulum\n",
"import json\n",
"from utils/gtools import MySQLconnect \n",
"from lxml import etree\n",
"from pathlib import Path\n",
"from datetime import datetime\n",
"cookie = Vc(user='robot1',pswd= 'xi%26SiH4LbJ')\n",
"headers = {\"Cookie\":cookie}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T10:32:48.135119Z",
"start_time": "2025-05-16T10:32:48.017568Z"
}
},
"outputs": [],
"source": [
"def get_fs(row):\n",
" data = row[\"采购单号\"]\n",
" buy_url = \"http://cp.maso.hk/index.php?main=store_in_receive\"\n",
"\n",
" payload = {\n",
" \"s_pid\": 2867159,\n",
" \"s_suborderid\": \"\",\n",
" \"pdt_standard_id\": \"\",\n",
" \"s_store\": -1,\n",
" \"s_status[0]\": 0,\n",
" \"s_sort\": \"desc\",\n",
" \"Submit\": \"查询\",\n",
" \"synergy_sign\": -1,\n",
" \"start_dep\": \"\",\n",
" \"start_user\": \"\",\n",
" \"to_dep\": \"\",\n",
" \"to_user\": \"\",\n",
" \"swebid\": 0,\n",
" \"local_pdt_id\": 0,\n",
" \"sadd_time\": \"\",\n",
" \"sadd_time_end\": \"\",\n",
" \"sreal_express_no\": \"\",\n",
" \"sweb_id\": \"\",\n",
" \"sof\": 0,\n",
" \"soe\": 0,\n",
" \"sod\": \"\",\n",
" \"tsid\": -1,\n",
" \"tsdid\": -1,\n",
" \"tsst\": -1,\n",
" \"order_cate\": -1,\n",
" \"error_status\": -1,\n",
" \"web_uid\": -1,\n",
" \"team_id\": -1,\n",
" \"handle\": -1,\n",
" \"handle_uid\": 0,\n",
" \"handle_time_start\": \"\",\n",
" \"handle_time_end\": \"\",\n",
" \"shiping_time_start\": \"\",\n",
" \"shiping_time_end\": \"\",\n",
" \"trade_time_start\": \"\",\n",
" \"trade_time_end\": \"\",\n",
" \"order_express_fee\": -1,\n",
" \"web_type\": -1,\n",
" \"shipping_type\": -1,\n",
" \"maintain_add_time_s\": \"\",\n",
" \"maintain_add_time_e\": \"\",\n",
" \"maintain_comfirm_time_s\": \"\",\n",
" \"maintain_comfirm_time_e\": \"\",\n",
" \"dispense_user_id\": \"\",\n",
" \"export_page\": 1\n",
" }\n",
" payload[\"s_pid\"] = data\n",
" resp = requests.post(url = buy_url ,headers=headers , data=payload)\n",
" buy_df_list = pd.read_html(resp.text,match=\"所属网站ID\")\n",
" buy_df = buy_df_list[1]\n",
" buy_df.columns = buy_df.loc[0,:]\n",
" trade_id = buy_df[\"交易ID\"][1]\n",
" #交易明细里头\n",
" trade_url = f\"http://cp.maso.hk/index.php?main=store_tradelist_info&trade_id={trade_id}\"\n",
" resp2 = requests.get(url = trade_url ,headers=headers )\n",
" df_list2 = pd.read_html(resp2.text,match=\"下单发货时间\")\n",
" df2 = df_list2[0]\n",
" df2.columns = df2.loc[0,:]\n",
" 下单发货时间 = int(df2.iloc[2,1][0].replace(\"--\",\"0\"))\n",
" 维护发货时间 = int(df2.iloc[2,3].replace(\"--\",\"0\"))\n",
" 支付时间 = pendulum.parse(df2.iloc[3,3])\n",
" 最大发货时间 = 支付时间.add(days=max(下单发货时间,维护发货时间))\n",
" #交易列表\n",
" trade_list_url = f\"http://cp.maso.hk/index.php?main=store_in_receive&navlist=trade_list&s_trade_id={trade_id}\"\n",
" resp3 = requests.get(url = trade_list_url ,headers=headers )\n",
" df_list3 = pd.read_html(resp3.text,match=\"涨幅\")\n",
" df3 = df_list3[0]\n",
" df3.columns = df3.loc[0,:]\n",
" 交易平台 = df3[\"交易平台\"][1]\n",
" 交易号 = df3[\"交易号\"][1]\n",
" 交易平台订单号 = df3[\"交易平台订单号\"][1]\n",
" \n",
" return pd.Series([trade_id,下单发货时间, 维护发货时间,支付时间,最大发货时间,交易平台,交易号,交易平台订单号])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T10:38:08.275276Z",
"start_time": "2025-05-16T10:34:21.240914Z"
}
},
"outputs": [],
"source": [
"resultdf = pd.read_excel(r\"跟单测试源文件.xlsx\")[[\"跟单任务ID\", \"采购单号\"]]\n",
"# 扩展 get_fs\n",
"fs_cols = resultdf.apply(lambda x: get_fs(x), axis=1, result_type=\"expand\")\n",
"fs_cols.columns = [\"交易ID\",'下单发货时间', '维护发货时间','支付时间','最大发货时间','交易平台','交易号','交易平台订单号']\n",
"resultdf = pd.concat([resultdf, fs_cols], axis=1)\n",
"# 处理日期\n",
"for col in ['支付时间', '最大发货时间']:\n",
" resultdf[col] = pd.to_datetime(resultdf[col], errors='coerce')\n",
" resultdf[col] = resultdf[col].dt.strftime('%Y-%m-%d')\n",
"resultdf['pay_date'] = resultdf['支付时间']\n",
"# POST\n",
"data = resultdf.to_dict(orient='records')\n",
"headers = {\"Content-Type\": \"application/json; charset=utf-8\"}\n",
"url = \"http://192.168.100.44/rpaapi/followup\" \n",
"response = requests.post(url, headers=headers, data=json.dumps(data))\n",
"print(\"状态码:\", response.status_code)\n",
"print(\"响应内容:\", response.json())\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T10:39:03.196709Z",
"start_time": "2025-05-16T10:38:50.994916Z"
}
},
"outputs": [],
"source": [
"mdm = MySQLconnect(\"mdm\")\n",
"#对数据库进行创建TASK这个应该放在后端\n",
"def create_first_task():\n",
" all_sql = \"select * from tw_order_follow_up WHERE platform = '淘天' AND length(trade_platform_order_num) >=12\"\n",
" df = pd.read_sql(all_sql, mdm.engine())\n",
" for idx,row in df.iterrows():\n",
" trade_id = row[\"trade_id\"]\n",
" max_logis_date_mmdd =row[\"max_logis_date\"]\n",
" mmdd = f\"{max_logis_date_mmdd.month}月{max_logis_date_mmdd.day}日\"\n",
" send_text = f\"平台交易号:{trade_id},你好,请问最快什么时候发货,{mmdd}前可以发货吗?\"\n",
" task_url = \"http://192.168.100.44/rpaapi/taskcreate\" \n",
" headers = {\n",
" \"Content-Type\": \"application/json; charset=utf-8\", # 指定 UTF-8 编码\n",
" \"Other-Header\": \"value\"\n",
" }\n",
"\n",
" response = requests.post(url=task_url, headers=headers, data=json.dumps({\"task_type\":\"跟单\",\"type_id\":row[\"cpmaso_task_id\"],\"send_content\":send_text,\"level\":\"level1\"}))\n",
"create_first_task()\n",
"\n",
"#这里是写到影刀里面的\n",
"def get_tw_url(task_id):\n",
" url = f\"http://192.168.100.44/rpaapi/get_url/{task_id}\"\n",
" response = requests.get(url=url).json()\n",
" return response\n",
"\n",
"def finish_task(task_id,task_status,session_id):\n",
" task_url = \"http://192.168.100.44/rpaapi/taskfinish\" \n",
" response = requests.post(url=task_url, headers=headers, data=json.dumps({\"task_id\":task_id,\"task_status\":task_status,\"session_id\":session_id}))\n",
" return response.json()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#以下内容也全都写到影刀里面\n",
"file = Path(r\"C:\\Users\\Admin\\Desktop\\taoworldtask.txt\")\n",
"def html_to_db(html): # -> list[dict]\n",
" tree = etree.HTML(html)\n",
" container = tree.xpath(\"//*[contains(@class, 'IMChat--ww_container--rcKMqZZ')]\")[0]\n",
" shopname = container.xpath(\"//*[contains(@class, 'IMChat--ww_header--qyQJ4Lp')]/text()\")[0].strip()\n",
" message_item_lines = container.xpath(\"//*[contains(@class, 'message-item-lin')]\")\n",
"\n",
" results = []\n",
" for msg in message_item_lines:\n",
" message_id = msg.get('id', '')\n",
" \n",
" # 昵称\n",
" nick_x = msg.xpath(\".//div[contains(@class, 'nick')]/text()\")\n",
" nick = nick_x[0].strip() if nick_x else ''\n",
" \n",
" # 时间\n",
" time_x = msg.xpath(\".//div[contains(@class, 'time')]/text()\")\n",
" time_str = time_x[0].strip() if time_x else ''\n",
" try:\n",
" time = datetime.strptime(time_str, \"%Y-%m-%d %H:%M:%S\") if time_str else None\n",
" except ValueError:\n",
" time = None\n",
"\n",
" # 内容或图片\n",
" content_x = msg.xpath(\".//pre[contains(@class, 'edit')]/text()\")\n",
" content = ','.join(content_x).strip() if content_x else ''\n",
" img_x = msg.xpath(\".//img[contains(@class, 'imui-msg-img')]/@src\")\n",
" if img_x:\n",
" content = img_x[0] # 可考虑记录 chat_type='image'\n",
"\n",
" result = {\n",
" 'id': message_id,\n",
" 'nick': nick,\n",
" 'time': time.strftime(\"%Y-%m-%d %H:%M:%S\") if time else None,\n",
" 'content': content\n",
" }\n",
" results.append(result)\n",
" return {\n",
" \"shopname\": shopname,\n",
" \"messages\": results\n",
" }\n",
"\n",
"def upload_msg(msg_list, account, create_chat_id=''):\n",
" url = \"http://192.168.100.44/rpaapi/upload_msg\"\n",
"\n",
" payload = {\n",
" \"shopname\": msg_list[\"shopname\"],\n",
" \"messages\": msg_list[\"messages\"],\n",
" \"account\": account,\n",
" \"creata_chat_id\": create_chat_id # 如果为空,表示接收方;否则为发送者创建会话用\n",
" }\n",
"\n",
" headers = {\n",
" \"Content-Type\": \"application/json\"\n",
" }\n",
"\n",
" try:\n",
" resp = requests.post(url, headers=headers, data=json.dumps(payload))\n",
" if resp.status_code == 200:\n",
" print(\"上传成功\")\n",
" else:\n",
" print(f\"上传失败: {resp.status_code} - {resp.text}\")\n",
" except Exception as e:\n",
" print(f\"请求异常: {e}\")\n",
"\n",
"msg_data = html_to_db(file.read_text(encoding='utf-8'))\n",
"msg_data1 = msg_data.copy()\n",
"msg_data1[\"messages\"] = msg_data[\"messages\"][:10]\n",
"upload_msg(msg_data1, account=\"t-2217567810350-0\", create_chat_id=\"3469772970637.PNM\")\n",
"msg_data2 = msg_data.copy()\n",
"msg_data2[\"messages\"] = msg_data[\"messages\"][5:]\n",
"upload_msg(msg_data2, account=\"t-2217567810350-0\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from http import HTTPStatus\n",
"from dashscope import Application\n",
"response = Application.call(\n",
" # 若没有配置环境变量可用百炼API Key将下行替换为api_key=\"sk-xxx\"。但不建议在生产环境中直接将API Key硬编码到代码中以减少API Key泄露风险。\n",
" api_key=\"sk-17d17a164fb44ff99d88647bc6a1d551\",\n",
" app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID\n",
" prompt='你是谁?')\n",
"if response.status_code != HTTPStatus.OK:\n",
" print(f'request_id={response.request_id}')\n",
" print(f'code={response.status_code}')\n",
" print(f'message={response.message}')\n",
" print(f'请参考文档https://help.aliyun.com/zh/model-studio/developer-reference/error-code')\n",
"else:\n",
" print(response.output.text)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-14T17:20:59.901784Z",
"start_time": "2025-05-14T17:20:59.797072Z"
}
},
"outputs": [],
"source": [
"import os\n",
"from http import HTTPStatus\n",
"from dashscope import Application\n",
"mdm = MySQLconnect(\"mdm\")\n",
"sql = \"\"\"SELECT * FROM `tw_session_detail` WHERE session_id = 111\"\"\"\n",
"chatdf = pd.read_sql(sql, mdm.engine())\n",
"rows_as_dict_list = chatdf.to_dict(orient='records')\n",
"rows_as_dict_list"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-14T17:21:12.453964Z",
"start_time": "2025-05-14T17:21:03.052705Z"
}
},
"outputs": [],
"source": [
"import os\n",
"from http import HTTPStatus\n",
"from dashscope import Application\n",
"response = Application.call(\n",
" # 若没有配置环境变量可用百炼API Key将下行替换为api_key=\"sk-xxx\"。但不建议在生产环境中直接将API Key硬编码到代码中以减少API Key泄露风险。\n",
" api_key=\"sk-17d17a164fb44ff99d88647bc6a1d551\",\n",
" app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID\n",
" prompt=str(rows_as_dict_list))\n",
"if response.status_code != HTTPStatus.OK:\n",
" print(f'request_id={response.request_id}')\n",
" print(f'code={response.status_code}')\n",
" print(f'message={response.message}')\n",
" print(f'请参考文档https://help.aliyun.com/zh/model-studio/developer-reference/error-code')\n",
"else:\n",
" print(json.loads(response.output.text))\n",
" #上传数据库\n",
" #"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"################################################################## 上传聊天记录"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T14:28:17.306768Z",
"start_time": "2025-05-16T14:28:17.294156Z"
},
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T15:38:46.563968Z",
"start_time": "2025-05-16T15:38:44.315926Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"import os\n",
"import pandas as pd\n",
"from datetime import datetime\n",
"from http import HTTPStatus\n",
"from dashscope import Application\n",
"from utils.gtools import MySQLconnect\n",
"import json\n",
"mdm = MySQLconnect('mdm')\n",
"import requests"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"def upload_to_cpmaso(id,date,file,process_remark='',is_return=0,is_refund=0,is_find_goods=0):\n",
" url = \"http://192.168.100.44/rpaapi/upload_system_appointed_time\"\n",
" data = {\"id\":id,\"date\":date,\"content\":file,\"process_remark\":process_remark,\"is_refund\":is_refund,\"is_return\":is_return,\"is_find_goods\":is_find_goods} # id是任务idcontent是txt文件内容remark是备注\n",
" headers = {\"Content-Type\": \"application/json\"}\n",
" response = requests.post(url=url,json=data,headers=headers)\n",
" return response"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"from http import HTTPStatus\n",
"from dashscope import Application\n",
"def aliyun(prompt):\n",
" response = Application.call(\n",
" # 若没有配置环境变量可用百炼API Key将下行替换为api_key=\"sk-xxx\"。但不建议在生产环境中直接将API Key硬编码到代码中以减少API Key泄露风险。\n",
" api_key=\"sk-17d17a164fb44ff99d88647bc6a1d551\",\n",
" app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID\n",
" prompt=prompt)\n",
" api_data = json.loads(response.output.text)\n",
" return api_data"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T15:38:58.960899Z",
"start_time": "2025-05-16T15:38:58.940364Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"sql = \"\"\"SELECT * FROM `tw_order_follow_up` where platform = '淘天' AND upload_cpmaso = 0\"\"\""
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T15:39:01.808655Z",
"start_time": "2025-05-16T15:39:01.716950Z"
},
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>cpmaso_task_id</th>\n",
" <th>buy_id</th>\n",
" <th>trade_id</th>\n",
" <th>trade_platform_order_num</th>\n",
" <th>pay_date</th>\n",
" <th>maintain_date</th>\n",
" <th>last_task_id</th>\n",
" <th>follow_type</th>\n",
" <th>max_logis_date</th>\n",
" <th>agreed_delivery_time</th>\n",
" <th>trans_id</th>\n",
" <th>payment_datetime</th>\n",
" <th>platform</th>\n",
" <th>task_status</th>\n",
" <th>need_refund</th>\n",
" <th>has_image</th>\n",
" <th>clearly_specify_the_delivery_time</th>\n",
" <th>one_more_time</th>\n",
" <th>create_date</th>\n",
" <th>upload_cpmaso</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>343636</td>\n",
" <td>2896029</td>\n",
" <td>2896029</td>\n",
" <td>2896029</td>\n",
" <td>2025-05-20</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-21</td>\n",
" <td>None</td>\n",
" <td>1863624</td>\n",
" <td>1</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-21</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>343650</td>\n",
" <td>2896044</td>\n",
" <td>2896044</td>\n",
" <td>2896044</td>\n",
" <td>2025-05-20</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-27</td>\n",
" <td>None</td>\n",
" <td>1863645</td>\n",
" <td>7</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-21</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>345441</td>\n",
" <td>2896633</td>\n",
" <td>2896633</td>\n",
" <td>2896633</td>\n",
" <td>2025-05-21</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-22</td>\n",
" <td>None</td>\n",
" <td>1864349</td>\n",
" <td>1</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>345460</td>\n",
" <td>2896653</td>\n",
" <td>896653</td>\n",
" <td>896653</td>\n",
" <td>2025-05-21</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-22</td>\n",
" <td>None</td>\n",
" <td>1864373</td>\n",
" <td>1</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>345510</td>\n",
" <td>2896706</td>\n",
" <td>2896706</td>\n",
" <td>2896706</td>\n",
" <td>2025-05-21</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-23</td>\n",
" <td>None</td>\n",
" <td>1864440</td>\n",
" <td>2</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>347335</td>\n",
" <td>2897332</td>\n",
" <td>2897332</td>\n",
" <td>2897332</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-25</td>\n",
" <td>None</td>\n",
" <td>1865297</td>\n",
" <td>3</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>6</th>\n",
" <td>347339</td>\n",
" <td>2897336</td>\n",
" <td>2897336</td>\n",
" <td>2897336</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-27</td>\n",
" <td>None</td>\n",
" <td>1865301</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>347345</td>\n",
" <td>2897342</td>\n",
" <td>2897342</td>\n",
" <td>2897342</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-25</td>\n",
" <td>None</td>\n",
" <td>1865307</td>\n",
" <td>3</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>8</th>\n",
" <td>347348</td>\n",
" <td>2897345</td>\n",
" <td>2897345</td>\n",
" <td>2897345</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-24</td>\n",
" <td>None</td>\n",
" <td>1865308</td>\n",
" <td>2</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>9</th>\n",
" <td>347415</td>\n",
" <td>2897416</td>\n",
" <td>2897416</td>\n",
" <td>2897416</td>\n",
" <td>2025-05-22</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-27</td>\n",
" <td>None</td>\n",
" <td>1865406</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>10</th>\n",
" <td>349155</td>\n",
" <td>2898014</td>\n",
" <td>2578499365301538788</td>\n",
" <td>1747991280236</td>\n",
" <td>2025-05-23</td>\n",
" <td>7</td>\n",
" <td>532</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1866518</td>\n",
" <td>7</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-24</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>11</th>\n",
" <td>349191</td>\n",
" <td>2898060</td>\n",
" <td>2577712694448538788</td>\n",
" <td>501566-186639528980603464</td>\n",
" <td>2025-05-23</td>\n",
" <td>3</td>\n",
" <td>533</td>\n",
" <td>1</td>\n",
" <td>2025-05-28</td>\n",
" <td>None</td>\n",
" <td>1866395</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-24</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>12</th>\n",
" <td>349219</td>\n",
" <td>2898090</td>\n",
" <td>2898090</td>\n",
" <td>2898090</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1866272</td>\n",
" <td>7</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-24</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>13</th>\n",
" <td>349350</td>\n",
" <td>2898239</td>\n",
" <td>2898239</td>\n",
" <td>2898239</td>\n",
" <td>2025-05-23</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-28</td>\n",
" <td>None</td>\n",
" <td>1866500</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-24</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>14</th>\n",
" <td>352340</td>\n",
" <td>2899178</td>\n",
" <td>2579933964195538788</td>\n",
" <td>501566-186750228991783425</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>537</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867502</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15</th>\n",
" <td>352363</td>\n",
" <td>2899201</td>\n",
" <td>4354718580547688148</td>\n",
" <td>1748139827823</td>\n",
" <td>2025-05-25</td>\n",
" <td>5</td>\n",
" <td>540</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867773</td>\n",
" <td>3</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>16</th>\n",
" <td>352392</td>\n",
" <td>2899231</td>\n",
" <td>2580629125407538788</td>\n",
" <td>501566-186754728992314910</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>542</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867547</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>17</th>\n",
" <td>352494</td>\n",
" <td>2899334</td>\n",
" <td>2579651619722538788</td>\n",
" <td>501566-186769728993341037</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>553</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867697</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>18</th>\n",
" <td>352504</td>\n",
" <td>2899345</td>\n",
" <td>2580008664490538788</td>\n",
" <td>501566-186771428993459718</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>555</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867714</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>19</th>\n",
" <td>352526</td>\n",
" <td>2899368</td>\n",
" <td>2579710119285538788</td>\n",
" <td>501566-186775328993689331</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>558</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867753</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>20</th>\n",
" <td>352631</td>\n",
" <td>2899481</td>\n",
" <td>2579924751782538788</td>\n",
" <td>501566-186789228994817432</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>580</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867892</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>352649</td>\n",
" <td>2899501</td>\n",
" <td>2899501</td>\n",
" <td>2899501</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>1</td>\n",
" <td>2025-05-28</td>\n",
" <td>None</td>\n",
" <td>1867913</td>\n",
" <td>3</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>22</th>\n",
" <td>352698</td>\n",
" <td>2899552</td>\n",
" <td>4355089779147463948</td>\n",
" <td>1748152477497</td>\n",
" <td>2025-05-25</td>\n",
" <td>5</td>\n",
" <td>594</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1867983</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>23</th>\n",
" <td>352735</td>\n",
" <td>2899590</td>\n",
" <td>2580755954053538788</td>\n",
" <td>501566-186804028995900068</td>\n",
" <td>2025-05-25</td>\n",
" <td>0</td>\n",
" <td>601</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1868040</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>24</th>\n",
" <td>352741</td>\n",
" <td>2899596</td>\n",
" <td>2580765530729538788</td>\n",
" <td>501566-186804828995968241</td>\n",
" <td>2025-05-25</td>\n",
" <td>5</td>\n",
" <td>603</td>\n",
" <td>1</td>\n",
" <td>2025-05-30</td>\n",
" <td>None</td>\n",
" <td>1868048</td>\n",
" <td>5</td>\n",
" <td>淘天</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" <td>2025-05-26</td>\n",
" <td>0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" cpmaso_task_id buy_id trade_id trade_platform_order_num \\\n",
"0 343636 2896029 2896029 2896029 \n",
"1 343650 2896044 2896044 2896044 \n",
"2 345441 2896633 2896633 2896633 \n",
"3 345460 2896653 896653 896653 \n",
"4 345510 2896706 2896706 2896706 \n",
"5 347335 2897332 2897332 2897332 \n",
"6 347339 2897336 2897336 2897336 \n",
"7 347345 2897342 2897342 2897342 \n",
"8 347348 2897345 2897345 2897345 \n",
"9 347415 2897416 2897416 2897416 \n",
"10 349155 2898014 2578499365301538788 1747991280236 \n",
"11 349191 2898060 2577712694448538788 501566-186639528980603464 \n",
"12 349219 2898090 2898090 2898090 \n",
"13 349350 2898239 2898239 2898239 \n",
"14 352340 2899178 2579933964195538788 501566-186750228991783425 \n",
"15 352363 2899201 4354718580547688148 1748139827823 \n",
"16 352392 2899231 2580629125407538788 501566-186754728992314910 \n",
"17 352494 2899334 2579651619722538788 501566-186769728993341037 \n",
"18 352504 2899345 2580008664490538788 501566-186771428993459718 \n",
"19 352526 2899368 2579710119285538788 501566-186775328993689331 \n",
"20 352631 2899481 2579924751782538788 501566-186789228994817432 \n",
"21 352649 2899501 2899501 2899501 \n",
"22 352698 2899552 4355089779147463948 1748152477497 \n",
"23 352735 2899590 2580755954053538788 501566-186804028995900068 \n",
"24 352741 2899596 2580765530729538788 501566-186804828995968241 \n",
"\n",
" pay_date maintain_date last_task_id follow_type max_logis_date \\\n",
"0 2025-05-20 0 0 1 2025-05-21 \n",
"1 2025-05-20 0 0 1 2025-05-27 \n",
"2 2025-05-21 0 0 1 2025-05-22 \n",
"3 2025-05-21 0 0 1 2025-05-22 \n",
"4 2025-05-21 0 0 1 2025-05-23 \n",
"5 2025-05-22 0 0 1 2025-05-25 \n",
"6 2025-05-22 0 0 1 2025-05-27 \n",
"7 2025-05-22 0 0 1 2025-05-25 \n",
"8 2025-05-22 0 0 1 2025-05-24 \n",
"9 2025-05-22 0 0 1 2025-05-27 \n",
"10 2025-05-23 7 532 1 2025-05-30 \n",
"11 2025-05-23 3 533 1 2025-05-28 \n",
"12 2025-05-23 0 0 1 2025-05-30 \n",
"13 2025-05-23 0 0 1 2025-05-28 \n",
"14 2025-05-25 0 537 1 2025-05-30 \n",
"15 2025-05-25 5 540 1 2025-05-30 \n",
"16 2025-05-25 0 542 1 2025-05-30 \n",
"17 2025-05-25 0 553 1 2025-05-30 \n",
"18 2025-05-25 0 555 1 2025-05-30 \n",
"19 2025-05-25 0 558 1 2025-05-30 \n",
"20 2025-05-25 0 580 1 2025-05-30 \n",
"21 2025-05-25 0 0 1 2025-05-28 \n",
"22 2025-05-25 5 594 1 2025-05-30 \n",
"23 2025-05-25 0 601 1 2025-05-30 \n",
"24 2025-05-25 5 603 1 2025-05-30 \n",
"\n",
" agreed_delivery_time trans_id payment_datetime platform task_status \\\n",
"0 None 1863624 1 淘天 0 \n",
"1 None 1863645 7 淘天 0 \n",
"2 None 1864349 1 淘天 0 \n",
"3 None 1864373 1 淘天 0 \n",
"4 None 1864440 2 淘天 0 \n",
"5 None 1865297 3 淘天 0 \n",
"6 None 1865301 5 淘天 0 \n",
"7 None 1865307 3 淘天 0 \n",
"8 None 1865308 2 淘天 0 \n",
"9 None 1865406 5 淘天 0 \n",
"10 None 1866518 7 淘天 0 \n",
"11 None 1866395 5 淘天 0 \n",
"12 None 1866272 7 淘天 0 \n",
"13 None 1866500 5 淘天 0 \n",
"14 None 1867502 5 淘天 0 \n",
"15 None 1867773 3 淘天 0 \n",
"16 None 1867547 5 淘天 0 \n",
"17 None 1867697 5 淘天 0 \n",
"18 None 1867714 5 淘天 0 \n",
"19 None 1867753 5 淘天 0 \n",
"20 None 1867892 5 淘天 0 \n",
"21 None 1867913 3 淘天 0 \n",
"22 None 1867983 5 淘天 0 \n",
"23 None 1868040 5 淘天 0 \n",
"24 None 1868048 5 淘天 0 \n",
"\n",
" need_refund has_image clearly_specify_the_delivery_time one_more_time \\\n",
"0 0 0 0 0 \n",
"1 0 0 0 0 \n",
"2 0 0 0 0 \n",
"3 0 0 0 0 \n",
"4 0 0 0 0 \n",
"5 0 0 0 0 \n",
"6 0 0 0 0 \n",
"7 0 0 0 0 \n",
"8 0 0 0 0 \n",
"9 0 0 0 0 \n",
"10 0 0 0 0 \n",
"11 0 0 0 0 \n",
"12 0 0 0 0 \n",
"13 0 0 0 0 \n",
"14 0 0 0 0 \n",
"15 0 0 0 0 \n",
"16 0 0 0 0 \n",
"17 0 0 0 0 \n",
"18 0 0 0 0 \n",
"19 0 0 0 0 \n",
"20 0 0 0 0 \n",
"21 0 0 0 0 \n",
"22 0 0 0 0 \n",
"23 0 0 0 0 \n",
"24 0 0 0 0 \n",
"\n",
" create_date upload_cpmaso \n",
"0 2025-05-21 0 \n",
"1 2025-05-21 0 \n",
"2 2025-05-22 0 \n",
"3 2025-05-22 0 \n",
"4 2025-05-22 0 \n",
"5 2025-05-23 0 \n",
"6 2025-05-23 0 \n",
"7 2025-05-23 0 \n",
"8 2025-05-23 0 \n",
"9 2025-05-23 0 \n",
"10 2025-05-24 0 \n",
"11 2025-05-24 0 \n",
"12 2025-05-24 0 \n",
"13 2025-05-24 0 \n",
"14 2025-05-26 0 \n",
"15 2025-05-26 0 \n",
"16 2025-05-26 0 \n",
"17 2025-05-26 0 \n",
"18 2025-05-26 0 \n",
"19 2025-05-26 0 \n",
"20 2025-05-26 0 \n",
"21 2025-05-26 0 \n",
"22 2025-05-26 0 \n",
"23 2025-05-26 0 \n",
"24 2025-05-26 0 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.read_sql(sql,mdm.engine())\n",
"df"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-15T15:26:13.035452Z",
"start_time": "2025-05-15T15:26:13.013689Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"def update_follow_up(task_id,time='null',task_status=0,refund=0,has_image=1,clearly_time='0',one_more_time=0):\n",
" sql = f\"\"\"\n",
" UPDATE `tw_order_follow_up`\n",
" SET agreed_delivery_time = {time},task_status = {task_status},need_refund = {refund},\n",
" has_image = {has_image},clearly_specify_the_delivery_time = {clearly_time},one_more_time = {one_more_time}\n",
" WHERE cpmaso_task_id = \"{task_id}\"\n",
" \"\"\"\n",
" connect = mdm.connect()\n",
" connect.cursor().execute(sql)\n",
" connect.commit()\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T15:45:35.889562Z",
"start_time": "2025-05-16T15:41:16.724883Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"from datetime import datetime \n",
"#id,date,file,remake='',is_return=0,is_refund=0,is_find_goods=0):\n",
"for idx,row in df.iterrows():\n",
" #如果已发货,就上传记录\n",
" if row[\"task_status\"] == 5:\n",
" resp=upload_to_cpmaso(id=row[\"cpmaso_task_id\"],\n",
" date = datetime.now().strftime(\"%Y-%m-%d\"),\n",
" file = \"\",\n",
" process_remark = \"已发货\")\n",
" print(resp)\n",
" url = 'http://192.168.100.44/rpaapi/upload_followup'\n",
" data = {\n",
" \"task_id\" : row[\"cpmaso_task_id\"],\n",
" \"task_status\":row[\"task_status\"],\n",
" \"upload_cpmaso\" : 1\n",
" }\n",
" headers = {\"Content-Type\": \"application/json\"}\n",
" response = requests.post(url=url,json=data,headers=headers)\n",
" print(1)\n",
" elif row[\"task_status\"] == 0:\n",
" chat_sql = f\"\"\"SELECT\n",
" t3.* \n",
" FROM\n",
" `tw_order_follow_up` t1 LEFT JOIN tw_auto_task t2 on t1.last_task_id = t2.id\n",
" LEFT JOIN tw_session_detail t3 on t3.session_id = t2.send_session\n",
" WHERE\n",
" cpmaso_task_id = {row[\"cpmaso_task_id\"]} \"\"\"\n",
" chatdf = pd.read_sql(chat_sql, mdm.engine())\n",
" \n",
" \n",
" if len(chatdf) == 0 or chatdf[\"id\"][0] is None:\n",
" continue\n",
" else:\n",
" last_match_idx = chatdf[chatdf['chat_content'].str.contains('平台交易号', na=False)].index[-1]\n",
" # # 获取该行及之后所有行\n",
" chatdf = chatdf.loc[last_match_idx:]\n",
" if len(chatdf) == 1:\n",
" resp=upload_to_cpmaso(id=row[\"cpmaso_task_id\"],\n",
" date =\"\",\n",
" file = str(chatdf.to_dict(orient='records')),\n",
" process_remark = \"买家未回复\")\n",
" continue\n",
" elif len(chatdf) >= 2:\n",
" pass\n",
" \n",
" rows_as_dict_list = chatdf.to_dict(orient='records')\n",
" prompt=str(rows_as_dict_list)\n",
" chat_list = [row['chat_content'] for row in rows_as_dict_list]\n",
" api_data= aliyun(prompt)\n",
" print(chat_list)\n",
" deliver_date = api_data['result']['约定发货信息']['发货时间'] #发货时间\n",
" answer_result = api_data[\"result\"]['回复结果'] # 回复结果\n",
" is_return = api_data['result']['是否需要退款']\n",
" is_deliver = api_data['result']['是否已发货'] \n",
" is_ask = api_data['result']['是否需要追问']\n",
" time = datetime.strptime(deliver_date, \"%Y/%m/%d\").date().strftime(\"%Y-%m-%d\") if deliver_date else \"\"\n",
" need_refund = 1 if is_return == \"是\" else 0\n",
" clearly_time = 1 if answer_result == '明确发货时间' else 2 if answer_result == '无法明确发货时间' else 3\n",
" one_more_time = 1 if is_ask == '是' else 2\n",
" has_image = 1 if answer_result == '内含图片' else 0\n",
" task_status = 5 if answer_result == '回复已发货' else 4 if has_image == 1 else 1 if clearly_time == 2 else 2 if clearly_time == 1 else 1\n",
" task_status = 4 if need_refund == 1 else task_status\n",
" print(api_data)\n",
"\n",
" resp=upload_to_cpmaso(id=row[\"cpmaso_task_id\"],\n",
" date = time,\n",
" file = str(chatdf.to_dict(orient='records')),\n",
" process_remark = answer_result)\n",
" \n",
" url = 'http://192.168.100.44/rpaapi/upload_followup'\n",
" data = {\n",
" \"task_id\" : row[\"cpmaso_task_id\"],\n",
" \"time\":time,\n",
" \"task_status\":task_status,\n",
" \"refund\": need_refund,\n",
" \"has_image\":has_image,\n",
" \"clearly_time\":clearly_time,\n",
" \"one_more_time\":one_more_time,\n",
" \"upload_cpmaso\" : 1\n",
" }\n",
"\n",
" headers = {\"Content-Type\": \"application/json\"}\n",
" response = requests.post(url=url,json=data,headers=headers)\n",
" print(1)\n",
" for j in range(len(rows_as_dict_list)):\n",
" id = rows_as_dict_list[j]['id']\n",
" url = 'http://192.168.100.44/rpaapi/read'\n",
" data = {\"chat_id\":id}\n",
" headers = {\"Content-Type\": \"application/json\"}\n",
" requests.post(url=url,json=data,headers=headers)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T15:00:09.917941Z",
"start_time": "2025-05-16T15:00:09.796011Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"def aliyun(rows_as_dict_list):\n",
" response = Application.call(\n",
" # 若没有配置环境变量可用百炼API Key将下行替换为api_key=\"sk-xxx\"。但不建议在生产环境中直接将API Key硬编码到代码中以减少API Key泄露风险。\n",
" api_key=\"sk-17d17a164fb44ff99d88647bc6a1d551\",\n",
" app_id='83af9a2c0cf444da9a1860c91a1963ec',# 替换为实际的应用 ID\n",
" prompt=str(rows_as_dict_list))\n",
" api_data = json.loads(response.output.text)\n",
" return api_data\n",
" deliver_date = api_data['result']['约定发货信息']['发货时间'] #发货时间\n",
" answer_result = api_data[\"result\"]['回复结果'] # 回复结果\n",
" is_return = api_data['result']['是否需要退款']\n",
" is_deliver = api_data['result']['是否已发货']\n",
" is_ask = api_data['result']['是否需要追问']\n",
" time = datetime.strptime(deliver_date, \"%Y/%m/%d\").date() if deliver_date else None\n",
" need_refund = 1 if is_return == \"是\" else 0\n",
" clearly_time = 1 if answer_result == '明确发货时间' else 2 if answer_result == '无法明确发货时间' else 3\n",
" one_more_time = 1 if is_ask == '是' else 2\n",
" has_image = 1 if answer_result == '内含图片' else 0\n",
" task_status = 5 if answer_result == '回复已发货' else 4 if has_image == 1 else 1 if clearly_time == 2 else 2 if clearly_time == 1 else 1\n",
" task_status = 4 if need_refund == 1 else task_status\n",
" print(api_data)\n",
"\n",
" url = 'http://192.168.100.44/rpaapi/upload_followup'\n",
" data = {\n",
" \"task_id\" : df.iloc[i,1],\"time\":time,\n",
" \"task_status\":task_status,\n",
" \"refund\": need_refund,\n",
" \"has_image\":has_image,\n",
" \"clearly_time\":clearly_time,\n",
" \"one_more_time\":one_more_time\n",
" }\n",
" headers = {\"Content-Type\": \"application/json\"}\n",
" response = requests.post(url=url,json=data,headers=headers)\n",
" print(1)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-16T15:07:00.762532Z",
"start_time": "2025-05-16T15:07:00.737861Z"
},
"collapsed": false
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"############################################################# 聊天记录上传系统"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-15T17:01:48.937072Z",
"start_time": "2025-05-15T17:01:47.491710Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"sql = \"\"\"SELECT cpmaso_task_id,agreed_delivery_time,task_status,need_refund,clearly_specify_the_delivery_time,one_more_time\n",
"from tw_order_follow_up\n",
"where platform = '淘天'\n",
"and DATE(create_date) = DATE(CONVERT_TZ(NOW(), '+00:00', '+08:00'))\n",
"and task_status != 0\n",
"and task_status != 5\n",
"and task_status != 4\"\"\"\n",
"df = pd.read_sql(sql,mdm.engine())\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-15T17:51:28.209124Z",
"start_time": "2025-05-15T17:51:28.204284Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"def upload_to_cpmaso(id,date,file,remake='',is_return=0,is_refund=0,is_find_goods=0):\n",
" url = \"http://192.168.100.44/rpaapi/upload_system_appointed_time\"\n",
" data = {\"id\":id,\"date\":date,\"content\":file,\"remark\":remake,\"is_refund\":is_refund,\"is_return\":is_return,\"is_find_goods\":is_find_goods} # id是任务idcontent是txt文件内容remark是备注\n",
" headers = {\"Content-Type\": \"application/json\"}\n",
" response = requests.post(url=url,json=data,headers=headers)\n",
" print(response)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2025-05-15T18:01:35.681048Z",
"start_time": "2025-05-15T18:01:24.070530Z"
},
"collapsed": false
},
"outputs": [],
"source": [
"for i in range(len(df)):\n",
" type_id = str(df.iloc[i]['cpmaso_task_id'])\n",
" is_refund = str(df.iloc[i]['need_refund'])\n",
" if df.iloc[i]['agreed_delivery_time']: # 如果时间不为空\n",
" date = str(df.iloc[i]['agreed_delivery_time'])\n",
" remake= ''\n",
" else:\n",
" date = ''\n",
" remake = '没有明确时间'\n",
" msg_sql = f\"\"\"SELECT b.*\n",
" FROM tw_auto_task a\n",
" left join tw_session_detail b on a.send_session = b.session_id\n",
" where a.type_id = {type_id}\"\"\"\n",
" msg_df = pd.read_sql(msg_sql,mdm.engine())\n",
" msg_df['chat_date'] = msg_df['chat_date'].dt.strftime('%Y-%m-%d %H:%M:%S')\n",
" msg_file = msg_df.to_dict(orient='records')\n",
" upload_to_cpmaso(id=type_id,date=date,file=msg_file,is_refund=is_refund,remake=remake)\n",
" print(msg_file)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}