From 4286338fa09dfd99e621c372696b4fbe1b94002b Mon Sep 17 00:00:00 2001 From: xiao12feng8 <16507319+xiao12feng8@user.noreply.gitee.com> Date: Sun, 1 Feb 2026 10:03:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E9=99=A4=E5=AF=86=E7=A0=81=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env | 23 +- create_tables.py | 106 - import_sql.py | 36 - init_db.py | 19 - lover/__pycache__/deps.cpython-314.pyc | Bin 6356 -> 6720 bytes lover/deps.py | 11 +- test_backend_status.py | 70 + test_config.py | 6 - test_db_connection.py | 23 - test_lover.html | 39 - test_mysql.py | 21 - xuniYou/pages/chat/index.vue | 485 +- xuniYou/pages/login/index.vue | 59 +- xunifriend_RaeeC/.env | 13 + .../application/api/controller/User.php | 10 +- xunifriend_RaeeC/public/test.php | 2 + xunifriend_RaeeC/runtime/log/202602/01.log | 3902 +++++++++++++++++ 开发/2026年2月1日.md | 1 + 18 files changed, 4560 insertions(+), 266 deletions(-) delete mode 100644 create_tables.py delete mode 100644 import_sql.py delete mode 100644 init_db.py create mode 100644 test_backend_status.py delete mode 100644 test_config.py delete mode 100644 test_db_connection.py delete mode 100644 test_lover.html delete mode 100644 test_mysql.py create mode 100644 xunifriend_RaeeC/.env create mode 100644 xunifriend_RaeeC/public/test.php create mode 100644 xunifriend_RaeeC/runtime/log/202602/01.log create mode 100644 开发/2026年2月1日.md diff --git a/.env b/.env index 79587c4..71f0234 100644 --- a/.env +++ b/.env @@ -1,4 +1,23 @@ -DATABASE_URL=mysql+pymysql://root:root@127.0.0.1:3306/lover?charset=utf8mb4 -USER_INFO_API=http://127.0.0.1:8080/api/user_basic/get_user_basic +# ===== 应用基础配置 ===== APP_ENV=development DEBUG=True + +# ===== 数据库配置 ===== +DATABASE_URL=mysql+pymysql://root:root@127.0.0.1:3306/lover?charset=utf8mb4 + +# ===== 用户信息接口 (PHP后端) ===== +# 开发环境暂时使用本地地址,PHP后端配置好后再修改 +USER_INFO_API=http://127.0.0.1:8080/api/user_basic/get_user_basic + +# ===== AI 配置 (暂时留空,测试阶段不需要) ===== +DASHSCOPE_API_KEY= +IMAGE_GEN_MODEL=wan2.6-t2i +IMAGE_GEN_SIZE=960*1280 +WAN26_ASYNC=true + +# ===== OSS 配置 (暂时留空) ===== +ALIYUN_OSS_ACCESS_KEY_ID= +ALIYUN_OSS_ACCESS_KEY_SECRET= +ALIYUN_OSS_BUCKET_NAME= +ALIYUN_OSS_ENDPOINT= +ALIYUN_OSS_CDN_DOMAIN= diff --git a/create_tables.py b/create_tables.py deleted file mode 100644 index 4260938..0000000 --- a/create_tables.py +++ /dev/null @@ -1,106 +0,0 @@ -"""直接用 SQL 创建必要的表""" -import pymysql - -SQL_STATEMENTS = """ -CREATE TABLE IF NOT EXISTS `nf_lovers` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `user_id` bigint NOT NULL, - `name` varchar(64) DEFAULT NULL, - `gender` enum('male','female') NOT NULL, - `intro` text, - `story_background` text, - `personality_tag` int DEFAULT NULL, - `interest_tags` json DEFAULT NULL, - `opening_line` text, - `personality_prompt` text, - `appearance_prompt` text, - `appearance_params` json DEFAULT NULL, - `hair_style_id` int DEFAULT NULL, - `eye_color_id` int DEFAULT NULL, - `outfit_desc` varchar(50) DEFAULT NULL, - `outfit_top_id` bigint DEFAULT NULL, - `outfit_bottom_id` bigint DEFAULT NULL, - `outfit_dress_id` bigint DEFAULT NULL, - `voice_id` bigint DEFAULT NULL, - `image_url` varchar(255) DEFAULT NULL, - `last_image_task_id` bigint DEFAULT NULL, - `image_gen_used` int DEFAULT '0', - `image_gen_limit` int DEFAULT '10', - `image_gen_reset_date` date DEFAULT NULL, - `init_model` varchar(64) DEFAULT NULL, - `init_at` datetime DEFAULT NULL, - `created_at` datetime DEFAULT CURRENT_TIMESTAMP, - `updated_at` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - PRIMARY KEY (`id`), - UNIQUE KEY `user_id` (`user_id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE IF NOT EXISTS `nf_voice_library` ( - `id` bigint NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL, - `gender` enum('male','female') NOT NULL, - `style_tag` varchar(32) DEFAULT NULL, - `avatar_url` varchar(255) DEFAULT NULL, - `sample_audio_url` varchar(255) DEFAULT NULL, - `tts_model_id` varchar(64) DEFAULT NULL, - `is_default` tinyint(1) DEFAULT '0', - `voice_code` varchar(64) NOT NULL, - `is_owned` tinyint(1) DEFAULT '1', - `price_gold` int DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE IF NOT EXISTS `nf_girlfriend_mould` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL, - `gender` enum('male','female') DEFAULT NULL, - `weigh` int DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE IF NOT EXISTS `nf_girlfriend_hobbies` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL, - `weigh` int DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE IF NOT EXISTS `nf_girlfriend_hairstyles` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL, - `weigh` int DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - -CREATE TABLE IF NOT EXISTS `nf_girlfriend_eyecolor` ( - `id` int NOT NULL AUTO_INCREMENT, - `name` varchar(64) NOT NULL, - `weigh` int DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -""" - -try: - conn = pymysql.connect( - host='127.0.0.1', - port=3306, - user='root', - password='root', - database='lover', - charset='utf8mb4' - ) - print("✓ 连接数据库成功") - - cursor = conn.cursor() - for statement in SQL_STATEMENTS.strip().split(';'): - statement = statement.strip() - if statement: - cursor.execute(statement) - print(f"✓ 执行成功") - - conn.commit() - print("✓ 所有表创建完成!") - cursor.close() - conn.close() -except Exception as e: - print(f"✗ 失败: {e}") diff --git a/import_sql.py b/import_sql.py deleted file mode 100644 index 881d62b..0000000 --- a/import_sql.py +++ /dev/null @@ -1,36 +0,0 @@ -"""导入 SQL 文件""" -import pymysql - -try: - conn = pymysql.connect( - host='127.0.0.1', - port=3306, - user='root', - password='root', - database='lover', - charset='utf8mb4' - ) - print("✓ 连接数据库成功") - - with open('xunifriend.sql', 'r', encoding='utf8') as f: - sql_content = f.read() - - cursor = conn.cursor() - # 分割并执行 SQL 语句 - statements = sql_content.split(';') - for i, statement in enumerate(statements): - statement = statement.strip() - if statement: - try: - cursor.execute(statement) - if (i + 1) % 100 == 0: - print(f"已执行 {i + 1} 条语句...") - except Exception as e: - print(f"执行语句失败: {str(e)[:100]}") - - conn.commit() - print(f"✓ SQL 导入完成,共执行 {len([s for s in statements if s.strip()])} 条语句") - cursor.close() - conn.close() -except Exception as e: - print(f"✗ 导入失败: {e}") diff --git a/init_db.py b/init_db.py deleted file mode 100644 index dbedf82..0000000 --- a/init_db.py +++ /dev/null @@ -1,19 +0,0 @@ -""" -数据库初始化脚本 -创建所有必需的表 -""" -from lover.db import engine, Base -from lover import models - -def init_database(): - """创建所有表""" - print("开始创建数据库表...") - try: - Base.metadata.create_all(bind=engine) - print("✓ 数据库表创建完成!") - except Exception as e: - print(f"✗ 创建表失败: {e}") - raise - -if __name__ == "__main__": - init_database() diff --git a/lover/__pycache__/deps.cpython-314.pyc b/lover/__pycache__/deps.cpython-314.pyc index 9e02be58d1e7033ebbd1f016e6225c110492d0c0..64954ad7c79daf804878f251fc512a1844a754b3 100644 GIT binary patch delta 1103 zcmca&c))~Dn~#@^0SH7^)nx__m=U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..3a412d6 100644 --- a/lover/deps.py +++ b/lover/deps.py @@ -89,6 +89,12 @@ def get_current_user( reg_step = payload.get("reg_step") or payload.get("stage") or 1 gender = payload.get("gender") or 0 nickname = payload.get("nickname") or payload.get("username") or "" + + # 开发环境:自动提升 reg_step 到 2,方便测试 + if settings.APP_ENV == "development" and settings.DEBUG and reg_step < 2: + logger.warning(f"开发环境:用户 reg_step={reg_step},自动提升到 2") + reg_step = 2 + if not user_id: raise HTTPException( status_code=status.HTTP_401_UNAUTHORIZED, detail="用户中心缺少用户ID" @@ -100,11 +106,12 @@ def get_current_user( nickname=nickname, token=token, ) - except HTTPException: + except HTTPException as e: # 如果是开发环境,token 验证失败时也返回测试用户 if settings.APP_ENV == "development" and settings.DEBUG: - logger.warning(f"开发环境:token 验证失败,使用测试用户") + logger.warning(f"开发环境:token 验证失败({e.detail}),使用测试用户") return AuthedUser(id=84, reg_step=2, gender=0, nickname="test-user", token="") + raise # 调试兜底:仅凭 X-User-Id 不校验 PHP,方便联调 if x_user_id is not None: diff --git a/test_backend_status.py b/test_backend_status.py new file mode 100644 index 0000000..7215865 --- /dev/null +++ b/test_backend_status.py @@ -0,0 +1,70 @@ +"""测试后端服务状态""" +import requests +import json + +print("=" * 60) +print("后端服务状态检查") +print("=" * 60) + +# 测试 PHP 后端 +print("\n1. 测试 PHP 后端 (http://127.0.0.1:8080)") +print("-" * 60) +try: + response = requests.get("http://127.0.0.1:8080", timeout=3) + print(f"✓ PHP 后端正常运行") + print(f" 状态码: {response.status_code}") +except requests.exceptions.ConnectionError: + print("✗ PHP 后端未启动或无法连接") + print(" 请使用 phpstudy 启动 Apache 服务") +except Exception as e: + print(f"✗ 连接错误: {e}") + +# 测试 Python 后端 +print("\n2. 测试 Python 后端 (http://127.0.0.1:8000)") +print("-" * 60) +try: + response = requests.get("http://127.0.0.1:8000/docs", timeout=3) + print(f"✓ Python 后端正常运行") + print(f" 状态码: {response.status_code}") +except requests.exceptions.ConnectionError: + print("✗ Python 后端未启动") + print(" 请运行: python -m uvicorn lover.main:app --reload --host 127.0.0.1 --port 8000") +except Exception as e: + print(f"✗ 连接错误: {e}") + +# 测试登录接口 +print("\n3. 测试登录接口") +print("-" * 60) +test_data = { + "mobile": "13758924481", + "password": "123456", + "captcha": "223344" +} +print(f"测试数据: {json.dumps(test_data, ensure_ascii=False)}") + +try: + response = requests.post( + "http://127.0.0.1:8080/api/user/mobilelogin", + json=test_data, + headers={ + "Content-Type": "application/json", + "sid": "2" + }, + timeout=5 + ) + print(f"状态码: {response.status_code}") + print(f"响应: {json.dumps(response.json(), ensure_ascii=False, indent=2)}") +except requests.exceptions.ConnectionError: + print("✗ 无法连接到登录接口") + print(" PHP 后端可能未正确配置") +except Exception as e: + print(f"✗ 请求错误: {e}") + +print("\n" + "=" * 60) +print("检查完成") +print("=" * 60) + +print("\n建议:") +print("1. 如果 PHP 后端未启动,请使用 phpstudy 启动 Apache") +print("2. 如果登录接口返回错误,检查数据库中是否有该用户") +print("3. 如果需要创建测试用户,可以在数据库中手动添加") diff --git a/test_config.py b/test_config.py deleted file mode 100644 index 77cbfe8..0000000 --- a/test_config.py +++ /dev/null @@ -1,6 +0,0 @@ -"""测试配置加载""" -from lover.config import settings - -print(f"DATABASE_URL: {settings.DATABASE_URL}") -print(f"APP_ENV: {settings.APP_ENV}") -print(f"DEBUG: {settings.DEBUG}") diff --git a/test_db_connection.py b/test_db_connection.py deleted file mode 100644 index 4afd10a..0000000 --- a/test_db_connection.py +++ /dev/null @@ -1,23 +0,0 @@ -"""测试 SQLAlchemy 连接""" -from sqlalchemy import text -from lover.db import engine, SessionLocal -from lover.models import Lover - -try: - # 测试连接 - with engine.connect() as conn: - result = conn.execute(text("SELECT 1")) - print("✓ Engine 连接成功") - - # 测试 Session - db = SessionLocal() - try: - lovers = db.query(Lover).limit(1).all() - print(f"✓ Session 查询成功,找到 {len(lovers)} 条记录") - finally: - db.close() - -except Exception as e: - print(f"✗ 失败: {e}") - import traceback - traceback.print_exc() diff --git a/test_lover.html b/test_lover.html deleted file mode 100644 index 261416b..0000000 --- a/test_lover.html +++ /dev/null @@ -1,39 +0,0 @@ - - - - - 测试 Lover API - - -

