|
|
|
@@ -4,10 +4,9 @@ import com.github.pagehelper.PageInfo; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxCUser; |
|
|
|
import com.iformall.domain.po.WxCoupon; |
|
|
|
import com.iformall.domain.po.WxCouponChannel; |
|
|
|
import com.iformall.domain.po.WxOrder; |
|
|
|
import com.iformall.domain.dto.OrderSaveDto; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.domain.vo.WxMerchantVo; |
|
|
|
import com.iformall.domain.vo.WxOrderCouponPressVo; |
|
|
|
import com.iformall.domain.vo.WxOrderCouponVo; |
|
|
|
import com.iformall.enums.*; |
|
|
|
@@ -26,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@RestController |
|
|
|
@@ -43,6 +44,7 @@ public class WxOrderController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private WxCouponService wxCouponService; |
|
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "免费领取", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"formId\":\"String\"}") |
|
|
|
@PostMapping("freeCoupon") |
|
|
|
public ResultData freeCoupon(@RequestBody Map<String, String> paramMap) { |
|
|
|
@@ -184,84 +186,21 @@ public class WxOrderController extends BaseController { |
|
|
|
|
|
|
|
@ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") |
|
|
|
@PostMapping("save_new") |
|
|
|
public ResultData saveOrderNew(@RequestBody Map<String, String> paramMap) { |
|
|
|
logger.info("OrderSave: " + paramMap.toString()); |
|
|
|
//Assert.notNull(wxOrders.getName(), "角色名不能为空"); |
|
|
|
//Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); |
|
|
|
String couponChannelIdStr = paramMap.get("couponChannelId"); |
|
|
|
String couponIdStr = paramMap.get("couponId"); |
|
|
|
String pressStr = paramMap.get("press"); |
|
|
|
String orderGroupIdStr = paramMap.get("orderGroupId"); |
|
|
|
String formId = paramMap.get("formId"); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(couponChannelIdStr)) { |
|
|
|
public ResultData saveOrderNew(@RequestBody OrderSaveDto orderSaveDto) { |
|
|
|
logger.info("OrderSave: " + orderSaveDto); |
|
|
|
if (orderSaveDto.getCouponChannelId() == null) { |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); |
|
|
|
} |
|
|
|
Long couponChannelId = 0L, couponId = 0L, orderGroupId = null; |
|
|
|
boolean isPress = false; |
|
|
|
|
|
|
|
if (StringUtils.isNotBlank(couponChannelIdStr)) { |
|
|
|
try { |
|
|
|
couponChannelId = Long.valueOf(couponChannelIdStr); |
|
|
|
} catch (NumberFormatException e) { |
|
|
|
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); |
|
|
|
} |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(orderSaveDto.getCouponChannelId()); |
|
|
|
ResultData resultData = couponChannelCheck(orderSaveDto, wxCouponChannel); |
|
|
|
if (resultData != null) return resultData; |
|
|
|
|
|
|
|
if (wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { |
|
|
|
Date now = new Date(); |
|
|
|
if (wxCouponChannel.getBeginTime().getTime() > now.getTime()) { |
|
|
|
logger.error("此券活动未开始:" + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_CHANNEL_IS_NOT_STARTED); |
|
|
|
} |
|
|
|
if (wxCouponChannel.getEndTime().getTime() < now.getTime()) { |
|
|
|
logger.error("此券活动已结束:" + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_CHANNEL_IS_END); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { |
|
|
|
logger.error("此券已下架:" + couponChannelIdStr); |
|
|
|
return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); |
|
|
|
} |
|
|
|
if (StringUtils.isBlank(couponIdStr)) { |
|
|
|
couponId = wxCouponChannel.getCouponId(); |
|
|
|
} |
|
|
|
} |
|
|
|
if (couponId <= 0 && !StringUtils.isBlank(couponIdStr)) { |
|
|
|
try { |
|
|
|
couponId = Long.valueOf(couponIdStr); |
|
|
|
} 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()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (couponId <= 0) { |
|
|
|
Long couponId = orderSaveDto.getCouponId() == null ? wxCouponChannel.getCouponId() : orderSaveDto.getCouponId(); |
|
|
|
if (couponId == null) { |
|
|
|
logger.error("couponChannelId或者couponId不能为空"); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId或者couponId不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
if(pressStr != null) { |
|
|
|
try{ |
|
|
|
isPress = Boolean.valueOf(pressStr); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("press转换失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (orderGroupIdStr != null) { |
|
|
|
try { |
|
|
|
orderGroupId = Long.valueOf(orderGroupIdStr); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("orderGroupId转换失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean isPress = orderSaveDto.getPress() != null ? orderSaveDto.getPress() : false; |
|
|
|
|
|
|
|
WxCUser user = getUser(); |
|
|
|
try { |
|
|
|
@@ -271,10 +210,10 @@ public class WxOrderController extends BaseController { |
|
|
|
if (coupon == null) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY); |
|
|
|
} |
|
|
|
if (wxOrderService.checkCouponIsFree(user, coupon)) { |
|
|
|
order = wxOrderService.saveFreeOrderForCoupon(user, coupon, couponChannelId, formId); |
|
|
|
if (wxOrderService.checkCouponIsFree(coupon)) { |
|
|
|
order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); |
|
|
|
} else { |
|
|
|
order = wxOrderService.saveNoFreeOrderForCoupon(user, coupon, couponChannelId, isPress, orderGroupId, formId); |
|
|
|
order = wxOrderService.saveNoFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), isPress, orderSaveDto.getOrderGroupId(), orderSaveDto.getFormId()); |
|
|
|
} |
|
|
|
return new ResultData(order); |
|
|
|
} catch (MallinkException e) { |
|
|
|
@@ -286,6 +225,31 @@ public class WxOrderController extends BaseController { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private ResultData couponChannelCheck(@RequestBody OrderSaveDto orderSaveDto, WxCouponChannel wxCouponChannel) { |
|
|
|
if (wxCouponChannel == null) { |
|
|
|
logger.error("couponChannelId convert error, " + orderSaveDto.getCouponChannelId()); |
|
|
|
return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); |
|
|
|
} |
|
|
|
|
|
|
|
if (wxCouponChannel.getTargetAd().equals(EnumCouponChannelType.COUPON_CHANNEL_ID_TIMED.getCode())) { |
|
|
|
Date now = new Date(); |
|
|
|
if (wxCouponChannel.getBeginTime().getTime() > now.getTime()) { |
|
|
|
logger.error("此券活动未开始:" + orderSaveDto.getCouponChannelId()); |
|
|
|
return new ResultData(ErrorCode.COUPON_CHANNEL_IS_NOT_STARTED); |
|
|
|
} |
|
|
|
if (wxCouponChannel.getEndTime().getTime() < now.getTime()) { |
|
|
|
logger.error("此券活动已结束:" + orderSaveDto.getCouponChannelId()); |
|
|
|
return new ResultData(ErrorCode.COUPON_CHANNEL_IS_END); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (wxCouponChannel.getStatus() == EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode()) { |
|
|
|
logger.error("此券已下架:" + orderSaveDto.getCouponChannelId()); |
|
|
|
return new ResultData(ErrorCode.COUPON_CHANNEL_IS_TAKE_OFF); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@ApiOperation(value = "取消订单", notes = "{\"orderId\":\"string\"}") |
|
|
|
@PostMapping("cancel") |
|
|
|
public ResultData cancelOrder(@RequestBody Map<String, String> paramMap) { |
|
|
|
|