From 394fa8d8be7bdd59c9cb247cfcf45f2c30815819 Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Sat, 20 Jan 2024 22:03:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E5=AD=A6=E5=90=8E=E4=BB=98=E7=AD=BE?= =?UTF-8?q?=E7=BA=A6,=E6=A0=B8=E9=94=80,=E5=8F=96=E6=B6=88=E7=AD=BE?= =?UTF-8?q?=E7=BA=A6=EF=BC=9B=E8=B0=83=E6=95=B4=E4=BA=91=E5=87=BD=E6=95=B0?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AF=BE=E5=8D=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/cloudDb/core/constant/CloudDbUrl.java | 2 +- .../cloudDb/core/dto/CloudClassCardDto.java | 73 ++++- .../handler/CloudClassCardHandler.java | 25 +- .../cloudDb/handler/CloudStoreHandler.java | 9 +- .../com/cpop/core/base/enums/OrderSource.java | 10 +- .../business/bo/LearnNowPayLaterPlanBo.java | 6 + .../bo/LearnNowPayLaterServiceOrderBo.java | 77 +++++ .../LearnNowPayLaterStopUserSignPlansBo.java | 26 ++ .../bo/LearnNowPayLaterUserSignPlansBo.java | 56 ++++ .../callback/CallBackEasyLearnController.java | 51 ++++ .../callback/EasyLearnCallBackController.java | 2 + ...r.java => MiniCardTemplateController.java} | 4 +- .../mini/MiniEasyLearnController.java | 36 ++- .../service/EasyLearnOrderService.java | 42 +++ .../service/impl/CardTemplateServiceImpl.java | 13 +- .../impl/EasyLearnOrderServiceImpl.java | 270 +++++++++++++++++- .../vo/LearnNowPayLaterPlanDetailVo.java | 8 +- .../framework/tasks/LearnNowPayLaterTask.java | 4 +- .../src/main/resources/application-dev.yml | 4 + .../com/cpop/oam/web/CpopDataSyncTests.java | 25 +- .../config/wxPay/WxPayProperties.java | 10 + .../framewok/handler/wxPay/WxPayHandler.java | 31 +- .../pay/framewok/task/WxPayAsyncTask.java | 2 +- .../system/business/entity/WxPayScore.java | 11 +- 24 files changed, 735 insertions(+), 62 deletions(-) create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterServiceOrderBo.java create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterStopUserSignPlansBo.java create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterUserSignPlansBo.java create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/CallBackEasyLearnController.java rename Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/{CardTemplateController.java => MiniCardTemplateController.java} (95%) diff --git a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/constant/CloudDbUrl.java b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/constant/CloudDbUrl.java index ed157d2..63af53c 100644 --- a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/constant/CloudDbUrl.java +++ b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/constant/CloudDbUrl.java @@ -14,7 +14,7 @@ public interface CloudDbUrl { /** * 课卡相关云函数 */ - String COMMON_CARD_URL = BASE_URL + "/merchant_cloud"; + String COMMON_USE_URL = BASE_URL + "/merchant_cloud"; /** * 查询云数据专用 diff --git a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/dto/CloudClassCardDto.java b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/dto/CloudClassCardDto.java index e49c83c..2329351 100644 --- a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/dto/CloudClassCardDto.java +++ b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/core/dto/CloudClassCardDto.java @@ -3,8 +3,6 @@ package com.cpop.api.cloudDb.core.dto; import com.google.gson.annotations.SerializedName; import lombok.Data; -import java.time.OffsetDateTime; - /** * @author DB * @version 1.0.0 @@ -101,4 +99,75 @@ public class CloudClassCardDto { @SerializedName("isDrainage") private boolean isDrainageCard; + /** + * 实收金额 + */ + @SerializedName("money") + private String payAmount; + + /** + * 云校区id + */ + @SerializedName("storeId") + private String storeCloudId; + + /** + * 客户手机号 + */ + @SerializedName("phone") + private String customerPhone; + + /** + * 模板id + */ + @SerializedName("templateId") + private String orderCloudId; + + /** + * 订单来源 + */ + private String orderSource; + + /** + * 子商户 + */ + private String subMchId; + + /** + * 模板路径 + */ + private String templateUrl; + + /** + * 客户openid + */ + @SerializedName("openid") + private String openId; + + /** + * 商户侧签约计划号 + */ + private String merchantSignPlanNo; + + /** + * 签约计划id + */ + private String signPlanId; + + /** + * 计划id + */ + private String planId; + + /** + * 每期课次 + */ + private Integer classHour; + + /** + * 签约计划详情,json格式 + */ + @SerializedName("signedDetailList") + private String signPlanDetails; + } diff --git a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudClassCardHandler.java b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudClassCardHandler.java index fee239d..f36e035 100644 --- a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudClassCardHandler.java +++ b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudClassCardHandler.java @@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSONObject; import com.cpop.api.cloudDb.core.constant.CloudDbUrl; import com.cpop.api.cloudDb.core.dto.CloudClassCardDto; import com.cpop.api.cloudDb.core.dto.CloudClassCardRecordDto; -import com.cpop.api.cloudDb.core.dto.CloudClassStudentDto; import com.cpop.common.utils.StringUtils; import com.cpop.core.base.entity.ExtendPage; +import com.cpop.core.base.exception.ServiceException; import com.cpop.core.base.exception.UtilException; import com.mybatisflex.core.paginate.Page; import org.springframework.beans.factory.annotation.Autowired; @@ -139,4 +139,27 @@ public class CloudClassCardHandler { return page; } } + + /** + * 添加课卡 + * @author DB + * @since 2024/1/20 + * @param dto 课卡中间表 + * @return String + */ + public String insertCloudClassCard(CloudClassCardDto dto){ + JSONObject jsonBody = JSONObject.parseObject(JSONObject.toJSONString(dto)); + jsonBody.put("_type", "addPeriod"); + JSONObject result = restTemplate.postForObject(CloudDbUrl.COMMON_USE_URL, jsonBody, JSONObject.class); + if (result != null) { + if (result.getBoolean("success")) { + return result.getString("data"); + } else { + throw new UtilException(result.getString("error")); + } + } else { + throw new ServiceException("办卡失败!"); + } + + } } diff --git a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudStoreHandler.java b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudStoreHandler.java index 25420ad..3f415ab 100644 --- a/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudStoreHandler.java +++ b/Cpop-Api/src/main/java/com/cpop/api/cloudDb/handler/CloudStoreHandler.java @@ -2,20 +2,13 @@ package com.cpop.api.cloudDb.handler; import com.alibaba.fastjson.JSONObject; import com.cpop.api.cloudDb.core.constant.CloudDbUrl; -import com.cpop.api.cloudDb.core.dto.CloudOrderDto; import com.cpop.api.cloudDb.core.dto.CloudStoreDto; import com.cpop.common.utils.StringUtils; -import com.cpop.core.base.entity.ExtendPage; import com.cpop.core.base.exception.UtilException; -import com.mybatisflex.core.paginate.Page; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * 云校区工具类 * @author DB @@ -54,7 +47,7 @@ public class CloudStoreHandler { if (StringUtils.isNotBlank(dto.getStoreAddr())) { jsonBody.put("address", dto.getStoreAddr()); } - JSONObject jsonObject = restTemplate.postForObject(CloudDbUrl.COMMON_CARD_URL, jsonBody, JSONObject.class); + JSONObject jsonObject = restTemplate.postForObject(CloudDbUrl.COMMON_USE_URL, jsonBody, JSONObject.class); if (jsonObject != null) { if (!jsonObject.getBoolean("success")) { throw new UtilException(jsonObject.getString("error")); diff --git a/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java b/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java index 8b93cf7..fb981da 100644 --- a/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java +++ b/Cpop-Core/src/main/java/com/cpop/core/base/enums/OrderSource.java @@ -14,9 +14,15 @@ public enum OrderSource { MALL("Mall",0.002), /** - * 微信支付 + * 一次性支付 */ - EASY_LEARN("EasyLearn",0.002); + EASY_LEARN("EasyLearn",0.002), + + /** + * 先学后付 + */ + LEARN_NOW_PAY_LATER("LearnNowPayLater",0.06) + ; OrderSource(String name, Double rate) { this.rate = rate; diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterPlanBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterPlanBo.java index e2e8f9a..4a3c4c6 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterPlanBo.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterPlanBo.java @@ -61,4 +61,10 @@ public class LearnNowPayLaterPlanBo { @ApiModelProperty("支付分计划明细列表") private List planDetailList; + /** + * 课次 + */ + @ApiModelProperty("支付分计划原总金额") + private String classHour; + } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterServiceOrderBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterServiceOrderBo.java new file mode 100644 index 0000000..f811093 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterServiceOrderBo.java @@ -0,0 +1,77 @@ +package com.cpop.jambox.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-20 12:33 + */ +@Data +@ApiModel(value = "先学后付用户核销") +public class LearnNowPayLaterServiceOrderBo { + + /** + * 支付分订单在商户侧的订单号,必须和创建签约计划时传入的该笔订单对应的商户侧计划明细使用订单号(merchant\_plan\_detail\_no)一致 + */ + @NotBlank(message = "待创建服务订单对应的用户的签约计划不能为空") + @ApiModelProperty(value = "待创建服务订单对应的用户的签约计划",required = true) + private String signPlanId; + + /** + * 待创建服务订单对应的用户的签约计划详情序号 + */ + @NotNull(message = "planDetailNo不能为空") + @ApiModelProperty(value = "待创建服务订单对应的用户的签约计划详情序号",required = true) + private Integer planDetailNo; + + /** + * 服务商公众号下的用户标识 + */ + @NotBlank(message = "openid不能为空") + @ApiModelProperty(value = "服务商公众号下的用户标识",required = true) + private String openid; + + /** + * 支付分订单在商户侧的订单号,必须和创建签约计划时传入的该笔订单对应的商户侧计划明细使用订单号(merchant\_plan\_detail\_no)一致 + */ + @NotBlank(message = "outTradeNo不能为空") + @ApiModelProperty(value = "支付分订单在商户侧的订单号,必须和创建签约计划时传入的该笔订单对应的商户侧计划明细使用订单号(merchant_plan_detail_no)一致",required = true) + private String outTradeNo; + + /** + * 卡号 + */ + @NotBlank(message = "cardNo不能为空") + @ApiModelProperty(value = "卡号",required = true) + private String cardNo; + + + + /** + * 课程信息 + */ + @NotBlank(message = "课程信息不能为空") + @ApiModelProperty(value = "课程信息",required = true) + private String serviceIntroduction; + + /** + * 核销金额 + */ + @NotNull(message = "核销金额不能为空") + @ApiModelProperty(value = "核销金额",required = true) + private Integer price; + + /** + * 是否是旧卡 + */ + @ApiModelProperty(value = "是否是旧卡") + private Boolean isOldCard; + + +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterStopUserSignPlansBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterStopUserSignPlansBo.java new file mode 100644 index 0000000..6e10eb3 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterStopUserSignPlansBo.java @@ -0,0 +1,26 @@ +package com.cpop.jambox.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-20 15:01 + */ +@Data +@ApiModel(value = "停止用户签约计划") +public class LearnNowPayLaterStopUserSignPlansBo { + + /** + * 签约计划id + */ + @ApiModelProperty(value = "签约计划id") + private String signPlanId; + + /** + * 取消理由 + */ + private String stopReason; +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterUserSignPlansBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterUserSignPlansBo.java new file mode 100644 index 0000000..3ee1da8 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/LearnNowPayLaterUserSignPlansBo.java @@ -0,0 +1,56 @@ +package com.cpop.jambox.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-19 22:40 + */ +@Data +@ApiModel(value = "先学后付用户签约计划") +public class LearnNowPayLaterUserSignPlansBo { + + /** + * 支付分id + */ + @NotBlank(message = "支付分id不能为空") + @ApiModelProperty(value = "支付分id",required = true) + private String id; + + /** + * 云校区id + */ + @NotBlank(message = "云校区id不能为空") + @ApiModelProperty(value = "云校区id",required = true) + private String storeCloudId; + + /** + * 子商户下用户openid + */ + @NotBlank(message = "子商户下用户openid不能为空") + @ApiModelProperty(value = "子商户下用户openid",required = true) + private String subOpenId; + + /** + * 支付分计划名称 + */ + @ApiModelProperty("支付分计划名称") + private String planName; + + /** + * 客户名 + */ + @ApiModelProperty("客户名") + private String customerName; + + /** + * 客户手机号 + */ + @ApiModelProperty("客户手机号") + private String customerPhone; +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/CallBackEasyLearnController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/CallBackEasyLearnController.java new file mode 100644 index 0000000..019efde --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/CallBackEasyLearnController.java @@ -0,0 +1,51 @@ +package com.cpop.jambox.business.controller.callback; + +import com.cpop.jambox.business.service.EasyLearnOrderService; +import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @author DB + * @version 1.0.0 + * @since 2024-01-20 0:22 + */ +@RestController +@Api(tags = "果酱-放心学回调接口") +@RequestMapping("/callback/easyLearn") +public class CallBackEasyLearnController { + + @Autowired + private EasyLearnOrderService easyLearnOrderService; + + /** + * 用户签约成功回调 + * @author DB + * @since 2024/1/20 + * @param notifyData 返回参数 + */ + @ApiOperation("放心学先学后付支付分回调通知") + @PostMapping("/learnNowPayLaterUserSignPlanNotify") + public String learnNowPayLaterUserSignPlanNotifyUrl(@RequestBody String notifyData) { + easyLearnOrderService.learnNowPayLaterUserSignPlanNotify(notifyData); + return WxPayNotifyResponse.success("成功"); + } + + /** + * 支付分用户核销成功回调 + * @author DB + * @since 2024/1/20 + * @param notifyData 返回参数 + */ + @ApiOperation("支付分用户核销成功回调") + @PostMapping("/userServiceOrderSuccess") + public String userServiceOrderSuccess(@RequestBody String notifyData) { + easyLearnOrderService.userServiceOrderSuccess(notifyData); + return WxPayNotifyResponse.success("成功"); + } +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/EasyLearnCallBackController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/EasyLearnCallBackController.java index 51fd1e3..15ec023 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/EasyLearnCallBackController.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/EasyLearnCallBackController.java @@ -46,4 +46,6 @@ public class EasyLearnCallBackController { return WxPayNotifyResponse.success("成功"); } + + } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/CardTemplateController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniCardTemplateController.java similarity index 95% rename from Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/CardTemplateController.java rename to Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniCardTemplateController.java index 0d594f9..784add9 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/CardTemplateController.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniCardTemplateController.java @@ -1,6 +1,5 @@ package com.cpop.jambox.business.controller.mini; -import com.cpop.core.annontation.SimpleSignatureCheck; import com.cpop.core.base.R; import com.cpop.core.utils.SpringUtils; import com.cpop.jambox.business.bo.CardTemplateUnionBo; @@ -9,7 +8,6 @@ import com.cpop.jambox.business.service.CardTemplateExtendService; import com.cpop.jambox.business.service.CardTemplateService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.apache.ibatis.annotations.Delete; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -26,7 +24,7 @@ import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TE @RestController @Api(tags = "果酱-课卡模板接口") @RequestMapping("/mini/cardTemplate") -public class CardTemplateController { +public class MiniCardTemplateController { @Autowired private CardTemplateService cardTemplateService; diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java index 524af37..14f4a93 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/mini/MiniEasyLearnController.java @@ -1,14 +1,19 @@ package com.cpop.jambox.business.controller.mini; import com.cpop.core.base.R; +import com.cpop.jambox.business.bo.LearnNowPayLaterServiceOrderBo; +import com.cpop.jambox.business.bo.LearnNowPayLaterStopUserSignPlansBo; +import com.cpop.jambox.business.bo.LearnNowPayLaterUserSignPlansBo; import com.cpop.jambox.business.service.CardTemplateService; import com.cpop.jambox.business.service.EasyLearnOrderService; -import com.cpop.jambox.business.vo.LearnNowPayLaterPlanDetailVo; import com.cpop.jambox.business.vo.LearnNowPayLaterPlanVo; +import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanResult; +import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreUserSignPlanResult; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; /** @@ -46,25 +51,42 @@ public class MiniEasyLearnController { /** * 获取支付分计划 * - * @param oldTemplateId 旧模板id - * @param isMonth 是否月付 + * @param bo 请求参数 * @return R * @author DB * @since 2024/1/18 */ @ApiOperation("创建用户签约计划") @PostMapping("/createUserSignPlans") - public R createUserSignPlans(@ApiParam(value = "旧模板id", required = true) @RequestParam("oldTemplateId") String oldTemplateId, - @ApiParam(value = "是否月付(0否1是)", required = true) @RequestParam("isMonth") Boolean isMonth) { - return R.ok(); + public R createUserSignPlans(@RequestBody @Validated LearnNowPayLaterUserSignPlansBo bo) { + WxPartnerPayScoreUserSignPlanResult result = easyLearnOrderService.createUserSignPlans(bo); + return R.ok(result); } /** * 创建用户服务订单(核销) + * @author DB + * @since 2024/1/20 + * @param bo 请求参数 */ @ApiOperation("创建用户服务订单(核销)") @PostMapping("/createServiceOrder") - public R createServiceOrder() { + public R createServiceOrder(@RequestBody @Validated LearnNowPayLaterServiceOrderBo bo) { + WxPartnerPayScoreSignPlanResult result = easyLearnOrderService.createServiceOrder(bo); + return R.ok(result); + } + + /** + * 取消用户签约计划 + * @author DB + * @since 2024/1/20 + * @param bo 请求参数 + * @return R + */ + @ApiOperation("取消用户签约计划") + @PostMapping("/stopUserSignPlans/{signPlanId}") + public R stopUserSignPlans(@RequestBody @Validated LearnNowPayLaterStopUserSignPlansBo bo){ + easyLearnOrderService.stopUserSignPlans(bo); return R.ok(); } } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/EasyLearnOrderService.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/EasyLearnOrderService.java index 10d2035..16f206c 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/EasyLearnOrderService.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/EasyLearnOrderService.java @@ -4,6 +4,8 @@ import com.cpop.jambox.business.bo.*; import com.cpop.jambox.business.dto.EasyLearnPageDto; import com.cpop.jambox.business.entity.EasyLearnOrder; import com.cpop.jambox.business.vo.EasyLearnPageVo; +import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanResult; +import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreUserSignPlanResult; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.service.IService; @@ -75,4 +77,44 @@ public interface EasyLearnOrderService extends IService { */ Object unifiedPay(EasyLearnUnifiedPayBo bo); + /** + * 创建用户签约计划 + * @author DB + * @since 2024/1/19 + * @param bo 请求参数 + */ + WxPartnerPayScoreUserSignPlanResult createUserSignPlans(LearnNowPayLaterUserSignPlansBo bo); + + /** + * 用户签约成功回调 + * @author DB + * @since 2024/1/20 + * @param notifyData 返回参数 + */ + void learnNowPayLaterUserSignPlanNotify(String notifyData); + + /** + * 创建用户服务订单(核销) + * @author DB + * @since 2024/1/20 + * @param bo 请求参数 + * @return WxPartnerPayScoreSignPlanResult + */ + WxPartnerPayScoreSignPlanResult createServiceOrder(LearnNowPayLaterServiceOrderBo bo); + + /** + * 支付分用户核销成功回调 + * @author DB + * @since 2024/1/20 + * @param notifyData 返回数据 + */ + void userServiceOrderSuccess(String notifyData); + + /** + * 取消用户签约计划 + * @author DB + * @since 2024/1/20 + * @param bo 请求参数 + */ + void stopUserSignPlans(LearnNowPayLaterStopUserSignPlansBo bo); } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java index 23b3417..7ed2da7 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/CardTemplateServiceImpl.java @@ -19,6 +19,7 @@ import com.cpop.jambox.business.vo.LearnNowPayLaterPlanDetailVo; import com.cpop.jambox.business.vo.LearnNowPayLaterPlanVo; import com.cpop.jambox.framework.tasks.LearnNowPayLaterTask; import com.cpop.system.business.entity.Store; +import com.cpop.system.business.entity.WxPayScore; import com.cpop.system.business.entity.WxPayScoreDetail; import com.cpop.system.business.service.StoreService; import com.cpop.system.business.service.WxPayScoreDetailService; @@ -288,12 +289,12 @@ public class CardTemplateServiceImpl extends ServiceImpl detailVos = SpringUtils.getBean(WxPayScoreDetailService.class).listAs(QueryWrapper.create() - .where(WX_PAY_SCORE_DETAIL.SYS_WX_PAY_SCORE_ID.eq(vo.getId())), - LearnNowPayLaterPlanDetailVo.class); + WxPayScore wxPayScore = SpringUtils.getBean(WxPayScoreService.class).getOne(QueryWrapper.create() + .where(WX_PAY_SCORE.ID.eq(cardTemplateExtend.getExtendId()))); + LearnNowPayLaterPlanVo vo = BeanUtils.mapToClass(wxPayScore, LearnNowPayLaterPlanVo.class); + List wxPayScoreDetails = SpringUtils.getBean(WxPayScoreDetailService.class).list(QueryWrapper.create() + .where(WX_PAY_SCORE_DETAIL.SYS_WX_PAY_SCORE_ID.eq(vo.getId()))); + List detailVos = BeanUtils.mapToList(wxPayScoreDetails, LearnNowPayLaterPlanDetailVo.class); vo.setPlanDetailList(detailVos); return vo; } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/EasyLearnOrderServiceImpl.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/EasyLearnOrderServiceImpl.java index 9d37bc7..b8252e9 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/EasyLearnOrderServiceImpl.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/service/impl/EasyLearnOrderServiceImpl.java @@ -1,6 +1,9 @@ package com.cpop.jambox.business.service.impl; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.cpop.api.cloudDb.core.dto.CloudClassCardDto; +import com.cpop.api.cloudDb.handler.CloudClassCardHandler; import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.common.utils.http.HttpUtils; @@ -15,11 +18,12 @@ import com.cpop.core.utils.sql.SqlUtils; import com.cpop.jambox.business.bo.*; import com.cpop.jambox.business.dto.EasyLearnPageDto; import com.cpop.jambox.business.entity.BrandExtend; -import com.cpop.jambox.business.entity.CardTemplate; import com.cpop.jambox.business.entity.EasyLearnOrder; +import com.cpop.jambox.business.entity.EasyLearnOrderDetail; import com.cpop.jambox.business.entity.StoreExtend; import com.cpop.jambox.business.mapper.EasyLearnOrderMapper; import com.cpop.jambox.business.service.BrandExtendService; +import com.cpop.jambox.business.service.EasyLearnOrderDetailService; import com.cpop.jambox.business.service.EasyLearnOrderService; import com.cpop.jambox.business.service.StoreExtendService; import com.cpop.jambox.business.vo.EasyLearnPageVo; @@ -30,11 +34,18 @@ import com.cpop.pay.framewok.config.wxPay.WxPayConfiguration; import com.cpop.pay.framewok.handler.wxPay.WxPayHandler; import com.cpop.pay.framewok.task.WxPayAsyncTask; import com.cpop.system.business.entity.Store; +import com.cpop.system.business.entity.WxPayScore; +import com.cpop.system.business.entity.WxPayScoreDetail; import com.cpop.system.business.service.StoreService; +import com.cpop.system.business.service.WxPayScoreDetailService; +import com.cpop.system.business.service.WxPayScoreService; +import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; +import com.github.binarywang.wxpay.bean.payscore.*; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.config.WxPayConfig; import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.PartnerPayScoreSignPlanService; import com.github.binarywang.wxpay.service.WxPayService; import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.datasource.DataSourceKey; @@ -53,13 +64,19 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.web.client.RestTemplate; import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.concurrent.locks.Lock; import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND; +import static com.cpop.jambox.business.entity.table.EasyLearnOrderDetailTableDef.EASY_LEARN_ORDER_DETAIL; import static com.cpop.jambox.business.entity.table.EasyLearnOrderTableDef.EASY_LEARN_ORDER; import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND; +import static com.cpop.system.business.entity.table.StoreTableDef.STORE; +import static com.cpop.system.business.entity.table.WxPayScoreDetailTableDef.WX_PAY_SCORE_DETAIL; /** * 果酱-放心学订单表 服务层实现。 @@ -77,6 +94,9 @@ public class EasyLearnOrderServiceImpl extends ServiceImpl wxPayScoreDetails = SpringUtils.getBean(WxPayScoreDetailService.class).queryChain() + .where(WX_PAY_SCORE_DETAIL.SYS_WX_PAY_SCORE_ID.eq(bo.getId())) + .list(); + Row brandAndStore = Db.selectOneByQuery(QueryWrapper.create() + .select(STORE.ID,STORE.BRAND_ID) + .leftJoin(STORE_EXTEND).on(STORE_EXTEND.STORE_ID.eq(STORE.ID)) + .where(STORE_EXTEND.STORE_CLOUD_ID.eq(bo.getStoreCloudId()))); + //创建用户签约计划 + String orderId = createEasyLearnUserSignPlans(bo, brandAndStore, wxPayScore); + String subMchId = wxPayHandler.getSubMchId(brandAndStore.getString("brandId"), brandAndStore.getString("id")); + WxPayService wxPayService = wxPayHandler.getWxPayService(null, subMchId); + PartnerPayScoreSignPlanService partnerPayScoreSignPlanService = wxPayService.getPartnerPayScoreSignPlanService(); + List payScorePlanDetailRequests = BeanUtils.mapToList(wxPayScoreDetails, PayScorePlanDetailRequest.class); + WxPartnerPayScoreSignPlanRequest signPlanRequest = new WxPartnerPayScoreSignPlanRequest(); + signPlanRequest.setPlanId(wxPayScore.getOutPlanId()).setSubAppid(subMchId) + .setSubOpenid(bo.getSubOpenId()) + .setMerchantSignPlanNo(orderId) + .setPlanDetailList(payScorePlanDetailRequests) + .setNotifyUrl(wxPayConfiguration.getProperties().getLearnNowPayLaterUserSignPlanNotifyUrl()); + try { + return partnerPayScoreSignPlanService.createUserSignPlans(signPlanRequest); + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + /** + * 创建用户支付计划 + * @author DB + * @since 2024/1/19 + * @param wxPayScore 支付分 + * @return String + */ + private String createEasyLearnUserSignPlans(LearnNowPayLaterUserSignPlansBo bo, Row brandAndStore, WxPayScore wxPayScore) { + EasyLearnOrder easyLearnOrder = new EasyLearnOrder(); + easyLearnOrder.setBrandId(brandAndStore.getString("brandId")) + .setStoreId(brandAndStore.getString("id")) + .setOrderContent(bo.getPlanName()) + .setOrderStatus(0) + .setCustomerName(bo.getCustomerName()) + .setCustomerPhone(bo.getCustomerPhone()) + .setTotalAmount(new BigDecimal(wxPayScore.getTotalOriginalPrice()).divide(BigDecimal.valueOf(100))) + .setTotalPayAmount(BigDecimal.ZERO) + .setOrderType(0) + .setRate(OrderSource.LEARN_NOW_PAY_LATER.getRate()); + this.save(easyLearnOrder); + return easyLearnOrder.getId(); + } + + /** + * 用户签约成功回调 + * @author DB + * @since 2024/1/20 + * @param notifyData 响应数据 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void learnNowPayLaterUserSignPlanNotify(String notifyData) { + try { + PayScoreNotifyData payScoreNotifyData = JSONObject.parseObject(notifyData, PayScoreNotifyData.class); + PartnerPayScoreSignPlanService partnerPayScoreSignPlanService = wxPayHandler.getWxPayService().getPartnerPayScoreSignPlanService(); + SignatureHeader signatureHeader = wxPayHandler.getSignatureHeader(); + PartnerUserSignPlanEntity result = partnerPayScoreSignPlanService.parseSignPlanNotifyResult(notifyData, signatureHeader); + String orderId = result.getMerchantSignPlanNo(); + EasyLearnOrder easyLearnOrder = this.getById(orderId); + //支付成功 + if (StringUtils.equals("PAYSCORE.USER_SIGN_PLAN", payScoreNotifyData.getEventType())) { + //订单已支付 + if (easyLearnOrder.getOrderStatus() == 1){ + return; + } + easyLearnOrder.setOrderStatus(1).setOutOrderNo(result.getSignPlanId()); + //添加支付分详情 + List easyLearnOrderDetails = new ArrayList<>(); + result.getSignedDetailList().forEach(item->{ + EasyLearnOrderDetail easyLearnOrderDetail = new EasyLearnOrderDetail(); + easyLearnOrderDetail.setOrderId(easyLearnOrder.getId()) + .setPeriodNo(item.getPlanDetailNo()) + .setAmount(new BigDecimal(item.getOriginalPrice()).divide(BigDecimal.valueOf(100))) + .setDetailDesc(item.getPlanDiscountDescription()) + .setActualPrice(new BigDecimal(item.getActualPrice()).divide(BigDecimal.valueOf(100))) + .setDetailStatus(0) + .setOutOrderNo(item.getOrderId()) + .setDetailName(item.getPlanDetailName()); + easyLearnOrderDetails.add(easyLearnOrderDetail); + }); + SpringUtils.getBean(EasyLearnOrderDetailService.class).saveBatch(easyLearnOrderDetails); + //云办卡 + CloudClassCardDto dto = new CloudClassCardDto(); + //TODO: 模板路径的用途 + //dto.setTemplateUrl(); + //jsonObject.put("templateUrl", templateUrl); + // jsonObject.put("templateUrl", "https://test.cpopsz.com/test/ass/"); + // jsonObject.put("templateUrl","https://api.jamboxsys.com/jambox/ass/"); + // 办卡 + dto.setOpenId(result.getSubOpenid()); + dto.setMerchantSignPlanNo(result.getMerchantSignPlanNo()); + dto.setSignPlanId(result.getSignPlanId()); + //TODO: 模板id + //dto.setOrderCloudId(easyLearnOrder); + StoreExtend storeExtend = SpringUtils.getBean(StoreExtendService.class).queryChain() + .where(STORE_EXTEND.STORE_ID.eq(easyLearnOrder.getStoreId())) + .one(); + dto.setStoreCloudId(storeExtend.getStoreCloudId()); + dto.setCustomerPhone(easyLearnOrder.getCustomerPhone()); + dto.setCustomerName(easyLearnOrder.getCustomerName()); + dto.setPlanId(result.getPlanId()); + dto.setSignPlanDetails(JSONArray.toJSONString(result.getSignedDetailList())); + //TODO: 课次 + String cloudCardId = SpringUtils.getBean(CloudClassCardHandler.class).insertCloudClassCard(dto); + easyLearnOrder.setProductId(cloudCardId); + this.updateById(easyLearnOrder); + } else if (StringUtils.equals("PAYSCORE.USER_CANCEL_SIGN_PLAN", payScoreNotifyData.getEventType())){ + //取消合约 + easyLearnOrder.setOrderStatus(2); + this.updateById(easyLearnOrder); + //批量修改订单详情状态 + SpringUtils.getBean(EasyLearnOrderDetailService.class).updateChain() + .set(EASY_LEARN_ORDER_DETAIL.DETAIL_STATUS, 3) + .where(EASY_LEARN_ORDER_DETAIL.ORDER_ID.eq(easyLearnOrder.getId())) + .and(EASY_LEARN_ORDER_DETAIL.DETAIL_STATUS.eq(0)) + .update(); + //TODO: 通知波哥取消课卡 + } + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 创建用户服务订单(核销) + * @author DB + * @since 2024/1/20 + * @param bo 请求参数 + * @return WxPartnerPayScoreSignPlanResult + */ + @Override + @Transactional(rollbackFor = Exception.class) + public WxPartnerPayScoreSignPlanResult createServiceOrder(LearnNowPayLaterServiceOrderBo bo) { + EasyLearnOrder easyLearnOrder = this.queryChain().where(EASY_LEARN_ORDER.OUT_ORDER_NO.eq(bo.getSignPlanId())).one(); + EasyLearnOrderDetailService easyLearnOrderDetailService = SpringUtils.getBean(EasyLearnOrderDetailService.class); + EasyLearnOrderDetail easyLearnOrderDetail = easyLearnOrderDetailService.queryChain() + .where(EASY_LEARN_ORDER_DETAIL.ORDER_ID.eq(easyLearnOrder.getId())) + .and(EASY_LEARN_ORDER_DETAIL.PERIOD_NO.eq(bo.getPlanDetailNo())) + .one(); + String subMchId = wxPayHandler.getSubMchId(easyLearnOrder.getBrandId(), easyLearnOrder.getStoreId()); + WxPayService wxPayService = wxPayHandler.getWxPayService(null, subMchId); + PartnerPayScoreSignPlanService partnerPayScoreSignPlanService = wxPayService.getPartnerPayScoreSignPlanService(); + WxPartnerPayScoreSignPlanRequest signPlanRequest = new WxPartnerPayScoreSignPlanRequest(); + signPlanRequest.setSignPlanId(easyLearnOrder.getOutOrderNo()) + .setPlanDetailNo(easyLearnOrderDetail.getPeriodNo()) + .setSubMchid(subMchId) + .setSubOpenid(bo.getOpenid()) + .setNotifyUrl(wxPayConfiguration.getProperties().getLearnNowPayLaterServiceOrderNotifyUrl()) + .setServiceIntroduction(easyLearnOrderDetail.getDetailDesc()); + TimeRange timeRange = new TimeRange(); + LocalDateTime now = LocalDateTime.now(); + DateTimeFormatter yyyyMMddHHmmss = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + String startTime = now.plusSeconds(10).format(yyyyMMddHHmmss); + timeRange.setStartTime(startTime); + String endTime = now.plusSeconds(60).format(yyyyMMddHHmmss); + timeRange.setEndTime(endTime); + signPlanRequest.setTimeRange(timeRange) + .setOutOrderNo(easyLearnOrderDetail.getId()); + easyLearnOrderDetail.setDetailStatus(1); + easyLearnOrderDetailService.updateById(easyLearnOrderDetail); + try { + return partnerPayScoreSignPlanService.signPlanServiceOrder(signPlanRequest); + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 支付分用户核销成功回调 + * @author DB + * @since 2024/1/20 + * @param notifyData 返回数据 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public void userServiceOrderSuccess(String notifyData) { + try { + WxPayOrderNotifyResult notifyResult = wxPayHandler.getWxPayService().parseOrderNotifyResult(notifyData); + EasyLearnOrderDetailService easyLearnOrderDetailService = SpringUtils.getBean(EasyLearnOrderDetailService.class); + EasyLearnOrderDetail easyLearnOrderDetail = easyLearnOrderDetailService.queryChain() + .where(EASY_LEARN_ORDER_DETAIL.ORDER_ID.eq(notifyResult.getOutTradeNo())) + .and(EASY_LEARN_ORDER_DETAIL.OUT_ORDER_NO.eq(notifyResult.getTransactionId())) + .one(); + EasyLearnOrder easyLearnOrder = this.getById(easyLearnOrderDetail.getOrderId()); + //需要分账 + String subMchId = wxPayHandler.getSubMchId(easyLearnOrder.getBrandId(), easyLearnOrder.getStoreId()); + if (notifyResult.getTotalFee() >= Math.ceil(1 / OrderSource.EASY_LEARN.getRate())) { + //设置子商户 + WxPayService wxPayService = wxPayHandler.getWxPayService(null, subMchId); + wxPayAsyncTask.asyncWxPayProfitSharing(notifyResult.getOutTradeNo(), notifyResult, wxPayService, OrderSource.LEARN_NOW_PAY_LATER); + } + BigDecimal payAmount = new BigDecimal(notifyResult.getTotalFee()).divide(BigDecimal.valueOf(100)); + easyLearnOrderDetail.setDetailStatus(2) + .setActualPrice(payAmount); + easyLearnOrderDetailService.updateById(easyLearnOrderDetail); + //修改订单实际支付金额 + easyLearnOrder.setTotalPayAmount(easyLearnOrder.getTotalPayAmount() == null ? payAmount : easyLearnOrder.getTotalPayAmount().add(payAmount)); + this.updateById(easyLearnOrder); + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 取消用户签约计划 + * @author DB + * @since 2024/1/20 + * @param bo 请求参数 + */ + @Override + public void stopUserSignPlans(LearnNowPayLaterStopUserSignPlansBo bo) { + EasyLearnOrder easyLearnOrder = this.queryChain().where(EASY_LEARN_ORDER.OUT_ORDER_NO.eq(bo.getSignPlanId())).one(); + String subMchId = wxPayHandler.getSubMchId(easyLearnOrder.getBrandId(), easyLearnOrder.getStoreId()); + WxPayService wxPayService = wxPayHandler.getWxPayService(null, subMchId); + try { + wxPayService.getPartnerPayScoreSignPlanService().stopUserSignPlans(easyLearnOrder.getId(), subMchId, bo.getStopReason()); + //取消合约 + easyLearnOrder.setOrderStatus(2); + this.updateById(easyLearnOrder); + //批量修改订单详情状态 + SpringUtils.getBean(EasyLearnOrderDetailService.class).updateChain() + .set(EASY_LEARN_ORDER_DETAIL.DETAIL_STATUS, 3) + .where(EASY_LEARN_ORDER_DETAIL.ORDER_ID.eq(easyLearnOrder.getId())) + .and(EASY_LEARN_ORDER_DETAIL.DETAIL_STATUS.eq(0)) + .update(); + //TODO: 通知波哥取消课卡 + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java index 1c9d2b0..7d0849e 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/vo/LearnNowPayLaterPlanDetailVo.java @@ -37,7 +37,7 @@ public class LearnNowPayLaterPlanDetailVo { @ApiModelProperty("计划明细实际支付金额(单位分)") private BigDecimal actualPrice; - public void setActualPrice(Integer actualPrice) { + public void setActualPrice(Long actualPrice) { this.actualPrice = new BigDecimal(actualPrice).divide(BigDecimal.valueOf(100)); } @@ -46,4 +46,10 @@ public class LearnNowPayLaterPlanDetailVo { */ @ApiModelProperty("计划明细名称") private String planDetailName; + + /** + * 签约计划编号 + */ + @ApiModelProperty("签约计划编号") + private Integer planDetailNo; } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java index 2474e68..aa08360 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/tasks/LearnNowPayLaterTask.java @@ -1,6 +1,5 @@ package com.cpop.jambox.framework.tasks; -import com.alibaba.fastjson.JSONArray; import com.cpop.common.utils.StringUtils; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.exception.ServiceException; @@ -33,7 +32,6 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.List; -import static com.cpop.jambox.business.entity.table.CardTemplateExtendTableDef.CARD_TEMPLATE_EXTEND; import static com.cpop.system.business.entity.table.WxPayScoreTableDef.WX_PAY_SCORE; /** @@ -64,7 +62,7 @@ public class LearnNowPayLaterTask { String subMchId = wxPayHandler.getSubMchId(cardTemplate.getBrandId(), cardTemplate.getStoreId()); //录入计划与详情 WxPayScore wxPayScore = BeanUtils.mapToClass(bo, WxPayScore.class); - wxPayScore.setSignAccount(subMchId); + wxPayScore.setSignAccount(subMchId).setClassHour(bo.getClassHour()); WxPayScoreService wxPayScoreService = SpringUtils.getBean(WxPayScoreService.class); wxPayScoreService.save(wxPayScore); //创建计划 diff --git a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml index 6eda66c..2177965 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml +++ b/Cpop-Oam/Cpop-Oam-Web/src/main/resources/application-dev.yml @@ -108,3 +108,7 @@ wx: privateKeyPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_key.pem # 私钥文件 privateCertPath: E:/Cpop/Cpop-Union/Cpop-Core/src/main/resources/static/keyPair/wxPay_cert.pem + # 先学后付用户签约通知地址 + learn-now-pay-later-user-sign-plan-notify-url: + # 先学后付用户核销通知地址 + learn-now-pay-later-service-order-notify-url: diff --git a/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopDataSyncTests.java b/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopDataSyncTests.java index 11a0010..ad659c3 100644 --- a/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopDataSyncTests.java +++ b/Cpop-Oam/Cpop-Oam-Web/src/test/java/com/cpop/oam/web/CpopDataSyncTests.java @@ -1,12 +1,15 @@ package com.cpop.oam.web; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; import com.cpop.common.utils.StringUtils; import com.cpop.core.utils.SpringUtils; -import com.cpop.jambox.business.entity.*; -import com.cpop.jambox.business.service.*; -import com.cpop.oam.business.service.StaffService; +import com.cpop.jambox.business.entity.BrandExtend; +import com.cpop.jambox.business.entity.CardTemplate; +import com.cpop.jambox.business.entity.CardTemplateExtend; +import com.cpop.jambox.business.entity.StoreExtend; +import com.cpop.jambox.business.service.BrandExtendService; +import com.cpop.jambox.business.service.CardTemplateExtendService; +import com.cpop.jambox.business.service.CardTemplateService; +import com.cpop.jambox.business.service.StoreExtendService; import com.cpop.system.business.entity.Store; import com.cpop.system.business.entity.StoreSign; import com.cpop.system.business.entity.WxPayScore; @@ -15,18 +18,15 @@ import com.cpop.system.business.service.StoreService; import com.cpop.system.business.service.StoreSignService; import com.cpop.system.business.service.WxPayScoreService; import com.mybatisflex.core.datasource.DataSourceKey; -import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.DbChain; import com.mybatisflex.core.row.Row; import com.mybatisflex.core.row.RowUtil; import com.mybatisflex.core.update.UpdateChain; -import org.apache.poi.ss.formula.functions.T; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ActiveProfiles; -import java.security.PublicKey; import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; @@ -46,7 +46,7 @@ import static com.mybatisflex.core.query.QueryMethods.max; * @since 2024-01-16 17:17 */ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@ActiveProfiles(profiles = {"prod", "core"}) +@ActiveProfiles(profiles = {"prod", "core", "pay"}) public class CpopDataSyncTests { /** @@ -139,7 +139,6 @@ public class CpopDataSyncTests { .setPayType(4); cardTemplateExtends.add(cardTemplateExtend); } - }); List entityList = RowUtil.toEntityList(rowList, CardTemplate.class); SpringUtils.getBean(CardTemplateService.class).saveBatch(entityList); @@ -172,7 +171,8 @@ public class CpopDataSyncTests { if (StringUtils.isNotBlank(row.getString("oncePlanId"))){ WxPayScore oncePlan = wxPayScoreMap.get(row.getString("oncePlanId")); if (oncePlan != null){ - cardTemplateExtend.setExtendId(oncePlan.getId()) + cardTemplateExtend.setTemplateId(row.getString("oldTemplateId")) + .setExtendId(oncePlan.getId()) .setPayType(1); cardTemplateExtends.add(cardTemplateExtend); } @@ -192,7 +192,8 @@ public class CpopDataSyncTests { if (StringUtils.isNotBlank(row.getString("monthPlanId"))){ WxPayScore monthPlan = wxPayScoreMap.get(row.getString("monthPlanId")); if (monthPlan != null){ - cardTemplateExtend.setExtendId(monthPlan.getId()) + cardTemplateExtend.setTemplateId(row.getString("oldTemplateId")) + .setExtendId(monthPlan.getId()) .setPayType(5); cardTemplateExtends.add(cardTemplateExtend); } diff --git a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java index 908ef9c..1c63503 100644 --- a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayProperties.java @@ -90,4 +90,14 @@ public class WxPayProperties { * 服务商模式下的子商户公众账号ID */ private String serviceAppId; + + /** + * 先学后付用户签约计划通知地址 + */ + private String learnNowPayLaterUserSignPlanNotifyUrl; + + /** + * 先学后付用户支付成功通知地址 + */ + private String learnNowPayLaterServiceOrderNotifyUrl; } diff --git a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java index 821da72..167b4df 100644 --- a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/handler/wxPay/WxPayHandler.java @@ -1,27 +1,21 @@ package com.cpop.pay.framewok.handler.wxPay; import com.alibaba.fastjson.JSONObject; +import com.cpop.common.utils.ServletUtils; import com.cpop.common.utils.StringUtils; -import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.exception.ServiceException; -import com.cpop.core.base.exception.UtilException; import com.cpop.core.utils.SecurityUtils; -import com.cpop.pay.framewok.core.dto.LearnNowPayLaterPlanDto; -import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanRequest; -import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreSignPlanResult; +import com.github.binarywang.wxpay.bean.ecommerce.SignatureHeader; import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.exception.WxPayException; -import com.github.binarywang.wxpay.service.PartnerPayScoreSignPlanService; import com.github.binarywang.wxpay.service.WxPayService; import com.mybatisflex.core.query.QueryWrapper; import com.mybatisflex.core.row.Db; import com.mybatisflex.core.row.Row; -import com.mybatisflex.core.row.RowKey; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; -import java.util.ArrayList; +import javax.servlet.http.HttpServletRequest; /** * @author DB @@ -29,6 +23,7 @@ import java.util.ArrayList; * @description */ @Component +@Slf4j public class WxPayHandler { @Autowired @@ -141,4 +136,20 @@ public class WxPayHandler { return wxMchId; } + /** + * 获取签约头 + * @author DB + * @since 2024/1/20 + * @return SignatureHeader + */ + public SignatureHeader getSignatureHeader() { + HttpServletRequest request = ServletUtils.getRequest(); + SignatureHeader signatureHeader = new SignatureHeader(); + signatureHeader.setSigned(request.getHeader("Wechatpay-Signature")); + signatureHeader.setNonce(request.getHeader("Wechatpay-Nonce")); + signatureHeader.setSerialNo(request.getHeader("Wechatpay-Serial")); + signatureHeader.setTimeStamp(request.getHeader("Wechatpay-Timestamp")); + log.info("微信支付分回调ID:{}",request.getHeader("Request-ID")); + return signatureHeader; + } } diff --git a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java index 2779422..e32dd1a 100644 --- a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java @@ -142,7 +142,7 @@ public class WxPayAsyncTask { throw new ServiceException(profitSharingResult.getReturnMsg()); } } catch (WxPayException e) { - if (flag > 5) { + if (flag > 2) { if (OrderSource.MALL == orderSource) { //关闭商城支付 DbChain.table("cp_sys_brand") diff --git a/Cpop-System/src/main/java/com/cpop/system/business/entity/WxPayScore.java b/Cpop-System/src/main/java/com/cpop/system/business/entity/WxPayScore.java index c172d3a..834273c 100644 --- a/Cpop-System/src/main/java/com/cpop/system/business/entity/WxPayScore.java +++ b/Cpop-System/src/main/java/com/cpop/system/business/entity/WxPayScore.java @@ -6,13 +6,11 @@ import com.cpop.core.base.entity.BaseUpdateListener; import com.mybatisflex.annotation.Column; import com.mybatisflex.annotation.Id; import com.mybatisflex.annotation.Table; -import java.io.Serializable; -import java.time.LocalDateTime; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.*; import lombok.experimental.Accessors; +import java.io.Serializable; + /** * 微信支付分计划表 实体类。 * @@ -74,6 +72,11 @@ public class WxPayScore extends BaseEntity implements Serializable { */ private String planSource; + /** + * 课次 + */ + private String classHour; + /** * 逻辑删除(0否1是) */