本文整理汇总了PHP中app\models\Payment::findornew方法的典型用法代码示例。如果您正苦于以下问题:PHP Payment::findornew方法的具体用法?PHP Payment::findornew怎么用?PHP Payment::findornew使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Payment
的用法示例。
在下文中一共展示了Payment::findornew方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: status
/**
* Store a sale
*
* 1. Save Sale
* 2. Save Payment or shipment
* 3. Save Transaction Log
*
* @return Response
*/
public function status()
{
if (!Input::has('sale')) {
return new JSend('error', (array) Input::all(), 'Tidak ada data sale.');
}
$errors = new MessageBag();
DB::beginTransaction();
//1. Validate Sale Parameter
$sale = Input::get('sale');
if (is_null($sale['id'])) {
return new JSend('error', (array) Input::all(), 'Tidak ada data sale.');
} else {
$is_new = false;
}
//1a. Get original data
$sale_data = \App\Models\Sale::findorfail($sale['id']);
//1b. Check if there were statuses differences
if ($sale_data['status'] == $sale['status']) {
$errors->add('Sale', 'Tidak ada perubahan status.');
}
//2. Check if status = paid
if (!$errors->count() && in_array($sale['status'], ['paid'])) {
if (!isset($sale['payment']) || is_null($sale['payment'])) {
$errors->add('Sale', 'Tidak ada data pembayaran.');
} else {
$paid_data = \App\Models\Payment::findornew($sale['payment']['id']);
$payment_rule = ['transaction_id' => 'exists:transactions,id|' . (!$paid_data ? '' : 'in:' . $sale_data['id']), 'method' => 'required|max:255', 'destination' => 'required|max:255', 'account_name' => 'required|max:255', 'account_number' => 'required|max:255', 'ondate' => 'required|date_format:"Y-m-d H:i:s"', 'amount' => 'required|numeric|in:' . $sale_data['bills']];
$validator = Validator::make($sale['payment'], $payment_rule);
//if there was log and validator false
if (!$validator->passes()) {
$errors->add('Log', $validator->errors());
} else {
$sale['payment']['transaction_id'] = $sale['id'];
$paid_data = $paid_data->fill($sale['payment']);
if (!$paid_data->save()) {
$errors->add('Log', $paid_data->getError());
}
}
}
}
//2. Check if status = shipping
if (!$errors->count() && in_array($sale['status'], ['shipping'])) {
if (is_null($sale['shipment']['receipt_number'])) {
$errors->add('Sale', 'Tidak ada nomor resi.');
} else {
$shipping_data = \App\Models\Shipment::id($sale['shipment']['id'])->first();
if ($shipping_data) {
$shipment_rule = ['receipt_number' => 'required|max:255'];
$validator = Validator::make($sale['shipment'], $shipment_rule);
//if there was log and validator false
if (!$validator->passes()) {
$errors->add('Log', $validator->errors());
} else {
$sale['shipment']['transaction_id'] = $sale['id'];
$shipping_data = $shipping_data->fill($sale['shipment']);
if (!$shipping_data->save()) {
$errors->add('Log', $shipping_data->getError());
}
}
} else {
$errors->add('Log', 'Shipment tidak valid.');
}
}
}
//3. Check if status = others
if (!$errors->count() && !in_array($sale['status'], ['paid', 'shipping'])) {
$log_rules = ['transaction_id' => 'exists:transactions,id|' . ($is_new ? '' : 'in:' . $sale_data['id']), 'status' => 'required|max:255|in:cart,wait,payment_process,paid,packed,shipping,delivered,canceled,abandoned'];
$validator = Validator::make($sale, $log_rules);
//if there was log and validator false
if (!$validator->passes()) {
$errors->add('Log', $validator->errors());
} else {
$log_data = new \App\Models\TransactionLog();
$log_data = $log_data->fill(['status' => $sale['status'], 'transaction_id' => $sale_data['id'], 'notes' => isset($sale['notes']) ? $sale['notes'] : '']);
if (!$log_data->save()) {
$errors->add('Log', $log_data->getError());
}
}
}
if ($errors->count()) {
DB::rollback();
return new JSend('error', (array) Input::all(), $errors);
}
DB::commit();
$final_sale = \App\Models\Sale::id($sale_data['id'])->with(['voucher', 'transactionlogs', 'user', 'transactiondetails', 'transactiondetails.varian', 'transactiondetails.varian.product', 'paidpointlogs', 'payment', 'shipment', 'shipment.address', 'shipment.courier', 'transactionextensions', 'transactionextensions.productextension'])->first()->toArray();
return new JSend('success', (array) $final_sale);
}