|
@@ -17,6 +17,7 @@
|
|
|
package org.springblade.modules.finance.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import org.springblade.common.base.BaseEntity;
|
|
|
import org.springblade.common.cache.ParamCache;
|
|
|
import org.springblade.common.constant.CacheBizConstant;
|
|
@@ -38,6 +39,7 @@ import org.springblade.modules.finance.wrapper.OrderWrapper;
|
|
|
import org.springblade.modules.groupon.entity.Groupon;
|
|
|
import org.springblade.modules.groupon.service.IGrouponService;
|
|
|
import org.springblade.modules.mall.service.IStoreService;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -46,10 +48,7 @@ import org.springframework.util.Assert;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
@@ -63,14 +62,19 @@ import java.util.stream.Collectors;
|
|
|
public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSales> implements IAfterSalesService {
|
|
|
|
|
|
@Resource
|
|
|
+ @Lazy
|
|
|
private IOrderGoodsService orderGoodsService;
|
|
|
@Resource
|
|
|
+ @Lazy
|
|
|
private IOrderService orderService;
|
|
|
@Resource
|
|
|
+ @Lazy
|
|
|
private IOrderGrouponService orderGrouponService;
|
|
|
@Resource
|
|
|
+ @Lazy
|
|
|
private IOrderRefundService orderRefundService;
|
|
|
@Resource
|
|
|
+ @Lazy
|
|
|
private IStoreService storeService;
|
|
|
@Resource
|
|
|
private ICommissionService commissionService;
|
|
@@ -79,6 +83,7 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
|
@Resource
|
|
|
private IGrouponService grouponService;
|
|
|
@Resource
|
|
|
+ @Lazy
|
|
|
private IAfterSalesGoodsService afterSalesGoodsService;
|
|
|
@Resource
|
|
|
private IAppointGoodsService appointGoodsService;
|
|
@@ -127,21 +132,27 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
|
|
|
|
order.setIsAftersales(YesOrNoEnum.YES.getValue());
|
|
|
orderService.updateById(order);
|
|
|
- OrderGroupon orderGroupon = orderGrouponService.lambdaQuery().eq(OrderGroupon::getOrderId, request.getOrderId()).one();
|
|
|
- Assert.notNull(orderGroupon, "orderGroupon数据不存在");
|
|
|
- Groupon groupon = grouponService.getById(orderGroupon.getGrouponId());
|
|
|
- Assert.notNull(orderGroupon, "groupon数据不存在");
|
|
|
+// OrderGroupon orderGroupon = orderGrouponService.lambdaQuery().eq(OrderGroupon::getOrderId, request.getOrderId()).one();
|
|
|
+// Assert.notNull(orderGroupon, "orderGroupon数据不存在");
|
|
|
+// Groupon groupon = grouponService.getById(orderGroupon.getGrouponId());
|
|
|
+// Assert.notNull(orderGroupon, "groupon数据不存在");
|
|
|
|
|
|
int afterSalesDays = Integer.parseInt(ParamCache.getValueDefault(CacheBizConstant.ORDER_AFTER_SALES_DAYS, "3"));
|
|
|
// 校验是否能申请售后
|
|
|
- LocalDateTime time = groupon.getTakeStartTime().plusDays(afterSalesDays);
|
|
|
- if (time.isBefore(LocalDateTime.now())) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ calendar.setTime(order.getCreateTime());
|
|
|
+ calendar.add(Calendar.DAY_OF_MONTH,afterSalesDays);
|
|
|
+ Date time = calendar.getTime();
|
|
|
+// LocalDateTime time = groupon.getTakeStartTime().plusDays(afterSalesDays);
|
|
|
+ if (time.compareTo(new Date()) <= 0) {
|
|
|
throw new ServiceException("已过售后期");
|
|
|
}
|
|
|
|
|
|
// 校验商品是否已经申请过售后
|
|
|
- List<Long> collect = request.getAfterGoodsList().stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
- List<OrderGoods> list = orderGoodsService.lambdaQuery().in(BaseEntity::getId, collect).list();
|
|
|
+ List<Long> goodsIds = request.getAfterGoodsList().stream().map(OrderGoods::getGoodsId).collect(Collectors.toList());
|
|
|
+ List<OrderGoods> list = orderGoodsService.lambdaQuery()
|
|
|
+ .eq(OrderGoods::getOrderId,request.getOrderId())
|
|
|
+ .in(OrderGoods::getGoodsId, goodsIds).list();
|
|
|
for (OrderGoods orderGoods : list) {
|
|
|
if (YesOrNoEnum.YES.getValue().equals(orderGoods.getIsAfterSales())) {
|
|
|
throw new ServiceException("商品【"+orderGoods.getGoodsName()+"】已申请过售后");
|
|
@@ -150,28 +161,17 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
|
}
|
|
|
// 更新售后状态
|
|
|
orderGoodsService.updateBatchById(list);
|
|
|
-
|
|
|
- Map<Long, OrderGoods> map = request.getAfterGoodsList().stream().collect(Collectors.toMap(BaseEntity::getId, Function.identity()));
|
|
|
- List<AfterSales> afterSalesList = new ArrayList<>();
|
|
|
- for (OrderGoods goods : list) {
|
|
|
- AfterSales afterSales = init();
|
|
|
- afterSales.setOrderId(request.getOrderId());
|
|
|
- afterSales.setReason(request.getReason());
|
|
|
- afterSales.setType(request.getAfterSalesType());
|
|
|
- afterSales.setOrderGoodsId(goods.getId());
|
|
|
-
|
|
|
- OrderGoods o = map.get(goods.getId());
|
|
|
- afterSales.setReturnGoodsNum(o.getGoodsNum());
|
|
|
- afterSales.setIsArrived(YesOrNoEnum.NO.getValue());
|
|
|
- afterSales.setUserId(AuthUtil.getUserId());
|
|
|
- afterSales.setStoreId(goods.getShopId());
|
|
|
- afterSales.setGrouponId(orderGroupon.getGrouponId());
|
|
|
- afterSalesList.add(afterSales);
|
|
|
- }
|
|
|
- saveBatch(afterSalesList);
|
|
|
-
|
|
|
- // TODO: 2024/7/29 将分销收益改为无效,所有售后结束后重新计算收益
|
|
|
- //commissionService.invalidCommission(order.getId());
|
|
|
+ AfterSales afterSales = init();
|
|
|
+ afterSales.setOrderId(request.getOrderId());
|
|
|
+ afterSales.setType(request.getAfterSalesType());
|
|
|
+ afterSales.setReason(request.getReason());
|
|
|
+ afterSales.setReasonId(request.getReasonId());
|
|
|
+ afterSales.setAfterSaleDescribe(request.getAfterSaleDescribe());
|
|
|
+ afterSales.setImgListStr(JSON.toJSONString(request.getImages()));
|
|
|
+ afterSales.setIsArrived(YesOrNoEnum.NO.getValue());
|
|
|
+ afterSales.setUserId(AuthUtil.getUserId());
|
|
|
+ afterSales.setReturnGoodsNum(request.getAfterGoodsList().get(0).getRefundGoodsNum());
|
|
|
+ this.save(afterSales);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -481,20 +481,18 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public IPage<AfterSalesVO> getUserAfterSalesList(IPage page, Long userId, Integer state) {
|
|
|
- List<AfterSalesVO> afterSalesVOS = baseMapper.selectUserAfterSalesList(page, userId, state);
|
|
|
- if (CollUtil.isNotEmpty(afterSalesVOS)) {
|
|
|
- for (AfterSalesVO vo : afterSalesVOS) {
|
|
|
- if (AfterSalesTypeEnum.REFUND.getValue().equals(vo.getType())) {
|
|
|
- List<OrderGoods> list = orderGoodsService.lambdaQuery().eq(OrderGoods::getOrderId, vo.getOrderId()).list();
|
|
|
- vo.setGoodsList(list);
|
|
|
- } else {
|
|
|
- List<OrderGoods> list = orderGoodsService.lambdaQuery().eq(BaseEntity::getId, vo.getOrderGoodsId()).list();
|
|
|
- vo.setGoodsList(list);
|
|
|
- }
|
|
|
- }
|
|
|
+ public IPage<AfterSalesVO> getUserAfterSalesList(IPage page, Long userId,Integer state ) {
|
|
|
+ IPage<AfterSalesVO> afterSalesVOS = baseMapper.selectUserAfterSalesList(page, userId,state);
|
|
|
+ if (CollUtil.isEmpty(afterSalesVOS.getRecords())){
|
|
|
+ return afterSalesVOS;
|
|
|
+ }
|
|
|
+ for (AfterSalesVO vo : afterSalesVOS.getRecords()) {
|
|
|
+ List<OrderGoods> list = orderGoodsService.lambdaQuery().eq(OrderGoods::getOrderId, vo.getOrderId()).list();
|
|
|
+ vo.setGoodsList(list);
|
|
|
+ List<AfterSalesGoods> list1 = afterSalesGoodsService.lambdaQuery().eq(AfterSalesGoods::getAfterSalesId,vo.getId()).list();
|
|
|
+ vo.setAfterSalesGoodsList(list1);
|
|
|
}
|
|
|
- return page.setRecords(afterSalesVOS);
|
|
|
+ return afterSalesVOS;
|
|
|
}
|
|
|
|
|
|
@Override
|