add cache lock
This commit is contained in:
@@ -51,6 +51,7 @@ class DamageManagementController extends Controller
|
|||||||
'unit' => $request->unit,
|
'unit' => $request->unit,
|
||||||
'base_price' => $request->base_price,
|
'base_price' => $request->base_price,
|
||||||
'status' => 1,
|
'status' => 1,
|
||||||
|
'update_time' => now()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
@@ -76,6 +77,7 @@ class DamageManagementController extends Controller
|
|||||||
'title' => $request->title,
|
'title' => $request->title,
|
||||||
'unit' => $request->unit,
|
'unit' => $request->unit,
|
||||||
'base_price' => $request->base_price,
|
'base_price' => $request->base_price,
|
||||||
|
'update_time' => now()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ use App\Services\NominatimService;
|
|||||||
use App\Services\PaymentService;
|
use App\Services\PaymentService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||||
@@ -283,6 +284,9 @@ class AccidentReceiptController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function submitInvoice(Accident $accident, PaymentService $paymentService, SubmitInvoiceRequest $request): JsonResponse
|
public function submitInvoice(Accident $accident, PaymentService $paymentService, SubmitInvoiceRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
|
$lock = Cache::lock("accidentPayment-{$accident->id}", 10);
|
||||||
|
throw_if(!$lock->get(), new ProhibitedAction('امکان درخواست مجدد تا 10 ثانیه دیگر وجود ندارد'));
|
||||||
|
|
||||||
$final_amount = $accident->driver_share_amount - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount);
|
$final_amount = $accident->driver_share_amount - ($accident->deposit_insurance_amount + $accident->deposit_daghi_amount);
|
||||||
|
|
||||||
throw_if($final_amount < 0, new ProhibitedAction('مبالغ داغی و بیمه از مبلغ کل بیشتر می باشد.'));
|
throw_if($final_amount < 0, new ProhibitedAction('مبالغ داغی و بیمه از مبلغ کل بیشتر می باشد.'));
|
||||||
@@ -305,6 +309,8 @@ class AccidentReceiptController extends Controller
|
|||||||
|
|
||||||
Sms::sendSms($accident->driver_phone_number, $msg);
|
Sms::sendSms($accident->driver_phone_number, $msg);
|
||||||
|
|
||||||
|
$lock->release();
|
||||||
|
|
||||||
return $this->successResponse();
|
return $this->successResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class AccidentReceiptTableService
|
|||||||
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
||||||
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
||||||
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
||||||
SUM(`sum`) AS kol_sabt_shode,
|
SUM(`driver_share_amount`) AS kol_sabt_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
||||||
@@ -68,7 +68,7 @@ class AccidentReceiptTableService
|
|||||||
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
||||||
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
||||||
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
||||||
SUM(`sum`) AS kol_sabt_shode,
|
SUM(`driver_share_amount`) AS kol_sabt_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
||||||
@@ -98,7 +98,7 @@ class AccidentReceiptTableService
|
|||||||
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
||||||
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
||||||
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
||||||
SUM(`sum`) AS kol_sabt_shode,
|
SUM(`driver_share_amount`) AS kol_sabt_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
||||||
@@ -115,7 +115,7 @@ class AccidentReceiptTableService
|
|||||||
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
COUNT(CASE WHEN STATUS =5 THEN 1 END ) AS khatm,
|
||||||
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
COUNT(CASE WHEN report_base = 0 THEN 1 END) AS police_rah,
|
||||||
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
COUNT(CASE WHEN report_base = 1 THEN 1 END) AS gozaresh_gasht,
|
||||||
SUM(`sum`) AS kol_sabt_shode,
|
SUM(`driver_share_amount`) AS kol_sabt_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
SUM(CASE WHEN STATUS > 3 THEN `sum` END) AS vasel_shode,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_insurance_amount` END) AS vasel_shode_bimeh,
|
||||||
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
SUM(CASE WHEN STATUS > 3 THEN `deposit_daghi_amount` END) AS vasel_shode_daghi,
|
||||||
|
|||||||
@@ -2,10 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
|
use App\Exceptions\ProhibitedAction;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
|
||||||
class PaymentService
|
class PaymentService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @throws ProhibitedAction
|
||||||
|
*/
|
||||||
public function invoiceBillApi($driver_national_code, $final_amount)
|
public function invoiceBillApi($driver_national_code, $final_amount)
|
||||||
{
|
{
|
||||||
if (App::isProduction())
|
if (App::isProduction())
|
||||||
@@ -32,7 +36,7 @@ class PaymentService
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
catch (\Throwable $th) {
|
catch (\Throwable $th) {
|
||||||
abort(500);
|
throw new ProhibitedAction('خطا در ارتباط با سرویس پرداخت');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('damages', function (Blueprint $table) {
|
||||||
|
$table->dateTime('update_time')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('damages', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('update_time');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user