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

fix 可用优惠卷展示

zoujiajian 3 жил өмнө
parent
commit
cf65195e88

+ 2 - 2
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -24,7 +24,7 @@
         left join `coupon` cp on cp.id = cu.coupon_id
         left join `coupon_sku` ck on ck.coupon_id = cp.id
         and ck.sku_id = #{skuId}
-        <if test="isRenew != null">
+        <if test="isRenew != null and isRenew">
             and cp.is_renew = #{isRenew}
         </if>
         and cu.status != 'used'
@@ -39,7 +39,7 @@
         left join `coupon_sku` ck on ck.coupon_id = cp.id
         where ck.sku_id = #{skuId} and cu.user_id = #{userId}
         and cu.status = 'unused'
-        <if test="isRenew != null">
+        <if test="isRenew != null and isRenew">
             and cp.is_renew = #{isRenew}
         </if>
     </select>

+ 2 - 0
netflix-service/src/main/java/com/cyksj/service/coupon/impl/CouponFontServiceImpl.java

@@ -170,6 +170,8 @@ public class CouponFontServiceImpl implements CouponFontService {
 				if (isRenew != null && isRenew) {
 					data.setReason(String.format("续费时,不可使用"));
 				}
+				//为了重新校验
+				data.setCouponUserStatus(CouponUser.Status.unused);
 				this.setCouponUserStatus(data, now);
 			});
 		});

+ 3 - 18
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -1082,26 +1082,11 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				log.info("用户已领取该{}优惠卷", couponUser.getCouponId());
 				throw BusinessRuntimeException.getInstance("该优惠卷已使用");
 			}
-		} else if (couponId != null) {
-			CouponUserView couponUserView = beanSearcher.searchFirst(CouponUserView.class, MapUtils.builder()
-					.field(CouponUserView::getCouponId, couponId).op(Operator.Equal)
-					.field(CouponUserView::getUserId, userId).op(Operator.Equal)
-					.build());
-			if (couponUserView == null) {
+		} else {
+			couponUser = couponUserMapper.selectOne(Wrappers.lambdaQuery(CouponUser.class).eq(CouponUser::getUserId, userId).eq(CouponUser::getCouponId, couponId).last("limit 1"));
+			if (couponUser == null) {
 				throw BusinessRuntimeException.getInstance("该优惠卷不存在");
 			}
-			if (couponUserView.getCouponUserStatus() == CouponUser.Status.used) {
-				throw BusinessRuntimeException.getInstance("该优惠卷已使用");
-			}
-			if (!couponUserView.getIsValidTime()) {
-				couponUserView.setValidStartTime(couponUserView.getCreatedTime());
-				couponUserView.setValidEndTime(DateUtil.offsetDay(couponUserView.getValidStartTime(), couponUserView.getValidDays()));
-			}
-			couponFontService.setCouponUserStatus(couponUserView, DateTime.now());
-			if (couponUserView.getCouponUserStatus() != CouponUser.Status.unused) {
-				throw BusinessRuntimeException.getInstance("该优惠卷不可使用");
-			}
-			couponUser = couponUserMapper.selectById(couponUserView.getId());
 			couponUser.setStatus(CouponUser.Status.used);
 			couponUserMapper.updateById(couponUser);
 		}