Merge pull request '会员支付优化' (#91) from khy1 into master
All checks were successful
continuous-integration/drone/push Build is passing

Reviewed-on: #91
This commit is contained in:
root 2024-10-29 11:53:15 +08:00
commit f2297720fc
13 changed files with 157 additions and 266 deletions

View File

@ -1,195 +0,0 @@
<template>
<Dialog :title="dialogTitle" v-model="dialogVisible">
<el-form
ref="formRef"
:model="formData"
:rules="formRules"
label-width="100px"
v-loading="formLoading"
>
<el-form-item label="手机号" prop="mobile">
<el-input v-model="formData.mobile" placeholder="请输入手机号" />
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="formData.password" placeholder="请输入密码" />
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="注册 IP" prop="registerIp">
<el-input v-model="formData.registerIp" placeholder="请输入注册 IP" />
</el-form-item>
<el-form-item label="注册终端" prop="registerTerminal">
<el-input v-model="formData.registerTerminal" placeholder="请输入注册终端" />
</el-form-item>
<el-form-item label="最后登录IP" prop="loginIp">
<el-input v-model="formData.loginIp" placeholder="请输入最后登录IP" />
</el-form-item>
<el-form-item label="最后登录时间" prop="loginDate">
<el-date-picker
v-model="formData.loginDate"
type="date"
value-format="x"
placeholder="选择最后登录时间"
/>
</el-form-item>
<el-form-item label="用户昵称" prop="nickname">
<el-input v-model="formData.nickname" placeholder="请输入用户昵称" />
</el-form-item>
<el-form-item label="头像" prop="avatar">
<el-input v-model="formData.avatar" placeholder="请输入头像" />
</el-form-item>
<el-form-item label="真实名字" prop="name">
<el-input v-model="formData.name" placeholder="请输入真实名字" />
</el-form-item>
<el-form-item label="性别" prop="sex">
<el-radio-group v-model="formData.sex">
<el-radio label="1">请选择字典生成</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="出生日期" prop="birthday">
<el-date-picker
v-model="formData.birthday"
type="date"
value-format="x"
placeholder="选择出生日期"
/>
</el-form-item>
<el-form-item label="所在地" prop="areaId">
<el-input v-model="formData.areaId" placeholder="请输入所在地" />
</el-form-item>
<el-form-item label="用户备注" prop="mark">
<el-input v-model="formData.mark" placeholder="请输入用户备注" />
</el-form-item>
<el-form-item label="积分" prop="point">
<el-input v-model="formData.point" placeholder="请输入积分" />
</el-form-item>
<el-form-item label="用户标签编号列表,以逗号分隔" prop="tagIds">
<el-input v-model="formData.tagIds" placeholder="请输入用户标签编号列表,以逗号分隔" />
</el-form-item>
<el-form-item label="等级编号" prop="levelId">
<el-input v-model="formData.levelId" placeholder="请输入等级编号" />
</el-form-item>
<el-form-item label="经验" prop="experience">
<el-input v-model="formData.experience" placeholder="请输入经验" />
</el-form-item>
<el-form-item label="用户分组编号" prop="groupId">
<el-input v-model="formData.groupId" placeholder="请输入用户分组编号" />
</el-form-item>
</el-form>
<template #footer>
<el-button @click="submitForm" type="primary" :disabled="formLoading"> </el-button>
<el-button @click="dialogVisible = false"> </el-button>
</template>
</Dialog>
</template>
<script setup lang="ts">
import { PaidMemberUserApi, PaidMemberUserVO } from '@/api/member/memberuser'
/** 付费会员 表单 */
defineOptions({ name: 'PaidMemberUserForm' })
const { t } = useI18n() //
const message = useMessage() //
const dialogVisible = ref(false) //
const dialogTitle = ref('') //
const formLoading = ref(false) // 12
const formType = ref('') // create - update -
const formData = ref({
id: undefined,
mobile: undefined,
password: undefined,
status: undefined,
registerIp: undefined,
registerTerminal: undefined,
loginIp: undefined,
loginDate: undefined,
nickname: undefined,
avatar: undefined,
name: undefined,
sex: undefined,
birthday: undefined,
areaId: undefined,
mark: undefined,
point: undefined,
tagIds: undefined,
levelId: undefined,
experience: undefined,
groupId: undefined,
})
const formRules = reactive({
})
const formRef = ref() // Ref
/** 打开弹窗 */
const open = async (type: string, id?: number) => {
dialogVisible.value = true
dialogTitle.value = t('action.' + type)
formType.value = type
resetForm()
//
if (id) {
formLoading.value = true
try {
formData.value = await PaidMemberUserApi.getPaidMemberUser(id)
} finally {
formLoading.value = false
}
}
}
defineExpose({ open }) // open
/** 提交表单 */
const emit = defineEmits(['success']) // success
const submitForm = async () => {
//
await formRef.value.validate()
//
formLoading.value = true
try {
const data = formData.value as unknown as PaidMemberUserVO
if (formType.value === 'create') {
await PaidMemberUserApi.createPaidMemberUser(data)
message.success(t('common.createSuccess'))
} else {
await PaidMemberUserApi.updatePaidMemberUser(data)
message.success(t('common.updateSuccess'))
}
dialogVisible.value = false
//
emit('success')
} finally {
formLoading.value = false
}
}
/** 重置表单 */
const resetForm = () => {
formData.value = {
id: undefined,
mobile: undefined,
password: undefined,
status: undefined,
registerIp: undefined,
registerTerminal: undefined,
loginIp: undefined,
loginDate: undefined,
nickname: undefined,
avatar: undefined,
name: undefined,
sex: undefined,
birthday: undefined,
areaId: undefined,
mark: undefined,
point: undefined,
tagIds: undefined,
levelId: undefined,
experience: undefined,
groupId: undefined,
}
formRef.value?.resetFields()
}
</script>

View File

@ -76,13 +76,13 @@
</template>
</el-table-column>
<el-table-column label="有效期限(天)" align="center" prop="deadlineDay" />
<el-table-column label="支付金额()" align="center" prop="price" />
<el-table-column label="支付金额()" align="center" prop="price" :formatter="formPriceInYuan"/>
<el-table-column label="支付方式" align="center" prop="payType" />
<el-table-column
label="购买时间"
align="center"
prop="payTime"
:formatter="dateFormatter"
:formatter="dateFormatter2"
width="180px"
/>
</el-table>
@ -95,17 +95,15 @@
/>
</ContentWrap>
<!-- 表单弹窗添加/修改 -->
<PaidMemberUserForm ref="formRef" @success="getList" />
</template>
<script setup lang="ts">
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import { dateFormatter } from '@/utils/formatTime'
import { dateFormatter2 } from '@/utils/formatTime'
import download from '@/utils/download'
import { PaidMemberUserApi, PaidMemberUserVO } from '@/api/member/memberuser'
import * as CardVoApid from '@/api/member/type'
import PaidMemberUserForm from './PaidMemberUserForm.vue'
import { column } from 'element-plus/es/components/table-v2/src/common'
/** 付费会员 列表 */
defineOptions({ name: 'PaidMemberUser' })
@ -167,6 +165,10 @@ const getList = async () => {
}
}
/** 将金额单位分转为元 */
const formPriceInYuan = (row,column,cellValue) =>{
return (cellValue / 100).toFixed(2)
}
/** 搜索按钮操作 */
const handleQuery = () => {

View File

@ -72,6 +72,7 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
.eq(TradeOrderDO::getUserId, userId)
.eqIfPresent(TradeOrderDO::getStatus, reqVO.getStatus())
.eqIfPresent(TradeOrderDO::getCommentStatus, reqVO.getCommentStatus())
.notLike(TradeOrderDO::getNo,"M")
.orderByDesc(TradeOrderDO::getId)); // TODO 芋艿未来不同的 status不同的排序
}
@ -79,7 +80,8 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
return selectCount(new LambdaQueryWrapperX<TradeOrderDO>()
.eq(TradeOrderDO::getUserId, userId)
.eqIfPresent(TradeOrderDO::getStatus, status)
.eqIfPresent(TradeOrderDO::getCommentStatus, commentStatus));
.eqIfPresent(TradeOrderDO::getCommentStatus, commentStatus)
.notLike(TradeOrderDO::getNo,"M"));
}
default TradeOrderDO selectOrderByIdAndUserId(Long orderId, Long loginUserId) {

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 付费会员分页 Request VO")
@ -85,6 +86,7 @@ public class PaidMemberUserPageReqVO extends PageParam {
private LocalDateTime[] payTime;
@Schema(description = "到期时间", example = "2024-11-22 09:30:05")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDateTime cardExpirationTime;

View File

@ -102,7 +102,7 @@ public class PaidMemberUserRespVO {
@Schema(description = "支付时间", example = "2024-11-22 09:30:05")
private LocalDateTime payTime;
@Schema(description = "到期时间", example = "2024-11-22 09:30:05")
@Schema(description = "到期时间", example = "2024-11-22")
private LocalDateTime cardExpirationTime;

View File

@ -7,6 +7,7 @@ import javax.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 会员新增/修改 Request VO")
@ -82,7 +83,8 @@ public class PaidMemberUserSaveReqVO {
@Schema(description = "支付时间", example = "2024-11-22 09:30:05")
private LocalDateTime payTime;
@Schema(description = "到期时间", example = "2024-11-22 09:30:05")
@Schema(description = "到期时间", example = "2024-11-22")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDateTime cardExpirationTime;

View File

@ -8,7 +8,7 @@ import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
@Schema(description = "用户 APP - 用户个人信息 Response VO")
@Data
@ -50,7 +50,7 @@ public class AppMemberUserInfoRespVO {
private String cardName;
@Schema(description = "过期时间", requiredMode = Schema.RequiredMode.REQUIRED)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDateTime cardExpirationTime;
@Schema(description = "用户 App - 会员等级")

View File

@ -331,7 +331,7 @@ public class MemberUserServiceImpl implements MemberUserService {
@Override
public void updateActivate(String cardName,Long userId) {
MemberUserDO memberUserDO = getUser(userId);
//设置个人信息的会员状态0未开通1试用2有效期3永久
//设置个人信息的会员状态0未开通1试用2有效期3永久4过期
if(cardName.equals("永久")){
memberUserDO.setActivate(3);
}else {

View File

@ -58,7 +58,12 @@ public interface PaidMemberUserService {
int getPriceByTtype(Integer activate, String cardName);
LocalDateTime getDeadLineDay(String cardName);
/*
* 判断当前是否会员
* 为会员则过期时间需要续时长
* 不为会员则直接加入过期时间
* */
LocalDateTime getDeadLineDay(String cardName,Long userId);
PaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO);
@ -93,4 +98,8 @@ public interface PaidMemberUserService {
public Long buildTradeOrder(PaidMemberUserDO updateReqVO);
void updateTradeOrderId(Long merchantOrderId, Long payOrderId);
PaidMemberUserSaveReqVO createPaidMemberUserSaveReqVO(MemberUserDO memberUserDO, String cardName);
// int expireMemberUser();
}

View File

@ -7,8 +7,10 @@ import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.api.address.MemberAddressApi;
import cn.iocoder.yudao.module.member.api.address.dto.MemberAddressRespDTO;
import cn.iocoder.yudao.module.member.dal.dataobject.membercardtype.PaidMemberCardTypeDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper;
import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum;
@ -23,7 +25,10 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.*;
@ -35,7 +40,10 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.dal.mysql.user.PaidMemberUserMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.addTime;
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.member.enums.ErrorCodeConstants.*;
@ -61,7 +69,7 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
private TradeOrderMapper tradeOrderMapper;
@Resource
private MemberAddressApi addressApi;
private MemberUserService memberUserService;
@Override
@ -110,20 +118,6 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
return paidMemberUserMapper.selectById(id);
}
// @Override
// public PaidMemberUserDO isValidPaidMember(Integer activate, LocalDateTime cardExpirationTime) {
// if (activate == 0){
// throw exception(PAID_MEMBER_USER_NOT_OPEN);
// } else if (activate != 0 && cardExpirationTime.isBefore(LocalDateTime.now())) {
// throw exception(PAID_MEMBER_USER_PASSED);
// }else {
// //当前用户为会员
// List<PaidMemberUserDO> list = paidMemberUserMapper.selectList(PaidMemberUserDO::getUid,getLoginUserId(),
// )
// }
// return null;
// }
@Override
public int getPriceByTtype(Integer activate, String cardName) {
int price = 0;
@ -140,22 +134,47 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
//获取会员类型对应的过期时间
@Override
public LocalDateTime getDeadLineDay(String cardName) {
public LocalDateTime getDeadLineDay(String cardName,Long userId) {
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);
}
PaidMemberCardTypeDO paidMemberCardTypeDO = memberCardTypeService.selectByName(cardName);
MemberUserDO memberUserDO = memberUserService.getUser(userId);
//判断是否为会员是否需要续期
if(memberUserDO.getActivate() !=1
&& memberUserDO.getActivate() != 2
&& memberUserDO.getActivate() != 3){
deadlineDay = getDay(cardName,now);
}
else {
List<PaidMemberUserDO> list = paidMemberUserMapper.selectList(new LambdaQueryWrapperX<PaidMemberUserDO>()
.eqIfPresent(PaidMemberUserDO::getUid, userId)
.isNotNull(PaidMemberUserDO::getCardExpirationTime)
.orderByDesc(PaidMemberUserDO::getId));
now = CollUtil.getFirst(list).getCardExpirationTime();
deadlineDay = getDay(cardName,now);
}
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(FORMAT_YEAR_MONTH_DAY);
String dayStr = deadlineDay.format(formatter);
LocalDate expireDate = LocalDate.parse(dayStr,formatter);
deadlineDay = expireDate.atStartOfDay();
return deadlineDay;
}
public LocalDateTime getDay(String cardName,LocalDateTime dateTime) {
LocalDateTime deadlineDay;
PaidMemberCardTypeDO paidMemberCardTypeDO = memberCardTypeService.selectByName(cardName);
if (cardName.equals("试用")){
deadlineDay = dateTime.plus(Long.parseLong(paidMemberCardTypeDO.getVid()), ChronoUnit.DAYS);
} else if (cardName.equals("月卡")) {
deadlineDay = dateTime.plus(1,ChronoUnit.MONTHS);
} else if (cardName.equals("季卡")) {
deadlineDay = dateTime.plus(3,ChronoUnit.MONTHS);
} else if (cardName.equals("年卡")) {
deadlineDay = dateTime.plus(1,ChronoUnit.YEARS);
} else {
//永久设置为一个非常远的的日期
deadlineDay = LocalDateTime.of(9999,12,31,23,59,59);
}
return deadlineDay;
}
@ -227,10 +246,6 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
orderDO.setUserIp(getClientIP()).setTerminal(getTerminal());
orderDO.setDeliveryType(DeliveryTypeEnum.EXPRESS.getType());
orderDO.setPayPrice(updateReqVO.getPrice());
//获取用户地址
// MemberAddressRespDTO address = addressApi.getDefaultAddress(updateReqVO.getUid());
// orderDO.setReceiverName(address.getName()).setReceiverMobile(address.getMobile())
// .setReceiverAreaId(address.getAreaId()).setReceiverDetailAddress(address.getDetailAddress());
//插入新增交易订单
tradeOrderMapper.insert(orderDO);
//查询最新的交易订单数据
@ -252,5 +267,26 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
tradeOrderMapper.updateById(orderDO);
}
@Override
public PaidMemberUserSaveReqVO createPaidMemberUserSaveReqVO(MemberUserDO memberUserDO, String cardName) {
PaidMemberUserSaveReqVO paidMemberUserSaveReqVO = new PaidMemberUserSaveReqVO();
//将用户信息复制到会员记录里
org.springframework.beans.BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO);
paidMemberUserSaveReqVO.setPayMemberType(cardName);
paidMemberUserSaveReqVO.setId(null);
paidMemberUserSaveReqVO.setUid(memberUserDO.getId());
//获取期限天数
String deadlineDay = memberCardTypeService.selectByName(cardName).getVid();
paidMemberUserSaveReqVO.setDeadlineDay(deadlineDay);
return paidMemberUserSaveReqVO;
}
// @Override
// public int expireMemberUser() {
// List<PaidMemberUserDO> list = paidMemberUserMapper.selectList
// (new LambdaQueryWrapperX<PaidMemberUserDO>().le(PaidMemberUserDO::getCardExpirationTime,LocalDateTime.now())
// .)
// return 0;
// }
}

View File

@ -91,27 +91,21 @@ public class AppPaidMembeController {
throw exception(MEMBER_USER_NOT_EXISTS);
}
PaidMemberUserDO paidMemberUserDO = new PaidMemberUserDO();
PaidMemberUserSaveReqVO paidMemberUserSaveReqVO = new PaidMemberUserSaveReqVO();
//初始化支付金额,单位为分
int price = 0;
Long payOrderId = null;
Long merchantOrderId = null;
//初始化付费会员记录
PaidMemberUserSaveReqVO paidMemberUserSaveReqVO = paidMemberUserService.
createPaidMemberUserSaveReqVO(memberUserDO,reqVO.getCardName());
if(reqVO.getCardName().equals("试用")){
BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO);
paidMemberUserSaveReqVO.setPayMemberType(reqVO.getCardName());
paidMemberUserSaveReqVO.setId(null);
paidMemberUserSaveReqVO.setUid(memberUserDO.getId());
paidMemberUserSaveReqVO.setPrice(price);
paidMemberUserSaveReqVO.setPaid(true);
//获取期限天数
String deadlineDay = memberCardService.selectByName(reqVO.getCardName()).getVid();
paidMemberUserSaveReqVO.setDeadlineDay(deadlineDay);
paidMemberUserSaveReqVO.setPayType("免费领取");
//获取支付时间
LocalDateTime payTime = LocalDateTime.now();
paidMemberUserSaveReqVO.setPayTime(payTime);
//获取试用类型的过期时间
LocalDateTime cardExpirationTime = paidMemberUserService.getDeadLineDay(reqVO.getCardName());
LocalDateTime cardExpirationTime = paidMemberUserService.getDeadLineDay(reqVO.getCardName(),getLoginUserId());
paidMemberUserSaveReqVO.setCardExpirationTime(cardExpirationTime);
//设置会员订单号
paidMemberUserSaveReqVO.setOrderNo(noRedisDAO.generate(PAID_MEMBER_NO_PREFIX));
@ -124,15 +118,8 @@ public class AppPaidMembeController {
memberUserService.updateUserDo(memberUserDO);
}
else {
BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO);
paidMemberUserSaveReqVO.setId(null);
paidMemberUserSaveReqVO.setPayMemberType(reqVO.getCardName());
paidMemberUserSaveReqVO.setUid(memberUserDO.getId());
//获取实际支付金额判断是否为会员有无优惠价
price = paidMemberUserService.getPriceByTtype(memberUserDO.getActivate(),reqVO.getCardName());
//获取期限天数
String deadlineDay = memberCardService.selectByName(reqVO.getCardName()).getVid();
paidMemberUserSaveReqVO.setDeadlineDay(deadlineDay);
paidMemberUserSaveReqVO.setPrice(price);
//设置会员订单号
paidMemberUserSaveReqVO.setOrderNo(noRedisDAO.generate(PAID_MEMBER_NO_PREFIX));
@ -141,7 +128,7 @@ public class AppPaidMembeController {
//查询新增的会员订单记录
paidMemberUserDO = paidMemberUserService.getMemberUser(id);
//创建交易订单号
merchantOrderId = paidMemberUserService.buildTradeOrder(paidMemberUserDO);
Long merchantOrderId = paidMemberUserService.buildTradeOrder(paidMemberUserDO);
paidMemberUserDO.setMerchantOrderId(String.valueOf(merchantOrderId));
//创建支付订单号
payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO()
@ -163,22 +150,21 @@ public class AppPaidMembeController {
@PostMapping("/update")
@Operation(summary = "余额支付")
public CommonResult<Boolean> updatePaidMemberUser(@Valid @RequestBody AppPaidMemeberOrderReqDto notifyReqDTO){
//获取当前登录用户信息,并判断用户是否为会员
MemberUserDO memberUserDO = memberUserService.getUser(getLoginUserId());
//获取订单记录
PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getMemberUser(notifyReqDTO.getId());
// 获取当前用户钱包信息
PayWalletDO walletDO = payWalletService.getOrCreateWallet(WebFrameworkUtils.getLoginUserId(),getLoginUserType());
// 扣减钱包余额
payWalletService.reduceWalletBalance
(walletDO.getId(),notifyReqDTO.getId(),PAYMENT,paidMemberUserDO.getPrice());
payWalletService.reduceWalletBalanceByCardType
(walletDO.getId(),notifyReqDTO.getId(),PAYMENT,paidMemberUserDO.getPrice(),
paidMemberUserDO.getPayMemberType());
//获取支付时间
LocalDateTime payTime = LocalDateTime.now();
paidMemberUserDO.setPayTime(payTime);
//更新会员订单支付状态为已支付
paidMemberUserDO.setPaid(true);
//获取试用类型的过期时间
LocalDateTime cardExpirationTime = paidMemberUserService.getDeadLineDay(notifyReqDTO.getCardName());
LocalDateTime cardExpirationTime = paidMemberUserService.getDeadLineDay(notifyReqDTO.getCardName(),getLoginUserId());
paidMemberUserDO.setCardExpirationTime(cardExpirationTime);
paidMemberUserDO.setPayChannel(notifyReqDTO.getPayChannel());
String payType = paidMemberUserService.currentPayType(notifyReqDTO.getPayChannel());
@ -187,8 +173,6 @@ public class AppPaidMembeController {
paidMemberUserService.update(paidMemberUserDO);
//更新用户会员状态
memberUserService.updateActivate(paidMemberUserDO.getPayMemberType(),getLoginUserId());
// return success(PayMemberOrderConvert.INSTANCE.convert(paidMemberUserDO.getId(),payOrderId
// ,paidMemberUserDO.getCardExpirationTime(),memberUserDO.getActivate()));
return success(true);
}

View File

@ -70,6 +70,20 @@ public interface PayWalletService {
PayWalletTransactionDO reduceWalletBalance(Long walletId, Long bizId,
PayWalletBizTypeEnum bizType, Integer price);
/**
* 根据会员购卡类型
* 扣减钱包余额
*
* @param walletId 钱包 id
* @param bizId 业务关联 id
* @param bizType 业务关联分类
* @param price 扣减金额
* @param payMemberType 会员类型
* @return 钱包流水
*/
PayWalletTransactionDO reduceWalletBalanceByCardType(Long walletId, Long bizId,
PayWalletBizTypeEnum bizType, Integer price,String payMemberType);
/**
* 增加钱包余额
*

View File

@ -169,6 +169,41 @@ public class PayWalletServiceImpl implements PayWalletService {
return walletTransactionService.createWalletTransaction(bo);
}
@Override
public PayWalletTransactionDO reduceWalletBalanceByCardType(Long walletId, Long bizId, PayWalletBizTypeEnum bizType, Integer price, String payMemberType) {
// 1. 获取钱包
PayWalletDO payWallet = getWallet(walletId);
if (payWallet == null) {
log.error("[reduceWalletBalance],用户钱包({})不存在.", walletId);
throw exception(WALLET_NOT_FOUND);
}
// 2.1 扣除余额
int updateCounts;
switch (bizType) {
case PAYMENT: {
updateCounts = walletMapper.updateWhenConsumption(payWallet.getId(), price);
break;
}
case RECHARGE_REFUND: {
updateCounts = walletMapper.updateWhenRechargeRefund(payWallet.getId(), price);
break;
}
default: {
// TODO 其它类型待实现
throw new UnsupportedOperationException("待实现");
}
}
if (updateCounts == 0) {
throw exception(WALLET_BALANCE_NOT_ENOUGH);
}
// 2.2 生成钱包流水
Integer afterBalance = payWallet.getBalance() - price;
WalletTransactionCreateReqBO bo = new WalletTransactionCreateReqBO().setWalletId(payWallet.getId())
.setPrice(-price).setBalance(afterBalance).setBizId(String.valueOf(bizId))
.setBizType(bizType.getType()).setTitle(bizType.getDescription()+payMemberType+"类型会员");
return walletTransactionService.createWalletTransaction(bo);
}
@Override
@Transactional(rollbackFor = Exception.class)
@SneakyThrows