영카트4에서 영카트5로 업그레이드시 포인트 소멸처리
본문
약 5년간 영카트4를 이용중입니다.
이번에 모바일지원 및 운영방식의 변경으로 인해서 영카트5로 업그레이드 작업을 준비중입니다.
영카트5로 업그레이드를 하면서 영카트4에서 기존에 회원에게 제공되었던 포인트를 일정기간 지난 포인트를 소멸 또는 삭제하고자 합니다.
g4_import_run.php 파일에서 포인트 내역마다 만료일을 지정하는 소스를 추가하였는데, 만료일이 지난 포인트가 소멸 또는 삭제가 되지 않습니다.
lib/common.lib.php 파일에서
// 소멸포인트 삭제
function delete_expire_point($mb_id, $point)
{
global $g5, $config;
$point1 = abs($point);
$sql = " select po_id, po_use_point, po_expired, po_expire_date
from {$g5['point_table']}
where mb_id = '$mb_id'
and po_expired = '1'
and po_point >= 0
and po_use_point > 0
order by po_expire_date desc, po_id desc ";
$result = sql_query($sql);
for($i=0; $row=sql_fetch_array($result); $i++) {
$point2 = $row['po_use_point'];
$po_expired = '0';
$po_expire_date = '9999-12-31';
if($config['cf_point_term'] > 0)
$po_expire_date = date('Y-m-d', strtotime('+'.($config['cf_point_term'] - 1).' days', G5_SERVER_TIME));
if($point2 > $point1) {
$sql = " update {$g5['point_table']}
set po_use_point = po_use_point - '$point1',
po_expired = '$po_expired',
po_expire_date = '$po_expire_date'
where po_id = '{$row['po_id']}' ";
sql_query($sql);
break;
} else {
$sql = " update {$g5['point_table']}
set po_use_point = '0',
po_expired = '$po_expired',
po_expire_date = '$po_expire_date'
where po_id = '{$row['po_id']}' ";
sql_query($sql);
$point1 -= $point2;
}
}
}
// 포인트 내역 합계
function get_point_sum($mb_id)
{
global $g5, $config;
if($config['cf_point_term'] > 0) {
// 소멸포인트가 있으면 내역 추가
$expire_point = get_expire_point($mb_id);
if($expire_point > 0) {
$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 = G5_TIME_YMD;
$po_expired = 1;
$sql = " insert into {$g5['point_table']}
set mb_id = '$mb_id',
po_datetime = '".G5_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 체크
$sql = " update {$g5['point_table']}
set po_expired = '1'
where mb_id = '$mb_id'
and po_expired <> '1'
and po_expire_date <> '9999-12-31'
and po_expire_date < '".G5_TIME_YMD."' ";
sql_query($sql);
}
// 포인트합
$sql = " select sum(po_point) as sum_po_point
from {$g5['point_table']}
where mb_id = '$mb_id' ";
$row = sql_fetch($sql);
return $row['sum_po_point'];
}
// 소멸 포인트
function get_expire_point($mb_id)
{
global $g5, $config;
if($config['cf_point_term'] == 0)
return 0;
$sql = " select sum(po_point - po_use_point) as sum_point
from {$g5['point_table']}
where mb_id = '$mb_id'
and po_expired = '0'
and po_expire_date <> '9999-12-31'
and po_expire_date < '".G5_TIME_YMD."' ";
$row = sql_fetch($sql);
return $row['sum_point'];
}
// 포인트 삭제
function delete_point($mb_id, $rel_table, $rel_id, $rel_action)
{
global $g5;
$result = false;
if ($rel_table || $rel_id || $rel_action)
{
// 포인트 내역정보
$sql = " select * from {$g5['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) {
$mb_id = $row['mb_id'];
$po_point = abs($row['po_point']);
delete_use_point($mb_id, $po_point);
} else {
if($row['po_use_point'] > 0) {
insert_use_point($row['mb_id'], $row['po_use_point'], $row['po_id']);
}
}
$result = sql_query(" delete from {$g5['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 {$g5['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 {$g5['member_table']} set mb_point = '$sum_point' where mb_id = '$mb_id' ";
$result = sql_query($sql);
}
return $result;
}
이 부분이 관련 소스인것 같은데 이래저래 적용을 해봐도 안되네요.
사용하지 않는 포인트를 소멸처리할려면 어떻게 해야되나요?
!-->답변 2
기본환경설정에 보시면 "포인트 유효기간" 이라는 항목이 있습니다.
여기에 날짜를 설정해주시면 해당 날짜가 지난 포인트들은 소멸됩니다.
위 라이브러리 소스상에서 보시면 delete_expire_point 함수내의 $config['cf_point_term'] 변수에 저장되어 처리됩니다.
포인트 유효기간 설정 시 자동으로 소멸처리되지 않고 해당 회원이 로그인시 소멸처리 되는 구조.
답변을 작성하시기 전에 로그인 해주세요.