| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- <?php
- namespace App\Http\Controllers\Admin\User\Dormant;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use App\Models\User;
- use App\Models\UserDormant;
- use App\Models\UserDormantNotify;
- use App\Models\EmailLib;
- use App\Models\DTO\SearchData;
- class ListController extends Controller
- {
- private User $userModel;
- private UserDormant $userDormantModel;
- private UserDormantNotify $userDormantNotifyModel;
- private EmailLib $emailLib;
- public function __construct(
- User $user,
- UserDormant $userDormant,
- UserDormantNotify $userDormantNotify,
- EmailLib $emailLib
- ) {
- $this->userModel = $user;
- $this->userDormantModel = $userDormant;
- $this->userDormantNotifyModel = $userDormantNotify;
- $this->emailLib = $emailLib;
- }
- /**
- * 휴면계정 관리
- * @method GET|POST
- * @see /admin/user/dormant/list
- */
- public function index(Request $request)
- {
- $params = SearchData::fromRequest($request);
- $params->activated = $request->get('activated');
- $params->userGroupID = $request->get('user_group_id', []);
- $params->userGradeID = $request->get('user_grade_id', []);
- $params->isDormancy = $request->get('is_dormant', 0);
- if (!$params->isDormancy) { // 회원
- $sModel = $this->userModel;
- $userDormantData = $sModel->dormantUsers($params);
- }else{ // 휴면회원
- $sModel = $this->userDormantModel;
- $userDormantData = $sModel->data($params);
- }
- $sTable = $sModel->getTable();
- if ($userDormantData->total > 0) {
- $num = listNum($userDormantData->total, $params->page, $params->perPage);
- foreach ($userDormantData->list as $i => $row) {
- $row->num = $num--;
- $row->point = number_format($row->point);
- $row->lastLoginAt = dateBr($row->last_login_at, '-');
- $row->createdAt = dateBr($row->created_at, '-');
- $row->dormantAt = dateBr($row->dormant_at, '-');
- $userDormantData->list[$i] = $row;
- }
- }
- return view('admin.user.dormant.index', [
- 'sTable' => $sTable,
- 'userDormantData' => $userDormantData,
- 'params' => $params
- ]);
- }
- /**
- * 휴면예정 알림 발송
- * @method POST
- * @see /admin/user/dormant/list/notify
- */
- public function notify(Request $request)
- {
- $chk = $request->post('chk');
- if ($chk) {
- foreach ($chk as $userID) {
- // 휴면예정 알림 발송
- if(!$this->userDormantNotifyModel->register(
- $this->userModel->find($userID)
- )) {
- return back()->withErrors([
- 'message' => sprintf('%d번 회원은 알림 발송이 거부되었습니다.', $userID)
- ])->withInput();
- }
- }
- }
- $message = '선택한 회원에게 알림이 발송되었습니다.';
- return redirect()->route('admin.user.dormant.list.index')->with('message', $message);
- }
- /**
- * 휴면 처리
- * @method POST
- * @see /admin/user/dormant/list/dormancy
- */
- public function dormancy(Request $request)
- {
- $chk = $request->post('chk');
- if ($chk) {
- foreach ($chk as $userID) {
- // 휴면 처리
- if($this->userDormantModel->dormancy($userID)) {
- // 휴면 알림 메일 발송
- $this->emailLib->send(
- SEND_MAIL_FORM_TYPE_12,
- $this->userDormantModel->find($userID)
- );
- }else{
- return back()->withErrors([
- 'message' => sprintf('%d번 회원 휴면 처리가 거부되었습니다.', $userID)
- ])->withInput();
- }
- }
- }
- $message = '선택한 회원이 휴면 처리되었습니다.';
- return redirect()->route('admin.user.dormant.list.index')->with('message', $message);
- }
- /**
- * 휴면 해제
- * @method POST
- * @see /admin/user/dormant/list/recover
- */
- public function recover(Request $request)
- {
- $chk = $request->post('chk');
- if ($chk) {
- foreach ($chk as $userID) {
- if($this->userDormantModel->recover($userID)) {
- // 휴면 해제 메일 발송
- $this->emailLib->send(
- SEND_MAIL_FORM_TYPE_13,
- $this->userModel->find($userID)
- );
- }else{
- return back()->withErrors([
- 'message' => sprintf('%d번 회원 휴면 해제가 거부되었습니다.', $userID)
- ])->withInput();
- }
- }
- }
- $message = '선택한 회원이 휴면 해제되었습니다.';
- return redirect()->route('admin.user.dormant.list.index')->with('message', $message);
- }
- }
|