order.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. // 辅助函数
  5. $act = $_GET['act'] ?? '';
  6. $urlStr = '';
  7. // 处理筛选条件
  8. $fliterFromDate = $_GET['fliterFromDate'] ?? '';
  9. $fliterToDate = $_GET['fliterToDate'] ?? '';
  10. $fliterStr = "";
  11. if (!empty($fliterFromDate)) {
  12. $fliterStr .= " AND o.order_date >= '" . mysqli_real_escape_string($conn, $fliterFromDate) . "'";
  13. $urlStr .= "&fliterFromDate=" . urlencode($fliterFromDate);
  14. }
  15. if (!empty($fliterToDate)) {
  16. $fliterStr .= " AND o.order_date <= '" . mysqli_real_escape_string($conn, $fliterToDate) . " 23:59:59'";
  17. $urlStr .= "&fliterToDate=" . urlencode($fliterToDate);
  18. }
  19. // 搜索和排序
  20. $keys = $_GET['Keys'] ?? '';
  21. $keyscode = mysqli_real_escape_string($conn, $keys);
  22. $page = $_GET['Page'] ?? 1;
  23. $ord = $_GET['Ord'] ?? '';
  24. $ordStr = !empty($ord) ? "$ord," : "";
  25. // 构建查询SQL
  26. $employee_id = $_SESSION['employee_id'];
  27. $isAdmin = checkIfAdmin();
  28. $sqlStr = "SELECT o.*, c.cs_company, c.cs_code,
  29. DATEDIFF(NOW(), o.created_at) as days_diff
  30. FROM orders o
  31. LEFT JOIN customer c ON o.customer_id = c.id
  32. WHERE 1=1";
  33. // 非管理员只能查看自己的订单
  34. if (!$isAdmin) {
  35. $sqlStr .= " AND o.employee_id = $employee_id";
  36. }
  37. if (!empty($keyscode)) {
  38. $sqlStr .= " AND (o.order_code LIKE '%$keyscode%'
  39. OR c.cs_company LIKE '%$keyscode%'
  40. OR c.cs_code LIKE '%$keyscode%')";
  41. }
  42. $sqlStr .= " $fliterStr ORDER BY {$ordStr}o.created_at DESC";
  43. ?>
  44. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  45. <html xmlns="http://www.w3.org/1999/xhtml">
  46. <head>
  47. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  48. <title>订单列表</title>
  49. <link rel="stylesheet" href="css/common.css" type="text/css" />
  50. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  51. <script src="js/jquery-1.7.2.min.js"></script>
  52. <script src="js/js.js"></script>
  53. <style>
  54. body {
  55. margin: 0;
  56. padding: 20px;
  57. background: #fff;
  58. }
  59. #man_zone {
  60. margin-left: 0;
  61. }
  62. /* 表格布局修复 */
  63. .table2 {
  64. width: 100%;
  65. }
  66. .theader, .tline {
  67. display: flex;
  68. flex-direction: row;
  69. align-items: center;
  70. width: 100%;
  71. border-bottom: 1px solid #ddd;
  72. }
  73. .theader {
  74. background-color: #f2f2f2;
  75. font-weight: bold;
  76. height: 40px;
  77. }
  78. .tline {
  79. height: 45px;
  80. }
  81. .tline:hover {
  82. background-color: #f5f5f5;
  83. }
  84. .col2 { width: 5%; text-align: center; }
  85. .col3 { width: 10%; }
  86. .col4 { width: 20%; }
  87. .col5 { width: 30%; }
  88. .col7 { width: 16%; }
  89. .col9 { width: 14%; text-align: right; }
  90. .col10 { width: 16%; text-align: center; }
  91. /* 表格布局修复,因为 "css/common.css 覆盖了 */
  92. .table2 .col2 { width: 5%; text-align: center; }
  93. .table2 .col3 { width: 10%; }
  94. .table2 .col4 { width: 20%; }
  95. .table2 .col5 { width: 30%; }
  96. .table2 .col7 { width: 16%; }
  97. .table2 .col9 { width: 14%; text-align: right; }
  98. .table2 .col10 { width: 16%; text-align: center; }
  99. .theader > div, .tline > div {
  100. padding: 0 5px;
  101. overflow: hidden;
  102. text-overflow: ellipsis;
  103. white-space: nowrap;
  104. }
  105. /* 日期选择器样式 */
  106. .date-input {
  107. padding: 5px;
  108. border: 1px solid #ccc;
  109. border-radius: 3px;
  110. }
  111. /* 滑动面板样式 */
  112. .slidepanel {
  113. cursor: pointer;
  114. }
  115. .slidepanel.open {
  116. font-weight: bold;
  117. color: #3366cc;
  118. }
  119. .notepanel {
  120. display: none;
  121. background: #f9f9f9;
  122. padding: 10px;
  123. border: 1px solid #eee;
  124. margin-bottom: 10px;
  125. }
  126. .notepanel .noteItem {
  127. font-weight: bold;
  128. margin-bottom: 5px;
  129. }
  130. .notepanel .noteItem2 {
  131. font-weight: bold;
  132. margin-bottom: 5px;
  133. }
  134. .lx {
  135. display: flex;
  136. flex-wrap: wrap;
  137. gap: 15px;
  138. }
  139. .lx > div {
  140. margin-bottom: 10px;
  141. }
  142. .lx > div > div {
  143. margin-bottom: 5px;
  144. }
  145. /* 按钮样式 */
  146. .ico_del {
  147. color: #e74c3c;
  148. }
  149. .ico_del:hover {
  150. color: #c0392b;
  151. }
  152. </style>
  153. </head>
  154. <body>
  155. <div id="man_zone">
  156. <div class="fastSelect clear">
  157. <H1>筛选条件</H1>
  158. <div class="selectItem">
  159. <label>出货日期</label>
  160. <input type="date" name="fliterFromDate" class="date-input filterSearch" value="<?= $fliterFromDate ?>">
  161. <label>到</label>
  162. <input type="date" name="fliterToDate" class="date-input filterSearch" value="<?= $fliterToDate ?>">
  163. </div>
  164. <div class="inputSearch" >
  165. <input type="text" id="keys" class="inputTxt" placeholder="请输入搜索关键词"
  166. value="<?= empty($keyscode) ? '' : $keyscode ?>" />
  167. <input type="button" id="searchgo" class="searchgo" value="搜索"
  168. onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
  169. </div>
  170. </div>
  171. <div align="right" style="margin-bottom: 10px;">
  172. <input type="button" value="新增订单" class="btn1" onClick="location.href='order_add.php'" />
  173. </div>
  174. <div class="table2 em<?= $_SESSION['employee_id'] ?>">
  175. <div class="theader">
  176. <div class="col2">序号</div>
  177. <div class="col3">销售开单号</div>
  178. <div class="col4">客户编码</div>
  179. <div class="col5">客户</div>
  180. <div class="col7">出货日期</div>
  181. <div class="col9">订单金额</div>
  182. <div class="col10">操作</div>
  183. </div>
  184. <?php
  185. // 设置每页显示记录数
  186. $pageSize = 20;
  187. // 获取总记录数
  188. $employee_id = $_SESSION['employee_id'];
  189. $countSql = "SELECT COUNT(*) AS total FROM orders o
  190. LEFT JOIN customer c ON o.customer_id = c.id
  191. WHERE 1=1";
  192. // 非管理员只能查看自己的订单
  193. if (!$isAdmin) {
  194. $countSql .= " AND o.employee_id = $employee_id";
  195. }
  196. if (!empty($keyscode)) {
  197. $countSql .= " AND (o.order_code LIKE '%$keyscode%'
  198. OR c.cs_company LIKE '%$keyscode%'
  199. OR c.cs_code LIKE '%$keyscode%')";
  200. }
  201. $countSql .= $fliterStr;
  202. $countResult = mysqli_query($conn, $countSql);
  203. $countRow = mysqli_fetch_assoc($countResult);
  204. $totalRecords = $countRow['total'];
  205. // 计算总页数
  206. $totalPages = ceil($totalRecords / $pageSize);
  207. if ($totalPages < 1) $totalPages = 1;
  208. // 验证当前页码
  209. $page = (int)$page;
  210. if ($page < 1) $page = 1;
  211. if ($page > $totalPages) $page = $totalPages;
  212. // 计算起始记录
  213. $offset = ($page - 1) * $pageSize;
  214. // 添加分页条件
  215. $sqlStr .= " LIMIT $offset, $pageSize";
  216. $result = mysqli_query($conn, $sqlStr);
  217. if (mysqli_num_rows($result) > 0) {
  218. $tempNum = ($page - 1) * $pageSize;
  219. while ($row = mysqli_fetch_assoc($result)) {
  220. $tempNum++;
  221. ?>
  222. <div class="tline">
  223. <div class="col2"><?= $tempNum ?></div>
  224. <div class="col3 slidepanel"><?= htmlspecialcharsFix($row['order_code']) ?></div>
  225. <div class="col4"><?= htmlspecialcharsFix($row['cs_code']) ?></div>
  226. <div class="col5"><?= htmlspecialcharsFix($row['cs_company']) ?></div>
  227. <div class="col7"><?= date('Y-m-d', strtotime($row['order_date'])) ?></div>
  228. <div class="col9"><?= number_format($row['total_amount'], 2) ?></div>
  229. <div class="col10">
  230. <?php if ($isAdmin || $row['days_diff'] <= 30): ?>
  231. <a href="order_edit.php?id=<?= $row['id'] ?>&keys=<?= $keys ?>&page=<?= $page ?>" class="ico_edit ico">修改</a>
  232. <?php endif; ?>
  233. <a href="order_details.php?id=<?= $row['id'] ?>" class="ico_view ico">查看详情</a>
  234. <?php if ($isAdmin): ?>
  235. <a href="javascript:void(0)" onclick="confirmDelete(<?= $row['id'] ?>, '<?= htmlspecialcharsFix($row['order_code']) ?>')" class="ico_del ico">删除</a>
  236. <?php endif; ?>
  237. </div>
  238. </div>
  239. <div class="notepanel clear">
  240. <div class="noteItem">订单详情</div>
  241. <div class="lx">
  242. <div><strong>总金额:</strong> <?= number_format($row['total_amount'], 2) ?></div>
  243. <!-- <div class="price-details">-->
  244. <!-- <div><strong>小计:</strong> --><?php //= number_format($row['subtotal'], 2) ?><!--</div>-->
  245. <!-- <div><strong>折扣金额:</strong> --><?php //= number_format($row['discount_amount'], 2) ?><!--</div>-->
  246. <!-- </div>-->
  247. </div>
  248. <div class="noteItem2">备注</div>
  249. <div class="notecontent"><?= htmlspecialcharsFix($row['notes']) ?></div>
  250. </div>
  251. <?php
  252. }
  253. } else {
  254. if (empty($keys) && empty($fliterStr)) {
  255. echo '<div class="tline"><div align="center" colspan="9">当前暂无订单记录</div></div>';
  256. } else {
  257. echo '<div class="tline"><div align="center" colspan="9"><a href="?">没有找到匹配的订单记录,点击返回</a></div></div>';
  258. }
  259. }
  260. ?>
  261. <div class="showpagebox">
  262. <?php
  263. if ($totalPages > 1) {
  264. $pageName = "?Keys=$keys$urlStr&";
  265. $pageLen = 3;
  266. if ($page > 1) {
  267. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  268. echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
  269. }
  270. if ($pageLen * 2 + 1 >= $totalPages) {
  271. $startPage = 1;
  272. $endPage = $totalPages;
  273. } else {
  274. if ($page <= $pageLen + 1) {
  275. $startPage = 1;
  276. $endPage = $pageLen * 2 + 1;
  277. } else {
  278. $startPage = $page - $pageLen;
  279. $endPage = $page + $pageLen;
  280. }
  281. if ($page + $pageLen > $totalPages) {
  282. $startPage = $totalPages - $pageLen * 2;
  283. $endPage = $totalPages;
  284. }
  285. }
  286. for ($i = $startPage; $i <= $endPage; $i++) {
  287. if ($i == $page) {
  288. echo "<a class=\"current\">$i</a>";
  289. } else {
  290. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  291. }
  292. }
  293. if ($page < $totalPages) {
  294. if ($totalPages - $page > $pageLen) {
  295. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  296. }
  297. echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
  298. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  299. }
  300. }
  301. ?>
  302. </div>
  303. </div>
  304. <script>
  305. $(document).ready(function() {
  306. // 添加日期验证逻辑
  307. $('input[name="fliterToDate"]').on('change', function() {
  308. var fromDate = $('input[name="fliterFromDate"]').val();
  309. var toDate = $(this).val();
  310. if (fromDate && toDate && new Date(toDate) < new Date(fromDate)) {
  311. alert('结束日期不能早于开始日期');
  312. $(this).val(''); // 清空结束日期
  313. return false;
  314. }
  315. });
  316. // 开始日期变更时也进行验证
  317. $('input[name="fliterFromDate"]').on('change', function() {
  318. var fromDate = $(this).val();
  319. var toDate = $('input[name="fliterToDate"]').val();
  320. if (fromDate && toDate && new Date(toDate) < new Date(fromDate)) {
  321. alert('开始日期不能晚于结束日期');
  322. $('input[name="fliterToDate"]').val(''); // 清空结束日期
  323. return false;
  324. }
  325. });
  326. // 处理筛选条件改变
  327. $('.filterSearch').change(function() {
  328. var url = '?';
  329. var keys = $('#keys').val();
  330. if (keys && keys != '请输入搜索关键词') {
  331. url += 'Keys=' + encodeURIComponent(keys) + '&';
  332. }
  333. $('.filterSearch').each(function() {
  334. var name = $(this).attr('name');
  335. var value = $(this).val();
  336. if (value) {
  337. url += name + '=' + encodeURIComponent(value) + '&';
  338. }
  339. });
  340. // 移除末尾的&
  341. if (url.endsWith('&')) {
  342. url = url.substring(0, url.length - 1);
  343. }
  344. location.href = url;
  345. });
  346. });
  347. </script>
  348. <script>
  349. function confirmDelete(id, orderCode) {
  350. if (confirm("确定要删除订单 " + orderCode + " 吗?此操作不可恢复!")) {
  351. window.location.href = "order_delete.php?id=" + id + "&keys=<?= urlencode($keys) ?>&page=<?= $page ?>";
  352. }
  353. }
  354. </script>
  355. </div>
  356. </body>
  357. </html>