diff --git a/pages/goods-update/goods-update.js b/pages/goods-update/goods-update.js index 98ccf90..bd2f94d 100644 --- a/pages/goods-update/goods-update.js +++ b/pages/goods-update/goods-update.js @@ -888,25 +888,36 @@ Page({ prepareUnpublishSupply: function() { console.log('准备下架商品 - 开始权限验证'); - // 权限控制 + const goodsDetail = this.data.goodsDetail; + const productSellerId = goodsDetail.sellerId || goodsDetail.product?.sellerId || ''; + const contactPhone = goodsDetail.contact_phone || goodsDetail.product_contact || ''; const userPhone = getLocalPhoneNumber(); + const currentUserId = wx.getStorageSync('userId'); + console.log('当前用户手机号:', userPhone); + console.log('当前用户userId:', currentUserId); + console.log('商品sellerId(创建人):', productSellerId); + console.log('商品联系人电话:', contactPhone); - // 先检查是否为管理员 - checkIsAdmin(userPhone) - .then(isAdmin => { - console.log('是否为管理员:', isAdmin); + Promise.all([ + checkIsAdmin(userPhone), + Promise.resolve({ isCreator: currentUserId === productSellerId }) + ]) + .then(([adminResult, creatorResult]) => { + const isAdmin = adminResult; + const isCreator = creatorResult.isCreator; + const isContact = userPhone === contactPhone; - if (isAdmin) { - // 是管理员,允许下架 - console.log('管理员权限验证通过,允许下架'); + console.log('权限检查结果 - 管理员:', isAdmin, '创建人:', isCreator, '联系人:', isContact); + + if (isAdmin || isCreator || isContact) { + console.log('权限验证通过,允许下架'); this.confirmUnpublish(); } else { - // 没有权限 console.log('没有下架权限'); wx.showModal({ title: '权限不足', - content: '你没有权限下架此货源', + content: '您没有权限下架此货源', showCancel: false }); }