]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-372] add sorting statuses
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 17 Mar 2025 12:54:52 +0000 (15:54 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 17 Mar 2025 12:54:52 +0000 (15:54 +0300)
erp24/controllers/crud/MarketplaceOrder1cStatusesController.php
erp24/migrations/m250314_114026_create_table_marketplace_order_1c_statuses.php
erp24/records/MarketplaceOrder1cStatuses.php
erp24/views/crud/marketplace-order-1c-statuses/index.php
erp24/web/js/crud/marketplace-order1c-statuses/index.js [new file with mode: 0644]

index 42a698d4fc38e94b1f726b75aa420bcc726b5a58..3046f987e16953ec4b7334f5d8fadc4f0b13046d 100644 (file)
@@ -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
index c02a15a94e5472f0eebe70321f8498eca593cb2c..4f059f61af08d892cc737b03c31edb9ff647004c 100755 (executable)
@@ -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],
+            ]);
         }
     }
 
index 38a6c5422b1f0bf8ec3878fb10576b6fa1a66905..d2289507bf46cf6530527c64999b19f63e2907e4 100644 (file)
@@ -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' => 'Порядок статусов',
         ];
     }
 }
index 011e0caa414093eac072e2583977ba741b26f86a..ef4ed3627ffda2cc431d52a20254f2f7cfe32079 100644 (file)
@@ -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;
 
     <p>
         <?= Html::a('Создать Маркетплейс Статус Заказа', ['create'], ['class' => 'btn btn-success']) ?>
+        <?= Html::button('Сортировка статусов заказа', ['class' => 'btn btn-secondary', 'onclick' => 'showSortingDialog()']) ?>
     </p>
 
 
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 (file)
index 0000000..327d307
--- /dev/null
@@ -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('<button class="btn btn-success">ОК</button>');
+            const $saveButton = $modalFooter.find('button');
+            $saveButton.on('click', () => { $mainModal.modal('hide'); })
+
+            let tbody = '';
+            $.each(data, (ind, el) => {
+                tbody += '<div style="display:flex; justify-content: flex-start; align-items: stretch; margin-top: 0.2rem;">' +
+                    '  <div class="drag-handler" style="width: 1rem;"></div>' +
+                    '  <div>' +
+                    {1 : "ФлауВау", 2 : "ЯндексМаркет"}[el.marketplace_id] + ' : ' + el.status +
+                    '  </div>' +
+                    '</div>'
+            })
+
+            $modalBody.html('<div class="draganddropTable">' + tbody + '</div>');
+
+            $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