diff --git a/mirzaev/skillparts/system/assets/invoices/18234637/invoice.xlsx b/mirzaev/skillparts/system/assets/invoices/18234637/invoice.xlsx deleted file mode 100644 index cdf3a5e..0000000 Binary files a/mirzaev/skillparts/system/assets/invoices/18234637/invoice.xlsx and /dev/null differ diff --git a/mirzaev/skillparts/system/config/web.php.example b/mirzaev/skillparts/system/config/web.php.example index c8a06e3..8b44719 100644 --- a/mirzaev/skillparts/system/config/web.php.example +++ b/mirzaev/skillparts/system/config/web.php.example @@ -97,7 +97,7 @@ $config = [ '<_key:[0-9]+>' => 'account/index', '<_key:[0-9]+>//' => 'account/', '<_key:[0-9]+>/files/' => 'account/file', - '<_key:[0-9]+>/' => 'account/', + '<_key:[0-9]+>/' => 'account/', 'product/' => 'product/index', 'product//' => 'product/', '///' => '
/-', diff --git a/mirzaev/skillparts/system/controllers/AccountController.php b/mirzaev/skillparts/system/controllers/AccountController.php index ffbe8f4..29534a4 100644 --- a/mirzaev/skillparts/system/controllers/AccountController.php +++ b/mirzaev/skillparts/system/controllers/AccountController.php @@ -23,7 +23,8 @@ class AccountController extends Controller [ 'allow' => true, 'actions' => [ - 'file' + 'file', + 'data' ] ], [ @@ -258,8 +259,9 @@ class AccountController extends Controller /** * Регенерация параметра * - * @param int $_key + * @param int $_key Идентификатор * @param string $target + * * @return void */ public function actionRegenerate(int $_key, string $target) @@ -299,4 +301,55 @@ class AccountController extends Controller return false; } + + /** + * Информация + * + * @param int $_key Идентификатор + */ + public function actionData(int $_key) + { + if (yii::$app->request->isPost) { + // AJAX-POST-запрос + + // Инициализация аккаунта (тот кто выполняет запрос) + $account = account::initAccount(); + + // Поиск данных об аккаунта (запрашиваемом) + $data = account::initAccount($_key)->getAttributes(); + + if ($account->isAdmin() || $account->isModer()) { + // Авторизован как работник + } else if ((int) $account->_key === $_key) { + // Авторизован как владелец аккаунта + + unset( + $data['vrfy'], + $data['geol'], + $data['auth'], + $data['jrnl'], + $data['acpt'], + $data['pswd'] + ); + } else { + // Не авторизован + + // Очистка от защищенных свойств + $data = [ + '_key' => $data['_key'], + 'indx' => $data['indx'], + 'agnt' => $data['agnt'], + 'type' => $data['type'] + ]; + } + + // Настройка формата ответа + yii::$app->response->format = Response::FORMAT_JSON; + + return [ + 'data' => $data, + '_csrf' => Yii::$app->request->getCsrfToken() + ]; + } + } } diff --git a/mirzaev/skillparts/system/controllers/OrderController.php b/mirzaev/skillparts/system/controllers/OrderController.php index 2ccf0fd..8707a87 100644 --- a/mirzaev/skillparts/system/controllers/OrderController.php +++ b/mirzaev/skillparts/system/controllers/OrderController.php @@ -588,67 +588,77 @@ class OrderController extends Controller // Инициализация $model = Order::searchByType(supplies: true); - // Поиск ребра - $account_edge_order = AccountEdgeOrder::searchByVertex(yii::$app->user->id, $model->readId(), 'current')[0]; + if (($account_edge_order = AccountEdgeOrder::searchByVertex(yii::$app->user->id, $model->readId(), 'current')[0]) ?? false) { + // Найдено ребро: АККАУНТ -> ЗАКАЗ - if ($supplies = OrderEdgeSupply::searchByDirection($account_edge_order->to)) { - // Поставки найдены - // Добавить проверку на то, что товары активны + if ($order_edge_supply = OrderEdgeSupply::searchByDirection($account_edge_order->_to, type: 'write', limit: 500)) { + // Найдены рёбра: ЗАКАЗ -> ПОСТАВКА - } + foreach ($order_edge_supply as $edge) { + // Перебор рёбер: ЗАКАЗ -> ПОСТАВКА - var_dump($supplies); die; + if ($product = Product::searchBySupplyId($edge->_to)) { + // Найден товар - if (count($account_edge_order) > 1) { - // Найден более чем 1 заказ - - return null; - } - - // Запись - $account_edge_order->type = 'requested'; - - if ($account_edge_order->update()) { - // Удалось сохранить изменения - - // Запись в журнал - $model->journal('requested'); - - // Инициализация буфера поставок - $supplies = []; - - foreach ($model['supplies'] as $supply) { - // Перебор поставок - - $supplies[] = [ - 'title' => $supply['supply']['catn'], - 'amount' => [ - 'value' => $supply['amount'] ?? 0, - 'unit' => 'шт' - ], - 'cost' => [ - 'value' => $supply['cost'] ?? 0, - 'unit' => 'руб' - ], - 'type' => 'supply' - ]; + // Проверка на активность товара + if ($product['stts'] === 'active'); + else $edge->delete(); + } + } } - Invoice::generate($model->_key, $this->renderPartial('/invoice/order/pattern', [ - 'buyer' => [ - 'id' => yii::$app->user->identity->_key, - 'info' => 'Неизвестно' - ], - 'order' => [ - 'id' => $model->_key, - 'date' => $account_edge_order->date ?? time(), - 'entries' => $supplies - ] - ])); + // Реиницилазация + $model = Order::searchByType(supplies: true); - // Отправка уведомлений модераторам - Notification::_write($this->renderPartial('/notification/system/orders/new', ['id' => $account_edge_order->_key]), true, '@auth', Notification::TYPE_MODERATOR_ORDER_NEW); + // Запись + $account_edge_order->type = 'requested'; + + if ($account_edge_order->update()) { + // Удалось сохранить изменения + + // Запись в журнал + $model->journal('requested'); + + // Инициализация буфера поставок + $supplies = []; + + foreach ($model['supplies'] as $supply) { + // Перебор поставок + + $supplies[] = [ + 'title' => $supply['supply']['catn'], + 'delivery' => 0, + 'amount' => [ + // 'value' => $supply['amount'][$supply['order_edge_supply'][]] ?? 0, + // 'value' => $supply['amount'] ?? 0, + 'value' => 0, + 'unit' => 'шт' + ], + 'cost' => [ + // 'value' => $supply['cost'] ?? 0, + 'value' => 0, + 'unit' => 'руб' + ], + 'type' => 'supply' + ]; + } + + Invoice::generate($model->_key, $this->renderPartial('/invoice/order/pattern', [ + 'buyer' => [ + 'id' => yii::$app->user->identity->_key, + 'info' => 'Неизвестно' + ], + 'order' => [ + 'id' => $model->_key, + 'date' => $account_edge_order->date ?? time(), + 'entries' => $supplies + ] + ])); + + // Отправка уведомлений модераторам + Notification::_write($this->renderPartial('/notification/system/orders/new', ['id' => $account_edge_order->_key]), true, '@auth', Notification::TYPE_MODERATOR_ORDER_NEW); + } } return $this->actionIndex(); diff --git a/mirzaev/skillparts/system/controllers/ProfileController.php b/mirzaev/skillparts/system/controllers/ProfileController.php index a54923f..b4f1052 100644 --- a/mirzaev/skillparts/system/controllers/ProfileController.php +++ b/mirzaev/skillparts/system/controllers/ProfileController.php @@ -877,6 +877,9 @@ class ProfileController extends Controller return false; } + /** + * Поиск заявок на регистрацию + */ public function actionPanelSuppliersRequestsSearch() { if (Yii::$app->request->isPost) { diff --git a/mirzaev/skillparts/system/controllers/SearchController.php b/mirzaev/skillparts/system/controllers/SearchController.php index f70e2ae..75cef95 100644 --- a/mirzaev/skillparts/system/controllers/SearchController.php +++ b/mirzaev/skillparts/system/controllers/SearchController.php @@ -31,6 +31,7 @@ class SearchController extends Controller if ($auth_only && yii::$app->user->isGuest) { // Если активирован режим "Поиск только аутентифицированным" и запрос пришел не от аутентифицированного + // Запись кода ответа: 401 (необходима авторизация) yii::$app->response->statusCode = 401; diff --git a/mirzaev/skillparts/system/models/Order.php b/mirzaev/skillparts/system/models/Order.php index 31041d9..e7fbbd5 100644 --- a/mirzaev/skillparts/system/models/Order.php +++ b/mirzaev/skillparts/system/models/Order.php @@ -549,7 +549,7 @@ class Order extends Document implements DocumentInterface // Чтение стоимости $cost = Supply::readCostById($connection['supply']['_id']); - if (empty($cost) || $cost['ЦенаЗаЕдиницу'] < 1) { + if (empty($cost) || $cost < 1) { // Если стоимость не найдена или равна нулю (явная ошибка) // Удаление из базы данных @@ -633,7 +633,7 @@ class Order extends Document implements DocumentInterface } // Запись цены (цена поставки + цена доставки + наша наценка) - $connection['cost']['auto'] = ($cost['ЦенаЗаЕдиницу'] ?? $connection['supply']->onec['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($connection['delivery']['auto']['price']['all'] ?? $connection['delivery']['auto']['price']['one'] ?? 0) + ($settings['increase'] ?? 0) ?? 0; + $connection['cost']['auto'] = ($cost ?? $connection['supply']->onec['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($connection['delivery']['auto']['price']['all'] ?? $connection['delivery']['auto']['price']['one'] ?? 0) + ($settings['increase'] ?? 0) ?? 0; // } else { // Доставка самолётом @@ -696,11 +696,11 @@ class Order extends Document implements DocumentInterface } // Запись цены (цена поставки + цена доставки + наша наценка) - $connection['cost']['avia'] = ($cost['ЦенаЗаЕдиницу'] ?? $connection['supply']->onec['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($connection['delivery']['avia']['price']['all'] ?? $connection['delivery']['avia']['price']['one'] ?? 0) + ($settings['increase'] ?? 0) ?? 0; + $connection['cost']['avia'] = ($cost ?? $connection['supply']->onec['Цены']['Цена']['ЦенаЗаЕдиницу']) + ($connection['delivery']['avia']['price']['all'] ?? $connection['delivery']['avia']['price']['one'] ?? 0) + ($settings['increase'] ?? 0) ?? 0; // } // Запись валюты - $connection['currency'] = $cost['Валюта']; + $connection['currency'] = 'руб'; } return $connections; diff --git a/mirzaev/skillparts/system/models/Search.php b/mirzaev/skillparts/system/models/Search.php index bda29d2..155a1fd 100644 --- a/mirzaev/skillparts/system/models/Search.php +++ b/mirzaev/skillparts/system/models/Search.php @@ -255,12 +255,12 @@ class Search extends Document } catch (Exception $e) { $connection['delivery']['error'] = true; - var_dump($e->getMessage()); - var_dump($e->getTrace()); - var_dump($e->getFile()); + // var_dump($e->getMessage()); + // var_dump($e->getTrace()); + // var_dump($e->getFile()); - var_dump(json_decode($e->getMessage(), true)['errors']); - die; + // var_dump(json_decode($e->getMessage(), true)['errors']); + // die; } finally { // echo $connection['delivery']['price']['all']; // Инициализация цены (цена поставки + цена доставки + наша наценка) diff --git a/mirzaev/skillparts/system/models/Supply.php b/mirzaev/skillparts/system/models/Supply.php index e6bf367..cebb1f6 100644 --- a/mirzaev/skillparts/system/models/Supply.php +++ b/mirzaev/skillparts/system/models/Supply.php @@ -895,15 +895,11 @@ class Supply extends Product implements ProductInterface, OfferInterface * @param string $_id Идентификатор поставки * @param Product|null $product Товар для поиска по вершинам * - * @return array|null Данные о ценах + * @return int|null Стоимость (руб) */ - public static function readCostById(string $_id, Product $product = null): ?array + public static function readCostById(string $_id, Product $product = null): ?int { - if (isset($product)) { - return SupplyEdgeProduct::searchByVertex($_id, $product->readId(), type: 'connect', limit: 1)['onec']['Цены']['Цена']; - } - - return SupplyEdgeProduct::searchByDirection($_id, type: 'connect', limit: 1)['onec']['Цены']['Цена']; + return Supply::searchById($_id)->cost ?? null; } /** diff --git a/mirzaev/skillparts/system/views/cart/index.php b/mirzaev/skillparts/system/views/cart/index.php index d7991e9..a28fa97 100644 --- a/mirzaev/skillparts/system/views/cart/index.php +++ b/mirzaev/skillparts/system/views/cart/index.php @@ -25,7 +25,6 @@ use DateTime; Артикул
- Описание
Количество @@ -104,7 +103,6 @@ use DateTime; {$supply['catn']}
- {$supply['dscr']}
diff --git a/mirzaev/skillparts/system/views/invoice/order/pattern.php b/mirzaev/skillparts/system/views/invoice/order/pattern.php index 6bd10dc..1b88f16 100644 --- a/mirzaev/skillparts/system/views/invoice/order/pattern.php +++ b/mirzaev/skillparts/system/views/invoice/order/pattern.php @@ -156,9 +156,7 @@ use app\models\Settings; - - - + diff --git a/mirzaev/skillparts/system/views/profile/supplies.php b/mirzaev/skillparts/system/views/profile/supplies.php index bf43ec8..2c9c7d6 100644 --- a/mirzaev/skillparts/system/views/profile/supplies.php +++ b/mirzaev/skillparts/system/views/profile/supplies.php @@ -216,7 +216,7 @@ $panel ?? $panel = 'profile_panel_supplies_input_import'; - + Создать склад
diff --git a/mirzaev/skillparts/system/web/js/cart.js b/mirzaev/skillparts/system/web/js/cart.js index 0daf049..0266378 100644 --- a/mirzaev/skillparts/system/web/js/cart.js +++ b/mirzaev/skillparts/system/web/js/cart.js @@ -348,7 +348,7 @@ function cart_registration_entity_init(_key, wrap = 'cart_registration_entity_bo wrap = document.getElementById(wrap); $.ajax({ - url: '/profile/panel/suppliers/requests/search', + url: '/' + _key + '/data', type: 'post', dataType: 'json', data: { @@ -361,13 +361,13 @@ function cart_registration_entity_init(_key, wrap = 'cart_registration_entity_bo if (data !== undefined) { // Получены данные с сервера - if (data.suppliers !== undefined && data.suppliers !== null) { + if (data.data !== undefined && data.data !== null) { // Найдены данные поставщиков // Удаление данных в оболочке wrap.innerHTML = null; - for (let html of cart_registration_entity_generate(data.suppliers[0])) { + for (let html of cart_registration_entity_generate(data.data)) { // Перебор сгенерированных HTML-элементов // Запись в документ @@ -438,7 +438,7 @@ function cart_registration_entity_generate(account) { input_boss.setAttribute('type', 'text'); input_boss.setAttribute('placeholder', 'Иванов Иван Иванович'); input_boss.setAttribute('onchange', 'return cart_registration_block_edit(' + account._key + ', "boss", this.value);'); - input_boss.value = account.boss ?? '';; + input_boss.value = account.boss ?? ''; // Инициализация ярлыка "SIMC" (телефон) let label_simc = document.createElement('label'); @@ -451,7 +451,7 @@ function cart_registration_entity_generate(account) { input_simc.setAttribute('class', 'form-control button_clean mb-3'); input_simc.setAttribute('type', 'number'); input_simc.setAttribute('onchange', 'return cart_registration_block_edit(' + account._key + ', "simc", this.value);'); - input_simc.value = ''; + input_simc.value = account.simc ?? ''; // Инициализация ярлыка "MAIL" let label_mail = document.createElement('label'); @@ -607,13 +607,21 @@ function cart_registration_entity_generate(account) { }; function cart_registration_choose(button = 'cart_registration_entity', account) { + // Инициализация элементов + let entity = document.getElementById('cart_registration_entity'); + let entity_button = document.getElementById('cart_registration_entity_button'); + let individual = document.getElementById('cart_registration_individual'); + let individual_button = document.getElementById('cart_registration_individual_button'); + // Деинициализация всех вкладок - document.getElementById('cart_registration_entity').checked = - document.getElementById('cart_registration_individual').checked = false; + entity.checked = false; + individual.checked = false; - document.getElementById('cart_registration_entity').setAttribute('onclick', 'page_profile_panel_choose(\'cart_registration_entity\')'); - document.getElementById('cart_registration_individual').setAttribute('onclick', 'page_profile_panel_choose(\'cart_registration_individual\'); cart_registration_entity_init(' + account + ')'); + // Запись скриптов + entity_button.setAttribute('onclick', 'cart_registration_choose(\'cart_registration_entity\', ' + account + '); cart_registration_entity_init(' + account + ')'); + individual_button.setAttribute('onclick', 'cart_registration_choose(\'cart_registration_individual\', ' + account + ')'); + // Удаление активного статуса document.querySelector('[for="cart_registration_entity"]').classList.remove('active'); document.querySelector('[for="cart_registration_individual"]').classList.remove('active');