first commit 2
This commit is contained in:
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
if (!defined('_GNUBOARD_'))
|
||||
exit;
|
||||
|
||||
// 필요한 클래스 및 라이브러리 포함
|
||||
require_once G5_PATH . '/adm/order_manage/classes/EstimateManager.class.php';
|
||||
require_once G5_PATH . '/lib/notification_helper.php';
|
||||
|
||||
/**
|
||||
* Class DealerNotification
|
||||
* 대리점 관련 알림을 처리하는 클래스
|
||||
*/
|
||||
class DealerNotification
|
||||
{
|
||||
private $estimateManager;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->estimateManager = new EstimateManager();
|
||||
}
|
||||
|
||||
/**
|
||||
* 대리점의 견적이 선택되었을 때 알림을 발송합니다.
|
||||
*
|
||||
* @param int $wr_id 게시물 ID
|
||||
* @param string $dealer_id 대리점 ID
|
||||
* @param array $bid_info 입찰 정보
|
||||
* @return array ['success' => bool, 'message' => string]
|
||||
*/
|
||||
public function sendBidSelectedNotification($wr_id, $dealer_id, $bid_info)
|
||||
{
|
||||
try {
|
||||
// 1. 고객 정보 조회
|
||||
$write = sql_fetch("SELECT * FROM g5_write_order WHERE wr_id = '{$wr_id}'");
|
||||
if (!$write) {
|
||||
throw new Exception('원본 게시물을 찾을 수 없습니다.');
|
||||
}
|
||||
$customer = get_member($write['mb_id']);
|
||||
|
||||
// 2. 대리점 정보 조회
|
||||
$dealer = get_member($dealer_id);
|
||||
if (!$dealer) {
|
||||
throw new Exception('대리점 정보를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 3. 알림에 필요한 변수 설정
|
||||
$vars = [
|
||||
'dealer_name' => $dealer['mb_name'],
|
||||
'customer_name' => $customer['mb_name'] ?? '고객',
|
||||
'estimate_id' => $bid_info['estimate_id'],
|
||||
'bid_amount' => number_format($bid_info['total_amount']),
|
||||
'selected_date' => date('Y-m-d H:i'),
|
||||
'estimate_url' => get_pretty_url('order', $wr_id)
|
||||
];
|
||||
|
||||
// 4. 알림 발송
|
||||
if (function_exists('notify_agent')) {
|
||||
notify_agent('bid_selected_email', $vars);
|
||||
}
|
||||
|
||||
return ['success' => true, 'message' => '대리점에게 견적 선택 알림을 발송했습니다.'];
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("DealerNotification::sendBidSelectedNotification Error: " . $e->getMessage());
|
||||
return ['success' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 시공 일정 알림 발송
|
||||
*
|
||||
* @param int $wr_id 게시물 ID
|
||||
* @return array ['success' => bool, 'message' => string]
|
||||
*/
|
||||
public function sendScheduleReminder($wr_id)
|
||||
{
|
||||
try {
|
||||
// 1. 시공 정보 조회
|
||||
$schedule_info = $this->estimateManager->getConstructionSchedule($wr_id);
|
||||
if (!$schedule_info || !$schedule_info['has_schedule']) {
|
||||
throw new Exception('시공 일정이 없습니다.');
|
||||
}
|
||||
|
||||
// 2. 대리점 정보 조회
|
||||
$dealer = get_member($schedule_info['dealer_id']);
|
||||
if (!$dealer) {
|
||||
throw new Exception('대리점 정보를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 3. 알림 변수 설정
|
||||
$vars = [
|
||||
'dealer_name' => $dealer['mb_name'],
|
||||
'customer_name' => $schedule_info['customer_name'],
|
||||
'estimate_id' => $schedule_info['estimate_id'],
|
||||
'construction_date' => $schedule_info['construction_date'],
|
||||
'interim_payment_date' => $schedule_info['interim_payment_date']
|
||||
];
|
||||
|
||||
// 4. 알림 발송
|
||||
if (function_exists('notify_agent')) {
|
||||
notify_agent('schedule_reminder_email', $vars);
|
||||
}
|
||||
|
||||
return ['success' => true, 'message' => '대리점에게 시공 일정 알림을 발송했습니다.'];
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("DealerNotification::sendScheduleReminder Error: " . $e->getMessage());
|
||||
return ['success' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 중도금 입금 기한 알림 발송
|
||||
*
|
||||
* @param int $wr_id 게시물 ID
|
||||
* @return array ['success' => bool, 'message' => string]
|
||||
*/
|
||||
public function sendInterimPaymentDueNotification($wr_id)
|
||||
{
|
||||
try {
|
||||
// 1. 중도금 입금 타이밍 확인
|
||||
$timing_info = $this->estimateManager->checkInterimPaymentTiming($wr_id);
|
||||
if (!$timing_info['is_due']) {
|
||||
return ['success' => true, 'message' => '중도금 입금 기한이 아직 도래하지 않았습니다.'];
|
||||
}
|
||||
|
||||
// 2. 시공 정보 조회
|
||||
$schedule_info = $this->estimateManager->getConstructionSchedule($wr_id);
|
||||
if (!$schedule_info) {
|
||||
throw new Exception('시공 정보를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 3. 대리점 정보 조회
|
||||
$dealer = get_member($schedule_info['dealer_id']);
|
||||
if (!$dealer) {
|
||||
throw new Exception('대리점 정보를 찾을 수 없습니다.');
|
||||
}
|
||||
|
||||
// 4. 알림 변수 설정
|
||||
$vars = [
|
||||
'dealer_name' => $dealer['mb_name'],
|
||||
'customer_name' => $schedule_info['customer_name'],
|
||||
'estimate_id' => $schedule_info['estimate_id'],
|
||||
'construction_date' => $schedule_info['construction_date'],
|
||||
'interim_payment_date' => $schedule_info['interim_payment_date'],
|
||||
'days_remaining' => $timing_info['days_remaining']
|
||||
];
|
||||
|
||||
// 5. 알림 발송
|
||||
if (function_exists('notify_agent')) {
|
||||
notify_agent('interim_due_email', $vars);
|
||||
}
|
||||
|
||||
return ['success' => true, 'message' => '대리점에게 중도금 입금 기한 알림을 발송했습니다.'];
|
||||
|
||||
} catch (Exception $e) {
|
||||
error_log("DealerNotification::sendInterimPaymentDueNotification Error: " . $e->getMessage());
|
||||
return ['success' => false, 'message' => $e->getMessage()];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user