286 lines
7.9 KiB
PHP
Executable File
286 lines
7.9 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\API;
|
|
|
|
use App\Contracts\AdminResourceInterface;
|
|
use App\Contracts\CityAndProvinceResourceInterface;
|
|
use App\Contracts\StationResourceInterface;
|
|
use App\Helpers\CurrentUserHelper;
|
|
use App\Http\Requests\SystemPreferenceFormValidation;
|
|
use App\Http\Resources\SystemPreferencesResource;
|
|
use App\Libraries\StratuscastLibrary;
|
|
use App\Libraries\RNRPHLibrary;
|
|
use App\Services\CityAndProvinceService;
|
|
use App\Services\StationService;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Helpers\HttpStatusCode;
|
|
use App\Contracts\SystemPreferenceResourceInterface;
|
|
|
|
use Illuminate\Routing\UrlGenerator;
|
|
|
|
class CityAndProvinceController extends Controller
|
|
{
|
|
|
|
public $cityAndProvince;
|
|
public $station;
|
|
|
|
protected $format;
|
|
|
|
protected $module;
|
|
|
|
protected $model;
|
|
|
|
public $admin;
|
|
|
|
|
|
public function __construct(CityAndProvinceResourceInterface $cityAndProvince,HttpStatusCode $httpStatusCode, UrlGenerator $url, AdminResourceInterface $admin, StationResourceInterface $station)
|
|
{
|
|
|
|
$this->cityAndProvince = $cityAndProvince;
|
|
$this->station = $station;
|
|
$this->format = $httpStatusCode;
|
|
$this->module = "CitAndProvince";
|
|
$this->model = "CitAndProvince";
|
|
$this->url = $url;
|
|
$this->admin = $admin;
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
//
|
|
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(SystemPreferenceFormValidation $request)
|
|
{
|
|
|
|
|
|
}
|
|
/**
|
|
* Display the specified resource.
|
|
*d
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show($id)
|
|
{
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Request $request, $id)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
//
|
|
}
|
|
|
|
public function sync()
|
|
{
|
|
|
|
$cyware = new StratuscastLibrary();
|
|
$cyware->getCityAndProvince();
|
|
if ($cyware->response['status_code'] == "200") {
|
|
foreach ($cyware->response['data'] as $key => $value) {
|
|
$province = $this->cityAndProvince->getProvinceByField("code", $value->province_code);
|
|
$province_id = 0;
|
|
|
|
$data['code'] = $value->province_code;
|
|
$data['name'] = $value->province_name;
|
|
|
|
if (isset($value->province_code)){
|
|
if (count($province) == 0) {
|
|
$province_id = $this->cityAndProvince->storeProvince($data);
|
|
} else {
|
|
$province_id = $province[0]->province_id;
|
|
$data['province_id'] = $province_id;
|
|
$this->cityAndProvince->updateProvince($data);
|
|
}
|
|
}
|
|
|
|
$city = $this->cityAndProvince->getCityByField("code", $value->city_code);
|
|
$data['code'] = $value->city_code;
|
|
$data['name'] = $value->city_name;
|
|
|
|
if (isset($value->city_code)){
|
|
if (count($city) == 0) {
|
|
$data['province_id'] = $province_id;
|
|
$this->cityAndProvince->storeCity($data);
|
|
} else {
|
|
$data['province_id'] = $province_id;
|
|
$data['city_id'] = $city[0]->city_id;
|
|
$this->cityAndProvince->updateCity($data);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
return $this->format->success("Success", []);
|
|
|
|
}else{
|
|
return $this->format->success("Something went wrong",[]);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function get_all()
|
|
{
|
|
$province_city = $this->cityAndProvince->getAllRelationship();
|
|
|
|
|
|
$return = [];
|
|
$previous_province = '';
|
|
$ctr = 0;
|
|
$current_array = [];
|
|
|
|
foreach ($province_city as $key => $province)
|
|
{
|
|
if($previous_province != $province->name)
|
|
{
|
|
if($ctr != 0)
|
|
$return[] = $current_array;
|
|
|
|
$current_array = [];
|
|
|
|
$current_array['name'] = $province->name;
|
|
$current_array['city'][] = [
|
|
'name' => $province->city_name,
|
|
'city_uuid' => $province->city_uuid,
|
|
];
|
|
}
|
|
else
|
|
{
|
|
$current_array['city'][] = [
|
|
'name' => $province->city_name,
|
|
'city_uuid' => $province->city_uuid,
|
|
];
|
|
}
|
|
$previous_province = $province->name;
|
|
$ctr++;
|
|
}
|
|
|
|
return $this->format->mobile_success('Success',$return);
|
|
}
|
|
|
|
|
|
|
|
//RNRPH
|
|
public function syncCityProvince()
|
|
{
|
|
|
|
$rnrph = new RNRPHLibrary();
|
|
$rnrph->getAllBranches();
|
|
if (count($rnrph->response['data']) > 0) {
|
|
$ids = [];
|
|
$st = $this->cityAndProvince->getAllCities();
|
|
foreach ($st as $key => $value) {
|
|
array_push($ids,$value->city_id);
|
|
}
|
|
$this->cityAndProvince->disbale_cities($ids);
|
|
foreach ($rnrph->response['data'] as $key => $value) {
|
|
// $province = $this->cityAndProvince->getProvinceByField("code", $value->province_code);
|
|
// $province_id = 0;
|
|
|
|
// $data['code'] = $value->province_code;
|
|
// $data['name'] = $value->province_name;
|
|
|
|
// if (isset($value->province_code)){
|
|
// if (count($province) == 0) {
|
|
// $province_id = $this->cityAndProvince->storeProvince($data);
|
|
// } else {
|
|
// $province_id = $province[0]->province_id;
|
|
// $data['province_id'] = $province_id;
|
|
// $this->cityAndProvince->updateProvince($data);
|
|
// }
|
|
// }
|
|
|
|
$city = $this->cityAndProvince->getCityByField("code", $value->city_code);
|
|
$data['code'] = $value->city_code;
|
|
$data['name'] = $value->city_name;
|
|
|
|
if (isset($value->city_code)){
|
|
if (count($city) == 0) {
|
|
$this->cityAndProvince->storeCity($data);
|
|
} else {
|
|
$data['city_id'] = $city[0]->city_id;
|
|
$this->cityAndProvince->updateCity($data);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
return $this->format->success("Success", $rnrph->response['data']);
|
|
|
|
}else{
|
|
return $this->format->success("Something went wrong",[]);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public function get_city_list()
|
|
{
|
|
$city = $this->cityAndProvince->getAllCities();
|
|
$return = [];
|
|
foreach ($city as $key => $value) {
|
|
$station = $this->station->get_station_by_city_uuid($value->city_id);
|
|
if(count($station) > 0){
|
|
$return[] = $value;
|
|
}
|
|
}
|
|
return $this->format->mobile_success('Success',$return);
|
|
|
|
}
|
|
|
|
}
|