记得上下班打卡 | git大法好,push需谨慎

Commit 9357af17 authored by 胡佳晨's avatar 胡佳晨

修改券接口

parent a33dd465
...@@ -23,7 +23,7 @@ public interface GoblinCouponService { ...@@ -23,7 +23,7 @@ public interface GoblinCouponService {
List<GoblinUserCouponVo> getList(String type); List<GoblinUserCouponVo> getList(String type);
//是否可用券 [价格] [spuId逗号隔开] [uid] //是否可用券 [价格] [spuId逗号隔开] [uid]
Boolean canUse(BigDecimal totalPrice, String spuId, String uid); GoblinUserCouponVo canUse(BigDecimal totalPrice, String spuId, String uid);
//可用券列表 [价格] [spuId逗号隔开] [uid] //可用券列表 [价格] [spuId逗号隔开] [uid]
List<GoblinUserCouponVo> useList(BigDecimal totalPrice, String spuId, String uid); List<GoblinUserCouponVo> useList(BigDecimal totalPrice, String spuId, String uid);
......
...@@ -101,14 +101,14 @@ public class GoblinCouponController { ...@@ -101,14 +101,14 @@ public class GoblinCouponController {
} }
@PostMapping("can/use") @PostMapping("can/use")
@ApiOperation("是否可用券") @ApiOperation("是否可用券[计算价格最高并返回vo]")
@ApiResponse(code = 200, message = "接口返回对象参数") @ApiResponse(code = 200, message = "接口返回对象参数")
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(type = "form", required = true, dataType = "Number", name = "totalPrice", value = "spuId"), @ApiImplicitParam(type = "form", required = true, dataType = "Number", name = "totalPrice", value = "spuId"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "逗号隔开"), @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "spuId", value = "逗号隔开"),
@ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "用户id"), @ApiImplicitParam(type = "form", required = true, dataType = "String", name = "uid", value = "用户id"),
}) })
public ResponseDto<Boolean> canUse(@RequestParam("totalPrice") @Valid BigDecimal totalPrice, public ResponseDto<GoblinUserCouponVo> canUse(@RequestParam("totalPrice") @Valid BigDecimal totalPrice,
@RequestParam("spuId") @Valid String spuId, @RequestParam("spuId") @Valid String spuId,
@RequestParam(value = "uid", required = false) @Valid String uid) { @RequestParam(value = "uid", required = false) @Valid String uid) {
if (uid == null) { if (uid == null) {
......
...@@ -122,9 +122,10 @@ public class GoblinCouponImpl implements GoblinCouponService { ...@@ -122,9 +122,10 @@ public class GoblinCouponImpl implements GoblinCouponService {
} }
@Override @Override
public Boolean canUse(BigDecimal totalPrice, String spuId, String uid) { public GoblinUserCouponVo canUse(BigDecimal totalPrice, String spuId, String uid) {
BigDecimal maxPrice = BigDecimal.ZERO;
GoblinUserCouponVo returnVo = GoblinUserCouponVo.getNew();
List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid); List<GoblinUserCouponVo> voList = goblinRedisUtils.getUserCouponVos(uid);
Boolean canUse = false;
for (GoblinUserCouponVo vo : voList) { for (GoblinUserCouponVo vo : voList) {
//判断券状态 和 触发金额 //判断券状态 和 触发金额
if (vo.getState().equals(1) && vo.getTriggers().compareTo(totalPrice) >= 0) { if (vo.getState().equals(1) && vo.getTriggers().compareTo(totalPrice) >= 0) {
...@@ -133,16 +134,23 @@ public class GoblinCouponImpl implements GoblinCouponService { ...@@ -133,16 +134,23 @@ public class GoblinCouponImpl implements GoblinCouponService {
for (String item : spuIds) { for (String item : spuIds) {
List<String> spuList = Arrays.asList(spuId.split(",")); List<String> spuList = Arrays.asList(spuId.split(","));
if (spuList.contains(item)) { if (spuList.contains(item)) {
canUse = true; BigDecimal tempPrice = BigDecimal.ZERO;
break; if (vo.getType().equals("1")) {//代金券
tempPrice = vo.getValFace();
} else if (vo.getType().equals("2")) {//折扣
tempPrice = totalPrice.multiply(vo.getDeduction()).setScale(2, BigDecimal.ROUND_HALF_UP);
} else if (vo.getType().equals("3") && vo.getTriggers().compareTo(totalPrice) >= 0) {//满减
tempPrice = vo.getValMinus();
}
if (maxPrice.compareTo(tempPrice) < 0) {
maxPrice = tempPrice;
returnVo = vo;
}
} }
} }
} }
if (canUse) {
break;
}
} }
return canUse; return returnVo;
} }
@Override @Override
...@@ -195,7 +203,7 @@ public class GoblinCouponImpl implements GoblinCouponService { ...@@ -195,7 +203,7 @@ public class GoblinCouponImpl implements GoblinCouponService {
vo.setUsedFor(content); vo.setUsedFor(content);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo); goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(), queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(),vo.getUsedFor(),LocalDateTime.now())); SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now()));
break; break;
} }
} }
...@@ -222,7 +230,7 @@ public class GoblinCouponImpl implements GoblinCouponService { ...@@ -222,7 +230,7 @@ public class GoblinCouponImpl implements GoblinCouponService {
goblinRedisUtils.setUserCouponVos(item.getUid(), voList); goblinRedisUtils.setUserCouponVos(item.getUid(), voList);
goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo); goblinMongoUtils.changeCouponVos(vo.getUcouponId(), vo);
queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(), queueUtils.sendMsgByRedis(MQConst.GoblinQueue.SQL_STORE.getKey(),
SqlMapping.get("goblin_user_coupon.updateState", vo.getState(),vo.getUsedFor(),LocalDateTime.now())); SqlMapping.get("goblin_user_coupon.updateState", vo.getState(), vo.getUsedFor(), LocalDateTime.now()));
} }
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment