* 'dev' of http://139.159.177.244:3000/hurui/hai-server:
  提交代码
  提交代码
  提交代碼
  提交代码
  提交代码
dev-discount
袁野 3 years ago
commit f5fe389bcc
  1. 21
      hai-bweb/src/main/java/com/bweb/controller/HighCouponAgentController.java
  2. 1
      hai-cweb/src/main/java/com/cweb/config/AuthConfig.java
  3. 39
      hai-cweb/src/main/java/com/cweb/controller/HighCouponAgentController.java
  4. 34
      hai-service/src/main/java/com/hai/dao/HighCouponAgentRelMapperExt.java
  5. 46
      hai-service/src/main/java/com/hai/model/HighCouponAgentRelModel.java
  6. 4
      hai-service/src/main/java/com/hai/service/HighCouponAgentService.java
  7. 56
      hai-service/src/main/java/com/hai/service/impl/HighCouponAgentServiceImpl.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 = "查询代理商已销售的卡券")

@ -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")

@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DeadlockLoserDataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@ -43,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 = "兑换码使用")
@ -64,14 +71,44 @@ public class HighCouponAgentController {
log.error("HighCouponAgentController -> queryConvertCode() error!","兑换码已被使用");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用");
}
if (convertCode.getCouponCodeId() != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用");
}
return ResponseMsgUtil.success(highCouponAgentService.useConvertCode(body.getString("code")));
} catch (DeadlockLoserDataAccessException deadlockLoserDataAccessException) {
log.error("HighActivityController -> userLottery() error!", "服务器繁忙");
return ResponseMsgUtil.builderResponse(ErrorCode.SERVER_BUSY_ERROR.getCode(),ErrorCode.SERVER_BUSY_ERROR.getMsg(),null);
} catch (Exception e) {
log.error("HighCouponAgentController --> useConvertCode() error!", e);
return ResponseMsgUtil.exception(e);
}
}
@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<String, Object> 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);
}
}
}

@ -9,6 +9,7 @@ import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;
import java.util.List;
import java.util.Map;
/**
@ -21,11 +22,11 @@ public interface HighCouponAgentRelMapperExt {
" case when sum(c.sales_price) is not null then sum(c.sales_price) else 0 end salesCountPrice " +
" 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 and b.consume_time >= #{consumeTimeS} and b.consume_time <= #{consumeTimeE}")
" and b.status = 3 and a.coupon_code_id = b.id and b.consume_time >= #{consumeTimeS} and b.consume_time <= #{consumeTimeE}")
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 +50,33 @@ 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);
@Select(" select " +
" a.id," +
" a.noUsedNum, " +
" (a.noUsedNum * a.price) noUsedPrice," +
" b.usedNum," +
" (b.usedNum * b.price) usedPrice" +
" from (" +
" select " +
" b.id," +
" count(1) noUsedNum," +
" b.sales_price price" +
" from high_coupon_agent_code a " +
" LEFT JOIN high_coupon_agent_rel b on b.id = a.coupon_agent_id" +
" where b.id = #{couponAgentRelId} and a.`status` = 2) a," +
" (select " +
" b.id," +
" count(1) usedNum," +
" b.sales_price price" +
" from high_coupon_agent_code a" +
" LEFT JOIN high_coupon_agent_rel b on b.id = a.coupon_agent_id" +
" where b.id = #{couponAgentRelId} and a.`status` = 3) b" +
" where a.id = b.id ")
Map<String, Object> getUseNum(@Param("couponAgentRelId") Long couponAgentRelId);
}

@ -3,6 +3,8 @@ package com.hai.model;
import com.hai.entity.HighAgent;
import com.hai.entity.HighCoupon;
import java.math.BigDecimal;
/**
* @Auther: 胡锐
* @Description:
@ -18,6 +20,18 @@ public class HighCouponAgentRelModel {
//代理商信息
private HighAgent highAgent;
// 未使用数量
private Integer noUsedNum;
// 未使用金额
private BigDecimal noUsedPrice;
// 使用数量
private Integer usedNum;
// 使用金额
private BigDecimal usedPrice;
public String getMerchantLogo() {
return merchantLogo;
}
@ -41,4 +55,36 @@ public class HighCouponAgentRelModel {
public void setHighAgent(HighAgent highAgent) {
this.highAgent = highAgent;
}
public Integer getNoUsedNum() {
return noUsedNum;
}
public void setNoUsedNum(Integer noUsedNum) {
this.noUsedNum = noUsedNum;
}
public BigDecimal getNoUsedPrice() {
return noUsedPrice;
}
public void setNoUsedPrice(BigDecimal noUsedPrice) {
this.noUsedPrice = noUsedPrice;
}
public Integer getUsedNum() {
return usedNum;
}
public void setUsedNum(Integer usedNum) {
this.usedNum = usedNum;
}
public BigDecimal getUsedPrice() {
return usedPrice;
}
public void setUsedPrice(BigDecimal usedPrice) {
this.usedPrice = usedPrice;
}
}

@ -80,6 +80,8 @@ public interface HighCouponAgentService {
**/
Map<String, Object> getSalesCountByAgent(Long agentId, Integer type) throws Exception;
Map<String, Object> getConvertCodeCountByAgent(Long agentId);
/**
*
* @param map
@ -123,6 +125,6 @@ public interface HighCouponAgentService {
* @param code
* @return
*/
String useConvertCode(String code);
Map<String, Object> useConvertCode(String code);
}

