|
@@ -13,7 +13,9 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
@@ -255,4 +257,44 @@ public class CouponService {
|
|
|
return couponMapper.selectList(
|
|
return couponMapper.selectList(
|
|
|
new LambdaQueryWrapper<Coupon>().eq(Coupon::getGrantType, "JOIN"));
|
|
new LambdaQueryWrapper<Coupon>().eq(Coupon::getGrantType, "JOIN"));
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ /** 我的优惠券:返回 user_coupon + coupon 联合数据,含 status/receivedAt/usedAt */
|
|
|
|
|
+ public List<Map<String, Object>> listMyCoupons(Long userId) {
|
|
|
|
|
+ List<UserCoupon> userCoupons = userCouponMapper.selectList(
|
|
|
|
|
+ new LambdaQueryWrapper<UserCoupon>()
|
|
|
|
|
+ .eq(UserCoupon::getUserId, userId)
|
|
|
|
|
+ .orderByDesc(UserCoupon::getReceivedAt));
|
|
|
|
|
+ if (userCoupons.isEmpty()) {
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ Date now = new Date();
|
|
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
|
|
+ for (UserCoupon uc : userCoupons) {
|
|
|
|
|
+ Coupon coupon = couponMapper.selectById(uc.getCouponId());
|
|
|
|
|
+ if (coupon == null) continue;
|
|
|
|
|
+ // 过期判断
|
|
|
|
|
+ String status = uc.getStatus();
|
|
|
|
|
+ if ("AVAILABLE".equals(status) && coupon.getValidUntil() != null && now.after(coupon.getValidUntil())) {
|
|
|
|
|
+ status = "EXPIRED";
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<String, Object> item = new HashMap<>();
|
|
|
|
|
+ item.put("userCouponId", uc.getId());
|
|
|
|
|
+ item.put("id", uc.getId());
|
|
|
|
|
+ item.put("couponId", coupon.getId());
|
|
|
|
|
+ item.put("name", coupon.getName());
|
|
|
|
|
+ item.put("type", coupon.getType());
|
|
|
|
|
+ item.put("value", coupon.getValue());
|
|
|
|
|
+ item.put("discountRate", coupon.getDiscountRate());
|
|
|
|
|
+ item.put("minSpend", coupon.getMinSpend());
|
|
|
|
|
+ item.put("applicableTo", coupon.getApplicableTo());
|
|
|
|
|
+ item.put("validFrom", coupon.getValidFrom());
|
|
|
|
|
+ item.put("validUntil", coupon.getValidUntil());
|
|
|
|
|
+ item.put("status", status);
|
|
|
|
|
+ item.put("receivedAt", uc.getReceivedAt());
|
|
|
|
|
+ item.put("usedAt", uc.getUsedAt());
|
|
|
|
|
+ item.put("orderId", uc.getOrderId());
|
|
|
|
|
+ result.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|