Commit 602ec7e2a9d82b76ea48bbb2c7d0cd76b8066da6
Merge branch 'shipments' into 'master'
add getShipments See merge request !4
Showing
3 changed files
with
623 additions
and
15 deletions
Show diff stats
src/app/frontend/controllers/DealerController.php
@@ -662,13 +662,13 @@ class DealerController extends \controllers\ControllerBase | @@ -662,13 +662,13 @@ class DealerController extends \controllers\ControllerBase | ||
662 | 662 | ||
663 | if($this->session->get('special_users_id') != null) { | 663 | if($this->session->get('special_users_id') != null) { |
664 | 664 | ||
665 | - $orders = $this->models->getOrders()->getOrdersByCustomerId( $this->session->get('id') ); | 665 | + $orders = $this->models->getShipments()->getOrdersByCustomerId( $this->session->get('id') ); |
666 | 666 | ||
667 | foreach($orders as $key => $value) { | 667 | foreach($orders as $key => $value) { |
668 | $orders[$key]['created_date'] = date('d', strtotime($value['created_date'])).'.'. | 668 | $orders[$key]['created_date'] = date('d', strtotime($value['created_date'])).'.'. |
669 | date('m', strtotime($value['created_date'])).'.'. | 669 | date('m', strtotime($value['created_date'])).'.'. |
670 | date('Y', strtotime($value['created_date'])); | 670 | date('Y', strtotime($value['created_date'])); |
671 | - $orders_sum = !empty($this->models->getOrders1C()->getOrdersSumById( $value['id'] )[0]) ? $this->models->getOrders()->getOrdersSumById( $value['id'] )[0] : 0; | 671 | + $orders_sum = !empty($this->models->getShipments()->getOrdersSumById( $value['id'] )[0]) ? $this->models->getShipments()->getOrdersSumById( $value['id'] )[0] : 0; |
672 | $orders[$key]['price'] = $orders_sum['price']; | 672 | $orders[$key]['price'] = $orders_sum['price']; |
673 | $orders[$key]['status'] = \config::get( 'global#status/'.$this->lang_id.'/'.$value['status'] ); | 673 | $orders[$key]['status'] = \config::get( 'global#status/'.$this->lang_id.'/'.$value['status'] ); |
674 | } | 674 | } |
src/lib/models.php
@@ -19,6 +19,7 @@ namespace | @@ -19,6 +19,7 @@ namespace | ||
19 | protected $_properties = false; | 19 | protected $_properties = false; |
20 | protected $_orders = false; | 20 | protected $_orders = false; |
21 | protected $_orders_1c = false; | 21 | protected $_orders_1c = false; |
22 | + protected $_shipments = false; | ||
22 | protected $_pages = false; | 23 | protected $_pages = false; |
23 | protected $_news = false; | 24 | protected $_news = false; |
24 | protected $_customers = false; | 25 | protected $_customers = false; |
@@ -64,7 +65,7 @@ namespace | @@ -64,7 +65,7 @@ namespace | ||
64 | * @author Jane Bezmaternykh | 65 | * @author Jane Bezmaternykh |
65 | * @version 0.1.20140321 | 66 | * @version 0.1.20140321 |
66 | * | 67 | * |
67 | - * @return obj | 68 | + * @return object |
68 | */ | 69 | */ |
69 | public function getFilters() | 70 | public function getFilters() |
70 | { | 71 | { |
@@ -105,7 +106,7 @@ namespace | @@ -105,7 +106,7 @@ namespace | ||
105 | * @author Jane Bezmaternykh | 106 | * @author Jane Bezmaternykh |
106 | * @version 0.1.20140327 | 107 | * @version 0.1.20140327 |
107 | * | 108 | * |
108 | - * @return obj | 109 | + * @return object |
109 | */ | 110 | */ |
110 | public function getRubricsNews() | 111 | public function getRubricsNews() |
111 | { | 112 | { |
@@ -126,7 +127,7 @@ namespace | @@ -126,7 +127,7 @@ namespace | ||
126 | * @author Jane Bezmaternykh | 127 | * @author Jane Bezmaternykh |
127 | * @version 0.1.20140404 | 128 | * @version 0.1.20140404 |
128 | * | 129 | * |
129 | - * @return obj | 130 | + * @return object |
130 | */ | 131 | */ |
131 | public function getProperties() | 132 | public function getProperties() |
132 | { | 133 | { |
@@ -147,7 +148,7 @@ namespace | @@ -147,7 +148,7 @@ namespace | ||
147 | * @author Jane Bezmaternykh | 148 | * @author Jane Bezmaternykh |
148 | * @version 0.1.20140422 | 149 | * @version 0.1.20140422 |
149 | * | 150 | * |
150 | - * @return obj | 151 | + * @return object |
151 | */ | 152 | */ |
152 | public function getOrders() | 153 | public function getOrders() |
153 | { | 154 | { |
@@ -168,7 +169,7 @@ namespace | @@ -168,7 +169,7 @@ namespace | ||
168 | * @author Jane Bezmaternykh | 169 | * @author Jane Bezmaternykh |
169 | * @version 0.1.20140422 | 170 | * @version 0.1.20140422 |
170 | * | 171 | * |
171 | - * @return obj | 172 | + * @return object |
172 | */ | 173 | */ |
173 | public function getOrders1C() | 174 | public function getOrders1C() |
174 | { | 175 | { |
@@ -180,6 +181,26 @@ namespace | @@ -180,6 +181,26 @@ namespace | ||
180 | 181 | ||
181 | return $this->_orders_1c; | 182 | return $this->_orders_1c; |
182 | } | 183 | } |
184 | + ///////////////////////////////////////////////////////////////////////////// | ||
185 | + | ||
186 | + /** | ||
187 | + * models::getShipments | ||
188 | + * | ||
189 | + * @author Jane Bezmaternykh | ||
190 | + * @version 0.1.20140422 | ||
191 | + * | ||
192 | + * @return object | ||
193 | + */ | ||
194 | + public function getShipments() | ||
195 | + { | ||
196 | + if( empty($this->_shipments) ) | ||
197 | + { | ||
198 | + $this->_shipments = new \models\shipments(); | ||
199 | + $this->_shipments->setDi( $this->getDi() ); | ||
200 | + } | ||
201 | + | ||
202 | + return $this->_shipments; | ||
203 | + } | ||
183 | 204 | ||
184 | ///////////////////////////////////////////////////////////////////////////// | 205 | ///////////////////////////////////////////////////////////////////////////// |
185 | 206 | ||
@@ -189,7 +210,7 @@ namespace | @@ -189,7 +210,7 @@ namespace | ||
189 | * @author Jane Bezmaternykh | 210 | * @author Jane Bezmaternykh |
190 | * @version 0.1.20140423 | 211 | * @version 0.1.20140423 |
191 | * | 212 | * |
192 | - * @return obj | 213 | + * @return object |
193 | */ | 214 | */ |
194 | public function getPages() | 215 | public function getPages() |
195 | { | 216 | { |
@@ -210,7 +231,7 @@ namespace | @@ -210,7 +231,7 @@ namespace | ||
210 | * @author Jane Bezmaternykh | 231 | * @author Jane Bezmaternykh |
211 | * @version 0.1.20140423 | 232 | * @version 0.1.20140423 |
212 | * | 233 | * |
213 | - * @return obj | 234 | + * @return object |
214 | */ | 235 | */ |
215 | public function getNews() | 236 | public function getNews() |
216 | { | 237 | { |
@@ -231,7 +252,7 @@ namespace | @@ -231,7 +252,7 @@ namespace | ||
231 | * @author Jane Bezmaternykh | 252 | * @author Jane Bezmaternykh |
232 | * @version 0.1.20140425 | 253 | * @version 0.1.20140425 |
233 | * | 254 | * |
234 | - * @return obj | 255 | + * @return object |
235 | */ | 256 | */ |
236 | public function getCustomers() | 257 | public function getCustomers() |
237 | { | 258 | { |
@@ -252,7 +273,7 @@ namespace | @@ -252,7 +273,7 @@ namespace | ||
252 | * @author Jane Bezmaternykh | 273 | * @author Jane Bezmaternykh |
253 | * @version 0.1.20140428 | 274 | * @version 0.1.20140428 |
254 | * | 275 | * |
255 | - * @return obj | 276 | + * @return object |
256 | */ | 277 | */ |
257 | public function getCatalog() | 278 | public function getCatalog() |
258 | { | 279 | { |
@@ -273,7 +294,7 @@ namespace | @@ -273,7 +294,7 @@ namespace | ||
273 | * @author Jane Bezmaternykh | 294 | * @author Jane Bezmaternykh |
274 | * @version 0.1.20140505 | 295 | * @version 0.1.20140505 |
275 | * | 296 | * |
276 | - * @return obj | 297 | + * @return object |
277 | */ | 298 | */ |
278 | public function getAdmins() | 299 | public function getAdmins() |
279 | { | 300 | { |
@@ -294,7 +315,7 @@ namespace | @@ -294,7 +315,7 @@ namespace | ||
294 | * @author Jane Bezmaternykh | 315 | * @author Jane Bezmaternykh |
295 | * @version 0.1.20140506 | 316 | * @version 0.1.20140506 |
296 | * | 317 | * |
297 | - * @return obj | 318 | + * @return object |
298 | */ | 319 | */ |
299 | public function getPartners() | 320 | public function getPartners() |
300 | { | 321 | { |
@@ -315,7 +336,7 @@ namespace | @@ -315,7 +336,7 @@ namespace | ||
315 | * @author Jane Bezmaternykh | 336 | * @author Jane Bezmaternykh |
316 | * @version 0.1.20140507 | 337 | * @version 0.1.20140507 |
317 | * | 338 | * |
318 | - * @return obj | 339 | + * @return object |
319 | */ | 340 | */ |
320 | public function getCallback() | 341 | public function getCallback() |
321 | { | 342 | { |
@@ -334,7 +355,7 @@ namespace | @@ -334,7 +355,7 @@ namespace | ||
334 | * @author Vitaliy | 355 | * @author Vitaliy |
335 | * @version 0.1.20140507 | 356 | * @version 0.1.20140507 |
336 | * | 357 | * |
337 | - * @return obj | 358 | + * @return object |
338 | */ | 359 | */ |
339 | public function getSeoInfo() | 360 | public function getSeoInfo() |
340 | { | 361 | { |
1 | +<?php | ||
2 | + | ||
3 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
4 | + | ||
5 | +namespace models; | ||
6 | + | ||
7 | +class shipments extends \db | ||
8 | +{ | ||
9 | + ///////////////////////////////////////////////////////////////////////////// | ||
10 | + | ||
11 | + public function addOrder( $order) | ||
12 | + { | ||
13 | + $connection = $this->database; | ||
14 | + $this->updateOrderId(); | ||
15 | + try | ||
16 | + | ||
17 | + { | ||
18 | + $connection->begin(); | ||
19 | + if( !empty( $order['email'] ) ) | ||
20 | + { | ||
21 | + $data_customer_isset = $this->get( | ||
22 | + ' | ||
23 | + SELECT | ||
24 | + id, | ||
25 | + status | ||
26 | + FROM | ||
27 | + public.customers | ||
28 | + WHERE | ||
29 | + email = :email | ||
30 | + LIMIT | ||
31 | + 1 | ||
32 | + ', | ||
33 | + [ | ||
34 | + 'email' => $order['email'] | ||
35 | + ], | ||
36 | + -1 | ||
37 | + ); | ||
38 | + } | ||
39 | + else | ||
40 | + { | ||
41 | + $data_customer_isset = $this->get( | ||
42 | + ' | ||
43 | + SELECT | ||
44 | + id, | ||
45 | + status | ||
46 | + FROM | ||
47 | + public.customers | ||
48 | + WHERE | ||
49 | + phone = :phone | ||
50 | + LIMIT | ||
51 | + 1 | ||
52 | + ', | ||
53 | + [ | ||
54 | + 'phone' => $order['phone'] | ||
55 | + ], | ||
56 | + -1 | ||
57 | + ); | ||
58 | + } | ||
59 | + | ||
60 | + if( empty( $data_customer_isset ) ) // new customer | ||
61 | + { | ||
62 | + $data_confirm_key = $this->getDi()->get('models')->getCustomers()->addNewCustomer( $order ); | ||
63 | + $confirmed = 0; | ||
64 | + $new = 1; | ||
65 | + $customer_id = $data_confirm_key['0']['id']; | ||
66 | + } | ||
67 | + elseif( !empty( $data_customer_isset ) and $data_customer_isset['0']['status'] == 0 ) // the customer do not finish registration | ||
68 | + { | ||
69 | + $confirmed = 0; | ||
70 | + $new = 0; | ||
71 | + $customer_id = $data_customer_isset['0']['id']; | ||
72 | + } | ||
73 | + elseif( !empty( $data_customer_isset ) and $data_customer_isset['0']['status'] == 1 ) // the customer finish registration | ||
74 | + { | ||
75 | + $confirmed = 1; | ||
76 | + $new = 0; | ||
77 | + $customer_id = $data_customer_isset['0']['id']; | ||
78 | + } | ||
79 | + $data_orders = $this->get( | ||
80 | + ' | ||
81 | + INSERT INTO | ||
82 | + public.shipments | ||
83 | + ( | ||
84 | + customer_id, | ||
85 | + name, | ||
86 | + phone, | ||
87 | + city, | ||
88 | + address, | ||
89 | + delivery, | ||
90 | + pay, | ||
91 | + email, | ||
92 | + comments, | ||
93 | + action_discount_id, | ||
94 | + firm_total, | ||
95 | + promo_code | ||
96 | + ) | ||
97 | + VALUES | ||
98 | + ( | ||
99 | + :customer_id, | ||
100 | + :name, | ||
101 | + :phone, | ||
102 | + :city, | ||
103 | + :address, | ||
104 | + :delivery, | ||
105 | + :pay, | ||
106 | + :email, | ||
107 | + :comments, | ||
108 | + :action_discount_id, | ||
109 | + :firm_total, | ||
110 | + :promo_code | ||
111 | + ) | ||
112 | + RETURNING id | ||
113 | + ', | ||
114 | + [ | ||
115 | + 'customer_id' => $customer_id, | ||
116 | + 'name' => $order['name'], | ||
117 | + 'phone' => $order['phone'], | ||
118 | + 'city' => $order['city'], | ||
119 | + 'address' => $order['address'], | ||
120 | + 'delivery' => $order['delivery'], | ||
121 | + 'pay' => $order['pay'], | ||
122 | + 'email' => $order['email'], | ||
123 | + 'comments' => $order['comments'], | ||
124 | + 'action_discount_id' => isset($order['action_id']) ? $order['action_id'] : null, | ||
125 | + 'firm_total' => isset($order['firm_total']) ? $order['firm_total'] : null, | ||
126 | + 'promo_code' => isset($order['promo_code']) ? $order['promo_code'] : null | ||
127 | + ], | ||
128 | + -1 | ||
129 | + ); | ||
130 | + | ||
131 | + foreach( $order['items'] as $i ) | ||
132 | + { | ||
133 | + $data_orders2items = $this->get( | ||
134 | + ' | ||
135 | + INSERT INTO | ||
136 | + public.shipments2items | ||
137 | + ( | ||
138 | + order_id, | ||
139 | + item_id, | ||
140 | + item_count, | ||
141 | + price | ||
142 | + ) | ||
143 | + VALUES | ||
144 | + ( | ||
145 | + :order_id, | ||
146 | + :item_id, | ||
147 | + :item_count, | ||
148 | + :price | ||
149 | + ) | ||
150 | + ', | ||
151 | + [ | ||
152 | + 'order_id' => $data_orders['0']['id'], | ||
153 | + 'item_id' => $i['id'], | ||
154 | + 'item_count' => $i['count'], | ||
155 | + 'price' => $i['price2'] | ||
156 | + ] | ||
157 | + ); | ||
158 | + } | ||
159 | + | ||
160 | + $data = | ||
161 | + [ | ||
162 | + 'proposal_number' => $data_orders['0']['id'], | ||
163 | + 'confirmed' => $confirmed, | ||
164 | + 'new' => $new, | ||
165 | + ]; | ||
166 | + | ||
167 | + if( $order['delivery'] == 3 || $order['delivery'] == 4 ) | ||
168 | + { | ||
169 | + switch( $order['delivery'] ) | ||
170 | + { | ||
171 | + case 3: | ||
172 | + default: | ||
173 | + $order['rcpt_warehouse'] = substr( $order['store_address'], 0, strpos( $order['store_address'], '-' ) ); | ||
174 | + $order['novaposhta_tnn'] = $this->getDi()->get('novaposhta')->ttn( $data_orders['0']['id'], $order['city'], $order['rcpt_warehouse'], NULL, $order['name'], $order['phone'], '10', $order['total_sum'] ); | ||
175 | + //$order['novaposhta_tnn'] = $this->getDi()->get('novaposhta')->ttn_ref( $data_orders['0']['id'], $order['city_ref'], $order['store_ref'], NULL, $order['name'], $order['phone'], '10', $order['total_sum'] ); | ||
176 | + break; | ||
177 | + case 4: | ||
178 | + $order['novaposhta_tnn'] = $this->getDi()->get('novaposhta')->ttn( $data_orders['0']['id'], $order['city'], NULL, $order['address'], $order['name'], $order['phone'], '10', $order['total_sum'] ); | ||
179 | + break; | ||
180 | + | ||
181 | + | ||
182 | + } | ||
183 | + | ||
184 | + if( !empty( $order['novaposhta_tnn'] ) && !empty( $data_orders['0']['id'] ) ) | ||
185 | + { | ||
186 | + $this->addNovaposhtaTnn( $order['novaposhta_tnn'], $data_orders['0']['id'] ); | ||
187 | + $data['novaposhta_tnn'] = $order['novaposhta_tnn']; | ||
188 | + } | ||
189 | + } | ||
190 | + | ||
191 | + $connection->commit(); | ||
192 | + return $data; | ||
193 | + } | ||
194 | + catch(\Exception $e) | ||
195 | + { | ||
196 | + $connection->rollback(); | ||
197 | + } | ||
198 | + | ||
199 | + return false; | ||
200 | + } | ||
201 | + | ||
202 | + ///////////////////////////////////////////////////////////////////////////// | ||
203 | + | ||
204 | + public function addNovaposhtaTnn( $tnn, $order_id ) | ||
205 | + { | ||
206 | + return $this->exec( | ||
207 | + ' | ||
208 | + UPDATE | ||
209 | + public.shipments | ||
210 | + SET | ||
211 | + novaposhta_tnn = :novaposhta_tnn | ||
212 | + WHERE | ||
213 | + id = :id | ||
214 | + ', | ||
215 | + [ | ||
216 | + 'novaposhta_tnn' => $tnn, | ||
217 | + 'id' => $order_id | ||
218 | + ] | ||
219 | + ); | ||
220 | + } | ||
221 | + | ||
222 | + ///////////////////////////////////////////////////////////////////////////// | ||
223 | + | ||
224 | + public function getOrdersSumById($id) { | ||
225 | + return $this->get( | ||
226 | + ' | ||
227 | + SELECT | ||
228 | + SUM((price * item_count)) as price | ||
229 | + FROM | ||
230 | + public.shipments2items | ||
231 | + WHERE | ||
232 | + order_id = :id | ||
233 | + GROUP BY | ||
234 | + order_id | ||
235 | + ', | ||
236 | + [ | ||
237 | + 'id' => $id, | ||
238 | + ], | ||
239 | + -1 | ||
240 | + ); | ||
241 | + } | ||
242 | + | ||
243 | + public function getOrdersByCustomerId( $customer_id ) | ||
244 | + { | ||
245 | + return $this->get( | ||
246 | + ' | ||
247 | + SELECT | ||
248 | + id, | ||
249 | + created_date, | ||
250 | + status, | ||
251 | + delivery | ||
252 | + FROM | ||
253 | + public.shipments | ||
254 | + WHERE | ||
255 | + customer_id = :customer_id | ||
256 | + ORDER BY id DESC | ||
257 | + ', | ||
258 | + [ | ||
259 | + 'customer_id' => $customer_id | ||
260 | + ], | ||
261 | + -1 | ||
262 | + ); | ||
263 | + } | ||
264 | + | ||
265 | + ///////////////////////////////////////////////////////////////////////////// | ||
266 | + | ||
267 | + public function getOrdersByOrderId( $order_id, $lang_id ) | ||
268 | + { | ||
269 | + return $this->get( | ||
270 | + ' | ||
271 | + SELECT | ||
272 | + item_id, | ||
273 | + item_count, | ||
274 | + ( | ||
275 | + SELECT | ||
276 | + group_id | ||
277 | + FROM | ||
278 | + public.items | ||
279 | + WHERE | ||
280 | + id = public.shipments2items.item_id | ||
281 | + LIMIT 1 | ||
282 | + ) AS group_id, | ||
283 | + ( | ||
284 | + SELECT | ||
285 | + firm | ||
286 | + FROM | ||
287 | + public.items | ||
288 | + WHERE | ||
289 | + id = public.shipments2items.item_id | ||
290 | + LIMIT 1 | ||
291 | + ) AS firm, | ||
292 | + ( | ||
293 | + SELECT | ||
294 | + price2 | ||
295 | + FROM | ||
296 | + public.items | ||
297 | + WHERE | ||
298 | + id = public.shipments2items.item_id | ||
299 | + LIMIT 1 | ||
300 | + ) AS price2, | ||
301 | + ( | ||
302 | + SELECT | ||
303 | + size | ||
304 | + FROM | ||
305 | + public.items | ||
306 | + WHERE | ||
307 | + id = public.shipments2items.item_id | ||
308 | + LIMIT 1 | ||
309 | + ) AS size, | ||
310 | + ( | ||
311 | + SELECT | ||
312 | + title | ||
313 | + FROM | ||
314 | + public.items_i18n | ||
315 | + WHERE | ||
316 | + item_id = public.shipments2items.item_id | ||
317 | + AND | ||
318 | + lang_id = :lang_id | ||
319 | + LIMIT 1 | ||
320 | + ) AS title, | ||
321 | + ( | ||
322 | + SELECT | ||
323 | + alias | ||
324 | + FROM | ||
325 | + public.items_group_alias | ||
326 | + WHERE | ||
327 | + group_id = | ||
328 | + ( | ||
329 | + SELECT | ||
330 | + group_id | ||
331 | + FROM | ||
332 | + public.items | ||
333 | + WHERE | ||
334 | + id = public.shipments2items.item_id | ||
335 | + LIMIT 1 | ||
336 | + ) | ||
337 | + LIMIT 1 | ||
338 | + ) AS group_alias, | ||
339 | + ( | ||
340 | + SELECT | ||
341 | + cover | ||
342 | + FROM | ||
343 | + public.items_group | ||
344 | + WHERE | ||
345 | + group_id = | ||
346 | + ( | ||
347 | + SELECT | ||
348 | + group_id | ||
349 | + FROM | ||
350 | + public.items | ||
351 | + WHERE | ||
352 | + id = public.shipments2items.item_id | ||
353 | + LIMIT 1 | ||
354 | + ) | ||
355 | + LIMIT 1 | ||
356 | + ) as cover, | ||
357 | + ( | ||
358 | + SELECT | ||
359 | + alias | ||
360 | + FROM | ||
361 | + public.types_i18n | ||
362 | + WHERE | ||
363 | + type = | ||
364 | + ( | ||
365 | + SELECT | ||
366 | + type | ||
367 | + FROM | ||
368 | + public.items | ||
369 | + WHERE | ||
370 | + id = public.shipments2items.item_id | ||
371 | + LIMIT 1 | ||
372 | + ) | ||
373 | + AND | ||
374 | + lang_id = :lang_id | ||
375 | + LIMIT 1 | ||
376 | + ) AS type_alias, | ||
377 | + ( | ||
378 | + SELECT | ||
379 | + alias | ||
380 | + FROM | ||
381 | + public.subtypes_i18n | ||
382 | + WHERE | ||
383 | + subtype = | ||
384 | + ( | ||
385 | + SELECT | ||
386 | + subtype | ||
387 | + FROM | ||
388 | + public.items | ||
389 | + WHERE | ||
390 | + id = public.shipments2items.item_id | ||
391 | + LIMIT 1 | ||
392 | + ) | ||
393 | + AND | ||
394 | + type = | ||
395 | + ( | ||
396 | + SELECT | ||
397 | + type | ||
398 | + FROM | ||
399 | + public.items | ||
400 | + WHERE | ||
401 | + id = public.shipments2items.item_id | ||
402 | + LIMIT 1 | ||
403 | + ) | ||
404 | + AND | ||
405 | + lang_id = :lang_id | ||
406 | + ) AS subtype_alias | ||
407 | + FROM | ||
408 | + public.shipments2items | ||
409 | + WHERE | ||
410 | + order_id = :order_id | ||
411 | + ', | ||
412 | + [ | ||
413 | + 'order_id' => $order_id, | ||
414 | + 'lang_id' => $lang_id | ||
415 | + ], | ||
416 | + -1 | ||
417 | + ); | ||
418 | + } | ||
419 | + | ||
420 | + ///////////////////////////////////////////////////////////////////////////// | ||
421 | + | ||
422 | + ///////////////////////////////////////////////////////////////////////////// | ||
423 | + | ||
424 | + ///////////////////////////////////////////////////////////////////////////// | ||
425 | + | ||
426 | + public function getAllOrders( $page ) | ||
427 | + { | ||
428 | + return $this->get( | ||
429 | + ' | ||
430 | + SELECT | ||
431 | + id, | ||
432 | + name, | ||
433 | + created_date, | ||
434 | + phone, | ||
435 | + comments, | ||
436 | + status, | ||
437 | + status_pay, | ||
438 | + delivery | ||
439 | + FROM | ||
440 | + public.shipments | ||
441 | + ORDER BY | ||
442 | + created_date | ||
443 | + LIMIT | ||
444 | + '.\config::get( 'limits/admin_orders' ).' | ||
445 | + OFFSET | ||
446 | + '.($page-1)*(\config::get( 'limits/admin_orders' )) | ||
447 | + , | ||
448 | + [ | ||
449 | + | ||
450 | + ], | ||
451 | + -1 | ||
452 | + ); | ||
453 | + } | ||
454 | + | ||
455 | + ///////////////////////////////////////////////////////////////////////////// | ||
456 | + | ||
457 | + public function getSortedOrders( $sort_type, $sort_id, $page ) | ||
458 | + { | ||
459 | + return $this->get( | ||
460 | + ' | ||
461 | + SELECT | ||
462 | + id, | ||
463 | + name, | ||
464 | + created_date, | ||
465 | + phone, | ||
466 | + comments, | ||
467 | + status, | ||
468 | + status_pay, | ||
469 | + delivery | ||
470 | + FROM | ||
471 | + public.shipments | ||
472 | + WHERE | ||
473 | + '.$sort_type.' = '.$sort_id.' | ||
474 | + ORDER BY | ||
475 | + created_date | ||
476 | + LIMIT | ||
477 | + '.\config::get( 'limits/admin_orders' ).' | ||
478 | + OFFSET | ||
479 | + '.($page-1)*(\config::get( 'limits/admin_orders' )) | ||
480 | + , | ||
481 | + [ | ||
482 | + | ||
483 | + ], | ||
484 | + -1 | ||
485 | + ); | ||
486 | + } | ||
487 | + | ||
488 | + ///////////////////////////////////////////////////////////////////////////// | ||
489 | + | ||
490 | + public function getOrdersWithIds( $orders_ids ) | ||
491 | + { | ||
492 | + return $this->get( | ||
493 | + ' | ||
494 | + SELECT | ||
495 | + order_id, | ||
496 | + item_count, | ||
497 | + price | ||
498 | + FROM | ||
499 | + public.shipments2items | ||
500 | + WHERE | ||
501 | + order_id IN ('.join( ',', $orders_ids ).') | ||
502 | + ', | ||
503 | + [ | ||
504 | + | ||
505 | + ], | ||
506 | + -1 | ||
507 | + ); | ||
508 | + } | ||
509 | + | ||
510 | + ///////////////////////////////////////////////////////////////////////////// | ||
511 | + | ||
512 | + public function countAllOrders() | ||
513 | + { | ||
514 | + return $this->get( | ||
515 | + ' | ||
516 | + SELECT | ||
517 | + COUNT(id) AS total | ||
518 | + FROM | ||
519 | + public.shipments | ||
520 | + ', | ||
521 | + [ | ||
522 | + | ||
523 | + ], | ||
524 | + -1 | ||
525 | + ); | ||
526 | + } | ||
527 | + | ||
528 | + ///////////////////////////////////////////////////////////////////////////// | ||
529 | + | ||
530 | + public function countSortedOrders( $sort_type, $sort_id ) | ||
531 | + { | ||
532 | + return $this->get( | ||
533 | + ' | ||
534 | + SELECT | ||
535 | + COUNT(id) AS total | ||
536 | + FROM | ||
537 | + public.shipments | ||
538 | + WHERE | ||
539 | + '.$sort_type.' = '.$sort_id.' | ||
540 | + ', | ||
541 | + [ | ||
542 | + | ||
543 | + ], | ||
544 | + -1 | ||
545 | + ); | ||
546 | + } | ||
547 | + | ||
548 | + ///////////////////////////////////////////////////////////////////////////// | ||
549 | + | ||
550 | + public function countStatus() | ||
551 | + { | ||
552 | + return $this->get( | ||
553 | + ' | ||
554 | + SELECT | ||
555 | + COUNT(status) AS total, | ||
556 | + status | ||
557 | + FROM | ||
558 | + public.shipments | ||
559 | + GROUP BY | ||
560 | + status | ||
561 | + ', | ||
562 | + [ | ||
563 | + | ||
564 | + ], | ||
565 | + -1 | ||
566 | + ); | ||
567 | + } | ||
568 | + | ||
569 | + public function updateOrderId() | ||
570 | + { | ||
571 | + return $this->get( | ||
572 | + " | ||
573 | + SELECT setval('orders_id_seq', (SELECT MAX(id) FROM public.shipments)) | ||
574 | + ", | ||
575 | + [ | ||
576 | + | ||
577 | + ], | ||
578 | + -1 | ||
579 | + ); | ||
580 | + } | ||
581 | + | ||
582 | + ///////////////////////////////////////////////////////////////////////////// | ||
583 | + | ||
584 | + | ||
585 | +} | ||
586 | + | ||
587 | +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// | ||
0 | \ No newline at end of file | 588 | \ No newline at end of file |