-
Notifications
You must be signed in to change notification settings - Fork 3
/
queries.sql
228 lines (225 loc) · 5.87 KB
/
queries.sql
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
/* CREATE TABLE LOG_ORDERS */
CREATE TABLE `log_orders` (
`auto_id` bigint AUTO_INCREMENT PRIMARY KEY,
`id` int(10) UNSIGNED NULL,
`user_id` int(10) UNSIGNED NULL,
`order_status_id` int(10) UNSIGNED NULL,
`tax` double(5, 2),
`delivery_fee` double(5, 2),
`hint` text NULL,
`active` tinyint(1) NULL,
`driver_id` int(10) UNSIGNED NULL,
`delivery_address_id` int(10) UNSIGNED NULL,
`payment_id` int(10) UNSIGNED NULL,
`created_at` timestamp NULL,
`updated_at` timestamp NULL,
`settlement_driver_id` int(10) UNSIGNED NULL,
`settlement_manager_id` int(10) UNSIGNED NULL,
`unregistered_customer_id` bigint(20) UNSIGNED NULL,
`restaurant_delivery_fee` double(5, 2),
`delivery_coupon_id` int(10) UNSIGNED NULL,
`delivery_coupon_value` double(5, 2),
`restaurant_coupon_id` int(10) UNSIGNED NULL,
`restaurant_coupon_value` double(5, 2),
`restaurant_id` int(10) UNSIGNED NULL,
`for_restaurants` tinyint(1) NULL,
`reason` text NULL,
`processing_time` int(11) NULL,
`operation` text,
`action_time` timestamp DEFAULT now(),
`last_user_action` int(10) UNSIGNED
);
/* INSERT ORDER TRIGGER */
CREATE TRIGGER log_orders_insert
AFTER
INSERT
ON orders FOR EACH ROW
INSERT INTO
`log_orders`(
`id`,
`user_id`,
`order_status_id`,
`tax`,
`delivery_fee`,
`hint`,
`active`,
`driver_id`,
`delivery_address_id`,
`payment_id`,
`created_at`,
`updated_at`,
`settlement_driver_id`,
`settlement_manager_id`,
`unregistered_customer_id`,
`restaurant_delivery_fee`,
`delivery_coupon_id`,
`delivery_coupon_value`,
`restaurant_coupon_id`,
`restaurant_coupon_value`,
`restaurant_id`,
`for_restaurants`,
`reason`,
`processing_time`,
`operation`,
`action_time`,
`last_user_action`
)
VALUES
(
NEW.`id`,
NEW.`user_id`,
NEW.`order_status_id`,
NEW.`tax`,
NEW.`delivery_fee`,
NEW.`hint`,
NEW.`active`,
NEW.`driver_id`,
NEW.`delivery_address_id`,
NEW.`payment_id`,
NEW.`created_at`,
NEW.`updated_at`,
NEW.`settlement_driver_id`,
NEW.`settlement_manager_id`,
NEW.`unregistered_customer_id`,
NEW.`restaurant_delivery_fee`,
NEW.`delivery_coupon_id`,
NEW.`delivery_coupon_value`,
NEW.`restaurant_coupon_id`,
NEW.`restaurant_coupon_value`,
NEW.`restaurant_id`,
NEW.`for_restaurants`,
NEW.`reason`,
NEW.`processing_time`,
'INSERT',
NOW(),
NEW.`last_user_action`
);
/* UPDATE ORDER TRIGGER */
CREATE TRIGGER log_orders_update
AFTER
UPDATE
ON orders FOR EACH ROW
INSERT INTO
`log_orders`(
`id`,
`user_id`,
`order_status_id`,
`tax`,
`delivery_fee`,
`hint`,
`active`,
`driver_id`,
`delivery_address_id`,
`payment_id`,
`created_at`,
`updated_at`,
`settlement_driver_id`,
`settlement_manager_id`,
`unregistered_customer_id`,
`restaurant_delivery_fee`,
`delivery_coupon_id`,
`delivery_coupon_value`,
`restaurant_coupon_id`,
`restaurant_coupon_value`,
`restaurant_id`,
`for_restaurants`,
`reason`,
`processing_time`,
`operation`,
`action_time`,
`last_user_action`
)
VALUES
(
NEW.`id`,
NEW.`user_id`,
NEW.`order_status_id`,
NEW.`tax`,
NEW.`delivery_fee`,
NEW.`hint`,
NEW.`active`,
NEW.`driver_id`,
NEW.`delivery_address_id`,
NEW.`payment_id`,
NEW.`created_at`,
NEW.`updated_at`,
NEW.`settlement_driver_id`,
NEW.`settlement_manager_id`,
NEW.`unregistered_customer_id`,
NEW.`restaurant_delivery_fee`,
NEW.`delivery_coupon_id`,
NEW.`delivery_coupon_value`,
NEW.`restaurant_coupon_id`,
NEW.`restaurant_coupon_value`,
NEW.`restaurant_id`,
NEW.`for_restaurants`,
NEW.`reason`,
NEW.`processing_time`,
'UPDATE',
NOW(),
NEW.`last_user_action`
);
/* DELTE ORDER TRIGGER */
CREATE TRIGGER log_orders_delete
AFTER
DELETE ON orders FOR EACH ROW
INSERT INTO
`log_orders`(
`id`,
`user_id`,
`order_status_id`,
`tax`,
`delivery_fee`,
`hint`,
`active`,
`driver_id`,
`delivery_address_id`,
`payment_id`,
`created_at`,
`updated_at`,
`settlement_driver_id`,
`settlement_manager_id`,
`unregistered_customer_id`,
`restaurant_delivery_fee`,
`delivery_coupon_id`,
`delivery_coupon_value`,
`restaurant_coupon_id`,
`restaurant_coupon_value`,
`restaurant_id`,
`for_restaurants`,
`reason`,
`processing_time`,
`operation`,
`action_time`,
`last_user_action`
)
VALUES
(
OLD.`id`,
OLD.`user_id`,
OLD.`order_status_id`,
OLD.`tax`,
OLD.`delivery_fee`,
OLD.`hint`,
OLD.`active`,
OLD.`driver_id`,
OLD.`delivery_address_id`,
OLD.`payment_id`,
OLD.`created_at`,
OLD.`updated_at`,
OLD.`settlement_driver_id`,
OLD.`settlement_manager_id`,
OLD.`unregistered_customer_id`,
OLD.`restaurant_delivery_fee`,
OLD.`delivery_coupon_id`,
OLD.`delivery_coupon_value`,
OLD.`restaurant_coupon_id`,
OLD.`restaurant_coupon_value`,
OLD.`restaurant_id`,
OLD.`for_restaurants`,
OLD.`reason`,
OLD.`processing_time`,
'DELETE',
NOW(),
OLD.`last_user_action`
);