/** @inheritdoc */ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if (!isset($changedAttributes['Money'])) { return; } $diff = $this->Money - $changedAttributes['Money']; Yii::warning('Изменен баланс ' . \yii\helpers\Html::a('№' . $this->PersonID . ' ' . $this->person->getFullName(true), ['/user/admin/update', 'id' => $this->PersonID]) . ' на ' . ($diff > 0 ? '+' : '') . $diff, 'info'); if ($diff > 0) { $levels = LevelsRecord::getAvailable(); /** @var LevelsRecord $level */ foreach ($levels as $level) { /** @var LevelsRecord $level */ if ($level->StartLevel || $level->id == $this->LevelID) { continue; } //Yii::warning('Проверка уровня ' . $level->Name . ': $level->OneCheckCharge ' . $level->OneCheckCharge . '/ $level->Charge ' . $level->Charge, 'info'); if ($level->PersonsExpression == LevelsRecord::TYPE_CHARGE && $diff >= $level->OneCheckCharge) { Yii::warning('Переход на следующий ' . \yii\helpers\Html::a('уровень (' . $level->Name . ')', ['/levels/index']) . ' по пополнению - №' . \yii\helpers\Html::a($this->person->getFullName(true), ['/user/admin/update', 'id' => $this->PersonID]), 'info'); return $this->updateAttributes(['LevelID' => $level->ID]); } else { if ($level->PersonsExpression == LevelsRecord::TYPE_SPEND && $this->Spend >= $level->Charge) { Yii::warning('Переход на следующий ' . \yii\helpers\Html::a('уровень (' . $level->Name . ')', ['/levels/index']) . ' по накоплению средств - №' . \yii\helpers\Html::a($this->person->getFullName(true), ['/user/admin/update', 'id' => $this->PersonID]), 'info'); return $this->updateAttributes(['LevelID' => $level->ID]); } } } } }
/** * Applying actions!!! * @todo attach as event handler * @inheritdoc */ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); if ($insert) { Yii::info(Html::a('Пользователь №' . $this->ContractorID, ['/user/admin/update', 'id' => $this->ContractorID]) . ' Транзакция: ID ' . $this->id . ': ' . $this->action->Name . ', сумма ' . $this->CashSum, 'info'); if ($this->CashSum > 0) { //Применение акций! $discounts = ActionsRecord::getDiscounts(); foreach ($discounts as $discount) { $discount->apply($this); } } } }