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.

185 lines
7.1 KiB

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