diff --git a/adm/config_form.php b/adm/config_form.php index fc061c043..a1f041388 100644 --- a/adm/config_form.php +++ b/adm/config_form.php @@ -101,17 +101,6 @@ if(!sql_query(" DESC {$g4['autosave_table']} ", false)) { ) ", false); } -// 포인트유효기간 필드추가 -if(!sql_query(" select cf_point_term from {$g4['config_table']} ", false)) { - sql_query(" ALTER TABLE `{$g4['config_table']}` - ADD `cf_point_term` int(11) NOT NULL DEFAULT '0' AFTER `cf_use_point` ", false); - sql_query(" ALTER TABLE `{$g4['point_table']}` - ADD `po_use_point` int(11) NOT NULL DEFAULT '0' AFTER `po_point`, - ADD `po_expired` tinyint(4) NOT NULL DEFAULT '0' AFTER `po_use_point`, - ADD `po_expire_date` date NOT NULL DEFAULT '0000-00-00' AFTER `po_expired` - ADD `po_mb_point` int(11) NOT NULL DEFAULT '0' AFTER `po_expire_date` ", false); -} - $g4['title'] = '환경설정'; include_once ('./admin.head.php'); diff --git a/adm/point_list_delete.php b/adm/point_list_delete.php index e09bafd48..32cc13681 100644 --- a/adm/point_list_delete.php +++ b/adm/point_list_delete.php @@ -1,5 +1,5 @@ 0) { + insert_use_point($row['mb_id'], $row['po_use_point'], $row['po_id']); + } + } + + // 포인트 내역삭제 $sql = " delete from {$g4['point_table']} where po_id = '{$_POST['po_id'][$k]}' "; sql_query($sql); - $sql = " select sum(po_point) as sum_po_point from {$g4['point_table']} where mb_id = '{$_POST['mb_id'][$k]}' "; - $row = sql_fetch($sql); - $sum_point = $row['sum_po_point']; + // po_mb_point에 반영 + $sql = " update {$g4['point_table']} + set po_mb_point = po_mb_point - '{$row['po_point']}' + where mb_id = '$mb_id' + and po_id > '{$row['po_id']}' "; + sql_query($sql); - $sql= " update {$g4['member_table']} set mb_point = '{$sum_point}' where mb_id = '{$_POST['mb_id'][$k]}' "; + $sum_point = get_point_sum($_POST['mb_id'][$k]); + $sql= " update {$g4['member_table']} set mb_point = '$sum_point' where mb_id = '{$_POST['mb_id'][$k]}' "; sql_query($sql); } goto_url('./point_list.php?'.$qstr); -?> +?> \ No newline at end of file diff --git a/bbs/delete.php b/bbs/delete.php index 973813b5f..e3b03a3f9 100644 --- a/bbs/delete.php +++ b/bbs/delete.php @@ -73,7 +73,8 @@ while ($row = sql_fetch_array($result)) if (!$row['wr_is_comment']) { // 원글 포인트 삭제 - insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} {$row['wr_id']} 글삭제"); + if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '쓰기')) + insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} {$row['wr_id']} 글삭제"); // 업로드된 파일이 있다면 파일삭제 $sql2 = " select * from {$g4['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' "; @@ -100,7 +101,8 @@ while ($row = sql_fetch_array($result)) else { // 코멘트 포인트 삭제 - insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 코멘트삭제"); + if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '댓글')) + insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 댓글삭제"); $count_comment++; } diff --git a/bbs/delete_all.php b/bbs/delete_all.php index 1c6bfbbf0..4e91bf319 100644 --- a/bbs/delete_all.php +++ b/bbs/delete_all.php @@ -84,7 +84,8 @@ for ($i=count($tmp_array)-1; $i>=0; $i--) if (!$row['wr_is_comment']) { // 원글 포인트 삭제 - insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} {$row['wr_id']} 글 삭제"); + if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '쓰기')) + insert_point($row['mb_id'], $board['bo_write_point'] * (-1), "{$board['bo_subject']} {$row['wr_id']} 글 삭제"); // 업로드된 파일이 있다면 $sql2 = " select * from {$g4['board_file_table']} where bo_table = '$bo_table' and wr_id = '{$row['wr_id']}' "; @@ -113,7 +114,8 @@ for ($i=count($tmp_array)-1; $i>=0; $i--) else { // 코멘트 포인트 삭제 - insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 코멘트삭제"); + if (!delete_point($row['mb_id'], $bo_table, $row['wr_id'], '댓글')) + insert_point($row['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_id']}-{$row['wr_id']} 댓글삭제"); $count_comment++; } diff --git a/bbs/delete_comment.php b/bbs/delete_comment.php index ca4c99421..7a0a7f855 100644 --- a/bbs/delete_comment.php +++ b/bbs/delete_comment.php @@ -58,8 +58,9 @@ $row = sql_fetch($sql); if ($row['cnt'] && !$is_admin) alert('이 코멘트와 관련된 답변코멘트가 존재하므로 삭제 할 수 없습니다.'); -// 코멘트 삭제 -insert_point($write['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_parent']}-{$comment_id} 코멘트삭제"); +// 코멘트 포인트 삭제 +if (!delete_point($write['mb_id'], $bo_table, $comment_id, '댓글')) + insert_point($write['mb_id'], $board['bo_comment_point'] * (-1), "{$board['bo_subject']} {$write['wr_parent']}-{$comment_id} 댓글삭제"); // 코멘트 삭제 sql_query(" delete from {$write_table} where wr_id = '{$comment_id}' "); diff --git a/bbs/point.php b/bbs/point.php index eafce2aaf..ebfdc9c56 100644 --- a/bbs/point.php +++ b/bbs/point.php @@ -55,13 +55,6 @@ $from_record = ($page - 1) * $rows; // 시작 열을 구함 } $po_content = $row['po_content']; - - // 소멸포인트 - if($row['po_point'] >= 0 && $row['po_expired'] == 1) { - $sum_point3 += $row['po_point']; - $po_content = ''.$po_content.''; - } - ?> @@ -87,12 +80,6 @@ $from_record = ($page - 1) * $rows; // 시작 열을 구함 - - - 소멸포인트 - - - 보유포인트 diff --git a/install/gnuboard4s.sql b/install/gnuboard4s.sql index 48af2f8d5..d08ad879d 100644 --- a/install/gnuboard4s.sql +++ b/install/gnuboard4s.sql @@ -501,7 +501,8 @@ CREATE TABLE IF NOT EXISTS `g4s_point` ( `po_rel_id` varchar(20) NOT NULL default '', `po_rel_action` varchar(255) NOT NULL default '', PRIMARY KEY (`po_id`), - KEY `index1` (`mb_id`,`po_rel_table`,`po_rel_id`,`po_rel_action`) + KEY `index1` (`mb_id`,`po_rel_table`,`po_rel_id`,`po_rel_action`), + KEY `index2` (`po_expire_date`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- diff --git a/lib/common.lib.php b/lib/common.lib.php index 3af0f16ee..9f82afe3e 100644 --- a/lib/common.lib.php +++ b/lib/common.lib.php @@ -868,6 +868,9 @@ function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $r $mb = sql_fetch(" select mb_id from {$g4['member_table']} where mb_id = '$mb_id' "); if (!$mb['mb_id']) { return 0; } + // 회원포인트 + $mb_point = get_point_sum($mb_id); + // 이미 등록된 내역이라면 건너뜀 if ($rel_table || $rel_id || $rel_action) { @@ -895,6 +898,7 @@ function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $r $po_expired = 1; $po_expire_date = G4_TIME_YMD; } + $po_mb_point = $mb_point + $point; $sql = " insert into {$g4['point_table']} set mb_id = '$mb_id', @@ -902,29 +906,21 @@ function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $r po_content = '".addslashes($content)."', po_point = '$point', po_use_point = '0', + po_mb_point = '$po_mb_point', po_expired = '$po_expired', po_expire_date = '$po_expire_date', po_rel_table = '$rel_table', po_rel_id = '$rel_id', po_rel_action = '$rel_action' "; sql_query($sql); - $po_id = mysql_insert_id(); // 포인트를 사용한 경우 포인트 내역에 사용금액 기록 if($point < 0) { insert_use_point($mb_id, $point); } - // 회원포인트 - $sum_mb_point = get_point_sum($mb_id); - // 포인트 UPDATE - $sql = " update {$g4['member_table']} set mb_point = '$sum_mb_point' where mb_id = '$mb_id' "; - sql_query($sql); - - $sql = " update {$g4['point_table']} - set po_mb_point = '$sum_mb_point' - where po_id = '$po_id' "; + $sql = " update {$g4['member_table']} set mb_point = '$po_mb_point' where mb_id = '$mb_id' "; sql_query($sql); return 1; @@ -953,7 +949,7 @@ function insert_use_point($mb_id, $point, $po_id='') $point2 = $row['po_point']; $point3 = $row['po_use_point']; - if(($point2 - $point3) >= $point1) { + if(($point2 - $point3) > $point1) { $sql = " update {$g4['point_table']} set po_use_point = po_use_point + '$point1' where po_id = '{$row['po_id']}' "; @@ -971,6 +967,49 @@ function insert_use_point($mb_id, $point, $po_id='') } } +// 사용포인트 삭제 +function delete_use_point($mb_id, $point) +{ + global $g4, $config; + + if($config['cf_point_term']) + $sql_order = " order by po_expire_date desc, po_id desc "; + else + $sql_order = " order by po_id desc "; + + $point1 = abs($point); + $sql = " select po_id, po_use_point, po_expired, po_expire_date + from {$g4['point_table']} + where mb_id = '$mb_id' + and po_use_point > 0 + $sql_order "; + $result = sql_query($sql); + for($i=0; $row=sql_fetch_array($result); $i++) { + $point2 = $row['po_use_point']; + + $po_expired = $row['po_expired']; + if($row['po_expired'] == 100 && ($row['po_expire_date'] == '9999-12-31' || $row['po_expire_date'] >= G4_TIME_YMD)) + $po_expired = 0; + + if($point2 > $point1) { + $sql = " update {$g4['point_table']} + set po_use_point = po_use_point - '$point1', + po_expired = '$po_expired' + where po_id = '{$row['po_id']}' "; + sql_query($sql); + break; + } else { + $sql = " update {$g4['point_table']} + set po_use_point = '0', + po_expired = '$po_expired' + where po_id = '{$row['po_id']}' "; + sql_query($sql); + + $point1 -= $point2; + } + } +} + // 포인트 내역 합계 function get_point_sum($mb_id) { @@ -980,7 +1019,34 @@ function get_point_sum($mb_id) // 소멸포인트가 있으면 내역 추가 $expire_point = get_expire_point($mb_id); if($expire_point > 0) { - insert_point($mb_id, -1*$expire_point, '포인트 소멸', '@expire', $mb_id, 'expire'.'-'.uniqid('')); + $mb = get_member($mb_id, 'mb_point'); + $content = '포인트 소멸'; + $rel_table = '@expire'; + $rel_id = $mb_id; + $rel_action = 'expire'.'-'.uniqid(''); + $point = $expire_point * (-1); + $po_mb_point = $mb['mb_point'] + $point; + $po_expire_date = G4_TIME_YMD; + $po_expired = 1; + + $sql = " insert into {$g4['point_table']} + set mb_id = '$mb_id', + po_datetime = '".G4_TIME_YMDHIS."', + po_content = '".addslashes($content)."', + po_point = '$point', + po_use_point = '0', + po_mb_point = '$po_mb_point', + po_expired = '$po_expired', + po_expire_date = '$po_expire_date', + po_rel_table = '$rel_table', + po_rel_id = '$rel_id', + po_rel_action = '$rel_action' "; + sql_query($sql); + + // 포인트를 사용한 경우 포인트 내역에 사용금액 기록 + if($point < 0) { + insert_use_point($mb_id, $point); + } } // 유효기간이 있을 때 기간이 지난 포인트 expired 체크 @@ -994,16 +1060,12 @@ function get_point_sum($mb_id) } // 포인트합 - $sql = " select sum(po_point - po_use_point) as sum_po_point + $sql = " select sum(po_point) as sum_po_point from {$g4['point_table']} - where mb_id = '$mb_id' - and po_expired = '0' "; + where mb_id = '$mb_id' "; $row = sql_fetch($sql); - if($row['sum_po_point'] < 0) - return 0; - else - return $row['sum_po_point']; + return $row['sum_po_point']; } // 소멸 포인트 @@ -1025,6 +1087,59 @@ function get_expire_point($mb_id) return $row['sum_point']; } +// 포인트 삭제 +function delete_point($mb_id, $rel_table, $rel_id, $rel_action) +{ + global $g4; + + $result = false; + if ($rel_table || $rel_id || $rel_action) + { + // 포인트 내역정보 + $sql = " select * from {$g4['point_table']} + where mb_id = '$mb_id' + and po_rel_table = '$rel_table' + and po_rel_id = '$rel_id' + and po_rel_action = '$rel_action' "; + $row = sql_fetch($sql); + + if($row['po_point'] < 0) { + if($row['po_rel_table'] != '@expire') { + $mb_id = $row['mb_id']; + $po_point = abs($row['po_point']); + + delete_use_point($mb_id, $po_point); + } + } else { + if($row['po_expired'] != 1 && $row['po_use_point'] > 0) { + insert_use_point($row['mb_id'], $row['po_use_point'], $row['po_id']); + } + } + + $result = sql_query(" delete from {$g4['point_table']} + where mb_id = '$mb_id' + and po_rel_table = '$rel_table' + and po_rel_id = '$rel_id' + and po_rel_action = '$rel_action' ", false); + + // po_mb_point에 반영 + $sql = " update {$g4['point_table']} + set po_mb_point = po_mb_point - '{$row['po_point']}' + where mb_id = '$mb_id' + and po_id > '{$row['po_id']}' "; + sql_query($sql); + + // 포인트 내역의 합을 구하고 + $sum_point = get_point_sum($mb_id); + + // 포인트 UPDATE + $sql = " update {$g4['member_table']} set mb_point = '$sum_point' where mb_id = '$mb_id' "; + $result = sql_query($sql); + } + + return $result; +} + // 회원 레이어 function get_sideview($mb_id, $name='', $email='', $homepage='') {