added failover failed
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FailoverTransactionFailed extends Model
|
||||
{
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'failover_transaction_failed';
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'original_id',
|
||||
'kodcaw',
|
||||
'norujukan',
|
||||
'code_error',
|
||||
'error_message'
|
||||
];
|
||||
|
||||
}
|
||||
@@ -598,7 +598,7 @@ class LelongController extends Controller
|
||||
|
||||
if($cawangan['tagarrahnbid'] == 1){
|
||||
if(env('APP_ENV') != 'production'){
|
||||
$link = 'https://niklah.arrahn.com.my/api/portalApi';
|
||||
$link = 'http://adminbid.arrahn/api/portalApi';
|
||||
}else{
|
||||
$link = 'http://adminbid.arrahn/api/portalApi';
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\KomuditiPurchase;
|
||||
use App\KomuditiTransaksi;
|
||||
use App\Marhun;
|
||||
use App\FailoverTransaction;
|
||||
use App\FailoverTransactionFailed;
|
||||
use App\Moratorium;
|
||||
use App\Support\OnePercent;
|
||||
use App\Tebus;
|
||||
@@ -947,15 +948,17 @@ class Penebusan
|
||||
|
||||
try{
|
||||
$failover_response = $this->handleFailOverTransaction($kodcaw,'create',$norujukan,$request->teller);
|
||||
DB::transaction(function () use ($failover_response,$kodcaw,$norujukan,$gadai,$cawangan,$array_tebus,$array_trans) {
|
||||
// DB::connection($cawangan['mysql'])->transaction(function () use ($failover_response,$kodcaw,$norujukan,$gadai,$cawangan,$array_tebus,$array_trans) {
|
||||
DB::connection($cawangan['mysql'])->beginTransaction();
|
||||
$this->saveTebus($kodcaw,$norujukan,$gadai,$cawangan,$array_tebus);
|
||||
$this->createTransaction($cawangan,$kodcaw,$norujukan,$array_trans,$failover_response['id']);
|
||||
});
|
||||
// });
|
||||
|
||||
DB::connection('mysql7')->transaction(function () use ($kodcaw,$norujukan,$gadai,$array_tebus_base,$array_trans_base) {
|
||||
DB::connection('mysql7')->beginTransaction();
|
||||
// DB::connection('mysql7')->transaction(function () use ($kodcaw,$norujukan,$gadai,$array_tebus_base,$array_trans_base) {
|
||||
$this->saveTebusBase($kodcaw,$norujukan,$gadai,$array_tebus_base);
|
||||
$this->createTransactionBase($norujukan,$kodcaw,$array_trans_base);
|
||||
});
|
||||
// });
|
||||
|
||||
$this->handleFailOverTransaction($kodcaw,'done',$norujukan,$request->teller,$failover_response['id']);
|
||||
|
||||
@@ -963,13 +966,19 @@ class Penebusan
|
||||
'result' => 'success',
|
||||
'data' => 1
|
||||
];
|
||||
|
||||
DB::connection($cawangan['mysql'])->commit();
|
||||
DB::connection('mysql7')->commit();
|
||||
|
||||
return response()->json($array_response);
|
||||
|
||||
}catch(\Exception $e){
|
||||
if (isset($failover_response['id'])) {
|
||||
$this->handleFailOverTransaction($kodcaw,'fail',$norujukan,$request->teller,$failover_response['id']);
|
||||
$this->handleFailOverTransaction($kodcaw,'fail',$norujukan,$request->teller,$failover_response['id'],$e->getCode(),$e->getMessage());
|
||||
}
|
||||
|
||||
DB::connection($cawangan['mysql'])->rollBack();
|
||||
DB::connection('mysql7')->rollBack();
|
||||
$array_response = [
|
||||
'result' => 'error',
|
||||
'data' => $e->getMessage()
|
||||
@@ -1041,7 +1050,7 @@ class Penebusan
|
||||
$upah_rebet = $this->kiraUpahRebetSebenar($kodcaw,$norujukan);
|
||||
|
||||
$array_onepercent_rebet = $this->kiraupahUjrahOnePercentRebate($kodcaw,$norujukan);
|
||||
|
||||
try{
|
||||
$onepercent_rebet = $array_onepercent_rebet['onepercent'] - $upah_rebet['onepercent'];
|
||||
$ujrah_rebet = $array_onepercent_rebet['ujrah'] - $upah_rebet['ujrah'];
|
||||
|
||||
@@ -1072,8 +1081,9 @@ class Penebusan
|
||||
'ujrah' => $ujrah_rebet,
|
||||
'onepercent' => $onepercent_rebet,
|
||||
]);
|
||||
|
||||
|
||||
}catch(\Exception $e){
|
||||
throw new \Exception("Error in Tebus: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function saveTebusBase($kodcaw,$norujukan,$gadai,$array_tebus_base){
|
||||
@@ -1095,6 +1105,7 @@ class Penebusan
|
||||
|
||||
$upah_rebet_sebenar = $harga_tebus['harga'] - $gadai['bakipjm'];
|
||||
|
||||
try{
|
||||
TransaksiKeuntungan::on('mysql7')->create([
|
||||
'norujukan' => $norujukan,
|
||||
'bayaran_keuntungan' => $upah_tebus,
|
||||
@@ -1125,6 +1136,9 @@ class Penebusan
|
||||
'duitpelanggan' => isset($array_tebus_base['duitpelanggan']) ? $array_tebus_base['duitpelanggan'] : 0,
|
||||
'bakipelanggan' => isset($array_tebus_base['bakipelanggan']) ? $array_tebus_base['bakipelanggan'] : 0
|
||||
]);
|
||||
}catch(\Exception $e){
|
||||
throw new \Exception("Error in TebusBase: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function createTransaction($cawangan,$kodcaw,$norujukan,$array_trans,$fail_id = 0){
|
||||
@@ -1139,6 +1153,7 @@ class Penebusan
|
||||
$new_transaction = sprintf("%04d",$new_sirig);
|
||||
$new_sag_number = strtoupper($cawangan['kodcaw']) . $current->year . $current->month . $current->day . '-' .$new_transaction;
|
||||
|
||||
try{
|
||||
Gadai::on($cawangan['mysql'])->create([
|
||||
'kodcaw'=>$kodcaw,
|
||||
'norujukan' => $new_sag_number,
|
||||
@@ -1256,6 +1271,10 @@ class Penebusan
|
||||
|
||||
$this->handleFailOverTransaction($kodcaw,'update',$new_sag_number,$array_trans['teller'],$fail_id);
|
||||
|
||||
}catch(\Exception $e){
|
||||
throw new \Exception("Error in Transaction: " . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function createTransactionBase($norujukan,$kodcaw,$array_trans_base){
|
||||
@@ -1264,7 +1283,9 @@ class Penebusan
|
||||
$komuditi_current = KomuditiPurchase::on('mysql7')->where('date_purchase','=',$current->toDateString())->orderBy('created_at','desc')->first();
|
||||
|
||||
$unit_current = isset($komuditi_current['unit_komuditi']) ? $komuditi_current['unit_komuditi']: 0;
|
||||
throw new \Exception('testis');
|
||||
|
||||
try{
|
||||
$update_unit = $unit_current - $array_trans_base['pinjaman'];
|
||||
|
||||
KomuditiPurchase::on('mysql7')->where('id','=',$komuditi_current['id'])->update([
|
||||
@@ -1280,9 +1301,12 @@ class Penebusan
|
||||
'masa' => $current->toTimeString(),
|
||||
'tarikh' => $current->toDateString()
|
||||
]);
|
||||
}catch(\Exception $e){
|
||||
throw new \Exception("Error in TransactionBase: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function handleFailOverTransaction($kodcaw,$status,$norujukan,$teller,$fail_id = 0){
|
||||
private function handleFailOverTransaction($kodcaw,$status,$norujukan,$teller,$fail_id = 0,$code_error = 500,$error_message = ''){
|
||||
$current = Carbon::now();
|
||||
|
||||
if($status == 'create'){
|
||||
@@ -1304,18 +1328,28 @@ class Penebusan
|
||||
]);
|
||||
|
||||
}else if($status == 'done'){
|
||||
return FailoverTransaction::on('mysql7')->where('id',$fail_id)->update([
|
||||
'new_norujukan' => $norujukan,
|
||||
return FailoverTransaction::on('mysql7')->where('id',$fail_id)->where('old_norujukan',$norujukan)->update([
|
||||
'db_caw' => true,
|
||||
'db_online' => true,
|
||||
'status' => 'resolved',
|
||||
'resolve_time' => $current
|
||||
]);
|
||||
}else{
|
||||
return FailoverTransaction::on('mysql7')->where('id',$fail_id)->update([
|
||||
FailoverTransaction::on('mysql7')->where('id',$fail_id)->where('old_norujukan',$norujukan)->update([
|
||||
'old_norujukan' => $norujukan,
|
||||
'status' => 'fail',
|
||||
'status' => 'failed',
|
||||
]);
|
||||
|
||||
FailoverTransactionFailed::on('mysql7')->create([
|
||||
'original_id' => $fail_id,
|
||||
'kodcaw' => $kodcaw,
|
||||
'norujukan' => $norujukan,
|
||||
'code_error' => $code_error,
|
||||
'error_message' => $error_message,
|
||||
]);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateFailoverTransactionFailedTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('failover_transaction_failed', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->unsignedBigInteger('original_id'); // Reference to failover_transaction
|
||||
$table->string('kodcaw');
|
||||
$table->string('norujukan');
|
||||
$table->integer('code_error');
|
||||
$table->text('error_message')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('failover_transaction_failed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user