Rebate.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. 'account' => ['nullable', 'string', 'max:64'],
  27. 'first_name' => ['nullable', 'string'],
  28. ]);
  29. $result = RebateService::paginate($search);
  30. } catch (ValidationException $e) {
  31. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  32. } catch (Exception $e) {
  33. return $this->error(intval($e->getCode()));
  34. }
  35. return $this->success($result);
  36. }
  37. public function store()
  38. {
  39. DB::beginTransaction();
  40. try {
  41. $params = request()->validate([
  42. 'id' => ['required', 'integer', 'min:1'],
  43. ]);
  44. $params['status'] = RebateModel::STATUS_WEI_FAN_YONG;
  45. $rebate = RebateService::findOne($params);
  46. if (!$rebate) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR);
  47. $date = Carbon::now('America/New_York')->format('Y-m-d');
  48. if (strtotime($rebate->date) >= strtotime($date)) {
  49. throw new Exception('未到发放时间', HttpStatus::CUSTOM_ERROR);
  50. }
  51. RebateService::BibiReturn($rebate, $rebate->effective_betting_amount);
  52. DB::commit();
  53. } catch (ValidationException $e) {
  54. DB::rollBack();
  55. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  56. } catch (Exception $e) {
  57. DB::rollBack();
  58. return $this->error(intval($e->getCode()), $e->getMessage());
  59. }
  60. return $this->success();
  61. }
  62. }