From 839a457182dc53e9e25ceb4d48b4df3af68bf7b4 Mon Sep 17 00:00:00 2001 From: lcc <805383944@qq.com> Date: Thu, 18 Sep 2025 17:11:35 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=90=8E=E5=8F=B0=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=94=A8=E6=88=B7=E6=93=8D=E4=BD=9C=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/pingan/organization/User.php | 29 +++++++ .../pingan/organization/UserLog.php | 80 +++++++++++++++++++ .../agent/pingan/Pingan_users_log_model.php | 50 ++++++++++++ 3 files changed, 159 insertions(+) create mode 100644 agent/admin/controllers/pingan/organization/UserLog.php create mode 100644 common/models/agent/pingan/Pingan_users_log_model.php diff --git a/agent/admin/controllers/pingan/organization/User.php b/agent/admin/controllers/pingan/organization/User.php index af889076..7a18163a 100644 --- a/agent/admin/controllers/pingan/organization/User.php +++ b/agent/admin/controllers/pingan/organization/User.php @@ -15,6 +15,7 @@ class User extends BaseController $this->load->model('agent/organization/Organization_model', 'mdOrganization'); $this->load->model('area_model'); $this->load->model('agent/pingan/Pingan_sys_role_model', 'mdSysRole'); + $this->load->model('agent/pingan/pingan_users_log_model', 'pinganUsersLog'); } public function page_get() @@ -245,6 +246,7 @@ class User extends BaseController $updateNum = 0; //更新用户数量 $orgTeamId = $_SESSION['orgTeamId'] ?: self::DEFAULT_ORG_TEAM_ID; $org = $this->mdOrganization->get(['id' => $orgTeamId]); + $ck = bin2hex($this->security->get_random_bytes(16)); for ($i = 2; $i <= $rowCnt; $i++) { //读取内容 $name = $objWorksheet->getCell('A' . $i)->getValue(); $userCode = $objWorksheet->getCell('B' . $i)->getValue(); @@ -289,6 +291,11 @@ class User extends BaseController $roleCode = "role-{$areaAddData['groupType']}"; $role[$roleCode] && $areaAddData['roleId'] = $role[$roleCode]; $areaUserId = $this->pinganUsers->add($areaAddData); + $logData = [ + 'optUserId' => $_SESSION['id'], 'userId' => $areaUserId, 'ck' => $ck, + 'filePath' => $uploadDir, 'afterData' => $areaAddData + ]; + $this->pinganUsersLog->add($logData); } } if ($depCode) { //获取部门用户uid @@ -311,6 +318,11 @@ class User extends BaseController $roleCode = "role-{$depAddData['groupType']}"; $role[$roleCode] && $depAddData['roleId'] = $role[$roleCode]; $depUserId = $this->pinganUsers->add($depAddData); + $logData = [ + 'optUserId' => $_SESSION['id'], 'userId' => $depUserId, 'ck' => $ck, + 'filePath' => $uploadDir, 'afterData' => json_encode($depAddData, JSON_UNESCAPED_UNICODE) + ]; + $this->pinganUsersLog->add($logData); } } if ($teamCode) { //获取团队用户id @@ -334,6 +346,11 @@ class User extends BaseController $roleCode = "role-{$teamAddData['groupType']}"; $role[$roleCode] && $teamAddData['roleId'] = $role[$roleCode]; $teamUserId = $this->pinganUsers->add($teamAddData); + $logData = [ + 'optUserId' => $_SESSION['id'], 'userId' => $teamUserId, 'ck' => $ck, + 'filePath' => $uploadDir, 'afterData' => json_encode($teamAddData, JSON_UNESCAPED_UNICODE) + ]; + $this->pinganUsersLog->add($logData); } } $userData = [ @@ -359,12 +376,24 @@ class User extends BaseController debug_log("更新结果:" . $result, $log_file); if (is_numeric($result) && $result) { $updateNum += 1; + $logData = [ + 'optUserId' => $_SESSION['id'], 'userId' => $user['id'], 'ck' => $ck, + 'filePath' => $uploadDir, 'type' => Pingan_users_log_model::TYPE_UPDATE, + 'beforeData' => json_encode($user, JSON_UNESCAPED_UNICODE), + 'afterData' => json_encode($userData, JSON_UNESCAPED_UNICODE) + ]; + $this->pinganUsersLog->add($logData); } } else { debug_log("新增数据:" . json_encode($userData, JSON_UNESCAPED_UNICODE), $log_file); $result = $this->pinganUsers->add($userData); if ($result) { $successNum += 1; + $logData = [ + 'optUserId' => $_SESSION['id'], 'userId' => $result, 'ck' => $ck, + 'filePath' => $uploadDir, 'afterData' => json_encode($userData, JSON_UNESCAPED_UNICODE) + ]; + $this->pinganUsersLog->add($logData); } } } diff --git a/agent/admin/controllers/pingan/organization/UserLog.php b/agent/admin/controllers/pingan/organization/UserLog.php new file mode 100644 index 00000000..89a01ab4 --- /dev/null +++ b/agent/admin/controllers/pingan/organization/UserLog.php @@ -0,0 +1,80 @@ +load->model('agent/pingan/pingan_users_model', 'pinganUsers'); + $this->load->model('agent/pingan/pingan_users_log_model', 'pinganUsersLog'); + } + + public function page_get() + { + $params = $this->input_param(); + $page = $this->input_param('page'); + $limit = $this->input_param('limit'); + $username = $this->input_param('username'); + $userCode = $this->input_param('userCode'); + $sort = $this->input_param('sort'); + $order = $this->input_param('order'); + !$page && $page = 1; + !$limit && $limit = 10; + $sort_order = 'id desc'; + if ($sort && $order) { + $sort_order = $sort . ' ' . $order; + } + $where = $list = []; + if ($username) { + $where["userId in (select id from lc_pingan_users where username LIKE '%{$username}%')"] = null; + } + if ($userCode) { + $where["userId in (select id from lc_pingan_users where userCode LIKE '%{$userCode}%')"] = null; + } + if ($params['dateRange'][0] && $params['dateRange'][1]) { + $where['optTime >='] = $params['dateRange'][0] . ' 00:00:00'; + $where['optTime <='] = $params['dateRange'][1] . ' 23:59:59'; + } + $params['type'] && $where['type'] = $params['type']; + $count = $this->pinganUsersLog->count($where); + if ($count) { + $res = $this->pinganUsersLog->select($where, $sort_order, $page, $limit); + $optIdArray = array_column($res, 'optUserId'); + $userIdArray = array_column($res, 'userId'); + $userIdArray = array_merge($optIdArray, $userIdArray); + $userIds = implode(',', $userIdArray); + $mapUsers = []; + if ($userIds) { + $where = ["id in ({$userIds})" => null]; + $mapUsers = $this->pinganUsers->map('id', '', $where, '', 0, 0, 'id,username,userCode'); + } + foreach ($res as $v) { + $userInfo = $mapUsers[$v['userId']] ? $mapUsers[$v['userId']][0] : []; + $result = $this->pinganUsersLog->getChangeData($v); + $list[] = [ + 'id' => $v['id'], + 'optUserName' => $mapUsers[$v['optUserId']] ? $mapUsers[$v['optUserId']][0]['username'] : '', + 'userInfo' => $userInfo, + 'beforeContent' => $result['beforeContent'], + 'afterContent' => $result['afterContent'], + 'typeCn' => Pingan_users_log_model::TYPE_LIST[$v['type']], + 'optTime' => $v['optTime'] + ]; + } + } + $data = ['list' => $list, 'count' => $count]; + $this->return_response_list($data); + } + + public function search_get() + { + $data = [ + 'typeList' => Pingan_users_log_model::TYPE_LIST + ]; + $this->return_response_list($data); + } +} \ No newline at end of file diff --git a/common/models/agent/pingan/Pingan_users_log_model.php b/common/models/agent/pingan/Pingan_users_log_model.php new file mode 100644 index 00000000..7591b693 --- /dev/null +++ b/common/models/agent/pingan/Pingan_users_log_model.php @@ -0,0 +1,50 @@ + '新增', + self::TYPE_UPDATE => '更新' + ]; + const SHOW_CONTENT_LIST = [ + "username" => "姓名", + "userCode" => "工号", + "centerNumber" => "中心", + "orgName" => "归属机构" + ]; + + public function __construct() + { + parent::__construct($this->table_name, 'default'); + } + + public function getChangeData($row) + { + $this->load->model('agent/pingan/pingan_users_model'); + $beforeData = json_decode($row['beforeData'], true); + $afterData = json_decode($row['afterData'], true); + $beforeContent = ""; + $afterContent = ""; + foreach (self::SHOW_CONTENT_LIST as $key => $value) { + if ($beforeData[$key] != $afterData[$key]) { + $beforeValue = $beforeData[$key] ?: ""; + $afterValue = $afterData[$key] ?: ""; + if ($key == "centerNumber") { + $beforeValue && $beforeValue = Pingan_users_model::TYPE_CENTER[$beforeValue]; + $afterValue && $afterValue = Pingan_users_model::TYPE_CENTER[$afterValue]; + } + $beforeContent .= "$value: 【{$beforeValue}】"; + $afterContent .= "$value: 【{$afterValue}】"; + } + } + return [ + 'beforeContent' => $beforeContent, + 'afterContent' => $afterContent + ]; + } +} \ No newline at end of file