From: Vladimir Fomichev Date: Tue, 26 Aug 2025 09:41:19 +0000 (+0300) Subject: Обработка в DataController X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=60e3382d96f91d5f2f6606ad283d03246aae2b57;p=erp24_rep%2Fyii-erp24%2F.git Обработка в DataController --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 7d487a2b..7a0a4c3e 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -12,6 +12,7 @@ use yii_app\helpers\SalaryHelper; use yii_app\records\Admin; use yii_app\records\AdminGroup; use yii_app\records\AnalystsBusinessOperations; +use yii_app\records\AnalystsBusinessOperationsTypes; use yii_app\records\ApiCron; use yii_app\records\Assemblies; use yii_app\records\Balances; @@ -2556,12 +2557,28 @@ class DataController extends BaseController $existingOperations = AnalystsBusinessOperations::find() ->select(['id']) ->column(); + $existingTypes = AnalystsBusinessOperationsTypes::find() + ->indexBy('code') + ->asArray() + ->all(); foreach ($result["analysts_business_operations"] as $operation) { if (!in_array($operation['guid'], $existingOperations)) { $newOperation = new AnalystsBusinessOperations(); $newOperation->id = $operation['guid']; $newOperation->name = $operation['name']; $newOperation->type = $operation['type']; + if (!in_array($newOperation->type, array_column($existingTypes, 'code'))) { + $newType = new AnalystsBusinessOperationsTypes(); + $newType->code = $operation['type']; + if ($newType->save()) { + $newOperation->type_id = $newType->id; + } else { + Yii::error('Ошибка сохранение типа ' . json_encode($newType->getErrors(), JSON_UNESCAPED_UNICODE), __METHOD__ ); + } + } else { + $newOperation->type_id = $existingTypes[$operation['type']]['id']; + } + if (!$newOperation->save()) { LogService::apiErrorLog( json_encode( @@ -2570,6 +2587,7 @@ class DataController extends BaseController ) ); } + } } diff --git a/erp24/commands/MarketplaceController.php b/erp24/commands/MarketplaceController.php index 1777a3bb..2573b6ad 100644 --- a/erp24/commands/MarketplaceController.php +++ b/erp24/commands/MarketplaceController.php @@ -49,8 +49,11 @@ class MarketplaceController extends Controller $config = Configuration::getDefaultConfiguration()->setApiKey('Api-Key', Yii::$app->params['YANDEX_MARKET_API_KEY']); - $products = Products1c::find()->alias('p')->leftJoin('products_class pc', 'p.parent_id = pc.category_id') - ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]])->all(); + $products = Products1c::find() + ->alias('p') + ->leftJoin('products_class pc', 'p.parent_id = pc.category_id') + ->where(['pc.tip' => [ProductsClass::MARKETPLACE, ProductsClass::MARKETPLACE_ADDITIONAL]]) + ->all(); $matrixErp = MatrixErp::find()->where(['guid' => ArrayHelper::getColumn($products, 'id')])->all(); $matrixErpByGuid = []; $hiddenOfferings = []; diff --git a/erp24/controllers/AnalystsBusinessOperationsTypesController.php b/erp24/controllers/AnalystsBusinessOperationsTypesController.php new file mode 100644 index 00000000..e4c4d344 --- /dev/null +++ b/erp24/controllers/AnalystsBusinessOperationsTypesController.php @@ -0,0 +1,144 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ] + ); + } + + /** + * Lists all AnalystsBusinessOperationsTypes models. + * + * @return string + */ + public function actionIndex() + { + $dataProvider = new ActiveDataProvider([ + 'query' => AnalystsBusinessOperationsTypes::find(), + /* + 'pagination' => [ + 'pageSize' => 50 + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + */ + ]); + + return $this->render('index', [ + 'dataProvider' => $dataProvider, + ]); + } + + /** + * Displays a single AnalystsBusinessOperationsTypes model. + * @param int $id ID + * @return string + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionView($id) + { + return $this->render('view', [ + 'model' => $this->findModel($id), + ]); + } + + /** + * Creates a new AnalystsBusinessOperationsTypes model. + * If creation is successful, the browser will be redirected to the 'view' page. + * @return string|\yii\web\Response + */ + public function actionCreate() + { + $model = new AnalystsBusinessOperationsTypes(); + + if ($this->request->isPost) { + if ($model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + } else { + $model->loadDefaultValues(); + } + + return $this->render('create', [ + 'model' => $model, + ]); + } + + /** + * Updates an existing AnalystsBusinessOperationsTypes model. + * If update is successful, the browser will be redirected to the 'view' page. + * @param int $id ID + * @return string|\yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionUpdate($id) + { + $model = $this->findModel($id); + + if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } + + return $this->render('update', [ + 'model' => $model, + ]); + } + + /** + * Deletes an existing AnalystsBusinessOperationsTypes model. + * If deletion is successful, the browser will be redirected to the 'index' page. + * @param int $id ID + * @return \yii\web\Response + * @throws NotFoundHttpException if the model cannot be found + */ + public function actionDelete($id) + { + $this->findModel($id)->delete(); + + return $this->redirect(['index']); + } + + /** + * Finds the AnalystsBusinessOperationsTypes model based on its primary key value. + * If the model is not found, a 404 HTTP exception will be thrown. + * @param int $id ID + * @return AnalystsBusinessOperationsTypes the loaded model + * @throws NotFoundHttpException if the model cannot be found + */ + protected function findModel($id) + { + if (($model = AnalystsBusinessOperationsTypes::findOne(['id' => $id])) !== null) { + return $model; + } + + throw new NotFoundHttpException('The requested page does not exist.'); + } +} diff --git a/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php b/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php index 2d97f8d6..9c6ead1f 100644 --- a/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php +++ b/erp24/migrations/m250825_141743_create_analysts_business_operations_table.php @@ -20,7 +20,7 @@ class m250825_141743_create_analysts_business_operations_table extends Migration 'id' => $this->string()->notNull()->unique()->comment('GUID аналитики'), 'name' => $this->string()->notNull()->comment('Название аналитики'), 'type' => $this->integer()->notNull()->comment('Вид использования хозяйственной операции'), - 'type_id' => $this->string()->null()->comment('ID Вида'), + 'type_id' => $this->integer()->null()->comment('ID Вида'), 'created_at' => $this->dateTime()->notNull()->comment('Дата создания'), ]); $this->addPrimaryKey('pk_analytics_id', self::TABLE_NAME, 'id'); diff --git a/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php b/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php new file mode 100644 index 00000000..807070d3 --- /dev/null +++ b/erp24/migrations/m250826_061451_add_analysts_business_operations_types_table.php @@ -0,0 +1,58 @@ +db->getTableSchema(self::TABLE_NAME); + + if (!isset($tableSchema)) { + $this->createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey()->comment('ID типа операции'), + 'code' => $this->integer()->notNull()->unique()->comment('Код типа (0,1,2...)'), + 'name' => $this->string()->notNull()->comment('Название типа операции'), + 'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()'), + ]); + $this->addForeignKey( + 'fk_operations_type', + 'analysts_business_operations', + 'type_id', + 'analysts_business_operations_types', + 'id' + ); + + } + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $tableSchema = $this->db->getTableSchema(self::TABLE_NAME); + if (isset($tableSchema)) { + $this->dropForeignKey('fk_operations_type', self::TABLE_NAME); + $this->dropTable(self::TABLE_NAME); + } + } + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m250826_061451_add_analysts_business_operations_types_table cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/erp24/records/AnalystsBusinessOperationsTypes.php b/erp24/records/AnalystsBusinessOperationsTypes.php new file mode 100644 index 00000000..d22ee85d --- /dev/null +++ b/erp24/records/AnalystsBusinessOperationsTypes.php @@ -0,0 +1,67 @@ + null], + [['code'], 'integer'], + [['created_at'], 'safe'], + [['name'], 'string', 'max' => 255], + [['code'], 'unique'], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'code' => 'Code', + 'name' => 'Name', + 'created_at' => 'Created At', + ]; + } + + /** + * Gets query for [[AnalystsBusinessOperations]]. + * + * @return \yii\db\ActiveQuery + */ + public function getAnalystsBusinessOperations() + { + return $this->hasMany(AnalystsBusinessOperations::class, ['type_id' => 'id']); + } + +} diff --git a/erp24/views/analysts-business-operations-types/_form.php b/erp24/views/analysts-business-operations-types/_form.php new file mode 100644 index 00000000..563dab3b --- /dev/null +++ b/erp24/views/analysts-business-operations-types/_form.php @@ -0,0 +1,27 @@ + + +
+ + + + field($model, 'code')->textInput() ?> + + field($model, 'name')->textInput(['maxlength' => true]) ?> + + field($model, 'created_at')->textInput() ?> + +
+ 'btn btn-success']) ?> +
+ + + +
diff --git a/erp24/views/analysts-business-operations-types/create.php b/erp24/views/analysts-business-operations-types/create.php new file mode 100644 index 00000000..cd09ac60 --- /dev/null +++ b/erp24/views/analysts-business-operations-types/create.php @@ -0,0 +1,20 @@ +title = 'Создать тип '; +$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/analysts-business-operations-types/index.php b/erp24/views/analysts-business-operations-types/index.php new file mode 100644 index 00000000..eeec3b09 --- /dev/null +++ b/erp24/views/analysts-business-operations-types/index.php @@ -0,0 +1,43 @@ +title = 'Типы бизнес операций из 1С'; +$this->params['breadcrumbs'][] = $this->title; +?> +
+ +

