Rebate.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Config;
  6. use App\Services\BalanceLogService;
  7. use App\Services\RebateService;
  8. use App\Services\WalletService;
  9. use Carbon\Carbon;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\DB;
  12. use Illuminate\Validation\ValidationException;
  13. use Exception;
  14. use App\Models\Rebate as RebateModel;
  15. class Rebate extends Controller
  16. {
  17. function index()
  18. {
  19. try {
  20. $search = request()->validate([
  21. 'page' => ['nullable', 'integer', 'min:1'],
  22. 'limit' => ['nullable', 'integer', 'min:1'],
  23. 'member_id' => ['nullable', 'integer', 'min:1'],
  24. 'date' => ['nullable', 'date_format:Y-m-d'],
  25. 'username' => ['nullable', 'string'],
  26. 'first_name' => ['nullable', 'string'],
  27. ]);
  28. $result = RebateService::paginate($search);
  29. } catch (ValidationException $e) {
  30. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  31. } catch (Exception $e) {
  32. return $this->error(intval($e->getCode()));
  33. }
  34. return $this->success($result);
  35. }
  36. public function store()
  37. {
  38. DB::beginTransaction();
  39. try {
  40. $params = request()->validate([
  41. 'id' => ['required', 'integer', 'min:1'],
  42. ]);
  43. $params['status'] = RebateModel::STATUS_WEI_FAN_YONG;
  44. $rebate = RebateService::findOne($params);
  45. if (!$rebate) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
  46. $date = Carbon::now('America/New_York')->format('Y-m-d');
  47. if (strtotime($rebate->date) >= strtotime($date)) {
  48. throw new Exception('未到发放时间', HttpStatus::CUSTOM_ERROR);
  49. }
  50. RebateService::BibiReturn($rebate, $rebate->effective_betting_amount);
  51. DB::commit();
  52. } catch (ValidationException $e) {
  53. DB::rollBack();
  54. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  55. } catch (Exception $e) {
  56. DB::rollBack();
  57. return $this->error(intval($e->getCode()), $e->getMessage());
  58. }
  59. return $this->success();
  60. }
  61. }