244 lines
6.9 KiB
PHP
244 lines
6.9 KiB
PHP
<?php
|
|
/**
|
|
* VIP 만료일 설정 페이지
|
|
* 방문횟수가 0인 경우 등록일 +1년을 만료일로 설정
|
|
* 방문횟수가 1 이상인 경우 최종이용일 +1년을 만료일로 설정
|
|
*/
|
|
|
|
include_once ('./_common.php');
|
|
include_once (FG_MANAGER_PATH.'/head.php');
|
|
|
|
if(!$_SESSION['user_id']) {
|
|
header('Location: '.FG_MANAGER_URL);
|
|
exit;
|
|
}
|
|
|
|
// 권한 체크 (관리자 이상만 가능)
|
|
if($_SESSION['user_lv'] < 2) {
|
|
die('권한이 없습니다.');
|
|
}
|
|
|
|
$isDebug = false; // 디버그 출력용 변수
|
|
$result_message = "";
|
|
$result_data = array();
|
|
$is_executed = false;
|
|
|
|
// AJAX 요청 처리
|
|
if(isset($_POST['ajax_mode'])) {
|
|
$ajax_mode = trim($_POST['ajax_mode']);
|
|
|
|
if ($ajax_mode === "bulk_set_expire_date") {
|
|
$status = isset($_POST['status']) ? trim($_POST['status']) : "정상";
|
|
$gr_id = isset($_POST['gr_id']) ? trim($_POST['gr_id']) : "";
|
|
|
|
// 검색 조건 만들기
|
|
$where = " WHERE status='{$status}'";
|
|
if (!empty($gr_id)) {
|
|
$where .= " AND gr_id='{$gr_id}'";
|
|
}
|
|
|
|
$squery = "SELECT * FROM {$fg['vip_list_table']}{$where}";
|
|
$result_list = sql_query($squery);
|
|
|
|
$updated_count = 0;
|
|
$error_count = 0;
|
|
$datetime = date("Y-m-d H:i:s");
|
|
|
|
while($list = sql_fetch_array($result_list)) {
|
|
$ent_count = $list['ent_count'];
|
|
|
|
// 만료일 설정 로직
|
|
if ($ent_count == 0) {
|
|
// 방문횟수가 0: 등록일 + 1년
|
|
$vip_date = date("Y-m-d", strtotime($list['join_datetime'] . " +1 year"));
|
|
} else {
|
|
// 방문횟수가 1 이상: 최종이용일 + 1년
|
|
$vip_date = date("Y-m-d", strtotime($list['last_ent_date'] . " +1 year"));
|
|
}
|
|
|
|
// DB 업데이트
|
|
$updateQuery = "UPDATE {$fg['vip_list_table']} SET vip_date='{$vip_date}' WHERE idx='{$list['idx']}'";
|
|
$update_result = sql_query($updateQuery);
|
|
|
|
if ($update_result) {
|
|
$updated_count++;
|
|
} else {
|
|
$error_count++;
|
|
}
|
|
|
|
// log 기록
|
|
$work = "VIP만료일일괄설정";
|
|
$work_detail = "카드번호 : ".$list['vip_card_no']." 만료일 : ".$vip_date." 처리자 : ".$_SESSION['user_name'];
|
|
|
|
$logUpdate = log_update($work, $work_detail, $_SESSION['user_id'], $datetime);
|
|
}
|
|
|
|
$data = array(
|
|
"isSuccess" => true,
|
|
"updated_count" => $updated_count,
|
|
"error_count" => $error_count
|
|
);
|
|
|
|
header("Content-Type: application/json");
|
|
echo json_encode($data);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
// 1회성 실행 모드 (GET/POST 쿼리 파라미터)
|
|
if(isset($_REQUEST['confirm']) && $_REQUEST['confirm'] == 'yes') {
|
|
$datetime = date("Y-m-d H:i:s");
|
|
$is_executed = true;
|
|
|
|
// 모든 VIP 정상 상태 데이터 조회
|
|
$squery = "SELECT * FROM {$fg['vip_list_table']} WHERE status='정상'";
|
|
$result_list = sql_query($squery);
|
|
|
|
$updated_count = 0;
|
|
$error_count = 0;
|
|
$details = array();
|
|
|
|
while($list = sql_fetch_array($result_list)) {
|
|
$ent_count = $list['ent_count'];
|
|
|
|
// 만료일 설정 로직
|
|
if ($ent_count == 0) {
|
|
// 방문횟수가 0: 등록일 + 1년
|
|
$vip_date = date("Y-m-d", strtotime($list['join_datetime'] . " +1 year"));
|
|
$logic_type = "등록일 기준";
|
|
} else {
|
|
// 방문횟수가 1 이상: 최종이용일 + 1년
|
|
$vip_date = date("Y-m-d", strtotime($list['last_ent_date'] . " +1 year"));
|
|
$logic_type = "최종이용일 기준";
|
|
}
|
|
|
|
// DB 업데이트
|
|
$updateQuery = "UPDATE {$fg['vip_list_table']} SET vip_date='{$vip_date}' WHERE idx='{$list['idx']}'";
|
|
$update_result = sql_query($updateQuery);
|
|
|
|
if ($update_result) {
|
|
$updated_count++;
|
|
$details[] = array(
|
|
'card_no' => $list['vip_card_no'],
|
|
'name' => $list['vip_name'],
|
|
'old_date' => $list['vip_date'],
|
|
'new_date' => $vip_date,
|
|
'logic' => $logic_type,
|
|
'ent_count' => $ent_count
|
|
);
|
|
} else {
|
|
$error_count++;
|
|
}
|
|
|
|
// log 기록
|
|
$work = "VIP만료일일괄설정";
|
|
$work_detail = "카드번호 : ".$list['vip_card_no']." 만료일 : ".$vip_date." (" . $logic_type . ") 처리자 : ".$_SESSION['user_name'];
|
|
|
|
$logUpdate = log_update($work, $work_detail, $_SESSION['user_id'], $datetime);
|
|
}
|
|
|
|
$result_message = "처리 완료: 업데이트 성공 {$updated_count}건, 실패 {$error_count}건";
|
|
$result_data = $details;
|
|
}
|
|
|
|
?>
|
|
<style>
|
|
.expire-date-container {
|
|
max-width: 900px;
|
|
margin: 20px auto;
|
|
}
|
|
.result-table {
|
|
font-size: 12px;
|
|
}
|
|
.result-table td {
|
|
padding: 8px;
|
|
}
|
|
.success-bg {
|
|
background-color: #d4edda;
|
|
}
|
|
.error-bg {
|
|
background-color: #f8d7da;
|
|
}
|
|
</style>
|
|
|
|
<div class="expire-date-container">
|
|
<h2 class="mb-4">VIP 만료일 일괄 설정</h2>
|
|
|
|
<?php if($is_executed) { ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
<strong>✓ 처리 완료!</strong>
|
|
<?= $result_message ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
|
|
<?php if(count($result_data) > 0) { ?>
|
|
<div class="card mt-4">
|
|
<div class="card-header">
|
|
<h5>처리 결과 상세</h5>
|
|
</div>
|
|
<div class="card-body">
|
|
<table class="table table-sm result-table">
|
|
<thead>
|
|
<tr>
|
|
<th>카드번호</th>
|
|
<th>성명</th>
|
|
<th>이전 만료일</th>
|
|
<th>신규 만료일</th>
|
|
<th>설정 기준</th>
|
|
<th>방문횟수</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach($result_data as $item) { ?>
|
|
<tr class="success-bg">
|
|
<td><?= $item['card_no'] ?></td>
|
|
<td><?= $item['name'] ?></td>
|
|
<td><?= ($item['old_date'] == '9999-12-31') ? '평생' : $item['old_date'] ?></td>
|
|
<td><strong><?= $item['new_date'] ?></strong></td>
|
|
<td><?= $item['logic'] ?></td>
|
|
<td><?= $item['ent_count'] ?></td>
|
|
</tr>
|
|
<?php } ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<?php } ?>
|
|
|
|
<div class="mt-4">
|
|
<a href="vip_list.php" class="btn btn-primary">VIP 목록으로 돌아가기</a>
|
|
</div>
|
|
<?php } else { ?>
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title">작업 설명</h5>
|
|
<ul>
|
|
<li><strong>상태: 정상</strong>인 모든 VIP의 만료일을 설정합니다</li>
|
|
<li><strong>방문횟수가 0</strong>이면: <mark>등록일 + 1년</mark>을 만료일로 설정</li>
|
|
<li><strong>방문횟수가 1 이상</strong>이면: <mark>최종이용일 + 1년</mark>을 만료일로 설정</li>
|
|
<li>모든 변경사항은 로그에 기록됩니다</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="alert alert-warning mt-4" role="alert">
|
|
<strong>⚠️ 주의:</strong> 이 작업은 취소할 수 없습니다.
|
|
<br>현재 상태의 모든 정상 상태 VIP <?php
|
|
$check_count = get_num_rows("{$fg['vip_list_table']}", "WHERE status='정상'");
|
|
echo $check_count;
|
|
?>건의 만료일이 변경됩니다.
|
|
</div>
|
|
|
|
<div class="mt-4">
|
|
<form method="post" style="display: inline;">
|
|
<button type="submit" name="confirm" value="yes" class="btn btn-danger btn-lg">
|
|
<i class="fa-solid fa-exclamation-triangle"></i> 실행
|
|
</button>
|
|
</form>
|
|
<a href="vip_list.php" class="btn btn-secondary btn-lg">취소</a>
|
|
</div>
|
|
<?php } ?>
|
|
</div>
|
|
|
|
<?php include_once FG_MANAGER_PATH.'/tail.php';
|