AiAssistantApi.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. 'roles' => ['ai'],
  32. 'sn' => 0,
  33. ];
  34. if ($user->avatar) {
  35. $img = str_replace('.jpg', '_s.jpg', $user->avatar);
  36. if (App::environment('local')) {
  37. $data['avatar'] = Storage::url($img);
  38. } else {
  39. $data['avatar'] = Storage::temporaryUrl($img, now()->addDays(6));
  40. }
  41. }
  42. return $data;
  43. }
  44. }