Write webservice for harim and Cmms

This commit is contained in:
2025-12-14 17:16:42 +03:30
committed by amirghasempoor
parent 0a2df262e1
commit 175b0fb6c7
9 changed files with 201 additions and 1 deletions

View File

@@ -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;

View File

@@ -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 => "ثبت فیش",
};
}
}

View File

@@ -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);
}
}

View File

@@ -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 [
//
];
}
}

View 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]);
}
}