| | |
| | | } |
| | | |
| | | |
| | | StockConfig mainBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode()); |
| | | |
| | | /*StockConfig mainBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MIN_BUY.getCode()); |
| | | if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最低购买数量"+mainBuyConfig.getCValue(), request); |
| | | }*/ |
| | | //最低购买数量 US 10 印度100 香港台湾1000 |
| | | Integer minBuyNum; |
| | | if (stock.getStockType().equals(EStockType.US.getCode())) { |
| | | minBuyNum = 10; |
| | | } else if (stock.getStockType().equals(EStockType.IN.getCode())) { |
| | | minBuyNum = 100; |
| | | } else { |
| | | minBuyNum = 1000; |
| | | } |
| | | if(buyNum < minBuyNum){ |
| | | return ServerResponse.createByErrorMsg("最低购买数量" + minBuyNum, request); |
| | | } |
| | | |
| | | UserAssets userAssets = iUserAssetsServices.assetsByTypeAndUserId(stock.getStockType(), user.getId()); |
| | | StockConfig maxBuyConfig = iStockConfigServices.queryByKey(EConfigKey.MAX_BUY.getCode()); |
| | | if(buyNum<Integer.parseInt(mainBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最高购买数量"+maxBuyConfig.getCValue(), request); |
| | | if(buyNum > Integer.parseInt(maxBuyConfig.getCValue())){ |
| | | return ServerResponse.createByErrorMsg("最高购买数量" + maxBuyConfig.getCValue(), request); |
| | | } |
| | | if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){ |
| | | return ServerResponse.createByErrorMsg("请先缴清待补资金", request); |
| | |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(buyAmt); |
| | | BigDecimal needBuyAmt = buyAmt.add(orderFree); |
| | | //资金校验 |
| | | if (!stock.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | /*if (!stock.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | needBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt); |
| | | } |
| | | }*/ |
| | | BigDecimal fundratio = new BigDecimal(user.getFundRatio()).divide(new BigDecimal(100)); |
| | | BigDecimal availableBalance = fundratio.multiply(userAssets.getAvailableBalance()); |
| | | if (availableBalance.compareTo(needBuyAmt) < 0) { |
| | |
| | | |
| | | userPosition.setOrderStayDays(Integer.valueOf(0)); |
| | | userPosition.setOrderStayFee(new BigDecimal("0")); |
| | | userPosition.setAmountToBeCovered(amountToBeCovered); |
| | | //userPosition.setAmountToBeCovered(amountToBeCovered); |
| | | userPosition.setNewId(stockSubscribe.getNewlistId()); |
| | | int ret = 0; |
| | | ret = this.userPositionMapper.insert(userPosition); |
| | |
| | | |
| | | BigDecimal newBuyAmt = buyAmt; |
| | | //如果不是默认货币需要转换金额 |
| | | if (!stock.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | /*if (!stock.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | newBuyAmt = userAssetsServices.exchangeAmountByRate(stock.getStockType(), buyAmt); |
| | | } |
| | | }*/ |
| | | if(newBuyAmt.compareTo(userAssets.getAvailableBalance()) > 0){ |
| | | return ServerResponse.createByErrorMsg("可用余额不足" + userAssets.getAvailableBalance(), request); |
| | | } |
| | |
| | | UserPosition userPosition = getUserPosition(dzId,num, user, stockDz, nowPrice, stock, buyAmt); |
| | | userPositionMapper.insert(userPosition); |
| | | BigDecimal buy_fee_amt = siteSettingBuyFee.multiply(newBuyAmt); |
| | | //已经转化 直接传默认类型 |
| | | userAssetsServices.availablebalanceChange(EStockType.getDefault().getCode(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange(EStockType.getDefault().getCode(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | |
| | | userAssetsServices.availablebalanceChange(stock.getStockType(), user.getId(), EUserAssets.BUY, newBuyAmt.negate(),"",""); |
| | | iUserAssetsServices.availablebalanceChange(stock.getStockType(), userAssets.getUserId(), EUserAssets.HANDLING_CHARGE, buy_fee_amt, "", ""); |
| | | return ServerResponse.createBySuccess("购买成功", request); |
| | | } catch (Exception e) { |
| | | log.error("大宗下单异常{}", e.getMessage()); |
| | |
| | | }else{ |
| | | userPositionVO.setProfitAndLose(userPositionVO.getProfitAndLose().multiply(new BigDecimal(userPositionVO.getOrderLever()))); |
| | | } |
| | | BigDecimal nowPriceSUM = nowPrice.multiply(BigDecimal.valueOf(position.getOrderNum())); |
| | | if (position.getStockGid().equals(EStockType.US.getCode())) { |
| | | usMarketValue = usMarketValue.add(nowPrice); |
| | | usMarketValue = usMarketValue.add(nowPriceSUM); |
| | | usPositionEarnings = usPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | usPositionEarningsParent = usPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.HK.getCode())) { |
| | | hkMarketValue = hkMarketValue.add(nowPrice); |
| | | hkMarketValue = hkMarketValue.add(nowPriceSUM); |
| | | hkPositionEarnings = hkPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | hkPositionEarningsParent = hkPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.IN.getCode())) { |
| | | inMarketValue = inMarketValue.add(nowPrice); |
| | | inMarketValue = inMarketValue.add(nowPriceSUM); |
| | | inPositionEarnings = inPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | inPositionEarningsParent = inPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } else if(position.getStockGid().equals(EStockType.TW.getCode())) { |
| | | twMarketValue = twMarketValue.add(nowPrice); |
| | | twMarketValue = twMarketValue.add(nowPriceSUM); |
| | | twPositionEarnings = twPositionEarnings.add(userPositionVO.getProfitAndLose()); |
| | | twPositionEarningsParent = twPositionEarningsParent.add(userPositionVO.getProfitAndLoseParent2()); |
| | | } |