AiAssistantApi.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Models\AiModel;
  4. use Illuminate\Support\Facades\Log;
  5. use Illuminate\Support\Facades\Storage;
  6. use Illuminate\Support\Facades\App;
  7. class AiAssistantApi
  8. {
  9. public static function getByUuid($id)
  10. {
  11. $user = AiModel::where('uid', $id)->first();
  12. return self::userInfo($user);
  13. }
  14. public static function userInfo($user)
  15. {
  16. if (!$user) {
  17. Log::error('$user=null;');
  18. return [
  19. 'id' => 0,
  20. 'nickName' => 'unknown',
  21. 'userName' => 'unknown',
  22. 'realName' => 'unknown',
  23. 'avatar' => '',
  24. ];
  25. }
  26. $data = [
  27. 'id' => $user->uid,
  28. 'nickName' => $user->name,
  29. 'userName' => $user->real_name,
  30. 'realName' => $user->real_name,
  31. 'sn' => 0,
  32. ];
  33. if ($user->avatar) {
  34. $img = str_replace('.jpg', '_s.jpg', $user->avatar);
  35. if (App::environment('local')) {
  36. $data['avatar'] = Storage::url($img);
  37. } else {
  38. $data['avatar'] = Storage::temporaryUrl($img, now()->addDays(6));
  39. }
  40. }
  41. return $data;
  42. }
  43. }