trade:砍价记录的详情 100%

This commit is contained in:
YunaiV 2023-10-06 10:17:41 +08:00
parent 5f57cc6247
commit 8e7b295d24
8 changed files with 40 additions and 29 deletions

View File

@ -92,40 +92,28 @@ public class AppBargainRecordController {
// 1. 查询砍价记录 + 砍价活动
Assert.isTrue(id != null || activityId != null, "砍价记录编号和活动编号不能同时为空");
BargainRecordDO record = id != null ? bargainRecordService.getBargainRecord(id)
: bargainRecordService.getInProgressBargainRecord(getLoginUserId(), activityId);
: bargainRecordService.getLastBargainRecord(getLoginUserId(), activityId);
if (activityId == null || record != null) {
activityId = record.getActivityId();
}
// 2. 查询助力记录
Integer helpAction = getHelpAction(record, activityId);
Long userId = getLoginUserId();
Integer helpAction = getHelpAction(userId, record, activityId);
// 3. 如果是自己的订单则查询订单信息
TradeOrderRespDTO order = record != null && record.getOrderId() != null && record.getUserId().equals(getLoginUserId())
? tradeOrderApi.getOrder(record.getOrderId()) : null;
// TODO 继续查询别的字段
// 拼接返回
return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction));
//
// AppBargainRecordDetailRespVO detail = new AppBargainRecordDetailRespVO();
// detail.setId(1L);
// detail.setUserId(1L);
// detail.setSpuId(1L);
// detail.setSkuId(1L);
// detail.setPrice(500);
// detail.setActivityId(1L);
// detail.setBargainPrice(150);
// detail.setPrice(200);
// detail.setPayPrice(180);
// detail.setStatus(1);
// detail.setExpireTime(LocalDateTimeUtils.addTime(Duration.ofDays(2)));
// return success(detail);
return success(BargainRecordConvert.INSTANCE.convert02(record, helpAction, order));
}
private Integer getHelpAction(BargainRecordDO record, Long activityId) {
private Integer getHelpAction(Long userId, BargainRecordDO record, Long activityId) {
// 0.1 如果没有活动无法帮砍
if (activityId == null) {
return null;
}
// 0.2 如果是自己的砍价记录无法帮砍
Long userId = getLoginUserId();
if (record != null && record.getUserId().equals(userId)) {
return null;
}
@ -141,7 +129,7 @@ public class AppBargainRecordController {
&& bargainHelpService.getBargainHelpCountByActivity(activityId, userId) >= activity.getBargainCount()) {
return AppBargainRecordDetailRespVO.HELP_ACTION_FULL;
}
// 3. 允许助力
return AppBargainRecordDetailRespVO.HELP_ACTION_NONE;
}

View File

@ -13,6 +13,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD
import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainRecordDO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
import java.util.List;
@ -83,6 +84,9 @@ public interface BargainRecordConvert {
return summary;
}
AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction);
@Mapping(source = "record.id", target = "id")
@Mapping(source = "record.userId", target = "userId")
@Mapping(source = "record.status", target = "status")
AppBargainRecordDetailRespVO convert02(BargainRecordDO record, Integer helpAction, TradeOrderRespDTO order);
}

View File

@ -42,6 +42,14 @@ public interface BargainRecordMapper extends BaseMapperX<BargainRecordDO> {
.eq(BargainRecordDO::getStatus, status));
}
default BargainRecordDO selectLastByUserIdAndActivityId(Long userId, Long activityId) {
return selectOne(new LambdaQueryWrapper<>(BargainRecordDO.class)
.eq(BargainRecordDO::getUserId, userId)
.eq(BargainRecordDO::getActivityId, activityId)
.orderByDesc(BargainRecordDO::getId)
.last("LIMIT 1"));
}
default Long selectCountByUserIdAndActivityIdAndStatus(
Long userId, Long activityId, Integer status) {
return selectCount(new LambdaQueryWrapper<>(BargainRecordDO.class)

View File

@ -74,15 +74,13 @@ public interface BargainRecordService {
BargainRecordDO getBargainRecord(Long id);
/**
* 获得用户当前正在砍价中+ 指定活动的砍价记录
*
* 因为一个用户在一个砍价活动砍价中只存在一条
* 获得用户在当前砍价活动中的最后一条砍价记录
*
* @param userId 用户编号
* @param activityId 砍价记录编号
* @return 砍价记录
*/
BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId);
BargainRecordDO getLastBargainRecord(Long userId, Long activityId);
/**
* 获得砍价人数 Map

View File

@ -115,10 +115,8 @@ public class BargainRecordServiceImpl implements BargainRecordService {
}
@Override
public BargainRecordDO getInProgressBargainRecord(Long userId, Long activityId) {
List<BargainRecordDO> list = bargainRecordMapper.selectListByUserIdAndActivityIdAndStatus(
userId, activityId, BargainRecordStatusEnum.IN_PROGRESS.getStatus());
return CollUtil.getFirst(list);
public BargainRecordDO getLastBargainRecord(Long userId, Long activityId) {
return bargainRecordMapper.selectLastByUserIdAndActivityId(userId, activityId);
}
@Override

View File

@ -22,6 +22,14 @@ public interface TradeOrderApi {
*/
List<TradeOrderRespDTO> getOrderList(Collection<Long> ids);
/**
* 获得订单
*
* @param id 订单编号
* @return 订单
*/
TradeOrderRespDTO getOrder(Long id);
// TODO 芋艿看看是不是可以删除掉
/**
* 获取订单状态

View File

@ -34,6 +34,11 @@ public class TradeOrderApiImpl implements TradeOrderApi {
return TradeOrderConvert.INSTANCE.convertList04(tradeOrderQueryService.getOrderList(ids));
}
@Override
public TradeOrderRespDTO getOrder(Long id) {
return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id));
}
@Override
public Integer getOrderStatus(Long id) {
TradeOrderDO order = tradeOrderQueryService.getOrder(id);

View File

@ -38,6 +38,7 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.ArrayList;
@ -261,6 +262,7 @@ public interface TradeOrderConvert {
return bo;
}
@Named("convertList04")
List<TradeOrderRespDTO> convertList04(List<TradeOrderDO> list);
}