ListController.php 5.2 KB

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