mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
trade: 会员取消订单
This commit is contained in:
parent
361ad2e22a
commit
b3fcefa677
@ -28,4 +28,10 @@ public interface CouponApi {
|
|||||||
*/
|
*/
|
||||||
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
CouponRespDTO validateCoupon(@Valid CouponValidReqDTO validReqDTO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退还已使用的优惠券
|
||||||
|
*
|
||||||
|
* @param id 优惠券编号
|
||||||
|
*/
|
||||||
|
void returnUsedCoupon(Long id);
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode COUPON_DELETE_FAIL_USED = new ErrorCode(1013005001, "回收优惠劵失败,优惠劵已被使用");
|
ErrorCode COUPON_DELETE_FAIL_USED = new ErrorCode(1013005001, "回收优惠劵失败,优惠劵已被使用");
|
||||||
ErrorCode COUPON_STATUS_NOT_UNUSED = new ErrorCode(1013005002, "优惠劵不处于待使用状态");
|
ErrorCode COUPON_STATUS_NOT_UNUSED = new ErrorCode(1013005002, "优惠劵不处于待使用状态");
|
||||||
ErrorCode COUPON_VALID_TIME_NOT_NOW = new ErrorCode(1013005003, "优惠券不在使用时间范围内");
|
ErrorCode COUPON_VALID_TIME_NOT_NOW = new ErrorCode(1013005003, "优惠券不在使用时间范围内");
|
||||||
|
ErrorCode COUPON_STATUS_NOT_USED = new ErrorCode(1013005004, "优惠劵不是已使用状态");
|
||||||
|
|
||||||
// ========== 满减送活动 1013006000 ==========
|
// ========== 满减送活动 1013006000 ==========
|
||||||
ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1013006000, "满减送活动不存在");
|
ErrorCode REWARD_ACTIVITY_NOT_EXISTS = new ErrorCode(1013006000, "满减送活动不存在");
|
||||||
|
@ -34,4 +34,9 @@ public class CouponApiImpl implements CouponApi {
|
|||||||
return CouponConvert.INSTANCE.convert(coupon);
|
return CouponConvert.INSTANCE.convert(coupon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void returnUsedCoupon(Long id) {
|
||||||
|
couponService.returnUsedCoupon(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -75,4 +75,10 @@ public interface CouponService {
|
|||||||
*/
|
*/
|
||||||
Long getUnusedCouponCount(Long userId);
|
Long getUnusedCouponCount(Long userId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退还已使用的优惠券
|
||||||
|
*
|
||||||
|
* @param id 优惠券编号
|
||||||
|
*/
|
||||||
|
void returnUsedCoupon(Long id);
|
||||||
}
|
}
|
||||||
|
@ -125,4 +125,27 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
return couponMapper.selectCountByUserIdAndStatus(userId, CouponStatusEnum.UNUSED.getStatus());
|
return couponMapper.selectCountByUserIdAndStatus(userId, CouponStatusEnum.UNUSED.getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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 增加优惠券变动记录?
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ public interface ErrorCodeConstants {
|
|||||||
ErrorCode ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000022, "交易订单发货失败,拼团未成功");
|
ErrorCode ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000022, "交易订单发货失败,拼团未成功");
|
||||||
ErrorCode ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000023, "交易订单发货失败,砍价未成功");
|
ErrorCode ORDER_DELIVERY_FAIL_BARGAIN_RECORD_STATUS_NOT_SUCCESS = new ErrorCode(1011000023, "交易订单发货失败,砍价未成功");
|
||||||
ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递");
|
ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递");
|
||||||
|
ErrorCode ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID = new ErrorCode(1011000025, "交易订单取消失败,订单不是【待支付】状态");
|
||||||
|
|
||||||
// ========== After Sale 模块 1011000100 ==========
|
// ========== After Sale 模块 1011000100 ==========
|
||||||
ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在");
|
ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在");
|
||||||
|
@ -150,7 +150,7 @@ public class AppTradeOrderController {
|
|||||||
@Operation(summary = "取消交易订单")
|
@Operation(summary = "取消交易订单")
|
||||||
@Parameter(name = "id", description = "交易订单编号")
|
@Parameter(name = "id", description = "交易订单编号")
|
||||||
public CommonResult<Boolean> cancelOrder(@RequestParam("id") Long id) {
|
public CommonResult<Boolean> cancelOrder(@RequestParam("id") Long id) {
|
||||||
// TODO @芋艿:未实现,mock 用
|
tradeOrderUpdateService.cancelOrder(getLoginUserId(), id);
|
||||||
return success(true);
|
return success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,6 +86,12 @@ public interface TradeOrderConvert {
|
|||||||
default ProductSkuUpdateStockReqDTO convert(List<TradeOrderItemDO> list) {
|
default ProductSkuUpdateStockReqDTO convert(List<TradeOrderItemDO> list) {
|
||||||
return new ProductSkuUpdateStockReqDTO(TradeOrderConvert.INSTANCE.convertList(list));
|
return new ProductSkuUpdateStockReqDTO(TradeOrderConvert.INSTANCE.convertList(list));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default ProductSkuUpdateStockReqDTO convertNegative(List<TradeOrderItemDO> list) {
|
||||||
|
List<ProductSkuUpdateStockReqDTO.Item> items = TradeOrderConvert.INSTANCE.convertList(list);
|
||||||
|
items.forEach(item -> item.setIncrCount(-item.getIncrCount()));
|
||||||
|
return new ProductSkuUpdateStockReqDTO(items);
|
||||||
|
}
|
||||||
List<ProductSkuUpdateStockReqDTO.Item> convertList(List<TradeOrderItemDO> list);
|
List<ProductSkuUpdateStockReqDTO.Item> convertList(List<TradeOrderItemDO> list);
|
||||||
@Mappings({
|
@Mappings({
|
||||||
@Mapping(source = "skuId", target = "id"),
|
@Mapping(source = "skuId", target = "id"),
|
||||||
|
@ -117,4 +117,11 @@ public interface TradeOrderUpdateService {
|
|||||||
*/
|
*/
|
||||||
Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO);
|
Long createOrderItemComment(Long userId, AppTradeOrderItemCommentCreateReqVO createReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 【会员】取消订单
|
||||||
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
|
* @param id 订单编号
|
||||||
|
*/
|
||||||
|
void cancelOrder(Long userId, Long id);
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> orderItems,
|
TradeOrderDO tradeOrderDO, List<TradeOrderItemDO> orderItems,
|
||||||
TradePriceCalculateRespBO calculateRespBO) {
|
TradePriceCalculateRespBO calculateRespBO) {
|
||||||
// 下单时扣减商品库存
|
// 下单时扣减商品库存
|
||||||
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
|
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(orderItems));
|
||||||
|
|
||||||
// 删除购物车商品
|
// 删除购物车商品
|
||||||
Set<Long> cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId);
|
Set<Long> cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId);
|
||||||
@ -299,7 +299,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
cartService.deleteCart(userId, cartIds);
|
cartService.deleteCart(userId, cartIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 扣减积分 TODO 芋艿:待实现
|
// 扣减积分 TODO 芋艿:待实现, 这个是不是应该放到支付成功之后?
|
||||||
|
|
||||||
// 有使用优惠券时更新
|
// 有使用优惠券时更新
|
||||||
if (createReqVO.getCouponId() != null) {
|
if (createReqVO.getCouponId() != null) {
|
||||||
@ -655,6 +655,41 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService {
|
|||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cancelOrder(Long userId, Long id) {
|
||||||
|
// 校验存在
|
||||||
|
TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(id, userId);
|
||||||
|
if (order == null) {
|
||||||
|
throw exception(ORDER_NOT_FOUND);
|
||||||
|
}
|
||||||
|
// 校验状态
|
||||||
|
if (ObjectUtil.notEqual(order.getStatus(), TradeOrderStatusEnum.UNPAID.getStatus())) {
|
||||||
|
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1.更新 TradeOrderDO 状态为已取消
|
||||||
|
int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(),
|
||||||
|
new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus())
|
||||||
|
.setCancelTime(LocalDateTime.now())
|
||||||
|
.setCancelType(TradeOrderCancelTypeEnum.MEMBER_CANCEL.getType()));
|
||||||
|
if (updateCount == 0) {
|
||||||
|
throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2.回滚库存
|
||||||
|
List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id);
|
||||||
|
productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems));
|
||||||
|
|
||||||
|
// 3.回滚优惠券
|
||||||
|
couponApi.returnUsedCoupon(order.getCouponId());
|
||||||
|
|
||||||
|
// 4.回滚积分:积分是支付成功后才增加的吧?
|
||||||
|
|
||||||
|
// TODO 芋艿:OrderLog
|
||||||
|
|
||||||
|
// TODO 芋艿:lili 发送订单变化的消息
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断指定订单的所有订单项,是不是都售后成功
|
* 判断指定订单的所有订单项,是不是都售后成功
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user