ActivityUser.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Illuminate\Http\JsonResponse;
  10. use Illuminate\Support\Facades\Cache;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Validation\ValidationException;
  13. use Exception;
  14. use App\Models\ActivityUser as ActivityUserModel;
  15. class ActivityUser extends Controller
  16. {
  17. public function finish(): JsonResponse
  18. {
  19. DB::beginTransaction();
  20. try {
  21. $params = request()->validate([
  22. 'id' => ['required', 'integer', 'min:1'],
  23. ]);
  24. DB::commit();
  25. } catch (ValidationException $e) {
  26. DB::rollBack();
  27. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  28. } catch (Exception $e) {
  29. DB::rollBack();
  30. return $this->error($e->getCode(), $e->getMessage());
  31. }
  32. return $this->success();
  33. }
  34. //赠送金额(充值)
  35. public function gift()
  36. {
  37. DB::beginTransaction();
  38. try {
  39. $params = request()->validate([
  40. 'id' => ['required', 'integer', 'min:1'],
  41. 'amount' => ['required', 'numeric', 'min:0.01'],
  42. 'effective_betting_amount' => ['required', 'integer', 'min:0', 'max:9999999'],
  43. ]);
  44. ActivityUserService::gift($params['id'], $params['amount'], $params['effective_betting_amount']);
  45. DB::commit();
  46. } catch (ValidationException $e) {
  47. DB::rollBack();
  48. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  49. } catch (Exception $e) {
  50. DB::rollBack();
  51. return $this->error($e->getCode(), $e->getMessage());
  52. }
  53. return $this->success();
  54. }
  55. public function index(): JsonResponse
  56. {
  57. try {
  58. $params = request()->validate([
  59. 'page' => ['required', 'integer', 'min:1'],
  60. 'limit' => ['required', 'integer', 'min:1'],
  61. 'title' => ['nullable', 'string'],
  62. 'member_id' => ['nullable', 'string'],
  63. ]);
  64. $page = request()->input('page', 1);
  65. $limit = request()->input('limit', 10);
  66. $where = ActivityUserService::getWhere($params);
  67. $query = ActivityUserModel::where($where);
  68. $count = $query->count();
  69. $list = $query->orderBy('status')
  70. ->orderByDesc('id')
  71. ->forPage($page, $limit)->get()->toArray();
  72. $result = ['total' => $count, 'data' => $list];
  73. } catch (ValidationException $e) {
  74. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  75. } catch (Exception $e) {
  76. return $this->error($e->getCode(), $e->getMessage());
  77. }
  78. return $this->success($result);
  79. }
  80. }