|  | @@ -10,10 +10,12 @@ import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  | +import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  |  import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | +import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.util.*;
 | 
	
	
		
			
				|  | @@ -30,6 +32,8 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 | 
	
		
			
				|  |  |      private MusicGroupDao musicGroupDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SysPaymentConfigService sysPaymentConfigService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysUserCashAccountService sysUserCashAccountService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public BaseDAO<Integer, SellOrder> getDAO() {
 | 
	
	
		
			
				|  | @@ -128,11 +132,11 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //库存类型
 | 
	
		
			
				|  |  | -            if(goodsStockType.equals(StockType.ALL) && accountType.equals(AccountType.INTERNAL)){
 | 
	
		
			
				|  |  | +            if (goodsStockType.equals(StockType.ALL) && accountType.equals(AccountType.INTERNAL)) {
 | 
	
		
			
				|  |  |                  sellOrder.setStockType(StockType.INTERNAL);
 | 
	
		
			
				|  |  | -            }else if(goodsStockType.equals(StockType.ALL) && accountType.equals(AccountType.EXTERNAL)){
 | 
	
		
			
				|  |  | +            } else if (goodsStockType.equals(StockType.ALL) && accountType.equals(AccountType.EXTERNAL)) {
 | 
	
		
			
				|  |  |                  sellOrder.setStockType(StockType.EXTERNAL);
 | 
	
		
			
				|  |  | -            }else {
 | 
	
		
			
				|  |  | +            } else {
 | 
	
		
			
				|  |  |                  sellOrder.setStockType(goodsStockType);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //批次号 TODO
 | 
	
	
		
			
				|  | @@ -236,11 +240,11 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 | 
	
		
			
				|  |  |                      sellOrder.setExpectAmount(BigDecimal.ZERO);
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  //库存类型
 | 
	
		
			
				|  |  | -                if(goods.getStockType().equals(StockType.ALL) && accountType.equals(AccountType.INTERNAL)){
 | 
	
		
			
				|  |  | +                if (goods.getStockType().equals(StockType.ALL) && accountType.equals(AccountType.INTERNAL)) {
 | 
	
		
			
				|  |  |                      sellOrder.setStockType(StockType.INTERNAL);
 | 
	
		
			
				|  |  | -                }else if(goods.getStockType().equals(StockType.ALL) && accountType.equals(AccountType.EXTERNAL)){
 | 
	
		
			
				|  |  | +                } else if (goods.getStockType().equals(StockType.ALL) && accountType.equals(AccountType.EXTERNAL)) {
 | 
	
		
			
				|  |  |                      sellOrder.setStockType(StockType.EXTERNAL);
 | 
	
		
			
				|  |  | -                }else {
 | 
	
		
			
				|  |  | +                } else {
 | 
	
		
			
				|  |  |                      sellOrder.setStockType(goods.getStockType());
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  //批次号 TODO
 | 
	
	
		
			
				|  | @@ -259,4 +263,29 @@ public class SellOrderServiceImpl extends BaseServiceImpl<Integer, SellOrder> im
 | 
	
		
			
				|  |  |          sellOrderDao.batchInsert(sellOrders);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | +    public SellOrder refund(Integer id) {
 | 
	
		
			
				|  |  | +        SellOrder sellOrder = sellOrderDao.get(id);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (!sellOrder.getStatus().equals(SellStatus.NORMAL)) {
 | 
	
		
			
				|  |  | +            throw new BizException("当前状态不能退货,请核查");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!sellOrder.getType().equals(SellTypeEnum.SCHOOL_BUY)) {
 | 
	
		
			
				|  |  | +            throw new BizException("学校采购不能退货");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //1、更改销售列表状态
 | 
	
		
			
				|  |  | +        sellOrder.setStatus(SellStatus.REFUND);
 | 
	
		
			
				|  |  | +        sellOrder.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        sellOrderDao.update(sellOrder);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //2、金额退到余额
 | 
	
		
			
				|  |  | +        if (sellOrder.getActualAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  | +            sysUserCashAccountService.updateBalance(sellOrder.getUserId(), sellOrder.getActualAmount().negate(), PlatformCashAccountDetailTypeEnum.REFUNDS, "退货");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //3、商品退回库存 TODO
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return sellOrder;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |  }
 |