修复订单确认页优惠券问题

This commit is contained in:
beaver383
2019-10-09 15:43:40 +08:00
parent 6fec6b588a
commit 898942fa82
6 changed files with 67 additions and 33 deletions

View File

@@ -240,6 +240,7 @@ public class WxOrderService {
Integer cartId = JacksonUtil.parseInteger(body, "cartId");
Integer addressId = JacksonUtil.parseInteger(body, "addressId");
Integer couponId = JacksonUtil.parseInteger(body, "couponId");
Integer userCouponId = JacksonUtil.parseInteger(body, "userCouponId");
String message = JacksonUtil.parseString(body, "message");
Integer grouponRulesId = JacksonUtil.parseInteger(body, "grouponRulesId");
Integer grouponLinkId = JacksonUtil.parseInteger(body, "grouponLinkId");
@@ -301,7 +302,7 @@ public class WxOrderService {
BigDecimal couponPrice = new BigDecimal(0.00);
// 如果couponId=0则没有优惠券couponId=-1则不使用优惠券
if (couponId != 0 && couponId != -1) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, checkedGoodsPrice);
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice);
if (coupon == null) {
return ResponseUtil.badArgumentValue();
}
@@ -390,7 +391,7 @@ public class WxOrderService {
// 如果使用了优惠券,设置优惠券使用状态
if (couponId != 0 && couponId != -1) {
LitemallCouponUser couponUser = couponUserService.queryOne(userId, couponId);
LitemallCouponUser couponUser = couponUserService.findById(userCouponId);
couponUser.setStatus(CouponUserConstant.STATUS_USED);
couponUser.setUsedTime(LocalDateTime.now());
couponUser.setOrderId(orderId);

View File

@@ -4,6 +4,7 @@ import java.time.LocalDateTime;
public class CouponVo {
private Integer id;
private Integer cid;
private String name;
private String desc;
private String tag;
@@ -11,6 +12,7 @@ public class CouponVo {
private String discount;
private LocalDateTime startTime;
private LocalDateTime endTime;
private boolean available;
public Integer getId() {
return id;
@@ -20,6 +22,14 @@ public class CouponVo {
this.id = id;
}
public Integer getCid() {
return cid;
}
public void setCid(Integer cid) {
this.cid = cid;
}
public String getName() {
return name;
}
@@ -75,4 +85,12 @@ public class CouponVo {
public void setEndTime(LocalDateTime endTime) {
this.endTime = endTime;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
}

View File

@@ -386,7 +386,7 @@ public class WxCartController {
* @return 购物车操作结果
*/
@GetMapping("checkout")
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer grouponRulesId) {
public Object checkout(@LoginUser Integer userId, Integer cartId, Integer addressId, Integer couponId, Integer userCouponId, Integer grouponRulesId) {
if (userId == null) {
return ResponseUtil.unlogin();
}
@@ -445,10 +445,12 @@ public class WxCartController {
// 计算优惠券可用情况
BigDecimal tmpCouponPrice = new BigDecimal(0.00);
Integer tmpCouponId = 0;
Integer tmpUserCouponId = 0;
int tmpCouponLength = 0;
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
for(LitemallCouponUser couponUser : couponUserList){
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), checkedGoodsPrice);
tmpUserCouponId = couponUser.getId();
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), tmpUserCouponId, checkedGoodsPrice);
if(coupon == null){
continue;
}
@@ -468,17 +470,20 @@ public class WxCartController {
// 3. 用户已选择优惠券,则测试优惠券是否合适
if (couponId == null || couponId.equals(-1)){
couponId = -1;
userCouponId = -1;
}
else if (couponId.equals(0)) {
couponPrice = tmpCouponPrice;
couponId = tmpCouponId;
userCouponId = tmpUserCouponId;
}
else {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, checkedGoodsPrice);
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponId, userCouponId, checkedGoodsPrice);
// 用户选择的优惠券有问题,则选择合适优惠券,否则使用用户选择的优惠券
if(coupon == null){
couponPrice = tmpCouponPrice;
couponId = tmpCouponId;
userCouponId = tmpUserCouponId;
}
else {
couponPrice = coupon.getDiscount();
@@ -502,6 +507,7 @@ public class WxCartController {
Map<String, Object> data = new HashMap<>();
data.put("addressId", addressId);
data.put("couponId", couponId);
data.put("userCouponId", userCouponId);
data.put("cartId", cartId);
data.put("grouponRulesId", grouponRulesId);
data.put("grouponPrice", grouponPrice);

View File

@@ -99,7 +99,8 @@ public class WxCouponController {
Integer couponId = couponUser.getCouponId();
LitemallCoupon coupon = couponService.findById(couponId);
CouponVo couponVo = new CouponVo();
couponVo.setId(coupon.getId());
couponVo.setId(couponUser.getId());
couponVo.setCid(coupon.getId());
couponVo.setName(coupon.getName());
couponVo.setDesc(coupon.getDesc());
couponVo.setTag(coupon.getTag());
@@ -160,17 +161,12 @@ public class WxCouponController {
// 计算优惠券可用情况
List<LitemallCouponUser> couponUserList = couponUserService.queryAll(userId);
List<LitemallCouponUser> availableCouponUserList = new ArrayList<>(couponUserList.size());
for (LitemallCouponUser couponUser : couponUserList) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, couponUser.getCouponId(), checkedGoodsPrice);
if (coupon == null) {
continue;
}
availableCouponUserList.add(couponUser);
List<CouponVo> couponVoList = change(couponUserList);
for (CouponVo cv : couponVoList) {
LitemallCoupon coupon = couponVerifyService.checkCoupon(userId, cv.getCid(), cv.getId(), checkedGoodsPrice);
cv.setAvailable(coupon != null);
}
List<CouponVo> couponVoList = change(availableCouponUserList);
return ResponseUtil.okList(couponVoList);
}