From 1d763a3221aa666009520b2c96dcae80625b7adc Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sun, 14 Dec 2025 17:16:42 +0330 Subject: [PATCH] Write webservice for harim and Cmms --- .env.example | 5 ++ .../Commands/GetMachinesInfoListCommand.php | 1 + app/Enums/HarimStates.php | 7 ++ .../V3/Dashboard/Harim/DetailController.php | 60 +++++++++++++++++ .../Detail/HarimSubmitInvoiceRequest.php | 30 +++++++++ .../Cartables/Harim/HarimPaymentService.php | 65 +++++++++++++++++++ config/harim_web_services.php | 4 ++ ...add_driver_name_to_cmms_machines_table.php | 28 ++++++++ resources/views/version2/dashboard.blade.php | 2 +- 9 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php create mode 100644 app/Services/Cartables/Harim/HarimPaymentService.php create mode 100644 database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php diff --git a/.env.example b/.env.example index 4e0ec85b..8daaa305 100644 --- a/.env.example +++ b/.env.example @@ -50,6 +50,11 @@ PAYMENT_USERNAME= PAYMENT_PASSWORD= PAYMENT_LINK= +HARIM_PAYMENT_USERNAME= +HARIM_PAYMENT_PASSWORD= +HARIM_PAYMENT_URL= +HARIM_PAYMENT_LINK= + RMS_VERSION=3.0 RMS_CTO_PHONE_NUMBER= diff --git a/app/Console/Commands/GetMachinesInfoListCommand.php b/app/Console/Commands/GetMachinesInfoListCommand.php index a11742cd..98ce995f 100644 --- a/app/Console/Commands/GetMachinesInfoListCommand.php +++ b/app/Console/Commands/GetMachinesInfoListCommand.php @@ -57,6 +57,7 @@ class GetMachinesInfoListCommand extends Command 'province_id' => $entry['UnitGroupCode'] ?? null, 'city_id' => $entry['UnitCode'] ?? null, 'station_id' => $entry['Layer3Code'] ?? null, + 'driver_name' => $entry['DriverName'] ?? null, ]); ++$updatedRows; diff --git a/app/Enums/HarimStates.php b/app/Enums/HarimStates.php index 426cb23a..580e2020 100644 --- a/app/Enums/HarimStates.php +++ b/app/Enums/HarimStates.php @@ -21,6 +21,10 @@ enum HarimStates: int case BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL = 15; case MOKHALEFAT_BA_DASTGAH = 16; case ETMAM_FARAYAND = 17; + case SODOR_FACTOR = 18; + case PARDAKHT_FACTOR = 19; + case SABT_FISH = 20; + public function label(): string { @@ -42,6 +46,9 @@ enum HarimStates: int self::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_MODIR_KOL => "تائید عرصه و اعیان ارسال شده توسط مدیر", self::MOKHALEFAT_BA_DASTGAH => "مخالفت با درخواست", self::ETMAM_FARAYAND => "اتمام فرایند", + self::SODOR_FACTOR => "صدور فاکتور", + self::PARDAKHT_FACTOR => "پرداخت فاکتور", + self::SABT_FISH => "ثبت فیش", }; } } \ No newline at end of file diff --git a/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php b/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php index 2b63341a..a3a6b019 100644 --- a/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php +++ b/app/Http/Controllers/V3/Dashboard/Harim/DetailController.php @@ -2,12 +2,18 @@ namespace App\Http\Controllers\V3\Dashboard\Harim; +use App\Facades\Sms\Sms; +use App\Enums\HarimStates; use App\Exceptions\ProhibitedAction; use App\Http\Controllers\Controller; +use App\Http\Requests\V3\Dashboard\Harim\Detail\HarimSubmitInvoiceRequest; use App\Http\Traits\ApiResponse; use App\Models\Harim; use App\Models\HarimState; +use App\Services\Cartables\Harim\HarimPaymentService; use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\DB; use Throwable; class DetailController extends Controller @@ -30,4 +36,58 @@ class DetailController extends Controller ->orderBy('id', 'desc') ->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); + } } diff --git a/app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php b/app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php new file mode 100644 index 00000000..4ae854f4 --- /dev/null +++ b/app/Http/Requests/V3/Dashboard/Harim/Detail/HarimSubmitInvoiceRequest.php @@ -0,0 +1,30 @@ +harim->state_id == HarimStates::SABT_FISH->value; + } + + /** + * Get the validation rules that apply to the request. + * + * @return array + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/app/Services/Cartables/Harim/HarimPaymentService.php b/app/Services/Cartables/Harim/HarimPaymentService.php new file mode 100644 index 00000000..9b9a4f69 --- /dev/null +++ b/app/Services/Cartables/Harim/HarimPaymentService.php @@ -0,0 +1,65 @@ + 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]); + } +} diff --git a/config/harim_web_services.php b/config/harim_web_services.php index dc3f4686..6628fe54 100644 --- a/config/harim_web_services.php +++ b/config/harim_web_services.php @@ -38,5 +38,9 @@ return [ 'Harim_Payment' => [ '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'), ] ]; diff --git a/database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php b/database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php new file mode 100644 index 00000000..80699afb --- /dev/null +++ b/database/migrations/2025_12_14_103256_add_driver_name_to_cmms_machines_table.php @@ -0,0 +1,28 @@ +string('driver_name')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('cmms_machines', function (Blueprint $table) { + $table->dropColumn('driver_name'); + }); + } +}; diff --git a/resources/views/version2/dashboard.blade.php b/resources/views/version2/dashboard.blade.php index 92a36e6c..bf8b5ac9 100644 --- a/resources/views/version2/dashboard.blade.php +++ b/resources/views/version2/dashboard.blade.php @@ -19,7 +19,7 @@ رسیدگی به شکایات واکنش سریع @endcan @can('add-safety-and-privacy') - ثبت نگهداری حریم راه + ثبت نگهداری حریم راه @endcan @endsection