369 lines
14 KiB
PHP
369 lines
14 KiB
PHP
<?php
|
|
$sub_menu = "800250";
|
|
include_once('./_common.php');
|
|
|
|
auth_check($auth[$sub_menu], 'r');
|
|
|
|
$g5['title'] = '대리점 설정 관리';
|
|
|
|
// 액션 처리
|
|
$action = isset($_REQUEST['action']) ? clean_xss_tags($_REQUEST['action']) : '';
|
|
|
|
if ($action && $_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
auth_check($auth[$sub_menu], 'w');
|
|
|
|
try {
|
|
if ($action === 'update_commission') {
|
|
$level_5_rate = (float) ($_POST['dealer_commission_level_5'] ?? 5);
|
|
$level_6_rate = (float) ($_POST['dealer_commission_level_6'] ?? 11);
|
|
$level_7_rate = (float) ($_POST['dealer_commission_level_7'] ?? 19);
|
|
|
|
// 수수료율 업데이트
|
|
$updates = [
|
|
'dealer_commission_level_5' => $level_5_rate,
|
|
'dealer_commission_level_6' => $level_6_rate,
|
|
'dealer_commission_level_7' => $level_7_rate
|
|
];
|
|
|
|
foreach ($updates as $key => $value) {
|
|
$existing = sql_fetch("SELECT config_key FROM order_config WHERE config_key = '{$key}'");
|
|
if ($existing) {
|
|
sql_query("UPDATE order_config SET config_value = '{$value}' WHERE config_key = '{$key}'");
|
|
} else {
|
|
sql_query("INSERT INTO order_config (config_key, config_value, description, type) VALUES ('{$key}', '{$value}', '대리점 수수료율', 'number')");
|
|
}
|
|
}
|
|
|
|
alert('대리점 수수료율이 업데이트되었습니다.', './dealer_config.php');
|
|
}
|
|
|
|
if ($action === 'update_dealer_level') {
|
|
$mb_id = clean_xss_tags($_POST['mb_id'] ?? '');
|
|
$new_level = (int) ($_POST['new_level'] ?? 0);
|
|
|
|
if ($mb_id && in_array($new_level, [5, 6, 7, 8])) {
|
|
sql_query("UPDATE g5_member SET mb_level = '{$new_level}' WHERE mb_id = '{$mb_id}'");
|
|
alert('대리점 레벨이 변경되었습니다.', './dealer_config.php');
|
|
} else {
|
|
throw new Exception('유효하지 않은 레벨입니다.');
|
|
}
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
alert('오류: ' . $e->getMessage());
|
|
}
|
|
|
|
goto_url('./dealer_config.php');
|
|
exit;
|
|
}
|
|
|
|
// 현재 수수료율 조회
|
|
$commission_rates = [];
|
|
$rates_sql = "SELECT config_key, config_value FROM order_config WHERE config_key LIKE 'dealer_commission_level_%'";
|
|
$rates_result = sql_query($rates_sql);
|
|
while ($row = sql_fetch_array($rates_result)) {
|
|
$commission_rates[$row['config_key']] = $row['config_value'];
|
|
}
|
|
|
|
// 대리점 목록 조회 (레벨 5-7)
|
|
$dealers = [];
|
|
$dealers_sql = "SELECT mb_id, mb_name, mb_level, mb_hp, mb_email, mb_datetime FROM g5_member WHERE mb_level IN (5,6,7) ORDER BY mb_level DESC, mb_name ASC";
|
|
$dealers_result = sql_query($dealers_sql);
|
|
while ($dealer = sql_fetch_array($dealers_result)) {
|
|
$dealers[] = $dealer;
|
|
}
|
|
|
|
// 대리점 성과 조회
|
|
$performance = [];
|
|
$performance_sql = "
|
|
SELECT
|
|
b.dealer_id,
|
|
COUNT(*) as total_bids,
|
|
COUNT(CASE WHEN b.status = 'selected' THEN 1 END) as selected_bids,
|
|
AVG(b.total_amount) as avg_amount,
|
|
SUM(CASE WHEN b.status = 'selected' THEN b.total_amount ELSE 0 END) as total_revenue
|
|
FROM estimate_bidding b
|
|
WHERE b.created_at >= DATE_SUB(NOW(), INTERVAL 3 MONTH)
|
|
GROUP BY b.dealer_id
|
|
";
|
|
$performance_result = sql_query($performance_sql);
|
|
while ($perf = sql_fetch_array($performance_result)) {
|
|
$performance[$perf['dealer_id']] = $perf;
|
|
}
|
|
|
|
include_once(G5_ADMIN_PATH . '/admin.head.php');
|
|
?>
|
|
|
|
<div class="local_desc01 local_desc">
|
|
<p>
|
|
대리점 수수료율 설정 및 대리점 레벨 관리를 할 수 있습니다.<br>
|
|
레벨별 수수료율은 견적 제안 시 자동으로 적용됩니다.
|
|
</p>
|
|
</div>
|
|
|
|
<!-- 수수료율 설정 -->
|
|
<div class="tbl_frm01 tbl_wrap">
|
|
<form name="fcommission" method="post">
|
|
<input type="hidden" name="action" value="update_commission">
|
|
|
|
<table>
|
|
<caption>대리점 수수료율 설정</caption>
|
|
<colgroup>
|
|
<col class="grid_4">
|
|
<col>
|
|
</colgroup>
|
|
<tbody>
|
|
<tr>
|
|
<th scope="row"><label for="dealer_commission_level_5">레벨 5 대리점 수수료율</label></th>
|
|
<td>
|
|
<input type="number" name="dealer_commission_level_5" id="dealer_commission_level_5"
|
|
value="<?php echo $commission_rates['dealer_commission_level_5'] ?? 5; ?>" class="frm_input"
|
|
min="0" max="50" step="0.1"> %
|
|
<span class="frm_info">기본 대리점 수수료율</span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><label for="dealer_commission_level_6">레벨 6 대리점 수수료율</label></th>
|
|
<td>
|
|
<input type="number" name="dealer_commission_level_6" id="dealer_commission_level_6"
|
|
value="<?php echo $commission_rates['dealer_commission_level_6'] ?? 11; ?>"
|
|
class="frm_input" min="0" max="50" step="0.1"> %
|
|
<span class="frm_info">중급 대리점 수수료율</span>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th scope="row"><label for="dealer_commission_level_7">레벨 7 대리점 수수료율</label></th>
|
|
<td>
|
|
<input type="number" name="dealer_commission_level_7" id="dealer_commission_level_7"
|
|
value="<?php echo $commission_rates['dealer_commission_level_7'] ?? 19; ?>"
|
|
class="frm_input" min="0" max="50" step="0.1"> %
|
|
<span class="frm_info">고급 대리점 수수료율</span>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
|
|
<div class="btn_confirm01 btn_confirm">
|
|
<input type="submit" value="수수료율 저장" class="btn_submit">
|
|
</div>
|
|
</form>
|
|
</div>
|
|
|
|
<!-- 대리점 목록 및 관리 -->
|
|
<div class="local_ov01 local_ov">
|
|
<span class="btn_ov01">
|
|
<span class="ov_txt">등록된 대리점 </span>
|
|
<span class="ov_num"><?php echo count($dealers); ?>개</span>
|
|
</span>
|
|
</div>
|
|
|
|
<div class="tbl_head01 tbl_wrap">
|
|
<table>
|
|
<caption>대리점 목록 및 성과</caption>
|
|
<thead>
|
|
<tr>
|
|
<th scope="col">대리점 정보</th>
|
|
<th scope="col">레벨</th>
|
|
<th scope="col">수수료율</th>
|
|
<th scope="col">최근 3개월 성과</th>
|
|
<th scope="col">가입일</th>
|
|
<th scope="col">관리</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php if (empty($dealers)): ?>
|
|
<tr>
|
|
<td colspan="6" class="empty_table">등록된 대리점이 없습니다.</td>
|
|
</tr>
|
|
<?php else: ?>
|
|
<?php foreach ($dealers as $dealer): ?>
|
|
<?php
|
|
$perf = $performance[$dealer['mb_id']] ?? null;
|
|
$success_rate = $perf && $perf['total_bids'] > 0 ? round(($perf['selected_bids'] / $perf['total_bids']) * 100, 1) : 0;
|
|
$commission_key = 'dealer_commission_level_' . $dealer['mb_level'];
|
|
$commission_rate = $commission_rates[$commission_key] ?? 0;
|
|
?>
|
|
<tr>
|
|
<td class="td_left">
|
|
<strong><?php echo get_text($dealer['mb_name']); ?></strong><br>
|
|
<small>ID: <?php echo $dealer['mb_id']; ?></small><br>
|
|
<small>연락처: <?php echo get_text($dealer['mb_hp']); ?></small><br>
|
|
<small>이메일: <?php echo get_text($dealer['mb_email']); ?></small>
|
|
</td>
|
|
<td class="td_center">
|
|
<span class="level-badge level-<?php echo $dealer['mb_level']; ?>">
|
|
레벨 <?php echo $dealer['mb_level']; ?>
|
|
</span>
|
|
</td>
|
|
<td class="td_center">
|
|
<strong><?php echo $commission_rate; ?>%</strong>
|
|
</td>
|
|
<td class="td_left">
|
|
<?php if ($perf): ?>
|
|
<strong>입찰: <?php echo number_format($perf['total_bids']); ?>건</strong><br>
|
|
<small>선택: <?php echo number_format($perf['selected_bids']); ?>건
|
|
(<?php echo $success_rate; ?>%)</small><br>
|
|
<small>매출: <?php echo number_format($perf['total_revenue']); ?>원</small><br>
|
|
<small>평균: <?php echo number_format($perf['avg_amount']); ?>원</small>
|
|
<?php else: ?>
|
|
<span class="text-muted">성과 데이터 없음</span>
|
|
<?php endif; ?>
|
|
</td>
|
|
<td class="td_datetime">
|
|
<?php echo date('Y-m-d', strtotime($dealer['mb_datetime'])); ?>
|
|
</td>
|
|
<td class="td_mng td_mng_s">
|
|
<button type="button" class="btn btn_03"
|
|
onclick="changeDealerLevel('<?php echo $dealer['mb_id']; ?>', <?php echo $dealer['mb_level']; ?>)">
|
|
레벨 변경
|
|
</button>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- 레벨 변경 모달 -->
|
|
<div id="levelModal" class="modal" style="display: none;">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h3>대리점 레벨 변경</h3>
|
|
<span class="close" onclick="closeModal()">×</span>
|
|
</div>
|
|
<div class="modal-body">
|
|
<form id="levelForm" method="post">
|
|
<input type="hidden" name="action" value="update_dealer_level">
|
|
<input type="hidden" id="modal_mb_id" name="mb_id">
|
|
|
|
<div class="form-group">
|
|
<label for="new_level">새 레벨:</label>
|
|
<select id="new_level" name="new_level" class="frm_input" required>
|
|
<option value="5">레벨 5 (기본 대리점 -
|
|
<?php echo $commission_rates['dealer_commission_level_5'] ?? 5; ?>%)</option>
|
|
<option value="6">레벨 6 (중급 대리점 -
|
|
<?php echo $commission_rates['dealer_commission_level_6'] ?? 11; ?>%)</option>
|
|
<option value="7">레벨 7 (고급 대리점 -
|
|
<?php echo $commission_rates['dealer_commission_level_7'] ?? 19; ?>%)</option>
|
|
<option value="8">레벨 8 (관리자)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="btn_confirm01 btn_confirm">
|
|
<input type="submit" value="레벨 변경" class="btn_submit">
|
|
<button type="button" onclick="closeModal()" class="btn_cancel">취소</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<style>
|
|
.level-badge {
|
|
padding: 3px 8px;
|
|
border-radius: 3px;
|
|
color: white;
|
|
font-size: 11px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.level-5 {
|
|
background-color: #28a745;
|
|
}
|
|
|
|
.level-6 {
|
|
background-color: #007bff;
|
|
}
|
|
|
|
.level-7 {
|
|
background-color: #6f42c1;
|
|
}
|
|
|
|
.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: 15% auto;
|
|
padding: 0;
|
|
border: 1px solid #888;
|
|
width: 400px;
|
|
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;
|
|
}
|
|
|
|
.form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.form-group label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
font-weight: bold;
|
|
}
|
|
|
|
.text-muted {
|
|
color: #6c757d;
|
|
}
|
|
</style>
|
|
|
|
<script>
|
|
// 대리점 레벨 변경
|
|
function changeDealerLevel(mb_id, current_level) {
|
|
document.getElementById('modal_mb_id').value = mb_id;
|
|
document.getElementById('new_level').value = current_level;
|
|
document.getElementById('levelModal').style.display = 'block';
|
|
}
|
|
|
|
// 모달 닫기
|
|
function closeModal() {
|
|
document.getElementById('levelModal').style.display = 'none';
|
|
}
|
|
|
|
// 모달 외부 클릭 시 닫기
|
|
window.onclick = function (event) {
|
|
const modal = document.getElementById('levelModal');
|
|
if (event.target === modal) {
|
|
closeModal();
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<?php
|
|
include_once(G5_ADMIN_PATH . '/admin.tail.php');
|
|
?>
|