country.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. <?php
  2. ob_start();
  3. require_once 'conn.php';
  4. checklogin("信息管理");
  5. ?>
  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8. <head>
  9. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  10. <title>管理区域</title>
  11. <link rel="stylesheet" href="css/common.css" type="text/css" />
  12. <link rel="stylesheet" href="css/jquery.galpop.css" type="text/css" />
  13. <script language="javascript" src="js/jquery-1.7.2.min.js"></script>
  14. <script type="text/javascript" src="js/js.js"></script>
  15. <script type="text/javascript" src="xheditor-1.1.9/xheditor-1.1.9-zh-cn.min.js"></script>
  16. <script type="text/javascript" src="js/Searchproduct.js"></script>
  17. </head>
  18. <body>
  19. <div id="man_zone">
  20. <?php
  21. $act = $_GET['act'] ?? '';
  22. if ($act == "save") {
  23. $isedit = false;
  24. $id = $_POST['id'] ?? '';
  25. if ($id != "" && is_numeric($id)) {
  26. $isedit = true;
  27. }
  28. $productIds = $_POST['productId'] ?? [];
  29. $nums = $_POST['num'] ?? [];
  30. $prices = $_POST['price'] ?? [];
  31. $countryName = $_POST['countryName'] ?? '';
  32. $countryCode = $_POST['countryCode'] ?? '';
  33. if ($isedit) {
  34. $sql = "UPDATE country SET
  35. countryName = '" . $conn->real_escape_string($countryName) . "',
  36. countryCode = '" . $conn->real_escape_string($countryCode) . "',
  37. addtime = NOW()
  38. WHERE id = $id";
  39. $conn->query($sql);
  40. // Delete all existing prices for this area
  41. $conn->query("DELETE FROM price WHERE AreaId=$id");
  42. // Only process if we have product IDs
  43. if (!empty($productIds) && is_array($productIds)) {
  44. for ($i = 0; $i < count($productIds); $i++) {
  45. if (isset($nums[$i]) && isset($prices[$i])) {
  46. $numVal = empty($nums[$i]) ? 0 : floatval($nums[$i]);
  47. $priceVal = empty($prices[$i]) ? 0 : $conn->real_escape_string($prices[$i]);
  48. $productId = intval($productIds[$i]);
  49. if ($productId > 0) {
  50. $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES ($productId, $id, $numVal, '$priceVal')";
  51. $conn->query($sql);
  52. }
  53. }
  54. }
  55. }
  56. $page = $_GET['Page'] ?? '';
  57. $keys = urlencode($_GET['Keys'] ?? '');
  58. $ord = urlencode($_GET['Ord'] ?? '');
  59. header("Location: ?keys=$keys&Ord=$ord&Page=$page");
  60. exit;
  61. } else {
  62. // For new country, include countryName and countryCode
  63. $sql = "INSERT INTO country (countryName, countryCode, addtime) VALUES (
  64. '" . $conn->real_escape_string($countryName) . "',
  65. '" . $conn->real_escape_string($countryCode) . "',
  66. NOW()
  67. )";
  68. $conn->query($sql);
  69. $id = $conn->insert_id;
  70. // Only process if we have product IDs
  71. if (!empty($productIds) && is_array($productIds)) {
  72. for ($i = 0; $i < count($productIds); $i++) {
  73. if (isset($nums[$i]) && isset($prices[$i])) {
  74. $numVal = empty($nums[$i]) ? 0 : floatval($nums[$i]);
  75. $priceVal = empty($prices[$i]) ? 0 : $conn->real_escape_string($prices[$i]);
  76. $productId = intval($productIds[$i]);
  77. if ($productId > 0) {
  78. $sql = "INSERT INTO price (productId, AreaId, num, price) VALUES ($productId, $id, $numVal, '$priceVal')";
  79. $conn->query($sql);
  80. }
  81. }
  82. }
  83. }
  84. header("Location: ?");
  85. exit;
  86. }
  87. }
  88. if ($act == "add" || $act == "edit") {
  89. $id = $_GET['id'] ?? '';
  90. $isedit = false;
  91. $countryCode = '';
  92. $countryName = '';
  93. $addtime = '';
  94. if ($id != "" && is_numeric($id)) {
  95. $isedit = true;
  96. $sql = "SELECT * FROM country WHERE id = $id";
  97. $result = $conn->query($sql);
  98. $row = $result->fetch_assoc();
  99. if ($row) {
  100. $countryCode = $row['countryCode'];
  101. $countryName = $row['countryName'];
  102. $addtime = $row['addtime'];
  103. } else {
  104. $isedit = false;
  105. }
  106. }
  107. $page = $_GET['Page'] ?? '';
  108. $keys = urlencode($_GET['Keys'] ?? '');
  109. $ord = urlencode($_GET['Ord'] ?? '');
  110. $hrefstr = "?keys=$keys&Ord=$ord&Page=$page";
  111. ?>
  112. <form name="form1" method="post" action="<?= $hrefstr ?>&act=save">
  113. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  114. <tbody>
  115. <tr>
  116. <th width="8%">国家</th>
  117. <td><input type="text" id="countryName" name="countryName" value="<?= htmlspecialcharsFix($countryName) ?>" class="txt1" /><input type="hidden" name="id" value="<?= $id ?>" /></td>
  118. </tr>
  119. <tr>
  120. <th width="8%">区号</th>
  121. <td><input type="text" id="countryCode" name="countryCode" value="<?= htmlspecialcharsFix($countryCode) ?>" class="txt1" /></td>
  122. </tr>
  123. <tr>
  124. <th width="8%">更新日期</th>
  125. <td><?= $addtime ?></td>
  126. </tr>
  127. <tr>
  128. <th width="8%">售价管理</th>
  129. <td>
  130. <div class="prowapper">
  131. <?php
  132. if (!empty($id) && $id > 0) {
  133. $sql = "SELECT p.id, p.ProductName, p.ProductImg, p.unit, p.category_id, pc.name as categoryName
  134. FROM products p
  135. LEFT JOIN product_categories pc ON p.category_id = pc.id
  136. WHERE p.id IN (SELECT productId FROM price WHERE AreaId = $id)";
  137. $result = $conn->query($sql);
  138. if ($result && $result->num_rows > 0) {
  139. while ($row = $result->fetch_assoc()) {
  140. // 准备分类显示
  141. $categoryDisplay = !empty($row['categoryName']) ? ' <span style="color:#888;font-size:12px;">['.$row['categoryName'].']</span>' : '';
  142. ?>
  143. <div class="proitem">
  144. <div class="prodelet"></div>
  145. <div class="proname"><?= htmlspecialcharsFix($row['ProductName']) ?><?= $categoryDisplay ?></div>
  146. <div class="propic"><img src="<?= htmlspecialcharsFix($row['ProductImg']) ?>"></div>
  147. <div class="proprice">
  148. <?php
  149. $sql2 = "SELECT num, price FROM price WHERE productId = {$row['id']} AND AreaId = $id ORDER BY num ASC";
  150. $result2 = $conn->query($sql2);
  151. while ($row2 = $result2->fetch_assoc()) {
  152. ?>
  153. <div class="priceitem">
  154. <input type="hidden" name="productId[]" value="<?= $row['id'] ?>">
  155. <label>≥</label>
  156. <input type="number" autocomplete="off" class="txt3 num" name="num[]" value="<?= $row2['num'] ?>">
  157. <label class='unit'><?= htmlspecialcharsFix($row['unit']) ?></label>
  158. <label>售价</label>
  159. <input type="text" class="txt3 price" autocomplete="off" name="price[]" value="<?= $row2['price'] ?>">
  160. <label>RMB</label>
  161. <span class="additem"></span>
  162. <span class="delitem"></span>
  163. <span class="note"></span>
  164. </div>
  165. <?php
  166. }
  167. ?>
  168. </div>
  169. </div>
  170. <?php
  171. }
  172. } else {
  173. echo "<p>该地区暂无产品价格设置</p>";
  174. }
  175. } else {
  176. echo "<p>添加产品后可管理产品价格</p>";
  177. }
  178. ?>
  179. </div>
  180. </td>
  181. </tr>
  182. <tr>
  183. <th width="8%">产品添加</th>
  184. <td class="productinput">
  185. <input type="text" id="productSearch" class="fastsearch">
  186. <div id="productlist" class="productlist"><ul></ul></div>
  187. </td>
  188. </tr>
  189. <tr>
  190. <th></th>
  191. <td>
  192. <input type="submit" name="save" id="save" value="确定" class="btn1" />
  193. <input type="reset" name="save" id="save" value="重置" class="btn1" />
  194. <input type="button" value="返回" class="btn1" onClick="location.href='<?= $hrefstr ?>'" />
  195. </td>
  196. </tr>
  197. </tbody>
  198. </table>
  199. </form>
  200. </div>
  201. </body>
  202. </html>
  203. <?php
  204. exit;
  205. }
  206. if ($act == "postchk") {
  207. $keys = urlencode($_GET['Keys'] ?? '');
  208. $ord = urlencode($_GET['Ord'] ?? '');
  209. $page = $_GET['Page'] ?? '';
  210. $chkact = $_POST['chkact'] ?? '';
  211. if (isset($_POST['chkbox']) && is_array($_POST['chkbox'])) {
  212. $ids = implode(',', array_map('intval', $_POST['chkbox']));
  213. $sql = "DELETE FROM country WHERE id IN ($ids)";
  214. $conn->query($sql);
  215. }
  216. header("Location: ?Keys=$keys&Ord=$ord&Page=$page");
  217. exit;
  218. }
  219. // Main list view
  220. $keys = $_GET['Keys'] ?? '';
  221. $keyscode = $keys;
  222. $ord = $_GET['Ord'] ?? '';
  223. $page = $_GET['Page'] ?? '';
  224. $sql = "SELECT * FROM country WHERE countryName LIKE '%$keyscode%' OR countryCode LIKE '%$keyscode%' ORDER BY id DESC";
  225. $result = $conn->query($sql);
  226. $results = [];
  227. while($row = $result->fetch_assoc()) {
  228. $results[] = $row;
  229. }
  230. $totalRecords = count($results);
  231. $pageSize = 20;
  232. $totalPages = ceil($totalRecords / $pageSize);
  233. if ($page == "") $page = 1;
  234. if ($page == "end") $page = $totalPages;
  235. if (!is_numeric($page) || $page < 1) $page = 1;
  236. $page = (int)$page;
  237. if ($page > $totalPages) $page = $totalPages;
  238. $start = ($page - 1) * $pageSize;
  239. $currentPageRecords = array_slice($results, $start, $pageSize);
  240. $keys = urlencode($keys);
  241. $ord = urlencode($ord);
  242. $hrefstr = "?keys=$keys";
  243. ?>
  244. <form id="form1" method="post" action="?act=postchk&Keys=<?= $keys ?>&Ord=<?= $ord ?>&Page=<?= $page ?>" onSubmit="return false">
  245. <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
  246. <thead>
  247. <tr>
  248. <th width="4%"><input type="checkbox" name="chkall" id="chkall" onClick="chkboxall(this,'chkbox')" /></th>
  249. <th width="6%">序号</th>
  250. <th width="30%">国家</th>
  251. <th width="30%">区号</th>
  252. <th width="30%">操作</th>
  253. </tr>
  254. </thead>
  255. <tbody>
  256. <?php
  257. if (!empty($currentPageRecords)) {
  258. $tempNum = $start;
  259. foreach ($currentPageRecords as $row) {
  260. $tempNum++;
  261. ?>
  262. <tr onMouseOver="this.style.background='#F7FCFF'" onMouseOut="this.style.background='#FFFFFF'">
  263. <td align="center"><input type="checkbox" name="chkbox[]" value="<?= $row['id'] ?>" /></td>
  264. <td align="center"><?= $tempNum ?></td>
  265. <td align="center"><?= htmlspecialcharsFix($row['countryName']) ?></td>
  266. <td align="center"><?= htmlspecialcharsFix($row['countryCode']) ?></td>
  267. <td align="center">
  268. <a href="?Keys=<?= $keys ?>&Ord=<?= $ord ?>&Page=<?= $page ?>&act=edit&id=<?= $row['id'] ?>" class="ico_edit ico">修改</a>
  269. </td>
  270. </tr>
  271. <?php
  272. }
  273. } else {
  274. if ($keys == "") {
  275. ?>
  276. <tr>
  277. <td align="center" colspan="5">Sorry,当前暂无信息</td>
  278. </tr>
  279. <?php
  280. } else {
  281. ?>
  282. <tr>
  283. <td align="center" colspan="5"><a href="?">Sorry,没有找到"<?= htmlspecialcharsFix($keyscode) ?>"相关的信息,点击返回</a></td>
  284. </tr>
  285. <?php
  286. }
  287. }
  288. ?>
  289. </tbody>
  290. <tfoot>
  291. <tr>
  292. <td colspan="5">
  293. <div class="showpagebox">
  294. <?php
  295. if ($totalPages > 1) {
  296. $pageName = "?Keys=$keys&Ord=$ord&";
  297. $pagelen = 3;
  298. if ($page > 1) {
  299. echo "<a href=\"{$pageName}Page=1\">首页</a>";
  300. echo "<a href=\"{$pageName}Page=" . ($page-1) . "\">上一页</a>";
  301. }
  302. if ($pagelen * 2 + 1 >= $totalPages) {
  303. $startPage = 1;
  304. $endPage = $totalPages;
  305. } else {
  306. if ($page <= $pagelen + 1) {
  307. $startPage = 1;
  308. $endPage = $pagelen * 2 + 1;
  309. } else {
  310. $startPage = $page - $pagelen;
  311. $endPage = $page + $pagelen;
  312. }
  313. if ($page + $pagelen > $totalPages) {
  314. $startPage = $totalPages - $pagelen * 2;
  315. $endPage = $totalPages;
  316. }
  317. }
  318. for ($i = $startPage; $i <= $endPage; $i++) {
  319. if ($i == $page) {
  320. echo "<a class=\"current\">$i</a>";
  321. } else {
  322. echo "<a href=\"{$pageName}Page=$i\">$i</a>";
  323. }
  324. }
  325. if ($page < $totalPages) {
  326. if ($totalPages - $page > $pagelen) {
  327. echo "<a href=\"{$pageName}Page=$totalPages\">...$totalPages</a>";
  328. }
  329. echo "<a href=\"{$pageName}Page=" . ($page+1) . "\">下一页</a>";
  330. echo "<a href=\"{$pageName}Page=$totalPages\">尾页</a>";
  331. }
  332. echo "<input type=\"text\" id=\"Pagego\" value=\"$page\" onFocus=\"if(this.value == '$page'){this.value='';}\""
  333. . " onBlur=\"if(this.value == ''){this.value='$page';}\""
  334. . " onKeyUp=\"this.value=this.value.replace(/\\D/g,'')\""
  335. . " onKeyDown=\"if(event.keyCode==13){location.href='{$pageName}Page='+document.getElementById('Pagego').value}\" />";
  336. }
  337. ?>
  338. </div>
  339. <div class="searchbox">
  340. <input type="text" id="keys" value="<?= $keyscode == "" ? "请输入搜索关键词" : htmlspecialcharsFix($keyscode) ?>"
  341. onFocus="if(this.value == '<?= $keyscode == "" ? "请输入搜索关键词" : htmlspecialcharsFix($keyscode) ?>'){this.value='';}"
  342. onBlur="if(this.value == ''){this.value='<?= $keyscode == "" ? "请输入搜索关键词" : htmlspecialcharsFix($keyscode) ?>';}"
  343. onKeyDown="if(event.keyCode==13){location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)}" />
  344. <input type="button" id="searchgo" value="go" onClick="location.href='?Keys='+encodeURIComponent(document.getElementById('keys').value)" />
  345. </div>
  346. <div class="postchkbox">
  347. <select id="chkact" name="chkact">
  348. <option value="1">请选择</option>
  349. <option value="-1">删除</option>
  350. </select>
  351. <input type="button" value="执行" onClick="postchk(1)" class="btn1" />
  352. <input type="button" value="新增" onClick="location.href='?act=add'" class="btn1" />
  353. </div>
  354. </td>
  355. </tr>
  356. </tfoot>
  357. </table>
  358. </form>
  359. </div>
  360. <script>
  361. $('.click-open-iframe').galpop({
  362. contentType: 'iframe',
  363. });
  364. </script>
  365. </body>
  366. </html>