123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- <?php
- require_once 'conn.php';
- checkLogin();
- // 获取当前登录员工ID
- $employee_id = $_SESSION['employee_id'];
- // 获取消息ID
- $message_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
- if ($message_id <= 0) {
- echo "<script>alert('无效的消息ID'); window.location.href='message_list.php';</script>";
- exit;
- }
- // 查询消息
- $sql = "SELECT m.*, mr.is_read, mr.read_time
- FROM messages m
- LEFT JOIN message_recipients mr ON m.id = mr.message_id AND mr.employee_id = $employee_id
- WHERE m.id = $message_id AND (m.target_type = 2 OR mr.employee_id = $employee_id)";
- $result = mysqli_query($conn, $sql);
- if (mysqli_num_rows($result) == 0) {
- echo "<script>alert('消息不存在或无权查看'); window.location.href='message_list.php';</script>";
- exit;
- }
- $message = mysqli_fetch_assoc($result);
- // 如果消息未读,标记为已读
- if (!$message['is_read']) {
- $check_sql = "SELECT id FROM message_recipients WHERE message_id = $message_id AND employee_id = $employee_id";
- $check_result = mysqli_query($conn, $check_sql);
- if (mysqli_num_rows($check_result) > 0) {
- // 更新已有记录
- $update_sql = "UPDATE message_recipients SET is_read = 1, read_time = NOW() WHERE message_id = $message_id AND employee_id = $employee_id";
- mysqli_query($conn, $update_sql);
- } else if ($message['target_type'] == 2) {
- // 全体公告,创建新的接收记录
- $insert_sql = "INSERT INTO message_recipients (message_id, employee_id, is_read, read_time, created_at)
- VALUES ($message_id, $employee_id, 1, NOW(), NOW())";
- mysqli_query($conn, $insert_sql);
- }
- }
- // 获取关联数据
- $related_data = [];
- if ($message['related_customer_id']) {
- $customer_sql = "SELECT id, cs_company FROM customer WHERE id = " . $message['related_customer_id'];
- $customer_result = mysqli_query($conn, $customer_sql);
- if ($customer = mysqli_fetch_assoc($customer_result)) {
- $related_data['customer'] = $customer;
- }
- }
- if ($message['related_order_id']) {
- $order_sql = "SELECT id, order_code FROM orders WHERE id = " . $message['related_order_id'];
- $order_result = mysqli_query($conn, $order_sql);
- if ($order = mysqli_fetch_assoc($order_result)) {
- $related_data['order'] = $order;
- }
- }
- // 消息类型和优先级文本
- $message_type_text = [
- 1 => '系统消息',
- 2 => '客户相关',
- 3 => '订单相关',
- 4 => '任务提醒',
- 5 => '其他'
- ][$message['message_type']] ?? '未知';
- $target_type_text = [
- 0 => '个人',
- 1 => '部分群发',
- 2 => '全体公告'
- ][$message['target_type']] ?? '未知';
- $priority_text = [
- 0 => '普通',
- 1 => '重要',
- 2 => '紧急'
- ][$message['priority']] ?? '未知';
- // 确定优先级样式
- $priority_class = [
- 0 => '',
- 1 => 'priority-1',
- 2 => 'priority-2'
- ][$message['priority']] ?? '';
- ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>消息详情</title>
- <link rel="stylesheet" href="css/common.css" type="text/css" />
- <link rel="stylesheet" href="css/alert.css" type="text/css" />
- <script src="js/jquery-1.7.2.min.js"></script>
- <script src="js/js.js"></script>
- <style>
- body {
- margin: 0;
- padding: 20px;
- background: #fff;
- }
- #man_zone {
- margin-left: 0;
- }
-
- /* 表格布局修复 */
- .table2 {
- width: 100%;
- margin-bottom: 15px;
- }
-
- .theader {
- background-color: #f2f2f2;
- font-weight: bold;
- height: 40px;
- display: flex;
- align-items: center;
- padding: 0 10px;
- border-bottom: 1px solid #ddd;
- }
-
- /* 消息头部 */
- .message-header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: 15px;
- }
-
- .message-header h2 {
- margin: 0;
- font-size: 18px;
- }
-
- .back-btn {
- display: inline-block;
- padding: 5px 12px;
- background-color: #4285f4;
- color: white;
- border-radius: 3px;
- text-decoration: none;
- font-size: 14px;
- }
-
- .back-btn:hover {
- background-color: #3367d6;
- }
-
- /* 消息标题区域 */
- .message-title {
- margin-bottom: 20px;
- padding: 15px;
- background: #f9f9f9;
- border: 1px solid #eee;
- border-radius: 3px;
- }
-
- .message-title h3 {
- margin: 0 0 10px 0;
- font-size: 16px;
- }
-
- .message-meta {
- color: #666;
- font-size: 13px;
- line-height: 1.5;
- }
-
- .message-meta span {
- margin-right: 15px;
- }
-
- /* 消息内容区域 */
- .message-section {
- margin-bottom: 20px;
- border: 1px solid #eee;
- border-radius: 3px;
- }
-
- .section-header {
- padding: 10px 15px;
- background: #f2f2f2;
- font-weight: bold;
- border-bottom: 1px solid #eee;
- }
-
- .section-body {
- padding: 15px;
- line-height: 1.6;
- }
-
- /* 相关信息区域 */
- .related-item {
- margin-bottom: 10px;
- }
-
- .related-item:last-child {
- margin-bottom: 0;
- }
-
- .related-item strong {
- margin-right: 5px;
- }
-
- /* 消息内容区域 */
- .message-content {
- white-space: pre-line;
- }
-
- /* 操作按钮区域 */
- .action-bar {
- text-align: right;
- margin-top: 20px;
- }
-
- .btn-danger {
- display: inline-block;
- padding: 5px 12px;
- background-color: #db4437;
- color: white;
- border: none;
- border-radius: 3px;
- cursor: pointer;
- font-size: 14px;
- }
-
- .btn-danger:hover {
- background-color: #c62828;
- }
-
- /* 优先级颜色 */
- .priority-1 {
- color: #f4b400;
- }
-
- .priority-2 {
- color: #db4437;
- font-weight: bold;
- }
- </style>
- </head>
- <body>
- <div id="man_zone">
- <div class="message-header">
- <h2>消息详情</h2>
- <a href="message_list.php" class="back-btn">返回列表</a>
- </div>
-
- <div class="message-title">
- <h3><?= htmlspecialcharsFix($message['title']) ?></h3>
- <div class="message-meta">
- <span>消息类型: <?= $message_type_text ?></span>
- <span>接收类型: <?= $target_type_text ?></span>
- <span>优先级: <span class="<?= $priority_class ?>"><?= $priority_text ?></span></span>
- <span>时间: <?= date('Y-m-d H:i:s', strtotime($message['created_at'])) ?></span>
- </div>
- </div>
-
- <?php if (!empty($related_data)): ?>
- <div class="message-section">
- <div class="section-header">相关信息</div>
- <div class="section-body">
- <?php if (isset($related_data['customer'])): ?>
- <div class="related-item">
- <strong>相关客户:</strong>
- <a href="customer_view.php?id=<?= $related_data['customer']['id'] ?>">
- <?= htmlspecialcharsFix($related_data['customer']['cs_company']) ?>
- </a>
- </div>
- <?php endif; ?>
-
- <?php if (isset($related_data['order'])): ?>
- <div class="related-item">
- <strong>相关订单:</strong>
- <a href="order_details.php?id=<?= $related_data['order']['id'] ?>">
- <?= htmlspecialcharsFix($related_data['order']['order_code']) ?>
- </a>
- </div>
- <?php endif; ?>
- </div>
- </div>
- <?php endif; ?>
-
- <div class="message-section">
- <div class="section-header">消息内容</div>
- <div class="section-body">
- <div class="message-content"><?= nl2br(htmlspecialcharsFix($message['content'])) ?></div>
- </div>
- </div>
-
- <div class="action-bar">
- <button class="btn-danger delete-message" data-id="<?= $message['id'] ?>">删除消息</button>
- </div>
- </div>
- <script>
- $(document).ready(function() {
- // 删除消息
- $('.delete-message').click(function() {
- if (confirm('确定要删除这条消息吗?')) {
- var messageId = $(this).data('id');
- $.post('message_action.php', {
- action: 'delete',
- message_id: messageId
- }, function(response) {
- try {
- var data = typeof response === 'string' ? JSON.parse(response) : response;
- if (data.success) {
- window.location.href = 'message_list.php';
- } else {
- alert('操作失败:' + data.message);
- }
- } catch (e) {
- alert('操作失败:服务器返回未知错误');
- }
- });
- }
- });
- });
- </script>
- </body>
- </html>
|