OrderCouponController.java
4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.yohoufo.promotion.controller;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.promotion.UserCouponsListBo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.promotion.service.ICouponService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* 全部是给订单的接口
*/
@RestController
@RequestMapping(value = "/orderCoupon")
public class OrderCouponController {
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
ICouponService couponService;
/**
* 使用优惠券(订单使用)
* @param uid
* @param couponCodes
* @param orderCode
* @return
*/
@RequestMapping(params = "method=ufo.coupons.use")
@ResponseBody
public ApiResponse useCoupon(@RequestParam(value = "uid") Integer uid,
@RequestParam(value = "orderCode") long orderCode,
@RequestParam(value = "couponCodes") List<String> couponCodes) {
logger.info("use coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode);
boolean useSuccess = couponService.useCoupon(uid, couponCodes, orderCode);
logger.info("use coupons, uid: {},couponCodes: {}, orderCode :{},result: {}", uid, couponCodes, orderCode, useSuccess);
return new ApiResponse.ApiResponseBuilder().code(200).data(useSuccess).build();
}
/**
* 使用优惠券(订单退还)
* @param uid
* @param couponCodes
* @param orderCode
* @return
*/
@RequestMapping(params = "method=ufo.coupons.cancel")
@ResponseBody
public ApiResponse cancelCoupon(@RequestParam(value = "uid") Integer uid,
@RequestParam(value = "orderCode") long orderCode,
@RequestParam(value = "couponCodes") List<String> couponCodes) {
logger.info("cancel coupons, uid: {},couponCodes: {}, orderCode :{}", uid, couponCodes, orderCode);
boolean cancelSuccess = couponService.cancelCoupon(uid, couponCodes, orderCode);
logger.info("cancel coupons, uid: {},couponCodes: {}, orderCode :{},result: {}", uid, couponCodes, orderCode, cancelSuccess);
return new ApiResponse.ApiResponseBuilder().code(200).data(cancelSuccess).build();
}
/**
* 优惠券列表(订单使用)
* @param uid
* @return
*/
@RequestMapping(params = "method=ufo.coupons.listNoUsed")
@ResponseBody
public ApiResponse queryUserNoUsedCoupons(@RequestParam(value = "uid") Integer uid) {
logger.info("use coupons, uid: {}", uid);
UserCouponsListBo couponBoList = couponService.queryUserNoUsedCoupons(uid);
logger.info("use coupons, uid: {}, success", uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(couponBoList).build();
}
/**
* 优惠券列表(订单使用)
*
* @param uid
* @return
*/
@RequestMapping(params = "method=ufo.coupons.checkAndGet")
@ResponseBody
public ApiResponse checkAndGetCoupons(@RequestParam(value = "uid") int uid,
@RequestParam(value = "couponCodes") List<String> couponCodes) {
logger.info("checkAndGet coupons, uid: {},couponCodes:{}", uid, couponCodes);
if (uid <= 0 || CollectionUtils.isEmpty(couponCodes)) {
throw new ServiceException(ServiceError.PROMOTION_REQUEST_PAREMENT_ERROR);
}
UserCouponsListBo couponBoList = couponService.checkAndGetCoupons(uid, couponCodes);
logger.info("checkAndGet coupons, uid: {},couponCodes:{},success", uid, couponCodes);
return new ApiResponse.ApiResponseBuilder().code(200).data(couponBoList).build();
}
}