fix: 推广费接口 companyId 归属校验

- updatePromotionFee: 强校验记录属于当前公司,禁止越权修改
- deletePromotionFee: 强校验记录属于当前公司,禁止越权删除
- getPromotionFeeById: 强校验记录属于当前公司,禁止越权查询
This commit is contained in:
小蟑螂
2026-03-26 12:22:50 +08:00
parent f172c12e4f
commit 32ef993ec6
2 changed files with 20 additions and 10 deletions
@@ -7,6 +7,7 @@ import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.xyquan.ecomdmbbackend.common.exception.BusinessException;
import top.xyquan.ecomdmbbackend.common.model.dto.PageQueryDTO;
import top.xyquan.ecomdmbbackend.common.model.vo.PageResultVO;
import top.xyquan.ecomdmbbackend.modules.ecom.promotion.mapper.PromotionFeeMapper;
@@ -56,10 +57,15 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
@Override
@Transactional(rollbackFor = Exception.class)
public void updatePromotionFee(UpdatePromotionFeeDTO dto) {
Long companyId = currentUserContext.getCurrentCompanyId();
PromotionFeePO existing = promotionFeeMapper.selectById(dto.getId());
if (existing == null || !existing.getCompanyId().equals(companyId)) {
throw new BusinessException("推广费记录不存在");
}
PromotionFeePO po = new PromotionFeePO();
BeanUtils.copyProperties(dto, po);
po.setUpdateBy(currentUserContext.getCurrentUserId());
po.setCompanyId(companyId);
promotionFeeMapper.updateById(po);
}
@@ -70,7 +76,11 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
@Override
@Transactional(rollbackFor = Exception.class)
public void deletePromotionFee(Long id) {
// 硬删除推广费记录(外键约束会自动处理相关数据)
Long companyId = currentUserContext.getCurrentCompanyId();
PromotionFeePO existing = promotionFeeMapper.selectById(id);
if (existing == null || !existing.getCompanyId().equals(companyId)) {
throw new BusinessException("推广费记录不存在");
}
promotionFeeMapper.deleteById(id);
}
@@ -81,11 +91,11 @@ public class PromotionFeeServiceImpl implements PromotionFeeService {
*/
@Override
public PromotionFeeVO getPromotionFeeById(Long id) {
Long companyId = currentUserContext.getCurrentCompanyId();
PromotionFeePO po = promotionFeeMapper.selectById(id);
if (po == null) {
return null;
if (po == null || !po.getCompanyId().equals(companyId)) {
throw new BusinessException("推广费记录不存在");
}
return convertToVO(po);
}