diff --git a/mirzaev/skillparts/system/config/web.php.example b/mirzaev/skillparts/system/config/web.php.example index cdc1c00..4f8eec4 100644 --- a/mirzaev/skillparts/system/config/web.php.example +++ b/mirzaev/skillparts/system/config/web.php.example @@ -97,6 +97,7 @@ $config = [ 'product/' => 'product/index', '///' => '
/-', 'orders' => 'order/index', + 'orders/' => 'order/index', 'orders/<_key:[^/]+>/' => 'order/', 'orders/supply/<_key:[^/]+>/' => 'order/supply-', 'orders/supply/<_key:[^/]+>//' => 'order/supply--', diff --git a/mirzaev/skillparts/system/controllers/AuthenticationController.php b/mirzaev/skillparts/system/controllers/AuthenticationController.php index 2ec840e..029603d 100644 --- a/mirzaev/skillparts/system/controllers/AuthenticationController.php +++ b/mirzaev/skillparts/system/controllers/AuthenticationController.php @@ -76,13 +76,13 @@ class AuthenticationController extends Controller // Запись ответа $return['redirect'] = '/' . $cookies['redirect']; - try { - if (empty($return['main'] = $this->renderPartial($return['redirect']))) { - throw new Exception('Представление найдено, но вернуло пустой результат'); - } - } catch (Throwable $t) { - $return['main'] = $this->renderPartial($return['redirect'] . '/index'); - } + // try { + // if (empty($return['main'] = $this->renderPartial($return['redirect']))) { + // throw new Exception('Представление найдено, но вернуло пустой результат'); + // } + // } catch (Throwable $t) { + // $return['main'] = $this->renderPartial($return['redirect'] . '/index'); + // } // Генерация и запись // $controller = 'app\\controllers\\' . ucfirst($cookies['redirect']) . 'Controller'; @@ -91,6 +91,11 @@ class AuthenticationController extends Controller // Очистка cookie unset(yii::$app->response->cookies['redirect']); + + yii::$app->response->format = Response::FORMAT_HTML; + + // Переадресация + return $this->redirect($return['redirect']); } else { // Не найдено cookie с переадресацией diff --git a/mirzaev/skillparts/system/controllers/OrderController.php b/mirzaev/skillparts/system/controllers/OrderController.php index 058aa8c..e2d019f 100644 --- a/mirzaev/skillparts/system/controllers/OrderController.php +++ b/mirzaev/skillparts/system/controllers/OrderController.php @@ -90,10 +90,10 @@ class OrderController extends Controller } } - public function actionIndex() + public function actionIndex(string $type = 'all') { // Инициализация - $orders = Order::search(type: 'all', limit: 10, page: 1, select: '{account_edge_order, order}', supplies: true); + $orders = Order::search(type: $type, limit: 10, page: 1, select: '{account_edge_order, order}', supplies: true); $moderator_orders = self::genOrdersForModeration(); if (yii::$app->request->isPost) { diff --git a/mirzaev/skillparts/system/controllers/ProfileController.php b/mirzaev/skillparts/system/controllers/ProfileController.php index d4fb16c..912ffc4 100644 --- a/mirzaev/skillparts/system/controllers/ProfileController.php +++ b/mirzaev/skillparts/system/controllers/ProfileController.php @@ -31,11 +31,6 @@ class ProfileController extends Controller 'roles' => ['@'], 'actions' => ['index', 'supplies', 'import', 'monitoring', 'readGroups'] ], - [ - 'allow' => false, - 'roles' => ['?'], - 'denyCallback' => [$this, 'accessDenied'] - ], [ 'allow' => true, 'actions' => ['panel', 'panel-notification-write'], @@ -49,6 +44,11 @@ class ProfileController extends Controller return false; } + ], + [ + 'allow' => false, + 'roles' => ['?'], + 'denyCallback' => [$this, 'accessDenied'] ] ] ] diff --git a/mirzaev/skillparts/system/controllers/RegistrationController.php b/mirzaev/skillparts/system/controllers/RegistrationController.php index 95ae540..cf97c53 100644 --- a/mirzaev/skillparts/system/controllers/RegistrationController.php +++ b/mirzaev/skillparts/system/controllers/RegistrationController.php @@ -68,10 +68,27 @@ class RegistrationController extends Controller // Запись ответа $return['redirect'] = '/' . $cookies['redirect']; - $return['main'] = $this->renderPartial($return['redirect'] . '/index'); + + // try { + // if (empty($return['main'] = $this->renderPartial($return['redirect']))) { + // throw new Exception('Представление найдено, но вернуло пустой результат'); + // } + // } catch (Throwable $t) { + // $return['main'] = $this->renderPartial($return['redirect'] . '/index'); + // } + + // Генерация и запись + // $controller = 'app\\controllers\\' . ucfirst($cookies['redirect']) . 'Controller'; + // $action = 'action' . ucfirst($cookies['redirect_action']); + // $return['main'] = (new $controller())->$action(); // Очистка cookie unset(yii::$app->response->cookies['redirect']); + + yii::$app->response->format = Response::FORMAT_HTML; + + // Переадресация + return $this->redirect($return['redirect']); } else { // Не найдено cookie с переадресацией diff --git a/mirzaev/skillparts/system/controllers/SearchController.php b/mirzaev/skillparts/system/controllers/SearchController.php index 12c8af5..0fbf2a3 100644 --- a/mirzaev/skillparts/system/controllers/SearchController.php +++ b/mirzaev/skillparts/system/controllers/SearchController.php @@ -186,6 +186,7 @@ class SearchController extends Controller try { // Инициализация данных геолокации + try { $from = (int) $connection['account']['opts']['delivery_from_terminal'] ?? Settings::search()->delivery_from_default ?? 36; } catch (Exception $e) { @@ -246,11 +247,13 @@ class SearchController extends Controller $connection['cost'] = ($cost['ЦенаЗаЕдиницу'] ?? $connection['supply_edge_product'][0]['onec']['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($connection['delivery']['price']['all'] ?? $connection['delivery']['price']['one'] ?? 0) + ($settings['increase'] ?? 0); // Инициализация версии для рассчета доставки по воздуху - $buffer = $connection; + $buffer_delivery_avia = $connection; + + try { + // Инициализация данных геолокации - try { // Инициализация данных геолокации try { - $from = (int) $connection['account']['opts']['delivery_from_terminal'] ?? Settings::search()->delivery_from_default ?? 36; + $from = (int) $buffer_delivery_avia['account']['opts']['delivery_from_terminal'] ?? Settings::search()->delivery_from_default ?? 36; } catch (Exception $e) { $from = (int) Settings::search()->delivery_from_default ?? 36; } @@ -262,41 +265,41 @@ class SearchController extends Controller } if ( - ($buffer_connection = $connection['product']['bffr']["$from-$to-avia"] ?? false) + ($buffer_connection = $buffer_delivery_avia['product']['bffr']["$from-$to-avia"] ?? false) && time() < $buffer_connection['expires'] ) { // Найдены данные доставки в буфере // и срок хранения не превышен, информация актуальна // Запись в буфер вывода - $connection['delivery'] = $buffer_connection['data']; - $connection['delivery']['type'] = 'avia'; + $buffer_delivery_avia['delivery'] = $buffer_connection['data']; + $buffer_delivery_avia['delivery']['type'] = 'avia'; } else { // Инициализация инстанции продукта в базе данных - $product = Product::searchByCatn($connection['product']['catn']); + $product = Product::searchByCatn($buffer_delivery_avia['product']['catn']); // Инициализация доставки Dellin (автоматическая) $product->bffr = [ "$from-$to-avia" => [ - 'data' => $connection['delivery'] = Dellin::calcDeliveryAdvanced( + 'data' => $buffer_delivery_avia['delivery'] = Dellin::calcDeliveryAdvanced( $from, $to, - (int) ($connection['product']['wght'] ?? 0), - (int) ($connection['product']['dmns']['x'] ?? 0), - (int) ($connection['product']['dmns']['y'] ?? 0), - (int) ($connection['product']['dmns']['z'] ?? 0), + (int) ($buffer_delivery_avia['product']['wght'] ?? 0), + (int) ($buffer_delivery_avia['product']['dmns']['x'] ?? 0), + (int) ($buffer_delivery_avia['product']['dmns']['y'] ?? 0), + (int) ($buffer_delivery_avia['product']['dmns']['z'] ?? 0), avia: true ), 'expires' => time() + 86400 ] ] + ($product->bffr ?? []); - $connection['delivery']['type'] = 'avia'; + $buffer_delivery_avia['delivery']['type'] = 'avia'; // Отправка в базу данных $product->update(); } } catch (Exception $e) { - $buffer['delivery']['error'] = true; + $buffer_delivery_avia['delivery']['error'] = true; // var_dump($e->getMessage()); // var_dump($e->getTrace()); @@ -306,14 +309,14 @@ class SearchController extends Controller // die; } - if (!isset($buffer['delivery']['error']) || $buffer['delivery']['error'] !== true) { + if (!isset($buffer_delivery_avia['delivery']['error']) || $buffer_delivery_avia['delivery']['error'] !== true) { // Если рассчиталась доставка самолётом // Инициализация цены (цена поставки + цена доставки + наша наценка) - $buffer['cost'] = ($cost['ЦенаЗаЕдиницу'] ?? $buffer['supply_edge_product'][0]['onec']['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($buffer['delivery']['price']['all'] ?? $buffer['delivery']['price']['one'] ?? 0) + ($settings['increase'] ?? 0); + $buffer_delivery_avia['cost'] = ($cost['ЦенаЗаЕдиницу'] ?? $buffer_delivery_avia['supply_edge_product'][0]['onec']['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($buffer_delivery_avia['delivery']['price']['all'] ?? $buffer_delivery_avia['delivery']['price']['one'] ?? 0) + ($settings['increase'] ?? 0); // Запись в буфер - $buffer_connections[] = $buffer; + $buffer_connections[] = $buffer_delivery_avia; } } diff --git a/mirzaev/skillparts/system/models/Account.php b/mirzaev/skillparts/system/models/Account.php index baff2be..76b5990 100644 --- a/mirzaev/skillparts/system/models/Account.php +++ b/mirzaev/skillparts/system/models/Account.php @@ -548,11 +548,24 @@ class Account extends Document implements IdentityInterface, PartnerInterface // Функция для конвертации цифр в буквы $int_to_string = function (int $target): string { - $alphabet = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я']; + // $alphabet = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Щ', 'Ъ', 'Ы', 'Ь', 'Э', 'Ю', 'Я']; + $alphabet = ['А', 'Б', 'В', 'Г', 'Д', 'Е', 'Ё', 'Ж', 'З', 'И', 'Й', 'К', 'Л', 'М', 'Н', 'О', 'П', 'Р', 'С', 'Т', 'У', 'Ф', 'Х', 'Ц', 'Ч', 'Ш', 'Ю', 'Я']; return $alphabet[$target]; }; + // Реестр запрещённых индексов + $registry = [ + 'ЧМО', + 'ХЕР', + 'ХУЙ', + 'БЛЯ', + 'СУК', + 'СУЧ', + 'ЖОП', + 'ЛОХ' + ]; + foreach ($accounts as $account) { // Перебор запрошенных аккаунтов @@ -560,11 +573,18 @@ class Account extends Document implements IdentityInterface, PartnerInterface // Запись только тех аккаунтов у кого не инициализирован индекс или если указано отсутствие проверки // Повтор генерации - regenerate: + regenerate_index: // Генерация $account->indx = $int_to_string(random_int(0, 32)) . $int_to_string(random_int(0, 32)) . $int_to_string(random_int(0, 32)); + if (in_array($account->indx, $registry)) { + // Сгенерированный индекс обнаружено в реестре запрещённых индексов + + // Повтор генерации + goto regenerate_index; + } + // Запись if ($account->save()) { // Аккаунт сохранён (в базе данных это поле проверяется на уникальность) @@ -586,7 +606,7 @@ class Account extends Document implements IdentityInterface, PartnerInterface echo "Не удалось сохранить аккаунт с псевдоанонимным идентификатором $account->indx" . PHP_EOL; } - goto regenerate; + goto regenerate_index; } } } diff --git a/mirzaev/skillparts/system/models/connection/Dellin.php b/mirzaev/skillparts/system/models/connection/Dellin.php index 335ac11..b09dac3 100644 --- a/mirzaev/skillparts/system/models/connection/Dellin.php +++ b/mirzaev/skillparts/system/models/connection/Dellin.php @@ -126,8 +126,8 @@ class Dellin extends Model $query = []; // Рассчёт типа доставки - if ( - $weight <= 30 + if ( !$avia + && $weight <= 30 && ($length <= 0.54 && $width <= 0.39 && $height <= 0.39) && $length * $width * $height <= 0.1 ) { diff --git a/mirzaev/skillparts/system/views/orders/index.php b/mirzaev/skillparts/system/views/orders/index.php index ea2fcb1..e789f4d 100644 --- a/mirzaev/skillparts/system/views/orders/index.php +++ b/mirzaev/skillparts/system/views/orders/index.php @@ -171,7 +171,35 @@ if (
diff --git a/mirzaev/skillparts/system/views/profile/index.php b/mirzaev/skillparts/system/views/profile/index.php index 2ecfb2e..a913c8e 100644 --- a/mirzaev/skillparts/system/views/profile/index.php +++ b/mirzaev/skillparts/system/views/profile/index.php @@ -55,7 +55,7 @@ if ( // Инициализация $model ?? $model = yii::$app->user->identity; - $delivery_to_terminal_list or $delivery_to_terminal_list = ['Нет данных']; + $delivery_to_terminal_list ?? $delivery_to_terminal_list = ['Нет данных']; ?> field($model, 'opts[delivery_to_terminal]', ['options' => ['class' => "mb-1"]]) diff --git a/mirzaev/skillparts/system/views/search/index.php b/mirzaev/skillparts/system/views/search/index.php index 5e4ce14..5fd4e6b 100644 --- a/mirzaev/skillparts/system/views/search/index.php +++ b/mirzaev/skillparts/system/views/search/index.php @@ -117,13 +117,28 @@ default => '' }; - // Инициализация времени + // Инициализация даты отправки try { + // Взять данные из "arrivalToOspSender" (Дата прибытия на терминал-отправитель) + + $delivery_send_date = DateTime::createFromFormat('Y-m-d', $delivery['orderDates']['arrivalToOspSender'])->getTimestamp(); + } catch (Throwable $e) { + // Взять данные из "pickup" (Дата передачи груза на адресе отправителя) + + $delivery_send_date = DateTime::createFromFormat('Y-m-d', $delivery['orderDates']['pickup'])->getTimestamp(); + } + + // Инициализация времени доставки + try { + // Доставка по воздуху (подразумевается), данные из "giveoutFromOspReceiver" (Дата и время, с которого груз готов к выдаче на терминале) + $delivery_converted = DateTime::createFromFormat('Y-m-d H:i:s', $delivery['orderDates']['giveoutFromOspReceiver'])->getTimestamp(); - } catch (Exception $e) { + } catch (Throwable $e) { + // Автоматическая доставка (подразумевается), данные из "arrivalToOspReceiver" (Дата прибытия натерминал-получатель) + $delivery_converted = DateTime::createFromFormat('Y-m-d', $delivery['orderDates']['arrivalToOspReceiver'])->getTimestamp(); } - $delivery = ceil(($delivery_converted - time()) / 60 / 60 / 24) + 1; + $delivery = ceil(($delivery_converted - ($delivery_send_date ?? 0)) / 60 / 60 / 24) + 1; } // Инициализация индекса аккаунта diff --git a/mirzaev/skillparts/system/web/js/main.js b/mirzaev/skillparts/system/web/js/main.js index eb52f97..232d328 100644 --- a/mirzaev/skillparts/system/web/js/main.js +++ b/mirzaev/skillparts/system/web/js/main.js @@ -35,3 +35,13 @@ function main_response(data, status, xhr) { }; }; }; + +var page_loaded_for_history = window.history.state; + +window.addEventListener('popstate', function() { + if (page_loaded_for_history) { + + console.log('сработало'); + window.location.reload(); + }; +}, false); diff --git a/mirzaev/skillparts/system/web/js/orders.js b/mirzaev/skillparts/system/web/js/orders.js index 30777c7..26a0ccf 100644 --- a/mirzaev/skillparts/system/web/js/orders.js +++ b/mirzaev/skillparts/system/web/js/orders.js @@ -1,3 +1,23 @@ +// Запросить заказы +function orders_read(type = 'all') { + // Запрос + $.ajax({ + url: '/orders/' + type, + type: 'post', + dataType: 'json', + data: { + '_csrf': yii.getCsrfToken() + }, + success: orders_response_success, + error: orders_response_error + }); + + // Пересчитывание стоимости + cart_cost_calculate(); + + return false; +} + function orders_response(data, status, xhr) { // Обработка ответов diff --git a/mirzaev/skillparts/system/web/js/search.js b/mirzaev/skillparts/system/web/js/search.js index 8b0fc6b..0f180f2 100644 --- a/mirzaev/skillparts/system/web/js/search.js +++ b/mirzaev/skillparts/system/web/js/search.js @@ -12,10 +12,10 @@ function product_search(text = '', advanced = 0) { 'advanced': advanced, 'request': text }, - success: function (data, statu, xhrs) { + success: function (data, status, xhr) { search_panel_success(text, advanced, data, status, xhr); }, - error: function (data, status) { + error: function (data, status, xhr) { search_panel_error(text, advanced, data, status, xhr); }, statusCode: search_panel_statusCode @@ -37,10 +37,10 @@ function product_search_history(text = '', advanced = 0) { 'type': 'product', 'history': true }, - success: function (data, status) { + success: function (data, status, xhr) { search_panel_success(text, advanced, data, status, xhr); }, - error: function (data, status) { + error: function (data, status, xhr) { search_panel_error(text, advanced, data, status, xhr); }, statusCode: search_panel_statusCode