From: fomichev Date: Thu, 14 May 2026 10:28:01 +0000 (+0300) Subject: правки по ревью X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=f8566e73b982d6b4a146d1af9866c228f2b61961;p=erp24_rep%2Fyii-erp24%2F.git правки по ревью --- diff --git a/erp24/commands/Products1cConceptController.php b/erp24/commands/Products1cConceptController.php index d90ad346..9a025fde 100644 --- a/erp24/commands/Products1cConceptController.php +++ b/erp24/commands/Products1cConceptController.php @@ -39,7 +39,7 @@ class Products1cConceptController extends Controller $transaction = $db->beginTransaction(); try { - $db->createCommand('TRUNCATE TABLE ' . self::TARGET_TABLE)->execute(); + $db->createCommand('TRUNCATE TABLE ' . $db->quoteTableName(self::TARGET_TABLE))->execute(); $now = date('Y-m-d H:i:s'); $inserted = $db->createCommand(<< VerbFilter::class, 'actions' => [ 'delete' => ['POST'], + 'ajax-delete' => ['POST'], + 'add-activity' => ['POST'], 'ajax-save-interval' => ['POST'], 'ajax-save-assortment' => ['POST'], 'ajax-remove-label' => ['POST'], @@ -574,19 +576,25 @@ class Products1cNomenclatureActualityController extends Controller { $request = Yii::$app->request; - $historyDays = $request->get('historyDays'); - $intervalMonths = $request->get('intervalMonths'); - $startFrom = $request->get('startFrom', date('Y-m-d')); + $historyDays = $request->post('historyDays'); + $intervalMonths = $request->post('intervalMonths'); + $startFrom = $request->post('startFrom', date('Y-m-d')); if ($historyDays === null || $intervalMonths === null) { return $this->render('add-activity', [ - 'historyDays' => $historyDays ?? 14, - 'intervalMonths' => $intervalMonths ?? 4, - 'startFrom' => $startFrom, + 'historyDays' => 14, + 'intervalMonths' => 4, + 'startFrom' => date('Y-m-d'), ]); } - $endDate = date('Y-m-d', strtotime($startFrom)); + $historyDays = max(1, min(365, (int)$historyDays)); + $intervalMonths = max(1, min(24, (int)$intervalMonths)); + $startFrom = preg_match('/^\d{4}-\d{2}-\d{2}$/', (string)$startFrom) + ? (string)$startFrom + : date('Y-m-d'); + + $endDate = $startFrom; $startDate = date('Y-m-d', strtotime("-{$historyDays} days", strtotime($endDate))); $productIds = (new Query()) @@ -1359,24 +1367,23 @@ class Products1cNomenclatureActualityController extends Controller { Yii::$app->response->format = Response::FORMAT_JSON; - $request = Yii::$app->request; - $id = $request->post('id') ?? $request->get('id'); + $id = Yii::$app->request->post('id'); if (empty($id)) { throw new BadRequestHttpException('Missing parameter: id'); } try { - $model = $this->findModel($id); - $model->delete(); + $this->findModel($id)->delete(); return [ 'success' => true, 'message' => 'Запись успешно удалена', ]; } catch (\Throwable $e) { + Yii::error($e->getMessage(), __CLASS__); return [ 'success' => false, - 'message' => $e->getMessage(), + 'message' => 'Ошибка удаления записи', ]; } } diff --git a/erp24/controllers/Products1cNomenclatureMarkupController.php b/erp24/controllers/Products1cNomenclatureMarkupController.php index 1b0b1796..289b5a0d 100644 --- a/erp24/controllers/Products1cNomenclatureMarkupController.php +++ b/erp24/controllers/Products1cNomenclatureMarkupController.php @@ -21,6 +21,14 @@ use yii_app\services\AutoMarkService; class Products1cNomenclatureMarkupController extends Controller { + private AutoMarkService $autoMarkService; + + public function init(): void + { + parent::init(); + $this->autoMarkService = new AutoMarkService(); + } + public const STATUS_NOT_NEEDED = 'not_needed'; public const STATUS_APPROVED = 'approved'; public const STATUS_AUTOMARK_PENDING = 'automark_pending'; @@ -228,9 +236,8 @@ class Products1cNomenclatureMarkupController extends Controller return ['success' => false, 'message' => 'Ошибка сохранения предсказания']; } - $service = new AutoMarkService(); try { - if ($service->applyApprovedPrediction($prediction->id)) { + if ($this->autoMarkService->applyApprovedPrediction($prediction->id)) { AuditLog::write( Products1cAutomarkPrediction::tableName(), (string)$prediction->id, @@ -284,9 +291,8 @@ class Products1cNomenclatureMarkupController extends Controller return ['success' => false, 'message' => implode(', ', $prediction->getFirstErrors())]; } - $service = new AutoMarkService(); try { - if ($service->applyApprovedPrediction($prediction->id)) { + if ($this->autoMarkService->applyApprovedPrediction($prediction->id)) { AuditLog::write( Products1cAutomarkPrediction::tableName(), (string)$prediction->id, @@ -320,37 +326,45 @@ class Products1cNomenclatureMarkupController extends Controller ->where(['id' => $ids, 'status' => Products1cAutomarkPrediction::STATUS_PENDING]) ->all(); - $service = new AutoMarkService(); - $now = date('Y-m-d H:i:s'); - $userId = (int)Yii::$app->user->id; + $now = date('Y-m-d H:i:s'); + $userId = (int)Yii::$app->user->id; $applied = 0; - foreach ($predictions as $prediction) { - $prediction->status = Products1cAutomarkPrediction::STATUS_APPROVED; - $prediction->approved_by = $userId; - $prediction->updated_at = $now; - - if (!$prediction->save()) { - continue; - } + $transaction = Yii::$app->db->beginTransaction(); + try { + foreach ($predictions as $prediction) { + $prediction->status = Products1cAutomarkPrediction::STATUS_APPROVED; + $prediction->approved_by = $userId; + $prediction->updated_at = $now; + + if (!$prediction->save()) { + $transaction->rollBack(); + return ['success' => false, 'message' => 'Ошибка сохранения предсказания #' . $prediction->id]; + } - try { - if ($service->applyApprovedPrediction($prediction->id)) { + if ($this->autoMarkService->applyApprovedPrediction($prediction->id)) { $applied++; + } else { + $transaction->rollBack(); + return ['success' => false, 'message' => 'Ошибка применения разметки для товара #' . $prediction->product_id]; } - } catch (\Exception $e) { - Yii::error($e->getMessage(), __CLASS__); } - } - if ($applied > 0) { - AuditLog::write( - Products1cAutomarkPrediction::tableName(), - null, - AuditLog::ACTION_BULK_UPDATE, - ['status' => Products1cAutomarkPrediction::STATUS_PENDING], - ['status' => Products1cAutomarkPrediction::STATUS_APPROVED, 'approved_by' => $userId, 'entity_ids' => $ids], - ); + if ($applied > 0) { + AuditLog::write( + Products1cAutomarkPrediction::tableName(), + null, + AuditLog::ACTION_BULK_UPDATE, + ['status' => Products1cAutomarkPrediction::STATUS_PENDING], + ['status' => Products1cAutomarkPrediction::STATUS_APPROVED, 'approved_by' => $userId, 'entity_ids' => $ids], + ); + } + + $transaction->commit(); + } catch (\Exception $e) { + $transaction->rollBack(); + Yii::error($e->getMessage(), __CLASS__); + return ['success' => false, 'message' => 'Ошибка пакетного подтверждения']; } return [ diff --git a/erp24/views/products1c-nomenclature-actuality/add-activity.php b/erp24/views/products1c-nomenclature-actuality/add-activity.php index a8e038f1..a86ea244 100644 --- a/erp24/views/products1c-nomenclature-actuality/add-activity.php +++ b/erp24/views/products1c-nomenclature-actuality/add-activity.php @@ -5,7 +5,6 @@ /** @var int $intervalMonths */ /* @var string $startFrom */ use dosamigos\datepicker\DatePicker; -use yii\base\DynamicModel; use yii\helpers\Html; use kartik\form\ActiveForm; @@ -28,23 +27,22 @@ $this->title = 'Заполнить актуальность товаров по 'get', - 'action'=>['add-activity'], + 'method' => 'post', + 'action' => ['add-activity'], ]); ?> 'startFrom', 'id' => 'startFrom', - 'value' => date('d-m-Y'), + 'value' => date('Y-m-d'), 'template' => '{addon}{input}', 'language' => 'ru', 'clientOptions' => [ 'autoclose' => true, - 'format' => 'dd-mm-yyyy', - 'todayBtn' => true - ], - 'clientEvents' => [ + 'format' => 'yyyy-mm-dd', + 'todayBtn' => true, ], + 'clientEvents' => [], 'containerOptions' => ['class' => 'mb-4'], ]) ?> diff --git a/erp24/views/products1c-nomenclature-actuality/index.php b/erp24/views/products1c-nomenclature-actuality/index.php index de6a8174..91cd77b0 100644 --- a/erp24/views/products1c-nomenclature-actuality/index.php +++ b/erp24/views/products1c-nomenclature-actuality/index.php @@ -483,6 +483,7 @@ function actConceptChips(array $names): string
Загрузка...