From ac090f7455fbd79e31fcf0396b489cd0e40a2956 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Mon, 17 Mar 2025 15:54:52 +0300 Subject: [PATCH] [ERP-372] add sorting statuses --- .../MarketplaceOrder1cStatusesController.php | 26 ++++++-- ...te_table_marketplace_order_1c_statuses.php | 20 +++++- erp24/records/MarketplaceOrder1cStatuses.php | 5 +- .../marketplace-order-1c-statuses/index.php | 5 ++ .../marketplace-order1c-statuses/index.js | 66 +++++++++++++++++++ 5 files changed, 114 insertions(+), 8 deletions(-) create mode 100644 erp24/web/js/crud/marketplace-order1c-statuses/index.js diff --git a/erp24/controllers/crud/MarketplaceOrder1cStatusesController.php b/erp24/controllers/crud/MarketplaceOrder1cStatusesController.php index 42a698d4..3046f987 100644 --- a/erp24/controllers/crud/MarketplaceOrder1cStatusesController.php +++ b/erp24/controllers/crud/MarketplaceOrder1cStatusesController.php @@ -2,11 +2,14 @@ namespace yii_app\controllers\crud; +use Yii; +use yii\helpers\ArrayHelper; use yii_app\records\MarketplaceOrder1cStatuses; use yii\data\ActiveDataProvider; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use yii_app\services\LessonService; /** * MarketplaceOrder1cStatusesController implements the CRUD actions for MarketplaceOrder1cStatuses model. @@ -22,7 +25,7 @@ class MarketplaceOrder1cStatusesController extends Controller parent::behaviors(), [ 'verbs' => [ - 'class' => VerbFilter::className(), + 'class' => VerbFilter::class, 'actions' => [ 'delete' => ['POST'], ], @@ -36,10 +39,25 @@ class MarketplaceOrder1cStatusesController extends Controller * * @return string */ - public function actionIndex() - { + public function actionIndex() { + if (Yii::$app->request->isPost) { + $action = Yii::$app->request->post('action'); + if ($action == 'sorting') { + $oldIndex = Yii::$app->request->post('oldIndex'); + $newIndex = Yii::$app->request->post('newIndex'); + + $mo1s = MarketplaceOrder1cStatuses::find()->orderBy(['posit' => SORT_ASC])->all(); + LessonService::movePosition($mo1s, $oldIndex, $newIndex, 'posit'); + + return $oldIndex . ' ' . $newIndex; + } else { + $this->response->format = \yii\web\Response::FORMAT_JSON; + return $this->asJson(MarketplaceOrder1cStatuses::find()->orderBy(['posit' => SORT_ASC])->asArray()->all()); + } + } + $dataProvider = new ActiveDataProvider([ - 'query' => MarketplaceOrder1cStatuses::find(), + 'query' => MarketplaceOrder1cStatuses::find()->orderBy(["posit" => SORT_ASC]), /* 'pagination' => [ 'pageSize' => 50 diff --git a/erp24/migrations/m250314_114026_create_table_marketplace_order_1c_statuses.php b/erp24/migrations/m250314_114026_create_table_marketplace_order_1c_statuses.php index c02a15a9..4f059f61 100755 --- a/erp24/migrations/m250314_114026_create_table_marketplace_order_1c_statuses.php +++ b/erp24/migrations/m250314_114026_create_table_marketplace_order_1c_statuses.php @@ -21,11 +21,25 @@ class m250314_114026_create_table_marketplace_order_1c_statuses extends Migratio 'marketplace_id' => $this->integer()->notNull()->comment('Маркетплейс'), 'status' => $this->string(100)->notNull()->comment('Статус'), 'status_instruction' => $this->text()->notNull()->comment('Инструкция к статусу'), + 'posit' => $this->integer()->notNull()->defaultValue(0)->comment('Порядок статусов'), ]); -// $this->batchInsert(self::TABLE_NAME, ['marketplace_id', 'status', 'status_instruction'], [ -// -// ]); + $this->batchInsert(self::TABLE_NAME, ['marketplace_id', 'status', 'status_instruction', 'posit'], [ + [1, 'Новый', '', 1], + [1, 'Правки флориста', '', 2], + [1, 'В работе', '', 3], + [1, 'Собрано', '', 4], + [1, 'Передано курьеру', '', 5], + [1, 'Успех', '', 6], + [1, 'Отказ', '', 7], + [2, 'Новый', '', 7 + 1], + [2, 'Правки флориста', '', 7 + 2], + [2, 'В работе', '', 7 + 3], + [2, 'Собрано', '', 7 + 4], + [2, 'Передано курьеру', '', 7 + 5], + [2, 'Успех', '', 7 + 6], + [2, 'Отказ', '', 7 + 7], + ]); } } diff --git a/erp24/records/MarketplaceOrder1cStatuses.php b/erp24/records/MarketplaceOrder1cStatuses.php index 38a6c542..d2289507 100644 --- a/erp24/records/MarketplaceOrder1cStatuses.php +++ b/erp24/records/MarketplaceOrder1cStatuses.php @@ -11,6 +11,7 @@ use Yii; * @property int $marketplace_id Маркетплейс * @property string $status Статус * @property string $status_instruction Инструкция к статусу + * @property int $posit Порядок статусов */ class MarketplaceOrder1cStatuses extends \yii\db\ActiveRecord { @@ -30,7 +31,8 @@ class MarketplaceOrder1cStatuses extends \yii\db\ActiveRecord return [ [['marketplace_id', 'status', 'status_instruction'], 'required'], [['marketplace_id'], 'default', 'value' => null], - [['marketplace_id'], 'integer'], + [['posit'], 'default', 'value' => 0], + [['marketplace_id', 'posit'], 'integer'], [['status_instruction'], 'string'], [['status'], 'string', 'max' => 100], ]; @@ -46,6 +48,7 @@ class MarketplaceOrder1cStatuses extends \yii\db\ActiveRecord 'marketplace_id' => 'Маркетплейс ID', 'status' => 'Статус', 'status_instruction' => 'Инструкция к статусу', + 'posit' => 'Порядок статусов', ]; } } diff --git a/erp24/views/crud/marketplace-order-1c-statuses/index.php b/erp24/views/crud/marketplace-order-1c-statuses/index.php index 011e0caa..ef4ed362 100644 --- a/erp24/views/crud/marketplace-order-1c-statuses/index.php +++ b/erp24/views/crud/marketplace-order-1c-statuses/index.php @@ -9,6 +9,10 @@ use yii\grid\GridView; /** @var yii\web\View $this */ /** @var yii\data\ActiveDataProvider $dataProvider */ +$this->registerCssFile('/css/customSortable.css'); +$this->registerJsFile('/js/Sortable.js', ['position' => \yii\web\View::POS_END]); +$this->registerJsFile('/js/crud/marketplace-order1c-statuses/index.js', ['position' => \yii\web\View::POS_END]); + $this->title = 'Маркетплейс статусы заказа'; $this->params['breadcrumbs'][] = $this->title; ?> @@ -18,6 +22,7 @@ $this->params['breadcrumbs'][] = $this->title;

'btn btn-success']) ?> + 'btn btn-secondary', 'onclick' => 'showSortingDialog()']) ?>

