Action.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace app\common\model;
  3. use app\hander\HelpHander;
  4. use think\Db;
  5. use think\Model;
  6. class Action extends Model
  7. {
  8. public function lists(){
  9. $lists = Db::name('action')
  10. ->order('id asc')
  11. ->select();
  12. return $lists?$lists:[];
  13. }
  14. public function logInfo($id){
  15. $info = Db::name('action_log')
  16. ->alias('al')
  17. ->join('action a','a.id = al.action_id')
  18. ->join('user_info ui','ui.user_id = al.user_id')
  19. ->join('user u','u.id = al.user_id')
  20. ->where('al.id',$id)
  21. ->field('al.id,al.create_time,al.content,al.device,al.data,a.name as module,u.code,ui.name')
  22. ->find();
  23. if(!$info){
  24. HelpHander::error('记录不存在');
  25. }
  26. if($info['data']){
  27. $info['data'] = json_decode($info['data'],true);
  28. }
  29. return $info;
  30. }
  31. // 日志列表
  32. public function selectActionLog($page,$size,$name,$code,$actionId,$startTime,$endTime){
  33. if($name){
  34. $map[] = ['ui.name','like','%'.$name.'%'];
  35. }
  36. if($code){
  37. $map[] = ['u.code','like','%'.$code.'%'];
  38. }
  39. if($actionId){
  40. $map[] = ['al.action_id','=',$actionId];
  41. }
  42. if($startTime&&$endTime){
  43. $map[] = ['al.create_time','>=',$startTime];
  44. $map[] = ['al.create_time','<=',$endTime];
  45. }
  46. $map = !empty($map)?$map:true;
  47. $lists = Db::name('action_log')
  48. ->alias('al')
  49. ->join('action a','a.id = al.action_id')
  50. ->join('user_info ui','ui.user_id = al.user_id')
  51. ->join('user u','u.id = al.user_id')
  52. ->where($map)
  53. ->page($page,$size)
  54. ->field('al.id,al.create_time,al.content,al.device,a.name as module,u.code,ui.name')
  55. ->order('al.id desc')
  56. ->select();
  57. $total = Db::name('action_log')
  58. ->alias('al')
  59. ->join('action a','a.id = al.action_id')
  60. ->join('user_info ui','ui.user_id = al.user_id')
  61. ->join('user u','u.id = al.user_id')
  62. ->where($map)->count();
  63. $data = [
  64. 'total' => $total,
  65. 'list' => $lists?$lists:[]
  66. ];
  67. return $data;
  68. }
  69. // 日志导出
  70. public function selectOperationLog($name,$code,$actionId,$startTime,$endTime){
  71. if($name){
  72. $map[] = ['ui.name','like','%'.$name.'%'];
  73. }
  74. if($code){
  75. $map[] = ['u.code','like','%'.$code.'%'];
  76. }
  77. if($actionId){
  78. $map[] = ['al.action_id','=',$actionId];
  79. }
  80. if($startTime&&$endTime){
  81. $map[] = ['al.create_time','>=',$startTime];
  82. $map[] = ['al.create_time','<=',$endTime];
  83. }
  84. $map = !empty($map)?$map:true;
  85. $lists = Db::name('action_log')
  86. ->alias('al')
  87. ->join('action a','a.id = al.action_id')
  88. ->join('user_info ui','ui.user_id = al.user_id')
  89. ->join('user u','u.id = al.user_id')
  90. ->where($map)
  91. ->field('al.id,al.create_time,al.content,al.device,a.name as module,u.code,ui.name')
  92. ->order('al.id desc')
  93. ->select();
  94. $columns = [
  95. ["title" => "序号","key" => "id"],
  96. ["title" => "日志行为","key" => "module"],
  97. ["title" => "操作人","key" => "name"],
  98. ["title" => "操作人工号","key" => "code"],
  99. ["title" => "操作说明","key" => "createTime"],
  100. ["title" => "操作动作","key" => "content"],
  101. ];
  102. $data = [
  103. 'columns' => $columns,
  104. 'list' => $lists?$lists:[]
  105. ];
  106. return $data;
  107. }
  108. }