package com.ssm.manage.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ssm.core.service.impl.BaseServiceImpl;
import com.ssm.core.utils.SnowflakeUtil;
import com.ssm.manage.dao.BaseDao;
import com.ssm.manage.dao.CooperateListDao;
import com.ssm.manage.dao.CooperateProjectDao;
import com.ssm.manage.dto.CouponShareDto;
import com.ssm.manage.entity.*;
import com.ssm.manage.mapper.CouponShareMapper;
import com.ssm.manage.mapper.PlatformCouponMapper;
import com.ssm.manage.query.CooperateListRequest;
import com.ssm.manage.query.CouponShareRequest;
import com.ssm.manage.query.ProjectRequest;
import com.ssm.manage.response.*;
import com.ssm.manage.service.*;
import com.ssm.manage.utils.SessionHelp;
import com.ssm.manage.utils.StringUtils;
import com.ssm.util.RedisClient;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import javax.servlet.http.HttpSession;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;


/**
 * (CouponShare)表服务实现类
 *
 * @author makejava
 * @since 2022-06-11 15:00:06
 */
@Service("cooperateListService")
public class CooperateListServiceImpl extends BaseServiceImpl<CooperateList> implements CooperateListService {

    @Autowired
    private CooperateListDao cooperateListDao;

    @Autowired
    private SsmProjectService ssmProjectService;

    @Autowired
    private SsmCardChangeService ssmCardChangeService;

    @Autowired
    private CooperateProjectDao cooperateProjectDao;

    @Autowired
    private SsmRepayTradeService ssmRepayTradeService;

    @Autowired
    private SsmCashService ssmCashService;

    @Autowired
    private SsmCourseService ssmCourseService;

    @Autowired
    private SsmRefundCourseService ssmRefundCourseService;

    @Autowired
    private SsmRefundCashService ssmRefundCashService;

    @Autowired
    private SsmBaseStoreService ssmBaseStoreService;

    @Autowired
    private SsmDocPromotionService ssmDocPromotionService;

    @Autowired
    private SsmPromotionProjectService ssmPromotionProjectService;


    private static String staffKey = "staffKey";
    @Autowired
    private RedisClient<StaffResponse> staffRedisClient;

    @Override
    public BaseDao<CooperateList> getDao() {
        return cooperateListDao;
    }

    @Override
    public int insert(CooperateListRequest cooperateListRequest, HttpSession session) {
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(SessionHelp.getStoreId(session));

        CooperateList cooperateList = new CooperateList();
        BeanUtils.copyProperties(cooperateListRequest,cooperateList);
        if(baseStore.getParentId()==null){
            cooperateList.setStoreId(baseStore.getId());
        }else cooperateList.setStoreId(baseStore.getParentId());
        cooperateList.setId(getId());
        cooperateList.setInputDate(new Date());
        String loginAccount = SessionHelp.getLoginAccount(session);
        if(staffRedisClient.hasKey(getStaffKey(loginAccount))){
            StaffResponse staffResponse = staffRedisClient.get(getStaffKey(loginAccount));
            cooperateList.setInputBy(staffResponse.getStaffName());
        }
        return cooperateListDao.insert(cooperateList);
    }

    @Override
    public int update(CooperateListRequest cooperateListRequest, HttpSession session) {
        CooperateList cooperateList = new CooperateList();
        BeanUtils.copyProperties(cooperateListRequest,cooperateList);
        String loginAccount = SessionHelp.getLoginAccount(session);
        if(staffRedisClient.hasKey(getStaffKey(loginAccount))){
            StaffResponse staffResponse = staffRedisClient.get(getStaffKey(loginAccount));
            cooperateList.setUpdateBy(staffResponse.getStaffName());
            cooperateList.setUpdateDate(new Date());
        }
        return cooperateListDao.updateByPrimaryKey(cooperateList);
    }

    @Override
    public int delete(Long id) {
        return cooperateListDao.deleteByPrimaryKey(id);
    }

