User.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\RoomService;
  6. use App\Services\SecretService;
  7. use App\Services\TopUpService;
  8. use Illuminate\Support\Facades\Auth;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Validator;
  11. use App\Services\UserService;
  12. use Exception;
  13. use Illuminate\Http\Request;
  14. use Illuminate\Validation\ValidationException;
  15. use App\Services\AddressService;
  16. use Illuminate\Http\JsonResponse;
  17. use App\Models\User as UserModel;
  18. class User extends Controller
  19. {
  20. /**
  21. * @api {get} /admin/user 会员列表
  22. * @apiGroup 会员管理
  23. *
  24. * @apiUse result
  25. * @apiUse header
  26. * @apiVersion 1.0.0
  27. *
  28. * @apiParam {int} [page=1]
  29. * @apiParam {int} [limit=10]
  30. * @apiParam {string} [first_name] 用户昵称
  31. * @apiParam {string} [member_id] 房主 tg会员ID
  32. * @apiParam {string} [game_id] 游戏ID
  33. *
  34. * @apiSuccess (data) {Object} data
  35. * @apiSuccess (data) {int} data.total 数量
  36. * @apiSuccess (data) {Object[]} data.data 列表
  37. * @apiSuccess (data) {int} data.data.id
  38. * @apiSuccess (data) {int} data.data.member_id tg会员id
  39. * @apiSuccess (data) {string} data.data.first_name 昵称
  40. * @apiSuccess (data) {string} data.data.usdt 用户usdt钱包地址
  41. * @apiSuccess (data) {string} data.data.game_id 游戏ID
  42. * @apiSuccess (data) {string} data.data.updated_at
  43. * @apiSuccess (data) {string} data.data.created_at
  44. * @apiSuccess (data) {string} data.data.secret_key 找回账号的秘钥
  45. */
  46. public function index()
  47. {
  48. try {
  49. request()->validate([
  50. 'game_id' => ['nullable', 'string', 'min:1'],
  51. 'member_id' => ['nullable', 'string', 'min:1'],
  52. 'first_name' => ['nullable', 'string', 'min:1'],
  53. 'username' => ['nullable', 'string', 'min:1'],
  54. ]);
  55. $search = request()->all();
  56. $result = UserService::paginate($search);
  57. } catch (ValidationException $e) {
  58. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  59. } catch (Exception $e) {
  60. return $this->error(intval($e->getCode()));
  61. }
  62. return $this->success($result);
  63. }
  64. /**
  65. * @api {post} /admin/user/merge 账户合并
  66. * @apiGroup 会员管理
  67. * @apiDescription 合并后,余额,银行卡,USDT地址 将合并到新用户,请谨慎操作
  68. *
  69. * @apiUse result
  70. * @apiUse header
  71. * @apiVersion 1.0.0
  72. *
  73. * @apiParam {string} member_id 接收者的member_id
  74. * @apiParam {string} secret_key 被合并的用户的秘钥
  75. */
  76. public function merge(): JsonResponse
  77. {
  78. DB::beginTransaction();
  79. try {
  80. $params = request()->validate([
  81. 'member_id' => ['required', 'string', 'min:1'],
  82. 'secret_key' => ['required', 'string', 'min:1'],
  83. ]);
  84. $res = SecretService::migration($params['member_id'], $params['secret_key']);
  85. if (!$res) {
  86. throw new Exception(lang("迁移失败"), HttpStatus::CUSTOM_ERROR);
  87. }
  88. $oldUser = UserModel::where('secret_key', $params['secret_key'])->first();
  89. $newUser = UserModel::where('member_id', $params['member_id'])->first();
  90. $text = "账户转移通知:\n";
  91. $text .= "管理员已将您的账户转移至新用户\n\n";
  92. $text .= "新用户信息\n";
  93. $text .= "用户ID:{$newUser->getMemberId()}\n";
  94. $text .= "用户名:{$newUser->getUsername()}\n";
  95. $text .= "昵称:{$newUser->getFirstName()}\n";
  96. TopUpService::notifyTransferSuccess($oldUser->getMemberId(), $text);
  97. $text = "账户转移通知:\n";
  98. $text .= "管理员已将指定账户转移至您的账户\n\n";
  99. $text .= "原账户信息\n\n";
  100. $text .= "用户ID:{$oldUser->getMemberId()}\n";
  101. $text .= "用户名:{$oldUser->getUsername()}\n";
  102. $text .= "昵称:{$oldUser->getFirstName()}\n";
  103. TopUpService::notifyTransferSuccess($newUser->getMemberId(), $text);
  104. DB::commit();
  105. } catch (ValidationException $e) {
  106. DB::rollBack();
  107. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  108. } catch (Exception $e) {
  109. DB::rollBack();
  110. if($e->getCode() == HttpStatus::CUSTOM_ERROR){
  111. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  112. }
  113. return $this->error(intval($e->getCode()));
  114. }
  115. return $this->success(msg: '已完成迁移');
  116. }
  117. public function address()
  118. {
  119. try {
  120. request()->validate([
  121. 'member_id' => ['required', 'integer', 'min:1'],
  122. ]);
  123. $search = request()->all();
  124. $result = AddressService::findAll($search);
  125. } catch (ValidationException $e) {
  126. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  127. } catch (Exception $e) {
  128. return $this->error(intval($e->getCode()));
  129. }
  130. return $this->success($result);
  131. }
  132. }