Przeglądaj źródła

[砍价][新增]:检查用户是否已参与砍价

release_toaliyun_real
Stormeye Wu 7 lat temu
rodzic
commit
3f2622f3a5
3 zmienionych plików z 35 dodań i 10 usunięć
  1. +23
    -10
      mallinkCApi/src/main/java/com/iformall/controller/WxPressOrderController.java
  2. +1
    -0
      mallinkService/src/main/java/com/iformall/common/ErrorCode.java
  3. +11
    -0
      mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java

+ 23
- 10
mallinkCApi/src/main/java/com/iformall/controller/WxPressOrderController.java Wyświetl plik

@@ -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<String, String> 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();
}


+ 1
- 0
mallinkService/src/main/java/com/iformall/common/ErrorCode.java Wyświetl plik

@@ -162,6 +162,7 @@ public enum ErrorCode{
*/
COUPON_PRESS_HAD_FINISHED(9070, "砍价已完成"),
COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"),
COUPON_PRESS_IS_EXIST(9072, "此人已参与此次砍价"),





+ 11
- 0
mallinkService/src/main/java/com/iformall/service/impl/WxOrderPressServiceImpl.java Wyświetl plik

@@ -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);


Ładowanie…
Anuluj
Zapisz