Lover API 测试

- - -

-
-    
-
-
diff --git a/test_mysql.py b/test_mysql.py
deleted file mode 100644
index fb00a02..0000000
--- a/test_mysql.py
+++ /dev/null
@@ -1,21 +0,0 @@
-"""测试 MySQL 连接"""
-import pymysql
-
-try:
-    conn = pymysql.connect(
-        host='127.0.0.1',
-        port=3306,
-        user='root',
-        password='root',
-        database='lover',
-        charset='utf8mb4'
-    )
-    print("✓ MySQL 连接成功!")
-    cursor = conn.cursor()
-    cursor.execute("SELECT VERSION()")
-    version = cursor.fetchone()
-    print(f"✓ MySQL 版本: {version[0]}")
-    cursor.close()
-    conn.close()
-except Exception as e:
-    print(f"✗ MySQL 连接失败: {e}")
diff --git a/xuniYou/pages/chat/index.vue b/xuniYou/pages/chat/index.vue
index 853a6d9..e5bdadd 100644
--- a/xuniYou/pages/chat/index.vue
+++ b/xuniYou/pages/chat/index.vue
@@ -25,6 +25,26 @@
 						
 					
 				
+				
+				
+				
+					
+						
+							
+								{{ tab.name }}
+								
+							
+						
+					
+				
+				
+				
+				
 				
