ActionLogService.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Common;
  12. use App\Models\ActionLogModel;
  13. use App\Services\BaseService;
  14. /**
  15. * 行为日志-服务类
  16. * @author laravel开发员
  17. * @since 2020/11/12
  18. * Class ActionLogService
  19. * @package App\Services\Common
  20. */
  21. class ActionLogService extends BaseService
  22. {
  23. public static $instance = null;
  24. /**
  25. * 构造函数
  26. * @author laravel开发员
  27. * @since 2020/11/12
  28. * ActionLogService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new ActionLogModel();
  33. }
  34. /**
  35. * 获取城市列表
  36. * @return array
  37. * @since 2020/11/11
  38. * @author laravel开发员
  39. */
  40. public function getList()
  41. {
  42. $param = request()->all();
  43. // 查询条件
  44. $map = [];
  45. // 城市名称
  46. $name = getter($param, "username");
  47. if ($name) {
  48. $map[] = ['username', 'like', "%{$name}%"];
  49. }
  50. $list = $this->model->getList($map, [['create_time', 'desc']]);
  51. if (!empty($list)) {
  52. foreach ($list as &$val) {
  53. $val['create_time'] = $val['create_time']? strtotime($val['create_time']) : time();
  54. }
  55. }
  56. return message("操作成功", true, $list);
  57. }
  58. /**
  59. * 删除七天之前标记软删除的数据
  60. */
  61. public function delete()
  62. {
  63. // 设置日志标题
  64. ActionLogModel::setRecord(session('userId'), ['type' => 1, 'title' => "删除操作日志信息", 'content' => json_encode(request()->post(), 256), 'module' => 'admin']);
  65. ActionLogModel::record();
  66. $this->model->where('mark', 0)->where('update_time', '<=', time() - 7 * 86400)->delete();
  67. return parent::delete();
  68. }
  69. }