本文整理汇总了PHP中Transaction::insert方法的典型用法代码示例。如果您正苦于以下问题:PHP Transaction::insert方法的具体用法?PHP Transaction::insert怎么用?PHP Transaction::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Transaction
的用法示例。
在下文中一共展示了Transaction::insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: begin
public static function begin()
{
$retval = new Transaction();
$retval->insert();
return $retval;
}
示例2: postScan
public function postScan()
{
$in = Input::get();
$code = $in['txtin'];
$outlet_id = $in['outlet_id'];
$use_outlet = $in['search_outlet'];
$action = strtolower($in['action']);
$session = $in['session'];
$outlets = Prefs::getOutlet()->OutletToSelection('_id', 'name', false);
$outlet_name = $outlets[$outlet_id];
$res = 'OK';
$msg = '';
if (strripos($code, '|') >= 0) {
$code = explode('|', $code);
$SKU = $code[0];
$unit_id = $code[1];
} else {
$SKU = trim($code);
$unit_id = null;
}
switch ($action) {
case 'add':
if (is_null($unit_id)) {
$res = 'NOK';
$msg = 'SKU: ' . $SKU . ' <br />Unit ID: NOT FOUND';
break;
}
$u = Stockunit::where('SKU', '=', $SKU)->where('_id', 'like', '%' . $unit_id)->where('status', 'available')->first();
if ($u) {
$ul = $u->toArray();
$ul['scancheckDate'] = new MongoDate();
$ul['createdDate'] = new MongoDate();
$ul['lastUpdate'] = new MongoDate();
$ul['action'] = $action;
$ul['status'] = 'reserved';
$ul['quantity'] = 1;
$ul['unitPrice'] = $ul['productDetail']['priceRegular'];
$ul['unitTotal'] = $ul['productDetail']['priceRegular'];
$ul['deliverTo'] = $outlet_name;
$ul['deliverToId'] = $outlet_id;
$ul['returnTo'] = $outlet_name;
$ul['returnToId'] = $outlet_id;
$ul['sessionId'] = $session;
$ul['sessionStatus'] = 'open';
$unit_id = $ul['_id'];
unset($ul['_id']);
$ul['unitId'] = $unit_id;
Transaction::insert($ul);
$history = array('datetime' => new MongoDate(), 'action' => 'pos', 'price' => $ul['productDetail']['priceRegular'], 'status' => $ul['status'], 'outletName' => $ul['outletName']);
//change status to sold
$u->status = 'reserved';
$u->push('history', $history);
$u->save();
$res = 'OK';
$msg = 'SKU: ' . $ul['SKU'] . ' <br />Unit ID: ' . $unit_id . ' <br />Outlet: ' . $ul['outletName'];
} else {
$res = 'NOK';
$msg = 'SKU: ' . $SKU . ' <br />Unit ID: ' . $unit_id . ' <br />NOT FOUND in this outlet';
}
break;
case 'remove':
if (is_null($unit_id)) {
$res = 'NOK';
$msg = 'SKU: ' . $SKU . ' <br />Unit ID: NOT FOUND';
break;
}
$u = Stockunit::where('SKU', '=', $SKU)->where('_id', 'like', '%' . $unit_id)->first();
if ($u) {
$ul = $u->toArray();
$ul['scancheckDate'] = new MongoDate();
$ul['createdDate'] = new MongoDate();
$ul['lastUpdate'] = new MongoDate();
$ul['action'] = $action;
$ul['deliverTo'] = $outlet_name;
$ul['deliverToId'] = $outlet_id;
$ul['returnTo'] = $outlet_name;
$ul['returnToId'] = $outlet_id;
$unit_id = $ul['_id'];
unset($ul['_id']);
$ul['unitId'] = $unit_id;
Stockunitlog::insert($ul);
$history = array('datetime' => new MongoDate(), 'action' => $action, 'price' => $ul['productDetail']['priceRegular'], 'status' => $ul['status'], 'outletName' => $ul['outletName']);
$u->push('history', $history);
$u->save();
$res = 'OK';
$msg = 'SKU: ' . $ul['SKU'] . ' <br />Unit ID: ' . $unit_id . ' <br />Outlet: ' . $ul['outletName'];
} else {
$res = 'NOK';
$msg = 'SKU: ' . $SKU . ' <br />Unit ID: ' . $unit_id . ' <br />NOT FOUND in this outlet';
}
break;
default:
break;
}
$total_price = Transaction::where('sessionId', $session)->sum('unitPrice');
$result = array('total_price' => $total_price, 'result' => $res, 'msg' => $msg);
return Response::json($result);
}
示例3: startPayment
/**
* Start Paytrail transaction.
*
* @param string $patronId Patron's catalog username (e.g. barcode)
* @param int $amount Payment amount without transaction fee (in cents)
* @param int $transactionFee Transaction fee (in cents)
* @param array $fines Fines that belong to the transaction
* @param string $currency Currency
* @param string $statusParam URL parameter for payment status in callback requests
* @param string $transactionIdParam URL parameter for transaction Id in callback requests
*
* @return false on error, otherwise redirects to Paytrail.
* @access public
*/
public function startPayment($patronId, $amount, $transactionFee, $fines, $currency, $statusParam, $transactionIdParam)
{
global $configArray;
global $user;
$orderNumber = $this->generateTransactionId($patronId);
$base = $configArray['Site']['url'];
$urlset = new Paytrail_Module_Rest_Urlset("{$base}/MyResearch/Fines?{$statusParam}=" . self::PAYMENT_SUCCESS . "&{$transactionIdParam}=" . urlencode($orderNumber), "{$base}/MyResearch/Fines?{$statusParam}=" . self::PAYMENT_FAILURE . "&{$transactionIdParam}=" . urlencode($orderNumber), "{$base}/AJAX/PaytrailNotify?{$statusParam}=" . self::PAYMENT_NOTIFY . "&{$transactionIdParam}=" . urlencode($orderNumber), "");
$totAmount = ($amount + $transactionFee) / 100.0;
$payment = new Paytrail_Module_Rest_Payment_S1($orderNumber, $urlset, $totAmount);
if (!($module = $this->initPaytrail())) {
error_log("Paytrail: error starting payment processing.");
return false;
}
try {
$result = $module->processPayment($payment);
} catch (Paytrail_Exception $e) {
error_log("Paytrail: error starting payment processing.");
error_log(" " . $e->getMessage());
header("Location: {$configArray['Site']['url']}/MyResearch/Fines");
}
$t = new Transaction();
$t->transaction_id = $orderNumber;
$t->driver = reset(explode('.', $patronId, 2));
$t->user_id = isset($user) && is_object($user) ? $user->id : null;
$t->amount = $amount;
$t->transaction_fee = $transactionFee;
$t->currency = $currency;
$t->created = date("Y-m-d H:i:s");
$t->complete = 0;
$t->status = 'started';
$t->cat_username = $patronId;
if (!$t->insert()) {
error_log('Paytrail: error creating transaction');
return false;
}
foreach ($fines as $fine) {
if (!$t->addFee($fine, $user, $currency)) {
error_log('Paytrail: error adding fee to transaction.');
return false;
}
}
header("Location: {$result->getUrl()}");
}