AdminTransformer.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Repositories\Transformers\Base;
  3. use App\Repositories\Models\Base\Admin;
  4. use League\Fractal\TransformerAbstract;
  5. class AdminTransformer extends TransformerAbstract
  6. {
  7. /**
  8. * Prepare data to present.
  9. *
  10. * @param Admin $admin
  11. * @return array
  12. */
  13. public function transform(Admin $admin)
  14. {
  15. // if (request()->has('id')) {
  16. // return [
  17. // 'id' => $admin->id,
  18. // 'name' => $admin->name,
  19. // 'username' => $admin->username,
  20. // 'mobile' => $admin->mobile,
  21. // 'sex' => $admin->sex,
  22. // 'email' => $admin->email,
  23. //// 'department' => $admin->department,
  24. //// 'job' => $admin->job,
  25. // 'shop' => $admin->shop,
  26. // 'roles' => $admin->roles()->select(['id', 'nickname', 'name'])->get(),
  27. // 'last_login_time' => $admin->last_login_time,
  28. // 'last_login_ip' => $admin->last_login_ip,
  29. //// 'wechat_auth_id' => $admin->wechat_auth_id,
  30. //// 'is_view_user_info' => $admin->is_view_user_info,
  31. //// 'company_id' => $admin->company_id,
  32. //// 'type' => $admin->type,
  33. // 'extra_fields' => $admin->extra_fields,
  34. // 'status' => $admin->status,
  35. // 'created_at' => $admin->created_at ? $admin->created_at->format('Y-m-d H:i:s') : null,
  36. // ];
  37. // }
  38. $department = $admin->department;
  39. if ($admin->shop_id) {
  40. $department = $admin->shop;
  41. }
  42. return [
  43. 'id' => $admin->id,
  44. 'name' => $admin->name,
  45. 'username' => $admin->username,
  46. 'mobile' => $admin->mobile,
  47. 'sex' => $admin->sex,
  48. 'email' => $admin->email,
  49. 'department' =>$department,
  50. // 'job' => $admin->job,
  51. // 'shop' => $admin->shop,
  52. 'roles' => $admin->roles()->select(['id', 'nickname', 'name'])->get(),
  53. 'role' => $admin->roles()->select(['id', 'nickname', 'name'])->orderBy('id', 'asc')->first(),
  54. 'last_login_time' => $admin->last_login_time,
  55. 'last_login_ip' => $admin->last_login_ip,
  56. // 'wechat_auth_id' => $admin->wechat_auth_id,
  57. // 'is_view_user_info' => $admin->is_view_user_info,
  58. // 'company' => $admin->company,
  59. 'extra_fields' => $admin->extra_fields,
  60. 'type' => $admin->type,
  61. 'status' => $admin->status,
  62. 'created_at' => $admin->created_at ? $admin->created_at->format('Y-m-d H:i:s') : null,
  63. ];
  64. }
  65. }