Эх сурвалжийг харах

平台发券GPT独立会员或代充退款 退还优惠券

zoujiajian 1 жил өмнө
parent
commit
5340d7eb17

+ 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);
 }

+ 7 - 0
netflix-dao/src/main/java/com/cyksj/model/views/UserActivityView.java

@@ -56,6 +56,13 @@ public class UserActivityView {
 	@DbField("ua.rules")
 	private String rules;
 
+	/**
+	 * 是否领取过活动
+	 * true已领取
+	 */
+	@DbIgnore
+	private Boolean isReceived;
+
 	@DbIgnore
 	private List<CouponView> couponViews;
 }

+ 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>

+ 7 - 0
netflix-service/src/main/java/com/cyksj/service/mange/coupon/impl/CouponCommonServiceImpl.java

@@ -66,6 +66,13 @@ public class CouponCommonServiceImpl implements CouponCommonService {
 		if (coupon.getId() == null || coupon.getId() < 1) {
 			throw BusinessRuntimeException.getInstance("请输入正确的优惠券id");
 		}
+		if (coupon.getType() == Coupon.Type.reduce) {
+			coupon.setDiscount(BigDecimal.ZERO);
+		}
+		if (coupon.getType() == Coupon.Type.discount) {
+			coupon.setReduceCondition(BigDecimal.ZERO);
+			coupon.setReduceMoney(BigDecimal.ZERO);
+		}
 		Coupon entity = couponMapper.selectById(coupon.getId());
 		if (entity == null || !entity.getDeleted()) {
 			throw BusinessRuntimeException.getInstance("该优惠券不存在");

+ 24 - 2
netflix-service/src/main/java/com/cyksj/service/mange/impl/CmsOrderDonServiceImpl.java

@@ -29,6 +29,7 @@ import com.cyksj.mapper.channel.ShopConfigMapper;
 import com.cyksj.mapper.channel.UserPayEquipmentAvailableBenefitsMapper;
 import com.cyksj.mapper.channel.UserPayEquipmentReceiveBenefitsRecordMapper;
 import com.cyksj.mapper.manage.cms.CmsUserMapper;
+import com.cyksj.mapper.manage.coupon.CouponUserMapper;
 import com.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeBusinessOrderDonRecordMapper;
 import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
@@ -71,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;
@@ -224,7 +226,7 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
 
     private final NetflixUserChangeOtherTicketRecordMapper netflixUserChangeOtherTicketRecordMapper;
 
-    private final OrderDonGalaxyCoinRecordMapper orderDonGalaxyCoinRecordMapper;
+    private final CouponUserMapper couponUserMapper;
 
     private final UserGalaxyCoinService userGalaxyCoinService;
 
@@ -371,7 +373,6 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
     }
 
     @Override
-    @Transactional(rollbackFor = Throwable.class)
     public void unifiedRefund(OrderRefundReq refundReq) throws Exception {
         OrderDon orderDon = orderDonMapper.selectById(refundReq.getOrderId());
         GoodsDonSku sku = null;
@@ -1312,6 +1313,27 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
         if (orderDon.getGoodsId() == Constant.GPT_PLUS_GID && sku.getNum() == 1) {
             subRechargeNumOrder(orderDon.getUserId(), orderDon.getRelationId(), sku.getMonths(), operator);
         }
+
+        //GPT独立会员退款 或代充退款 退还平台发券
+        if ((orderDon.getGoodsId() == Constant.GPT_PLUS_GID && sku.getNum() == 1) || orderDon.getGoodsId() == Constant.GPT_RECHARGE_GOODS_ID) {
+            //若不存在对应的车票 则清除优惠券
+            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()));
+                }
+            }
+        }
     }
 
     //处理下级渠道分销提成

+ 7 - 1
netflix-web/src/main/java/com/cyksj/web/controller/coupon/CouponFrontController.java

@@ -534,15 +534,21 @@ public class CouponFrontController {
 	 */
 	@GetMapping("/get/goods/activity")
 	public Result<UserActivityView> getGoodsActivity() throws Exception {
+		Long userId = StpUserUtil.getUserIdAfterLogin();
 		String dateStr = DateTime.now().toString();
 		String time = String.format(" and (ua.start_time is null or (ua.start_time < '%s' and ua.end_time > '%s'))", dateStr, dateStr);
 		UserActivityView userActivityView = beanSearcher.searchFirst(UserActivityView.class, MapUtils.flatBuilder(request.getParameterMap())
 				.field(UserActivityView::getType, 3)
 				.put("time", time)
 				.build());
-		if (StrUtil.isNotBlank(userActivityView.getCouponIds())) {
+		if (userActivityView != null && StrUtil.isNotBlank(userActivityView.getCouponIds())) {
 			List<Long> couponIds = Jsons.parseList(userActivityView.getCouponIds(), Long.class);
 			userActivityView.setCouponViews(beanSearcher.searchAll(CouponView.class, MapUtils.builder().field(CouponView::getId, couponIds).op(Operator.InList).build()));
+			//是否领取过
+			if (userId != null) {
+				Integer selectCount = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class).in(CouponUser::getCouponId, couponIds).eq(CouponUser::getUserId, userId));
+				userActivityView.setIsReceived(selectCount == couponIds.size());
+			}
 		}
 		return GatewayResponse.SUCCESS.newBuilder().toResult(userActivityView);
 	}