item.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace app\admin;
  3. class item extends Base
  4. {
  5. public function initialize()
  6. {
  7. parent::initialize();
  8. $this->type_text = json_decode(IN_ITEM_TYPE, true);
  9. $this->Administrator(6);
  10. $this->header();
  11. }
  12. public function __destruct()
  13. {
  14. ?> <script>
  15. $('input[name=sort]').on('input', function () {
  16. var sort = $(this).val();
  17. if (sort != $(this).attr('data-sort'))
  18. $.ajax({
  19. url: '?c=ajax&a=item_sort',
  20. data: {id: $(this).attr('data-id'), sort: sort},
  21. type: 'post',
  22. success: function (ret) {
  23. console.log(ret)
  24. }
  25. });
  26. });
  27. </script>
  28. <?php
  29. $this->footer();
  30. }
  31. function index($_var_0 = [])
  32. {
  33. $_var_1 = SafeRequest("page", "get");
  34. $this->search = SafeRequest("search", "get");
  35. $this->search && ($_var_0[] = ["name|note", "like", "%" . $this->search . "%"]);
  36. $this->type = SafeRequest("type", "get");
  37. is_numeric($this->type) && ($_var_0[] = ["type", "=", $this->type]);
  38. $_var_2 = db("item")->where($_var_0)->order("sort,id desc")->paginate(["page" => $_var_1]);
  39. $_var_3 = $_var_2->items();
  40. $_var_4 = getRender($_var_2, $_var_1);
  41. $_var_5 = $_var_2->total();
  42. ?><div class="container"><?php
  43. $this->searchForm("可以输入名称、描述等关键词进行搜索", "", function () {
  44. ?> <select name="type" onchange="document.btnsearch.submit();">
  45. <option value="">全部类型</option>
  46. <?php
  47. foreach ($this->type_text as $_var_6 => $_var_7) {
  48. ?> <option value="<?php echo $_var_6;?>" <?php echo is_numeric($this->type) && $this->type == $_var_6 ? "selected=\"selected\"" : "";?>>
  49. <?php echo $_var_7;?> </option>
  50. <?php
  51. }
  52. ?> </select>
  53. <?php
  54. });
  55. ?>
  56. <table class="tb tb2">
  57. <tr><th class="partition">商品列表</th></tr>
  58. </table>
  59. <table class="tb tb2">
  60. <tr class="header">
  61. <th>ID</th>
  62. <th>名称</th>
  63. <th>描述</th>
  64. <th>数目</th>
  65. <th>价格</th>
  66. <th>原价</th>
  67. <th>类型</th>
  68. <th>排序</th>
  69. <th>状态</th>
  70. <th>编辑操作</th>
  71. </tr>
  72. <?php
  73. if ($_var_5 == 0) {
  74. ?><tr><td colspan="2" class="td27">没有商品管理</td></tr>
  75. <?php
  76. }
  77. if ($_var_3) {
  78. foreach ($_var_3 as $_var_8) {
  79. ?><tr class="hover">
  80. <td class="td25"><?php echo $_var_8["id"];?></td>
  81. <td><?php echo lightnum($_var_8["name"], $this->search);?></td>
  82. <td><?php echo lightnum($_var_8["note"], $this->search);?></td>
  83. <td><?php echo $_var_8["number"];?></td>
  84. <td><?php echo $_var_8["price"];?></td>
  85. <td><?php echo $_var_8["old_price"];?></td>
  86. <td><?php echo $this->type_text[$_var_8["type"]];?></td>
  87. <td><input type="text" name="sort" data-id="<?php echo $_var_8["id"];?>" value="<?php echo $_var_8["sort"];?>" data-value="<?php echo $_var_8["sort"];?>" style="width: 30px;"/></td>
  88. <td>
  89. <a href="?c=item&a=change_status&id=<?php echo $_var_8["id"];?>&status=<?php echo $_var_8["status"] ? "0" : "1";?>&hash=<?php echo $_COOKIE["in_adminpassword"];?>">
  90. <img src="static/admincp/image/show_<?php echo $_var_8["status"] ? "yes" : "no";?>.gif" />
  91. </a>
  92. </td>
  93. <script type="text/javascript" src="/xinadmin/js/item.js"></script>
  94. <td><a href="javascript:;" onclick="x_admin_show('编辑','?c=item&a=edit&id=<?php echo $_var_8["id"];?>')" class="act">编辑</a></td></tr><?php
  95. }
  96. }
  97. ?></table></div><?php echo $_var_4;?><?php
  98. }
  99. function edit()
  100. {
  101. $_var_9 = SafeRequest("id", "get");
  102. $_var_10 = $_var_9 ? "编辑" : "新增";
  103. $_var_11 = db("item")->where("id", $_var_9)->find();
  104. ?><div class="container"><?php
  105. $this->nav3();
  106. ?><table class="tb tb2">
  107. <form action="?c=item&a=save" method="post" name="form">
  108. <input type="hidden" name="id" value="<?php echo $_var_9;?>"/>
  109. <input type="hidden" name="hash" value="<?php echo $_COOKIE["in_adminpassword"];?>" />
  110. <tr><th colspan="15" class="partition"><?php echo $_var_10;?>商品</th></tr>
  111. <tr><td colspan="2" class="td27">商品名称:</td></tr>
  112. <tr><td class="vtop rowform">
  113. <input type="text" class="txt" value="<?php echo $_var_11["name"];?>" name="name" id="name">
  114. </td>
  115. </tr>
  116. <tr><td colspan="2" class="td27">数目:</td></tr>
  117. <tr><td class="vtop rowform">
  118. <input type="number" class="txt" name="number" id="number" value="<?php echo $_var_11["number"];?>">
  119. </td>
  120. </tr>
  121. <tr><td colspan="2" class="td27">价格:</td></tr>
  122. <tr><td class="vtop rowform">
  123. <input type="number" class="txt" name="price" id="price" value="<?php echo $_var_11["price"];?>">
  124. </td>
  125. </tr>
  126. <tr><td colspan="2" class="td27">原价:</td></tr>
  127. <tr><td class="vtop rowform">
  128. <input type="number" class="txt" name="old_price" id="old_price" value="<?php echo $_var_11["old_price"];?>">
  129. </td>
  130. </tr>
  131. <tr><td colspan="2" class="td27">类型:</td></tr>
  132. <tr><td class="vtop rowform">
  133. <select name="type"><?php
  134. foreach ($this->type_text as $_var_12 => $_var_13) {
  135. ?><option value="<?php echo $_var_12;?>" <?php echo $_var_11["type"] == $_var_12 ? "selected" : "";?>><?php echo $_var_13;?></option><?php
  136. }
  137. ?></select>
  138. </td>
  139. </tr>
  140. <tr><td colspan="2" class="td27">描述:</td></tr>
  141. <tr><td class="vtop rowform">
  142. <textarea rows="6" name="note" class="tarea" id="note"><?php echo $_var_11["note"];?></textarea>
  143. </td>
  144. </tr>
  145. <tr><td colspan="15">
  146. <div class="fixsel">
  147. <input type="submit" class="btn" onclick="return CheckForm();" value="提交" />
  148. </div>
  149. </td></tr>
  150. </form>
  151. </table>
  152. </div>
  153. <?php
  154. }
  155. function save()
  156. {
  157. if (!submitcheck("hash", 1)) {
  158. $this->ShowMessage("表单来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  159. }
  160. $_var_14 = intval(SafeRequest("id", "post"));
  161. $_var_15 = SafeRequest("name", "post");
  162. if (!$_var_15) {
  163. $this->ShowMessage("商品名称不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  164. }
  165. $_var_16 = SafeRequest("number", "post");
  166. if (!$_var_16) {
  167. $this->ShowMessage("数目不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  168. }
  169. $_var_17 = SafeRequest("price", "post");
  170. if (!$_var_17) {
  171. $this->ShowMessage("价格不能为空", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  172. }
  173. $_var_18 = SafeRequest("old_price", "post");
  174. $_var_19 = SafeRequest("note", "post");
  175. $_var_20 = SafeRequest("type", "post");
  176. $_var_21 = ["name" => $_var_15, "number" => $_var_16, "price" => $_var_17, "old_price" => $_var_18, "type" => $_var_20, "note" => $_var_19];
  177. if ($_var_14) {
  178. $_var_22 = db("item")->where("id", $_var_14)->update($_var_21);
  179. } else {
  180. if (db("item")->where("name", $_var_15)->where("number", $_var_16)->where("price", $_var_17)->where("type", $_var_20)->count()) {
  181. $this->ShowMessage("已存在相同的商品", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  182. }
  183. $_var_22 = db("item")->insert($_var_21);
  184. }
  185. $_var_22 && $this->ShowMessage("恭喜您,商品保存成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
  186. $this->ShowMessage("商品保存失败!请稍后重试!", $_SERVER["HTTP_REFERER"], "infotitle3", 3000, 1);
  187. }
  188. function change_status()
  189. {
  190. if (!submitcheck("hash", -1)) {
  191. $this->ShowMessage("链接来路不明,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  192. }
  193. $_var_23 = intval(SafeRequest("id", "get"));
  194. $_var_24 = intval(SafeRequest("status", "get"));
  195. $_var_25 = db("item")->where("id", $_var_23)->update(["status" => $_var_24]);
  196. $this->ShowMessage("恭喜您,状态切换成功!", "?c=item", "infotitle2", 1000, 1);
  197. }
  198. }