You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

186 lines
7.2 KiB

5 years ago
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. require APPPATH . '/libraries/REST_Controller.php';
  4. class Members extends REST_Controller
  5. {
  6. /**************************************************************
  7. * 사용자 목록
  8. ***************************************************************/
  9. function index_get()
  10. {
  11. $page_rows = $this->get('take', TRUE);
  12. $start = $this->get('skip', TRUE);
  13. $sdate = $this->input->get('sdate', TRUE);
  14. $startdate = $this->input->get('startdate', TRUE);
  15. $enddate = $this->input->get('enddate', TRUE);
  16. if(! empty($sdate) && !empty($startdate)) $this->db->where('mem_'.$sdate.' >=', $startdate.' 00:00:00');
  17. if(! empty($sdate) && !empty($enddate)) $this->db->where('mem_'.$sdate.' <=', $enddate.' 23:59:59');
  18. if(empty($page_rows)) $this->db->limit($page_rows, $start);
  19. $order_by = 'mem_idx DESC';
  20. $this->db->order_by($order_by);
  21. $this->db->select("SQL_CALC_FOUND_ROWS *", FALSE);
  22. $this->db->from('member');
  23. $this->db->limit($page_rows, $start);
  24. $result = $this->db->get();
  25. $return['lists'] = $result->result_array();
  26. $return['totalCount'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  27. foreach($return['lists'] as $i=>&$row) {
  28. $row['nums'] = $return['totalCount'] - (int)$start - $i;
  29. $row['mem_regip'] = long2ip((int)$row['mem_regip']);
  30. $row['mem_logip'] = long2ip((int)$row['mem_logip']);
  31. }
  32. $this->response($return, 200);
  33. }
  34. /**************************************************************
  35. * 사용자 상태 변경
  36. ***************************************************************/
  37. function status_post()
  38. {
  39. if(! $this->member->is_super() )
  40. $this->response(array('status'=>FALSE, 'message'=>'권한이 없습니다.'), 400);
  41. $mem_idx = $this->post('mem_idx', TRUE);
  42. $current_status = $this->post('current_status', TRUE);
  43. $change_status = $this->post('change_status', TRUE);
  44. if(empty($mem_idx))
  45. $this->response(array('status'=>FALSE, 'message'=>'관리자로 설정할 회원이 존재하지 않습니다.'), 400);
  46. if(! $mem = $this->member->get_member($mem_idx,'mem_idx') )
  47. {
  48. $this->response(array('status'=>FALSE, 'message'=>'존재하지 않는 회원입니다.'), 400);
  49. }
  50. if( $mem['mem_status'] != $current_status )
  51. {
  52. $this->response(array('status'=>FALSE, 'message'=>'변경전 회원상태가 실제 DB상 회원상태와 일치하지 않습니다.'), 400);
  53. }
  54. if( ! in_array($change_status, array('Y','N','D','H')))
  55. {
  56. $this->response(array('status'=>FALSE, 'message'=>'변경하려는 회원상태가 올바르지 않습니다.'), 400);
  57. }
  58. $this->db->trans_start();
  59. if( $change_status == 'Y' ) {
  60. $this->db->set('mem_leavetime', '0000-00-00 00:00:00');
  61. $this->db->set('mem_bantime', '0000-00-00 00:00:00');
  62. $this->db->set('mem_htime', '0000-00-00 00:00:00');
  63. }
  64. else if ($change_status == 'B') {
  65. $this->db->set('mem_bantime', date('Y-m-d H:i:s'));
  66. }
  67. else if ($change_status == 'N') {
  68. $this->db->set('mem_leavetime', date('Y-m-d H:i:s'));
  69. }
  70. else if ($change_status == 'H') {
  71. $this->db->set('mem_htime', date('Y-m-d H:i:s'));
  72. }
  73. $this->db->set('mem_status', $change_status)->where('mem_idx', $mem_idx)->update('member');
  74. if ($this->db->trans_status() === FALSE)
  75. {
  76. $this->db->trans_rollback();
  77. $this->response(array('status'=>FALSE, 'message'=>'시스템 오류가 발생하였습니다.'), 500);
  78. }
  79. else
  80. {
  81. $this->db->trans_commit();
  82. $this->response(array('status'=>TRUE, 'message'=>'회원 상태변경이 완료되었습니다.'), 200);
  83. }
  84. }
  85. function logs_get()
  86. {
  87. $page_rows = $this->get('take', TRUE);
  88. $start = $this->get('skip', TRUE);
  89. $start_date = $this->input->get('startdate', TRUE, date('Y-m-d', strtotime("-1 month", time())));
  90. $end_date = $this->input->get('enddate', TRUE, date('Y-m-d'));
  91. $st = $this->input->get('st', TRUE);
  92. $sc = $this->input->get('sc', TRUE);
  93. if ( !empty($st) && !empty($sc) )
  94. {
  95. if( $sc == 'nickname' OR $sc == 'userid')
  96. {
  97. $sc = "member_log.mem_" . $sc;
  98. $this->db->like($sc, $st);
  99. }
  100. else if ( $sc == 'idx' )
  101. {
  102. $this->db->where('member_log.mem_idx', $st);
  103. }
  104. }
  105. if(! empty($start_date)) $this->db->where('mlg_regtime >=',$start_date . " 00:00:00");
  106. if(! empty($end_date)) $this->db->where('mlg_regtime <=',$end_date . " 23:59:59");
  107. if(! empty($page_rows)) $this->db->limit($page_rows, $start);
  108. $this->db->select("SQL_CALC_FOUND_ROWS *", FALSE);
  109. $this->db->from('member_log');
  110. $this->db->join('member','member.mem_idx=member_log.mem_idx','inner');
  111. $result = $this->db->get();
  112. $return['lists'] = $result->result_array();
  113. $return['totalCount'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  114. foreach($return['lists'] as $i=>&$row) {
  115. $row['nums'] = $return['totalCount'] - $i - $start;
  116. $row['mlg_is_mobile'] = $row['mlg_is_mobile'] == 'Y';
  117. $row['mlg_ip'] = long2ip((int)$row['mlg_ip']);
  118. }
  119. $this->response($return, 200);
  120. }
  121. /**************************************************************
  122. * 포인트 목록
  123. ***************************************************************/
  124. function points_get()
  125. {
  126. $start_date = $this->get('startdate', TRUE);
  127. $end_date = $this->get('enddate', TRUE);
  128. $target_type = $this->get('target_type', TRUE);
  129. $mem_idx = $this->get('mem_idx', TRUE);
  130. $page_rows = $this->get('take', TRUE);
  131. $start = $this->get('skip', TRUE);
  132. if( ! empty($target_type) ) $this->db->where('target_type', $target_type);
  133. if( ! empty($start_date)) $this->db->where('reg_datetime >= ', $start_date . ' 00:00:00');
  134. if( ! empty($end_date)) $this->db->where('reg_datetime <= ', $end_date . ' 23:59:59');
  135. if( ! empty($mem_idx)) $this->db->where('MP.mem_idx', $mem_idx);
  136. if( ! empty($page_rows)) $this->db->limit($page_rows, $start);
  137. $this->db->order_by('mpo_idx DESC');
  138. $this->db->select("SQL_CALC_FOUND_ROWS MP.*, M.*", FALSE);
  139. $this->db->from('member_point AS MP');
  140. $this->db->join('member AS M','M.mem_idx=MP.mem_idx','inner');
  141. $result = $this->db->get();
  142. $return['lists'] = $result->result_array();
  143. $return['totalCount'] = (int)$this->db->query("SELECT FOUND_ROWS() AS cnt")->row(0)->cnt;
  144. foreach($return['lists'] as $i=>&$row)
  145. {
  146. $row['nums'] = $return['totalCount'] - $i - $start;
  147. $row['target_type'] = point_type($row['target_type']);
  148. }
  149. $this->response($return, 200);
  150. }
  151. }