]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
ссылка на заказ
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 17 Apr 2025 09:56:02 +0000 (12:56 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Thu, 17 Apr 2025 09:56:02 +0000 (12:56 +0300)
erp24/controllers/MarketplaceOrdersController.php
erp24/migrations/m250417_074545_add_order_link_column_to_marketlplace_orders_table.php [new file with mode: 0644]
erp24/records/MarketplaceOrders.php
erp24/services/MarketplaceService.php
erp24/views/marketplace-orders/get-flowwow-orders.php
erp24/views/marketplace-orders/view.php

index e4bedccc4f2211773dc14f10e83b39d603d446e6..7f1a1af1ab60075e296c3b203a0fbb289ab06c6a 100644 (file)
@@ -143,6 +143,40 @@ class MarketplaceOrdersController extends Controller
         ]);
     }
 
+    public function actionSetOrderLink()
+    {
+        $orders = MarketplaceOrders::find()->where(['order_link' => null])->all();
+
+        foreach ($orders as $order) {
+            if ($order->marketplace_id == 1) {
+                $baseUrl = "https://flowwow.com/admin/order/index?Order%5Bid%5D=";
+                $order->order_link = $baseUrl . $order->marketplace_order_id;
+                if(!$order->save()) {
+                    Yii::error('Ошибка сохранения ссылки' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__);
+                }
+//                $data = json_decode($order->raw_data, true);
+//                if (isset($data['orderLink'])) {
+//                    $order->order_link = $data['orderLink'];
+//                    if(!$order->save()) {
+//                        Yii::error('Ошибка сохранения ссылки' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__);
+//                    }
+//                }
+            } elseif ($order->marketplace_id == 2) {
+                $baseUrl = "https://partner.market.yandex.ru/order/";
+                $order->order_link = $baseUrl . $order->marketplace_order_id . "?tld=ru&partnerId=197274828";
+                if(!$order->save()) {
+                    Yii::error('Ошибка сохранения ссылки' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__);
+                }
+            } else {
+                continue;
+            }
+
+        }
+
+        $this->redirect(['/marketplace-orders/index']);
+
+    }
+
     public function actionUpdateToReadyStatus($id)
     {
         $model = $this->findModel($id);
diff --git a/erp24/migrations/m250417_074545_add_order_link_column_to_marketlplace_orders_table.php b/erp24/migrations/m250417_074545_add_order_link_column_to_marketlplace_orders_table.php
new file mode 100644 (file)
index 0000000..9eeeb65
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Handles adding columns to table `{{%marketlplace_orders}}`.
+ */
+class m250417_074545_add_order_link_column_to_marketlplace_orders_table extends Migration
+{
+    const TABLE_NAME = 'erp24.marketplace_orders';
+    /**
+     * {@inheritdoc}
+     */
+    public function safeUp()
+    {
+        $table = $this->db->schema->getTableSchema(self::TABLE_NAME);
+        if ($table === null) {
+            return;
+        }
+
+        if (!$this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('order_link')) {
+            $this->addColumn(
+                self::TABLE_NAME,
+                'order_link',
+                $this->text()->null()->comment('Ссылка на заказ в МП')
+            );
+        }
+    }
+
+    /**
+     * {@inheritdoc}
+     */
+    public function safeDown()
+    {
+        if ($this->db->schema->getTableSchema(self::TABLE_NAME, true)->getColumn('order_link')) {
+            $this->dropColumn(self::TABLE_NAME, 'order_link');
+        }
+    }
+}
index 025ff03e6181f6c173227aef4d36703ff89da9df..c265458f1c401db904f8b31e6cb957a748ab9d1e 100644 (file)
@@ -34,6 +34,7 @@ use Yii;
  * @property string|null $number_1c Название документа в 1с
  * @property string|null $telegram_error ошибка телеграмма
  * @property string|null $status_processing_1c Статус обработки заказа в 1С
+ * @property string|null $order_link Ссылка на заказ в МП
  */
 class MarketplaceOrders extends \yii\db\ActiveRecord
 {
@@ -84,11 +85,11 @@ class MarketplaceOrders extends \yii\db\ActiveRecord
             [['store_id', 'warehouse_guid', 'returned_at', 'return_data', 'raw_data', 'guid'], 'default', 'value' => null],
             [['cancel_requested', 'status_telegram'], 'default', 'value' => 0],
             [['marketplace_order_id', 'marketplace_id', 'marketplace_name', 'status_id', 'substatus_id', 'creation_date', 'updated_at', 'total', 'delivery_total', 'buyer_total_before_discount', 'tax_system', 'payment_type', 'payment_method'], 'required'],
-            [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_processing_1c'], 'default', 'value' => null],
+            [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_processing_1c', 'order_link'], 'default', 'value' => null],
             [[ 'fake'], 'default', 'value' => 0],
             [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'marketplace_id', 'status_telegram', 'status_processing_1c'], 'integer'],
             [['creation_date', 'updated_at', 'returned_at'], 'safe'],
-            [['return_data', 'raw_data', 'marketplace_name', 'telegram_error'], 'string'],
+            [['return_data', 'raw_data', 'marketplace_name', 'telegram_error', 'order_link'], 'string'],
             [['total', 'delivery_total', 'buyer_total_before_discount'], 'number'],
             [['marketplace_order_id'], 'string', 'max' => 64],
             [['number_1c'], 'string', 'max' => 100],
@@ -132,6 +133,7 @@ class MarketplaceOrders extends \yii\db\ActiveRecord
             'status_telegram' => 'Статус отправки в телеграм',
             'telegram_error' => 'Ошибка телеграмма',
             'status_processing_1c' => 'Статус обработки заказа в 1С',
+            'order_link' => 'Ссылка на заказ в МП',
         ];
     }
 
index f9a1bb5c4439bf2f655a75d881e1519fb60d28cf..13f31c0bf088317e3bccdc5c815d37bed747412a 100644 (file)
@@ -1023,6 +1023,8 @@ class MarketplaceService
                     $marketplaceOrder->substatus_id = (int)$substatusId;
                     $marketplaceOrder->raw_data = $newRawData;
                     $marketplaceOrder->status_1c = MarketplaceOrders::STATUSES_1C_CREATED_IN_ERP;
+                    $baseUrl = "https://partner.market.yandex.ru/order/";
+                    $marketplaceOrder->order_link = $baseUrl . $marketplaceOrder->marketplace_order_id . "?tld=ru&partnerId=197274828";
 
                     if ($marketplaceOrder->save()) {
                         self::sendMessageToTelegram($marketplaceOrder->guid, "Тестовое сообщение для https://tracker.yandex.ru/ERP-326 из [1]");
@@ -2004,6 +2006,9 @@ class MarketplaceService
         $marketplaceOrder->marketplace_id = 1;
         $marketplaceOrder->store_id = $store->store_id;
         $marketplaceOrder->status_1c = MarketplaceOrders::STATUSES_1C_CREATED_IN_ERP;
+        //$marketplaceOrder->order_link = $order['orderLink'];
+        $baseUrl = "https://flowwow.com/admin/order/index?Order%5Bid%5D=";
+        $marketplaceOrder->order_link = $baseUrl . $marketplaceOrder->marketplace_order_id;
 
         return $marketplaceOrder;
     }
index 6007015f9abf7022350d9bad1ebc91535a272438..f9f4e1d12131b72ad9f523a58cc6341c9c10f17e 100644 (file)
@@ -12,6 +12,7 @@ $this->title = 'Загрузка заказов Flowwow';
 <div class="get-flowwow-orders p-4">
 
     <?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary my-4']) ?>
+    <?= Html::a('Ссылки на заказы', ['set-order-link'], ['class' => 'btn btn-primary my-4']) ?>
     <h1><?= Html::encode($this->title) ?></h1>
 
 <?php $form = ActiveForm::begin(); ?>
index 7e6b74df0cc0974e4a9d6372a731436be6faf637..6399c7f53fbc621b180fcae71f4435a10868a53c 100644 (file)
@@ -22,6 +22,7 @@ $this->params['breadcrumbs'][] = $this->title;
         'model' => $model,
         'attributes' => [
             'id',
+            'order_link',
             'marketplace_order_id',
             [
                 'attribute' => 'store_id',