From efdb99f8cecc4afb592afad79c761081d5d5cf22 Mon Sep 17 00:00:00 2001 From: lee <4766465@qq.com> Date: Wed, 18 Dec 2024 13:27:00 +0800 Subject: [PATCH] init --- yami-shop-api/src/main/java/com/yami/shop/api/controller/PayLevelController.java | 124 +++++++++++++++++++++++++++++++++++++++++ 1 files changed, 124 insertions(+), 0 deletions(-) diff --git a/yami-shop-api/src/main/java/com/yami/shop/api/controller/PayLevelController.java b/yami-shop-api/src/main/java/com/yami/shop/api/controller/PayLevelController.java new file mode 100644 index 0000000..cc5f02b --- /dev/null +++ b/yami-shop-api/src/main/java/com/yami/shop/api/controller/PayLevelController.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved. + * + * https://www.mall4j.com/ + * + * 未经允许,不可做商业用途! + * + * 版权所有,侵权必究! + */ +package com.yami.shop.api.controller; + +import cn.hutool.core.lang.Snowflake; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.yami.shop.bean.app.param.PayUserParam; +import com.yami.shop.bean.enums.PayEntry; +import com.yami.shop.bean.model.UserExtension; +import com.yami.shop.bean.pay.PayInfoDto; +import com.yami.shop.common.exception.YamiShopBindException; +import com.yami.shop.common.response.ServerResponseEntity; +import com.yami.shop.manager.impl.PayManager; +import com.yami.shop.security.api.model.YamiUser; +import com.yami.shop.security.api.util.SecurityUtils; +import com.yami.shop.service.PayInfoService; +import com.yami.shop.service.UserExtensionService; +import com.yami.shop.user.common.model.UserLevel; +import com.yami.shop.user.common.model.UserLevelLog; +import com.yami.shop.user.common.service.UserLevelLogService; +import com.yami.shop.user.common.service.UserLevelService; +import io.swagger.v3.oas.annotations.tags.Tag; +import io.swagger.v3.oas.annotations.Operation; +import lombok.AllArgsConstructor; +import lombok.SneakyThrows; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.Date; +import java.util.Objects; + +/** + * @author LHD on 2020/03/02. + */ +@Tag(name = "会员购买接口") +@RestController +@RequestMapping("/p/level") +@AllArgsConstructor +public class PayLevelController { + + private final UserLevelService userLevelService; + private final UserExtensionService userExtensionService; + private final UserLevelLogService userLevelLogService; + private final PayManager payManager; + private final PayInfoService payInfoService; + private final Snowflake snowflake; + + /** + * 会员支付接口 + */ + @PostMapping("/payLevel") + @Operation(summary = "根据会员等级进行支付" , description = "根据会员等级进行支付") + @SneakyThrows + public ServerResponseEntity<?> payVip(HttpServletResponse httpResponse, @RequestBody PayUserParam payCardParam) { + YamiUser user = SecurityUtils.getUser(); + if (!user.getEnabled()) { + // 您已被禁用,不能购买,请联系平台客服 + throw new YamiShopBindException("yami.order.pay.user.disable"); + } + UserExtension userExtension = userExtensionService.getOne(new LambdaQueryWrapper<UserExtension>() + .eq(UserExtension::getUserId, user.getUserId())); + UserLevel userLevel = userLevelService.getById(payCardParam.getId()); + + //如果会员等级为空 + if(userLevel == null || !Objects.equals(userLevel.getLevelType(),1)) { + // 会员等级不存在或当前等级不为付费会员等级! + throw new YamiShopBindException("yami.user.level.no.exist"); + } + if(Objects.equals(userExtension.getLevelType(),1) && userExtension.getLevel() > userLevel.getLevel()){ + // 用户无法在会员期间购买低等级会员 + throw new YamiShopBindException("yami.user.pay.level.check"); + } + if(userExtension.getGrowth() < userLevel.getNeedGrowth()){ + // 用户成长值不足,无法购买 + throw new YamiShopBindException("yami.user.growh.no.enough"); + } + + String payNo = String.valueOf(snowflake.nextId()); + + Date now = new Date(); + //生成等级日志 + UserLevelLog userLevelLog = new UserLevelLog(); + userLevelLog.setGiftTime(now); + userLevelLog.setCreateTime(now); + userLevelLog.setLevel(userLevel.getLevel()); + userLevelLog.setState(0); + userLevelLog.setPayNo(payNo); + userLevelLog.setIsPayed(0); + userLevelLog.setPayAmount(userLevel.getNeedAmount()); + userLevelLog.setLevelName(userLevel.getLevelName()); + userLevelLog.setTerm(userLevel.getTerm()); + userLevelLog.setTermType(userLevel.getTermType()); + userLevelLog.setPayType(payCardParam.getPayType()); + userLevelLog.setUserId(userExtension.getUserId()); + //插入一条等级日志 + userLevelLogService.save(userLevelLog); + + payCardParam.setPayNo(payNo); + payCardParam.setOrderIds(userLevelLog.getLevelLogId()); + payCardParam.setNeedAmount(userLevel.getNeedAmount()); + + PayInfoDto payInfo = payInfoService.buyVip(user.getUserId(), payCardParam); + + payInfo.setBizUserId(user.getBizUserId()); + payInfo.setPayType(payCardParam.getPayType()); + payInfo.setApiNoticeUrl("/notice/pay/" + PayEntry.VIP.value() + "/" + payCardParam.getPayType()); + payInfo.setReturnUrl(payCardParam.getReturnUrl()); + return payManager.doPay(httpResponse, payInfo); + } + + @GetMapping("/isPay") + public ServerResponseEntity<Integer> isPay(){ + YamiUser user = SecurityUtils.getUser(); + UserLevelLog uLog = userLevelLogService.getMaxCrtTimeByUserId(user.getUserId()); + return ServerResponseEntity.success(uLog.getIsPayed()); + } +} -- Gitblit v1.9.3