yexianchao 1 неделя назад
Родитель
Сommit
46487eb2c9
47 измененных файлов с 818 добавлено и 105 удалено
  1. 5 0
      crm-custom/src/main/java/com/crm/custom/controller/CustomController.java
  2. 0 3
      crm-custom/src/main/java/com/crm/custom/controller/GoldenRewardQuestionController.java
  3. 4 0
      crm-custom/src/main/java/com/crm/custom/dao/repository/CustomInfoRepository.java
  4. 2 0
      crm-custom/src/main/java/com/crm/custom/dao/repository/GoldenCustomRewardRecordRepository.java
  5. 16 0
      crm-custom/src/main/java/com/crm/custom/dao/repository/GoldenRewardAmountConfigRepository.java
  6. 3 0
      crm-custom/src/main/java/com/crm/custom/service/CustomInfoService.java
  7. 1 0
      crm-custom/src/main/java/com/crm/custom/service/GoldenRewardQuestionService.java
  8. 87 46
      crm-custom/src/main/java/com/crm/custom/service/impl/CustomInfoServiceImpl.java
  9. 100 1
      crm-custom/src/main/java/com/crm/custom/service/impl/GoldenCustomBalanceRecordServiceImpl.java
  10. 3 7
      crm-custom/src/main/java/com/crm/custom/service/impl/GoldenGoodsServiceImpl.java
  11. 26 0
      crm-custom/src/main/java/com/crm/custom/service/impl/GoldenOrderServiceImpl.java
  12. 37 0
      crm-custom/src/main/java/com/crm/custom/service/impl/GoldenRewardQuestionServiceImpl.java
  13. 11 7
      crm-custom/src/main/resources/mapper/GoldenGoods.xml
  14. 7 0
      crm-manager/src/main/java/com/crm/manager/controller/CustomInfoController.java
  15. 54 0
      crm-manager/src/main/java/com/crm/manager/controller/GoldenRewardAmountConfigController.java
  16. 14 0
      crm-manager/src/main/java/com/crm/manager/dao/mapper/GoldenRewardAmountConfigMapper.java
  17. 2 0
      crm-manager/src/main/java/com/crm/manager/dao/repository/CustomInfoRepository.java
  18. 22 0
      crm-manager/src/main/java/com/crm/manager/dao/repository/GoldenRewardAmountConfigRepository.java
  19. 4 0
      crm-manager/src/main/java/com/crm/manager/service/CustomInfoService.java
  20. 24 0
      crm-manager/src/main/java/com/crm/manager/service/GoldenRewardAmountConfigService.java
  21. 24 0
      crm-manager/src/main/java/com/crm/manager/service/impl/CustomInfoServiceImpl.java
  22. 100 0
      crm-manager/src/main/java/com/crm/manager/service/impl/GoldenRewardAmountConfigServiceImpl.java
  23. 31 0
      crm-manager/src/main/resources/mapper/GoldenRewardAmountConfigMapper.xml
  24. 8 0
      crm-model/src/main/java/com/crm/rely/backend/model/constant/ConfigConstants.java
  25. 2 0
      crm-model/src/main/java/com/crm/rely/backend/model/constant/EmailTemplateConstants.java
  26. 8 0
      crm-model/src/main/java/com/crm/rely/backend/model/dto/custom/InfoDto.java
  27. 8 0
      crm-model/src/main/java/com/crm/rely/backend/model/dto/custom/potential/CustomListDto.java
  28. 2 0
      crm-model/src/main/java/com/crm/rely/backend/model/dto/golden/order/GoldenOrderDetailsDto.java
  29. 19 0
      crm-model/src/main/java/com/crm/rely/backend/model/dto/golden/reward/GoldenRewardAmountConfigListDto.java
  30. 15 8
      crm-model/src/main/java/com/crm/rely/backend/model/entity/custom/info/CustomInfoEntity.java
  31. 3 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/custom/info/CustomInfoRegisterEntity.java
  32. 5 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/custom/info/CustomInfoUpdateEntity.java
  33. 3 3
      crm-model/src/main/java/com/crm/rely/backend/model/entity/finance/deposit/FinanceDepositAddEntity.java
  34. 12 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/finance/deposit/GoldenOrderDetailsEntity.java
  35. 21 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigAddEntity.java
  36. 9 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigDeleteEntitys.java
  37. 11 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigSearchEntity.java
  38. 21 0
      crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigUpdateEntity.java
  39. 14 0
      crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/CustomInfoTable.java
  40. 2 0
      crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/GoldenCustomBalanceRecordTable.java
  41. 2 0
      crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/GoldenOrderDetailsTable.java
  42. 19 0
      crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/GoldenRewardAmountConfigTable.java
  43. 2 0
      crm-model/src/main/java/com/crm/rely/backend/model/pojo/view/CustomView.java
  44. 1 1
      crm-pay/src/main/java/com/crm/pay/controller/base/BasePayCloseFunctionController.java
  45. 2 0
      crm-pay/src/main/java/com/crm/pay/dao/repository/CustomInfoRepository.java
  46. 2 1
      crm-pay/src/main/java/com/crm/pay/entity/FinanceDepositParameterEntity.java
  47. 50 28
      crm-pay/src/main/java/com/crm/pay/service/impl/FinanceDepositServiceImpl.java

+ 5 - 0
crm-custom/src/main/java/com/crm/custom/controller/CustomController.java

@@ -382,4 +382,9 @@ public class CustomController extends BaseLoginController {
         return BaseResultDto.success(balance);
     }
 
+    @RequestMapping("/get/label")
+    public BaseResultDto getLevelLabel(CustomInfoEntity infoEntity) throws Exception {
+        return BaseResultDto.success(customInfoService.getLevelLabel(infoEntity.getId()));
+    }
+
 }

+ 0 - 3
crm-custom/src/main/java/com/crm/custom/controller/GoldenRewardQuestionController.java

@@ -8,7 +8,6 @@ import com.crm.rely.backend.core.entity.base.SingleLongEntity;
 import com.crm.rely.backend.model.dto.golden.question.GoldenRewardQuestionListDto;
 import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
 import com.crm.rely.backend.model.entity.golden.question.*;
-import com.crm.rely.backend.util.DateUtil;
 import lombok.extern.log4j.Log4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -19,8 +18,6 @@ import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
-import java.util.Date;
-
 @Log4j
 @RestController
 @RequestMapping("/reward/question")

+ 4 - 0
crm-custom/src/main/java/com/crm/custom/dao/repository/CustomInfoRepository.java

@@ -105,4 +105,8 @@ public interface CustomInfoRepository extends BaseRepository<CustomInfoTable> {
 
     boolean existsByIdentity(String identity);
     CustomInfoTable getFirstBySno(String sno);
+
+    CustomInfoTable getFirstByReferralCode(String referralCode);
+
+    Integer countByPId(Long pId);
 }

+ 2 - 0
crm-custom/src/main/java/com/crm/custom/dao/repository/GoldenCustomRewardRecordRepository.java

@@ -12,4 +12,6 @@ public interface GoldenCustomRewardRecordRepository extends BaseRepository<Golde
     List<GoldenCustomRewardRecordTable> findByStatus(Integer status);
 
     GoldenCustomRewardRecordTable findFirstByCustomId(Long customId);
+
+    GoldenCustomRewardRecordTable findFirstByCustomIdAndStatus(Long customId, Integer status);
 }

+ 16 - 0
crm-custom/src/main/java/com/crm/custom/dao/repository/GoldenRewardAmountConfigRepository.java

@@ -0,0 +1,16 @@
+package com.crm.custom.dao.repository;
+
+import com.crm.rely.backend.dao.repository.BaseRepository;
+import com.crm.rely.backend.model.pojo.table.GoldenRewardAmountConfigTable;
+import org.springframework.data.jpa.repository.Lock;
+import org.springframework.stereotype.Repository;
+
+import javax.persistence.LockModeType;
+import java.util.List;
+
+@Repository
+public interface GoldenRewardAmountConfigRepository extends BaseRepository<GoldenRewardAmountConfigTable> {
+
+    GoldenRewardAmountConfigTable getFirstByEmail(String email);
+
+}

+ 3 - 0
crm-custom/src/main/java/com/crm/custom/service/CustomInfoService.java

@@ -5,6 +5,7 @@ import com.crm.rely.backend.core.exception.ServiceException;
 import com.crm.rely.backend.model.entity.custom.info.*;
 import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
 import org.springframework.web.multipart.MultipartFile;
+import com.crm.rely.backend.model.dto.custom.potential.CustomListDto;
 
 import java.math.BigDecimal;
 
@@ -91,4 +92,6 @@ public interface CustomInfoService {
     Integer getPosition(Long customId) throws ServiceException;
 
     BigDecimal getBalance(Long id) throws ServiceException;
+
+    CustomListDto getLevelLabel(Long id);
 }

+ 1 - 0
crm-custom/src/main/java/com/crm/custom/service/GoldenRewardQuestionService.java

