auth->id ?? -1; $page = $this->request->get('page', 1); $page_size = $this->request->get('page_size', 10); $tab = $this->request->get('tab', 'all'); $accountType = $this->request->get('accountType', ''); $where = [ 'user_id' => $user_id, ]; if ($tab != 'all') { $where['inc_or_exp'] = $tab == 'income' ? 1 : 2; } if ($accountType) { $where['account_type'] = $accountType == 'amount' ? ['in', ['amount', 'freeze']] : $accountType; } $list = AccountLogService::getList($where, $page_size, 'id desc')->toArray(); $this->success('', $list); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } public function info() { $user_id = $this->auth->id ?? -1; $data = AccountService::getOne(['user_id' => $user_id]); $this->success('success', $data); } public function applyWithdraw() { try { $user_id = $this->auth->id ?? -1; $amount = $this->request->post('amount', 0); $name = $this->request->post('name', ''); // 验证参数(单笔 0.1~200 元,与 AccountWithdrawService 中的限制保持一致) $error = $this->validate($this->request->post(), [ 'name' => 'require', 'amount' => 'require|number|float|between:' . AccountWithdrawService::WITHDRAW_MIN_AMOUNT . ',' . AccountWithdrawService::WITHDRAW_MAX_AMOUNT, ], [ 'name.require' => '微信真实姓名必填', 'amount.require' => '提现金额不正确', 'amount.number' => '提现金额必须为数字', 'amount.float' => '提现金额必须为数字', 'amount.between' => '单笔提现金额需在' . AccountWithdrawService::WITHDRAW_MIN_AMOUNT . '~' . AccountWithdrawService::WITHDRAW_MAX_AMOUNT . '元之间', ]); if (true !== $error) { throw new \Exception($error); } AccountWithdrawService::applyWithdraw($user_id, $amount, $name); $this->success('提现申请成功,1-3个工作日到账'); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } /** * 免确认收款授权(发起/查询),供前端 wx.requestMerchantTransfer 拉起授权页 * @ApiMethod (POST) */ public function transferAuthorization() { try { $user_id = $this->auth->id ?? 0; if (!$user_id) { throw new \Exception('请先登录'); } $user = UserService::get($user_id); if (!$user) { throw new \Exception('用户不存在'); } //授权详情展示账号名:优先微信实名(提现填写的姓名),其次昵称 $displayName = $user->username ?: ($user->nickname ?: ''); $res = TransferAuthorizationService::apply($user, $displayName); $this->success('', $res); } catch (\Exception $e) { if ($e instanceof HttpResponseException) { throw $e; } $this->error($e->getMessage()); } } /** * 免确认收款授权结果回调(微信异步通知,已加入 noNeedLogin) * @return void */ public function transferAuthorizationNotify() { header('Content-Type: application/json; charset=utf-8'); try { // PSR-7 响应(SDK 已完成验签/解密,业务失败返回 500 由微信重试) $response = (new EasyWeChatService())->handleTransferAuthorizationNotify( function (PayMessage $message) { TransferAuthorizationService::handleAuthorizationNotify($message->toArray()); } ); http_response_code($response->getStatusCode()); foreach ($response->getHeaders() as $name => $values) { header($name . ': ' . implode(', ', $values)); } $body = $response->getBody()->getContents(); Log::info('免确认收款授权回调[应答] http_code=' . $response->getStatusCode() . ' body=' . $body); echo $body; exit; } catch (\Throwable $e) { Log::error('免确认收款授权回调[异常]:' . json_encode([ 'msg' => $e->getMessage(), 'file' => $e->getFile() . ':' . $e->getLine(), ], JSON_UNESCAPED_UNICODE)); http_response_code(500); echo json_encode(['code' => 'FAIL', 'message' => $e->getMessage()], JSON_UNESCAPED_UNICODE); exit; } } }