feat:支付
This commit is contained in:
1 parent
eec07ac718
commit
bb1def88d9
17 files changed
+278
-54
No files matched your search
@@ -6,15 +6,15 @@ create table act_cancel
|
||||
notice_id BIGINT(19) not null comment '公告id',
|
||||
active_org_price INT(10) null comment '活动原价',
|
||||
active_cancel_price INT(10) not null comment '活动核销价',
|
||||
start_time DATETIME null comment '开始时间',
|
||||
expire_time DATETIME not null comment '到期时间',
|
||||
act_status CHAR(32) not null comment '活动状态(1:正常 2:关闭)',
|
||||
act_title CHAR(32) not null comment '活动标题',
|
||||
act_content CHAR(32) null comment '活动内容',
|
||||
create_by VARCHAR(64) null comment '创建人',
|
||||
create_time DATETIME null comment '创建时间',
|
||||
update_by VARCHAR(64) null comment '修改人',
|
||||
update_time DATETIME null comment '修改时间',
|
||||
start_time DATETIME null comment '开始时间',
|
||||
expire_time DATETIME not null comment '到期时间',
|
||||
act_status CHAR(32) not null comment '活动状态(1:正常 2:关闭)',
|
||||
act_title CHAR(32) not null comment '活动标题',
|
||||
act_content CHAR(32) null comment '活动内容',
|
||||
create_by VARCHAR(64) null comment '创建人',
|
||||
create_time DATETIME null comment '创建时间',
|
||||
update_by VARCHAR(64) null comment '修改人',
|
||||
update_time DATETIME null comment '修改时间',
|
||||
del_flag CHAR default '0' null comment '删除标记',
|
||||
tenant_id BIGINT(19) null comment '租户ID'
|
||||
);
|
||||
@@ -47,6 +47,7 @@ DROP TABLE IF EXISTS act_coupon;
|
||||
CREATE TABLE act_coupon
|
||||
(
|
||||
id BIGINT(20) NOT NULL AUTO_INCREMENT COMMENT '优惠券ID',
|
||||
parent_act_id BIGINT(20) DEFAULT NULL COMMENT '父活动id',
|
||||
name VARCHAR(128) NOT NULL COMMENT '优惠券名称',
|
||||
type VARCHAR(64) NOT NULL COMMENT '优惠券类型 (1:满减券 2:折扣券 3:立减券 4:兑换券)',
|
||||
face_value INT DEFAULT 0 COMMENT '面额/折扣 (满减/立减单位:分, 折扣单位:百分比)',
|
||||
@@ -71,8 +72,8 @@ CREATE TABLE act_coupon
|
||||
del_flag char(1) COLLATE utf8mb4_general_ci DEFAULT '0' COMMENT '删除标记',
|
||||
tenant_id bigint DEFAULT NULL COMMENT '租户ID',
|
||||
PRIMARY KEY (id),
|
||||
KEY idx_status (status),
|
||||
KEY idx_valid_end_time (valid_end_time)
|
||||
KEY idx_status (status),
|
||||
KEY idx_valid_end_time (valid_end_time)
|
||||
) ENGINE = InnoDB COMMENT ='优惠券活动';
|
||||
|
||||
DROP TABLE IF EXISTS act_coupon_record;
|
||||
@@ -109,8 +110,8 @@ CREATE TABLE act_coupon_record
|
||||
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_coupon_code (coupon_code),
|
||||
KEY idx_user_id (user_id),
|
||||
KEY idx_coupon_id (coupon_id),
|
||||
KEY idx_end_time (end_time),
|
||||
KEY idx_status (status)
|
||||
KEY idx_user_id (user_id),
|
||||
KEY idx_coupon_id (coupon_id),
|
||||
KEY idx_end_time (end_time),
|
||||
KEY idx_status (status)
|
||||
) ENGINE = InnoDB COMMENT ='优惠券领取记录表';
|
||||
+12
@@ -81,6 +81,12 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "支付时间")
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/**
|
||||
* 支付参数
|
||||
*/
|
||||
@Schema(description = "支付参数")
|
||||
private String payRep;
|
||||
|
||||
/**
|
||||
* 支付返回
|
||||
*/
|
||||
@@ -99,6 +105,12 @@ public class ThirdPayOrderEntity extends Model<ThirdPayOrderEntity> {
|
||||
@Schema(description = "退款时间")
|
||||
private LocalDateTime refundTime;
|
||||
|
||||
/**
|
||||
* 退款参数
|
||||
*/
|
||||
@Schema(description = "退款参数")
|
||||
private String refundRep;
|
||||
|
||||
/**
|
||||
* 退款返回
|
||||
*/
|
||||
|
||||
+15
@@ -122,4 +122,19 @@ public class ThirdMiniWechatQueryVo {
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(ThirdMiniWechatQueryVo.SUCCESS, result_code);
|
||||
}
|
||||
|
||||
public static String wechantError() {
|
||||
return "<xml>" +
|
||||
"<return_code><![CDATA[FAIL]]></return_code>" +
|
||||
"<return_msg><![CDATA[FAIL]]></return_msg>" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
public static String wechantSuccess() {
|
||||
return "<xml>" +
|
||||
" <return_code><![CDATA[SUCCESS]]></return_code>" +
|
||||
" <return_msg><![CDATA[OK]]></return_msg>\n" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
}
|
||||
+15
-1
@@ -92,11 +92,25 @@ public class ThirdMiniWechatRefundQueryVo {
|
||||
private Long refund_fee;
|
||||
|
||||
public boolean isHttpSucess() {
|
||||
return ObjectUtil.equals(ThirdMiniWechatRefundQueryVo.SUCCESS, err_code);
|
||||
return ObjectUtil.equals(ThirdMiniWechatRefundQueryVo.SUCCESS, err_code) || ObjectUtil.isEmpty(err_code);
|
||||
}
|
||||
|
||||
public boolean isPaySucess() {
|
||||
return ObjectUtil.equals(ThirdMiniWechatRefundQueryVo.SUCCESS, result_code);
|
||||
}
|
||||
|
||||
public static String wechantError() {
|
||||
return "<xml>" +
|
||||
"<return_code><![CDATA[FAIL]]></return_code>" +
|
||||
"<return_msg><![CDATA[FAIL]]></return_msg>" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
public static String wechantSuccess() {
|
||||
return "<xml>" +
|
||||
" <return_code><![CDATA[SUCCESS]]></return_code>" +
|
||||
" <return_msg><![CDATA[OK]]></return_msg>\n" +
|
||||
"</xml>";
|
||||
}
|
||||
|
||||
}
|
||||
+6
@@ -3,6 +3,7 @@ package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.*;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.*;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
@@ -46,6 +47,11 @@ public interface ThirdMiniAppWechatService {
|
||||
*/
|
||||
ThirdMiniWechatRefundQueryVo refundQuery(ThirdMiniWechatRefundQueryDto dto);
|
||||
|
||||
/**
|
||||
* 支付的回调通知
|
||||
*/
|
||||
ThirdPayOrderEntity payCallback(String body, @RequestHeader Map<String, String> headers);
|
||||
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
|
||||
+5
@@ -1,5 +1,6 @@
|
||||
package com.bsd.pjcloud.thirdparty.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.common.data.datascope.DataScope;
|
||||
@@ -11,4 +12,8 @@ public interface ThirdPayOrderService extends IService<ThirdPayOrderEntity> {
|
||||
|
||||
Page<ThirdPayOrderVo> scopePage(Page page, ThirdPayOrderDto dto, DataScope dataScope);
|
||||
|
||||
default ThirdPayOrderEntity getByPayNo(String payNo) {
|
||||
return getOne(new LambdaQueryWrapper<ThirdPayOrderEntity>().eq(ThirdPayOrderEntity::getPayNo, payNo));
|
||||
}
|
||||
|
||||
}
|
||||
+54
-4
@@ -3,6 +3,8 @@ package com.bsd.pjcloud.thirdparty.service.impl.miniapp;
|
||||
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.XmlUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserInfo;
|
||||
import com.bsd.pjcloud.admin.api.dto.UserTokenDTO;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteTokenService;
|
||||
@@ -14,11 +16,12 @@ import com.bsd.pjcloud.app.api.feign.RemoteAppUserService;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformLoginErrorEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.miniplatform.MiniPlatformTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderStatusEnum;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppGetUniqueDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppOAth2LoginDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.ThirdMiniAppPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.dto.oathmini.pay.wechat.ThirdMiniJsapiPayDto;
|
||||
import com.bsd.pjcloud.thirdparty.entity.api.ThirdPayLogEntity;
|
||||
import com.bsd.pjcloud.thirdparty.entity.pay.ThirdPayOrderEntity;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppAliPayService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppService;
|
||||
import com.bsd.pjcloud.thirdparty.service.ThirdMiniAppWechatService;
|
||||
@@ -26,6 +29,9 @@ import com.bsd.pjcloud.thirdparty.service.ThirdPayLogService;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.ThirdMinAppOAth2LoginVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.ThirdMiniAppPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniJsapiPayVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniWechatQueryVo;
|
||||
import com.bsd.pjcloud.thirdparty.vo.oathmini.pay.wechat.ThirdMiniWechatRefundQueryVo;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.feign.RemoteWalletRechargePackageService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -36,7 +42,6 @@ import org.springframework.validation.annotation.Validated;
|
||||
import javax.net.ssl.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -146,7 +151,7 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
if (ObjectUtil.isEmpty(walletPackage)) {
|
||||
throw new RuntimeException("错误的充值配置");
|
||||
}
|
||||
int price = walletPackage.getPayPrice() + walletPackage.getBonusPrice();
|
||||
int price = walletPackage.getPayPrice();
|
||||
if (price <= 0) {
|
||||
throw new RuntimeException("错误的充值配置");
|
||||
}
|
||||
@@ -194,7 +199,52 @@ public class ThirdMiniAppServiceImpl implements ThirdMiniAppService {
|
||||
*/
|
||||
@Override
|
||||
public String miniPayCallback(String body, Map<String, String> headers) {
|
||||
return "";
|
||||
MiniPlatformTypeEnum platformType = checkMiniPlatformType(body);
|
||||
// 微信小程序
|
||||
if (ObjectUtil.equals(platformType, MiniPlatformTypeEnum.WECHAT)) {
|
||||
ThirdPayOrderEntity thirdPayOrder = thirdMiniAppWechatService.payCallback(body, headers);
|
||||
if (ObjectUtil.isEmpty(thirdPayOrder)) {
|
||||
return ThirdMiniWechatQueryVo.wechantError();
|
||||
}
|
||||
// 根据订单bizType来处理
|
||||
boolean isSuccess = disposePaySuccessAfter(thirdPayOrder);
|
||||
return isSuccess ? ThirdMiniWechatQueryVo.wechantSuccess() : ThirdMiniWechatQueryVo.wechantError();
|
||||
}
|
||||
// 支付宝
|
||||
else if (ObjectUtil.equals(platformType, MiniPlatformTypeEnum.ALI_PAY)) {
|
||||
return null;
|
||||
}
|
||||
// 不支持的支付类型
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private MiniPlatformTypeEnum checkMiniPlatformType(String body) {
|
||||
ThirdMiniWechatRefundQueryVo vo = JSONUtil.toBean(JSONUtil.toJsonStr(XmlUtil.xmlToMap(body)), ThirdMiniWechatRefundQueryVo.class);
|
||||
// 查询订单
|
||||
if (ObjectUtil.isNotEmpty(vo) && ObjectUtil.isNotEmpty(vo.getTransaction_id())) {
|
||||
return MiniPlatformTypeEnum.WECHAT;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean disposePaySuccessAfter(ThirdPayOrderEntity thirdPayOrder) {
|
||||
if (ObjectUtil.notEqual(thirdPayOrder.getStatus(), ThirdPayOrderStatusEnum.PAY_SUCCESS.getType())) {
|
||||
return true;
|
||||
}
|
||||
// 已经支付
|
||||
try {
|
||||
WalletRechargePaySuccess dto = new WalletRechargePaySuccess();
|
||||
dto.setPayNo(thirdPayOrder.getPayNo());
|
||||
dto.setUserId(thirdPayOrder.getUserId());
|
||||
dto.setBizId(thirdPayOrder.getBizId());
|
||||
dto.setBizType(thirdPayOrder.getBizType());
|
||||
return remoteWalletRechargePackageService.remotePaySuccess(dto).getData();
|
||||
} catch (Exception e) {
|
||||
log.error("处理小程序支付成功回调异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+41
-3
@@ -68,6 +68,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
payOrder.setUserCode(dto.getOpenid());
|
||||
payOrder.setPrice(dto.getAmount());
|
||||
payOrder.setStatus(ThirdPayOrderStatusEnum.PAY_UNPAID.getType());
|
||||
payOrder.setPayNo(dto.getOutTradeNo());
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
// 公众账号ID
|
||||
@@ -85,7 +86,7 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
// 商户订单号
|
||||
params.put("out_trade_no", dto.getOutTradeNo());
|
||||
// 商户回调地址
|
||||
params.put("notify_url", wechatConfig.getRefundCallbackUrl());
|
||||
params.put("notify_url", wechatConfig.getPayCallbackUrl());
|
||||
// 订单总金额,单位为分
|
||||
params.put("total_fee", dto.getAmount());
|
||||
// 终端IP
|
||||
@@ -97,7 +98,11 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
// 生成签名
|
||||
params.put("sign", generateSign(params));
|
||||
ThirdMiniWechantPayConstant.Api api = initApi(ThirdMiniWechantPayConstant.WECHAT_PAY);
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
|
||||
String xmlStr = XmlUtil.mapToXmlStr(params);
|
||||
payOrder.setPayRep(xmlStr);
|
||||
|
||||
String res = api.getHttpRequest().body(xmlStr).execute().body();
|
||||
log.debug("JSAPI/小程序下单,json,xml|{}", res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("JSAPI/小程序下单,res为空");
|
||||
@@ -297,7 +302,10 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
params.put("sign", generateSign(params));
|
||||
ThirdMiniWechantPayConstant.Api api = initApi(ThirdMiniWechantPayConstant.REFUND);
|
||||
api.setSslSocketFactory(createSSLSocketFactory());
|
||||
String res = api.getHttpRequest().body(XmlUtil.mapToXmlStr(params)).execute().body();
|
||||
|
||||
String xmlStr = XmlUtil.mapToXmlStr(params);
|
||||
|
||||
String res = api.getHttpRequest().body(xmlStr).execute().body();
|
||||
log.debug("|{}|申请退款,json,xml|{}", TAG, res);
|
||||
if (ObjectUtil.isEmpty(res)) {
|
||||
log.error("|{}|申请退款,res为空", TAG);
|
||||
@@ -356,6 +364,36 @@ public class ThirdMiniAppWechatServiceImpl implements ThirdMiniAppWechatService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付的回调通知
|
||||
*/
|
||||
@Override
|
||||
public ThirdPayOrderEntity payCallback(String body, Map<String, String> headers) {
|
||||
String bodyJson = JSONUtil.toJsonStr(XmlUtil.xmlToMap(body));
|
||||
ThirdMiniWechatRefundQueryVo vo = JSONUtil.toBean(bodyJson, ThirdMiniWechatRefundQueryVo.class);
|
||||
if (ObjectUtil.isEmpty(vo) || !vo.isHttpSucess()) {
|
||||
return null;
|
||||
}
|
||||
boolean paySucess = vo.isPaySucess();
|
||||
// 查询订单
|
||||
ThirdPayOrderEntity payOrderEntity = thirdPayOrderService.getByPayNo(vo.getOut_trade_no());
|
||||
if (ObjectUtil.isEmpty(payOrderEntity)) {
|
||||
log.error("|{}|payCallback,意外的错误,订单不存在,微信返回json|{}|", TAG, bodyJson);
|
||||
return null;
|
||||
}
|
||||
// 重复的回调
|
||||
if (ObjectUtil.notEqual(payOrderEntity.getStatus(), ThirdPayOrderStatusEnum.PAY_UNPAID.getType())) {
|
||||
log.error("|{}|payCallback,意外的错误,重复的回调,微信返回json|{}|", TAG, bodyJson);
|
||||
return null;
|
||||
}
|
||||
// 更新订单状态
|
||||
ThirdPayOrderEntity updateObj = new ThirdPayOrderEntity();
|
||||
updateObj.setId(payOrderEntity.getId());
|
||||
updateObj.setStatus(paySucess ? ThirdPayOrderStatusEnum.PAY_SUCCESS.getType() : ThirdPayOrderStatusEnum.PAY_FAILED.getType());
|
||||
thirdPayOrderService.updateById(updateObj);
|
||||
return thirdPayOrderService.getById(payOrderEntity.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 退款回调
|
||||
*/
|
||||
|
||||
+2
-2
@@ -182,8 +182,8 @@ mini-platform:
|
||||
merchant-id: 1106210589
|
||||
api-v2-key: qr0w9WkAu6GG3uuxPjDT7bcdIVoBr0rw
|
||||
merchant-serial-path: /Users/dengzhangchen/Desktop/backups/pay/third_cert/apiclient_cert.p12
|
||||
pay-callback-url: https://rj4jv5rwqs.by.takin.cc/third/third-mini-app-pay/app/pay-callback
|
||||
refund-callback-url: https://rj4jv5rwqs.by.takin.cc/hard/hard-wechant-pay/app/refund-callback
|
||||
pay-callback-url: https://dzc-test-1.fy.takin.cc/third/third-mini-app-pay/app/pay-callback
|
||||
refund-callback-url: https://dzc-test-1.fy.takin.cc/third/third-mini-app-pay/app/refund-callback
|
||||
spbill-create-ip: 59.202.170.152
|
||||
base-url: https://api.mch.weixin.qq.com
|
||||
ali-pay-config:
|
||||
|
||||
Vendored
+5
@@ -13,9 +13,11 @@
|
||||
a.status,
|
||||
a.pay_no,
|
||||
a.pay_time,
|
||||
a.pay_rep,
|
||||
a.pay_res,
|
||||
a.refund_no,
|
||||
a.refund_time,
|
||||
a.refund_rep,
|
||||
a.refund_res,
|
||||
a.expire_time,
|
||||
a.create_time,
|
||||
@@ -28,6 +30,9 @@
|
||||
|
||||
<sql id="whereA">
|
||||
a.del_flag = '0'
|
||||
<if test="dto.payNo null and dto.payNo != '' ">
|
||||
and a.pay_no LIKE concat('%',#{dto.payNo},'%')
|
||||
</if>
|
||||
<if test="dto.id != null">
|
||||
and a.id = #{dto.id}
|
||||
</if>
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package com.bsd.pjcloud.wallet.api.dto.recharge;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class WalletRechargePaySuccess {
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String payNo;
|
||||
|
||||
/**
|
||||
* 用户id
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 业务类型
|
||||
*/
|
||||
private String bizType;
|
||||
|
||||
/**
|
||||
* 业务id
|
||||
*/
|
||||
private String bizId;
|
||||
|
||||
}
|
||||
+8
@@ -2,10 +2,14 @@ package com.bsd.pjcloud.wallet.api.feign;
|
||||
|
||||
import com.bsd.pjcloud.common.core.constant.ServiceNameConstants;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.feign.annotation.NoToken;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(contextId = "remoteWalletRechargePackageService", value = ServiceNameConstants.WALLET_SERVICE)
|
||||
public interface RemoteWalletRechargePackageService {
|
||||
@@ -13,4 +17,8 @@ public interface RemoteWalletRechargePackageService {
|
||||
@GetMapping("/wallet-recharge-package/remote/{id}")
|
||||
R<WalletRechargePackageEntity> remoteGetById(@PathVariable("id") Long id);
|
||||
|
||||
@NoToken
|
||||
@PostMapping("/wallet-recharge-package/remote/pay-success")
|
||||
R<Boolean> remotePaySuccess(@RequestBody WalletRechargePaySuccess dto);
|
||||
|
||||
}
|
||||
+9
@@ -7,7 +7,9 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.bsd.pjcloud.common.core.util.R;
|
||||
import com.bsd.pjcloud.common.log.annotation.SysLog;
|
||||
import com.bsd.pjcloud.common.security.annotation.Inner;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePackageDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.service.WalletRechargePackageService;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
@@ -43,6 +45,13 @@ public class WalletRechargePackageController {
|
||||
public R<WalletRechargePackageEntity> remoteGetById(@PathVariable("id") Long id) {
|
||||
return R.ok(walletRechargePackageService.getById(id));
|
||||
}
|
||||
|
||||
@Inner
|
||||
@Operation(summary = "支付成功", description = "支付成功")
|
||||
@PostMapping("/remote/pay-success")
|
||||
public R<Boolean> remotePaySuccess(@RequestBody WalletRechargePaySuccess dto) {
|
||||
return R.ok(walletRechargePackageService.remotePaySuccess(dto));
|
||||
}
|
||||
/* ************************************* end remote end ************************************* */
|
||||
|
||||
/* ************************************* start app start ************************************* */
|
||||
|
||||
+7
@@ -3,15 +3,22 @@ package com.bsd.pjcloud.wallet.service;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePackageDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargePackageVo;
|
||||
|
||||
public interface WalletRechargePackageService extends IService<WalletRechargePackageEntity> {
|
||||
|
||||
/**
|
||||
* 支付成功
|
||||
*/
|
||||
Boolean remotePaySuccess(WalletRechargePaySuccess dto);
|
||||
|
||||
Page<WalletRechargePackageVo> pageJoin(Page page, WalletRechargePackageDto dto);
|
||||
|
||||
/**
|
||||
* 校验是否有效
|
||||
*
|
||||
* @param packageId
|
||||
* @return
|
||||
*/
|
||||
|
||||
-9
@@ -17,25 +17,16 @@ public interface WalletRechargeService extends IService<WalletRechargeEntity> {
|
||||
|
||||
/**
|
||||
* app充值
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
WalletRechargeEntity createWalletRecharge(WalletAppRechargeDto dto);
|
||||
|
||||
/**
|
||||
* 远程调用-退款
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
WalletRechargeVo refund(WalletRechargeRefundDto dto);
|
||||
|
||||
|
||||
/**
|
||||
* 根据退款id查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
WalletRechargeEntity getByRefundId(Long refundId);
|
||||
}
|
||||
-16
@@ -38,32 +38,16 @@ public interface WalletTransactionService extends IService<WalletTransactionEnti
|
||||
|
||||
/**
|
||||
* 扣减钱包余额
|
||||
*
|
||||
* @param walletId 钱包 id
|
||||
* @param price 扣减金额
|
||||
* @param bizId 业务关联 id
|
||||
* @param bizType 业务关联分类
|
||||
* @return 钱包流水
|
||||
*/
|
||||
WalletTransactionEntity reduceWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType, Boolean force);
|
||||
|
||||
|
||||
/**
|
||||
* 增加钱包余额
|
||||
*
|
||||
* @param walletId 钱包 id
|
||||
* @param price 增加金额
|
||||
* @param bizId 业务关联 id
|
||||
* @param bizType 业务关联分类
|
||||
* @return 钱包流水
|
||||
*/
|
||||
WalletTransactionEntity addWalletBalance(Long walletId, Integer price, String bizId, WalletBizEnum bizType);
|
||||
|
||||
/**
|
||||
* 更新会员用户余额
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
Boolean updateWalletBalance(WalletTransactionDto dto);
|
||||
|
||||
|
||||
+55
-4
@@ -1,25 +1,76 @@
|
||||
package com.bsd.pjcloud.wallet.service.impl.recharge;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.thirdparty.constant.pay.ThirdPayOrderBizTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletBizEnum;
|
||||
import com.bsd.pjcloud.wallet.api.constant.WalletTypeEnum;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePackageDto;
|
||||
import com.bsd.pjcloud.wallet.api.dto.recharge.WalletRechargePaySuccess;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletManageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.WalletTransactionEntity;
|
||||
import com.bsd.pjcloud.wallet.api.entity.recharge.WalletRechargePackageEntity;
|
||||
import com.bsd.pjcloud.wallet.api.vo.recharge.WalletRechargePackageVo;
|
||||
import com.bsd.pjcloud.wallet.mapper.recharge.WalletRechargePackageMapper;
|
||||
import com.bsd.pjcloud.wallet.service.WalletManageService;
|
||||
import com.bsd.pjcloud.wallet.service.WalletRechargePackageService;
|
||||
import com.bsd.pjcloud.wallet.service.WalletTransactionService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* 充值套餐表
|
||||
*
|
||||
* @author dzc
|
||||
* @date 2025-01-03 18:33:55
|
||||
* 充值套餐
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class WalletRechargePackageServiceImpl extends ServiceImpl<WalletRechargePackageMapper, WalletRechargePackageEntity> implements WalletRechargePackageService {
|
||||
|
||||
static private final String TAG = "充值套餐";
|
||||
|
||||
private final WalletManageService walletManageService;
|
||||
private final WalletTransactionService walletTransactionService;
|
||||
|
||||
/**
|
||||
* 支付成功的回调
|
||||
*/
|
||||
@Override
|
||||
public Boolean remotePaySuccess(WalletRechargePaySuccess dto) {
|
||||
// 小程序用户钱包充值
|
||||
if (ObjectUtil.equals(dto.getBizType(), ThirdPayOrderBizTypeEnum.MINI_APP_WALLET_RECHARGE.getType())) {
|
||||
// 查询充值套餐
|
||||
WalletRechargePackageEntity rechargePackage = baseMapper.selectById(dto.getBizId());
|
||||
if (ObjectUtil.isEmpty(rechargePackage)) {
|
||||
log.error("{}支付成功的回调,充值套餐不存在,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
// 需要充值的金额
|
||||
Integer totalPrice = rechargePackage.getPayPrice() + rechargePackage.getBonusPrice();
|
||||
if (totalPrice <= 0) {
|
||||
log.error("{}支付成功的回调,充值套餐金额<=0,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
// 查询这个用户的充值钱包
|
||||
WalletManageEntity topupWallet = walletManageService.getWallet(dto.getUserId(), WalletTypeEnum.TOPUP);
|
||||
if (ObjectUtil.isEmpty(topupWallet)) {
|
||||
log.error("{}支付成功的回调,查询这个用户的充值钱包,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
// 进行充值
|
||||
WalletTransactionEntity walletTransaction = walletTransactionService.addWalletBalance(topupWallet.getId(), totalPrice, dto.getPayNo(), WalletBizEnum.RECHARGE);
|
||||
return ObjectUtil.isNotEmpty(walletTransaction);
|
||||
}
|
||||
// 不支持的类型
|
||||
else {
|
||||
log.error("{}支付成功的回调,不支持的类型,dto:{}", TAG, JSONUtil.toJsonStr(dto));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<WalletRechargePackageVo> pageJoin(Page page, WalletRechargePackageDto dto) {
|
||||
return baseMapper.pageJoin(page, dto);
|
||||
|
||||
Reference in new issue
Block a user