From d3ca17d681d7afd87c3b0a3bb73fc42119364268 Mon Sep 17 00:00:00 2001 From: DB <2502523450@qq.com> Date: Thu, 21 Dec 2023 18:31:02 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=A8=A1=E5=9D=97=E5=89=A5?= =?UTF-8?q?=E7=A6=BB;=E6=8A=A5=E9=94=80=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cpop/core/base/enums/OrderSource.java | 8 +- Cpop-Jambox/pom.xml | 11 +- .../jambox/business/bo/OncePlaceOrderBo.java | 68 +++++++++ .../CardTemplateController.java | 2 +- .../{ => backstage}/EasyLearnController.java | 27 ++-- .../callback/EasyLearnCallBackController.java | 50 +++++++ .../business/entity/EasyLearnOrder.java | 12 +- .../service/EasyLearnOrderService.java | 27 +++- .../impl/EasyLearnOrderServiceImpl.java | 141 +++++++++++++++++- .../constant/JamboxRedisConstant.java | 14 ++ .../com/cpop/mall/web/CpopWxPayTests.java | 8 +- .../service/impl/OrderRefundServiceImpl.java | 9 +- .../service/impl/OrderServiceImpl.java | 17 +-- .../config/wxPay/WxPayConfiguration.java | 48 ------ .../config/wxPay/WxPayProperties.java | 78 ---------- .../mall/framework/handler/WxPayHandler.java | 72 --------- .../bo/FinanceReimburseAuditPageBo.java | 4 +- .../business/bo/FinanceReimbursePageBo.java | 4 +- .../controller/backstage/WxPayController.java | 7 +- .../impl/FinanceReimburseServiceImpl.java | 14 +- .../vo/FinanceReimburseAuditPageVo.java | 4 +- .../business/vo/FinanceReimbursePageVo.java | 4 +- .../config/wxPay/WxPayConfiguration.java | 51 ------- .../config/wxPay/WxPayProperties.java | 78 ---------- .../framework/handler/wxPay/WxPayHandler.java | 72 --------- Cpop-Pay/pom.xml | 4 +- .../config/wxPay/WxPayConfiguration.java | 1 + .../core}/dto/WxPayGoodsDetailDto.java | 2 +- .../framewok/handler/wxPay/WxPayHandler.java | 21 +++ .../pay/framewok}/task/WxPayAsyncTask.java | 68 +++++---- 30 files changed, 422 insertions(+), 504 deletions(-) create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/OncePlaceOrderBo.java rename Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/{ => backstage}/CardTemplateController.java (93%) rename Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/{ => backstage}/EasyLearnController.java (83%) create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/EasyLearnCallBackController.java create mode 100644 Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxRedisConstant.java delete mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java delete mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java delete mode 100644 Cpop-Mall/src/main/java/com/cpop/mall/framework/handler/WxPayHandler.java delete mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java delete mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java delete mode 100644 Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxPay/WxPayHandler.java rename {Cpop-Mall/src/main/java/com/cpop/mall/business => Cpop-Pay/src/main/java/com/cpop/pay/framewok/core}/dto/WxPayGoodsDetailDto.java (93%) rename {Cpop-Mall/src/main/java/com/cpop/mall/framework => Cpop-Pay/src/main/java/com/cpop/pay/framewok}/task/WxPayAsyncTask.java (67%) 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 59a78dd..2d842ef 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 @@ -1,7 +1,6 @@ package com.cpop.core.base.enums; import lombok.Getter; -import lombok.Setter; /** * 订单来源 @@ -12,7 +11,12 @@ public enum OrderSource { /** * 商城 */ - MALL("Mall",0.002); + MALL("Mall",0.002), + + /** + * 微信支付 + */ + EASY_LEARN("easyLearn",0.002); OrderSource(String name, Double rate) { this.rate = rate; diff --git a/Cpop-Jambox/pom.xml b/Cpop-Jambox/pom.xml index 20628bc..213b6e1 100644 --- a/Cpop-Jambox/pom.xml +++ b/Cpop-Jambox/pom.xml @@ -18,10 +18,15 @@ com.cpop Cpop-Core - + - com.github.binarywang - weixin-java-pay + com.cpop + Cpop-System + + + + com.cpop + Cpop-Pay diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/OncePlaceOrderBo.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/OncePlaceOrderBo.java new file mode 100644 index 0000000..1a334c9 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/bo/OncePlaceOrderBo.java @@ -0,0 +1,68 @@ +package com.cpop.jambox.business.bo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.math.BigDecimal; + +/** + * @author DB + * @version 1.0.0 + * @since 2023-12-21 17:15 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "OncePlaceOrderBo对象", description = "一次性支付参数") +public class OncePlaceOrderBo { + + /** + * 品牌id + */ + @ApiModelProperty("品牌id") + private String brandCloudId; + + /** + * 校区id + */ + @ApiModelProperty("校区id") + private String storeCloudId; + + /** + * 客户名 + */ + @ApiModelProperty("客户名") + private String customerName; + + /** + * 客户电话 + */ + @ApiModelProperty("客户电话") + private String customerPhone; + + /** + * 产品/课卡id + */ + @ApiModelProperty("产品/课卡id") + private String productId; + + /** + * 总金额 + */ + @ApiModelProperty("总金额") + private BigDecimal totalAmount; + + /** + * 总支付金额 + */ + @ApiModelProperty("总支付金额") + private BigDecimal totalPayAmount; + + /** + * 员工id + */ + @ApiModelProperty("员工id") + private String staffId; + +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/CardTemplateController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/CardTemplateController.java similarity index 93% rename from Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/CardTemplateController.java rename to Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/CardTemplateController.java index 0ec2687..c1a9e34 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/CardTemplateController.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/CardTemplateController.java @@ -1,4 +1,4 @@ -package com.cpop.jambox.business.controller; +package com.cpop.jambox.business.controller.backstage; import com.mybatisflex.core.paginate.Page; import com.cpop.core.base.R; diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/EasyLearnController.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/EasyLearnController.java similarity index 83% rename from Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/EasyLearnController.java rename to Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/EasyLearnController.java index 3921032..d8c527c 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/EasyLearnController.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/backstage/EasyLearnController.java @@ -1,27 +1,23 @@ -package com.cpop.jambox.business.controller; +package com.cpop.jambox.business.controller.backstage; import com.alibaba.excel.EasyExcel; import com.cpop.core.base.R; import com.cpop.jambox.business.bo.EasyLearnPageBo; +import com.cpop.jambox.business.bo.OncePlaceOrderBo; import com.cpop.jambox.business.dto.EasyLearnPageDto; import com.cpop.jambox.business.service.EasyLearnOrderService; import com.cpop.jambox.business.vo.EasyLearnPageVo; import com.mybatisflex.core.paginate.Page; +import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; -import io.swagger.annotations.Api; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.net.URLEncoder; -import java.time.LocalDate; -import java.util.List; /** * 果酱-放心学订单表 控制层。 @@ -89,4 +85,17 @@ public class EasyLearnController { response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx"); EasyExcel.write(response.getOutputStream(), EasyLearnPageDto.class).sheet("记录").doWrite(easyLearnOrderService.getEasyLearnXml(bo)); } + + /** + * 一次性支付下单 + * @author DB + * @since 2023/10/23 12:15 + * @param bo 下单请求对象 + * @return com.cpop.core.base.R + */ + @PostMapping("/oncePlaceOrderBo") + @ApiOperation("一次性支付下单") + public R oncePlaceOrderBo(@RequestBody @Validated @ApiParam("一次性支付") OncePlaceOrderBo bo) { + return R.ok(easyLearnOrderService.oncePlaceOrderBo(bo)); + } } 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 new file mode 100644 index 0000000..adc0fb2 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/controller/callback/EasyLearnCallBackController.java @@ -0,0 +1,50 @@ +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 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 2023-12-21 16:06 + */ +@RestController +@Api(tags = "果酱-放心学回调接口") +@RequestMapping("/easyLearn/callBack") +public class EasyLearnCallBackController { + + @Autowired + private EasyLearnOrderService easyLearnOrderService; + + /** + * 微信支付订单通知 + * @author DB + * @since 2023/12/21 + * @param xmlData 数据 + * @return java.lang.String + */ + @PostMapping("/notify/order") + public String parseOrderNotifyResult(@RequestBody String xmlData){ + easyLearnOrderService.wxPayNotifyOrder(xmlData); + return WxPayNotifyResponse.success("成功"); + } + + /** + * 微信支付分账通知 + * @author DB + * @since 2023/10/27 16:04 + * @param xmlData 数据 + * @return java.lang.String + */ + @PostMapping("/notify/profitSharing") + public String parseProfitSharingNotifyResult(@RequestBody String xmlData){ + easyLearnOrderService.parseProfitSharingNotifyResult(xmlData); + return WxPayNotifyResponse.success("成功"); + } +} diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/EasyLearnOrder.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/EasyLearnOrder.java index b813de9..af21127 100644 --- a/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/EasyLearnOrder.java +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/business/entity/EasyLearnOrder.java @@ -6,14 +6,12 @@ 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.math.BigDecimal; -import java.time.LocalDateTime; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; import lombok.*; import lombok.experimental.Accessors; +import java.io.Serializable; +import java.math.BigDecimal; + /** * 果酱-放心学订单表 实体类。 * @@ -85,10 +83,6 @@ public class EasyLearnOrder extends BaseEntity implements Serializable { */ private Integer orderType; - - - - /** * 逻辑删除(0否1是) */ 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 57d833c..73f253b 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 @@ -1,14 +1,13 @@ package com.cpop.jambox.business.service; import com.cpop.jambox.business.bo.EasyLearnPageBo; +import com.cpop.jambox.business.bo.OncePlaceOrderBo; import com.cpop.jambox.business.dto.EasyLearnPageDto; import com.cpop.jambox.business.entity.EasyLearnOrder; import com.cpop.jambox.business.vo.EasyLearnPageVo; import com.mybatisflex.core.paginate.Page; import com.mybatisflex.core.service.IService; -import java.time.LocalDate; -import java.util.Collection; import java.util.List; /** @@ -36,4 +35,28 @@ public interface EasyLearnOrderService extends IService { * @return List */ List getEasyLearnXml(EasyLearnPageBo bo); + + /** + * 微信支付订单通知 + * @author DB + * @since 2023/12/21 + * @param xmlData 数据 + */ + void wxPayNotifyOrder(String xmlData); + + /** + * 微信支付分账通知 + * @author DB + * @since 2023/12/21 + * @param xmlData 数据 + */ + void parseProfitSharingNotifyResult(String xmlData); + + /** + * 一次性支付下单 + * @author DB + * @since 2023/10/23 12:15 + * @param bo 下单请求对象 + */ + Object oncePlaceOrderBo(OncePlaceOrderBo bo); } 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 6682d2d..f913a09 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,34 +1,56 @@ package com.cpop.jambox.business.service.impl; +import com.alibaba.fastjson.JSONObject; import com.cpop.common.utils.StringUtils; +import com.cpop.common.utils.bean.BeanUtils; +import com.cpop.common.utils.ip.IpUtils; import com.cpop.core.base.entity.PageDomain; +import com.cpop.core.base.enums.OrderSource; +import com.cpop.core.base.exception.ServiceException; +import com.cpop.core.service.RedisService; +import com.cpop.core.utils.SecurityUtils; +import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.sql.SqlUtils; import com.cpop.jambox.business.bo.EasyLearnPageBo; +import com.cpop.jambox.business.bo.OncePlaceOrderBo; import com.cpop.jambox.business.dto.EasyLearnPageDto; +import com.cpop.jambox.business.entity.BrandExtend; import com.cpop.jambox.business.entity.EasyLearnOrder; +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.EasyLearnOrderService; +import com.cpop.jambox.business.service.StoreExtendService; import com.cpop.jambox.business.vo.EasyLearnPageVo; +import com.cpop.jambox.framework.constant.JamboxRedisConstant; +import com.cpop.pay.framewok.handler.wxPay.WxPayHandler; +import com.cpop.pay.framewok.task.WxPayAsyncTask; +import com.cpop.system.business.service.ProfitSharingService; +import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; +import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; +import com.github.binarywang.wxpay.exception.WxPayException; +import com.github.binarywang.wxpay.service.WxPayService; import com.mybatisflex.core.FlexGlobalConfig; import com.mybatisflex.core.datasource.DataSourceKey; import com.mybatisflex.core.datasource.FlexDataSource; import com.mybatisflex.core.paginate.Page; 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.spring.service.impl.ServiceImpl; import com.zaxxer.hikari.HikariDataSource; -import org.apache.poi.util.StringUtil; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.locks.Lock; -import static com.mybatisflex.core.query.QueryMethods.column; -import static com.mybatisflex.core.query.QueryMethods.distinct; +import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND; +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.ProfitSharingTableDef.PROFIT_SHARING; /** * 果酱-放心学订单表 服务层实现。 @@ -39,6 +61,12 @@ import static com.mybatisflex.core.query.QueryMethods.distinct; @Service("easyLearnOrderService") public class EasyLearnOrderServiceImpl extends ServiceImpl implements EasyLearnOrderService { + @Autowired + private WxPayHandler wxPayHandler; + + @Autowired + private WxPayAsyncTask wxPayAsyncTask; + /** * 获取放心学分页 * @@ -312,4 +340,107 @@ public class EasyLearnOrderServiceImpl extends ServiceImpl= Math.ceil(1 / OrderSource.MALL.getRate())) { + wxPayAsyncTask.asyncWxPayProfitSharing(orderId, notifyResult, wxPayService, OrderSource.EASY_LEARN); + } + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 微信支付分账通知 + * @author DB + * @since 2023/12/21 + * @param xmlData 数据 + */ + @Override + public void parseProfitSharingNotifyResult(String xmlData) { + WxPayService wxPayService = wxPayHandler.getWxPayService(); + try { + WxPayOrderNotifyResult notifyResult = wxPayService.parseOrderNotifyResult(xmlData); + //更新分账订单 + SpringUtils.getBean(ProfitSharingService.class).updateChain().set(PROFIT_SHARING.OUT_PROFIT_SHARING_ID, notifyResult.getTransactionId()) + .set(PROFIT_SHARING.AMOUNT, notifyResult.getTotalFee()) + .set(PROFIT_SHARING.PROFIT_SHARING_STATUS, 1) + //当前分账账户 + .set(PROFIT_SHARING.PAY_ACCOUNT, wxPayService.getConfig().getSubMchId()) + .where(PROFIT_SHARING.ID.eq(notifyResult.getOutTradeNo())) + .update(); + } catch (WxPayException e) { + throw new ServiceException(e.getMessage()); + } + } + + /** + * 一次性支付下单 + * @author DB + * @since 2023/10/23 12:15 + * @param bo 下单请求对象 + */ + @Override + public Object oncePlaceOrderBo(OncePlaceOrderBo bo) { + //获取当前下单用户信息 + JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo(); + //分布式锁进行幂等处理 + RedisService redisService = SpringUtils.getBean(RedisService.class); + //分布式锁进行幂等处理 + Lock userIdLock = redisService.distributedLock(JamboxRedisConstant.ONCE_PAY_LOCK_USER_PAY + bo.getCustomerPhone()); + if (userIdLock.tryLock()){ + try { + //获取品牌 + BrandExtend brandExtend = SpringUtils.getBean(BrandExtendService.class).queryChain().where(BRAND_EXTEND.BRAND_CLOUD_ID.eq(bo.getBrandCloudId())).one(); + //获取校区 + StoreExtend storeExtend = SpringUtils.getBean(StoreExtendService.class).queryChain().where(STORE_EXTEND.STORE_CLOUD_ID.eq(bo.getStoreCloudId())).one(); + //创建订单 + EasyLearnOrder easyLearnOrder = BeanUtils.mapToClass(bo, EasyLearnOrder.class); + easyLearnOrder.setOrderType(2).setBrandId(brandExtend.getBrandId()).setStoreId(storeExtend.getStoreId()); + this.save(easyLearnOrder); + //获取商户信息 + WxPayService wxPayService = wxPayHandler.getWxPayService(null, null, null); + WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest(); + //需要分账 + if (bo.getTotalAmount().scaleByPowerOfTen(2).intValue() >= Math.ceil(1 / OrderSource.EASY_LEARN.getRate())) { + //需要分账 + orderRequest.setProfitSharing("Y"); + } + orderRequest.setSpbillCreateIp(IpUtils.getHostIp()) + .setOpenid(loginUserInfo.getString("openId")) + //商品描述 + .setBody("一次性支付") + .setOutTradeNo(easyLearnOrder.getId()) + //元转分 + .setTotalFee(easyLearnOrder.getTotalAmount().scaleByPowerOfTen(2).intValue()) + .setTradeType("JSAPI"); + return wxPayService.createOrder(orderRequest); + } catch (Exception e) { + throw new ServiceException(e.getMessage()); + } finally { + //释放锁 + userIdLock.unlock(); + } + } else { + //获取锁失败,直接返回空 + throw new ServiceException("请勿重复支付"); + } + } } diff --git a/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxRedisConstant.java b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxRedisConstant.java new file mode 100644 index 0000000..2dc1188 --- /dev/null +++ b/Cpop-Jambox/src/main/java/com/cpop/jambox/framework/constant/JamboxRedisConstant.java @@ -0,0 +1,14 @@ +package com.cpop.jambox.framework.constant; + +/** + * @author DB + * @version 1.0.0 + * @since 2023-12-21 17:29 + */ +public interface JamboxRedisConstant { + + /** + * 一次性支付 + */ + String ONCE_PAY_LOCK_USER_PAY = "jambox:oncePayLock:userPay:"; +} diff --git a/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java b/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java index fc09845..2c8fe1a 100644 --- a/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java +++ b/Cpop-Mall/Cpop-Mall-Web/src/test/java/com/cpop/mall/web/CpopWxPayTests.java @@ -3,21 +3,15 @@ package com.cpop.mall.web; import com.alibaba.fastjson.JSONObject; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.uuid.IdUtils; -import com.cpop.mall.business.entity.Order; -import com.cpop.mall.business.service.OrderService; -import com.cpop.mall.framework.config.wxPay.WxPayProperties; +import com.cpop.pay.framewok.config.wxPay.WxPayProperties; import com.cpop.system.business.entity.Brand; -import com.cpop.system.business.entity.ProfitSharing; import com.cpop.system.business.service.BrandService; -import com.cpop.system.business.service.ProfitSharingService; -import com.github.binarywang.wxpay.bean.payscore.WxPartnerPayScoreResult; import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingFinishRequest; import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingQueryRequest; import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingQueryResult; import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingReceiverRequest; import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingResult; import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingReturnRequest; -import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingUnfreezeRequest; import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request; import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult; import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result; diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderRefundServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderRefundServiceImpl.java index 56a7282..8896e23 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderRefundServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderRefundServiceImpl.java @@ -7,7 +7,6 @@ import com.cpop.core.base.exception.ServiceException; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.sql.SqlUtils; -import com.cpop.core.utils.uuid.IdUtils; import com.cpop.mall.business.bo.OrderRefundPageBo; import com.cpop.mall.business.bo.OrderRejectRefundBo; import com.cpop.mall.business.dto.UserPointDto; @@ -17,17 +16,13 @@ import com.cpop.mall.business.mapper.OrderRefundMapper; import com.cpop.mall.business.service.OrderRefundService; import com.cpop.mall.business.service.OrderService; import com.cpop.mall.business.vo.OrderRefundPageVo; -import com.cpop.mall.framework.config.wxPay.WxPayProperties; -import com.cpop.mall.framework.handler.WxPayHandler; -import com.cpop.system.business.entity.Brand; +import com.cpop.pay.framewok.config.wxPay.WxPayProperties; +import com.cpop.pay.framewok.handler.wxPay.WxPayHandler; import com.cpop.system.business.entity.ProfitSharing; -import com.cpop.system.business.service.BrandService; import com.cpop.system.business.service.ProfitSharingService; -import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult; import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyV3Result; import com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingReturnRequest; import com.github.binarywang.wxpay.bean.request.WxPayRefundV3Request; -import com.github.binarywang.wxpay.bean.result.WxPayRefundV3Result; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; import com.mybatisflex.annotation.KeyType; diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java index cec090b..579f56c 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java +++ b/Cpop-Mall/src/main/java/com/cpop/mall/business/service/impl/OrderServiceImpl.java @@ -19,25 +19,24 @@ import com.cpop.jambox.business.entity.BrandExtend; import com.cpop.jambox.business.service.BrandExtendService; import com.cpop.mall.business.bo.*; import com.cpop.mall.business.dto.UserPointDto; -import com.cpop.mall.business.dto.WxPayGoodsDetailDto; +import com.cpop.pay.framewok.core.dto.WxPayGoodsDetailDto; import com.cpop.mall.business.entity.*; import com.cpop.mall.business.mapper.OrderMapper; import com.cpop.mall.business.service.*; -import com.cpop.mall.framework.task.OrderDetailAsyncTask; -import com.cpop.mall.framework.task.OrderOverTimeUnPayTask; -import com.cpop.mall.framework.task.ProductRecordSyncStockTask; -import com.cpop.mall.framework.task.WxPayAsyncTask; import com.cpop.mall.business.vo.OrderDetailVo; import com.cpop.mall.business.vo.OrderInfoVo; import com.cpop.mall.business.vo.OrderPageVo; import com.cpop.mall.framework.constant.MallRedisConstant; import com.cpop.mall.framework.enums.BuyRestrictEnums; import com.cpop.mall.framework.enums.QuartzEnums; -import com.cpop.mall.framework.handler.WxPayHandler; +import com.cpop.mall.framework.task.OrderDetailAsyncTask; +import com.cpop.mall.framework.task.OrderOverTimeUnPayTask; +import com.cpop.mall.framework.task.ProductRecordSyncStockTask; +import com.cpop.pay.framewok.task.WxPayAsyncTask; +import com.cpop.pay.framewok.handler.wxPay.WxPayHandler; import com.cpop.system.business.entity.Brand; import com.cpop.system.business.service.BrandService; import com.cpop.system.business.service.ProfitSharingService; - import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest; import com.github.binarywang.wxpay.exception.WxPayException; @@ -69,7 +68,7 @@ import static com.cpop.mall.business.entity.table.ProductRecordTableDef.PRODUCT_ import static com.cpop.mall.business.entity.table.ProductTableDef.PRODUCT; import static com.cpop.system.business.entity.table.ProfitSharingTableDef.PROFIT_SHARING; import static com.cpop.system.business.entity.table.StoreTableDef.STORE; -import static com.mybatisflex.core.query.QueryMethods.*; +import static com.mybatisflex.core.query.QueryMethods.sum; /** @@ -530,7 +529,7 @@ public class OrderServiceImpl extends ServiceImpl implements Map orderNumMap = orderDetails.stream().collect(Collectors.toMap(OrderDetail::getProductRecordId, OrderDetail::getNumber)); //需要分账 if (notifyResult.getTotalFee() >= Math.ceil(1 / OrderSource.MALL.getRate())) { - wxPayAsyncTask.asyncWxPayProfitSharing(orderId, notifyResult, wxPayService); + wxPayAsyncTask.asyncWxPayProfitSharing(orderId, notifyResult, wxPayService, OrderSource.MALL); } //异步更新 SpringUtils.getBean(ProductRecordSyncStockTask.class).asyncUpdateRecords(orderNumMap); diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java deleted file mode 100644 index 16a6fbe..0000000 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayConfiguration.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.cpop.mall.framework.config.wxPay; - -import com.cpop.common.utils.StringUtils; -import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.service.WxPayService; -import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; -import lombok.AllArgsConstructor; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author DB - * @Description: - * @create 2023-10-26 22:38 - */ -@Configuration -@ConditionalOnClass(WxPayService.class) -@EnableConfigurationProperties(WxPayProperties.class) -@AllArgsConstructor -public class WxPayConfiguration { - private WxPayProperties properties; - - @Bean - @ConditionalOnMissingBean - public WxPayService wxService() { - WxPayConfig payConfig = new WxPayConfig(); - payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId())); - payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); - payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); - //服务商模式微信支付 - payConfig.setApiV3Key(this.properties.getApiV3Key()); - payConfig.setCertSerialNo(this.properties.getCertSerialNo()); - payConfig.setKeyPath(this.properties.getKeyPath()); - payConfig.setPrivateKeyPath(this.properties.getPrivateKeyPath()); - payConfig.setPrivateCertPath(this.properties.getPrivateCertPath()); - //通知地址 - payConfig.setNotifyUrl(this.properties.getNotifyUrl()); - // 可以指定是否使用沙箱环境 - payConfig.setUseSandboxEnv(false); - WxPayService wxPayService = new WxPayServiceImpl(); - wxPayService.setConfig(payConfig); - return wxPayService; - } - -} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java b/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java deleted file mode 100644 index e2899a8..0000000 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/config/wxPay/WxPayProperties.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.cpop.mall.framework.config.wxPay; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * @author DB - * @Description: - * @create 2023-10-26 22:39 - */ -@Data -@ConfigurationProperties(prefix = "wx.pay") -public class WxPayProperties { - /** - * 设置微信公众号或者小程序等的appid - */ - private String appId; - - /** - * 微信支付商户号 - */ - private String mchId; - - /** - * 微信支付商户密钥 - */ - private String mchKey; - - /** - * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定 - */ - private String keyPath; - - /** - * apiV3 秘钥值 - */ - private String apiV3Key; - - /** - * apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径 - */ - private String privateKeyPath; - - /** - * apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径 - */ - private String privateCertPath; - - /** - * apiV3 证书序列号值 - */ - private String certSerialNo; - - /** - * 支付通知地址 - */ - private String notifyUrl; - - /** - * 退款通知 - */ - private String notifyRefund; - - /** - * 分账账号 - */ - private String sharingAccount; - - /** - * 分账账号名 - */ - private String sharingAccountName; - - /** - * 分账通知 - */ - private String notifySharing; -} diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/handler/WxPayHandler.java b/Cpop-Mall/src/main/java/com/cpop/mall/framework/handler/WxPayHandler.java deleted file mode 100644 index 0d9b141..0000000 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/handler/WxPayHandler.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.cpop.mall.framework.handler; - -import com.alibaba.fastjson.JSONObject; -import com.cpop.common.utils.StringUtils; -import com.cpop.core.base.exception.ServiceException; -import com.cpop.core.utils.SecurityUtils; -import com.cpop.core.utils.SpringUtils; -import com.cpop.system.business.entity.Brand; -import com.cpop.system.business.service.BrandService; -import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.service.WxPayService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * @author DB - * @createTime 2023/10/27 15:47 - * @description - */ -@Component -public class WxPayHandler { - - @Autowired - private WxPayService wxPayService; - - /** - * @descriptions 获取微信支付service - * @author DB - * @date 2023/10/27 15:53 - * @return: com.github.binarywang.wxpay.service.WxPayService - */ - public WxPayService getWxPayService(){ - //查询当前登陆用户所在品牌的商户id - JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo(); - if (loginUserInfo == null) { - //直接返回 - return wxPayService; - } - String brandId = loginUserInfo.getString("brandId"); - Brand brand = SpringUtils.getBean(BrandService.class).getById(brandId); - //检查是否开启分账 - if (!brand.getIsOpenSharing()) { - throw new ServiceException("当前商户暂未开启分账,请联系相关客服"); - } - WxPayConfig payConfig = wxPayService.getConfig(); - //子商户信息 - payConfig.setSubMchId(StringUtils.trimToNull(brand.getWxMchId())); - // 可以指定是否使用沙箱环境 - payConfig.setUseSandboxEnv(false); - wxPayService.setConfig(payConfig); - return wxPayService; - } - - /** - * @descriptions 根据商户appid或商户号获取对应微信支付接口 - * @author DB - * @date 2023/10/18 10:34 - * @param subAppId 子商户appid - * @param subMchId 子商户id - * @return: com.github.binarywang.wxpay.service.WxPayService - */ - public WxPayService getWxPayService(String subAppId, String subMchId) { - WxPayConfig payConfig = wxPayService.getConfig(); - //子商户信息 - payConfig.setSubAppId(StringUtils.trimToNull(subAppId)); - payConfig.setSubMchId(StringUtils.trimToNull(subMchId)); - // 可以指定是否使用沙箱环境 - payConfig.setUseSandboxEnv(false); - wxPayService.setConfig(payConfig); - return wxPayService; - } -} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimburseAuditPageBo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimburseAuditPageBo.java index 0a1cb2b..81c12f3 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimburseAuditPageBo.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimburseAuditPageBo.java @@ -17,9 +17,9 @@ import java.io.Serializable; @ApiModel(value = "FinanceReimburseAuditPageBo对象", description = "财务报销审核请求参数") public class FinanceReimburseAuditPageBo implements Serializable { /** - * 状态:0已提交1审批中2已下发3:下款中;5:驳回 + * 状态:0:审批中;1:下款中;2:已下发-1:驳回 */ - @ApiModelProperty(value = "状态:0已提交1审批中2已下发3:下款中;4:驳回") + @ApiModelProperty(value = "状态:0:审批中;1:下款中;2:已下发-1:驳回") private Integer status; /** diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimbursePageBo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimbursePageBo.java index 1d74e2a..72e146c 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimbursePageBo.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/bo/FinanceReimbursePageBo.java @@ -18,9 +18,9 @@ import java.io.Serializable; public class FinanceReimbursePageBo implements Serializable { /** - * 状态:0已提交1审批中2已下发3:下款中;5:驳回 + * 状态:0:审批中;1:下款中;2:已下发-1:驳回 */ - @ApiModelProperty(value = "状态:0:已提交;1:审批中;2:下款中;3:已下发;4:驳回") + @ApiModelProperty(value = "状态:0:审批中;1:下款中;2:已下发-1:驳回") private Integer status; /** diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java index 6ef980c..443fa7b 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/controller/backstage/WxPayController.java @@ -4,7 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.cpop.common.utils.StringUtils; import com.cpop.core.base.R; import com.cpop.core.base.exception.ServiceException; -import com.cpop.oam.framework.config.wxPay.WxPayConfiguration; +import com.cpop.pay.framewok.config.wxPay.WxPayConfiguration; import com.cpop.system.business.bo.ChangeWechatSharingBo; import com.cpop.system.business.entity.Brand; import com.cpop.system.business.service.BrandService; @@ -17,7 +17,10 @@ import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; import java.util.HashMap; import java.util.Map; diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/FinanceReimburseServiceImpl.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/FinanceReimburseServiceImpl.java index 4f99be7..38da404 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/FinanceReimburseServiceImpl.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/service/impl/FinanceReimburseServiceImpl.java @@ -1,16 +1,10 @@ package com.cpop.oam.business.service.impl; import com.alibaba.fastjson.JSONObject; -import com.mybatisflex.core.paginate.Page; -import com.mybatisflex.core.query.QueryWrapper; -import com.mybatisflex.spring.service.impl.ServiceImpl; import com.cpop.common.utils.bean.BeanUtils; import com.cpop.core.base.entity.LoginUser; import com.cpop.core.base.entity.PageDomain; -import com.cpop.core.base.entity.loginInfo.OamStaffLoginInfo; -import com.cpop.core.base.enums.UserType; import com.cpop.core.base.exception.ServiceException; -import com.cpop.core.service.RedisService; import com.cpop.core.utils.SecurityUtils; import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.sql.SqlUtils; @@ -23,6 +17,9 @@ import com.cpop.oam.business.service.FinanceReimburseStageService; import com.cpop.oam.business.vo.FinanceReimburseAuditPageVo; import com.cpop.oam.business.vo.FinanceReimbursePageVo; import com.cpop.oam.business.vo.ReimbursePersonStatisticVo; +import com.mybatisflex.core.paginate.Page; +import com.mybatisflex.core.query.QueryWrapper; +import com.mybatisflex.spring.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -115,6 +112,11 @@ public class FinanceReimburseServiceImpl extends ServiceImpl list = this.list(QueryWrapper.create().where(FINANCE_REIMBURSE.ID.in(bo.getIds()))); + //审批批量转下款 + if (list.get(0).getStatus() == 1) { + + } + List allFinishReimburseIds = new ArrayList<>(); if (!list.isEmpty()){ list.forEach(item->{ diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimburseAuditPageVo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimburseAuditPageVo.java index 5400f39..287505e 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimburseAuditPageVo.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimburseAuditPageVo.java @@ -41,9 +41,9 @@ public class FinanceReimburseAuditPageVo implements Serializable { private String staffName; /** - * 状态:0已提交1审批中2已下发3:下款中;5:驳回 + * 状态:0:审批中;1:下款中;2:已下发-1:驳回 */ - @ApiModelProperty("状态:0已提交1审批中2已下发3:下款中;5:驳回") + @ApiModelProperty("状态:0:审批中;1:下款中;2:已下发-1:驳回") private Integer status; /** diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimbursePageVo.java b/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimbursePageVo.java index 31f3b74..48c8352 100644 --- a/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimbursePageVo.java +++ b/Cpop-Oam/src/main/java/com/cpop/oam/business/vo/FinanceReimbursePageVo.java @@ -41,9 +41,9 @@ public class FinanceReimbursePageVo implements Serializable { private String staffName; /** - * 状态:0已提交1审批中2已下发3:下款中;5:驳回 + * 状态:0:审批中;1:下款中;2:已下发-1:驳回 */ - @ApiModelProperty("状态:0已提交1审批中2已下发3:下款中;5:驳回") + @ApiModelProperty("状态:0:审批中;1:下款中;2:已下发-1:驳回") private Integer status; /** diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java deleted file mode 100644 index c7331dd..0000000 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayConfiguration.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.cpop.oam.framework.config.wxPay; - -import com.cpop.common.utils.StringUtils; -import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.service.WxPayService; -import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl; -import lombok.AllArgsConstructor; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @author DB - * @Description: - * @create 2023-10-26 22:38 - */ -@Configuration -@ConditionalOnClass(WxPayService.class) -@EnableConfigurationProperties(WxPayProperties.class) -@AllArgsConstructor -public class WxPayConfiguration { - private WxPayProperties properties; - - @Bean - @ConditionalOnMissingBean - public WxPayService wxService() { - WxPayConfig payConfig = new WxPayConfig(); - payConfig.setAppId(StringUtils.trimToNull(this.properties.getAppId())); - payConfig.setMchId(StringUtils.trimToNull(this.properties.getMchId())); - payConfig.setMchKey(StringUtils.trimToNull(this.properties.getMchKey())); - //服务商模式微信支付 - payConfig.setApiV3Key(this.properties.getApiV3Key()); - payConfig.setCertSerialNo(this.properties.getCertSerialNo()); - payConfig.setKeyPath(this.properties.getKeyPath()); - payConfig.setPrivateKeyPath(this.properties.getPrivateKeyPath()); - payConfig.setPrivateCertPath(this.properties.getPrivateCertPath()); - //通知地址 - payConfig.setNotifyUrl(this.properties.getNotifyUrl()); - // 可以指定是否使用沙箱环境 - payConfig.setUseSandboxEnv(false); - WxPayService wxPayService = new WxPayServiceImpl(); - wxPayService.setConfig(payConfig); - return wxPayService; - } - - public WxPayProperties getProperties() { - return properties; - } -} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java deleted file mode 100644 index bc3755c..0000000 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/config/wxPay/WxPayProperties.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.cpop.oam.framework.config.wxPay; - -import lombok.Data; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * @author DB - * @Description: - * @create 2023-10-26 22:39 - */ -@Data -@ConfigurationProperties(prefix = "wx.pay") -public class WxPayProperties { - /** - * 设置微信公众号或者小程序等的appid - */ - private String appId; - - /** - * 微信支付商户号 - */ - private String mchId; - - /** - * 微信支付商户密钥 - */ - private String mchKey; - - /** - * apiclient_cert.p12文件的绝对路径,或者如果放在项目中,请以classpath:开头指定 - */ - private String keyPath; - - /** - * apiV3 秘钥值 - */ - private String apiV3Key; - - /** - * apiclient_key.pem证书文件的绝对路径或者以classpath:开头的类路径 - */ - private String privateKeyPath; - - /** - * apiclient_cert.pem证书文件的绝对路径或者以classpath:开头的类路径 - */ - private String privateCertPath; - - /** - * apiV3 证书序列号值 - */ - private String certSerialNo; - - /** - * 支付通知地址 - */ - private String notifyUrl; - - /** - * 退款通知 - */ - private String notifyRefund; - - /** - * 分账账号 - */ - private String sharingAccount; - - /** - * 分账账号名 - */ - private String sharingAccountName; - - /** - * 分账通知 - */ - private String notifySharing; -} diff --git a/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxPay/WxPayHandler.java b/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxPay/WxPayHandler.java deleted file mode 100644 index 778da05..0000000 --- a/Cpop-Oam/src/main/java/com/cpop/oam/framework/handler/wxPay/WxPayHandler.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.cpop.oam.framework.handler.wxPay; - -import com.alibaba.fastjson.JSONObject; -import com.cpop.common.utils.StringUtils; -import com.cpop.core.base.exception.ServiceException; -import com.cpop.core.utils.SecurityUtils; -import com.cpop.core.utils.SpringUtils; -import com.cpop.system.business.entity.Brand; -import com.cpop.system.business.service.BrandService; -import com.github.binarywang.wxpay.config.WxPayConfig; -import com.github.binarywang.wxpay.service.WxPayService; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -/** - * @author DB - * @createTime 2023/10/27 15:47 - * @description - */ -@Component -public class WxPayHandler { - - @Autowired - private WxPayService wxPayService; - - /** - * @descriptions 获取微信支付service - * @author DB - * @date 2023/10/27 15:53 - * @return: com.github.binarywang.wxpay.service.WxPayService - */ - public WxPayService getWxPayService(){ - //查询当前登陆用户所在品牌的商户id - JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo(); - if (loginUserInfo == null) { - //直接返回 - return wxPayService; - } - String brandId = loginUserInfo.getString("brandId"); - Brand brand = SpringUtils.getBean(BrandService.class).getById(brandId); - //检查是否开启分账 - if (!brand.getIsOpenSharing()) { - throw new ServiceException("当前商户暂未开启分账,请联系相关客服"); - } - WxPayConfig payConfig = wxPayService.getConfig(); - //子商户信息 - payConfig.setSubMchId(StringUtils.trimToNull(brand.getWxMchId())); - // 可以指定是否使用沙箱环境 - payConfig.setUseSandboxEnv(false); - wxPayService.setConfig(payConfig); - return wxPayService; - } - - /** - * @descriptions 根据商户appid或商户号获取对应微信支付接口 - * @author DB - * @date 2023/10/18 10:34 - * @param subAppId 子商户appid - * @param subMchId 子商户id - * @return: com.github.binarywang.wxpay.service.WxPayService - */ - public WxPayService getWxPayService(String subAppId, String subMchId) { - WxPayConfig payConfig = wxPayService.getConfig(); - //子商户信息 - payConfig.setSubAppId(StringUtils.trimToNull(subAppId)); - payConfig.setSubMchId(StringUtils.trimToNull(subMchId)); - // 可以指定是否使用沙箱环境 - payConfig.setUseSandboxEnv(false); - wxPayService.setConfig(payConfig); - return wxPayService; - } -} diff --git a/Cpop-Pay/pom.xml b/Cpop-Pay/pom.xml index c7a6de5..57195c3 100644 --- a/Cpop-Pay/pom.xml +++ b/Cpop-Pay/pom.xml @@ -12,9 +12,7 @@ Cpop-Pay Cpop-Pay jar - - 17 - + diff --git a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayConfiguration.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayConfiguration.java index 90ab1b8..f65d3ef 100644 --- a/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayConfiguration.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/config/wxPay/WxPayConfiguration.java @@ -23,6 +23,7 @@ import org.springframework.context.annotation.Configuration; @EnableConfigurationProperties(WxPayProperties.class) @AllArgsConstructor public class WxPayConfiguration { + private WxPayProperties properties; @Bean diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/business/dto/WxPayGoodsDetailDto.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/core/dto/WxPayGoodsDetailDto.java similarity index 93% rename from Cpop-Mall/src/main/java/com/cpop/mall/business/dto/WxPayGoodsDetailDto.java rename to Cpop-Pay/src/main/java/com/cpop/pay/framewok/core/dto/WxPayGoodsDetailDto.java index b8f33bc..7158d42 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/business/dto/WxPayGoodsDetailDto.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/core/dto/WxPayGoodsDetailDto.java @@ -1,4 +1,4 @@ -package com.cpop.mall.business.dto; +package com.cpop.pay.framewok.core.dto; import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; 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 7829849..59da159 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 @@ -72,4 +72,25 @@ public class WxPayHandler { wxPayService.setConfig(payConfig); return wxPayService; } + + /** + * 根据商户appid或商户号获取对应微信支付接口 + * @author DB + * @since 2023/10/18 10:34 + * @param subAppId 子商户appid + * @param subMchId 子商户id + * @param notifyUrl 通知地址 + * @return com.github.binarywang.wxpay.service.WxPayService + */ + public WxPayService getWxPayService(String subAppId, String subMchId,String notifyUrl) { + WxPayConfig payConfig = wxPayService.getConfig(); + //子商户信息 + payConfig.setSubAppId(StringUtils.trimToNull(subAppId)); + payConfig.setSubMchId(StringUtils.trimToNull(subMchId)); + payConfig.setNotifyUrl(notifyUrl); + // 可以指定是否使用沙箱环境 + payConfig.setUseSandboxEnv(false); + wxPayService.setConfig(payConfig); + return wxPayService; + } } diff --git a/Cpop-Mall/src/main/java/com/cpop/mall/framework/task/WxPayAsyncTask.java b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java similarity index 67% rename from Cpop-Mall/src/main/java/com/cpop/mall/framework/task/WxPayAsyncTask.java rename to Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java index b1441d0..7b9c33e 100644 --- a/Cpop-Mall/src/main/java/com/cpop/mall/framework/task/WxPayAsyncTask.java +++ b/Cpop-Pay/src/main/java/com/cpop/pay/framewok/task/WxPayAsyncTask.java @@ -1,32 +1,29 @@ -package com.cpop.mall.framework.task; +package com.cpop.pay.framewok.task; -import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.cpop.common.utils.StringUtils; import com.cpop.core.base.enums.OrderSource; import com.cpop.core.base.exception.ServiceException; -import com.cpop.core.utils.SpringUtils; -import com.cpop.mall.framework.config.wxPay.WxPayProperties; -import com.cpop.system.business.entity.ProfitSharing; -import com.cpop.system.business.service.BrandService; -import com.cpop.system.business.service.ProfitSharingService; +import com.cpop.pay.framewok.config.wxPay.WxPayProperties; import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult; import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingRequest; import com.github.binarywang.wxpay.bean.profitsharing.ProfitSharingResult; import com.github.binarywang.wxpay.exception.WxPayException; import com.github.binarywang.wxpay.service.WxPayService; +import com.mybatisflex.core.row.Db; +import com.mybatisflex.core.row.DbChain; +import com.mybatisflex.core.row.Row; +import com.mybatisflex.core.row.RowKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import static com.cpop.system.business.entity.table.BrandTableDef.BRAND; -import static com.cpop.system.business.entity.table.ProfitSharingTableDef.PROFIT_SHARING; - /** * @author DB * @createTime 2023/11/03 11:13 @@ -48,11 +45,11 @@ public class WxPayAsyncTask { * @return: void */ @Async("customAsyncThreadPool") - public void asyncWxPayProfitSharing(String orderId, WxPayOrderNotifyResult notifyResult, WxPayService wxPayService) { - ProfitSharingRequest profitSharingRequest = buildProfitSharingRequest(orderId, notifyResult); + public void asyncWxPayProfitSharing(String orderId, WxPayOrderNotifyResult notifyResult, WxPayService wxPayService,OrderSource orderSource) { + ProfitSharingRequest profitSharingRequest = buildProfitSharingRequest(orderId, notifyResult, orderSource); try { Thread.sleep(5000); - wxPayProfitSharing(profitSharingRequest, wxPayService, 0); + wxPayProfitSharing(profitSharingRequest, wxPayService, 0,orderSource); } catch (InterruptedException e) { throw new ServiceException(e.getMessage()); } @@ -66,16 +63,20 @@ public class WxPayAsyncTask { * @param notifyResult 通知结果 * @return: com.github.binarywang.wxpay.bean.profitsharingV3.ProfitSharingRequest */ - private ProfitSharingRequest buildProfitSharingRequest(String orderId, WxPayOrderNotifyResult notifyResult) { + private ProfitSharingRequest buildProfitSharingRequest(String orderId, WxPayOrderNotifyResult notifyResult,OrderSource orderSource) { + LocalDateTime now = LocalDateTime.now(); Double ceil = Math.ceil(notifyResult.getTotalFee() * OrderSource.MALL.getRate()); - ProfitSharing profitSharing = new ProfitSharing(); - profitSharing.setOrderId(orderId) - .setProfitSharingStatus(0) - .setOrderSource(OrderSource.MALL.toString()) - .setAmount(ceil.longValue()) - .setPayAccount(notifyResult.getSubMchId()); - ProfitSharingService profitSharingService = SpringUtils.getBean(ProfitSharingService.class); - profitSharingService.save(profitSharing); + Row row = Row.ofKey(RowKey.SNOW_FLAKE_ID) + .set("order_id", orderId) + .set("profit_sharing_status", 0) + .set("amount", ceil.longValue()) + .set("pay_account", notifyResult.getSubMchId()) + .set("order_source",orderSource.toString()) + .set("create_time", now) + .set("update_time", now) + .set("create_user_id", "1") + .set("update_user_id", "1"); + Db.insert("cp_sys_profit_sharing", row); //固定商户信息 Map mapReceiver = new HashMap<>(4); mapReceiver.put("type", "MERCHANT_ID"); @@ -87,7 +88,7 @@ public class WxPayAsyncTask { //分账请求参数 ProfitSharingRequest profitSharingRequest = new ProfitSharingRequest(); profitSharingRequest.setReceivers(JSONObject.toJSONString(receivers)); - profitSharingRequest.setOutOrderNo(profitSharing.getId()); + profitSharingRequest.setOutOrderNo(row.getString("id")); profitSharingRequest.setTransactionId(notifyResult.getTransactionId()); profitSharingRequest.setSubMchId(notifyResult.getSubMchId()); return profitSharingRequest; @@ -102,28 +103,33 @@ public class WxPayAsyncTask { * @param flag 标记 * @return: void */ - private void wxPayProfitSharing(ProfitSharingRequest profitSharingRequest, WxPayService wxPayService, Integer flag) { + private void wxPayProfitSharing(ProfitSharingRequest profitSharingRequest, WxPayService wxPayService, Integer flag, OrderSource orderSource) { try { ProfitSharingResult profitSharingResult = wxPayService.getProfitSharingService().profitSharing(profitSharingRequest); if (StringUtils.equals(profitSharingResult.getResultCode(), "SUCCESS")) { //存入系统 - SpringUtils.getBean(ProfitSharingService.class).updateChain() - .set(PROFIT_SHARING.OUT_PROFIT_SHARING_ID, profitSharingResult.getOrderId()) - .set(PROFIT_SHARING.PROFIT_SHARING_STATUS, 1) - .where(PROFIT_SHARING.ID.eq(profitSharingResult.getOutOrderNo())) + DbChain.table("cp_sys_profit_sharing") + .set("out_profit_sharing_id", profitSharingResult.getOrderId()) + .set("profit_sharing_status", 1) + .where("id = ?", profitSharingResult.getOutOrderNo()) .update(); } else { throw new ServiceException(profitSharingResult.getReturnMsg()); } } catch (WxPayException e) { if (flag > 5) { - //关闭商城支付 - SpringUtils.getBean(BrandService.class).updateChain().set(BRAND.IS_OPEN_SHARING, false).where(BRAND.WX_MCH_ID.eq(wxPayService.getConfig().getSubMchId())).update(); + if (OrderSource.MALL == orderSource) { + //关闭商城支付 + DbChain.table("cp_sys_brand") + .set("is_open_sharing", false) + .where("wx_mch_id = ?", wxPayService.getConfig().getSubMchId()) + .update(); + } throw new ServiceException(e.getMessage()); } else { //重复调用 flag = flag + 1; - wxPayProfitSharing(profitSharingRequest, wxPayService, flag); + wxPayProfitSharing(profitSharingRequest, wxPayService, flag, orderSource); } } }