title) ?>

+ +

+ 'btn btn-success']) ?> +

+ + + $dataProvider, + 'columns' => [ + ['class' => 'yii\grid\SerialColumn'], + + 'id', + 'code', + 'name', + 'created_at', + [ + 'class' => ActionColumn::class, + 'urlCreator' => function ($action, AnalystsBusinessOperationsTypes $model, $key, $index, $column) { + return Url::toRoute([$action, 'id' => $model->id]); + } + ], + ], + ]); ?> + + +
diff --git a/erp24/views/analysts-business-operations-types/update.php b/erp24/views/analysts-business-operations-types/update.php new file mode 100644 index 00000000..99b7931a --- /dev/null +++ b/erp24/views/analysts-business-operations-types/update.php @@ -0,0 +1,21 @@ +title = 'Изменить тип: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update'; +?> +
+ +

title) ?>

+ + render('_form', [ + 'model' => $model, + ]) ?> + +
diff --git a/erp24/views/analysts-business-operations-types/view.php b/erp24/views/analysts-business-operations-types/view.php new file mode 100644 index 00000000..c7e44f02 --- /dev/null +++ b/erp24/views/analysts-business-operations-types/view.php @@ -0,0 +1,39 @@ +title = $model->name; +$this->params['breadcrumbs'][] = ['label' => 'Analysts Business Operations Types', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +\yii\web\YiiAsset::register($this); +?> +
+ +

title) ?>

+ +

+ $model->id], ['class' => 'btn btn-primary']) ?> + $model->id], [ + 'class' => 'btn btn-danger', + 'data' => [ + 'confirm' => 'Вы уверены, что хотите удалить запись?', + 'method' => 'post', + ], + ]) ?> +

+ + $model, + 'attributes' => [ + 'id', + 'code', + 'name', + 'created_at', + ], + ]) ?> + +