From f021fe38377189fab68bcad3de8c04854fe01fed Mon Sep 17 00:00:00 2001 From: LMR <59361885@qq.com> Date: Mon, 6 Jan 2025 14:16:50 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=8E=E5=A4=96=E9=83=A8=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E4=BA=BAname?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/models/logs_model.php | 491 ++++++++++++++---------------- 1 file changed, 234 insertions(+), 257 deletions(-) diff --git a/application/models/logs_model.php b/application/models/logs_model.php index 6a168bff..67e839a3 100644 --- a/application/models/logs_model.php +++ b/application/models/logs_model.php @@ -1,109 +1,98 @@ HT = $this->load->database('INFORMATION', true); +class Logs_model extends CI_Model { + + public $insert_id = -1; + public $top_num = false; + public $log_res_id = false; + public $log_id = false; + public $log_action = false; + public $order_by = false; + public $log_datetime = false; + + public function __construct() { + parent::__construct(); + $this->HT = $this->load->database('INFORMATION', true); + } + + public function init() { + $this->top_num = false; + $this->log_res_id = false; + $this->log_id = false; + $this->log_action = false; + $this->log_datetime = false; + $this->order_by = " ORDER BY il.log_id DESC "; + } + + //获取日志详情. + public function read($log_id) { + $this->init(); + $this->top_num = 1; + $this->log_id = " AND il.log_id =" . $this->HT->escape($log_id); + return $this->get_list(); + } + + //获取备份信息内容 + public function get_backup_list($is_id) { + $this->init(); + $this->top_num = 16; + $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); + $this->log_action = " AND il.log_action = 'backup_info'"; + return $this->get_list(); + } + + //获取最近的备份信息内容 + public function get_last_backup($is_id) { + $this->init(); + $this->top_num = 1; + $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); + $this->log_action = " AND il.log_action = 'backup_info'"; + return $this->get_list(); + } + + //获取所有备份信息内容 + public function get_all_backup_list($is_id, $amp = false) { + $this->init(); + $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); + if ($amp) { + $this->log_action = " AND (il.log_action = 'backup_amp')"; + } else { + $this->log_action = " AND (il.log_action = 'backup_info')"; } - public function init() - { - $this->top_num = false; - $this->log_res_id = false; - $this->log_id = false; - $this->log_action = false; - $this->log_datetime = false; - $this->order_by = " ORDER BY il.log_id DESC "; + return $this->get_list(); + } + + //获取最后操作信息 + public function get_last_edit($is_id) { + $this->init(); + $this->top_num = 1; + $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); + return $this->get_list(); + } + + public function get_last_log() { + $this->init(); + $this->top_num = 1; + $this->log_action = " AND il.log_action = 'backup_info'"; + $this->order_by = " ORDER BY log_id DESC"; + return $this->get_list(); + } + + public function get_last_cdn_update_info() { + $this->init(); + $this->top_num = 1; + $this->log_action = " AND il.log_action = 'update_cdn'"; + return $this->get_list(); + } + + public function get_uncdn_list($last_id = false) { + $map = ''; + if ($last_id) { + $map = " AND log_id > $last_id"; } - //获取日志详情. - public function read($log_id) - { - $this->init(); - $this->top_num = 1; - $this->log_id = " AND il.log_id =" . $this->HT->escape($log_id); - return $this->get_list(); - } - - //获取备份信息内容 - public function get_backup_list($is_id) - { - $this->init(); - $this->top_num = 16; - $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); - $this->log_action = " AND il.log_action = 'backup_info'"; - return $this->get_list(); - } - - //获取最近的备份信息内容 - public function get_last_backup($is_id) - { - $this->init(); - $this->top_num = 1; - $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); - $this->log_action = " AND il.log_action = 'backup_info'"; - return $this->get_list(); - } - - //获取所有备份信息内容 - public function get_all_backup_list($is_id, $amp = false) - { - $this->init(); - $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); - if ($amp) { - $this->log_action = " AND (il.log_action = 'backup_amp')"; - } else { - $this->log_action = " AND (il.log_action = 'backup_info')"; - } - - return $this->get_list(); - } - - //获取最后操作信息 - public function get_last_edit($is_id) - { - $this->init(); - $this->top_num = 1; - $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); - return $this->get_list(); - } - - public function get_last_log() - { - $this->init(); - $this->top_num = 1; - $this->log_action = " AND il.log_action = 'backup_info'"; - $this->order_by = " ORDER BY log_id DESC"; - return $this->get_list(); - } - - public function get_last_cdn_update_info() - { - $this->init(); - $this->top_num = 1; - $this->log_action = " AND il.log_action = 'update_cdn'"; - return $this->get_list(); - } - - public function get_uncdn_list($last_id = false) - { - $map = ''; - if ($last_id) { - $map = " AND log_id > $last_id"; - } - - $sql = " SELECT log_id,is_sitecode,ic_url + $sql = " SELECT log_id,is_sitecode,ic_url FROM infoLogs LEFT JOIN infoStructures ON is_id=log_res_id LEFT JOIN infoContents ON is_ic_id=ic_id @@ -112,115 +101,103 @@ class Logs_model extends CI_Model $map ORDER BY log_id ASC"; - $query = $this->HT->query($sql); - return $query->result(); + $query = $this->HT->query($sql); + return $query->result(); + } + + public function get_list_by_action() { + $this->init(); + $this->top_num = 50; + $this->log_action = " AND il.log_action = 'send_mail'"; + $this->order_by = " ORDER BY log_id DESC"; + return $this->get_list(); + } + + public function get_list() { + $this->top_num ? $sql = "SELECT TOP " . $this->top_num : $sql = "SELECT "; + $sql .= " il.log_id, \n" + . " il.log_action, \n" + . " il.log_res_id, \n" + . " il.log_ht_usercode, \n" + . " il.log_ht_username, \n" + . " il.log_content, \n" + . " il.log_datetime \n" + . "FROM infoLogs il \n" + . "WHERE 1=1 \n"; + $this->log_res_id ? $sql .= $this->log_res_id : false; + $this->log_id ? $sql .= $this->log_id : false; + $this->log_action ? $sql .= $this->log_action : false; + $this->log_datetime ? $sql .= $this->log_datetime : false; + $this->order_by ? $sql .= $this->order_by : false; + $query = $this->HT->query($sql); + if ($this->top_num == 1) { + if ($query->num_rows() > 0) { + $row = $query->row(); + return $row; + } else { + return false; + } + } else { + return $query->result(); } - - public function get_list_by_action() - { - $this->init(); - $this->top_num = 50; - $this->log_action = " AND il.log_action = 'send_mail'"; - $this->order_by = " ORDER BY log_id DESC"; - return $this->get_list(); - } - - public function get_list() - { - $this->top_num ? $sql = "SELECT TOP " . $this->top_num : $sql = "SELECT "; - $sql .= " il.log_id, \n" - . " il.log_action, \n" - . " il.log_res_id, \n" - . " il.log_ht_usercode, \n" - . " il.log_ht_username, \n" - . " il.log_content, \n" - . " il.log_datetime \n" - . "FROM infoLogs il \n" - . "WHERE 1=1 \n"; - $this->log_res_id ? $sql .= $this->log_res_id : false; - $this->log_id ? $sql .= $this->log_id : false; - $this->log_action ? $sql .= $this->log_action : false; - $this->log_datetime ? $sql .= $this->log_datetime : false; - $this->order_by ? $sql .= $this->order_by : false; - $query = $this->HT->query($sql); - if ($this->top_num == 1) { - if ($query->num_rows() > 0) { - $row = $query->row(); - return $row; - } else { - return false; - } - } else { - return $query->result(); - } - } - - //备份信息内容 - public function backup_project($p_id, $log_content) - { - return $this->write('backup_project', $p_id, $log_content); - } - - //备份信息内容 - public function backup($is_id, $log_content) - { - return $this->write('backup_info', $is_id, $log_content); - } - - //备份信息meta内容,lmr - 2020/03/12 - public function backup_meta($is_id, $log_content, $meta_code) - { - $add_icid_time_flug = 'backup_meta_' . $meta_code . '_' . $is_id . '_' . time(); - $this->write($add_icid_time_flug, $is_id, $log_content); - return $add_icid_time_flug; - } - //列表信息meta内容,lmr - 2020/03/23 - public function list_backup_meta($is_id, $meta_code) - { - $this->init(); - $this->top_num = 50; - $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); - $this->log_action = " AND il.log_action like 'backup_meta_" . $meta_code . "_%'"; - return $this->get_list(); - } - //制定读取信息meta内容,lmr - 2020/03/23 - public function pick_backup_meta($action) - { - $this->init(); - $this->top_num = 1; - $this->log_action = " AND il.log_action =" . $this->HT->escape($action); - return $this->get_list(); - } - - //备份信息简介 - public function backup_summary($is_id, $log_content) - { - return $this->write('backup_summary', $is_id, $log_content); - } - - //添加信息 - public function add($is_id) - { - return $this->write('add_info', $is_id); - } - - //删除信息 - public function delete($is_id, $log_content) - { - return $this->write('delete_info', $is_id, $log_content); - } - - //移动信息 - public function move($is_id_array) - { - //移动是很多个信息节点变动的,在日志内容中记录所有几点id - return $this->write('move_info', 0, $is_id_array); - } - - //写入测试,看看数据库写入是否正常 - public function write_test() - { - $sql = " + } + + //备份信息内容 + public function backup_project($p_id, $log_content) { + return $this->write('backup_project', $p_id, $log_content); + } + + //备份信息内容 + public function backup($is_id, $log_content) { + return $this->write('backup_info', $is_id, $log_content); + } + + //备份信息meta内容,lmr - 2020/03/12 + public function backup_meta($is_id, $log_content, $meta_code) { + $add_icid_time_flug = 'backup_meta_' . $meta_code . '_' . $is_id . '_' . time(); + $this->write($add_icid_time_flug, $is_id, $log_content); + return $add_icid_time_flug; + } + //列表信息meta内容,lmr - 2020/03/23 + public function list_backup_meta($is_id, $meta_code) { + $this->init(); + $this->top_num = 50; + $this->log_res_id = " AND il.log_res_id =" . $this->HT->escape($is_id); + $this->log_action = " AND il.log_action like 'backup_meta_" . $meta_code . "_%'"; + return $this->get_list(); + } + //制定读取信息meta内容,lmr - 2020/03/23 + public function pick_backup_meta($action) { + $this->init(); + $this->top_num = 1; + $this->log_action = " AND il.log_action =" . $this->HT->escape($action); + return $this->get_list(); + } + + //备份信息简介 + public function backup_summary($is_id, $log_content) { + return $this->write('backup_summary', $is_id, $log_content); + } + + //添加信息 + public function add($is_id) { + return $this->write('add_info', $is_id); + } + + //删除信息 + public function delete($is_id, $log_content) { + return $this->write('delete_info', $is_id, $log_content); + } + + //移动信息 + public function move($is_id_array) { + //移动是很多个信息节点变动的,在日志内容中记录所有几点id + return $this->write('move_info', 0, $is_id_array); + } + + //写入测试,看看数据库写入是否正常 + public function write_test() { + $sql = " INSERT INTO infoLogs ( log_action @@ -234,58 +211,58 @@ class Logs_model extends CI_Model ( ?,?,N?,?,N?,GETDATE()) "; - $query = $this->HT->query($sql, array('write_test', 0, '数据库写入测试', 'system', 'system')); - $this->insert_id = $this->HT->last_id('infoLogs'); - if (empty($this->insert_id)) { - return false; - } else { - return $this->insert_id; - } + $query = $this->HT->query($sql, array('write_test', 0, '数据库写入测试', 'system', 'system')); + $this->insert_id = $this->HT->last_id('infoLogs'); + if (empty($this->insert_id)) { + return false; + } else { + return $this->insert_id; } - - //写入操作日志 - public function write($log_action, $is_id, $log_content = '') - { - $admin_info = $this->session->userdata('session_admin'); - $sql = "INSERT INTO infoLogs \n" - . " ( \n" - . " log_action, log_res_id, log_content, log_ht_usercode, log_ht_username, \n" - . " log_datetime \n" - . " ) \n" - . "VALUES \n" - . " ( \n" - . " ?, ?, N?, ?, N?, GETDATE() \n" - . " )"; - - // fix 外部站点调用 - $op_code = null; - if ($admin_info['OPI_Code']) { - $op_code = $admin_info['OPI_Code']; - } - - $op_name = 'outside'; - if ($admin_info['OPI_Name']) { - $op_name = $admin_info['OPI_Name']; - } - - $query = $this->HT->query($sql, array($log_action, $is_id, $log_content, $op_code, $op_name)); - $this->insert_id = $this->HT->last_id('infoLogs'); - return $query; - //print_r($this->HT->queries); + } + + //写入操作日志 + public function write($log_action, $is_id, $log_content = '') { + $admin_info = $this->session->userdata('session_admin'); + $sql = "INSERT INTO infoLogs \n" + . " ( \n" + . " log_action, log_res_id, log_content, log_ht_usercode, log_ht_username, \n" + . " log_datetime \n" + . " ) \n" + . "VALUES \n" + . " ( \n" + . " ?, ?, N?, ?, N?, GETDATE() \n" + . " )"; + + // fix 外部站点调用 + $op_code = null; + if ($admin_info['OPI_Code']) { + $op_code = $admin_info['OPI_Code']; } - public function update($log_action, $log_res_id) - { - $sql = "UPDATE infoLogs SET log_res_id=? WHERE log_action=?"; - $query = $this->HT->query($sql, array($log_res_id, $log_action)); - return $query; + $op_name = $this->input->get_post('opname'); + if (empty($op_name)) { + $op_name = 'outside'; } - - //查询上一次修改记录 - public function get_last_edit_amp($ic_id) - { - $sql = 'select top 1 log_id from infoLogs where log_res_id = ? order by log_datetime desc'; - $query = $this->HT->query($sql, array($ic_id)); - return $query->row(); + if ($admin_info['OPI_Name']) { + $op_name = $admin_info['OPI_Name']; } + + $query = $this->HT->query($sql, array($log_action, $is_id, $log_content, $op_code, $op_name)); + $this->insert_id = $this->HT->last_id('infoLogs'); + return $query; + //print_r($this->HT->queries); + } + + public function update($log_action, $log_res_id) { + $sql = "UPDATE infoLogs SET log_res_id=? WHERE log_action=?"; + $query = $this->HT->query($sql, array($log_res_id, $log_action)); + return $query; + } + + //查询上一次修改记录 + public function get_last_edit_amp($ic_id) { + $sql = 'select top 1 log_id from infoLogs where log_res_id = ? order by log_datetime desc'; + $query = $this->HT->query($sql, array($ic_id)); + return $query->row(); + } } \ No newline at end of file