@@ -6,6 +6,7 @@ import com.crm.rely.backend.core.exception.ServiceException;
 import com.crm.rely.backend.model.dto.golden.question.GoldenRewardQuestionDto;
 import com.crm.rely.backend.model.dto.golden.question.GoldenRewardQuestionListDto;
 import com.crm.rely.backend.model.entity.golden.question.*;
+import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
 
 public interface GoldenRewardQuestionService {
 

+ 87 - 46
crm-custom/src/main/java/com/crm/custom/service/impl/CustomInfoServiceImpl.java

@@ -1,9 +1,11 @@
 package com.crm.custom.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.crm.custom.dao.mapper.CustomFileDao;
 import com.crm.custom.dao.mapper.CustomInfoDao;
 import com.crm.custom.dao.repository.CustomInfoRepository;
 import com.crm.custom.dao.repository.CustomLoginHistoryRepository;
+import com.crm.custom.dao.repository.GoldenCustomRewardRecordRepository;
 import com.crm.custom.dao.repository.UserInfoRepository;
 import com.crm.custom.service.*;
 import com.crm.custom.service.impl.base.BaseUploadServiceImpl;
@@ -18,11 +20,13 @@ import com.crm.rely.backend.core.pojo.table.SysConfigTable;
 import com.crm.rely.backend.core.pojo.table.SysCountryTable;
 import com.crm.rely.backend.model.constant.ConfigConstants;
 import com.crm.rely.backend.model.constant.CustomConstants;
-import com.crm.rely.backend.model.entity.custom.bank.CustomBankAddEntity;
+import com.crm.rely.backend.model.constant.EmailTemplateConstants;
+import com.crm.rely.backend.model.dto.custom.potential.CustomListDto;
 import com.crm.rely.backend.model.entity.custom.fund.history.CustomFundHistoryAddEntity;
 import com.crm.rely.backend.model.entity.custom.info.*;
 import com.crm.rely.backend.model.entity.user.info.UserInfoEntity;
 import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
+import com.crm.rely.backend.model.pojo.table.GoldenCustomRewardRecordTable;
 import com.crm.rely.backend.model.pojo.table.UserInfoTable;
 import com.crm.rely.backend.model.util.CustomInfoUtil;
 import com.crm.rely.backend.service.EmailService;
@@ -33,6 +37,7 @@ import com.google.common.base.Strings;
 import lombok.extern.log4j.Log4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
@@ -92,7 +97,8 @@ public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements Cust
 
     @Autowired
     private LocaleMessage localeMessage;
-
+    @Autowired
+    private GoldenCustomRewardRecordRepository goldenCustomRewardRecordRepository;
 
     /**
      * 用户登录
@@ -231,40 +237,26 @@ public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements Cust
     public void add(CustomInfoRegisterEntity entity) throws ServiceException, InterruptedException {
 
         //打印注册信息日志
-        String registerString = String.format("register email:%s,emailCode:%s,agentId:%d",entity.getEmail(),entity.getEmailCode(), entity.getAgentId());
+        String registerString = String.format("register email:%s,emailCode:%s,referralCode:%s",entity.getEmail(),entity.getEmailCode(), entity.getReferralCode());
         log.info(registerString);
 
         //emailService.validateCode(entity.getEmail(), entity.getEmailCode());
         //验证邮箱是否存在
         existByEmail(entity.getEmail());
 
-        /*if (entity.getAgentId() != null) {
-            UserInfoTable agent = userInfoRepository.getFirstById(entity.getAgentId());
-            //不存在代理设置为null 外佣设置为0
-            if (agent == null) {
-
-                log.error("get agent is null,agentId:" + entity.getAgentId());
-                entity.setAgentId(null);
-            } else {
-
-            }
-        }
-
-        //如果代理链接错误或者没有代理 则将客户挂在公司名下
-        if (entity.getAgentId() == null) {
-            SysConfigTable sysConfigTable = sysConfigService.getByCode(GlobalConfigConstants.COMPANY_ACCOUNT_SUPER);
-            if (sysConfigTable != null) {
-
-                Long agentId = Long.parseLong(sysConfigTable.getValue());
-                entity.setAgentId(agentId);
-            }
-        }*/
+        CustomInfoTable pCustom = customInfoRepository.getFirstByReferralCode(entity.getReferralCode());
+        entity.setReferralCode(null);
 
         //获取国家信息
         SysCountryTable sysCountryTable = sysCountryService.getByCode(entity.getCountry());
 
         CustomInfoTable customInfoTable = new CustomInfoTable();
         BeanUtils.copyProperties(entity, customInfoTable);
+
+        if (pCustom != null) {
+            customInfoTable.setPId(pCustom.getId());
+        }
+
         //设置国家信息
         customInfoTable.setCountryEnName(sysCountryTable.getEnName());
         customInfoTable.setCountryName(sysCountryTable.getName());
@@ -272,24 +264,14 @@ public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements Cust
         customInfoTable.setPayStatus(0);
         //获取和设置c_id
         customInfoTable.setCId(CidUtil.getCid().longValue());
+        customInfoTable.setLevelLabel(1);
         customInfoRepository.save(customInfoTable);
         customInfoTable.setAddUser(customInfoTable.getId());
-//
-//        //构建实体
-//        SysEmailSendEntity sysEmailSendEntity = createRegisterCompleteSysEmailEntity(customInfoTable);
-//
-//        //发送收据
-//        emailService.sendEmail(sysEmailSendEntity);
-//
-//        WebNoticeRecordAndEmailMqEntity mqEntity = new WebNoticeRecordAndEmailMqEntity(sysEmailSendEntity,
-//                customInfoTable.getCId(), customInfoTable.getId());
-//        mqSendService.send(Constants.WEB_NOTICE_PUT_RECORD, mqEntity);
-//
-//        //构建实体
-//        SysEmailSendEntity sysEmailSendEntityToManger = createRegisterCompleteToMangerSysEmailEntity(customInfoTable);
-//
-//        //发送收据
-//        emailService.sendEmail(sysEmailSendEntityToManger);
+
+        if (pCustom != null) {
+            mqSendService.send(ConfigConstants.CUSTOM_LEVEL_LABEL, pCustom);
+        }
+
     }
 
     /**
@@ -310,15 +292,10 @@ public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements Cust
         BeanUtils.copyProperties(entity, customInfoTable);
 
         //获取国家信息
-      /*  SysCountryTable sysCountryTable = sysCountryService.getByCode(entity.getCountry());
+        SysCountryTable sysCountryTable = sysCountryService.getByCode(entity.getCountry());
         //设置国家信息
         customInfoTable.setCountryEnName(sysCountryTable.getEnName());
         customInfoTable.setCountryName(sysCountryTable.getName());
-        if (entity.getAddressLines() != null) {
-            customInfoTable.setAddressLine(String.join("@#", entity.getAddressLines()));
-        } else {
-            customInfoTable.setAddressLine(null);
-        }*/
 
         customInfoRepository.save(customInfoTable);
 
@@ -798,6 +775,60 @@ public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements Cust
         return infoEntity;
     }
 
