diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java index 43c8fa4d..769f094e 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -14,10 +14,7 @@ import com.hai.entity.*; import com.hai.model.HighCouponModel; import com.hai.model.HighUserModel; import com.hai.model.ResponseData; -import com.hai.service.HighCouponCodeService; -import com.hai.service.HighCouponService; -import com.hai.service.HighOrderService; -import com.hai.service.HighUserService; +import com.hai.service.*; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.slf4j.Logger; @@ -57,6 +54,9 @@ public class HighOrderController { @Resource private HighCouponCodeService highCouponCodeService; + @Resource + private HighDiscountUserRelService highDiscountUserRelService; + @Resource private HighUserService highUserService; @@ -137,11 +137,58 @@ public class HighOrderController { totalPrice = totalPrice.add(childOrder.getTotalPrice()); } + // 是否使用了优惠券 + if (highOrder.getMemDiscountId() != null) { + // 卡优惠券信息 + HighDiscountUserRel rel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); + if (rel == null || rel.getStatus() != 1) { + log.error("HighOrderController --> addOrder() error!", "优惠券状态错误"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误"); + } + highOrder.setMemDiscountName(rel.getHighDiscount().getDiscountName()); + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (rel.getHighDiscount().getDiscountType() == 1) { + // 如果订单总额 小于 满减价格 + if (highOrder.getTotalPrice().compareTo(rel.getHighDiscount().getDiscountCondition()) > 1) { + log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+rel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); + } + // 订单总额 - 满减额度 + BigDecimal total = highOrder.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); + // 如果总额小于0 + if (total.compareTo(new BigDecimal("0")) == -1) { + highOrder.setTotalPrice(new BigDecimal("0")); + } else { + highOrder.setTotalPrice(total); + } + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (rel.getHighDiscount().getDiscountType() == 2) { + // 订单总额 - 满减额度 + BigDecimal total = highOrder.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); + // 如果总额小于0 + if (total.compareTo(new BigDecimal("0")) == -1) { + highOrder.setTotalPrice(new BigDecimal("0")); + } else { + highOrder.setTotalPrice(total); + } + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (rel.getHighDiscount().getDiscountType() == 3) { + // 折扣除100 + BigDecimal discountPrice = rel.getHighDiscount().getDiscountPrice().divide(new BigDecimal("100")); + // 订单总额 * 折扣 + BigDecimal total = highOrder.getTotalPrice().multiply(discountPrice); + highOrder.setTotalPrice(total); + } + } + highOrder.setOrderNo("HF" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5)); highOrder.setMemId(userInfoModel.getHighUser().getId()); highOrder.setMemName(userInfoModel.getHighUser().getName()); highOrder.setMemPhone(userInfoModel.getHighUser().getPhone()); - highOrder.setTotalPrice(totalPrice); highOrder.setPayPrice(totalPrice); highOrder.setCreateTime(new Date()); highOrder.setOrderStatus(1); @@ -156,7 +203,6 @@ public class HighOrderController { } } - @RequestMapping(value = "/getOrderById", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "根据id查询订单详情") @@ -171,6 +217,68 @@ public class HighOrderController { } } +/* + @RequestMapping(value = "/calculateOrder", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "计算订单详情") + public ResponseData calculateOrder(@RequestParam(name = "orderId", required = true) Long orderId, + @RequestParam(name = "userDiscountId", required = false) Long userDiscountId) { + try { + + HighOrder order = highOrderService.getOrderById(orderId); + if (order != null && userDiscountId != null) { + // 卡优惠券信息 + HighDiscountUserRel rel = highDiscountUserRelService.getRelById(userDiscountId); + order.setMemDiscountId(userDiscountId); + order.setMemDiscountName(rel.getHighDiscount().getDiscountName()); + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (rel.getHighDiscount().getDiscountType() == 1) { + // 如果订单总额 小于 满减价格 + if (order.getTotalPrice().compareTo(rel.getHighDiscount().getDiscountCondition()) > 1) { + log.error("HighOrderController --> addOrder() error!", "订单未达到满减额度"); + throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到"+rel.getHighDiscount().getDiscountCondition()+"元,无法使用此优惠券"); + } + // 订单总额 - 满减额度 + BigDecimal totalPrice = order.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); + // 如果总额小于0 + if (totalPrice.compareTo(new BigDecimal("0")) == -1) { + order.setTotalPrice(new BigDecimal("0")); + } else { + order.setTotalPrice(totalPrice); + } + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (rel.getHighDiscount().getDiscountType() == 2) { + // 订单总额 - 满减额度 + BigDecimal totalPrice = order.getTotalPrice().subtract(rel.getHighDiscount().getDiscountPrice()); + // 如果总额小于0 + if (totalPrice.compareTo(new BigDecimal("0")) == -1) { + order.setTotalPrice(new BigDecimal("0")); + } else { + order.setTotalPrice(totalPrice); + } + } + + // 卡卷类型 1:满减 2:抵扣 3:折扣 + if (rel.getHighDiscount().getDiscountType() == 3) { + // 折扣除100 + BigDecimal discountPrice = rel.getHighDiscount().getDiscountPrice().divide(new BigDecimal("100")); + // 订单总额 * 折扣 + BigDecimal totalPrice = order.getTotalPrice().multiply(discountPrice); + order.setTotalPrice(totalPrice); + } + } + return ResponseMsgUtil.success(order); + + } catch (Exception e) { + log.error("HighOrderController --> cancelOrder() error!", e); + return ResponseMsgUtil.exception(e); + } + } +*/ + @RequestMapping(value = "/cancelOrder", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "取消订单") @@ -187,7 +295,6 @@ public class HighOrderController { } } - @RequestMapping(value = "/getUserOrderList", method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取用户订单") 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 a5f87994..e8e05613 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighUserDiscountController.java @@ -69,7 +69,7 @@ public class HighUserDiscountController { } } - @RequestMapping(value="/getUserDiscountList",method = RequestMethod.POST) + @RequestMapping(value="/getUserDiscountList",method = RequestMethod.GET) @ResponseBody @ApiOperation(value = "获取用户的优惠券列表") public ResponseData getUserDiscountList(@RequestParam(name = "status", required = false) Integer status, @@ -90,7 +90,28 @@ public class HighUserDiscountController { return ResponseMsgUtil.success(new PageInfo<>(highDiscountUserRelService.getDiscountList(map))); } catch (Exception e) { - log.error("HighDiscountController -> receiveDiscount() error!",e); + log.error("HighDiscountController -> getUserDiscountList() error!",e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value="/getUserNormalDiscountList",method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取用户的【可以使用】的优惠券列表") + public ResponseData getUserNormalDiscountList(HttpServletRequest request) { + try { + + // 用户 + SessionObject sessionObject = userCenter.getSessionObject(request); + HighUserModel userInfoModel = (HighUserModel) sessionObject.getObject(); + + Map map = new HashMap<>(); + map.put("userId", userInfoModel.getHighUser().getId()); + map.put("status", 1); + return ResponseMsgUtil.success(highDiscountUserRelService.getDiscountList(map)); + + } catch (Exception e) { + log.error("HighDiscountController -> getUserNormalDiscountList() error!",e); return ResponseMsgUtil.exception(e); } } diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java index 9a3e0d47..0e0f3fab 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelMapper.java @@ -40,13 +40,13 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Insert({ "insert into high_discount_user_rel (discount_id, agent_id, ", - "user_id, `status`, create_time, ", - "use_end_time, ext_1, ", - "ext_2, ext_3)", + "user_id, `status`, use_time, ", + "create_time, use_end_time, ", + "ext_1, ext_2, ext_3)", "values (#{discountId,jdbcType=BIGINT}, #{agentId,jdbcType=BIGINT}, ", - "#{userId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP}, ", - "#{useEndTime,jdbcType=TIMESTAMP}, #{ext1,jdbcType=VARCHAR}, ", - "#{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{userId,jdbcType=BIGINT}, #{status,jdbcType=INTEGER}, #{useTime,jdbcType=TIMESTAMP}, ", + "#{createTime,jdbcType=TIMESTAMP}, #{useEndTime,jdbcType=TIMESTAMP}, ", + "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighDiscountUserRel record); @@ -62,6 +62,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), + @Result(column="use_time", property="useTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="use_end_time", property="useEndTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @@ -72,8 +73,8 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Select({ "select", - "id, discount_id, agent_id, user_id, `status`, create_time, use_end_time, ext_1, ", - "ext_2, ext_3", + "id, discount_id, agent_id, user_id, `status`, use_time, create_time, use_end_time, ", + "ext_1, ext_2, ext_3", "from high_discount_user_rel", "where id = #{id,jdbcType=BIGINT}" }) @@ -83,6 +84,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt @Result(column="agent_id", property="agentId", jdbcType=JdbcType.BIGINT), @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), + @Result(column="use_time", property="useTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="use_end_time", property="useEndTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @@ -106,6 +108,7 @@ public interface HighDiscountUserRelMapper extends HighDiscountUserRelMapperExt "agent_id = #{agentId,jdbcType=BIGINT},", "user_id = #{userId,jdbcType=BIGINT},", "`status` = #{status,jdbcType=INTEGER},", + "use_time = #{useTime,jdbcType=TIMESTAMP},", "create_time = #{createTime,jdbcType=TIMESTAMP},", "use_end_time = #{useEndTime,jdbcType=TIMESTAMP},", "ext_1 = #{ext1,jdbcType=VARCHAR},", diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java index 4eda9831..54556153 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountUserRelSqlProvider.java @@ -44,6 +44,10 @@ public class HighDiscountUserRelSqlProvider { sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); } + if (record.getUseTime() != null) { + sql.VALUES("use_time", "#{useTime,jdbcType=TIMESTAMP}"); + } + if (record.getCreateTime() != null) { sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}"); } @@ -78,6 +82,7 @@ public class HighDiscountUserRelSqlProvider { sql.SELECT("agent_id"); sql.SELECT("user_id"); sql.SELECT("`status`"); + sql.SELECT("use_time"); sql.SELECT("create_time"); sql.SELECT("use_end_time"); sql.SELECT("ext_1"); @@ -120,6 +125,10 @@ public class HighDiscountUserRelSqlProvider { sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); } + if (record.getUseTime() != null) { + sql.SET("use_time = #{record.useTime,jdbcType=TIMESTAMP}"); + } + if (record.getCreateTime() != null) { sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); } @@ -153,6 +162,7 @@ public class HighDiscountUserRelSqlProvider { sql.SET("agent_id = #{record.agentId,jdbcType=BIGINT}"); sql.SET("user_id = #{record.userId,jdbcType=BIGINT}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); + sql.SET("use_time = #{record.useTime,jdbcType=TIMESTAMP}"); sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}"); sql.SET("use_end_time = #{record.useEndTime,jdbcType=TIMESTAMP}"); sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); @@ -184,6 +194,10 @@ public class HighDiscountUserRelSqlProvider { sql.SET("`status` = #{status,jdbcType=INTEGER}"); } + if (record.getUseTime() != null) { + sql.SET("use_time = #{useTime,jdbcType=TIMESTAMP}"); + } + if (record.getCreateTime() != null) { sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}"); } diff --git a/hai-service/src/main/java/com/hai/dao/HighOrderMapper.java b/hai-service/src/main/java/com/hai/dao/HighOrderMapper.java index bfd04edd..4ff79e64 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOrderMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighOrderMapper.java @@ -39,7 +39,8 @@ public interface HighOrderMapper extends HighOrderMapperExt { int deleteByPrimaryKey(Long id); @Insert({ - "insert into high_order (order_no, mem_id, ", + "insert into high_order (order_no, mem_discount_id, ", + "mem_discount_name, mem_id, ", "mem_name, mem_phone, ", "pay_model, pay_type, ", "pay_gold, pay_price, ", @@ -49,7 +50,8 @@ public interface HighOrderMapper extends HighOrderMapperExt { "cancel_time, finish_time, ", "remarks, ext_1, ext_2, ", "ext_3)", - "values (#{orderNo,jdbcType=VARCHAR}, #{memId,jdbcType=BIGINT}, ", + "values (#{orderNo,jdbcType=VARCHAR}, #{memDiscountId,jdbcType=BIGINT}, ", + "#{memDiscountName,jdbcType=VARCHAR}, #{memId,jdbcType=BIGINT}, ", "#{memName,jdbcType=VARCHAR}, #{memPhone,jdbcType=VARCHAR}, ", "#{payModel,jdbcType=INTEGER}, #{payType,jdbcType=INTEGER}, ", "#{payGold,jdbcType=INTEGER}, #{payPrice,jdbcType=DECIMAL}, ", @@ -71,6 +73,8 @@ public interface HighOrderMapper extends HighOrderMapperExt { @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="mem_discount_id", property="memDiscountId", jdbcType=JdbcType.BIGINT), + @Result(column="mem_discount_name", property="memDiscountName", jdbcType=JdbcType.VARCHAR), @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT), @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR), @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR), @@ -95,15 +99,18 @@ public interface HighOrderMapper extends HighOrderMapperExt { @Select({ "select", - "id, order_no, mem_id, mem_name, mem_phone, pay_model, pay_type, pay_gold, pay_price, ", - "pay_real_price, pay_serial_no, order_status, total_price, create_time, pay_time, ", - "cancel_time, finish_time, remarks, ext_1, ext_2, ext_3", + "id, order_no, mem_discount_id, mem_discount_name, mem_id, mem_name, mem_phone, ", + "pay_model, pay_type, pay_gold, pay_price, pay_real_price, pay_serial_no, order_status, ", + "total_price, create_time, pay_time, cancel_time, finish_time, remarks, ext_1, ", + "ext_2, ext_3", "from high_order", "where id = #{id,jdbcType=BIGINT}" }) @Results({ @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true), @Result(column="order_no", property="orderNo", jdbcType=JdbcType.VARCHAR), + @Result(column="mem_discount_id", property="memDiscountId", jdbcType=JdbcType.BIGINT), + @Result(column="mem_discount_name", property="memDiscountName", jdbcType=JdbcType.VARCHAR), @Result(column="mem_id", property="memId", jdbcType=JdbcType.BIGINT), @Result(column="mem_name", property="memName", jdbcType=JdbcType.VARCHAR), @Result(column="mem_phone", property="memPhone", jdbcType=JdbcType.VARCHAR), @@ -138,6 +145,8 @@ public interface HighOrderMapper extends HighOrderMapperExt { @Update({ "update high_order", "set order_no = #{orderNo,jdbcType=VARCHAR},", + "mem_discount_id = #{memDiscountId,jdbcType=BIGINT},", + "mem_discount_name = #{memDiscountName,jdbcType=VARCHAR},", "mem_id = #{memId,jdbcType=BIGINT},", "mem_name = #{memName,jdbcType=VARCHAR},", "mem_phone = #{memPhone,jdbcType=VARCHAR},", diff --git a/hai-service/src/main/java/com/hai/dao/HighOrderSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighOrderSqlProvider.java index 44792d07..a7207c04 100644 --- a/hai-service/src/main/java/com/hai/dao/HighOrderSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighOrderSqlProvider.java @@ -32,6 +32,14 @@ public class HighOrderSqlProvider { sql.VALUES("order_no", "#{orderNo,jdbcType=VARCHAR}"); } + if (record.getMemDiscountId() != null) { + sql.VALUES("mem_discount_id", "#{memDiscountId,jdbcType=BIGINT}"); + } + + if (record.getMemDiscountName() != null) { + sql.VALUES("mem_discount_name", "#{memDiscountName,jdbcType=VARCHAR}"); + } + if (record.getMemId() != null) { sql.VALUES("mem_id", "#{memId,jdbcType=BIGINT}"); } @@ -119,6 +127,8 @@ public class HighOrderSqlProvider { sql.SELECT("id"); } sql.SELECT("order_no"); + sql.SELECT("mem_discount_id"); + sql.SELECT("mem_discount_name"); sql.SELECT("mem_id"); sql.SELECT("mem_name"); sql.SELECT("mem_phone"); @@ -163,6 +173,14 @@ public class HighOrderSqlProvider { sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}"); } + if (record.getMemDiscountId() != null) { + sql.SET("mem_discount_id = #{record.memDiscountId,jdbcType=BIGINT}"); + } + + if (record.getMemDiscountName() != null) { + sql.SET("mem_discount_name = #{record.memDiscountName,jdbcType=VARCHAR}"); + } + if (record.getMemId() != null) { sql.SET("mem_id = #{record.memId,jdbcType=BIGINT}"); } @@ -249,6 +267,8 @@ public class HighOrderSqlProvider { sql.SET("id = #{record.id,jdbcType=BIGINT}"); sql.SET("order_no = #{record.orderNo,jdbcType=VARCHAR}"); + sql.SET("mem_discount_id = #{record.memDiscountId,jdbcType=BIGINT}"); + sql.SET("mem_discount_name = #{record.memDiscountName,jdbcType=VARCHAR}"); sql.SET("mem_id = #{record.memId,jdbcType=BIGINT}"); sql.SET("mem_name = #{record.memName,jdbcType=VARCHAR}"); sql.SET("mem_phone = #{record.memPhone,jdbcType=VARCHAR}"); @@ -282,6 +302,14 @@ public class HighOrderSqlProvider { sql.SET("order_no = #{orderNo,jdbcType=VARCHAR}"); } + if (record.getMemDiscountId() != null) { + sql.SET("mem_discount_id = #{memDiscountId,jdbcType=BIGINT}"); + } + + if (record.getMemDiscountName() != null) { + sql.SET("mem_discount_name = #{memDiscountName,jdbcType=VARCHAR}"); + } + if (record.getMemId() != null) { sql.SET("mem_id = #{memId,jdbcType=BIGINT}"); } diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java index 90197178..cfac7c4d 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRel.java @@ -40,6 +40,11 @@ public class HighDiscountUserRel extends HighDiscountUserRelModel implements Ser */ private Integer status; + /** + * 使用时间 + */ + private Date useTime; + /** * 创建时间 */ @@ -98,6 +103,14 @@ public class HighDiscountUserRel extends HighDiscountUserRelModel implements Ser this.status = status; } + public Date getUseTime() { + return useTime; + } + + public void setUseTime(Date useTime) { + this.useTime = useTime; + } + public Date getCreateTime() { return createTime; } @@ -155,6 +168,7 @@ public class HighDiscountUserRel extends HighDiscountUserRelModel implements Ser && (this.getAgentId() == null ? other.getAgentId() == null : this.getAgentId().equals(other.getAgentId())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) + && (this.getUseTime() == null ? other.getUseTime() == null : this.getUseTime().equals(other.getUseTime())) && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime())) && (this.getUseEndTime() == null ? other.getUseEndTime() == null : this.getUseEndTime().equals(other.getUseEndTime())) && (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1())) @@ -171,6 +185,7 @@ public class HighDiscountUserRel extends HighDiscountUserRelModel implements Ser result = prime * result + ((getAgentId() == null) ? 0 : getAgentId().hashCode()); result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); + result = prime * result + ((getUseTime() == null) ? 0 : getUseTime().hashCode()); result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode()); result = prime * result + ((getUseEndTime() == null) ? 0 : getUseEndTime().hashCode()); result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode()); @@ -190,6 +205,7 @@ public class HighDiscountUserRel extends HighDiscountUserRelModel implements Ser sb.append(", agentId=").append(agentId); sb.append(", userId=").append(userId); sb.append(", status=").append(status); + sb.append(", useTime=").append(useTime); sb.append(", createTime=").append(createTime); sb.append(", useEndTime=").append(useEndTime); sb.append(", ext1=").append(ext1); diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java index 2d0f92c9..bd364fd8 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountUserRelExample.java @@ -425,6 +425,66 @@ public class HighDiscountUserRelExample { return (Criteria) this; } + public Criteria andUseTimeIsNull() { + addCriterion("use_time is null"); + return (Criteria) this; + } + + public Criteria andUseTimeIsNotNull() { + addCriterion("use_time is not null"); + return (Criteria) this; + } + + public Criteria andUseTimeEqualTo(Date value) { + addCriterion("use_time =", value, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeNotEqualTo(Date value) { + addCriterion("use_time <>", value, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeGreaterThan(Date value) { + addCriterion("use_time >", value, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeGreaterThanOrEqualTo(Date value) { + addCriterion("use_time >=", value, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeLessThan(Date value) { + addCriterion("use_time <", value, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeLessThanOrEqualTo(Date value) { + addCriterion("use_time <=", value, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeIn(List values) { + addCriterion("use_time in", values, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeNotIn(List values) { + addCriterion("use_time not in", values, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeBetween(Date value1, Date value2) { + addCriterion("use_time between", value1, value2, "useTime"); + return (Criteria) this; + } + + public Criteria andUseTimeNotBetween(Date value1, Date value2) { + addCriterion("use_time not between", value1, value2, "useTime"); + return (Criteria) this; + } + public Criteria andCreateTimeIsNull() { addCriterion("create_time is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/entity/HighOrder.java b/hai-service/src/main/java/com/hai/entity/HighOrder.java index af2d41d5..87eba376 100644 --- a/hai-service/src/main/java/com/hai/entity/HighOrder.java +++ b/hai-service/src/main/java/com/hai/entity/HighOrder.java @@ -25,6 +25,16 @@ public class HighOrder implements Serializable { */ private String orderNo; + /** + * 用户的优惠券high_discount_user_rel表的id + */ + private Long memDiscountId; + + /** + * 用户的优惠券名称 + */ + private String memDiscountName; + /** * 用户表ID */ @@ -139,6 +149,22 @@ public class HighOrder implements Serializable { this.orderNo = orderNo; } + public Long getMemDiscountId() { + return memDiscountId; + } + + public void setMemDiscountId(Long memDiscountId) { + this.memDiscountId = memDiscountId; + } + + public String getMemDiscountName() { + return memDiscountName; + } + + public void setMemDiscountName(String memDiscountName) { + this.memDiscountName = memDiscountName; + } + public Long getMemId() { return memId; } @@ -305,6 +331,8 @@ public class HighOrder implements Serializable { HighOrder other = (HighOrder) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) && (this.getOrderNo() == null ? other.getOrderNo() == null : this.getOrderNo().equals(other.getOrderNo())) + && (this.getMemDiscountId() == null ? other.getMemDiscountId() == null : this.getMemDiscountId().equals(other.getMemDiscountId())) + && (this.getMemDiscountName() == null ? other.getMemDiscountName() == null : this.getMemDiscountName().equals(other.getMemDiscountName())) && (this.getMemId() == null ? other.getMemId() == null : this.getMemId().equals(other.getMemId())) && (this.getMemName() == null ? other.getMemName() == null : this.getMemName().equals(other.getMemName())) && (this.getMemPhone() == null ? other.getMemPhone() == null : this.getMemPhone().equals(other.getMemPhone())) @@ -332,6 +360,8 @@ public class HighOrder implements Serializable { int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); result = prime * result + ((getOrderNo() == null) ? 0 : getOrderNo().hashCode()); + result = prime * result + ((getMemDiscountId() == null) ? 0 : getMemDiscountId().hashCode()); + result = prime * result + ((getMemDiscountName() == null) ? 0 : getMemDiscountName().hashCode()); result = prime * result + ((getMemId() == null) ? 0 : getMemId().hashCode()); result = prime * result + ((getMemName() == null) ? 0 : getMemName().hashCode()); result = prime * result + ((getMemPhone() == null) ? 0 : getMemPhone().hashCode()); @@ -362,6 +392,8 @@ public class HighOrder implements Serializable { sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); sb.append(", orderNo=").append(orderNo); + sb.append(", memDiscountId=").append(memDiscountId); + sb.append(", memDiscountName=").append(memDiscountName); sb.append(", memId=").append(memId); sb.append(", memName=").append(memName); sb.append(", memPhone=").append(memPhone); diff --git a/hai-service/src/main/java/com/hai/entity/HighOrderExample.java b/hai-service/src/main/java/com/hai/entity/HighOrderExample.java index 3bdc3317..f674d4c3 100644 --- a/hai-service/src/main/java/com/hai/entity/HighOrderExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighOrderExample.java @@ -256,6 +256,136 @@ public class HighOrderExample { return (Criteria) this; } + public Criteria andMemDiscountIdIsNull() { + addCriterion("mem_discount_id is null"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdIsNotNull() { + addCriterion("mem_discount_id is not null"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdEqualTo(Long value) { + addCriterion("mem_discount_id =", value, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdNotEqualTo(Long value) { + addCriterion("mem_discount_id <>", value, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdGreaterThan(Long value) { + addCriterion("mem_discount_id >", value, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdGreaterThanOrEqualTo(Long value) { + addCriterion("mem_discount_id >=", value, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdLessThan(Long value) { + addCriterion("mem_discount_id <", value, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdLessThanOrEqualTo(Long value) { + addCriterion("mem_discount_id <=", value, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdIn(List values) { + addCriterion("mem_discount_id in", values, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdNotIn(List values) { + addCriterion("mem_discount_id not in", values, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdBetween(Long value1, Long value2) { + addCriterion("mem_discount_id between", value1, value2, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountIdNotBetween(Long value1, Long value2) { + addCriterion("mem_discount_id not between", value1, value2, "memDiscountId"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameIsNull() { + addCriterion("mem_discount_name is null"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameIsNotNull() { + addCriterion("mem_discount_name is not null"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameEqualTo(String value) { + addCriterion("mem_discount_name =", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameNotEqualTo(String value) { + addCriterion("mem_discount_name <>", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameGreaterThan(String value) { + addCriterion("mem_discount_name >", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameGreaterThanOrEqualTo(String value) { + addCriterion("mem_discount_name >=", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameLessThan(String value) { + addCriterion("mem_discount_name <", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameLessThanOrEqualTo(String value) { + addCriterion("mem_discount_name <=", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameLike(String value) { + addCriterion("mem_discount_name like", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameNotLike(String value) { + addCriterion("mem_discount_name not like", value, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameIn(List values) { + addCriterion("mem_discount_name in", values, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameNotIn(List values) { + addCriterion("mem_discount_name not in", values, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameBetween(String value1, String value2) { + addCriterion("mem_discount_name between", value1, value2, "memDiscountName"); + return (Criteria) this; + } + + public Criteria andMemDiscountNameNotBetween(String value1, String value2) { + addCriterion("mem_discount_name not between", value1, value2, "memDiscountName"); + return (Criteria) this; + } + public Criteria andMemIdIsNull() { addCriterion("mem_id is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java index 7778a594..81e316a7 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountUserRelService.java @@ -22,11 +22,25 @@ public interface HighDiscountUserRelService { /** * @Author 胡锐 - * @Description + * @Description 修改 + * @Date 2021/4/4 18:41 + **/ + void updateDiscountUserRel(HighDiscountUserRel highDiscountUserRel); + + /** + * @Author 胡锐 + * @Description 根据用户id和优惠券id查询 * @Date 2021/4/4 15:45 **/ HighDiscountUserRel getRelByUserDiscount(Long userId,Long discountId); + /** + * @Author 胡锐 + * @Description 根据id查询 + * @Date 2021/4/4 18:02 + **/ + HighDiscountUserRel getRelById(Long id); + /** * @Author 胡锐 * @Description 查询优惠券列表 diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java index c96d28a8..01cd9ac0 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountUserRelServiceImpl.java @@ -85,6 +85,11 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic } + @Override + public void updateDiscountUserRel(HighDiscountUserRel highDiscountUserRel) { + highDiscountUserRelMapper.updateByPrimaryKey(highDiscountUserRel); + } + @Override public HighDiscountUserRel getRelByUserDiscount(Long userId, Long discountId) { HighDiscountUserRelExample example = new HighDiscountUserRelExample(); @@ -96,6 +101,16 @@ public class HighDiscountUserRelServiceImpl implements HighDiscountUserRelServic return null; } + @Override + public HighDiscountUserRel getRelById(Long id) { + HighDiscountUserRel rel = highDiscountUserRelMapper.selectByPrimaryKey(id); + if(rel != null) { + rel.setHighDiscount(highDiscountService.getDiscountById(rel.getDiscountId())); + rel.setHighAgent(highAgentService.findByAgentMsgId(rel.getAgentId())); + } + return rel; + } + @Override public List getDiscountList(Map map) { HighDiscountUserRelExample example = new HighDiscountUserRelExample(); diff --git a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java index 6a96b002..0efe0c0b 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java @@ -57,12 +57,22 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighUserCouponMapper highUserCouponMapper; + @Resource + private HighDiscountUserRelService highDiscountUserRelService; @Override @Transactional(propagation= Propagation.REQUIRES_NEW) public void insertOrder(HighOrder highOrder) throws Exception { highOrderMapper.insert(highOrder); + // 使用优惠券 + if (highOrder.getMemDiscountId() != null) { + HighDiscountUserRel discountUserRel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId()); + discountUserRel.setUseTime(new Date()); // 使用时间 + discountUserRel.setStatus(2); //状态 0:已过期 1:未使用 2:已使用 + highDiscountUserRelService.updateDiscountUserRel(discountUserRel); + } + for (int i = 0; i < highOrder.getHighChildOrderList().size();i++) { HighChildOrder childOrder = highOrder.getHighChildOrderList().get(i); childOrder.setOrderId(highOrder.getId());