| | |
| | | import com.nq.pojo.MoneyLog; |
| | | import com.nq.pojo.UserAssets; |
| | | import com.nq.service.IUserAssetsServices; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | |
| | | @Resource |
| | | MoneyLogMapper moneyLogMapper; |
| | | |
| | | @Autowired |
| | | UserRechargeServiceImpl userRechargeService; |
| | | |
| | | @Autowired |
| | | UserWithdrawServiceImpl withdrawService; |
| | | |
| | | @Override |
| | | public UserAssets assetsByTypeAndUserId(String accetType, Integer userId) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse updateUserAssets(Integer id, String amt) { |
| | | public ServerResponse updateUserAssets(Integer id, String amt,String type) { |
| | | UserAssets userAssets = userAssetsMapper.selectById(id); |
| | | |
| | | // 0 入款 1是扣钱 2 是充值 3 是提币 |
| | | BigDecimal bigAmt = new BigDecimal(amt); |
| | | if(amt.contains("-")){ |
| | | if(userAssets.getAvailableBalance().compareTo(bigAmt.negate())<0){ |
| | | return ServerResponse.createByErrorMsg("账户余额不足"); |
| | | if(type.equals("0") || type.equals("1 ")){ |
| | | if(type.equals("1")){ |
| | | bigAmt = bigAmt.negate(); |
| | | } |
| | | |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(bigAmt)); |
| | | if( userAssetsMapper.updateById(userAssets)>0){ |
| | | return ServerResponse.createBySuccess(); |
| | | }else{ |
| | | return ServerResponse.createByErrorMsg("修改金额失败"); |
| | | } |
| | | }else{ |
| | | if(type.equals("2")){ |
| | | return userRechargeService.createOrder(userAssets.getUserId(),1,bigAmt.intValue(),"1"); |
| | | }else{ |
| | | |
| | | |
| | | return ServerResponse.createBySuccess(); |
| | | } |
| | | } |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(bigAmt)); |
| | | if( userAssetsMapper.updateById(userAssets)>0){ |
| | | return ServerResponse.createBySuccess(); |
| | | }else{ |
| | | return ServerResponse.createByErrorMsg("修改金额失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | moneyLog.setType(eUserAssets.getCode()); |
| | | moneyLog.setUserId(userId+""); |
| | | moneyLog.setSymbol(EStockType.getEStockTypeByCode(accetType).getSymbol()); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogMapper.insert(moneyLog); |
| | | return userAssetsMapper.updateById(userAssets)>1; |
| | | } |