config.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. <?php
  2. namespace app\admin;
  3. class config extends Base
  4. {
  5. public function initialize()
  6. {
  7. parent::initialize();
  8. $this->Administrator(6);
  9. $ca = db('action')->where('c', 'config_setting')->where('a', '<>', 'index')->select();
  10. $this->category_text = ['system' => '全局配置'];
  11. foreach ($ca as $v) {
  12. $this->category_text[$v['a']] = $v['name'];
  13. }
  14. $this->type_text = json_decode(IN_CONFIG_TYPE, true);
  15. $this->header();
  16. }
  17. public function __destruct()
  18. {
  19. // TODO: Implement __destruct() method.
  20. ?>
  21. <script>
  22. $('input[name=sort]').on('input', function () {
  23. var sort = $(this).val();
  24. console.log(sort)
  25. if (sort != $(this).attr('data-sort'))
  26. $.ajax({
  27. url: '?c=ajax&a=config_sort',
  28. data: {id: $(this).attr('data-id'), sort: sort},
  29. type: 'post',
  30. success: function (ret) {
  31. console.log(ret)
  32. }
  33. });
  34. });
  35. </script>
  36. <?php
  37. $this->footer();
  38. }
  39. function index($map = [])
  40. {
  41. $page = SafeRequest('page', 'get');
  42. $this->search = SafeRequest('search', 'get');
  43. $this->search && $map[] = ['title|name|group|note', 'like', "%$this->search%"];
  44. $this->category = SafeRequest('category', 'get');
  45. $this->category && $map[] = ['category', '=', $this->category];
  46. $this->type = SafeRequest('type', 'get');
  47. $this->type && $map[] = ['type', '=', $this->type];
  48. $list = db('config')->where($map)->order('category,group,status,sort,name')->paginate([
  49. 'page' => $page
  50. ]);
  51. $result = $list->items();
  52. $render = getRender($list, $page);
  53. $count = $list->total();
  54. echo '<div class="container">';
  55. $this->searchForm('可以输入名称等关键词进行搜索', '', function () {
  56. ?>
  57. <select name="category" onchange="document.btnsearch.submit();">
  58. <option value="">全部类别</option>
  59. <?php foreach ($this->category_text as $value => $label) { ?>
  60. <option value="<?php echo $value ?>" <?php echo $this->category == $value ? 'selected="selected"' : '' ?>>
  61. <?php echo $label ?>
  62. </option>
  63. <?php } ?>
  64. </select>
  65. <select name="type" onchange="document.btnsearch.submit();">
  66. <option value="">全部类型</option>
  67. <?php foreach ($this->type_text as $value => $label) { ?>
  68. <option value="<?php echo $value ?>" <?php echo $this->type == $value ? 'selected="selected"' : '' ?>>
  69. <?php echo $label ?>
  70. </option>
  71. <?php } ?>
  72. </select>
  73. <?php
  74. });
  75. echo '
  76. <table class="tb tb2">
  77. <tr><th class="partition">配置列表</th></tr>
  78. </table>
  79. <table class="layui-table">
  80. <thead>
  81. <tr>
  82. <th>ID</th>
  83. <th>名称</th>
  84. <th>变量名称</th>
  85. <th>分组</th>
  86. <th>类别</th>
  87. <th>类型</th>
  88. <th>排序</th>
  89. <th>状态</th>
  90. </tr>
  91. </thead>
  92. ';
  93. if ($count == 0) {
  94. echo '<tr><td colspan="2" class="td27">没有配置管理</td></tr>
  95. ';
  96. }
  97. if ($result) {
  98. foreach ($result as $item) {
  99. echo '<tr class="hover">
  100. <td class="td25">' . $item['id'] . '</td>
  101. <td>' . lightnum($item['title'], $this->search) . '</a></td>
  102. <td>' . lightnum($item['name'], $this->search) . '</td>
  103. <td>' . $this->category_text[$item['category']] . '</td>
  104. <td>' . lightnum($item['group'], $this->search) . '</td>
  105. <td>' . $this->type_text[$item['type']] . '</td>
  106. <td><input type="text" name="sort" data-id="' . $item['id'] . '" value="' . $item['sort'] . '" data-value="' . $item['sort'] . '" style="width: 30px;"/></td>
  107. <td>
  108. <a href="?c=config&a=change_status&id=' . $item['id'] . '&status=' . ($item['status'] ? '0' : '1') . '&hash=' . $_COOKIE['in_adminpassword'] . '">
  109. <img src="static/admincp/image/show_' . ($item['status'] ? 'yes' : 'no') . '.gif" />
  110. </a>
  111. </td>
  112. <td>';
  113. echo '</td></tr>';
  114. }
  115. }
  116. echo '</table></div>' . $render;
  117. }
  118. function edit()
  119. {
  120. $id = SafeRequest("id", "get");
  121. $arrname = $id ? '编辑' : '新增';
  122. $data = db('config')->where('id', $id)->find();
  123. echo '<div class="container">';
  124. $this->nav3();
  125. echo '<table class="tb tb2">
  126. <form action="?c=config&a=save" method="post" name="form">
  127. <input type="hidden" name="id" value="' . $id . '"/>
  128. <input type="hidden" name="hash" value="' . $_COOKIE['in_adminpassword'] . '" />
  129. <tr><th colspan="15" class="partition">' . $arrname . '配置</th></tr>
  130. <tr><td colspan="2" class="td27">配置名称:</td></tr>
  131. <tr><td class="vtop rowform">
  132. <input type="text" class="txt" value="' . $data['title'] . '" name="title" id="title">
  133. </td>
  134. </tr>
  135. <tr>';
  136. echo '<td colspan="2" class="td27">变量名称:' . ($id ? '<span style="color: red;">(禁止修改,如要变更,请修改数据库)</span>' : '') . '</td></tr>
  137. <tr><td class="vtop rowform">
  138. <input type="text" class="txt" name="name" id="name" value="' . $data['name'] . '" ' . ($id ? 'readonly' : '') . '>
  139. </td>
  140. </tr>
  141. </tr>';
  142. echo '<tr><td colspan="2" class="td27">分类:</td></tr>
  143. <tr><td class="vtop rowform">
  144. <select name="category">';
  145. foreach ($this->category_text as $k => $v) {
  146. echo '<option value="' . $k . '" ' . ($data['category'] == $k ? 'selected' : '') . '>' . $v . '</option>';
  147. }
  148. echo '</select>
  149. </td>
  150. </tr>
  151. <tr><td colspan="2" class="td27">分组:</td></tr>
  152. <tr><td class="vtop rowform">
  153. <input type="text" class="txt" name="group" id="group" value="' . $data['group'] . '">
  154. </td>
  155. </tr>
  156. <tr><td colspan="2" class="td27">类型:</td></tr>
  157. <tr><td class="vtop rowform">
  158. <select name="type">';
  159. foreach ($this->type_text as $k => $v) {
  160. echo '<option value="' . $k . '" ' . ($data['type'] == $k ? 'selected' : '') . '>' . $v . '</option>';
  161. }
  162. echo '</select>
  163. </td>
  164. </tr>
  165. <tr><td colspan="2" class="td27">描述:</td></tr>
  166. <tr><td class="vtop rowform">
  167. <textarea rows="6" name="note" class="tarea" id="note">' . $data['note'] . '</textarea>
  168. </td>
  169. </tr>
  170. <tr><td colspan="2" class="td27">内容:<span style="color: red;">(此处为JSON格式,不懂勿动,默认:[0,100])</span></td></tr>
  171. <tr>
  172. <td class="vtop rowform">
  173. <textarea rows="6" name="content" class="tarea" id="note">' . $data['content'] . '</textarea>
  174. </td>
  175. </tr>
  176. <tr><td colspan="15">
  177. <div class="fixsel">
  178. <input type="submit" class="btn" onclick="return CheckForm();" value="提交" />
  179. </div>
  180. </td></tr>
  181. </form>
  182. </table>
  183. </div>
  184. ';
  185. }
  186. function save()
  187. {
  188. if (!submitcheck('hash', 1)) {
  189. $this->ShowMessage("表单来路不明,无法提交!", '?c=config', "infotitle3", 3000, 1);
  190. }
  191. $id = intval(SafeRequest("id", "post"));
  192. $title = SafeRequest("title", "post");
  193. if (!$title) {
  194. $this->ShowMessage("配置名称不能为空", '?c=config', "infotitle3", 3000, 1);
  195. }
  196. $name = SafeRequest("name", "post");
  197. if (!$name) {
  198. $this->ShowMessage("变量名称不能为空", '?c=config', "infotitle3", 3000, 1);
  199. }
  200. $note = SafeRequest("note", "post");
  201. $type = SafeRequest("type", "post");
  202. $category = SafeRequest("category", "post");
  203. $group = SafeRequest("group", "post");
  204. $content = SafeRequest("content", "post",1);
  205. !$content && $content = '[0, 100]';
  206. if (isJson($content) == false) {
  207. $this->ShowMessage("内容不是合法的JSON格式", '?c=config', "infotitle3", 3000, 1);
  208. }
  209. $data = [
  210. 'name' => $name,
  211. 'title' => $title,
  212. 'type' => $type,
  213. 'note' => $note,
  214. 'category' => $category,
  215. 'group' => $group,
  216. 'content' => $content,
  217. ];
  218. if ($id) {
  219. $res = db('config')->where('id', $id)->update($data);
  220. } else {
  221. $config = db('config')->where('name', $name)->find();
  222. if ($config) {
  223. $this->ShowMessage("已存在相同的配置", '?c=config', "infotitle3", 3000, 1);
  224. }
  225. $data['value']='';
  226. $res = db('config')->insert($data);
  227. }
  228. $res && $this->ShowMessage("恭喜您,配置保存成功!", '?c=config', "infotitle2", 1000, 1);
  229. $this->ShowMessage("配置保存失败!请稍后重试!", '?c=config', "infotitle3", 3000, 1);
  230. }
  231. function change_status()
  232. {
  233. if (!submitcheck('hash', -1)) {
  234. $this->ShowMessage("链接来路不明,无法提交!", $_SERVER['HTTP_REFERER'], "infotitle3", 3000, 1);
  235. }
  236. $id = intval(SafeRequest("id", "get"));
  237. $status = intval(SafeRequest("status", "get"));
  238. $res = db('config')->where('id', $id)->update(['status' => $status]);
  239. $this->ShowMessage("恭喜您,状态切换成功!", "?c=config", "infotitle2", 1000, 1);
  240. }
  241. }