|
|
|
@@ -2,8 +2,12 @@ package com.simple.controller; |
|
|
|
|
|
|
|
import com.simple.common.ErrorCode; |
|
|
|
import com.simple.domain.po.WxCUser; |
|
|
|
import com.simple.domain.po.WxCouponChannel; |
|
|
|
import com.simple.enums.EnumCouponChannelStatus; |
|
|
|
import com.simple.enums.EnumCouponStatus; |
|
|
|
import com.simple.enums.EnumOrderStatus; |
|
|
|
import com.simple.exception.MallinkException; |
|
|
|
import com.simple.service.WxCouponChannelService; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.log4j.Logger; |
|
|
|
@@ -28,24 +32,40 @@ import java.util.Map; |
|
|
|
public class WxOrderController extends BaseController { |
|
|
|
private Logger logger = Logger.getLogger(WxOrderController.class); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponChannelService wxCouponChannelService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxOrderService wxOrderService; |
|
|
|
|
|
|
|
@ApiOperation(value = "免费领取", notes = "{\"couponId\":\"String\"}") |
|
|
|
@ApiOperation(value = "免费领取", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\"}") |
|
|
|
@PostMapping("freeCoupon") |
|
|
|
public ResultData freeCoupon(@RequestBody Map<String, String> paramMap) { |
|
|
|
//Assert.notNull(wxOrders.getName(), "角色名不能为空"); |
|
|
|
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); |
|
|
|
String couponChannelIdStr = paramMap.get("couponChannelId"); |
|
|
|
String couponIdStr = paramMap.get("couponId"); |
|
|
|
if (StringUtils.isBlank(couponIdStr)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); |
|
|
|
if (StringUtils.isBlank(couponChannelIdStr)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); |
|
|
|
} |
|
|
|
Long couponId = 0L; |
|
|
|
Long couponChannelId = 0L, couponId = 0L; |
|
|
|
try { |
|
|
|
couponId = Long.valueOf(couponIdStr); |
|
|
|
couponChannelId = Long.valueOf(couponChannelIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error("couponId convert error, " + couponIdStr + ", e:" + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponId: " + couponIdStr + ", e:" + e.getMessage()); |
|
|
|
logger.error("couponChannelId convert error, " + couponChannelIdStr + ", e:" + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponChannelId: " + couponChannelIdStr + ", e:" + e.getMessage()); |
|
|
|
} |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannelId); |
|
|
|
if (wxCouponChannel == null) { |
|
|
|
logger.error("couponChannelId convert error, " + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "找不到发布的频道"); |
|
|
|
} |
|
|
|
if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { |
|
|
|
logger.error("此券已下架:" + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(), "此券已下架"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(couponIdStr)) { |
|
|
|
couponId = wxCouponChannel.getCouponId(); |
|
|
|
} |
|
|
|
|
|
|
|
WxCUser user = getUser(); |
|
|
|
@@ -64,21 +84,34 @@ public class WxOrderController extends BaseController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "下订单", notes = "{\"couponId\":\"String\"}") |
|
|
|
@ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\"}") |
|
|
|
@PostMapping("save") |
|
|
|
public ResultData saveOrder(@RequestBody Map<String, String> paramMap) { |
|
|
|
//Assert.notNull(wxOrders.getName(), "角色名不能为空"); |
|
|
|
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); |
|
|
|
String couponChannelIdStr = paramMap.get("couponChannelId"); |
|
|
|
String couponIdStr = paramMap.get("couponId"); |
|
|
|
if (StringUtils.isBlank(couponIdStr)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); |
|
|
|
if (StringUtils.isBlank(couponChannelIdStr)) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); |
|
|
|
} |
|
|
|
Long couponId = 0L; |
|
|
|
Long couponChannelId = 0L, couponId = 0L; |
|
|
|
try { |
|
|
|
couponId = Long.valueOf(couponIdStr); |
|
|
|
couponChannelId = Long.valueOf(couponChannelIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
logger.error("couponId convert error, " + couponIdStr + ", e:" + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponId: " + couponIdStr + ", e:" + e.getMessage()); |
|
|
|
logger.error("couponChannelId convert error, " + couponChannelIdStr + ", e:" + e.getMessage()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponChannelId: " + couponChannelIdStr + ", e:" + e.getMessage()); |
|
|
|
} |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(couponChannelId); |
|
|
|
if (wxCouponChannel == null) { |
|
|
|
logger.error("couponChannelId convert error, " + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "找不到发布的频道"); |
|
|
|
} |
|
|
|
if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { |
|
|
|
logger.error("此券已下架:" + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_TAKE_OFF.getCode(), "此券已下架"); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(couponIdStr)) { |
|
|
|
couponId = wxCouponChannel.getCouponId(); |
|
|
|
} |
|
|
|
WxCUser user = getUser(); |
|
|
|
|
|
|
|
|