zoujiajian 1 jaar geleden
bovenliggende
commit
42cb180b6b

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/GoodsDonSkuMapper.java

@@ -34,4 +34,6 @@ public interface GoodsDonSkuMapper  extends BaseMapper<GoodsDonSku> {
 	List<Long> selectGIdsBySkuIds(@Param("ids") List<Long> ids);
 
 	List<GoodsDonSkuDetailView> selectExchangeTitleSkus(@Param("ids") List<Long> skuIds);
+
+	List<Long> selectIdpGptAndRechargeSkuIds(@Param("gptPlusGid") Long gptPlusGid, @Param("gptRechargeGoodsId") Long gptRechargeGoodsId);
 }

+ 4 - 0
netflix-dao/src/main/resources/mapper/GoodsDonSkuMapper.xml

@@ -79,4 +79,8 @@
             #{item}
         </foreach>
     </select>
+
+    <select id="selectIdpGptAndRechargeSkuIds" resultType="java.lang.Long">
+        select id from goods_don_sku where ((goods_id = #{gptPlusGid} and num = 1) or goods_id = #{gptRechargeGoodsId}) and status is true
+    </select>
 </mapper>

+ 16 - 6
netflix-service/src/main/java/com/cyksj/service/mange/impl/CmsOrderDonServiceImpl.java

@@ -72,6 +72,7 @@ import com.cyksj.service.user.UserBenefitsService;
 import com.cyksj.service.user.UserBindRelationService;
 import com.cyksj.service.wechat.WeChatService;
 import com.ejlchina.searcher.BeanSearcher;
+import com.ejlchina.searcher.param.Operator;
 import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
@@ -1316,12 +1317,21 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
 
         //GPT独立会员退款 或代充退款 退还平台发券
         if ((orderDon.getGoodsId() == Constant.GPT_PLUS_GID && sku.getNum() == 1) || orderDon.getGoodsId() == Constant.GPT_RECHARGE_GOODS_ID) {
-            List<CouponUser> couponUsers = couponUserMapper.selectList(Wrappers.lambdaQuery(CouponUser.class)
-                    .eq(CouponUser::getUserId, orderDon.getUserId())
-                    .eq(CouponUser::getChannel, CouponUser.Channel.ptfq)
-                    .eq(CouponUser::getStatus, CouponUser.Status.unused));
-            if (CollUtil.isNotEmpty(couponUsers)) {
-                couponUserMapper.deleteBatchIds(couponUsers.stream().map(CouponUser::getId).collect(Collectors.toList()));
+            //若不存在对应的车票 则清除优惠券
+            List<Long> skuIds  =goodsDonSkuMapper.selectIdpGptAndRechargeSkuIds(Constant.GPT_PLUS_GID, Constant.GPT_RECHARGE_GOODS_ID);
+            List<Long> userIdList = userBindRelationService.getRelationUserIdList(orderDon.getUserId(), null);
+            Number number = beanSearcher.searchCount(GroupsRelationView.class, MapUtils.builder().field(GroupsRelationView::getUserId, userIdList).op(Operator.InList)
+                    .field(GroupsRelationView::getSkuId, skuIds).op(Operator.InList)
+                    .field(GroupsRelationView::getStatus, GroupsRelation.Status.validity.name())
+                    .build());
+            if (number.intValue() == 0) {
+                List<CouponUser> couponUsers = couponUserMapper.selectList(Wrappers.lambdaQuery(CouponUser.class)
+                        .eq(CouponUser::getUserId, orderDon.getUserId())
+                        .eq(CouponUser::getChannel, CouponUser.Channel.ptfq)
+                        .eq(CouponUser::getStatus, CouponUser.Status.unused));
+                if (CollUtil.isNotEmpty(couponUsers)) {
+                    couponUserMapper.deleteBatchIds(couponUsers.stream().map(CouponUser::getId).collect(Collectors.toList()));
+                }
             }
         }
     }