rebate_history.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. <?php
  2. require_once 'conn.php';
  3. checkLogin();
  4. // 辅助函数
  5. $urlStr = '';
  6. // 处理筛选条件
  7. $fliterFromDate = $_GET['fliterFromDate'] ?? '';
  8. $fliterToDate = $_GET['fliterToDate'] ?? '';
  9. $fliterStr = "";
  10. if (!empty($fliterFromDate)) {
  11. $fliterStr .= " AND rr.redemption_date >= '" . mysqli_real_escape_string($conn, $fliterFromDate) . "'";
  12. $urlStr .= "&fliterFromDate=" . urlencode($fliterFromDate);
  13. }
  14. if (!empty($fliterToDate)) {
  15. $fliterStr .= " AND rr.redemption_date <= '" . mysqli_real_escape_string($conn, $fliterToDate) . " 23:59:59'";
  16. $urlStr .= "&fliterToDate=" . urlencode($fliterToDate);
  17. }
  18. // 搜索参数
  19. $keys = $_GET['Keys'] ?? '';
  20. $keyscode = mysqli_real_escape_string($conn, $keys);
  21. $page = isset($_GET['Page']) ? intval($_GET['Page']) : 1;
  22. // 构建基本条件SQL
  23. $employee_id = $_SESSION['employee_id'];
  24. $isAdmin = checkIfAdmin();
  25. // 检查是否为财务角色或管理员
  26. $isFinance = false;
  27. $checkRoleSql = "SELECT em_permission_role_id FROM employee WHERE id = $employee_id";
  28. $roleResult = mysqli_query($conn, $checkRoleSql);
  29. if ($roleResult && $row = mysqli_fetch_assoc($roleResult)) {
  30. $isFinance = ($row['em_permission_role_id'] == 6 || $row['em_permission_role_id'] == 1);
  31. }
  32. // 基础查询,计算总记录数
  33. $countSql = "SELECT COUNT(*) AS total
  34. FROM rebate_redemptions rr
  35. JOIN customer c ON rr.customer_id = c.id
  36. LEFT JOIN employee e ON rr.created_by = e.id
  37. WHERE 1=1";
  38. // 非管理员和非财务只能查看自己客户的返点历史
  39. if (!$isAdmin && !$isFinance) {
  40. $countSql .= " AND c.cs_belong = $employee_id";
  41. }
  42. // 添加搜索条件
  43. if (!empty($keyscode)) {
  44. $countSql .= " AND (c.cs_company LIKE '%$keyscode%' OR c.cs_code LIKE '%$keyscode%' OR e.em_user LIKE '%$keyscode%')";
  45. }
  46. // 添加日期筛选
  47. $countSql .= $fliterStr;
  48. // 执行查询获取总记录数
  49. $countResult = mysqli_query($conn, $countSql);
  50. if (!$countResult) {
  51. die("查询记录数量错误: " . mysqli_error($conn));
  52. }
  53. $countRow = mysqli_fetch_assoc($countResult);
  54. $totalRecords = $countRow['total'];
  55. // 设置每页显示记录数和分页
  56. $pageSize = 20;
  57. // 计算总页数
  58. $totalPages = ceil($totalRecords / $pageSize);
  59. if ($totalPages < 1) $totalPages = 1;
  60. // 验证当前页码
  61. if ($page < 1) $page = 1;
  62. if ($page > $totalPages) $page = $totalPages;
  63. // 计算起始记录
  64. $offset = ($page - 1) * $pageSize;
  65. // 查询返点兑换历史记录
  66. $sql = "SELECT
  67. rr.id AS redemption_id,
  68. rr.customer_id,
  69. c.cs_code,
  70. c.cs_company AS customer_name,
  71. rr.redemption_date,
  72. rr.total_rebate_amount,
  73. rr.notes,
  74. rr.status,
  75. rr.examine_status,
  76. rr.examine_date,
  77. e.em_user AS employee_name,
  78. e2.em_user AS examine_by_name,
  79. (SELECT COUNT(DISTINCT product_id) FROM rebate_redemption_items WHERE redemption_id = rr.id) AS product_count
  80. FROM
  81. rebate_redemptions rr
  82. JOIN
  83. customer c ON rr.customer_id = c.id
  84. LEFT JOIN
  85. employee e ON rr.created_by = e.id
  86. LEFT JOIN
  87. employee e2 ON rr.examine_by = e2.id
  88. WHERE
  89. 1=1";
  90. // 非管理员和非财务只能查看自己客户的返点历史
  91. if (!$isAdmin && !$isFinance) {
  92. $sql .= " AND c.cs_belong = $employee_id";
  93. }
  94. // 添加搜索条件
  95. if (!empty($keyscode)) {
  96. $sql .= " AND (c.cs_company LIKE '%$keyscode%' OR c.cs_code LIKE '%$keyscode%' OR e.em_user LIKE '%$keyscode%')";
  97. }
  98. // 添加日期筛选
  99. $sql .= $fliterStr;
  100. // 添加排序和分页
  101. $sql .= " ORDER BY rr.redemption_date DESC, rr.id DESC LIMIT $offset, $pageSize";
  102. $result = mysqli_query($conn, $sql);
  103. if (!$result) {
  104. die("查询返点历史错误: " . mysqli_error($conn));
  105. }
  106. // 获取返点历史记录
  107. $redemptions = [];
  108. while ($row = mysqli_fetch_assoc($result)) {
  109. $redemptions[] = $row;
  110. }
  111. // 处理审核操作
  112. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'examine' && $isFinance) {
  113. $redemptionId = isset($_POST['redemption_id']) ? intval($_POST['redemption_id']) : 0;
  114. $examineStatus = isset($_POST['examine_status']) ? intval($_POST['examine_status']) : 0;
  115. if ($redemptionId > 0 && in_array($examineStatus, [1, 2])) {
  116. $updateSql = "UPDATE rebate_redemptions
  117. SET examine_status = $examineStatus,
  118. examine_date = NOW(),
  119. examine_by = $employee_id
  120. WHERE id = $redemptionId";
  121. if (mysqli_query($conn, $updateSql)) {
  122. // 刷新页面以显示更新后的状态
  123. echo "<script>window.location.href = window.location.href;</script>";
  124. exit;
  125. } else {
  126. echo "<script>alert('审核操作失败: " . mysqli_error($conn) . "');</script>";
  127. }
  128. }
  129. }
  130. ?>
  131. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  132. <html xmlns="http://www.w3.org/1999/xhtml">
  133. <head>
  134. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  135. <title>客户返点历史</title>
  136. <link rel="stylesheet" href="css/common.css" type="text/css" />
  137. <link rel="stylesheet" href="css/alert.css" type="text/css" />
  138. <script src="js/jquery-1.7.2.min.js"></script>
  139. <script src="js/js.js"></script>
  140. <style>
  141. body {
  142. margin: 0;
  143. padding: 20px;
  144. background: #fff;
  145. }
  146. #man_zone {
  147. margin-left: 0;
  148. }
  149. /* 表格布局 */
  150. .table2 {
  151. width: 100%;
  152. }
  153. .theader, .tline {
  154. display: flex;
  155. flex-direction: row;
  156. align-items: center;
  157. width: 100%;
  158. border-bottom: 1px solid #ddd;
  159. }
  160. .theader {
  161. background-color: #f2f2f2;
  162. font-weight: bold;
  163. height: 40px;
  164. }
  165. .tline {
  166. height: 45px;
  167. }
  168. .tline:hover {
  169. background-color: #f5f5f5;
  170. }
  171. .col2 { width: 5%; text-align: center; }
  172. .col3 { width: 15%; }
  173. .col4 { width: 12%; text-align: center; }
  174. .col5 { width: 8%; text-align: center; }
  175. .col6 { width: 15%; text-align: right; }
  176. .col7 { width: 10%; text-align: center; }
  177. .col8 { width: 15%; text-align: center; }
  178. .col9 { width: 15%; text-align: center; }
  179. /* 表格布局修复 */
  180. .table2 .col2 { width: 5%; text-align: center; }
  181. .table2 .col3 { width: 15%; }
  182. .table2 .col4 { width: 12%; text-align: center; }
  183. .table2 .col5 { width: 8%; text-align: center; }
  184. .table2 .col6 { width: 15%; text-align: right; }
  185. .table2 .col7 { width: 10%; text-align: center; }
  186. .table2 .col8 { width: 15%; text-align: center; }
  187. .table2 .col9 { width: 15%; text-align: center; }
  188. .theader > div, .tline > div {
  189. padding: 0 5px;
  190. overflow: hidden;
  191. text-overflow: ellipsis;
  192. white-space: nowrap;
  193. display: flex;
  194. align-items: center;
  195. justify-content: center;
  196. }
  197. .col3 {
  198. justify-content: flex-start !important;
  199. }
  200. .col7 {
  201. justify-content: flex-end !important;
  202. }
  203. /* 日期选择器样式 */
  204. .date-input {
  205. padding: 5px;
  206. border: 1px solid #ccc;
  207. border-radius: 3px;
  208. }
  209. /* 滑动面板样式 */
  210. .rb-slidepanel {
  211. cursor: pointer;
  212. }
  213. .rb-slidepanel.open {
  214. font-weight: bold;
  215. color: #3366cc;
  216. }
  217. .notepanel {
  218. display: none;
  219. background: #f9f9f9;
  220. padding: 10px;
  221. border: 1px solid #eee;
  222. margin-bottom: 10px;
  223. }
  224. .notepanel .noteItem {
  225. font-weight: bold;
  226. margin-bottom: 5px;
  227. }
  228. .rebate-details {
  229. margin-top: 10px;
  230. border-top: 1px dashed #ddd;
  231. padding-top: 10px;
  232. }
  233. /* 状态样式 */
  234. .status-active {
  235. color: #27ae60;
  236. font-weight: bold;
  237. }
  238. .status-cancelled {
  239. color: #e74c3c;
  240. text-decoration: line-through;
  241. }
  242. /* 审核状态样式 */
  243. .examine-pending {
  244. color: #f39c12;
  245. font-weight: bold;
  246. }
  247. .examine-approved {
  248. color: #27ae60;
  249. font-weight: bold;
  250. }
  251. .examine-rejected {
  252. color: #e74c3c;
  253. font-weight: bold;
  254. }
  255. /* 备注文本溢出控制 */
  256. .notes-text {
  257. max-width: 200px;
  258. white-space: nowrap;
  259. overflow: hidden;
  260. text-overflow: ellipsis;
  261. display: inline-block;
  262. }
  263. /* 审核操作按钮 */
  264. .examine-btn {
  265. display: inline-block;
  266. padding: 3px 8px;
  267. margin: 0 2px;
  268. border-radius: 3px;
  269. cursor: pointer;
  270. text-decoration: none;
  271. font-size: 12px;
  272. color: white;
  273. box-sizing: border-box;
  274. height: 24px;
  275. line-height: 18px;
  276. vertical-align: middle;
  277. }
  278. .export-btn {
  279. display: inline-block;
  280. padding: 3px 8px;
  281. margin: 0 2px;
  282. border-radius: 3px;
  283. cursor: pointer;
  284. text-decoration: none;
  285. font-size: 12px;
  286. color: white;
  287. box-sizing: border-box;
  288. height: 24px;
  289. line-height: 18px;
  290. vertical-align: middle;
  291. }
  292. .approve-btn {
  293. background-color: #0f9d58; /* 绿色 */
  294. }
  295. .reject-btn {
  296. background-color: #db4437; /* 红色 */
  297. }
  298. .examine-btn:hover {
  299. opacity: 0.9;
  300. }
  301. /* 模态窗口样式 */
  302. .modal {
  303. display: none;
  304. position: fixed;
  305. z-index: 1000;
  306. left: 0;
  307. top: 0;
  308. width: 100%;
  309. height: 100%;
  310. background-color: rgba(0,0,0,0.5);
  311. }
  312. .modal-content {
  313. background-color: #fefefe;
  314. margin: 15% auto;
  315. padding: 20px;
  316. border: 1px solid #888;
  317. width: 300px;
  318. border-radius: 5px;
  319. text-align: center;
  320. }
  321. .modal-buttons {
  322. margin-top: 20px;
  323. display: flex;
  324. justify-content: center;
  325. }
  326. .modal-btn {
  327. padding: 5px 15px;
  328. margin: 0 5px;
  329. border-radius: 3px;
  330. cursor: pointer;
  331. display: inline-block;
  332. min-width: 60px;
  333. height: 30px;
  334. line-height: 20px;
  335. text-align: center;
  336. font-size: 14px;
  337. border: none;
  338. }
  339. .confirm-btn {
  340. background-color: #3498db;
  341. color: white;
  342. }
  343. .cancel-btn {
  344. background-color: #95a5a6;
  345. color: white;
  346. }
  347. </style>
  348. </head>
  349. <body>
  350. <div id="man_zone">
  351. <div class="fastSelect clear">
  352. <H1>客户返点历史查询</H1>
  353. <div class="selectItem">
  354. <label>兑换日期</label>
  355. <input type="date" name="fliterFromDate" class="date-input filterSearch" value="<?= $fliterFromDate ?>">
  356. <label>到</label>
  357. <input type="date" name="fliterToDate" class="date-input filterSearch" value="<?= $fliterToDate ?>">
  358. </div>
  359. <div class="inputSearch">
  360. <input type="text" id="keys" class="inputTxt" placeholder="请输入客户名称、编码或处理人"
  361. value="<?= empty($keyscode) ? '' : $keyscode ?>" />
  362. <input type="button" id="searchgo" class="searchgo" value="搜索"
  363. onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
  364. </div>
  365. <div style="text-align: right; margin-top: 10px; clear: both;">
  366. <a href="rebate_expiring.php" class="btn1" style="display: inline-flex; align-items: center; justify-content: center; padding: 5px 15px; margin-top: 0; height: 22px; background-color: #e74c3c; margin-right: 5px;">查看过期预警</a>
  367. <a href="rebate_summary.php" class="btn1" style="display: inline-flex; align-items: center; justify-content: center; padding: 5px 15px; margin-top: 0; height: 22px;">返回返点统计</a>
  368. </div>
  369. </div>
  370. <div class="table2 em<?= $_SESSION['employee_id'] ?>">
  371. <div class="theader">
  372. <div class="col2">序号</div>
  373. <div class="col3">客户编码</div>
  374. <div class="col4">兑换日期</div>
  375. <div class="col5">产品数</div>
  376. <div class="col6">返点金额</div>
  377. <div class="col7">处理人</div>
  378. <div class="col8">审核状态</div>
  379. <div class="col9">操作</div>
  380. </div>
  381. <?php
  382. if (!empty($redemptions)) {
  383. $tempNum = ($page - 1) * $pageSize;
  384. foreach ($redemptions as $redemption) {
  385. $tempNum++;
  386. $statusClass = $redemption['status'] == 1 ? 'status-active' : 'status-cancelled';
  387. // 审核状态
  388. $examineStatusText = '未审核';
  389. $examineStatusClass = 'examine-pending';
  390. if ($redemption['examine_status'] == 1) {
  391. $examineStatusText = '已通过';
  392. $examineStatusClass = 'examine-approved';
  393. } elseif ($redemption['examine_status'] == 2) {
  394. $examineStatusText = '已拒绝';
  395. $examineStatusClass = 'examine-rejected';
  396. }
  397. ?>
  398. <div class="tline">
  399. <div class="col2"><?= $tempNum ?></div>
  400. <div class="col3 rb-slidepanel" data-id="<?= $redemption['redemption_id'] ?>" title="<?= htmlspecialcharsFix($redemption['cs_code']) ?>"><?= htmlspecialcharsFix($redemption['cs_code']) ?></div>
  401. <div class="col4"><?= date('Y-m-d', strtotime($redemption['redemption_date'])) ?></div>
  402. <div class="col5"><?= $redemption['product_count'] ?></div>
  403. <div class="col6 <?= $statusClass ?>"><?= number_format($redemption['total_rebate_amount'], 2) ?> 元</div>
  404. <div class="col7"><?= htmlspecialcharsFix($redemption['employee_name']) ?></div>
  405. <div class="col8 <?= $examineStatusClass ?>">
  406. <?= $examineStatusText ?>
  407. <?php if ($redemption['examine_status'] > 0 && !empty($redemption['examine_by_name'])): ?>
  408. <!-- <div style="font-size: 12px; color: #666; margin-top: 2px;">
  409. <?= htmlspecialcharsFix($redemption['examine_by_name']) ?>
  410. <br><?= date('m-d H:i', strtotime($redemption['examine_date'])) ?>
  411. </div> -->
  412. <?php endif; ?>
  413. </div>
  414. <div class="col9">
  415. <a href="javascript:void(0)" class="rb-toggleDetail" data-id="<?= $redemption['redemption_id'] ?>">查看详情</a>
  416. <?php if ($isFinance && $redemption['examine_status'] == 0 && $redemption['status'] == 1): ?>
  417. <span style="margin-left: 5px; display: inline-block;">
  418. <a href="javascript:void(0)" class="examine-btn approve-btn"
  419. data-id="<?= $redemption['redemption_id'] ?>" data-status="1">通过</a>
  420. <a href="javascript:void(0)" class="examine-btn reject-btn"
  421. data-id="<?= $redemption['redemption_id'] ?>" data-status="2">拒绝</a>
  422. <a href="javascript:void(0)" class="export-btn" style="background-color: #3498db;"
  423. data-id="<?= $redemption['redemption_id'] ?>">导出CSV</a>
  424. </span>
  425. <?php endif; ?>
  426. </div>
  427. </div>
  428. <div class="notepanel clear" id="detail-<?= $redemption['redemption_id'] ?>">
  429. <div class="noteItem">返点详情</div>
  430. <?php if (!empty($redemption['notes'])): ?>
  431. <div style="margin-bottom: 10px; color: #666;">
  432. <strong>备注:</strong> <?= htmlspecialcharsFix($redemption['notes']) ?>
  433. </div>
  434. <?php endif; ?>
  435. <div class="rebate-details" id="rebate-details-<?= $redemption['redemption_id'] ?>">
  436. <div style="text-align: center; padding: 10px;">
  437. <img src="images/loading.gif" alt="加载中" style="width: 20px; height: 20px;">
  438. 加载返点详情...
  439. </div>
  440. </div>
  441. </div>
  442. <?php
  443. }
  444. } else {
  445. if (empty($keys) && empty($fliterStr)) {
  446. echo '<div class="tline"><div style="width: 100%; text-align: center;">当前没有返点历史记录</div></div>';
  447. } else {
  448. echo '<div class="tline"><div style="width: 100%; text-align: center;"><a href="?">没有找到匹配的返点历史记录,点击返回</a></div></div>';
  449. }
  450. }
  451. ?>
  452. <div class="showpagebox">
  453. <?php
  454. if ($totalPages > 1) {
  455. $pageName = "?Keys=$keys$urlStr&";
  456. $pageLen = 3;
  457. if ($page > 1) {
  458. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  459. echo "<a href=\"{$pageName}Page=" . ($page - 1) . "\">上一页</a>";
  460. }
  461. if ($pageLen * 2 + 1 >= $totalPages) {
  462. $startPage = 1;
  463. $endPage = $totalPages;
  464. } else {
  465. if ($page <= $pageLen + 1) {
  466. $startPage = 1;
  467. $endPage = $pageLen * 2 + 1;
  468. } else {
  469. $startPage = $page - $pageLen;
  470. $endPage = $page + $pageLen;
  471. }
  472. if ($page + $pageLen > $totalPages) {
  473. $startPage = $totalPages - $pageLen * 2;
  474. $endPage = $totalPages;
  475. }
  476. }
  477. for ($i = $startPage; $i <= $endPage; $i++) {
  478. if ($i == $page) {
  479. echo "<a class=\"current\">$i</a>";
  480. } else {
  481. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  482. }
  483. }
  484. if ($page < $totalPages) {
  485. if ($totalPages - $page > $pageLen) {
  486. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  487. }
  488. echo "<a href=\"{$pageName}Page=" . ($page + 1) . "\">下一页</a>";
  489. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  490. }
  491. }
  492. ?>
  493. </div>
  494. </div>
  495. <!-- 审核确认模态窗口 -->
  496. <div id="examineModal" class="modal">
  497. <div class="modal-content">
  498. <p id="examineMessage">确认要执行此操作吗?</p>
  499. <div class="modal-buttons">
  500. <form id="examineForm" method="post">
  501. <input type="hidden" name="action" value="examine">
  502. <input type="hidden" name="redemption_id" id="modalRedemptionId" value="">
  503. <input type="hidden" name="examine_status" id="modalExamineStatus" value="">
  504. <button type="submit" class="modal-btn confirm-btn">确认</button>
  505. <button type="button" class="modal-btn cancel-btn" id="cancelExamine">取消</button>
  506. </form>
  507. </div>
  508. </div>
  509. </div>
  510. <script>
  511. $(document).ready(function() {
  512. // 添加日期验证逻辑
  513. $('input[name="fliterToDate"]').on('change', function() {
  514. var fromDate = $('input[name="fliterFromDate"]').val();
  515. var toDate = $(this).val();
  516. if (fromDate && toDate && new Date(toDate) < new Date(fromDate)) {
  517. alert('结束日期不能早于开始日期');
  518. $(this).val(''); // 清空结束日期
  519. return false;
  520. }
  521. });
  522. // 开始日期变更时也进行验证
  523. $('input[name="fliterFromDate"]').on('change', function() {
  524. var fromDate = $(this).val();
  525. var toDate = $('input[name="fliterToDate"]').val();
  526. if (fromDate && toDate && new Date(toDate) < new Date(fromDate)) {
  527. alert('开始日期不能晚于结束日期');
  528. $('input[name="fliterToDate"]').val(''); // 清空结束日期
  529. return false;
  530. }
  531. });
  532. // 处理筛选条件改变
  533. $('.filterSearch').change(function() {
  534. var url = '?';
  535. var keys = $('#keys').val();
  536. if (keys && keys != '请输入客户名称或编码') {
  537. url += 'Keys=' + encodeURIComponent(keys) + '&';
  538. }
  539. $('.filterSearch').each(function() {
  540. var name = $(this).attr('name');
  541. var value = $(this).val();
  542. if (value) {
  543. url += name + '=' + encodeURIComponent(value) + '&';
  544. }
  545. });
  546. // 移除末尾的&
  547. if (url.endsWith('&')) {
  548. url = url.substring(0, url.length - 1);
  549. }
  550. location.href = url;
  551. });
  552. // 切换显示返点详情
  553. $('.rb-toggleDetail').on('click', function(e) {
  554. e.preventDefault();
  555. e.stopPropagation(); // 阻止事件冒泡
  556. var redemptionId = $(this).data('id');
  557. var $detailPanel = $('#detail-' + redemptionId);
  558. var $panel = $(this);
  559. if ($detailPanel.is(':visible')) {
  560. $detailPanel.slideUp();
  561. $panel.text('查看详情');
  562. // 移除打开状态
  563. $panel.closest('.tline').find('.rb-slidepanel').removeClass('open');
  564. } else {
  565. $detailPanel.slideDown();
  566. $panel.text('收起详情');
  567. // 添加打开状态
  568. $panel.closest('.tline').find('.rb-slidepanel').addClass('open');
  569. // 加载详情数据
  570. loadRedemptionDetails(redemptionId);
  571. }
  572. });
  573. // 客户名称点击也可以切换显示
  574. $('.rb-slidepanel').on('click', function(e) {
  575. e.preventDefault();
  576. e.stopPropagation(); // 阻止事件冒泡
  577. var redemptionId = $(this).data('id');
  578. var $detailPanel = $('#detail-' + redemptionId);
  579. var $toggleButton = $('.rb-toggleDetail[data-id="' + redemptionId + '"]');
  580. if ($detailPanel.is(':visible')) {
  581. $detailPanel.slideUp();
  582. $toggleButton.text('查看详情');
  583. $(this).removeClass('open');
  584. } else {
  585. $detailPanel.slideDown();
  586. $toggleButton.text('收起详情');
  587. $(this).addClass('open');
  588. // 加载详情数据
  589. loadRedemptionDetails(redemptionId);
  590. }
  591. });
  592. // 审核按钮点击事件
  593. $('.examine-btn').on('click', function() {
  594. var redemptionId = $(this).data('id');
  595. var examineStatus = $(this).data('status');
  596. var actionText = examineStatus == 1 ? '通过' : '拒绝';
  597. $('#modalRedemptionId').val(redemptionId);
  598. $('#modalExamineStatus').val(examineStatus);
  599. $('#examineMessage').text('确认要' + actionText + '这条返点记录吗?');
  600. $('#examineModal').show();
  601. });
  602. // 取消审核按钮
  603. $('#cancelExamine').on('click', function() {
  604. $('#examineModal').hide();
  605. });
  606. // 点击模态窗口外部关闭模态窗口
  607. $(window).on('click', function(e) {
  608. if ($(e.target).is('#examineModal')) {
  609. $('#examineModal').hide();
  610. }
  611. });
  612. // 导出CSV按钮点击事件
  613. $('.export-btn').on('click', function() {
  614. var redemptionId = $(this).data('id');
  615. window.location.href = 'export_rebate_details.php?redemption_id=' + redemptionId;
  616. });
  617. // 加载返点详情
  618. function loadRedemptionDetails(redemptionId) {
  619. var $detailsContainer = $('#rebate-details-' + redemptionId);
  620. // 检查是否已经加载过
  621. if ($detailsContainer.data('loaded')) {
  622. return;
  623. }
  624. // 异步加载详情
  625. $.ajax({
  626. url: 'get_rebate_details.php',
  627. type: 'GET',
  628. data: { redemption_id: redemptionId },
  629. dataType: 'json',
  630. success: function(data) {
  631. if (data && data.success) {
  632. var html = '<table class="detail-table" style="width:100%; border-collapse: collapse;">';
  633. html += '<tr style="background-color: #eee; font-weight: bold;">' +
  634. '<th style="padding: 8px; text-align: left; border: 1px solid #ddd;">订单编号</th>' +
  635. '<th style="padding: 8px; text-align: center; border: 1px solid #ddd;">最新销售单日期</th>' +
  636. '<th style="padding: 8px; text-align: center; border: 1px solid #ddd;">出货日期</th>' +
  637. '<th style="padding: 8px; text-align: left; border: 1px solid #ddd;">产品名称</th>' +
  638. '<th style="padding: 8px; text-align: center; border: 1px solid #ddd;">数量</th>' +
  639. '<th style="padding: 8px; text-align: right; border: 1px solid #ddd;">返点单价</th>' +
  640. '<th style="padding: 8px; text-align: right; border: 1px solid #ddd;">返点金额</th>' +
  641. '</tr>';
  642. $.each(data.items, function(i, item) {
  643. html += '<tr style="border-bottom: 1px solid #ddd;">' +
  644. '<td style="padding: 8px; border: 1px solid #ddd;">' + item.order_code + '</td>' +
  645. '<td style="padding: 8px; text-align: center; border: 1px solid #ddd;">' + (item.order_date || '-') + '</td>' +
  646. '<td style="padding: 8px; text-align: center; border: 1px solid #ddd;">' + (item.shipping_date || '-') + '</td>' +
  647. '<td style="padding: 8px; border: 1px solid #ddd;">' + item.product_name + '</td>' +
  648. '<td style="padding: 8px; text-align: center; border: 1px solid #ddd;">' + item.quantity + ' ' + item.unit + '</td>' +
  649. '<td style="padding: 8px; text-align: right; border: 1px solid #ddd;">' + item.rebate_amount + ' 元/件</td>' +
  650. '<td style="padding: 8px; text-align: right; border: 1px solid #ddd;">' + item.total_rebate + ' 元</td>' +
  651. '</tr>';
  652. });
  653. html += '</table>';
  654. $detailsContainer.html(html);
  655. $detailsContainer.data('loaded', true);
  656. } else {
  657. $detailsContainer.html('<div style="padding: 10px; color: #e74c3c;">加载详情失败: ' + (data.message || '未知错误') + '</div>');
  658. }
  659. },
  660. error: function(jqXHR, textStatus, errorThrown) {
  661. $detailsContainer.html('<div style="padding: 10px; color: #e74c3c;">加载详情失败: ' + textStatus + '</div>');
  662. }
  663. });
  664. }
  665. });
  666. </script>
  667. </div>
  668. </body>
  669. </html>