diff --git a/db/810pjcloudx_wallet_act.sql b/db/810pjcloudx_wallet_act.sql index fd86effd1..aa4b3912f 100644 --- a/db/810pjcloudx_wallet_act.sql +++ b/db/810pjcloudx_wallet_act.sql @@ -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 ='优惠券领取记录表'; \ No newline at end of file diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/entity/pay/ThirdPayOrderEntity.java b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/entity/pay/ThirdPayOrderEntity.java index 11c27dbd4..8207b6ae2 100755 --- a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/entity/pay/ThirdPayOrderEntity.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/entity/pay/ThirdPayOrderEntity.java @@ -81,6 +81,12 @@ public class ThirdPayOrderEntity extends Model { @Schema(description = "支付时间") private LocalDateTime payTime; + /** + * 支付参数 + */ + @Schema(description = "支付参数") + private String payRep; + /** * 支付返回 */ @@ -99,6 +105,12 @@ public class ThirdPayOrderEntity extends Model { @Schema(description = "退款时间") private LocalDateTime refundTime; + /** + * 退款参数 + */ + @Schema(description = "退款参数") + private String refundRep; + /** * 退款返回 */ diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatQueryVo.java b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatQueryVo.java index c444c19b7..27c956cee 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatQueryVo.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatQueryVo.java @@ -122,4 +122,19 @@ public class ThirdMiniWechatQueryVo { public boolean isPaySucess() { return ObjectUtil.equals(ThirdMiniWechatQueryVo.SUCCESS, result_code); } + + public static String wechantError() { + return "" + + "" + + "" + + ""; + } + + public static String wechantSuccess() { + return "" + + " " + + " \n" + + ""; + } + } diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatRefundQueryVo.java b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatRefundQueryVo.java index 4b335d07b..92f2a4e13 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatRefundQueryVo.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-api/src/main/java/com/bsd/pjcloud/thirdparty/vo/oathmini/pay/wechat/ThirdMiniWechatRefundQueryVo.java @@ -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 "" + + "" + + "" + + ""; + } + + public static String wechantSuccess() { + return "" + + " " + + " \n" + + ""; + } + } diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdMiniAppWechatService.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdMiniAppWechatService.java index fcac1eb70..552543ced 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdMiniAppWechatService.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdMiniAppWechatService.java @@ -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 headers); + /** * 退款回调 */ diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdPayOrderService.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdPayOrderService.java index e32d92e9e..68b9c61ea 100755 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdPayOrderService.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/ThirdPayOrderService.java @@ -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 { Page scopePage(Page page, ThirdPayOrderDto dto, DataScope dataScope); + default ThirdPayOrderEntity getByPayNo(String payNo) { + return getOne(new LambdaQueryWrapper().eq(ThirdPayOrderEntity::getPayNo, payNo)); + } + } \ No newline at end of file diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppServiceImpl.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppServiceImpl.java index 3ed3ab022..9f30b1b91 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppServiceImpl.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppServiceImpl.java @@ -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 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; + } } /** diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppWechatServiceImpl.java b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppWechatServiceImpl.java index 13b0a5daa..980d66631 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppWechatServiceImpl.java +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/java/com/bsd/pjcloud/thirdparty/service/impl/miniapp/ThirdMiniAppWechatServiceImpl.java @@ -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 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 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()); + } + /** * 退款回调 */ diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/application.yml b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/application.yml index a1250c208..f7dd38a16 100644 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/application.yml +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/application.yml @@ -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: diff --git a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/mapper/ThirdPayOrderMapper.xml b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/mapper/ThirdPayOrderMapper.xml index ca6862101..376a66a5a 100755 --- a/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/mapper/ThirdPayOrderMapper.xml +++ b/pjcloud-thirdparty/pjcloud-thirdparty-biz/src/main/resources/mapper/ThirdPayOrderMapper.xml @@ -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 @@ a.del_flag = '0' + + and a.pay_no LIKE concat('%',#{dto.payNo},'%') + and a.id = #{dto.id} diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/recharge/WalletRechargePaySuccess.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/recharge/WalletRechargePaySuccess.java new file mode 100644 index 000000000..25518965b --- /dev/null +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/dto/recharge/WalletRechargePaySuccess.java @@ -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; + +} diff --git a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletRechargePackageService.java b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletRechargePackageService.java index 1a6ca9eaf..b2db8d400 100644 --- a/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletRechargePackageService.java +++ b/pjcloud-wallet/pjcloud-wallet-api/src/main/java/com/bsd/pjcloud/wallet/api/feign/RemoteWalletRechargePackageService.java @@ -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 remoteGetById(@PathVariable("id") Long id); + @NoToken + @PostMapping("/wallet-recharge-package/remote/pay-success") + R remotePaySuccess(@RequestBody WalletRechargePaySuccess dto); + } diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargePackageController.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargePackageController.java index 94dfe8a03..cb2b5af8d 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargePackageController.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/controller/recharge/WalletRechargePackageController.java @@ -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 remoteGetById(@PathVariable("id") Long id) { return R.ok(walletRechargePackageService.getById(id)); } + + @Inner + @Operation(summary = "支付成功", description = "支付成功") + @PostMapping("/remote/pay-success") + public R remotePaySuccess(@RequestBody WalletRechargePaySuccess dto) { + return R.ok(walletRechargePackageService.remotePaySuccess(dto)); + } /* ************************************* end remote end ************************************* */ /* ************************************* start app start ************************************* */ diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargePackageService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargePackageService.java index 533f005c4..8c173d9d1 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargePackageService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargePackageService.java @@ -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 { + /** + * 支付成功 + */ + Boolean remotePaySuccess(WalletRechargePaySuccess dto); + Page pageJoin(Page page, WalletRechargePackageDto dto); /** * 校验是否有效 + * * @param packageId * @return */ diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeService.java index 5913a3a91..ff599ce08 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletRechargeService.java @@ -17,25 +17,16 @@ public interface WalletRechargeService extends IService { /** * app充值 - * - * @param dto - * @return */ WalletRechargeEntity createWalletRecharge(WalletAppRechargeDto dto); /** * 远程调用-退款 - * - * @param dto - * @return */ WalletRechargeVo refund(WalletRechargeRefundDto dto); - /** * 根据退款id查询 - * - * @return */ WalletRechargeEntity getByRefundId(Long refundId); } \ No newline at end of file diff --git a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java index 05a25fa45..66f7f9174 100644 --- a/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java +++ b/pjcloud-wallet/pjcloud-wallet-biz/src/main/java/com/bsd/pjcloud/wallet/service/WalletTransactionService.java @@ -38,32 +38,16 @@ public interface WalletTransactionService extends IService 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 pageJoin(Page page, WalletRechargePackageDto dto) { return baseMapper.pageJoin(page, dto);