message_detail.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. // 获取当前登录员工ID
  5. $employee_id = $_SESSION['employee_id'];
  6. // 获取消息ID
  7. $message_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
  8. if ($message_id <= 0) {
  9. echo "<script>alert('无效的消息ID'); window.location.href='message_list.php';</script>";
  10. exit;
  11. }
  12. // 查询消息
  13. $sql = "SELECT m.*, mr.is_read, mr.read_time
  14. FROM messages m
  15. LEFT JOIN message_recipients mr ON m.id = mr.message_id AND mr.employee_id = $employee_id
  16. WHERE m.id = $message_id AND (m.target_type = 2 OR mr.employee_id = $employee_id)";
  17. $result = mysqli_query($conn, $sql);
  18. if (mysqli_num_rows($result) == 0) {
  19. echo "<script>alert('消息不存在或无权查看'); window.location.href='message_list.php';</script>";
  20. exit;
  21. }
  22. $message = mysqli_fetch_assoc($result);
  23. // 如果消息未读,标记为已读
  24. if (!$message['is_read']) {
  25. $check_sql = "SELECT id FROM message_recipients WHERE message_id = $message_id AND employee_id = $employee_id";
  26. $check_result = mysqli_query($conn, $check_sql);
  27. if (mysqli_num_rows($check_result) > 0) {
  28. // 更新已有记录
  29. $update_sql = "UPDATE message_recipients SET is_read = 1, read_time = NOW() WHERE message_id = $message_id AND employee_id = $employee_id";
  30. mysqli_query($conn, $update_sql);
  31. } else if ($message['target_type'] == 2) {
  32. // 全体公告,创建新的接收记录
  33. $insert_sql = "INSERT INTO message_recipients (message_id, employee_id, is_read, read_time, created_at)
  34. VALUES ($message_id, $employee_id, 1, NOW(), NOW())";
  35. mysqli_query($conn, $insert_sql);
  36. }
  37. }
  38. // 获取关联数据
  39. $related_data = [];
  40. if ($message['related_customer_id']) {
  41. $customer_sql = "SELECT id, cs_company FROM customer WHERE id = " . $message['related_customer_id'];
  42. $customer_result = mysqli_query($conn, $customer_sql);
  43. if ($customer = mysqli_fetch_assoc($customer_result)) {
  44. $related_data['customer'] = $customer;
  45. }
  46. }
  47. if ($message['related_order_id']) {
  48. $order_sql = "SELECT id, order_code FROM orders WHERE id = " . $message['related_order_id'];
  49. $order_result = mysqli_query($conn, $order_sql);
  50. if ($order = mysqli_fetch_assoc($order_result)) {
  51. $related_data['order'] = $order;
  52. }
  53. }
  54. // 消息类型和优先级文本
  55. $message_type_text = [
  56. 1 => '系统消息',
  57. 2 => '客户相关',
  58. 3 => '订单相关',
  59. 4 => '任务提醒',
  60. 5 => '其他'
  61. ][$message['message_type']] ?? '未知';
  62. $target_type_text = [
  63. 0 => '个人',
  64. 1 => '部分群发',
  65. 2 => '全体公告'
  66. ][$message['target_type']] ?? '未知';
  67. $priority_text = [
  68. 0 => '普通',
  69. 1 => '重要',
  70. 2 => '紧急'
  71. ][$message['priority']] ?? '未知';
  72. // 确定优先级样式
  73. $priority_class = [
  74. 0 => '',
  75. 1 => 'priority-1',
  76. 2 => 'priority-2'
  77. ][$message['priority']] ?? '';
  78. ?>
  79. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  80. <html xmlns="http://www.w3.org/1999/xhtml">
  81. <head>
  82. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  83. <title>消息详情</title>
  84. <link rel="stylesheet" href="css/common.css" type="text/css" />
  85. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  86. <script src="js/jquery-1.7.2.min.js"></script>
  87. <script src="js/js.js"></script>
  88. <style>
  89. body {
  90. margin: 0;
  91. padding: 20px;
  92. background: #fff;
  93. }
  94. #man_zone {
  95. margin-left: 0;
  96. }
  97. /* 表格布局修复 */
  98. .table2 {
  99. width: 100%;
  100. margin-bottom: 15px;
  101. }
  102. .theader {
  103. background-color: #f2f2f2;
  104. font-weight: bold;
  105. height: 40px;
  106. display: flex;
  107. align-items: center;
  108. padding: 0 10px;
  109. border-bottom: 1px solid #ddd;
  110. }
  111. /* 消息头部 */
  112. .message-header {
  113. display: flex;
  114. justify-content: space-between;
  115. align-items: center;
  116. margin-bottom: 15px;
  117. }
  118. .message-header h2 {
  119. margin: 0;
  120. font-size: 18px;
  121. }
  122. .back-btn {
  123. display: inline-block;
  124. padding: 5px 12px;
  125. background-color: #4285f4;
  126. color: white;
  127. border-radius: 3px;
  128. text-decoration: none;
  129. font-size: 14px;
  130. }
  131. .back-btn:hover {
  132. background-color: #3367d6;
  133. }
  134. /* 消息标题区域 */
  135. .message-title {
  136. margin-bottom: 20px;
  137. padding: 15px;
  138. background: #f9f9f9;
  139. border: 1px solid #eee;
  140. border-radius: 3px;
  141. }
  142. .message-title h3 {
  143. margin: 0 0 10px 0;
  144. font-size: 16px;
  145. }
  146. .message-meta {
  147. color: #666;
  148. font-size: 13px;
  149. line-height: 1.5;
  150. }
  151. .message-meta span {
  152. margin-right: 15px;
  153. }
  154. /* 消息内容区域 */
  155. .message-section {
  156. margin-bottom: 20px;
  157. border: 1px solid #eee;
  158. border-radius: 3px;
  159. }
  160. .section-header {
  161. padding: 10px 15px;
  162. background: #f2f2f2;
  163. font-weight: bold;
  164. border-bottom: 1px solid #eee;
  165. }
  166. .section-body {
  167. padding: 15px;
  168. line-height: 1.6;
  169. }
  170. /* 相关信息区域 */
  171. .related-item {
  172. margin-bottom: 10px;
  173. }
  174. .related-item:last-child {
  175. margin-bottom: 0;
  176. }
  177. .related-item strong {
  178. margin-right: 5px;
  179. }
  180. /* 消息内容区域 */
  181. .message-content {
  182. white-space: pre-line;
  183. }
  184. /* 操作按钮区域 */
  185. .action-bar {
  186. text-align: right;
  187. margin-top: 20px;
  188. }
  189. .btn-danger {
  190. display: inline-block;
  191. padding: 5px 12px;
  192. background-color: #db4437;
  193. color: white;
  194. border: none;
  195. border-radius: 3px;
  196. cursor: pointer;
  197. font-size: 14px;
  198. }
  199. .btn-danger:hover {
  200. background-color: #c62828;
  201. }
  202. /* 优先级颜色 */
  203. .priority-1 {
  204. color: #f4b400;
  205. }
  206. .priority-2 {
  207. color: #db4437;
  208. font-weight: bold;
  209. }
  210. </style>
  211. </head>
  212. <body>
  213. <div id="man_zone">
  214. <div class="message-header">
  215. <h2>消息详情</h2>
  216. <a href="message_list.php" class="back-btn">返回列表</a>
  217. </div>
  218. <div class="message-title">
  219. <h3><?= htmlspecialcharsFix($message['title']) ?></h3>
  220. <div class="message-meta">
  221. <span>消息类型: <?= $message_type_text ?></span>
  222. <span>接收类型: <?= $target_type_text ?></span>
  223. <span>优先级: <span class="<?= $priority_class ?>"><?= $priority_text ?></span></span>
  224. <span>时间: <?= date('Y-m-d H:i:s', strtotime($message['created_at'])) ?></span>
  225. </div>
  226. </div>
  227. <?php if (!empty($related_data)): ?>
  228. <div class="message-section">
  229. <div class="section-header">相关信息</div>
  230. <div class="section-body">
  231. <?php if (isset($related_data['customer'])): ?>
  232. <div class="related-item">
  233. <strong>相关客户:</strong>
  234. <a href="customer_view.php?id=<?= $related_data['customer']['id'] ?>">
  235. <?= htmlspecialcharsFix($related_data['customer']['cs_company']) ?>
  236. </a>
  237. </div>
  238. <?php endif; ?>
  239. <?php if (isset($related_data['order'])): ?>
  240. <div class="related-item">
  241. <strong>相关订单:</strong>
  242. <a href="order_details.php?id=<?= $related_data['order']['id'] ?>">
  243. <?= htmlspecialcharsFix($related_data['order']['order_code']) ?>
  244. </a>
  245. </div>
  246. <?php endif; ?>
  247. </div>
  248. </div>
  249. <?php endif; ?>
  250. <div class="message-section">
  251. <div class="section-header">消息内容</div>
  252. <div class="section-body">
  253. <div class="message-content"><?= nl2br(htmlspecialcharsFix($message['content'])) ?></div>
  254. </div>
  255. </div>
  256. <div class="action-bar">
  257. <button class="btn-danger delete-message" data-id="<?= $message['id'] ?>">删除消息</button>
  258. </div>
  259. </div>
  260. <script>
  261. $(document).ready(function() {
  262. // 删除消息
  263. $('.delete-message').click(function() {
  264. if (confirm('确定要删除这条消息吗?')) {
  265. var messageId = $(this).data('id');
  266. $.post('message_action.php', {
  267. action: 'delete',
  268. message_id: messageId
  269. }, function(response) {
  270. try {
  271. var data = typeof response === 'string' ? JSON.parse(response) : response;
  272. if (data.success) {
  273. window.location.href = 'message_list.php';
  274. } else {
  275. alert('操作失败:' + data.message);
  276. }
  277. } catch (e) {
  278. alert('操作失败:服务器返回未知错误');
  279. }
  280. });
  281. }
  282. });
  283. });
  284. </script>
  285. </body>
  286. </html>