|
|
|
@ -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; |
|
|
|
@ -29,9 +26,8 @@ import org.springframework.web.bind.annotation.*; |
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import java.math.BigDecimal; |
|
|
|
|
import java.util.Date; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.*; |
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* @Auther: 胡锐 |
|
|
|
@ -57,6 +53,12 @@ public class HighOrderController { |
|
|
|
|
@Resource |
|
|
|
|
private HighCouponCodeService highCouponCodeService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighDiscountUserRelService highDiscountUserRelService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighDiscountCouponRelService highDiscountCouponRelService; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighUserService highUserService; |
|
|
|
|
|
|
|
|
@ -96,6 +98,20 @@ public class HighOrderController { |
|
|
|
|
log.error("HighOrderController --> addOrder() error!", "未找到卡卷信息"); |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, ""); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// 校验优惠券是否可用
|
|
|
|
|
if (highOrder.getMemDiscountId() != null) { |
|
|
|
|
List<HighDiscountCouponRel> discountCouponRelList = highDiscountCouponRelService.getRelByCoupon(coupon.getId()); |
|
|
|
|
if (discountCouponRelList.size() > 0) { |
|
|
|
|
List<HighDiscountCouponRel> collect = discountCouponRelList.stream().filter(o -> o.getDiscountId().equals(highOrder.getMemDiscountId())).collect(Collectors.toList()); |
|
|
|
|
if (collect == null || collect.size() == 0) { |
|
|
|
|
log.error("HighOrderController --> addOrder() error!", "无法使用优惠券"); |
|
|
|
|
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用优惠券"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 是否到底限购数量
|
|
|
|
|
if (highCouponService.userBuyLimitNumber(userInfoModel.getHighUser().getId(), coupon.getId()) == true) { |
|
|
|
|
log.error("HighOrderController --> addOrder() error!", "已达到限购数量"); |
|
|
|
@ -137,11 +153,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 +219,6 @@ public class HighOrderController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getOrderById", method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "根据id查询订单详情") |
|
|
|
@ -171,6 +233,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 +311,6 @@ public class HighOrderController { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getUserOrderList", method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "获取用户订单") |
|
|
|
|