User.php 6.0 KB

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