diff --git a/erp24/web/js/crud/marketplace-order1c-statuses/index.js b/erp24/web/js/crud/marketplace-order1c-statuses/index.js new file mode 100644 index 00000000..327d307f --- /dev/null +++ b/erp24/web/js/crud/marketplace-order1c-statuses/index.js @@ -0,0 +1,66 @@ +/* jshint esversion: 6 */ + +const param31 = $('meta[name=csrf-param]').attr("content"); +const token31 = $('meta[name=csrf-token]').attr("content"); + +function showSortingDialog() { + $.ajax({ + method : "POST", + url : window.location.href, + data : {[param31] : token31}, + dataType : "json", + success: function (data) { + const $mainModal = $('#mainModal'); + const $modalBody = $mainModal.find('.modal-body'); + const $modalFooter = $mainModal.find('.modal-footer'); + $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); }); + $mainModal.find('.modal-title').html('Сортировка статусов'); + $modalFooter.html(''); + const $saveButton = $modalFooter.find('button'); + $saveButton.on('click', () => { $mainModal.modal('hide'); }) + + let tbody = ''; + $.each(data, (ind, el) => { + tbody += '
' + + '
' + + '
' + + {1 : "ФлауВау", 2 : "ЯндексМаркет"}[el.marketplace_id] + ' : ' + el.status + + '
' + + '
' + }) + + $modalBody.html('
' + tbody + '
'); + + $mainModal.modal('show'); + + var $tableBody = $(".draganddropTable"); + + $tableBody.each(function () { + Sortable.create( + this, + { + animation: 250, + scroll: true, + handle: ".drag-handler", + onEnd: function (e) { + const name = $(e.from).data('name'); + const oldIndex = e.oldIndex; + const newIndex = e.newIndex; + $.post(window.location.href, { + action: 'sorting', + name : name, + oldIndex : oldIndex, + newIndex : newIndex, + [param31] : token31 + }, + function (data) { + console.log(data); + }); + } + } + ); + }); + + } + }); +} \ No newline at end of file -- 2.39.5