| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Http\Controllers\admin;
- use App\Constants\HttpStatus;
- use App\Http\Controllers\Controller;
- use App\Models\WalletFreezeRecord;
- use App\Services\ManualAuditService;
- use App\Services\WalletFreezeService;
- use Exception;
- use Illuminate\Validation\ValidationException;
- /** 会员列表 / 人工稽查的冻结、解冻,以及冻结记录列表。 */
- class WalletFreeze extends Controller
- {
- private const AMOUNT_PATTERN = '/^\d{1,20}(?:\.\d{1,10})?$/';
- public function index()
- {
- try {
- $params = request()->validate([
- 'page' => ['nullable', 'integer', 'min:1'],
- 'limit' => ['nullable', 'integer', 'min:1', 'max:200'],
- 'member_id' => ['nullable', 'string', 'max:64'],
- 'account' => ['nullable', 'string', 'max:64'],
- 'type' => ['nullable', 'string', 'in:' . implode(',', array_keys(WalletFreezeRecord::TYPE_LABELS))],
- 'status' => ['nullable', 'string', 'in:' . implode(',', array_keys(WalletFreezeRecord::STATUS_LABELS))],
- 'start_date' => ['nullable', 'date_format:Y-m-d', 'required_with:end_date'],
- 'end_date' => ['nullable', 'date_format:Y-m-d', 'required_with:start_date', 'after_or_equal:start_date'],
- ]);
- return $this->success(WalletFreezeService::list($params));
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
- }
- }
- public function freeze()
- {
- return $this->apply(true);
- }
- public function unfreeze()
- {
- return $this->apply(false);
- }
- private function apply(bool $isFreeze)
- {
- try {
- $params = request()->validate([
- 'request_id' => ['required', 'uuid'],
- 'member_id' => ['nullable', 'required_without:account', 'string', 'max:64'],
- 'account' => ['nullable', 'required_without:member_id', 'string', 'max:64'],
- 'amount' => ['required', 'numeric', 'min:0.01', 'regex:' . self::AMOUNT_PATTERN],
- 'wager_amount' => ['required', 'numeric', 'min:0', 'regex:' . self::AMOUNT_PATTERN],
- 'reason' => ['required', 'string', 'min:1', 'max:255'],
- ]);
- $memberId = ManualAuditService::resolveMemberId($params['member_id'] ?? null, $params['account'] ?? null);
- $method = $isFreeze ? 'freeze' : 'unfreeze';
- return $this->success(WalletFreezeService::$method((string)$params['request_id'], (int)request()->user->id, $memberId,
- (string)$params['amount'], (string)$params['wager_amount'], trim((string)$params['reason'])));
- } catch (ValidationException $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
- } catch (Exception $e) {
- return $this->error(HttpStatus::CUSTOM_ERROR, $e->getMessage());
- }
- }
- }
|