xiaoyong931011
2020-06-02 d90e8bfffc0bf032499982b83813de307a6749e9
src/main/java/com/xcong/excoin/modules/contract/service/impl/OrderWebsocketServiceImpl.java
@@ -1,6 +1,8 @@
package com.xcong.excoin.modules.contract.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.modules.coin.dao.MemberAccountFlowEntityDao;
import com.xcong.excoin.modules.coin.entity.MemberAccountFlowEntity;
import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity;
import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
import com.xcong.excoin.modules.contract.entity.ContractOrderEntity;
@@ -8,6 +10,7 @@
import com.xcong.excoin.modules.contract.service.ContractEntrustOrderService;
import com.xcong.excoin.modules.contract.service.ContractHoldOrderService;
import com.xcong.excoin.modules.contract.service.ContractOrderService;
import com.xcong.excoin.modules.member.dao.AgentReturnDao;
import com.xcong.excoin.modules.member.entity.AgentReturnEntity;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
@@ -20,8 +23,6 @@
import com.xcong.excoin.utils.CacheSettingUtils;
import com.xcong.excoin.utils.CalculateUtil;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -55,6 +56,12 @@
    @Resource
    MemberService memberService;
    @Resource
    private AgentReturnDao agentReturnDao;
    @Resource
    private MemberAccountFlowEntityDao memberAccountFlowEntityDao;
@@ -185,21 +192,11 @@
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        // 流水记录 TODO 531
//                        MemberAccountFlowRecord record = new MemberAccountFlowRecord();
//                        record.setCreateTime(new Date());
//                        record.setDirectionSource("止盈平仓");
//                        record.setRemark("止盈平仓");
//                        record.setMemberBalance(wallet.getAvailableBalance());
//                        record.setMemberid(order.getMemberId());
//                        record.setSymbolName(order.getSymbol());
//                        record.setMemberName(wallet.getMemberName());
//                        record.setMemberPhone(order.getMemberPhone());
//                        record.setPrice(profitLossPrice + order.getPrePrice());
//                        memberService.addFlowRecord(record);
//
//                        //返佣 TODO 531
//                        calYj(order.getMemberId(), new BigDecimal(order.getClosingPrice()), order, 2);
                        // 流水记录 TODO 531e
                        insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓");
                        //返佣
                       calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                    }
                }
            }
@@ -282,21 +279,11 @@
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
//                        // 流水记录 TODO 531
//                        MemberAccountFlowRecord record = new MemberAccountFlowRecord();
//                        record.setCreateTime(new Date());
//                        record.setDirectionSource("止盈平仓");
//                        record.setRemark("止盈平仓");
//                        record.setMemberBalance(wallet.getAvailableBalance());
//                        record.setMemberid(order.getMemberId());
//                        record.setSymbolName(order.getSymbol());
//                        record.setMemberName(wallet.getMemberName());
//                        record.setMemberPhone(order.getMemberPhone());
//                        record.setPrice(profitLossPrice + order.getPrePrice());
//                        memberService.addFlowRecord(record);
//
//                        //返佣 TODO 531
//                        calYj(order.getMemberId(), new BigDecimal(order.getClosingPrice()), order, 2);
                        insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓");
                        //返佣
                        calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                    }
                }
            }
@@ -381,21 +368,10 @@
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        // 流水记录 TODO 531
//                        MemberAccountFlowRecord record = new MemberAccountFlowRecord();
//                        record.setCreateTime(new Date());
//                        record.setDirectionSource("开多止损平仓");
//                        record.setRemark("开多止损平仓");
//                        record.setMemberBalance(wallet.getAvailableBalance());
//                        record.setMemberid(order.getMemberId());
//                        record.setSymbolName(order.getSymbol());
//                        record.setMemberName(wallet.getMemberName());
//                        record.setMemberPhone(order.getMemberPhone());
//                        record.setPrice(profitLossPrice + order.getPrePrice());
//                        memberService.addFlowRecord(record);
//
//                        //返佣 TODO
//                        calYj(order.getMemberId(), new BigDecimal(order.getClosingPrice()), order, 2);
                        insertAccountFlow(order, wallet, profitLossPrice, "开多止损平仓");
                        //返佣
                        calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                    }
                }
            }
@@ -479,26 +455,27 @@
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance,totalReturn,null,wallet.getId());
                        // 流水记录 TODO 531
