Compare commits
13 Commits
734cb109fb
...
715174403b
Author | SHA1 | Date |
---|---|---|
|
715174403b | |
|
3b4ff9f774 | |
|
11b42f5fe2 | |
|
6f45a85b95 | |
|
79bfa1a981 | |
|
9014190840 | |
|
7ce0a4fbcb | |
|
dcce7b4b29 | |
|
58a0b376bc | |
|
3559242524 | |
|
904235425f | |
|
efa88e9d7a | |
|
effbb7f046 |
|
@ -16,7 +16,11 @@
|
|||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alipay.sdk</groupId>
|
||||
<artifactId>alipay-easysdk</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
<!-- spring-boot-devtools -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -73,6 +77,12 @@
|
|||
<artifactId>mcwl-common</artifactId>
|
||||
<version>3.8.8</version>
|
||||
</dependency>
|
||||
<!-- 支付模块-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl-pay</artifactId>
|
||||
<version>3.8.8</version>
|
||||
</dependency>
|
||||
<!-- 资源中心模块-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
|
|
|
@ -0,0 +1,137 @@
|
|||
package com.mcwl.web.controller.memberCenter;
|
||||
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.memberCenter.domain.MemberConsume;
|
||||
import com.mcwl.memberCenter.domain.Member;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
import com.mcwl.memberCenter.service.MemberBenefitService;
|
||||
import com.mcwl.memberCenter.service.MemberLevelService;
|
||||
import com.mcwl.web.controller.memberCenter.pojo.dto.RechargePointsDto;
|
||||
import com.mcwl.web.controller.memberCenter.pojo.dto.UserMemberDto;
|
||||
import com.mcwl.memberCenter.service.MemberConsumeService;
|
||||
import com.mcwl.memberCenter.service.MemberService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import com.mcwl.web.controller.memberCenter.pojo.vo.PointsVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("member")
|
||||
@RequiredArgsConstructor
|
||||
public class MemberController {
|
||||
|
||||
private final MemberService memberService;
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
private final MemberConsumeService memberConsumeService;
|
||||
|
||||
private final MemberBenefitService memberBenefitService;
|
||||
|
||||
|
||||
/**
|
||||
* 创建用户会员
|
||||
*
|
||||
* @param userMemberDto 参数
|
||||
* @return 用户会员
|
||||
*/
|
||||
@PostMapping("createMember")
|
||||
public AjaxResult createMemberCenter(@RequestBody UserMemberDto userMemberDto) {
|
||||
Long userId = userMemberDto.getUserId();
|
||||
if (userId == null) {
|
||||
return AjaxResult.warn("用户未登录");
|
||||
}
|
||||
Long memberLevelId = userMemberDto.getMemberLevelId();
|
||||
if (memberLevelId == null) {
|
||||
return AjaxResult.warn("会员等级未选择");
|
||||
}
|
||||
String paymentMethod = userMemberDto.getPaymentMethod();
|
||||
if (paymentMethod == null) {
|
||||
return AjaxResult.warn("支付方式错误,请重新支付");
|
||||
}
|
||||
Member member = memberService.createUserMember(userId, memberLevelId, paymentMethod);
|
||||
if (member == null) {
|
||||
return AjaxResult.warn("创建会员失败");
|
||||
}
|
||||
return AjaxResult.success(member);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取积分余额和历史记录
|
||||
* @param userId 用户id
|
||||
* @return 积分余额和历史记录
|
||||
*/
|
||||
@GetMapping("getPoints/{id}")
|
||||
public AjaxResult getPoints(@PathVariable("id") Long userId) {
|
||||
if (userId == null) {
|
||||
return AjaxResult.warn("用户未登录");
|
||||
}
|
||||
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
if (sysUser == null) {
|
||||
return AjaxResult.warn("用户不存在");
|
||||
}
|
||||
|
||||
Member member = memberService.getUseUserMemberByUserId(userId);
|
||||
if (member == null) {
|
||||
return AjaxResult.warn("用户未开通会员");
|
||||
}
|
||||
|
||||
PointsVO pointsVO = new PointsVO();
|
||||
|
||||
// 会员消费记录
|
||||
List<MemberConsume> memberConsumeList = memberConsumeService
|
||||
.lambdaQuery()
|
||||
.eq(MemberConsume::getUserId, userId)
|
||||
.list();
|
||||
|
||||
pointsVO.setPoints(member.getPoints());
|
||||
pointsVO.setMemberConsumeList(memberConsumeList);
|
||||
|
||||
return AjaxResult.success(pointsVO);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 会员积分充值
|
||||
*/
|
||||
@PostMapping("rechargePoints")
|
||||
public AjaxResult rechargePoints(@RequestBody RechargePointsDto rechargePointsDto) {
|
||||
Long userId = rechargePointsDto.getUserId();
|
||||
Double points = rechargePointsDto.getPoints();
|
||||
|
||||
if (userId == null) {
|
||||
return AjaxResult.warn("用户未登录");
|
||||
}
|
||||
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
if (sysUser == null) {
|
||||
return AjaxResult.warn("用户不存在");
|
||||
}
|
||||
|
||||
if (points == null) {
|
||||
return AjaxResult.warn("充值积分为空");
|
||||
}
|
||||
|
||||
if (points <= 0) {
|
||||
return AjaxResult.warn("充值积分必须大于0");
|
||||
}
|
||||
|
||||
Member member = memberService.rechargePoints(userId, points);
|
||||
|
||||
// 返回充值积分
|
||||
if (member == null) {
|
||||
return AjaxResult.warn("充值积分失败");
|
||||
}
|
||||
|
||||
rechargePointsDto.setPoints(member.getPoints());
|
||||
|
||||
return AjaxResult.success(rechargePointsDto);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
package com.mcwl.web.controller.memberCenter;
|
||||
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.memberCenter.domain.MemberBenefit;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
import com.mcwl.memberCenter.service.MemberBenefitService;
|
||||
import com.mcwl.memberCenter.service.MemberLevelService;
|
||||
import com.mcwl.web.controller.memberCenter.pojo.vo.MemberBenefitVO;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("memberLevel")
|
||||
@RequiredArgsConstructor
|
||||
public class MemberLevelController {
|
||||
|
||||
private final MemberLevelService memberLevelService;
|
||||
|
||||
private final MemberBenefitService memberBenefitService;
|
||||
|
||||
/**
|
||||
* 获取会员等级列表
|
||||
*
|
||||
* @return 会员等级列表
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public AjaxResult list() {
|
||||
|
||||
List<MemberLevel> memberLevelList = memberLevelService.list();
|
||||
|
||||
return AjaxResult.success(memberLevelList);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取会员等级及权益列表
|
||||
*/
|
||||
@GetMapping("getMemberBenefitList")
|
||||
public AjaxResult getMemberBenefitList() {
|
||||
|
||||
List<MemberBenefitVO> memberBenefitVOList = new ArrayList<>();
|
||||
|
||||
List<MemberLevel> memberLevelList = memberLevelService.list();
|
||||
for (MemberLevel memberLevel : memberLevelList) {
|
||||
MemberBenefitVO memberBenefitVO = new MemberBenefitVO();
|
||||
memberBenefitVO.setMemberLevel(memberLevel);
|
||||
// 获取会员等级对应的权益
|
||||
List<MemberBenefit> memberBenefitList = memberBenefitService.lambdaQuery()
|
||||
.eq(MemberBenefit::getMemberLevelId, memberLevel.getId())
|
||||
.list();
|
||||
memberBenefitVO.setMemberBenefitList(memberBenefitList);
|
||||
memberBenefitVOList.add(memberBenefitVO);
|
||||
}
|
||||
|
||||
return AjaxResult.success(memberBenefitVOList);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mcwl.web.controller.memberCenter.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RechargePointsDto {
|
||||
|
||||
// 用户ID
|
||||
private Long userId;
|
||||
|
||||
// 充值积分
|
||||
private Double points;
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package com.mcwl.web.controller.memberCenter.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserMemberDto {
|
||||
|
||||
// 用户ID
|
||||
private Long userId;
|
||||
|
||||
// 会员ID
|
||||
private Long memberLevelId;
|
||||
|
||||
// 支付方式
|
||||
private String paymentMethod;
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.mcwl.web.controller.memberCenter.pojo.vo;
|
||||
|
||||
import com.mcwl.memberCenter.domain.MemberBenefit;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MemberBenefitVO {
|
||||
|
||||
// 会员等级
|
||||
private MemberLevel memberLevel;
|
||||
|
||||
// 会员权益
|
||||
private List<MemberBenefit> memberBenefitList = new ArrayList<>();
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.mcwl.web.controller.memberCenter.pojo.vo;
|
||||
|
||||
import com.mcwl.memberCenter.domain.MemberConsume;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 积分余额和历史记录
|
||||
*/
|
||||
@Data
|
||||
public class PointsVO {
|
||||
// 积分余额
|
||||
private Double points;
|
||||
|
||||
// 积分消费记录
|
||||
private List<MemberConsume> memberConsumeList = new ArrayList<>();
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.mcwl.web.controller.pay;
|
||||
|
||||
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.easysdk.factory.Factory;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
/**
|
||||
* 支付宝支付
|
||||
|
||||
*/
|
||||
@Component
|
||||
public class AliPayIntegration {
|
||||
@Autowired
|
||||
private Config config;
|
||||
|
||||
|
||||
/**
|
||||
* 调用支付宝预下订单接口
|
||||
*
|
||||
* @param tradeEntity 订单实体
|
||||
* @return 二维码url
|
||||
* @throws Exception
|
||||
*/
|
||||
public String pay(OrderTrade tradeEntity) throws Exception {
|
||||
Factory.setOptions(config);
|
||||
//调用支付宝的接口
|
||||
AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
|
||||
.preCreate("商城",
|
||||
tradeEntity.getCode(),
|
||||
tradeEntity.getPaymentAmount().toString());
|
||||
//参照官方文档响应示例,解析返回结果
|
||||
String httpBodyStr = payResponse.getHttpBody();
|
||||
JSONObject jsonObject = JSONObject.parseObject(httpBodyStr);
|
||||
return jsonObject.getJSONObject("alipay_trade_precreate_response").get("qr_code").toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package com.mcwl.web.controller.pay;
|
||||
|
||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||
import com.mcwl.common.core.controller.BaseController;
|
||||
import com.mcwl.common.core.domain.AjaxResult;
|
||||
import com.mcwl.common.core.page.TableDataInfo;
|
||||
import com.mcwl.common.domain.IdsParam;
|
||||
import com.mcwl.common.interfaces.NoLogin;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import com.mcwl.pay.service.OrderTradeService;
|
||||
import com.mcwl.resource.domain.MallProduct;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.mcwl.common.utils.PageUtils.startPage;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.web.controller.pay
|
||||
* @Filename:OrderTradeController
|
||||
* @Description 支付模块
|
||||
* @Date:2025/1/3 14:46
|
||||
*/
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/web/pay")
|
||||
@Validated
|
||||
public class OrderTradeController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private OrderTradeService orderTradeService;
|
||||
|
||||
@Autowired
|
||||
private AliPayIntegration aliPayIntegration;
|
||||
|
||||
/**
|
||||
* 查询列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(OrderTrade orderTrade)
|
||||
{
|
||||
startPage();
|
||||
List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
@PostMapping("/add")
|
||||
public AjaxResult add(@RequestBody OrderTrade orderTrade)
|
||||
{
|
||||
// 获取当前用户
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return AjaxResult.warn("用户未登录");
|
||||
}
|
||||
orderTrade.setUserId(userId);
|
||||
orderTrade.setCreateBy(getUsername());
|
||||
return toAjax(orderTradeService.insertMallProduct(orderTrade));
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
*/
|
||||
@PostMapping("/upda")
|
||||
public AjaxResult upda(@RequestBody OrderTrade orderTrade)
|
||||
{
|
||||
// 获取当前用户
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
if (userId == null) {
|
||||
return AjaxResult.warn("用户未登录");
|
||||
}
|
||||
orderTrade.setUserId(userId);
|
||||
orderTrade.setUpdateBy(getUsername());
|
||||
return toAjax(orderTradeService.updateMallProduct(orderTrade));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult remove(@RequestBody IdsParam ids)
|
||||
{
|
||||
orderTradeService.deleteMallProductByIds(ids);
|
||||
return success();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 支付接口
|
||||
*
|
||||
* @param tradeEntity 订单实体
|
||||
* @param response 响应
|
||||
* @throws Exception
|
||||
*/
|
||||
@NoLogin
|
||||
@PostMapping("/doPay")
|
||||
public void doPay(@RequestBody OrderTrade tradeEntity, HttpServletResponse response) throws Exception {
|
||||
String qrUrl = aliPayIntegration.pay(tradeEntity);
|
||||
QrCodeUtil.generate(qrUrl, 300, 300, "png", response.getOutputStream());
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package com.mcwl.web.controller.rabbitmq.config;
|
||||
|
||||
import com.alipay.easysdk.kernel.Config;
|
||||
import com.mcwl.common.config.BusinessConfig;
|
||||
import com.mcwl.common.domain.AliPayProperties;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.common.config
|
||||
* @Filename:AliPayConfig
|
||||
* @Description 支付宝配置
|
||||
* @Date:2025/1/3 18:45
|
||||
*/
|
||||
@Configuration
|
||||
public class AliPayConfig {
|
||||
|
||||
@Autowired
|
||||
private BusinessConfig businessConfig;
|
||||
|
||||
@Bean
|
||||
public Config config() {
|
||||
AliPayProperties aliPayConfig = businessConfig.getAliPayConfig();
|
||||
Config config = new Config();
|
||||
config.protocol = aliPayConfig.getProtocol();
|
||||
config.gatewayHost = aliPayConfig.getGatewayHost();
|
||||
config.signType = aliPayConfig.getSignType();
|
||||
config.appId = aliPayConfig.getAppId();
|
||||
config.merchantPrivateKey = aliPayConfig.getPrivateKey();
|
||||
config.alipayPublicKey = aliPayConfig.getPublicKey();
|
||||
config.notifyUrl = aliPayConfig.getNotifyUrl();
|
||||
return config;
|
||||
}
|
||||
}
|
|
@ -7,9 +7,11 @@ import com.mcwl.common.core.page.TableDataInfo;
|
|||
import com.mcwl.common.domain.IdsParam;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.resource.domain.MallProduct;
|
||||
import com.mcwl.resource.service.MallProductService;
|
||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||
import com.mcwl.resource.service.MallProductService;
|
||||
import com.mcwl.web.controller.common.OssUtil;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -36,6 +38,51 @@ public class MallProductController extends BaseController {
|
|||
}
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* 图片
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/file")
|
||||
public AjaxResult Malifile(@RequestParam MultipartFile file){
|
||||
|
||||
String s = OssUtil.uploadMultipartFile(file);
|
||||
return AjaxResult.success(s);
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* zip
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/zipUrlFile")
|
||||
public AjaxResult zipUrlFile(@RequestParam MultipartFile file){
|
||||
String s = OssUtil.uploadMultipartFile(file);
|
||||
return AjaxResult.success(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* 下载zip
|
||||
* @param file
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/zipUrl")
|
||||
public AjaxResult zipUrl(@RequestParam MultipartFile file){
|
||||
String s = OssUtil.uploadMultipartFile(file);
|
||||
return AjaxResult.success(s);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询商品列表
|
||||
*/
|
||||
|
@ -51,12 +98,14 @@ public class MallProductController extends BaseController {
|
|||
/**
|
||||
* 获取详细信息
|
||||
*/
|
||||
@GetMapping(value = "/{jobId}")
|
||||
public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
||||
@GetMapping(value = "/{id}")
|
||||
public AjaxResult getInfo(@PathVariable("id") Long jobId)
|
||||
{
|
||||
return success(mallProductRuleInfoService.selectMallProductById(jobId));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 新增
|
||||
*/
|
||||
|
@ -80,7 +129,7 @@ public class MallProductController extends BaseController {
|
|||
|
||||
|
||||
/**
|
||||
* 删除定
|
||||
* 删除
|
||||
*/
|
||||
@PostMapping
|
||||
public AjaxResult remove(@RequestBody IdsParam ids)
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.mcwl.web.core.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* 跨域配置
|
||||
*/
|
||||
@Configuration
|
||||
public class CorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||||
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||
corsConfiguration.addAllowedOrigin("*");
|
||||
corsConfiguration.addAllowedHeader("*");
|
||||
corsConfiguration.addAllowedMethod("*");
|
||||
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
||||
return new CorsFilter(urlBasedCorsConfigurationSource);
|
||||
}
|
||||
}
|
|
@ -10,7 +10,7 @@ spring:
|
|||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次之能获取一条
|
||||
acknowledge-mode: auto # 设置消费端手动ack确认
|
||||
acknowledge-mode: manual # 设置消费端手动ack确认
|
||||
retry:
|
||||
enabled: true # 是否支持重试
|
||||
# 生产者配置
|
||||
|
|
|
@ -164,14 +164,23 @@ xss:
|
|||
# 匹配链接
|
||||
urlPatterns: /system/*,/monitor/*,/tool/*
|
||||
|
||||
# yml版(application.yml)
|
||||
aliyun:
|
||||
oss:
|
||||
bucketName: ybl2112
|
||||
endpoint: oss-cn-beijing.aliyuncs.com
|
||||
accessKeyId: LTAI5tSHZZ8wHJRP8X4r9TXT
|
||||
accessKeySecret: F82IVNx0IGJ3AnP6gSIfcyql1HCXIH
|
||||
policy : https://ybl2112.oss-cn-beijing.aliyuncs.com/
|
||||
|
||||
#aliyun-oss
|
||||
# aliyun:
|
||||
# oss:
|
||||
# file:
|
||||
# endPoint: "http://oss-cn-beijing.aliyuncs.com" // 一般不用改,选择自己的地址即可
|
||||
# keyid: "保存的key"
|
||||
# keyecrets: "保存的secret"
|
||||
# #bucket可以在控制台创建,也可以使用java代码创建
|
||||
# bucketname: "实例名称"
|
||||
|
||||
mall:
|
||||
mgt:
|
||||
aliPayConfig:
|
||||
protocol: https
|
||||
gatewayHost: openapi-sandbox.dl.alipaydev.com
|
||||
signType: RSA2
|
||||
appId: 9021000138607290
|
||||
privateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCarcUREqQVHIYq4FBuqvcYxOxsuUI3gOphRXcN0k/hIUV7fcfO9ivui99pJihbou9MmC22FM7hzFMHHl4GvZQJuw/GgJlnh9T/SlfS9Awlr0nbzVtXYOd7Os1EM4Jry2PW3zkvaWMvO3DfcYU47bqN8aw+vVBhSVeVhq41zKkH9k8UPw6Ny4WmVUHje84ykf1uBR8AqPxEeDIYD79CGGLtGLECuHoeRsVpGrNmZxwmcen1Bwf8oWiM68+Ein3S/pV69ED6x74+/WDJO71IHUJN+1DclLVXWVGriUenUzTVrAhh8RHgtF5J+t4K24qrGpbsryXzuYJ/p872ieI2oFnLAgMBAAECggEAVfbziiyJAq6qplOqgAcGcz6mgzpm4cAFAvB/XTAgcudx3VMnZA+OlPIpxR+O2Hbydegxp3tjCzzqfA9VhHuCNfI/rzuzhkWIjCV+L+Cwi5UjAETeWe6iV+tzP089UbllEHtZJc91bz+i2JwXxW7h+pdw+iFu9dK0GYcTdRT8cE6FVkBtRikUMA/bAQ4f5umF/vv5yx2XsyfCJddyI2eKIOQQ3FZ27/EEvj+hkWFGj+hcTO0zchCzYudaUyhVanJfPOTMeQrh5J9d13HXQYH0qPT4NYrLSXPjl04zAhWyZQw50kFMpkYnog0i9E9XWESSBXilALd2hITmRAj8MPqi8QKBgQDmJ4P5Fa88nvBoPvpjkevcoOP7EzokvsJuw9QHwr7mKwY5/uTrDkHmgy0iIQJ7BQmYOTW+CcwAcaquQwZrdauxsto5sG+Vle62e9FIGxqsCqrzqRS3bKY2NHUS33Ep43lA9Uz07wYchFHs17e4rTidotaWd+ONhGu2zi44vXZOMwKBgQCsDHr1fDoKplRnJ9Na+YkkpG86lGvHW8R/69dn4ur89mCGhFyexLrSA1NggAMYT9pADg4G2jYvsPa+0ynV4rg8fmvfgpO9dvv3UoOGBxxdzaxNlIdb5LsuyQMN6wcWNSQFH9qDt9nyZ5BLCQXd/DJLMtgLSBpAYi+HZD1E4Zv+CQKBgQCaDZslr+ES56QtcvIwkazZigvvtCf4DoOglo2nADC9adEKItZhi7KKtAUS0huR8oZAkRKq+G3HYk4HxK9YYHQjRn8RnEqkSq51ER29cP8CZ0WUQPmv6Ra8M5KlplBd5Hf2BfuT+yYREnSv3piIEdJSmXufTfJPeHKM8yc3LYIxxwKBgFnjK1qWTLzDqdU7OXGObdh3EKXKZYUCrOcokKH2LE99aXDeNoW8wt52XllMiFFrZtuQfEOYPjcsfb21FWZpzVfNtQ5Ral7Si1HsCks769YWXq8pqo6YMjN/UdkzscAog2kp+0BWDchX00tgq3APEze2mKlMQmrg4XQbKueR964BAoGBAMA5mWyKVfphQ2SsOrYSF5hQ7PBaTT/gLLU2CWBcCXge4oO7dd3MIsd2+7cJG9uYPiSgJdLGqmVfet4pBXNd4znYjHunRr6BukTZzQSNujn0j2fr3SDN46vuqVjYsPF05hGWy3XH5NflrTHq7RO6qkqcqxdaSCRZO7a9G+ckzvx/
|
||||
publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjehzFgsbjUfksMRBGsYGi/ycg5/SMP8jmGMbRWbiVmDVKO8GdVI0StLZvfLi8ozUPcGrJzQL3HaXx+b88JXQPJ2ftUiBvQnoAf+qzWKqsqXo40uuy6DZc+0LAGoxup2WyFp4YcIf+XFMJBSGmQaGSqYs3Lx49/aWI1uFTzBL4YF4X7ckXm6Cl2xr5gD1Gl1twbKIyeDnAZal2Eego4pLwFkcP6jZFaAY0V3YqTfhZLAl5NK+K4BCB2iQPOiK6Qr5XMRhnUVQVeZr5T9PmYf1GyncBIWgUaZlmGNq6Yup2trQW/mEqDqzeek4N3NuoORdZ2JBAnLdqAjQyRBrQAnkbQIDAQAA
|
||||
notifyUrl: http://susan.net.cn/notify
|
||||
|
|
|
@ -17,11 +17,17 @@
|
|||
</description>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<!--OSS-->
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.17.1</version>
|
||||
<version>3.17.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>3.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
|
@ -44,13 +50,32 @@
|
|||
<artifactId>fastdfs-client</artifactId>
|
||||
<version>1.26.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>1.1.1</version>
|
||||
</dependency>
|
||||
<!-- no more than 2.3.3-->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jaxb</groupId>
|
||||
<artifactId>jaxb-runtime</artifactId>
|
||||
<version>2.3.3</version>
|
||||
</dependency>
|
||||
<!-- quartz定时任务-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-quartz</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun.oss</groupId>
|
||||
<artifactId>aliyun-sdk-oss</artifactId>
|
||||
<version>3.17.4</version>
|
||||
</dependency>
|
||||
<!-- SpringWeb模块 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package com.mcwl.common.config;
|
||||
|
||||
import com.mcwl.common.config.properties.QuartzThreadPoolProperties;
|
||||
import com.mcwl.common.domain.AliPayProperties;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.common.config
|
||||
* @Filename:BusinessConfig
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 18:46
|
||||
*/
|
||||
@Data
|
||||
@Component
|
||||
@Slf4j
|
||||
@ConfigurationProperties(prefix = "mall.mgt")
|
||||
public class BusinessConfig {
|
||||
|
||||
/**
|
||||
* 动态定时任务线程池配置
|
||||
*/
|
||||
private QuartzThreadPoolProperties QuartzThreadPoolConfig = new QuartzThreadPoolProperties();
|
||||
|
||||
/**
|
||||
* 商品搜索index名称
|
||||
*/
|
||||
private String productEsIndexName = "product-es-index-v1";
|
||||
|
||||
/**
|
||||
* 支付宝支付相关配置
|
||||
*/
|
||||
private AliPayProperties aliPayConfig = new AliPayProperties();
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.mcwl.common.config.properties;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QuartzThreadPoolProperties {
|
||||
|
||||
/**
|
||||
* 核心线程数
|
||||
*/
|
||||
private int corePoolSize = 8;
|
||||
|
||||
/**
|
||||
* 最大线程数
|
||||
*/
|
||||
private int maxPoolSize = 10;
|
||||
|
||||
/**
|
||||
* 队列大小
|
||||
*/
|
||||
private int queueSize = 200;
|
||||
|
||||
/**
|
||||
* 空闲线程回收时间,多少秒
|
||||
*/
|
||||
private int keepAliveSeconds = 30;
|
||||
|
||||
/**
|
||||
* 线程前缀
|
||||
*/
|
||||
private String threadNamePrefix = "QuartzThread";
|
||||
|
||||
|
||||
}
|
|
@ -101,6 +101,18 @@ public class BaseEntity implements Serializable
|
|||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
|
||||
public String getDelFlag()
|
||||
{
|
||||
return delFlag;
|
||||
}
|
||||
|
||||
public void setDelFlag(String delFlag)
|
||||
{
|
||||
this.delFlag = delFlag;
|
||||
}
|
||||
|
||||
|
||||
public String getRemark()
|
||||
{
|
||||
return remark;
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package com.mcwl.common.domain;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.common.domain
|
||||
* @Filename:AliPayProperties
|
||||
* @Description 支付宝支付配置
|
||||
* @Date:2025/1/3 18:45
|
||||
*/
|
||||
@Data
|
||||
public class AliPayProperties {
|
||||
|
||||
private String protocol;
|
||||
private String gatewayHost;
|
||||
private String signType;
|
||||
private String appId;
|
||||
private String privateKey;
|
||||
private String publicKey;
|
||||
private String notifyUrl;
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.mcwl.common.interfaces;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 无需登录注解
|
||||
*
|
||||
* @author 陈妍
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface NoLogin {
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
||||
*
|
||||
* https://www.mall4j.com/
|
||||
*
|
||||
* 未经允许,不可做商业用途!
|
||||
*
|
||||
* 版权所有,侵权必究!
|
||||
*/
|
||||
package com.mcwl.common.utils;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 对象转换工具类
|
||||
*/
|
||||
public class BeanUtil {
|
||||
public static <S, D> List<D> mapAsList(final Iterable<S> sourceObject, Class<D> clazz) {
|
||||
return JSONObject.parseArray(JSONObject.toJSONString(sourceObject), clazz);
|
||||
}
|
||||
public static <S, D> D map(final S sourceObject, Class<D> clazz) {
|
||||
return JSONObject.parseObject(JSONObject.toJSONString(sourceObject), clazz);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,153 @@
|
|||
package com.mcwl.common.utils.oss;
|
||||
|
||||
import com.aliyun.oss.OSS;
|
||||
import com.aliyun.oss.OSSClientBuilder;
|
||||
import com.aliyun.oss.model.GetObjectRequest;
|
||||
import com.aliyun.oss.model.PutObjectRequest;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Oss服务调用
|
||||
*/
|
||||
@Log4j2
|
||||
public class OssUtil {
|
||||
|
||||
/**
|
||||
* Endpoint 存储对象概述 阿里云主账号AccessKey,accessKeySecret拥有所有API的访问权限 访问路径前缀 存储对象概述
|
||||
*/
|
||||
private static String endPoint = "oss-cn-beijing.aliyuncs.com";
|
||||
private static String accessKeyId = "LTAI5tSHZZ8wHJRP8X4r9TXT";
|
||||
private static String accessKeySecret = "F82IVNx0IGJ3AnP6gSIfcyql1HCXIH";
|
||||
private static String accessPre = "https://ybl2112.oss-cn-beijing.aliyuncs.com/";
|
||||
|
||||
/**
|
||||
* bucket名称
|
||||
* @return
|
||||
*/
|
||||
private static String bucketName = "ylb2112";
|
||||
|
||||
private static OSS ossClient ;
|
||||
|
||||
static {
|
||||
ossClient = new OSSClientBuilder().build(
|
||||
endPoint,
|
||||
accessKeyId,
|
||||
accessKeySecret);
|
||||
log.info("oss服务连接成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传本地文件
|
||||
* @param filePath
|
||||
*/
|
||||
public static String uploadFile(String filePath){
|
||||
return uploadFileForBucket(bucketName,getOssFilePath(filePath) ,filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认路径上传multipartFile文件
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(MultipartFile multipartFile) {
|
||||
return uploadMultipartFile(bucketName,getOssFilePath(multipartFile.getOriginalFilename()),multipartFile);
|
||||
}
|
||||
/**
|
||||
* 上传 multipartFile 类型文件
|
||||
* @param bucketName
|
||||
* @param ossPath
|
||||
* @param multipartFile
|
||||
*/
|
||||
public static String uploadMultipartFile(String bucketName , String ossPath , MultipartFile multipartFile){
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = multipartFile.getInputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre+ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用File上传PutObject上传文件 ** 程序默认使用次方法上传
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileForBucket(String bucketName , String ossPath , String filePath) {
|
||||
// 创建PutObjectRequest对象。
|
||||
PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, ossPath, new File(filePath));
|
||||
|
||||
// 上传
|
||||
ossClient.putObject(putObjectRequest);
|
||||
return accessPre+ossPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用文件流上传到指定的bucket实例
|
||||
* @param bucketName 实例名称
|
||||
* @param ossPath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static String uploadFileInputStreamForBucket(String bucketName , String ossPath , String filePath){
|
||||
|
||||
// 填写本地文件的完整路径。如果未指定本地路径,则默认从示例程序所属项目对应本地路径中上传文件流。
|
||||
InputStream inputStream = null;
|
||||
try {
|
||||
inputStream = new FileInputStream(filePath);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 填写Bucket名称和Object完整路径。Object完整路径中不能包含Bucket名称。
|
||||
uploadFileInputStreamForBucket(bucketName, ossPath, inputStream);
|
||||
return accessPre+ossPath;
|
||||
}
|
||||
|
||||
public static void uploadFileInputStreamForBucket(String bucketName , String ossPath , InputStream inputStream ){
|
||||
ossClient.putObject(bucketName, ossPath, inputStream);
|
||||
}
|
||||
|
||||
/**
|
||||
* 下载
|
||||
* @param ossFilePath
|
||||
* @param filePath
|
||||
*/
|
||||
public static void downloadFile(String ossFilePath , String filePath ){
|
||||
downloadFileForBucket(bucketName , ossFilePath , filePath);
|
||||
}
|
||||
/**
|
||||
* 下载
|
||||
* @param bucketName 实例名称
|
||||
* @param ossFilePath oss存储路径
|
||||
* @param filePath 本地文件路径
|
||||
*/
|
||||
public static void downloadFileForBucket(String bucketName , String ossFilePath , String filePath ){
|
||||
ossClient.getObject(new GetObjectRequest(bucketName, ossFilePath), new File(filePath));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getOssDefaultPath(){
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String url =
|
||||
now.getYear()+"/"+
|
||||
now.getMonth()+"/"+
|
||||
now.getDayOfMonth()+"/"+
|
||||
now.getHour()+"/"+
|
||||
now.getMinute()+"/";
|
||||
return url;
|
||||
}
|
||||
|
||||
public static String getOssFilePath(String filePath){
|
||||
String fileSuf = filePath.substring(filePath.indexOf(".") + 1);
|
||||
return getOssDefaultPath() + UUID.randomUUID().toString() + "." + fileSuf;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,16 +1,16 @@
|
|||
package com.mcwl.memberCenter.consumer;
|
||||
|
||||
import com.mcwl.common.constant.QueueConstants;
|
||||
import com.mcwl.memberCenter.domain.UserMember;
|
||||
import com.mcwl.memberCenter.service.UserMemberService;
|
||||
import com.mcwl.memberCenter.task.UserMemberTask;
|
||||
import com.mcwl.memberCenter.domain.Member;
|
||||
import com.mcwl.memberCenter.service.MemberService;
|
||||
import com.rabbitmq.client.Channel;
|
||||
import org.springframework.amqp.core.Message;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
@Slf4j
|
||||
|
@ -18,23 +18,39 @@ import java.util.List;
|
|||
@RequiredArgsConstructor
|
||||
public class EmptyPointsRemindConsumer {
|
||||
|
||||
private final UserMemberService userMemberService;
|
||||
private final MemberService memberService;
|
||||
|
||||
@RabbitListener(queues = QueueConstants.EMPTY_POINTS_REMIND_QUEUE)
|
||||
public void emptyPointsRemind(List<UserMember> userMemberList) {
|
||||
// TODO 发送短信提醒用户积分即将清零
|
||||
log.info("消费者获取到积分清零提醒的数据:{}", userMemberList);
|
||||
@RabbitListener(queues = QueueConstants.EMPTY_POINTS_REMIND_QUEUE, ackMode = "MANUAL")
|
||||
public void emptyPointsRemind(Member Member, Channel channel, Message message) {
|
||||
try {
|
||||
// TODO 发送短信提醒用户积分即将清零
|
||||
log.info("获取到积分清零提醒的数据:{}", Member);
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
|
||||
} catch (Exception e) {
|
||||
log.error("处理积分清零提醒消息时出错: {}", e.getMessage(), e);
|
||||
try {
|
||||
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
} catch (IOException ex) {
|
||||
log.error("消息确认失败: {}", ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RabbitListener(queues = QueueConstants.MEMBER_BILLING_QUEUE)
|
||||
public void memberBillingQueue(UserMember userMember) {
|
||||
// TODO 发送短信提醒用户会员账单,如果支付成功,更新last_payment_date,并重新计算end_date(start_date + 1个月)
|
||||
log.info("消费者获取到会员账单的数据:{}", userMember);
|
||||
@RabbitListener(queues = QueueConstants.MEMBER_BILLING_QUEUE, ackMode = "MANUAL")
|
||||
public void memberBillingQueue(Member member, Channel channel, Message message) {
|
||||
try {
|
||||
// TODO 发送短信提醒用户会员账单,如果支付成功,更新last_payment_date,并重新计算end_date(start_date + 1个月)
|
||||
log.info("获取到会员账单的数据:{}", member);
|
||||
} catch (Exception e) {
|
||||
log.error("处理会员账单消息时出错: {}", e.getMessage(), e);
|
||||
try {
|
||||
channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
|
||||
} catch (IOException ex) {
|
||||
log.error("消息确认失败: {}", ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
package com.mcwl.memberCenter.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import com.mcwl.memberCenter.enums.MemberEnum;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
|
@ -16,24 +18,37 @@ public class Member extends BaseEntity {
|
|||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 会员类型
|
||||
private String memberType;
|
||||
// 用户ID
|
||||
private Long userId;
|
||||
|
||||
// 会员名称
|
||||
private String memberName;
|
||||
// 会员等级ID
|
||||
private Long memberLevelId;
|
||||
|
||||
// 会员价格
|
||||
private Double unitPrice;
|
||||
// 会员开始时间
|
||||
private Date startDate;
|
||||
|
||||
// 会员原价
|
||||
private Double originalPrice;
|
||||
// 会员结束时间
|
||||
private Date endDate;
|
||||
|
||||
// 会员积分
|
||||
private Integer points;
|
||||
private Double points;
|
||||
|
||||
// 订阅周期(天)
|
||||
private Integer subscriptionPeriod;
|
||||
// 订阅状态 active(活跃,连续包月)、inactive(非活跃,不连续包月)、pending(待支付)和expired(过期)
|
||||
private MemberEnum subscriptionStatus;
|
||||
|
||||
// 支付方式
|
||||
private String paymentMethod;
|
||||
|
||||
// 上次支付时间
|
||||
private Date lastPaymentDate;
|
||||
|
||||
// 下次计费时间
|
||||
private Date nextBillingDate;
|
||||
|
||||
// 上次登录时间
|
||||
private Date lastLoginDate;
|
||||
|
||||
// 状态(0:正常 1:禁用)
|
||||
private String status;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package com.mcwl.memberCenter.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import com.mcwl.memberCenter.enums.MemberBenefitTypeEnum;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mem_member_benefit")
|
||||
public class MemberBenefit extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 会员等级id
|
||||
private Long memberLevelId;
|
||||
|
||||
// 权益名称
|
||||
private String benefitName;
|
||||
|
||||
// 权益描述
|
||||
private String benefitDesc;
|
||||
|
||||
// 权益类型
|
||||
private MemberBenefitTypeEnum benefitType;
|
||||
|
||||
// 权益折扣 当权益类型为折扣时,记录折扣的具体数值,如0.9代表9折
|
||||
private Double benefitDiscount;
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.mcwl.memberCenter.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mem_member_consume")
|
||||
public class MemberConsume extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 用户id
|
||||
private Long userId;
|
||||
|
||||
// 消费积分
|
||||
private Double consumePoints;
|
||||
|
||||
// 剩余积分
|
||||
private Double remainingPoints;
|
||||
|
||||
// 消费时间
|
||||
private Date consumeTime;
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package com.mcwl.memberCenter.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import com.mcwl.memberCenter.enums.MemberPeriodicEnum;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mem_member_level")
|
||||
public class MemberLevel extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 会员名称
|
||||
private String memberName;
|
||||
|
||||
// 会员价格
|
||||
private Double unitPrice;
|
||||
|
||||
// 会员原价
|
||||
private Double originalPrice;
|
||||
|
||||
// 订阅周期(年,季度,月,包月)
|
||||
private MemberPeriodicEnum subscriptionPeriod;
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
package com.mcwl.memberCenter.domain;
|
||||
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableLogic;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import com.mcwl.memberCenter.enums.MemberMenu;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@TableName("mem_user_member")
|
||||
public class UserMember extends BaseEntity {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
|
||||
// 用户ID
|
||||
private Long userId;
|
||||
|
||||
// 会员ID
|
||||
private Long memberId;
|
||||
|
||||
// 会员开始时间
|
||||
private Date startDate;
|
||||
|
||||
// 会员结束时间
|
||||
private Date endDate;
|
||||
|
||||
// 会员积分
|
||||
private Integer points;
|
||||
|
||||
// 订阅状态 active(活跃,连续包月)、inactive(非活跃,不连续包月)、pending(待支付)和expired(过期)
|
||||
private MemberMenu subscriptionStatus;
|
||||
|
||||
// 支付方式
|
||||
private String paymentMethod;
|
||||
|
||||
// 上次支付时间
|
||||
private Date lastPaymentDate;
|
||||
|
||||
// 下次计费时间
|
||||
private Date nextBillingDate;
|
||||
|
||||
// 上次登录时间
|
||||
private Date lastLoginDate;
|
||||
|
||||
// 状态(0:正常 1:禁用)
|
||||
private String status;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.mcwl.memberCenter.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MemberBenefitTypeEnum {
|
||||
|
||||
DISCOUNT("discount", "折扣"),
|
||||
|
||||
POINTS("points", "积分"),
|
||||
|
||||
CASH("cash", "现金"),
|
||||
|
||||
FREE("free", "免费");
|
||||
|
||||
private final String name;
|
||||
|
||||
@EnumValue
|
||||
private final String value;
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@ import lombok.Getter;
|
|||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MemberMenu {
|
||||
public enum MemberEnum {
|
||||
MEMBER_CENTER_ACTIVE("active", "活跃"),
|
||||
MEMBER_CENTER_INACTIVE("inactive", "非活跃"),
|
||||
MEMBER_CENTER_PENDING("pending", "待支付"),
|
|
@ -0,0 +1,19 @@
|
|||
package com.mcwl.memberCenter.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum MemberPeriodicEnum {
|
||||
YEAR("year", "年"),
|
||||
QUARTER("quarter", "季度"),
|
||||
MONTH("month", "月"),
|
||||
CONTINUE_MONTH("continueMonth", "包月");
|
||||
|
||||
|
||||
private final String name;
|
||||
@EnumValue
|
||||
private final String value;
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.mcwl.memberCenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.memberCenter.domain.MemberBenefit;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MemberBenefitMapper extends BaseMapper<MemberBenefit> {
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.mcwl.memberCenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.memberCenter.domain.MemberConsume;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface MemberConsumeMapper extends BaseMapper<MemberConsume> {
|
||||
}
|
|
@ -1,9 +1,11 @@
|
|||
package com.mcwl.memberCenter.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.memberCenter.domain.UserMember;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
//@Mapper
|
||||
public interface UserMemberMapper extends BaseMapper<UserMember> {
|
||||
@Mapper
|
||||
public interface MemberLevelMapper extends BaseMapper<MemberLevel> {
|
||||
|
||||
|
||||
}
|
|
@ -4,8 +4,6 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import com.mcwl.memberCenter.domain.Member;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
//@Mapper
|
||||
@Mapper
|
||||
public interface MemberMapper extends BaseMapper<Member> {
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package com.mcwl.memberCenter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.memberCenter.domain.MemberBenefit;
|
||||
|
||||
public interface MemberBenefitService extends IService<MemberBenefit> {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.mcwl.memberCenter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.memberCenter.domain.MemberConsume;
|
||||
|
||||
public interface MemberConsumeService extends IService<MemberConsume> {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.mcwl.memberCenter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
|
||||
public interface MemberLevelService extends IService<MemberLevel> {
|
||||
|
||||
|
||||
}
|
|
@ -7,5 +7,28 @@ import java.util.List;
|
|||
|
||||
public interface MemberService extends IService<Member> {
|
||||
|
||||
/**
|
||||
* 创建用户会员
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param memberLevelId 会员等级id
|
||||
* @return 用户会员
|
||||
*/
|
||||
Member createUserMember(Long userId, Long memberLevelId, String paymentMethod);
|
||||
|
||||
/**
|
||||
*
|
||||
* @return 获取正常的正在使用的用户会员集合
|
||||
*/
|
||||
List<Member> getUseUserMember();
|
||||
|
||||
/**
|
||||
* 根据用户id获取正常的正在使用的用户会员
|
||||
* @param userId 用户id
|
||||
* @return 用户会员
|
||||
*/
|
||||
Member getUseUserMemberByUserId(Long userId);
|
||||
|
||||
|
||||
Member rechargePoints(Long userId, Double points);
|
||||
}
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
package com.mcwl.memberCenter.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.memberCenter.domain.UserMember;
|
||||
|
||||
public interface UserMemberService extends IService<UserMember> {
|
||||
|
||||
/**
|
||||
* 创建用户会员
|
||||
* @param userId 用户id
|
||||
* @param memberId 会员id
|
||||
* @return 用户会员
|
||||
*/
|
||||
UserMember createUserMember(Long userId, Long memberId, String paymentMethod);
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mcwl.memberCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.memberCenter.domain.MemberBenefit;
|
||||
import com.mcwl.memberCenter.mapper.MemberBenefitMapper;
|
||||
import com.mcwl.memberCenter.service.MemberBenefitService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MemberBenefitServiceImpl extends ServiceImpl<MemberBenefitMapper, MemberBenefit> implements MemberBenefitService {
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package com.mcwl.memberCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.memberCenter.domain.MemberConsume;
|
||||
import com.mcwl.memberCenter.mapper.MemberConsumeMapper;
|
||||
import com.mcwl.memberCenter.service.MemberConsumeService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MemberConsumeServiceImpl extends ServiceImpl<MemberConsumeMapper, MemberConsume> implements MemberConsumeService {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.mcwl.memberCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
import com.mcwl.memberCenter.mapper.MemberLevelMapper;
|
||||
import com.mcwl.memberCenter.service.MemberLevelService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class MemberLevelServiceImpl extends ServiceImpl<MemberLevelMapper, MemberLevel> implements MemberLevelService {
|
||||
|
||||
}
|
|
@ -1,14 +1,185 @@
|
|||
package com.mcwl.memberCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.memberCenter.domain.MemberBenefit;
|
||||
import com.mcwl.memberCenter.domain.MemberLevel;
|
||||
import com.mcwl.memberCenter.domain.Member;
|
||||
import com.mcwl.memberCenter.enums.MemberBenefitTypeEnum;
|
||||
import com.mcwl.memberCenter.enums.MemberEnum;
|
||||
import com.mcwl.memberCenter.enums.MemberPeriodicEnum;
|
||||
import com.mcwl.memberCenter.mapper.MemberMapper;
|
||||
import com.mcwl.memberCenter.service.MemberBenefitService;
|
||||
import com.mcwl.memberCenter.service.MemberLevelService;
|
||||
import com.mcwl.memberCenter.service.MemberService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class MemberServiceImpl extends ServiceImpl<MemberMapper, Member> implements MemberService {
|
||||
|
||||
private final MemberLevelService memberLevelService;
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
private final MemberBenefitService memberBenefitService;
|
||||
|
||||
@Override
|
||||
public Member createUserMember(Long userId, Long memberLevelId, String paymentMethod) {
|
||||
if (userId == null) {
|
||||
return null;
|
||||
}
|
||||
SysUser user = sysUserService.selectUserById(userId);
|
||||
if (user == null || memberLevelId == null) {
|
||||
return null;
|
||||
}
|
||||
MemberLevel memberLevel = memberLevelService.getById(memberLevelId);
|
||||
if (memberLevel == null) {
|
||||
return null;
|
||||
}
|
||||
// 查询用户是否已经存在会员
|
||||
LambdaQueryWrapper<Member> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(Member::getUserId, userId)
|
||||
// subscriptionStatus不为expired
|
||||
.ne(Member::getSubscriptionStatus, MemberEnum.MEMBER_CENTER_EXPIRED)
|
||||
.orderBy(true, false, Member::getEndDate);
|
||||
List<Member> memberList = baseMapper.selectList(lqw);
|
||||
Member member = new Member();
|
||||
// 设置用户id
|
||||
member.setUserId(userId);
|
||||
// 设置会员id
|
||||
member.setMemberLevelId(memberLevelId);
|
||||
if (memberList != null && !memberList.isEmpty()) {
|
||||
Member lastMember = memberList.get(0);
|
||||
Date endDate = lastMember.getEndDate();
|
||||
// 设置会员开始时间和结束时间
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(endDate);
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
member.setStartDate(calendar.getTime());
|
||||
member.setEndDate(this.getEndDate(memberLevel.getSubscriptionPeriod(), calendar));
|
||||
} else {
|
||||
// 用户不存在会员
|
||||
// 设置会员开始时间和结束时间
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
member.setStartDate(calendar.getTime());
|
||||
member.setEndDate(this.getEndDate(memberLevel.getSubscriptionPeriod(), calendar));
|
||||
}
|
||||
|
||||
// 设置积分
|
||||
MemberBenefit memberBenefit = memberBenefitService.lambdaQuery()
|
||||
.eq(MemberBenefit::getMemberLevelId, memberLevelId)
|
||||
.eq(MemberBenefit::getBenefitType, MemberBenefitTypeEnum.POINTS)
|
||||
.one();
|
||||
if (memberBenefit != null) {
|
||||
member.setPoints(memberBenefit.getBenefitDiscount());
|
||||
}
|
||||
|
||||
// 设置订阅状态
|
||||
if (memberLevel.getSubscriptionPeriod() == MemberPeriodicEnum.CONTINUE_MONTH) {
|
||||
// 连续包月,会员状态为活跃
|
||||
member.setSubscriptionStatus(MemberEnum.MEMBER_CENTER_ACTIVE);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(member.getEndDate());
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
member.setNextBillingDate(calendar.getTime());
|
||||
} else {
|
||||
member.setSubscriptionStatus(MemberEnum.MEMBER_CENTER_INACTIVE);
|
||||
}
|
||||
// 设置支付时间
|
||||
member.setLastPaymentDate(new Date());
|
||||
// 设置支付方式
|
||||
member.setPaymentMethod(paymentMethod);
|
||||
// 设置创建者
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
member.setCreateBy(sysUser.getUserName());
|
||||
member.setCreateTime(new Date());
|
||||
member.setUpdateBy(sysUser.getUserName());
|
||||
member.setUpdateTime(new Date());
|
||||
|
||||
baseMapper.insert(member);
|
||||
|
||||
|
||||
return member;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Member> getUseUserMember() {
|
||||
return this.getUseUserMember(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member getUseUserMemberByUserId(Long userId) {
|
||||
|
||||
List<Member> memberList = this.getUseUserMember(userId);
|
||||
if (memberList == null || memberList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return memberList.get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Member rechargePoints(Long userId, Double points) {
|
||||
if (userId == null) {
|
||||
return null;
|
||||
}
|
||||
if (points == null) {
|
||||
return null;
|
||||
}
|
||||
Member member = getUseUserMemberByUserId(userId);
|
||||
if (member != null) {
|
||||
member.setPoints(member.getPoints() + points);
|
||||
baseMapper.updateById(member);
|
||||
return member;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Member> getUseUserMember(Long userId) {
|
||||
// startDate 小于等于当前时间、endDate 大于等于当前时间
|
||||
// subscriptionStatus 不为 "过期" 或 "待支付"
|
||||
// status 为 0 的
|
||||
LambdaQueryWrapper<Member> qw = new LambdaQueryWrapper<>();
|
||||
qw.le(Member::getStartDate, new Date())
|
||||
.ge(Member::getEndDate, new Date())
|
||||
.ne(Member::getSubscriptionStatus, MemberEnum.MEMBER_CENTER_EXPIRED)
|
||||
.ne(Member::getSubscriptionStatus, MemberEnum.MEMBER_CENTER_PENDING)
|
||||
.eq(Member::getStatus, "0")
|
||||
.eq(userId != null, Member::getUserId, userId);
|
||||
return baseMapper.selectList(qw);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据订阅周期和开始时间 计算结束时间
|
||||
* @param subscriptionPeriod 订阅周期
|
||||
* @param calendar 结束时间(日历)
|
||||
* @return 结束时间
|
||||
*/
|
||||
private Date getEndDate(MemberPeriodicEnum subscriptionPeriod, Calendar calendar) {
|
||||
switch (subscriptionPeriod) {
|
||||
case YEAR:
|
||||
calendar.add(Calendar.YEAR, 1);
|
||||
break;
|
||||
case QUARTER:
|
||||
calendar.add(Calendar.MONTH, 3);
|
||||
break;
|
||||
case MONTH:
|
||||
case CONTINUE_MONTH:
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
package com.mcwl.memberCenter.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.core.domain.entity.SysUser;
|
||||
import com.mcwl.common.exception.ServiceException;
|
||||
import com.mcwl.common.utils.SecurityUtils;
|
||||
import com.mcwl.memberCenter.domain.Member;
|
||||
import com.mcwl.memberCenter.domain.UserMember;
|
||||
import com.mcwl.memberCenter.enums.MemberMenu;
|
||||
import com.mcwl.memberCenter.mapper.UserMemberMapper;
|
||||
import com.mcwl.memberCenter.service.MemberService;
|
||||
import com.mcwl.memberCenter.service.UserMemberService;
|
||||
import com.mcwl.system.service.ISysUserService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserMemberServiceImpl extends ServiceImpl<UserMemberMapper, UserMember> implements UserMemberService {
|
||||
|
||||
private final MemberService memberService;
|
||||
|
||||
private final ISysUserService sysUserService;
|
||||
|
||||
|
||||
public void aaa() {
|
||||
LambdaQueryWrapper<Member> lqw = new LambdaQueryWrapper<>();
|
||||
|
||||
Member member = new Member();
|
||||
memberService.update(lqw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserMember createUserMember(Long userId, Long memberId, String paymentMethod) {
|
||||
if (userId == null) {
|
||||
throw new ServiceException("用户不能为空");
|
||||
}
|
||||
SysUser user = sysUserService.selectUserById(userId);
|
||||
if (user == null) {
|
||||
throw new ServiceException("用户不存在");
|
||||
}
|
||||
if (memberId == null) {
|
||||
throw new ServiceException("会员不能为空");
|
||||
}
|
||||
Member member = memberService.getById(memberId);
|
||||
if (member == null) {
|
||||
throw new ServiceException("会员不存在");
|
||||
}
|
||||
// 查询用户是否已经存在会员
|
||||
LambdaQueryWrapper<UserMember> lqw = new LambdaQueryWrapper<>();
|
||||
lqw.eq(UserMember::getUserId, userId)
|
||||
// subscriptionStatus不为expired
|
||||
.ne(UserMember::getSubscriptionStatus, MemberMenu.MEMBER_CENTER_EXPIRED)
|
||||
.orderBy(true, false, UserMember::getEndDate);
|
||||
List<UserMember> userMemberList = baseMapper.selectList(lqw);
|
||||
UserMember userMember = new UserMember();
|
||||
// 设置用户id
|
||||
userMember.setUserId(userId);
|
||||
// 设置会员id
|
||||
userMember.setMemberId(memberId);
|
||||
if (userMemberList != null && !userMemberList.isEmpty()) {
|
||||
UserMember lastUserMember = userMemberList.get(0);
|
||||
Date endDate = lastUserMember.getEndDate();
|
||||
// 设置会员开始时间和结束时间
|
||||
Date startDate = new Date(endDate.getTime() + 1000L * 60L * 60L * 24L);
|
||||
userMember.setStartDate(startDate);
|
||||
userMember.setEndDate(new Date(startDate.getTime() + member.getSubscriptionPeriod() * 1000L * 60L * 60L * 24L));
|
||||
} else {
|
||||
// 用户不存在会员
|
||||
// 设置会员开始时间和结束时间
|
||||
Date startDate = new Date();
|
||||
userMember.setStartDate(startDate);
|
||||
userMember.setEndDate(new Date(startDate.getTime() + member.getSubscriptionPeriod() * 1000L * 60L * 60L * 24L));
|
||||
}
|
||||
|
||||
// 设置积分
|
||||
userMember.setPoints(member.getPoints());
|
||||
// 设置订阅状态
|
||||
if (member.getSubscriptionPeriod() == null) {
|
||||
// 连续包月,会员状态为活跃
|
||||
userMember.setSubscriptionStatus(MemberMenu.MEMBER_CENTER_ACTIVE);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(userMember.getEndDate());
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
userMember.setNextBillingDate(calendar.getTime());
|
||||
} else {
|
||||
userMember.setSubscriptionStatus(MemberMenu.MEMBER_CENTER_INACTIVE);
|
||||
}
|
||||
// 设置支付时间
|
||||
userMember.setLastPaymentDate(new Date());
|
||||
// 设置支付方式
|
||||
userMember.setPaymentMethod(paymentMethod);
|
||||
// 设置创建者
|
||||
SysUser sysUser = sysUserService.selectUserById(userId);
|
||||
userMember.setCreateBy(sysUser.getUserName());
|
||||
userMember.setCreateTime(new Date());
|
||||
userMember.setUpdateBy(sysUser.getUserName());
|
||||
userMember.setUpdateTime(new Date());
|
||||
|
||||
baseMapper.insert(userMember);
|
||||
|
||||
|
||||
return userMember;
|
||||
}
|
||||
}
|
|
@ -1,17 +1,13 @@
|
|||
package com.mcwl.memberCenter.task;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.mcwl.common.constant.QueueConstants;
|
||||
import com.mcwl.memberCenter.domain.UserMember;
|
||||
import com.mcwl.memberCenter.enums.MemberMenu;
|
||||
import com.mcwl.memberCenter.service.UserMemberService;
|
||||
import com.mcwl.memberCenter.domain.Member;
|
||||
import com.mcwl.memberCenter.enums.MemberEnum;
|
||||
import com.mcwl.memberCenter.service.MemberService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -21,7 +17,7 @@ import java.util.List;
|
|||
@RequiredArgsConstructor
|
||||
public class UserMemberTask {
|
||||
|
||||
private final UserMemberService userMemberService;
|
||||
private final MemberService memberService;
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
@ -30,10 +26,14 @@ public class UserMemberTask {
|
|||
* 积分清零提醒 月底前五天
|
||||
*/
|
||||
public void emptyPointsRemindTask() {
|
||||
List<UserMember> userMemberList = this.getUseUserMember();
|
||||
|
||||
List<Member> memberList = memberService.getUseUserMember();
|
||||
if (memberList == null || memberList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
// 发送积分清零消息
|
||||
rabbitTemplate.convertAndSend(QueueConstants.EMPTY_POINTS_REMIND_QUEUE, userMemberList);
|
||||
for (Member member : memberList) {
|
||||
rabbitTemplate.convertAndSend(QueueConstants.EMPTY_POINTS_REMIND_QUEUE, member);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -42,70 +42,54 @@ public class UserMemberTask {
|
|||
* 清空积分 每月月底前两天
|
||||
*/
|
||||
public void emptyPointsTsk() {
|
||||
List<UserMember> userMemberList = this.getUseUserMember();
|
||||
if (userMemberList == null || userMemberList.isEmpty()) {
|
||||
List<Member> memberList = memberService.getUseUserMember();
|
||||
if (memberList == null || memberList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
for (UserMember userMember : userMemberList) {
|
||||
userMember.setPoints(0);
|
||||
userMember.setUpdateTime(new Date());
|
||||
for (Member member : memberList) {
|
||||
member.setPoints(0.0);
|
||||
member.setUpdateTime(new Date());
|
||||
}
|
||||
userMemberService.updateBatchById(userMemberList);
|
||||
memberService.updateBatchById(memberList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新会员状态 间隔1h检查
|
||||
*/
|
||||
public void updateSubscriptionStatusTask() {
|
||||
LambdaQueryWrapper<UserMember> qw = new LambdaQueryWrapper<>();
|
||||
LambdaQueryWrapper<Member> qw = new LambdaQueryWrapper<>();
|
||||
// endDate大于当前时间, subscriptionStatus不为过期
|
||||
qw.gt(UserMember::getEndDate, System.currentTimeMillis())
|
||||
.ne(UserMember::getSubscriptionStatus, MemberMenu.MEMBER_CENTER_EXPIRED);
|
||||
List<UserMember> userMemberList = userMemberService.list(qw);
|
||||
if (userMemberList == null || userMemberList.isEmpty()) {
|
||||
qw.gt(Member::getEndDate, System.currentTimeMillis())
|
||||
.ne(Member::getSubscriptionStatus, MemberEnum.MEMBER_CENTER_EXPIRED)
|
||||
.ne(Member::getSubscriptionStatus, MemberEnum.MEMBER_CENTER_PENDING);
|
||||
List<Member> memberList = memberService.list(qw);
|
||||
if (memberList == null || memberList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println("userMemberList = " + userMemberList);
|
||||
System.out.println("userMemberList = " + memberList);
|
||||
|
||||
for (UserMember userMember : userMemberList) {
|
||||
MemberMenu subscriptionStatus = userMember.getSubscriptionStatus();
|
||||
if (subscriptionStatus == MemberMenu.MEMBER_CENTER_ACTIVE) {
|
||||
for (Member member : memberList) {
|
||||
MemberEnum subscriptionStatus = member.getSubscriptionStatus();
|
||||
if (subscriptionStatus == MemberEnum.MEMBER_CENTER_ACTIVE) {
|
||||
// 如果subscriptionStatus是活跃的,表示连续包月。订阅状态改为"待支付"
|
||||
userMember.setSubscriptionStatus(MemberMenu.MEMBER_CENTER_PENDING);
|
||||
member.setSubscriptionStatus(MemberEnum.MEMBER_CENTER_PENDING);
|
||||
// nextBillingDate设置为当前会员结束日期的下个月的同一天,发送账单通知
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(userMember.getEndDate());
|
||||
calendar.setTime(member.getEndDate());
|
||||
calendar.add(Calendar.MONTH, 1);
|
||||
userMember.setNextBillingDate(calendar.getTime());
|
||||
userMemberService.updateById(userMember);
|
||||
member.setNextBillingDate(calendar.getTime());
|
||||
memberService.updateById(member);
|
||||
// 发送会员账单消息,如果支付成功,更新last_payment_date,并重新计算end_date(start_date + 1个月)
|
||||
rabbitTemplate.convertAndSend(QueueConstants.MEMBER_BILLING_QUEUE, userMember);
|
||||
} else if (subscriptionStatus == MemberMenu.MEMBER_CENTER_INACTIVE) {
|
||||
rabbitTemplate.convertAndSend(QueueConstants.MEMBER_BILLING_QUEUE, member);
|
||||
} else if (subscriptionStatus == MemberEnum.MEMBER_CENTER_INACTIVE) {
|
||||
// 不是连续包月,会员状态改为过期,状态改为"1"
|
||||
userMember.setSubscriptionStatus(MemberMenu.MEMBER_CENTER_EXPIRED);
|
||||
userMember.setStatus("1");
|
||||
userMember.setUpdateTime(new Date());
|
||||
member.setSubscriptionStatus(MemberEnum.MEMBER_CENTER_EXPIRED);
|
||||
member.setStatus("1");
|
||||
member.setUpdateTime(new Date());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取正常使用的会员
|
||||
private List<UserMember> getUseUserMember() {
|
||||
// startDate 小于等于当前时间、endDate 大于等于当前时间
|
||||
// subscriptionStatus 不为 "过期" 或 "待支付"
|
||||
// status 为 0 的
|
||||
LambdaQueryWrapper<UserMember> qw = new LambdaQueryWrapper<>();
|
||||
qw.le(UserMember::getStartDate, System.currentTimeMillis())
|
||||
.ge(UserMember::getEndDate, System.currentTimeMillis())
|
||||
.ne(UserMember::getSubscriptionStatus, MemberMenu.MEMBER_CENTER_EXPIRED)
|
||||
.ne(UserMember::getSubscriptionStatus, MemberMenu.MEMBER_CENTER_PENDING)
|
||||
.eq(UserMember::getStatus, "0");
|
||||
// 对应的sql为
|
||||
System.out.println("sql = " + qw.getSqlSegment());
|
||||
return userMemberService.list();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.mcwl.memberCenter.mapper.MemberMapper">
|
||||
<mapper namespace="com.mcwl.memberCenter.mapper.MemberLevelMapper">
|
||||
|
||||
|
||||
|
|
@ -27,9 +27,6 @@ public class Commission extends BaseEntity {
|
|||
// 支付状态
|
||||
private Integer payStatus;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
|
|
@ -25,9 +25,6 @@ public class Consume extends BaseEntity {
|
|||
// 消费时间
|
||||
private Date consumeDate;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
|
|
@ -25,8 +25,6 @@ public class Invitation extends BaseEntity {
|
|||
// 邀请码
|
||||
private String invitationCode;
|
||||
|
||||
// 备注
|
||||
private String remark;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl</artifactId>
|
||||
<version>3.8.8</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>mcwl-pay</artifactId>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<description>
|
||||
pay支付模块
|
||||
</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- 通用工具-->
|
||||
<dependency>
|
||||
<groupId>com.mcwl</groupId>
|
||||
<artifactId>mcwl-common</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||
<version>${mybatis-plus.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
|
@ -0,0 +1,94 @@
|
|||
package com.mcwl.pay.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.mcwl.common.core.domain.BaseEntity;
|
||||
import com.mcwl.common.interfaces.MaxMoney;
|
||||
import com.mcwl.common.interfaces.MinMoney;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.pay.domain
|
||||
* @Filename:OrderTrade
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 14:15
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
@TableName("order_trade")
|
||||
public class OrderTrade extends BaseEntity {
|
||||
|
||||
/**
|
||||
* ID
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 订单编码
|
||||
*/
|
||||
private String code;
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Integer productId;
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
private String productName;
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String userName;
|
||||
/**
|
||||
* 支付方式第三方支付平台返回的交易流水号
|
||||
*/
|
||||
private String paymentMethod;
|
||||
/**
|
||||
* 支付方式
|
||||
*/
|
||||
private Integer transactionId;
|
||||
/**
|
||||
* 下单时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-mm-dd")
|
||||
@DateTimeFormat(pattern = "yyyy-mm-dd")
|
||||
private Date orderTime;
|
||||
/**
|
||||
* 订单状态 1:下单 2:支付 3:完成 4:取消
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer orderStatus;
|
||||
/**
|
||||
* 支付状态 1:待支付 2:已支付 3:退款
|
||||
*/
|
||||
@NotNull(message = "状态不能为空")
|
||||
private Integer payStatus;
|
||||
/**
|
||||
* 总金额
|
||||
*/
|
||||
@NotNull(message = "总金额不能为空")
|
||||
@MinMoney(value = 0, message = "总金额不能小于0")
|
||||
@MaxMoney(value = 100000, message = "总金额必须小于100000")
|
||||
private Integer totalAmount;
|
||||
/**
|
||||
* 付款金额
|
||||
*/
|
||||
@NotNull(message = "付款金额不能为空")
|
||||
@MinMoney(value = 0, message = "付款金额不能小于0")
|
||||
@MaxMoney(value = 100000, message = "付款金额必须小于100000")
|
||||
private Integer paymentAmount;
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.mcwl.pay.domain;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.pay.domain
|
||||
* @Filename:PaymentResult
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 17:30
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Data
|
||||
public class PaymentResult {
|
||||
private boolean success;
|
||||
private String message;
|
||||
private String transactionId;
|
||||
private String errorCode;
|
||||
private BigDecimal amount;
|
||||
private String currency;
|
||||
private String paymentMethod;
|
||||
private LocalDateTime timestamp;
|
||||
private Map<String, Object> extraData;
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private final PaymentResult result = new PaymentResult();
|
||||
|
||||
public Builder setSuccess(boolean success) {
|
||||
result.success = success;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMessage(String message) {
|
||||
result.message = message;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTransactionId(String transactionId) {
|
||||
result.transactionId = transactionId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setErrorCode(String errorCode) {
|
||||
result.errorCode = errorCode;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setAmount(BigDecimal amount) {
|
||||
result.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setCurrency(String currency) {
|
||||
result.currency = currency;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setPaymentMethod(String paymentMethod) {
|
||||
result.paymentMethod = paymentMethod;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setTimestamp(LocalDateTime timestamp) {
|
||||
result.timestamp = timestamp;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setExtraData(Map<String, Object> extraData) {
|
||||
result.extraData = extraData;
|
||||
return this;
|
||||
}
|
||||
|
||||
public PaymentResult build() {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PaymentResult{" +
|
||||
"success=" + success +
|
||||
", message='" + message + '\'' +
|
||||
", transactionId='" + transactionId + '\'' +
|
||||
", errorCode='" + errorCode + '\'' +
|
||||
", amount=" + amount +
|
||||
", currency='" + currency + '\'' +
|
||||
", paymentMethod='" + paymentMethod + '\'' +
|
||||
", timestamp=" + timestamp +
|
||||
", extraData=" + extraData +
|
||||
'}';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package com.mcwl.pay.domain.enums;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.pay.domain
|
||||
* @Filename:PaymentStatus
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 17:24
|
||||
*/
|
||||
|
||||
public enum PaymentStatus {
|
||||
|
||||
PENDING("待支付"),
|
||||
COMPLETED("已支付"),
|
||||
FAILED("支付失败"),
|
||||
REFUNDED("已退款");
|
||||
|
||||
private final String description;
|
||||
|
||||
PaymentStatus(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name() + "(" + description + ")";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package com.mcwl.pay.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import com.mcwl.pay.domain.PaymentResult;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.pay.mapper
|
||||
* @Filename:OrderTradeMapper
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 14:51
|
||||
*/
|
||||
@Mapper
|
||||
public interface OrderTradeMapper extends BaseMapper<OrderTrade> {
|
||||
|
||||
PaymentResult chargeCard(Integer totalAmount, String paymentMethod);
|
||||
|
||||
}
|
|
@ -0,0 +1,28 @@
|
|||
package com.mcwl.pay.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.mcwl.common.domain.IdsParam;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.pay.service
|
||||
* @Filename:OrderTradeService
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 14:51
|
||||
*/
|
||||
public interface OrderTradeService extends IService<OrderTrade> {
|
||||
List<OrderTrade> selectMallProductList(OrderTrade orderTrade);
|
||||
|
||||
int insertMallProduct(OrderTrade orderTrade);
|
||||
|
||||
void deleteMallProductByIds(IdsParam ids);
|
||||
|
||||
int updateMallProduct(OrderTrade orderTrade);
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,104 @@
|
|||
package com.mcwl.pay.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.mcwl.common.domain.IdsParam;
|
||||
import com.mcwl.common.utils.StringUtils;
|
||||
import com.mcwl.pay.domain.OrderTrade;
|
||||
import com.mcwl.pay.domain.PaymentResult;
|
||||
import com.mcwl.pay.domain.enums.PaymentStatus;
|
||||
import com.mcwl.pay.mapper.OrderTradeMapper;
|
||||
import com.mcwl.pay.service.OrderTradeService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author:ChenYan
|
||||
* @Project:McWl
|
||||
* @Package:com.mcwl.pay.service.impl
|
||||
* @Filename:OrderTradeServiceImpl
|
||||
* @Description TODO
|
||||
* @Date:2025/1/3 14:51
|
||||
*/
|
||||
@Service
|
||||
public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTrade> implements OrderTradeService {
|
||||
|
||||
@Autowired
|
||||
private OrderTradeMapper orderTradeMapper;
|
||||
|
||||
@Override
|
||||
public List<OrderTrade> selectMallProductList(OrderTrade orderTrade) {
|
||||
// 创建一个 LambdaQueryWrapper 实例
|
||||
LambdaQueryWrapper<OrderTrade> queryWrapper = new LambdaQueryWrapper<>();
|
||||
|
||||
// 使用非空检查来添加查询条件
|
||||
if (StringUtils.isNotNull(orderTrade.getCode())) {
|
||||
queryWrapper.eq(OrderTrade::getCode, orderTrade.getCode());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getUserId())) {
|
||||
queryWrapper.eq(OrderTrade::getUserId, orderTrade.getUserId());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getProductId())) {
|
||||
queryWrapper.eq(OrderTrade::getProductId, orderTrade.getProductId());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getProductName())) {
|
||||
queryWrapper.like(OrderTrade::getProductName, orderTrade.getProductName());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getUserName())) {
|
||||
queryWrapper.eq(OrderTrade::getUserName, orderTrade.getUserName());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getOrderTime())) {
|
||||
queryWrapper.eq(OrderTrade::getOrderTime, orderTrade.getOrderTime());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getOrderStatus())) {
|
||||
queryWrapper.eq(OrderTrade::getOrderStatus, orderTrade.getOrderStatus());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getPayStatus())) {
|
||||
queryWrapper.eq(OrderTrade::getPayStatus, orderTrade.getPayStatus());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getTotalAmount())) {
|
||||
queryWrapper.eq(OrderTrade::getTotalAmount, orderTrade.getTotalAmount());
|
||||
}
|
||||
if (StringUtils.isNotNull(orderTrade.getPaymentAmount())) {
|
||||
queryWrapper.eq(OrderTrade::getPaymentAmount, orderTrade.getPaymentAmount());
|
||||
}
|
||||
|
||||
return orderTradeMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int insertMallProduct(OrderTrade orderTrade) {
|
||||
PaymentResult paymentResult = orderTradeMapper.chargeCard(orderTrade.getTotalAmount(), orderTrade.getPaymentMethod());
|
||||
|
||||
if (paymentResult.isSuccess()) {
|
||||
// 支付成功后的处理:更新订单状态、生成激活码、更新用户权限等
|
||||
orderTrade.setOrderStatus(PaymentStatus.COMPLETED.ordinal());
|
||||
|
||||
// 保存订单
|
||||
return orderTradeMapper.insert(orderTrade);
|
||||
} else {
|
||||
// 支付失败处理...
|
||||
orderTrade.setOrderStatus(PaymentStatus.FAILED.ordinal());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteMallProductByIds(IdsParam ids) {
|
||||
orderTradeMapper.deleteBatchIds(ids.getIds());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateMallProduct(OrderTrade orderTrade) {
|
||||
return orderTradeMapper.updateById(orderTrade);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue