|
|
@@ -21,6 +21,7 @@ import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -55,7 +56,7 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
@Override
|
|
|
- public void receivePayRealGoodsBenefits(Long userId, Long orderId, Long goodsId, List<Long> skuIds) {
|
|
|
+ public void getPayRealGoodsBenefits(Long userId, Long orderId, Long goodsId, List<Long> skuIds) {
|
|
|
skuIds.forEach(skuId->{
|
|
|
GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(skuId);
|
|
|
if (goodsDonSku != null) {
|
|
|
@@ -111,6 +112,57 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
|
|
|
.eq(UserPayEquipmentAvailableBenefits::getRealOrderId, orderId));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Throwable.class)
|
|
|
+ public GroupsRelationView receiveRealGoodsBenefits(Long userId, Long benefitsId, Long goodsId, Long skuId, Long relationId) {
|
|
|
+ //可获取的权益是否存在
|
|
|
+ UserPayEquipmentAvailableBenefits availableBenefits = availableBenefitsMapper.selectById(benefitsId);
|
|
|
+ if (availableBenefits == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("可获取的权益不存在");
|
|
|
+ }
|
|
|
+ if (!availableBenefits.getDeleted()) {
|
|
|
+ throw BusinessRuntimeException.getInstance("购买的实物设备已退款,无法领取该权益");
|
|
|
+ }
|
|
|
+ if (!availableBenefits.getSkuId().equals(skuId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("可领取的车票权益规格错误");
|
|
|
+ }
|
|
|
+ GroupsRelationView groupsRelationView = beanSearcher.searchFirst(GroupsRelationView.class, MapUtils.builder()
|
|
|
+ .field(GroupsRelationView::getGoodsId, goodsId)
|
|
|
+ .field(GroupsRelationView::getId, relationId)
|
|
|
+ .field(GroupsRelationView::getStatus, GroupsRelation.Status.validity.name())
|
|
|
+ .field(GroupsRelationView::getUserId, userId)
|
|
|
+ .build());
|
|
|
+ Optional.ofNullable(groupRelationClearService).ifPresentOrElse(ticket -> {
|
|
|
+ Date expiryTime = groupsRelationView.getExpiryTime();
|
|
|
+ if (expiryTime == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("该车位暂未发车,请发车后再领取权益");
|
|
|
+ }
|
|
|
+ GoodsDonSku goodsDonSku = goodsDonSkuMapper.selectById(skuId);
|
|
|
+ if (goodsDonSku == null || !goodsDonSku.getGoodsId().equals(goodsId)) {
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
+ }
|
|
|
+ //删除可领取的权益
|
|
|
+ int update = availableBenefitsMapper.update(null, Wrappers.lambdaUpdate(UserPayEquipmentAvailableBenefits.class)
|
|
|
+ .set(UserPayEquipmentAvailableBenefits::getDeleted, false)
|
|
|
+ .eq(UserPayEquipmentAvailableBenefits::getDeleted, true)
|
|
|
+ .eq(UserPayEquipmentAvailableBenefits::getId, benefitsId));
|
|
|
+ if (update != 1) {
|
|
|
+ throw BusinessRuntimeException.getInstance("系统错误,请刷新页面重试");
|
|
|
+ }
|
|
|
+ DateTime updateExpiryTime = DateUtil.offset(expiryTime, DateField.MONTH, goodsDonSku.getMonths());
|
|
|
+ groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getId, groupsRelationView.getId())
|
|
|
+ .eq(GroupsRelation::getUserId, userId)
|
|
|
+ .set(GroupsRelation::getExpiryTime, updateExpiryTime));
|
|
|
+ groupsRelationView.setUpdateExpiryTime(updateExpiryTime);
|
|
|
+ //保存领取权益
|
|
|
+ saveReceiveBenefitsRecord(userId, skuId, availableBenefits.getRealOrderId(), null, relationId, goodsDonSku.getMonths(), 1);
|
|
|
+ }, () -> {
|
|
|
+ throw BusinessRuntimeException.getInstance("对应规格车票不存在");
|
|
|
+ });
|
|
|
+ return groupsRelationView;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存获取权益记录
|
|
|
*/
|