You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
295 lines
7.8 KiB
PHP
295 lines
7.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Contracts\Support\Renderable;
|
|
use Illuminate\Http\Request;
|
|
use Carbon\Carbon;
|
|
use App\Models\User;
|
|
|
|
class UserController extends Controller
|
|
{
|
|
protected $breadcrumbs = [
|
|
[
|
|
'title' => '회원',
|
|
'link' => '/cms/user'
|
|
]
|
|
];
|
|
|
|
protected $page = [
|
|
'code' => 'cms.user',
|
|
'title' => '회원',
|
|
'icon' => 'fa-users',
|
|
'description' => '',
|
|
'link' => '/cms/user'
|
|
];
|
|
|
|
/**
|
|
* 회원 목록
|
|
*
|
|
* @Verb : GET
|
|
* @Path : /admin/missing
|
|
* @return Renderable
|
|
*/
|
|
public function index()
|
|
{
|
|
}
|
|
|
|
/**
|
|
* 회원 등록/수정
|
|
*
|
|
* @Verb : GET
|
|
* @Path : /cms/user/create
|
|
* @Path : /cms/user/modify/{uid}
|
|
* @param null $uid
|
|
* @return Renderable
|
|
*/
|
|
public function create($uid = null)
|
|
{
|
|
$data = null;
|
|
|
|
// 등록양식
|
|
$this->addModal(MissingUpdateModal::class);
|
|
|
|
if ($uid) {
|
|
$data = Missing::query()
|
|
->withTrashed()
|
|
->with(['profile', 'assets', 'modified', 'user' => function($query) {
|
|
$query->withTrashed();
|
|
}])
|
|
->withCount('reports', 'modified')
|
|
->where('uid', $uid)
|
|
->first();
|
|
//logger(json_decode(json_encode($data->user), true));
|
|
}
|
|
|
|
if (!$data) {
|
|
$fields = [
|
|
'uid' => '',
|
|
'inflow' => 'admin',
|
|
'type' => 1,
|
|
'name' => '',
|
|
'gender' => 'M',
|
|
'birthday' => '',
|
|
'missing_at' => '',
|
|
'address' => '',
|
|
'latitude' => '',
|
|
'longitude' => '',
|
|
'content' => '',
|
|
'register_name' => '',
|
|
'register_phone' => '',
|
|
'reports' => null,
|
|
'status' => 0,
|
|
'created_id' => '',
|
|
'created_at' => '',
|
|
'approved_at' => '',
|
|
'completed_at' => '',
|
|
'profile' => null,
|
|
'assets' => null,
|
|
'modified' => null,
|
|
'reports_count' => 0,
|
|
'modified_count' => 0,
|
|
'user' => null
|
|
];
|
|
$data = (object)$fields;
|
|
}
|
|
|
|
$config = config('missing');
|
|
|
|
return $this->setView('admin.missing.detail', compact('data', 'config'));
|
|
}
|
|
|
|
/**
|
|
* 회원 저장
|
|
*
|
|
* Verb : Post
|
|
* Path : /cms/user/store
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$validate = [
|
|
'type' => 'required|integer',
|
|
'name' => 'required|string|max:50',
|
|
'gender' => 'required|in:M,F',
|
|
'birthday' => 'required|string|size:10',
|
|
'missing_at' => 'required|string|size:10',
|
|
'address' => 'required|string',
|
|
'content' => 'required|string',
|
|
'register_name' => 'required|string|max:50',
|
|
'register_phone' => 'required|string|max:20'
|
|
];
|
|
|
|
$validator = $this->validatorApi($request, $validate);
|
|
if ($validator !== true) {
|
|
return $validator;
|
|
}
|
|
|
|
$config = config('missing');
|
|
|
|
$fields = $request->only([
|
|
'type', 'name', 'gender', 'birthday', 'missing_at',
|
|
'address', 'latitude', 'longitude', 'content',
|
|
'register_name', 'register_phone',
|
|
'status'
|
|
]);
|
|
|
|
if (!array_key_exists($fields['type'], $config['types'])) {
|
|
$fields['type'] = 1;
|
|
}
|
|
|
|
if (!array_key_exists($fields['status'], $config['status'])) {
|
|
$fields['status'] = 0;
|
|
}
|
|
|
|
$fields['birthday'] = str_replace('.', '-', trim($fields['birthday']));
|
|
$fields['missing_at'] = str_replace('.', '-', trim($fields['missing_at']));
|
|
|
|
$isNew = true;
|
|
|
|
$oldStatus = 0;
|
|
$newStatus = $fields['status'];
|
|
|
|
// 수정
|
|
if ($request->filled('uid')) {
|
|
$isNew = false;
|
|
|
|
$data = Missing::data($request->uid, false, 'user');
|
|
if ($data->error) {
|
|
return $this->sendResultMessage($data->error, false);
|
|
}
|
|
|
|
$oldStatus = $data->status;
|
|
|
|
$data->fill($fields);
|
|
$data->save();
|
|
|
|
// 등록
|
|
} else {
|
|
$fields['inflow'] = 'admin';
|
|
|
|
$data = Missing::add($fields);
|
|
}
|
|
|
|
if ($isNew && !$data->id) {
|
|
return $this->sendResultMessage('실종자 등록이 실패했습니다.', false);
|
|
}
|
|
|
|
if ($isNew) {
|
|
$message = '실종자 정보가 등록되었습니다.';
|
|
} else {
|
|
$message = '실종자 정보가 수정되었습니다.';
|
|
}
|
|
|
|
return $this->sendResult($message, $data);
|
|
}
|
|
|
|
/**
|
|
* 회원 비밀번호 변경
|
|
*
|
|
* Verb : POST
|
|
* Path : /cms/user/change/password
|
|
* @param Request $request
|
|
* @return \Illuminate\Http\JsonResponse
|
|
*/
|
|
public function passwordChange(Request $request)
|
|
{
|
|
$uid = $request->post('uid', '');
|
|
|
|
$data = MissingUpdate::data($uid, false, 'profile');
|
|
if ($data->error) {
|
|
return $this->sendResultMessage($data->error, false);
|
|
}
|
|
|
|
$missing_uid = $data->missing_uid;
|
|
$missing = Missing::data($missing_uid, false, ['profile','user']);
|
|
if ($missing->error) {
|
|
return $this->sendResultMessage($missing->error, false);
|
|
}
|
|
|
|
$now = (string)Carbon::now();
|
|
|
|
// 실종자 정보변경
|
|
$fields = $data->only([
|
|
'type', 'name', 'gender', 'birthday', 'missing_at',
|
|
'address', 'latitude', 'longitude', 'content',
|
|
'register_name', 'register_phone'
|
|
]);
|
|
|
|
$additions = [
|
|
'updated_id' => auth()->user()->id,
|
|
'updated_at' => $now
|
|
];
|
|
|
|
$missing->fill(array_merge($fields, $additions));
|
|
if (!$missing->save()) {
|
|
return $this->sendResultMessage('실종자 정보수정이 실패했습니다.', false);
|
|
}
|
|
|
|
// 수정요청 상태 변경
|
|
$data->fill(['status' => 1]);
|
|
$data->save();
|
|
|
|
return $this->sendResult('수정요청이 승인되었습니다.', $data);
|
|
}
|
|
|
|
/**
|
|
* 회원 탈퇴 처리
|
|
*
|
|
* Verb : POST
|
|
* Path : /cms/user/signout
|
|
* @param Request $request
|
|
* @return bool|\Illuminate\Http\JsonResponse
|
|
*/
|
|
public function signout(Request $request)
|
|
{
|
|
$data = Missing::data($request->uid);
|
|
if ($data->error) {
|
|
return $this->sendResultMessage($data->error, false);
|
|
}
|
|
|
|
// 사진파일 삭제
|
|
if ($data->assets) {
|
|
foreach ($data->assets as $asset) {
|
|
$fileService->deleteFile($asset->uid);
|
|
$asset->delete();
|
|
}
|
|
}
|
|
|
|
$data->delete();
|
|
|
|
return $this->sendResult('실종자 정보가 삭제되었습니다.', $data);
|
|
}
|
|
|
|
/**
|
|
* 회원 복구
|
|
*
|
|
* Verb : POST
|
|
* Path : /cms/user/restore
|
|
* @param Request $request
|
|
* @return bool|\Illuminate\Http\JsonResponse
|
|
*/
|
|
public function restore(Request $request)
|
|
{
|
|
$data = Missing::data($request->uid);
|
|
if ($data->error) {
|
|
return $this->sendResultMessage($data->error, false);
|
|
}
|
|
|
|
// 사진파일 삭제
|
|
if ($data->assets) {
|
|
foreach ($data->assets as $asset) {
|
|
$fileService->deleteFile($asset->uid);
|
|
$asset->delete();
|
|
}
|
|
}
|
|
|
|
$data->delete();
|
|
|
|
return $this->sendResult('실종자 정보가 삭제되었습니다.', $data);
|
|
}
|
|
}
|