diff --git a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java index 78ac2dab..8265d525 100644 --- a/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java +++ b/hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java @@ -80,6 +80,27 @@ public class HighCouponAgentController { } } + @RequestMapping(value = "/getAgentConvertCodeCount", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "代理商兑换码统计") + public ResponseData getAgentConvertCodeCount(HttpServletRequest request) { + try { + SessionObject sessionObject = userCenter.getSessionObject(request); + UserInfoModel userInfoModel = (UserInfoModel) sessionObject.getObject(); + + if (userInfoModel.getHighAgent() == null) { + log.error("HighCouponAgentController -> assignCouponAgent() error!","该主角色没有权限"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.MENU_TREE_HAS_NOT_ERROR, ""); + } + + return ResponseMsgUtil.success(highCouponAgentService.getConvertCodeCountByAgent(userInfoModel.getHighAgent().getId())); + + } catch (Exception e) { + log.error("HighCouponAgentController --> getCodeById() error!", e); + return ResponseMsgUtil.exception(e); + } + } + @RequestMapping(value = "/getAgentSalesCodeList", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "查询代理商已销售的卡券") diff --git a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java index bd90ed5c..b6ce7d39 100644 --- a/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java +++ b/hai-cweb/src/main/java/com/cweb/config/AuthConfig.java @@ -94,6 +94,7 @@ public class AuthConfig implements WebMvcConfigurer { .excludePathPatterns("/coupon/getCouponList") .excludePathPatterns("/wechatpay/*") .excludePathPatterns("/couponAgent/useConvertCode") + .excludePathPatterns("/couponAgent/convertCodeDetail") .excludePathPatterns("/coupon/getCouponById") .excludePathPatterns("/discount/getDiscountByQrCode") .excludePathPatterns("/discount/getDiscountById") diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java b/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java index c904232d..f627d928 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java @@ -44,6 +44,12 @@ public class HighCouponAgentController { @Resource private HighCouponAgentService highCouponAgentService; + @Resource + private HighCouponService highCouponService; + + @Resource + private HighCouponCodeService highCouponCodeService; + @RequestMapping(value = "/useConvertCode", method = RequestMethod.POST) @ResponseBody @ApiOperation(value = "兑换码使用") @@ -80,5 +86,29 @@ public class HighCouponAgentController { } } + @RequestMapping(value = "/convertCodeDetail", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "兑换码详情") + public ResponseData convertCodeDetail(@RequestParam(name = "code", required = true) String code) { + try { + + // 查询兑换码 + HighCouponAgentCode couponAgentCode = highCouponAgentService.getConvertCode(code); + if (couponAgentCode == null) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到销售码"); + } + + Map map = new HashMap<>(); + map.put("couponInfo", highCouponService.getCouponById(couponAgentCode.getCouponId())); + map.put("couponCode", highCouponCodeService.getCouponCodeById(couponAgentCode.getCouponCodeId())); + map.put("couponAgentCode", couponAgentCode); + return ResponseMsgUtil.success(map); + + } catch (Exception e) { + log.error("HighCouponAgentController --> getConvertCodeDetail() error!", e); + return ResponseMsgUtil.exception(e); + } + } + } diff --git a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java index 34fa18c8..0d31cc76 100644 --- a/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java +++ b/hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java @@ -25,7 +25,7 @@ public interface HighCouponAgentRelMapperExt { AgentSalesModel getAgentSales(@Param("agentId") Long agentId, @Param("consumeTimeS")String consumeTimeS, @Param("consumeTimeE")String consumeTimeE); @Select(" select a.* from high_coupon_agent_code a,high_coupon_code b,high_coupon_agent_rel c " + - " where c.id = a.coupon_agent_id and c.agent_id = #{agentId} and a.status = 3 and a.coupon_code_id = b.id " + + " where c.id = a.coupon_agent_id and c.agent_id = #{agentId} and b.`status` = 3 and a.coupon_code_id = b.id " + " and b.consume_time >= #{consumeTimeS} and b.consume_time <= #{consumeTimeE} ORDER BY b.consume_time desc") @Results({ @Result(column="id", property="id", jdbcType= JdbcType.BIGINT, id=true), @@ -49,4 +49,9 @@ public interface HighCouponAgentRelMapperExt { @Select(" select count(1) from high_coupon_agent_code a where a.agent_id = #{agentId} and a.`status` in (${status}) and a.type = #{type} ") Integer getAgentCodeCount(@Param("agentId") Long agentId,@Param("status") String status,@Param("type") Integer type); + + @Select(" select sum(b.sales_price) from high_coupon_agent_code a " + + " LEFT JOIN high_coupon_agent_rel b on b.id = a.coupon_agent_id " + + " where a.agent_id = #{agentId} and a.`status` in (${status}) and a.type = #{type} ") + Integer getAgentCodePrice(@Param("agentId") Long agentId,@Param("status") String status,@Param("type") Integer type); } diff --git a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java index bf526f8f..052070db 100644 --- a/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java +++ b/hai-service/src/main/java/com/hai/service/HighCouponAgentService.java @@ -80,6 +80,8 @@ public interface HighCouponAgentService { **/ Map getSalesCountByAgent(Long agentId, Integer type) throws Exception; + Map getConvertCodeCountByAgent(Long agentId); + /** * * @param map @@ -123,6 +125,6 @@ public interface HighCouponAgentService { * @param code * @return */ - String useConvertCode(String code); + Map useConvertCode(String code); } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java index 4e2fa5ee..c34d57ac 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.java @@ -311,6 +311,34 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { return returnMap; } + @Override + public Map getConvertCodeCountByAgent(Long agentId) { + Map listMap = new HashMap<>(); + listMap.put("agentId", agentId); + List list = getCouponAgentList(listMap).stream().sorted(Comparator.comparing(HighCouponAgentRel::getSalesPrice)).collect(Collectors.toList()); + + Map returnMap = new HashMap<>(); + returnMap.put("list", list); + + // 待销售 + returnMap.put("noSalesNum", highCouponAgentRelMapper.getAgentCodeCount(agentId, "1", 2)); + returnMap.put("noSalesPrice", highCouponAgentRelMapper.getAgentCodePrice(agentId, "1", 2)); + + // 已销售 + returnMap.put("salesNum", highCouponAgentRelMapper.getAgentCodeCount(agentId, "2", 2)); + returnMap.put("salesPrice", highCouponAgentRelMapper.getAgentCodePrice(agentId, "2", 2)); + + // 待使用 + returnMap.put("noUsedNum", highCouponAgentRelMapper.getAgentCodeCount(agentId, "2", 2)); + returnMap.put("noUsedPrice", highCouponAgentRelMapper.getAgentCodePrice(agentId, "2", 2)); + + // 已使用 + returnMap.put("usedNum", highCouponAgentRelMapper.getAgentCodeCount(agentId, "3", 2)); + returnMap.put("usedPrice", highCouponAgentRelMapper.getAgentCodePrice(agentId, "3", 2)); + + return returnMap; + } + @Override public List getRecordList(Map map) { HighCouponAgentRecordExample example = new HighCouponAgentRecordExample(); @@ -373,7 +401,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { @Override @Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE) - public String useConvertCode(String code) { + public Map useConvertCode(String code) { // 查询兑换码 HighCouponAgentCode convertCode = getConvertCode(code); if (convertCode == null) { @@ -395,9 +423,14 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService { convertCode.setCouponCodeId(couponCode.getId()); convertCode.setCouponCode(couponCode.getSalesCode()); convertCode.setQrCode(couponCode.getExt1()); - convertCode.setStatus(2); + convertCode.setStatus(3); highCouponAgentCodeMapper.updateByPrimaryKey(convertCode); - return "/couponCode/"+couponCode.getExt1(); + // 查询卡券销售码 + Map map = new HashMap<>(); + map.put("couponInfo", highCouponService.getCouponById(convertCode.getCouponId())); + map.put("couponCode", highCouponCodeService.getCouponCodeById(convertCode.getCouponCodeId())); + map.put("couponAgentCode", convertCode); + return map; } }