From e0bac9998e0e0f4ef8344b16fa0d2e27393fa395 Mon Sep 17 00:00:00 2001 From: khy <2908249413@qq.com> Date: Wed, 23 Oct 2024 14:07:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=AE=A2=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/enums/ErrorCodeConstants.java | 4 + .../PaidMemberCardTypeController.java | 14 +- .../user/vo/PaidMemberUserSaveReqVO.java | 6 + .../dal/dataobject/user/MemberUserDO.java | 2 +- .../dal/dataobject/user/PaidMemberUserDO.java | 8 + .../PaidMemberCardTypeServiceImpl.java | 2 - .../service/order/PaidMemberOrderService.java | 14 +- .../order/PaidMemberOrderServiceImpl.java | 76 ++++---- .../service/user/PaidMemberUserService.java | 10 + .../user/PaidMemberUserServiceImpl.java | 62 +++++- .../app/member/AppPaidMembeController.java | 146 +++++++++++++++ .../member/AppPaidMembeOrderController.java | 176 ------------------ .../member/vo/AppPaidMemberCreateReqVO.java | 15 ++ ...VO.java => AppPaidMemberCreateRespVO.java} | 9 +- .../member/vo/AppPaidMemberOrderReqVO.java | 29 --- .../member/vo/AppPaidMemeberOrderReqDto.java | 16 +- .../convert/member/PayMemberOrderConvert.java | 4 +- 17 files changed, 316 insertions(+), 277 deletions(-) create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java delete mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeOrderController.java create mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/vo/AppPaidMemberCreateReqVO.java rename yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/vo/{AppPaidMemberOrderRespVO.java => AppPaidMemberCreateRespVO.java} (74%) delete mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/vo/AppPaidMemberOrderReqVO.java diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index 5b7bc4d..20995c4 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -68,4 +68,8 @@ public interface ErrorCodeConstants { ErrorCode CARD_NOT_EXISTS = new ErrorCode(1_004_020_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_USER_ORDER_NO_NOT_EXISTS = new ErrorCode(1_004_023_000, "生成会员订单号失败,请重新提交"); + + } diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/membercardtype/PaidMemberCardTypeController.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/membercardtype/PaidMemberCardTypeController.java index cc4af4a..0a50621 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/membercardtype/PaidMemberCardTypeController.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/membercardtype/PaidMemberCardTypeController.java @@ -34,20 +34,20 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; public class PaidMemberCardTypeController { @Resource - private PaidMemberCardTypeService cardService; + private PaidMemberCardTypeService cardTypeService; @PostMapping("/create") @Operation(summary = "创建会员卡类型") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:create')") public CommonResult createcard(@Valid @RequestBody PaidMemberCardTypeSaveReqVO createReqVO) { - return success(cardService.createcard(createReqVO)); + return success(cardTypeService.createcard(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新会员卡类型") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:update')") public CommonResult updatecard(@Valid @RequestBody PaidMemberCardTypeSaveReqVO updateReqVO) { - cardService.updatecard(updateReqVO); + cardTypeService.updatecard(updateReqVO); return success(true); } @@ -58,7 +58,7 @@ public class PaidMemberCardTypeController { @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:delete')") public CommonResult deletecard(@RequestParam("id") long memberCardId) { System.out.println(memberCardId); - cardService.deletecard(memberCardId); + cardTypeService.deletecard(memberCardId); return success(true); } @@ -67,7 +67,7 @@ public class PaidMemberCardTypeController { @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:query')") public CommonResult getcard(@RequestParam("id") Long id) { - PaidMemberCardTypeDO card = cardService.getcard(id); + PaidMemberCardTypeDO card = cardTypeService.getcard(id); return success(BeanUtils.toBean(card, PaidMemberCardTypeRespVO.class)); } @@ -75,7 +75,7 @@ public class PaidMemberCardTypeController { @Operation(summary = "获得会员卡类型分页") @PreAuthorize("@ss.hasPermission('member:paid-member-card-type:query')") public CommonResult> getcardPage(@Valid PaidMemberCardTypePageReqVO pageReqVO) { - PageResult pageResult = cardService.getcardPage(pageReqVO); + PageResult pageResult = cardTypeService.getcardPage(pageReqVO); return success(BeanUtils.toBean(pageResult, PaidMemberCardTypeRespVO.class)); } @@ -86,7 +86,7 @@ public class PaidMemberCardTypeController { public void exportcardExcel(@Valid PaidMemberCardTypePageReqVO pageReqVO, HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); - List list = cardService.getcardPage(pageReqVO).getList(); + List list = cardTypeService.getcardPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "会员卡类型.xls", "数据", PaidMemberCardTypeRespVO.class, BeanUtils.toBean(list, PaidMemberCardTypeRespVO.class)); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java index aa184f0..e495ec3 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/admin/user/vo/PaidMemberUserSaveReqVO.java @@ -16,6 +16,9 @@ public class PaidMemberUserSaveReqVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12209") private Long id; + @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "12209") + private Long uid; + @Schema(description = "手机号") private String mobile; @@ -95,4 +98,7 @@ public class PaidMemberUserSaveReqVO { @Schema(description = "支付渠道", example = "public-公众号,mini-小程序,h5-网页支付,wechatIos-微信Ios,wechatAndroid-微信Android,alipay-支付包,alipayApp-支付宝App,give-平台赠送,yue-余额支付") private String payChannel; + @Schema(description = "订单号", requiredMode = Schema.RequiredMode.REQUIRED) + private String orderNo; + } \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java index bf8732e..f619f1d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java @@ -143,7 +143,7 @@ public class MemberUserDO extends TenantBaseDO { private Long groupId; /** - * 是否绑过卡,是否开通过试用会员 + * 是否绑过卡,是否开通过会员(0:未开通,1:试用,2:有效期,3:永久) */ private Integer activate; diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java index 8113753..d1fbc00 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/PaidMemberUserDO.java @@ -31,6 +31,10 @@ public class PaidMemberUserDO extends TenantBaseDO { */ @TableId private Long id; + /** + * 用户编号 + */ + private Long uid; /** * 手机号 */ @@ -137,6 +141,10 @@ public class PaidMemberUserDO extends TenantBaseDO { * 支付渠道 */ private String payChannel; + /** + * 订单号 + */ + private String orderNo; } \ 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/membercardtype/PaidMemberCardTypeServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/membercardtype/PaidMemberCardTypeServiceImpl.java index db1c064..2f3b10e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/membercardtype/PaidMemberCardTypeServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/membercardtype/PaidMemberCardTypeServiceImpl.java @@ -34,8 +34,6 @@ public class PaidMemberCardTypeServiceImpl implements PaidMemberCardTypeService @Resource private PaidMemberCardTypeMapper cardMapper; - @Resource - private PaidMemberUserService paidMemberUserService01; @Override public Long createcard(PaidMemberCardTypeSaveReqVO createReqVO) { diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderService.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderService.java index be1e653..64abcab 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderService.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderService.java @@ -60,8 +60,8 @@ public interface PaidMemberOrderService { * * @return 编号 */ - BigDecimal createMemberRecord(Long userId, Integer userType, String userIp, - Integer type,String cardName); +// BigDecimal createMemberRecord(Long userId, Integer userType, String userIp, +// Integer type,String cardName); /** * 创建付费会员订单 @@ -78,11 +78,11 @@ public interface PaidMemberOrderService { */ void updateOrder(@Valid PaidMemberOrderDO updateReqVO); - /** - * 根据订单会员类型 - * 获得到期时间 - */ - LocalDateTime getDeadLineDay(String cardName); +// /** +// * 根据订单会员类型 +// * 获得到期时间 +// */ +// LocalDateTime getDeadLineDay(String cardName); /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderServiceImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderServiceImpl.java index 16d56d5..ef2e37e 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderServiceImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/order/PaidMemberOrderServiceImpl.java @@ -87,27 +87,27 @@ public class PaidMemberOrderServiceImpl implements PaidMemberOrderService { return paidMemberOrderMapper.selectPage(pageReqVO); } - @Override - public BigDecimal createMemberRecord(Long userId, Integer userType, String userIp, - Integer type, String cardName) { - //定义一个支付金额 - BigDecimal payPrice = null; - BigDecimal gitBalance = BigDecimal.valueOf(0);//赠送余额,权益规则还未定 - - if(Objects.nonNull(type)){ - PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getMemberUser(getLoginUserId()); - PaidMemberCardTypeDO paidMemberCardTypeDO =typeService.selectByName(cardName); - if(paidMemberCardTypeDO.getName().equals("试用")){ - payPrice = paidMemberCardTypeDO.getOriginalPrice(); - }else if (paidMemberUserDO != null){ - payPrice = paidMemberCardTypeDO.getSpecialPrice(); - } - else { - payPrice = paidMemberCardTypeDO.getOriginalPrice(); - } - } - return payPrice; - } +// @Override +// public BigDecimal createMemberRecord(Long userId, Integer userType, String userIp, +// Integer type, String cardName) { +// //定义一个支付金额 +// BigDecimal payPrice = null; +// BigDecimal gitBalance = BigDecimal.valueOf(0);//赠送余额,权益规则还未定 +// +// if(Objects.nonNull(type)){ +// PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getMemberUser(getLoginUserId()); +// PaidMemberCardTypeDO paidMemberCardTypeDO =typeService.selectByName(cardName); +// if(paidMemberCardTypeDO.getName().equals("试用")){ +// payPrice = paidMemberCardTypeDO.getOriginalPrice(); +// }else if (paidMemberUserDO != null){ +// payPrice = paidMemberCardTypeDO.getSpecialPrice(); +// } +// else { +// payPrice = paidMemberCardTypeDO.getOriginalPrice(); +// } +// } +// return payPrice; +// } @Override public void createOrder(PaidMemberOrderDO createReqVO) { @@ -119,23 +119,23 @@ public class PaidMemberOrderServiceImpl implements PaidMemberOrderService { paidMemberOrderMapper.updateById(updateReqVO); } - @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 = null; - } - return deadlineDay; - } +// @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 = null; +// } +// return deadlineDay; +// } @Override public PaidMemberOrderDO getPaidMemeberOrder(Long id) { 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 9d20748..b96c42e 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 @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.member.service.user; +import java.time.LocalDateTime; import java.util.*; import javax.validation.*; import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; @@ -24,6 +25,9 @@ public interface PaidMemberUserService { */ Long createMemberUser(@Valid PaidMemberUserSaveReqVO createReqVO); + + + /** * 更新会员 * @@ -46,6 +50,12 @@ public interface PaidMemberUserService { */ PaidMemberUserDO getMemberUser(Long id); + int getPriceByTtype(Integer activate, String cardName); + + LocalDateTime getDeadLineDay(String cardName); + + PaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO); + // /** // * 获得会员分页 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 fe7410b..bd6068b 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 @@ -1,11 +1,18 @@ 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.module.member.dal.dataobject.user.MemberUserDO; +import cn.iocoder.yudao.module.member.service.membercardtype.PaidMemberCardTypeService; import org.springframework.stereotype.Service; import javax.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.transaction.annotation.Transactional; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; import java.util.*; import cn.iocoder.yudao.module.member.controller.admin.user.vo.*; import cn.iocoder.yudao.module.member.dal.dataobject.user.PaidMemberUserDO; @@ -30,16 +37,29 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { @Resource private PaidMemberUserMapper paidMemberUserMapper; + @Resource + private PaidMemberCardTypeService memberCardTypeService; + @Override public Long createMemberUser(PaidMemberUserSaveReqVO createReqVO) { // 插入 PaidMemberUserDO memberUser = BeanUtils.toBean(createReqVO, PaidMemberUserDO.class); + String prefix = String.valueOf('m'); + memberUser.setOrderNo(generate(prefix)); + if(getPaidMemberUserByOrderNo(memberUser.getOrderNo()) != null){ + throw exception(PAID_MEMBER_USER_ORDER_NO_NOT_EXISTS); + } paidMemberUserMapper.insert(memberUser); // 返回 return memberUser.getId(); } + public String generate(String prefix){ + String no = prefix + DateUtil.format(LocalDateTime.now(), DatePattern.PURE_DATETIME_PATTERN); + return no; + } + @Override public void updateMemberUser(PaidMemberUserSaveReqVO updateReqVO) { // 校验存在 @@ -59,15 +79,55 @@ public class PaidMemberUserServiceImpl implements PaidMemberUserService { private void validateMemberUserExists(Long id) { if (paidMemberUserMapper.selectById(id) == null) { - throw exception(MEMBER_USER_NOT_EXISTS); + throw exception(PAID_MEMBER_ORDER_NOT_EXISTS); } } @Override public PaidMemberUserDO getMemberUser(Long id) { + validateMemberUserExists(id); return paidMemberUserMapper.selectById(id); } + @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 = null; + } + return deadlineDay; + } + + @Override + public PaidMemberUserDO getPaidMemberUserByOrderNo(String orderNO) { + PaidMemberUserDO paidMemberUserDO = paidMemberUserMapper.selectOne(PaidMemberUserDO::getOrderNo,orderNO); + return paidMemberUserDO; + } + // @Override // public PageResult getMemberUserPage(PaidMemberUserPageReqVO pageReqVO) { // return memberUserMapper.selectPage(pageReqVO); 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 new file mode 100644 index 0000000..3699ea7 --- /dev/null +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/member/AppPaidMembeController.java @@ -0,0 +1,146 @@ +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.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.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.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.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.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 { + + @Resource + private MemberUserService memberUserService; + + @Resource + private PaidMemberUserService paidMemberUserService; + + @Resource + private PaidMemberCardTypeService memberCardService; + + @Resource + private PayWalletService payWalletService; + + @PostMapping("/create") + @Operation(summary = "创建会员支付记录(发起支付)") + public CommonResult 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; + if(reqVO.getCardName().equals("试用")){ + BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO); + 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); + //新增会员订单记录 + Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO); + //查询新增的会员订单记录 + paidMemberUserDO = paidMemberUserService.getMemberUser(id); + memberUserDO.setActivate(1); + //跟新用户的会员启用状态 + memberUserService.updateUserDo(memberUserDO); + } + else { + BeanUtils.copyProperties(memberUserDO,paidMemberUserSaveReqVO); + paidMemberUserSaveReqVO.setId(null); + 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.setPayType("钱包支付"); + //新增会员订单记录 + Long id = paidMemberUserService.createMemberUser(paidMemberUserSaveReqVO); + //查询新增的会员订单记录 + paidMemberUserDO = paidMemberUserService.getMemberUser(id); + } + return success(PayMemberOrderConvert.INSTANCE.convert(paidMemberUserDO.getId(),paidMemberUserDO.getOrderNo() + ,paidMemberUserDO.getCardExpirationTime(),memberUserDO.getActivate())); + } + +// @PostMapping("/update") +// @Operation(summary = "更新会员订单未支付为已支付") // 由 pay-module 支付服务,进行回调,可见 PayNotifyJob +// public CommonResult updatePaidMemberUser(@Valid @RequestBody AppPaidMemeberOrderReqDto notifyReqDTO){ +// //获取订单记录 +// PaidMemberUserDO paidMemberUserDO = paidMemberUserService.getMemberUser(notifyReqDTO.getId()); +//// 校验钱包充值是否可以支付 +// PayWalletDO walletDO = payWalletService.getOrCreateWallet(WebFrameworkUtils.getLoginUserId(),getLoginUserType()); +// if(walletDO.getBalance() 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 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()