diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java index 4595b701..d8155383 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -1,6 +1,7 @@ package com.hai.service; import com.hai.entity.HighDiscountAgentCode; +import io.swagger.models.auth.In; import java.util.List; import java.util.Map; @@ -51,6 +52,16 @@ public interface HighDiscountAgentCodeService { **/ List getDiscountCodeByDiscountAgentId(Long discountAgentId); + /** + * @Author Sum1Dream + * @name getDiscountCodeByDiscountAgentId.java + * @Description // 根据关系id 查询 未领取的卡券 + * @Date 14:20 2021/9/29 + * @Param [discountAgentId] + * @return java.util.List + **/ + List getDiscountCodeByStatus(Long discountAgentId , Integer status); + /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java index 23499ce6..06066ffb 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountAgentCodeServiceImpl.java @@ -101,6 +101,14 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe return highDiscountAgentCodeMapper.selectByExample(example); } + @Override + public List getDiscountCodeByStatus(Long discountAgentId, Integer status) { + HighDiscountAgentCodeExample example = new HighDiscountAgentCodeExample(); + HighDiscountAgentCodeExample.Criteria criteria = example.createCriteria(); + criteria.andDiscountAgentIdEqualTo(discountAgentId).andStatusEqualTo(status); + example.setOrderByClause("create_time desc"); + return highDiscountAgentCodeMapper.selectByExample(example); + } @Override public HighDiscountAgentCode getCodeById(Long id) { diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java index 9692734a..c89c93d1 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageServiceImpl.java @@ -88,10 +88,11 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic } @Override - public HighDiscountPackage getCallExclusive(Integer usingAttribution , Integer companyId) { + public HighDiscountPackage getCallExclusive(Integer usingAttribution, Integer companyId) { HighDiscountPackageExample example = new HighDiscountPackageExample(); HighDiscountPackageExample.Criteria criteria = example.createCriteria(); - criteria.andUsingAttributionEqualTo(usingAttribution).andStatusNotEqualTo(4).andCompanyIdEqualTo(companyId);; + criteria.andUsingAttributionEqualTo(usingAttribution).andStatusNotEqualTo(4).andCompanyIdEqualTo(companyId); + ; return highDiscountPackageMapper.selectByExample(example).get(0); } @@ -139,10 +140,10 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic } @Override - @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) - public void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel , Integer num) { + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void addDiscountPackageStock(HighDiscountPackage highDiscountPackage, UserInfoModel userInfoModel, Integer num) { - Map mapRule = new HashMap<>(); + Map mapRule = new HashMap<>(); mapRule.put("discountPackageId", highDiscountPackage.getId()); // 查询优惠券包规则 @@ -158,14 +159,34 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic for (int i = 0; i < num; i++) { discountPackageActual.setCreatedTime(new Date()); discountPackageActualMapper.insert(discountPackageActual); - } - - // 循环 优惠券包规则详情 列表 - for (HighDiscountPackageDetails detailsList: discountPackageDetailsList) { - // 查询代理商与优惠券关系 列表 - List discountAgentRels = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue() , detailsList.getAgentId()); + // 循环 优惠券包规则详情 列表 + for (HighDiscountPackageDetails detailsList : discountPackageDetailsList) { + // 查询代理商与优惠券关系 列表 + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue(), detailsList.getAgentId()); + List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByStatus(discountAgentRel.getId() , 1); + + // 赠送优惠券 + for (HighDiscountAgentCode discountAgentCode : discountAgentCodeList.subList(0, detailsList.getNum())) { + HighDiscountPackageDiscountActual discountPackageDiscountActual = new HighDiscountPackageDiscountActual(); + discountPackageDiscountActual.setDiscountPackageId(highDiscountPackage.getId()); + discountPackageDiscountActual.setDiscountPackageActualId(discountPackageActual.getId()); + discountPackageDiscountActual.setCreatedUserId(userInfoModel.getSecUser().getId().intValue()); + discountPackageDiscountActual.setCreatedTime(new Date()); + discountPackageDiscountActual.setAgentDiscountCodeId(discountAgentCode.getId()); + discountPackageDiscountActual.setStatus(1); + discountPackageDiscountActualMapper.insert(discountPackageDiscountActual); + + // 修改优惠券二维码状态 + discountAgentCode.setStatus(5); + highDiscountAgentCodeService.updateCode(discountAgentCode); + + } + + } } + highDiscountPackage.setTotalStock(num); + highDiscountPackage.setSurplusStock(highDiscountPackage.getSurplusStock() + num); } }