Oper.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace addons\shopro\library;
  3. use app\admin\library\Auth as AdminAuth;
  4. use addons\shopro\model\Store;
  5. use addons\shopro\model\User;
  6. class Oper
  7. {
  8. public static function set($operType = '', $operId = 0)
  9. {
  10. if ($operType === '') {
  11. // 自动获取操作人
  12. $admin = AdminAuth::instance(); // 没有登录返回的还是这个类实例
  13. if ($admin->isLogin()) {
  14. // 后台管理员
  15. $operType = 'admin';
  16. $operId = $admin->id;
  17. } else if (strpos(request()->url(), 'store.store') !== false) {
  18. // 门店
  19. $store = Store::info();
  20. if ($store) {
  21. $operType = 'store';
  22. $operId = $store['id'];
  23. }
  24. } else if (strpos(request()->url(), 'addons/shopro') !== false) {
  25. // 用户
  26. $user = User::info();
  27. if ($user) {
  28. $operType = 'user';
  29. $operId = $user->id;
  30. }
  31. }
  32. }
  33. if ($operType === '') {
  34. $operType = 'system';
  35. }
  36. return [
  37. 'oper_type' => $operType,
  38. 'oper_id' => $operId
  39. ];
  40. }
  41. public static function get($operType, $operId)
  42. {
  43. $operator = null;
  44. if ($operType === 'admin') {
  45. $operator = \app\admin\model\Admin::where('id', $operId)->field('nickname as name, avatar')->find();
  46. $operator['type'] = '管理员';
  47. } elseif ($operType === 'user') {
  48. $operator = \addons\shopro\model\User::where('id', $operId)->field('nickname as name, avatar')->find();
  49. $operator['type'] = '用户';
  50. } elseif ($operType === 'store') {
  51. $operator = \addons\shopro\model\Store::where('id', $operId)->field('name')->find();
  52. $operator['type'] = '用户';
  53. $operator['avatar'] = '';
  54. } else {
  55. $operator = [
  56. 'name' => '系统',
  57. 'avatar' => '',
  58. 'type' => '系统'
  59. ];
  60. }
  61. if(!isset($operator['name'])) {
  62. $operator['name'] = '已删除';
  63. $operator['avatar'] = '';
  64. }
  65. return $operator;
  66. }
  67. }