Commit c485c6e04de2f1d1a0db144e32c44f15c3bfadfd
1 parent
c9531757
订单:重构拼团下单流程更改为订单支付后再创建拼团记录
Showing
14 changed files
with
117 additions
and
140 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java
| ... | ... | @@ -4,7 +4,6 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCr |
| 4 | 4 | import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; |
| 5 | 5 | |
| 6 | 6 | import javax.validation.Valid; |
| 7 | -import java.time.LocalDateTime; | |
| 8 | 7 | |
| 9 | 8 | // TODO @芋艿:后面也再撸撸这几个接口 |
| 10 | 9 | |
| ... | ... | @@ -43,14 +42,6 @@ public interface CombinationRecordApi { |
| 43 | 42 | boolean isCombinationRecordSuccess(Long userId, Long orderId); |
| 44 | 43 | |
| 45 | 44 | /** |
| 46 | - * 更新拼团状态为【成功】 | |
| 47 | - * | |
| 48 | - * @param userId 用户编号 | |
| 49 | - * @param orderId 订单编号 | |
| 50 | - */ | |
| 51 | - void updateRecordStatusToSuccess(Long userId, Long orderId); | |
| 52 | - | |
| 53 | - /** | |
| 54 | 45 | * 更新拼团状态为【失败】 |
| 55 | 46 | * |
| 56 | 47 | * @param userId 用户编号 |
| ... | ... | @@ -59,15 +50,6 @@ public interface CombinationRecordApi { |
| 59 | 50 | void updateRecordStatusToFailed(Long userId, Long orderId); |
| 60 | 51 | |
| 61 | 52 | /** |
| 62 | - * 更新拼团状态为 进行中 | |
| 63 | - * | |
| 64 | - * @param userId 用户编号 | |
| 65 | - * @param orderId 订单编号 | |
| 66 | - * @param startTime 开始时间 | |
| 67 | - */ | |
| 68 | - void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime); | |
| 69 | - | |
| 70 | - /** | |
| 71 | 53 | * 【下单前】校验是否满足拼团活动条件 |
| 72 | 54 | * |
| 73 | 55 | * 如果校验失败,则抛出业务异常 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java
| ... | ... | @@ -8,7 +8,6 @@ import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordSe |
| 8 | 8 | import org.springframework.stereotype.Service; |
| 9 | 9 | |
| 10 | 10 | import javax.annotation.Resource; |
| 11 | -import java.time.LocalDateTime; | |
| 12 | 11 | |
| 13 | 12 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 14 | 13 | import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COMBINATION_RECORD_NOT_EXISTS; |
| ... | ... | @@ -45,22 +44,11 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { |
| 45 | 44 | } |
| 46 | 45 | |
| 47 | 46 | @Override |
| 48 | - public void updateRecordStatusToSuccess(Long userId, Long orderId) { | |
| 49 | - recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.SUCCESS.getStatus(), userId, orderId); | |
| 50 | - } | |
| 51 | - | |
| 52 | - @Override | |
| 53 | 47 | public void updateRecordStatusToFailed(Long userId, Long orderId) { |
| 54 | 48 | recordService.updateCombinationRecordStatusByUserIdAndOrderId(CombinationRecordStatusEnum.FAILED.getStatus(), userId, orderId); |
| 55 | 49 | } |
| 56 | 50 | |
| 57 | 51 | @Override |
| 58 | - public void updateRecordStatusToInProgress(Long userId, Long orderId, LocalDateTime startTime) { | |
| 59 | - recordService.updateRecordStatusAndStartTimeByUserIdAndOrderId(CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), | |
| 60 | - userId, orderId, startTime); | |
| 61 | - } | |
| 62 | - | |
| 63 | - @Override | |
| 64 | 52 | public CombinationValidateJoinRespDTO validateJoinCombination(Long userId, Long activityId, Long headId, Long skuId, Integer count) { |
| 65 | 53 | return recordService.validateJoinCombination(userId, activityId, headId, skuId, count); |
| 66 | 54 | } | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java
| ... | ... | @@ -22,11 +22,13 @@ import cn.iocoder.yudao.module.promotion.controller.app.combination.vo.record.Ap |
| 22 | 22 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; |
| 23 | 23 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; |
| 24 | 24 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 25 | +import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; | |
| 25 | 26 | import org.mapstruct.Mapper; |
| 26 | 27 | import org.mapstruct.Mapping; |
| 27 | 28 | import org.mapstruct.Mappings; |
| 28 | 29 | import org.mapstruct.factory.Mappers; |
| 29 | 30 | |
| 31 | +import java.time.LocalDateTime; | |
| 30 | 32 | import java.util.List; |
| 31 | 33 | import java.util.Map; |
| 32 | 34 | |
| ... | ... | @@ -110,14 +112,19 @@ public interface CombinationActivityConvert { |
| 110 | 112 | CombinationActivityDO activity, MemberUserRespDTO user, |
| 111 | 113 | ProductSpuRespDTO spu, ProductSkuRespDTO sku) { |
| 112 | 114 | return convert(reqDTO) |
| 113 | - .setCount(reqDTO.getCount()).setUserCount(1) | |
| 115 | + .setHeadId(reqDTO.getHeadId()) // 显示性再设置一下 | |
| 116 | + .setCount(reqDTO.getCount()) | |
| 114 | 117 | .setVirtualGroup(false) |
| 118 | + .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 | |
| 119 | + .setStartTime(LocalDateTime.now()) | |
| 115 | 120 | .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) |
| 116 | 121 | .setUserSize(activity.getUserSize()) |
| 122 | + .setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 | |
| 117 | 123 | .setNickname(user.getNickname()) |
| 118 | 124 | .setAvatar(user.getAvatar()) |
| 119 | 125 | .setSpuName(spu.getName()) |
| 120 | 126 | .setPicUrl(sku.getPicUrl()); |
| 127 | + | |
| 121 | 128 | } |
| 122 | 129 | |
| 123 | 130 | List<AppCombinationActivityRespVO> convertAppList(List<CombinationActivityDO> list); | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java
| ... | ... | @@ -32,12 +32,6 @@ public interface CombinationRecordMapper extends BaseMapperX<CombinationRecordDO |
| 32 | 32 | CombinationRecordDO::getOrderId, orderId); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - default List<CombinationRecordDO> selectListByUserIdAndStatus(Long userId, Integer status) { | |
| 36 | - return selectList(new LambdaQueryWrapperX<CombinationRecordDO>() | |
| 37 | - .eq(CombinationRecordDO::getUserId, userId) | |
| 38 | - .eq(CombinationRecordDO::getStatus, status)); | |
| 39 | - } | |
| 40 | - | |
| 41 | 35 | /** |
| 42 | 36 | * 查询拼团记录 |
| 43 | 37 | * | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java
| ... | ... | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP |
| 10 | 10 | import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; |
| 11 | 11 | |
| 12 | 12 | import javax.annotation.Nullable; |
| 13 | -import java.time.LocalDateTime; | |
| 14 | 13 | import java.util.Collection; |
| 15 | 14 | import java.util.List; |
| 16 | 15 | import java.util.Map; |
| ... | ... | @@ -53,16 +52,6 @@ public interface CombinationRecordService { |
| 53 | 52 | void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); |
| 54 | 53 | |
| 55 | 54 | /** |
| 56 | - * 更新拼团状态和开始时间 | |
| 57 | - * | |
| 58 | - * @param status 状态 | |
| 59 | - * @param userId 用户编号 | |
| 60 | - * @param orderId 订单编号 | |
| 61 | - * @param startTime 开始时间 | |
| 62 | - */ | |
| 63 | - void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime); | |
| 64 | - | |
| 65 | - /** | |
| 66 | 55 | * 获得拼团记录 |
| 67 | 56 | * |
| 68 | 57 | * @param userId 用户编号 | ... | ... |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
| ... | ... | @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.promotion.service.combination; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.ObjUtil; |
| 5 | -import cn.hutool.core.util.ObjectUtil; | |
| 6 | 5 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 7 | 6 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 8 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| ... | ... | @@ -22,7 +21,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR |
| 22 | 21 | import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; |
| 23 | 22 | import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; |
| 24 | 23 | import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; |
| 25 | -import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; | |
| 26 | 24 | import org.springframework.context.annotation.Lazy; |
| 27 | 25 | import org.springframework.stereotype.Service; |
| 28 | 26 | import org.springframework.transaction.annotation.Transactional; |
| ... | ... | @@ -30,7 +28,7 @@ import org.springframework.validation.annotation.Validated; |
| 30 | 28 | |
| 31 | 29 | import javax.annotation.Nullable; |
| 32 | 30 | import javax.annotation.Resource; |
| 33 | -import java.time.LocalDateTime; | |
| 31 | +import java.util.ArrayList; | |
| 34 | 32 | import java.util.Collection; |
| 35 | 33 | import java.util.List; |
| 36 | 34 | import java.util.Map; |
| ... | ... | @@ -80,30 +78,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 80 | 78 | recordMapper.updateById(record); |
| 81 | 79 | } |
| 82 | 80 | |
| 83 | - @Override | |
| 84 | - @Transactional(rollbackFor = Exception.class) | |
| 85 | - public void updateRecordStatusAndStartTimeByUserIdAndOrderId(Integer status, Long userId, Long orderId, LocalDateTime startTime) { | |
| 86 | - CombinationRecordDO record = validateCombinationRecord(userId, orderId); | |
| 87 | - // 更新状态 | |
| 88 | - record.setStatus(status); | |
| 89 | - // 更新开始时间 | |
| 90 | - record.setStartTime(startTime); | |
| 91 | - recordMapper.updateById(record); | |
| 92 | - | |
| 93 | - // 更新拼团参入人数 | |
| 94 | - List<CombinationRecordDO> records = recordMapper.selectListByHeadIdAndStatus(record.getHeadId(), status); | |
| 95 | - if (CollUtil.isNotEmpty(records)) { | |
| 96 | - records.forEach(item -> { | |
| 97 | - item.setUserCount(records.size()); | |
| 98 | - // 校验拼团是否满足要求 | |
| 99 | - if (ObjectUtil.equal(records.size(), record.getUserSize())) { | |
| 100 | - item.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); | |
| 101 | - } | |
| 102 | - }); | |
| 103 | - recordMapper.updateBatch(records); | |
| 104 | - } | |
| 105 | - } | |
| 106 | - | |
| 107 | 81 | private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { |
| 108 | 82 | // 校验拼团是否存在 |
| 109 | 83 | CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId); |
| ... | ... | @@ -143,15 +117,15 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 143 | 117 | if (ObjUtil.equal(record.getUserCount(), record.getUserSize())) { |
| 144 | 118 | throw exception(COMBINATION_RECORD_USER_FULL); |
| 145 | 119 | } |
| 146 | - // 2.3、校验拼团是否过期 | |
| 120 | + // 2.3、校验拼团是否过期(有父拼团的时候只校验父拼团的过期时间) | |
| 147 | 121 | if (beforeNow(record.getExpireTime())) { |
| 148 | 122 | throw exception(COMBINATION_RECORD_FAILED_TIME_END); |
| 149 | 123 | } |
| 150 | - } | |
| 151 | - | |
| 152 | - // 3、校验当前活动是否结束 | |
| 153 | - if (beforeNow(activity.getEndTime())) { | |
| 154 | - throw exception(COMBINATION_RECORD_FAILED_TIME_END); | |
| 124 | + } else { | |
| 125 | + // 3、校验当前活动是否结束(自己是父拼团的时候才校验活动是否结束) | |
| 126 | + if (beforeNow(activity.getEndTime())) { | |
| 127 | + throw exception(COMBINATION_RECORD_FAILED_TIME_END); | |
| 128 | + } | |
| 155 | 129 | } |
| 156 | 130 | |
| 157 | 131 | // 4、校验活动商品是否存在 |
| ... | ... | @@ -187,19 +161,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 187 | 161 | throw exception(COMBINATION_RECORD_FAILED_TOTAL_LIMIT_COUNT_EXCEED); |
| 188 | 162 | } |
| 189 | 163 | |
| 190 | - // 7、校验拼团记录是否存在未支付的订单(如果存在未支付的订单则不允许发起新的拼团) | |
| 191 | - CombinationRecordDO record = findFirst(recordList, item -> ObjectUtil.equals(item.getStatus(), null)); | |
| 192 | - if (record == null) { | |
| 193 | - return new KeyValue<>(activity, product); | |
| 194 | - } | |
| 195 | - // 7.1、查询关联的订单是否已经支付 | |
| 196 | - // 当前 activityId 已经有未支付的订单,不允许在发起新的;要么支付,要么去掉先; | |
| 197 | - // TODO 芋艿:看看是不是可以删除掉; | |
| 198 | - Integer orderStatus = tradeOrderApi.getOrderStatus(record.getOrderId()); | |
| 199 | - if (ObjectUtil.equal(orderStatus, TradeOrderStatusEnum.UNPAID.getStatus())) { | |
| 200 | - throw exception(COMBINATION_RECORD_FAILED_ORDER_STATUS_UNPAID); | |
| 201 | - } | |
| 202 | - | |
| 203 | 164 | return new KeyValue<>(activity, product); |
| 204 | 165 | } |
| 205 | 166 | |
| ... | ... | @@ -215,9 +176,62 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { |
| 215 | 176 | MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); |
| 216 | 177 | ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); |
| 217 | 178 | ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); |
| 218 | - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku)); | |
| 219 | - // TODO @puhui999:status 未设置;headId 未设置 | |
| 220 | - recordMapper.insert(CombinationActivityConvert.INSTANCE.convert(reqDTO, activity, user, spu, sku)); | |
| 179 | + CombinationRecordDO recordDO = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); | |
| 180 | + recordMapper.insert(recordDO); | |
| 181 | + | |
| 182 | + // 3、如果是团长需要设置 headId 为它自己 | |
| 183 | + if (reqDTO.getHeadId() == null) { | |
| 184 | + recordMapper.updateById(new CombinationRecordDO().setId(recordDO.getId()).setHeadId(recordDO.getId())); | |
| 185 | + return; | |
| 186 | + } | |
| 187 | + | |
| 188 | + // TODO 这里要不要弄成异步的 | |
| 189 | + // 4、更新拼团相关信息到订单 | |
| 190 | + updateOrderCombinationInfo(recordDO.getOrderId(), recordDO.getActivityId(), recordDO.getId(), recordDO.getHeadId()); | |
| 191 | + // 4、更新拼团记录 | |
| 192 | + updateCombinationRecords(keyValue.getKey(), reqDTO.getHeadId()); | |
| 193 | + | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * 更新拼团相关信息到订单 | |
| 198 | + * | |
| 199 | + * @param orderId 订单编号 | |
| 200 | + * @param activityId 拼团活动编号 | |
| 201 | + * @param combinationRecordId 拼团记录编号 | |
| 202 | + * @param headId 团长编号 | |
| 203 | + */ | |
| 204 | + private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { | |
| 205 | + tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * 更新拼团记录 | |
| 210 | + * | |
| 211 | + * @param activity 活动 | |
| 212 | + * @param headId 团长编号 | |
| 213 | + */ | |
| 214 | + private void updateCombinationRecords(CombinationActivityDO activity, Long headId) { | |
| 215 | + List<CombinationRecordDO> records = recordMapper.selectList(CombinationRecordDO::getHeadId, headId); | |
| 216 | + List<CombinationRecordDO> updateRecords = new ArrayList<>(); | |
| 217 | + | |
| 218 | + if (CollUtil.isEmpty(records)) { | |
| 219 | + return; | |
| 220 | + } | |
| 221 | + | |
| 222 | + boolean isEqual = ObjUtil.equal(records.size(), activity.getUserSize()); | |
| 223 | + records.forEach(item -> { | |
| 224 | + CombinationRecordDO recordDO = new CombinationRecordDO(); | |
| 225 | + recordDO.setId(item.getId()); | |
| 226 | + recordDO.setUserCount(records.size()); | |
| 227 | + // 校验拼团是否满足要求 | |
| 228 | + if (isEqual) { | |
| 229 | + recordDO.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); | |
| 230 | + } | |
| 231 | + updateRecords.add(recordDO); | |
| 232 | + }); | |
| 233 | + | |
| 234 | + recordMapper.updateBatch(updateRecords); | |
| 221 | 235 | } |
| 222 | 236 | |
| 223 | 237 | @Override | ... | ... |
yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java
| ... | ... | @@ -30,15 +30,6 @@ public interface TradeOrderApi { |
| 30 | 30 | */ |
| 31 | 31 | TradeOrderRespDTO getOrder(Long id); |
| 32 | 32 | |
| 33 | - // TODO 芋艿:看看是不是可以删除掉; | |
| 34 | - /** | |
| 35 | - * 获取订单状态 | |
| 36 | - * | |
| 37 | - * @param id 订单编号 | |
| 38 | - * @return 订单状态 | |
| 39 | - */ | |
| 40 | - Integer getOrderStatus(Long id); | |
| 41 | - | |
| 42 | 33 | /** |
| 43 | 34 | * 获取订单统计 |
| 44 | 35 | * |
| ... | ... | @@ -48,4 +39,14 @@ public interface TradeOrderApi { |
| 48 | 39 | */ |
| 49 | 40 | TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); |
| 50 | 41 | |
| 42 | + /** | |
| 43 | + * 更新拼团相关信息到订单 | |
| 44 | + * | |
| 45 | + * @param orderId 订单编号 | |
| 46 | + * @param activityId 拼团活动编号 | |
| 47 | + * @param combinationRecordId 拼团记录编号 | |
| 48 | + * @param headId 团长编号 | |
| 49 | + */ | |
| 50 | + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); | |
| 51 | + | |
| 51 | 52 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java
| ... | ... | @@ -3,20 +3,16 @@ package cn.iocoder.yudao.module.trade.api.order; |
| 3 | 3 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; |
| 4 | 4 | import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; |
| 5 | 5 | import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; |
| 6 | -import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; | |
| 7 | 6 | import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; |
| 7 | +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; | |
| 8 | 8 | import org.springframework.stereotype.Service; |
| 9 | 9 | import org.springframework.validation.annotation.Validated; |
| 10 | 10 | |
| 11 | 11 | import javax.annotation.Resource; |
| 12 | - | |
| 13 | 12 | import java.time.LocalDateTime; |
| 14 | 13 | import java.util.Collection; |
| 15 | 14 | import java.util.List; |
| 16 | 15 | |
| 17 | -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 18 | -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; | |
| 19 | - | |
| 20 | 16 | /** |
| 21 | 17 | * 订单 API 接口实现类 |
| 22 | 18 | * |
| ... | ... | @@ -28,6 +24,8 @@ public class TradeOrderApiImpl implements TradeOrderApi { |
| 28 | 24 | |
| 29 | 25 | @Resource |
| 30 | 26 | private TradeOrderQueryService tradeOrderQueryService; |
| 27 | + @Resource | |
| 28 | + private TradeOrderUpdateService tradeOrderUpdateService; | |
| 31 | 29 | |
| 32 | 30 | @Override |
| 33 | 31 | public List<TradeOrderRespDTO> getOrderList(Collection<Long> ids) { |
| ... | ... | @@ -40,17 +38,13 @@ public class TradeOrderApiImpl implements TradeOrderApi { |
| 40 | 38 | } |
| 41 | 39 | |
| 42 | 40 | @Override |
| 43 | - public Integer getOrderStatus(Long id) { | |
| 44 | - TradeOrderDO order = tradeOrderQueryService.getOrder(id); | |
| 45 | - if (order == null) { | |
| 46 | - throw exception(ORDER_NOT_FOUND); | |
| 47 | - } | |
| 48 | - return order.getStatus(); | |
| 41 | + public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { | |
| 42 | + return tradeOrderQueryService.getOrderSummary(beginTime, endTime); | |
| 49 | 43 | } |
| 50 | 44 | |
| 51 | 45 | @Override |
| 52 | - public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { | |
| 53 | - return tradeOrderQueryService.getOrderSummary(beginTime, endTime); | |
| 46 | + public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { | |
| 47 | + tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); | |
| 54 | 48 | } |
| 55 | 49 | |
| 56 | 50 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/order/vo/AppTradeOrderSettlementReqVO.java
| ... | ... | @@ -52,7 +52,6 @@ public class AppTradeOrderSettlementReqVO { |
| 52 | 52 | private Long seckillActivityId; |
| 53 | 53 | |
| 54 | 54 | // ========== 拼团活动相关字段 ========== |
| 55 | - // TODO @puhui999:是不是拼团记录的编号哈? | |
| 56 | 55 | @Schema(description = "拼团活动编号", example = "1024") |
| 57 | 56 | private Long combinationActivityId; |
| 58 | 57 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateService.java
| ... | ... | @@ -170,4 +170,14 @@ public interface TradeOrderUpdateService { |
| 170 | 170 | */ |
| 171 | 171 | int createOrderItemCommentBySystem(); |
| 172 | 172 | |
| 173 | + /** | |
| 174 | + * 更新拼团相关信息到订单 | |
| 175 | + * | |
| 176 | + * @param orderId 订单编号 | |
| 177 | + * @param activityId 拼团活动编号 | |
| 178 | + * @param combinationRecordId 拼团记录编号 | |
| 179 | + * @param headId 团长编号 | |
| 180 | + */ | |
| 181 | + void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); | |
| 182 | + | |
| 173 | 183 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java
| ... | ... | @@ -250,7 +250,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 250 | 250 | /** |
| 251 | 251 | * 订单创建前,执行前置逻辑 |
| 252 | 252 | * |
| 253 | - * @param order 订单 | |
| 253 | + * @param order 订单 | |
| 254 | 254 | * @param orderItems 订单项 |
| 255 | 255 | */ |
| 256 | 256 | private void beforeCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { |
| ... | ... | @@ -267,9 +267,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 267 | 267 | * <p> |
| 268 | 268 | * 例如说:优惠劵的扣减、积分的扣减、支付单的创建等等 |
| 269 | 269 | * |
| 270 | - * @param order 订单 | |
| 271 | - * @param orderItems 订单项 | |
| 272 | - * @param createReqVO 创建订单请求 | |
| 270 | + * @param order 订单 | |
| 271 | + * @param orderItems 订单项 | |
| 272 | + * @param createReqVO 创建订单请求 | |
| 273 | 273 | */ |
| 274 | 274 | private void afterCreateTradeOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems, |
| 275 | 275 | AppTradeOrderCreateReqVO createReqVO) { |
| ... | ... | @@ -331,7 +331,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | // 3、订单支付成功后 |
| 334 | - tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order)); | |
| 334 | + List<TradeOrderItemDO> orderItems = tradeOrderItemMapper.selectListByOrderId(id); | |
| 335 | + tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order, orderItems)); | |
| 335 | 336 | |
| 336 | 337 | // 4.1 增加用户积分(赠送) |
| 337 | 338 | addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); |
| ... | ... | @@ -909,6 +910,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { |
| 909 | 910 | return count; |
| 910 | 911 | } |
| 911 | 912 | |
| 913 | + @Override | |
| 914 | + @Transactional(rollbackFor = Exception.class) | |
| 915 | + public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { | |
| 916 | + tradeOrderMapper.updateById( | |
| 917 | + new TradeOrderDO().setId(orderId).setCombinationActivityId(activityId) | |
| 918 | + .setCombinationRecordId(combinationRecordId).setCombinationHeadId(headId)); | |
| 919 | + } | |
| 920 | + | |
| 912 | 921 | /** |
| 913 | 922 | * 创建单个订单的评论 |
| 914 | 923 | * | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java
| ... | ... | @@ -39,29 +39,18 @@ public class TradeCombinationHandler implements TradeOrderHandler { |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | @Override |
| 42 | - public void afterOrderCreate(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | |
| 42 | + public void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | |
| 43 | 43 | // 如果不是拼团订单则结束 |
| 44 | 44 | if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { |
| 45 | 45 | return; |
| 46 | 46 | } |
| 47 | + | |
| 47 | 48 | Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); |
| 48 | 49 | |
| 49 | 50 | // 获取商品信息 |
| 50 | 51 | TradeOrderItemDO item = orderItems.get(0); |
| 51 | 52 | // 创建拼团记录 |
| 52 | - // TODO puhui:这里应该先不创建;等支付好,才去创建;另外,创建好后,需要更新编号到订单; | |
| 53 | 53 | combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - @Override | |
| 57 | - public void afterPayOrder(TradeOrderDO order) { | |
| 58 | - // 如果不是拼团订单则结束 | |
| 59 | - if (ObjectUtil.notEqual(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { | |
| 60 | - return; | |
| 61 | - } | |
| 62 | - | |
| 63 | - // 更新拼团状态 TODO puhui999:订单支付失败或订单支付过期删除这条拼团记录 | |
| 64 | - combinationRecordApi.updateRecordStatusToInProgress(order.getUserId(), order.getId(), order.getPayTime()); | |
| 65 | - } | |
| 66 | - | |
| 67 | 56 | } | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java
| ... | ... | @@ -33,8 +33,10 @@ public interface TradeOrderHandler { |
| 33 | 33 | * 支付订单后 |
| 34 | 34 | * |
| 35 | 35 | * @param order 订单 |
| 36 | + * @param orderItems 订单项 | |
| 36 | 37 | */ |
| 37 | - default void afterPayOrder(TradeOrderDO order) {} | |
| 38 | + default void afterPayOrder(TradeOrderDO order, List<TradeOrderItemDO> orderItems) { | |
| 39 | + } | |
| 38 | 40 | |
| 39 | 41 | /** |
| 40 | 42 | * 订单取消 | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/price/bo/TradePriceCalculateReqBO.java