AdminHistory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace App\Models\Manager;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 后台管理员操作历史
  7. *
  8. */
  9. class AdminHistory extends Model
  10. {
  11. use HasFactory;
  12. // 与模型关联的表名
  13. protected $table = 'admin_history';
  14. // 定义时间戳字段名
  15. // const CREATED_AT = 'insert_time';
  16. // const UPDATED_AT = 'update_time';
  17. /**
  18. * 添加数据
  19. *
  20. * @param Int $uid 用户ID
  21. * @param String $table 操作表
  22. * @param Int $type 操作类型,1添加,2修改,3=删除
  23. * @param Array $oldData 旧数据
  24. * @param Array $oldData 新数据
  25. * @param String $general_description 操作描述
  26. *
  27. */
  28. public function addAll($admin_menu_name, $uid, $is_admin, $table, $type, $oldData, $newData, $general_description = '')
  29. {
  30. $insert_data = [
  31. // 模块菜单名称
  32. 'module_menu_name' => $admin_menu_name,
  33. //操作描述
  34. 'general_description' => $general_description,
  35. // 操作类型
  36. 'notes_type' => $type,
  37. // 操作表名
  38. 'table_name' => $table,
  39. // 操作用户
  40. 'admin_uid' => $uid,
  41. // 是否是管理员
  42. 'is_admin' => $is_admin,
  43. // 操作之前
  44. 'before_value' => json_encode($oldData),
  45. // 操作之后
  46. 'after_value' => json_encode($newData),
  47. // 时间
  48. 'insert_time' => time(),
  49. ];
  50. // 结果
  51. $result = $this->insertGetId($insert_data);
  52. // 如果有数据
  53. return $result;
  54. }
  55. }