AdminHistory.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Models\Manager;
  3. use Illuminate\Database\Eloquent\Factories\HasFactory;
  4. use Illuminate\Database\Eloquent\Model;
  5. use App\Models\Manager\AdminUser as AdminUserModel;
  6. use App\Models\Manager\Personnel\Employee as EmployeeModel;
  7. use App\Models\manager\External\Company as CompanyModel;
  8. /**
  9. * 后台管理员操作历史
  10. *
  11. */
  12. class AdminHistory extends Model
  13. {
  14. use HasFactory;
  15. // 与模型关联的表名
  16. protected $table = 'admin_history';
  17. // 定义时间戳字段名
  18. // const CREATED_AT = 'insert_time';
  19. // const UPDATED_AT = 'update_time';
  20. /**
  21. * 添加数据
  22. *
  23. * @param Int $uid 用户ID
  24. * @param String $table 操作表
  25. * @param Int $type 操作类型,1添加,2修改,3=删除
  26. * @param Array $oldData 旧数据
  27. * @param Array $oldData 新数据
  28. * @param String $general_description 操作描述
  29. *
  30. */
  31. public function addAll($admin_menu_name,$company_id='0', $uid, $is_admin, $table, $type, $oldData, $newData, $general_description = '')
  32. {
  33. $user_name = '';
  34. if ($is_admin == 1){
  35. $user_name = (new AdminUserModel())->where(['uid'=>$uid])->value('username');
  36. }else{
  37. $user_name = (new EmployeeModel())->where(['id'=>$uid])->value('name');
  38. }
  39. $company_name = (new CompanyModel())->where(['id'=>$company_id])->value('company_name');
  40. $insert_data = [
  41. // 操作用户
  42. 'user_name' => isset($user_name)? $user_name : '',
  43. // 品牌方公司名称
  44. 'company_name' => isset($company_name)? $company_name : '',
  45. // 公司ID
  46. 'company_id' => $company_id,
  47. // 模块菜单名称
  48. 'module_menu_name' => $admin_menu_name,
  49. //操作描述
  50. 'general_description' => $general_description,
  51. // 操作类型
  52. 'notes_type' => $type,
  53. // 操作表名
  54. 'table_name' => $table,
  55. // 操作用户
  56. 'admin_uid' => $uid,
  57. // 是否是管理员
  58. 'is_admin' => $is_admin,
  59. // 操作之前
  60. 'before_value' => json_encode($oldData),
  61. // 操作之后
  62. 'after_value' => json_encode($newData),
  63. // 时间
  64. 'insert_time' => time(),
  65. ];
  66. // 结果
  67. $result = $this->insertGetId($insert_data);
  68. // 如果有数据
  69. return $result;
  70. }
  71. }