StudioApi.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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(!empty($userInfo->role)){
  38. $data['roles'] = json_decode($userInfo->role);
  39. }
  40. if($userInfo->avatar){
  41. $img = str_replace('.jpg','_s.jpg',$userInfo->avatar);
  42. if (App::environment('local')) {
  43. $data['avatar'] = Storage::url($img);
  44. }else{
  45. $data['avatar'] = Storage::temporaryUrl($img, now()->addDays(6));
  46. }
  47. }
  48. return $data;
  49. }
  50. public static function getByIntId($id){
  51. //TODO 改为studio table
  52. if(empty($id)){
  53. return false;
  54. }
  55. $userInfo = UserInfo::where('id',$id)->first();
  56. if(!$userInfo){
  57. return false;
  58. }
  59. return [
  60. 'id'=>$userInfo['userid'],
  61. 'nickName'=>$userInfo['nickname'],
  62. 'realName'=>$userInfo['username'],
  63. 'studioName'=>$userInfo['username'],
  64. 'avatar'=>'',
  65. ];
  66. }
  67. }