Merge branch 'develop' into feature/CheckPaymentHarim
This commit is contained in:
9
app/Enums/PanjarehVahedHistoryActions.php
Normal file
9
app/Enums/PanjarehVahedHistoryActions.php
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum PanjarehVahedHistoryActions : int
|
||||||
|
{
|
||||||
|
case RECEIVE = 0;
|
||||||
|
case SEND = 1;
|
||||||
|
}
|
||||||
@@ -11,7 +11,6 @@ use App\Http\Requests\V3\Dashboard\Harim\PanjareVahed\ReceiveNewRequest;
|
|||||||
use App\Http\Traits\ApiResponse;
|
use App\Http\Traits\ApiResponse;
|
||||||
use App\Models\City;
|
use App\Models\City;
|
||||||
use App\Models\Harim;
|
use App\Models\Harim;
|
||||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
|
||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
@@ -21,43 +20,18 @@ class PanjareVahedController extends Controller
|
|||||||
|
|
||||||
public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse
|
public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
$iv = config('harim_web_services.Harim_Info.iv');
|
|
||||||
$keyString = config('harim_web_services.Harim_Info.key');
|
|
||||||
|
|
||||||
$key = hash('sha256', $keyString, true);
|
|
||||||
|
|
||||||
$decrypted = openssl_decrypt($request->data, 'aes-256-cbc', $key, false, $iv);
|
|
||||||
|
|
||||||
$decodedString = json_decode($decrypted);
|
|
||||||
$decodedArray = json_decode($decodedString, true);
|
|
||||||
|
|
||||||
$wkt = 'POLYGON(('.implode(',', array_map(fn ($c) => "{$c[0]} {$c[1]}", $request->primary_area['coordinates'])).'))';
|
$wkt = 'POLYGON(('.implode(',', array_map(fn ($c) => "{$c[0]} {$c[1]}", $request->primary_area['coordinates'])).'))';
|
||||||
$result = DB::selectOne('SELECT ST_AsText(ST_PointOnSurface(ST_GeomFromText(?, 4326))) AS point', [$wkt]);
|
$result = DB::selectOne('SELECT ST_AsText(ST_PointOnSurface(ST_GeomFromText(?, 4326))) AS point', [$wkt]);
|
||||||
preg_match('/POINT\(([^ ]+) ([^ ]+)\)/', $result->point, $matches);
|
preg_match('/POINT\(([^ ]+) ([^ ]+)\)/', $result->point, $matches);
|
||||||
|
|
||||||
try {
|
$city = City::findCityWithLatLng(lat:$matches[2], lng: $matches[1]);
|
||||||
$city = City::query()
|
|
||||||
->whereRaw("ST_Contains(
|
|
||||||
geometry,
|
|
||||||
ST_GeomFromText('POINT($matches[1] $matches[2])', 4326))"
|
|
||||||
)
|
|
||||||
->firstOrFail(['id', 'name_fa', 'province_id']);
|
|
||||||
} catch (ModelNotFoundException $exception) {
|
|
||||||
$city = City::query()
|
|
||||||
->orderByRaw("ST_Distance(
|
|
||||||
geometry,
|
|
||||||
ST_GeomFromText('POINT($matches[1] $matches[2])', 4326)) ASC"
|
|
||||||
)
|
|
||||||
->first(['id', 'name_fa', 'province_id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
$harim = Harim::query()->firstOrCreate(
|
$state = HarimStates::BARESI_EDARE_SHAHRESTAN->value;
|
||||||
|
|
||||||
|
$harim = Harim::query()->firstOrCreate(['panjare_vahed_id' => $request->request_id],
|
||||||
[
|
[
|
||||||
'panjare_vahed_id' => $request->request_id,
|
'state_id' => $state,
|
||||||
],
|
'state_name' => HarimStates::name($state),
|
||||||
[
|
|
||||||
'state_id' => HarimStates::BARESI_EDARE_SHAHRESTAN->value,
|
|
||||||
'state_name' => HarimStates::BARESI_EDARE_SHAHRESTAN->label(),
|
|
||||||
'panjare_vahed_id' => $request->request_id,
|
'panjare_vahed_id' => $request->request_id,
|
||||||
'national_id' => $request->national_id,
|
'national_id' => $request->national_id,
|
||||||
'phone_number' => $request->phone_number,
|
'phone_number' => $request->phone_number,
|
||||||
@@ -74,9 +48,14 @@ class PanjareVahedController extends Controller
|
|||||||
'response_options' => json_encode($request->response_options),
|
'response_options' => json_encode($request->response_options),
|
||||||
'isic' => $request->isic,
|
'isic' => $request->isic,
|
||||||
'primary_area' => json_encode($request->primary_area),
|
'primary_area' => json_encode($request->primary_area),
|
||||||
'data' => $decodedString,
|
'data' => $request->data,
|
||||||
'token' => $decodedArray['token'],
|
]
|
||||||
]);
|
);
|
||||||
|
|
||||||
|
$harim->panjarehVahedHistories()->create([
|
||||||
|
'harim_id' => $harim->id,
|
||||||
|
'data' => $request->data,
|
||||||
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'id' => $harim->id,
|
'id' => $harim->id,
|
||||||
@@ -91,16 +70,19 @@ class PanjareVahedController extends Controller
|
|||||||
{
|
{
|
||||||
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
||||||
|
|
||||||
|
$harim->panjarehVahedHistories()->create([
|
||||||
|
'harim_id' => $harim->id,
|
||||||
|
'data' => $harim->data,
|
||||||
|
]);
|
||||||
|
|
||||||
$harim->update([
|
$harim->update([
|
||||||
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->value,
|
'state_id' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->value,
|
||||||
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->label(),
|
'state_name' => HarimStates::BARESI_RAHE_DASTRASI_APLODE_SHODE_TAVASOTE_DAFTAR_HARIM->label(),
|
||||||
'access_road' => json_encode($request->access_road),
|
'access_road' => json_encode($request->access_road),
|
||||||
'data' => $request->data['data'],
|
'data' => $request->data,
|
||||||
'token' => $request->data['token'],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'request_id' => $request->request_id,
|
|
||||||
'id' => $harim->id,
|
'id' => $harim->id,
|
||||||
'statusCode' => 200,
|
'statusCode' => 200,
|
||||||
'message' => 'successful',
|
'message' => 'successful',
|
||||||
@@ -113,15 +95,18 @@ class PanjareVahedController extends Controller
|
|||||||
|
|
||||||
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
||||||
|
|
||||||
|
$harim->panjarehVahedHistories()->create([
|
||||||
|
'harim_id' => $harim->id,
|
||||||
|
'data' => $harim->data,
|
||||||
|
]);
|
||||||
|
|
||||||
$harim->update([
|
$harim->update([
|
||||||
'state_id' => $state,
|
'state_id' => $state,
|
||||||
'state_name' => HarimStates::name($state),
|
'state_name' => HarimStates::name($state),
|
||||||
'data' => $request->data['data'],
|
'data' => $request->data,
|
||||||
'token' => $request->data['token'],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'request_id' => $request->request_id,
|
|
||||||
'id' => $harim->id,
|
'id' => $harim->id,
|
||||||
'statusCode' => 200,
|
'statusCode' => 200,
|
||||||
'message' => 'successful',
|
'message' => 'successful',
|
||||||
@@ -133,17 +118,20 @@ class PanjareVahedController extends Controller
|
|||||||
|
|
||||||
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
$harim = Harim::query()->firstWhere('panjare_vahed_id', '=', $request->request_id);
|
||||||
|
|
||||||
|
$harim->panjarehVahedHistories()->create([
|
||||||
|
'harim_id' => $harim->id,
|
||||||
|
'data' => $harim->data,
|
||||||
|
]);
|
||||||
|
|
||||||
$harim->update([
|
$harim->update([
|
||||||
'state_id' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->value,
|
'state_id' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->value,
|
||||||
'state_name' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->label(),
|
'state_name' => HarimStates::BARESI_ARSE_VA_AYAN_ERSAL_SHODE_TAVASOT_DAFTAR_HARIM->label(),
|
||||||
'final_area' => json_encode($request->final_area),
|
'final_area' => json_encode($request->final_area),
|
||||||
'final_plan' => json_encode($request->final_plan),
|
'final_plan' => json_encode($request->final_plan),
|
||||||
'data' => $request->data['data'],
|
'data' => $request->data,
|
||||||
'token' => $request->data['token'],
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'request_id' => $request->request_id,
|
|
||||||
'id' => $harim->id,
|
'id' => $harim->id,
|
||||||
'statusCode' => 200,
|
'statusCode' => 200,
|
||||||
'message' => 'successful',
|
'message' => 'successful',
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class GetAccessRoadRequest extends FormRequest
|
|||||||
'access_road' => 'required|array',
|
'access_road' => 'required|array',
|
||||||
'access_road.type' => 'required|string',
|
'access_road.type' => 'required|string',
|
||||||
'access_road.coordinates' => 'required|array',
|
'access_road.coordinates' => 'required|array',
|
||||||
'data' => 'required|array',
|
'data' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class GetFinalPolygonsRequest extends FormRequest
|
|||||||
'final_plan' => 'required|array',
|
'final_plan' => 'required|array',
|
||||||
'final_plan.type' => 'required|string',
|
'final_plan.type' => 'required|string',
|
||||||
'final_plan.coordinates' => 'required|array',
|
'final_plan.coordinates' => 'required|array',
|
||||||
'data' => 'required|array',
|
'data' => 'required|string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,8 @@ class GetRejectRequest extends FormRequest
|
|||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'request_id' => 'required|exists:harims,panjare_vahed_id',
|
'request_id' => 'required|exists:harims,panjare_vahed_id',
|
||||||
'data' => 'required|array',
|
'data' => 'required|string',
|
||||||
|
'status' => 'required|integer'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,23 +86,18 @@ class City extends Model
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$city = City::query()
|
$city = City::query()
|
||||||
->whereRaw("
|
->whereRaw("ST_Contains(
|
||||||
ST_Contains(
|
geometry,
|
||||||
geometry,
|
ST_GeomFromText('POINT($lng $lat)', 4326))"
|
||||||
ST_GeomFromText('POINT($lng $lat)', 4326)
|
)
|
||||||
)
|
->firstOrFail(['id', 'name_fa', 'province_id']);
|
||||||
")
|
} catch (ModelNotFoundException $exception) {
|
||||||
->firstOrFail();
|
|
||||||
}
|
|
||||||
catch (ModelNotFoundException $exception) {
|
|
||||||
$city = City::query()
|
$city = City::query()
|
||||||
->orderByRaw("
|
->orderByRaw("ST_Distance(
|
||||||
ST_Distance(
|
geometry,
|
||||||
geometry,
|
ST_GeomFromText('POINT($lng $lat)', 4326)) ASC"
|
||||||
ST_GeomFromText('POINT($lng $lat)', 4326)
|
)
|
||||||
) ASC
|
->first(['id', 'name_fa', 'province_id']);
|
||||||
")
|
|
||||||
->first();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $city;
|
return $city;
|
||||||
|
|||||||
@@ -44,5 +44,21 @@ class Harim extends Model
|
|||||||
|
|
||||||
$this->update($data);
|
$this->update($data);
|
||||||
});
|
});
|
||||||
|
public function panjarehVahedHistories(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(PanjarehVahedHistory::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function data(): Attribute
|
||||||
|
{
|
||||||
|
return Attribute::make(
|
||||||
|
set: function ($value) {
|
||||||
|
$iv = config('harim_web_services.Harim_Info.iv');
|
||||||
|
$keyString = config('harim_web_services.Harim_Info.keyString');
|
||||||
|
$key = hash('sha256',$keyString, true);
|
||||||
|
$decrypted = openssl_decrypt($value,'aes-256-cbc',$key,false, $iv);
|
||||||
|
return json_decode($decrypted);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
app/Models/PanjarehVahedHistory.php
Normal file
13
app/Models/PanjarehVahedHistory.php
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class PanjarehVahedHistory extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $guarded = [];
|
||||||
|
}
|
||||||
23
database/factories/PanjarehVahedHistoryFactory.php
Normal file
23
database/factories/PanjarehVahedHistoryFactory.php
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\PanjarehVahedHistory>
|
||||||
|
*/
|
||||||
|
class PanjarehVahedHistoryFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -13,7 +13,6 @@ return new class extends Migration
|
|||||||
{
|
{
|
||||||
Schema::table('harims', function (Blueprint $table) {
|
Schema::table('harims', function (Blueprint $table) {
|
||||||
$table->longText('data')->nullable();
|
$table->longText('data')->nullable();
|
||||||
$table->string('token', 255)->nullable();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ return new class extends Migration
|
|||||||
public function down(): void
|
public function down(): void
|
||||||
{
|
{
|
||||||
Schema::table('harims', function (Blueprint $table) {
|
Schema::table('harims', function (Blueprint $table) {
|
||||||
$table->dropColumn(['data', 'token']);
|
$table->dropColumn('data');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
<?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::create('panjareh_vahed_histories', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('harim_id')->constrained('harims');
|
||||||
|
$table->longText('data');
|
||||||
|
$table->tinyInteger('action')->default(0); // 0 => receive, 1 => send
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('panjareh_vahed_histories');
|
||||||
|
}
|
||||||
|
};
|
||||||
17
database/seeders/PanjarehVahedHistorySeeder.php
Normal file
17
database/seeders/PanjarehVahedHistorySeeder.php
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Seeders;
|
||||||
|
|
||||||
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
|
class PanjarehVahedHistorySeeder extends Seeder
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the database seeds.
|
||||||
|
*/
|
||||||
|
public function run(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user