diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java b/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java index cfbe37a5..a99a18d8 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighActivityController.java @@ -39,8 +39,8 @@ import java.util.*; * @author hurui */ @Controller -@RequestMapping(value = "/activity") -@Api(value = "活动业务接口") +@RequestMapping(value = "/activityAward") +@Api(value = "活动奖励接口") public class HighActivityController { private static Logger log = LoggerFactory.getLogger(HighActivityController.class); @@ -78,10 +78,10 @@ public class HighActivityController { // 组装奖品 if (body.getJSONArray("activityPrizes") != null && body.getJSONArray("activityPrizes").size() > 0) { - for (Object object : body.getJSONArray("ruleArray")) { + for (Object object : body.getJSONArray("activityPrizes")) { JSONObject activityObject = (JSONObject)object; if ( - activityObject.getInteger("prizeType") == null || + activityObject.getInteger("agentId") == null || activityObject.getLong("prizeId") == null || StringUtils.isBlank(activityObject.getString("prizeName")) || activityObject.getInteger("prizeNum") == null @@ -92,7 +92,7 @@ public class HighActivityController { activityPrize = new HighActivityPrize(); - activityPrize.setPrizeType(activityObject.getInteger("prizeType")); + activityPrize.setPrizeType(2); activityPrize.setPrizeId(activityObject.getLong("prizeId")); activityPrize.setPrizeName(activityObject.getString("prizeName")); activityPrize.setPrizeNum(activityObject.getInteger("prizeNum")); @@ -127,7 +127,7 @@ public class HighActivityController { highActivityAwardService.editHighActivateAward(highActivityAward , activityPrizes); - return ResponseMsgUtil.success("1"); + return ResponseMsgUtil.success("成功"); } catch (Exception e) { log.error("HighActivityController -> userLottery() error!",e); 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 d8539d52..55c245a3 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountAgentCodeService.java @@ -49,7 +49,7 @@ public interface HighDiscountAgentCodeService { * @Param [discountAgentId] * @return java.util.List **/ - List getDiscountCodeByDiscountAgentId(Long discountAgentId , Integer num); + List getDiscountCodeByDiscountAgentId(Long discountAgentId); /** * @Author 胡锐 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java index 0d73e77e..f9274185 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighActivityAwardServiceImpl.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.common.utils.DateUtil; import com.hai.common.utils.IDGenerator; import com.hai.dao.HighActivityAwardActualPrizeMapper; @@ -38,6 +41,9 @@ public class HighActivityAwardServiceImpl implements HighActivityAwardService { @Resource private HighDiscountAgentCodeService highDiscountAgentCodeService; + @Resource + private HighActivityAwardActualPrizeMapper highActivityAwardActualPrizeM; + @Override public List getListByActivityId(Long activityId) { @@ -61,10 +67,21 @@ public class HighActivityAwardServiceImpl implements HighActivityAwardService { highActivityAwardMapper.updateByPrimaryKey(highActivityAward); } - HighActivityAwardSerialNum serialNum; + // 增加奖品 + for (HighActivityPrize list : highActivityPrizes) { + list.setActivityAwardId(highActivityAward.getId()); + list.setCreateTime(new Date()); + list.setUpdateTime(new Date()); + list.setStatus(1); + highActivityPrizeMapper.insert(list); + } + + + HighActivityAwardSerialNum serialNum; HighActivityAwardActualPrize actualPrize; + // 生成中奖编号 for (int i = 0; i < highActivityAward.getNum(); i++) { serialNum = new HighActivityAwardSerialNum(); serialNum.setActivityInfoId(highActivityAward.getActivityInfoId()); @@ -74,28 +91,43 @@ public class HighActivityAwardServiceImpl implements HighActivityAwardService { serialNum.setCreateTime(new Date()); highActivityAwardSerialNumM.insert(serialNum); - // 增加奖品 + // 循环奖品 for (HighActivityPrize list : highActivityPrizes) { - list.setActivityAwardId(highActivityAward.getId()); - list.setCreateTime(new Date()); - list.setStatus(1); - highActivityPrizeMapper.insert(list); - HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(list.getPrizeId() , Long.valueOf(list.getExt1())); - - List codeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId() , list.getPrizeNum()); - - for (HighDiscountAgentCode agentCode: codeList) { - actualPrize = new HighActivityAwardActualPrize(); - actualPrize.setActivityAwardPrizeId(list.getId()); - actualPrize.setActivityAwardSerialNumId(serialNum.getId()); - actualPrize.setActualPrizeType(2); - actualPrize.setActualPrizeId(agentCode.getId()); - actualPrize.setStatus(1); - actualPrize.setCreateTime(new Date()); + + + // 奖品类型 1:卡券 2:优惠券 + if (list.getPrizeType() == 2) { + int startNum = 0; + int endNum = 0; + endNum += list.getPrizeNum(); + HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelByDiscountAgent(list.getPrizeId() , Long.valueOf(list.getExt1())); + + List codeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId()); + + if (list.getPrizeNum() > codeList.size()) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.ADD_DATA_ERROR, ""); + } + + for (HighDiscountAgentCode agentCode: codeList.subList(startNum, endNum)) { + + agentCode.setStatus(5); + + actualPrize = new HighActivityAwardActualPrize(); + actualPrize.setActivityAwardPrizeId(list.getId()); + actualPrize.setActivityAwardSerialNumId(serialNum.getId()); + actualPrize.setActualPrizeType(2); + actualPrize.setActualPrizeId(agentCode.getId()); + actualPrize.setStatus(1); + actualPrize.setCreateTime(new Date()); + highActivityAwardActualPrizeM.insert(actualPrize); + highDiscountAgentCodeService.updateCode(agentCode); + } + startNum += list.getPrizeNum(); } - } + + } } 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 d345bc13..4ff24be7 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 @@ -92,12 +92,11 @@ public class HighDiscountAgentCodeServiceImpl implements HighDiscountAgentCodeSe } @Override - public List getDiscountCodeByDiscountAgentId(Long discountAgentId , Integer num) { + public List getDiscountCodeByDiscountAgentId(Long discountAgentId) { HighDiscountAgentCodeExample example = new HighDiscountAgentCodeExample(); HighDiscountAgentCodeExample.Criteria criteria = example.createCriteria(); criteria.andDiscountAgentIdEqualTo(discountAgentId).andStatusEqualTo(1); - example.setLimit(num); example.setOrderByClause("create_time desc"); return highDiscountAgentCodeMapper.selectByExample(example); }