|
@@ -17,6 +17,7 @@
|
|
package org.springblade.modules.finance.service.impl;
|
|
package org.springblade.modules.finance.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
import org.springblade.common.base.BaseEntity;
|
|
import org.springblade.common.base.BaseEntity;
|
|
import org.springblade.common.cache.ParamCache;
|
|
import org.springblade.common.cache.ParamCache;
|
|
import org.springblade.common.constant.CacheBizConstant;
|
|
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.entity.Groupon;
|
|
import org.springblade.modules.groupon.service.IGrouponService;
|
|
import org.springblade.modules.groupon.service.IGrouponService;
|
|
import org.springblade.modules.mall.service.IStoreService;
|
|
import org.springblade.modules.mall.service.IStoreService;
|
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -46,10 +48,7 @@ import org.springframework.util.Assert;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDateTime;
|
|
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.function.Function;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -63,14 +62,19 @@ import java.util.stream.Collectors;
|
|
public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSales> implements IAfterSalesService {
|
|
public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSales> implements IAfterSalesService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
|
|
+ @Lazy
|
|
private IOrderGoodsService orderGoodsService;
|
|
private IOrderGoodsService orderGoodsService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ @Lazy
|
|
private IOrderService orderService;
|
|
private IOrderService orderService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ @Lazy
|
|
private IOrderGrouponService orderGrouponService;
|
|
private IOrderGrouponService orderGrouponService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ @Lazy
|
|
private IOrderRefundService orderRefundService;
|
|
private IOrderRefundService orderRefundService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ @Lazy
|
|
private IStoreService storeService;
|
|
private IStoreService storeService;
|
|
@Resource
|
|
@Resource
|
|
private ICommissionService commissionService;
|
|
private ICommissionService commissionService;
|
|
@@ -79,6 +83,7 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
@Resource
|
|
@Resource
|
|
private IGrouponService grouponService;
|
|
private IGrouponService grouponService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ @Lazy
|
|
private IAfterSalesGoodsService afterSalesGoodsService;
|
|
private IAfterSalesGoodsService afterSalesGoodsService;
|
|
@Resource
|
|
@Resource
|
|
private IAppointGoodsService appointGoodsService;
|
|
private IAppointGoodsService appointGoodsService;
|
|
@@ -122,45 +127,51 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
public void submit(AfterSalesRequest request) {
|
|
public void submit(AfterSalesRequest request) {
|
|
- Order order = orderService.getById(request.getOrderId());
|
|
|
|
- Assert.notNull(order, "订单数据不存在");
|
|
|
|
-
|
|
|
|
- order.setIsAftersales(YesOrNoEnum.YES.getValue());
|
|
|
|
- orderService.updateById(order);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // 校验商品是否已经申请过售后
|
|
|
|
- List<Long> collect = request.getAfterGoodsList().stream().map(BaseEntity::getId).collect(Collectors.toList());
|
|
|
|
- List<OrderGoods> list = orderGoodsService.lambdaQuery().in(BaseEntity::getId, collect).list();
|
|
|
|
- for (OrderGoods orderGoods : list) {
|
|
|
|
- if (YesOrNoEnum.YES.getValue().equals(orderGoods.getIsAfterSales())) {
|
|
|
|
- throw new ServiceException("商品【"+orderGoods.getGoodsName()+"】已申请过售后");
|
|
|
|
- }
|
|
|
|
- orderGoods.setIsAfterSales(YesOrNoEnum.YES.getValue());
|
|
|
|
- }
|
|
|
|
- // 更新售后状态
|
|
|
|
- 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());
|
|
|
|
- afterSalesList.add(afterSales);
|
|
|
|
- }
|
|
|
|
- saveBatch(afterSalesList);
|
|
|
|
-
|
|
|
|
- // TODO: 2024/7/29 将分销收益改为无效,所有售后结束后重新计算收益
|
|
|
|
- //commissionService.invalidCommission(order.getId());
|
|
|
|
|
|
+ Order order = orderService.getById(request.getOrderId());
|
|
|
|
+ Assert.notNull(order, "订单数据不存在");
|
|
|
|
+
|
|
|
|
+ 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数据不存在");
|
|
|
|
+
|
|
|
|
+ int afterSalesDays = Integer.parseInt(ParamCache.getValueDefault(CacheBizConstant.ORDER_AFTER_SALES_DAYS, "3"));
|
|
|
|
+ // 校验是否能申请售后
|
|
|
|
+ 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> 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()+"】已申请过售后");
|
|
|
|
+ }
|
|
|
|
+ orderGoods.setIsAfterSales(YesOrNoEnum.YES.getValue());
|
|
|
|
+ }
|
|
|
|
+ // 更新售后状态
|
|
|
|
+ orderGoodsService.updateBatchById(list);
|
|
|
|
+ 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
|
|
@Override
|
|
@@ -470,20 +481,18 @@ public class AfterSalesServiceImpl extends ServiceImpl<AfterSalesMapper, AfterSa
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@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
|
|
@Override
|