123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?php
- namespace App\Repositories\Transformers\Base;
- use App\Repositories\Models\Base\Admin;
- use League\Fractal\TransformerAbstract;
- class AdminTransformer extends TransformerAbstract
- {
- /**
- * Prepare data to present.
- *
- * @param Admin $admin
- * @return array
- */
- public function transform(Admin $admin)
- {
- // if (request()->has('id')) {
- // return [
- // 'id' => $admin->id,
- // 'name' => $admin->name,
- // 'username' => $admin->username,
- // 'mobile' => $admin->mobile,
- // 'sex' => $admin->sex,
- // 'email' => $admin->email,
- //// 'department' => $admin->department,
- //// 'job' => $admin->job,
- // 'shop' => $admin->shop,
- // 'roles' => $admin->roles()->select(['id', 'nickname', 'name'])->get(),
- // 'last_login_time' => $admin->last_login_time,
- // 'last_login_ip' => $admin->last_login_ip,
- //// 'wechat_auth_id' => $admin->wechat_auth_id,
- //// 'is_view_user_info' => $admin->is_view_user_info,
- //// 'company_id' => $admin->company_id,
- //// 'type' => $admin->type,
- // 'extra_fields' => $admin->extra_fields,
- // 'status' => $admin->status,
- // 'created_at' => $admin->created_at ? $admin->created_at->format('Y-m-d H:i:s') : null,
- // ];
- // }
- $department = $admin->department;
- if ($admin->shop_id) {
- $department = $admin->shop;
- }
- return [
- 'id' => $admin->id,
- 'name' => $admin->name,
- 'username' => $admin->username,
- 'mobile' => $admin->mobile,
- 'sex' => $admin->sex,
- 'email' => $admin->email,
- 'department' =>$department,
- // 'job' => $admin->job,
- // 'shop' => $admin->shop,
- 'roles' => $admin->roles()->select(['id', 'nickname', 'name'])->get(),
- 'role' => $admin->roles()->select(['id', 'nickname', 'name'])->orderBy('id', 'asc')->first(),
- 'last_login_time' => $admin->last_login_time,
- 'last_login_ip' => $admin->last_login_ip,
- // 'wechat_auth_id' => $admin->wechat_auth_id,
- // 'is_view_user_info' => $admin->is_view_user_info,
- // 'company' => $admin->company,
- 'extra_fields' => $admin->extra_fields,
- 'type' => $admin->type,
- 'status' => $admin->status,
- 'created_at' => $admin->created_at ? $admin->created_at->format('Y-m-d H:i:s') : null,
- ];
- }
- }
|