提交代码

dev-discount
胡锐 2 years ago
parent 8724386e31
commit 14704881a7
  1. 20
      hai-bweb/src/main/java/com/bweb/controller/HighDiscountAgentRelController.java
  2. 2
      hai-bweb/src/main/java/com/bweb/controller/HighDiscountController.java
  3. 65
      hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java
  4. 29
      hai-service/src/main/java/com/hai/dao/HighDiscountMapper.java
  5. 14
      hai-service/src/main/java/com/hai/dao/HighDiscountSqlProvider.java
  6. 4
      hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapperExt.java
  7. 16
      hai-service/src/main/java/com/hai/entity/HighDiscount.java
  8. 60
      hai-service/src/main/java/com/hai/entity/HighDiscountExample.java
  9. 7
      hai-service/src/main/java/com/hai/service/HighDiscountService.java
  10. 16
      hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java
  11. 11
      hai-service/src/main/java/com/hai/service/impl/HighDiscountServiceImpl.java
  12. 73
      hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java

@ -16,6 +16,7 @@ import com.hai.common.security.UserCenter;
import com.hai.common.utils.DateUtil; import com.hai.common.utils.DateUtil;
import com.hai.common.utils.IDGenerator; import com.hai.common.utils.IDGenerator;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.config.CommonSysConst;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.enum_type.QrCodeType; import com.hai.enum_type.QrCodeType;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
@ -31,6 +32,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -139,6 +141,24 @@ public class HighDiscountAgentRelController {
} }
} }
@RequestMapping(value="/getReceiveLink",method = RequestMethod.GET)
@ResponseBody
@ApiOperation(value = "获取领取链接")
public ResponseData getReceiveLink(@RequestParam(name = "id", required = true) Long id) {
try {
String param = URLEncoder.encode(AESEncodeUtil.aesEncrypt(id.toString()), "UTF-8");
String url = CommonSysConst.getSysConfig().getHsgDomainName() + "?p=" + param;
return ResponseMsgUtil.success(url);
} catch (Exception e) {
log.error("HighDiscountController -> getReceiveLink() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getDiscountAgentList",method = RequestMethod.GET) @RequestMapping(value="/getDiscountAgentList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "查询列表") @ApiOperation(value = "查询列表")

@ -63,6 +63,7 @@ public class HighDiscountController {
|| highDiscount.getDiscountType() == null || highDiscount.getDiscountType() == null
|| highDiscount.getDiscountPrice() == null || highDiscount.getDiscountPrice() == null
|| highDiscount.getEffectiveDay() == null || highDiscount.getEffectiveDay() == null
|| highDiscount.getReceiveNumber() == null
|| highDiscount.getUseScope() == null || highDiscount.getUseScope() == null
|| highDiscount.getSalesEndTime() == null) { || highDiscount.getSalesEndTime() == null) {
log.error("HighDiscountController -> insertDiscount() error!","参数错误"); log.error("HighDiscountController -> insertDiscount() error!","参数错误");
@ -113,6 +114,7 @@ public class HighDiscountController {
if (highDiscount.getId() == null if (highDiscount.getId() == null
|| StringUtils.isBlank(highDiscount.getDiscountName()) || StringUtils.isBlank(highDiscount.getDiscountName())
|| StringUtils.isBlank(highDiscount.getDiscountImg()) || StringUtils.isBlank(highDiscount.getDiscountImg())
|| highDiscount.getReceiveNumber() == null
|| highDiscount.getEffectiveDay() == null || highDiscount.getEffectiveDay() == null
|| highDiscount.getSalesEndTime() == null) { || highDiscount.getSalesEndTime() == null) {
log.error("HighDiscountController -> updateDiscount() error!","参数错误"); log.error("HighDiscountController -> updateDiscount() error!","参数错误");

@ -6,18 +6,17 @@ import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode; import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.security.SessionObject; import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter; import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil; import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.*; import com.hai.entity.*;
import com.hai.model.HighUserModel; import com.hai.model.HighUserModel;
import com.hai.model.ResponseData; import com.hai.model.ResponseData;
import com.hai.service.HighDiscountAgentCodeService; import com.hai.service.*;
import com.hai.service.HighDiscountCouponRelService;
import com.hai.service.HighDiscountUserRelService;
import com.hai.service.HighOpenApiService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -27,6 +26,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -45,6 +45,12 @@ public class HighUserDiscountController {
@Autowired @Autowired
private UserCenter userCenter; private UserCenter userCenter;
@Resource
private HighDiscountService discountService;
@Resource
private HighDiscountAgentRelService discountAgentRelService;
@Resource @Resource
private HighDiscountUserRelService highDiscountUserRelService; private HighDiscountUserRelService highDiscountUserRelService;
@ -56,7 +62,7 @@ public class HighUserDiscountController {
@RequestMapping(value="/receiveDiscount",method = RequestMethod.POST) @RequestMapping(value="/receiveDiscount",method = RequestMethod.POST)
@ResponseBody @ResponseBody
@ApiOperation(value = "用户领取优惠券") @ApiOperation(value = "用户领取优惠券码【领取优惠码值】")
public ResponseData receiveDiscount(@RequestBody String reqBody, HttpServletRequest request) { public ResponseData receiveDiscount(@RequestBody String reqBody, HttpServletRequest request) {
try { try {
@ -70,6 +76,7 @@ public class HighUserDiscountController {
log.error("HighDiscountController -> receiveDiscount() error!", "参数错误"); log.error("HighDiscountController -> receiveDiscount() error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, ""); throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
} }
// 领取 // 领取
highDiscountUserRelService.receiveDiscount(userInfoModel.getHighUser().getId(), codeId); highDiscountUserRelService.receiveDiscount(userInfoModel.getHighUser().getId(), codeId);
return ResponseMsgUtil.success("领取成功"); return ResponseMsgUtil.success("领取成功");
@ -84,6 +91,54 @@ public class HighUserDiscountController {
} }
} }
@RequestMapping(value="/receive",method = RequestMethod.POST)
@ResponseBody
@ApiOperation(value = "用户领取优惠券【领取优惠】")
public ResponseData receive(@RequestBody String reqBody, HttpServletRequest request) {
try {
// 用户
SessionObject sessionObject = userCenter.getSessionObject(request);
HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject();
JSONObject jsonObject = JSONObject.parseObject(reqBody);
String discountAgentCode = jsonObject.getString("code");
if (StringUtils.isNotBlank(discountAgentCode)) {
log.error("HighDiscountController -> receiveDiscount() error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
// 解密
String discountAgentId = AESEncodeUtil.aesDecrypt(URLDecoder.decode(discountAgentCode, "UTF-8"));
HighDiscountAgentRel discountAgentRel = discountAgentRelService.getRelById(Long.parseLong(discountAgentId));
if (discountAgentRel == null) {
log.error("HighDiscountController -> receiveDiscount() error!", "参数错误");
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券");
}
// 查询优惠券信息
HighDiscount discount = discountService.getDiscountById(discountAgentRel.getDiscountId());
if (discount == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券");
}
if (!discount.getStatus().equals(2)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券活动已过期");
}
// 领取
highDiscountUserRelService.receive(userInfoModel.getHighUser().getId(), discountAgentRel.getId());
return ResponseMsgUtil.success("领取成功");
} 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("HighDiscountController -> receiveDiscount() error!",e);
return ResponseMsgUtil.exception(e);
}
}
@RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET) @RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET)
@ResponseBody @ResponseBody
@ApiOperation(value = "获取用户的优惠券列表") @ApiOperation(value = "获取用户的优惠券列表")

@ -44,21 +44,21 @@ public interface HighDiscountMapper extends HighDiscountMapperExt {
"discount_name, discount_img, ", "discount_name, discount_img, ",
"discount_carousel_img, discount_type, ", "discount_carousel_img, discount_type, ",
"discount_condition, discount_price, ", "discount_condition, discount_price, ",
"effective_day, sales_end_time, ", "receive_number, effective_day, ",
"create_time, update_time, ", "sales_end_time, create_time, ",
"operator_id, operator_name, ", "update_time, operator_id, ",
"`status`, ext_1, ext_2, ", "operator_name, `status`, ",
"ext_3)", "ext_1, ext_2, ext_3)",
"values (#{companyId,jdbcType=BIGINT}, #{discountKey,jdbcType=VARCHAR}, ", "values (#{companyId,jdbcType=BIGINT}, #{discountKey,jdbcType=VARCHAR}, ",
"#{usingRange,jdbcType=INTEGER}, #{useScope,jdbcType=INTEGER}, ", "#{usingRange,jdbcType=INTEGER}, #{useScope,jdbcType=INTEGER}, ",
"#{discountName,jdbcType=VARCHAR}, #{discountImg,jdbcType=VARCHAR}, ", "#{discountName,jdbcType=VARCHAR}, #{discountImg,jdbcType=VARCHAR}, ",
"#{discountCarouselImg,jdbcType=VARCHAR}, #{discountType,jdbcType=INTEGER}, ", "#{discountCarouselImg,jdbcType=VARCHAR}, #{discountType,jdbcType=INTEGER}, ",
"#{discountCondition,jdbcType=DECIMAL}, #{discountPrice,jdbcType=DECIMAL}, ", "#{discountCondition,jdbcType=DECIMAL}, #{discountPrice,jdbcType=DECIMAL}, ",
"#{effectiveDay,jdbcType=INTEGER}, #{salesEndTime,jdbcType=TIMESTAMP}, ", "#{receiveNumber,jdbcType=INTEGER}, #{effectiveDay,jdbcType=INTEGER}, ",
"#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ", "#{salesEndTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, ",
"#{operatorId,jdbcType=BIGINT}, #{operatorName,jdbcType=VARCHAR}, ", "#{updateTime,jdbcType=TIMESTAMP}, #{operatorId,jdbcType=BIGINT}, ",
"#{status,jdbcType=INTEGER}, #{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, ", "#{operatorName,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
"#{ext3,jdbcType=VARCHAR})" "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
}) })
@Options(useGeneratedKeys=true,keyProperty="id") @Options(useGeneratedKeys=true,keyProperty="id")
int insert(HighDiscount record); int insert(HighDiscount record);
@ -80,6 +80,7 @@ public interface HighDiscountMapper extends HighDiscountMapperExt {
@Result(column="discount_type", property="discountType", jdbcType=JdbcType.INTEGER), @Result(column="discount_type", property="discountType", jdbcType=JdbcType.INTEGER),
@Result(column="discount_condition", property="discountCondition", jdbcType=JdbcType.DECIMAL), @Result(column="discount_condition", property="discountCondition", jdbcType=JdbcType.DECIMAL),
@Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.DECIMAL), @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.DECIMAL),
@Result(column="receive_number", property="receiveNumber", jdbcType=JdbcType.INTEGER),
@Result(column="effective_day", property="effectiveDay", jdbcType=JdbcType.INTEGER), @Result(column="effective_day", property="effectiveDay", jdbcType=JdbcType.INTEGER),
@Result(column="sales_end_time", property="salesEndTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="sales_end_time", property="salesEndTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@ -96,9 +97,9 @@ public interface HighDiscountMapper extends HighDiscountMapperExt {
@Select({ @Select({
"select", "select",
"id, company_id, discount_key, using_range, use_scope, discount_name, discount_img, ", "id, company_id, discount_key, using_range, use_scope, discount_name, discount_img, ",
"discount_carousel_img, discount_type, discount_condition, discount_price, effective_day, ", "discount_carousel_img, discount_type, discount_condition, discount_price, receive_number, ",
"sales_end_time, create_time, update_time, operator_id, operator_name, `status`, ", "effective_day, sales_end_time, create_time, update_time, operator_id, operator_name, ",
"ext_1, ext_2, ext_3", "`status`, ext_1, ext_2, ext_3",
"from high_discount", "from high_discount",
"where id = #{id,jdbcType=BIGINT}" "where id = #{id,jdbcType=BIGINT}"
}) })
@ -114,6 +115,7 @@ public interface HighDiscountMapper extends HighDiscountMapperExt {
@Result(column="discount_type", property="discountType", jdbcType=JdbcType.INTEGER), @Result(column="discount_type", property="discountType", jdbcType=JdbcType.INTEGER),
@Result(column="discount_condition", property="discountCondition", jdbcType=JdbcType.DECIMAL), @Result(column="discount_condition", property="discountCondition", jdbcType=JdbcType.DECIMAL),
@Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.DECIMAL), @Result(column="discount_price", property="discountPrice", jdbcType=JdbcType.DECIMAL),
@Result(column="receive_number", property="receiveNumber", jdbcType=JdbcType.INTEGER),
@Result(column="effective_day", property="effectiveDay", jdbcType=JdbcType.INTEGER), @Result(column="effective_day", property="effectiveDay", jdbcType=JdbcType.INTEGER),
@Result(column="sales_end_time", property="salesEndTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="sales_end_time", property="salesEndTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@ -148,6 +150,7 @@ public interface HighDiscountMapper extends HighDiscountMapperExt {
"discount_type = #{discountType,jdbcType=INTEGER},", "discount_type = #{discountType,jdbcType=INTEGER},",
"discount_condition = #{discountCondition,jdbcType=DECIMAL},", "discount_condition = #{discountCondition,jdbcType=DECIMAL},",
"discount_price = #{discountPrice,jdbcType=DECIMAL},", "discount_price = #{discountPrice,jdbcType=DECIMAL},",
"receive_number = #{receiveNumber,jdbcType=INTEGER},",
"effective_day = #{effectiveDay,jdbcType=INTEGER},", "effective_day = #{effectiveDay,jdbcType=INTEGER},",
"sales_end_time = #{salesEndTime,jdbcType=TIMESTAMP},", "sales_end_time = #{salesEndTime,jdbcType=TIMESTAMP},",
"create_time = #{createTime,jdbcType=TIMESTAMP},", "create_time = #{createTime,jdbcType=TIMESTAMP},",

@ -68,6 +68,10 @@ public class HighDiscountSqlProvider {
sql.VALUES("discount_price", "#{discountPrice,jdbcType=DECIMAL}"); sql.VALUES("discount_price", "#{discountPrice,jdbcType=DECIMAL}");
} }
if (record.getReceiveNumber() != null) {
sql.VALUES("receive_number", "#{receiveNumber,jdbcType=INTEGER}");
}
if (record.getEffectiveDay() != null) { if (record.getEffectiveDay() != null) {
sql.VALUES("effective_day", "#{effectiveDay,jdbcType=INTEGER}"); sql.VALUES("effective_day", "#{effectiveDay,jdbcType=INTEGER}");
} }
@ -128,6 +132,7 @@ public class HighDiscountSqlProvider {
sql.SELECT("discount_type"); sql.SELECT("discount_type");
sql.SELECT("discount_condition"); sql.SELECT("discount_condition");
sql.SELECT("discount_price"); sql.SELECT("discount_price");
sql.SELECT("receive_number");
sql.SELECT("effective_day"); sql.SELECT("effective_day");
sql.SELECT("sales_end_time"); sql.SELECT("sales_end_time");
sql.SELECT("create_time"); sql.SELECT("create_time");
@ -199,6 +204,10 @@ public class HighDiscountSqlProvider {
sql.SET("discount_price = #{record.discountPrice,jdbcType=DECIMAL}"); sql.SET("discount_price = #{record.discountPrice,jdbcType=DECIMAL}");
} }
if (record.getReceiveNumber() != null) {
sql.SET("receive_number = #{record.receiveNumber,jdbcType=INTEGER}");
}
if (record.getEffectiveDay() != null) { if (record.getEffectiveDay() != null) {
sql.SET("effective_day = #{record.effectiveDay,jdbcType=INTEGER}"); sql.SET("effective_day = #{record.effectiveDay,jdbcType=INTEGER}");
} }
@ -258,6 +267,7 @@ public class HighDiscountSqlProvider {
sql.SET("discount_type = #{record.discountType,jdbcType=INTEGER}"); sql.SET("discount_type = #{record.discountType,jdbcType=INTEGER}");
sql.SET("discount_condition = #{record.discountCondition,jdbcType=DECIMAL}"); sql.SET("discount_condition = #{record.discountCondition,jdbcType=DECIMAL}");
sql.SET("discount_price = #{record.discountPrice,jdbcType=DECIMAL}"); sql.SET("discount_price = #{record.discountPrice,jdbcType=DECIMAL}");
sql.SET("receive_number = #{record.receiveNumber,jdbcType=INTEGER}");
sql.SET("effective_day = #{record.effectiveDay,jdbcType=INTEGER}"); sql.SET("effective_day = #{record.effectiveDay,jdbcType=INTEGER}");
sql.SET("sales_end_time = #{record.salesEndTime,jdbcType=TIMESTAMP}"); sql.SET("sales_end_time = #{record.salesEndTime,jdbcType=TIMESTAMP}");
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
@ -318,6 +328,10 @@ public class HighDiscountSqlProvider {
sql.SET("discount_price = #{discountPrice,jdbcType=DECIMAL}"); sql.SET("discount_price = #{discountPrice,jdbcType=DECIMAL}");
} }
if (record.getReceiveNumber() != null) {
sql.SET("receive_number = #{receiveNumber,jdbcType=INTEGER}");
}
if (record.getEffectiveDay() != null) { if (record.getEffectiveDay() != null) {
sql.SET("effective_day = #{effectiveDay,jdbcType=INTEGER}"); sql.SET("effective_day = #{effectiveDay,jdbcType=INTEGER}");
} }

@ -39,4 +39,8 @@ public interface HighDiscountUserRelMapperExt {
" ORDER BY hdur.create_time desc" + " ORDER BY hdur.create_time desc" +
"</script>"}) "</script>"})
List<HighUserDiscountUnicomModel> getUserCouponsList(@Param("map") Map<String,Object> map); List<HighUserDiscountUnicomModel> getUserCouponsList(@Param("map") Map<String,Object> map);
@Select({" <![CDATA[ select count(1) count from high_discount_user_rel where user_id = #{userId} and discount_id = #{discountId} and `status` <> 100 ]]> "})
Integer receiveDiscountCount(@Param("userId") Long userId, @Param("discountId") Long discountId);
} }

@ -69,6 +69,11 @@ public class HighDiscount implements Serializable {
*/ */
private BigDecimal discountPrice; private BigDecimal discountPrice;
/**
* 领取次数
*/
private Integer receiveNumber;
/** /**
* 领取有效天数 * 领取有效天数
*/ */
@ -200,6 +205,14 @@ public class HighDiscount implements Serializable {
this.discountPrice = discountPrice; this.discountPrice = discountPrice;
} }
public Integer getReceiveNumber() {
return receiveNumber;
}
public void setReceiveNumber(Integer receiveNumber) {
this.receiveNumber = receiveNumber;
}
public Integer getEffectiveDay() { public Integer getEffectiveDay() {
return effectiveDay; return effectiveDay;
} }
@ -303,6 +316,7 @@ public class HighDiscount implements Serializable {
&& (this.getDiscountType() == null ? other.getDiscountType() == null : this.getDiscountType().equals(other.getDiscountType())) && (this.getDiscountType() == null ? other.getDiscountType() == null : this.getDiscountType().equals(other.getDiscountType()))
&& (this.getDiscountCondition() == null ? other.getDiscountCondition() == null : this.getDiscountCondition().equals(other.getDiscountCondition())) && (this.getDiscountCondition() == null ? other.getDiscountCondition() == null : this.getDiscountCondition().equals(other.getDiscountCondition()))
&& (this.getDiscountPrice() == null ? other.getDiscountPrice() == null : this.getDiscountPrice().equals(other.getDiscountPrice())) && (this.getDiscountPrice() == null ? other.getDiscountPrice() == null : this.getDiscountPrice().equals(other.getDiscountPrice()))
&& (this.getReceiveNumber() == null ? other.getReceiveNumber() == null : this.getReceiveNumber().equals(other.getReceiveNumber()))
&& (this.getEffectiveDay() == null ? other.getEffectiveDay() == null : this.getEffectiveDay().equals(other.getEffectiveDay())) && (this.getEffectiveDay() == null ? other.getEffectiveDay() == null : this.getEffectiveDay().equals(other.getEffectiveDay()))
&& (this.getSalesEndTime() == null ? other.getSalesEndTime() == null : this.getSalesEndTime().equals(other.getSalesEndTime())) && (this.getSalesEndTime() == null ? other.getSalesEndTime() == null : this.getSalesEndTime().equals(other.getSalesEndTime()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
@ -330,6 +344,7 @@ public class HighDiscount implements Serializable {
result = prime * result + ((getDiscountType() == null) ? 0 : getDiscountType().hashCode()); result = prime * result + ((getDiscountType() == null) ? 0 : getDiscountType().hashCode());
result = prime * result + ((getDiscountCondition() == null) ? 0 : getDiscountCondition().hashCode()); result = prime * result + ((getDiscountCondition() == null) ? 0 : getDiscountCondition().hashCode());
result = prime * result + ((getDiscountPrice() == null) ? 0 : getDiscountPrice().hashCode()); result = prime * result + ((getDiscountPrice() == null) ? 0 : getDiscountPrice().hashCode());
result = prime * result + ((getReceiveNumber() == null) ? 0 : getReceiveNumber().hashCode());
result = prime * result + ((getEffectiveDay() == null) ? 0 : getEffectiveDay().hashCode()); result = prime * result + ((getEffectiveDay() == null) ? 0 : getEffectiveDay().hashCode());
result = prime * result + ((getSalesEndTime() == null) ? 0 : getSalesEndTime().hashCode()); result = prime * result + ((getSalesEndTime() == null) ? 0 : getSalesEndTime().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
@ -360,6 +375,7 @@ public class HighDiscount implements Serializable {
sb.append(", discountType=").append(discountType); sb.append(", discountType=").append(discountType);
sb.append(", discountCondition=").append(discountCondition); sb.append(", discountCondition=").append(discountCondition);
sb.append(", discountPrice=").append(discountPrice); sb.append(", discountPrice=").append(discountPrice);
sb.append(", receiveNumber=").append(receiveNumber);
sb.append(", effectiveDay=").append(effectiveDay); sb.append(", effectiveDay=").append(effectiveDay);
sb.append(", salesEndTime=").append(salesEndTime); sb.append(", salesEndTime=").append(salesEndTime);
sb.append(", createTime=").append(createTime); sb.append(", createTime=").append(createTime);

@ -826,6 +826,66 @@ public class HighDiscountExample {
return (Criteria) this; return (Criteria) this;
} }
public Criteria andReceiveNumberIsNull() {
addCriterion("receive_number is null");
return (Criteria) this;
}
public Criteria andReceiveNumberIsNotNull() {
addCriterion("receive_number is not null");
return (Criteria) this;
}
public Criteria andReceiveNumberEqualTo(Integer value) {
addCriterion("receive_number =", value, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberNotEqualTo(Integer value) {
addCriterion("receive_number <>", value, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberGreaterThan(Integer value) {
addCriterion("receive_number >", value, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberGreaterThanOrEqualTo(Integer value) {
addCriterion("receive_number >=", value, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberLessThan(Integer value) {
addCriterion("receive_number <", value, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberLessThanOrEqualTo(Integer value) {
addCriterion("receive_number <=", value, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberIn(List<Integer> values) {
addCriterion("receive_number in", values, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberNotIn(List<Integer> values) {
addCriterion("receive_number not in", values, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberBetween(Integer value1, Integer value2) {
addCriterion("receive_number between", value1, value2, "receiveNumber");
return (Criteria) this;
}
public Criteria andReceiveNumberNotBetween(Integer value1, Integer value2) {
addCriterion("receive_number not between", value1, value2, "receiveNumber");
return (Criteria) this;
}
public Criteria andEffectiveDayIsNull() { public Criteria andEffectiveDayIsNull() {
addCriterion("effective_day is null"); addCriterion("effective_day is null");
return (Criteria) this; return (Criteria) this;

@ -33,6 +33,13 @@ public interface HighDiscountService {
**/ **/
HighDiscount getDiscountById(Long id); HighDiscount getDiscountById(Long id);
/**
* 根据优惠券key查询
* @param discountKey
* @return
*/
HighDiscount getDiscountByKey(String discountKey);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 查询优惠券列表 * @Description 查询优惠券列表

@ -15,11 +15,18 @@ public interface HighDiscountUserRelService {
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 领取优惠券 * @Description 领取优惠券code
* @Date 2021/4/4 15:12 * @Date 2021/4/4 15:12
**/ **/
void receiveDiscount(Long userId,Long codeId); void receiveDiscount(Long userId,Long codeId);
/**
* @Author 胡锐
* @Description 领取优惠券
* @Date 2021/4/4 15:12
**/
void receive(Long userId, Long discountAgentId);
/** /**
* @Author 胡锐 * @Author 胡锐
* @Description 修改 * @Description 修改
@ -62,5 +69,12 @@ public interface HighDiscountUserRelService {
**/ **/
List<HighDiscountUserRel> getExpiredDiscount(); List<HighDiscountUserRel> getExpiredDiscount();
/**
* 领取优惠券统计
* @param userId
* @param discountId
* @return
*/
Integer receiveDiscountCount(Long userId,Long discountId);
} }

@ -39,6 +39,17 @@ public class HighDiscountServiceImpl implements HighDiscountService {
return highDiscountMapper.selectByPrimaryKey(id); return highDiscountMapper.selectByPrimaryKey(id);
} }
@Override
public HighDiscount getDiscountByKey(String discountKey) {
HighDiscountExample example = new HighDiscountExample();
example.createCriteria().andDiscountKeyEqualTo(discountKey).andStatusNotEqualTo(0);
List<HighDiscount> list = highDiscountMapper.selectByExample(example);
if (list.size() > 0) {
return list.get(0);
}
return null;
}
@Override @Override
public List<HighDiscount> getDiscount(Map<String, Object> map) { public List<HighDiscount> getDiscount(Map<String, Object> map) {
HighDiscountExample example = new HighDiscountExample(); HighDiscountExample example = new HighDiscountExample();

@ -51,7 +51,6 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
if(code == null) { if(code == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在");
} }
// 状态 0:删除 1:待领取 2:待使用 3:已使用 4:已过期 5: 已分配 // 状态 0:删除 1:待领取 2:待使用 3:已使用 4:已过期 5: 已分配
if(code.getStatus() != 1 && code.getStatus() != 5) { if(code.getStatus() != 1 && code.getStatus() != 5) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在或已被领取"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "二维码不存在或已被领取");
@ -67,6 +66,18 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
rel.setStockCount(rel.getStockCount() - 1); rel.setStockCount(rel.getStockCount() - 1);
highDiscountAgentRelService.updateDiscountAgentRel(rel); highDiscountAgentRelService.updateDiscountAgentRel(rel);
// 查询优惠券信息
HighDiscount discount = highDiscountService.getDiscountById(rel.getDiscountId());
if (discount == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的优惠券信息");
}
if (!discount.getStatus().equals(2)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券活动已过期");
}
if (discount.getReceiveNumber() > 0 && this.receiveDiscountCount(userId, discount.getId()) < discount.getReceiveNumber()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已达到上线");
}
// 校验卡卷状态 // 校验卡卷状态
if (rel.getHighDiscount().getStatus() != 2) { if (rel.getHighDiscount().getStatus() != 2) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券已过期"); throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券已过期");
@ -106,6 +117,61 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
} }
@Override
@Transactional(propagation= Propagation.REQUIRES_NEW,isolation= Isolation.SERIALIZABLE)
public void receive(Long userId, Long discountAgentId) {
// 查询优惠券与代理商关系
HighDiscountAgentRel discountAgentRel = highDiscountAgentRelService.getRelById(discountAgentId);
if (discountAgentRel == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券");
}
// 查询优惠券信息
HighDiscount discount = discountAgentRel.getHighDiscount();
if (discount == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知优惠券");
}
if (!discount.getStatus().equals(2)) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法领取,优惠券活动已过期");
}
if (discount.getReceiveNumber() > 0 && this.receiveDiscountCount(userId, discount.getId()) < discount.getReceiveNumber()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已达到上线");
}
// 查询可分配的优惠券code
List<HighDiscountAgentCode> discountAgentCodeList = highDiscountAgentCodeService.getDiscountCodeByDiscountAgentId(discountAgentRel.getId());
if (discountAgentCodeList.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券已无库存");
}
HighDiscountAgentCode code = discountAgentCodeList.get(0);
code.setStatus(2);
highDiscountAgentCodeService.updateCode(code);
// 查询优惠券信息
discountAgentRel.setStockCount(discountAgentRel.getStockCount() - 1);
highDiscountAgentRelService.updateDiscountAgentRel(discountAgentRel);
HighDiscountUserRel userRel = new HighDiscountUserRel();
userRel.setDiscountId(discountAgentRel.getDiscountId());
userRel.setAgentId(discountAgentRel.getAgentId());
userRel.setUserId(userId);
userRel.setStatus(1); // 状态 0:已过期 1:未使用 2:已使用
userRel.setCreateTime(new Date());
userRel.setDiscountAgentCodeId(code.getId());
// 计算使用有效期
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, discountAgentRel.getHighDiscount().getEffectiveDay());
if (userEndTime.getTime().compareTo(discountAgentRel.getHighDiscount().getSalesEndTime()) == 1) {
userRel.setUseEndTime(discountAgentRel.getHighDiscount().getSalesEndTime());
} else {
userRel.setUseEndTime(userEndTime.getTime());
}
highDiscountUserRelMapper.insert(userRel);
}
@Override @Override
public void updateDiscountUserRel(HighDiscountUserRel highDiscountUserRel) { public void updateDiscountUserRel(HighDiscountUserRel highDiscountUserRel) {
highDiscountUserRelMapper.updateByPrimaryKey(highDiscountUserRel); highDiscountUserRelMapper.updateByPrimaryKey(highDiscountUserRel);
@ -171,4 +237,9 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic
example.createCriteria().andStatusEqualTo(1).andUseEndTimeLessThanOrEqualTo(new Date()); example.createCriteria().andStatusEqualTo(1).andUseEndTimeLessThanOrEqualTo(new Date());
return highDiscountUserRelMapper.selectByExample(example); return highDiscountUserRelMapper.selectByExample(example);
} }
@Override
public Integer receiveDiscountCount(Long userId, Long discountId) {
return highDiscountUserRelMapper.receiveDiscountCount(userId, discountId);
}
} }

Loading…
Cancel
Save