order.php 13 KB

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