    @Override
    public PageResponse<CooperateList> page(CooperateListRequest cooperateListRequest) {
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(cooperateListRequest.getStoreId());
        CooperateList cooperateList = new CooperateList();
        BeanUtils.copyProperties(cooperateListRequest,cooperateList);
        if(baseStore.getParentId()!=null){
            cooperateList.setStoreId(baseStore.getParentId());
        }
        PageHelper.startPage(cooperateListRequest.getPageNum(),cooperateListRequest.getPageSize());
        List<CooperateList> select = cooperateListDao.select(cooperateList);
        Example example = new Example(CooperateList.class);
        Example.Criteria criteria = example.createCriteria();
        if (cooperateListRequest.getBrandNum()!=null && !cooperateListRequest.getBrandNum().equals("")){
            criteria.andLike(CooperateListRequest.Fields.brandNum,cooperateListRequest.getBrandNum());
        }
        if(cooperateListRequest.getBrandName()!=null && !cooperateListRequest.getBrandName().equals("")){
            criteria.andLike(CooperateListRequest.Fields.brandName,cooperateList.getBrandName());
        }
        if(cooperateList.getStoreId()!=null){
            criteria.andEqualTo(CooperateListRequest.Fields.storeId,cooperateList.getStoreId());
        }
        if(cooperateListRequest.getPhone()!=null){
            criteria.andLike(CooperateListRequest.Fields.phone,cooperateListRequest.getPhone());
        }
//        int i = 1/0;
        List<CooperateList> cooperateLists = cooperateListDao.selectByExample(example);
        PageInfo<CooperateList> pageInfo = new PageInfo<>(select);
        PageResponse<CooperateList> pageResponse = new PageResponse<>();
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @Override
    public PageResponse<CooperateList> bind(CooperateListRequest cooperateListRequest) {
        //查询当前的项目
        BaseProject baseProject = ssmProjectService.selectByPrimaryKey(cooperateListRequest.getProjectId());
        baseProject.setCooperateId(cooperateListRequest.getId());
        ssmProjectService.updateByPrimaryKey(baseProject);
        //
        PageResponse<CooperateList> pageResponse = new PageResponse<>();
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        return pageResponse;
    }

    @Override
    public PageResponse<BaseProject> cooperateProjectPage(ProjectRequest baseProject) {
        PageHelper.startPage(baseProject.getPageNum(),baseProject.getPageSize(),"cooperate_id");
        Example example = new Example(BaseProject.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andIsNotNull("cooperateId");
        if(baseProject.getCooperateId()!=null){
            criteria.andEqualTo(BaseProject.Fields.cooperateId,baseProject.getCooperateId());
        }
        if(baseProject.getStoreId()!=null){
            criteria.andEqualTo(BaseProject.Fields.storeId,baseProject.getStoreId());
        }
        List<BaseProject> projectList = ssmProjectService.selectByExample(example);
        if(projectList!=null && projectList.size()>0){
            List<Long> collect = projectList.stream().map(BaseProject::getCooperateId).collect(Collectors.toList());
            Example example1 = new Example(CooperateList.class);
            Example.Criteria criteria1 = example1.createCriteria();
            criteria1.andIn("id",collect);
            List<CooperateList> cooperateLists = cooperateListDao.selectByExample(example1);
            for (BaseProject project : projectList) {
                for (CooperateList cooperateList : cooperateLists) {
                    if(project.getCooperateId().compareTo(cooperateList.getId())==0){
                        project.setCooperateList(cooperateList);
                        continue;
                    }
                }
            }
        }
//        ConcurrentHashMap<String,Integer> concurrentHashMap = new ConcurrentHashMap();
//        concurrentHashMap.get();
//        concurrentHashMap.put()
        PageResponse<BaseProject> pageResponse = new PageResponse<>();
        PageInfo<BaseProject> pageInfo = new PageInfo<>(projectList);
        pageResponse.setCodeAndMsg(ResponseCode.OK);
        pageResponse.setPageInfo(pageInfo);
        return pageResponse;
    }

    @Override
    public GenericResponse<List<CooperateResponse>> cooperByDate(ProjectRequest baseProject) throws ParseException, SmsException {
        GenericResponse<List<CooperateResponse>> genericResponse = new GenericResponse<>();
        genericResponse.setCodeAndMsg(ResponseCode.OK);
        List<CooperateResponse> cooperateResponseList = new ArrayList<>();
        //根据门店id查询当前的合作商有哪些
        BaseStore baseStore = ssmBaseStoreService.selectByPrimaryKey(baseProject.getStoreId());
        CooperateList cooperateList = new CooperateList();
        if(baseStore.getParentId()!=null){
            cooperateList.setStoreId(baseStore.getParentId());
        }else {
            cooperateList.setStoreId(baseStore.getId());
        }
        List<CooperateList> cooperateLists = cooperateListDao.select(cooperateList);
        if(cooperateLists==null || cooperateLists.size()==0){
            genericResponse.setData(cooperateResponseList);
            return genericResponse;
        }
        //根据合作商查询所有的合作商项目
        List<Long> cooperateIds = cooperateLists.stream().map(CooperateList::getId).collect(Collectors.toList());
        List<CooperateProject> cooperateProjects = cooperateProjectDao.selectByCooperateIds(cooperateIds);
        if(cooperateProjects==null || cooperateProjects.size()==0){
            genericResponse.setData(cooperateResponseList);
            return genericResponse;
        }
        Map<Long, List<Long>> coopGroupProject = cooperateProjects.stream()
                .collect(Collectors.groupingBy(CooperateProject::getCooperateId,
                        Collectors.mapping(CooperateProject::getProjectId, Collectors.toList())));


        String dateStr = baseProject.getStartTime().toString().substring(0, 7);
        //所有的收银
        List<CashList> cashLists = ssmCashService.selectListByStartTimeAndEndTime(baseStore.getId(), dateStr, baseProject.getStartTime(), baseProject.getEndTime());
        //所有的收银退
        List<RefundCash> refundCashLists = ssmRefundCashService.selectListsByStartTimeAndEndTime(baseStore.getId(), dateStr, baseProject.getStartTime(), baseProject.getEndTime());
        //所有的疗程
        List<CourseList> courseLists = ssmCourseService.selectListByStarteTimeAndEndTime(baseStore.getId(), dateStr, baseProject.getStartTime(), baseProject.getEndTime());
        //所有疗程退
        List<RefundCourse> refundCourseLists = ssmRefundCourseService.selectListByStartTimeAndEndTime(baseStore.getId(), baseProject.getStartTime(), baseProject.getEndTime());
        //查询所有的促销活动
        List<DocPromotion> docPromotionList = ssmDocPromotionService.selectListByStartTimeAndEndTime(baseStore.getId(), baseProject.getStartTime(), baseProject.getEndTime());
        //促销活动id
        List<Long> promotionIds = docPromotionList.stream().map(DocPromotion::getPromotionId).collect(Collectors.toList());
        //查询促销项目
        List<PromotionProject> promotionProjectList = new ArrayList<>();
        if(promotionIds!=null && promotionIds.size()>0){
            promotionProjectList = ssmPromotionProjectService.selectByPromotionIds(promotionIds);
        }
        //查询疗程和促销还款
        List<RepayTradeList> repayTradeList =  ssmRepayTradeService.selectListByStartTimeAndEndTime(baseStore.getId(), baseProject.getStartTime(), baseProject.getEndTime());
        //查询加价转疗程
        List<CardChangeInProjectResponse> cardChangeInProjects = ssmCardChangeService.selectListByStartTimeAndEndTime(baseStore.getId(), baseProject.getStartTime(), baseProject.getEndTime());
        /**
         * 所有的单据进行过滤
         */
        Iterator<Map.Entry<Long, List<Long>>> iterator = coopGroupProject.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<Long, List<Long>> listEntry = iterator.next();
            List<Long> projectList = listEntry.getValue();
            Long cooperId = listEntry.getKey();
            List<CashList> cashList = cashLists.stream().filter(item -> projectList.contains(item.getProjectId())).collect(Collectors.toList());
            List<RefundCash> refundCashList = refundCashLists.stream().filter(item -> projectList.contains(item.getProjectId())).collect(Collectors.toList());
            List<CourseList> courseList = courseLists.stream().filter(item -> projectList.contains(item.getProjctId())).collect(Collectors.toList());
            List<RefundCourse> refundCourseList = refundCourseLists.stream().filter(item -> projectList.contains(item.getCourseProjectId())).collect(Collectors.toList());
            List<CooperateProject> cashProject = cooperateProjects.stream().filter(item -> item.getType() == 0).collect(Collectors.toList());
            List<CooperateProject> courseProject = cooperateProjects.stream().filter(item -> item.getType() == 1).collect(Collectors.toList());
            //疗程促销的按购买进行抽佣  需要抽佣的项目
            List<PromotionProject> coopProject = promotionProjectList.stream().filter(item -> projectList.contains(item)).collect(Collectors.toList());





            BigDecimal cashMoney = BigDecimal.ZERO;
            BigDecimal cashCoopMoney = BigDecimal.ZERO;
            BigDecimal cashRefundMoney = BigDecimal.ZERO;
            BigDecimal cashRefundCoopMoney = BigDecimal.ZERO;
            BigDecimal courseCoopMoney = BigDecimal.ZERO;
            BigDecimal courseMoney = BigDecimal.ZERO;
            BigDecimal courseRefundMoney = BigDecimal.ZERO;
            BigDecimal courseRefundCoopMoney = BigDecimal.ZERO;
            BigDecimal promotionCoopMoney = BigDecimal.ZERO;
            BigDecimal promotionMoney = BigDecimal.ZERO;
            BigDecimal courseChangeMoney = BigDecimal.ZERO;
            BigDecimal courseChangeCoopMoney = BigDecimal.ZERO;
            BigDecimal courseRepayMoney = BigDecimal.ZERO;
            BigDecimal courseRepayCoopMoney = BigDecimal.ZERO;
            BigDecimal promotionRepayMoney = BigDecimal.ZERO;
            BigDecimal promotionRepayCoopMoney = BigDecimal.ZERO;
            BigDecimal hundred = new BigDecimal("100");
            //计算收银金额
            computeCashList(cashList, cashProject, cashMoney, cashCoopMoney, hundred);

            //计算收银退款金额
            computeRefundCashList(refundCashList, cashProject, cashRefundMoney, cashRefundCoopMoney, hundred);

            //计算疗程金额
            computeCourseList(courseList, courseProject, courseCoopMoney, courseMoney, hundred);

            //计算疗程退款金额
            computeRefundCourseList(refundCourseList, courseProject, courseRefundMoney, courseRefundCoopMoney, hundred);

            //计算促销金额
            for (DocPromotion docPromotion : docPromotionList) {
                for (PromotionProject promotionProject : coopProject) {
                    if(docPromotion.getPromotionId().compareTo(promotionProject.getPromotionId())==0){
                        for (CooperateProject cooperateProject : courseProject) {
                            if(cooperateProject.getProjectId().compareTo(promotionProject.getProjectId())==0){
                                //确认项目金额和促销总价的比例
//                                BigDecimal projectTotalMoney = promotionProject.getProjectTotalMoney();
//                                BigDecimal oneTimeSaleMoney = docPromotion.getAmount().divide(new BigDecimal(docPromotion.getCount().toString()), 4, BigDecimal.ROUND_HALF_UP);
//                                BigDecimal projectBroker = projectTotalMoney.divide(oneTimeSaleMoney, 4, BigDecimal.ROUND_HALF_UP);
                                BigDecimal amount = docPromotion.getCollectionCashAmount().add(docPromotion.getCollectionRechargeAmount());
//                                BigDecimal docProjectMoney = projectBroker.multiply(amount);
                                //查询项目的抽成
                                if (cooperateProject.getType()==0){
                                    BigDecimal coopMoney = cooperateProject.getBrokerage()
                                            .multiply(BigDecimal.valueOf(promotionProject.getTimes())
                                                    .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                                    promotionCoopMoney = promotionCoopMoney.add(coopMoney);
                                    promotionMoney = promotionMoney.add(amount.subtract(coopMoney));
                                }
                                if (cooperateProject.getType()==1){
                                    BigDecimal coopMoney = cooperateProject.getBrokerage().divide(hundred, 4, BigDecimal.ROUND_HALF_UP)
                                            .multiply(cooperateProject.getProjectMoney())
                                            .multiply(BigDecimal.valueOf(promotionProject.getTimes())
                                                    .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                                    promotionCoopMoney = promotionCoopMoney.add(coopMoney);
                                    promotionMoney = promotionMoney.add(amount.subtract(coopMoney));
                                }
                            }
                        }
                    }
                }
            }



            CooperateResponse response = new CooperateResponse();
            response.setCashMoney(cashMoney);
            response.setCashCoopMoney(cashCoopMoney);
            response.setCashRefundMoney(cashRefundMoney);
            response.setCashRefundCoopMoney(cashRefundCoopMoney);
            response.setCourseMoney(courseMoney);
            response.setCourseCoopMoney(courseCoopMoney);
            response.setCourseRefundMoney(courseRefundMoney);
            response.setCourseRefundCoopMoney(courseRefundCoopMoney);
            response.setPromotionMoney(promotionMoney);
            response.setPromotionCoopMoney(promotionCoopMoney);
            for (CooperateList list : cooperateLists) {
                if(list.getId().compareTo(cooperId)==0){
                    response.setCooperNum(list.getBrandNum());
                    response.setCooperName(list.getBrandName());
                }
            }
            cooperateResponseList.add(response);

        }
        genericResponse.setData(cooperateResponseList);


//        //所有的加价转疗程
//        List<CardChangeInProjectResponse> cardChangeInProjectResponses = ssmCardChangeService.selectListByStartTimeAndEndTime(baseStore.getId(), dateStr, baseProject.getStartTime(), baseProject.getEndTime());
//        //疗程转充值
//        //促销
//        //疗程内调

        return genericResponse;
    }

    private void computeRefundCourseList(List<RefundCourse> refundCourseList, List<CooperateProject> courseProject, BigDecimal courseRefundMoney, BigDecimal courseRefundCoopMoney, BigDecimal hundred) {
        for (RefundCourse list : refundCourseList) {
            for (CooperateProject cooperateProject : courseProject) {
                if(list.getCourseProjectId()!=null && cooperateProject.getProjectId()!=null && list.getCourseProjectId().compareTo(cooperateProject.getProjectId())==0){
                    if (cooperateProject.getType()==1){
                        BigDecimal coopMoney = cooperateProject.getBrokerage()
                                .multiply(BigDecimal.valueOf(list.getRefundNumber())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        courseRefundCoopMoney = courseRefundCoopMoney.add(coopMoney);
                        courseRefundMoney = courseRefundMoney.add(list.getCourseRefundMoney().subtract(coopMoney));
                    }
                    if (cooperateProject.getType()==1){
                        BigDecimal coopMoney = cooperateProject.getBrokerage().divide(hundred, 4, BigDecimal.ROUND_HALF_UP)
                                .multiply(cooperateProject.getProjectMoney())
                                .multiply(BigDecimal.valueOf(list.getRefundNumber())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        courseRefundCoopMoney = courseRefundCoopMoney.add(coopMoney);
                        courseRefundMoney = courseRefundMoney.add(list.getCourseRefundMoney().subtract(coopMoney));
                    }

                }
            }
        }
    }

    private void computeCourseList(List<CourseList> courseList, List<CooperateProject> courseProject, BigDecimal courseCoopMoney, BigDecimal courseMoney, BigDecimal hundred) {
        for (CourseList list : courseList) {
            for (CooperateProject cooperateProject : courseProject) {
                if(list.getProjctId()!=null && cooperateProject.getProjectId()!=null && list.getProjctId().compareTo(cooperateProject.getProjectId())==0){
                    if (cooperateProject.getType()==0){
                        BigDecimal coopMoney = cooperateProject.getBrokerage()
                                .multiply(BigDecimal.valueOf(list.getNumberTimes())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        courseCoopMoney = courseCoopMoney.add(coopMoney);
                        courseMoney = courseMoney.add(list.getAmount().subtract(coopMoney));
                    }
                    if (cooperateProject.getType()==1){
                        BigDecimal coopMoney = cooperateProject.getBrokerage().divide(hundred, 4, BigDecimal.ROUND_HALF_UP)
                                .multiply(cooperateProject.getProjectMoney())
                                .multiply(BigDecimal.valueOf(list.getNumberTimes())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        courseCoopMoney = courseCoopMoney.add(coopMoney);
                        courseMoney = courseMoney.add(list.getAmount().subtract(coopMoney));
                    }

                }
            }
        }
    }

    private void computeRefundCashList(List<RefundCash> refundCashList, List<CooperateProject> cashProject, BigDecimal cashRefundMoney, BigDecimal cashRefundCoopMoney, BigDecimal hundred) {
        for (RefundCash list : refundCashList) {
            for (CooperateProject cooperateProject : cashProject) {
                if(list.getProjectId()!=null && cooperateProject.getProjectId()!=null && list.getProjectId().compareTo(cooperateProject.getProjectId())==0){
                    if (cooperateProject.getType()==0){
                        BigDecimal coopMoney = cooperateProject.getBrokerage()
                                .multiply(BigDecimal.valueOf(list.getNumberTimes())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        cashRefundCoopMoney = cashRefundCoopMoney.add(coopMoney);
                        cashRefundMoney = cashRefundMoney.add(list.getTransactionPrice().subtract(coopMoney));
                    }
                    if (cooperateProject.getType()==1){
                        BigDecimal coopMoney = cooperateProject.getBrokerage().divide(hundred, 4, BigDecimal.ROUND_HALF_UP)
                                .multiply(cooperateProject.getProjectMoney())
                                .multiply(BigDecimal.valueOf(list.getNumberTimes())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        cashRefundCoopMoney = cashRefundCoopMoney.add(coopMoney);
                        cashRefundMoney = cashRefundMoney.add(list.getTransactionPrice().subtract(coopMoney));
                    }

                }
            }
        }
    }

    private void computeCashList(List<CashList> cashList, List<CooperateProject> cashProject, BigDecimal cashMoney, BigDecimal cashCoopMoney, BigDecimal hundred) {
        for (CashList list : cashList) {
            for (CooperateProject cooperateProject : cashProject) {
                if(list.getProjectId()!=null && cooperateProject.getProjectId()!=null && list.getProjectId().compareTo(cooperateProject.getProjectId())==0){
                    if (cooperateProject.getType()==0){
                        BigDecimal coopMoney = cooperateProject.getBrokerage()
                                .multiply(BigDecimal.valueOf(list.getNumberTimes())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        cashCoopMoney = cashCoopMoney.add(coopMoney);
                        cashMoney = cashMoney.add(list.getTransactionPrice().subtract(coopMoney));
                    }
                    if (cooperateProject.getType()==1){
                        BigDecimal coopMoney = cooperateProject.getBrokerage().divide(hundred, 4, BigDecimal.ROUND_HALF_UP)
                                .multiply(cooperateProject.getProjectMoney())
                                .multiply(BigDecimal.valueOf(list.getNumberTimes())
                                        .divide(BigDecimal.valueOf(cooperateProject.getProjectNumber()), 4, BigDecimal.ROUND_HALF_UP));
                        cashCoopMoney = cashCoopMoney.add(coopMoney);
                        cashMoney = cashMoney.add(list.getTransactionPrice().subtract(coopMoney));
                    }

                }
            }
        }
    }


    public Long getId(){
        return new SnowflakeUtil(new Random().nextInt(1023)).nextId();
    }

    public String getStaffKey(String phone){
        return staffKey + phone;
    }
}