json([ 'code' => 200, 'message' => '获取成功', 'data' => $user, ]); } catch (\Exception $e) { Log::error('获取用户信息失败: '.$e->getMessage()); throw $e; } } /** * 更新当前用户信息 * * @return \Illuminate\Http\JsonResponse */ public function updateUserInfo(array $data) { try { // 更新用户信息 $user = Auth::user(); $user->update($data); return response()->json([ 'code' => 200, 'message' => '修改成功', 'data' => null, ]); } catch (\Exception $e) { Log::error('更新用户信息失败: '.$e->getMessage()); throw $e; } } /** * 提交用户反馈 * * @return \Illuminate\Http\JsonResponse */ public function feedback(string $content) { try { // 保存用户反馈 // Feedback::create([ // 'user_id' => Auth::id(), // 'content' => $content, // ]); // return response()->json([ // 'code' => 200, // 'message' => '提交成功', // 'data' => null, // ]); } catch (\Exception $e) { Log::error('提交反馈失败: '.$e->getMessage()); throw $e; } } /** * 申请成为技师 * * @return \Illuminate\Http\JsonResponse */ public function applyCoach(string $mobile, string $gender, string $work_years, string $intention_city) { try { // 创建技师申请记录 // CoachApplication::create([ // 'user_id' => Auth::id(), // 'mobile' => $mobile, // 'gender' => $gender, // 'work_years' => $work_years, // 'intention_city' => $intention_city, // ]); return response()->json([ 'code' => 200, 'message' => '申请成功', 'data' => null, ]); } catch (\Exception $e) { Log::error('申请成为技师失败: '.$e->getMessage()); throw $e; } } /** * 生成用户邀请码 * * @return \Illuminate\Http\JsonResponse */ public function generateInviteCode() { try { // 获取当前用户 $user = Auth::user(); // 生成邀请码 $inviteCode = strtoupper(substr(md5($user->id), 0, 6)); // 生成带参数的网页链接 $qrContent = config('app.url').'/invite?'.http_build_query([ 'user_id' => $user->id, 'role' => 'user', 'code' => $inviteCode, ]); // 使用QrCode库生成SVG格式的二维码 $qrImage = QrCode::format('svg') ->size(200) ->margin(2) ->encoding('UTF-8') ->generate($qrContent); // 将SVG转为base64 $qrBase64 = base64_encode($qrImage); // 记录生成日志 Log::info('用户生成邀请码:', [ 'user_id' => $user->id, 'invite_code' => $inviteCode, 'invite_url' => $qrContent, // 记录生成的邀请链接 ]); return response()->json([ 'code' => 200, 'message' => '生成成功', 'data' => [ 'invite_code' => $inviteCode, 'invite_url' => $qrContent, // 返回邀请链接 'qr_code' => 'data:image/svg+xml;base64,'.$qrBase64, ], ]); } catch (\Exception $e) { Log::error('生成邀请码失败: '.$e->getMessage()); return response()->json([ 'code' => 500, 'msg' => '生成二维码失败,请稍后再试。', ]); } } }