Compare commits

...

11 Commits

Author SHA1 Message Date
81be16bd6c 后台-客服跳转 2024-10-24 10:50:29 +08:00
314cc090ee Merge pull request '会员余额支付' (#68) from khy1 into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #68
2024-10-23 21:35:12 +08:00
khy
41bcb2c9ea 会员余额支付 2024-10-23 21:34:18 +08:00
c613b2e3c1 Merge pull request '会员回显' (#67) from khy1 into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #67
2024-10-23 21:12:23 +08:00
khy
a35f333ec2 会员回显 2024-10-23 21:10:42 +08:00
dbf38c1aa4 Merge pull request '支付订单状态变更' (#66) from khy1 into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #66
2024-10-23 18:16:17 +08:00
khy
a4cc10ccb9 支付订单状态变更 2024-10-23 18:11:40 +08:00
9fcf547417 Merge pull request '创建订单' (#65) from khy1 into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #65
2024-10-23 14:09:53 +08:00
28ce473568 Merge pull request '客服-最近浏览-字段缺失补充' (#64) from cxw into master
Some checks failed
continuous-integration/drone/push Build is failing
Reviewed-on: #64
2024-10-23 14:09:44 +08:00
khy
e0bac9998e 创建订单 2024-10-23 14:07:18 +08:00
505aa43c36 Merge pull request '支付方式接口调整' (#63) from cxw into master
All checks were successful
continuous-integration/drone/push Build is passing
Reviewed-on: #63
2024-10-23 11:01:58 +08:00
24 changed files with 475 additions and 308 deletions

View File

@ -26,7 +26,7 @@
import { KeFuConversationList, KeFuMessageList, MemberBrowsingHistory } from './components' import { KeFuConversationList, KeFuMessageList, MemberBrowsingHistory } from './components'
import { WebSocketMessageTypeConstants } from './components/tools/constants' import { WebSocketMessageTypeConstants } from './components/tools/constants'
import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation' import { KeFuConversationRespVO } from '@/api/mall/promotion/kefu/conversation'
import { getRefreshToken } from '@/utils/auth' import { getRefreshToken, getAccessToken } from '@/utils/auth'
import { useWebSocket } from '@vueuse/core' import { useWebSocket } from '@vueuse/core'
defineOptions({ name: 'KeFu' }) defineOptions({ name: 'KeFu' })

View File

@ -166,7 +166,7 @@
:formatter="dateFormatter" :formatter="dateFormatter"
width="180px" width="180px"
/> />
<el-table-column label="操作" align="center"> <el-table-column fixed="right" label="操作" align="center" min-width="200">
<template #default="scope"> <template #default="scope">
<el-button <el-button
link link
@ -184,6 +184,14 @@
> >
删除 删除
</el-button> </el-button>
<el-button
v-if="scope.row.status == 1"
link
type="success"
@click="handleEnterConsole(scope.row.id)"
>
进入工作台
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -275,7 +283,11 @@ const handleDelete = async (id: number) => {
await getList() await getList()
} catch {} } catch {}
} }
/** 客服进入工作台 */
const handleEnterConsole = async (id: number) => {
window.open(`${window.location.origin}/kefu/kefu`, '_blank');
}
/** 导出按钮操作 */ /** 导出按钮操作 */
const handleExport = async () => { const handleExport = async () => {
try { try {

View File

@ -68,4 +68,9 @@ public interface ErrorCodeConstants {
ErrorCode CARD_NOT_EXISTS = new ErrorCode(1_004_020_000, "会员卡类型不存在"); ErrorCode CARD_NOT_EXISTS = new ErrorCode(1_004_020_000, "会员卡类型不存在");
ErrorCode MEMBER_USER_NOT_EXISTS = new ErrorCode(1_004_021_000, "会员不存在"); ErrorCode MEMBER_USER_NOT_EXISTS = new ErrorCode(1_004_021_000, "会员不存在");
ErrorCode PAID_MEMBER_ORDER_NOT_EXISTS = new ErrorCode(1_004_022_000, "付费会员订单不存在"); ErrorCode PAID_MEMBER_ORDER_NOT_EXISTS = new ErrorCode(1_004_022_000, "付费会员订单不存在");
ErrorCode PAID_MEMBER_USER_ORDER_NO_NOT_EXISTS = new ErrorCode(1_004_023_000, "生成会员订单号失败,请重新提交");
ErrorCode PAID_MEMBER_USER_NOT_OPEN = new ErrorCode(1_004_021_000, "会员未开通");
ErrorCode PAID_MEMBER_USER_PASSED = new ErrorCode(1_004_021_000, "会员已过期");
} }

View File

@ -34,20 +34,20 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
public class PaidMemberCardTypeController { public class PaidMemberCardTypeController {
@Resource @Resource
private PaidMemberCardTypeService cardService; private PaidMemberCardTypeService cardTypeService;
@PostMapping("/create") @PostMapping("/create")
@Operation(summary = "创建会员卡类型") @Operation(summary = "创建会员卡类型")
@PreAuthorize("@ss.hasPermission('member:paid-member-card-type:create')") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:create')")
public CommonResult<Long> createcard(@Valid @RequestBody PaidMemberCardTypeSaveReqVO createReqVO) { public CommonResult<Long> createcard(@Valid @RequestBody PaidMemberCardTypeSaveReqVO createReqVO) {
return success(cardService.createcard(createReqVO)); return success(cardTypeService.createcard(createReqVO));
} }
@PutMapping("/update") @PutMapping("/update")
@Operation(summary = "更新会员卡类型") @Operation(summary = "更新会员卡类型")
@PreAuthorize("@ss.hasPermission('member:paid-member-card-type:update')") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:update')")
public CommonResult<Boolean> updatecard(@Valid @RequestBody PaidMemberCardTypeSaveReqVO updateReqVO) { public CommonResult<Boolean> updatecard(@Valid @RequestBody PaidMemberCardTypeSaveReqVO updateReqVO) {
cardService.updatecard(updateReqVO); cardTypeService.updatecard(updateReqVO);
return success(true); return success(true);
} }
@ -58,7 +58,7 @@ public class PaidMemberCardTypeController {
@PreAuthorize("@ss.hasPermission('member:paid-member-card-type:delete')") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:delete')")
public CommonResult<Boolean> deletecard(@RequestParam("id") long memberCardId) { public CommonResult<Boolean> deletecard(@RequestParam("id") long memberCardId) {
System.out.println(memberCardId); System.out.println(memberCardId);
cardService.deletecard(memberCardId); cardTypeService.deletecard(memberCardId);
return success(true); return success(true);
} }
@ -67,7 +67,7 @@ public class PaidMemberCardTypeController {
@Parameter(name = "id", description = "编号", required = true, example = "1024") @Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('member:paid-member-card-type:query')") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:query')")
public CommonResult<PaidMemberCardTypeRespVO> getcard(@RequestParam("id") Long id) { public CommonResult<PaidMemberCardTypeRespVO> getcard(@RequestParam("id") Long id) {
PaidMemberCardTypeDO card = cardService.getcard(id); PaidMemberCardTypeDO card = cardTypeService.getcard(id);
return success(BeanUtils.toBean(card, PaidMemberCardTypeRespVO.class)); return success(BeanUtils.toBean(card, PaidMemberCardTypeRespVO.class));
} }
@ -75,7 +75,7 @@ public class PaidMemberCardTypeController {
@Operation(summary = "获得会员卡类型分页") @Operation(summary = "获得会员卡类型分页")
@PreAuthorize("@ss.hasPermission('member:paid-member-card-type:query')") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:query')")
public CommonResult<PageResult<PaidMemberCardTypeRespVO>> getcardPage(@Valid PaidMemberCardTypePageReqVO pageReqVO) { public CommonResult<PageResult<PaidMemberCardTypeRespVO>> getcardPage(@Valid PaidMemberCardTypePageReqVO pageReqVO) {
PageResult<PaidMemberCardTypeDO> pageResult = cardService.getcardPage(pageReqVO); PageResult<PaidMemberCardTypeDO> pageResult = cardTypeService.getcardPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, PaidMemberCardTypeRespVO.class)); return success(BeanUtils.toBean(pageResult, PaidMemberCardTypeRespVO.class));
} }
@ -86,7 +86,7 @@ public class PaidMemberCardTypeController {
public void exportcardExcel(@Valid PaidMemberCardTypePageReqVO pageReqVO, public void exportcardExcel(@Valid PaidMemberCardTypePageReqVO pageReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<PaidMemberCardTypeDO> list = cardService.getcardPage(pageReqVO).getList(); List<PaidMemberCardTypeDO> list = cardTypeService.getcardPage(pageReqVO).getList();
// 导出 Excel // 导出 Excel
ExcelUtils.write(response, "会员卡类型.xls", "数据", PaidMemberCardTypeRespVO.class, ExcelUtils.write(response, "会员卡类型.xls", "数据", PaidMemberCardTypeRespVO.class,
BeanUtils.toBean(list, PaidMemberCardTypeRespVO.class)); BeanUtils.toBean(list, PaidMemberCardTypeRespVO.class));

View File

@ -16,6 +16,9 @@ public class PaidMemberUserSaveReqVO {
@Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12209") @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12209")
private Long id; private Long id;
@Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12209")
private Long uid;
@Schema(description = "手机号") @Schema(description = "手机号")
private String mobile; private String mobile;
@ -95,4 +98,12 @@ public class PaidMemberUserSaveReqVO {
@Schema(description = "支付渠道", example = "public-公众号,mini-小程序h5-网页支付,wechatIos-微信IoswechatAndroid-微信Android,alipay-支付包alipayApp-支付宝App,give-平台赠送,yue-余额支付") @Schema(description = "支付渠道", example = "public-公众号,mini-小程序h5-网页支付,wechatIos-微信IoswechatAndroid-微信Android,alipay-支付包alipayApp-支付宝App,give-平台赠送,yue-余额支付")
private String payChannel; private String payChannel;
@Schema(description = "订单号", requiredMode = Schema.RequiredMode.REQUIRED)
private String orderNo;
@Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED)
private Long payOrderId;
@Schema(description = "会员类型", requiredMode = Schema.RequiredMode.REQUIRED)
private String payMemberType;
} }

View File

@ -34,15 +34,11 @@ public class AppMemberCardTypeController {
@GetMapping("/list") @GetMapping("/list")
@Operation(summary = "获得会员卡类型列表") @Operation(summary = "获得会员卡类型列表")
public CommonResult<List<AppMemberCardTypeRespVO>> list(@RequestParam(value = "name",required = false) String name) { public CommonResult<List<AppMemberCardTypeRespVO>> list() {
/** 查询状态为启用的会员卡类型列表 */ /** 查询状态为启用的会员卡类型列表 */
MemberUserDO memberUserDO = userService.getUser(getLoginUserId()); MemberUserDO memberUserDO = userService.getUser(getLoginUserId());
/** 根据用户查询是否有试用会员的类型列表 */ /** 根据用户查询是否有试用会员的类型列表 */
List<PaidMemberCardTypeDO> list = cardService.getCardTypeList(memberUserDO.getActivate()); List<PaidMemberCardTypeDO> list = cardService.getCardTypeList(memberUserDO.getActivate());
if(name != null){
//根据用户查询是否有有效期会员的类型列表
list = cardService.getCardTypeList2(memberUserDO.getActivate(),name);
}
return success(MemberCardTypeConvert.INSTANCE.convertList(list)); return success(MemberCardTypeConvert.INSTANCE.convertList(list));
} }

View File

@ -21,6 +21,7 @@ import cn.iocoder.yudao.module.member.dal.dataobject.level.MemberLevelDO;
import cn.iocoder.yudao.module.member.dal.dataobject.memberCode.MemberCodeDo; import cn.iocoder.yudao.module.member.dal.dataobject.memberCode.MemberCodeDo;
import cn.iocoder.yudao.module.member.dal.dataobject.transferlog.TransferLogDO; import cn.iocoder.yudao.module.member.dal.dataobject.transferlog.TransferLogDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO;
import cn.iocoder.yudao.module.member.dal.mysql.memberCode.MemberCodeMapper; import cn.iocoder.yudao.module.member.dal.mysql.memberCode.MemberCodeMapper;
import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum;
import cn.iocoder.yudao.module.member.service.afterverification.AfterVerificationService; import cn.iocoder.yudao.module.member.service.afterverification.AfterVerificationService;
@ -32,6 +33,7 @@ import cn.iocoder.yudao.module.member.service.point.MemberPointRecordService;
import cn.iocoder.yudao.module.member.service.transfer.TransferService; import cn.iocoder.yudao.module.member.service.transfer.TransferService;
import cn.iocoder.yudao.module.member.service.transferlog.TransferLogService; import cn.iocoder.yudao.module.member.service.transferlog.TransferLogService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService; import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.service.user.PaidMemberUserService;
import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO;
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
@ -78,13 +80,19 @@ public class AppMemberUserController {
private MemberPointRecordService pointRecordService; private MemberPointRecordService pointRecordService;
@Resource @Resource
private MemberCodeMapper memberCodeMapper; private MemberCodeMapper memberCodeMapper;
@Resource
private PaidMemberUserService paidMemberUserService;
@GetMapping("/get") @GetMapping("/get")
@Operation(summary = "获得基本信息") @Operation(summary = "获得基本信息")
@PreAuthenticated @PreAuthenticated
public CommonResult<AppMemberUserInfoRespVO> getUserInfo() { public CommonResult<AppMemberUserInfoRespVO> getUserInfo() {
MemberUserDO user = userService.getUser(getLoginUserId()); MemberUserDO user = userService.getUser(getLoginUserId());
MemberLevelDO level = levelService.getLevel(user.getLevelId()); MemberLevelDO level = levelService.getLevel(user.getLevelId());
return success(MemberUserConvert.INSTANCE.convert(user, level)); PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getPaidMemberUserByUid(getLoginUserId());
if (paidMemberUserDO == null) {
return success(MemberUserConvert.INSTANCE.convert(user, level,null,null));
}
return success(MemberUserConvert.INSTANCE.convert(user, level,paidMemberUserDO.getPayMemberType(),paidMemberUserDO.getCardExpirationTime()));
} }
@PutMapping("/update") @PutMapping("/update")

View File

@ -41,6 +41,12 @@ public class AppMemberUserInfoRespVO {
@Schema(description = "是否成为推广员", requiredMode = Schema.RequiredMode.REQUIRED, example = "true") @Schema(description = "是否成为推广员", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
private Boolean brokerageEnabled; private Boolean brokerageEnabled;
@Schema(description = "会员名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "季卡")
private String cardName;
@Schema(description = "会员名称", requiredMode = Schema.RequiredMode.REQUIRED)
private String cardExpirationTime;
@Schema(description = "用户 App - 会员等级") @Schema(description = "用户 App - 会员等级")
@Data @Data
public static class Level { public static class Level {

View File

@ -15,6 +15,7 @@ import org.mapstruct.Mapping;
import org.mapstruct.Mappings; import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -34,7 +35,7 @@ public interface MemberUserConvert {
@Mapping(source = "bean.id", target = "id"), @Mapping(source = "bean.id", target = "id"),
@Mapping(source = "bean.experience", target = "experience") @Mapping(source = "bean.experience", target = "experience")
}) })
AppMemberUserInfoRespVO convert(MemberUserDO bean, MemberLevelDO level); AppMemberUserInfoRespVO convert(MemberUserDO bean, MemberLevelDO level, String cardName, LocalDateTime cardExpirationTime);
MemberUserRespDTO convert2(MemberUserDO bean); MemberUserRespDTO convert2(MemberUserDO bean);

View File

@ -143,7 +143,7 @@ public class MemberUserDO extends TenantBaseDO {
private Long groupId; private Long groupId;
/** /**
* 是否绑过卡,是否开通过试用会员 * 是否绑过卡,是否开通过会员(0未开通,1试用,2有效期,3永久)
*/ */
private Integer activate; private Integer activate;

View File

@ -31,6 +31,10 @@ public class PaidMemberUserDO extends TenantBaseDO {
*/ */
@TableId @TableId
private Long id; private Long id;
/**
* 用户编号
*/
private Long uid;
/** /**
* 手机号 * 手机号
*/ */
@ -137,6 +141,20 @@ public class PaidMemberUserDO extends TenantBaseDO {
* 支付渠道 * 支付渠道
*/ */
private String payChannel; private String payChannel;
/**
* 订单号
*/
private String orderNo;
/**
* 支付订单编号
*
* 关联 {@link PayOrderDO#getId()}
*/
private Long payOrderId;
/**
* 会员类型
*/
private String payMemberType;
} }

View File

@ -62,13 +62,6 @@ public interface PaidMemberCardTypeService {
*/ */
List<PaidMemberCardTypeDO> getCardTypeList (Integer activate); List<PaidMemberCardTypeDO> getCardTypeList (Integer activate);
/**
* 根据用户是否使用有效期会员
* 查询会员类型列表
* @param activate
* @return
*/
List<PaidMemberCardTypeDO> getCardTypeList2 (Integer activate,String name);

View File

@ -34,8 +34,6 @@ public class PaidMemberCardTypeServiceImpl implements PaidMemberCardTypeService
@Resource @Resource
private PaidMemberCardTypeMapper cardMapper; private PaidMemberCardTypeMapper cardMapper;
@Resource
private PaidMemberUserService paidMemberUserService01;
@Override @Override
public Long createcard(PaidMemberCardTypeSaveReqVO createReqVO) { public Long createcard(PaidMemberCardTypeSaveReqVO createReqVO) {
@ -83,28 +81,15 @@ public class PaidMemberCardTypeServiceImpl implements PaidMemberCardTypeService
public List<PaidMemberCardTypeDO> getCardTypeList(Integer activate) { public List<PaidMemberCardTypeDO> getCardTypeList(Integer activate) {
List<PaidMemberCardTypeDO> list = new ArrayList<>(); List<PaidMemberCardTypeDO> list = new ArrayList<>();
Integer status = 1; Integer status = 1;
if(activate == 1){ if(activate == 0){
list = cardMapper.selectListByIsActivate(status); list = cardMapper.selectListByStatus(status);
} }
else { else {
list = cardMapper.selectListByStatus(status); list = cardMapper.selectListByIsActivate(status);
} }
return list; return list;
} }
@Override
public List<PaidMemberCardTypeDO> getCardTypeList2(Integer activate,String name) {
List<PaidMemberCardTypeDO> list = new ArrayList<>();
Integer status = 1;
if (activate == 2){
list = cardMapper.selectList(new LambdaQueryWrapperX<PaidMemberCardTypeDO>()
.eqIfPresent(PaidMemberCardTypeDO::getStatus,status)
.neIfPresent(PaidMemberCardTypeDO::getName,name)
.neIfPresent(PaidMemberCardTypeDO::getName,"试用")
.orderByAsc(PaidMemberCardTypeDO::getId));
}
return list;
}
@Override @Override

View File

@ -60,8 +60,8 @@ public interface PaidMemberOrderService {
* *
* @return 编号 * @return 编号
*/ */
BigDecimal createMemberRecord(Long userId, Integer userType, String userIp, // BigDecimal createMemberRecord(Long userId, Integer userType, String userIp,
Integer type,String cardName); // Integer type,String cardName);
/** /**
* 创建付费会员订单 * 创建付费会员订单
@ -78,11 +78,11 @@ public interface PaidMemberOrderService {
*/ */
void updateOrder(@Valid PaidMemberOrderDO updateReqVO); void updateOrder(@Valid PaidMemberOrderDO updateReqVO);
/** // /**
* 根据订单会员类型 // * 根据订单会员类型
* 获得到期时间 // * 获得到期时间
*/ // */
LocalDateTime getDeadLineDay(String cardName); // LocalDateTime getDeadLineDay(String cardName);
/** /**

View File

@ -87,27 +87,27 @@ public class PaidMemberOrderServiceImpl implements PaidMemberOrderService {
return paidMemberOrderMapper.selectPage(pageReqVO); return paidMemberOrderMapper.selectPage(pageReqVO);
} }
@Override // @Override
public BigDecimal createMemberRecord(Long userId, Integer userType, String userIp, // public BigDecimal createMemberRecord(Long userId, Integer userType, String userIp,
Integer type, String cardName) { // Integer type, String cardName) {
//定义一个支付金额 // //定义一个支付金额
BigDecimal payPrice = null; // BigDecimal payPrice = null;
BigDecimal gitBalance = BigDecimal.valueOf(0);//赠送余额权益规则还未定 // BigDecimal gitBalance = BigDecimal.valueOf(0);//赠送余额权益规则还未定
//
if(Objects.nonNull(type)){ // if(Objects.nonNull(type)){
PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getMemberUser(getLoginUserId()); // PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getMemberUser(getLoginUserId());
PaidMemberCardTypeDO paidMemberCardTypeDO =typeService.selectByName(cardName); // PaidMemberCardTypeDO paidMemberCardTypeDO =typeService.selectByName(cardName);
if(paidMemberCardTypeDO.getName().equals("试用")){ // if(paidMemberCardTypeDO.getName().equals("试用")){
payPrice = paidMemberCardTypeDO.getOriginalPrice(); // payPrice = paidMemberCardTypeDO.getOriginalPrice();
}else if (paidMemberUserDO != null){ // }else if (paidMemberUserDO != null){
payPrice = paidMemberCardTypeDO.getSpecialPrice(); // payPrice = paidMemberCardTypeDO.getSpecialPrice();
} // }
else { // else {
payPrice = paidMemberCardTypeDO.getOriginalPrice(); // payPrice = paidMemberCardTypeDO.getOriginalPrice();
} // }
} // }
return payPrice; // return payPrice;
} // }
@Override @Override
public void createOrder(PaidMemberOrderDO createReqVO) { public void createOrder(PaidMemberOrderDO createReqVO) {
@ -119,23 +119,23 @@ public class PaidMemberOrderServiceImpl implements PaidMemberOrderService {
paidMemberOrderMapper.updateById(updateReqVO); paidMemberOrderMapper.updateById(updateReqVO);
} }
@Override // @Override
public LocalDateTime getDeadLineDay(String cardName) { // public LocalDateTime getDeadLineDay(String cardName) {
LocalDateTime now = LocalDateTime.now(); // LocalDateTime now = LocalDateTime.now();
LocalDateTime deadlineDay; // LocalDateTime deadlineDay;
if (cardName.equals("试用")){ // if (cardName.equals("试用")){
deadlineDay = now.plus(1, ChronoUnit.DAYS); // deadlineDay = now.plus(1, ChronoUnit.DAYS);
} else if (cardName.equals("月卡")) { // } else if (cardName.equals("月卡")) {
deadlineDay = now.plus(1,ChronoUnit.MONTHS); // deadlineDay = now.plus(1,ChronoUnit.MONTHS);
} else if (cardName.equals("季卡")) { // } else if (cardName.equals("季卡")) {
deadlineDay = now.plus(3,ChronoUnit.MONTHS); // deadlineDay = now.plus(3,ChronoUnit.MONTHS);
} else if (cardName.equals("年卡")) { // } else if (cardName.equals("年卡")) {
deadlineDay = now.plus(1,ChronoUnit.YEARS); // deadlineDay = now.plus(1,ChronoUnit.YEARS);
} else { // } else {
deadlineDay = null; // deadlineDay = null;
} // }
return deadlineDay; // return deadlineDay;
} // }
@Override @Override
public PaidMemberOrderDO getPaidMemeberOrder(Long id) { public PaidMemberOrderDO getPaidMemeberOrder(Long id) {

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.member.service.user; package cn.iocoder.yudao.module.member.service.user;
import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import javax.validation.*; import javax.validation.*;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; import cn.iocoder.yudao.module.member.controller.admin.user.vo.*;
@ -24,6 +25,9 @@ public interface PaidMemberUserService {
*/ */
Long createMemberUser(@Valid PaidMemberUserSaveReqVO createReqVO); Long createMemberUser(@Valid PaidMemberUserSaveReqVO createReqVO);
/** /**
* 更新会员 * 更新会员
* *
@ -46,6 +50,26 @@ public interface PaidMemberUserService {
*/ */
PaidMemberUserDO getMemberUser(Long id); PaidMemberUserDO getMemberUser(Long id);
// /**
// * 判断是否为会员
// */
// PaidMemberUserDO isValidPaidMember(Integer activate,LocalDateTime cardExpirationTime);
int getPriceByTtype(Integer activate, String cardName);
LocalDateTime getDeadLineDay(String cardName);
PaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO);
/**
* 更新会员
*
* @param updateReqVO 更新信息
*/
void update(@Valid PaidMemberUserDO updateReqVO);
PaidMemberUserDO getPaidMemberUserByUid(Long uid);
// /** // /**
// * 获得会员分页 // * 获得会员分页

View File

@ -1,11 +1,20 @@
package cn.iocoder.yudao.module.member.service.user; package cn.iocoder.yudao.module.member.service.user;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; import cn.iocoder.yudao.module.member.controller.admin.user.vo.*;
import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO; import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO;
@ -16,6 +25,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.member.dal.mysql.user.PaidMemberUserMapper; 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.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.*;
/** /**
@ -30,16 +40,28 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
@Resource @Resource
private PaidMemberUserMapper paidMemberUserMapper; private PaidMemberUserMapper paidMemberUserMapper;
@Resource
private PaidMemberCardTypeService memberCardTypeService;
@Override @Override
public Long createMemberUser(PaidMemberUserSaveReqVO createReqVO) { public Long createMemberUser(PaidMemberUserSaveReqVO createReqVO) {
// 插入 // 插入
PaidMemberUserDO memberUser = BeanUtils.toBean(createReqVO, PaidMemberUserDO.class); PaidMemberUserDO memberUser = BeanUtils.toBean(createReqVO, PaidMemberUserDO.class);
if(getPaidMemberUserByOrderNo(memberUser.getOrderNo()) != null){
throw exception(PAID_MEMBER_USER_ORDER_NO_NOT_EXISTS);
}
paidMemberUserMapper.insert(memberUser); paidMemberUserMapper.insert(memberUser);
// 返回 // 返回
return memberUser.getId(); return memberUser.getId();
} }
// public String generate(String prefix){
// String no = prefix + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN);
// return no;
// }
@Override @Override
public void updateMemberUser(PaidMemberUserSaveReqVO updateReqVO) { public void updateMemberUser(PaidMemberUserSaveReqVO updateReqVO) {
// 校验存在 // 校验存在
@ -59,16 +81,90 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService {
private void validateMemberUserExists(Long id) { private void validateMemberUserExists(Long id) {
if (paidMemberUserMapper.selectById(id) == null) { if (paidMemberUserMapper.selectById(id) == null) {
throw exception(MEMBER_USER_NOT_EXISTS); throw exception(PAID_MEMBER_ORDER_NOT_EXISTS);
} }
} }
@Override @Override
public PaidMemberUserDO getMemberUser(Long id) { public PaidMemberUserDO getMemberUser(Long id) {
validateMemberUserExists(id);
return paidMemberUserMapper.selectById(id); return paidMemberUserMapper.selectById(id);
} }
// @Override // @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;
if(activate == 0){
BigDecimal payprice = memberCardTypeService.selectByName(cardName).getOriginalPrice();
price = payprice.multiply(new BigDecimal("100")).intValue();
}
else {
BigDecimal payprice = memberCardTypeService.selectByName(cardName).getSpecialPrice();
price = payprice.multiply(new BigDecimal("100")).intValue();
}
return price;
}
//获取会员类型对应的过期时间
@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 PaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO) {
PaidMemberUserDO paidMemberUserDO = paidMemberUserMapper.selectOne(PaidMemberUserDO::getOrderNo,orderNO);
return paidMemberUserDO;
}
@Override
public void update(PaidMemberUserDO updateReqVO) {
// 校验存在
validateMemberUserExists(updateReqVO.getId());
paidMemberUserMapper.updateById(updateReqVO);
}
@Override
public PaidMemberUserDO getPaidMemberUserByUid(Long uid) {
List<PaidMemberUserDO> list = paidMemberUserMapper.selectList(
new LambdaQueryWrapperX<PaidMemberUserDO>().eq(PaidMemberUserDO::getUid,uid)
.orderByDesc(PaidMemberUserDO::getId));
if(list.isEmpty()){
return null;
}
PaidMemberUserDO paidMemberUserDO = list.get(0);
return paidMemberUserDO;
}
// @Override
// public PageResult<PaidMemberUserDO> getMemberUserPage(PaidMemberUserPageReqVO pageReqVO) { // public PageResult<PaidMemberUserDO> getMemberUserPage(PaidMemberUserPageReqVO pageReqVO) {
// return memberUserMapper.selectPage(pageReqVO); // return memberUserMapper.selectPage(pageReqVO);
// } // }

View File

@ -0,0 +1,203 @@
package cn.iocoder.yudao.module.pay.controller.app.member;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
//import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.PaidMemberUserSaveReqVO;
import cn.iocoder.yudao.module.member.convert.order.PaidMemberOrderConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.order.PaidMemberOrderDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO;
import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService;
import cn.iocoder.yudao.module.member.service.order.PaidMemberOrderService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.service.user.PaidMemberUserService;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemberCreateReqVO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemberCreateRespVO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemeberOrderReqDto;
import cn.iocoder.yudao.module.pay.convert.member.PayMemberOrderConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
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.pay.core.enums.channel.PayChannelEnum.WALLET;
import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserType;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.MEMBER_USER_NOT_EXISTS;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_BALANCE_NOT_ENOUGH;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
import static cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum.PAYMENT;
@Tag(name = "用户 APP - 会员支付")
@RestController
@RequestMapping("/pay/member")
@Validated
@Slf4j
public class AppPaidMembeController {
/**
* 会员支付的 no 前缀
* */
private static final String PAID_MEMBER_NO_PREFIX = "M";
private static final String PAID_MEMBER_USER_SUBJECT = "会员支付购卡";
@Resource
private MemberUserService memberUserService;
@Resource
private PaidMemberUserService paidMemberUserService;
@Resource
private PaidMemberCardTypeService memberCardService;
@Resource
private PayWalletService payWalletService;
@Resource
private PayNoRedisDAO noRedisDAO;
@Resource
private PayOrderService payOrderService;
@PostMapping("/create")
@Operation(summary = "创建会员支付记录(发起支付)")
public CommonResult<AppPaidMemberCreateRespVO> createcard(@Valid @RequestBody AppPaidMemberCreateReqVO reqVO) {
//获取当前登录用户信息,并判断用户是否存在
MemberUserDO memberUserDO = memberUserService.getUser(getLoginUserId());
if (memberUserDO == null){
throw exception(MEMBER_USER_NOT_EXISTS);
}
PaidMemberUserDO paidMemberUserDO = new PaidMemberUserDO();
PaidMemberUserSaveReqVO paidMemberUserSaveReqVO = new PaidMemberUserSaveReqVO();
//初始化支付金额,单位为分
int price = 0;
Long payOrderId = null;
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());
paidMemberUserSaveReqVO.setCardExpirationTime(cardExpirationTime);
//设置会员订单号
paidMemberUserSaveReqVO.setOrderNo(noRedisDAO.generate(PAID_MEMBER_NO_PREFIX));
//新增会员订单记录
Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO);
//查询新增的会员订单记录
paidMemberUserDO = paidMemberUserService.getMemberUser(id);
memberUserDO.setActivate(1);
//跟新用户的会员启用状态
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));
//新增会员订单记录
Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO);
//查询新增的会员订单记录
paidMemberUserDO = paidMemberUserService.getMemberUser(id);
// 创建支付订单号
payOrderId = payOrderService.createOrder(new PayOrderCreateReqDTO()
.setAppId(1L).setUserIp(getClientIP())
.setMerchantOrderId(""+paidMemberUserDO.getId())
.setSubject(PAID_MEMBER_USER_SUBJECT).setBody("")
.setPrice(paidMemberUserDO.getPrice())
.setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿支付超时时间
paidMemberUserDO.setPayOrderId(payOrderId);
//跟新支付订单号进付费会员表里
paidMemberUserService.update(paidMemberUserDO);
}
return success(PayMemberOrderConvert.INSTANCE.convert(paidMemberUserDO.getId(),payOrderId
,paidMemberUserDO.getCardExpirationTime(),memberUserDO.getActivate()));
}
@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());
//获取支付时间
LocalDateTime payTime = LocalDateTime.now();
paidMemberUserDO.setPayTime(payTime);
//更新会员订单支付状态为已支付
paidMemberUserDO.setPaid(true);
//获取试用类型的过期时间
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("模拟支付");
}
//更新会员订单
paidMemberUserService.update(paidMemberUserDO);
//设置个人信息的会员状态0未开通1试用2有效期3永久
if(notifyReqDTO.getCardName().equals("永久")){
memberUserDO.setActivate(3);
}else {
memberUserDO.setActivate(2);
}
//更新用户会员状态
memberUserService.updateUserDo(memberUserDO);
// return success(PayMemberOrderConvert.INSTANCE.convert(paidMemberUserDO.getId(),payOrderId
// ,paidMemberUserDO.getCardExpirationTime(),memberUserDO.getActivate()));
return success(true);
}
}

View File

@ -1,176 +0,0 @@
package cn.iocoder.yudao.module.pay.controller.app.member;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.enums.UserTypeEnum;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
//import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
import cn.iocoder.yudao.module.member.controller.admin.user.vo.PaidMemberUserSaveReqVO;
import cn.iocoder.yudao.module.member.convert.order.PaidMemberOrderConvert;
import cn.iocoder.yudao.module.member.dal.dataobject.order.PaidMemberOrderDO;
import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO;
import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService;
import cn.iocoder.yudao.module.member.service.order.PaidMemberOrderService;
import cn.iocoder.yudao.module.member.service.user.MemberUserService;
import cn.iocoder.yudao.module.member.service.user.PaidMemberUserService;
import cn.iocoder.yudao.module.pay.api.notify.dto.PayOrderNotifyReqDTO;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemberOrderReqVO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemberOrderRespVO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemeberOrderReqDto;
import cn.iocoder.yudao.module.pay.convert.member.PayMemberOrderConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
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.getLoginUserType;
import static cn.iocoder.yudao.module.member.enums.ErrorCodeConstants.PAID_MEMBER_ORDER_NOT_EXISTS;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_BALANCE_NOT_ENOUGH;
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND;
import static cn.iocoder.yudao.module.pay.enums.wallet.PayWalletBizTypeEnum.PAYMENT;
@Tag(name = "用户 APP - 会员支出")
@RestController
@RequestMapping("/pay/member")
@Validated
@Slf4j
public class AppPaidMembeOrderController {
@Resource
private MemberUserService userService1;
@Resource
private PaidMemberUserService memberUserService1;
@Resource
private PaidMemberOrderService paidMemberOrderService1;
@Resource
private PayWalletService memberWalletService;
@Resource
private PayOrderService payOrderService01;
@Resource
private PaidMemberCardTypeService cardService;
@Resource
private PayWalletService payWalletService;
@PostMapping("/create")
@Operation(summary = "创建会员支付记录(发起支付)")
public CommonResult<AppPaidMemberOrderRespVO> createcard(@Valid @RequestBody AppPaidMemberOrderReqVO reqVO) {
MemberUserDO memberUserDO = userService1.getUser(getLoginUserId());
PaidMemberUserSaveReqVO paidMemberUserSaveReqVO = new PaidMemberUserSaveReqVO();
// 判断当前用户是否选择过试用会员
if(memberUserDO.getActivate() == 0 && memberUserDO != null && reqVO.getCardName().equals("试用")){
//试用会员
memberUserDO.setActivate(CommonStatusEnum.DISABLE.getStatus());
}else if(reqVO.getCardName().equals("永久")){
//永久会员
memberUserDO.setActivate(3);
}else {
//有效期会员
memberUserDO.setActivate(2);
}
// 若不是会员则往会员表插入数据
if(memberUserService1.getMemberUser(memberUserDO.getId()) == null){
BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO);
memberUserService1.createMemberUser(paidMemberUserSaveReqVO);
}
//判断会员类型
if(reqVO.getCardName().equals("试用")){
reqVO.setType(0);
} else if (reqVO.getCardName().equals("永久")) {
reqVO.setType(2);
}else {
reqVO.setType(1);
}
//获得对应会员期限天数
String deadlineDay = cardService.selectByName(reqVO.getCardName()).getVid();
LocalDateTime payTime = LocalDateTime.now();
LocalDateTime cardExpirationTime = paidMemberOrderService1.getDeadLineDay(reqVO.getCardName());
//获得支付金额
BigDecimal payPrice = paidMemberOrderService1.createMemberRecord(getLoginUserId(),
getLoginUserType(),getClientIP(),reqVO.getType(),reqVO.getCardName());
BigDecimal p = payPrice.multiply(new BigDecimal("100"));
Integer payPriceInt = p.intValue();
BigDecimal originalPrice = cardService.selectByName(reqVO.getCardName()).getOriginalPrice();
// PayWalletDO walletDO = memberWalletService.getOrCreateWallet(getLoginUserId(),getLoginUserType());
//订单对象赋值
PaidMemberOrderDO paidMemberOrderDO = PaidMemberOrderConvert.INSTANCE.convert(getLoginUserId(),
reqVO.getCardName(),reqVO.getType(),payPrice,payTime,deadlineDay,cardExpirationTime,originalPrice);
paidMemberOrderService1.createOrder(paidMemberOrderDO);
Long payOrderId = payOrderService01.createOrder(new PayOrderCreateReqDTO()
.setAppId(1L).setUserIp(getClientIP())
.setMerchantOrderId(""+paidMemberOrderDO.getId()) // 业务的订单编号
.setSubject("会员支付").setBody("")
.setPrice(payPriceInt)
.setExpireTime(addTime(Duration.ofHours(2L)))); // TODO @芋艿支付超时时间
paidMemberOrderDO.setPayOrderId(payOrderId);
userService1.updateUserDo(memberUserDO);
paidMemberOrderService1.updateOrder(paidMemberOrderDO);
return success(PayMemberOrderConvert.INSTANCE.convert(paidMemberOrderDO.getId(),paidMemberOrderDO.getPayOrderId()
,paidMemberOrderDO.getCardExpirationTime(),memberUserDO.getActivate()));
}
@PostMapping("/update")
@Operation(summary = "更新会员订单未支付为已支付") // pay-module 支付服务进行回调可见 PayNotifyJob
public CommonResult<Boolean> updatePaidMemberOrder(@Valid @RequestBody AppPaidMemeberOrderReqDto notifyReqDTO){
//获取订单记录
PaidMemberOrderDO paidMemberOrderDO = paidMemberOrderService1.getPaidMemeberOrder(Long.valueOf(notifyReqDTO.getMerchantOrderId()));
if(paidMemberOrderDO == null){
log.error("[updatePaidMemberOrder]updateReqVO({}) 付费会员订单不存在.");
throw exception(PAID_MEMBER_ORDER_NOT_EXISTS);
}
BigDecimal decimalprice = paidMemberOrderDO.getPrice();
Integer price = decimalprice.multiply(new BigDecimal("100")).intValue();
// 校验钱包充值是否可以支付
PayWalletDO walletDO = payWalletService.getOrCreateWallet(WebFrameworkUtils.getLoginUserId(),getLoginUserType());
if(walletDO == null){
log.error("[updatePaidMemberOrder]updateReqVO({}) 用户钱包不存在.");
throw exception(WALLET_NOT_FOUND);
}
if(walletDO.getBalance()<price){
log.error("[updatePaidMemberOrder]updateReqVO({}) 钱包余额不足.");
throw exception(WALLET_BALANCE_NOT_ENOUGH);
}
PayOrderDO payOrderDO = payOrderService01.getOrder(notifyReqDTO.getPayOrderId());
//更新订单支付状态为已支付
paidMemberOrderDO.setPaid(true);
paidMemberOrderDO.setPayChannel(payOrderDO.getChannelCode());
paidMemberOrderService1.updateOrder(paidMemberOrderDO);
//扣减钱包余额
PayWalletTransactionDO payWalletTransactionDO = payWalletService.reduceWalletBalance
(walletDO.getId(),notifyReqDTO.getPayOrderId(),PAYMENT,price);
return success(true);
}
}

View File

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.pay.controller.app.member.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
@Schema(description = "用户 APP - 会员支付 Request VO")
@Data
public class AppPaidMemberCreateReqVO {
@Schema(description = "会员卡名称", example = "试用")
private String cardName;
}

View File

@ -10,7 +10,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Schema(description = "用户 APP - 会员支付 Resp VO") @Schema(description = "用户 APP - 会员支付 Resp VO")
@Data @Data
public class AppPaidMemberOrderRespVO { public class AppPaidMemberCreateRespVO {
@Schema(description = "会员支付编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @Schema(description = "会员支付编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id; private Long id;
@ -18,6 +18,9 @@ public class AppPaidMemberOrderRespVO {
@Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "o100") @Schema(description = "支付订单编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "o100")
private Long payOrderId; private Long payOrderId;
// @Schema(description = "会员订单号", requiredMode = Schema.RequiredMode.REQUIRED, example = "m100")
// private String orderNo;
@Schema(description = "到期时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-11-22 09:30:05") @Schema(description = "到期时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-11-22 09:30:05")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime cardExpirationTime; private LocalDateTime cardExpirationTime;

View File

@ -1,29 +0,0 @@
package cn.iocoder.yudao.module.pay.controller.app.member.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
@Schema(description = "用户 APP - 会员支付 Request VO")
@Data
public class AppPaidMemberOrderReqVO {
@Schema(description = "会员卡售价", example = "1000")
@Min(value = 0, message = "会员卡必须大等于零")
private BigDecimal price;
@Schema(description = "会员卡名称", example = "试用")
private String cardName;
@Schema(description = "会员类型", example = "0-试用1-期限2-永久")
private Integer type;
// @Schema(description = "支付方式", example = "weixin,alipay,give,yue")
// private String payType;
@Schema(description = "支付渠道", example = "公众号,mini-小程序h5-网页支付,wechatIos-微信IoswechatAndroid-微信Android,alipay-支付包alipayApp-支付宝App,give-平台赠送")
private String payChannel;
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.pay.controller.app.member.vo; package cn.iocoder.yudao.module.pay.controller.app.member.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Builder; import lombok.Builder;
import lombok.Data; import lombok.Data;
@ -18,17 +19,12 @@ import javax.validation.constraints.NotNull;
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class AppPaidMemeberOrderReqDto { public class AppPaidMemeberOrderReqDto {
@Schema(description = "会员支付编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long id;
/** @Schema(description = "会员卡名称", example = "试用")
* 商户订单编号 private String cardName;
*/
@NotEmpty(message = "商户订单号不能为空")
private String merchantOrderId;
/**
* 支付订单编号
*/
@NotNull(message = "支付订单编号不能为空")
private Long payOrderId;
@Schema(description = "支付渠道", example = "公众号,mini-小程序h5-网页支付,wechatIos-微信IoswechatAndroid-微信Android,alipay-支付包alipayApp-支付宝App,give-平台赠送")
private String payChannel;
} }

View File

@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.pay.convert.member;
import cn.iocoder.yudao.module.member.controller.admin.order.vo.PaidMemberOrderRespVO; import cn.iocoder.yudao.module.member.controller.admin.order.vo.PaidMemberOrderRespVO;
import cn.iocoder.yudao.module.member.dal.dataobject.order.PaidMemberOrderDO; import cn.iocoder.yudao.module.member.dal.dataobject.order.PaidMemberOrderDO;
import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemberOrderRespVO; import cn.iocoder.yudao.module.pay.controller.app.member.vo.AppPaidMemberCreateRespVO;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers; import org.mapstruct.factory.Mappers;
@ -13,5 +13,5 @@ public interface PayMemberOrderConvert {
PayMemberOrderConvert INSTANCE = Mappers.getMapper(PayMemberOrderConvert.class); PayMemberOrderConvert INSTANCE = Mappers.getMapper(PayMemberOrderConvert.class);
AppPaidMemberOrderRespVO convert(Long id, Long payOrderId, LocalDateTime cardExpirationTime, Integer activate); AppPaidMemberCreateRespVO convert(Long id, Long payOrderId, LocalDateTime cardExpirationTime, Integer activate);
} }