order_details.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. $id = $_GET['id'] ?? '';
  5. // 验证并获取订单数据
  6. if (!empty($id) && is_numeric($id)) {
  7. // 获取订单基本信息
  8. $employee_id = $_SESSION['employee_id'];
  9. $sql = "SELECT o.*, c.cs_company, cc.contact_name, e.em_user as employee_name
  10. FROM orders o
  11. LEFT JOIN customer c ON o.customer_id = c.id
  12. LEFT JOIN customer_contact cc ON o.contact_id = cc.id
  13. LEFT JOIN employee e ON o.employee_id = e.id
  14. WHERE o.id = $id AND o.employee_id = $employee_id";
  15. $result = mysqli_query($conn, $sql);
  16. if ($row = mysqli_fetch_assoc($result)) {
  17. $order = $row;
  18. } else {
  19. echo "<script>alert('订单不存在或您没有权限查看');history.back();</script>";
  20. exit;
  21. }
  22. // 获取订单项信息
  23. $sql = "SELECT oi.*, p.ProductName
  24. FROM order_items oi
  25. LEFT JOIN products p ON oi.product_id = p.id
  26. WHERE oi.order_id = $id";
  27. $itemsResult = mysqli_query($conn, $sql);
  28. $orderItems = [];
  29. while ($itemRow = mysqli_fetch_assoc($itemsResult)) {
  30. $orderItems[] = $itemRow;
  31. }
  32. } else {
  33. echo "<script>alert('订单不存在!');history.back();</script>";
  34. exit;
  35. }
  36. ?>
  37. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  38. <html xmlns="http://www.w3.org/1999/xhtml">
  39. <head>
  40. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  41. <title>订单详情</title>
  42. <link rel="stylesheet" href="css/common.css" type="text/css" />
  43. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  44. <script src="js/jquery-1.7.2.min.js"></script>
  45. <script src="js/js.js"></script>
  46. <style>
  47. body {
  48. margin: 0;
  49. padding: 20px;
  50. background: #fff;
  51. }
  52. #man_zone {
  53. margin-left: 0;
  54. }
  55. .order-info {
  56. border: 1px solid #ddd;
  57. padding: 15px;
  58. margin-bottom: 20px;
  59. background-color: #f9f9f9;
  60. }
  61. .order-info h2 {
  62. margin-top: 0;
  63. border-bottom: 1px solid #ddd;
  64. padding-bottom: 10px;
  65. }
  66. .order-info .info-row {
  67. margin-bottom: 10px;
  68. }
  69. .order-info .info-label {
  70. font-weight: bold;
  71. display: inline-block;
  72. width: 120px;
  73. }
  74. .products-table {
  75. width: 100%;
  76. border-collapse: collapse;
  77. margin-bottom: 20px;
  78. }
  79. .products-table th, .products-table td {
  80. border: 1px solid #ddd;
  81. padding: 8px;
  82. text-align: left;
  83. }
  84. .products-table th {
  85. background-color: #f2f2f2;
  86. }
  87. /* 移除徽章式样,使用普通文本显示 */
  88. .order-status {
  89. font-weight: bold;
  90. }
  91. .payment-status {
  92. font-weight: bold;
  93. }
  94. .notes-section {
  95. border: 1px solid #ddd;
  96. padding: 15px;
  97. margin-bottom: 20px;
  98. }
  99. .total-section {
  100. text-align: right;
  101. font-size: 1.1em;
  102. margin-top: 10px;
  103. border-top: 1px solid #ddd;
  104. padding-top: 10px;
  105. }
  106. </style>
  107. </head>
  108. <body>
  109. <div id="man_zone">
  110. <div align="right" style="margin-bottom: 10px;">
  111. <input type="button" value="返回订单列表" class="btn1" onClick="location.href='order.php'" />
  112. <input type="button" value="编辑此订单" class="btn1" onClick="location.href='order_edit.php?id=<?= $id ?>'" />
  113. </div>
  114. <div class="order-info">
  115. <h2>订单信息</h2>
  116. <div class="info-row">
  117. <span class="info-label">订单编号:</span> <?= htmlspecialcharsFix($order['order_code']) ?>
  118. </div>
  119. <div class="info-row">
  120. <span class="info-label">客户:</span> <?= htmlspecialcharsFix($order['cs_company']) ?>
  121. </div>
  122. <div class="info-row">
  123. <span class="info-label">联系人:</span> <?= htmlspecialcharsFix($order['contact_name']) ?>
  124. </div>
  125. <div class="info-row">
  126. <span class="info-label">订单日期:</span> <?= date('Y-m-d', strtotime($order['order_date'])) ?>
  127. </div>
  128. <div class="info-row">
  129. <span class="info-label">创建时间:</span> <?= $order['created_at'] ?>
  130. </div>
  131. <div class="info-row">
  132. <span class="info-label">最后更新:</span> <?= $order['updated_at'] ?>
  133. </div>
  134. <div class="info-row">
  135. <span class="info-label">销售员:</span> <?= htmlspecialcharsFix($order['employee_name']) ?>
  136. </div>
  137. </div>
  138. <h2>订单产品</h2>
  139. <table class="products-table">
  140. <thead>
  141. <tr>
  142. <th>序号</th>
  143. <th>产品名称</th>
  144. <th>数量</th>
  145. <th>单位</th>
  146. <th>单价</th>
  147. <th>折扣</th>
  148. <th>总价</th>
  149. <th>备注</th>
  150. </tr>
  151. </thead>
  152. <tbody>
  153. <?php foreach ($orderItems as $index => $item): ?>
  154. <tr>
  155. <td><?= $index + 1 ?></td>
  156. <td><?= htmlspecialcharsFix($item['ProductName']) ?></td>
  157. <td><?= $item['quantity'] ?></td>
  158. <td><?= htmlspecialcharsFix($item['unit']) ?></td>
  159. <td><?= number_format($item['unit_price'], 2) ?></td>
  160. <td>
  161. <?php if ($item['discount_amount'] > 0): ?>
  162. <?= number_format($item['discount_amount'], 2) ?>
  163. (<?= number_format($item['discount_percent'], 2) ?>%)
  164. <?php else: ?>
  165. -
  166. <?php endif; ?>
  167. </td>
  168. <td><?= number_format($item['total_price'], 2) ?></td>
  169. <td><?= htmlspecialcharsFix($item['notes']) ?></td>
  170. </tr>
  171. <?php endforeach; ?>
  172. </tbody>
  173. </table>
  174. <div class="total-section">
  175. <div>
  176. <strong>订单小计:</strong> <?= number_format($order['subtotal'], 2) ?>
  177. </div>
  178. <?php if(isset($order['discount_amount']) && $order['discount_amount'] > 0): ?>
  179. <div>
  180. <strong>订单折扣:</strong> <?= number_format($order['discount_amount'], 2) ?>
  181. </div>
  182. <?php endif; ?>
  183. <div style="font-size: 1.2em; margin-top: 5px;">
  184. <strong>订单总额:</strong> <?= number_format($order['total_amount'], 2) ?>
  185. </div>
  186. </div>
  187. <?php if (!empty($order['notes'])): ?>
  188. <div class="notes-section">
  189. <h2>备注信息</h2>
  190. <div>
  191. <strong>订单备注:</strong>
  192. <p><?= nl2br(htmlspecialcharsFix($order['notes'])) ?></p>
  193. </div>
  194. </div>
  195. <?php endif; ?>
  196. </div>
  197. </body>
  198. </html>