//                        MemberAccountFlowRecord record = new MemberAccountFlowRecord();
//                        record.setCreateTime(new Date());
//                        record.setDirectionSource("开空止损平仓");
//                        record.setRemark("开空止损平仓");
//                        record.setMemberBalance(wallet.getAvailableBalance());
//                        record.setMemberid(order.getMemberId());
//                        record.setSymbolName(order.getSymbol());
//                        record.setMemberName(wallet.getMemberName());
//                        record.setMemberPhone(order.getMemberPhone());
//                        record.setPrice(profitLossPrice + order.getPrePrice());
//                        memberService.addFlowRecord(record);
//
//                        //返佣 TODO
//                        calYj(order.getMemberId(), new BigDecimal(order.getClosingPrice()), order, 2);
//
                        insertAccountFlow(order, wallet, profitLossPrice, "开空止损平仓");
                        //返佣
                        calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                    }
                }
            }
        }
    }
    private void insertAccountFlow(ContractHoldOrderEntity order, MemberWalletContractEntity wallet, BigDecimal profitLossPrice, String source) {
        MemberAccountFlowEntity record = new MemberAccountFlowEntity();
        record.setCreateTime(new Date());
        record.setSource(source);
        record.setRemark(source);
        record.setBalance(wallet.getAvailableBalance());
        record.setMemberId(order.getMemberId());
        record.setSymbol(order.getSymbol());
        record.setPrice(profitLossPrice.add(order.getPrePaymentAmount()));
        memberAccountFlowEntityDao.insert(record);
    }
@@ -585,7 +562,7 @@
                memberWalletContractService.increaseWalletContractBalanceById(null,totalBalance,null,wallet.getId());
                // TODO 531 待写
                //calYj(memId, new BigDecimal(coinsCoinsOrder.getClosingPrice()), coinsCoinsOrder, 1);
                calYj(memId, contractOrderEntity.getClosingFeeAmount(), contractOrderEntity, 1);
            }
        }
    }
@@ -666,19 +643,17 @@
                    BigDecimal totalPrice = coinsOrder.getPrePaymentAmount().negate();
                    //Double totalPrice = - coinsOrder.getPrePrice();
                    memberWalletContractService.increaseWalletContractBalanceById(null,totalPrice,null,usdt.getId());
                    // 流水记录 TODO
//                    MemberAccountFlowRecord record = new MemberAccountFlowRecord();
//                    record.setCreateTime(new Date());
//                    record.setDirectionSource("系统自动平仓");
//                    record.setRemark("系统自动平仓");
//                    record.setMemberBalance(coinsOrder.getPrePrice());
//                    record.setMemberid(memId);
//                    record.setSymbolName(null);
//                    record.setMemberName(null);
//                    record.setMemberPhone(null);
//                    record.setPrice(coinsOrder.getPrePrice());
//                    memberService.addFlowRecord(record);
                    MemberAccountFlowEntity record = new MemberAccountFlowEntity();
                    record.setCreateTime(new Date());
                    record.setSource("系统自动平仓");
                    record.setRemark("系统自动平仓");
                    record.setBalance(usdt.getAvailableBalance());
                    record.setMemberId(memId);
                    record.setSymbol(coinsOrder.getSymbol());
                    record.setPrice(coinsOrder.getPrePaymentAmount());
                    memberAccountFlowEntityDao.insert(record);
                }
            }
@@ -743,19 +718,20 @@
            agent.setOrderId(order.getId());
            agent.setOrderNo(order.getOrderNo());
            agent.setRefererId(agentMember.getId());
            agent.setOrderType(order.getClosingType());
            agent.setOrderType(order.getOrderType());
            agent.setReturnSymbol(order.getSymbol());
            agent.setIsReturn(0);
            agent.setReturnAmount(entry.getValue());
            agent.setClosingType(order.getClosingType());
            if (type == 1) {//开仓
                agent.setOpeningFeeAmount(order.getOpeningFeeAmount());
            } else if (type == 2) {//平仓
                agent.setClosingFeeAmount(order.getOpeningFeeAmount());
                agent.setClosingFeeAmount(order.getClosingFeeAmount());
            } else {//持仓费
                agent.setHoldingFeeAmount(order.getHoldAmount());
            }
            agent.setInviteId(entry.getKey());
            //agentReturnMapper.insert(agent);
            agentReturnDao.insert(agent);
        }