/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new PaymentMethod(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['PaymentMethod'])) { $model->attributes = $_POST['PaymentMethod']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function actionCreate() { $companyId = Helper::getCompanyId(Yii::app()->request->getParam('companyId')); $model = new PaymentMethod(); $model->dpid = $companyId; if (Yii::app()->request->isPostRequest) { $model->attributes = Yii::app()->request->getPost('PaymentMethod'); $se = new Sequence("payment_method"); $model->lid = $se->nextval(); $model->create_at = date('Y-m-d H:i:s'); $model->update_at = date('Y-m-d H:i:s', time()); // var_dump($model->attributes);exit; if ($model->save()) { Yii::app()->user->setFlash('success', yii::t('app', '添加成功')); $this->redirect(array('payMethod/index', 'companyId' => $companyId)); } } $this->render('create', array('model' => $model)); }
public function addMoneyToAccount() { $rules = ['add_method' => 'required', 'add_money' => 'required', 'credentials' => 'required']; $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator); } $uid = Auth::user()->id; $wallet = PaymentMethod::where('account_id', '=', Input::get('credentials'))->where('user_id', '=', $uid)->first(); if ($wallet == null) { $payment = new PaymentMethod(); $payment->title = Input::get('add_method'); $payment->account_id = Input::get('credentials'); $payment->user_id = $uid; $payment->save(); } $transaction = new Transaction(); $transaction->ammount = Input::get('add_money'); $transaction->payment_system = Input::get('add_method'); $transaction->transaction_direction = 'added'; $transaction->confirmed = 0; $transaction->date = date('Y-m-d H:i:s'); $transaction->user_id = $uid; $wallet = PaymentMethod::where('user_id', '=', $uid)->orderBy('created_at', 'DESC')->first(); $transaction->from_credentials = $wallet->id; $transaction->save(); $user = Auth::user(); $data = MailHelper::prepareData($user); $data['ammount'] = $transaction->ammount; Mail::send('emails.moneyadded', $data, function ($message) use($user) { $message->to($user->email)->subject('Successful transfer!'); }); $msg = 'You\'ve requested to add ' . Input::get('add_money') . '$ to your account, wait for the response.'; return Redirect::back()->with('msg', $msg); }