Browse Source

feat: 下架按钮权限规则补充创建人和联系人验证

pull/9/head
徐飞洋 2 months ago
parent
commit
0e2819b50b
  1. 31
      pages/goods-update/goods-update.js

31
pages/goods-update/goods-update.js

@ -888,25 +888,36 @@ Page({
prepareUnpublishSupply: function() { prepareUnpublishSupply: function() {
console.log('准备下架商品 - 开始权限验证'); 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 userPhone = getLocalPhoneNumber();
const currentUserId = wx.getStorageSync('userId');
console.log('当前用户手机号:', userPhone); console.log('当前用户手机号:', userPhone);
console.log('当前用户userId:', currentUserId);
console.log('商品sellerId(创建人):', productSellerId);
console.log('商品联系人电话:', contactPhone);
// 先检查是否为管理员 Promise.all([
checkIsAdmin(userPhone) checkIsAdmin(userPhone),
.then(isAdmin => { Promise.resolve({ isCreator: currentUserId === productSellerId })
console.log('是否为管理员:', isAdmin); ])
.then(([adminResult, creatorResult]) => {
const isAdmin = adminResult;
const isCreator = creatorResult.isCreator;
const isContact = userPhone === contactPhone;
if (isAdmin) { console.log('权限检查结果 - 管理员:', isAdmin, '创建人:', isCreator, '联系人:', isContact);
// 是管理员,允许下架
console.log('管理员权限验证通过,允许下架'); if (isAdmin || isCreator || isContact) {
console.log('权限验证通过,允许下架');
this.confirmUnpublish(); this.confirmUnpublish();
} else { } else {
// 没有权限
console.log('没有下架权限'); console.log('没有下架权限');
wx.showModal({ wx.showModal({
title: '权限不足', title: '权限不足',
content: '没有权限下架此货源', content: '没有权限下架此货源',
showCancel: false showCancel: false
}); });
} }

Loading…
Cancel
Save