NotifyController.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Http\Controllers\Admin\User\Dormant;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\UserDormantNotify;
  6. use App\Models\DTO\SearchData;
  7. use Exception;
  8. class NotifyController extends Controller
  9. {
  10. private UserDormantNotify $userDormantNotifyModel;
  11. public function __construct(UserDormantNotify $userDormantNotify)
  12. {
  13. $this->userDormantNotifyModel = $userDormantNotify;
  14. }
  15. /**
  16. * 휴면계정 관리 - 알림 발송 내역
  17. * @method GET|POST
  18. * @see /admin/user/dormant/notify
  19. */
  20. public function index(Request $request)
  21. {
  22. $params = SearchData::fromRequest($request);
  23. $params->startDate = $request->get('start_date');
  24. $params->endDate = $request->get('end_date');
  25. $userDormantNotifyData = $this->userDormantNotifyModel->data($params);
  26. if($userDormantNotifyData->rows > 0) {
  27. $num = listNum($userDormantNotifyData->total, $params->page, $params->perPage);
  28. foreach($userDormantNotifyData->list as $i => $row) {
  29. $row->num = $num--;
  30. $row->lastLoginAt = dateBr($row->last_login_at, '-');
  31. $row->dormantAt = dateBr($row->dormant_at, '-');
  32. $row->createdAt = dateBr($row->created_at, '-');
  33. $userDormantNotifyData->list[$i] = $row;
  34. }
  35. }
  36. return view('admin.user.dormant.notify', [
  37. 'userDormantNotifyData' => $userDormantNotifyData,
  38. 'params' => $params
  39. ]);
  40. }
  41. /**
  42. * 휴면계정 관리 - 알림 발송 내역 삭제
  43. * @method POST
  44. * @see /admin/user/dormant/notify/destroy
  45. */
  46. public function destroy(Request $request)
  47. {
  48. try{
  49. $chk = $request->post('chk');
  50. if ($chk) {
  51. foreach ($chk as $notifyID) {
  52. $notify = $this->userDormantNotifyModel->findOrNew($notifyID);
  53. if(!$notify->exists) {
  54. throw new Exception($notifyID . '번 알림은 존재하지 않습니다.');
  55. }
  56. $notify->delete();
  57. }
  58. }
  59. $message = '알림 발송 내역이 삭제되었습니다.';
  60. return redirect()->route('admin.user.dormant.notify.index')->with('message', $message);
  61. }catch(Exception $e) {
  62. return back()->withErrors($e->getMessage())->withInput();
  63. }
  64. }
  65. }