96 lines
2.5 KiB
PHP
96 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Core\Service;
|
|
|
|
use App\Core\Repository\PropertyChain\PropertyChainRepository;
|
|
|
|
|
|
use App;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Exception;
|
|
use App\Exceptions\ApiErrorException;
|
|
|
|
class PropertyChainService
|
|
{
|
|
|
|
private $propertyChainRepository;
|
|
|
|
|
|
|
|
public function __construct(
|
|
PropertyChainRepository $propertyChainRepository
|
|
|
|
)
|
|
{
|
|
|
|
$this->propertyChainRepository = $propertyChainRepository;
|
|
|
|
}
|
|
|
|
public function select($param = [], $column = ['*'])
|
|
{
|
|
|
|
$response = ['status' => -1, 'message' => '', 'data' => null];
|
|
|
|
try {
|
|
|
|
$data = $this->propertyChainRepository->findByCriteria($param, $column);
|
|
$response = [
|
|
'status' => true,
|
|
'data' => $data,
|
|
];
|
|
|
|
} catch (ApiErrorException $e) {
|
|
$response['message'] = $e->getMessage();
|
|
} catch (Exception $e) {
|
|
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
|
Log::error($message);
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
return output($response);
|
|
}
|
|
|
|
public function getPropertyChains($params){
|
|
|
|
$response = ['status' => false, 'message' => '', 'data' => null, 'statusCode' => 500];
|
|
try {
|
|
|
|
$return = [];
|
|
$searchCriteria = [
|
|
'criteria' => [
|
|
['field' => 'status', 'condition' => '=', 'value' => 1]
|
|
],
|
|
'orderBy' => [
|
|
['field' => 'priority','value' => 'ASC']
|
|
]
|
|
];
|
|
|
|
$searchResult = $this->select($searchCriteria, ['id', 'name', 'loyalty' ]);
|
|
|
|
if($searchResult['status'] != 'success'){
|
|
throw new ApiErrorException($searchResult['message']);
|
|
}
|
|
|
|
$return = $searchResult['data'];
|
|
|
|
$response = ['statusCode' => 200, 'status' => true, 'message' => '', 'data' => ['property_chains' =>$return ] ];
|
|
} catch (ApiErrorException $e) {
|
|
$response['message'] = implode(', ', $e->getMessageArr());
|
|
$response['statusCode'] = 400;
|
|
} catch (Exception $e) {
|
|
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
|
Log::error($message);
|
|
$response['message'] = $e->getMessage();
|
|
$response['statusCode'] = 500;
|
|
}
|
|
|
|
return output($response);
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|