|
|
|
@ -161,6 +161,39 @@ function formatDateTime(dateString) { |
|
|
|
return dateString; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取用户手机号
|
|
|
|
function getUserPhoneNumber() { |
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
try { |
|
|
|
// 尝试从多个可能的存储位置获取手机号
|
|
|
|
const users = wx.getStorageSync('users') || {}; |
|
|
|
const userId = wx.getStorageSync('userId'); |
|
|
|
|
|
|
|
if (userId && users[userId] && users[userId].phoneNumber) { |
|
|
|
resolve(users[userId].phoneNumber); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const userInfo = wx.getStorageSync('userInfo'); |
|
|
|
if (userInfo && userInfo.phoneNumber) { |
|
|
|
resolve(userInfo.phoneNumber); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
const phoneNumber = wx.getStorageSync('phoneNumber'); |
|
|
|
if (phoneNumber) { |
|
|
|
resolve(phoneNumber); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
reject(new Error('未找到手机号')); |
|
|
|
} catch (e) { |
|
|
|
console.error('获取手机号失败:', e); |
|
|
|
reject(e); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理净重件数对应数据,支持逗号分隔的价格与规格一一对应
|
|
|
|
function processWeightAndQuantityData(weightSpecString, quantityString, specString, price = '', costprice = '') { |
|
|
|
console.log('===== 处理净重、件数和规格数据 ====='); |
|
|
|
@ -771,22 +804,119 @@ Page({ |
|
|
|
console.log('当前用户手机号:', userPhone); |
|
|
|
console.log('联系人电话:', contactPhone); |
|
|
|
|
|
|
|
// 先检查是否为管理员
|
|
|
|
checkIsAdmin(userPhone) |
|
|
|
.then(isAdmin => { |
|
|
|
console.log('是否为管理员:', isAdmin); |
|
|
|
// 使用更详细的请求参数,确保后端返回所有记录
|
|
|
|
const requestData = { |
|
|
|
phone: userPhone, |
|
|
|
// 添加额外参数,确保后端返回所有记录
|
|
|
|
getAll: true, |
|
|
|
pageSize: 100 // 设置较大的页大小,确保能返回所有记录
|
|
|
|
}; |
|
|
|
|
|
|
|
// 直接调用request函数获取完整的人员信息,现在该端点返回所有匹配的记录
|
|
|
|
API.request('/api/personnel/get', 'POST', requestData) |
|
|
|
.then(res => { |
|
|
|
console.log('直接请求personnel表响应:', res); |
|
|
|
let hasPermission = false; |
|
|
|
|
|
|
|
// 详细记录响应数据结构,便于调试
|
|
|
|
console.log('响应数据类型:', typeof res.data); |
|
|
|
console.log('响应数据是否为数组:', Array.isArray(res.data)); |
|
|
|
if (typeof res.data === 'object') { |
|
|
|
console.log('响应数据的所有属性:', Object.keys(res.data)); |
|
|
|
// 检查是否有其他可能包含数据的属性
|
|
|
|
if (res.data.rows) { |
|
|
|
console.log('响应数据包含rows属性,类型:', typeof res.data.rows, '是否为数组:', Array.isArray(res.data.rows)); |
|
|
|
} |
|
|
|
if (res.data.data) { |
|
|
|
console.log('响应数据包含data属性,类型:', typeof res.data.data, '是否为数组:', Array.isArray(res.data.data)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (res && res.code === 200 && res.data) { |
|
|
|
// 处理数据库返回的各种格式,确保能获取到所有记录
|
|
|
|
let allPersonnelData = []; |
|
|
|
|
|
|
|
// 处理不同的数据格式
|
|
|
|
if (Array.isArray(res.data)) { |
|
|
|
// 情况1:data直接是数组(现在后端返回的是这种格式)
|
|
|
|
allPersonnelData = res.data; |
|
|
|
} else if (typeof res.data === 'object') { |
|
|
|
// 情况2:data是对象
|
|
|
|
// 检查是否有rows属性(常见于分页接口)
|
|
|
|
if (Array.isArray(res.data.rows)) { |
|
|
|
allPersonnelData = res.data.rows; |
|
|
|
} |
|
|
|
// 检查是否有data属性(嵌套data)
|
|
|
|
else if (Array.isArray(res.data.data)) { |
|
|
|
allPersonnelData = res.data.data; |
|
|
|
} |
|
|
|
// 检查是否有children属性
|
|
|
|
else if (Array.isArray(res.data.children)) { |
|
|
|
allPersonnelData = res.data.children; |
|
|
|
} |
|
|
|
// 检查是否有list属性
|
|
|
|
else if (Array.isArray(res.data.list)) { |
|
|
|
allPersonnelData = res.data.list; |
|
|
|
} |
|
|
|
// 检查是否有items属性
|
|
|
|
else if (Array.isArray(res.data.items)) { |
|
|
|
allPersonnelData = res.data.items; |
|
|
|
} |
|
|
|
// 情况3:兼容旧格式,单个对象转换为数组
|
|
|
|
else { |
|
|
|
allPersonnelData = [res.data]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log('最终处理后的所有身份记录:', allPersonnelData); |
|
|
|
console.log('用户所有身份:', allPersonnelData.map(item => { |
|
|
|
console.log('单个身份记录:', item); |
|
|
|
return item.projectName || item.position || item.role || '未知身份'; |
|
|
|
})); |
|
|
|
|
|
|
|
// 检查是否有管理员、采购员或销售员身份
|
|
|
|
// 优先级:管理员 > 采购员/销售员
|
|
|
|
const isAdmin = allPersonnelData.some(item => |
|
|
|
(item.projectName && item.projectName === '管理员') || |
|
|
|
(item.position && item.position === '管理员') || |
|
|
|
(item.role && item.role === '管理员') |
|
|
|
); |
|
|
|
const isBuyer = allPersonnelData.some(item => |
|
|
|
(item.projectName && item.projectName === '采购员') || |
|
|
|
(item.position && item.position === '采购员') || |
|
|
|
(item.role && item.role === '采购员') |
|
|
|
); |
|
|
|
const isSeller = allPersonnelData.some(item => |
|
|
|
(item.projectName && item.projectName === '销售员') || |
|
|
|
(item.position && item.position === '销售员') || |
|
|
|
(item.role && item.role === '销售员') |
|
|
|
); |
|
|
|
|
|
|
|
console.log('权限检查结果 - 管理员:', isAdmin, '采购员:', isBuyer, '销售员:', isSeller); |
|
|
|
|
|
|
|
if (isAdmin) { |
|
|
|
// 是管理员,允许编辑
|
|
|
|
// 管理员权限最高,直接允许编辑
|
|
|
|
hasPermission = true; |
|
|
|
console.log('管理员权限验证通过,允许编辑'); |
|
|
|
this.openEditModal(goodsDetail); |
|
|
|
} else if (userPhone === contactPhone) { |
|
|
|
// 手机号匹配联系人电话,允许编辑
|
|
|
|
console.log('手机号匹配联系人电话,允许编辑'); |
|
|
|
} else if (isBuyer || isSeller) { |
|
|
|
// 采购员或销售员,检查是否为联系人
|
|
|
|
if (userPhone === contactPhone) { |
|
|
|
hasPermission = true; |
|
|
|
console.log('采购员/销售员且为联系人,允许编辑'); |
|
|
|
} else { |
|
|
|
console.log('采购员/销售员但非联系人,无编辑权限'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log('无匹配身份,无编辑权限'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log('未找到用户信息,无编辑权限'); |
|
|
|
} |
|
|
|
|
|
|
|
if (hasPermission) { |
|
|
|
this.openEditModal(goodsDetail); |
|
|
|
} else { |
|
|
|
// 没有权限
|
|
|
|
console.log('没有编辑权限'); |
|
|
|
wx.showModal({ |
|
|
|
title: '权限不足', |
|
|
|
content: '你没有权限编辑此货源', |
|
|
|
@ -1162,22 +1292,120 @@ Page({ |
|
|
|
console.log('商品sellerId(创建人):', productSellerId, '(类型:', typeof productSellerId, ')'); |
|
|
|
console.log('商品联系人电话:', contactPhone); |
|
|
|
|
|
|
|
Promise.all([ |
|
|
|
checkIsAdmin(userPhone), |
|
|
|
Promise.resolve({ isCreator: String(currentUserId) === String(productSellerId) }) |
|
|
|
]) |
|
|
|
.then(([adminResult, creatorResult]) => { |
|
|
|
const isAdmin = adminResult; |
|
|
|
const isCreator = creatorResult.isCreator; |
|
|
|
// 使用更详细的请求参数,确保后端返回所有记录
|
|
|
|
const requestData = { |
|
|
|
phone: userPhone, |
|
|
|
// 添加额外参数,确保后端返回所有记录
|
|
|
|
getAll: true, |
|
|
|
pageSize: 100 // 设置较大的页大小,确保能返回所有记录
|
|
|
|
}; |
|
|
|
|
|
|
|
// 直接调用request函数获取完整的人员信息,现在该端点返回所有匹配的记录
|
|
|
|
API.request('/api/personnel/get', 'POST', requestData) |
|
|
|
.then(res => { |
|
|
|
console.log('直接请求personnel表响应:', res); |
|
|
|
let hasPermission = false; |
|
|
|
|
|
|
|
// 详细记录响应数据结构,便于调试
|
|
|
|
console.log('响应数据类型:', typeof res.data); |
|
|
|
console.log('响应数据是否为数组:', Array.isArray(res.data)); |
|
|
|
if (typeof res.data === 'object') { |
|
|
|
console.log('响应数据的所有属性:', Object.keys(res.data)); |
|
|
|
// 检查是否有其他可能包含数据的属性
|
|
|
|
if (res.data.rows) { |
|
|
|
console.log('响应数据包含rows属性,类型:', typeof res.data.rows, '是否为数组:', Array.isArray(res.data.rows)); |
|
|
|
} |
|
|
|
if (res.data.data) { |
|
|
|
console.log('响应数据包含data属性,类型:', typeof res.data.data, '是否为数组:', Array.isArray(res.data.data)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (res && res.code === 200 && res.data) { |
|
|
|
// 处理数据库返回的各种格式,确保能获取到所有记录
|
|
|
|
let allPersonnelData = []; |
|
|
|
|
|
|
|
// 处理不同的数据格式
|
|
|
|
if (Array.isArray(res.data)) { |
|
|
|
// 情况1:data直接是数组(现在后端返回的是这种格式)
|
|
|
|
allPersonnelData = res.data; |
|
|
|
} else if (typeof res.data === 'object') { |
|
|
|
// 情况2:data是对象
|
|
|
|
// 检查是否有rows属性(常见于分页接口)
|
|
|
|
if (Array.isArray(res.data.rows)) { |
|
|
|
allPersonnelData = res.data.rows; |
|
|
|
} |
|
|
|
// 检查是否有data属性(嵌套data)
|
|
|
|
else if (Array.isArray(res.data.data)) { |
|
|
|
allPersonnelData = res.data.data; |
|
|
|
} |
|
|
|
// 检查是否有children属性
|
|
|
|
else if (Array.isArray(res.data.children)) { |
|
|
|
allPersonnelData = res.data.children; |
|
|
|
} |
|
|
|
// 检查是否有list属性
|
|
|
|
else if (Array.isArray(res.data.list)) { |
|
|
|
allPersonnelData = res.data.list; |
|
|
|
} |
|
|
|
// 检查是否有items属性
|
|
|
|
else if (Array.isArray(res.data.items)) { |
|
|
|
allPersonnelData = res.data.items; |
|
|
|
} |
|
|
|
// 情况3:兼容旧格式,单个对象转换为数组
|
|
|
|
else { |
|
|
|
allPersonnelData = [res.data]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
console.log('最终处理后的所有身份记录:', allPersonnelData); |
|
|
|
console.log('用户所有身份:', allPersonnelData.map(item => { |
|
|
|
console.log('单个身份记录:', item); |
|
|
|
return item.projectName || item.position || item.role || '未知身份'; |
|
|
|
})); |
|
|
|
|
|
|
|
// 检查是否为管理员
|
|
|
|
const isAdmin = allPersonnelData.some(item => |
|
|
|
(item.projectName && item.projectName === '管理员') || |
|
|
|
(item.position && item.position === '管理员') || |
|
|
|
(item.role && item.role === '管理员') |
|
|
|
); |
|
|
|
// 检查是否为创建人
|
|
|
|
const isCreator = String(currentUserId) === String(productSellerId); |
|
|
|
// 检查是否为联系人
|
|
|
|
const isContact = userPhone === contactPhone; |
|
|
|
// 检查是否为采购员或销售员
|
|
|
|
const isBuyerOrSeller = allPersonnelData.some(item => |
|
|
|
(item.projectName && item.projectName === '采购员') || |
|
|
|
(item.projectName && item.projectName === '销售员') || |
|
|
|
(item.position && item.position === '采购员') || |
|
|
|
(item.position && item.position === '销售员') || |
|
|
|
(item.role && item.role === '采购员') || |
|
|
|
(item.role && item.role === '销售员') |
|
|
|
); |
|
|
|
|
|
|
|
console.log('权限检查结果 - 管理员:', isAdmin, '创建人:', isCreator, '联系人:', isContact); |
|
|
|
console.log('权限检查结果 - 管理员:', isAdmin, '创建人:', isCreator, '联系人:', isContact, '采购员/销售员:', isBuyerOrSeller); |
|
|
|
|
|
|
|
if (isAdmin || isCreator || isContact) { |
|
|
|
console.log('权限验证通过,允许下架'); |
|
|
|
this.confirmUnpublish(); |
|
|
|
if (isAdmin) { |
|
|
|
// 管理员权限最高,直接允许下架
|
|
|
|
hasPermission = true; |
|
|
|
console.log('管理员权限验证通过,允许下架'); |
|
|
|
} else if (isCreator) { |
|
|
|
// 创建人允许下架
|
|
|
|
hasPermission = true; |
|
|
|
console.log('创建人权限验证通过,允许下架'); |
|
|
|
} else if (isContact && isBuyerOrSeller) { |
|
|
|
// 采购员或销售员且为联系人,允许下架
|
|
|
|
hasPermission = true; |
|
|
|
console.log('采购员/销售员且为联系人,允许下架'); |
|
|
|
} else { |
|
|
|
console.log('没有下架权限'); |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.log('未找到用户信息,无下架权限'); |
|
|
|
} |
|
|
|
|
|
|
|
if (hasPermission) { |
|
|
|
this.confirmUnpublish(); |
|
|
|
} else { |
|
|
|
wx.showModal({ |
|
|
|
title: '权限不足', |
|
|
|
content: '您没有权限下架此货源', |
|
|
|
|