| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.github.pagehelper.PageInfo; |
| | | import com.nq.Repository.ExchangeRateRepository; |
| | | import com.nq.common.ResponseCode; |
| | | import com.nq.common.ServerResponse; |
| | | import com.nq.dao.StockSubscribeMapper; |
| | | import com.nq.dao.UserAssetsMapper; |
| | | import com.nq.dao.UserMapper; |
| | | import com.nq.dao.UserStockSubscribeMapper; |
| | | import com.nq.dao.*; |
| | | import com.nq.enums.EStockType; |
| | | import com.nq.enums.EUserAssets; |
| | | import com.nq.pojo.*; |
| | |
| | | ISiteProductService iSiteProductService; |
| | | @Autowired |
| | | IUserService iUserService; |
| | | @Autowired |
| | | ISiteSettingService iSiteSettingService; |
| | | @Autowired |
| | | TradingHourServiceImpl tradingHourService; |
| | | |
| | | @Resource |
| | | IUserAssetsServices iUserAssetsServices; |
| | |
| | | UserAssetsMapper userAssetsMapper; |
| | | |
| | | @Autowired |
| | | ExchangeRateRepository exchangeRateRepository; |
| | | MoneyLogMapper moneyLogMapper; |
| | | |
| | | /** |
| | | * 用户新股申购 |
| | |
| | | if (model.getNewCode() != null) { |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<StockSubscribe>() |
| | | .eq("newlist_id", model.getNewlistId())); |
| | | if (stockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("新的股票代码不存在",request); |
| | | } |
| | | //判断购买新股需不需要密钥 |
| | | if(StringUtils.isNotEmpty(stockSubscribe.getPassword()) && !stockSubscribe.getPassword().equals(model.getPassword())){ |
| | | return ServerResponse.createByErrorMsg("密钥输入错误",request); |
| | |
| | | return ServerResponse.createByErrorMsg("最多可申购:" + stockSubscribe.getOrderNumber(), request); |
| | | } |
| | | |
| | | BigDecimal sumPrice = stockSubscribe.getPrice().multiply(new BigDecimal(model.getApplyNums())); |
| | | /*BigDecimal sumPrice = stockSubscribe.getPrice().multiply(new BigDecimal(model.getApplyNums())); |
| | | if(userAssets.getAvailableBalance().compareTo(sumPrice) < 0){ |
| | | return ServerResponse.createByErrorMsg("账户余额不足", request); |
| | | } |
| | | }*/ |
| | | |
| | | Date currentDate = new Date(); |
| | | if(currentDate.before(stockSubscribe.getSubscriptionTime())){ |
| | |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定",request); |
| | | } |
| | | if (stockSubscribe == null) { |
| | | return ServerResponse.createByErrorMsg("新的股票代码不存在",request); |
| | | } |
| | | |
| | | model.setApplyNums((int) (model.getApplyNums()*stockSubscribe.getLever())); |
| | | |
| | |
| | | }else{ |
| | | bound = new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice()); |
| | | } |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound); |
| | | } |
| | | if(userAssets.getAvailableBalance().compareTo(bound) < 0){ |
| | | return ServerResponse.createByErrorMsg("账户余额不足", request); |
| | | } |
| | | |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | | if(stockSubscribe.getType() == 1){ |
| | | model.setUserId(user.getId()); |
| | | model.setNewName(stockSubscribe.getName()); |
| | |
| | | userStockSubscribe.setNewStockId(stockSubscribe.getNewlistId()); |
| | | ret = userStockSubscribeMapper.insert(userStockSubscribe); |
| | | |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound); |
| | | } |
| | | BigDecimal subtract = userAssets.getAvailableBalance().subtract(bound); |
| | | if(subtract.compareTo(BigDecimal.ZERO) >= 0){ |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().add(bound)); |
| | |
| | | userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().add(subtract.abs())); |
| | | } |
| | | userAssetsMapper.updateById(userAssets); |
| | | |
| | | //交易记录MEX |
| | | MoneyLog moneyLog = new MoneyLog(); |
| | | EUserAssets eUserAssets = EUserAssets.BUY; |
| | | moneyLog.setDescs(eUserAssets.getDesc()); |
| | | moneyLog.setBeFore(before); |
| | | moneyLog.setAfter(userAssets.getAvailableBalance().toString()); |
| | | moneyLog.setAmount(bound.negate().toString()); |
| | | moneyLog.setAccectType(EStockType.MX.getCode()); |
| | | moneyLog.setType(eUserAssets.getCode()); |
| | | moneyLog.setUserId(user.getId()+""); |
| | | moneyLog.setSymbol(EStockType.MX.getSymbol()); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogMapper.insert(moneyLog); |
| | | if (ret > 0) { |
| | | return ServerResponse.createBySuccessMsg("申购成功",request); |
| | | } else { |
| | |
| | | return ServerResponse.createByErrorMsg("客户资金账户不存在"); |
| | | } |
| | | int applyNumber = userStockSubscribe.getApplyNums() - model.getApplyNumber(); |
| | | BigDecimal refundPrice = BigDecimal.ZERO; |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) <= 0){ |
| | | if(applyNumber > 0){ |
| | | //需要退回的资金 |
| | | BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber)); |
| | | refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber)); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice); |
| | |
| | | } |
| | | }else{ |
| | | if(applyNumber > 0){ |
| | | BigDecimal refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber)); |
| | | refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber)); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice); |
| | |
| | | } |
| | | } |
| | | } |
| | | //退回资金 交易记录MEX |
| | | MoneyLog moneyLog = new MoneyLog(); |
| | | EUserAssets eUserAssets = EUserAssets.BUY_RT; |
| | | moneyLog.setDescs(eUserAssets.getDesc()); |
| | | moneyLog.setBeFore(before); |
| | | moneyLog.setAfter(userAssets.getAvailableBalance().toString()); |
| | | moneyLog.setAmount(refundPrice.toString()); |
| | | moneyLog.setAccectType(EStockType.MX.getCode()); |
| | | moneyLog.setType(eUserAssets.getCode()); |
| | | moneyLog.setUserId(userAssets.getUserId()+""); |
| | | moneyLog.setSymbol(EStockType.MX.getSymbol()); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogMapper.insert(moneyLog); |
| | | ret = userStockSubscribeMapper.update1(model); |
| | | userAssetsMapper.updateById(userAssets); |
| | | iUserPositionService.newStockToPosition(model.getId(),userAssets.getAmountToBeCovered());//转持仓 |