]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
feat(BR-132): add is_promo_balance flag to promocode
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 20 Feb 2026 13:47:30 +0000 (16:47 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Fri, 20 Feb 2026 13:47:30 +0000 (16:47 +0300)
Boolean field to distinguish promo codes that credit separate promo
balance vs regular bonuses. Propagated to child codes on generation
and bulk update. UI toggle added to edit form.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
erp24/migrations/m260220_130000_add_is_promo_balance_to_promocode.php [new file with mode: 0644]
erp24/records/Promocode.php
erp24/services/PromocodeService.php
erp24/views/promocode/edit.php

diff --git a/erp24/migrations/m260220_130000_add_is_promo_balance_to_promocode.php b/erp24/migrations/m260220_130000_add_is_promo_balance_to_promocode.php
new file mode 100644 (file)
index 0000000..d2079cf
--- /dev/null
@@ -0,0 +1,23 @@
+<?php
+
+use yii\db\Migration;
+
+/**
+ * BR-132: Признак промокода для отдельного промо-баланса.
+ */
+class m260220_130000_add_is_promo_balance_to_promocode extends Migration
+{
+    public function safeUp()
+    {
+        $this->addColumn(
+            '{{%erp24.promocode}}',
+            'is_promo_balance',
+            $this->boolean()->notNull()->defaultValue(false)->comment('Начислять в промо-баланс')
+        );
+    }
+
+    public function safeDown()
+    {
+        $this->dropColumn('{{%erp24.promocode}}', 'is_promo_balance');
+    }
+}
index 93a7b2fc903c6cb0238ef2268dc806897071d886..134b3245468022cd3918c521410f3af46aaa5d6b 100644 (file)
@@ -21,6 +21,7 @@ use Yii;
  * @property int|null $updated_by ID редактора записи
  * @property string $created_at Дата создания
  * @property string|null $updated_at Дата изменения
+ * @property bool $is_promo_balance Начислять в промо-баланс (а не в обычные бонусы)
  */
 class Promocode extends \yii\db\ActiveRecord
 {
@@ -44,7 +45,7 @@ class Promocode extends \yii\db\ActiveRecord
         return [
             [['code', 'bonus', 'duration', 'active', 'date_start', 'date_end', 'created_by', 'created_at'], 'required'],
             [['code'], 'string', 'max' => 20],
-            [['bonus', 'duration', 'active', 'used', 'base', 'parent_id', 'created_by', 'updated_by'], 'integer'],
+            [['bonus', 'duration', 'active', 'used', 'base', 'parent_id', 'created_by', 'updated_by', 'is_promo_balance'], 'integer'],
             [['date_start', 'date_end', 'created_at', 'updated_at'], 'datetime', 'format' => 'php:Y-m-d H:i:s'],
             [['updated_by', 'updated_at', 'generatePromocodeCount', 'generateFormat'], 'safe'],
             ['generateFormat', 'in', 'range' => [self::FORMAT_DIGITS, self::FORMAT_ALPHANUMERIC]],
index 5f536a463b6a28288c651e302f51fedbe5c3f845..507aad1227dec97ae34a9590bc6f85a1c09df1d4 100644 (file)
@@ -52,6 +52,7 @@ class PromocodeService
             $singleUsePromocode->parent_id = $basePromocode->id;
             $singleUsePromocode->date_start = $basePromocode->date_start;
             $singleUsePromocode->date_end = $basePromocode->date_end;
+            $singleUsePromocode->is_promo_balance = $basePromocode->is_promo_balance;
             $singleUsePromocode->created_by = Yii::$app->user->id;
             $singleUsePromocode->created_at = date("Y-m-d H:i:s");
             $singleUsePromocode->save();
@@ -70,6 +71,7 @@ class PromocodeService
             $singleUsePromocode->active = $basePromocode->active;
             $singleUsePromocode->date_start = $basePromocode->date_start;
             $singleUsePromocode->date_end = $basePromocode->date_end;
+            $singleUsePromocode->is_promo_balance = $basePromocode->is_promo_balance;
             $singleUsePromocode->save();
             if ($singleUsePromocode->getErrors()) {
                 var_dump($singleUsePromocode->getErrors());
index 2fbbbeac38baba27dadc42f1cef965e27fe6302e..05f3533860fb6dabba349a83170e69f3e5660964 100644 (file)
@@ -35,6 +35,8 @@ $this->registerJsFile('/js/xlsx.full.min.js', ['position' => \yii\web\View::POS_
 
     <?php PrintBlockHelper::printBlock('Активность', $form->field($model, 'active')->dropDownList(['Не активен', 'Активен'])->label(false)) ?>
 
+    <?php PrintBlockHelper::printBlock('Начислять в промо-баланс', $form->field($model, 'is_promo_balance')->dropDownList([0 => 'Нет (обычные бонусы)', 1 => 'Да (промо-баланс)'])->label(false)) ?>
+
     <?php PrintBlockHelper::printBlock('Дата начала действия промокода', $form->field($model, 'date_start')->widget(DateTimePicker::class, [
         'language' => 'ru',
         'template' => '{input}',