|  | @@ -7,6 +7,8 @@ import cn.newfeifan.mall.framework.common.pojo.PageParam;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.framework.common.pojo.PageResult;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.framework.common.util.object.ObjectUtils;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.framework.mybatis.core.query.LambdaQueryWrapperX;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.distri.enums.CaclEnum;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.distri.service.integral.IntegralService;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.pay.api.refund.PayRefundApi;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.pay.api.refund.dto.PayRefundCreateReqDTO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.system.controller.admin.user.vo.user.UserShopDetailsVO;
 | 
	
	
		
			
				|  | @@ -14,6 +16,7 @@ import cn.newfeifan.mall.module.system.service.user.AdminUserService;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
 | 
	
		
			
				|  |  | +import cn.newfeifan.mall.module.trade.controller.admin.delivery.vo.expresstemplate.ShopBO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.controller.app.aftersale.vo.AppAfterSaleCreateReqVO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.convert.aftersale.AfterSaleConvert;
 | 
	
	
		
			
				|  | @@ -35,8 +38,12 @@ import cn.newfeifan.mall.module.trade.framework.order.config.TradeOrderPropertie
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.service.delivery.DeliveryExpressService;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.service.order.TradeOrderQueryService;
 | 
	
		
			
				|  |  |  import cn.newfeifan.mall.module.trade.service.order.TradeOrderUpdateService;
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 | 
	
		
			
				|  |  |  import lombok.extern.slf4j.Slf4j;
 | 
	
		
			
				|  |  | +import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | +import org.slf4j.Logger;
 | 
	
		
			
				|  |  | +import org.springframework.data.redis.core.StringRedisTemplate;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.support.TransactionSynchronization;
 | 
	
	
		
			
				|  | @@ -48,6 +55,7 @@ import java.time.LocalDateTime;
 | 
	
		
			
				|  |  |  import java.util.List;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import static cn.newfeifan.mall.framework.common.exception.util.ServiceExceptionUtil.exception;
 | 
	
		
			
				|  |  | +import static cn.newfeifan.mall.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
 | 
	
		
			
				|  |  |  import static cn.newfeifan.mall.module.trade.enums.ErrorCodeConstants.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  /**
 | 
	
	
		
			
				|  | @@ -80,6 +88,16 @@ public class AfterSaleServiceImpl implements AfterSaleService {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Resource
 | 
	
		
			
				|  |  |      private AdminUserService userService;
 | 
	
		
			
				|  |  | +    private StringRedisTemplate stringRedisTemplate;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private AdminUserMapper userMapper;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private TradeOrderMapper tradeOrderMapper;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private TradeOrderItemMapper tradeOrderItemMapper;
 | 
	
		
			
				|  |  | +    @Resource
 | 
	
		
			
				|  |  | +    private IntegralService integralService;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public PageResult<AfterSaleDO> getAfterSalePage(AfterSalePageReqVO pageReqVO) {
 | 
	
	
		
			
				|  | @@ -362,6 +380,31 @@ public class AfterSaleServiceImpl implements AfterSaleService {
 | 
	
		
			
				|  |  |              throw exception(AFTER_SALE_REFUND_FAIL_STATUS_NOT_WAIT_REFUND);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        //退积分 add by Ben
 | 
	
		
			
				|  |  | +        //1. 退购物使用的积分
 | 
	
		
			
				|  |  | +        Long tradeOrderId = afterSale.getOrderId();//购物单ID
 | 
	
		
			
				|  |  | +        Long orderUserId = afterSale.getUserId();
 | 
	
		
			
				|  |  | +        TradeOrderDO tradeOrderDO = tradeOrderMapper.selectById(tradeOrderId);
 | 
	
		
			
				|  |  | +        String tradeOrderNum = tradeOrderDO.getNo();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //交易订单项编号
 | 
	
		
			
				|  |  | +        Long orderItemId = afterSale.getOrderItemId();
 | 
	
		
			
				|  |  | +        TradeOrderItemDO tradeOrderItemDO = tradeOrderItemMapper.selectById(orderItemId);
 | 
	
		
			
				|  |  | +        Long payIntegral = tradeOrderItemDO.getPayIntegral();//支付积分
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //记录退还积分
 | 
	
		
			
				|  |  | +        TradeOrderItemDO toid = new TradeOrderItemDO();
 | 
	
		
			
				|  |  | +        toid.setId(tradeOrderItemDO.getId());
 | 
	
		
			
				|  |  | +        toid.setRefundIntegral(payIntegral);
 | 
	
		
			
				|  |  | +        tradeOrderItemMapper.updateById(toid);
 | 
	
		
			
				|  |  | +        //返回退款订单项对应的积分
 | 
	
		
			
				|  |  | +        integralService.updateUserIntegral(orderUserId, CaclEnum.ORDER_REFUND_INTEGRAL, payIntegral,0l,tradeOrderId,tradeOrderNum);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //2. 减少退货物品对应的冻结积分
 | 
	
		
			
				|  |  | +        Long increaseIntegral = tradeOrderItemDO.getIncreaseIntegral();
 | 
	
		
			
				|  |  | +        integralService.updateUserIntegral(orderUserId, CaclEnum.ORDER_REFUND_CANCEL_INTEGRAL, 0l,increaseIntegral*(-1),tradeOrderId,tradeOrderNum);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          // 发起退款单。注意,需要在事务提交后,再进行发起,避免重复发起
 | 
	
		
			
				|  |  |          createPayRefund(userIp, afterSale);
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -453,4 +496,21 @@ public class AfterSaleServiceImpl implements AfterSaleService {
 | 
	
		
			
				|  |  |                  .eqIfPresent(AfterSaleDO::getShopId, userShopDetails.getShopId())
 | 
	
		
			
				|  |  |                  .eq(AfterSaleDO::getMerchantId, userShopDetails.getMerchantId()));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    public static ShopBO getShopBO(StringRedisTemplate stringRedisTemplate, AdminUserMapper userMapper, Logger log) {
 | 
	
		
			
				|  |  | +        Long loginUserId = getLoginUserId();
 | 
	
		
			
				|  |  | +        String s = stringRedisTemplate.opsForValue().get("shop:" + loginUserId);
 | 
	
		
			
				|  |  | +        if (StringUtils.isEmpty(s)) {
 | 
	
		
			
				|  |  | +            AdminUserDO adminUserDO = userMapper.selectById(loginUserId);
 | 
	
		
			
				|  |  | +            ShopBO shop = new ShopBO();
 | 
	
		
			
				|  |  | +            shop.setShopId(adminUserDO.getShopId());
 | 
	
		
			
				|  |  | +            shop.setMerId(adminUserDO.getMerchantId());
 | 
	
		
			
				|  |  | +            log.info("====shop:{}", shop);
 | 
	
		
			
				|  |  | +            return shop;
 | 
	
		
			
				|  |  | +        } else {
 | 
	
		
			
				|  |  | +            log.info("====shop:{}", s);
 | 
	
		
			
				|  |  | +            return JSONObject.parseObject(s, ShopBO.class);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |