|
|
|
@@ -6,7 +6,9 @@ import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.Result; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.controller.base.BaseController; |
|
|
|
import com.iformall.domain.dto.OrderSaveDto; |
|
|
|
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.vo.WxOrderQueryVo; |
|
|
|
@@ -16,6 +18,7 @@ import com.iformall.enums.EnumUserType; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.service.WxCUserService; |
|
|
|
import com.iformall.service.WxCouponChannelService; |
|
|
|
import com.iformall.service.WxCouponService; |
|
|
|
import com.iformall.service.WxOrderService; |
|
|
|
import io.swagger.annotations.ApiImplicitParam; |
|
|
|
import io.swagger.annotations.ApiImplicitParams; |
|
|
|
@@ -43,6 +46,9 @@ public class WxOrderController extends BaseController { |
|
|
|
@Autowired |
|
|
|
private WxCUserService wxCUserService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private WxCouponService wxCouponService; |
|
|
|
|
|
|
|
@ApiOperation("分页列表接口") |
|
|
|
@GetMapping("list") |
|
|
|
@ApiImplicitParams({ |
|
|
|
@@ -130,101 +136,35 @@ public class WxOrderController extends BaseController { |
|
|
|
|
|
|
|
@ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}") |
|
|
|
@PostMapping("save") |
|
|
|
public ResultData saveOrder(@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"); |
|
|
|
//被操作人的ID |
|
|
|
String userIdStr = paramMap.get("userId"); |
|
|
|
Long userId = 0L; |
|
|
|
if (StringUtils.isNotBlank(userIdStr)) { |
|
|
|
userId = Long.valueOf(userIdStr); |
|
|
|
} |
|
|
|
WxCUser wxCUser = wxCUserService.getById(userId); |
|
|
|
if (wxCUser == null) { |
|
|
|
throw new MallinkException(ErrorCode.USER_NOT_MEMBER); |
|
|
|
} |
|
|
|
|
|
|
|
if (StringUtils.isBlank(couponChannelIdStr)) { |
|
|
|
public ResultData saveOrder(@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); |
|
|
|
} |
|
|
|
|
|
|
|
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()); |
|
|
|
} |
|
|
|
} |
|
|
|
WxCouponChannel wxCouponChannel = wxCouponChannelService.getById(orderSaveDto.getCouponChannelId()); |
|
|
|
ResultData resultData = couponChannelCheck(orderSaveDto, wxCouponChannel); |
|
|
|
if (resultData != null) return resultData; |
|
|
|
|
|
|
|
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转换失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//用于标记当前操作人为A端用户 |
|
|
|
wxCUser.setOperatorType(EnumUserType.MALLUSER.getCode()); |
|
|
|
wxCUser.setOperatorId(getUser().getId()); |
|
|
|
try { |
|
|
|
WxOrder order = wxOrderService.saveCouponOrder(wxCUser, couponChannelId, couponId, isPress, orderGroupId, formId); |
|
|
|
WxCUser user = wxCUserService.getById(orderSaveDto.getUserId()); |
|
|
|
//用于标记当前操作人为A端用户 |
|
|
|
user.setOperatorType(EnumUserType.MALLUSER.getCode()); |
|
|
|
user.setOperatorId(getUser().getId()); |
|
|
|
WxOrder order = null; |
|
|
|
WxCoupon coupon = wxCouponService.getById(couponId); |
|
|
|
if (coupon == null) { |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_EMPTY); |
|
|
|
} |
|
|
|
if (!wxOrderService.checkCouponIsFree(coupon)) |
|
|
|
return new ResultData(ErrorCode.COUPON_IS_NOT_FREE); |
|
|
|
// 免费券 |
|
|
|
order = wxOrderService.saveFreeOrderForCoupon(user, coupon, orderSaveDto.getCouponChannelId(), orderSaveDto.getFormId()); |
|
|
|
return new ResultData(order); |
|
|
|
} catch (MallinkException e) { |
|
|
|
logger.error(e.getMessage()); |
|
|
|
@@ -235,4 +175,29 @@ 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; |
|
|
|
} |
|
|
|
|
|
|
|
} |