ActivityUser.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Wallet as WalletModel;
  6. use App\Services\ActivityUserService;
  7. use App\Services\BalanceLogService;
  8. use App\Services\TopUpService;
  9. use App\Support\MemberAccount;
  10. use Illuminate\Http\JsonResponse;
  11. use Illuminate\Support\Facades\Cache;
  12. use Illuminate\Support\Facades\DB;
  13. use Illuminate\Validation\ValidationException;
  14. use Exception;
  15. use App\Models\ActivityUser as ActivityUserModel;
  16. class ActivityUser extends Controller
  17. {
  18. public function finish(): JsonResponse
  19. {
  20. DB::beginTransaction();
  21. try {
  22. $params = request()->validate([
  23. 'id' => ['required', 'integer', 'min:1'],
  24. ]);
  25. ActivityUserService::finish($params['id']);
  26. DB::commit();
  27. } catch (ValidationException $e) {
  28. DB::rollBack();
  29. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  30. } catch (Exception $e) {
  31. DB::rollBack();
  32. return $this->error($e->getCode(), $e->getMessage());
  33. }
  34. return $this->success();
  35. }
  36. //赠送金额(充值)
  37. public function gift()
  38. {
  39. DB::beginTransaction();
  40. try {
  41. $params = request()->validate([
  42. 'id' => ['required', 'integer', 'min:1'],
  43. 'amount' => ['required', 'numeric', 'min:0.01', 'regex:/^\d{1,12}(\.\d{1,2})?$/'],
  44. 'betting_amount' => ['required', 'integer', 'min:0', 'max:9999999'],
  45. ]);
  46. ActivityUserService::gift($params['id'], $params['amount'], $params['betting_amount']);
  47. DB::commit();
  48. } catch (ValidationException $e) {
  49. DB::rollBack();
  50. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  51. } catch (Exception $e) {
  52. DB::rollBack();
  53. return $this->error($e->getCode(), $e->getMessage());
  54. }
  55. return $this->success();
  56. }
  57. public function index(): JsonResponse
  58. {
  59. try {
  60. $params = request()->validate([
  61. 'page' => ['required', 'integer', 'min:1'],
  62. 'limit' => ['required', 'integer', 'min:1'],
  63. 'title' => ['nullable', 'string'],
  64. 'member_id' => ['nullable', 'string'],
  65. 'account' => ['nullable', 'string', 'max:64'],
  66. ]);
  67. $page = request()->input('page', 1);
  68. $limit = request()->input('limit', 10);
  69. $where = ActivityUserService::getWhere($params);
  70. $query = MemberAccount::filter(ActivityUserModel::where($where), $params['account'] ?? null);
  71. $count = $query->count();
  72. $list = $query->orderBy('status')
  73. ->with(['member'])
  74. ->orderByDesc('id')
  75. ->forPage($page, $limit)->get()->toArray();
  76. foreach ($list as &$item)
  77. {
  78. $item['gift_amount'] = floatval($item['gift_amount']);
  79. $item['effective_betting_amount'] = floatval($item['effective_betting_amount']);
  80. $item['betting_amount'] = floatval($item['betting_amount']);
  81. $item['account'] = (string)($item['member']['account'] ?? '');
  82. }
  83. $result = ['total' => $count, 'data' => $list];
  84. } catch (ValidationException $e) {
  85. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  86. } catch (Exception $e) {
  87. return $this->error($e->getCode(), $e->getMessage());
  88. }
  89. return $this->success($result);
  90. }
  91. }