From: fomichev Date: Fri, 17 Apr 2026 14:04:10 +0000 (+0300) Subject: feat(ERP-292): web-контроллер и views авторазметки X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=711163253a21110262eced427ac9d5d904071ef2;p=erp24_rep%2Fyii-erp24%2F.git feat(ERP-292): web-контроллер и views авторазметки Co-Authored-By: Claude Sonnet 4.6 --- diff --git a/erp24/controllers/AutoMarkController.php b/erp24/controllers/AutoMarkController.php new file mode 100644 index 00000000..c5d62713 --- /dev/null +++ b/erp24/controllers/AutoMarkController.php @@ -0,0 +1,73 @@ +with('product') + ->orderBy(['confidence' => SORT_DESC, 'created_at' => SORT_DESC]); + + $status = Yii::$app->request->get('status'); + if ($status !== null) { + $query->andWhere(['status' => (int) $status]); + } else { + $query->andWhere(['status' => Products1cAutomarkPrediction::STATUS_PENDING]); + } + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => ['pageSize' => 50], + ]); + + return $this->render('index', ['dataProvider' => $dataProvider]); + } + + public function actionReview(int $id): string + { + $prediction = $this->findPrediction($id); + + if (Yii::$app->request->isPost) { + $action = Yii::$app->request->post('action'); + $service = new AutoMarkService(); + + if ($action === 'approve') { + $prediction->status = Products1cAutomarkPrediction::STATUS_APPROVED; + $prediction->approved_by = Yii::$app->user->id; + $prediction->updated_at = date('Y-m-d H:i:s'); + $prediction->save(); + $service->applyApprovedPrediction($prediction->id); + Yii::$app->session->setFlash('success', 'Разметка применена.'); + } elseif ($action === 'reject') { + $prediction->status = Products1cAutomarkPrediction::STATUS_REJECTED; + $prediction->updated_at = date('Y-m-d H:i:s'); + $prediction->save(); + Yii::$app->session->setFlash('info', 'Предсказание отклонено.'); + } + + return $this->redirect(['index']); + } + + return $this->render('review', ['prediction' => $prediction]); + } + + private function findPrediction(int $id): Products1cAutomarkPrediction + { + $model = Products1cAutomarkPrediction::find()->with('product')->where(['id' => $id])->one(); + if ($model === null) { + throw new NotFoundHttpException("Предсказание #{$id} не найдено."); + } + return $model; + } +} diff --git a/erp24/views/auto-mark/index.php b/erp24/views/auto-mark/index.php new file mode 100644 index 00000000..1bf8a9d0 --- /dev/null +++ b/erp24/views/auto-mark/index.php @@ -0,0 +1,43 @@ +title = 'Авторазметка товаров'; +?> +
+

title) ?>

+ +
+ Products1cAutomarkPrediction::STATUS_PENDING], ['class' => 'btn btn-warning']) ?> + Products1cAutomarkPrediction::STATUS_APPROVED], ['class' => 'btn btn-success']) ?> + Products1cAutomarkPrediction::STATUS_REJECTED], ['class' => 'btn btn-secondary']) ?> +
+ + $dataProvider, + 'columns' => [ + 'id', + [ + 'label' => 'Товар', + 'value' => fn($m) => $m->product?->name ?? $m->product_id, + ], + 'category', + 'species', + 'sort', + 'color', + 'size', + [ + 'label' => 'Confidence', + 'value' => fn($m) => number_format($m->confidence * 100, 1) . '%', + ], + 'method', + [ + 'label' => 'Действия', + 'format' => 'raw', + 'value' => fn($m) => Html::a('Проверить', ['review', 'id' => $m->id], ['class' => 'btn btn-sm btn-primary']), + ], + ], + ]) ?> +
diff --git a/erp24/views/auto-mark/review.php b/erp24/views/auto-mark/review.php new file mode 100644 index 00000000..8e3a27c3 --- /dev/null +++ b/erp24/views/auto-mark/review.php @@ -0,0 +1,56 @@ +title = 'Проверка разметки #' . $prediction->id; +?> +
+

title) ?>

+ +
+
Товар из 1С
+
+

GUID: product_id) ?>

+

Название: product?->name ?? '—') ?>

+

Код: product?->code ?? '—') ?>

+
+
+ +
+
+ Предсказание + — метод: method) ?>, + уверенность: confidence * 100, 1) ?>% +
+
+ + + + + + + + +
Категорияcategory ?? '—') ?>
Подкатегорияsubcategory ?? '—') ?>
Видspecies ?? '—') ?>
Сортsort ?? '—') ?>
Типtype ?? '—') ?>
Размерsize ?? '—' ?>
Цветcolor ?? '—') ?>
+
+
+ + isPending()): ?> +
+ $prediction->id], 'post') ?> + + 'btn btn-success']) ?> + + + $prediction->id], 'post') ?> + + 'btn btn-danger']) ?> + +
+ + +
+ 'btn btn-secondary']) ?> +
+