]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ERP-150 Присвоить каждому магазину ID склада feature_zozirova_erp-150_marketplace_store origin/feature_zozirova_erp-150_marketplace_store
authormarina <m.zozirova@gmail.com>
Wed, 23 Oct 2024 13:41:02 +0000 (16:41 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 23 Oct 2024 13:41:02 +0000 (16:41 +0300)
erp24/controllers/MarketplaceStoreController.php [new file with mode: 0755]
erp24/migrations/m241023_064710_create_marketplace_store_table.php [new file with mode: 0644]
erp24/records/CityStore.php
erp24/records/MarketplaceStore.php [new file with mode: 0755]
erp24/views/marketplace-store/_form.php [new file with mode: 0644]
erp24/views/marketplace-store/create.php [new file with mode: 0644]
erp24/views/marketplace-store/index.php [new file with mode: 0644]
erp24/views/marketplace-store/update.php [new file with mode: 0644]
erp24/views/marketplace-store/view.php [new file with mode: 0644]

diff --git a/erp24/controllers/MarketplaceStoreController.php b/erp24/controllers/MarketplaceStoreController.php
new file mode 100755 (executable)
index 0000000..a5be886
--- /dev/null
@@ -0,0 +1,95 @@
+<?php
+
+namespace app\controllers;
+use Yii;
+use yii\data\ActiveDataProvider;
+use yii\helpers\ArrayHelper;
+use yii\web\Controller;
+use yii\web\NotFoundHttpException;
+use yii_app\records\Admin;
+use yii_app\records\CityStore;
+use yii_app\records\Firms;
+use yii_app\records\MarketplaceStore;
+
+class MarketplaceStoreController extends Controller
+{
+    public function actionIndex()
+    {
+        $firms = Firms::getInn();
+        $dataProvider = new ActiveDataProvider([
+            'query' => MarketplaceStore::find(),
+            'pagination' => false,
+        ]);
+
+        return $this->render('index', [
+            'dataProvider' => $dataProvider,
+            'firms' => $firms
+        ]);
+    }
+
+    public function actionView($id)
+    {
+        $model = $this->findModel($id);
+        $firms = Firms::getInn();
+
+        return $this->render('view', [
+            'model' => $model,
+            'firms' => $firms,
+        ]);
+    }
+
+    public function actionCreate()
+    {
+        $model = new MarketplaceStore();
+        $stores = CityStore::getAllActiveIdName();
+        $firms = Firms::getInn();
+        $storesGuid = CityStore::getAllActiveGuidId();
+
+
+        if ($model->load(Yii::$app->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('create', [
+            'model' => $model,
+            'stores' => $stores,
+            'storesGuid' => $storesGuid,
+            'firms' => $firms,
+        ]);
+    }
+
+    public function actionUpdate($id)
+    {
+        $model = MarketplaceStore::findOne($id);
+        $stores = CityStore::getAllActiveIdName();
+        $firms = Firms::getInn();
+        $storesGuid = CityStore::getAllActiveGuidId();
+
+        if ($model->load(Yii::$app->request->post()) && $model->save()) {
+            return $this->redirect(['view', 'id' => $model->id]);
+        }
+
+        return $this->render('update', [
+            'model' => $model,
+            'stores' => $stores,
+            'storesGuid' => $storesGuid,
+            'firms' => $firms,
+        ]);
+    }
+
+    public function actionDelete($id)
+    {
+        $this->findModel($id)->delete();
+
+        return $this->redirect(['index']);
+    }
+
+    protected function findModel($id)
+    {
+        if (($model = MarketplaceStore::findOne($id)) !== null) {
+            return $model;
+        }
+
+        throw new NotFoundHttpException('The requested page does not exist.');
+    }
+}
diff --git a/erp24/migrations/m241023_064710_create_marketplace_store_table.php b/erp24/migrations/m241023_064710_create_marketplace_store_table.php
new file mode 100644 (file)
index 0000000..bf3cae0
--- /dev/null
@@ -0,0 +1,44 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles the creation of table `{{%marketplace_store}}` in the `erp24` schema.
+ */
+class m241023_064710_create_marketplace_store_table extends Migration
+{
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        if (!$this->db->schema->getTableSchema('erp24.marketplace_store', true)) {
+            $this->createTable('{{%erp24.marketplace_store}}', [
+                'id' => $this->primaryKey(),
+                'store_id' => $this->integer()->notNull()->comment('id магазина'),
+                'guid' => $this->string(255)->notNull()->comment('гуид магазина'),
+                'name' => $this->string()->comment('название магазина(адрес) = название склада'),
+                'yandex_market_id' => $this->integer()->comment('id склада в данном маркетплейсе'),
+                'flowwow_id' => $this->integer()->comment('id склада в данном маркетплейсе'),
+                'firm' => $this->string(255)->comment('юр . лицо, к которому относится магазин'),
+                'created_at' => $this->datetime()->notNull()->comment('дата создания записи'),
+                'created_by' => $this->integer()->notNull()->comment('автор создания записи'),
+                'updated_at' => $this->datetime()->notNull()->comment('дата изменения записи'),
+                'updated_by' => $this->integer()->notNull()->comment('автор изменения записи'),
+            ]);
+
+            $this->addForeignKey('fk_marketplace_store_to_city_store', '{{%erp24.marketplace_store}}', 'store_id', '{{%city_store}}', 'id');
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        if ($this->db->schema->getTableSchema('erp24.marketplace_store', true)) {
+            $this->dropForeignKey('fk_marketplace_store_to_city_store', '{{%erp24.marketplace_store}}');
+            $this->dropTable('{{%erp24.marketplace_store}}');
+        }
+    }
+}
index 34bdb0997f45031b2857f60303ea856d4371f78b..36e1d3f8b72ad1e34b091327f298c149ad299b45 100755 (executable)
@@ -265,6 +265,22 @@ class CityStore extends ActiveRecord
         return $result;
     }
 
+
+    public static function getAllActiveGuidId()
+    {
+        $result = [];
+
+        $values = self::find()->joinWith('storeGuid')
+            ->orderBy([self::tableName() . '.id' => SORT_ASC])->asArray()
+            ->all();
+
+        if (!empty($values)) {
+            $result = ArrayHelper::map($values,  'id', 'storeGuid.export_val');
+        }
+
+        return $result;
+    }
+
     public static function getCityStoreById(int $id, $withGuid = false): array
     {
         $query = self::find();
diff --git a/erp24/records/MarketplaceStore.php b/erp24/records/MarketplaceStore.php
new file mode 100755 (executable)
index 0000000..7c30aa6
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+use yii\behaviors\BlameableBehavior;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+
+/**
+ * This is the model class for table "marketplace_store".
+ *
+ * @property int $id
+ * @property int $store_id
+ * @property string $guid
+ * @property int $yandex_market_id
+ * @property int $flowwow_id
+ * @property string $firm
+ * @property int $created_at
+ * @property int $created_by
+ * @property int $updated_at
+ * @property int $updated_by
+ */
+class MarketplaceStore extends \yii\db\ActiveRecord
+{
+    /**
+     * {@inheritdoc}
+     */
+    public static function tableName()
+    {
+        return 'marketplace_store';
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function rules()
+    {
+        return [
+            [['store_id', 'guid', 'yandex_market_id', 'flowwow_id', 'firm'], 'required'],
+            [['store_id'], 'exist', 'targetClass' => CityStore::class, 'targetAttribute' => 'id'],
+            [['name', 'guid', 'firm'], 'string'],
+            [['store_id', 'yandex_market_id', 'flowwow_id', 'created_at', 'created_by', 'updated_at', 'updated_by'], 'integer'],
+
+        ];
+    }
+
+    public function behaviors()
+    {
+        return [
+            [
+                'class' => TimestampBehavior::class,
+                'createdAtAttribute' => 'created_at',
+                'updatedAtAttribute' => 'updated_at',
+                'value' => new Expression('NOW()'),
+            ],
+            [
+                'class' => BlameableBehavior::class,
+                'createdByAttribute' => 'created_by',
+                'updatedByAttribute' => 'updated_by',
+            ],
+        ];
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function attributeLabels()
+    {
+        return [
+            'id' => 'ID',
+            'store_id' => 'ID магазина',
+            'guid' => 'GUID магазина',
+            'name' => 'Название магазина(адрес) = Название склада',
+            'yandex_market_id' => 'ID склада в Яндекс Маркете',
+            'flowwow_id' => 'ID склада в Flowwow',
+            'firm' => 'Юр.лицо, к которому относится магазин',
+            'created_at' => 'Дата создания записи',
+            'created_by' => 'Автор создания записи',
+            'updated_at' => 'Дата изменения записи',
+            'updated_by' => 'Автор изменения записи'
+        ];
+    }
+
+    public function getStore() {
+        return $this->hasOne(CityStore::class, ['id' => 'store_id']);
+    }
+
+    public function getCreatedBy() {
+        return $this->hasOne(Admin::class, ['id' => 'created_by']);
+    }
+
+    public function getUpdatedBy() {
+        return $this->hasOne(Admin::class, ['id' => 'updated_by']);
+    }
+}
diff --git a/erp24/views/marketplace-store/_form.php b/erp24/views/marketplace-store/_form.php
new file mode 100644 (file)
index 0000000..7331b3f
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+use yii\helpers\Html;
+use yii\widgets\ActiveForm;
+
+/* @var $model yii_app\records\MarketplaceStore */
+/* @var $form yii\widgets\ActiveForm */
+?>
+
+<div class="marketplace-store-form">
+
+    <?php $form = ActiveForm::begin(); ?>
+        <?= $form->field($model, 'store_id')->dropDownList($stores, [
+            'prompt' => 'Выберите магазин',
+            'onchange' => 'updateGuid(this.value)' // Вызов функции для обновления guid
+        ]) ?>
+
+        <?= $form->field($model, 'guid')->textInput(['maxlength' => true, 'value' => $model->guid, 'readonly' => true, 'id' => 'guid-input']) ?>
+    <?= $form->field($model, 'yandex_market_id')->textInput() ?>
+    <?= $form->field($model, 'flowwow_id')->textInput(['type' => 'integer']) ?>
+    <?= $form->field($model, 'firm')->dropDownList($firms, ['prompt' => 'Выберите юр лицо']) ?>
+
+    <div class="form-group">
+        <?= Html::submitButton($model->isNewRecord ? 'Создать' : 'Сохранить', ['class' => 'btn btn-success']) ?>
+    </div>
+
+    <?php ActiveForm::end(); ?>
+
+</div>
+
+
+<script>
+    const storesGuid = <?= json_encode($storesGuid) ?>; // Преобразуем массив GUID в JSON
+
+    function updateGuid(storeId) {
+        const guidInput = document.getElementById('guid-input');
+        guidInput.value = storesGuid[storeId] || ''; // Обновляем значение GUID
+    }
+</script>
\ No newline at end of file
diff --git a/erp24/views/marketplace-store/create.php b/erp24/views/marketplace-store/create.php
new file mode 100644 (file)
index 0000000..c7031ba
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use yii\helpers\Html;
+
+$this->title = 'Создать Магазин';
+$this->params['breadcrumbs'][] = ['label' => 'Список Магазинов', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="marketplace-store-create">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+        'stores' => $stores,
+        'storesGuid' => $storesGuid,
+        'firms' => $firms,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/marketplace-store/index.php b/erp24/views/marketplace-store/index.php
new file mode 100644 (file)
index 0000000..43c0157
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+use yii_app\records\Firms;
+
+$this->title = 'Список Магазинов';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="marketplace-store-index">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Создать Магазин', ['create'], ['class' => 'btn btn-success']) ?>
+    </p>
+
+    <?= GridView::widget([
+        'dataProvider' => $dataProvider,
+        'columns' => [
+            ['class' => 'yii\grid\SerialColumn'],
+
+            'id',
+            [
+                'attribute' => 'store_id',
+                'value' => function ($model) {
+                    return $model->store->name;
+                }
+            ],
+            'guid',
+            'yandex_market_id',
+            'flowwow_id',
+            [
+                'attribute' => 'firm',
+                'value' => function ($model) {
+                    return Firms::getInn()[$model->firm];
+                }
+            ],
+            'created_at',
+            'updated_at',
+
+            ['class' => 'yii\grid\ActionColumn'],
+        ],
+    ]); ?>
+
+</div>
diff --git a/erp24/views/marketplace-store/update.php b/erp24/views/marketplace-store/update.php
new file mode 100644 (file)
index 0000000..f5e9bca
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+use yii\helpers\Html;
+
+$this->title = 'Обновить Магазин: ' . $model->store->name;
+$this->params['breadcrumbs'][] = ['label' => 'Список Магазинов', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="marketplace-store-update">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <?= $this->render('_form', [
+        'model' => $model,
+        'stores' => $stores,
+        'storesGuid' => $storesGuid,
+        'firms' => $firms,
+    ]) ?>
+
+</div>
diff --git a/erp24/views/marketplace-store/view.php b/erp24/views/marketplace-store/view.php
new file mode 100644 (file)
index 0000000..7c98826
--- /dev/null
@@ -0,0 +1,68 @@
+<?php
+
+use yii\helpers\Html;
+
+$this->title = 'Просмотр магазина: ' . $model->store->name;
+$this->params['breadcrumbs'][] = ['label' => 'Список Магазинов', 'url' => ['index']];
+$this->params['breadcrumbs'][] = $this->title;
+?>
+
+<div class="marketplace-store-view">
+
+    <h1><?= Html::encode($this->title) ?></h1>
+
+    <p>
+        <?= Html::a('Обновить', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
+        <?= Html::a('Удалить', ['delete', 'id' => $model->id], [
+            'class' => 'btn btn-danger',
+            'data' => [
+                'confirm' => 'Вы уверены, что хотите удалить этот элемент?',
+                'method' => 'post',
+            ],
+        ]) ?>
+    </p>
+
+    <table class="table table-bordered">
+        <tr>
+            <th>ID</th>
+            <td><?= Html::encode($model->id) ?></td>
+        </tr>
+        <tr>
+            <th>ID Магазина</th>
+            <td><?= Html::encode($model->store->name) ?></td>
+        </tr>
+        <tr>
+            <th>GUID</th>
+            <td><?= Html::encode($model->guid) ?></td>
+        </tr>
+        <tr>
+            <th>ID в Яндекс.Маркете</th>
+            <td><?= Html::encode($model->yandex_market_id) ?></td>
+        </tr>
+        <tr>
+            <th>ID в Flowwow</th>
+            <td><?= Html::encode($model->flowwow_id) ?></td>
+        </tr>
+        <tr>
+            <th>Юридическое Лицо</th>
+            <td><?= Html::encode($firms[$model->firm]) ?></td>
+        </tr>
+        <tr>
+            <th>Автор создания</th>
+            <td><?= Html::encode($model->createdBy->name) ?></td>
+        </tr>
+        <tr>
+            <th>Дата создания</th>
+            <td><?= Html::encode(date('Y-m-d H:i:s', strtotime($model->created_at))) ?></td>
+        </tr>
+        <tr>
+            <th>Автор обновления</th>
+            <td><?= Html::encode($model->updatedBy->name) ?></td>
+        </tr>
+        <tr>
+            <th>Дата обновления</th>
+            <td><?= Html::encode(date('Y-m-d H:i:s', strtotime($model->updated_at))) ?></td>
+        </tr>
+    </table>
+
+</div>