test_business_unit_billing_statistics_detailed.sh
4.41 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
#!/bin/bash
# 测试事业部开单统计接口(详细版)
BASE_URL="http://localhost:2011"
TOKEN=""
TEST_DATE="${1:-2026-01-20}"
echo "================================================================================"
echo "事业部开单统计接口测试(详细版)"
echo "测试日期: $TEST_DATE"
echo "================================================================================"
echo ""
# 获取Token
LOGIN_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/oauth/Login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "account=admin&password=e10adc3949ba59abbe56e057f20f883e")
TOKEN=$(echo $LOGIN_RESPONSE | python3 -c "import sys, json; data=json.load(sys.stdin); print(data.get('data', {}).get('token', ''))" 2>/dev/null)
if [ -z "$TOKEN" ]; then
echo "❌ 无法获取Token"
exit 1
fi
# 调用接口
echo "调用接口: POST /api/Extend/LqDailyReport/get-business-unit-billing-statistics"
echo "参数: {\"date\": \"$TEST_DATE\"}"
echo ""
STATISTICS_RESPONSE=$(curl -s -X POST "${BASE_URL}/api/Extend/LqDailyReport/get-business-unit-billing-statistics" \
-H "Authorization: ${TOKEN}" \
-H "Content-Type: application/json" \
-d "{\"date\": \"$TEST_DATE\"}")
# 详细解析结果
python3 <<PYTHON_SCRIPT
import json
try:
response_text = '''$STATISTICS_RESPONSE'''
data = json.loads(response_text)
PYTHON_SCRIPT
echo "$STATISTICS_RESPONSE" | python3 <<'PYTHON_SCRIPT'
import sys, json
try:
data = json.load(sys.stdin)
if data.get('code') == 200:
result = data.get('data', [])
print(f'✅ 接口调用成功')
print(f'事业部数量: {len(result)}')
print()
if not result:
print('⚠️ 该日期没有开单数据')
else:
total_performance = sum(unit.get('totalPerformance', 0) for unit in result)
total_orders = sum(unit.get('totalOrderCount', 0) for unit in result)
print(f'总业绩: {total_performance}')
print(f'总单量: {total_orders}')
print()
# 查找西站店
has_xizhan = False
all_stores = []
for unit in result:
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', '无')
order_time = order.get('orderTime', '')
marker = '⭐ 西站店' if '西站' in store_name else ' '
print(f' {marker} {store_name}: {amount}元 (健康师: {teacher})')
if '西站' in store_name:
has_xizhan = True
all_stores.append(store_name)
else:
print(f' (无开单记录)')
print()
print('=' * 80)
if has_xizhan:
print('✅ 找到西站店的开单数据!')
else:
print('⚠️ 未找到西站店的开单数据')
if all_stores:
print(f'该日期共有 {len(set(all_stores))} 个不同门店的开单:')
for store in sorted(set(all_stores)):
print(f' - {store}')
else:
print(f'❌ 接口调用失败')
print(f'错误码: {data.get(\"code\")}')
print(f'错误信息: {data.get(\"msg\", \"未知错误\")}')
except Exception as e:
print(f'❌ 解析响应失败: {e}')
import traceback
traceback.print_exc()
PYTHON_SCRIPT
echo ""
echo "================================================================================"
echo "完整响应数据(JSON):"
echo "================================================================================"
echo "$STATISTICS_RESPONSE" | python3 -m json.tool 2>/dev/null || echo "$STATISTICS_RESPONSE"