order.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. // 辅助函数
  5. function textDecode($str) {
  6. return htmlspecialchars_decode($str, ENT_QUOTES);
  7. }
  8. function htmlDecode($str) {
  9. return htmlspecialchars_decode($str, ENT_QUOTES);
  10. }
  11. $act = $_GET['act'] ?? '';
  12. $urlStr = '';
  13. // 处理筛选条件
  14. $fliterStatus = $_GET['fliterStatus'] ?? '';
  15. $fliterPayment = $_GET['fliterPayment'] ?? '';
  16. $fliterCustomer = $_GET['fliterCustomer'] ?? '';
  17. $fliterFromDate = $_GET['fliterFromDate'] ?? '';
  18. $fliterToDate = $_GET['fliterToDate'] ?? '';
  19. $fliterStr = "";
  20. if (!empty($fliterStatus)) {
  21. $fliterStr .= " AND o.order_status = " . intval($fliterStatus);
  22. $urlStr .= "&fliterStatus=" . $fliterStatus;
  23. }
  24. if (!empty($fliterPayment)) {
  25. $fliterStr .= " AND o.payment_status = " . intval($fliterPayment);
  26. $urlStr .= "&fliterPayment=" . $fliterPayment;
  27. }
  28. if (!empty($fliterCustomer)) {
  29. $fliterStr .= " AND o.customer_id = " . intval($fliterCustomer);
  30. $urlStr .= "&fliterCustomer=" . $fliterCustomer;
  31. }
  32. if (!empty($fliterFromDate)) {
  33. $fliterStr .= " AND o.order_date >= '" . mysqli_real_escape_string($conn, $fliterFromDate) . "'";
  34. $urlStr .= "&fliterFromDate=" . urlencode($fliterFromDate);
  35. }
  36. if (!empty($fliterToDate)) {
  37. $fliterStr .= " AND o.order_date <= '" . mysqli_real_escape_string($conn, $fliterToDate) . " 23:59:59'";
  38. $urlStr .= "&fliterToDate=" . urlencode($fliterToDate);
  39. }
  40. // 搜索和排序
  41. $keys = $_GET['Keys'] ?? '';
  42. $keyscode = mysqli_real_escape_string($conn, $keys);
  43. $page = $_GET['Page'] ?? 1;
  44. $ord = $_GET['Ord'] ?? '';
  45. $ordStr = !empty($ord) ? "$ord," : "";
  46. // 构建查询SQL
  47. $employee_id = $_SESSION['employee_id'];
  48. $sqlStr = "SELECT o.*, c.cs_company, cc.contact_name
  49. FROM orders o
  50. LEFT JOIN customer c ON o.customer_id = c.id
  51. LEFT JOIN customer_contact cc ON o.contact_id = cc.id
  52. WHERE o.employee_id = $employee_id";
  53. if (!empty($keyscode)) {
  54. $sqlStr .= " AND (o.order_code LIKE '%$keyscode%'
  55. OR c.cs_company LIKE '%$keyscode%'
  56. OR cc.contact_name LIKE '%$keyscode%')";
  57. }
  58. $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
  59. ?>
  60. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  61. <html xmlns="http://www.w3.org/1999/xhtml">
  62. <head>
  63. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  64. <title>订单列表</title>
  65. <link rel="stylesheet" href="css/common.css" type="text/css" />
  66. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  67. <script src="js/jquery-1.7.2.min.js"></script>
  68. <script src="js/js.js"></script>
  69. <style>
  70. body {
  71. margin: 0;
  72. padding: 20px;
  73. background: #fff;
  74. }
  75. #man_zone {
  76. margin-left: 0;
  77. }
  78. .status-badge {
  79. display: inline-block;
  80. padding: 3px 8px;
  81. border-radius: 3px;
  82. font-size: 12px;
  83. color: white;
  84. }
  85. .status-0 { background-color: #999; }
  86. .status-1 { background-color: #5bc0de; }
  87. .status-2 { background-color: #337ab7; }
  88. .status-3 { background-color: #f0ad4e; }
  89. .status-4 { background-color: #5cb85c; }
  90. .status-5 { background-color: #28a745; }
  91. .payment-badge {
  92. display: inline-block;
  93. padding: 3px 8px;
  94. border-radius: 3px;
  95. font-size: 12px;
  96. color: white;
  97. }
  98. .payment-0 { background-color: #d9534f; }
  99. .payment-1 { background-color: #f0ad4e; }
  100. .payment-2 { background-color: #5cb85c; }
  101. /* Date picker styling */
  102. .date-input {
  103. padding: 5px;
  104. border: 1px solid #ccc;
  105. border-radius: 3px;
  106. }
  107. /* 新的表格样式 */
  108. .order-table {
  109. width: 100%;
  110. border-collapse: collapse;
  111. margin-bottom: 20px;
  112. }
  113. .order-table th {
  114. background-color: #f2f2f2;
  115. padding: 10px;
  116. text-align: left;
  117. border-bottom: 2px solid #ddd;
  118. font-weight: bold;
  119. }
  120. .order-table td {
  121. padding: 8px 10px;
  122. border-bottom: 1px solid #ddd;
  123. vertical-align: middle;
  124. }
  125. .order-table tr:hover {
  126. background-color: #f5f5f5;
  127. }
  128. .pagination {
  129. text-align: center;
  130. margin: 20px 0;
  131. }
  132. .pagination a {
  133. display: inline-block;
  134. padding: 5px 10px;
  135. margin: 0 3px;
  136. border: 1px solid #ddd;
  137. text-decoration: none;
  138. color: #337ab7;
  139. }
  140. .pagination a.current {
  141. background-color: #337ab7;
  142. color: white;
  143. border-color: #337ab7;
  144. }
  145. .pagination a:hover:not(.current) {
  146. background-color: #ddd;
  147. }
  148. </style>
  149. </head>
  150. <body>
  151. <div id="man_zone">
  152. <div class="fastSelect clear">
  153. <H1>筛选条件</H1>
  154. <div class="selectItem">
  155. <label>订单状态</label>
  156. <select name="fliterStatus" class="filterSearch">
  157. <option value="">全部状态</option>
  158. <option value="0"<?= $fliterStatus == "0" ? ' selected' : '' ?>>已取消</option>
  159. <option value="1"<?= $fliterStatus == "1" ? ' selected' : '' ?>>待确认</option>
  160. <option value="2"<?= $fliterStatus == "2" ? ' selected' : '' ?>>已确认</option>
  161. <option value="3"<?= $fliterStatus == "3" ? ' selected' : '' ?>>生产中</option>
  162. <option value="4"<?= $fliterStatus == "4" ? ' selected' : '' ?>>已发货</option>
  163. <option value="5"<?= $fliterStatus == "5" ? ' selected' : '' ?>>已完成</option>
  164. </select>
  165. </div>
  166. <div class="selectItem">
  167. <label>付款状态</label>
  168. <select name="fliterPayment" class="filterSearch">
  169. <option value="">全部付款状态</option>
  170. <option value="0"<?= $fliterPayment == "0" ? ' selected' : '' ?>>未付款</option>
  171. <option value="1"<?= $fliterPayment == "1" ? ' selected' : '' ?>>部分付款</option>
  172. <option value="2"<?= $fliterPayment == "2" ? ' selected' : '' ?>>已付清</option>
  173. </select>
  174. </div>
  175. <div class="selectItem">
  176. <label>客户筛选</label>
  177. <select name="fliterCustomer" class="filterSearch">
  178. <option value="">全部客户</option>
  179. <?php
  180. $employee_id = $_SESSION['employee_id'];
  181. $customerSql = "SELECT id, cs_company FROM customer WHERE cs_belong = $employee_id ORDER BY cs_company";
  182. $customerResult = mysqli_query($conn, $customerSql);
  183. while ($customerRow = mysqli_fetch_assoc($customerResult)) {
  184. $selected = ($fliterCustomer == $customerRow['id']) ? ' selected' : '';
  185. echo "<option value=\"{$customerRow['id']}\"$selected>" . htmlspecialcharsFix($customerRow['cs_company']) . "</option>";
  186. }
  187. ?>
  188. </select>
  189. </div>
  190. <div class="selectItem">
  191. <label>订单日期 从</label>
  192. <input type="date" name="fliterFromDate" class="date-input filterSearch" value="<?= $fliterFromDate ?>">
  193. <label>到</label>
  194. <input type="date" name="fliterToDate" class="date-input filterSearch" value="<?= $fliterToDate ?>">
  195. </div>
  196. <div class="inputSearch">
  197. <input type="text" id="keys" class="inputTxt"
  198. value="<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>"
  199. onFocus="if(this.value == '<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>'){this.value='';}"
  200. onBlur="if(this.value == ''){this.value='<?= empty($keyscode) ? '请输入搜索关键词' : $keyscode ?>';}"
  201. onKeyDown="if(event.keyCode==13){location.href='?Keys='+escape(document.getElementById('keys').value)}" />
  202. <input type="button" id="searchgo" class="searchgo" value="go"
  203. onClick="location.href='?Keys='+escape(document.getElementById('keys').value)" />
  204. </div>
  205. </div>
  206. <div align="right" style="margin-bottom: 10px;">
  207. <input type="button" value="新增订单" class="btn1" onClick="location.href='order_add.php'" />
  208. </div>
  209. <table class="order-table">
  210. <thead>
  211. <tr>
  212. <th>序号</th>
  213. <th>订单编号</th>
  214. <th>客户</th>
  215. <th>联系人</th>
  216. <th>订单日期</th>
  217. <th>订单状态</th>
  218. <th>付款状态</th>
  219. <th>订单金额</th>
  220. <th>操作</th>
  221. </tr>
  222. </thead>
  223. <tbody>
  224. <?php
  225. // 设置每页显示记录数
  226. $pageSize = 20;
  227. // 获取总记录数
  228. $employee_id = $_SESSION['employee_id'];
  229. $countSql = "SELECT COUNT(*) AS total FROM orders o
  230. WHERE o.employee_id = $employee_id";
  231. if (!empty($keyscode)) {
  232. $countSql .= " AND (o.order_code LIKE '%$keyscode%'
  233. OR o.customer_id IN (SELECT id FROM customer WHERE cs_company LIKE '%$keyscode%'))";
  234. }
  235. $countSql .= $fliterStr;
  236. $countResult = mysqli_query($conn, $countSql);
  237. $countRow = mysqli_fetch_assoc($countResult);
  238. $totalRecords = $countRow['total'];
  239. // 计算总页数
  240. $totalPages = ceil($totalRecords / $pageSize);
  241. if ($totalPages < 1) $totalPages = 1;
  242. // 验证当前页码
  243. $page = (int)$page;
  244. if ($page < 1) $page = 1;
  245. if ($page > $totalPages) $page = $totalPages;
  246. // 计算起始记录
  247. $offset = ($page - 1) * $pageSize;
  248. // 添加分页条件
  249. $sqlStr .= " LIMIT $offset, $pageSize";
  250. $result = mysqli_query($conn, $sqlStr);
  251. if (mysqli_num_rows($result) > 0) {
  252. $tempNum = ($page - 1) * $pageSize;
  253. while ($row = mysqli_fetch_assoc($result)) {
  254. $tempNum++;
  255. ?>
  256. <tr>
  257. <td><?= $tempNum ?></td>
  258. <td><?= htmlspecialcharsFix($row['order_code']) ?></td>
  259. <td><?= htmlspecialcharsFix($row['cs_company']) ?></td>
  260. <td><?= htmlspecialcharsFix($row['contact_name']) ?></td>
  261. <td><?= date('Y-m-d', strtotime($row['order_date'])) ?></td>
  262. <td>
  263. <?php
  264. $statusMap = [
  265. 0 => '已取消',
  266. 1 => '待确认',
  267. 2 => '已确认',
  268. 3 => '生产中',
  269. 4 => '已发货',
  270. 5 => '已完成'
  271. ];
  272. echo '<span class="status-badge status-' . $row['order_status'] . '">' .
  273. $statusMap[$row['order_status']] . '</span>';
  274. ?>
  275. </td>
  276. <td>
  277. <?php
  278. $paymentMap = [
  279. 0 => '未付款',
  280. 1 => '部分付款',
  281. 2 => '已付清'
  282. ];
  283. echo '<span class="payment-badge payment-' . $row['payment_status'] . '">' .
  284. $paymentMap[$row['payment_status']] . '</span>';
  285. ?>
  286. </td>
  287. <td><?= number_format($row['total_amount'], 2) . ' ' . $row['currency'] ?></td>
  288. <td>
  289. <a href="order_edit.php?id=<?= $row['id'] ?>&keys=<?= $keys ?>&page=<?= $page ?>" class="ico_edit ico">修改</a>
  290. <a href="order_details.php?id=<?= $row['id'] ?>" class="ico_view ico">查看详情</a>
  291. </td>
  292. </tr>
  293. <?php
  294. }
  295. } else {
  296. if (empty($keys) && empty($fliterStr)) {
  297. echo '<tr><td colspan="9" align="center">当前暂无订单记录</td></tr>';
  298. } else {
  299. echo '<tr><td colspan="9" align="center"><a href="?">没有找到匹配的订单记录,点击返回</a></td></tr>';
  300. }
  301. }
  302. ?>
  303. </tbody>
  304. </table>
  305. <div class="pagination">
  306. <?php
  307. if ($totalPages > 1) {
  308. $pageName = "?Keys=$keys$urlStr&";
  309. $pageLen = 3;
  310. if ($page > 1) {
  311. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  312. echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
  313. }
  314. if ($pageLen * 2 + 1 >= $totalPages) {
  315. $startPage = 1;
  316. $endPage = $totalPages;
  317. } else {
  318. if ($page <= $pageLen + 1) {
  319. $startPage = 1;
  320. $endPage = $pageLen * 2 + 1;
  321. } else {
  322. $startPage = $page - $pageLen;
  323. $endPage = $page + $pageLen;
  324. }
  325. if ($page + $pageLen > $totalPages) {
  326. $startPage = $totalPages - $pageLen * 2;
  327. $endPage = $totalPages;
  328. }
  329. }
  330. for ($i = $startPage; $i <= $endPage; $i++) {
  331. if ($i == $page) {
  332. echo "<a class=\"current\">$i</a>";
  333. } else {
  334. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  335. }
  336. }
  337. if ($page < $totalPages) {
  338. if ($totalPages - $page > $pageLen) {
  339. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  340. }
  341. echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
  342. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  343. }
  344. }
  345. ?>
  346. </div>
  347. <script>
  348. $(document).ready(function() {
  349. // 处理筛选条件改变
  350. $('.filterSearch').change(function() {
  351. var url = '?';
  352. var keys = $('#keys').val();
  353. if (keys && keys != '请输入搜索关键词') {
  354. url += 'Keys=' + encodeURIComponent(keys) + '&';
  355. }
  356. $('.filterSearch').each(function() {
  357. var name = $(this).attr('name');
  358. var value = $(this).val();
  359. if (value) {
  360. url += name + '=' + encodeURIComponent(value) + '&';
  361. }
  362. });
  363. // 移除末尾的&
  364. if (url.endsWith('&')) {
  365. url = url.substring(0, url.length - 1);
  366. }
  367. location.href = url;
  368. });
  369. });
  370. </script>
  371. </div>
  372. </body>
  373. </html>