@ -311,6 +311,43 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
return returnMap;
}
@Override
public Map<String, Object> getConvertCodeCountByAgent(Long agentId) {
Map<String,Object> listMap = new HashMap<>();
listMap.put("agentId", agentId);
listMap.put("type", 2);
List<HighCouponAgentRel> list = getCouponAgentList(listMap).stream().sorted(Comparator.comparing(HighCouponAgentRel::getSalesPrice)).collect(Collectors.toList());
for (HighCouponAgentRel couponAgentRel : list) {
Map<String, Object> map = highCouponAgentRelMapper.getUseNum(couponAgentRel.getId());
couponAgentRel.setUsedNum(MapUtils.getInteger(map, "usedNum"));
couponAgentRel.setUsedPrice(new BigDecimal(MapUtils.getString(map, "usedPrice")));
couponAgentRel.setNoUsedNum(MapUtils.getInteger(map, "noUsedNum"));
couponAgentRel.setNoUsedPrice(new BigDecimal(MapUtils.getString(map, "noUsedPrice")));
}
Map<String, Object> 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<HighCouponAgentRecord> getRecordList(Map<String, Object> map) {
HighCouponAgentRecordExample example = new HighCouponAgentRecordExample();
@ -373,7 +410,7 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE)
public String useConvertCode(String code) {
public Map<String, Object> useConvertCode(String code) {
// 查询兑换码
HighCouponAgentCode convertCode = getConvertCode(code);
if (convertCode == null) {
@ -382,19 +419,32 @@ public class HighCouponAgentServiceImpl implements HighCouponAgentService {
if (convertCode.getStatus() == 3) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用");
}
if (convertCode.getCouponCodeId() != null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "兑换码已被使用");
}
// 查询未销售的卡券
List<HighCouponCode> codeList = highCouponCodeService.getNoSaleCode(convertCode.getCouponId());
if (codeList.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法使用兑换码");
}
HighCouponCode couponCode = codeList.get(0);
couponCode.setIsAssignAgent(true);
couponCode.setAgentId(couponCode.getAgentId());
couponCode.setReceiveTime(new Date());
couponCode.setStatus(2);
highCouponCodeService.updateCouponCode(couponCode);
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<String, Object> map = new HashMap<>();
map.put("couponInfo", highCouponService.getCouponById(convertCode.getCouponId()));
map.put("couponCode", highCouponCodeService.getCouponCodeById(convertCode.getCouponCodeId()));
map.put("couponAgentCode", convertCode);
return map;
}
}

Loading…
Cancel
Save