User.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\SecretService;
  6. use App\Services\TopUpService;
  7. use Illuminate\Support\Facades\App;
  8. use Illuminate\Support\Facades\DB;
  9. use App\Services\UserService;
  10. use App\Services\RegisterStatService;
  11. use Exception;
  12. use Illuminate\Validation\ValidationException;
  13. use App\Services\AddressService;
  14. use Illuminate\Http\JsonResponse;
  15. use App\Models\User as UserModel;
  16. use App\Models\UserSession;
  17. use App\Models\UserLogin;
  18. use App\Models\ThirdGameRecycle;
  19. use App\Models\Wallet;
  20. use App\Services\BalanceLogService;
  21. use App\Services\ThirdGameBalanceService;
  22. use Illuminate\Support\Facades\Cache;
  23. use Illuminate\Support\Str;
  24. class User extends Controller
  25. {
  26. //修改用户密码/资金密码
  27. function setPassword()
  28. {
  29. try {
  30. $params = request()->validate([
  31. 'member_id' => ['required', 'string', 'min:1'],
  32. 'password' => ['nullable'],
  33. 'payment_password' => ['nullable'],
  34. ]);
  35. $user = UserModel::where('member_id', $params['member_id'])->first();
  36. if (!$user) throw new Exception("用户不存在", HttpStatus::CUSTOM_ERROR);
  37. if (!empty($params['password'])) {
  38. $user->password = create_password($params['password']);
  39. $user->save();
  40. //删除缓存
  41. $token = UserSession::where('user_id', $params['member_id'])->orderByDesc('expire_time')->value('token');
  42. Cache::delete('token_user_' . $token);
  43. UserSession::where('user_id', $params['member_id'])->delete();
  44. }
  45. if (!empty($params['payment_password'])) {
  46. $user->payment_password = password_hash($params['payment_password'], PASSWORD_DEFAULT);
  47. $user->save();
  48. }
  49. } catch (ValidationException $e) {
  50. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  51. } catch (Exception $e) {
  52. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  53. }
  54. return $this->success();
  55. }
  56. function banned()
  57. {
  58. try {
  59. $params = request()->validate([
  60. 'member_id' => ['required', 'string', 'min:1'],
  61. 'is_banned' => ['required', 'integer', 'in:0,1'],
  62. ]);
  63. UserModel::where('member_id', $params['member_id'])->update(['is_banned' => $params['is_banned']]);
  64. if ($params['is_banned'] == 1) {
  65. //如果用户被禁用,删除所有会话
  66. UserSession::where('user_id', $params['member_id'])->delete();
  67. return $this->success();
  68. }
  69. } catch (ValidationException $e) {
  70. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  71. } catch (Exception $e) {
  72. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  73. }
  74. return $this->success();
  75. }
  76. function setNote()
  77. {
  78. try {
  79. $params = request()->validate([
  80. 'member_id' => ['required', 'string', 'min:1'],
  81. 'admin_note' => ['required', 'string', 'min:1', 'max:120'],
  82. ]);
  83. $user = UserModel::where('member_id', $params['member_id'])->first();
  84. if (!$user) throw new Exception("用户不存在", HttpStatus::CUSTOM_ERROR);
  85. $user->admin_note = $params['admin_note'];
  86. $user->save();
  87. } catch (ValidationException $e) {
  88. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  89. } catch (Exception $e) {
  90. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  91. }
  92. return $this->success();
  93. }
  94. public function index(): JsonResponse
  95. {
  96. try {
  97. $search = request()->validate([
  98. 'page' => ['nullable', 'integer', 'min:1'],
  99. 'limit' => ['nullable', 'integer', 'min:1'],
  100. 'member_id' => ['nullable', 'string', 'min:1'],
  101. 'like_first_name' => ['nullable', 'string', 'min:1'],
  102. 'username' => ['nullable', 'string', 'min:1'],
  103. 'register_ip' => ['nullable', 'string', 'min:1'],
  104. 'order' => ["nullable", 'string', "in:asc,desc"],
  105. 'by' => ['nullable', 'string', "in:available_balance,created_at,last_active_time"],
  106. 'user_code' => ['nullable'],
  107. 'agent_user_code' => ['nullable'],
  108. 'level' => ['nullable'],
  109. 'from' => ['nullable'],
  110. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'],
  111. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
  112. 'recharge_channel_group_id' => ['nullable'],
  113. ]);
  114. $order = request()->input('order', 'desc');
  115. $by = request()->input('by', 'available_balance');
  116. $result = UserService::paginate($search,$order,$by);
  117. } catch (ValidationException $e) {
  118. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first().'ssss');
  119. } catch (Exception $e) {
  120. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  121. }
  122. return $this->success($result);
  123. }
  124. /**
  125. * 查询指定用户在 ag、pg 等三方游戏平台的余额明细。
  126. */
  127. public function thirdGameDetail(ThirdGameBalanceService $service): JsonResponse
  128. {
  129. try {
  130. $params = request()->validate([
  131. 'member_id' => ['required', 'string', 'min:1'],
  132. ]);
  133. if (!UserModel::where('member_id', $params['member_id'])->exists()) {
  134. throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
  135. }
  136. $result = $service->detail((string) $params['member_id']);
  137. if (!$result['ok']) {
  138. throw new Exception($result['msg'], HttpStatus::CUSTOM_ERROR);
  139. }
  140. unset($result['ok']);
  141. return $this->success($result);
  142. } catch (ValidationException $e) {
  143. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  144. } catch (Exception $e) {
  145. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  146. }
  147. }
  148. /**
  149. * 一键回收指定用户的全部三方游戏余额并入账主钱包。
  150. */
  151. public function recycleThirdGameBalance(ThirdGameBalanceService $service): JsonResponse
  152. {
  153. $lock = null;
  154. $lockAcquired = false;
  155. try {
  156. $params = request()->validate([
  157. 'member_id' => ['required', 'string', 'min:1'],
  158. ]);
  159. $memberId = (string) $params['member_id'];
  160. if (!UserModel::where('member_id', $memberId)->exists()) {
  161. throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
  162. }
  163. if (!Wallet::where('member_id', $memberId)->exists()) {
  164. throw new Exception('用户钱包不存在', HttpStatus::CUSTOM_ERROR);
  165. }
  166. $lock = Cache::lock('admin_third_game_recycle:' . $memberId, 120);
  167. $lockAcquired = $lock->get();
  168. if (!$lockAcquired) {
  169. throw new Exception('该用户正在回收三方余额,请勿重复操作', HttpStatus::CUSTOM_ERROR);
  170. }
  171. $pendingCredit = ThirdGameRecycle::where('member_id', $memberId)
  172. ->where('status', ThirdGameRecycle::STATUS_PROVIDER_SUCCEEDED)
  173. ->orderBy('id')
  174. ->first();
  175. if ($pendingCredit) {
  176. try {
  177. $credited = $this->creditThirdGameRecycle($pendingCredit->id);
  178. } catch (Exception $e) {
  179. throw new Exception(
  180. '三方余额已回收但钱包补入账失败,流水号:' . $pendingCredit->operation_id,
  181. HttpStatus::CUSTOM_ERROR
  182. );
  183. }
  184. $credited['recovered_pending_operation'] = true;
  185. return $this->success($credited);
  186. }
  187. $unresolved = ThirdGameRecycle::where('member_id', $memberId)
  188. ->whereIn('status', [
  189. ThirdGameRecycle::STATUS_PENDING,
  190. ThirdGameRecycle::STATUS_UNCERTAIN,
  191. ])
  192. ->orderByDesc('id')
  193. ->first();
  194. if ($unresolved) {
  195. throw new Exception(
  196. '存在待核对的三方回收流水:' . $unresolved->operation_id . ',请先人工核对三方账单',
  197. HttpStatus::CUSTOM_ERROR
  198. );
  199. }
  200. $operation = ThirdGameRecycle::create([
  201. 'operation_id' => (string) Str::uuid(),
  202. 'member_id' => $memberId,
  203. 'player_id' => $service->playerId($memberId),
  204. 'status' => ThirdGameRecycle::STATUS_PENDING,
  205. ]);
  206. $recycled = $service->recycle($memberId);
  207. if (!$recycled['ok']) {
  208. $operation->status = !empty($recycled['uncertain'])
  209. ? ThirdGameRecycle::STATUS_UNCERTAIN
  210. : ThirdGameRecycle::STATUS_FAILED;
  211. $operation->error = $recycled['msg'];
  212. $operation->save();
  213. throw new Exception(
  214. $recycled['msg'] . ',流水号:' . $operation->operation_id,
  215. HttpStatus::CUSTOM_ERROR
  216. );
  217. }
  218. $operation->status = ThirdGameRecycle::STATUS_PROVIDER_SUCCEEDED;
  219. $operation->game_balance = $recycled['game_balance'];
  220. $operation->wallet_balance = $recycled['wallet_balance'];
  221. $operation->save();
  222. try {
  223. $credited = $this->creditThirdGameRecycle($operation->id);
  224. } catch (Exception $e) {
  225. throw new Exception(
  226. '三方余额已回收但钱包入账失败,请重试回收以补入账,流水号:' . $operation->operation_id,
  227. HttpStatus::CUSTOM_ERROR
  228. );
  229. }
  230. return $this->success($credited);
  231. } catch (ValidationException $e) {
  232. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  233. } catch (Exception $e) {
  234. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  235. } finally {
  236. if ($lockAcquired && $lock) {
  237. $lock->release();
  238. }
  239. }
  240. }
  241. /**
  242. * 将三方已回收的流水幂等入账;事务失败时保留 provider_succeeded 供下次补偿。
  243. */
  244. private function creditThirdGameRecycle(int $operationId): array
  245. {
  246. return DB::transaction(function () use ($operationId) {
  247. $operation = ThirdGameRecycle::where('id', $operationId)->lockForUpdate()->firstOrFail();
  248. if ($operation->status === ThirdGameRecycle::STATUS_COMPLETED) {
  249. $walletBalance = (float) Wallet::where('member_id', $operation->member_id)
  250. ->value('available_balance');
  251. return $this->recycleResponse($operation, $walletBalance);
  252. }
  253. if ($operation->status !== ThirdGameRecycle::STATUS_PROVIDER_SUCCEEDED) {
  254. throw new Exception('三方回收流水状态不可入账', HttpStatus::CUSTOM_ERROR);
  255. }
  256. $wallet = Wallet::where('member_id', $operation->member_id)->lockForUpdate()->firstOrFail();
  257. $before = (string) $wallet->available_balance;
  258. $walletGain = (string) $operation->wallet_balance;
  259. $after = bcadd($before, $walletGain, 10);
  260. if (bccomp($walletGain, '0', 10) > 0) {
  261. BalanceLogService::addLog(
  262. $operation->member_id,
  263. $walletGain,
  264. $before,
  265. $after,
  266. '三方游戏转出',
  267. $operation->id,
  268. '后台一键回收游戏余额'
  269. );
  270. $wallet->available_balance = $after;
  271. $wallet->save();
  272. }
  273. $operation->status = ThirdGameRecycle::STATUS_COMPLETED;
  274. $operation->credited_at = now();
  275. $operation->save();
  276. return $this->recycleResponse($operation, (float) $after);
  277. });
  278. }
  279. private function recycleResponse(ThirdGameRecycle $operation, float $walletBalance): array
  280. {
  281. return [
  282. 'operation_id' => $operation->operation_id,
  283. 'member_id' => $operation->member_id,
  284. 'recovered_game_balance' => (float) $operation->game_balance,
  285. 'recovered_balance' => (float) $operation->wallet_balance,
  286. 'wallet_balance' => $walletBalance,
  287. ];
  288. }
  289. /**
  290. * 查询三方游戏回收流水,用于核对 pending/uncertain 状态。
  291. */
  292. public function thirdGameRecycleRecords(): JsonResponse
  293. {
  294. try {
  295. $params = request()->validate([
  296. 'page' => ['nullable', 'integer', 'min:1'],
  297. 'limit' => ['nullable', 'integer', 'min:1', 'max:100'],
  298. 'member_id' => ['nullable', 'string', 'min:1'],
  299. 'status' => ['nullable', 'string', 'in:pending,provider_succeeded,completed,failed,uncertain'],
  300. ]);
  301. $page = (int) ($params['page'] ?? 1);
  302. $limit = (int) ($params['limit'] ?? 15);
  303. $query = ThirdGameRecycle::query()
  304. ->when(!empty($params['member_id']), function ($query) use ($params) {
  305. $query->where('member_id', $params['member_id']);
  306. })
  307. ->when(!empty($params['status']), function ($query) use ($params) {
  308. $query->where('status', $params['status']);
  309. });
  310. $total = (clone $query)->count();
  311. $list = $query->orderByDesc('id')->forPage($page, $limit)->get();
  312. return $this->success(['total' => $total, 'data' => $list]);
  313. } catch (ValidationException $e) {
  314. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  315. } catch (Exception $e) {
  316. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  317. }
  318. }
  319. /**
  320. * 人工核对待确认流水:确认未回收,或按三方实际金额补入账。
  321. */
  322. public function resolveThirdGameRecycle(ThirdGameBalanceService $service): JsonResponse
  323. {
  324. $lock = null;
  325. $lockAcquired = false;
  326. try {
  327. $params = request()->validate([
  328. 'operation_id' => ['required', 'uuid'],
  329. 'action' => ['required', 'string', 'in:failed,credit'],
  330. 'game_balance' => ['nullable', 'required_if:action,credit', 'numeric', 'min:0'],
  331. 'remark' => ['nullable', 'string', 'max:500'],
  332. ]);
  333. $operation = ThirdGameRecycle::where('operation_id', $params['operation_id'])->first();
  334. if (!$operation) {
  335. throw new Exception('三方回收流水不存在', HttpStatus::CUSTOM_ERROR);
  336. }
  337. $lock = Cache::lock('admin_third_game_recycle:' . $operation->member_id, 120);
  338. $lockAcquired = $lock->get();
  339. if (!$lockAcquired) {
  340. throw new Exception('该用户正在处理三方回收,请稍后再试', HttpStatus::CUSTOM_ERROR);
  341. }
  342. $operation = DB::transaction(function () use ($operation, $params, $service) {
  343. $operation = ThirdGameRecycle::where('id', $operation->id)->lockForUpdate()->firstOrFail();
  344. if (!in_array($operation->status, [
  345. ThirdGameRecycle::STATUS_PENDING,
  346. ThirdGameRecycle::STATUS_UNCERTAIN,
  347. ], true)) {
  348. throw new Exception('当前流水状态无需人工处理', HttpStatus::CUSTOM_ERROR);
  349. }
  350. $remark = trim((string) ($params['remark'] ?? ''));
  351. if ($params['action'] === 'failed') {
  352. $operation->status = ThirdGameRecycle::STATUS_FAILED;
  353. $operation->resolution_remark = '后台人工核对:确认三方未回收'
  354. . ($remark !== '' ? ';' . $remark : '');
  355. } else {
  356. $gameBalance = (float) $params['game_balance'];
  357. $operation->status = ThirdGameRecycle::STATUS_PROVIDER_SUCCEEDED;
  358. $operation->game_balance = $gameBalance;
  359. $operation->wallet_balance = $service->toWalletBalance($gameBalance);
  360. $operation->resolution_remark = '后台人工核对:确认三方已回收'
  361. . ($remark !== '' ? ';' . $remark : '');
  362. }
  363. $operation->save();
  364. return $operation;
  365. });
  366. if ($params['action'] === 'failed') {
  367. return $this->success([
  368. 'operation_id' => $operation->operation_id,
  369. 'member_id' => $operation->member_id,
  370. 'status' => $operation->status,
  371. ]);
  372. }
  373. try {
  374. $credited = $this->creditThirdGameRecycle($operation->id);
  375. } catch (Exception $e) {
  376. throw new Exception(
  377. '核对金额已保存但钱包入账失败,请再次提交回收操作补入账,流水号:' . $operation->operation_id,
  378. HttpStatus::CUSTOM_ERROR
  379. );
  380. }
  381. $credited['resolved_manually'] = true;
  382. return $this->success($credited);
  383. } catch (ValidationException $e) {
  384. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  385. } catch (Exception $e) {
  386. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  387. } finally {
  388. if ($lockAcquired && $lock) {
  389. $lock->release();
  390. }
  391. }
  392. }
  393. public function merge(): JsonResponse
  394. {
  395. DB::beginTransaction();
  396. try {
  397. $params = request()->validate([
  398. 'member_id' => ['required', 'string', 'min:1'],
  399. 'secret_key' => ['required', 'string', 'min:1'],
  400. ]);
  401. $res = SecretService::migration($params['member_id'], $params['secret_key']);
  402. if (!$res) {
  403. throw new Exception(lang("迁移失败"), HttpStatus::CUSTOM_ERROR);
  404. }
  405. $oldUser = UserModel::where('secret_key', $params['secret_key'])->first();
  406. $newUser = UserModel::where('member_id', $params['member_id'])->first();
  407. App::setLocale($oldUser->language);
  408. $text = lang('账户转移通知') . ":\n";
  409. $text .= lang('管理员已将您的账户转移至新用户') . "\n\n";
  410. $text .= lang('新用户信息') . "\n";
  411. $text .= lang('用户ID') . ":{$newUser->getMemberId()}\n";
  412. if ($newUser->getUsername()) {
  413. $text .= lang("用户名") . ":@{$newUser->getUsername()}\n";
  414. }
  415. $text .= lang('昵称') . ":{$newUser->getFirstName()}\n";
  416. TopUpService::notifyTransferSuccess($oldUser->getMemberId(), $text);
  417. App::setLocale($newUser->language);
  418. $text = lang("账户转移通知") . ":\n";
  419. $text .= lang("管理员已将指定账户转移至您的账户") . "\n\n";
  420. $text .= lang('原账户信息') . "\n\n";
  421. $text .= lang('用户ID') . ":{$oldUser->getMemberId()}\n";
  422. if ($oldUser->getUsername()) {
  423. $text .= lang('用户名') . ":@{$oldUser->getUsername()}\n";
  424. }
  425. $text .= lang('昵称') . ":{$oldUser->getFirstName()}\n";
  426. TopUpService::notifyTransferSuccess($newUser->getMemberId(), $text);
  427. DB::commit();
  428. } catch (ValidationException $e) {
  429. DB::rollBack();
  430. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  431. } catch (Exception $e) {
  432. DB::rollBack();
  433. if ($e->getCode() == HttpStatus::CUSTOM_ERROR) {
  434. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  435. }
  436. return $this->error(intval($e->getCode()));
  437. }
  438. return $this->success(msg: '已完成迁移');
  439. }
  440. public function address()
  441. {
  442. try {
  443. request()->validate([
  444. 'member_id' => ['required', 'integer', 'min:1'],
  445. ]);
  446. $search = request()->all();
  447. $result = AddressService::findAll($search);
  448. } catch (ValidationException $e) {
  449. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  450. } catch (Exception $e) {
  451. return $this->error(intval($e->getCode()));
  452. }
  453. return $this->success($result);
  454. }
  455. /**
  456. * 用户登录日志(只读,不写库、不打外网)
  457. */
  458. public function loginLog()
  459. {
  460. try {
  461. $params = request()->validate([
  462. 'page' => ['nullable', 'integer', 'min:1'],
  463. 'limit' => ['nullable', 'integer', 'min:1'],
  464. 'user_id' => ['nullable'],
  465. 'member_id' => ['nullable'],
  466. 'first_name' => ['nullable'],
  467. 'status' => ['nullable', 'integer', 'in:0,1'],
  468. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:end_time'],
  469. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'required_with:start_time'],
  470. ]);
  471. $page = (int)request()->input('page', 1);
  472. $limit = (int)request()->input('limit', 15);
  473. $query = UserLogin::query()
  474. ->leftJoin('users', 'user_login.user_id', '=', 'users.user_id')
  475. ->select([
  476. 'user_login.id',
  477. 'user_login.user_id',
  478. 'user_login.login_account',
  479. 'user_login.login_ip',
  480. 'user_login.login_domain',
  481. 'user_login.country',
  482. 'user_login.browser',
  483. 'user_login.os',
  484. 'user_login.platform',
  485. 'user_login.status',
  486. 'user_login.logout_time',
  487. 'user_login.online_duration',
  488. 'user_login.user_agent',
  489. 'user_login.created_at',
  490. 'user_login.updated_at',
  491. 'users.member_id',
  492. 'users.first_name',
  493. 'users.account',
  494. 'users.username',
  495. ]);
  496. if (!empty($params['user_id'])) {
  497. $query->where('user_login.user_id', $params['user_id']);
  498. }
  499. if (!empty($params['member_id'])) {
  500. $query->where('user_login.user_id', $params['member_id']);
  501. }
  502. if (!empty($params['first_name'])) {
  503. $query->where('users.first_name', 'like', "%{$params['first_name']}%");
  504. }
  505. if (array_key_exists('status', $params) && $params['status'] !== null) {
  506. $query->where('user_login.status', (int)$params['status']);
  507. }
  508. if (!empty($params['start_time'])) {
  509. $query->where('user_login.created_at', '>=', $params['start_time'] . ' 00:00:00');
  510. }
  511. if (!empty($params['end_time'])) {
  512. $query->where('user_login.created_at', '<=', $params['end_time'] . ' 23:59:59');
  513. }
  514. $count = (clone $query)->count();
  515. $list = $query
  516. ->forPage($page, $limit)
  517. ->orderByDesc('user_login.id')
  518. ->get();
  519. } catch (Exception $e) {
  520. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  521. }
  522. return $this->success(['total' => $count, 'data' => $list]);
  523. }
  524. /**
  525. * 会员注册走势图
  526. */
  527. public function registerTrend()
  528. {
  529. try {
  530. $params = request()->validate([
  531. 'type' => ['nullable', 'string', 'in:today,all'],
  532. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d'],
  533. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_time'],
  534. ]);
  535. $data = RegisterStatService::trend(
  536. $params['type'] ?? 'today',
  537. $params['start_time'] ?? null,
  538. $params['end_time'] ?? null
  539. );
  540. } catch (Exception $e) {
  541. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  542. }
  543. return $this->success($data);
  544. }
  545. /**
  546. * 注册域名统计
  547. */
  548. public function registerDomain()
  549. {
  550. try {
  551. $params = request()->validate([
  552. 'start_time' => ['nullable', 'date', 'date_format:Y-m-d'],
  553. 'end_time' => ['nullable', 'date', 'date_format:Y-m-d', 'after_or_equal:start_time'],
  554. 'page' => ['nullable', 'integer', 'min:1'],
  555. 'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
  556. ]);
  557. $page = (int)request()->input('page', 1);
  558. $limit = (int)request()->input('limit', 50);
  559. $data = RegisterStatService::domain(
  560. $params['start_time'] ?? null,
  561. $params['end_time'] ?? null,
  562. $page,
  563. $limit
  564. );
  565. } catch (Exception $e) {
  566. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  567. }
  568. return $this->success($data);
  569. }
  570. function setRechargeChannelGroup()
  571. {
  572. try {
  573. $params = request()->validate([
  574. 'member_id' => ['required', 'array'],
  575. 'recharge_channel_group_id' => ['required', 'integer', 'min:1'],
  576. ]);
  577. UserModel::whereIn('member_id', $params['member_id'])->update(['recharge_channel_group_id' => $params['recharge_channel_group_id']]);
  578. } catch (ValidationException $e) {
  579. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  580. } catch (Exception $e) {
  581. return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
  582. }
  583. return $this->success();
  584. }
  585. }