mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
code review:交易订单的取消
This commit is contained in:
parent
9c0d0c809a
commit
c25bf38f50
@ -20,6 +20,13 @@ public interface CouponApi {
|
||||
*/
|
||||
void useCoupon(@Valid CouponUseReqDTO useReqDTO);
|
||||
|
||||
/**
|
||||
* 退还已使用的优惠券
|
||||
*
|
||||
* @param id 优惠券编号
|
||||
*/
|
||||
void returnUsedCoupon(Long id);
|
||||
|
||||
/**
|
||||
* 校验优惠劵
|
||||
*
|
||||
@ -28,10 +35,4 @@ public interface CouponApi {
|
||||
*/
|
||||
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
||||
|
||||
/**
|
||||
* 退还已使用的优惠券
|
||||
*
|
||||
* @param id 优惠券编号
|
||||
*/
|
||||
void returnUsedCoupon(Long id);
|
||||
}
|
||||
|
@ -28,15 +28,15 @@ public class CouponApiImpl implements CouponApi {
|
||||
useReqDTO.getOrderId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnUsedCoupon(Long id) {
|
||||
couponService.returnUsedCoupon(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CouponRespDTO validateCoupon(CouponValidReqDTO validReqDTO) {
|
||||
CouponDO coupon = couponService.validCoupon(validReqDTO.getId(), validReqDTO.getUserId());
|
||||
return CouponConvert.INSTANCE.convert(coupon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnUsedCoupon(Long id) {
|
||||
couponService.returnUsedCoupon(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -54,6 +54,13 @@ public interface CouponService {
|
||||
*/
|
||||
void useCoupon(Long id, Long userId, Long orderId);
|
||||
|
||||
/**
|
||||
* 退还已使用的优惠券
|
||||
*
|
||||
* @param id 优惠券编号
|
||||
*/
|
||||
void returnUsedCoupon(Long id);
|
||||
|
||||
/**
|
||||
* 回收优惠劵
|
||||
*
|
||||
@ -117,10 +124,4 @@ public interface CouponService {
|
||||
takeCoupon(templateId, CollUtil.newHashSet(userId), CouponTakeTypeEnum.REGISTER);
|
||||
}
|
||||
|
||||
/**
|
||||
* 退还已使用的优惠券
|
||||
*
|
||||
* @param id 优惠券编号
|
||||
*/
|
||||
void returnUsedCoupon(Long id);
|
||||
}
|
||||
|
@ -102,6 +102,29 @@ public class CouponServiceImpl implements CouponService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnUsedCoupon(Long id) {
|
||||
// 校验存在
|
||||
CouponDO coupon = couponMapper.selectById(id);
|
||||
if (coupon == null) {
|
||||
throw exception(COUPON_NOT_EXISTS);
|
||||
}
|
||||
// 校验状态
|
||||
if (ObjectUtil.notEqual(coupon.getTemplateId(), CouponStatusEnum.USED.getStatus())) {
|
||||
throw exception(COUPON_STATUS_NOT_USED);
|
||||
}
|
||||
|
||||
// 退还
|
||||
// TODO @疯狂:最好 where status,避免可能存在的并发问题
|
||||
Integer status = LocalDateTimeUtils.beforeNow(coupon.getValidEndTime())
|
||||
// 退还时可能已经过期了
|
||||
? CouponStatusEnum.EXPIRE.getStatus()
|
||||
: CouponStatusEnum.UNUSED.getStatus();
|
||||
couponMapper.updateById(new CouponDO().setId(id).setStatus(status));
|
||||
|
||||
// TODO 增加优惠券变动记录?
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteCoupon(Long id) {
|
||||
@ -202,27 +225,4 @@ public class CouponServiceImpl implements CouponService {
|
||||
userIds.removeIf(userId -> MapUtil.getInt(userTakeCountMap, userId, 0) >= couponTemplate.getTakeLimitCount());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void returnUsedCoupon(Long id) {
|
||||
// 校验存在
|
||||
CouponDO coupon = couponMapper.selectById(id);
|
||||
if (coupon == null) {
|
||||
throw exception(COUPON_NOT_EXISTS);
|
||||
}
|
||||
|
||||
// 校验状态
|
||||
if (!CouponStatusEnum.USED.getStatus().equals(coupon.getStatus())) {
|
||||
throw exception(COUPON_STATUS_NOT_USED);
|
||||
}
|
||||
|
||||
// 退还
|
||||
Integer status = LocalDateTimeUtils.beforeNow(coupon.getValidEndTime())
|
||||
// 退还时可能已经过期了
|
||||
? CouponStatusEnum.EXPIRE.getStatus()
|
||||
: CouponStatusEnum.UNUSED.getStatus();
|
||||
couponMapper.updateById(new CouponDO().setId(id).setStatus(status));
|
||||
|
||||
// TODO 增加优惠券变动记录?
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -699,7 +699,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
||||
// 3.回滚优惠券
|
||||
couponApi.returnUsedCoupon(order.getCouponId());
|
||||
|
||||
// 4.回滚积分:积分是支付成功后才增加的吧?
|
||||
// 4.回滚积分:积分是支付成功后才增加的吧? 回复:每个项目不同,目前看下来,确认收货貌似更合适,我再看看其它项目的业务选择;
|
||||
|
||||
// TODO 芋艿:OrderLog
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user