diff --git a/hai-cweb/src/main/java/com/cweb/controller/HighDiscountPackageController.java b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountPackageController.java new file mode 100644 index 00000000..f80cc680 --- /dev/null +++ b/hai-cweb/src/main/java/com/cweb/controller/HighDiscountPackageController.java @@ -0,0 +1,118 @@ +package com.cweb.controller; + +import com.alibaba.fastjson.JSONObject; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; +import com.hai.common.exception.ErrorCode; +import com.hai.common.exception.ErrorHelp; +import com.hai.common.exception.SysCode; +import com.hai.common.security.SessionObject; +import com.hai.common.security.UserCenter; +import com.hai.common.utils.ResponseMsgUtil; +import com.hai.entity.*; +import com.hai.model.ResponseData; +import com.hai.model.UserInfoModel; +import com.hai.service.*; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.*; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Controller +@RequestMapping(value = "/discountPackage") +@Api(value = "优惠券包接口") +public class HighDiscountPackageController { + + private static Logger log = LoggerFactory.getLogger(HighDiscountPackageController.class); + + @Autowired + private UserCenter userCenter; + + @Resource + private CommonService commonService; + + @Resource + private BsCompanyService bsCompanyService; + + @Resource + private HighDiscountPackageService highDiscountPackageService; + + @Resource + private HighDiscountPackageDetailsService highDiscountPackageDetailsService; + + @Resource + private HighDiscountService highDiscountService; + + @RequestMapping(value = "/getDiscountPackageList", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取优惠券包列表") + public ResponseData getDiscountPackageList(@RequestParam(name = "regionId", required = true) String regionId, + @RequestParam(name = "usingAttribution", required = false) Integer usingAttribution, + @RequestParam(name = "title", required = false) String title, + @RequestParam(name = "pageNum", required = true) Integer pageNum, + @RequestParam(name = "pageSize", required = true) Integer pageSize) { + try { + + SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId)); + if (region != null) { + BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString()); + if (bsCompany != null) { + Map map = new HashMap<>(); + map.put("companyId", bsCompany.getId()); + map.put("usingAttribution", usingAttribution); + map.put("title" , title); + map.put("salesType" , 1); + map.put("status" , 1); + PageHelper.startPage(pageNum, pageSize); + return ResponseMsgUtil.success(new PageInfo<>(highDiscountPackageService.getDiscountPackageList(map))); + } + } + return ResponseMsgUtil.success(new PageInfo<>()); + + } catch (Exception e) { + log.error("HighDiscountPackageController --> getDiscountPackageList() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + @RequestMapping(value = "/getDiscountPackageDetail", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "获取优惠券包详情") + public ResponseData getDiscountPackageDetail(@RequestParam(name = "packageId", required = true) Integer packageId) { + try { + + Map map = new HashMap<>(); + + HighDiscountPackage discountPackage = highDiscountPackageService.findDiscountPackageById(packageId); + if (discountPackage != null) { + map.put("packageDetail", discountPackage); + // 查询包内的优惠券 + List detailsList = highDiscountPackageDetailsService.getDetailByPackage(packageId); + for (HighDiscountPackageDetails discount: detailsList) { + discount.setDiscountDetail(highDiscountService.getDiscountById(Long.parseLong(discount.getDiscountId().toString()))); + } + map.put("discountList", detailsList); + return ResponseMsgUtil.success(map); + } + return ResponseMsgUtil.success(null); + + } catch (Exception e) { + log.error("HighDiscountPackageController --> getDiscountPackageDetail() error!", e); + return ResponseMsgUtil.exception(e); + } + } + + + +} 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 64332c7e..f005354a 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/HighOrderController.java @@ -68,6 +68,12 @@ public class HighOrderController { @Resource private HighDiscountCouponRelService highDiscountCouponRelService; + @Resource + private HighDiscountPackageService discountPackageService; + + @Resource + private HighDiscountPackageActualService discountPackageActualService; + @Resource private HighUserService highUserService; @@ -234,6 +240,28 @@ public class HighOrderController { childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); } + if (childOrder.getGoodsType() == 7) { + // 查询优惠券包 + HighDiscountPackage discountPackage = discountPackageService.findDiscountPackageById(childOrder.getGoodsType().intValue()); + if (discountPackage == null) { + log.error("HighOrderController --> addOrder() error!", ""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到优惠券包"); + } + if (discountPackage.getStatus() != 1) { + log.error("HighOrderController --> addOrder() error!", ""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券包不可用"); + } + if (discountPackageActualService.getStockByPackageId(discountPackage.getId()) == 0) { + log.error("HighOrderController --> addOrder() error!", ""); + throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "库存数量不足"); + } + childOrder.setGoodsActualPrice(childOrder.getGoodsPrice()); + childOrder.setGoodsName(discountPackage.getTitle()); + childOrder.setGoodsImg(discountPackage.getListImg()); + childOrder.setGoodsPrice(discountPackage.getPrice()); + childOrder.setGoodsSpecName("默认"); + } + childOrder.setMemId(userInfoModel.getHighUser().getId()); childOrder.setTotalPrice(childOrder.getGoodsPrice().multiply(new BigDecimal(childOrder.getSaleCount().toString()))); childOrder.setGiveawayType(false); // 是否是赠品 0:否 1:是 @@ -349,68 +377,6 @@ 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 = "根据订单id 取消订单") diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java index 2d2b2da0..67f228d9 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/UnionPayController.java @@ -87,6 +87,15 @@ public class UnionPayController { @Resource private HighPayRecordMapper highPayRecordMapper; + @Resource + private HighDiscountPackageDiscountActualService discountPackageDiscountActualService; + + @Resource + private HighDiscountPackageActualService discountPackageActualService; + + @Resource + private HighDiscountUserRelService highDiscountUserRelService; + @Resource private OutRechargeOrderService outRechargeOrderService; @@ -295,10 +304,22 @@ public class UnionPayController { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } } + + if (highChildOrder.getGoodsType() == 7) { + HighDiscountPackageActual actual = discountPackageActualService.getDetailByChildOrderId(highChildOrder.getId()); + if (actual != null) { + List discountList = discountPackageDiscountActualService.getHighDiscountPackageDiscountActualList(actual.getId()); + for (HighDiscountPackageDiscountActual discount : discountList) { + highDiscountUserRelService.receiveDiscount(order.getMemId(), discount.getAgentDiscountCodeId()); + } + actual.setStatus(3); // 状态: 1: 待分配 2:预分配(售卖)3:已分配 + } + } } highOrderService.updateOrder(order); } + } } diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualMapper.java b/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualMapper.java index 5460995e..56c748c6 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualMapper.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualMapper.java @@ -41,12 +41,14 @@ public interface HighDiscountPackageActualMapper extends HighDiscountPackageActu @Insert({ "insert into high_discount_package_actual (discount_package_id, created_user_id, ", "created_time, user_id, ", - "allocation_time, `status`, ", - "ext_1, ext_2, ext_3)", + "allocation_time, child_order_id, ", + "`status`, ext_1, ext_2, ", + "ext_3)", "values (#{discountPackageId,jdbcType=INTEGER}, #{createdUserId,jdbcType=INTEGER}, ", "#{createdTime,jdbcType=TIMESTAMP}, #{userId,jdbcType=INTEGER}, ", - "#{allocationTime,jdbcType=TIMESTAMP}, #{status,jdbcType=INTEGER}, ", - "#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})" + "#{allocationTime,jdbcType=TIMESTAMP}, #{childOrderId,jdbcType=BIGINT}, ", + "#{status,jdbcType=INTEGER}, #{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, ", + "#{ext3,jdbcType=VARCHAR})" }) @Options(useGeneratedKeys=true,keyProperty="id") int insert(HighDiscountPackageActual record); @@ -63,6 +65,7 @@ public interface HighDiscountPackageActualMapper extends HighDiscountPackageActu @Result(column="created_time", property="createdTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER), @Result(column="allocation_time", property="allocationTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @@ -73,7 +76,7 @@ public interface HighDiscountPackageActualMapper extends HighDiscountPackageActu @Select({ "select", "id, discount_package_id, created_user_id, created_time, user_id, allocation_time, ", - "`status`, ext_1, ext_2, ext_3", + "child_order_id, `status`, ext_1, ext_2, ext_3", "from high_discount_package_actual", "where id = #{id,jdbcType=INTEGER}" }) @@ -84,6 +87,7 @@ public interface HighDiscountPackageActualMapper extends HighDiscountPackageActu @Result(column="created_time", property="createdTime", jdbcType=JdbcType.TIMESTAMP), @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER), @Result(column="allocation_time", property="allocationTime", jdbcType=JdbcType.TIMESTAMP), + @Result(column="child_order_id", property="childOrderId", jdbcType=JdbcType.BIGINT), @Result(column="status", property="status", jdbcType=JdbcType.INTEGER), @Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR), @Result(column="ext_2", property="ext2", jdbcType=JdbcType.VARCHAR), @@ -107,6 +111,7 @@ public interface HighDiscountPackageActualMapper extends HighDiscountPackageActu "created_time = #{createdTime,jdbcType=TIMESTAMP},", "user_id = #{userId,jdbcType=INTEGER},", "allocation_time = #{allocationTime,jdbcType=TIMESTAMP},", + "child_order_id = #{childOrderId,jdbcType=BIGINT},", "`status` = #{status,jdbcType=INTEGER},", "ext_1 = #{ext1,jdbcType=VARCHAR},", "ext_2 = #{ext2,jdbcType=VARCHAR},", diff --git a/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualSqlProvider.java b/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualSqlProvider.java index 7c1d53eb..d28d118d 100644 --- a/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualSqlProvider.java +++ b/hai-service/src/main/java/com/hai/dao/HighDiscountPackageActualSqlProvider.java @@ -48,6 +48,10 @@ public class HighDiscountPackageActualSqlProvider { sql.VALUES("allocation_time", "#{allocationTime,jdbcType=TIMESTAMP}"); } + if (record.getChildOrderId() != null) { + sql.VALUES("child_order_id", "#{childOrderId,jdbcType=BIGINT}"); + } + if (record.getStatus() != null) { sql.VALUES("`status`", "#{status,jdbcType=INTEGER}"); } @@ -79,6 +83,7 @@ public class HighDiscountPackageActualSqlProvider { sql.SELECT("created_time"); sql.SELECT("user_id"); sql.SELECT("allocation_time"); + sql.SELECT("child_order_id"); sql.SELECT("`status`"); sql.SELECT("ext_1"); sql.SELECT("ext_2"); @@ -124,6 +129,10 @@ public class HighDiscountPackageActualSqlProvider { sql.SET("allocation_time = #{record.allocationTime,jdbcType=TIMESTAMP}"); } + if (record.getChildOrderId() != null) { + sql.SET("child_order_id = #{record.childOrderId,jdbcType=BIGINT}"); + } + if (record.getStatus() != null) { sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); } @@ -154,6 +163,7 @@ public class HighDiscountPackageActualSqlProvider { sql.SET("created_time = #{record.createdTime,jdbcType=TIMESTAMP}"); sql.SET("user_id = #{record.userId,jdbcType=INTEGER}"); sql.SET("allocation_time = #{record.allocationTime,jdbcType=TIMESTAMP}"); + sql.SET("child_order_id = #{record.childOrderId,jdbcType=BIGINT}"); sql.SET("`status` = #{record.status,jdbcType=INTEGER}"); sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}"); sql.SET("ext_2 = #{record.ext2,jdbcType=VARCHAR}"); @@ -188,6 +198,10 @@ public class HighDiscountPackageActualSqlProvider { sql.SET("allocation_time = #{allocationTime,jdbcType=TIMESTAMP}"); } + if (record.getChildOrderId() != null) { + sql.SET("child_order_id = #{childOrderId,jdbcType=BIGINT}"); + } + if (record.getStatus() != null) { sql.SET("`status` = #{status,jdbcType=INTEGER}"); } diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActual.java b/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActual.java index 5eccde6c..1f7c30d7 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActual.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActual.java @@ -43,6 +43,11 @@ public class HighDiscountPackageActual implements Serializable { */ private Date allocationTime; + /** + * 子订单id + */ + private Long childOrderId; + /** * 状态: 1: 待分配 2:预分配(售卖)3:已分配 */ @@ -113,6 +118,14 @@ public class HighDiscountPackageActual implements Serializable { this.allocationTime = allocationTime; } + public Long getChildOrderId() { + return childOrderId; + } + + public void setChildOrderId(Long childOrderId) { + this.childOrderId = childOrderId; + } + public Integer getStatus() { return status; } @@ -163,6 +176,7 @@ public class HighDiscountPackageActual implements Serializable { && (this.getCreatedTime() == null ? other.getCreatedTime() == null : this.getCreatedTime().equals(other.getCreatedTime())) && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId())) && (this.getAllocationTime() == null ? other.getAllocationTime() == null : this.getAllocationTime().equals(other.getAllocationTime())) + && (this.getChildOrderId() == null ? other.getChildOrderId() == null : this.getChildOrderId().equals(other.getChildOrderId())) && (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus())) && (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1())) && (this.getExt2() == null ? other.getExt2() == null : this.getExt2().equals(other.getExt2())) @@ -179,6 +193,7 @@ public class HighDiscountPackageActual implements Serializable { result = prime * result + ((getCreatedTime() == null) ? 0 : getCreatedTime().hashCode()); result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode()); result = prime * result + ((getAllocationTime() == null) ? 0 : getAllocationTime().hashCode()); + result = prime * result + ((getChildOrderId() == null) ? 0 : getChildOrderId().hashCode()); result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode()); result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode()); result = prime * result + ((getExt2() == null) ? 0 : getExt2().hashCode()); @@ -198,6 +213,7 @@ public class HighDiscountPackageActual implements Serializable { sb.append(", createdTime=").append(createdTime); sb.append(", userId=").append(userId); sb.append(", allocationTime=").append(allocationTime); + sb.append(", childOrderId=").append(childOrderId); sb.append(", status=").append(status); sb.append(", ext1=").append(ext1); sb.append(", ext2=").append(ext2); diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActualExample.java b/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActualExample.java index f0e24573..2504f371 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActualExample.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountPackageActualExample.java @@ -485,6 +485,66 @@ public class HighDiscountPackageActualExample { return (Criteria) this; } + public Criteria andChildOrderIdIsNull() { + addCriterion("child_order_id is null"); + return (Criteria) this; + } + + public Criteria andChildOrderIdIsNotNull() { + addCriterion("child_order_id is not null"); + return (Criteria) this; + } + + public Criteria andChildOrderIdEqualTo(Long value) { + addCriterion("child_order_id =", value, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdNotEqualTo(Long value) { + addCriterion("child_order_id <>", value, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdGreaterThan(Long value) { + addCriterion("child_order_id >", value, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdGreaterThanOrEqualTo(Long value) { + addCriterion("child_order_id >=", value, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdLessThan(Long value) { + addCriterion("child_order_id <", value, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdLessThanOrEqualTo(Long value) { + addCriterion("child_order_id <=", value, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdIn(List values) { + addCriterion("child_order_id in", values, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdNotIn(List values) { + addCriterion("child_order_id not in", values, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdBetween(Long value1, Long value2) { + addCriterion("child_order_id between", value1, value2, "childOrderId"); + return (Criteria) this; + } + + public Criteria andChildOrderIdNotBetween(Long value1, Long value2) { + addCriterion("child_order_id not between", value1, value2, "childOrderId"); + return (Criteria) this; + } + public Criteria andStatusIsNull() { addCriterion("`status` is null"); return (Criteria) this; diff --git a/hai-service/src/main/java/com/hai/entity/HighDiscountPackageDetails.java b/hai-service/src/main/java/com/hai/entity/HighDiscountPackageDetails.java index ef7058a5..eed40642 100644 --- a/hai-service/src/main/java/com/hai/entity/HighDiscountPackageDetails.java +++ b/hai-service/src/main/java/com/hai/entity/HighDiscountPackageDetails.java @@ -83,6 +83,16 @@ public class HighDiscountPackageDetails implements Serializable { */ private String ext3; + private HighDiscount discountDetail; + + public HighDiscount getDiscountDetail() { + return discountDetail; + } + + public void setDiscountDetail(HighDiscount discountDetail) { + this.discountDetail = discountDetail; + } + private static final long serialVersionUID = 1L; public Integer getId() { @@ -270,4 +280,4 @@ public class HighDiscountPackageDetails implements Serializable { sb.append("]"); return sb.toString(); } -} \ No newline at end of file +} diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java b/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java index 6d474edb..3d23abe2 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountPackageActualService.java @@ -1,6 +1,7 @@ package com.hai.service; import com.hai.entity.HighDiscountPackageActual; +import com.hai.entity.HighDiscountPackageDiscountActual; import java.util.List; import java.util.Map; @@ -46,4 +47,26 @@ public interface HighDiscountPackageActualService { */ List getHighDiscountPackageActualList(Integer discountPackageId); + /** + * 获取库存 + * @param packageId + * @return + */ + long getStockByPackageId(Integer packageId); + + /** + * 获取库存 + * @param childOrderId + * @return + */ + HighDiscountPackageActual getDetailByChildOrderId(Long childOrderId); + + /** + * 查询优惠券包列表 + * @param packageId + * @param status + * @return + */ + List getListByPackageId(Integer packageId, Integer status); + } diff --git a/hai-service/src/main/java/com/hai/service/HighDiscountPackageDetailsService.java b/hai-service/src/main/java/com/hai/service/HighDiscountPackageDetailsService.java index 5699aa56..a2f4159b 100644 --- a/hai-service/src/main/java/com/hai/service/HighDiscountPackageDetailsService.java +++ b/hai-service/src/main/java/com/hai/service/HighDiscountPackageDetailsService.java @@ -1,5 +1,6 @@ package com.hai.service; +import com.hai.entity.HighDiscount; import com.hai.entity.HighDiscountPackageDetails; import java.util.List; @@ -34,6 +35,13 @@ public interface HighDiscountPackageDetailsService { */ HighDiscountPackageDetails findDetailsById(Integer id); + /** + * 查询包中的优惠券详情 + * @param packageId + * @return + */ + List getDetailByPackage(Integer packageId); + /** * @Author Sum1Dream * @name insertDiscountPackageDetails.java diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java index 0a7c1a11..78b2586b 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageActualServiceImpl.java @@ -4,6 +4,8 @@ import com.hai.dao.HighDiscountPackageActualMapper; import com.hai.dao.HighDiscountPackageDiscountActualMapper; import com.hai.entity.HighDiscountPackageActual; import com.hai.entity.HighDiscountPackageActualExample; +import com.hai.entity.HighDiscountPackageDiscountActual; +import com.hai.entity.HighDiscountPackageDiscountActualExample; import com.hai.service.HighDiscountPackageActualService; import org.springframework.stereotype.Service; @@ -21,10 +23,12 @@ import java.util.Map; @Service("highDiscountPackageActualService") public class HighDiscountPackageActualServiceImpl implements HighDiscountPackageActualService { - @Resource private HighDiscountPackageActualMapper discountPackageActualMapper; + @Resource + private HighDiscountPackageDiscountActualMapper discountPackageDiscountActualMapper; + @Override public void insertHighDiscountPackageActual(HighDiscountPackageActual highDiscountPackageActual) { discountPackageActualMapper.insert(highDiscountPackageActual); @@ -45,4 +49,34 @@ public class HighDiscountPackageActualServiceImpl implements HighDiscountPackage return discountPackageActualMapper.selectByExample(example); } + + + @Override + public long getStockByPackageId(Integer packageId) { + HighDiscountPackageDiscountActualExample example = new HighDiscountPackageDiscountActualExample(); + example.createCriteria().andDiscountPackageIdEqualTo(packageId).andStatusEqualTo(1); + return discountPackageDiscountActualMapper.countByExample(example); + } + + @Override + public HighDiscountPackageActual getDetailByChildOrderId(Long childOrderId) { + HighDiscountPackageActualExample example = new HighDiscountPackageActualExample(); + example.createCriteria().andChildOrderIdEqualTo(childOrderId); + List list = discountPackageActualMapper.selectByExample(example); + if (list.size() > 0) { + return list.get(0); + } + return null; + } + + @Override + public List getListByPackageId(Integer packageId, Integer status) { + HighDiscountPackageActualExample example = new HighDiscountPackageActualExample(); + HighDiscountPackageActualExample.Criteria criteria = example.createCriteria().andDiscountPackageIdEqualTo(packageId); + if (status != null) { + criteria.andStatusEqualTo(status); + } + example.setOrderByClause("created_time"); + return discountPackageActualMapper.selectByExample(example); + } } diff --git a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDetailsServiceImpl.java b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDetailsServiceImpl.java index 12670662..18f37756 100644 --- a/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDetailsServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/impl/HighDiscountPackageDetailsServiceImpl.java @@ -1,10 +1,12 @@ package com.hai.service.impl; import com.hai.dao.HighDiscountPackageDetailsMapper; +import com.hai.entity.HighDiscount; import com.hai.entity.HighDiscountPackage; import com.hai.entity.HighDiscountPackageDetails; import com.hai.entity.HighDiscountPackageDetailsExample; import com.hai.service.HighDiscountPackageDetailsService; +import com.hai.service.HighDiscountService; import org.apache.commons.collections4.MapUtils; import org.springframework.stereotype.Service; @@ -48,6 +50,13 @@ public class HighDiscountPackageDetailsServiceImpl implements HighDiscountPackag return highDiscountPackageDetailsMapper.selectByPrimaryKey(id); } + @Override + public List getDetailByPackage(Integer packageId) { + HighDiscountPackageDetailsExample example = new HighDiscountPackageDetailsExample(); + example.createCriteria().andStatusNotEqualTo(0).andDiscountPackageIdEqualTo(packageId); + return highDiscountPackageDetailsMapper.selectByExample(example); + } + @Override public void insertDiscountPackageDetails(HighDiscountPackageDetails highDiscountPackageDetails) { highDiscountPackageDetailsMapper.insert(highDiscountPackageDetails); 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 14eb2db2..f2c9cfcf 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 @@ -89,6 +89,12 @@ public class HighOrderServiceImpl implements HighOrderService { @Resource private HighActivityUserLotteryNumService highActivityUserLotteryNumService; + @Resource + private HighDiscountPackageActualService discountPackageActualService; + + @Resource + private HighDiscountPackageDiscountActualService discountPackageDiscountActualService; + @Resource private HuiLianTongConfig huiLianTongConfig; @@ -166,6 +172,17 @@ public class HighOrderServiceImpl implements HighOrderService { } } } + + if (childOrder.getGoodsType() == 7) { + // 查询库存 + List list = discountPackageActualService.getListByPackageId(childOrder.getGoodsId().intValue(), 1); + if (list == null || list.size() == 0) { + throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, ""); + } + list.get(0).setChildOrderId(childOrder.getId()); + list.get(0).setStatus(2); // 状态: 1: 待分配 2:预分配(售卖)3:已分配 + discountPackageActualService.updateHighDiscountPackageActual(list.get(0)); + } } } @@ -314,6 +331,17 @@ public class HighOrderServiceImpl implements HighOrderService { highActivityUserLotteryNumService.addLotteryNum(MapUtils.getLong(activity, "id"),highOrder.getMemId(), 1); } } + + if (highChildOrder.getGoodsType() == 7) { + HighDiscountPackageActual actual = discountPackageActualService.getDetailByChildOrderId(highChildOrder.getId()); + if (actual != null) { + List discountList = discountPackageDiscountActualService.getHighDiscountPackageDiscountActualList(actual.getId()); + for (HighDiscountPackageDiscountActual discount : discountList) { + highDiscountUserRelService.receiveDiscount(highOrder.getMemId(), discount.getAgentDiscountCodeId()); + } + actual.setStatus(3); // 状态: 1: 待分配 2:预分配(售卖)3:已分配 + } + } } updateOrder(highOrder); @@ -362,6 +390,11 @@ public class HighOrderServiceImpl implements HighOrderService { } goodsDesc = "加油站加"+order.getPayPrice()+"元油"; tranDesc = "【"+order.getHighChildOrderList().get(0).getGoodsName()+"】加油"+order.getPayPrice()+"元"; + + } else if (order.getHighChildOrderList().get(0).getGoodsType() == 7) { + goodsDesc = "购买优惠券包"; + tranDesc = "购买"+ order.getHighChildOrderList().get(0).getGoodsName() +"优惠券包"; + } else { throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法支付,请使用其他支付方式"); } @@ -576,6 +609,17 @@ public class HighOrderServiceImpl implements HighOrderService { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } } + + if (highChildOrder.getGoodsType() == 7) { + HighDiscountPackageActual actual = discountPackageActualService.getDetailByChildOrderId(highChildOrder.getId()); + if (actual != null) { + List discountList = discountPackageDiscountActualService.getHighDiscountPackageDiscountActualList(actual.getId()); + for (HighDiscountPackageDiscountActual discount : discountList) { + highDiscountUserRelService.receiveDiscount(order.getMemId(), discount.getAgentDiscountCodeId()); + } + actual.setStatus(3); // 状态: 1: 待分配 2:预分配(售卖)3:已分配 + } + } } updateOrder(order); diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java index efbebf0e..b7735298 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java @@ -92,6 +92,15 @@ public class GoodsOrderServiceImpl implements PayService { @Resource private HighActivityUserLotteryNumService highActivityUserLotteryNumService; + @Resource + private HighDiscountPackageDiscountActualService discountPackageDiscountActualService; + + @Resource + private HighDiscountPackageActualService discountPackageActualService; + + @Resource + private HighDiscountUserRelService highDiscountUserRelService; + @Resource private NotifyService notifyService; @@ -285,6 +294,17 @@ public class GoodsOrderServiceImpl implements PayService { highChildOrder.setGasOrderNo(orderPushObject.getJSONObject("result").getString("orderNo")); } } + + if (highChildOrder.getGoodsType() == 7) { + HighDiscountPackageActual actual = discountPackageActualService.getDetailByChildOrderId(highChildOrder.getId()); + if (actual != null) { + List discountList = discountPackageDiscountActualService.getHighDiscountPackageDiscountActualList(actual.getId()); + for (HighDiscountPackageDiscountActual discount : discountList) { + highDiscountUserRelService.receiveDiscount(order.getMemId(), discount.getAgentDiscountCodeId()); + } + actual.setStatus(3); // 状态: 1: 待分配 2:预分配(售卖)3:已分配 + } + } } highOrderService.updateOrder(order);