]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-155] инетрфейс настройки марктеплейс приоритетов
authorAlexander Smirnov <fredeom@mail.ru>
Tue, 1 Oct 2024 08:19:23 +0000 (11:19 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Tue, 1 Oct 2024 08:19:23 +0000 (11:19 +0300)
erp24/actions/marketplace/PriorityAction.php [new file with mode: 0644]
erp24/controllers/MarketplaceController.php [new file with mode: 0644]
erp24/migrations/m240930_100018_create_table_marketplace_priority.php [new file with mode: 0755]
erp24/records/MarketplacePriority.php [new file with mode: 0644]
erp24/views/marketplace/priority.php [new file with mode: 0644]
erp24/web/js/marketplace/priority.js [new file with mode: 0644]

diff --git a/erp24/actions/marketplace/PriorityAction.php b/erp24/actions/marketplace/PriorityAction.php
new file mode 100644 (file)
index 0000000..60cd8a6
--- /dev/null
@@ -0,0 +1,51 @@
+<?php
+
+namespace yii_app\actions\marketplace;
+
+use Yii;
+use yii\base\Action;
+use yii\helpers\ArrayHelper;
+use yii\helpers\Json;
+use yii_app\records\MarketplacePriority;
+use yii_app\records\Products1c;
+use yii_app\records\ProductsClass;
+
+class PriorityAction extends Action
+{
+    public function run() {
+        if (Yii::$app->request->isPost) {
+            $guid = Yii::$app->request->post('guid');
+            $paramName = Yii::$app->request->post('paramName');
+            $value = Yii::$app->request->post('value');
+            $marketplacePriority = MarketplacePriority::findOne(['guid' => $guid]);
+            if (!$marketplacePriority) {
+                $marketplacePriority = new MarketplacePriority;
+                $marketplacePriority->guid = $guid;
+                $marketplacePriority->reminder_koef = 2;
+                $marketplacePriority->minimal_quantity = 2;
+            }
+            if ($paramName == 'reminder_koef') {
+                $marketplacePriority->reminder_koef = $value;
+            }
+            if ($paramName == 'minimal_quantity') {
+                $marketplacePriority->minimal_quantity = $value;
+            }
+            $marketplacePriority->save();
+            if ($marketplacePriority->getErrors()) {
+                return 'not ok Error: ' . Json::encode($marketplacePriority->getErrors());
+            }
+            return 'ok ' . $guid . ' ' . $paramName . ' ' . $value;
+        }
+
+        $productsClass = ArrayHelper::getColumn(ProductsClass::find()->where(['tip' => 'matrix'])->all(), 'category_id');
+        $products = ArrayHelper::map(Products1c::find()->where(['parent_id' => $productsClass])->all(), 'id', 'name');
+
+        $marketplacePriorityMap = [];
+        foreach (MarketplacePriority::find()->all() as $mp) {
+            /** @var $mp MarketplacePriority */
+            $marketplacePriorityMap[$mp->guid] = $mp;
+        }
+        return $this->controller->render('priority',
+            compact('products', 'marketplacePriorityMap'));
+    }
+}
\ No newline at end of file
diff --git a/erp24/controllers/MarketplaceController.php b/erp24/controllers/MarketplaceController.php
new file mode 100644 (file)
index 0000000..765fad6
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+
+namespace app\controllers;
+
+use yii\web\Controller;
+
+class MarketplaceController extends Controller
+{
+    public function actions() {
+        return [
+            'priority' => \yii_app\actions\marketplace\PriorityAction::class,
+        ];
+    }
+}
\ No newline at end of file
diff --git a/erp24/migrations/m240930_100018_create_table_marketplace_priority.php b/erp24/migrations/m240930_100018_create_table_marketplace_priority.php
new file mode 100755 (executable)
index 0000000..d899480
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m240930_100018_create_table_marketplace_priority
+ */
+class m240930_100018_create_table_marketplace_priority extends Migration
+{
+    const TABLE_NAME = 'erp24.marketplace_priority';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $this->createTable(self::TABLE_NAME, [
+            'id' => $this->primaryKey(),
+            'guid' => $this->string(36)->notNull()->comment('GUID матричного букета'),
+            'reminder_koef' => $this->float()->notNull()->comment('коэффициент остатка'),
+            'minimal_quantity' => $this->integer()->notNull()->comment('минимальное количество'),
+            'created_at' => $this->dateTime()->notNull()->comment('Дата создания'),
+            'created_by' => $this->integer()->notNull()->comment('id пользователя создавшего запись'),
+            'updated_at' => $this->datetime()->null()->comment('Дата изменения записи'),
+            'updated_by' => $this->integer()->null()->comment('id пользователя обновившего запись'),
+        ]);
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        $this->dropTable(self::TABLE_NAME);
+    }
+}
diff --git a/erp24/records/MarketplacePriority.php b/erp24/records/MarketplacePriority.php
new file mode 100644 (file)
index 0000000..938afe7
--- /dev/null
@@ -0,0 +1,84 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+
+/**
+ * This is the model class for table "marketplace_priority".
+ *
+ * @property int $id
+ * @property string $guid GUID матричного букета
+ * @property float $reminder_koef коэффициент остатка
+ * @property int $minimal_quantity минимальное количество
+ * @property string $created_at Дата создания
+ * @property int $created_by id пользователя создавшего запись
+ * @property string|null $updated_at Дата изменения записи
+ * @property int|null $updated_by id пользователя обновившего запись
+ */
+class MarketplacePriority extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'marketplace_priority';
+    }
+
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['guid', 'reminder_koef', 'minimal_quantity'], 'required'],
+            [['reminder_koef'], 'number'],
+            [['minimal_quantity', 'created_by', 'updated_by'], 'default', 'value' => null],
+            [['minimal_quantity', 'created_by', 'updated_by'], 'integer'],
+            [['created_at', 'updated_at'], 'safe'],
+            [['guid'], 'string', 'max' => 36],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'guid' => 'Guid',
+            'reminder_koef' => 'Reminder Koef',
+            'minimal_quantity' => 'Minimal Quantity',
+            'created_at' => 'Created At',
+            'created_by' => 'Created By',
+            'updated_at' => 'Updated At',
+            'updated_by' => 'Updated By',
+        ];
+    }
+
+    public function beforeSave($insert) {
+        if ($this->isNewRecord) {
+            $this->created_by = Yii::$app->user->id;
+            $this->updated_by = Yii::$app->user->id;
+        } else {
+            $this->updated_by = Yii::$app->user->id;
+        }
+        return parent::beforeSave($insert);
+    }
+}
diff --git a/erp24/views/marketplace/priority.php b/erp24/views/marketplace/priority.php
new file mode 100644 (file)
index 0000000..6fdccb7
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+use yii\helpers\Html;
+
+/** @var $storeId string */
+/** @var $storeName string */
+/** @var $products array */
+/** @var $marketplacePriorityMap array */
+
+$this->registerJsFile('/js/marketplace/priority.js', ['position' => \yii\web\View::POS_END]);
+
+?>
+
+<div class="marketplacePriority m-5">
+
+    <div class="w-50">
+        <table id="priorityTable">
+            <thead>
+            <tr>
+                <th>ID букета</th>
+                <th>Название</th>
+                <th>Коэффициент остатка</th>
+                <th>Минимальное количество</th>
+            </tr>
+            </thead>
+            <tbody>
+            <?php foreach($products as $guid => $name): ?>
+                <tr>
+                    <td><?= $guid ?></td>
+                    <td><?= $name ?></td>
+                    <?php
+                    $reminderKoef = $marketplacePriorityMap[$guid]->reminder_koef ?? 2;
+                    $minimalQuantity = $marketplacePriorityMap[$guid]->minimal_quantity ?? 2;
+                    ?>
+                    <td><input onblur="ajaxSavePrameter('<?= $guid ?>', 'reminder_koef', this.value)" value="<?= $reminderKoef ?>"/></td>
+                    <td><input onblur="ajaxSavePrameter('<?= $guid ?>', 'minimal_quantity', this.value)" value="<?= $minimalQuantity ?>"/></td>
+                </tr>
+            <?php endforeach; ?>
+            </tbody>
+        </table>
+    </div>
+</div>
+
+<script>
+
+</script>
\ No newline at end of file
diff --git a/erp24/web/js/marketplace/priority.js b/erp24/web/js/marketplace/priority.js
new file mode 100644 (file)
index 0000000..de4a738
--- /dev/null
@@ -0,0 +1,26 @@
+/* jshint esversion: 6 */
+
+const param22 = $('meta[name=csrf-param]').attr('content');
+const token22 = $('meta[name=csrf-token]').attr('content');
+
+$.ready(() => {
+    $('#priorityTable').DataTable({
+        sorting: false,
+        info: false,
+        paging: true,
+        searching: true,
+        language: data_table_language
+    });
+})
+
+function ajaxSavePrameter(guid, paramName, value) {
+    $.ajax({
+        url: window.location.href,
+        method: 'post',
+        dataType: 'text',
+        data: {guid, paramName, value, [param22]: token22},
+        success: function(data) {
+            console.log(data);
+        },
+    });
+}
\ No newline at end of file