zoujiajian há 1 ano atrás
pai
commit
5013ab4efc

+ 52 - 2
netflix-web/src/main/java/com/cyksj/web/controller/claude/ClaudeCodeController.java

@@ -328,7 +328,7 @@ public class ClaudeCodeController {
 	 */
 	@GetMapping("/authorize")
 	public Result<String> authorize(@RequestParam(name = "client_id") String clientId,
-									@RequestParam String state) throws Exception {
+	                                @RequestParam String state) throws Exception {
 		// 验证参数
 		if (clientId == null || clientId.isEmpty() ||
 				state == null || state.isEmpty()) {
@@ -365,7 +365,7 @@ public class ClaudeCodeController {
 			}
 
 			// 验证token
-			OAuthToken oauthToken = oAuthClaudeCodeService.validateToken(code,token);
+			OAuthToken oauthToken = oAuthClaudeCodeService.validateToken(code, token);
 			if (oauthToken == null) {
 				throw BusinessRuntimeException.getInstance("Invalid or expired token");
 			}
@@ -444,4 +444,54 @@ public class ClaudeCodeController {
 		}
 	}
 
+	public void setClaudeCodeSkuCouponInfo(String dsCode, Long userId, List<GoodsDonSkuView> goodsDonSkuViews) {
+		//渠道推广
+		if (dsCode != null) {
+			UserSharedDto popularizeDto = userService.getUserShredDtoByDsCode(dsCode);
+			if (popularizeDto != null) {
+				UserDistribute userDistribute = userDistributeMapper.selectOne(Wrappers.lambdaQuery(UserDistribute.class).eq(UserDistribute::getUserId, popularizeDto.getSharedId()).eq(UserDistribute::getDeleted, Boolean.TRUE).last("limit 1"));
+				//渠道推广
+				if (userDistribute != null) {
+					Integer selectCount = couponDistributePopularizeMapper.selectCount(Wrappers.lambdaQuery(CouponDistributePopularize.class)
+							.eq(CouponDistributePopularize::getDistributeId, userDistribute.getId())
+							.eq(CouponDistributePopularize::getCouponId, Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID)
+							.eq(CouponDistributePopularize::getDeleted, Boolean.TRUE));
+					//已配置使用渠道优惠码 未配置使用推荐优惠券
+					Coupon coupon = couponMapper.selectById(selectCount > 0 ? Constant.DISTRIBUTE_CLAUDE_CODE_COUPON_ID : Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID);
+					if (coupon == null) {
+						return;
+					}
+					if (coupon.getId() == Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID) {
+						int isTj = couponRecommendMapper.checkPresentRecommendByCouponId(Constant.DISTRIBUTE_CLAUDE_CODE_NO_CODE_COUPON_ID);
+						if (isTj == 0) {
+							return;
+						}
+					}
+					List<Long> couponSkuIds = couponSkuMapper.selectList(Wrappers.lambdaQuery(CouponSku.class).eq(CouponSku::getCouponId, coupon.getId()).eq(CouponSku::getDeleted, Boolean.TRUE)).stream().map(CouponSku::getSkuId).collect(Collectors.toList());
+					//该优惠券是否已经使用
+					if (userId != null) {
+						Integer isUsed = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
+								.eq(CouponUser::getCouponId, coupon.getId())
+								.eq(CouponUser::getStatus, CouponUser.Status.unused)
+								.eq(CouponUser::getUserId, userId)
+								.lt(CouponUser::getValidStartTime, DateTime.now())
+								.gt(CouponUser::getValidEndTime, DateTime.now()));
+						if (isUsed == 0) {
+							return;
+						}
+					}
+					goodsDonSkuViews.forEach(sku -> {
+						if (couponSkuIds.contains(sku.getSkuId())) {
+							if (coupon.getType() == Coupon.Type.discount) {
+								sku.setDiscount(coupon.getDiscount());
+								sku.setDiscountPrice(sku.getMoney().multiply(coupon.getDiscount()));
+							} else {
+								sku.setReduceMoney(coupon.getReduceMoney());
+							}
+						}
+					});
+				}
+			}
+		}
+	}
 }