管理后台增加用户操作日志
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
require_once APPPATH . 'controllers/api/BaseController.php';
|
||||
require_once COMMPATH . '/third_party/PHPExcel/IOFactory.php';
|
||||
|
||||
|
||||
class UserLog extends BaseController
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Pingan_users_log_model extends HD_Model
|
||||
{
|
||||
private $table_name = 'lc_pingan_users_log';
|
||||
const TYPE_ADD = 1;
|
||||
const TYPE_UPDATE = 2;
|
||||
|
||||
const TYPE_LIST = [
|
||||
self::TYPE_ADD => '新增',
|
||||
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
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user