Преглед изворни кода

[订单][流程]:优化

release_toaliyun_real
hanxueda пре 7 година
родитељ
комит
c474f0bd13
4 измењених фајлова са 98 додато и 114 уклоњено
  1. +43
    -79
      mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java
  2. +22
    -0
      mallinkService/src/main/java/com/iformall/domain/dto/OrderSaveDto.java
  3. +1
    -1
      mallinkService/src/main/java/com/iformall/service/WxOrderService.java
  4. +32
    -34
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java

+ 43
- 79
mallinkCApi/src/main/java/com/iformall/controller/WxOrderController.java Прегледај датотеку

@@ -4,10 +4,9 @@ import com.github.pagehelper.PageInfo;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
import com.iformall.common.Result; import com.iformall.common.Result;
import com.iformall.common.ResultData; 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.WxOrderCouponPressVo;
import com.iformall.domain.vo.WxOrderCouponVo; import com.iformall.domain.vo.WxOrderCouponVo;
import com.iformall.enums.*; import com.iformall.enums.*;
@@ -26,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;


import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;


@RestController @RestController
@@ -43,6 +44,7 @@ public class WxOrderController extends BaseController {
@Autowired @Autowired
private WxCouponService wxCouponService; private WxCouponService wxCouponService;



@ApiOperation(value = "免费领取", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"formId\":\"String\"}") @ApiOperation(value = "免费领取", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"formId\":\"String\"}")
@PostMapping("freeCoupon") @PostMapping("freeCoupon")
public ResultData freeCoupon(@RequestBody Map<String, String> paramMap) { 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\"}") @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\",\"formId\":\"String\"}")
@PostMapping("save_new") @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不能为空"); 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不能为空"); logger.error("couponChannelId或者couponId不能为空");
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "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(); WxCUser user = getUser();
try { try {
@@ -271,10 +210,10 @@ public class WxOrderController extends BaseController {
if (coupon == null) { if (coupon == null) {
return new ResultData(ErrorCode.COUPON_IS_EMPTY); 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 { } 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); return new ResultData(order);
} catch (MallinkException e) { } 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\"}") @ApiOperation(value = "取消订单", notes = "{\"orderId\":\"string\"}")
@PostMapping("cancel") @PostMapping("cancel")
public ResultData cancelOrder(@RequestBody Map<String, String> paramMap) { public ResultData cancelOrder(@RequestBody Map<String, String> paramMap) {


+ 22
- 0
mallinkService/src/main/java/com/iformall/domain/dto/OrderSaveDto.java Прегледај датотеку

@@ -0,0 +1,22 @@
package com.iformall.domain.dto;

import lombok.Data;

import java.io.Serializable;

@Data
public class OrderSaveDto implements Serializable {

private static final long serialVersionUID = 1L;

private Long couponChannelId;

private Long couponId;

private Boolean press;

private Long orderGroupId;

private String formId;

}

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/WxOrderService.java Прегледај датотеку

@@ -177,7 +177,7 @@ public interface WxOrderService {
* 订单处理 * 订单处理
* 1. 检查coupon是否免费 * 1. 检查coupon是否免费
*/ */
boolean checkCouponIsFree(WxCUser user, WxCoupon coupon);
boolean checkCouponIsFree(WxCoupon coupon);


// 2. 创建免费订单, 领取 couponOrder // 2. 创建免费订单, 领取 couponOrder
WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId); WxOrder saveFreeOrderForCoupon(WxCUser user, WxCoupon coupon, Long couponChannelId, String formId);


+ 32
- 34
mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java Прегледај датотеку

@@ -938,14 +938,8 @@ public class WxOrderServiceImpl implements WxOrderService {
throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR);
} }


// 发券couponOrder
try {
wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.C_ORDER,updateOrder);
} catch (Exception e) {
logger.error("订单发券:" + e.getMessage());
}
// 增加成长值和积分
addScoreAndCredit(updateOrder, coupon, user);
// 增加成长值和积分和发券
addScoreAndCreditAndSendCoupon(updateOrder, coupon, user);
return ret; return ret;
} }


@@ -965,19 +959,18 @@ public class WxOrderServiceImpl implements WxOrderService {
logger.error("用户不存在, userId: " + updateOrder.getcUserId()); logger.error("用户不存在, userId: " + updateOrder.getcUserId());
throw new MallinkException(ErrorCode.USER_IS_EMPTY); throw new MallinkException(ErrorCode.USER_IS_EMPTY);
} }
int ret = 0;
// 增加成长值和积分和发券
addScoreAndCreditAndSendCoupon(updateOrder, coupon, user);
return 0;
}

