where('id', $appid)->find(); if (!$app_res) json(201, '应用不存在'); $str = ''; for ($i = 1; $i <= $num; $i++) { $key = getcode($k_length); if ($out == 1) { $add_res = Db::table('kami')->add(['kami' => $key, 'type' => $type, 'amount' => $amount, 'note' => $note, 'appid' => $appid, 'new' => 'y']); } else { $add_res = Db::table('kami')->add(['kami' => $key, 'type' => $type, 'amount' => $amount, 'note' => $note, 'appid' => $appid]); } if (!$add_res) { $key = getcode($k_length); $add_res = Db::table('kami')->add(['kami' => $key, 'type' => $type, 'amount' => $amount, 'note' => $note, 'appid' => $appid]); } $str .= $key . "\r\n"; } if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_add', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 if ($out == 1) { $str = "==============卡密开始================\r\n\r\n" . $str . "\r\n==============卡密结束================"; json(202, $str); } else { json(200, '添加成功'); } } if ($act == 'note') { $id = isset($_POST['kid']) ? intval($_POST['kid']) : 0; $note = isset($_POST['note']) ? purge($_POST['note']) : ''; if ($id <= 0) json(201, '需要修改的卡密有误'); $k_res = Db::table('kami')->where('id', $id)->find(); if (!$k_res) json(201, '卡密不存在'); $res = Db::table('kami')->where('id', $id)->update(['note' => $note]); //die($res); if ($res) { if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_note', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 json(200, '编辑成功'); } else { if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_note', 'status' => 201, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 json(201, '编辑失败'); } } if ($act == 'state') { $id = isset($_POST['id']) ? intval($_POST['id']) : 0; $state = isset($_POST['state']) ? purge($_POST['state']) : 'y'; if ($id <= 0) json(201, '需要修改的卡密有误'); $k_res = Db::table('kami')->where('id', $id)->find(); if (!$k_res) json(201, '卡密不存在'); $res = Db::table('kami')->where('id', $id)->update(['state' => $state]); //,false //die($res); if ($res) { if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_state', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 json(200, '编辑成功'); } else { if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_state', 'status' => 201, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 json(201, '编辑失败'); } } if ($act == 'del') { //删除卡密 $id = isset($_POST['id']) ? $_POST['id'] : ''; if ($id) { $ids = ''; foreach ($id as $value) { $ids .= intval($value) . ","; } $ids = rtrim($ids, ","); $res = Db::table('kami')->where('id', 'in', '(' . $ids . ')')->del(); //false //die($res); if ($res) { if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_del', 'status' => 200, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 json(200, '删除成功'); } else { if (defined('ADM_LOG') && ADM_LOG == 1) { Db::table('log')->add(['group' => 'adm', 'type' => 'kami_del', 'status' => 201, 'time' => time(), 'ip' => getip(), 'data' => json_encode($_POST)]); } //记录日志 json(201, '删除失败'); } } else { json(201, '没有需要删除的数据'); } } ?>