123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278 |
- <?php
- namespace app\admin;
- class super_code extends Base
- {
- public $statusText = [-2 => "签名失败", -1 => "解析失败", "未签名", "准备中", "正在解析", "正在签名", "正在打包", "签名完成"];
- public function initialize()
- {
- parent::initialize();
- $this->Administrator(6);
- $this->header(["save"]);
- }
- public function __destruct()
- {
- $this->footer(["save"]);
- }
- function index($map = [])
- {
- $this->search = SafeRequest("search", "get");
- $this->search && ($map[] = ["user_id|app_id|code|udid|cert_iss", "like", "%" . $this->search . "%"]);
- $_var_0 = SafeRequest("app_id", "get");
- $_var_0 && ($map[] = ["app_id", "=", $_var_0]);
- $this->type = SafeRequest("type", "get");
- if($this->type == '3'){
- $map[] = ["use_time", ">", '0'];
- }else{
- is_numeric($this->type) && ($map[] = ["type", "=", $this->type]);
- }
-
- $_var_1 = SafeRequest("udid", "get");
- $_var_1 && ($map[] = ["udid", "=", $_var_1]);
- $_var_2 = SafeRequest("page", "get");
- $this->mapTime("create_time", true, $map);
- $_var_3 = db("super_code")->where($map)->order("use_time asc,id desc")->paginate(["page" => $_var_2]);
- $_var_4 = $_var_3->items();
- $_var_5 = getRender($_var_3, $_var_2);
- $_var_6 = $_var_3->total();
- ?><div class="container"><?php
- $this->nav3();
- $this->searchForm("", "", function () {
- ?> <select name="type" onchange="document.btnsearch.submit();">
- <option value="">全部类型</option>
- <option value="1" <?php echo $this->type == "1" ? "selected=\"selected\"" : "";?>>一码一用</option>
- <option value="2" <?php echo $this->type == "2" ? "selected=\"selected\"" : "";?>>一码多用</option>
- <option value="3" <?php echo $this->type == "3" ? "selected=\"selected\"" : "";?>>已使用</option>
- </select>
- <?php
- }, function () {
- ?><input class="btn" type="button" value="生成授权码" onclick="make_key()"><?php
- });
- ?><form name="form" method="post" action="?c=super_code&a=allsave">
- <style type="text/css">
- .checkbox {
- height: 14px;
- position: relative;
- top: 0;
- width: 18px;
- height: 23px;
- line-height: 10px;
- border: 1px solid #d2d2d2;
- font-size: 12px;
- border-radius: 10px;
- background-color: #fff;
- -webkit-transition: .1s linear;
- transition: .1s linear;
- }
- </style>
- <table class="tb tb2">
- <tr><th class="partition">授权码列表</th></tr>
- </table>
- <table class="tb tb2">
- <tr><td><label for="chkall">全选</label> <select id="in_allsave" name="in_allsave" onchange="all_save(this.form);">
- <option value="statusOn">启用</option>
- <option value="statusOff">禁用</option>
- <option value="del">删除</option>
- </select> <input type="submit" name="allsave" class="layui-btn" value="批量操作" /></td></tr>
- </table>
- <table class="layui-table">
- <thead>
- <tr>
- <th>
- <input type="checkbox" id="chkall" class="checkbox" onclick="CheckAll(this.form);"/>
- </th>
- <th>ID</th>
- <td>创建用户</td>
- <th>授权码</th>
- <th>设备号</th>
- <th>应用名称</th>
- <th>类型</th>
- <th>创建时间</th>
- <th>使用时间</th>
- <th>有效时长</th>
- <th>状态</th>
- <th>操作</th>
- </tr>
- </thead>
- <?php
- if ($_var_6 == 0) {
- ?><tr><td colspan="2" class="td27">没有授权码</td></tr>
- <?php
- }
- if ($_var_4) {
- foreach ($_var_4 as $_var_7) {
- if ($_var_7["app_id"]) {
- $_var_8 = db("appid")->where("in_id", $_var_7["app_id"])->value("in_name");
- if (!$_var_8) {
- $_var_8 = "应用已删除";
- }
- } else {
- $_var_8 = "未使用";
- }
- if ($_var_7["user_id"]) {
- $_var_9 = db("user")->where("in_userid", $_var_7["user_id"])->value("in_username");
- if (!$_var_9) {
- $_var_9 = "用户已删除";
- }
- } else {
- $_var_9 = "平台";
- }
- ?><tr class="hover">
- <td>
- <input class="checkbox" type="checkbox" name="in_id[]" id="in_id" value="<?php echo $_var_7["id"];?>">
- </td>
- <td><?php echo $_var_7["id"];?></td>
- <td><?php echo $_var_9;?></td>
- <td><?php echo $_var_7["code"];?></td>
- <td><?php echo $_var_7["udid"] ?: "未使用";?></td>
- <td><?php echo $_var_8;?></td>
- <td><font color="red"><?php echo $_var_7["type"] == 1 ? "一码一用" : "一码多用";?></font></td>
- <td><?php echo date("Y-m-d H:i", $_var_7["create_time"]);?></td>
- <td><?php echo $_var_7["use_time"] ? date("Y-m-d H:i", $_var_7["use_time"]) : "未使用";?></td>
- <td><?php echo $_var_7["days"] ? $_var_7["days"] . "天" : "长期";?></td>
- <td><?php echo $_var_7["status"] ? "已禁用" : "正常";?></td>
- <td>
- <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>
- <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>
- </td>
- </tr><?php
- }
- }
- ?></table></form><?php echo $_var_5;?> </div>
- <script>
- function make_key(_tid) {
- return pop.up('no', '生成授权码', '?c=super_code&a=create', '500px', '500px', '40px');
- }
- </script>
- <?php
- }
- function allsave()
- {
- if (!submitcheck("allsave")) {
- $this->ShowMessage("表单验证不符,无法提交!", $_SERVER["PHP_SELF"], "infotitle3", 3000, 1);
- }
- $_var_10 = RequestBox("in_id");
- $_var_11 = SafeRequest("in_allsave", "post");
- if ($_var_10 == 0) {
- $this->ShowMessage("批量操作失败,请先勾选要删除的应用!", $_SERVER["HTTP_REFERER"], "infotitle3", 3000, 1);
- } else {
- if ($_var_11 == "del") {
- $_var_12 = db("super_code")->where("id", "in", $_var_10)->delete();
- $this->ShowMessage("恭喜您,批量刪除成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
- } elseif ($_var_11 == "statusOff") {
- $_var_12 = db("super_code")->where("id", "in", $_var_10)->update(["status" => 1]);
- $this->ShowMessage("恭喜您,批量禁用成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
- } elseif ($_var_11 == "statusOn") {
- $_var_12 = db("super_code")->where("id", "in", $_var_10)->update(["status" => 0]);
- $this->ShowMessage("恭喜您,批量启用成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
- }
- }
- }
- function create()
- {
- ?> <style>
- p {
- color: red;
- font-size: 12px;
- }
- </style>
- <main style="padding: 15px;">
- <form action="?c=super_code&a=save" method="post">
- <table class="tb tb2">
- <tr>
- <td colspan="2" class="td27">生成数量:</td>
- </tr>
- <tr>
- <td class="vtop rowform">
- <input type="number" class="txt" value="" name="nums" placeholder="默认10个">
- <p>不填默认生成10个,每次最多200,超过200也只生成200</p>
- </td>
- </tr>
- <tr>
- <td colspan="2" class="td27">有效时长:</td>
- </tr>
- <tr>
- <td class="vtop rowform">
- <input type="number" class="txt" value="" name="days" placeholder="(天)">
- <p>不设置则掉签失效,设置则到期失效</p>
- </td>
- </tr>
- <tr>
- <td colspan="2" class="td27">证书类型:</td>
- </tr>
- <tr>
- <td class="vtop rowform">
- <select name="type">
- <option value="1">一码一用</option>
- <option value="2">一码多用</option>
- </select>
- <p>一码一用,仅可授权单个应用</p>
- <p>一码多用,可授权同一用户下的所用应用,平台码则为全平台通用</p>
- </td>
- </tr>
- <tr>
- <td colspan="15">
- <div class="fixsel">
- <input type="button" class="btn" onclick="create_form_submit()" value="提交"/>
- </div>
- </td>
- </tr>
- </table>
- </form>
- </main>
- <script>
- function create_form_submit() {
- var nums = $('input[name=nums]').val();
- var days = $('input[name=days]').val();
- var type = $('select[name=type]').val();
- $.post('?c=super_code&a=save', {
- nums, days, type
- }, function (ret) {
- if (ret.msg) layer.msg(ret.msg);
- if (ret.data) $('main').html('<textarea rows="27" style="width: 100%;height: 100%;">' + ret.data.codes + '</textarea>');
- }, 'json');
- }
- </script>
- <?php
- }
- function del()
- {
- $_var_13 = SafeRequest("id", "get");
- $_var_14 = db("super_code")->where("id", $_var_13)->delete();
- $this->ShowMessage("恭喜您,删除成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
- }
- function save()
- {
- $_var_15 = SafeRequest("nums", "post");
- $_var_16 = intval(SafeRequest("days"));
- $_var_17 = SafeRequest("type", "post");
- $_var_15 = is_numeric($_var_15) && $_var_15 > 0 ? $_var_15 : 10;
- if ($_var_15 > 200) {
- $_var_15 = 200;
- }
- $_var_18 = [];
- db("super_code")->startTrans();
- try {
- for ($_var_19 = 1; $_var_19 <= $_var_15; $_var_19++) {
- $_var_20 = Randomstr(12);
- db("super_code")->insert(["user_id" => 0, "code" => $_var_20, "type" => $_var_17, "days" => $_var_16, "create_time" => time()]);
- $_var_18[] = $_var_20;
- }
- db("super_code")->commit();
- } catch (\Exception $_var_21) {
- db("super_code")->rollback();
- reJSON("生成失败", 404);
- }
- $_var_18 = implode("\n", $_var_18);
- reJSON(["codes" => $_var_18], 200, "生成成功");
- }
- function setStatus()
- {
- $_var_22 = SafeRequest("id", "get");
- $_var_23 = SafeRequest("status", "get");
- $_var_24 = db("super_code")->where("id", $_var_22)->update(["status" => intval(!$_var_23)]);
- $this->ShowMessage("恭喜您,修改成功!", $_SERVER["HTTP_REFERER"], "infotitle2", 1000, 1);
- }
- }
|