private void addScoreAndCreditAndSendCoupon(WxOrder updateOrder, WxCoupon coupon, WxCUser user) {
// 发券couponOrder // 发券couponOrder
try { try {
wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.C_ORDER,updateOrder); wxCouponSendService.sendCouponToUser(EnumCouponSendSendType.C_ORDER,updateOrder);
} catch (Exception e) { } catch (Exception e) {
logger.error("订单发券:" + e.getMessage()); logger.error("订单发券:" + e.getMessage());
} }
// 增加成长值和积分
addScoreAndCredit(updateOrder, coupon, user);
return ret;
}

private void addScoreAndCredit(WxOrder updateOrder, WxCoupon coupon, WxCUser user) {
// 成长值 计算 // 成长值 计算
try { try {
wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, updateOrder, coupon.getBusiness()); wxScoreRulesService.addScore2(EnumScoreType.CONSUMPTION, updateOrder, coupon.getBusiness());
@@ -1421,25 +1414,7 @@ public class WxOrderServiceImpl implements WxOrderService {
} }


@Override @Override
public boolean checkCouponIsFree(WxCUser user, WxCoupon coupon) {
// 检查用户
if (user == null) {
logger.error("用户不存在");
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}
// 检查券
if (coupon == null) {
logger.error("券不存在");
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) {
logger.error("券已下架, couponId: " + coupon.getId());
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID);
}
if (!isCouponMerchantValid(coupon.getId())) {
logger.error("商户不存在, couponId: " + coupon.getId());
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND);
}
public boolean checkCouponIsFree(WxCoupon coupon) {
return coupon.getSalePrice() == 0; return coupon.getSalePrice() == 0;
} }


@@ -1452,6 +1427,7 @@ public class WxOrderServiceImpl implements WxOrderService {
// 4. 积分券 -- 扣减积分 // 4. 积分券 -- 扣减积分
// 10. coupon order // 10. coupon order
// 11. 生成完成后一系列操作 // 11. 生成完成后一系列操作
userCouponMerchantCheck(user, coupon);
if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) { if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) {
//若用户剩余积分比积分售价低则不能支付 //若用户剩余积分比积分售价低则不能支付
if (user.getCredit() == null || user.getCredit() < coupon.getCreditPrice()) { if (user.getCredit() == null || user.getCredit() < coupon.getCreditPrice()) {
@@ -1510,6 +1486,27 @@ public class WxOrderServiceImpl implements WxOrderService {
return record; return record;
} }


private void userCouponMerchantCheck(WxCUser user, WxCoupon coupon) {
// 检查用户
if (user == null) {
logger.error("用户不存在");
throw new MallinkException(ErrorCode.USER_IS_EMPTY);
}
// 检查券
if (coupon == null) {
logger.error("券不存在");
throw new MallinkException(ErrorCode.COUPON_IS_EMPTY);
}
if (coupon.getStatus().equals(EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode())) {
logger.error("券已下架, couponId: " + coupon.getId());
throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID);
}
if (!isCouponMerchantValid(coupon.getId())) {
logger.error("商户不存在, couponId: " + coupon.getId());
throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND);
}
}

private void creditPay(WxCUser user, WxCoupon coupon, WxOrder record) { private void creditPay(WxCUser user, WxCoupon coupon, WxOrder record) {
if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) { if (coupon.getType() == EnumCouponType.COUPON_CREDIT.getCode() || coupon.getType() == EnumCouponType.COUPON_CREDIT_PARK.getCode()) {
//-------此处为【积分支付】记录增加积分操作------- //-------此处为【积分支付】记录增加积分操作-------
@@ -1543,6 +1540,7 @@ public class WxOrderServiceImpl implements WxOrderService {
// 2. save order // 2. save order
// 拼团 // 拼团
// 拼团 // 拼团
userCouponMerchantCheck(user, coupon);
if (orderGroupId != null && !orderGroupId.equals(0L)) { if (orderGroupId != null && !orderGroupId.equals(0L)) {
WxOrderGroup group = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); WxOrderGroup group = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId);
if (group.getStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode())) { if (group.getStatus().equals(EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode())) {


Loading…
Откажи
Сачувај