|
@@ -4,8 +4,10 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.etotem.cfc.dto.ProductReviewRequest;
|
|
import com.etotem.cfc.dto.ProductReviewRequest;
|
|
|
import com.etotem.cfc.dto.ProductReviewResponse;
|
|
import com.etotem.cfc.dto.ProductReviewResponse;
|
|
|
|
|
+import com.etotem.cfc.entity.Product;
|
|
|
import com.etotem.cfc.entity.ProductOrder;
|
|
import com.etotem.cfc.entity.ProductOrder;
|
|
|
import com.etotem.cfc.entity.ProductReview;
|
|
import com.etotem.cfc.entity.ProductReview;
|
|
|
|
|
+import com.etotem.cfc.mapper.ProductMapper;
|
|
|
import com.etotem.cfc.mapper.ProductOrderMapper;
|
|
import com.etotem.cfc.mapper.ProductOrderMapper;
|
|
|
import com.etotem.cfc.mapper.ProductReviewMapper;
|
|
import com.etotem.cfc.mapper.ProductReviewMapper;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -43,6 +45,9 @@ public class ProductReviewServiceImpl extends ServiceImpl<ProductReviewMapper, P
|
|
|
@Resource
|
|
@Resource
|
|
|
private ProductOrderMapper orderMapper;
|
|
private ProductOrderMapper orderMapper;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ProductMapper productMapper;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional
|
|
@Transactional
|
|
|
public String createReview(ProductReviewRequest request, Long reviewerId) {
|
|
public String createReview(ProductReviewRequest request, Long reviewerId) {
|
|
@@ -198,6 +203,50 @@ public class ProductReviewServiceImpl extends ServiceImpl<ProductReviewMapper, P
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional
|
|
|
|
|
+ public String reply(Long reviewId, String replyText, Long operatorId) {
|
|
|
|
|
+ // 入参守卫(顺序:先校验,再查库,避免无效请求触达 DB)
|
|
|
|
|
+ if (reviewId == null) {
|
|
|
|
|
+ throw new RuntimeException("评价ID不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (replyText == null || replyText.trim().isEmpty()) {
|
|
|
|
|
+ throw new RuntimeException("回复内容不能为空");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (replyText.length() > 500) {
|
|
|
|
|
+ throw new RuntimeException("商家回复不能超过500字");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (operatorId == null) {
|
|
|
|
|
+ throw new RuntimeException("登录商家身份缺失");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 评价存在性:不存在直接拒绝,不写库
|
|
|
|
|
+ ProductReview review = reviewMapper.selectById(reviewId);
|
|
|
|
|
+ if (review == null) {
|
|
|
|
|
+ throw new RuntimeException("评价不存在");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 鉴权:评价对应商品须属于当前登录商家(product.vendorId == operatorId)
|
|
|
|
|
+ Long productId = review.getProductId();
|
|
|
|
|
+ if (productId == null) {
|
|
|
|
|
+ throw new RuntimeException("评价未关联商品,无法回复");
|
|
|
|
|
+ }
|
|
|
|
|
+ Product product = productMapper.selectById(productId);
|
|
|
|
|
+ if (product == null || product.getVendorId() == null
|
|
|
|
|
+ || !product.getVendorId().equals(operatorId)) {
|
|
|
|
|
+ throw new RuntimeException("无权回复非本人商品的评价");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 一评一回复覆盖式更新(P2 再议多次回复)
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ review.setReplyText(replyText);
|
|
|
|
|
+ review.setRepliedAt(now);
|
|
|
|
|
+ review.setReplyBy(operatorId);
|
|
|
|
|
+ review.setUpdatedAt(now);
|
|
|
|
|
+ reviewMapper.updateById(review);
|
|
|
|
|
+ return "回复成功";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 商品详情页评价列表(R3,能力键 {@code shop.review.list},公开只读)。
|
|
* 商品详情页评价列表(R3,能力键 {@code shop.review.list},公开只读)。
|
|
|
*
|
|
*
|