public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $wallet = new Wallet();
     $wallet->name = $this->name;
     $wallet->setUser($this->_user);
     if ($wallet->save()) {
         $walletAmount = new WalletAmount();
         $walletAmount->wallet_id = $wallet->id;
         $walletAmount->currency_id = $this->_currency->id;
         $walletAmount->amount = (double) $this->amount;
         if ($walletAmount->save()) {
             return [array_merge($wallet->toArray(), ['amounts' => $wallet->getAmounts()->all()])];
         }
     }
     return false;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getWallet()
 {
     return $this->hasOne(Wallet::className(), ['id' => 'wallet_id']);
 }
예제 #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getWallets()
 {
     return $this->hasMany(Wallet::className(), ['user_id' => 'id']);
 }
 public function actionIndex()
 {
     $wallets = Wallet::find()->active()->forUsersInSameGroup($this->_user)->expand(Yii::$app->request->getQueryParams())->asArray()->all();
     return ['status' => true, 'data' => $wallets];
 }