|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Front;
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Libs\TraitSetting;
|
|
|
|
use App\Libs\TraitBoard;
|
|
|
|
|
|
|
|
use App\Services\SmsService;
|
|
|
|
use App\Services\CrossFileService;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Contracts\View\View;
|
|
|
|
use Illuminate\Support\Facades\Cookie;
|
|
|
|
|
|
|
|
class BoardController extends Controller
|
|
|
|
{
|
|
|
|
use TraitSetting;
|
|
|
|
use TraitBoard;
|
|
|
|
|
|
|
|
protected $page = [
|
|
|
|
'code' => 'board',
|
|
|
|
'title' => '게시판',
|
|
|
|
'subTitle' => '',
|
|
|
|
'description' => '',
|
|
|
|
'link' => '/board/notice'
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 게시글 목록
|
|
|
|
*
|
|
|
|
* @Verb : GET
|
|
|
|
* @Path : /board/{code}
|
|
|
|
* @param Request $request
|
|
|
|
* @param string $code
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function index(Request $request, string $code = '')
|
|
|
|
{
|
|
|
|
if ($code == 'inquiry') {
|
|
|
|
return redirect(route('board.create', [$code]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($code == 'news') {
|
|
|
|
$perPage = 0;
|
|
|
|
} else {
|
|
|
|
$perPage = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = $this->getPostList($request, $code, $perPage);
|
|
|
|
|
|
|
|
$this->page['code'] .= '.' . $code;
|
|
|
|
$this->page['subTitle'] = $data['board']->name;
|
|
|
|
|
|
|
|
$skin = $data['board']->skin ?? 'default';
|
|
|
|
|
|
|
|
$view = 'board.'. $skin .'.index';
|
|
|
|
|
|
|
|
return $this->setView($view, $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 게시글 상세
|
|
|
|
*
|
|
|
|
* @Verb : GET
|
|
|
|
* @Path : /board/{code}/{uid}
|
|
|
|
* @param Request $request
|
|
|
|
* @param string $code
|
|
|
|
* @param string $uid
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function view(Request $request, string $code = '', string $uid = '')
|
|
|
|
{
|
|
|
|
$data = $this->showPost($request, $code, $uid);
|
|
|
|
|
|
|
|
// 조회수 추가
|
|
|
|
$cookie = unserialize($request->cookie('readIds'));
|
|
|
|
if (empty($cookie)) {
|
|
|
|
$cookie = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!in_array($uid, $cookie)) {
|
|
|
|
$cookie[] = $uid;
|
|
|
|
|
|
|
|
$data->increment('view_count');
|
|
|
|
Cookie::queue('readIds', serialize($cookie));
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->page['code'] .= '.' . $code;
|
|
|
|
$this->page['subTitle'] = $data->board->name;
|
|
|
|
|
|
|
|
$skin = $data->board->skin ?? 'default';
|
|
|
|
|
|
|
|
$view = 'board.'. $skin .'.view';
|
|
|
|
|
|
|
|
return $this->setView($view, compact('data'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 문의하기 등록
|
|
|
|
*
|
|
|
|
* @Verb : GET
|
|
|
|
* @Path : /board/{code}/create
|
|
|
|
* @param Request $request
|
|
|
|
* @param string $code
|
|
|
|
* @param string $uid
|
|
|
|
* @return View
|
|
|
|
*/
|
|
|
|
public function create(Request $request, string $code = '', string $uid = '')
|
|
|
|
{
|
|
|
|
$data = $this->createPost($request, $code, $uid);
|
|
|
|
|
|
|
|
$this->page['code'] .= '.' . $code;
|
|
|
|
$this->page['subTitle'] = $data->board->name;
|
|
|
|
|
|
|
|
$skin = $data->board->skin ?? 'default';
|
|
|
|
|
|
|
|
$view = 'board.'. $skin .'.create';
|
|
|
|
|
|
|
|
return $this->setView($view, compact('data'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 문의하기 저장
|
|
|
|
*
|
|
|
|
* @Verb : POST
|
|
|
|
* @Path : /board/store
|
|
|
|
* @param Request $request
|
|
|
|
* @param CrossFileService $fileService
|
|
|
|
* @param SmsService $smsService
|
|
|
|
* @return JsonResponse
|
|
|
|
*/
|
|
|
|
public function store(Request $request, CrossFileService $fileService, SmsService $smsService)
|
|
|
|
{
|
|
|
|
$result = $this->storePost($request, $fileService);
|
|
|
|
|
|
|
|
// 문의등록시 SMS 문자 보내기
|
|
|
|
if ($request->get('code') == 'inquiry' && !empty($request->get('name')) && $result['code'] == 'success') {
|
|
|
|
$settings = $this->getArraySettings();
|
|
|
|
|
|
|
|
$message = '['. $settings['site_name'] .'] '. $request->name .'님의 문의가 접수되었습니다.';
|
|
|
|
|
|
|
|
$phone = '1599-3574';
|
|
|
|
if (isset($settings['sms_phone']) && !empty($settings['sms_phone'])) {
|
|
|
|
$phone = $settings['sms_phone'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$smsResult = $smsService->sendPhone($phone, $message);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->sendJson($result['message'], $result['code']);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|