135 lines
3.7 KiB
PHP
135 lines
3.7 KiB
PHP
<?php
|
|
|
|
namespace App\Core\Service;
|
|
|
|
use App\Core\Repository\ChannelManager\ChannelManagerRepository;
|
|
|
|
|
|
use App;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Exception;
|
|
use App\Exceptions\ApiErrorException;
|
|
|
|
class ChannelManagerService
|
|
{
|
|
|
|
private $channelManagerRepository;
|
|
|
|
|
|
public function __construct(
|
|
ChannelManagerRepository $channelManagerRepository
|
|
)
|
|
{
|
|
$this->channelManagerRepository = $channelManagerRepository;
|
|
}
|
|
|
|
public function select($param = [], $column = ['*'])
|
|
{
|
|
|
|
$response = ['status' => -1, 'message' => '', 'data' => null];
|
|
|
|
try {
|
|
|
|
$data = $this->channelManagerRepository->findByCriteria($param, $column);
|
|
|
|
$response = [
|
|
'status' => true,
|
|
'data' => $data,
|
|
];
|
|
|
|
}catch (Exception $e) {
|
|
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
|
Log::error($message);
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
return output($response);
|
|
}
|
|
|
|
public function create($params = [])
|
|
{
|
|
$response = ['status' => -1, 'message' => '', 'data' => null];
|
|
try {
|
|
|
|
$createResult = $this->channelManagerRepository->create($params);
|
|
|
|
if ($createResult['status'] != 'success') {
|
|
throw new ApiErrorException('api-unknown_error');
|
|
}
|
|
$createData = $createResult["data"];
|
|
$response = [
|
|
'status' => true,
|
|
'data' => $createData,
|
|
];
|
|
|
|
} catch (ApiErrorException $e) {
|
|
$response['message'] = implode(', ', $e->getMessageArr());
|
|
} catch (Exception $e) {
|
|
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
|
Log::error($message);
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
return output($response);
|
|
}
|
|
|
|
public function update($id, $param = [])
|
|
{
|
|
|
|
$response = ['status' => -1, 'message' => '', 'data' => null];
|
|
try {
|
|
|
|
|
|
$updateResult = $this->channelManagerRepository->update($id, $param);
|
|
if ($updateResult['status'] != 'success') {
|
|
throw new ApiErrorException('api-unknown_error');
|
|
}
|
|
$updateData = $updateResult["data"];
|
|
$response = [
|
|
'status' => true,
|
|
'data' => $updateData,
|
|
];
|
|
|
|
} catch (ApiErrorException $e) {
|
|
$response['message'] = implode(', ', $e->getMessageArr());
|
|
} catch (Exception $e) {
|
|
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
|
Log::error($message);
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
return output($response);
|
|
}
|
|
|
|
public function delete($ids = []){
|
|
|
|
$response = ['status' => -1, 'message' => '', 'data' => null];
|
|
try {
|
|
|
|
|
|
$deleteResult = $this->channelManagerRepository->destroy($ids);
|
|
|
|
if ($deleteResult['status'] != 'success') {
|
|
throw new ApiErrorException('api-unknown_error');
|
|
}
|
|
|
|
$response = [
|
|
'status' => true,
|
|
'data' => $deleteResult['data'] // affected row count
|
|
];
|
|
|
|
} catch (ApiErrorException $e) {
|
|
$response['message'] = implode(', ', $e->getMessageArr());
|
|
} catch (Exception $e) {
|
|
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
|
Log::error($message);
|
|
$response['message'] = $e->getMessage();
|
|
}
|
|
|
|
return output($response);
|
|
|
|
}
|
|
|
|
|
|
}
|