포인트 유효기간 설정 추가

This commit is contained in:
chicpro
2013-07-22 16:43:01 +09:00
parent 0527a9feb8
commit 18da974e7f
7 changed files with 122 additions and 18 deletions

View File

@ -65,7 +65,7 @@ if(!isset($config['cf_mobile_pages'])) {
if(!isset($config['cf_facebook_appid'])) {
sql_query(" ALTER TABLE `{$g4['config_table']}`
ADD `cf_facebook_appid` VARCHAR(255) NOT NULL AFTER `cf_kcpcert_use`,
ADD `cf_facebook_appid` VARCHAR(255) NOT NULL AFTER `cf_kcpcert_use`,
ADD `cf_facebook_secret` VARCHAR(255) NOT NULL AFTER `cf_facebook_appid`,
ADD `cf_twitter_key` VARCHAR(255) NOT NULL AFTER `cf_facebook_secret`,
ADD `cf_twitter_secret` VARCHAR(255) NOT NULL AFTER `cf_twitter_key`,
@ -101,6 +101,16 @@ 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` ", false);
}
$g4['title'] = '환경설정';
include_once ('./admin.head.php');
@ -333,6 +343,13 @@ $pg_anchor = '<ul class="anchor">
<input type="checkbox" name="cf_use_copy_log" value="1" id="cf_use_copy_log" <?php echo $config['cf_use_copy_log']?'checked':''; ?>> 남김
</td>
</tr>
<tr>
<th scope="row"><label for="cf_point_term">포인트 유효기간</label></th>
<td colspan="3">
<?php echo help('기간을 0으로 설정시 포인트 유효기간이 적용되지 않습니다.') ?>
<input type="text" name="cf_point_term" value="<?php echo $config['cf_point_term']; ?>" id="cf_point_term" required class="required frm_input" size="5"> 일
</td>
</tr>
<tr>
<th scope="row"><label for="cf_possible_ip">접근가능 IP</label></th>
<td>

View File

@ -23,6 +23,7 @@ $sql = " update {$g4['config_table']}
cf_include_tail = '{$_POST['cf_include_tail']}',
cf_add_script = '{$_POST['cf_add_script']}',
cf_use_point = '{$_POST['cf_use_point']}',
cf_point_term = '{$_POST['cf_point_term']}',
cf_use_norobot = '{$_POST['cf_use_norobot']}',
cf_use_copy_log = '{$_POST['cf_use_copy_log']}',
cf_use_email_certify = '{$_POST['cf_use_email_certify']}',

View File

@ -9,6 +9,7 @@ $token = get_token();
$sql_common = " from {$g4['point_table']} ";
$sql_search = " where (1) ";
if ($stx) {
$sql_search .= " and ( ";
switch ($sfl) {
@ -58,7 +59,12 @@ if ($sfl == 'mb_id' && $stx)
$g4['title'] = '포인트관리';
include_once ('./admin.head.php');
$colspan = 8;
$colspan = 9;
$po_expire_term = '';
if($config['cf_point_term'] > 0) {
$po_expire_term = $config['cf_point_term'];
}
?>
<script>
@ -128,6 +134,7 @@ function point_clear()
<th scope="col">일시</th>
<th scope="col">포인트 내용</th>
<th scope="col">포인트</th>
<th scope="col">만료</th>
<th scope="col">포인트합</th>
</tr>
</thead>
@ -161,6 +168,7 @@ function point_clear()
<td class="td_time"><?php echo $row['po_datetime'] ?></td>
<td class="td_pt_log"><?php echo $link1 ?><?php echo $row['po_content'] ?><?php echo $link2 ?></td>
<td class="td_num td_pt"><?php echo number_format($row['po_point']) ?></td>
<td><?php echo $row['po_expired'] ? '예' : '아니오'; ?></td>
<td class="td_bignum td_pt"><?php echo number_format($row2['mb_point']) ?></td>
</tr>
@ -211,6 +219,12 @@ function point_clear()
<th scope="row"><label for="po_point">포인트<strong class="sound_only">필수</strong></label></th>
<td><input type="text" name="po_point" id="po_point" required class="required frm_input"></td>
</tr>
<?php if($config['cf_point_term'] > 0) { ?>
<tr>
<th scope="row"><label for="po_expire_term">포인트 유효기간</label></th>
<td><input type="text" name="po_expire_term" value="<?php echo $po_expire_term; ?>" id="po_expire_term" class="frm_input" size="5"> 일</td>
</tr>
<?php } ?>
</tbody>
</table>

View File

@ -20,9 +20,7 @@ for ($i=0; $i<$count; $i++)
$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'];
$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);

View File

@ -9,6 +9,7 @@ check_token();
$mb_id = $_POST['mb_id'];
$po_point = $_POST['po_point'];
$po_content = $_POST['po_content'];
$expire = preg_replace('/[^0-9]/', '', $_POST['po_expire_term']);
$mb = get_member($mb_id);
@ -18,7 +19,7 @@ if (!$mb['mb_id'])
if (($po_point < 0) && ($po_point * (-1) > $mb['mb_point']))
alert('포인트를 깎는 경우 현재 포인트보다 작으면 안됩니다.', './point_list.php?'.$qstr);
insert_point($mb_id, $po_point, $po_content, '@passive', $mb_id, $member['mb_id']."-".uniqid(""));
insert_point($mb_id, $po_point, $po_content, '@passive', $mb_id, $member['mb_id'].'-'.uniqid(''), $expire);
goto_url('./point_list.php?'.$qstr);
?>

View File

@ -197,6 +197,7 @@ CREATE TABLE IF NOT EXISTS `g4s_config` (
`cf_include_tail` varchar(255) NOT NULL DEFAULT '',
`cf_add_script` text NOT NULL,
`cf_use_point` tinyint(4) NOT NULL DEFAULT '0',
`cf_point_term` int(11) NOT NULL DEFAULT '0',
`cf_use_norobot` tinyint(4) NOT NULL DEFAULT '0',
`cf_use_copy_log` tinyint(4) NOT NULL DEFAULT '0',
`cf_use_email_certify` tinyint(4) NOT NULL DEFAULT '0',
@ -492,6 +493,9 @@ CREATE TABLE IF NOT EXISTS `g4s_point` (
`po_datetime` datetime NOT NULL default '0000-00-00 00:00:00',
`po_content` varchar(255) NOT NULL default '',
`po_point` int(11) NOT NULL default '0',
`po_use_point` int(11) NOT NULL default '0',
`po_expired` tinyint(4) NOT NULL default '0',
`po_expire_date` date NOT NULL default '0000-00-00',
`po_rel_table` varchar(20) NOT NULL default '',
`po_rel_id` varchar(20) NOT NULL default '',
`po_rel_action` varchar(255) NOT NULL default '',

View File

@ -539,7 +539,7 @@ function html_purifier($html)
// 첫행이 # 이면 주석 처리
if (!preg_match("/^#/", $domain)) {
$domain = trim($domain);
if ($domain)
if ($domain)
array_push($domains, $domain);
}
}
@ -851,7 +851,7 @@ function get_yn_select($name, $selected='1', $event='')
// 포인트 부여
function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $rel_action='')
function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $rel_action='', $expire='')
{
global $config;
global $g4;
@ -881,21 +881,65 @@ function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $r
return -1;
}
// 포인트를 사용한 경우 포인트 내역에 사용금액 기록
if($point < 0) {
$point1 = abs($point);
$sql = " select po_id, po_point, po_use_point
from {$g4['point_table']}
where mb_id = '$mb_id'
and po_expired = '0'
and po_point > po_use_point
order by po_datetime asc ";
$result = sql_query($sql);
for($i=0; $row=sql_fetch_array($result); $i++) {
$point2 = $row['po_point'];
$point3 = $row['po_use_point'];
if(($point2 - $point3) >= $point1) {
$sql = " update {$g4['point_table']}
set po_use_point = po_use_point + '$point1'
where po_id = '{$row['po_id']}' ";
sql_query($sql);
break;
} else {
$point4 = $point2 - $point3;
$sql = " update {$g4['point_table']}
set po_use_point = po_use_point + '$point4',
po_expired = '1'
where po_id = '{$row['po_id']}' ";
sql_query($sql);
$point1 -= $point4;
}
}
}
// 포인트 건별 생성
$po_expire_date = '0000-00-00';
if($config['cf_point_term'] > 0) {
if($expire != '' && $expire > 0)
$po_expire_date = date('Y-m-d', strtotime('+'.($expire - 1).' days', G4_SERVER_TIME));
else
$po_expire_date = date('Y-m-d', strtotime('+'.($config['cf_point_term'] - 1).' days', G4_SERVER_TIME));
}
$po_expired = 0;
if($point < 0)
$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_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);
// 포인트 내역의 합을 구하고
$sql = " select sum(po_point) as sum_po_point from {$g4['point_table']} where mb_id = '$mb_id' ";
$row = sql_fetch($sql);
$sum_point = $row['sum_po_point'];
$sum_point = get_point_sum($mb_id);
// 포인트 UPDATE
$sql = " update {$g4['member_table']} set mb_point = '$sum_point' where mb_id = '$mb_id' ";
@ -904,6 +948,31 @@ function insert_point($mb_id, $point, $content='', $rel_table='', $rel_id='', $r
return 1;
}
// 포인트 내역 합계
function get_point_sum($mb_id)
{
global $g4, $config;
// 유효기간이 있을 때 기간이 지난 포인트 expired 체크
if($config['cf_point_term'] > 0) {
$sql = " update {$g4['point_table']}
set po_expired = '1'
where mb_id = '$mb_id'
and po_expire_date <> '0000-00-00'
and po_expire_date < '".G4_TIME_YMD."' ";
sql_query($sql);
}
// 포인트합
$sql = " select sum(po_point - po_use_point) as sum_po_point
from {$g4['point_table']}
where mb_id = '$mb_id'
and po_expired = '0' ";
$row = sql_fetch($sql);
return $row['sum_po_point'];
}
// 포인트 삭제
function delete_point($mb_id, $rel_table, $rel_id, $rel_action)
{
@ -963,11 +1032,11 @@ function get_sideview($mb_id, $name='', $email='', $homepage='')
if ($config['cf_use_member_icon'] == 2) // 회원아이콘+이름
$tmp_name = $tmp_name.' '.$name;
} else {
$tmp_name = $tmp_name." ".$name;
}
} else {
$tmp_name = $tmp_name.' '.$name;
} else {
$tmp_name = $tmp_name." ".$name;
}
} else {
$tmp_name = $tmp_name.' '.$name;
}
$tmp_name .= '</a>';
@ -2010,7 +2079,7 @@ function board_notice($bo_notice, $wr_id, $insert=false)
// goo.gl 짧은주소 만들기
function googl_short_url($longUrl)
function googl_short_url($longUrl)
{
global $config;