| 
					
				 | 
			
			
				@@ -1,10 +1,16 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.yonge.cooleshow.biz.dal.service.impl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.core.metadata.IPage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.baomidou.mybatisplus.core.toolkit.Wrappers; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dto.UserAccountRecordDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.dto.req.TotalReq; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.entity.UserAccountRecord; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.entity.UserOrder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.enums.InOrOutEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.service.UserOrderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.yonge.cooleshow.biz.dal.vo.UserOrderVo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.enums.CacheNameEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.enums.FrozenTypeEnum; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.service.UserAccountRecordService; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -13,6 +19,8 @@ import com.yonge.cooleshow.biz.dal.vo.res.AccountTotal; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.common.entity.HttpResponseResult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.toolset.base.exception.BizException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.redisson.api.RedissonClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.yonge.cooleshow.biz.dal.entity.UserAccount; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -30,10 +38,14 @@ import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 @Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAccount> implements UserAccountService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private final static Logger log = LoggerFactory.getLogger(UserAccountServiceImpl.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private UserAccountRecordService userAccountRecordService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private RedissonClient redissonClient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    private UserOrderService orderService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     @Override 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public UserAccountVo detail(Long id) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -118,18 +130,31 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     private HttpResponseResult<UserAccountRecord> doAccountChange(UserAccountRecordDto accountRecordDto) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         UserAccountVo detail = detail(accountRecordDto.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //收入要校验金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (InOrOutEnum.IN.equals(accountRecordDto.getInOrOut())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            UserOrder userOrder = orderService.getOne(Wrappers.<UserOrder>lambdaQuery() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    .eq(UserOrder::getOrderNo, accountRecordDto.getOrderNo())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            BigDecimal totalTransAmount = baseMapper.totalTransAmount(accountRecordDto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (null == totalTransAmount) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                totalTransAmount = BigDecimal.ZERO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            //金额校验失败,入账为冻结金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (null == userOrder || totalTransAmount.add(accountRecordDto.getTransAmount()).compareTo(userOrder.getActualPrice()) > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                log.error("账户变更失败,param is " + JSONObject.toJSONString(accountRecordDto)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                accountRecordDto.setErrFlag(1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                accountRecordDto.setErrMsg("账户变更异常,订单入账总金额大于购买金额,订单号:" + accountRecordDto.getOrderNo()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                accountRecordDto.setFrozenType(FrozenTypeEnum.FROZEN); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (FrozenTypeEnum.FROZEN.equals(accountRecordDto.getFrozenType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //校验冻结金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.frozenChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else if (FrozenTypeEnum.FROZEN_DEDUCT.equals(accountRecordDto.getFrozenType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.frozenDeductChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else if (FrozenTypeEnum.FROZEN_BACK.equals(accountRecordDto.getFrozenType())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.frozenBackChangeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             baseMapper.changeAccount(accountRecordDto.getUserId(), accountRecordDto.getTransAmount(), accountRecordDto.getInOrOut().getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -141,6 +166,7 @@ public class UserAccountServiceImpl extends ServiceImpl<UserAccountDao, UserAcco 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             //插入账户变更记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             accountRecordDto.setAccountId(accountRecordDto.getUserId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             accountRecordDto.setAccountBalance(detail.getAmountUsable()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             userAccountRecordService.save(accountRecordDto); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return HttpResponseResult.succeed(accountRecordDto); 
			 |