From d4bc3e2263ceab0acd93b052f0af52e453e81726 Mon Sep 17 00:00:00 2001 From: Arsen Mirzaev Tatyano-Muradovich Date: Tue, 13 Apr 2021 07:21:31 +1000 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=20=D0=BD=D0=B0=D1=87=D0=B0?= =?UTF-8?q?=D0=BB=D0=BE=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D1=80=D0=B0=D1=81=D1=81=D1=87=D1=91=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B4=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 3 +- composer.lock | 398 ++++++++++++------ .../skillparts/system/config/web.php.example | 4 +- .../system/controllers/ProductController.php | 195 ++++++++- .../system/controllers/ProfileController.php | 14 +- .../m210412_171912_create_city_controller.php | 20 + mirzaev/skillparts/system/models/Account.php | 16 + mirzaev/skillparts/system/models/City.php | 65 +++ .../system/models/connection/Dellin.php | 155 +++++++ .../skillparts/system/views/profile/index.php | 92 ++-- .../system/web/Nginx_1.19_vhost.conf | 2 +- mirzaev/skillparts/system/web/js/profile.js | 13 +- 12 files changed, 802 insertions(+), 175 deletions(-) create mode 100644 mirzaev/skillparts/system/migrations/arangodb/m210412_171912_create_city_controller.php create mode 100644 mirzaev/skillparts/system/models/City.php create mode 100644 mirzaev/skillparts/system/models/connection/Dellin.php diff --git a/composer.json b/composer.json index 314e3ad..1f72687 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,8 @@ "carono/yii2-1c-exchange": "^0.3.1", "yiisoft/yii2-imagine": "*", "mirzaev/yii2-arangodb": ">=2.1.x-dev", - "mirzaev/yii2-arangodb-sessions": ">=1.1.x-dev" + "mirzaev/yii2-arangodb-sessions": ">=1.1.x-dev", + "guzzlehttp/guzzle": "^7.3" }, "require-dev": { "codeception/codeception": ">=4.1", diff --git a/composer.lock b/composer.lock index 4112255..57392e1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "ccecbc4681132b24e370af7c3db52dd8", + "content-hash": "281d5a604bec47375e20427f528690c7", "packages": [ { "name": "bower-asset/bootstrap", @@ -471,6 +471,239 @@ }, "time": "2020-06-29T00:56:53+00:00" }, + { + "name": "guzzlehttp/guzzle", + "version": "7.3.0", + "source": { + "type": "git", + "url": "https://github.com/guzzle/guzzle.git", + "reference": "7008573787b430c1c1f650e3722d9bba59967628" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628", + "reference": "7008573787b430c1c1f650e3722d9bba59967628", + "shasum": "" + }, + "require": { + "ext-json": "*", + "guzzlehttp/promises": "^1.4", + "guzzlehttp/psr7": "^1.7 || ^2.0", + "php": "^7.2.5 || ^8.0", + "psr/http-client": "^1.0" + }, + "provide": { + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4.1", + "ext-curl": "*", + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.5.5 || ^9.3.5", + "psr/log": "^1.1" + }, + "suggest": { + "ext-curl": "Required for CURL handler support", + "ext-intl": "Required for Internationalized Domain Name (IDN) support", + "psr/log": "Required for using the Log middleware" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "7.3-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "Guzzle is a PHP HTTP client library", + "homepage": "http://guzzlephp.org/", + "keywords": [ + "client", + "curl", + "framework", + "http", + "http client", + "psr-18", + "psr-7", + "rest", + "web service" + ], + "support": { + "issues": "https://github.com/guzzle/guzzle/issues", + "source": "https://github.com/guzzle/guzzle/tree/7.3.0" + }, + "funding": [ + { + "url": "https://github.com/GrahamCampbell", + "type": "github" + }, + { + "url": "https://github.com/Nyholm", + "type": "github" + }, + { + "url": "https://github.com/alexeyshockov", + "type": "github" + }, + { + "url": "https://github.com/gmponos", + "type": "github" + } + ], + "time": "2021-03-23T11:33:13+00:00" + }, + { + "name": "guzzlehttp/promises", + "version": "1.4.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/promises.git", + "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "shasum": "" + }, + "require": { + "php": ">=5.5" + }, + "require-dev": { + "symfony/phpunit-bridge": "^4.4 || ^5.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.4-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Promise\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + } + ], + "description": "Guzzle promises library", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/guzzle/promises/issues", + "source": "https://github.com/guzzle/promises/tree/1.4.1" + }, + "time": "2021-03-07T09:25:29+00:00" + }, + { + "name": "guzzlehttp/psr7", + "version": "1.8.1", + "source": { + "type": "git", + "url": "https://github.com/guzzle/psr7.git", + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", + "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "psr/http-message": "~1.0", + "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" + }, + "provide": { + "psr/http-message-implementation": "1.0" + }, + "require-dev": { + "ext-zlib": "*", + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" + }, + "suggest": { + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7-dev" + } + }, + "autoload": { + "psr-4": { + "GuzzleHttp\\Psr7\\": "src/" + }, + "files": [ + "src/functions_include.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Dowling", + "email": "mtdowling@gmail.com", + "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Schultze", + "homepage": "https://github.com/Tobion" + } + ], + "description": "PSR-7 message implementation that also provides common utility methods", + "keywords": [ + "http", + "message", + "psr-7", + "request", + "response", + "stream", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/guzzle/psr7/issues", + "source": "https://github.com/guzzle/psr7/tree/1.8.1" + }, + "time": "2021-03-21T16:25:00+00:00" + }, { "name": "imagine/imagine", "version": "1.2.4", @@ -1304,6 +1537,50 @@ }, "time": "2017-10-23T01:57:42+00:00" }, + { + "name": "ralouphie/getallheaders", + "version": "3.0.3", + "source": { + "type": "git", + "url": "https://github.com/ralouphie/getallheaders.git", + "reference": "120b605dfeb996808c31b6477290a714d356e822" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", + "reference": "120b605dfeb996808c31b6477290a714d356e822", + "shasum": "" + }, + "require": { + "php": ">=5.6" + }, + "require-dev": { + "php-coveralls/php-coveralls": "^2.1", + "phpunit/phpunit": "^5 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/getallheaders.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ralph Khattar", + "email": "ralph.khattar@gmail.com" + } + ], + "description": "A polyfill for getallheaders.", + "support": { + "issues": "https://github.com/ralouphie/getallheaders/issues", + "source": "https://github.com/ralouphie/getallheaders/tree/develop" + }, + "time": "2019-03-08T08:55:37+00:00" + }, { "name": "swiftmailer/swiftmailer", "version": "v6.2.7", @@ -3119,81 +3396,6 @@ }, "time": "2021-03-30T06:27:33+00:00" }, - { - "name": "guzzlehttp/psr7", - "version": "1.8.1", - "source": { - "type": "git", - "url": "https://github.com/guzzle/psr7.git", - "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/35ea11d335fd638b5882ff1725228b3d35496ab1", - "reference": "35ea11d335fd638b5882ff1725228b3d35496ab1", - "shasum": "" - }, - "require": { - "php": ">=5.4.0", - "psr/http-message": "~1.0", - "ralouphie/getallheaders": "^2.0.5 || ^3.0.0" - }, - "provide": { - "psr/http-message-implementation": "1.0" - }, - "require-dev": { - "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" - }, - "suggest": { - "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.7-dev" - } - }, - "autoload": { - "psr-4": { - "GuzzleHttp\\Psr7\\": "src/" - }, - "files": [ - "src/functions_include.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Michael Dowling", - "email": "mtdowling@gmail.com", - "homepage": "https://github.com/mtdowling" - }, - { - "name": "Tobias Schultze", - "homepage": "https://github.com/Tobion" - } - ], - "description": "PSR-7 message implementation that also provides common utility methods", - "keywords": [ - "http", - "message", - "psr-7", - "request", - "response", - "stream", - "uri", - "url" - ], - "support": { - "issues": "https://github.com/guzzle/psr7/issues", - "source": "https://github.com/guzzle/psr7/tree/1.8.1" - }, - "time": "2021-03-21T16:25:00+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.10.2", @@ -4340,50 +4542,6 @@ }, "time": "2019-01-08T18:20:26+00:00" }, - { - "name": "ralouphie/getallheaders", - "version": "3.0.3", - "source": { - "type": "git", - "url": "https://github.com/ralouphie/getallheaders.git", - "reference": "120b605dfeb996808c31b6477290a714d356e822" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822", - "reference": "120b605dfeb996808c31b6477290a714d356e822", - "shasum": "" - }, - "require": { - "php": ">=5.6" - }, - "require-dev": { - "php-coveralls/php-coveralls": "^2.1", - "phpunit/phpunit": "^5 || ^6.5" - }, - "type": "library", - "autoload": { - "files": [ - "src/getallheaders.php" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Ralph Khattar", - "email": "ralph.khattar@gmail.com" - } - ], - "description": "A polyfill for getallheaders.", - "support": { - "issues": "https://github.com/ralouphie/getallheaders/issues", - "source": "https://github.com/ralouphie/getallheaders/tree/develop" - }, - "time": "2019-03-08T08:55:37+00:00" - }, { "name": "sebastian/cli-parser", "version": "1.0.1", diff --git a/mirzaev/skillparts/system/config/web.php.example b/mirzaev/skillparts/system/config/web.php.example index 06ea121..4cfe6f9 100644 --- a/mirzaev/skillparts/system/config/web.php.example +++ b/mirzaev/skillparts/system/config/web.php.example @@ -77,7 +77,7 @@ $config = [ 'controller' => 'main' ], 'product/' => 'product/index', - 'product///' => 'product/-', + 'product///' => 'product/-', 'orders' => 'order/index' ], ], @@ -121,4 +121,4 @@ if (YII_ENV_DEV) { ]; } -return $config; \ No newline at end of file +return $config; diff --git a/mirzaev/skillparts/system/controllers/ProductController.php b/mirzaev/skillparts/system/controllers/ProductController.php index 83d0c0e..63e7d83 100644 --- a/mirzaev/skillparts/system/controllers/ProductController.php +++ b/mirzaev/skillparts/system/controllers/ProductController.php @@ -106,8 +106,8 @@ class ProductController extends Controller if ($model = Product::searchByCatn($catn)) { // Товар найден - // Инициализация - $text = yii::$app->request->get('text') ?? yii::$app->request->post('text') ?? 'Без названия'; + // Инициализация + $text = yii::$app->request->post('text') ?? yii::$app->request->get('text') ?? 'Без названия'; $model->catn = $text; @@ -138,7 +138,7 @@ class ProductController extends Controller } } - public function actionEditDesc(string $catn): array|string|null + public function actionEditDscr(string $catn): array|string|null { // Инициализация $return = [ @@ -159,7 +159,7 @@ class ProductController extends Controller // Инициализация $text = yii::$app->request->get('text') ?? yii::$app->request->post('text') ?? 'Без названия'; - $product->desc = $text; + $product->dscr = $text; if ($product->save()) { // Товар обновлён @@ -188,6 +188,63 @@ class ProductController extends Controller } } + public function actionEditDmns(string $catn): array|string|null + { + // Инициализация + $return = [ + '_csrf' => yii::$app->request->getCsrfToken() + ]; + + if (is_null($catn)) { + // Не получен артикул + + yii::$app->response->statusCode = 500; + + goto end; + } + + if ($product = Product::searchByCatn($catn)) { + // Товар найден + + // Инициализация + $text = yii::$app->request->post('text') ?? yii::$app->request->get('text') ?? '0'; + $text or $text = '0'; + $dimension = yii::$app->request->post('dimension') ?? yii::$app->request->get('dimension') ?? 'x'; + + $product->dmns = array_merge( + $product->dmns ?? [], + [ + $dimension => $text + ] + ); + + if ($product->save()) { + // Товар обновлён + + $return['dimension'] = $text; + } + } + + /** + * Конец алгоритма + */ + end: + + if (yii::$app->request->isPost) { + // POST-запрос + + yii::$app->response->format = Response::FORMAT_JSON; + + return $return; + } + + if ($model = Product::searchByCatn($catn)) { + return $this->render('index', compact('model')); + } else { + return $this->redirect('/'); + } + } + public function actionWriteImage(string $catn): array|string|null { // Инициализация @@ -203,17 +260,137 @@ class ProductController extends Controller goto end; } - if ($model = Product::searchByCatn($catn)) { + if ($product = Product::searchByCatn($catn)) { // Товар найден // Инициализация - $model->file_image = UploadedFile::getInstancesByName('images'); - $model->scenario = $model::SCENARIO_IMPORT_IMAGE; + $product->file_image = UploadedFile::getInstancesByName('images'); + $product->scenario = $product::SCENARIO_IMPORT_IMAGE; - if ($model->importImages() > 0) { + if ($product->importImages() > 0) { // Товар обновлён - $return['main'] = $this->renderPartial('index', compact('model')); + $return['main'] = $this->renderPartial('index', ['model' => $product]); + } + } + + /** + * Конец алгоритма + */ + end: + + if (yii::$app->request->isPost) { + // POST-запрос + + yii::$app->response->format = Response::FORMAT_JSON; + + return $return; + } + + if ($model = Product::searchByCatn($catn)) { + return $this->render('index', compact('model')); + } else { + return $this->redirect('/'); + } + } + + public function actionDeleteImage(string $catn): array|string|null + { + // Инициализация + $return = [ + '_csrf' => yii::$app->request->getCsrfToken() + ]; + $index = yii::$app->request->post('index') ?? yii::$app->request->get('index'); + + if (is_null($catn) || is_null($index)) { + // Не получены обязательные параметры + + yii::$app->response->statusCode = 500; + + goto end; + } + + if ($product = Product::searchByCatn($catn)) { + // Товар найден + + // Инициализация (буфер нужен из-за кривых сеттеров) + $buffer = $product->imgs; + + // Удаление + unset($buffer[$index]); + + // Запись + $product->imgs = $buffer; + + if ($product->save()) { + // Товар обновлён + + $return['main'] = $this->renderPartial('index', ['model' => $product]); + } + } + + /** + * Конец алгоритма + */ + end: + + if (yii::$app->request->isPost) { + // POST-запрос + + yii::$app->response->format = Response::FORMAT_JSON; + + return $return; + } + + if ($model = Product::searchByCatn($catn)) { + return $this->render('index', compact('model')); + } else { + return $this->redirect('/'); + } + } + + public function actionWriteCover(string $catn): array|string|null + { + // Инициализация + $return = [ + '_csrf' => yii::$app->request->getCsrfToken() + ]; + $index = yii::$app->request->post('index') ?? yii::$app->request->get('index'); + + if (is_null($catn) || is_null($index)) { + // Не получены обязательные параметры + + yii::$app->response->statusCode = 500; + + goto end; + } + + if ($product = Product::searchByCatn($catn)) { + // Товар найден + + // Инициализация (буфер нужен из-за кривых сеттеров) + $buffer = $product->imgs; + + foreach($buffer as $image_index => &$image) { + // Перебор изображений + + if ($image_index === (int) $index) { + // Найдено запрашиваемое изображение + + // Установка обложки + $image['covr'] = true; + } else { + $image['covr'] = false; + } + } + + // Запись + $product->imgs = $buffer; + + if ($product->save()) { + // Товар обновлён + + $return['main'] = $this->renderPartial('index', ['model' => $product]); } } diff --git a/mirzaev/skillparts/system/controllers/ProfileController.php b/mirzaev/skillparts/system/controllers/ProfileController.php index 3b5491f..26287e2 100644 --- a/mirzaev/skillparts/system/controllers/ProfileController.php +++ b/mirzaev/skillparts/system/controllers/ProfileController.php @@ -17,6 +17,7 @@ use app\models\Search; use app\models\Notification; use app\models\Settings; use app\models\SettingsEdgeSettings; +use app\models\connection\Dellin; class ProfileController extends Controller { @@ -90,6 +91,10 @@ class ProfileController extends Controller */ public function actionIndex(): string|array { + $browser = new Dellin(); + + $browser->syncCities(); + // Инициализация $model = yii::$app->user->identity; $panel = yii::$app->request->post('panel') ?? yii::$app->request->get('panel'); @@ -117,7 +122,8 @@ class ProfileController extends Controller } // Инициализация - $list = $model->genListOem(Supply::searchByAccount(select: 'supply.onec["ЗначенияСвойств"]', limit: null)); + $account_sections_city_list = null; + $import_sections_oem_list = $model->genListOem(Supply::searchByAccount(select: 'supply.onec["ЗначенияСвойств"]')); if (yii::$app->request->isPost) { // POST-запрос @@ -128,7 +134,8 @@ class ProfileController extends Controller 'main' => $this->renderPartial('index', compact( 'model', 'sidebar', - 'list', + 'account_sections_city_list', + 'import_sections_oem_list', 'panel' )), 'redirect' => '/profile', @@ -139,7 +146,8 @@ class ProfileController extends Controller return $this->render('index', compact( 'model', 'sidebar', - 'list', + 'account_sections_city_list', + 'import_sections_oem_list', 'panel' )); } diff --git a/mirzaev/skillparts/system/migrations/arangodb/m210412_171912_create_city_controller.php b/mirzaev/skillparts/system/migrations/arangodb/m210412_171912_create_city_controller.php new file mode 100644 index 0000000..8dec6f9 --- /dev/null +++ b/mirzaev/skillparts/system/migrations/arangodb/m210412_171912_create_city_controller.php @@ -0,0 +1,20 @@ +createCollection('city', ['type' => 2]); + } + + public function down() + { + $this->dropCollection('city'); + } +} diff --git a/mirzaev/skillparts/system/models/Account.php b/mirzaev/skillparts/system/models/Account.php index 3d6a4d6..6f0398c 100644 --- a/mirzaev/skillparts/system/models/Account.php +++ b/mirzaev/skillparts/system/models/Account.php @@ -9,6 +9,8 @@ use yii\web\IdentityInterface; use carono\exchange1c\interfaces\PartnerInterface; +use app\models\connection\Dellin; + /** * Аккаунт * @@ -245,6 +247,20 @@ class Account extends Document implements IdentityInterface, PartnerInterface return $this->save(); } + /** + * Генерация списка городов + * + * Актуальное (выбранное, активное) значение записывается первым + */ + public function genListCity(): array + { + $browser = new Dellin(); + + $request = $browser->get('https://api.github.com/user', [ + 'auth' => ['user', 'pass'] + ]); + } + /** * Генерация списка OEM-номеров * diff --git a/mirzaev/skillparts/system/models/City.php b/mirzaev/skillparts/system/models/City.php new file mode 100644 index 0000000..a35141d --- /dev/null +++ b/mirzaev/skillparts/system/models/City.php @@ -0,0 +1,65 @@ + 'Заполните поле: {attribute}' + ], + [ + [ + 'name', + 'code' + ], + 'string' + ], + [ + 'term', + 'boolean' + ] + ] + ); + } + + public function attributeLabels(): array + { + return array_merge( + parent::attributeLabels(), + [ + 'name' => 'Название', + 'code' => 'Код КЛАДР', + 'term' => 'Указатель наличия терминала в городе' + ] + ); + } +} diff --git a/mirzaev/skillparts/system/models/connection/Dellin.php b/mirzaev/skillparts/system/models/connection/Dellin.php new file mode 100644 index 0000000..6780a09 --- /dev/null +++ b/mirzaev/skillparts/system/models/connection/Dellin.php @@ -0,0 +1,155 @@ +browser = new Guzzle([ + 'base_uri' => 'https://api.dellin.ru/' + ]); + + $this->authorization(); + } + + /** + * Поиск городов + * + * @return array|null Найденные города + */ + public function searchCities(): ?array + { + // $this->onReady(function () { + // // Запрос городов + // $request = $this->browser->post('/v2/public/kladr.json', [ + // 'json' => [ + // 'appkey' => yii::$app->params['dellin']['key'], + + // ] + // ]) + // }); + } + + /** + * Синхронизация городов + * + * @return array|null Найденные города + * + * @todo Написать проверку по хешу + */ + public function syncCities(): ?array + { + return $this->ifReady(function () { + // Запрос ссылки на файл с городам + // Получаем hash и url () + $request = $this->browser->post('/v1/public/cities.json', [ + 'json' => [ + 'appkey' => yii::$app->params['dellin']['key'], + ] + ]); + + if ($request->getStatusCode() === 200) { + // Запрос прошел успешно + + // Инициализация + $response = json_decode((string) $request->getBody(), true); + + + if ($response['metadata']['status'] === 200) { + // Аутентификация и авторизация пройдены успешно + + // Запись сессии + + return $this; + } + + throw new Exception('Не удалось синхронизировать данные городов с ДеловыеЛинии', $response['metadata']['status']); + } + + + throw new Exception('Не удалось синхронизировать данные городов с ДеловыеЛинии', $request->getStatusCode); + + }); + } + + /** + * Аутентификация и авторизация + */ + protected function authorization(): ?self + { + return $this->ifReady(function () { + // Аутентификация и авторизация + $request = $this->browser->post('/v3/auth/login.json', [ + 'json' => [ + 'appkey' => yii::$app->params['dellin']['key'], + 'login' => yii::$app->params['dellin']['nickname'], + 'password' => yii::$app->params['dellin']['password'] + ] + ]); + + if ($request->getStatusCode() === 200) { + // Запрос прошел успешно + + // Инициализация + $response = json_decode((string) $request->getBody(), true); + + if ($response['metadata']['status'] === 200) { + // Аутентификация и авторизация пройдены успешно + + // Запись сессии + $this->session = $response['data']['sessionID']; + + return $this; + } + + throw new Exception('Не удалось авторизироваться в ДеловыеЛинии', $response['metadata']['status']); + } + + + throw new Exception('Не удалось авторизироваться в ДеловыеЛинии', $request->getStatusCode); + }); + } + + /** + * Проверка на то, что браузер готов к работе + * + * @param callable $function Код к выполнению + * @param [type] ...$vars Параметры к нему + * + * @return mixed Возврат из функции + */ + protected function ifReady(callable $function, ...$vars): mixed + { + if (isset($this->browser)) { + // Браузер инициализирован + + return $function(...$vars); + } + + throw new Exception('Браузер не инициализирован', 500); + } +} diff --git a/mirzaev/skillparts/system/views/profile/index.php b/mirzaev/skillparts/system/views/profile/index.php index 8660d13..1ec2552 100644 --- a/mirzaev/skillparts/system/views/profile/index.php +++ b/mirzaev/skillparts/system/views/profile/index.php @@ -10,7 +10,7 @@ if ( !yii::$app->user->isGuest && yii::$app->user->identity->agnt ) { - $panel ?? $panel = 'profile_panel_settings_import'; + $panel ?? $panel = 'profile_panel_settings_account'; } else { $panel ?? $panel = 'profile_panel_settings_account'; } @@ -28,38 +28,19 @@ if (

Настройки

- - user->isGuest - && yii::$app->user->identity->agnt - ) { - echo <<user->isGuest) : ?> + + user->identity->agnt) : ?> - HTML; - } - ?> + +
- /> -
- 1 -
- - user->isGuest - && yii::$app->user->identity->agnt - ) : ?> - /> + user->isGuest) : ?> + />
- 2 -
- - /> -
-
Параметры 1C
- +
Основная информация
'form_profile_settings', 'action' => false, @@ -73,20 +54,57 @@ if ( // Инициализация $model ?? $model = yii::$app->user->identity; - $list or $list = ['Нет данных']; + $account_sections_city_list or $account_sections_city_list = ['Нет данных']; ?> - field($model, 'opts[import_sections_oem]', ['options' => ['class' => "mb-1"]]) - ->dropDownList($list, [ - 'onChange' => 'page_profile_settings(this.parentElement.parentElement, \'profile_panel_settings_import\')', - 'disabled' => count($list) <= 1 - ])->label('OEM-номера'); ?> + field($model, 'opts[account_sections_city]', ['options' => ['class' => "mb-1"]]) + ->dropDownList($account_sections_city_list, [ + 'onChange' => 'page_profile_settings(this.parentElement.parentElement, \'profile_panel_settings_account\')' + ])->label('Город'); ?> - Выберите поле в котором хранятся ОЕМ-номера и повторите импорт - Значения взяты из импортированных товаров + Выберите город для рассчёта доставки
+ + user->identity->agnt) : ?> + /> +
+ 2 +
+ + /> +
+
Параметры 1C
+ + 'form_profile_settings', + 'action' => false, + 'fieldConfig' => [ + 'template' => '{label}{input}', + ], + 'options' => [ + 'onsubmit' => 'return false;' + ] + ]); + + // Инициализация + $model ?? $model = yii::$app->user->identity; + $import_sections_oem_list or $import_sections_oem_list = ['Нет данных']; + ?> + + field($model, 'opts[import_sections_oem]', ['options' => ['class' => "mb-1"]]) + ->dropDownList($import_sections_oem_list, [ + 'onChange' => 'page_profile_settings(this.parentElement.parentElement, \'profile_panel_settings_import\')', + 'disabled' => count($import_sections_oem_list) <= 1 + ])->label('OEM-номера'); ?> + + Выберите поле в котором хранятся ОЕМ-номера и повторите импорт + Значения взяты из импортированных товаров + + +
+
@@ -102,4 +120,4 @@ if ( || yii::$app->user->identity->type === 'moderator' ) : ?> - \ No newline at end of file + diff --git a/mirzaev/skillparts/system/web/Nginx_1.19_vhost.conf b/mirzaev/skillparts/system/web/Nginx_1.19_vhost.conf index 8ff2116..3a49c1f 100644 --- a/mirzaev/skillparts/system/web/Nginx_1.19_vhost.conf +++ b/mirzaev/skillparts/system/web/Nginx_1.19_vhost.conf @@ -48,7 +48,7 @@ location ~* ^.+\.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff? location / { # Force index.php routing (if not found) - try_files $uri $uri/ /index.php$is_args$args; + try_files $uri $uri/ /index_dev.php$is_args$args; # Force index.php routing (all requests) # rewrite ^/(.*)$ /index.php?/$1 last; diff --git a/mirzaev/skillparts/system/web/js/profile.js b/mirzaev/skillparts/system/web/js/profile.js index 6d191c1..02d4e5b 100644 --- a/mirzaev/skillparts/system/web/js/profile.js +++ b/mirzaev/skillparts/system/web/js/profile.js @@ -176,12 +176,21 @@ function page_profile_response(data, status) { } // Сокрытие первого элемента