-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopping.cpp
More file actions
executable file
·234 lines (191 loc) · 7.99 KB
/
Copy pathshopping.cpp
File metadata and controls
executable file
·234 lines (191 loc) · 7.99 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include "check_time.h"
#include "database.h"
#include "shopping.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int shopping(char user_id[30], char temp_goods_name[50], char temp_shop_id[50],
int temp_purchase_num) {
int i = 0;
if (!database_goods_index(temp_goods_name, 0)) {
return 0;
}
database_consumer_information(user_id, 0);
while (goods_index[i].in_price != 0) {
if (strcmp(temp_shop_id, goods_index[i].shop_id) == 0)
break;
else
i++;
}
if (temp_purchase_num > goods_index[i].goods_in_stock) {
return 0;
}
// 判断时间
int price_choice = check_time(i);
float temp_price;
if (price_choice)
temp_price = goods_index[i].discount_price;
else
temp_price = goods_index[i].unit_price;
float temp_profit;
temp_profit = temp_price - goods_index[i].in_price;
if (temp_price * temp_purchase_num <= consumer_information.money) {
/************************************************
减掉顾客余额
数据库: consumer_information
************************************************/
consumer_information.money -= temp_price * temp_purchase_num;
database_consumer_information(user_id, 1);
/************************************************
减掉菜品清单中的库存, 销量加1
数据库: goods_index
************************************************/
goods_index[i].goods_in_stock -= temp_purchase_num;
goods_index[i].sales_volume += temp_purchase_num;
database_goods_index(temp_goods_name, 1);
/************************************************
减掉商店清单中的库存, 销量加1
数据库: shop_index
************************************************/
database_shop_index(temp_shop_id, 0);
while (shop_index[i].in_price != 0) {
if (strcmp(temp_goods_name, shop_index[i].goods_name) == 0)
break;
else
i++;
}
shop_index[i].goods_in_stock -= temp_purchase_num;
shop_index[i].sales_volume += temp_purchase_num;
database_shop_index(temp_shop_id, 1);
/************************************************
增加管理员订单all
数据库: order_admin_all
************************************************/
// 找到该货物所对应的饭店名并存入订单
if (!database_order_admin_all(temp_shop_id, 0)) {
for (i = 0; i <= 100; i++) {
strcpy(order_admin_all[i].order_id, ""); // 订单编号
strcpy(order_admin_all[i].consumer_id, ""); // 顾客编号
order_admin_all[i].sold_time.tm_year = 0; // 购买时间
order_admin_all[i].sold_time.tm_mon = 0; // ...
order_admin_all[i].sold_time.tm_mday = 0; // ...
order_admin_all[i].sold_time.tm_hour = 0; // ...
order_admin_all[i].sold_time.tm_min = 0; // ...
strcpy(order_admin_all[i].goods_name, ""); // 菜品名
order_admin_all[i].purchase_num = 0; // 购买数量
order_admin_all[i].unit_price = 0; // 单价
order_admin_all[i].all_price = 0;
} // 总价
database_order_admin_all(temp_shop_id, 1);
}
// 深度探测
i = 0;
while (order_admin_all[i].purchase_num != 0)
i++;
// 找到目前的时间信息并存入字符串
time_t calendar_time = time(NULL);
struct tm *tm_local = localtime(&calendar_time);
char time_str[30];
tm_local->tm_year += 1900; // 处理tm类型偏差
tm_local->tm_mon += 1; // 处理tm类型偏差
sprintf(time_str, "%04d:%02d:%02d:%02d:%02d", tm_local->tm_year,
tm_local->tm_mon, tm_local->tm_mday, tm_local->tm_hour,
tm_local->tm_min);
strcpy(order_admin_all[i].order_id, user_id); // 订单编号
strcat(order_admin_all[i].order_id, ":");
strcat(order_admin_all[i].order_id, time_str);
strcpy(time_str, "");
order_admin_all[i].sold_time.tm_year = tm_local->tm_year; // 记录购买时间
order_admin_all[i].sold_time.tm_mon = tm_local->tm_mon; // ...
order_admin_all[i].sold_time.tm_mday = tm_local->tm_mday; // ...
order_admin_all[i].sold_time.tm_hour = tm_local->tm_hour; // ...
order_admin_all[i].sold_time.tm_min = tm_local->tm_min; // ...
strcpy(order_admin_all[i].consumer_id, user_id); // 顾客ID
strcpy(order_admin_all[i].goods_name, temp_goods_name); // 菜品名
order_admin_all[i].unit_price = temp_price; // 单价
order_admin_all[i].purchase_num = temp_purchase_num; // 购买数量
order_admin_all[i].all_price = temp_price * temp_purchase_num; // 总价
database_order_admin_all(temp_shop_id, 1);
/************************************************
增加管理员订单_goods
数据库: order_admin_goods
************************************************/
if (!database_order_admin_goods(temp_shop_id, 0)) {
database_order_admin_goods(temp_shop_id, 1);
database_order_admin_goods(temp_shop_id, 0);
}
i = 0;
while (order_admin_goods[i].purchase_num != 0) {
if (strcmp(temp_goods_name, order_admin_goods[i].goods_name) == 0)
break;
else
i++;
}
if (order_admin_goods[i].purchase_num == 0) {
strcpy(order_admin_goods[i].goods_name, temp_goods_name); // 菜品名
order_admin_goods[i].purchase_num = temp_purchase_num; // 销量
order_admin_goods[i].all_price = temp_price * temp_purchase_num; // 总价
order_admin_goods[i].profit = temp_profit * temp_purchase_num; // 利润
} else {
order_admin_goods[i].purchase_num += temp_purchase_num; // 销量
order_admin_goods[i].all_price += temp_price * temp_purchase_num; // 总价
order_admin_goods[i].profit += temp_profit * temp_purchase_num; // 利润
}
database_order_admin_goods(temp_shop_id, 1);
/************************************************
增加管理员订单_consumer
数据库: order_admin_consumer
************************************************/
if (!database_order_admin_consumer(temp_shop_id, 0)) {
database_order_admin_consumer(temp_shop_id, 1);
database_order_admin_consumer(temp_shop_id, 0);
}
i = 0;
while (order_admin_consumer[i].purchase_num != 0) {
if (strcmp(user_id, order_admin_consumer[i].consumer_id) == 0)
break;
else
i++;
}
if (order_admin_consumer[i].purchase_num == 0 ||
order_admin_consumer[i].purchase_num < temp_purchase_num) {
strcpy(order_admin_consumer[i].consumer_id, user_id);
strcpy(order_admin_consumer[i].goods_name, temp_goods_name);
order_admin_consumer[i].purchase_num = temp_purchase_num;
}
database_order_admin_consumer(temp_shop_id, 1);
/************************************************
增加顾客订单
数据库: order_consumer
************************************************/
if (!database_order_consumer(user_id, 0)) {
database_order_consumer(user_id, 1);
}
// 深度探测
i = 0;
while (order_consumer[i].purchase_num != 0)
i++;
// 找到目前的时间信息并存入字符串
calendar_time = time(NULL);
struct tm *tm_local2 = localtime(&calendar_time);
tm_local2->tm_year += 1900; // 处理tm类型偏差
tm_local2->tm_mon += 1; // 处理tm类型偏差
sprintf(time_str, "%04d:%02d:%02d:%02d:%02d", tm_local2->tm_year,
tm_local2->tm_mon, tm_local2->tm_mday, tm_local2->tm_hour,
tm_local2->tm_min);
strcpy(order_consumer[i].order_id, user_id); // 订单编号
strcat(order_consumer[i].order_id, ":");
strcat(order_consumer[i].order_id, time_str);
strcpy(order_consumer[i].sold_time, time_str); // 购买时间
strcpy(order_consumer[i].goods_name, temp_goods_name); // 菜品名
order_consumer[i].purchase_num = temp_purchase_num; // 购买数量
order_consumer[i].unit_price = temp_price; // 单价
order_consumer[i].all_price = temp_price * temp_purchase_num; // 总价
database_order_consumer(user_id, 1);
return 1;
}
else
return -1;
return 1;
}