|
|
@@ -9,6 +9,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.mapper.GoodsDonSkuMapper;
|
|
|
import com.cyksj.mapper.GroupsRelationMapper;
|
|
|
import com.cyksj.mapper.OrderDonMapper;
|
|
|
+import com.cyksj.mapper.UserBenefitsComboRelationRecordMapper;
|
|
|
import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
|
|
|
import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
@@ -57,6 +58,8 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
|
|
|
|
|
|
private final OrderDonMapper orderDonMapper;
|
|
|
|
|
|
+ private final UserBenefitsComboRelationRecordMapper userBenefitsComboRelationRecordMapper;
|
|
|
+
|
|
|
@Override
|
|
|
public Boolean getPayRealGoodsBenefits(Long userId, Long orderId, Long yhsId, List<GoodsDonSku> skuIds) {
|
|
|
Boolean isReceivedAll = true;
|
|
|
@@ -210,6 +213,49 @@ public class UserRealOrderBenefitsImpl implements UserRealOrderBenefitsService {
|
|
|
return ticketViews;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void sendUserBenefitsTicket(OrderDon orderDon, List<GoodsDonSku> goodsDonSkus) {
|
|
|
+ Long orderId = orderDon.getId();
|
|
|
+ Long userId = orderDon.getUserId();
|
|
|
+ Long yhsId = orderDon.getYhsId();
|
|
|
+ List<Long> relationIds = new ArrayList<>();
|
|
|
+ goodsDonSkus.forEach(sku -> {
|
|
|
+ Long skuId = sku.getId();
|
|
|
+ sku = goodsDonSkuMapper.selectById(skuId);
|
|
|
+ Long goodsId = sku.getGoodsId();
|
|
|
+ log.info("开始发放用户套餐优惠权益订单:{} 车票规格:{}", orderId, skuId);
|
|
|
+ List<GroupsRelationView> relationViewList = groupsRelationMapper.selectRelationByGoodsId(goodsId, userId, yhsId);
|
|
|
+ //是否有该规格车票,若无直接发放车票
|
|
|
+ if (CollUtil.isEmpty(relationViewList)) {
|
|
|
+ log.info("用户userId:{}未有skuId:{}车票,获取对应车票", userId, sku.getId());
|
|
|
+ //领取权益时,没有车票的用户自动上车,获得对应车票
|
|
|
+ GroupsRelation relation = exchangeCodeService.getGroupTripsTicket(yhsId, sku, userId, null, OrderDon.Type.PAY_EQUIPMENT, null);
|
|
|
+ relationIds.add(relation.getId());
|
|
|
+ } else {
|
|
|
+ //若有且只有一张增加时长
|
|
|
+ GroupsRelationView groupsRelationView = relationViewList.get(0);
|
|
|
+ log.info("存在对应规格:{}的车票,增加车票:relationId:{}时长", sku.getId(), groupsRelationView.getId());
|
|
|
+ Date expiryTime = groupsRelationView.getExpiryTime();
|
|
|
+ if (expiryTime == null) {
|
|
|
+ throw BusinessRuntimeException.getInstance("用户存在未发车的车票,请发车后再进行发货");
|
|
|
+ }
|
|
|
+ DateTime updateExpiryTime = DateUtil.offset(expiryTime, DateField.MONTH, sku.getMonths());
|
|
|
+ updateExpiryTime = DateUtil.offsetDay(updateExpiryTime, 3);
|
|
|
+ groupsRelationMapper.update(null, Wrappers.lambdaUpdate(GroupsRelation.class)
|
|
|
+ .eq(GroupsRelation::getId, groupsRelationView.getId())
|
|
|
+ .eq(GroupsRelation::getUserId, userId)
|
|
|
+ .set(GroupsRelation::getExpiryTime, updateExpiryTime));
|
|
|
+ groupsRelationView.setUpdateExpiryTime(updateExpiryTime);
|
|
|
+ relationIds.add(groupsRelationView.getId());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ UserBenefitsComboRelationRecord userBenefitsComboRelationRecord = new UserBenefitsComboRelationRecord();
|
|
|
+ userBenefitsComboRelationRecord.setOrderId(orderId);
|
|
|
+ userBenefitsComboRelationRecord.setRelationIds(relationIds.toString());
|
|
|
+ userBenefitsComboRelationRecord.setUserId(orderDon.getUserId());
|
|
|
+ userBenefitsComboRelationRecordMapper.insert(userBenefitsComboRelationRecord);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 保存获取权益记录
|
|
|
*/
|