Commit f770dc82 by cyuanming

docs(operations): 补充嘀加智享车生活系列工单知识库文档

- 新增已有门店批量新增上架工单财务规则追加的详细操作说明及Python脚本
- 添加异常订单处理事项中线下支付订单更新支付方式或支付流水的SQL脚本及邮件截图
- 增加新增发货主体工单的邮件截图及插入脚本模板
- 补充错误订单回退上一个状态工单操作流程、SQL示例及触发定时任务的说明
- 添加财务和对账规则导出SQL脚本及邮件截屏,方便查询和使用
1 parent 2aabfe3e
## 背景
批量上架商品,商品的规则复用指定的商品配置的规则
## 产品发送的邮件
![邮件](../../assets/images/工单_已有门店批量新增上架_财务规则追加_邮件.png)
## 具体操作步骤
### 1. 生成工单sql
#### 1.1 打开邮件中的附件excel
![img](../../assets/images/工单_已有门店批量新增上架_财务规则追加_步骤1.png)
#### 1.2 准备要处理的excel
按商户号、产品ID、原上架的商品ID的顺序,按列依次粘贴到 ~\Desktop\pyDeal\convert\group_by_c.xlsx
![img](../../assets/images/工单_已有门店批量新增上架_财务规则追加_步骤12.png)
#### 1.3 运行python脚本生成sql
```py
import os
import re
from collections import defaultdict
import datetime
import xlwings as xw
def compileFunc_sql():
"""
处理Excel文件,按C列分组
从第二行开始读取数据,收集所有A列的值并去重拼接得到merchantIds字段
按C列分组,去重并用英文逗号拼接C列得到oldUids字段
最后输出C列的值和对应处理结果:merchantIds、oldUids(所有C列值对应相同的merchantIds)
"""
# 设置参数
first_data_row = 2 # 从第二行开始读取数据
app = xw.App(visible=False, add_book=False)
# 设置文件路径
filepath = r'C:\Users\tianming\Desktop\pyDeal\convert\group_by_c.xlsx' # 输入文件路径
# 设置输出文件路径
current_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
output_filepath = os.path.join(os.path.dirname(filepath), f'财务对账规则追加指定商品_{current_time}.sql')
try:
# 打开Excel文件
wb = app.books.open(filepath)
ws = wb.sheets[0]
nrows = ws.used_range.last_cell.row
# 用于存储分组数据的字典
group_data = defaultdict(lambda: {'new_uids': set()})
# 收集所有A列的值(商户ID)
all_merchant_ids = set()
# 读取数据并按C列分组
print('开始处理Excel数据...')
for i in range(first_data_row, nrows + 1):
merchant_id = ws.range('A{}'.format(i)).value
new_product_id = ws.range('B{}'.format(i)).value
old_product_id = ws.range('C{}'.format(i)).value
# 收集所有商户ID
if merchant_id is not None:
# 如果是浮点数且小数部分为0,则转换为整数再转字符串
if isinstance(merchant_id, float) and merchant_id.is_integer():
all_merchant_ids.add(str(int(merchant_id)))
else:
all_merchant_ids.add(str(merchant_id))
if old_product_id is not None and new_product_id is not None:
# 将B列数据添加到对应的分组中
group_data[old_product_id]['new_uids'].add(str(new_product_id))
# 准备输出处理结果
print('\n处理结果如下:')
print(f'结果将同时保存到文件: {output_filepath}')
print('-' * 80)
print('{:<20} {:<40} {:<40}'.format('原产品ID', '商户IDs', '新产品IDs'))
print('-' * 80)
# 将所有商户ID转换为逗号分隔的字符串
all_merchant_ids_str = ','.join(sorted(all_merchant_ids))
# 打印商户ID信息
print('商户IDs总数: {}'.format(len(all_merchant_ids)))
print('所有商户IDs: {}'.format(all_merchant_ids_str))
print('-' * 80)
# 创建输出文件
with open(output_filepath, 'w', encoding='utf-8') as f:
# 写入每个分组的数据
for old_product_id, data in group_data.items():
# 使用所有商户ID作为每个分组的merchant_ids
merchant_ids = all_merchant_ids_str
new_uids = ','.join(f"'{x}'" for x in sorted(data['new_uids']))
# 同时打印到控制台
print('原产品ID: {}'.format(old_product_id))
print('商户IDs数量: {}'.format(len(all_merchant_ids)))
print('新产品IDs数量: {}'.format(len(data['new_uids'])))
print('新产品IDs: {}'.format(new_uids))
print('-' * 80)
# 写入完整输出到文件(不截断)
f.write('\n\n-- 财务-{}'.format(old_product_id))
f.write(f'''
insert into dj_car_life_goods_type_group_relation(rule_type, goods_type_group_rule_id, category_type, upgrade_goods_id,
created_by, created_date, updated_by, updated_date, deleted_flag)
select
1,
dclgtg.id,
2,
dclug2.id,
'caiym_sql_{datetime.datetime.now().strftime("%Y%m%d")}',
now(),
'caiym_sql_{datetime.datetime.now().strftime("%Y%m%d")}',
now(),
'N'
from dj_car_life_division_rule_effect_record dcldrer
left join dj_car_life_merchant_goods_type_group_settle_rule dclmgtgsr
on dcldrer.rule_id = dclmgtgsr.settle_rule_id and dcldrer.deleted_flag = 'N'
left join dj_car_life_goods_type_group dclgtg
on dclmgtgsr.goods_type_group_id = dclgtg.id and dclgtg.deleted_flag = 'N'
left join dj_car_life_upgrade_goods dclug2
on dclug2.commodity_code in
({new_uids})
where dcldrer.merchant_id in
({all_merchant_ids_str})
and scene_type = 0
and rule_type = 1
and (effect_end_date is null
or effect_end_date > now())
and exists(select 1
from dj_car_life_goods_type_group_relation dclgtgr
left join dj_car_life_upgrade_goods dclug on dclug.id = dclgtgr.upgrade_goods_id
where dclgtgr.goods_type_group_rule_id = dclgtg.id
and dclgtgr.deleted_flag = 'N'
and dclgtgr.category_type = 2
and dclgtgr.rule_type = 1
and dclug.commodity_code = '{old_product_id}');
''')
f.write('\n\n-- 对账-{}'.format(old_product_id))
f.write(f'''
insert into dj_car_life_goods_type_group_relation(rule_type, goods_type_group_rule_id, category_type, upgrade_goods_id,
created_by, created_date, updated_by, updated_date, deleted_flag)
select 3,
dclmgtgsr.id,
2,
dclug2.id,
'caiym_sql_{datetime.datetime.now().strftime("%Y%m%d")}',
now(),
'caiym_sql_{datetime.datetime.now().strftime("%Y%m%d")}',
now(),
'N'
from dj_car_life_division_rule_effect_record dcldrer
left join dj_car_life_merchant_goods_type_group_reconciliation_rule dclmgtgsr
on dcldrer.rule_id = dclmgtgsr.reconciliation_rule_id and dcldrer.deleted_flag = 'N'
left join dj_car_life_upgrade_goods dclug2
on dclug2.commodity_code in
({new_uids})
where dcldrer.merchant_id in
({all_merchant_ids_str})
and scene_type = 0
and dcldrer.rule_type = 3
and (effect_end_date is null
or effect_end_date > now())
and exists(select 1
from dj_car_life_goods_type_group_relation dclgtgr
left join dj_car_life_upgrade_goods dclug on dclug.id = dclgtgr.upgrade_goods_id
where dclgtgr.goods_type_group_rule_id = dclmgtgsr.id
and dclgtgr.deleted_flag = 'N'
and dclgtgr.rule_type = 3
and dclgtgr.category_type = 2
and dclug.commodity_code = '{old_product_id}');
''')
except Exception as e:
print('处理Excel文件时发生错误: {}'.format(e))
finally:
# 关闭Excel文件和应用
if 'wb' in locals():
wb.close()
app.quit()
print('处理完成!结果已保存到: {}'.format(output_filepath))
if __name__ == '__main__':
compileFunc_sql()
```
### 2.执行工单
\ No newline at end of file \ No newline at end of file
## 工单收到的邮件
## ![异常订单_线下支付订单更新支付方式或流水_邮件截图](..\..\assets\images\异常订单_线下支付订单更新支付方式或流水_邮件截图.jpg)
## 工单回复
![异常订单_线下支付订单更新支付方式或流水_邮件截图](..\..\assets\images\异常订单_线下支付订单更新支付方式或流水_回复邮件截图.jpg)
## 更新支付流水sql
```sql
# 更新支付订单pay_order out_trade_no
update dj_car_life_pay_order set updated_date = now(), updated_by = 'caiym_liusq_sql_260302', out_trade_no = '031767549210260101601600469618' where order_code = '260131133709498' and deleted_flag = 'N';
# 更新pay_order trade_no
update dj_car_life_pay_order
set trade_no = out_trade_no
where order_code in
('260131133709498','260108173900668','260111005636206','260115110748556','260122162625623','260125135218201','260125175348444','260125175817321','260128101216255','260120175848330','260112144351467','260210143213409','260119084840858','260126183939560','260123174716708','260126180401296','260123175701737','260123181032136','260120162547424','260122173042347','260203124038750','260206174721157','260126155634712','260203151223221','260126152546245','260131175210567','260202184136666','260202115823680','260205152914932')
and deleted_flag = 'N';
# 更新分账记录dj_car_life_order_division out_trade_no
update dj_car_life_order_division dclod, dj_car_life_pay_order dclpo
set dclod.out_trade_no = dclpo.out_trade_no,
dclod.updated_date = now(),
dclod.updated_by = 'caiym_liusq_sql_260302'
where dclod.order_code in
('260131133709498','260108173900668','260111005636206','260115110748556','260122162625623','260125135218201','260125175348444','260125175817321','260128101216255','260120175848330','260112144351467','260210143213409','260119084840858','260126183939560','260123174716708','260126180401296','260123175701737','260123181032136','260120162547424','260122173042347','260203124038750','260206174721157','260126155634712','260203151223221','260126152546245','260131175210567','260202184136666','260202115823680','260205152914932')
and dclpo.id = dclod.pay_order_id
and dclod.deleted_flag = 'N'
and dclpo.deleted_flag = 'N';
# 更新报价单dj_car_life_vd_quotation trade_no
update dj_car_life_vd_quotation dclvq, dj_car_life_pay_order dclpo
set dclvq.trade_no = dclpo.trade_no,
dclvq.updated_time = now(),
dclvq.updated_by = 'caiym_liusq_sql_260302'
where dclvq.pay_id in
('260131133709498','260108173900668','260111005636206','260115110748556','260122162625623','260125135218201','260125175348444','260125175817321','260128101216255','260120175848330','260112144351467','260210143213409','260119084840858','260126183939560','260123174716708','260126180401296','260123175701737','260123181032136','260120162547424','260122173042347','260203124038750','260206174721157','260126155634712','260203151223221','260126152546245','260131175210567','260202184136666','260202115823680','260205152914932')
and dclpo.order_code = dclvq.pay_id
and dclvq.del_flag = 'N'
and dclpo.deleted_flag = 'N';
# 回复邮件-原out_trade_no trade_no
# select order_code, out_trade_no, trade_no
# from dj_car_life_pay_order
# where deleted_flag = 'N'
# and order_code in
# ('260131133709498','260108173900668','260111005636206','260115110748556','260122162625623','260125135218201','260125175348444','260125175817321','260128101216255','260120175848330','260112144351467','260210143213409','260119084840858','260126183939560','260123174716708','260126180401296','260123175701737','260123181032136','260120162547424','260122173042347','260203124038750','260206174721157','260126155634712','260203151223221','260126152546245','260131175210567','260202184136666','260202115823680','260205152914932');
```
## 更新支付流水 sql
```sql
# 更新支付订单dj_car_life_pay_order pay_type
update dj_car_life_pay_order set updated_date = now(), updated_by = 'caiym_liusq_sql_260227', pay_type = 2 where order_code = '260108175224168' and deleted_flag = 'N';
# 更新订单摘要dj_car_life_order_summary pay_type
update dj_car_life_order_summary dclos , dj_car_life_pay_order dclpo
set dclos.pay_type = dclpo.pay_type,
dclos.updated_date = now(),
dclos.updated_by = 'caiym_liusq_sql_260227'
where dclos.order_code in
('260108175224168', '260115140457648', '260116161754164', '260119095917375', '260120175148732', '260123141816503',
'260123164739880', '260123171043336', '260123171415767', '260129134352517', '260130180603301', '260130193114905')
and dclos.order_code = dclpo.order_code
and dclos.deleted_flag = 'N'
and dclpo.deleted_flag = 'N';
# 更新报价单dj_car_life_vd_quotation pay_type
update dj_car_life_vd_quotation dclvq, dj_car_life_pay_order dclpo
set dclvq.pay_type = dclpo.pay_type,
dclvq.updated_time = now(),
dclvq.updated_by = 'caiym_liusq_sql_260227'
where dclvq.pay_id in
('260108175224168', '260115140457648', '260116161754164', '260119095917375', '260120175148732', '260123141816503',
'260123164739880', '260123171043336', '260123171415767', '260129134352517', '260130180603301', '260130193114905')
and dclpo.order_code = dclvq.pay_id
and dclvq.del_flag = 'N'
and dclpo.deleted_flag = 'N';
# 回复邮件-查询原支付方式
# select order_code, case pay_type when 0 then '不升级' when 1 then '微信支付' when 2 then '4S店收款' when 3 then 'POS机收款'
# when 4 then '支付宝支付' when 5 then '嘀加收款' when 6 then '对公转账' when 7 then '其他收款' end as '支付方式'
# from dj_car_life_pay_order
# where deleted_flag = 'N' and order_code in
# ('260108175224168', '260115140457648', '260116161754164', '260119095917375', '260120175148732', '260123141816503',
# '260123164739880', '260123171043336', '260123171415767', '260129134352517', '260130180603301', '260130193114905');
```
## 邮件
![](..\..\assets\images\工单_新增发货主体_邮件.jpg)
## 脚本
```sql
INSERT INTO dj_car_life_shipping_entity_info (shipping_entity_id, shipping_entity, created_by,
created_date, updated_by, updated_date, deleted_flag)
VALUES (#递增,查看表里最大值加一#,
#新增发货主体名称#,
#更新人说明,比如caiymsql#, now(), #更新人说明,比如caiymsql#, now(),
'N');
```
## 背景
运营误操作,把订单标记为错误订单,但是但是实际上要退款,受限于订单状态为错误订单的订单,不能退款,需要回退订单状态为上一个已支付/待上传状态。
### 收到的邮件截图
![工单_订单_错误订单回退已支付状态_产品发送的邮件截图](../../assets/images/工单_嘀加智享车生活_订单_错误订单回退已支付状态_产品发送的邮件截图.png)
## 操作流程
![工单_订单_错误订单回退上一个状态_操作流程_流程图](../../assets/images/工单_订单_错误订单回退上一个状态_操作流程_流程图.png)
```mermaid
flowchart TD
A([收到错误订单回退工单]) --> B{确认订单状态是否为 11<br/>错误订单?}
B -->|否| C[结束: 非错误订单<br/>反馈运营停止处理]
B -->|是| D{标记错误时是否录入新订单?}
D -->|录入新订单| E[结束: 通知运营在生意助手<br/>员工版撤销新订单<br/>错误订单自动回退]
D -->|未录入新订单| F[执行工单回退<br/>更新订单状态及记录表]
F --> G[申请触发定时任务<br/>OrderAfterWorkAsyncExecuteJob]
```
## 具体操作步骤
### 1.确认订单此时的状态与上一个状态
- 如果此时的状态不是11,表示不是错误订单,运营搞错了要处理的订单号,反馈给运营,停止处理
- 查上一个状态是因为要回退到上一个状态
```sql
select dclgo.order_code as '订单号',
dclgo.status as '订单状态',
(select dclosr.order_status
from dj_car_life_order_status_record dclosr
where dclosr.order_code = dclgo.order_code
order by dclosr.id desc
limit 1,1) as '上一个订单状态',
if(dclgo.status = 1, dclgo.associated_order_code, null) as '标记错误时录入的新订单的订单号'
from dj_car_life_goods_order dclgo
where dclgo.order_code = #要处理的订单号#;
```
### 2.确定标记错误时是否录入了新订单
标记错误订单有两种方式:
- 标记错误订单并录入新订单。这种两个订单有关联
- 标记错误订单无需补录。
如果是标记错误订单并录入新订单,要回退这个错误订单到上一个状态,只需要运营在生意助手员工版小程序撤销新的订单,这个错误订单就会自动回退到上一个状态,不需要开发操作数据库。直接邮件回复:该订单是通过补录新订单标记错误的,撤销订单:[步骤1的查询结果-标记错误时录入的新订单的订单号]即可回退状态,停止处理。
### 3.工单回退订单状态到上一个状态
```sql
update dj_car_life_goods_order
set status = 4,
updated_by = #提工单人、运营的信息,比如caiym_lianghh_260319#,
updated_date = now()
where order_code = #要处理的订单号#;
INSERT INTO dj_car_life_order_status_record (order_code, order_status, remark, created_by, created_date, updated_by,
updated_date, deleted_flag)
VALUES (#要处理的订单号#, #上一个订单状态#, '运营错误操作标记错误订单,要求工单回退上一个状态',
#提工单人、运营的信息,比如caiym_lianghh_260319#, now(),
#提工单人、运营的信息,比如caiym_lianghh_260319#, now(), 'N');
```
### 4.触发定时任务处理订单状态的回退
发邮件申请触发定时任务
```
欣伟:
         申请线上定时任务触发,用于线上工单处理:错误订单回退上一个订单状态
         
         触发时间:立即触发
         注册中心:dubbo.zk.glsx.com:2181
         命名空间:glsx_elastic_job
         需要触发的定时任务名:OrderAfterWorkAsyncExecuteJob
         
         原表达式:0 0 0 * * ? 2099
         
         需要修改为的自定义参数:#要处理的订单号#-DJ_SMARTCARLIFE_EVENT_ORDER_UPGRADE_BACK(比如260315160432558-DJ_SMARTCARLIFE_EVENT_ORDER_UPGRADE_BACK)
         执行步骤:先把上述job的corn表达式改成离当前时间一分钟,例如(0 0 23 * * ?) 23点0分执行,让程序自己执行一次,执行一次后,会变成正常可触发状态,无需再次触发,只需要把corn表达式还原(0 0 0 * * ? 2099)、自定义参数清空就行
```
## 背景
## 产品发送的邮件
## 操作流程
## 具体操作步骤
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!