123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Http\Controllers\Client;
- use App\Http\Controllers\Controller;
- use App\Services\Client\WalletService;
- use Auth;
- use Illuminate\Http\Request;
- class WalletController extends Controller
- {
- protected WalletService $service;
- public function __construct(WalletService $service)
- {
- $this->service = $service;
- }
-
- public function records()
- {
- return $this->service->getWalletRecords(Auth::user()->id, request('per_page', 10));
- }
-
- public function wallet()
- {
- return $this->service->getUserWallet(Auth::user()->id);
- }
-
- public function withdraw(Request $request)
- {
-
- $data = $request->validate([
- 'amount' => 'required|numeric|min:100',
- 'withdraw_type' => 'required|integer|in:1,2,3',
- 'withdraw_account' => 'required|string|max:100',
- 'withdraw_account_name' => 'required|string|max:50',
- ]);
-
- switch ($data['withdraw_type']) {
- case 1:
- $request->validate([
- 'withdraw_account' => [
- 'required',
- 'string',
- 'regex:/^[a-zA-Z][a-zA-Z\d_-]{5,19}$/',
- 'max:20',
- ],
- ], [
- 'withdraw_account.regex' => '微信号格式不正确',
- ]);
- break;
- case 2:
- $request->validate([
- 'withdraw_account' => [
- 'required',
- 'string',
- function ($attribute, $value, $fail) {
- if (! filter_var($value, FILTER_VALIDATE_EMAIL) && ! preg_match('/^1[3-9]\d{9}$/', $value)) {
- $fail('支付宝账号必须是有效的邮箱或手机号');
- }
- },
- ],
- ]);
- break;
- case 3:
- $request->validate([
- 'withdraw_account' => [
- 'required',
- 'string',
- 'regex:/^\d{16,19}$/',
- ],
- ], [
- 'withdraw_account.regex' => '银行卡号格式不正确',
- ]);
- break;
- }
-
- abort_if(mb_strlen($data['withdraw_account_name']) < 2, 422, '提现账户名称至少2个字符');
- abort_if(! preg_match('/^[\x{4e00}-\x{9fa5}a-zA-Z\s]+$/u', $data['withdraw_account_name']), 422, '提现账户名称只能包含中文、英文字母和空格');
- return $this->service->withdraw(Auth::user()->id, $data);
- }
- }
|