Browse Source

Merge pull request 'Xfy' (#18) from Xfy into Main

Reviewed-on: http://8.137.125.67:4000/SwtTt29/Program-mini/pulls/18
pull/1/head
SwtTt29 3 months ago
parent
commit
435fef0cd2
  1. 66
      pages/test-tools/api-test.js
  2. 2
      pages/test-tools/api-test.wxml
  3. 66
      pages/test-tools/clear-storage.js
  4. 2
      pages/test-tools/clear-storage.wxml
  5. 66
      pages/test-tools/connection-test.js
  6. 2
      pages/test-tools/connection-test.wxml
  7. 66
      pages/test-tools/fix-connection.js
  8. 2
      pages/test-tools/fix-connection.wxml
  9. 66
      pages/test-tools/gross-weight-tester.js
  10. 2
      pages/test-tools/gross-weight-tester.wxml
  11. 66
      pages/test-tools/phone-test.js
  12. 2
      pages/test-tools/phone-test.wxml
  13. 139
      pages/test-tools/test-mode-switch.js
  14. 50
      pages/test-tools/test-mode-switch.wxml
  15. 149
      pages/test-tools/test-mode-switch.wxss
  16. 9
      server-example/server-mysql-backup-alias.js
  17. 9
      server-example/server-mysql-backup-count.js
  18. 9
      server-example/server-mysql-backup-final.js
  19. 9
      server-example/server-mysql.backup.js
  20. 1
      server-example/test-request.json
  21. 59
      server-example/test_results_2025-11-28T07-49-43-353Z.json
  22. 274
      server-example/test_settlement_api.js

66
pages/test-tools/api-test.js

@ -1,66 +0,0 @@
// pages/test-tools/api-test.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

2
pages/test-tools/api-test.wxml

@ -1,2 +0,0 @@
<!--pages/test-tools/api-test.wxml-->
<text>pages/test-tools/api-test.wxml</text>

66
pages/test-tools/clear-storage.js

@ -1,66 +0,0 @@
// pages/test-tools/clear-storage.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

2
pages/test-tools/clear-storage.wxml

@ -1,2 +0,0 @@
<!--pages/test-tools/clear-storage.wxml-->
<text>pages/test-tools/clear-storage.wxml</text>

66
pages/test-tools/connection-test.js

@ -1,66 +0,0 @@
// pages/test-tools/connection-test.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

2
pages/test-tools/connection-test.wxml

@ -1,2 +0,0 @@
<!--pages/test-tools/connection-test.wxml-->
<text>pages/test-tools/connection-test.wxml</text>

66
pages/test-tools/fix-connection.js

@ -1,66 +0,0 @@
// pages/test-tools/fix-connection.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

2
pages/test-tools/fix-connection.wxml

@ -1,2 +0,0 @@
<!--pages/test-tools/fix-connection.wxml-->
<text>pages/test-tools/fix-connection.wxml</text>

66
pages/test-tools/gross-weight-tester.js

@ -1,66 +0,0 @@
// pages/test-tools/gross-weight-tester.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

2
pages/test-tools/gross-weight-tester.wxml

@ -1,2 +0,0 @@
<!--pages/test-tools/gross-weight-tester.wxml-->
<text>pages/test-tools/gross-weight-tester.wxml</text>

66
pages/test-tools/phone-test.js

@ -1,66 +0,0 @@
// pages/test-tools/phone-test.js
Page({
/**
* 页面的初始数据
*/
data: {
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})

2
pages/test-tools/phone-test.wxml

@ -1,2 +0,0 @@
<!--pages/test-tools/phone-test.wxml-->
<text>pages/test-tools/phone-test.wxml</text>

139
pages/test-tools/test-mode-switch.js

@ -1,139 +0,0 @@
// pages/test-tools/test-mode-switch.js
Page({
/**
* 页面的初始数据
*/
data: {
isDarkMode: false,
isHighContrast: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
// 从本地存储获取当前模式设置
const darkMode = wx.getStorageSync('isDarkMode') || false
const highContrast = wx.getStorageSync('isHighContrast') || false
this.setData({
isDarkMode: darkMode,
isHighContrast: highContrast
})
this.applyModeSettings()
},
/**
* 切换深色/浅色模式
*/
toggleDarkMode(e) {
const isDarkMode = e.detail.value
this.setData({ isDarkMode })
wx.setStorageSync('isDarkMode', isDarkMode)
this.applyModeSettings()
},
/**
* 切换高对比度模式
*/
toggleHighContrast(e) {
const isHighContrast = e.detail.value
this.setData({ isHighContrast })
wx.setStorageSync('isHighContrast', isHighContrast)
this.applyModeSettings()
},
/**
* 应用模式设置
*/
applyModeSettings() {
const { isDarkMode, isHighContrast } = this.data
// 创建或删除高对比度样式
this.createOrRemoveHighContrastStyle(isHighContrast)
// 更新窗口背景和导航栏样式
this.updateWindowStyle(isDarkMode)
console.log(`黑白测试模式设置: 深色模式=${isDarkMode}, 高对比度=${isHighContrast}`)
wx.showToast({
title: '模式已更新',
icon: 'success'
})
},
/**
* 创建或删除高对比度样式
*/
createOrRemoveHighContrastStyle(enable) {
// 移除旧的高对比度样式
const oldStyle = wx.createSelectorQuery().select('#highContrastStyle')
oldStyle.context((res) => {
if (res.context) {
wx.removeStyleSheet('#highContrastStyle')
}
})
if (enable) {
// 创建高对比度样式
const styleContent = `
/* 高对比度样式 */
* {
filter: grayscale(100%) contrast(120%) !important;
}
/* 确保文字可读性 */
text, span, div, p {
color: #000 !important;
background-color: #fff !important;
}
/* 按钮和交互元素 */
button, .btn {
border: 2px solid #000 !important;
color: #000 !important;
background-color: #fff !important;
}
`
// 动态添加样式
const styleSheet = document.createElement('style')
styleSheet.id = 'highContrastStyle'
styleSheet.textContent = styleContent
document.head.appendChild(styleSheet)
}
},
/**
* 更新窗口样式
*/
updateWindowStyle(isDarkMode) {
wx.setNavigationBarColor({
frontColor: isDarkMode ? '#ffffff' : '#000000',
backgroundColor: isDarkMode ? '#000000' : '#ffffff',
animation: {
duration: 400,
timingFunc: 'easeInOut'
}
})
wx.setBackgroundColor({
backgroundColor: isDarkMode ? '#000000' : '#ffffff',
backgroundColorTop: isDarkMode ? '#000000' : '#ffffff',
backgroundColorBottom: isDarkMode ? '#000000' : '#ffffff'
})
},
/**
* 重置所有设置
*/
resetAllSettings() {
this.setData({
isDarkMode: false,
isHighContrast: false
})
wx.setStorageSync('isDarkMode', false)
wx.setStorageSync('isHighContrast', false)
this.applyModeSettings()
}
})

50
pages/test-tools/test-mode-switch.wxml

@ -1,50 +0,0 @@
<!--pages/test-tools/test-mode-switch.wxml-->
<view class="container">
<view class="header">
<text class="title">黑白测试设置</text>
<text class="subtitle">调整应用的显示模式以进行黑白测试</text>
</view>
<view class="setting-item">
<view class="setting-label">
<text class="label-text">深色模式</text>
<text class="label-desc">切换应用的明/暗主题</text>
</view>
<switch
class="setting-switch"
checked="{{isDarkMode}}"
bindchange="toggleDarkMode"
color="#1AAD19"
/>
</view>
<view class="setting-item">
<view class="setting-label">
<text class="label-text">高对比度模式</text>
<text class="label-desc">启用黑白高对比度显示</text>
</view>
<switch
class="setting-switch"
checked="{{isHighContrast}}"
bindchange="toggleHighContrast"
color="#1AAD19"
/>
</view>
<view class="button-group">
<button
class="reset-button"
bindtap="resetAllSettings"
type="default"
>
重置为默认设置
</button>
</view>
<view class="tips">
<text class="tip-text">提示:</text>
<text class="tip-content">1. 深色模式会改变应用的整体色调</text>
<text class="tip-content">2. 高对比度模式会将所有元素转为黑白并提高对比度</text>
<text class="tip-content">3. 这些设置会保存在本地,下次打开应用时自动应用</text>
</view>
</view>

149
pages/test-tools/test-mode-switch.wxss

@ -1,149 +0,0 @@
/** pages/test-tools/test-mode-switch.wxss **/
.container {
padding: 40rpx 30rpx;
background-color: #fff;
min-height: 100vh;
}
.header {
text-align: center;
margin-bottom: 60rpx;
}
.title {
font-size: 36rpx;
font-weight: bold;
color: #333;
display: block;
margin-bottom: 20rpx;
}
.subtitle {
font-size: 26rpx;
color: #666;
display: block;
line-height: 1.5;
}
.setting-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 30rpx 0;
border-bottom: 1rpx solid #f0f0f0;
}
.setting-label {
flex: 1;
margin-right: 30rpx;
}
.label-text {
font-size: 30rpx;
color: #333;
display: block;
margin-bottom: 8rpx;
}
.label-desc {
font-size: 24rpx;
color: #999;
display: block;
line-height: 1.4;
}
.setting-switch {
transform: scale(1.2);
}
.button-group {
margin-top: 60rpx;
padding: 0 20rpx;
}
.reset-button {
width: 100%;
height: 90rpx;
line-height: 90rpx;
font-size: 30rpx;
border-radius: 15rpx;
border: 2rpx solid #1AAD19;
color: #1AAD19;
background-color: #fff;
}
.reset-button:active {
background-color: #f0f0f0;
}
.tips {
margin-top: 60rpx;
padding: 30rpx;
background-color: #f8f8f8;
border-radius: 15rpx;
border-left: 4rpx solid #1AAD19;
}
.tip-text {
font-size: 28rpx;
font-weight: bold;
color: #333;
display: block;
margin-bottom: 15rpx;
}
.tip-content {
font-size: 24rpx;
color: #666;
display: block;
margin-bottom: 10rpx;
line-height: 1.5;
}
/* 深色模式适配 */
.container.dark-mode {
background-color: #1a1a1a;
}
.container.dark-mode .title {
color: #fff;
}
.container.dark-mode .subtitle {
color: #ccc;
}
.container.dark-mode .setting-item {
border-bottom-color: #333;
}
.container.dark-mode .label-text {
color: #fff;
}
.container.dark-mode .label-desc {
color: #999;
}
.container.dark-mode .reset-button {
border-color: #4CAF50;
color: #4CAF50;
background-color: #1a1a1a;
}
.container.dark-mode .reset-button:active {
background-color: #333;
}
.container.dark-mode .tips {
background-color: #2a2a2a;
border-left-color: #4CAF50;
}
.container.dark-mode .tip-text {
color: #fff;
}
.container.dark-mode .tip-content {
color: #ccc;
}

9
server-example/server-mysql-backup-alias.js

@ -620,7 +620,7 @@ app.post('/api/user/upload', async (req, res) => {
console.log('收到用户信息上传请求:', userData); console.log('收到用户信息上传请求:', userData);
// 如果用户信息中包含手机号,检查手机号是否已被其他用户使用 // 如果用户信息中包含手机号,检查手机号是否已被其他用户使用
if (userData.phoneNumber && userData.phoneNumber !== '13800138000') { // 排除临时占位手机号 if (userData.phoneNumber) {
const existingUserWithPhone = await User.findOne({ const existingUserWithPhone = await User.findOne({
where: { where: {
phoneNumber: userData.phoneNumber, phoneNumber: userData.phoneNumber,
@ -654,10 +654,9 @@ app.post('/api/user/upload', async (req, res) => {
); );
user = await User.findOne({ where: { openid: userData.openid } }); user = await User.findOne({ where: { openid: userData.openid } });
} else { } else {
// 创建新用户(使用临时手机号) // 创建新用户
user = await User.create({ user = await User.create({
...userDataWithoutPhone, ...userDataWithoutPhone,
phoneNumber: '13800138000', // 临时占位
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
@ -877,14 +876,13 @@ app.post('/api/wechat/getOpenid', async (req, res) => {
userId, userId,
session_key, session_key,
nickName: '微信用户', // 临时占位,等待用户授权 nickName: '微信用户', // 临时占位,等待用户授权
phoneNumber: '13800138000', // 临时占位,等待用户授权
type: userType, // 使用客户端传入的类型或默认买家身份 type: userType, // 使用客户端传入的类型或默认买家身份
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
// 为新创建的用户创建关联记录 // 为新创建的用户创建关联记录
const newUser = { userId, openid, nickName: '微信用户', phoneNumber: '13800138000' }; const newUser = { userId, openid, nickName: '微信用户' };
await createUserAssociations(newUser); await createUserAssociations(newUser);
} }
@ -2686,7 +2684,6 @@ app.post('/api/product/edit', async (req, res) => {
openid: 'test_openid', openid: 'test_openid',
userId: 'test_user_id', userId: 'test_user_id',
nickName: '测试用户', nickName: '测试用户',
phoneNumber: '13800138000',
type: 'seller' type: 'seller'
}); });
} catch (createError) { } catch (createError) {

9
server-example/server-mysql-backup-count.js

@ -620,7 +620,7 @@ app.post('/api/user/upload', async (req, res) => {
console.log('收到用户信息上传请求:', userData); console.log('收到用户信息上传请求:', userData);
// 如果用户信息中包含手机号,检查手机号是否已被其他用户使用 // 如果用户信息中包含手机号,检查手机号是否已被其他用户使用
if (userData.phoneNumber && userData.phoneNumber !== '13800138000') { // 排除临时占位手机号 if (userData.phoneNumber) {
const existingUserWithPhone = await User.findOne({ const existingUserWithPhone = await User.findOne({
where: { where: {
phoneNumber: userData.phoneNumber, phoneNumber: userData.phoneNumber,
@ -654,10 +654,9 @@ app.post('/api/user/upload', async (req, res) => {
); );
user = await User.findOne({ where: { openid: userData.openid } }); user = await User.findOne({ where: { openid: userData.openid } });
} else { } else {
// 创建新用户(使用临时手机号) // 创建新用户
user = await User.create({ user = await User.create({
...userDataWithoutPhone, ...userDataWithoutPhone,
phoneNumber: '13800138000', // 临时占位
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
@ -877,14 +876,13 @@ app.post('/api/wechat/getOpenid', async (req, res) => {
userId, userId,
session_key, session_key,
nickName: '微信用户', // 临时占位,等待用户授权 nickName: '微信用户', // 临时占位,等待用户授权
phoneNumber: '13800138000', // 临时占位,等待用户授权
type: userType, // 使用客户端传入的类型或默认买家身份 type: userType, // 使用客户端传入的类型或默认买家身份
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
// 为新创建的用户创建关联记录 // 为新创建的用户创建关联记录
const newUser = { userId, openid, nickName: '微信用户', phoneNumber: '13800138000' }; const newUser = { userId, openid, nickName: '微信用户' };
await createUserAssociations(newUser); await createUserAssociations(newUser);
} }
@ -2686,7 +2684,6 @@ app.post('/api/product/edit', async (req, res) => {
openid: 'test_openid', openid: 'test_openid',
userId: 'test_user_id', userId: 'test_user_id',
nickName: '测试用户', nickName: '测试用户',
phoneNumber: '13800138000',
type: 'seller' type: 'seller'
}); });
} catch (createError) { } catch (createError) {

9
server-example/server-mysql-backup-final.js

@ -620,7 +620,7 @@ app.post('/api/user/upload', async (req, res) => {
console.log('收到用户信息上传请求:', userData); console.log('收到用户信息上传请求:', userData);
// 如果用户信息中包含手机号,检查手机号是否已被其他用户使用 // 如果用户信息中包含手机号,检查手机号是否已被其他用户使用
if (userData.phoneNumber && userData.phoneNumber !== '13800138000') { // 排除临时占位手机号 if (userData.phoneNumber) {
const existingUserWithPhone = await User.findOne({ const existingUserWithPhone = await User.findOne({
where: { where: {
phoneNumber: userData.phoneNumber, phoneNumber: userData.phoneNumber,
@ -654,10 +654,9 @@ app.post('/api/user/upload', async (req, res) => {
); );
user = await User.findOne({ where: { openid: userData.openid } }); user = await User.findOne({ where: { openid: userData.openid } });
} else { } else {
// 创建新用户(使用临时手机号) // 创建新用户
user = await User.create({ user = await User.create({
...userDataWithoutPhone, ...userDataWithoutPhone,
phoneNumber: '13800138000', // 临时占位
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
@ -877,14 +876,13 @@ app.post('/api/wechat/getOpenid', async (req, res) => {
userId, userId,
session_key, session_key,
nickName: '微信用户', // 临时占位,等待用户授权 nickName: '微信用户', // 临时占位,等待用户授权
phoneNumber: '13800138000', // 临时占位,等待用户授权
type: userType, // 使用客户端传入的类型或默认买家身份 type: userType, // 使用客户端传入的类型或默认买家身份
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
// 为新创建的用户创建关联记录 // 为新创建的用户创建关联记录
const newUser = { userId, openid, nickName: '微信用户', phoneNumber: '13800138000' }; const newUser = { userId, openid, nickName: '微信用户' };
await createUserAssociations(newUser); await createUserAssociations(newUser);
} }
@ -2717,7 +2715,6 @@ app.post('/api/product/edit', async (req, res) => {
openid: 'test_openid', openid: 'test_openid',
userId: 'test_user_id', userId: 'test_user_id',
nickName: '测试用户', nickName: '测试用户',
phoneNumber: '13800138000',
type: 'seller' type: 'seller'
}); });
} catch (createError) { } catch (createError) {

9
server-example/server-mysql.backup.js

@ -620,7 +620,7 @@ app.post('/api/user/upload', async (req, res) => {
console.log('收到用户信息上传请求:', userData); console.log('收到用户信息上传请求:', userData);
// 如果用户信息中包含手机号,检查手机号是否已被其他用户使用 // 如果用户信息中包含手机号,检查手机号是否已被其他用户使用
if (userData.phoneNumber && userData.phoneNumber !== '13800138000') { // 排除临时占位手机号 if (userData.phoneNumber) {
const existingUserWithPhone = await User.findOne({ const existingUserWithPhone = await User.findOne({
where: { where: {
phoneNumber: userData.phoneNumber, phoneNumber: userData.phoneNumber,
@ -654,10 +654,9 @@ app.post('/api/user/upload', async (req, res) => {
); );
user = await User.findOne({ where: { openid: userData.openid } }); user = await User.findOne({ where: { openid: userData.openid } });
} else { } else {
// 创建新用户(使用临时手机号) // 创建新用户
user = await User.create({ user = await User.create({
...userDataWithoutPhone, ...userDataWithoutPhone,
phoneNumber: '13800138000', // 临时占位
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
@ -877,14 +876,13 @@ app.post('/api/wechat/getOpenid', async (req, res) => {
userId, userId,
session_key, session_key,
nickName: '微信用户', // 临时占位,等待用户授权 nickName: '微信用户', // 临时占位,等待用户授权
phoneNumber: '13800138000', // 临时占位,等待用户授权
type: userType, // 使用客户端传入的类型或默认买家身份 type: userType, // 使用客户端传入的类型或默认买家身份
created_at: new Date(), created_at: new Date(),
updated_at: new Date() updated_at: new Date()
}); });
// 为新创建的用户创建关联记录 // 为新创建的用户创建关联记录
const newUser = { userId, openid, nickName: '微信用户', phoneNumber: '13800138000' }; const newUser = { userId, openid, nickName: '微信用户' };
await createUserAssociations(newUser); await createUserAssociations(newUser);
} }
@ -2676,7 +2674,6 @@ app.post('/api/product/edit', async (req, res) => {
openid: 'test_openid', openid: 'test_openid',
userId: 'test_user_id', userId: 'test_user_id',
nickName: '测试用户', nickName: '测试用户',
phoneNumber: '13800138000',
type: 'seller' type: 'seller'
}); });
} catch (createError) { } catch (createError) {

1
server-example/test-request.json

@ -1 +0,0 @@
{"openid":"user_1760087570258_r8f3eepnw","page":1,"pageSize":20}

59
server-example/test_results_2025-11-28T07-49-43-353Z.json

@ -1,59 +0,0 @@
{
"timestamp": "2025-11-28T07:49:43.354Z",
"baseUrl": "http://localhost:3003",
"testData": {
"openid": "test_openid_1764316183092",
"userId": "test_user_id_1764316183092",
"collaborationid": "supplier",
"company": "测试供应商公司",
"province": "北京市",
"city": "北京市",
"district": "海淀区",
"detailedaddress": "中关村科技园区",
"cooperation": "wholesale",
"phone": "13800138000",
"applicationId": "mock_application_id_1764316183154"
},
"results": [
{
"name": "上传文件",
"status": "passed",
"data": "https://example.com/uploaded/test_business_license.jpg"
},
{
"name": "提交入驻申请",
"status": "passed",
"data": {
"success": true,
"data": {
"applicationId": "mock_application_id_1764316183154"
}
}
},
{
"name": "获取入驻状态",
"status": "passed",
"data": {
"success": true,
"data": {
"partnerstatus": "underreview",
"id": "mock_application_id_1764316183154"
}
}
},
{
"name": "撤回入驻申请",
"status": "passed",
"data": {
"success": true
}
},
{
"name": "重新提交入驻申请",
"status": "passed",
"data": {
"success": true
}
}
]
}

274
server-example/test_settlement_api.js

@ -1,274 +0,0 @@
// 立即入驻功能API接口测试脚本
const axios = require('axios');
const fs = require('fs');
const path = require('path');
// 服务器基础URL - 根据实际情况修改
const BASE_URL = 'http://localhost:3003';
// 测试用的临时数据
const testData = {
openid: 'test_openid_' + Date.now(),
userId: 'test_user_id_' + Date.now(),
collaborationid: 'supplier', // 合作商身份ID
company: '测试供应商公司',
province: '北京市',
city: '北京市',
district: '海淀区',
detailedaddress: '中关村科技园区',
cooperation: 'wholesale', // 合作模式
phone: null,
applicationId: null // 将在测试过程中设置
};
// 测试结果
const testResults = [];
// 测试函数 - 统一处理测试结果
async function runTest(testName, testFunction) {
console.log(`\n===== 开始测试: ${testName} =====`);
try {
const result = await testFunction();
testResults.push({ name: testName, status: 'passed', data: result });
console.log(`✅ 测试通过: ${testName}`);
return result;
} catch (error) {
testResults.push({ name: testName, status: 'failed', error: error.message });
console.error(`❌ 测试失败: ${testName}`, error.message);
return null;
}
}
// 1. 测试上传文件接口
async function testUploadFile() {
console.log('测试上传文件接口...');
// 注意:实际测试需要准备一个测试图片文件
// 这里我们模拟一个成功的上传结果,因为实际文件上传需要物理文件
const mockUploadResult = {
success: true,
data: {
fileUrl: 'https://example.com/uploaded/test_business_license.jpg'
}
};
console.log('模拟文件上传成功:', mockUploadResult.data.fileUrl);
return mockUploadResult.data.fileUrl;
// 以下是实际上传文件的代码(需要准备测试文件)
/*
const formData = new FormData();
formData.append('file', fs.createReadStream('./test_license.jpg'));
formData.append('openid', testData.openid);
formData.append('userId', testData.userId);
formData.append('fileType', 'license');
const response = await axios.post(`${BASE_URL}/api/settlement/upload`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
});
if (response.data.success) {
return response.data.data.fileUrl;
} else {
throw new Error(response.data.message || '文件上传失败');
}
*/
}
// 2. 测试提交入驻申请接口
async function testSubmitApplication(businessLicenseUrl) {
console.log('测试提交入驻申请接口...');
const submitData = {
openid: testData.openid,
collaborationid: testData.collaborationid,
company: testData.company,
province: testData.province,
city: testData.city,
district: testData.district,
detailedaddress: testData.detailedaddress,
cooperation: testData.cooperation,
phone: testData.phone,
businesslicenseurl: businessLicenseUrl,
proofurl: 'https://example.com/uploaded/test_proof.jpg', // 模拟的证明文件URL
brandurl: 'https://example.com/uploaded/test_brand.jpg' // 模拟的品牌授权URL
};
try {
const response = await axios.post(`${BASE_URL}/api/settlement/submit`, submitData);
if (response.data.success) {
testData.applicationId = response.data.data.applicationId;
console.log('入驻申请提交成功,申请ID:', testData.applicationId);
return response.data;
} else {
throw new Error(response.data.message || '提交入驻申请失败');
}
} catch (error) {
console.error('提交入驻申请时的HTTP错误:', error.message);
// 模拟成功响应以便继续测试流程
const mockResponse = {
success: true,
data: {
applicationId: 'mock_application_id_' + Date.now()
}
};
testData.applicationId = mockResponse.data.applicationId;
console.log('使用模拟的成功响应,申请ID:', testData.applicationId);
return mockResponse;
}
}
// 3. 测试获取入驻状态接口
async function testGetSettlementStatus() {
console.log('测试获取入驻状态接口...');
try {
const response = await axios.get(`${BASE_URL}/api/settlement/status/${testData.userId}`);
if (response.data.success) {
console.log('获取入驻状态成功,状态:', response.data.data.partnerstatus);
return response.data;
} else {
throw new Error(response.data.message || '获取入驻状态失败');
}
} catch (error) {
console.error('获取入驻状态时的HTTP错误:', error.message);
// 模拟成功响应
const mockResponse = {
success: true,
data: {
partnerstatus: 'underreview',
id: testData.applicationId
}
};
console.log('使用模拟的成功响应,状态:', mockResponse.data.partnerstatus);
return mockResponse;
}
}
// 4. 测试撤回入驻申请接口
async function testWithdrawApplication() {
console.log('测试撤回入驻申请接口...');
if (!testData.applicationId) {
throw new Error('没有可用的申请ID');
}
try {
const response = await axios.post(
`${BASE_URL}/api/settlement/withdraw/${testData.applicationId}`,
{ openid: testData.openid }
);
if (response.data.success) {
console.log('撤回入驻申请成功');
return response.data;
} else {
throw new Error(response.data.message || '撤回入驻申请失败');
}
} catch (error) {
console.error('撤回入驻申请时的HTTP错误:', error.message);
// 模拟成功响应
const mockResponse = { success: true };
console.log('使用模拟的成功响应');
return mockResponse;
}
}
// 5. 测试重新提交入驻申请接口(需要先有被拒绝的申请)
async function testResubmitApplication() {
console.log('测试重新提交入驻申请接口...');
if (!testData.applicationId) {
throw new Error('没有可用的申请ID');
}
try {
const response = await axios.post(
`${BASE_URL}/api/settlement/resubmit/${testData.applicationId}`,
{ openid: testData.openid }
);
if (response.data.success) {
console.log('重新提交入驻申请成功');
return response.data;
} else {
throw new Error(response.data.message || '重新提交入驻申请失败');
}
} catch (error) {
console.error('重新提交入驻申请时的HTTP错误:', error.message);
// 模拟成功响应
const mockResponse = { success: true };
console.log('使用模拟的成功响应');
return mockResponse;
}
}
// 主测试流程
async function runAllTests() {
console.log('\n========== 开始执行立即入驻功能API测试 ==========');
console.log('测试环境:', BASE_URL);
console.log('测试用户:', testData.openid);
try {
// 1. 上传文件测试
const businessLicenseUrl = await runTest('上传文件', testUploadFile);
// 2. 提交入驻申请测试
await runTest('提交入驻申请', () => testSubmitApplication(businessLicenseUrl));
// 3. 获取入驻状态测试
await runTest('获取入驻状态', testGetSettlementStatus);
// 4. 撤回入驻申请测试
await runTest('撤回入驻申请', testWithdrawApplication);
// 5. 重新提交入驻申请测试(注意:在实际场景中,需要先有被拒绝的申请)
// 由于测试环境限制,这里可能会失败,这是预期行为
await runTest('重新提交入驻申请', testResubmitApplication);
} finally {
// 打印测试总结
console.log('\n========== 测试总结 ==========');
const passed = testResults.filter(r => r.status === 'passed').length;
const failed = testResults.filter(r => r.status === 'failed').length;
console.log(`总测试数: ${testResults.length}`);
console.log(`通过: ${passed}`);
console.log(`失败: ${failed}`);
if (failed > 0) {
console.log('\n失败的测试:');
testResults.forEach(result => {
if (result.status === 'failed') {
console.log(`- ${result.name}: ${result.error}`);
}
});
}
// 保存测试结果到文件
const resultFileName = `test_results_${new Date().toISOString().replace(/[:.]/g, '-')}.json`;
fs.writeFileSync(
path.join(__dirname, resultFileName),
JSON.stringify({
timestamp: new Date().toISOString(),
baseUrl: BASE_URL,
testData: testData,
results: testResults
}, null, 2)
);
console.log(`\n测试结果已保存到: ${resultFileName}`);
}
}
// 执行测试
runAllTests();
// 注意事项:
// 1. 运行此测试脚本前,请确保服务器已经启动
// 2. 对于文件上传测试,需要准备一个实际的图片文件并修改相关代码
// 3. 测试结果会保存在当前目录下的test_results_时间戳.json文件中
// 4. 重新提交申请测试需要先有一个被拒绝的申请,在测试环境中可能会失败
Loading…
Cancel
Save