service = $service; } /** * [钱包]获取钱包信息 * * @description 获取技师钱包余额和收入统计信息 * * @authenticated * * @response { * "data": { * "balance": "1000.00", * "frozen_amount": "0.00", * "total_income": "5000.00", * "total_withdraw": "4000.00", * "today_income": "100.00", * "month_income": "2000.00", * "last_month_income": "3000.00" * } * } */ public function getWallet() { return $this->success($this->service->getWallet(Auth::user()->id)); } /** * [钱包]获取钱包流水记录 * * @description 获取技师钱包的收支明细记录 * * @authenticated * * @queryParam type integer 记录类型(1:收入 2:支出) Example: 1 * @queryParam start_date date 开始日期 Example: 2024-01-01 * @queryParam end_date date 结束日期 Example: 2024-03-21 * @queryParam min_amount numeric 最小金额 Example: 100 * @queryParam max_amount numeric 最大金额 Example: 1000 * @queryParam status integer 交易状态(1:成功 2:处理中 3:失败) Example: 1 * @queryParam sort_field string 排序字段(created_at, amount, balance) Example: created_at * @queryParam sort_order string 排序顺序(asc, desc) Example: desc * @queryParam page integer 页码 Example: 1 * @queryParam per_page integer 每页数量 Example: 10 * * @response { * "data": { * "items": [ * { * "id": 1, * "amount": "100.00", * "type": 1, * "remark": "订单收入", * "created_at": "2024-03-21 10:00:00" * } * ], * "total": 100 * } * } */ public function getWalletRecords(Request $request) { $params = $request->validate([ 'type' => 'nullable|integer|in:1,2', 'start_date' => 'nullable|date', 'end_date' => 'nullable|date|after_or_equal:start_date', 'min_amount' => 'nullable|numeric|min:0', 'max_amount' => 'nullable|numeric|gt:min_amount', 'status' => 'nullable|integer|in:1,2,3', 'sort_field' => 'nullable|string|in:created_at,amount,balance', 'sort_order' => 'nullable|string|in:asc,desc', 'page' => 'nullable|integer|min:1', 'per_page' => 'nullable|integer|min:1|max:50', ]); return $this->success($this->service->getWalletRecords(Auth::user()->id, $params)); } /** * [钱包]申请提现 * * @description 技师申请提现到指定账户 * * @authenticated * * @bodyParam amount numeric required 提现金额(最低100元) Example: 100.00 * @bodyParam withdraw_type integer required 提现方式(1:微信 2:支付宝 3:银行卡) Example: 1 * @bodyParam withdraw_account string required 提现账号 Example: example@alipay.com * @bodyParam withdraw_account_name string required 提现账户名称 Example: 张三 * * @response { * "message": "提现申请已提交", * "trans_no": "W202403211234567890", * "amount": "100.00", * "status": "处理中" * } * @response 422 { * "message": "可提现余额不足" * } */ 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->success($this->service->withdraw(Auth::user()->id, $data)); } }