/pgsql_last.sql
/pgsql_last.sql.gz
erp24/api2/users_auth_call_log2.txt
+/.history/
.project
.settings
+#
+.history
+
# windows thumbnail cache
Thumbs.db
use yii_app\services\LogService;
use yii_app\services\MarketplaceService;
use yii_app\services\TelegramService;
+use yii_app\services\SelfCostProductDinamicService;
class DataController extends BaseController
{
if (!empty($values)) {
$this->setSelfCostUpdate($values);
+ SelfCostProductDinamicService::UpdateResult($values);
}
}
--- /dev/null
+<?php
+/**
+ * @link https://www.yiiframework.com/
+ * @copyright Copyright (c) 2008 Yii Software LLC
+ * @license https://www.yiiframework.com/license/
+ */
+
+namespace yii_app\commands;
+
+use yii\console\Controller;
+use yii\console\ExitCode;
+use yii_app\records\SelfCostProduct;
+use yii_app\services\SelfCostProductDinamicService;
+
+
+class SelfCostController extends Controller
+{
+
+ public function actionTransferData()
+ {
+ echo "Start " . __LINE__ . " " . time() . "\n";
+ // echo " Line " . __LINE__ . "\n";
+
+ // сбор гуидов
+ $selfCostProductGuid = SelfCostProduct::find()
+ ->select(["DISTINCT(product_guid) as product_guid"])
+ ->asArray()
+ ->all();
+
+ var_dump(count($selfCostProductGuid));
+ echo " Line " . __LINE__ . "\n";
+
+ $arrayCount = $rowsCount = count($selfCostProductGuid);
+ // $rowsCount = 2;
+ // echo('<br>');
+ while ($rowsCount > 0) {
+
+ $shiftRow = array_shift($selfCostProductGuid);
+ // echo($shiftRow["product_guid"].'<br>');
+ // echo($rowsCount.'<br>');
+ $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;
+ }
+}
--- /dev/null
+<?php
+
+use yii\db\Migration;
+
+/**
+ * Class m250925_231312_craete_table_self_cost_product_dynamic
+ */
+class m250925_231312_craete_table_self_cost_product_dynamic extends Migration
+{
+ const TABLE_NAME = 'erp24.self_cost_product_dynamic';
+
+ /**
+ * {@inheritdoc}
+ */
+ public function safeUp()
+ {
+ $this->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);
+ }
+}
--- /dev/null
+<?php
+
+namespace yii_app\records;
+
+use Yii;
+use yii\behaviors\TimestampBehavior;
+use yii\db\Expression;
+
+/**
+ * This is the model class for table "self_cost_product_dynamic".
+ *
+ * @property int $id
+ * @property int $store_id
+ * @property string $product_guid product guid
+ * @property float $price price
+ * @property string $date_from Дата начала
+ * @property string $date_to Дата окончания
+ * @property string $created_at Дата создания записи
+ * @property string|null $updated_at Дата внесения записи
+ */
+class SelfCostProductDynamic extends \yii\db\ActiveRecord
+{
+ /**
+ * {@inheritdoc}
+ */
+ public function behaviors()
+ {
+ return [
+ 'timestamp' => [
+ '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