ListController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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\User;
  6. use App\Models\UserDormant;
  7. use App\Models\UserDormantNotify;
  8. use App\Models\EmailLib;
  9. use App\Models\DTO\SearchData;
  10. class ListController extends Controller
  11. {
  12. private User $userModel;
  13. private UserDormant $userDormantModel;
  14. private UserDormantNotify $userDormantNotifyModel;
  15. private EmailLib $emailLib;
  16. public function __construct(
  17. User $user,
  18. UserDormant $userDormant,
  19. UserDormantNotify $userDormantNotify,
  20. EmailLib $emailLib
  21. ) {
  22. $this->userModel = $user;
  23. $this->userDormantModel = $userDormant;
  24. $this->userDormantNotifyModel = $userDormantNotify;
  25. $this->emailLib = $emailLib;
  26. }
  27. /**
  28. * 휴면계정 관리
  29. * @method GET|POST
  30. * @see /admin/user/dormant/list
  31. */
  32. public function index(Request $request)
  33. {
  34. $params = SearchData::fromRequest($request);
  35. $params->activated = $request->get('activated');
  36. $params->userGroupID = $request->get('user_group_id', []);
  37. $params->userGradeID = $request->get('user_grade_id', []);
  38. $params->isDormancy = $request->get('is_dormant', 0);
  39. if (!$params->isDormancy) { // 회원
  40. $sModel = $this->userModel;
  41. $userDormantData = $sModel->dormantUsers($params);
  42. }else{ // 휴면회원
  43. $sModel = $this->userDormantModel;
  44. $userDormantData = $sModel->data($params);
  45. }
  46. $sTable = $sModel->getTable();
  47. if ($userDormantData->total > 0) {
  48. $num = listNum($userDormantData->total, $params->page, $params->perPage);
  49. foreach ($userDormantData->list as $i => $row) {
  50. $row->num = $num--;
  51. $row->point = number_format($row->point);
  52. $row->lastLoginAt = dateBr($row->last_login_at, '-');
  53. $row->createdAt = dateBr($row->created_at, '-');
  54. $row->dormantAt = dateBr($row->dormant_at, '-');
  55. $userDormantData->list[$i] = $row;
  56. }
  57. }
  58. return view('admin.user.dormant.index', [
  59. 'sTable' => $sTable,
  60. 'userDormantData' => $userDormantData,
  61. 'params' => $params
  62. ]);
  63. }
  64. /**
  65. * 휴면예정 알림 발송
  66. * @method POST
  67. * @see /admin/user/dormant/list/notify
  68. */
  69. public function notify(Request $request)
  70. {
  71. $chk = $request->post('chk');
  72. if ($chk) {
  73. foreach ($chk as $userID) {
  74. // 휴면예정 알림 발송
  75. if(!$this->userDormantNotifyModel->register(
  76. $this->userModel->find($userID)
  77. )) {
  78. return back()->withErrors([
  79. 'message' => sprintf('%d번 회원은 알림 발송이 거부되었습니다.', $userID)
  80. ])->withInput();
  81. }
  82. }
  83. }
  84. $message = '선택한 회원에게 알림이 발송되었습니다.';
  85. return redirect()->route('admin.user.dormant.list.index')->with('message', $message);
  86. }
  87. /**
  88. * 휴면 처리
  89. * @method POST
  90. * @see /admin/user/dormant/list/dormancy
  91. */
  92. public function dormancy(Request $request)
  93. {
  94. $chk = $request->post('chk');
  95. if ($chk) {
  96. foreach ($chk as $userID) {
  97. // 휴면 처리
  98. if($this->userDormantModel->dormancy($userID)) {
  99. // 휴면 알림 메일 발송
  100. $this->emailLib->send(
  101. SEND_MAIL_FORM_TYPE_12,
  102. $this->userDormantModel->find($userID)
  103. );
  104. }else{
  105. return back()->withErrors([
  106. 'message' => sprintf('%d번 회원 휴면 처리가 거부되었습니다.', $userID)
  107. ])->withInput();
  108. }
  109. }
  110. }
  111. $message = '선택한 회원이 휴면 처리되었습니다.';
  112. return redirect()->route('admin.user.dormant.list.index')->with('message', $message);
  113. }
  114. /**
  115. * 휴면 해제
  116. * @method POST
  117. * @see /admin/user/dormant/list/recover
  118. */
  119. public function recover(Request $request)
  120. {
  121. $chk = $request->post('chk');
  122. if ($chk) {
  123. foreach ($chk as $userID) {
  124. if($this->userDormantModel->recover($userID)) {
  125. // 휴면 해제 메일 발송
  126. $this->emailLib->send(
  127. SEND_MAIL_FORM_TYPE_13,
  128. $this->userModel->find($userID)
  129. );
  130. }else{
  131. return back()->withErrors([
  132. 'message' => sprintf('%d번 회원 휴면 해제가 거부되었습니다.', $userID)
  133. ])->withInput();
  134. }
  135. }
  136. }
  137. $message = '선택한 회원이 휴면 해제되었습니다.';
  138. return redirect()->route('admin.user.dormant.list.index')->with('message', $message);
  139. }
  140. }