StudioApi.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace App\Http\Api;
  3. use App\Models\UserInfo;
  4. use Illuminate\Support\Facades\Storage;
  5. use Illuminate\Support\Facades\App;
  6. class StudioApi{
  7. public static function getIdByName($name){
  8. /**
  9. * 获取 uuid
  10. */
  11. //TODO 改为studio table
  12. if(empty($name)){
  13. return false;
  14. }
  15. $userInfo = UserInfo::where('username',$name)->first();
  16. if(!$userInfo){
  17. return false;
  18. }else{
  19. return $userInfo->userid;
  20. }
  21. }
  22. public static function getById($id){
  23. //TODO 改为studio table
  24. if(empty($id)){
  25. return false;
  26. }
  27. $userInfo = UserInfo::where('userid',$id)->first();
  28. if(!$userInfo){
  29. return false;
  30. }
  31. $data = [
  32. 'id'=>$id,
  33. 'nickName'=>$userInfo->nickname,
  34. 'realName'=>$userInfo->username,
  35. 'studioName'=>$userInfo->username,
  36. ];
  37. if($userInfo->avatar){
  38. $img = str_replace('.jpg','_s.jpg',$userInfo->avatar);
  39. if (App::environment('local')) {
  40. $data['avatar'] = Storage::url($img);
  41. }else{
  42. $data['avatar'] = Storage::temporaryUrl($img, now()->addDays(6));
  43. }
  44. }
  45. return $data;
  46. }
  47. public static function getByIntId($id){
  48. //TODO 改为studio table
  49. if(empty($id)){
  50. return false;
  51. }
  52. $userInfo = UserInfo::where('id',$id)->first();
  53. if(!$userInfo){
  54. return false;
  55. }
  56. return [
  57. 'id'=>$userInfo['userid'],
  58. 'nickName'=>$userInfo['nickname'],
  59. 'realName'=>$userInfo['username'],
  60. 'studioName'=>$userInfo['username'],
  61. 'avatar'=>'',
  62. ];
  63. }
  64. }