+    @JmsListener(destination = ConfigConstants.CUSTOM_LEVEL_LABEL)
+    @Transactional(rollbackFor = Exception.class)
+    public void updateCustomLevelLabel(String content) throws ServiceException {
+        log.info(String.format("CUSTOM_LEVEL_LABEL,content:", content));
+        CustomInfoTable customTable = JSON.parseObject(content, CustomInfoTable.class);
+        if (customTable == null) {
+            log.error("CUSTOM_LEVEL_LABEL,table is null");
+            return;
+        }
+
+        Integer count = customInfoRepository.countByPId(customTable.getId());
+        if (count == null || count < 5 ) {
+            log.info(String.format("CUSTOM_LEVEL_LABEL,referral num: %d",count));
+            return;
+        }
+
+        GoldenCustomRewardRecordTable recodeTable = goldenCustomRewardRecordRepository.findFirstByCustomIdAndStatus(customTable.getId(),2);
+        if (recodeTable == null) {
+            log.info("CUSTOM_LEVEL_LABEL,reward unfinished");
+            return;
+        }
+
+        sendCustomLevelLabelEmail(customTable);
+    }
+
+    private void sendCustomLevelLabelEmail(CustomInfoTable customTable) throws ServiceException {
+        //该客户已获得奖学金,成功推荐人数5人,请将其标签调整为“传誉师”。
+
+        SysConfigTable sysConfigTable = sysConfigService.getByCode(ConfigConstants.UPDATE_LEVEL_LABEL_EMAIL);
+
+        //构建map 用于后面邮件模版替换
+        Map<String, String> map = new HashMap<>(6);
+        map.put(MapConstants.DATE_TIME, DateUtil.formatTime(new Date()));
+
+        map.put(MapConstants.C_ID, String.valueOf(customTable.getCId()));
+        map.put(MapConstants.EMAIL, customTable.getEmail());
+        map.put(MapConstants.PHONE, customTable.getPhone());
+        map.put(MapConstants.NAME, customTable.getName());
+        map.put(ConfigConstants.REFERRAL_CODE, customTable.getName());
+
+        SysEmailSendEntity sysEmailSendEntity = new SysEmailSendEntity();
+        sysEmailSendEntity.setSubject("Update Label Notice");
+        sysEmailSendEntity.setEmailSendEnum(EmailSendEnum.UPDATE_LEVEL_LABEL);
+        sysEmailSendEntity.setMap(map);
+        sysEmailSendEntity.setTemplateName(EmailTemplateConstants.UPDATE_LEVEL_LABEL);
+
+        sysEmailSendEntity.setUsers(sysConfigTable.getValue());
+        try {
+            emailService.sendEmail(sysEmailSendEntity);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void deleteInBatch(LongEntitys entitys) throws Exception {
@@ -873,4 +904,14 @@ public class CustomInfoServiceImpl extends BaseUploadServiceImpl implements Cust
         return customInfoTable.getBalance() == null ? BigDecimal.ZERO : customInfoTable.getBalance();
     }
 
+    @Override
+    public CustomListDto getLevelLabel(Long id) {
+        CustomInfoTable customInfoTable = customInfoRepository.getFirstById(id);
+
+        CustomListDto dto = new CustomListDto();
+        dto.setLevelLabel(customInfoTable.getLevelLabel());
+        dto.setReferralCode(customInfoTable.getReferralCode());
+        return dto;
+    }
+
 }

+ 100 - 1
crm-custom/src/main/java/com/crm/custom/service/impl/GoldenCustomBalanceRecordServiceImpl.java

@@ -1,22 +1,39 @@
 package com.crm.custom.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.crm.custom.dao.mapper.GoldenCustomBalanceRecordMapper;
+import com.crm.custom.dao.repository.CustomInfoRepository;
 import com.crm.custom.dao.repository.GoldenCustomBalanceRecordRepository;
+import com.crm.custom.dao.repository.GoldenRewardAmountConfigRepository;
 import com.crm.custom.service.GoldenCustomBalanceRecordService;
+import com.crm.custom.service.SysConfigService;
 import com.crm.rely.backend.core.constant.Constants;
 import com.crm.rely.backend.core.dto.base.PageDto;
 import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
 import com.crm.rely.backend.core.exception.ServiceException;
+import com.crm.rely.backend.core.pojo.table.SysConfigTable;
+import com.crm.rely.backend.model.constant.ConfigConstants;
 import com.crm.rely.backend.model.dto.golden.goods.GoldenCustomBalanceRecordListDto;
 import com.crm.rely.backend.model.entity.golden.order.GoldenBalanceSearchEntity;
+import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
+import com.crm.rely.backend.model.pojo.table.FinanceDepositTable;
 import com.crm.rely.backend.model.pojo.table.GoldenCustomBalanceRecordTable;
+import com.crm.rely.backend.model.pojo.table.GoldenRewardAmountConfigTable;
+import com.google.common.base.Strings;
+import lombok.extern.log4j.Log4j;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jms.annotation.JmsListener;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 
+@Log4j
 @Service
 public class GoldenCustomBalanceRecordServiceImpl implements GoldenCustomBalanceRecordService {
 
@@ -24,7 +41,14 @@ public class GoldenCustomBalanceRecordServiceImpl implements GoldenCustomBalance
     private GoldenCustomBalanceRecordRepository repository;
     @Autowired
     private GoldenCustomBalanceRecordMapper mapper;
-
+    @Autowired
+    private CustomInfoRepository customInfoRepository;
+    @Autowired
+    private SysConfigService sysConfigService;
+    @Autowired
+    private GoldenCustomBalanceRecordRepository customBalanceRecordRepository;
+    @Autowired
+    private GoldenRewardAmountConfigRepository goldenRewardAmountConfigRepository;
    
     @Override
     public ResultWithPagerDto<GoldenCustomBalanceRecordListDto> searchPageList(GoldenBalanceSearchEntity entity) throws ServiceException {
@@ -54,4 +78,79 @@ public class GoldenCustomBalanceRecordServiceImpl implements GoldenCustomBalance
     }
 
 
+    @JmsListener(destination = ConfigConstants.CUSTOM_TRAINEE_REWARD_RECORD)
+    @Transactional(rollbackFor = Exception.class)
+    public void updateCustomLevelLabel(String content) throws ServiceException {
+        log.info(String.format("CUSTOM_TRAINEE_REWARD_RECORD,content:", content));
+        FinanceDepositTable table= JSON.parseObject(content, FinanceDepositTable.class);
+        if (table == null) {
+            log.error("CUSTOM_LEVEL_LABEL,table is null");
+            return;
+        }
+
+        CustomInfoTable custom = customInfoRepository.findFirstById(table.getCustomId());
+        if (custom == null) {
+            log.error("CUSTOM_TRAINEE_REWARD_RECORD,custom is null");
+            return;
+        }
+
+        CustomInfoTable pCustom = customInfoRepository.findFirstById(custom.getPId());
+        if (pCustom == null) {
+            log.error("CUSTOM_TRAINEE_REWARD_RECORD,pCustom is null");
+            return;
+        }
+
+        if(pCustom.getLevelLabel() < 5){
+            log.info(String.format("CUSTOM_TRAINEE_REWARD_RECORD,pCustom levelLabel: %d", pCustom.getLevelLabel()));
+            return;
+        }
+
+        BigDecimal rewardAmountLimit = custom.getRewardAmountLimit() == null ? BigDecimal.ZERO : custom.getRewardAmountLimit();
+        rewardAmountLimit = rewardAmountLimit.add(table.getAmount());
+
+        Integer num = rewardAmountLimit.divide(new BigDecimal(5000), 0, RoundingMode.DOWN).intValue()
+                - ( custom.getPRewardNum() == null ? 0 : custom.getPRewardNum() );
+
+        if(num > 0){
+            BigDecimal giveAmount = null;
+            Integer count = customInfoRepository.countByPId(pCustom.getId());
+
+            if (count < 10){
+                SysConfigTable sysConfigTable = sysConfigService.getByCode(ConfigConstants.CUSTOM_TRAINEE_REWARD_AMOUNT);
+                giveAmount = (sysConfigTable == null || sysConfigTable.getValue() == null)
+                        ? BigDecimal.ZERO : new BigDecimal(sysConfigTable.getValue());
+
+            }else{
+                GoldenRewardAmountConfigTable rewardCconfig = goldenRewardAmountConfigRepository.getFirstByEmail(pCustom.getEmail());
+                if(rewardCconfig != null && rewardCconfig.getAmount() != null){
+                    giveAmount = rewardCconfig.getAmount();
+                }else {
+                    SysConfigTable sysConfigTable = sysConfigService.getByCode(ConfigConstants.CUSTOM_TRAINEE_ADVANCED_REWARD_AMOUNT);
+                    giveAmount = (sysConfigTable == null || sysConfigTable.getValue() == null)
+                            ? BigDecimal.ZERO : new BigDecimal(sysConfigTable.getValue());
+                }
+            }
+
+            BigDecimal balance = pCustom.getBalance() == null ? BigDecimal.ZERO : pCustom.getBalance();
+            pCustom.setBalance(balance.add(giveAmount.multiply(new BigDecimal(num))));
+            customInfoRepository.save(pCustom);
+
+            custom.setRewardAmountLimit(rewardAmountLimit.add(table.getAmount()));
+            custom.setPRewardNum(custom.getPRewardNum() == null ? num : custom.getPRewardNum()+num);
+            customInfoRepository.save(custom);
+
+            for (int i = 0; i < num; i++) {
+                GoldenCustomBalanceRecordTable record = new GoldenCustomBalanceRecordTable();
+                record.setCustomId(pCustom.getId());
+                record.setCId(pCustom.getCId());
+                record.setAmount(giveAmount);
+                record.setType(2);
+                record.setAddTime(new Date());
+                record.setComment("名下学员消费满额赠金:"+custom.getId());
+                customBalanceRecordRepository.save(record);
+            }
+        }
+
+    }
+
 }

+ 3 - 7
crm-custom/src/main/java/com/crm/custom/service/impl/GoldenGoodsServiceImpl.java

@@ -44,14 +44,14 @@ public class GoldenGoodsServiceImpl extends BaseUploadServiceImpl implements Gol
             throw new ServiceException(Constants.SYSTEM_ERROR);
         }
 
-        Map<Long,GoldenGoodsTable> map = new HashMap<>();
+        /*Map<Long,GoldenGoodsTable> map = new HashMap<>();
         if (entity.getCustomId() > 0){
             List<Long> goodsIds = new ArrayList<>();
             for (GoldenGoodsTable table : tables) {
                 goodsIds.add(table.getId());
             }
             map = getCustomOrderGoods(goodsIds,entity.getCustomId());
-        }
+        }*/
 
         List<GoldenGoodsListDto> dtos = new ArrayList<>(tables.size());
         for (GoldenGoodsTable table : tables) {
@@ -60,11 +60,7 @@ public class GoldenGoodsServiceImpl extends BaseUploadServiceImpl implements Gol
             if (entity.getCustomId() < 0) {
                 dto.setCustomType(0);
             }else{
-                if(map.containsKey(table.getId())){
-                    dto.setCustomType(2);
-                }else{
-                    dto.setCustomType(1);
-                }
+                dto.setCustomType(1);
             }
             dtos.add(dto);
         }

