From 3f2622f3a59e7ab408e050d1d5165e04a5d5b666 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Wed, 16 Jan 2019 11:06:15 +0800 Subject: [PATCH] =?UTF-8?q?[=E7=A0=8D=E4=BB=B7][=E6=96=B0=E5=A2=9E]:?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E7=94=A8=E6=88=B7=E6=98=AF=E5=90=A6=E5=B7=B2?= =?UTF-8?q?=E5=8F=82=E4=B8=8E=E7=A0=8D=E4=BB=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/WxPressOrderController.java | 33 +++++++++++++------ .../java/com/iformall/common/ErrorCode.java | 1 + .../service/impl/WxOrderPressServiceImpl.java | 11 +++++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/mallinkCApi/src/main/java/com/iformall/controller/WxPressOrderController.java b/mallinkCApi/src/main/java/com/iformall/controller/WxPressOrderController.java index a178c319a..63ea44803 100644 --- a/mallinkCApi/src/main/java/com/iformall/controller/WxPressOrderController.java +++ b/mallinkCApi/src/main/java/com/iformall/controller/WxPressOrderController.java @@ -1,27 +1,24 @@ package com.iformall.controller; -import com.github.pagehelper.PageInfo; import com.iformall.common.ErrorCode; import com.iformall.common.ResultData; import com.iformall.domain.po.WxCUser; import com.iformall.domain.po.WxCoupon; import com.iformall.domain.po.WxOrder; +import com.iformall.exception.MallinkException; import com.iformall.service.WxCouponService; import com.iformall.service.WxOrderPressService; import com.iformall.service.WxOrderService; import io.swagger.annotations.Api; -import io.swagger.annotations.ApiImplicitParam; -import io.swagger.annotations.ApiImplicitParams; 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.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.Date; +import java.util.Map; @RestController @RequestMapping("/api/press") @@ -46,10 +43,21 @@ public class WxPressOrderController extends BaseController { // 砍价券详情 - /api/order/pressOrderDetail - @ApiOperation("参与砍价") + @ApiOperation(value = "参与砍价", notes = "{\"orderId\":\"String\"}") @PostMapping("pressOrderJoin") - public ResultData pressOrderJoin(Long orderId) { + public ResultData pressOrderJoin(@RequestBody Map paramMap) { Date curDate = new Date(); + String orderIdStr = paramMap.get("orderId"); + if (StringUtils.isBlank(orderIdStr)) { + return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); + } + Long orderId = 0L; + try { + orderId = Long.valueOf(orderIdStr); + } catch (NumberFormatException e) { + logger.error("orderId convert error, " + orderIdStr + ", e:" + e.getMessage()); + return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "orderId: " + orderIdStr + ", e:" + e.getMessage()); + } WxCUser user = getUser(); WxOrder order = wxOrderService.getById(orderId); if(order == null) { @@ -72,7 +80,12 @@ public class WxPressOrderController extends BaseController { return new ResultData(ErrorCode.COUPON_PRESS_HAD_FINISHED); } - wxOrderPressService.pressCouponJoin(order, coupon, user); + try { + wxOrderPressService.pressCouponJoin(order, coupon, user); + } catch (MallinkException e) { + logger.error(e.getMessage()); + return new ResultData(e.getErrorCode(), e.getMessage()); + } return new ResultData(); } diff --git a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java index 8b3bf7cf5..4014b98ed 100644 --- a/mallinkService/src/main/java/com/iformall/common/ErrorCode.java +++ b/mallinkService/src/main/java/com/iformall/common/ErrorCode.java @@ -162,6 +162,7 @@ public enum ErrorCode{ */ COUPON_PRESS_HAD_FINISHED(9070, "砍价已完成"), COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"), + COUPON_PRESS_IS_EXIST(9072, "此人已参与此次砍价"), diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java index 363a0cc42..7e248c3e4 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java @@ -63,11 +63,22 @@ public class WxOrderPressServiceImpl implements WxOrderPressService { public void pressCouponJoin(WxOrder order, WxCoupon coupon, WxCUser user) { final IdWorker idWorker = IdWorker.get(); Date curDate = new Date(); + // 检查此人是否已参与砍价 + WxOrderPress orderPressQ = new WxOrderPress(); + orderPressQ.setTenantId(order.getTenantId()); + orderPressQ.setOrderId(order.getId()); + orderPressQ.setUserId(user.getId()); + int count = wxOrderPressMapper.selectCount(orderPressQ); + if(count > 1) { + throw new MallinkException(ErrorCode.COUPON_PRESS_IS_EXIST); + } + // 添加 wx_order_press int total = coupon.getPrice() - coupon.getSalePrice(); int left_total = order.getPressCurrentValue(); WxOrderPress orderPress = new WxOrderPress(); orderPress.setId(idWorker.nextId()); + orderPress.setTenantId(order.getTenantId()); orderPress.setOrderId(order.getId()); orderPress.setUserId(user.getId()); orderPress.setCreateDate(curDate);