From: Aleksey Filippov Date: Fri, 20 Feb 2026 13:47:30 +0000 (+0300) Subject: feat(BR-132): add is_promo_balance flag to promocode X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=b104c2667bc115b9d80e53076ff1a1077b2433b5;p=erp24_rep%2Fyii-erp24%2F.git feat(BR-132): add is_promo_balance flag to promocode 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 --- 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 index 00000000..d2079cfd --- /dev/null +++ b/erp24/migrations/m260220_130000_add_is_promo_balance_to_promocode.php @@ -0,0 +1,23 @@ +addColumn( + '{{%erp24.promocode}}', + 'is_promo_balance', + $this->boolean()->notNull()->defaultValue(false)->comment('Начислять в промо-баланс') + ); + } + + public function safeDown() + { + $this->dropColumn('{{%erp24.promocode}}', 'is_promo_balance'); + } +} diff --git a/erp24/records/Promocode.php b/erp24/records/Promocode.php index 93a7b2fc..134b3245 100644 --- a/erp24/records/Promocode.php +++ b/erp24/records/Promocode.php @@ -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]], diff --git a/erp24/services/PromocodeService.php b/erp24/services/PromocodeService.php index 5f536a46..507aad12 100644 --- a/erp24/services/PromocodeService.php +++ b/erp24/services/PromocodeService.php @@ -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()); diff --git a/erp24/views/promocode/edit.php b/erp24/views/promocode/edit.php index 2fbbbeac..05f35338 100644 --- a/erp24/views/promocode/edit.php +++ b/erp24/views/promocode/edit.php @@ -35,6 +35,8 @@ $this->registerJsFile('/js/xlsx.full.min.js', ['position' => \yii\web\View::POS_ field($model, 'active')->dropDownList(['Не активен', 'Активен'])->label(false)) ?> + field($model, 'is_promo_balance')->dropDownList([0 => 'Нет (обычные бонусы)', 1 => 'Да (промо-баланс)'])->label(false)) ?> + field($model, 'date_start')->widget(DateTimePicker::class, [ 'language' => 'ru', 'template' => '{input}',