+ 26 - 0
crm-custom/src/main/java/com/crm/custom/service/impl/GoldenOrderServiceImpl.java

@@ -23,12 +23,14 @@ import com.crm.rely.backend.service.EmailService;
 import com.crm.rely.backend.service.MqSendService;
 import com.crm.rely.backend.util.DateUtil;
 import com.crm.rely.backend.util.GetRandom;
+import com.google.common.base.Strings;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 
 @Service
@@ -123,6 +125,16 @@ public class GoldenOrderServiceImpl implements GoldenOrderService {
         depositTable.setModifyTime(new Date());
         financeDepositRepository.save(depositTable);
 
+        if(customTable.getLevelLabel() == 1){
+            customTable.setLevelLabel(2);//当用户完成购课动作后自动更新。
+        }
+        if(customTable.getLevelLabel() == 3){
+            customTable.setLevelLabel(4);//当“学成”状态的用户产生复购行为时自动更新
+        }
+        if(customTable.getLevelLabel() >=3 && Strings.isNullOrEmpty(customTable.getReferralCode())){
+            customTable.setReferralCode(getCode());
+        }
+
         BigDecimal totalSpendingAmount = customTable.getTotalSpendingAmount() == null ? BigDecimal.ZERO : customTable.getTotalSpendingAmount();
         customTable.setTotalSpendingAmount(totalSpendingAmount.add(table.getAmount()));
         customInfoRepository.save(customTable);
@@ -136,6 +148,9 @@ public class GoldenOrderServiceImpl implements GoldenOrderService {
             mqSendService.send(ConfigConstants.CUSTOM_REWARD_RECORD, customTable.getId());
         }
 
+        //传誉名下学员消费满额赠金
+        mqSendService.send(ConfigConstants.CUSTOM_TRAINEE_REWARD_RECORD, depositTable);
+
     }
 
     @Override
@@ -193,6 +208,7 @@ public class GoldenOrderServiceImpl implements GoldenOrderService {
         detailsTable.setGoodsId(goodsTable.getId());
         detailsTable.setSerial(orderNo);
         detailsTable.setCustomId(infoEntity.getId());
+        detailsTable.setGoodsNum(1);
         goldenOrderDetailsRepository.save(detailsTable);
 
         sendCustomGoldenOrderEmail(infoEntity.getName(), detailsTable.getDownload(), infoEntity.getEmail());
@@ -229,4 +245,14 @@ public class GoldenOrderServiceImpl implements GoldenOrderService {
         }
     }
 
+    public String getCode() {
+        String value = GetRandom.getCaseRandom(8);
+        CustomInfoTable table = customInfoRepository.getFirstByReferralCode(value);
+        if (table == null) {
+            return value;
+        } else {
+            return getCode();
+        }
+    }
+
 }

+ 37 - 0
crm-custom/src/main/java/com/crm/custom/service/impl/GoldenRewardQuestionServiceImpl.java

@@ -16,7 +16,9 @@ import com.crm.rely.backend.model.dto.golden.question.GoldenRewardQuestionDto;
 import com.crm.rely.backend.model.dto.golden.question.GoldenRewardQuestionListDto;
 import com.crm.rely.backend.model.entity.golden.question.*;
 import com.crm.rely.backend.model.pojo.table.*;
+import com.crm.rely.backend.service.MqSendService;
 import com.crm.rely.backend.util.DateUtil;
+import com.crm.rely.backend.util.GetRandom;
 import com.google.common.base.Strings;
 import lombok.extern.log4j.Log4j;
 import org.springframework.beans.BeanUtils;
@@ -50,6 +52,8 @@ public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionServ
     private GoldenCustomBalanceRecordRepository customBalanceRecordRepository;
     @Autowired
     private SysConfigService sysConfigService;
+    @Autowired
+    private MqSendService mqSendService;
 
     @Override
     public GoldenRewardQuestionDto getQuestion(Long customId) throws Exception {
@@ -75,7 +79,13 @@ public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionServ
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public void customAddQuestion(GoldenQuestionCustomAddEntity entity) throws Exception {
+        CustomInfoTable custom = customInfoRepository.findFirstById(entity.getCustomId());
+        if (custom == null) {
+            throw ServiceException.exception(Constants.INFO_NOT_FOUND);
+        }
+
         Date startDate = DateUtil.getThisWeekMonday(new Date());
         Date endDate = DateUtil.addDate(startDate,7);
         Integer count = goldenQuestionCustomMapper.getCountQuestionByDate(entity.getCustomId(),startDate,endDate);
@@ -94,6 +104,15 @@ public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionServ
         table.setAnswer(questionTable.getAnswer());
         table.setCustomRight(questionTable.getAnswer() == table.getCustomAnswer() ? 1 : 0 );
         goldenQuestionCustomRepository.save(table);
+
+        if(custom.getLevelLabel() == 2){
+            if(Strings.isNullOrEmpty(custom.getReferralCode())){
+                custom.setReferralCode(getCode());//推荐码
+            }
+            custom.setLevelLabel(3);
+            customInfoRepository.save(custom);
+        }
+
     }
 
     @Override
@@ -162,6 +181,11 @@ public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionServ
         return dto;
     }
 
+    public static void main(String[] args) throws Exception {
+        Date endDate = DateUtil.addDate(new Date(),-180);
+        System.out.println(DateUtil.formatDate(endDate));
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void rewardQuestionTask() throws Exception {
@@ -193,8 +217,11 @@ public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionServ
                     record.setAmount(giveAmount);
                     record.setType(2);
                     record.setAddTime(new Date());
+                    record.setComment("有奖问答赠金");
                     customBalanceRecordRepository.save(record);
 
+                    mqSendService.send(ConfigConstants.CUSTOM_LEVEL_LABEL, custom);
+
                 }else{
                     table.setStatus(3);
                 }
@@ -229,4 +256,14 @@ public class GoldenRewardQuestionServiceImpl implements GoldenRewardQuestionServ
 
     }
 
+    public String getCode() {
+        String value = GetRandom.getCaseRandom(8);
+        CustomInfoTable table = customInfoRepository.getFirstByReferralCode(value);
+        if (table == null) {
+            return value;
+        } else {
+            return getCode();
+        }
+    }
+
 }

+ 11 - 7
crm-custom/src/main/resources/mapper/GoldenGoods.xml

@@ -6,13 +6,16 @@
 
     <select id="customOrderCount" resultType="integer"
             parameterType="com.crm.rely.backend.model.entity.golden.goods.GoldenGoodsSearchEntity">
-        select count(*) from golden_goods goods
-        left join golden_order_details der on goods.id = der.goods_id
-        left join golden_order gor on der.serial = gor.serial
-        where gor.status = 2 and der.custom_id = #{customId}
-        <if test="goodsType!=null">
-            and goods.`goods_type` = #{goodsType}
-        </if>
+        select count(*) from (
+            select goods.* from golden_goods goods
+            left join golden_order_details der on goods.id = der.goods_id
+            left join golden_order gor on der.serial = gor.serial
+            where gor.status = 2 and der.custom_id = #{customId}
+            <if test="goodsType!=null">
+                and goods.`goods_type` = #{goodsType}
+            </if>
+            group by goods.id
+        ) goods
     </select>
 
     <select id="customOrderList" resultType="com.crm.rely.backend.model.pojo.table.GoldenGoodsTable"
@@ -31,6 +34,7 @@
                 #{item}
             </foreach>
         </if>
+        group by goods.id
         order by der.id desc
         <if test="page != null">
             limit #{page.offset},#{page.row}

+ 7 - 0
crm-manager/src/main/java/com/crm/manager/controller/CustomInfoController.java

@@ -225,6 +225,13 @@ public class CustomInfoController {
         return customInfoService.getPageList(entity);
     }
 
