From cfb208ba0fbae5ef4248fdd21d3e2e25a1c9ec55 Mon Sep 17 00:00:00 2001 From: Aleksey Filippov Date: Fri, 3 Oct 2025 00:04:16 +0300 Subject: [PATCH] =?utf8?q?=D0=9A=D0=BE=D0=BF=D0=B0=D0=BA=D1=82=D0=BD=D1=8B?= =?utf8?q?=D0=B9=20=D1=81=D0=B1=D0=BE=D1=80=20=D0=B4=D0=B0=D0=BD=D0=BD?= =?utf8?q?=D1=8B=D1=85=20=D0=BE=20=D1=81=D0=B5=D0=B1=D0=B5=D1=81=D1=82?= =?utf8?q?=D0=BE=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + erp24/.gitignore | 3 + erp24/api2/controllers/DataController.php | 2 + erp24/commands/SelfCostController.php | 76 ++++++++++++++++++ ...craete_table_self_cost_product_dynamic.php | 36 +++++++++ erp24/records/SelfCostProductDynamic.php | 77 +++++++++++++++++++ 6 files changed, 195 insertions(+) create mode 100644 erp24/commands/SelfCostController.php create mode 100644 erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php create mode 100644 erp24/records/SelfCostProductDynamic.php diff --git a/.gitignore b/.gitignore index 67bdd40f..45b2c806 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ erp24/package-lock.json /pgsql_last.sql /pgsql_last.sql.gz erp24/api2/users_auth_call_log2.txt +/.history/ diff --git a/erp24/.gitignore b/erp24/.gitignore index 85c59d70..eca74311 100644 --- a/erp24/.gitignore +++ b/erp24/.gitignore @@ -9,6 +9,9 @@ nbproject .project .settings +# +.history + # windows thumbnail cache Thumbs.db diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index 055469fa..742f5dfc 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -66,6 +66,7 @@ use yii_app\services\InfoLogService; use yii_app\services\LogService; use yii_app\services\MarketplaceService; use yii_app\services\TelegramService; +use yii_app\services\SelfCostProductDinamicService; class DataController extends BaseController { @@ -1152,6 +1153,7 @@ class DataController extends BaseController if (!empty($values)) { $this->setSelfCostUpdate($values); + SelfCostProductDinamicService::UpdateResult($values); } } diff --git a/erp24/commands/SelfCostController.php b/erp24/commands/SelfCostController.php new file mode 100644 index 00000000..f57e53dc --- /dev/null +++ b/erp24/commands/SelfCostController.php @@ -0,0 +1,76 @@ +select(["DISTINCT(product_guid) as product_guid"]) + ->asArray() + ->all(); + + var_dump(count($selfCostProductGuid)); + echo " Line " . __LINE__ . "\n"; + + $arrayCount = $rowsCount = count($selfCostProductGuid); + // $rowsCount = 2; + // echo('
'); + while ($rowsCount > 0) { + + $shiftRow = array_shift($selfCostProductGuid); + // echo($shiftRow["product_guid"].'
'); + // echo($rowsCount.'
'); + $selfCostProductGuidStore = SelfCostProduct::find() + ->select(['product_guid','store_id']) + ->where(['product_guid' => (string)$shiftRow["product_guid"]]) + ->groupBy(['product_guid','store_id']) + ->asArray() + ->all(); + + foreach ($selfCostProductGuidStore as $rowGuidStore) { + + $selfCostProduct = SelfCostProduct::find() + ->where(['product_guid' => (string)$rowGuidStore['product_guid']]) + ->andWhere(['store_id' => $rowGuidStore['store_id']]) + ->select(['product_guid','store_id','price', "string_agg(date::character varying, ', ' order by date ASC) as dates"]) + ->groupBy(['product_guid','store_id','price']) + ->asArray() + ->all(); + // var_dump($selfCostProduct); + $resultRow = SelfCostProductDinamicService::PrepareResult($selfCostProduct); + // print_r($resultRow); + SelfCostProductDinamicService::SaveResult($resultRow); + // echo " Line " . __LINE__ . "\n"; + + + + } + + + + + $rowsCount--; + } + + echo "\nStop " . time() . "\n"; + return ExitCode::OK; + } +} diff --git a/erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php b/erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php new file mode 100644 index 00000000..8d4df58b --- /dev/null +++ b/erp24/migrations/m250925_231312_craete_table_self_cost_product_dynamic.php @@ -0,0 +1,36 @@ +createTable(self::TABLE_NAME, [ + 'id' => $this->bigPrimaryKey(), + 'store_id' => $this->integer()->notNull(), + 'product_guid' => $this->string()->notNull()->comment('product guid'), + 'price' => $this->float()->notNull()->comment('price'), + 'date_from' => $this->date()->notNull()->comment('Дата начала'), + 'date_to' => $this->date()->defaultValue('2100-01-01')->notNull()->comment('Дата окончания'), + 'created_at' => $this->dateTime()->notNull()->defaultExpression('NOW()')->comment('Дата создания записи'), + 'updated_at' => $this->datetime()->null()->comment('Дата внесения записи'), + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable(self::TABLE_NAME); + } +} diff --git a/erp24/records/SelfCostProductDynamic.php b/erp24/records/SelfCostProductDynamic.php new file mode 100644 index 00000000..dfd292ef --- /dev/null +++ b/erp24/records/SelfCostProductDynamic.php @@ -0,0 +1,77 @@ + [ + 'class' => TimestampBehavior::class, + 'createdAtAttribute' => 'created_at', + 'updatedAtAttribute' => 'updated_at', + 'value' => new Expression('NOW()'), + ], + ]; + } + + /** + * {@inheritdoc} + */ + public static function tableName() + { + return 'self_cost_product_dynamic'; + } + + /** + * {@inheritdoc} + */ + public function rules() + { + return [ + [['store_id', 'product_guid', 'price', 'date_from'], 'required'], + [['store_id'], 'default', 'value' => null], + [['store_id'], 'integer'], + [['price'], 'number'], + [['date_from', 'date_to', 'created_at', 'updated_at'], 'safe'], + [['product_guid'], 'string', 'max' => 255], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'store_id' => 'Store ID', + 'product_guid' => 'Product Guid', + 'price' => 'Price', + 'date_from' => 'Date From', + 'date_to' => 'Date To', + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + ]; + } +} \ No newline at end of file -- 2.39.5