本文整理汇总了PHP中Transaction::save方法的典型用法代码示例。如果您正苦于以下问题:PHP Transaction::save方法的具体用法?PHP Transaction::save怎么用?PHP Transaction::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save()
{
$Transaction = new Transaction($this->data->Transaction);
$Transaction->save();
$go = '>auth/Transaction/formObject/' . $Transaction->getId();
$this->renderPrompt('information', 'OK', $go);
}
示例2: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate($for = null, $mass_id = null)
{
$model = new MassBooking();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['MassBooking'])) {
$tr = Yii::app()->db->beginTransaction();
$acct = Account::get('Mass Bookings');
$trans = new Transaction();
$trans->type = 'credit';
$trans->account_id = $acct->id;
$trans->amount = $_POST['amount'];
$trans->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
$trans->creator = Yii::app()->user->id;
$trans->descr = "Mass booking";
if ($trans->save()) {
$model->attributes = $_POST['MassBooking'];
$model->trans_id = $trans->id;
if ($model->save()) {
$trans->saveAttributes(array('descr' => "Mass booking #" . $model->id));
$tr->commit();
$this->redirect(array('view', 'id' => $model->id));
return;
}
}
$tr->rollback();
}
$parms = array('model' => $model);
$parms['mass_dt'] = isset($for) ? $for : '';
$parms['mass_id'] = isset($mass_id) ? $mass_id : '';
$this->render('create', $parms);
}
示例3: actionIndex
public function actionIndex()
{
$user = Yii::app()->user->data();
if (Yii::app()->user->isGuest) {
$this->layout = '//layouts/landing';
$this->render('index');
} elseif ($user->isActivated()) {
if ($user->isVerified()) {
$buyform = new BuyBtcForm();
// $transactions = Transaction::model ()->findAllByAttributes(array('id_user' => $user->id, 'type' => 1));
$avail_balance_local = money_format('%.2n', count($user->balance) > 0 ? $user->balance->local : 0);
$avail_balance_usd = money_format('%.2n', count($user->balance) > 0 ? $user->balance->usd : 0);
$avail_balance_btc = money_format('%.2n', count($user->balance) > 0 ? $user->balance->btc : 0);
$request = Yii::app()->request;
$formData = $request->getPost(get_class($buyform), false);
if ($formData) {
$buyform->amount_btc = $formData['amount_btc'];
$buyform->amount_fiat = $formData['amount_fiat'];
$buyform->type_trans = $formData['type_trans'];
/*if ($buyform->hasErrors ()) {
}
else{
*/
if ($buyform->validate(array(''))) {
$tran = new Transaction();
$tran->id_user = $user->id;
$tran->status = 0;
if ($buyform->type_trans == "BUY") {
$tran->type = 4;
$tran->descr = "You purchased Bitcoins";
$tran->currency = "USD";
$tran->amount = $buyform->amount_btc;
} elseif ($buyform->type_trans == "SELL") {
$tran->type = 3;
$tran->descr = "You sold Bitcoins";
$tran->currency = "BTC";
$tran->amount = $buyform->amount_fiat;
} else {
Yii::app()->user->setFlash('error', Yii::t('translation', 'Error! Unable to create transaction'));
}
if (!$tran->save()) {
Yii::app()->user->setFlash('error', Yii::t('translation', 'Error! Unable to create transaction'));
}
} else {
Yii::app()->user->setFlash('error', Yii::t('translation', 'Error in the fields'));
}
}
$this->render('index-activated', compact('avail_balance_local', 'user', 'buyform', 'avail_balance_local', 'avail_balance_usd', 'avail_balance_btc'));
} else {
$this->render('notverified');
}
} else {
$this->render('index');
}
}
示例4: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Transaction();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Transaction'])) {
$model->attributes = $_POST['Transaction'];
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例5: edit
function edit()
{
if ($this->request->is_post()) {
$transaction = new Transaction($_POST);
$transaction->save();
$this->redirect_to(array('action' => 'index'));
} else {
$this->transaction = new Transaction();
$this->transaction->find_by_id($_GET['id']);
$this->transaction->stock = new Stock();
$this->transaction->stock->find_by_id($this->transaction->isin);
}
}
示例6: actionCreate
public function actionCreate()
{
$model = new Transaction();
if (isset($_POST['Transaction'])) {
$model->setAttributes($_POST['Transaction']);
if ($model->save()) {
if (Yii::app()->getRequest()->getIsAjaxRequest()) {
Yii::app()->end();
} else {
$this->redirect(array('view', 'id' => $model->id));
}
}
}
$this->render('create', array('model' => $model));
}
示例7: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Transaction();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['Transaction'])) {
$model->attributes = $_POST['Transaction'];
$model->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
$model->creator = Yii::app()->user->id;
if ($model->save()) {
$this->redirect(array('view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例8: deductAmount
public function deductAmount($userId, $amount, $type = 9)
{
$model = $this->findByAttributes(array('fk_user' => $userId));
if ($model) {
if ($model->amount >= $amount) {
$model->amount = $model->amount - $amount;
$model->save();
$transObj = new Transaction();
$transObj->attributes = array('fk_user' => $userId, 'type' => $type, 'amount' => $amount);
$transObj->save();
return true;
}
}
return false;
}
示例9: Account
function new_transaction()
{
if (!$this->auth->logged_in()) {
$this->auth->login();
return;
}
$account = new Account();
$transaction = new Transaction();
$account->get_by_id($this->input->post('account_id'));
$transaction->date = $this->input->post('date');
$transaction->description = $this->input->post('description');
$transaction->credit = $this->input->post('credit');
$transaction->debit = $this->input->post('debit');
$transaction->save($account);
$this->index();
}
示例10: actionCreate
public function actionCreate()
{
$model = new Transaction();
if (isset($_POST['Transaction'])) {
$model->attributes = $_POST['Transaction'];
$model->account_id = Account::get('Collection')->id;
$model->type = 'credit';
Yii::trace("Transaction account id: " . $model->account_id, 'application.controllers.CollectionController');
$model->created = Yii::app()->dateFormatter->formatDateTime(time(), 'short', 'medium');
$model->creator = Yii::app()->user->id;
$date = $_POST['date'];
$model->descr = "Collection for {$date}";
if ($model->save()) {
$this->redirect(array('/transaction/view', 'id' => $model->id));
}
}
$this->render('create', array('model' => $model));
}
示例11: checkoutAction
function checkoutAction($params)
{
if ($this->isGuest()) {
$this->redirect("Site", "login");
}
$userId = $this->signedInUser()->id;
$itemId = $params["itemId"];
$item = Item::model()->find($itemId);
$item->quantity--;
$transaction = new Transaction();
$transaction->userId = $userId;
$transaction->itemId = $item->id;
$transaction->date = date("Y-m-d H:i:s");
$item->save();
$transaction->save();
$this->addFlash("Item bought successfully!");
return $this->redirect("Site", "index");
}
示例12: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$rules = array('item' => 'required|min:2', 'amount' => 'required');
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
//return to form with erros
return Redirect::to('transactions/create')->withErrors($validator)->withInput(Input::all());
} else {
//save record
$transaction = new Transaction();
$transaction->user_id = Auth::user()->id;
$transaction->amount = Input::get('amount');
$transaction->item = Input::get('item');
$transaction->date_purchased = date('Y-m-d H:i:s', strtotime(Input::get('date_purchased')));
$transaction->save();
Session::flash('message', $transaction->item . ' added to ' . Auth::user()->firstname);
return Redirect::to(Request::url());
}
}
示例13: createAction
/**
* Creates a new transaction
*/
public function createAction()
{
if (!$this->request->isPost()) {
return $this->dispatcher->forward(array("controller" => "transaction", "action" => "index"));
}
$transaction = new Transaction();
$transaction->id = $this->request->getPost("id");
$transaction->student_id = $this->request->getPost("student_id");
$transaction->librarian_id = $this->request->getPost("librarian_id");
$transaction->book_id = $this->request->getPost("book_id");
$transaction->action = $this->request->getPost("action");
$transaction->time = $this->request->getPost("time");
if (!$transaction->save()) {
foreach ($transaction->getMessages() as $message) {
$this->flash->error($message);
}
return $this->dispatcher->forward(array("controller" => "transaction", "action" => "new"));
}
$this->flash->success("transaction was created successfully");
return $this->dispatcher->forward(array("controller" => "transaction", "action" => "index"));
}
示例14: addTransaction
/**
* Ajoute une transaction
* Utilisé uniquement par le code
*
* @param $user_id
* @param $bet_id
* @param $value
* @param $type
* @return bool
*/
public static function addTransaction($user_id, $bet_id, $value, $type)
{
if (in_array($type, array('gain', 'bet')) && Bet::find($bet_id)) {
$transaction = new Transaction();
$transaction->user_id = $user_id;
$transaction->bet_id = $bet_id;
$transaction->value = $value;
$transaction->type = $type;
$transaction->save();
//On déduit/ajoute les point de la transaction
$user = User::find($user_id);
if ($transaction->type == "bet") {
$user->points -= $transaction->value;
} else {
if ($transaction->type == "gain") {
$user->points += $transaction->value;
}
}
$user->save();
}
return false;
}
示例15: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$input = Input::all();
$input['reference_number'] = date('Ymd') . '-' . str_random(5);
$validation = Validator::make($input, Transaction::$rules);
if ($validation->passes()) {
// CREATE NEW TRANSACTION
$transaction = new Transaction();
$transaction->reference_number = date('Ymd') . '-' . str_random(5);
$transaction->property_id = Input::get('property_id');
$transaction->reservation_id = Input::get('reservation_id');
$transaction->status = Input::get('status');
$transaction->amount = Input::get('amount');
$transaction->firstname = Input::get('firstname');
$transaction->lastname = Input::get('lastname');
$transaction->contact_number = Input::get('contact_number');
$transaction->address = Input::get('address');
$transaction->email = Input::get('email');
$transaction->remarks = Input::get('remarks');
$transaction->save();
// GENERATE INVOICE
$html = View::make('admin.transactions.show', compact('transaction'));
$pdf = storage_path() . '/invoices/' . $transaction->reference_number . '.pdf';
$dompdf = new DOMPDF();
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents($pdf, $output);
// EMAIL THE INVOICE
$data['transaction'] = $transaction;
Mail::send('mails.default', $data, function ($message) use($transaction, $pdf) {
$message->to($transaction->email)->subject("Your Invoice");
$message->attach($pdf);
});
return Redirect::route('admin.transactions.index')->with('success', 'An invoice has been sent to the client.');
}
return Redirect::route('admin.transactions.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.');
}