From 03605101b16b4957f050e1a6df63ad479eee80f2 Mon Sep 17 00:00:00 2001 From: Vladimir Fomichev Date: Thu, 19 Feb 2026 10:35:46 +0300 Subject: [PATCH] =?utf8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=BF?= =?utf8?q?=D1=80=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?utf8?q?=D1=8F=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=D0=B0=20=D0=B7=D0=B0?= =?utf8?q?=D0=BA=D0=B0=D0=B7=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../MarketplaceFlowwowEmailsController.php | 29 +++++++++++++++++++ erp24/services/MarketplaceService.php | 5 ++++ .../marketplace-flowwow-emails/index.php | 3 ++ 3 files changed, 37 insertions(+) diff --git a/erp24/controllers/MarketplaceFlowwowEmailsController.php b/erp24/controllers/MarketplaceFlowwowEmailsController.php index 3f382e13..5055a96e 100644 --- a/erp24/controllers/MarketplaceFlowwowEmailsController.php +++ b/erp24/controllers/MarketplaceFlowwowEmailsController.php @@ -63,6 +63,35 @@ class MarketplaceFlowwowEmailsController extends Controller ]); } + /** + * Проставляет marketplace_order_id из темы письма для обработанных записей, где он не заполнен. + * Извлекает номер по паттерну №XXXX из subject. + */ + public function actionFillMissingOrderIds(): \yii\web\Response + { + if (!Yii::$app->request->isPost) { + throw new \yii\web\BadRequestHttpException('Только POST.'); + } + + $emails = MarketplaceFlowwowEmails::find() + ->where(['or', ['marketplace_order_id' => null], ['marketplace_order_id' => '']]) + ->andWhere(['email_status' => MarketplaceFlowwowEmails::STATUS_PROCESSED]) + ->all(); + + $updated = 0; + foreach ($emails as $email) { + if (preg_match('/№(\d+)/', $email->subject, $matches)) { + $email->marketplace_order_id = $matches[1]; + if ($email->save(false, ['marketplace_order_id'])) { + $updated++; + } + } + } + + Yii::$app->session->setFlash('success', "Обновлено записей: {$updated} из " . count($emails)); + return $this->redirect(['index']); + } + public function actionDecodeBodies() { if (Yii::$app->request->isPost) { diff --git a/erp24/services/MarketplaceService.php b/erp24/services/MarketplaceService.php index 327eabf8..5d1d7108 100644 --- a/erp24/services/MarketplaceService.php +++ b/erp24/services/MarketplaceService.php @@ -2582,6 +2582,11 @@ class MarketplaceService Yii::warning('Не найден заголовок заказа (h1) в HTML', __METHOD__); } + // Fallback: извлекаем номер заказа из темы письма, если из h1 не получилось + if (empty($orderNumber) && !empty($message['subject']) && preg_match('/№(\d+)/', $message['subject'], $matches)) { + $orderNumber = (int)$matches[1]; + } + $orderDetails['number'] = $orderNumber; $orderDetails['date'] = $message['date']; $deliveryText = ''; diff --git a/erp24/views/marketplace-flowwow-emails/index.php b/erp24/views/marketplace-flowwow-emails/index.php index a71ea666..4446dd40 100644 --- a/erp24/views/marketplace-flowwow-emails/index.php +++ b/erp24/views/marketplace-flowwow-emails/index.php @@ -17,6 +17,9 @@ $this->params['breadcrumbs'][] = $this->title; 'btn btn-primary my-4']) ?> 'btn btn-primary my-4']) ?> + 'display:inline']) ?> + 'btn btn-warning my-4', 'onclick' => 'return confirm("Заполнить marketplace_order_id из темы письма для всех обработанных записей без номера?")']) ?> +

title) ?>

'btn btn-primary my-4']) ?> -- 2.39.5