Пример #1
0
 public function afterSave($insert, $changedAttributes)
 {
     if (!$insert) {
         if (isset($changedAttributes['money'])) {
             /**@var $moneyLogModel MoneyLog **/
             $moneyLogModel = Yii::createObject(MoneyLog::className());
             if ($changedAttributes['money'] > $this->money) {
                 $moneyLogModel->type = $moneyLogModel::STATUS_EXPEND;
             } else {
                 $moneyLogModel->type = $moneyLogModel::STATUS_INCOME;
             }
             $moneyLogModel->user_id = $this->user_id;
             $moneyLogModel->money = abs($changedAttributes['money'] - $this->money);
             $moneyLogModel->info = $this->info;
             if (!$moneyLogModel->save()) {
                 throw new Exception(Yii::t('money', MoneyLog::className() . 'save fail'));
             }
         }
     }
     parent::afterSave($insert, $changedAttributes);
 }
Пример #2
0
 public function actionMoneyLog()
 {
     $model = Yii::createObject(MoneyLog::className());
     $dataProvider = new ActiveDataProvider(['query' => $model::find()->where(['user_id' => Yii::$app->user->id])->orderBy(['create_at' => SORT_DESC])]);
     return $this->render('moneyLog', ['dataProvider' => $dataProvider]);
 }