+    @RequestMapping("/update/label")
+    public BaseResultDto updateLevelLabel(@RequestBody @Validated CustomInfoUpdateEntity entity) throws Exception {
+        customInfoService.updateLevelLabel(entity);
+        return BaseResultDto.success();
+    }
+
+
     private void validSortName(String sortName) {
         if (!Strings.isNullOrEmpty(sortName)) {
             List<String> tableFields = new ArrayList<>(10);

+ 54 - 0
crm-manager/src/main/java/com/crm/manager/controller/GoldenRewardAmountConfigController.java

@@ -0,0 +1,54 @@
+package com.crm.manager.controller;
+
+import com.crm.manager.service.GoldenRewardAmountConfigService;
+import com.crm.rely.backend.core.dto.base.BaseResultDto;
+import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
+import com.crm.rely.backend.core.entity.base.SingleLongEntity;
+import com.crm.rely.backend.model.dto.golden.reward.GoldenRewardAmountConfigListDto;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigAddEntity;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigDeleteEntitys;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigSearchEntity;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigUpdateEntity;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/reward/amount")
+public class GoldenRewardAmountConfigController {
+
+    @Autowired
+    private GoldenRewardAmountConfigService goldenRewardAmountConfigService;
+
+    @PostMapping("/add")
+    public BaseResultDto add(@RequestBody @Validated GoldenRewardAmountConfigAddEntity entity) throws Exception {
+        goldenRewardAmountConfigService.add(entity);
+        return BaseResultDto.success();
+    }
+
+    @PostMapping("/delete")
+    public BaseResultDto delete(@RequestBody @Validated GoldenRewardAmountConfigDeleteEntitys entitys) throws Exception {
+        goldenRewardAmountConfigService.delete(entitys);
+        return BaseResultDto.success();
+    }
+
+    @PostMapping("/update")
+    public BaseResultDto update(@RequestBody @Validated GoldenRewardAmountConfigUpdateEntity entity) throws Exception {
+        goldenRewardAmountConfigService.update(entity);
+        return BaseResultDto.success();
+    }
+
+    @PostMapping("/search/list")
+    public ResultWithPagerDto<GoldenRewardAmountConfigListDto> pageList(@RequestBody GoldenRewardAmountConfigSearchEntity entity) throws Exception {
+        return goldenRewardAmountConfigService.searchPageList(entity);
+    }
+
+    @PostMapping("/search/single")
+    public BaseResultDto searchSingle(@RequestBody @Validated SingleLongEntity entity) throws Exception {
+        return BaseResultDto.success(goldenRewardAmountConfigService.searchSingle(entity));
+    }
+
+}

+ 14 - 0
crm-manager/src/main/java/com/crm/manager/dao/mapper/GoldenRewardAmountConfigMapper.java

@@ -0,0 +1,14 @@
+package com.crm.manager.dao.mapper;
+
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigSearchEntity;
+import com.crm.rely.backend.model.pojo.table.GoldenRewardAmountConfigTable;
+
+import java.util.List;
+
+public interface GoldenRewardAmountConfigMapper {
+
+    Integer countList(GoldenRewardAmountConfigSearchEntity entity);
+
+    List<GoldenRewardAmountConfigTable> pageList(GoldenRewardAmountConfigSearchEntity entity);
+
+}

+ 2 - 0
crm-manager/src/main/java/com/crm/manager/dao/repository/CustomInfoRepository.java

@@ -30,4 +30,6 @@ public interface CustomInfoRepository extends BaseRepository<CustomInfoTable> {
     CustomInfoTable getFirstByEmail(String email);
 
     boolean existsByIdentity(String identity);
+
+    CustomInfoTable getFirstByReferralCode(String referralCode);
 }

+ 22 - 0
crm-manager/src/main/java/com/crm/manager/dao/repository/GoldenRewardAmountConfigRepository.java

@@ -0,0 +1,22 @@
+package com.crm.manager.dao.repository;
+
+import com.crm.rely.backend.dao.repository.BaseRepository;
+import com.crm.rely.backend.model.pojo.table.GoldenRewardAmountConfigTable;
+import org.springframework.data.jpa.repository.Lock;
+import org.springframework.stereotype.Repository;
+
+import javax.persistence.LockModeType;
+import java.util.List;
+
+@Repository
+public interface GoldenRewardAmountConfigRepository extends BaseRepository<GoldenRewardAmountConfigTable> {
+
+    @Lock(LockModeType.PESSIMISTIC_WRITE)
+    GoldenRewardAmountConfigTable findFirstById(Long id);
+
+    List<GoldenRewardAmountConfigTable> findAllByIdIn(List<Long> ids);
+
+    GoldenRewardAmountConfigTable getFirstById(Long id);
+
+
+}

+ 4 - 0
crm-manager/src/main/java/com/crm/manager/service/CustomInfoService.java

@@ -5,6 +5,7 @@ import com.crm.rely.backend.core.exception.ServiceException;
 import com.crm.rely.backend.model.dto.custom.CustomInfoDto;
 import com.crm.rely.backend.model.dto.custom.potential.CustomListDto;
 import com.crm.rely.backend.model.entity.custom.info.CustomApproveEntity;
+import com.crm.rely.backend.model.entity.custom.info.CustomInfoUpdateEntity;
 import com.crm.rely.backend.model.entity.custom.info.CustomSearchEntity;
 import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
 
@@ -33,4 +34,7 @@ public interface CustomInfoService {
     void batchDeleteByIdList(List<Long> ids) throws Exception;
 //
 //    void updatePassword(CustomUpdatePasswordByManagerEntity entity) throws ServiceException;
+
+    void updateLevelLabel(CustomInfoUpdateEntity entity);
+
 }

+ 24 - 0
crm-manager/src/main/java/com/crm/manager/service/GoldenRewardAmountConfigService.java

@@ -0,0 +1,24 @@
+package com.crm.manager.service;
+
+import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
+import com.crm.rely.backend.core.entity.base.SingleLongEntity;
+import com.crm.rely.backend.core.exception.ServiceException;
+import com.crm.rely.backend.model.dto.golden.reward.GoldenRewardAmountConfigListDto;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigAddEntity;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigDeleteEntitys;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigSearchEntity;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigUpdateEntity;
+
+public interface GoldenRewardAmountConfigService {
+
+    void add(GoldenRewardAmountConfigAddEntity entity) throws ServiceException;
+
+    void delete(GoldenRewardAmountConfigDeleteEntitys entitys) throws ServiceException;
+
+    void update(GoldenRewardAmountConfigUpdateEntity entity) throws ServiceException;
+
+    ResultWithPagerDto<GoldenRewardAmountConfigListDto> searchPageList(GoldenRewardAmountConfigSearchEntity entity) throws ServiceException;
+
+    GoldenRewardAmountConfigListDto searchSingle(SingleLongEntity entity) throws ServiceException;
+    
+}

+ 24 - 0
crm-manager/src/main/java/com/crm/manager/service/impl/CustomInfoServiceImpl.java

@@ -21,6 +21,7 @@ import com.crm.rely.backend.model.dto.custom.CustomInfoDto;
 import com.crm.rely.backend.model.dto.custom.potential.CustomListDto;
 import com.crm.rely.backend.model.entity.custom.info.CustomApproveEntity;
 import com.crm.rely.backend.model.entity.custom.info.CustomInfoEntity;
+import com.crm.rely.backend.model.entity.custom.info.CustomInfoUpdateEntity;
 import com.crm.rely.backend.model.entity.custom.info.CustomSearchEntity;
 import com.crm.rely.backend.model.pojo.table.CustomBankTable;
 import com.crm.rely.backend.model.pojo.table.CustomInfoTable;
@@ -32,6 +33,7 @@ import com.crm.rely.backend.service.MqSendService;
 import com.crm.rely.backend.service.RedisService;
 import com.crm.rely.backend.util.DateUtil;
 import com.crm.rely.backend.util.FormatPage;
+import com.crm.rely.backend.util.GetRandom;
 import com.crm.rely.backend.util.RexUtil;
 import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
@@ -486,4 +488,26 @@ public class CustomInfoServiceImpl implements CustomInfoService {
 //
 //    }
 
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void updateLevelLabel(CustomInfoUpdateEntity entity) {
+        CustomInfoTable customInfoTable = customInfoRepository.findFirstById(entity.getId());
+        customInfoTable.setLevelLabel(entity.getLevelLabel());
+        if(customInfoTable.getLevelLabel() >=3 && Strings.isNullOrEmpty(customInfoTable.getReferralCode())){
+            customInfoTable.setReferralCode(getCode());//推荐码
+        }
+
+        customInfoRepository.save(customInfoTable);
+    }
+
+    public String getCode() {
+        String value = GetRandom.getCaseRandom(8);
+        CustomInfoTable table = customInfoRepository.getFirstByReferralCode(value);
+        if (table == null) {
+            return value;
+        } else {
+            return getCode();
+        }
+    }
+
 }

+ 100 - 0
crm-manager/src/main/java/com/crm/manager/service/impl/GoldenRewardAmountConfigServiceImpl.java

@@ -0,0 +1,100 @@
+package com.crm.manager.service.impl;
+
+import com.crm.manager.dao.mapper.GoldenRewardAmountConfigMapper;
+import com.crm.manager.dao.repository.GoldenRewardAmountConfigRepository;
+import com.crm.manager.service.GoldenRewardAmountConfigService;
+import com.crm.rely.backend.core.constant.Constants;
+import com.crm.rely.backend.core.dto.base.PageDto;
+import com.crm.rely.backend.core.dto.base.ResultWithPagerDto;
+import com.crm.rely.backend.core.entity.base.SingleLongEntity;
+import com.crm.rely.backend.core.exception.ServiceException;
+import com.crm.rely.backend.model.dto.golden.reward.GoldenRewardAmountConfigListDto;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigAddEntity;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigDeleteEntitys;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigSearchEntity;
+import com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigUpdateEntity;
+import com.crm.rely.backend.model.pojo.table.GoldenRewardAmountConfigTable;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class GoldenRewardAmountConfigServiceImpl implements GoldenRewardAmountConfigService {
+
+    @Autowired
+    private GoldenRewardAmountConfigRepository repository;
+    @Autowired
+    private GoldenRewardAmountConfigMapper mapper;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void add(GoldenRewardAmountConfigAddEntity entity) throws ServiceException {
+        GoldenRewardAmountConfigTable table = new GoldenRewardAmountConfigTable();
+        BeanUtils.copyProperties(entity, table);
+        repository.save(table);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void delete(GoldenRewardAmountConfigDeleteEntitys entity) throws ServiceException {
+        List<GoldenRewardAmountConfigTable> tables = repository.findAllByIdIn(entity.getIds());
+        if (tables == null) {
+            throw ServiceException.exception(Constants.INFO_NOT_FOUND);
+        }
+        repository.delete(tables);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void update(GoldenRewardAmountConfigUpdateEntity entity) throws ServiceException {
+        GoldenRewardAmountConfigTable table = repository.findFirstById(entity.getId());
+        if (table == null) {
+            throw ServiceException.exception(Constants.INFO_NOT_FOUND);
+        }
+        BeanUtils.copyProperties(entity, table);
+        repository.save(table);
+    }
+
+    @Override
+    public ResultWithPagerDto<GoldenRewardAmountConfigListDto> searchPageList(GoldenRewardAmountConfigSearchEntity entity) throws ServiceException {
+        Integer count = mapper.countList(entity);
+        PageDto pageDto = PageDto.format(entity, count);
+        if (count == null || count <= 0) {
+            return ResultWithPagerDto.success(pageDto);
+        }
+        List<GoldenRewardAmountConfigTable> tables = mapper.pageList(entity);
+        if (tables == null || tables.size() <= 0) {
+            throw new ServiceException(Constants.SYSTEM_ERROR);
+        }
+        List<GoldenRewardAmountConfigListDto> dtos = new ArrayList<>(tables.size());
+
+        for (GoldenRewardAmountConfigTable table : tables) {
+            GoldenRewardAmountConfigListDto dto = transformSearchListDto(table);
+            dtos.add(dto);
+        }
+
+        return ResultWithPagerDto.success(pageDto, dtos);
+    }
+
+    @Override
+    public GoldenRewardAmountConfigListDto searchSingle(SingleLongEntity entity) throws ServiceException {
+        GoldenRewardAmountConfigTable table = repository.getFirstById(entity.getId());
+        if (table == null) {
+            throw ServiceException.exception(Constants.INFO_NOT_FOUND);
+        }
+
+        return transformSearchListDto(table);
+    }
+
+    private GoldenRewardAmountConfigListDto transformSearchListDto(GoldenRewardAmountConfigTable table) {
+        GoldenRewardAmountConfigListDto dto = new GoldenRewardAmountConfigListDto();
+        BeanUtils.copyProperties(table, dto);
+        return dto;
+    }
+
+
+}

+ 31 - 0
crm-manager/src/main/resources/mapper/GoldenRewardAmountConfigMapper.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.crm.manager.dao.mapper.GoldenRewardAmountConfigMapper">
+
+    <select id="countList" resultType="integer"
+            parameterType="com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigSearchEntity">
+        select count(*) from golden_reward_amount_config
+        <where>
+            <if test="email!=null and email!=''">
+                and email like concat('%',#{email},'%')
+            </if>
+        </where>
+    </select>
+
+    <select id="pageList" resultType="com.crm.rely.backend.model.pojo.table.GoldenRewardAmountConfigTable"
+            parameterType="com.crm.rely.backend.model.entity.golden.reward.GoldenRewardAmountConfigSearchEntity">
+        select * from golden_reward_amount_config
+        <where>
+            <if test="email!=null and email!=''">
+                and email like concat('%',#{email},'%')
+            </if>
+        </where>
+        order by id desc
+        <if test="page != null">
+            limit #{page.offset},#{page.row}
+        </if>
+    </select>
+
+</mapper>

+ 8 - 0
crm-model/src/main/java/com/crm/rely/backend/model/constant/ConfigConstants.java

@@ -53,5 +53,13 @@ public class ConfigConstants {
     public static final String CUSTOM_REWARD_QUESTION_AMOUNT = "CUSTOM_REWARD_QUESTION_AMOUNT";
 
     public static final String DOWNLOAD_URL = "V_DOWNLOAD_URL_V";
+    public static final String REFERRAL_CODE = "V_REFERRAL_CODE_V";
+
+    public static final String CUSTOM_LEVEL_LABEL = "CUSTOM_LEVEL_LABEL";
+    public static final String UPDATE_LEVEL_LABEL_EMAIL = "UPDATE_LEVEL_LABEL_EMAIL";
+
+    public static final String CUSTOM_TRAINEE_REWARD_RECORD = "CUSTOM_TRAINEE_REWARD_RECORD";
+    public static final String CUSTOM_TRAINEE_REWARD_AMOUNT = "CUSTOM_TRAINEE_REWARD_AMOUNT";
+    public static final String CUSTOM_TRAINEE_ADVANCED_REWARD_AMOUNT = "CUSTOM_TRAINEE_ADVANCED_REWARD_AMOUNT";
 
 }

+ 2 - 0
crm-model/src/main/java/com/crm/rely/backend/model/constant/EmailTemplateConstants.java

@@ -33,4 +33,6 @@ public class EmailTemplateConstants {
     public final static String CUSTOM_ORDER_SUCCESS_CN = "CUSTOM_ORDER_SUCCESS_CN";
     public final static String CUSTOM_ORDER_SUCCESS_EN = "CUSTOM_ORDER_SUCCESS_EN";
 
+    public final static String UPDATE_LEVEL_LABEL = "UPDATE_LEVEL_LABEL";
+
 }

+ 8 - 0
crm-model/src/main/java/com/crm/rely/backend/model/dto/custom/InfoDto.java

@@ -143,4 +143,12 @@ public class InfoDto extends InfoEntity {
     private Integer payStatus;
 
     private String sno;
+
+    /**
+     * 1:初探 2:研习 3:学成 4:深耕 5:传誉
+     */
+    private Integer levelLabel;
+
+    private String referralCode;
+
 }

+ 8 - 0
crm-model/src/main/java/com/crm/rely/backend/model/dto/custom/potential/CustomListDto.java

@@ -30,4 +30,12 @@ public class CustomListDto {
     private String identity;
 
     private BigDecimal totalSpendingAmount;
+
+    /**
+     * 1:初探 2:研习 3:学成 4:深耕 5:传誉
+     */
+    private Integer levelLabel;
+
+    private String referralCode;
+
 }

+ 2 - 0
crm-model/src/main/java/com/crm/rely/backend/model/dto/golden/order/GoldenOrderDetailsDto.java

@@ -23,6 +23,8 @@ public class GoldenOrderDetailsDto {
 
     private BigDecimal goodsPrice;
 
+    private Integer goodsNum;
+
     /**
      * 封面
      */

+ 19 - 0
crm-model/src/main/java/com/crm/rely/backend/model/dto/golden/reward/GoldenRewardAmountConfigListDto.java

@@ -0,0 +1,19 @@
+package com.crm.rely.backend.model.dto.golden.reward;
+
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+
+@Data
+public class GoldenRewardAmountConfigListDto {
+
+    private Long id;
+
+    private String email;
+
+    private BigDecimal amount;
+
+    private Date addTime;
+
+}

+ 15 - 8
crm-model/src/main/java/com/crm/rely/backend/model/entity/custom/info/CustomInfoEntity.java

@@ -61,7 +61,7 @@ public class CustomInfoEntity extends BaseCustomInfoEntity {
     /**
      * 出生日期
      */
-    private Date birth;
+    //private Date birth;
 
     /**
      * 身份证件号 身份证 护照等
@@ -83,7 +83,7 @@ public class CustomInfoEntity extends BaseCustomInfoEntity {
      */
     private String countryEnName;
 
-    private String state;
+    //private String state;
 
     private String city;
 
@@ -92,9 +92,9 @@ public class CustomInfoEntity extends BaseCustomInfoEntity {
     /**
      * 详细地址
      */
-    private String addressLine;
+    /*private String addressLine;
 
-    private String taxNumber;
+    private String taxNumber;*/
 
 
     /**
@@ -107,7 +107,7 @@ public class CustomInfoEntity extends BaseCustomInfoEntity {
 
     private String lastIp;
 
-    private String lastAddress;
+    //private String lastAddress;
     /**
      * 代理ID
      */
@@ -125,7 +125,7 @@ public class CustomInfoEntity extends BaseCustomInfoEntity {
 
     private List<CustomFileDto> files;
 
-    private String bankUname;
+    /*private String bankUname;
 
     private String bankCardNum;
 
@@ -141,11 +141,18 @@ public class CustomInfoEntity extends BaseCustomInfoEntity {
 
     private String bankFront;
 
-    private String bankBack;
+    private String bankBack;*/
 
     private Long ibId;
 
     private Integer payStatus;
 
-    private String sno;
+    //private String sno;
+
+    /**
+     * 1:初探 2:研习 3:学成 4:深耕 5:传誉
+     */
+    private Integer levelLabel;
+
+    private String referralCode;
 }

+ 3 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/custom/info/CustomInfoRegisterEntity.java

@@ -63,4 +63,7 @@ public class CustomInfoRegisterEntity extends BaseAddEntity {
 
 
     private String sno;
+
+    private String referralCode;
+
 }

+ 5 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/custom/info/CustomInfoUpdateEntity.java

@@ -118,4 +118,9 @@ public class CustomInfoUpdateEntity {
 
     private String sno;
 
+    /**
+     * 1:初探 2:研习 3:学成 4:深耕 5:传誉
+     */
+    private Integer levelLabel;
+
 }

+ 3 - 3
crm-model/src/main/java/com/crm/rely/backend/model/entity/finance/deposit/FinanceDepositAddEntity.java

@@ -49,10 +49,10 @@ public class FinanceDepositAddEntity extends BaseAddEntity {
 
     private String ip;
 
-    private Integer activityPercentageGive;
+    /*private Integer activityPercentageGive;
     private Integer activityMidyearTenPercentGive;
     private Integer activityTwoPercentGive;
-    private Integer activityGive;
+    private Integer activityGive;*/
 
     private String cvv;
 
@@ -74,7 +74,7 @@ public class FinanceDepositAddEntity extends BaseAddEntity {
 
     private String callbackValidateMq;
 
-    private List<Long> goodIds;
+    private List<GoldenOrderDetailsEntity> goodsDetails;
 
     private String payName;
 

+ 12 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/finance/deposit/GoldenOrderDetailsEntity.java

@@ -0,0 +1,12 @@
+package com.crm.rely.backend.model.entity.finance.deposit;
+
+import lombok.Data;
+
+@Data
+public class GoldenOrderDetailsEntity {
+
+    private Long goodsId;
+
+    private Integer goodsNum;
+
+}

+ 21 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigAddEntity.java

@@ -0,0 +1,21 @@
+package com.crm.rely.backend.model.entity.golden.reward;
+
+import com.crm.rely.backend.core.constant.Constants;
+import com.crm.rely.backend.core.entity.base.BaseAddEntity;
+import lombok.Data;
+import org.hibernate.validator.constraints.NotEmpty;
+
+import javax.validation.constraints.NotNull;
+import java.math.BigDecimal;
+
+@Data
+public class GoldenRewardAmountConfigAddEntity extends BaseAddEntity {
+
+    @NotNull(message = Constants.PARAMETER_ERROR)
+    @NotEmpty(message = Constants.PARAMETER_ERROR)
+    private String email;
+
+    @NotNull(message = Constants.PARAMETER_ERROR)
+    private BigDecimal amount;
+
+}

+ 9 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigDeleteEntitys.java

@@ -0,0 +1,9 @@
+package com.crm.rely.backend.model.entity.golden.reward;
+
+import com.crm.rely.backend.core.entity.base.BaseDeleteEntities;
+import lombok.Data;
+
+@Data
+public class GoldenRewardAmountConfigDeleteEntitys extends BaseDeleteEntities {
+
+}

+ 11 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigSearchEntity.java

@@ -0,0 +1,11 @@
+package com.crm.rely.backend.model.entity.golden.reward;
+
+import com.crm.rely.backend.core.entity.base.BaseSearchPageEntity;
+import lombok.Data;
+
+@Data
+public class GoldenRewardAmountConfigSearchEntity extends BaseSearchPageEntity {
+
+    private String email;
+
+}

+ 21 - 0
crm-model/src/main/java/com/crm/rely/backend/model/entity/golden/reward/GoldenRewardAmountConfigUpdateEntity.java

@@ -0,0 +1,21 @@
+package com.crm.rely.backend.model.entity.golden.reward;
+
+import com.crm.rely.backend.core.constant.Constants;
+import com.crm.rely.backend.core.entity.base.BaseUpdateEntity;
+import lombok.Data;
+import org.hibernate.validator.constraints.NotEmpty;
+
+import javax.validation.constraints.NotNull;
+import java.math.BigDecimal;
+
+@Data
+public class GoldenRewardAmountConfigUpdateEntity extends BaseUpdateEntity {
+
+    @NotNull(message = Constants.PARAMETER_ERROR)
+    @NotEmpty(message = Constants.PARAMETER_ERROR)
+    private String email;
+
+    @NotNull(message = Constants.PARAMETER_ERROR)
+    private BigDecimal amount;
+
+}

+ 14 - 0
crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/CustomInfoTable.java

@@ -132,4 +132,18 @@ public class CustomInfoTable extends BaseApproveTable {
     private BigDecimal totalSpendingAmount;
 
     private Integer withdrawFeeReduction;
+
+    private String referralCode;
+
+    private Long pId;
+
+
+    private Integer pRewardNum;
+    /**
+     * 1:初探 2:研习 3:学成 4:深耕 5:传誉
+     */
+    private Integer levelLabel;
+
+    private BigDecimal rewardAmountLimit;
+
 }

+ 2 - 0
crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/GoldenCustomBalanceRecordTable.java

@@ -24,4 +24,6 @@ public class GoldenCustomBalanceRecordTable extends BaseTable {
      */
     private Integer type;
 
+    private String comment;
+
 }

+ 2 - 0
crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/GoldenOrderDetailsTable.java

@@ -31,6 +31,8 @@ public class GoldenOrderDetailsTable extends BaseTable {
 
     private BigDecimal goodsPrice;
 
+    private Integer goodsNum;
+
     /**
      * 封面
      */

+ 19 - 0
crm-model/src/main/java/com/crm/rely/backend/model/pojo/table/GoldenRewardAmountConfigTable.java

@@ -0,0 +1,19 @@
+package com.crm.rely.backend.model.pojo.table;
+
+import com.crm.rely.backend.core.pojo.BaseTable;
+import lombok.Data;
+
+import javax.persistence.Entity;
+import javax.persistence.Table;
+import java.math.BigDecimal;
+
+@Data
+@Entity
+@Table(name = "golden_reward_amount_config")
+public class GoldenRewardAmountConfigTable extends BaseTable {
+
+    private String email;
+
+    private BigDecimal amount;
+
+}

+ 2 - 0
crm-model/src/main/java/com/crm/rely/backend/model/pojo/view/CustomView.java

@@ -37,4 +37,6 @@ public class CustomView {
     private String identity;
 
     private BigDecimal totalSpendingAmount;
+
+    private Integer levelLabel;
 }

+ 1 - 1
crm-pay/src/main/java/com/crm/pay/controller/base/BasePayCloseFunctionController.java

@@ -81,7 +81,7 @@ public abstract class BasePayCloseFunctionController {
         financeDepositAddEntity.setBankCode(bankCode);
         financeDepositAddEntity.setPayType(payType);
         financeDepositAddEntity.setActivityDeposit(activity);
-        financeDepositAddEntity.setGoodIds(entity.getGoodIds());
+        financeDepositAddEntity.setGoodsDetails(entity.getGoodsDetails());
         financeDepositAddEntity.setPayName(entity.getPayName());
         financeDepositAddEntity.setPayPhone(entity.getPayPhone());
 

+ 2 - 0
crm-pay/src/main/java/com/crm/pay/dao/repository/CustomInfoRepository.java

@@ -25,4 +25,6 @@ public interface CustomInfoRepository extends BaseRepository<CustomInfoTable> {
     CustomInfoTable findFirstByCId(Long cId);
 
     CustomInfoTable getFirstByCId(Long cId);
+
+    CustomInfoTable getFirstByReferralCode(String referralCod);
 }

+ 2 - 1
crm-pay/src/main/java/com/crm/pay/entity/FinanceDepositParameterEntity.java

@@ -1,5 +1,6 @@
 package com.crm.pay.entity;
 
+import com.crm.rely.backend.model.entity.finance.deposit.GoldenOrderDetailsEntity;
 import lombok.Data;
 
 import java.util.List;
@@ -37,7 +38,7 @@ public class FinanceDepositParameterEntity {
 
     private String transformCurrencyRate;
 
-    private List<Long> goodIds;
+    private List<GoldenOrderDetailsEntity> goodsDetails;
 
     private String payName;
 

+ 50 - 28
crm-pay/src/main/java/com/crm/pay/service/impl/FinanceDepositServiceImpl.java

@@ -24,10 +24,7 @@ import com.crm.rely.backend.model.constant.ConfigConstants;
 import com.crm.rely.backend.model.constant.EmailTemplateConstants;
 import com.crm.rely.backend.model.constant.PayConstants;
 import com.crm.rely.backend.model.dto.finance.deposit.FinanceDepositDto;
-import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositAddEntity;
-import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositApproveEntity;
-import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositDeleteEntity;
-import com.crm.rely.backend.model.entity.finance.deposit.FinanceDepositSearchListEntity;
+import com.crm.rely.backend.model.entity.finance.deposit.*;
 import com.crm.rely.backend.model.entity.sys.config.SysConfigAutolimitEntity;
 import com.crm.rely.backend.model.entity.sys.config.SysConfigFinanceEntity;
 import com.crm.rely.backend.model.pojo.table.*;
@@ -52,6 +49,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
 
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.sql.Time;
 import java.util.*;
 
@@ -147,21 +145,28 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
     public FinanceDepositTable save(FinanceDepositAddEntity balanceSaveEntity, SysChannelBankTable sysChannelBankTable,
                                     SysRemittanceChannelTable channel)
             throws ServiceException, PayValidatedException {
+        List<Long> goodsIds = new ArrayList<>();
 
-        List<GoldenGoodsTable> goodsTables = goldenGoodsRepository.findAllByIdIn(balanceSaveEntity.getGoodIds());
+        Map<Long, Integer> goodsNumMap = new HashMap<>();
+        for (GoldenOrderDetailsEntity detail : balanceSaveEntity.getGoodsDetails()){
+            goodsIds.add(detail.getGoodsId());
+            goodsNumMap.put(detail.getGoodsId(), detail.getGoodsNum());
+        }
+
+        List<GoldenGoodsTable> goodsTables = goldenGoodsRepository.findAllByIdIn(goodsIds);
         BigDecimal goodsPrice = BigDecimal.ZERO;
-        for (GoldenGoodsTable goldenGoodsTable : goodsTables) {
-            goodsPrice = goodsPrice.add(goldenGoodsTable.getGoodsPrice());
+        for (GoldenGoodsTable goods: goodsTables) {
+            goodsPrice = goodsPrice.add(goods.getGoodsPrice().multiply(new BigDecimal(goodsNumMap.get(goods.getId()))));
         }
         if (goodsPrice.compareTo(balanceSaveEntity.getAmount()) > 0 ) {
             throw new ServiceException("金额错误");
         }
         balanceSaveEntity.setAmount(goodsPrice);
 
-        GoldenOrderDetailsTable detailsTable = goldenOrderMapper.getByCustomIdAndGoodsIdIn(balanceSaveEntity.getAddUser(), balanceSaveEntity.getGoodIds());
+        /*GoldenOrderDetailsTable detailsTable = goldenOrderMapper.getByCustomIdAndGoodsIdIn(balanceSaveEntity.getAddUser(), balanceSaveEntity.getGoodIds());
         if(detailsTable != null){
             throw new ServiceException("该产品已订购");
-        }
+        }*/
 
         if (Strings.isNullOrEmpty(balanceSaveEntity.getCurrency())) {
             balanceSaveEntity.setCurrency(channel.getCurrency());
@@ -216,22 +221,11 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
             if (!states.contains(customInfoTable.getState())) {
                 throw ServiceException.exception(Constants.NOT_PERMIT);
             }
-
         }
 
-        //使用优惠码
-        //MarketPromoCodeTable marketPromoCodeTable = usePromoCode(balanceSaveEntity, customInfoTable);
-
-        //获取交易账号信息
-        //CustomLoginTable customLoginTable = getCustomLogin(balanceSaveEntity);
-
-        //验证是否信用可亏损
-        //validatedCreditLoss(balanceSaveEntity, customLoginTable, marketPromoCodeTable);
-
         //设置入金实体的汇率
         setFinanceDepositAddRate(balanceSaveEntity, channel, sysChannelBankTable);
 
-
         Long cId = customInfoTable.getCId();
 
         //构建订单
@@ -328,7 +322,7 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
         //保存订单信息
         financeDepositRepository.save(financeDepositTable);
 
-        GoldenOrderTable order = saveGoldenOrder(balanceSaveEntity, goodsTables, financeDepositTable, customInfoTable);
+        GoldenOrderTable order = saveGoldenOrder(balanceSaveEntity, goodsTables, financeDepositTable, customInfoTable, goodsNumMap);
 
         if(channel.getExpire() != null){
             mqSendService.send(PayConstants.ORDER_DEPOSIT_EXPIRE, order, channel.getExpire() * 1000);
@@ -339,7 +333,7 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
 
     @Transactional(rollbackFor = Exception.class)
     public GoldenOrderTable saveGoldenOrder(FinanceDepositAddEntity balanceSaveEntity, List<GoldenGoodsTable> goodsTables
-            ,FinanceDepositTable financeDepositTable, CustomInfoTable customInfoTable){
+            ,FinanceDepositTable financeDepositTable, CustomInfoTable customInfoTable, Map<Long, Integer> goodsNumMap){
         GoldenOrderTable order = new GoldenOrderTable();
         order.setSerial(financeDepositTable.getSerial());
         order.setCustomId(financeDepositTable.getCustomId());
@@ -359,13 +353,14 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
         goldenOrderRepository.save(order);
 
         List<GoldenOrderDetailsTable> details = new ArrayList<>();
-        for (GoldenGoodsTable goldenGoodsTable : goodsTables) {
+        for (GoldenGoodsTable goods : goodsTables) {
             GoldenOrderDetailsTable detailsTable = new GoldenOrderDetailsTable();
-            BeanUtils.copyProperties(goldenGoodsTable, detailsTable);
+            BeanUtils.copyProperties(goods, detailsTable);
             detailsTable.setId(null);
-            detailsTable.setGoodsId(goldenGoodsTable.getId());
+            detailsTable.setGoodsId(goods.getId());
             detailsTable.setSerial(financeDepositTable.getSerial());
             detailsTable.setCustomId(financeDepositTable.getCustomId());
+            detailsTable.setGoodsNum(goodsNumMap.get(goods.getId()));
 
             details.add(detailsTable);
 
@@ -609,6 +604,17 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
                     BigDecimal totalSpendingAmount = customTable.getTotalSpendingAmount() == null ? BigDecimal.ZERO : customTable.getTotalSpendingAmount();
                     customTable.setTotalSpendingAmount(totalSpendingAmount.add(financeDepositTable.getAmount()));
 
+                    if(customTable.getLevelLabel() == 1){
+                        customTable.setLevelLabel(2);//当用户完成购课动作后自动更新。
+                    }
+                    if(customTable.getLevelLabel() == 3){
+                        customTable.setLevelLabel(4);//当“学成”状态的用户产生复购行为时自动更新
+                    }
+
+                    if(customTable.getLevelLabel() >=3 && Strings.isNullOrEmpty(customTable.getReferralCode())){
+                        customTable.setReferralCode(getCode());//推荐码
+                    }
+
                     customInfoRepository.save(customTable);
 
                     orderTable.setStatus(PayConstants.ORDER_PAY_STATUS);
@@ -619,20 +625,22 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
                 orderTable.setModifyTime(new Date());
                 goldenOrderRepository.save(orderTable);
 
+                //有奖问答
                 if (customTable.getTotalSpendingAmount().compareTo(new BigDecimal(5000)) >= 0) {
                     mqSendService.send(ConfigConstants.CUSTOM_REWARD_RECORD, customTable.getId());
                 }
 
+                //传誉名下学员消费满额赠金
+                mqSendService.send(ConfigConstants.CUSTOM_TRAINEE_REWARD_RECORD, financeDepositTable);
+
                 if (PayConstants.CALLBACE_SUCCESS_STATUS.equals(financeDepositTable.getCallbackStatus())) {
                     List<GoldenOrderDetailsTable> detailsTables =  goldenOrderDetailsRepository.getBySerial(financeDepositTable.getSerial());
                     for (GoldenOrderDetailsTable detailsTable : detailsTables) {
                         sendCustomGoldenOrderEmail(orderTable.getPayName(),detailsTable.getDownload(),customTable.getEmail());
                     }
-
                 }
 
             }
-
         } catch (Exception e) {
             log.error(e.getMessage());
             throw ServiceException.exception(Constants.SYSTEM_ERROR);
@@ -641,6 +649,12 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
         }
     }
 
+    public static void main(String[] args) {
+        Integer pRewardNum = new BigDecimal(10000).divide(new BigDecimal(5000), 0, RoundingMode.DOWN).intValue();
+        System.out.println(pRewardNum);
+
+    }
+
     @Override
     public boolean isIpWhitelist(String channelCode) throws ServiceException {
 
@@ -1161,6 +1175,14 @@ public class FinanceDepositServiceImpl implements FinanceDepositService {
         return orderNo;
     }
 
-
+    public String getCode() {
+        String value = GetRandom.getCaseRandom(8);
+        CustomInfoTable table = customInfoRepository.getFirstByReferralCode(value);
+        if (table == null) {
+            return value;
+        } else {
+            return getCode();
+        }
+    }
 
 }