Files
2026-06-11 18:47:38 +09:00

337 lines
14 KiB
PHP

<?php
$sub_menu = "800400";
include_once('./_common.php');
auth_check($auth[$sub_menu], 'r');
$g5['title'] = '전문가 방문 관리';
// EstimateManager 클래스 로드
require_once G5_PATH . '/adm/order_manage/classes/EstimateManager.class.php';
$estimateManager = new EstimateManager();
// 액션 처리
$action = isset($_REQUEST['action']) ? clean_xss_tags($_REQUEST['action']) : '';
$wr_id = (int) ($_REQUEST['wr_id'] ?? 0);
// POST 요청 처리
if ($action && $_SERVER['REQUEST_METHOD'] === 'POST') {
auth_check($auth[$sub_menu], 'w');
try {
if ($action === 'confirm_payment') {
$result = $estimateManager->confirmExpertVisitPayment($wr_id);
} elseif ($action === 'schedule_visit') {
$visit_datetime = clean_xss_tags($_POST['visit_datetime'] ?? '');
$expert_id = clean_xss_tags($_POST['expert_id'] ?? '');
$result = $estimateManager->scheduleExpertVisit($wr_id, $visit_datetime, $expert_id);
} elseif ($action === 'complete_visit') {
$visit_notes = clean_xss_tags($_POST['visit_notes'] ?? '');
$result = $estimateManager->completeExpertVisit($wr_id, $visit_notes);
} else {
throw new Exception('알 수 없는 요청입니다.');
}
if ($result['success']) {
alert($result['message'], './expert_visits.php');
} else {
throw new Exception($result['message']);
}
} catch (Exception $e) {
alert('오류: ' . $e->getMessage());
}
goto_url('./expert_visits.php');
exit;
}
// 검색 조건
$sfl = isset($_GET['sfl']) ? clean_xss_tags($_GET['sfl']) : '';
$stx = isset($_GET['stx']) ? clean_xss_tags($_GET['stx']) : '';
$status_filter = isset($_GET['status_filter']) ? clean_xss_tags($_GET['status_filter']) : '';
$where = [];
if ($stx) {
if ($sfl === 'customer_name') {
$where[] = "cm.mb_name LIKE '%{$stx}%'";
} elseif ($sfl === 'expert_name') {
$where[] = "em.mb_name LIKE '%{$stx}%'";
}
}
if ($status_filter) {
$where[] = "e.temp_2 = '{$status_filter}'";
}
$where_clause = empty($where) ? "e.temp_1 = 'Y'" : "e.temp_1 = 'Y' AND " . implode(' AND ', $where);
// 페이징
$page = (int) ($_GET['page'] ?? 1);
$page_rows = 10;
$total_count_sql = "
SELECT COUNT(*) as cnt
FROM estimate e
LEFT JOIN g5_write_order w ON e.wr_id = w.wr_id
LEFT JOIN g5_member cm ON w.mb_id = cm.mb_id
LEFT JOIN g5_member em ON e.extra_4 = em.mb_id
WHERE {$where_clause}
";
$total_count_res = sql_fetch($total_count_sql);
$total_count = $total_count_res['cnt'];
$total_page = ceil($total_count / $page_rows);
$from_record = ($page - 1) * $page_rows;
// 목록 조회
$sql = "
SELECT
e.id as estimate_id, e.wr_id, e.temp_1, e.temp_2 as status, e.temp_3 as visit_fee,
e.temp_4 as visit_datetime, e.temp_5 as visit_notes, e.extra_4 as expert_id,
w.wr_subject, w.mb_id as customer_id,
cm.mb_name as customer_name, cm.mb_hp as customer_phone,
em.mb_name as expert_name
FROM estimate e
LEFT JOIN g5_write_order w ON e.wr_id = w.wr_id
LEFT JOIN g5_member cm ON w.mb_id = cm.mb_id
LEFT JOIN g5_member em ON e.extra_4 = em.mb_id
WHERE {$where_clause}
ORDER BY e.id DESC
LIMIT {$from_record}, {$page_rows}
";
$result = sql_query($sql);
$visits = [];
while ($row = sql_fetch_array($result)) {
$visits[] = $row;
}
// 전문가 목록 (레벨 8 이상)
$experts = [];
$expert_sql = "SELECT mb_id, mb_name FROM g5_member WHERE mb_level >= 9 ORDER BY mb_name";
$expert_result = sql_query($expert_sql);
while ($row = sql_fetch_array($expert_result)) {
$experts[] = $row;
}
include_once(G5_ADMIN_PATH . '/admin.head.php');
// var_dump($expert_sql);
// var_dump(sql_fetch_array($expert_result));
?>
<div class="local_desc01 local_desc">
<p>
고객이 요청한 전문가 방문을 관리합니다. <br> 결제 확인, 일정 조율, 방문 완료 처리를 할 수 있습니다.
</p>
</div>
<!-- 검색 폼 -->
<form name="fsearch" id="fsearch" class="local_sch01 local_sch" method="get">
<label for="sfl" class="sound_only">검색대상</label>
<select name="sfl" id="sfl">
<option value="customer_name" <?php echo get_selected($sfl, 'customer_name'); ?>>고객명</option>
<option value="expert_name" <?php echo get_selected($sfl, 'expert_name'); ?>>전문가명</option>
</select>
<label for="stx" class="sound_only">검색어<strong class="sound_only"> 필수</strong></label>
<input type="text" name="stx" value="<?php echo $stx ?>" id="stx" class="frm_input">
<label for="status_filter" class="sound_only">상태</label>
<select name="status_filter" id="status_filter">
<option value="">전체 상태</option>
<option value="requested" <?php echo get_selected($status_filter, 'requested'); ?>>결제 대기</option>
<option value="payment_confirmed" <?php echo get_selected($status_filter, 'payment_confirmed'); ?>>일정 조율</option>
<option value="scheduled" <?php echo get_selected($status_filter, 'scheduled'); ?>>방문 예정</option>
<option value="completed" <?php echo get_selected($status_filter, 'completed'); ?>>방문 완료</option>
<option value="cancelled" <?php echo get_selected($status_filter, 'cancelled'); ?>>취소</option>
</select>
<input type="submit" value="검색" class="btn_submit">
</form>
<div class="tbl_head01 tbl_wrap">
<table>
<caption><?php echo $g5['title']; ?> 목록</caption>
<thead>
<tr>
<th scope="col">견적 ID</th>
<th scope="col">고객명</th>
<th scope="col">연락처</th>
<th scope="col">방문 상태</th>
<th scope="col">방문 비용</th>
<th scope="col">방문 일정</th>
<th scope="col">담당 전문가</th>
<th scope="col">관리</th>
</tr>
</thead>
<tbody>
<?php if (empty($visits)): ?>
<tr>
<td colspan="8" class="empty_table">데이터가 없습니다.</td>
</tr>
<?php else: ?>
<?php foreach ($visits as $visit): ?>
<tr>
<td>
<a href="<?php echo G5_BBS_URL; ?>/board.php?bo_table=order&wr_id=<?php echo $visit['wr_id']; ?>"
target="_blank"><?php echo $visit['wr_id']; ?></a>
</td>
<td><?php echo $visit['customer_name']; ?></td>
<td><?php echo $visit['customer_phone']; ?></td>
<td>
<?php
switch ($visit['status']) {
case 'requested': echo '결제 대기'; break;
case 'payment_confirmed': echo '일정 조율'; break;
case 'scheduled': echo '방문 예정'; break;
case 'completed': echo '방문 완료'; break;
case 'cancelled': echo '취소'; break;
default: echo '알 수 없음';
}
?>
</td>
<td><?php echo number_format($visit['visit_fee']); ?>원</td>
<td><?php echo $visit['visit_datetime'] ? date('Y-m-d H:i', strtotime($visit['visit_datetime'])) : '-'; ?></td>
<td><?php echo $visit['expert_name'] ?: '미배정'; ?></td>
<td class="td_mng td_mng_l">
<?php if ($visit['status'] === 'requested'): ?>
<form name="frm_confirm_<?php echo $visit['wr_id']; ?>" method="post" style="display:inline;">
<input type="hidden" name="action" value="confirm_payment">
<input type="hidden" name="wr_id" value="<?php echo $visit['wr_id']; ?>">
<button type="submit" class="btn btn_03"
onclick="return confirm('결제를 확인 처리하시겠습니까?');">결제확인</button>
</form>
<?php elseif ($visit['status'] === 'payment_confirmed'): ?>
<button type="button" class="btn btn_02"
onclick="openScheduleModal(<?php echo $visit['wr_id']; ?>)">일정조율</button>
<?php elseif ($visit['status'] === 'scheduled'): ?>
<form name="frm_complete_<?php echo $visit['wr_id']; ?>" method="post" style="display:inline;">
<input type="hidden" name="action" value="complete_visit">
<input type="hidden" name="wr_id" value="<?php echo $visit['wr_id']; ?>">
<input type="hidden" name="visit_notes" value="방문 완료됨">
<button type="submit" class="btn btn_01"
onclick="return confirm('방문을 완료 처리하시겠습니까?');">방문완료</button>
</form>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
<?php echo get_paging(G5_IS_MOBILE ? $config['cf_mobile_pages'] : $config['cf_write_pages'], $page, $total_page, "{$_SERVER['SCRIPT_NAME']}?$qstr&amp;page="); ?>
<!-- 일정 조율 모달 -->
<div id="scheduleModal" class="modal" style="display: none;">
<div class="modal-content">
<div class="modal-header">
<h3>방문 일정 조율</h3>
<span class="close" onclick="closeScheduleModal()">&times;</span>
</div>
<div class="modal-body">
<form name="frm_schedule" id="frm_schedule" method="post">
<input type="hidden" name="action" value="schedule_visit">
<input type="hidden" name="wr_id" id="modal_wr_id">
<div class="tbl_frm01 tbl_wrap">
<table>
<tr>
<th scope="row"><label for="modal_visit_datetime">방문 일시</label></th>
<td>
<input type="datetime-local" name="visit_datetime" id="modal_visit_datetime"
class="frm_input" required>
</td>
</tr>
<tr>
<th scope="row"><label for="modal_expert_id">담당 전문가</label></th>
<td>
<select name="expert_id" id="modal_expert_id" class="frm_input">
<option value="">선택하세요</option>
<?php foreach ($experts as $expert): ?>
<option value="<?php echo $expert['mb_id']; ?>">
<?php echo $expert['mb_name']; ?> (<?php echo $expert['mb_id']; ?>)
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
</table>
</div>
<div class="btn_confirm01 btn_confirm">
<button type="submit" class="btn_submit">일정 저장</button>
</div>
</form>
</div>
</div>
</div>
<style>
.modal {
position: fixed;
z-index: 1000;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
}
.modal-content {
background-color: #fefefe;
margin: 10% auto;
padding: 0;
border: 1px solid #888;
width: 80%;
max-width: 600px;
border-radius: 5px;
}
.modal-header {
padding: 15px 20px;
background-color: #f8f9fa;
border-bottom: 1px solid #dee2e6;
border-radius: 5px 5px 0 0;
}
.modal-header h3 {
margin: 0;
display: inline-block;
}
.close {
color: #aaa;
float: right;
font-size: 28px;
font-weight: bold;
cursor: pointer;
}
.close:hover {
color: black;
}
.modal-body {
padding: 20px;
}
</style>
<script>
function openScheduleModal(wr_id) {
document.getElementById('modal_wr_id').value = wr_id;
document.getElementById('scheduleModal').style.display = 'block';
}
function closeScheduleModal() {
document.getElementById('scheduleModal').style.display = 'none';
}
window.onclick = function (event) {
const modal = document.getElementById('scheduleModal');
if (event.target === modal) {
closeScheduleModal();
}
}
</script>
<?php
include_once(G5_ADMIN_PATH . '/admin.tail.php');
?>