super_code.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <?php
  2. namespace app\admin;
  3. class super_code extends Base
  4. {
  5. public $statusText = [-2 => "签名失败", -1 => "解析失败", "未签名", "准备中", "正在解析", "正在签名", "正在打包", "签名完成"];
  6. public function initialize()
  7. {
  8. parent::initialize();
  9. $this->Administrator(6);
  10. $this->header(["save"]);
  11. }
  12. public function __destruct()
  13. {
  14. $this->footer(["save"]);
  15. }
  16. function index($map = [])
  17. {
  18. $this->search = SafeRequest("search", "get");
  19. $this->search && ($map[] = ["user_id|app_id|code|udid|cert_iss", "like", "%" . $this->search . "%"]);
  20. $_var_0 = SafeRequest("app_id", "get");
  21. $_var_0 && ($map[] = ["app_id", "=", $_var_0]);
  22. $this->type = SafeRequest("type", "get");
  23. if($this->type == '3'){
  24. $map[] = ["use_time", ">", '0'];
  25. }else{
  26. is_numeric($this->type) && ($map[] = ["type", "=", $this->type]);
  27. }
  28. $_var_1 = SafeRequest("udid", "get");
  29. $_var_1 && ($map[] = ["udid", "=", $_var_1]);
  30. $_var_2 = SafeRequest("page", "get");
  31. $this->mapTime("create_time", true, $map);
  32. $_var_3 = db("super_code")->where($map)->order("use_time asc,id desc")->paginate(["page" => $_var_2]);
  33. $_var_4 = $_var_3->items();
  34. $_var_5 = getRender($_var_3, $_var_2);
  35. $_var_6 = $_var_3->total();
  36. ?><div class="container"><?php
  37. $this->nav3();
  38. $this->searchForm("", "", function () {
  39. ?> <select name="type" onchange="document.btnsearch.submit();">
  40. <option value="">全部类型</option>
  41. <option value="1" <?php echo $this->type == "1" ? "selected=\"selected\"" : "";?>>一码一用</option>
  42. <option value="2" <?php echo $this->type == "2" ? "selected=\"selected\"" : "";?>>一码多用</option>
  43. <option value="3" <?php echo $this->type == "3" ? "selected=\"selected\"" : "";?>>已使用</option>
  44. </select>
  45. <?php
  46. }, function () {
  47. ?><input class="btn" type="button" value="生成授权码" onclick="make_key()"><?php
  48. });
  49. ?><form name="form" method="post" action="?c=super_code&a=allsave">
  50. <style type="text/css">
  51. .checkbox {
  52. height: 14px;
  53. position: relative;
  54. top: 0;
  55. width: 18px;
  56. height: 23px;
  57. line-height: 10px;
  58. border: 1px solid #d2d2d2;
  59. font-size: 12px;
  60. border-radius: 10px;
  61. background-color: #fff;
  62. -webkit-transition: .1s linear;
  63. transition: .1s linear;
  64. }
  65. </style>
  66. <table class="tb tb2">
  67. <tr><th class="partition">授权码列表</th></tr>
  68. </table>
  69. <table class="tb tb2">
  70. <tr><td><label for="chkall">全选</label> &nbsp;&nbsp; <select id="in_allsave" name="in_allsave" onchange="all_save(this.form);">
  71. <option value="statusOn">启用</option>
  72. <option value="statusOff">禁用</option>
  73. <option value="del">删除</option>
  74. </select> &nbsp;&nbsp; <input type="submit" name="allsave" class="layui-btn" value="批量操作" /></td></tr>
  75. </table>
  76. <table class="layui-table">
  77. <thead>
  78. <tr>
  79. <th>
  80. <input type="checkbox" id="chkall" class="checkbox" onclick="CheckAll(this.form);"/>
  81. </th>
  82. <th>ID</th>
  83. <td>创建用户</td>
  84. <th>授权码</th>
  85. <th>设备号</th>
  86. <th>应用名称</th>
  87. <th>类型</th>
  88. <th>创建时间</th>
  89. <th>使用时间</th>
  90. <th>有效时长</th>
  91. <th>状态</th>
  92. <th>操作</th>
  93. </tr>
  94. </thead>
  95. <?php
  96. if ($_var_6 == 0) {
  97. ?><tr><td colspan="2" class="td27">没有授权码</td></tr>
  98. <?php
  99. }
  100. if ($_var_4) {
  101. foreach ($_var_4 as $_var_7) {
  102. if ($_var_7["app_id"]) {
  103. $_var_8 = db("appid")->where("in_id", $_var_7["app_id"])->value("in_name");
  104. if (!$_var_8) {
  105. $_var_8 = "应用已删除";
  106. }
  107. } else {
  108. $_var_8 = "未使用";
  109. }
  110. if ($_var_7["user_id"]) {
  111. $_var_9 = db("user")->where("in_userid", $_var_7["user_id"])->value("in_username");
  112. if (!$_var_9) {
  113. $_var_9 = "用户已删除";
  114. }
  115. } else {
  116. $_var_9 = "平台";
  117. }
  118. ?><tr class="hover">
  119. <td>
  120. <input class="checkbox" type="checkbox" name="in_id[]" id="in_id" value="<?php echo $_var_7["id"];?>">
  121. </td>
  122. <td><?php echo $_var_7["id"];?></td>
  123. <td><?php echo $_var_9;?></td>
  124. <td><?php echo $_var_7["code"];?></td>
  125. <td><?php echo $_var_7["udid"] ?: "未使用";?></td>
  126. <td><?php echo $_var_8;?></td>
  127. <td><font color="red"><?php echo $_var_7["type"] == 1 ? "一码一用" : "一码多用";?></font></td>
  128. <td><?php echo date("Y-m-d H:i", $_var_7["create_time"]);?></td>
  129. <td><?php echo $_var_7["use_time"] ? date("Y-m-d H:i", $_var_7["use_time"]) : "未使用";?></td>
  130. <td><?php echo $_var_7["days"] ? $_var_7["days"] . "天" : "长期";?></td>
  131. <td><?php echo $_var_7["status"] ? "已禁用" : "正常";?></td>
  132. <td>
  133. <a class="layui-btn layui-btn-normal layui-btn-xs" href="?c=super_code&a=setStatus&id=<?php echo $_var_7["id"];?>&status=<?php echo $_var_7["status"];?>"><i class="layui-icon layui-icon-password"></i><?php echo $_var_7["status"] ? "启用" : "禁用";?></a>
  134. <a class="layui-btn layui-btn-danger layui-btn-xs" style="cursor:pointer" onclick="del_msgsqm('?c=super_code&a=del&id=<?php echo $_var_7["id"];?>');"><i class="layui-icon layui-icon-delete"></i>删除</a>
  135. </td>
  136. </tr><?php
  137. }
  138. }
  139. ?></table></form><?php echo $_var_5;?> </div>
  140. <script>
  141. function make_key(_tid) {
  142. return pop.up('no', '生成授权码', '?c=super_code&a=create', '500px', '500px', '40px');
  143. }
  144. </script>
  145. <?php
  146. }
  147. function allsave()
  148. {
  149. if (!submitcheck("allsave")) {
  150. $this->ShowMessage("表单验证不符,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
  151. }
  152. $_var_10 = RequestBox("in_id");
  153. $_var_11 = SafeRequest("in_allsave", "post");
  154. if ($_var_10 == 0) {
  155. $this->ShowMessage("批量操作失败,请先勾选要删除的应用!", $_SERVER["HTTP_REFERER"], "infotitle3", 3000, 1);
  156. } else {
  157. if ($_var_11 == "del") {
  158. $_var_12 = db("super_code")->where("id", "in", $_var_10)->delete();
  159. $this->ShowMessage("恭喜您,批量刪除成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
  160. } elseif ($_var_11 == "statusOff") {
  161. $_var_12 = db("super_code")->where("id", "in", $_var_10)->update(["status" => 1]);
  162. $this->ShowMessage("恭喜您,批量禁用成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
  163. } elseif ($_var_11 == "statusOn") {
  164. $_var_12 = db("super_code")->where("id", "in", $_var_10)->update(["status" => 0]);
  165. $this->ShowMessage("恭喜您,批量启用成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
  166. }
  167. }
  168. }
  169. function create()
  170. {
  171. ?> <style>
  172. p {
  173. color: red;
  174. font-size: 12px;
  175. }
  176. </style>
  177. <main style="padding: 15px;">
  178. <form action="?c=super_code&a=save" method="post">
  179. <table class="tb tb2">
  180. <tr>
  181. <td colspan="2" class="td27">生成数量:</td>
  182. </tr>
  183. <tr>
  184. <td class="vtop rowform">
  185. <input type="number" class="txt" value="" name="nums" placeholder="默认10个">
  186. <p>不填默认生成10个,每次最多200,超过200也只生成200</p>
  187. </td>
  188. </tr>
  189. <tr>
  190. <td colspan="2" class="td27">有效时长:</td>
  191. </tr>
  192. <tr>
  193. <td class="vtop rowform">
  194. <input type="number" class="txt" value="" name="days" placeholder="(天)">
  195. <p>不设置则掉签失效,设置则到期失效</p>
  196. </td>
  197. </tr>
  198. <tr>
  199. <td colspan="2" class="td27">证书类型:</td>
  200. </tr>
  201. <tr>
  202. <td class="vtop rowform">
  203. <select name="type">
  204. <option value="1">一码一用</option>
  205. <option value="2">一码多用</option>
  206. </select>
  207. <p>一码一用,仅可授权单个应用</p>
  208. <p>一码多用,可授权同一用户下的所用应用,平台码则为全平台通用</p>
  209. </td>
  210. </tr>
  211. <tr>
  212. <td colspan="15">
  213. <div class="fixsel">
  214. <input type="button" class="btn" onclick="create_form_submit()" value="提交"/>
  215. </div>
  216. </td>
  217. </tr>
  218. </table>
  219. </form>
  220. </main>
  221. <script>
  222. function create_form_submit() {
  223. var nums = $('input[name=nums]').val();
  224. var days = $('input[name=days]').val();
  225. var type = $('select[name=type]').val();
  226. $.post('?c=super_code&a=save', {
  227. nums, days, type
  228. }, function (ret) {
  229. if (ret.msg) layer.msg(ret.msg);
  230. if (ret.data) $('main').html('<textarea rows="27" style="width: 100%;height: 100%;">' + ret.data.codes + '</textarea>');
  231. }, 'json');
  232. }
  233. </script>
  234. <?php
  235. }
  236. function del()
  237. {
  238. $_var_13 = SafeRequest("id", "get");
  239. $_var_14 = db("super_code")->where("id", $_var_13)->delete();
  240. $this->ShowMessage("恭喜您,删除成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
  241. }
  242. function save()
  243. {
  244. $_var_15 = SafeRequest("nums", "post");
  245. $_var_16 = intval(SafeRequest("days"));
  246. $_var_17 = SafeRequest("type", "post");
  247. $_var_15 = is_numeric($_var_15) && $_var_15 > 0 ? $_var_15 : 10;
  248. if ($_var_15 > 200) {
  249. $_var_15 = 200;
  250. }
  251. $_var_18 = [];
  252. db("super_code")->startTrans();
  253. try {
  254. for ($_var_19 = 1; $_var_19 <= $_var_15; $_var_19++) {
  255. $_var_20 = Randomstr(12);
  256. db("super_code")->insert(["user_id" => 0, "code" => $_var_20, "type" => $_var_17, "days" => $_var_16, "create_time" => time()]);
  257. $_var_18[] = $_var_20;
  258. }
  259. db("super_code")->commit();
  260. } catch (\Exception $_var_21) {
  261. db("super_code")->rollback();
  262. reJSON("生成失败", 404);
  263. }
  264. $_var_18 = implode("\n", $_var_18);
  265. reJSON(["codes" => $_var_18], 200, "生成成功");
  266. }
  267. function setStatus()
  268. {
  269. $_var_22 = SafeRequest("id", "get");
  270. $_var_23 = SafeRequest("status", "get");
  271. $_var_24 = db("super_code")->where("id", $_var_22)->update(["status" => intval(!$_var_23)]);
  272. $this->ShowMessage("恭喜您,修改成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
  273. }
  274. }