test_business_unit_billing_statistics.py
5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
测试事业部开单统计接口
"""
import json
import sys
import requests
BASE_URL = "http://localhost:2011"
TEST_DATE = sys.argv[1] if len(sys.argv) > 1 else "2026-01-20"
def get_token():
"""获取登录token"""
login_data = {
"account": "admin",
"password": "e10adc3949ba59abbe56e057f20f883e"
}
try:
response = requests.post(
f"{BASE_URL}/api/oauth/Login",
data=login_data,
headers={"Content-Type": "application/x-www-form-urlencoded"},
timeout=10
)
if response.status_code == 200:
result = response.json()
if result.get('code') == 200 and result.get('data') and result.get('data').get('token'):
return result['data']['token']
return None
except Exception as e:
print(f"获取Token失败: {e}")
return None
def test_statistics(token, date):
"""测试事业部开单统计接口"""
url = f"{BASE_URL}/api/Extend/LqDailyReport/get-business-unit-billing-statistics"
headers = {
"Authorization": token,
"Content-Type": "application/json"
}
data = {"date": date}
try:
response = requests.post(url, json=data, headers=headers, timeout=10)
return response.json()
except Exception as e:
print(f"接口调用失败: {e}")
return None
def main():
print("=" * 80)
print("事业部开单统计接口测试(修复后验证)")
print(f"测试日期: {TEST_DATE}")
print("=" * 80)
print()
# 获取Token
print("步骤 1: 获取Token")
token = get_token()
if not token:
print("❌ Token获取失败")
return
print("✓ Token获取成功")
print()
# 调用接口
print(f"步骤 2: 调用接口")
print(f"接口: POST /api/Extend/LqDailyReport/get-business-unit-billing-statistics")
print(f"参数: {{\"date\": \"{TEST_DATE}\"}}")
print()
result = test_statistics(token, TEST_DATE)
if not result:
print("❌ 接口调用失败")
return
# 解析结果
print("步骤 3: 解析结果")
print("-" * 80)
if result.get('code') == 200:
data_list = result.get('data', [])
print(f"✅ 接口调用成功")
print(f"事业部数量: {len(data_list)}")
print()
if not data_list:
print("⚠️ 该日期没有开单数据")
else:
total_performance = sum(unit.get('totalPerformance', 0) for unit in data_list)
total_orders = sum(unit.get('totalOrderCount', 0) for unit in data_list)
print(f"总业绩: {total_performance}")
print(f"总单量: {total_orders}")
print()
# 查找西站店
has_xizhan = False
all_stores = []
xizhan_orders = []
for unit in data_list:
unit_name = unit.get('businessUnitName', '未知事业部')
orders = unit.get('orders', [])
print(f"【{unit_name}】")
print(f" 业绩: {unit.get('totalPerformance', 0)}")
print(f" 单量: {unit.get('totalOrderCount', 0)}")
if orders:
print(f" 开单列表:")
for order in orders:
store_name = order.get('storeName', '未知门店')
amount = order.get('amount', 0)
teacher = order.get('healthTeacherNames', '无')
if '西站' in store_name:
marker = '⭐ 西站店'
has_xizhan = True
xizhan_orders.append({
'unit': unit_name,
'store': store_name,
'amount': amount,
'teacher': teacher,
'orderId': order.get('orderId', '')
})
else:
marker = ' '
print(f" {marker} {store_name}: {amount}元 (健康师: {teacher})")
all_stores.append(store_name)
else:
print(f" (无开单记录)")
print()
print("=" * 80)
if has_xizhan:
print("✅ 找到西站店的开单数据!")
print()
print("西站店开单详情:")
for order in xizhan_orders:
print(f" - 事业部: {order['unit']}")
print(f" 门店: {order['store']}")
print(f" 金额: {order['amount']}元")
print(f" 健康师: {order['teacher']}")
print(f" 开单ID: {order['orderId']}")
print()
else:
print("⚠️ 未找到西站店的开单数据")
if all_stores:
unique_stores = sorted(set(all_stores))
print(f"该日期共有 {len(unique_stores)} 个不同门店的开单:")
for store in unique_stores:
print(f" - {store}")
else:
print(f"❌ 接口调用失败")
print(f"错误码: {result.get('code')}")
print(f"错误信息: {result.get('msg', '未知错误')}")
print()
print("=" * 80)
print("测试完成")
print("=" * 80)
if __name__ == "__main__":
main()