Write webservice for harim and Cmms
This commit is contained in:
@@ -50,6 +50,11 @@ PAYMENT_USERNAME=
|
|||||||
PAYMENT_PASSWORD=
|
PAYMENT_PASSWORD=
|
||||||
PAYMENT_LINK=
|
PAYMENT_LINK=
|
||||||
|
|
||||||
|
HARIM_PAYMENT_USERNAME=
|
||||||
|
HARIM_PAYMENT_PASSWORD=
|
||||||
|
HARIM_PAYMENT_URL=
|
||||||
|
HARIM_PAYMENT_LINK=
|
||||||
|
|
||||||
RMS_VERSION=3.0
|
RMS_VERSION=3.0
|
||||||
RMS_CTO_PHONE_NUMBER=
|
RMS_CTO_PHONE_NUMBER=
|
||||||
|
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class GetMachinesInfoListCommand extends Command
|
|||||||
'province_id' => $entry['UnitGroupCode'] ?? null,
|
'province_id' => $entry['UnitGroupCode'] ?? null,
|
||||||
'city_id' => $entry['UnitCode'] ?? null,
|
'city_id' => $entry['UnitCode'] ?? null,
|
||||||
'station_id' => $entry['Layer3Code'] ?? null,
|
'station_id' => $entry['Layer3Code'] ?? null,
|
||||||
|
'driver_name' => $entry['DriverName'] ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
++$updatedRows;
|
++$updatedRows;
|
||||||
|
|||||||
@@ -21,6 +21,10 @@ enum HarimStates: int
|
|||||||
case BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL = 15;
|
case BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL = 15;
|
||||||
case MOKHALEFAT_BA_DASTGAH = 16;
|
case MOKHALEFAT_BA_DASTGAH = 16;
|
||||||
case ETMAM_FARAYAND = 17;
|
case ETMAM_FARAYAND = 17;
|
||||||
|
case SODOR_FACTOR = 18;
|
||||||
|
case PARDAKHT_FACTOR = 19;
|
||||||
|
case SABT_FISH = 20;
|
||||||
|
|
||||||
|
|
||||||
public function label(): string
|
public function label(): string
|
||||||
{
|
{
|
||||||
@@ -42,6 +46,9 @@ enum HarimStates: int
|
|||||||
self::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL => "تائید عرصه و اعیان ارسال شده توسط مدیر",
|
self::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL => "تائید عرصه و اعیان ارسال شده توسط مدیر",
|
||||||
self::MOKHALEFAT_BA_DASTGAH => "مخالفت با درخواست",
|
self::MOKHALEFAT_BA_DASTGAH => "مخالفت با درخواست",
|
||||||
self::ETMAM_FARAYAND => "اتمام فرایند",
|
self::ETMAM_FARAYAND => "اتمام فرایند",
|
||||||
|
self::SODOR_FACTOR => "صدور فاکتور",
|
||||||
|
self::PARDAKHT_FACTOR => "پرداخت فاکتور",
|
||||||
|
self::SABT_FISH => "ثبت فیش",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,12 +2,18 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
namespace App\Http\Controllers\V3\Dashboard\Harim;
|
||||||
|
|
||||||
|
use App\Facades\Sms\Sms;
|
||||||
|
use App\Enums\HarimStates;
|
||||||
use App\Exceptions\ProhibitedAction;
|
use App\Exceptions\ProhibitedAction;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
|
use App\Http\Requests\V3\Dashboard\Harim\Detail\HarimSubmitInvoiceRequest;
|
||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\Harim;
|
use App\Models\Harim;
|
||||||
use App\Models\HarimState;
|
use App\Models\HarimState;
|
||||||
|
use App\Services\Cartables\Harim\HarimPaymentService;
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class DetailController extends Controller
|
class DetailController extends Controller
|
||||||
@@ -30,4 +36,58 @@ class DetailController extends Controller
|
|||||||
->orderBy('id', 'desc')
|
->orderBy('id', 'desc')
|
||||||
->get(['id', 'expert_description', 'action_name', 'previous_state_name']));
|
->get(['id', 'expert_description', 'action_name', 'previous_state_name']));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Throwable
|
||||||
|
* @throws ProhibitedAction
|
||||||
|
*/
|
||||||
|
public function submitInvoice(Harim $harim, HarimPaymentService $harimpaymentService, HarimSubmitInvoiceRequest $request): JsonResponse
|
||||||
|
{
|
||||||
|
$lock = Cache::lock("harimPayment-{$harim->id}", 10);
|
||||||
|
throw_if(! $lock->get(), new ProhibitedAction('امکان درخواست مجدد تا 10 ثانیه دیگر وجود ندارد'));
|
||||||
|
|
||||||
|
$payment_amount = $harim->payment_amount;
|
||||||
|
|
||||||
|
$bill_code = $harimpaymentService->invoiceBillApi($harim->national_id, $payment_amount);
|
||||||
|
|
||||||
|
DB::transaction(function () use ($bill_code, $harim) {
|
||||||
|
|
||||||
|
$harim->histories()->update([
|
||||||
|
// 'bill_code' => $bill_code,
|
||||||
|
'status' => HarimStates::SODOR_FACTOR->value,
|
||||||
|
'status_fa' => HarimStates::SODOR_FACTOR->label(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
$msg = "فاکتور با شناسه پرداخت \n" . explode("/", $harim->bill_code)[0]. "\n برای پرداخت از لینک زیر اقدام نمایید.\n\n"
|
||||||
|
. config('harim_web_services.Harim_Payment.LINK')."/#/pay/".explode("/", $harim->bill_code)[0]."/$payment_amount";
|
||||||
|
|
||||||
|
Sms::sendSms($harim->phone_number, $msg);
|
||||||
|
|
||||||
|
$lock->release();
|
||||||
|
|
||||||
|
return $this->successResponse();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws Throwable
|
||||||
|
*/
|
||||||
|
public function checkPaymentStatus(Harim $harim, HarimPaymentService $harimpaymentService): JsonResponse
|
||||||
|
{
|
||||||
|
DB::transaction(function () use ($harim, $harimpaymentService) {
|
||||||
|
|
||||||
|
$response = json_decode($harimpaymentService->callPaymentStatusBillApi(explode('/', $harim->bill_code)[0]));
|
||||||
|
|
||||||
|
throw_if(! $response->isPayed, new ProhibitedAction('پرداخت انجام نشده است'));
|
||||||
|
|
||||||
|
$harim->histories()->update([
|
||||||
|
'status' => HarimStates::PARDAKHT_FACTOR->value,
|
||||||
|
'status_fa' => HarimStates::PARDAKHT_FACTOR->label(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this->successResponse($harim);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requests\V3\Dashboard\Harim\Detail;
|
||||||
|
|
||||||
|
use App\Enums\HarimStates;
|
||||||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class HarimSubmitInvoiceRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Determine if the user is authorized to make this request.
|
||||||
|
*/
|
||||||
|
public function authorize(): bool
|
||||||
|
{
|
||||||
|
return $this->harim->state_id == HarimStates::SABT_FISH->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array<string, ValidationRule|array|string>
|
||||||
|
*/
|
||||||
|
public function rules(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
65
app/Services/Cartables/Harim/HarimPaymentService.php
Normal file
65
app/Services/Cartables/Harim/HarimPaymentService.php
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services\Cartables\Harim;
|
||||||
|
|
||||||
|
use App\Exceptions\ProhibitedAction;
|
||||||
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
|
||||||
|
class HarimPaymentService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @throws ProhibitedAction
|
||||||
|
*/
|
||||||
|
public function invoiceBillApi($national_id, $payment_amount): int|string
|
||||||
|
{
|
||||||
|
if (App::isProduction())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$payload = array(
|
||||||
|
'username' => config('harim_web_services.Harim_Payment.username'),
|
||||||
|
'password' => config('harim_web_services.Harim_Payment.PASSWORD'),
|
||||||
|
'amount' => $payment_amount,
|
||||||
|
'serial' => "12345",
|
||||||
|
'type' => 1,
|
||||||
|
'instanceid' => 123,
|
||||||
|
'ownerid' => $national_id,
|
||||||
|
'calculationBox' => "{\"rows\":[{\"amount\":" . $payment_amount . ",\"code\":\"7070011026200593\"}]}"
|
||||||
|
);
|
||||||
|
|
||||||
|
$response = Http::retry(3, 100)->withBody(http_build_query($payload))
|
||||||
|
->post(config('harim_web_services.Harim_Payment.url'));
|
||||||
|
|
||||||
|
return $response->body();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (\Throwable $th) {
|
||||||
|
throw new ProhibitedAction('خطا در ارتباط با سرویس پرداخت');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function callPaymentStatusBillApi($bill_code)
|
||||||
|
{
|
||||||
|
if (App::isProduction())
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$username = config('harim_web_services.Harim_Payment.username');
|
||||||
|
$password = config('harim_web_services.Harim_Payment.PASSWORD');
|
||||||
|
$url = config('harim_web_services.Harim_Payment.url');
|
||||||
|
|
||||||
|
$result = "{$url}/{$username}/{$password}/{$bill_code}";
|
||||||
|
|
||||||
|
$response = Http::timeout(10)->get($result);
|
||||||
|
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
} catch (\Throwable $th) {
|
||||||
|
abort(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return json_encode(['isPayed' => 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,5 +38,9 @@ return [
|
|||||||
|
|
||||||
'Harim_Payment' => [
|
'Harim_Payment' => [
|
||||||
'fee' => env('HARIM_AMOUNT_FEE'),
|
'fee' => env('HARIM_AMOUNT_FEE'),
|
||||||
|
'username' => env('HARIM_ENCRYPTION_USERNAME'),
|
||||||
|
'password' => env('HARIM_ENCRYPTION_PASSWORD'),
|
||||||
|
'url' => env('HARIM_ENCRYPTION_URL'),
|
||||||
|
'LINK' => env('HARIM_ENCRYPTION_LINK'),
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -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('cmms_machines', function (Blueprint $table) {
|
||||||
|
$table->string('driver_name')->nullable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('cmms_machines', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('driver_name');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
<a href="{{ route('v2.road_observations.pending_view') }}" class="btn btn-default btn-block my-2">رسیدگی به شکایات واکنش سریع</a>
|
<a href="{{ route('v2.road_observations.pending_view') }}" class="btn btn-default btn-block my-2">رسیدگی به شکایات واکنش سریع</a>
|
||||||
@endcan
|
@endcan
|
||||||
@can('add-safety-and-privacy')
|
@can('add-safety-and-privacy')
|
||||||
<a href="{{ route('v2.safety_and_privacy.operator.create') }}" class="btn btn-default btn-block my-2">ثبت نگهداری حریم راه</a>
|
<a href="/v3/dashboard/road-safety/operator" class="btn btn-default btn-block my-2">ثبت نگهداری حریم راه</a>
|
||||||
@endcan
|
@endcan
|
||||||
</div>
|
</div>
|
||||||
@endsection
|
@endsection
|
||||||
|
|||||||
Reference in New Issue
Block a user