test_store_dashboard_zijing.sh
4.9 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
#!/bin/bash
# 测试门店驾驶舱统计数据接口 - 绿纤紫荆店
echo "=== 测试门店驾驶舱统计数据接口 - 绿纤紫荆店 ==="
echo ""
# 1. 获取token
echo "=== 1. 获取Token ==="
TOKEN_RESPONSE=$(curl -s -X POST "http://localhost:2011/api/oauth/Login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "account=admin&password=e10adc3949ba59abbe56e057f20f883e")
TOKEN=$(echo "$TOKEN_RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); print(data['data']['token'])" 2>/dev/null)
if [ -z "$TOKEN" ]; then
echo "❌ Token获取失败"
echo "$TOKEN_RESPONSE"
exit 1
fi
echo "✅ Token获取成功"
echo ""
# 2. 测试接口 - 使用当前月份
echo "=== 2. 测试接口 - 绿纤紫荆店 ==="
echo ""
# 绿纤紫荆店门店ID
STORE_ID="1649328471923847169"
# 获取当前月份(YYYYMM格式)
CURRENT_MONTH=$(date +%Y%m)
echo "请求参数:"
echo " - storeId: $STORE_ID (绿纤紫荆店)"
echo " - statisticsMonth: $CURRENT_MONTH"
echo ""
RESPONSE=$(curl -s -X POST "http://localhost:2011/api/Extend/LqStoreDashboard/GetStatistics" \
-H "Authorization: $TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"storeId\": \"$STORE_ID\",
\"statisticsMonth\": \"$CURRENT_MONTH\"
}")
echo "$RESPONSE" | python3 -c "
import sys, json
try:
data = json.load(sys.stdin)
code = data.get('code')
msg = data.get('msg')
result = data.get('data', {})
print('=' * 80)
print('门店驾驶舱统计数据 - 接口测试结果')
print('=' * 80)
print(f'HTTP状态码: {code}')
print(f'消息: {msg}')
print('')
if code == 200:
print('✅ 接口测试成功!')
print('')
print('=' * 80)
print('返回数据:')
print('=' * 80)
print('【核心指标】')
print(f' 开单业绩: ¥{result.get(\"BillingPerformance\", 0):,.2f}')
print(f' 消耗业绩: ¥{result.get(\"ConsumePerformance\", 0):,.2f}')
print(f' 完成率: {result.get(\"CompletionRate\", 0):.2f}%')
print(f' 净业绩: ¥{result.get(\"NetPerformance\", 0):,.2f}')
print('')
print('【业绩概览数据】')
print(f' 开单次数: {result.get(\"BillingCount\", 0):,}')
print(f' 消耗次数: {result.get(\"ConsumeCount\", 0):,}')
print(f' 退卡次数: {result.get(\"RefundCount\", 0):,}')
print(f' 平均开单金额: ¥{result.get(\"AvgBillingAmount\", 0):,.2f}')
print(f' 平均消耗金额: ¥{result.get(\"AvgConsumeAmount\", 0):,.2f}')
print(f' 剩余权益: ¥{result.get(\"RemainingRightsAmount\", 0):,.2f}')
print(f' 目标业绩: ¥{result.get(\"TargetPerformance\", 0):,.2f}')
print(f' 退卡金额: ¥{result.get(\"RefundAmount\", 0):,.2f}')
print('')
# 检查数据是否为0
print('=' * 80)
print('数据检查:')
print('-' * 80)
if result.get('BillingCount', 0) == 0:
print('⚠️ 开单次数为0,可能该月份没有开单数据')
if result.get('ConsumeCount', 0) == 0:
print('⚠️ 消耗次数为0,可能该月份没有消耗数据')
if result.get('RemainingRightsAmount', 0) == 0:
print('⚠️ 剩余权益为0,可能该门店没有会员权益数据')
if result.get('TargetPerformance', 0) == 0:
print('⚠️ 目标业绩为0,可能该月份没有设置目标')
# 验证数据完整性
print('')
print('=' * 80)
print('数据完整性检查:')
print('-' * 80)
required_fields = [
'BillingPerformance', 'ConsumePerformance', 'CompletionRate', 'NetPerformance',
'BillingCount', 'ConsumeCount', 'RefundCount',
'AvgBillingAmount', 'AvgConsumeAmount',
'RemainingRightsAmount', 'TargetPerformance', 'RefundAmount'
]
all_ok = True
for field in required_fields:
if field in result:
value = result[field]
if isinstance(value, (int, float)):
print(f'✅ {field}: {value} (类型正确)')
else:
print(f'❌ {field}: {value} (类型错误,应为数字)')
all_ok = False
else:
print(f'❌ {field}: 缺失')
all_ok = False
if all_ok:
print('')
print('✅ 所有字段都存在且类型正确!')
else:
print(f'❌ 接口返回错误: {msg}')
print('完整响应:')
print(json.dumps(data, indent=2, ensure_ascii=False))
except json.JSONDecodeError as e:
print('❌ JSON解析失败')
print('响应内容:')
print(sys.stdin.read())
except Exception as e:
print(f'❌ 处理失败: {e}')
import traceback
traceback.print_exc()
"
echo ""
echo "=== 测试完成 ==="