| | |
| | | // 申请数量为空时返回错误信息 |
| | | return ServerResponse.createByErrorMsg("申请数量不能为空", request); |
| | | } |
| | | |
| | | //用户是否杠杆 |
| | | boolean isLever = model.getLever() != null && model.getLever().intValue() > 0; |
| | | if (isLever) { |
| | | model.setApplyNums(model.getApplyNums() * model.getLever().intValue()); |
| | | } else { |
| | | model.setApplyNums(model.getApplyNums() * stockSubscribe.getLever().intValue()); |
| | | } |
| | | |
| | | if(model.getApplyNums() < stockSubscribe.getMinNumber() ){ |
| | | return ServerResponse.createByErrorMsg("最少申购:" + stockSubscribe.getMinNumber(), request); |
| | | } |
| | |
| | | } |
| | | |
| | | // //重复申购限制 |
| | | Long count = userStockSubscribeMapper.selectCount(new QueryWrapper<UserStockSubscribe>().eq( |
| | | /*Long count = userStockSubscribeMapper.selectCount(new QueryWrapper<UserStockSubscribe>().eq( |
| | | "new_code", model.getNewCode()).eq("user_id", user.getId()).eq("type", model.getType())); |
| | | if (count > 0) { |
| | | return ServerResponse.createByErrorMsg("请勿重复申请",request); |
| | | } |
| | | }*/ |
| | | if (siteProduct.getRealNameDisplay() && user.getIsLock().intValue() == 1) { |
| | | return ServerResponse.createByErrorMsg("订单失败,帐户已被锁定",request); |
| | | } |
| | | |
| | | model.setApplyNums((int) (model.getApplyNums()*stockSubscribe.getLever())); |
| | | |
| | | //计算申购金额 |
| | | BigDecimal bound; |
| | |
| | | }else{ |
| | | bound = new BigDecimal(model.getApplyNums()).multiply(stockSubscribe.getPrice()); |
| | | } |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | /*//如果不是默认货币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | bound = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), bound); |
| | | }*/ |
| | | |
| | | //需要资金 |
| | | BigDecimal needBound; |
| | | //杠杆账户只需初始数量资金 |
| | | if (isLever) { |
| | | needBound = bound.divide(new BigDecimal(model.getLever())); |
| | | } else { |
| | | needBound = bound; |
| | | } |
| | | if(userAssets.getAvailableBalance().compareTo(bound) < 0){ |
| | | if(userAssets.getAvailableBalance().compareTo(needBound) < 0){ |
| | | return ServerResponse.createByErrorMsg("账户余额不足", request); |
| | | } |
| | | |
| | |
| | | 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.setAccectType(stockSubscribe.getStockType()); |
| | | moneyLog.setType(eUserAssets.getCode()); |
| | | moneyLog.setUserId(user.getId()+""); |
| | | moneyLog.setSymbol(EStockType.MX.getSymbol()); |
| | | moneyLog.setSymbol(EStockType.getEStockTypeByCode(stockSubscribe.getStockType()).getSymbol()); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogMapper.insert(moneyLog); |
| | | if (ret > 0) { |
| | |
| | | if(applyNumber > 0){ |
| | | //需要退回的资金 |
| | | refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber)); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | /*//如果不是默认货币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice); |
| | | } |
| | | }*/ |
| | | userAssets.setAvailableBalance(userAssets.getAvailableBalance().add(refundPrice)); |
| | | userAssets.setFreezeMoney(userAssets.getFreezeMoney().subtract(refundPrice)); |
| | | } |
| | | }else{ |
| | | if(applyNumber > 0){ |
| | | refundPrice = userStockSubscribe.getBuyPrice().multiply(new BigDecimal(applyNumber)); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.MX.getCode())) { |
| | | /*//如果不是默认货币需要转换金额 |
| | | if (!stockSubscribe.getStockType().equals(EStockType.getDefault().getCode())) { |
| | | refundPrice = iUserAssetsServices.exchangeAmountByRate(stockSubscribe.getStockType(), refundPrice); |
| | | } |
| | | }*/ |
| | | BigDecimal subtract = refundPrice.subtract(userAssets.getAmountToBeCovered()); |
| | | if(subtract.compareTo(BigDecimal.ZERO) <= 0){//如果退回的资金不足补足待补则直接减 |
| | | userAssets.setAmountToBeCovered(userAssets.getAmountToBeCovered().subtract(refundPrice)); |
| | |
| | | moneyLog.setBeFore(before); |
| | | moneyLog.setAfter(userAssets.getAvailableBalance().toString()); |
| | | moneyLog.setAmount(refundPrice.toString()); |
| | | moneyLog.setAccectType(EStockType.MX.getCode()); |
| | | moneyLog.setAccectType(stockSubscribe.getStockType()); |
| | | moneyLog.setType(eUserAssets.getCode()); |
| | | moneyLog.setUserId(userAssets.getUserId()+""); |
| | | moneyLog.setSymbol(EStockType.MX.getSymbol()); |
| | | moneyLog.setSymbol(EStockType.getEStockTypeByCode(stockSubscribe.getStockType()).getSymbol()); |
| | | moneyLog.setCreateTime(new Date()); |
| | | moneyLogMapper.insert(moneyLog); |
| | | } |
| | |
| | | String header = request.getHeader(property); |
| | | if (header != null) { |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | |
| | | List<UserStockSubscribeVo> userStockSubscribe = this.userStockSubscribeMapper.getListByParam(user.getId(), type, status); |
| | | /*if (type==null||type.equals("")){ |
| | | userStockSubscribe = this.userStockSubscribeMapper.selectList(new QueryWrapper<>(new UserStockSubscribe()).eq("user_id", user.getId()).orderByDesc("add_time")); |
| | | }else{ |
| | | userStockSubscribe = this.userStockSubscribeMapper.selectList(new QueryWrapper<>(new UserStockSubscribe()).eq("user_id", user.getId()).eq("type", type).orderByDesc("add_time")); |
| | | }*/ |
| | | |
| | | List<UserStockSubscribeVo> list = new ArrayList<>(); |
| | | for (UserStockSubscribeVo userStockSubscribe1 : userStockSubscribe) { |
| | | StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new QueryWrapper<>(new StockSubscribe()) |
| | | .eq("newlist_id", userStockSubscribe1.getNewStockId())); |
| | | if (stockSubscribe != null) { |
| | | list.add(userStockSubscribe1); |
| | | } |
| | | } |
| | | return ServerResponse.createBySuccess(list); |
| | | return ServerResponse.createBySuccess(userStockSubscribe); |
| | | } |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录"); |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse getOneSubscribeByUserIdPage(int pageNum,int pageSize,String type, Integer status, HttpServletRequest request) { |
| | | String property = PropertiesUtil.getProperty("user.cookie.name"); |
| | | String header = request.getHeader(property); |
| | | if (header != null) { |
| | | User user = iUserService.getCurrentRefreshUser(request); |
| | | PageHelper.startPage(pageNum, pageSize); |
| | | List<UserStockSubscribeVo> userStockSubscribe = this.userStockSubscribeMapper.getListByParam(user.getId(), type, status); |
| | | PageInfo<UserStockSubscribeVo> pageInfo = new PageInfo<>(userStockSubscribe); |
| | | return ServerResponse.createBySuccess(pageInfo); |
| | | } |
| | | return ServerResponse.createByErrorCodeMsg(ResponseCode.NEED_LOGIN.getCode(),"请先登录"); |
| | | } |
| | | |
| | | /** |
| | | * 新股申购-用户提交金额 |
| | | */ |