From 734af91921bc8500b3f6e6fa88d702f6e2756b37 Mon Sep 17 00:00:00 2001 From: khy <2908249413@qq.com> Date: Thu, 24 Oct 2024 18:35:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=EF=BC=88=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E6=94=AF=E4=BB=98=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataobject/member/TradeMemberUserDO.java | 156 +++++++++++++++++ .../member/TradePaidMemberUserDO.java | 157 ++++++++++++++++++ .../mysql/member/TradeMemberUserMapper.java | 72 ++++++++ .../member/TradePaidMemberUserMapper.java | 14 ++ .../member/TradeMemberUserService.java | 26 +++ .../member/TradeMemberUserServiceImpl.java | 107 ++++++++++++ .../member/TradePaidMemberUserService.java | 37 +++++ .../TradeTradePaidMemberUserServiceImpl.java | 95 +++++++++++ .../order/TradeOrderUpdateServiceImpl.java | 31 +++- .../service/user/MemberUserService.java | 2 + .../service/user/MemberUserServiceImpl.java | 13 ++ .../service/user/PaidMemberUserService.java | 7 + .../user/PaidMemberUserServiceImpl.java | 23 +++ .../app/member/AppPaidMembeController.java | 19 +-- 14 files changed, 742 insertions(+), 17 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradeMemberUserDO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradePaidMemberUserDO.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradeMemberUserMapper.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradePaidMemberUserMapper.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserService.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradeMemberUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradeMemberUserDO.java new file mode 100644 index 0000000..f97712f --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradeMemberUserDO.java @@ -0,0 +1,156 @@ +package cn.iocoder.yudao.module.trade.dal.dataobject.member; + +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.enums.TerminalEnum; +import cn.iocoder.yudao.framework.ip.core.Area; +import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; +import cn.iocoder.yudao.module.system.enums.common.SexEnum; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 会员用户 DO + * + * uk_mobile 索引:基于 {@link #mobile} 字段 + * + * @author 芋道源码 + */ +@TableName(value = "member_user", autoResultMap = true) +@KeySequence("member_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TradeMemberUserDO extends TenantBaseDO { + + // ========== 账号信息 ========== + + /** + * 用户ID + */ + @TableId + private Long id; + /** + * 手机 + */ + private String mobile; + /** + * 加密后的密码 + * + * 因为目前使用 {@link BCryptPasswordEncoder} 加密器,所以无需自己处理 salt 盐 + */ + private String password; + /** + * 帐号状态 + * + * 枚举 {@link CommonStatusEnum} + */ + private Integer status; + /** + * 注册 IP + */ + private String registerIp; + /** + * 注册终端 + * 枚举 {@link TerminalEnum} + */ + private Integer registerTerminal; + /** + * 最后登录IP + */ + private String loginIp; + /** + * 最后登录时间 + */ + private LocalDateTime loginDate; + + // ========== 基础信息 ========== + + /** + * 用户昵称 + */ + private String nickname; + /** + * 用户头像 + */ + private String avatar; + + /** + * 真实名字 + */ + private String name; + /** + * 性别 + * + * 枚举 {@link SexEnum} + */ + private Integer sex; + /** + * 出生日期 + */ + private LocalDateTime birthday; + /** + * 所在地 + * + * 关联 {@link Area#getId()} 字段 + */ + private Integer areaId; + /** + * 用户备注 + */ + private String mark; + + // ========== 其它信息 ========== + + /** + * 积分 + */ + private Integer point; + // TODO 疯狂:增加一个 totalPoint;个人信息接口要返回 + + /** + * 会员标签列表,以逗号分隔 + */ + @TableField(typeHandler = LongListTypeHandler.class) + private List tagIds; + + /** + * 会员级别编号 + * + * 关联 {@link MemberLevelDO#getId()} 字段 + */ + private Long levelId; + /** + * 会员经验 + */ + private Integer experience; + /** + * 用户分组编号 + * + * 关联 {@link MemberGroupDO#getId()} 字段 + */ + private Long groupId; + + /** + * 是否绑过卡,是否开通过会员(0:未开通,1:试用,2:有效期,3:永久) + */ + private Integer activate; + + /** + * 会员权益id + */ + private Long noticeInterestId; + /** + * 角色id(0:普通用户, 1:工作人员) + */ + private Integer roleId; +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradePaidMemberUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradePaidMemberUserDO.java new file mode 100644 index 0000000..476bc3c --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/member/TradePaidMemberUserDO.java @@ -0,0 +1,157 @@ +package cn.iocoder.yudao.module.trade.dal.dataobject.member; + +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; +import com.baomidou.mybatisplus.annotation.KeySequence; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.*; + +import java.time.LocalDateTime; + +/** + * 会员 DO + * + * @author 管理员 + */ +@TableName("paid_member_user") +@KeySequence("paid_member_user_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +@Builder +@NoArgsConstructor +@AllArgsConstructor +public class TradePaidMemberUserDO extends TenantBaseDO { + + /** + * 编号 + */ + @TableId + private Long id; + /** + * 用户编号 + */ + private Long uid; + /** + * 手机号 + */ + private String mobile; + /** + * 密码 + */ + private String password; + /** + * 状态 + */ + private Integer status; + /** + * 注册 IP + */ + private String registerIp; + /** + * 注册终端 + */ + private Integer registerTerminal; + /** + * 最后登录IP + */ + private String loginIp; + /** + * 最后登录时间 + */ + private LocalDateTime loginDate; + /** + * 用户昵称 + */ + private String nickname; + /** + * 头像 + */ + private String avatar; + /** + * 真实名字 + */ + private String name; + /** + * 性别 + */ + private Integer sex; + /** + * 出生日期 + */ + private LocalDateTime birthday; + /** + * 所在地 + */ + private Integer areaId; + /** + * 用户备注 + */ + private String mark; + /** + * 积分 + */ + private Integer point; + /** + * 用户标签编号列表,以逗号分隔 + */ + private String tagIds; + /** + * 等级编号 + */ + private Long levelId; + /** + * 经验 + */ + private Integer experience; + /** + * 用户分组编号 + */ + private Long groupId; + + /** + * 是否支付,0:未支付,1:已支付 + * */ + private Boolean paid; + + /* + * 支付时间 + * */ + private LocalDateTime payTime; + /** + * 到期时间 + */ + private LocalDateTime cardExpirationTime; + /** + * 支付金额,单位为分 + */ + private Integer price; + /** + * 期限天数 + */ + private String deadlineDay ; + /** + * 支付方式 + */ + private String payType; + /** + * 支付渠道 + */ + private String payChannel; + /** + * 订单号 + */ + private String orderNo; + /** + * 支付订单编号 + * + * 关联 {@link PayOrderDO#getId()} + */ + private Long payOrderId; + /** + * 会员类型 + */ + private String payMemberType; + + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradeMemberUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradeMemberUserMapper.java new file mode 100644 index 0000000..0642ddc --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradeMemberUserMapper.java @@ -0,0 +1,72 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.member; + +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradeMemberUserDO; +import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +/** + * 会员 User Mapper + * + * @author 芋道源码 + */ +@Mapper +public interface TradeMemberUserMapper extends BaseMapperX { + + default TradeMemberUserDO selectByMobile(String mobile) { + return selectOne(TradeMemberUserDO::getMobile, mobile); + } + + default List selectListByNicknameLike(String nickname) { + return selectList(new LambdaQueryWrapperX() + .likeIfPresent(TradeMemberUserDO::getNickname, nickname)); + } + + + default Long selectCountByGroupId(Long groupId) { + return selectCount(TradeMemberUserDO::getGroupId, groupId); + } + + default Long selectCountByLevelId(Long levelId) { + return selectCount(TradeMemberUserDO::getLevelId, levelId); + } + + default Long selectCountByTagId(Long tagId) { + return selectCount(new LambdaQueryWrapperX() + .apply("FIND_IN_SET({0}, tag_ids)", tagId)); + } + + /** + * 更新用户积分(增加) + * + * @param id 用户编号 + * @param incrCount 增加积分(正数) + */ + default void updatePointIncr(Long id, Integer incrCount) { + Assert.isTrue(incrCount > 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" point = point + " + incrCount) + .eq(TradeMemberUserDO::getId, id); + update(null, lambdaUpdateWrapper); + } + + /** + * 更新用户积分(减少) + * + * @param id 用户编号 + * @param incrCount 增加积分(负数) + * @return 更新行数 + */ + default int updatePointDecr(Long id, Integer incrCount) { + Assert.isTrue(incrCount < 0); + LambdaUpdateWrapper lambdaUpdateWrapper = new LambdaUpdateWrapper() + .setSql(" point = point + " + incrCount) // 负数,所以使用 + 号 + .eq(TradeMemberUserDO::getId, id); + return update(null, lambdaUpdateWrapper); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradePaidMemberUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradePaidMemberUserMapper.java new file mode 100644 index 0000000..d0d33d8 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/member/TradePaidMemberUserMapper.java @@ -0,0 +1,14 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.member; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradePaidMemberUserDO; +import org.apache.ibatis.annotations.Mapper; + +/** + * 会员 Mapper + * + * @author 管理员 + */ +@Mapper +public interface TradePaidMemberUserMapper extends BaseMapperX { +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserService.java new file mode 100644 index 0000000..9061ee5 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserService.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.trade.service.member; + +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradeMemberUserDO; + +/** + * 会员用户 Service 接口 + * + * @author 芋道源码 + */ +public interface TradeMemberUserService { + + + /** + * 通过用户 ID 查询用户 + * + * @param id 用户ID + * @return 用户对象信息 + */ + TradeMemberUserDO getUser(Long id); + + + void updateUserDo(TradeMemberUserDO user); + + void updateActivate(String cardName); + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserServiceImpl.java new file mode 100644 index 0000000..23a0fa7 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeMemberUserServiceImpl.java @@ -0,0 +1,107 @@ +package cn.iocoder.yudao.module.trade.service.member; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradeMemberUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.member.TradeMemberUserMapper; +import com.google.common.annotations.VisibleForTesting; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import javax.validation.Valid; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; + +/** + * 会员 User Service 实现类 + * + * @author 芋道源码 + */ +@Service +@Valid +@Slf4j +public class TradeMemberUserServiceImpl implements TradeMemberUserService { + + @Resource + private TradeMemberUserMapper tradeMemberUserMapper; + + + + @Override + public TradeMemberUserDO getUser(Long id) { + return tradeMemberUserMapper.selectById(id); + } + + + + private TradeMemberUserDO validateUserExists(String mobile) { + TradeMemberUserDO user = tradeMemberUserMapper.selectByMobile(mobile); + if (user == null) { + throw exception(USER_MOBILE_NOT_EXISTS); + } + return user; + } + + + @VisibleForTesting + TradeMemberUserDO validateUserExists(Long id) { + if (id == null) { + return null; + } + TradeMemberUserDO user = tradeMemberUserMapper.selectById(id); + if (user == null) { + throw exception(USER_NOT_EXISTS); + } + return user; + } + + @VisibleForTesting + void validateMobileUnique(Long id, String mobile) { + if (StrUtil.isBlank(mobile)) { + return; + } + TradeMemberUserDO user = tradeMemberUserMapper.selectByMobile(mobile); + if (user == null) { + return; + } + // 如果 id 为空,说明不用比较是否为相同 id 的用户 + if (id == null) { + throw exception(USER_MOBILE_USED, mobile); + } + if (!user.getId().equals(id)) { + throw exception(USER_MOBILE_USED, mobile); + } + } + + + + @Override + public void updateUserDo(TradeMemberUserDO tradeMemberUserDO) { + // 校验存在 + validateUserExists(tradeMemberUserDO.getId()); + // 校验手机唯一 + validateMobileUnique(tradeMemberUserDO.getId(), tradeMemberUserDO.getMobile()); + + // 更新 + if(tradeMemberUserDO.getLevelId() != null && tradeMemberUserDO.getLevelId() == 5){ + tradeMemberUserDO.setLevelId(Long.parseLong("1")); + } + tradeMemberUserMapper.updateById(tradeMemberUserDO); + } + + @Override + public void updateActivate(String cardName) { + TradeMemberUserDO tradeMemberUserDO = getUser(getLoginUserId()); + //设置个人信息的会员状态,0:未开通,1试用,2有效期,3永久 + if(cardName.equals("永久")){ + tradeMemberUserDO.setActivate(3); + }else { + tradeMemberUserDO.setActivate(2); + } + tradeMemberUserMapper.updateById(tradeMemberUserDO); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java new file mode 100644 index 0000000..823c807 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradePaidMemberUserService.java @@ -0,0 +1,37 @@ +package cn.iocoder.yudao.module.trade.service.member; + +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradePaidMemberUserDO; + +import javax.validation.Valid; +import java.time.LocalDateTime; + +/** + * 会员 Service 接口 + * + * @author 管理员 + */ +public interface TradePaidMemberUserService { + + + + LocalDateTime getDeadLineDay(String cardName); + + TradePaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO); + + /** + * 判断当前支付方式 + * */ + String currentPayType(String payChannel); + + /** + * 更新会员 + * + * @param updateReqVO 更新信息 + */ + void update(@Valid TradePaidMemberUserDO updateReqVO); + + + + TradePaidMemberUserDO getByIdAndPayOrderId(Long id, Long payOrderId); + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java new file mode 100644 index 0000000..34c5b17 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/member/TradeTradePaidMemberUserServiceImpl.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.trade.service.member; + +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradePaidMemberUserDO; +import cn.iocoder.yudao.module.trade.dal.mysql.member.TradePaidMemberUserMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.PAID_MEMBER_ORDER_NOT_EXISTS; + +/** + * 会员 Service 实现类 + * + * @author 管理员 + */ +@Service +@Validated +public class TradeTradePaidMemberUserServiceImpl implements TradePaidMemberUserService { + + @Resource + private TradePaidMemberUserMapper tradePaidMemberUserMapper; + + private void validateMemberUserExists(Long id) { + if (tradePaidMemberUserMapper.selectById(id) == null) { + throw exception(PAID_MEMBER_ORDER_NOT_EXISTS); + } + } + + + + //获取会员类型对应的过期时间 + @Override + public LocalDateTime getDeadLineDay(String cardName) { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime deadlineDay; + //判断是否具有过期时间,该操作为续费 + if (cardName.equals("试用")){ + deadlineDay = now.plus(1, ChronoUnit.DAYS); + } else if (cardName.equals("月卡")) { + deadlineDay = now.plus(1,ChronoUnit.MONTHS); + } else if (cardName.equals("季卡")) { + deadlineDay = now.plus(3,ChronoUnit.MONTHS); + } else if (cardName.equals("年卡")) { + deadlineDay = now.plus(1,ChronoUnit.YEARS); + } else { + //永久设置为一个非常远的的日期 + deadlineDay = LocalDateTime.of(9999,12,31,23,59,59); + } + return deadlineDay; + } + + @Override + public TradePaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO) { + TradePaidMemberUserDO tradePaidMemberUserDO = tradePaidMemberUserMapper.selectOne(TradePaidMemberUserDO::getOrderNo,orderNO); + return tradePaidMemberUserDO; + } + + @Override + public String currentPayType(String payChannel) { + String payType = null; + if (payChannel.equals("wallet")){ + payType = "余额"; + } else if(payChannel.startsWith("wx")){ + payType = "微信"; + } else if (payChannel.startsWith("alipay")) { + payType = "支付宝"; + } else { + payType = "模拟支付"; + } + return payType; + } + + @Override + public void update(TradePaidMemberUserDO updateReqVO) { + // 校验存在 + validateMemberUserExists(updateReqVO.getId()); + tradePaidMemberUserMapper.updateById(updateReqVO); + } + + + + @Override + public TradePaidMemberUserDO getByIdAndPayOrderId(Long id, Long payOrderId) { + TradePaidMemberUserDO tradePaidMemberUserDO = tradePaidMemberUserMapper.selectOne( + new LambdaQueryWrapperX().eqIfPresent(TradePaidMemberUserDO::getId,id) + .eqIfPresent(TradePaidMemberUserDO::getPayOrderId,payOrderId)); + return tradePaidMemberUserDO; + } + +} \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 80d4545..86b4ec0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -22,7 +22,6 @@ import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; -import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.dal.dataobject.pointorder.PointOrderDO; import cn.iocoder.yudao.module.promotion.dal.mysql.pointorder.PointOrderMapper; import cn.iocoder.yudao.module.system.api.social.SocialUserApi; @@ -38,6 +37,8 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderI import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradeMemberUserDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.member.TradePaidMemberUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; @@ -50,6 +51,8 @@ import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrder import cn.iocoder.yudao.module.trade.framework.order.core.utils.TradeOrderLogUtils; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; +import cn.iocoder.yudao.module.trade.service.member.TradeMemberUserService; +import cn.iocoder.yudao.module.trade.service.member.TradePaidMemberUserService; import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; import cn.iocoder.yudao.module.trade.service.message.bo.TradeOrderMessageWhenDeliveryOrderReqBO; import cn.iocoder.yudao.module.trade.service.order.handler.TradeOrderHandler; @@ -75,6 +78,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.minusTime; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getTerminal; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; @@ -128,6 +132,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private ProductSpuApi productSpuApi; + @Resource + private TradeMemberUserService tradeMemberUserService; + + @Resource + private TradePaidMemberUserService tradePaidMemberUserService; + // =================== Order =================== @@ -325,6 +335,25 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { TradeOrderDO order = orderResult.getKey(); PayOrderRespDTO payOrder = orderResult.getValue(); + //会员用户信息,支付状态修改 + TradeMemberUserDO tradeMemberUserDO = tradeMemberUserService.getUser(getLoginUserId()); + TradePaidMemberUserDO tradePaidMemberUserDO = tradePaidMemberUserService.getByIdAndPayOrderId(id,payOrderId); + if(tradePaidMemberUserDO != null && tradeMemberUserDO != null){ + tradePaidMemberUserDO.setPayTime(LocalDateTime.now()); + tradePaidMemberUserDO.setPaid(true); + //过期时间 + LocalDateTime cardExpirationTime = tradePaidMemberUserService.getDeadLineDay(tradePaidMemberUserDO.getPayMemberType()); + tradePaidMemberUserDO.setCardExpirationTime(cardExpirationTime); + tradePaidMemberUserDO.setPayChannel(payOrder.getChannelCode()); + //支付方式 + String payType = tradePaidMemberUserService.currentPayType(payOrder.getChannelCode()); + tradePaidMemberUserDO.setPayType(payType); + //更新会员订单 + tradePaidMemberUserService.update(tradePaidMemberUserDO); + //更新用户会员状态 + tradeMemberUserService.updateActivate(tradePaidMemberUserDO.getPayMemberType()); + } + // 2. 更新 TradeOrderDO 状态为已支付,等待发货 int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), new TradeOrderDO().setStatus(TradeOrderStatusEnum.UNDELIVERED.getStatus()).setPayStatus(true) diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java index d33d722..21c7819 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserService.java @@ -189,4 +189,6 @@ public interface MemberUserService { void updateUserDo(MemberUserDO user); + void updateActivate(String cardName); + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java index 6400bf8..8727150 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/MemberUserServiceImpl.java @@ -38,6 +38,7 @@ import java.util.List; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP; +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; /** @@ -328,4 +329,16 @@ public class MemberUserServiceImpl implements MemberUserService { memberUserMapper.updateById(memberUserDO); } + @Override + public void updateActivate(String cardName) { + MemberUserDO memberUserDO = getUser(getLoginUserId()); + //设置个人信息的会员状态,0:未开通,1试用,2有效期,3永久 + if(cardName.equals("永久")){ + memberUserDO.setActivate(3); + }else { + memberUserDO.setActivate(2); + } + memberUserMapper.updateById(memberUserDO); + } + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java index 16c4969..67ada52 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserService.java @@ -61,6 +61,11 @@ public interface PaidMemberUserService { PaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO); + /** + * 判断当前支付方式 + * */ + String currentPayType(String payChannel); + /** * 更新会员 * @@ -79,4 +84,6 @@ public interface PaidMemberUserService { */ PageResult getMemberUserPage(PaidMemberUserPageReqVO pageReqVO); + PaidMemberUserDO getByIdAndPayOrderId(Long id,Long payOrderId); + } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java index 304b55e..b9fa2d1 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/user/PaidMemberUserServiceImpl.java @@ -146,6 +146,21 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { return paidMemberUserDO; } + @Override + public String currentPayType(String payChannel) { + String payType = null; + if (payChannel.equals("wallet")){ + payType = "余额"; + } else if(payChannel.startsWith("wx")){ + payType = "微信"; + } else if (payChannel.startsWith("alipay")) { + payType = "支付宝"; + } else { + payType = "模拟支付"; + } + return payType; + } + @Override public void update(PaidMemberUserDO updateReqVO) { // 校验存在 @@ -170,4 +185,12 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { return paidMemberUserMapper.selectPage(pageReqVO); } + @Override + public PaidMemberUserDO getByIdAndPayOrderId(Long id, Long payOrderId) { + PaidMemberUserDO paidMemberUserDO = paidMemberUserMapper.selectOne( + new LambdaQueryWrapperX().eqIfPresent(PaidMemberUserDO::getId,id) + .eqIfPresent(PaidMemberUserDO::getPayOrderId,payOrderId)); + return paidMemberUserDO; + } + } \ No newline at end of file diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java index 11de3ff..1cf5851 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java @@ -175,25 +175,12 @@ public class AppPaidMembeController { LocalDateTime cardExpirationTime = paidMemberUserService.getDeadLineDay(notifyReqDTO.getCardName()); paidMemberUserDO.setCardExpirationTime(cardExpirationTime); paidMemberUserDO.setPayChannel(notifyReqDTO.getPayChannel()); - if (notifyReqDTO.getPayChannel().equals("wallet")){ - paidMemberUserDO.setPayType("余额"); - } else if(notifyReqDTO.getPayChannel().startsWith("wx")){ - paidMemberUserDO.setPayType("微信"); - } else if (notifyReqDTO.getPayChannel().startsWith("alipay")) { - paidMemberUserDO.setPayType("支付宝"); - } else { - paidMemberUserDO.setPayType("模拟支付"); - } + String payType = paidMemberUserService.currentPayType(notifyReqDTO.getPayChannel()); + paidMemberUserDO.setPayType(payType); //更新会员订单 paidMemberUserService.update(paidMemberUserDO); - //设置个人信息的会员状态,0:未开通,1试用,2有效期,3永久 - if(notifyReqDTO.getCardName().equals("永久")){ - memberUserDO.setActivate(3); - }else { - memberUserDO.setActivate(2); - } //更新用户会员状态 - memberUserService.updateUserDo(memberUserDO); + memberUserService.updateActivate(paidMemberUserDO.getPayMemberType()); // return success(PayMemberOrderConvert.INSTANCE.convert(paidMemberUserDO.getId(),payOrderId // ,paidMemberUserDO.getCardExpirationTime(),memberUserDO.getActivate())); return success(true); -- 2.45.2