拼团活动:完善 review 提到的问题

This commit is contained in:
puhui999 2023-10-08 17:46:48 +08:00
parent 2e559ebe06
commit 2c0f1121ca
4 changed files with 16 additions and 28 deletions

View File

@ -29,8 +29,9 @@ public interface CombinationRecordApi {
* 创建开团记录
*
* @param reqDTO 请求 DTO
* @return 开团记录编号
*/
void createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
Long createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO);
/**
* 查询拼团记录是否成功

View File

@ -29,8 +29,8 @@ public class CombinationRecordApiImpl implements CombinationRecordApi {
}
@Override
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
recordService.createCombinationRecord(reqDTO);
public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
return recordService.createCombinationRecord(reqDTO);
}
@Override

View File

@ -49,8 +49,9 @@ public interface CombinationRecordService {
* 创建拼团记录
*
* @param reqDTO 创建信息
* @return 开团记录编号
*/
void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO);
/**
* 获得拼团记录
@ -87,7 +88,7 @@ public interface CombinationRecordService {
/**
* 获取拼团记录数
*
* @param status 状态-允许为空
* @param status 状态-允许为空
* @param virtualGroup 是否虚拟成团-允许为空
* @return 记录数
*/

View File

@ -31,7 +31,8 @@ import javax.annotation.Resource;
import java.util.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow;
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
@ -163,7 +164,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
@Override
@Transactional(rollbackFor = Exception.class)
public void createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) {
// 1. 校验拼团活动
KeyValue<CombinationActivityDO, CombinationProductDO> keyValue = validateCombinationRecord(reqDTO.getUserId(),
reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount());
@ -173,34 +174,19 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
// TODO @puhui head 的情况下 head 结束为准
// 3. 如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
record.setHeadId(record.getHeadId() == null ? CombinationRecordDO.HEAD_ID_GROUP : record.getHeadId());
recordMapper.insert(record);
// 3. 如果是团长需要设置 headId CombinationRecordDO#HEAD_ID_GROUP
// TODO @puhui999是不是只要是团长record 设置了就好啦不用 update
if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, reqDTO.getHeadId())) {
recordMapper.updateById(new CombinationRecordDO().setId(record.getId()).setHeadId(CombinationRecordDO.HEAD_ID_GROUP));
return;
if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) {
return record.getId();
}
// TODO 这里要不要弄成异步的不用异步哈就是事务好了
// 4更新拼团相关信息到订单
updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId());
// 4更新拼团记录
updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey());
}
// TODO @puhui999这个更新放到 trade 那就好了createCombinationRecord 返回一个 recordId
/**
* 更新拼团相关信息到订单
*
* @param orderId 订单编号
* @param activityId 拼团活动编号
* @param combinationRecordId 拼团记录编号
* @param headId 团长编号
*/
private void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) {
tradeOrderApi.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId);
return record.getId();
}
/**