@@ -164,8 +184,103 @@
                  -->
 			
 		
-
-		
+		
+		
+		
+			
+				唱歌功能
+				让她为你唱一首歌
+				
+					
+						
+							{{item.title}}
+						
+						
+					
+				
+			
+		
+		
+		
+		
+			
+				跳舞功能
+				让她为你跳一支舞
+				
+					
+					生成舞蹈
+				
+			
+		
+		
+		
+		
+			
+				换服装
+				为她挑选不同的服装
+				
+					
+						
+						服装 {{i}}
+					
+				
+			
+		
+		
+		
+		
+			
+				送礼物
+				送她一份心意
+				
+					
+						
+						礼物 {{i}}
+						{{i * 10}} 金币
+					
+				
+			
+		
+		
+		
+		
+			
+				商城
+				购买更多功能和道具
+				
+					
+						
+							套餐 {{i}}
+							包含多种功能和道具
+						
+						
+							¥{{i * 30}}
+							购买
+						
+					
+				
+			
+		
+		
+		
+		
+			
+				短剧
+				观看精彩短剧内容
+				
+					
+						
+						
+							短剧标题 {{i}}
+							精彩剧情简介...
+							播放
+						
+					
+				
+			
+		
+		
+		
 		
 			
 			
@@ -269,6 +384,19 @@
 		},
 		data() {
 			return {
+				// Tab 相关
+				currentTab: 0,
+				tabScrollLeft: 0,
+				tabList: [
+					{ name: '聊天', icon: '' },
+					{ name: '唱歌', icon: '' },
+					{ name: '跳舞', icon: '' },
+					{ name: '换服装', icon: '' },
+					{ name: '刷礼物', icon: '' },
+					{ name: '商城', icon: '' },
+					{ name: '短剧', icon: '' }
+				],
+				dancePrompt: '', // 跳舞描述
 				// 可以在这里添加聊天数据
 				// messages: [],
 				loverBasicList: uni.getStorageSync('loverBasicList'),
@@ -349,6 +477,54 @@
 			this.stopCurrentAudio();
 		},
 		methods: {
+			// Tab 切换方法
+			switchTab(index) {
+				this.currentTab = index;
+				// 计算滚动位置,使当前 tab 居中
+				const tabWidth = 120; // 每个 tab 的宽度(rpx)
+				const screenWidth = 750; // 屏幕宽度(rpx)
+				this.tabScrollLeft = Math.max(0, (index * tabWidth) - (screenWidth / 2) + (tabWidth / 2));
+			},
+			// 直接选择歌曲并生成
+			selectSongDirect(song) {
+				this.songId = song.id;
+				uni.showLoading({
+					title: '生成中...'
+				});
+				SingGenerate({
+					song_id: song.id
+				}).then(res => {
+					if (res.code == 1) {
+						this.getSingGenerateTask(res.data.task_id);
+					} else {
+						uni.hideLoading();
+						uni.showToast({
+							title: res.msg,
+							icon: 'none'
+						});
+					}
+				});
+			},
+			// 请求跳舞
+			requestDance() {
+				if (!this.dancePrompt || !this.dancePrompt.trim()) {
+					uni.showToast({
+						title: '请输入舞蹈描述',
+						icon: 'none'
+					});
+					return;
+				}
+				this.messageprompt = this.dancePrompt;
+				this.savechatSing();
+			},
+			// 送礼物
+			sendGift(giftId) {
+				uni.showToast({
+					title: `送出礼物 ${giftId}`,
+					icon: 'success'
+				});
+				// 这里可以调用送礼物的 API
+			},
 			initAudio() {
 				// 销毁旧的音频上下文(如果存在)
 				if (this.audioContext) {
@@ -1750,6 +1926,311 @@