diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java index d1042d98..ab6ee599 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighDiscountPackageController.java @@ -12,10 +12,7 @@ import com.hai.common.utils.ResponseMsgUtil; import com.hai.entity.*; import com.hai.model.ResponseData; import com.hai.model.UserInfoModel; -import com.hai.service.HighCouponService; -import com.hai.service.HighDiscountPackageDetailsService; -import com.hai.service.HighDiscountPackageService; -import com.hai.service.HighDiscountService; +import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; @@ -55,6 +52,8 @@ public class HighDiscountPackageController { @Resource private HighDiscountService highDiscountService; + @Resource + private HighDiscountInventoryRecordService discountInventoryRecordService; @RequestMapping(value = "/getDiscountPackageList", method = RequestMethod.GET) @ResponseBody @@ -421,6 +420,11 @@ public class HighDiscountPackageController { throw ErrorHelp.genException(SysCode.System, ErrorCode.STATUS_ERROR, ""); } + if (highDiscountPackage.getSurplusStock() == null || highDiscountPackage.getSurplusStock() == 0 ) { + log.error("highCouponPackage -> upDiscountPackage() error!","当前库存不足"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前库存不足"); + } + highDiscountPackage.setStatus(1); highDiscountPackage.setUpdatedTime(new Date()); highDiscountPackage.setUpdatedUserId(userInfoModel.getSecUser().getId().intValue()); @@ -539,4 +543,29 @@ public class HighDiscountPackageController { } } + + @RequestMapping(value = "/getDiscountInventoryRecordServList", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取优惠券包记录列表") + public ResponseData getDiscountInventoryRecordServList( + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize, + HttpServletRequest request) { + try { + + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + + map.put("companyId", userInfoModel.getBsCompany().getId()); + PageHelper.startPage(pageNum,pageSize); + return ResponseMsgUtil.success(new PageInfo<>(discountInventoryRecordService.getDiscountInventoryRecordServList(map))); + + } catch (Exception e) { + log.error("HighOrderController --> getUserOrderList() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java b/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java index 164168ec..d68a8e5f 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighOpenApiController.java @@ -46,7 +46,7 @@ public class HighOpenApiController { @RequestMapping(value = "/getUserOrderPreList", method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "获取用户预约订单") + @ApiOperation(value = "获取专属优惠券") public ResponseData getUserOrderPreList(@RequestParam(name = "usingAttribution", required = false) Integer usingAttribution, @RequestParam(name = "phone", required = true) String phone, @RequestParam(name = "year", required = false) String year) { diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java index e0dc89e8..0d2e938c 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -165,10 +165,10 @@ public class HighUserDiscountController { } } - @RequestMapping(value = "/getUserOrderPreList", method = RequestMethod.GET) + @RequestMapping(value = "/getUserExclusiveDiscount", method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "获取用户预约订单") - public ResponseData getUserOrderPreList(@RequestParam(name = "usingAttribution", required = false) Integer usingAttribution, + @ApiOperation(value = "获取用户专属优惠券") + public ResponseData getUserExclusiveDiscount(@RequestParam(name = "usingAttribution", required = false) Integer usingAttribution, @RequestParam(name = "year", required = false) String year, HttpServletRequest request) { try { 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 d8155383..40a9ea9c 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -72,6 +72,7 @@ public interface HighDiscountAgentCodeService { + /** * 查询已分配的优惠券总数 * @param discountAgentId diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountInventoryRecordService.java b/hai-service/src/main/java/com/hai/service/HighDiscountInventoryRecordService.java new file mode 100644 index 00000000..7d0ee6ea --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighDiscountInventoryRecordService.java @@ -0,0 +1,26 @@ +package com.hai.service; + +import com.hai.entity.HighDiscountInventoryRecord; + +import java.util.List; +import java.util.Map; + +/** + * @serviceName HighDiscountInventoryRecordService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 优惠券包库存记录接口 + * @createTime 4:35 下午 2021/12/8 + **/ +public interface HighDiscountInventoryRecordService { + + /** + * @Author Sum1Dream + * @name getDiscountInventoryRecordServList.java + * @Description //查询优惠券包库存记录列表 + * @Date 4:36 下午 2021/12/8 + * @Param [java.util.Map] + * @return java.util.List + */ + List getDiscountInventoryRecordServList(Map map); +} diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java b/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java new file mode 100644 index 00000000..6d474edb --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java @@ -0,0 +1,49 @@ +package com.hai.service; + +import com.hai.entity.HighDiscountPackageActual; + +import java.util.List; +import java.util.Map; + +/** + * @serviceName HighDiscountPackageActualService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 优惠券包实际库存接口 + * @createTime 3:02 下午 2021/12/8 + **/ +public interface HighDiscountPackageActualService { + + /** + * @Author Sum1Dream + * @name insertHighDiscountPackageActual.java + * @Description // 新增优惠券包实际库存 + * @Date 3:03 下午 2021/12/8 + * @Param [com.hai.entity.HighDiscountPackageActual] + * @return void + */ + void insertHighDiscountPackageActual(HighDiscountPackageActual highDiscountPackageActual); + + + /** + * @Author Sum1Dream + * @name updateHighDiscountPackageActual.java + * @Description // 修改优惠券包实际库存 + * @Date 3:04 下午 2021/12/8 + * @Param [com.hai.entity.HighDiscountPackageActual] + * @return void + */ + void updateHighDiscountPackageActual(HighDiscountPackageActual highDiscountPackageActual); + + + /** + * @Author Sum1Dream + * @name getHighDiscountPackageActualList.java + * @Description // 查询优惠券包列表; + * @Date 3:05 下午 2021/12/8 + * @Param [java.util.Map] + * @return java.util.List + */ + List getHighDiscountPackageActualList(Integer discountPackageId); + +} diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountPackageDiscountActualService.java b/hai-service/src/main/java/com/hai/service/HighDiscountPackageDiscountActualService.java new file mode 100644 index 00000000..4e733359 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/HighDiscountPackageDiscountActualService.java @@ -0,0 +1,47 @@ +package com.hai.service; + +import com.hai.entity.HighDiscountPackageDiscountActual; + +import java.util.List; + +/** + * @serviceName HighDiscountPackageDiscountActualService.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 优惠券包实际库存优惠券实际 + * @createTime 3:13 下午 2021/12/8 + **/ +public interface HighDiscountPackageDiscountActualService { + + /** + * @Author Sum1Dream + * @name insertHighDiscountPackageDiscountActual.java + * @Description // 新增优惠券包实际库存 + * @Date 3:03 下午 2021/12/8 + * @Param [com.hai.entity.HighDiscountPackageDiscountActual] + * @return void + */ + void insertHighDiscountPackageDiscountActual(HighDiscountPackageDiscountActual highDiscountPackageDiscountActual); + + + /** + * @Author Sum1Dream + * @name updateHighDiscountPackageDiscountActual.java + * @Description // 修改优惠券包实际库存 + * @Date 3:04 下午 2021/12/8 + * @Param [com.hai.entity.HighDiscountPackageDiscountActual] + * @return void + */ + void updateHighDiscountPackageDiscountActual(HighDiscountPackageDiscountActual highDiscountPackageDiscountActual); + + + /** + * @Author Sum1Dream + * @name getHighDiscountPackageDiscountActualList.java + * @Description // 查询优惠券包列表; + * @Date 3:05 下午 2021/12/8 + * @Param [java.util.Map] + * @return java.util.List + */ + List getHighDiscountPackageDiscountActualList(Integer discountPackageActualId); +} 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 06066ffb..ae562893 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 @@ -115,6 +115,7 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe return highDiscountAgentCodeMapper.selectByPrimaryKey(id); } + @Override public Integer getTotalDiscount(Long discountAgentId) { HighDiscountAgentCodeExample example = new HighDiscountAgentCodeExample(); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountInventoryRecordServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountInventoryRecordServiceImpl.java new file mode 100644 index 00000000..cdcb6aed --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountInventoryRecordServiceImpl.java @@ -0,0 +1,34 @@ +package com.hai.service.impl; + +import com.hai.dao.HighDiscountInventoryRecordMapper; +import com.hai.entity.HighDiscountInventoryRecord; +import com.hai.entity.HighDiscountInventoryRecordExample; +import com.hai.service.HighDiscountInventoryRecordService; +import org.apache.commons.collections4.MapUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +@Service("highDiscountInventoryRecordService") +public class HighDiscountInventoryRecordServiceImpl implements HighDiscountInventoryRecordService { + + @Resource + private HighDiscountInventoryRecordMapper discountInventoryRecordMapper; + + @Override + public List getDiscountInventoryRecordServList(Map map) { + + HighDiscountInventoryRecordExample example = new HighDiscountInventoryRecordExample(); + HighDiscountInventoryRecordExample.Criteria criteria = example.createCriteria(); + + if (MapUtils.getInteger(map , "companyId") != null) { + criteria.andCompanyIdEqualTo(MapUtils.getInteger(map , "companyId")); + } + + example.setOrderByClause("created_time"); + + return discountInventoryRecordMapper.selectByExample(example); + } +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java new file mode 100644 index 00000000..0a7c1a11 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java @@ -0,0 +1,48 @@ +package com.hai.service.impl; + +import com.hai.dao.HighDiscountPackageActualMapper; +import com.hai.dao.HighDiscountPackageDiscountActualMapper; +import com.hai.entity.HighDiscountPackageActual; +import com.hai.entity.HighDiscountPackageActualExample; +import com.hai.service.HighDiscountPackageActualService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Map; + +/** + * @serviceName HighDiscountPackageActualServiceImpl.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 优惠券包实际库存 + * @createTime 3:06 下午 2021/12/8 + **/ +@Service("highDiscountPackageActualService") +public class HighDiscountPackageActualServiceImpl implements HighDiscountPackageActualService { + + + @Resource + private HighDiscountPackageActualMapper discountPackageActualMapper; + + @Override + public void insertHighDiscountPackageActual(HighDiscountPackageActual highDiscountPackageActual) { + discountPackageActualMapper.insert(highDiscountPackageActual); + } + + @Override + public void updateHighDiscountPackageActual(HighDiscountPackageActual highDiscountPackageActual) { + discountPackageActualMapper.updateByPrimaryKey(highDiscountPackageActual); + } + + @Override + public List getHighDiscountPackageActualList(Integer discountPackageId) { + + HighDiscountPackageActualExample example = new HighDiscountPackageActualExample(); + HighDiscountPackageActualExample.Criteria criteria = example.createCriteria(); + + criteria.andDiscountPackageIdEqualTo(discountPackageId).andStatusEqualTo(1); + + return discountPackageActualMapper.selectByExample(example); + } +} diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDiscountActualServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDiscountActualServiceImpl.java new file mode 100644 index 00000000..ca20c382 --- /dev/null +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDiscountActualServiceImpl.java @@ -0,0 +1,45 @@ +package com.hai.service.impl; + +import com.hai.dao.HighDiscountPackageDiscountActualMapper; +import com.hai.entity.HighDiscountPackageDiscountActual; +import com.hai.entity.HighDiscountPackageDiscountActualExample; +import com.hai.service.HighDiscountPackageDiscountActualService; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +/** + * @serviceName HighDiscountPackageDiscountActualServiceImpl.java + * @author Sum1Dream + * @version 1.0.0 + * @Description // 优惠券包实际库存优惠券实际接口 + * @createTime 3:15 下午 2021/12/8 + **/ +@Service("highDiscountPackageDiscountActualService") +public class HighDiscountPackageDiscountActualServiceImpl implements HighDiscountPackageDiscountActualService { + + @Resource + private HighDiscountPackageDiscountActualMapper discountPackageDiscountActualMapper; + + @Override + public void insertHighDiscountPackageDiscountActual(HighDiscountPackageDiscountActual highDiscountPackageDiscountActual) { + discountPackageDiscountActualMapper.insert(highDiscountPackageDiscountActual); + } + + @Override + public void updateHighDiscountPackageDiscountActual(HighDiscountPackageDiscountActual highDiscountPackageDiscountActual) { + discountPackageDiscountActualMapper.updateByPrimaryKey(highDiscountPackageDiscountActual); + } + + @Override + public List getHighDiscountPackageDiscountActualList(Integer discountPackageActualId) { + + HighDiscountPackageDiscountActualExample example = new HighDiscountPackageDiscountActualExample(); + HighDiscountPackageDiscountActualExample.Criteria criteria = example.createCriteria(); + + criteria.andDiscountPackageActualIdEqualTo(discountPackageActualId).andStatusEqualTo(1); + + return discountPackageDiscountActualMapper.selectByExample(example); + } +} 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 c89c93d1..5b470a50 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 @@ -1,5 +1,8 @@ package com.hai.service.impl; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; import com.hai.dao.*; import com.hai.entity.*; import com.hai.model.UserInfoModel; @@ -40,15 +43,15 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic @Resource private HighDiscountAgentCodeService highDiscountAgentCodeService; - @Resource - private HighDiscountInventoryRecordMapper highDiscountInventoryRecordMapper; - @Resource private HighDiscountPackageActualMapper discountPackageActualMapper; @Resource private HighDiscountPackageDiscountActualMapper discountPackageDiscountActualMapper; + @Resource + private HighDiscountInventoryRecordMapper discountInventoryRecordMapper; + @Override public List getDiscountPackageList(Map map) { @@ -166,6 +169,10 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(detailsList.getDiscountId().longValue(), detailsList.getAgentId()); List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByStatus(discountAgentRel.getId() , 1); + if (discountAgentCodeList.size() < detailsList.getNum()) { + throw ErrorHelp.genException(SysCode.System , ErrorCode.COMMON_ERROR , detailsList.getDiscountName() +"优惠券库存不足"); + } + // 赠送优惠券 for (HighDiscountAgentCode discountAgentCode : discountAgentCodeList.subList(0, detailsList.getNum())) { HighDiscountPackageDiscountActual discountPackageDiscountActual = new HighDiscountPackageDiscountActual(); @@ -175,6 +182,8 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic discountPackageDiscountActual.setCreatedTime(new Date()); discountPackageDiscountActual.setAgentDiscountCodeId(discountAgentCode.getId()); discountPackageDiscountActual.setStatus(1); + discountPackageDiscountActual.setDiscountId(detailsList.getDiscountId().longValue()); + discountPackageDiscountActual.setAgentId(detailsList.getAgentId()); discountPackageDiscountActualMapper.insert(discountPackageDiscountActual); // 修改优惠券二维码状态 @@ -186,7 +195,27 @@ public class HighDiscountPackageServiceImpl implements HighDiscountPackageServic } } - highDiscountPackage.setTotalStock(num); - highDiscountPackage.setSurplusStock(highDiscountPackage.getSurplusStock() + num); + // 设置库存 + int surplusStock = highDiscountPackage.getSurplusStock() == null ? 0 :highDiscountPackage.getSurplusStock(); + int totalStock = highDiscountPackage.getTotalStock() == null ? 0 :highDiscountPackage.getTotalStock(); + + // 新增补库记录 + HighDiscountInventoryRecord discountInventoryRecord = new HighDiscountInventoryRecord(); + discountInventoryRecord.setDiscountPackageId(highDiscountPackage.getId()); + discountInventoryRecord.setDiscountPackageTitle(highDiscountPackage.getTitle()); + discountInventoryRecord.setCreatedUserId(userInfoModel.getSecUser().getId().intValue()); + discountInventoryRecord.setCompanyId(userInfoModel.getBsCompany().getId().intValue()); + discountInventoryRecord.setCreatedTime(new Date()); + discountInventoryRecord.setStatus(1); + discountInventoryRecord.setStockNum(num); + discountInventoryRecord.setFrontStockNum(highDiscountPackage.getSurplusStock()); + discountInventoryRecord.setNowStockNum(surplusStock + num); + + discountInventoryRecordMapper.insert(discountInventoryRecord); + + // 设置库存 + highDiscountPackage.setSurplusStock(surplusStock + num); + highDiscountPackage.setTotalStock(totalStock + num); + highDiscountPackageMapper.updateByPrimaryKey(highDiscountPackage); } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HltUnionCardVipServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HltUnionCardVipServiceImpl.java index ebce2fcf..aac6346e 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HltUnionCardVipServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HltUnionCardVipServiceImpl.java @@ -9,6 +9,8 @@ import com.hai.common.utils.DateUtil; import com.hai.common.utils.IDGenerator; import com.hai.common.utils.ResponseMsgUtil; import com.hai.config.HuiLianTongUnionCardConfig; +import com.hai.dao.HighDiscountPackageActualMapper; +import com.hai.dao.HighDiscountPackageDiscountActualMapper; import com.hai.dao.HighDiscountPackageRecordMapper; import com.hai.dao.HighDiscountUserRelMapper; import com.hai.entity.*; @@ -54,9 +56,15 @@ public class HltUnionCardVipServiceImpl implements HltUnionCardVipService { @Resource private HighDiscountService highDiscountService; + @Resource + private HighDiscountPackageActualService discountPackageActualService; + + @Resource + private HighDiscountPackageDiscountActualService discountPackageDiscountActualService; + @Override - @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) + @Transactional(propagation= Propagation.REQUIRES_NEW) public JSONObject GetMembershipLevel(String phone , String regionId) throws Exception { SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId)); @@ -107,59 +115,55 @@ public class HltUnionCardVipServiceImpl implements HltUnionCardVipService { HighDiscountPackage highDiscountPackage = highDiscountPackages.get(0); - Map mapRule = new HashMap<>(); - mapRule.put("discountPackageId", highDiscountPackage.getId()); - - // 查询优惠券包规则 - List discountPackageDetailsList = highDiscountPackageDetailsService.getDiscountPackageDetailsList(mapRule); + highDiscountPackage.setSurplusStock(highDiscountPackage.getSurplusStock() - 1); + highDiscountPackageService.updateDiscountPackage(highDiscountPackage); - // 循环 优惠券包规则详情 列表 - for (HighDiscountPackageDetails detailsList: discountPackageDetailsList) { + // 查询优惠券包实际库存 + HighDiscountPackageActual discountPackageActual = discountPackageActualService.getHighDiscountPackageActualList(highDiscountPackage.getId()).get(0); - // 查询代理商与优惠券关系 列表 - List discountAgentRels = highDiscountAgentRelService.getRelByDiscountId(detailsList.getDiscountId().longValue()); + // 修改优惠券包实际库存状态 + discountPackageActual.setStatus(0); + discountPackageActual.setUserId(highUser.getId().intValue()); + discountPackageActual.setAllocationTime(new Date()); + discountPackageActualService.updateHighDiscountPackageActual(discountPackageActual); - HighDiscountAgentRel discountAgentRel = new HighDiscountAgentRel(); + // 查询优惠券包实际库存中实际优惠券数量 + List discountPackageDiscountActual = discountPackageDiscountActualService.getHighDiscountPackageDiscountActualList(discountPackageActual.getId()); - for (HighDiscountAgentRel discountAgentRelList: discountAgentRels) { - // 判断当前是否足够库存赠送 - if (discountAgentRelList.getStockCount() > detailsList.getNum()) { - discountAgentRel = discountAgentRelList; - break; - } - } + // 循环赠送优惠券 + for (HighDiscountPackageDiscountActual actualList: discountPackageDiscountActual) { - List discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId()); + HighDiscountUserRel highDiscountUserRel = new HighDiscountUserRel(); + highDiscountUserRel.setDiscountId(actualList.getDiscountId()); + highDiscountUserRel.setUserId(highUser.getId()); + highDiscountUserRel.setAgentId(actualList.getAgentId()); + highDiscountUserRel.setDiscountAgentCodeId(actualList.getAgentDiscountCodeId()); + highDiscountUserRel.setStatus(1); + highDiscountUserRel.setCreateTime(new Date()); - // 赠送优惠券 - for (HighDiscountAgentCode discountAgentCode : discountAgentCodeList.subList(0, detailsList.getNum())) { - HighDiscountUserRel highDiscountUserRel = new HighDiscountUserRel(); - highDiscountUserRel.setDiscountId(discountAgentRel.getDiscountId()); - highDiscountUserRel.setUserId(highUser.getId()); - highDiscountUserRel.setAgentId(discountAgentRel.getAgentId()); - highDiscountUserRel.setDiscountAgentCodeId(discountAgentCode.getId()); - highDiscountUserRel.setStatus(1); - highDiscountUserRel.setCreateTime(new Date()); + HighDiscount highDiscount = highDiscountService.getDiscountById(actualList.getDiscountId()); - HighDiscount highDiscount = highDiscountService.getDiscountById(discountAgentRel.getDiscountId()); + // 计算使用有效期 + Calendar userEndTime = Calendar.getInstance(); + userEndTime.setTime(new Date()); + userEndTime.set(Calendar.HOUR_OF_DAY, 23); + userEndTime.set(Calendar.MINUTE, 59); + userEndTime.set(Calendar.SECOND, 59); + userEndTime.add(Calendar.DATE, highDiscount.getEffectiveDay()); + highDiscountUserRel.setUseEndTime(userEndTime.getTime()); - // 计算使用有效期 - Calendar userEndTime = Calendar.getInstance(); - userEndTime.setTime(new Date()); - userEndTime.set(Calendar.HOUR_OF_DAY, 23); - userEndTime.set(Calendar.MINUTE, 59); - userEndTime.set(Calendar.SECOND, 59); - userEndTime.add(Calendar.DATE, highDiscount.getEffectiveDay()); - highDiscountUserRel.setUseEndTime(userEndTime.getTime()); + HighDiscountAgentCode discountAgentCode = highDiscountAgentCodeService.getCodeById(actualList.getAgentDiscountCodeId()); - // 修改优惠券二维码状态 - discountAgentCode.setStatus(2); - highDiscountAgentCodeService.updateCode(discountAgentCode); + // 修改优惠券二维码状态 + discountAgentCode.setStatus(2); + highDiscountAgentCodeService.updateCode(discountAgentCode); - // 新增优惠券与用户的绑定关系 - highDiscountUserRelMapper.insert(highDiscountUserRel); - } + // 新增优惠券与用户的绑定关系 + highDiscountUserRelMapper.insert(highDiscountUserRel); + // 修改优惠券包实际库存实际优惠券状态 + actualList.setStatus(0); + discountPackageDiscountActualService.updateHighDiscountPackageDiscountActual(actualList); } // 增加赠送记录