validate([ 'page' => ['nullable', 'integer', 'min:1'], 'limit' => ['nullable', 'integer', 'min:1'], 'member_id' => ['nullable', 'integer', 'min:1'], 'date' => ['nullable', 'date_format:Y-m-d'], 'username' => ['nullable', 'string'], 'first_name' => ['nullable', 'string'], ]); $result = RebateService::paginate($search); } catch (ValidationException $e) { return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { return $this->error(intval($e->getCode())); } return $this->success($result); } public function store() { DB::beginTransaction(); try { $params = request()->validate([ 'id' => ['required', 'integer', 'min:1'], ]); $params['id']; $params['status'] = 0; $rebate = RebateService::findOne($params); if (!$rebate) throw new Exception('数据不存在', HttpStatus::CUSTOM_ERROR); $date = Carbon::now('America/New_York')->format('Y-m-d'); if (strtotime($rebate->date) >= strtotime($date)) { throw new Exception('未到发放时间', HttpStatus::CUSTOM_ERROR); } $rebate_ratio = Config::where('field', 'rebate')->first()->val; $rebateAmount = bcmul($rebate->betting_amount, $rebate_ratio, 2); // 返利金额 $huishuiAmount = 0; //限额 $huishui_restriction = Config::where('field', 'huishui_restriction')->first()->val; //比例 $huishui_percentage = Config::where('field', 'huishui_percentage')->first()->val; $lose = $rebate->profit * -1; if ($lose >= $huishui_restriction) { $huishuiAmount = bcmul($rebate->profit, $huishui_percentage, 2); // 返利金额 } $rebate->huishui_restriction = $huishui_restriction; $rebate->huishui_percentage = $huishui_percentage; $rebate->huishui_amount = $huishuiAmount; $rebate->amount = $rebateAmount; $rebate->rebate_ratio = $rebate_ratio; $rebate->status = 1; $rebate->audited_by = request()->user->username; $rebate->save(); if ($huishuiAmount > 0) { $res = WalletService::updateBalance($rebate->member_id, $huishuiAmount); BalanceLogService::addLog( $rebate->member_id, $huishuiAmount, $res['before_balance'], $res['after_balance'], "回水", $rebate->id, "输{$lose}; 回水{$huishuiAmount}"); } // if ($rebateAmount > 0) { $res = WalletService::updateBalance($rebate->member_id, $rebateAmount); BalanceLogService::addLog( $rebate->member_id, $rebateAmount, $res['before_balance'], $res['after_balance'], '返水', $rebate->id, ''); } DB::commit(); } catch (ValidationException $e) { DB::rollBack(); return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first()); } catch (Exception $e) { DB::rollBack(); return $this->error(intval($e->getCode()), $e->getMessage()); } return $this->success(); } }