AdminHistory.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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, $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. 'before_value' => json_encode($oldData),
  43. // 操作之后
  44. 'after_value' => json_encode($newData),
  45. // 时间
  46. 'insert_time' => time(),
  47. ];
  48. // 结果
  49. $result = $this->insertGetId($insert_data);
  50. // 如果有数据
  51. return $result;
  52. }
  53. }