]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Установка доставки
authorfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 23 Apr 2025 11:26:46 +0000 (14:26 +0300)
committerfomichev <vladimir.fomichev@erp-flowers.ru>
Wed, 23 Apr 2025 11:26:46 +0000 (14:26 +0300)
erp24/controllers/MarketplaceOrdersController.php
erp24/records/MarketplaceOrders.php
erp24/views/marketplace-orders/get-flowwow-orders.php
erp24/views/marketplace-orders/view.php

index 9fb4e5aeafc3b0a8774d42aff4c06f326f2e10ae..a42e8c0d8cdb194b8dab705b5cc4dabf66744ab2 100644 (file)
@@ -542,6 +542,83 @@ class MarketplaceOrdersController extends Controller
 
     }
 
+    public function actionSetOrderDelivery()
+    {
+        $orders = MarketplaceOrders::find()->where(['delivery_to' => null])->all();
+
+        foreach ($orders as $order) {
+            $data = json_decode($order->raw_data, true);
+            if ($order->marketplace_id == 1 && isset($data['delivery'])) {
+                $deliveryText = (explode(',', $data['delivery']))[1] ?? '';
+                $deliveryText = trim(str_replace('Нижний Новгород', '', $deliveryText));
+
+                $months = [
+                    'января' => '01', 'февраля' => '02', 'марта' => '03',
+                    'апреля' => '04', 'мая' => '05', 'июня' => '06',
+                    'июля' => '07', 'августа' => '08', 'сентября' => '09',
+                    'октября' => '10', 'ноября' => '11', 'декабря' => '12',
+                ];
+
+                $date = null;
+
+                if (preg_match('/(\d{1,2})\s+([а-яА-Я]+)\s+(\d{4})/u', $deliveryText, $match)) {
+                    [$__, $day, $monthName, $year] = $match;
+                    $month = $months[mb_strtolower($monthName)] ?? null;
+                    if ($month) {
+                        $date = sprintf('%04d-%02d-%02d', $year, $month, $day);
+                    }
+                }
+
+                $time = null;
+
+                // интервал: в 22:30—23:00
+                if (preg_match('/в\s+(\d{1,2}:\d{2})[—-](\d{1,2}:\d{2})/u', $deliveryText, $timeMatch)) {
+                    $time = $timeMatch[1];
+                }
+                // вариант: с 16:26
+                elseif (preg_match('/с\s+(\d{1,2}:\d{2})/u', $deliveryText, $timeMatch)) {
+                    $time = $timeMatch[1];
+                }
+
+                if ($date && $time) {
+                    $order->delivery_to = "$date $time:00";
+
+                    if (!$order->save()) {
+                        Yii::error('Ошибка сохранения delivery_to: ' . json_encode($order->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__);
+                    }
+                } else {
+                    Yii::warning("Не удалось разобрать delivery: '{$deliveryText}'", __METHOD__);
+                }
+            } elseif ($order->marketplace_id == 2) {
+               // var_dump($data['delivery']['shipments']); die();
+                if (isset($data['delivery']) && isset($data['delivery']['shipments'])) {
+                    $deliveryData = $data['delivery'];
+                    $shipments = $deliveryData['shipments'];
+                    $deliveryDates = isset($deliveryData['dates']) ? $deliveryData['dates'] : [];
+                    foreach ($shipments as $shipment) {
+                        $date = isset($shipment['shipmentDate']) ? $shipment['shipmentDate'] : null;
+                        $time = isset($shipment['shipmentTime']) ? $shipment['shipmentTime'] : null;
+                        if (!$date && !$time) {
+                           continue;
+                        } else {
+                            $deliveryDateTo = $date ?? ($deliveryDates['fromDate'] ?? explode(' ', $order->creation_date)[0]);
+                            $deliveryTimeTo = $time ?? ($deliveryDates['fromTime'] ?? explode(' ', $order->creation_date)[1]);
+                            $datetimeString = $deliveryDateTo . ' ' . $deliveryTimeTo;
+                            $order->delivery_to = date('Y-m-d H:i:s', strtotime($datetimeString));
+                            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);
index c265458f1c401db904f8b31e6cb957a748ab9d1e..05bbf7adbd01fadc82422ccbbc2342be3160e607 100644 (file)
@@ -35,6 +35,7 @@ use Yii;
  * @property string|null $telegram_error ошибка телеграмма
  * @property string|null $status_processing_1c Статус обработки заказа в 1С
  * @property string|null $order_link Ссылка на заказ в МП
+ * @property string|null $delivery_to Сроки доставки заказа
  */
 class MarketplaceOrders extends \yii\db\ActiveRecord
 {
@@ -85,11 +86,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', 'order_link'], 'default', 'value' => null],
+            [['store_id', 'status_id', 'substatus_id', 'fake', 'cancel_requested', 'status_1c', 'status_processing_1c', 'order_link', 'delivery_to'], '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', 'order_link'], 'string'],
+            [['return_data', 'raw_data', 'marketplace_name', 'telegram_error', 'order_link', 'delivery_to'], 'string'],
             [['total', 'delivery_total', 'buyer_total_before_discount'], 'number'],
             [['marketplace_order_id'], 'string', 'max' => 64],
             [['number_1c'], 'string', 'max' => 100],
@@ -134,6 +135,7 @@ class MarketplaceOrders extends \yii\db\ActiveRecord
             'telegram_error' => 'Ошибка телеграмма',
             'status_processing_1c' => 'Статус обработки заказа в 1С',
             'order_link' => 'Ссылка на заказ в МП',
+            'delivery_to' => 'Сроки доставки заказа',
         ];
     }
 
index f9f4e1d12131b72ad9f523a58cc6341c9c10f17e..88e186b9f33455811f91f409bc475565ef0f9321 100644 (file)
@@ -13,6 +13,7 @@ $this->title = 'Загрузка заказов Flowwow';
 
     <?= Html::a('Назад', ['index'], ['class' => 'btn btn-primary my-4']) ?>
     <?= Html::a('Ссылки на заказы', ['set-order-link'], ['class' => 'btn btn-primary my-4']) ?>
+    <?= Html::a('Проставить доставку', ['set-order-delivery'], ['class' => 'btn btn-primary my-4']) ?>
     <h1><?= Html::encode($this->title) ?></h1>
 
 <?php $form = ActiveForm::begin(); ?>
index e7437724874e01b1b8915bd0641791b2299cda6f..b0e2f01fd172a1924892954ea153b57a67a12f93 100644 (file)
@@ -58,6 +58,7 @@ $this->params['breadcrumbs'][] = $this->title;
             'warehouse_guid',
             'creation_date',
             'updated_at',
+            'delivery_to',
             'total',
             'delivery_total',
             'buyer_total_before_discount',