diff --git a/cash-api/order-server/src/main/java/com/czg/controller/DistributionPayController.java b/cash-api/order-server/src/main/java/com/czg/controller/DistributionPayController.java index 873201979..1afaa9c5b 100644 --- a/cash-api/order-server/src/main/java/com/czg/controller/DistributionPayController.java +++ b/cash-api/order-server/src/main/java/com/czg/controller/DistributionPayController.java @@ -6,6 +6,7 @@ import com.czg.resp.CzgResult; import com.czg.sa.StpKit; import com.czg.service.order.service.DistributionPayService; import com.czg.system.service.SysParamsService; +import com.czg.utils.AssertUtil; import com.czg.utils.ServletUtil; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; @@ -52,14 +53,14 @@ public class DistributionPayController { /** - * 运营端小程序支付 + * 运营端小程序余额充值 * payType 必填 支付方式,aliPay 支付宝,wechatPay 微信 - * openId 必填 */ @PostMapping("/mchRecharge") @Debounce(value = "#payParam.userId") public CzgResult> mchRecharge(@RequestHeader Long shopId, HttpServletRequest request, @Validated @RequestBody MkDistributionPayDTO payParam) { payParam.setShopId(shopId); + AssertUtil.isBlank(payParam.getCode(), "微信code不为空"); return CzgResult.success(payService.mchRecharge(ServletUtil.getClientIP(request), payParam)); } // diff --git a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java index c48c0e6f2..2c8100c2c 100644 --- a/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java +++ b/cash-api/order-server/src/main/java/com/czg/controller/NotifyController.java @@ -7,14 +7,18 @@ import cn.hutool.core.util.RandomUtil; import com.alibaba.fastjson2.JSONObject; import com.czg.CzgPayUtils; import com.czg.entity.CzgBaseRespParams; +import com.czg.market.service.MkDistributionConfigService; import com.czg.mq.PrintMqListener; +import com.czg.order.entity.OrderPayment; import com.czg.order.service.OrderInfoService; +import com.czg.order.service.OrderPaymentService; import com.czg.order.service.ShopTableOrderStatisticService; import com.czg.service.Impl.WxServiceImpl; import com.czg.system.service.WxService; import com.czg.task.StatisticTask; import com.czg.utils.AssertUtil; import com.ijpay.core.kit.AesUtil; +import com.mybatisflex.core.query.QueryWrapper; import jakarta.annotation.Resource; import jakarta.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; @@ -46,11 +50,15 @@ public class NotifyController { private ShopTableOrderStatisticService shopTableOrderStatisticService; @Resource private WxService wxService; + @Resource + private MkDistributionConfigService distributionConfigService; + @Resource + private OrderPaymentService paymentService; @GetMapping("testOpen") public Map test1(String code) throws Exception { - return wxService.v3Pay("oeQYq5LzW-kSxJL9TR4s_UmOmNLE", new BigDecimal("0.01"), "测试", "testZs" + RandomUtil.randomNumbers(20), "test"); + return wxService.v3Pay("oeQYq5LzW-kSxJL9TR4s_UmOmNLE", new BigDecimal("0.01"), "测试", "testZs" + RandomUtil.randomNumbers(20), "distributionRecharge"); } @@ -66,7 +74,6 @@ public class NotifyController { @RequestMapping("/native/wx/pay/distributionRecharge") public String nativeNotify(HttpServletRequest request) throws IOException { - String timestamp = request.getHeader("Wechatpay-Timestamp"); String nonce = request.getHeader("Wechatpay-Nonce"); String serialNo = request.getHeader("Wechatpay-Serial"); @@ -79,14 +86,19 @@ public class NotifyController { String nonceStr = resource.getString("nonce"); String plainText = wxService.decryptToString(associatedData, nonceStr, ciphertext); - log.info("支付通知明文 {}", plainText); + log.info("充值支付通知明文 {}", plainText); JSONObject plainTextJson = JSONObject.parseObject(plainText); String outTradeNo = plainTextJson.getString("out_trade_no"); String tradeState = plainTextJson.getString("trade_state"); String transactionId = plainTextJson.getString("transaction_id"); - if ("SUCCESS" == tradeState) { - + if ("SUCCESS".equals(tradeState)) { + OrderPayment payment = paymentService.getOne(new QueryWrapper().eq(OrderPayment::getOrderNo, outTradeNo)); + payment.setTradeNumber(transactionId); + payment.setPayTime(DateUtil.date().toLocalDateTime()); + payment.setRespJson(plainTextJson.toJSONString()); + paymentService.updateById(payment); + distributionConfigService.rechargeCallBack(payment.getSourceId(), payment.getShopId(), payment.getAmount(), payment.getId()); } return "SUCCESS"; diff --git a/cash-common/cash-common-service/src/main/java/com/czg/account/dto/SysLoginDTO.java b/cash-common/cash-common-service/src/main/java/com/czg/account/dto/SysLoginDTO.java index 2b9787f86..902f43a05 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/account/dto/SysLoginDTO.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/account/dto/SysLoginDTO.java @@ -17,6 +17,6 @@ public record SysLoginDTO( @NotEmpty(message = "uid不为空") String uuid, // 验证码uid @NotNull - Integer loginType // 登录类型 0:商户登录 1:员工登录 + Integer loginType ) { } diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionConfigService.java b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionConfigService.java index 29018d4fe..b96677916 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionConfigService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/service/MkDistributionConfigService.java @@ -19,4 +19,18 @@ public interface MkDistributionConfigService extends IService pay(long userId, MkDistributionPayDTO payDTO); + + Boolean cashPayOrder(long adminId, MkDistributionPayDTO payParam); + + /** + * 分销员开通 + * @param userId 用户 + * @param amount 金额 + * @param shopId 店铺id + */ + void open(Long userId, BigDecimal amount, Long shopId, Long sourceId); + + void rechargeCallBack(Long userId, Long shopId, BigDecimal amount, Long paymentId); } diff --git a/cash-common/cash-common-service/src/main/java/com/czg/order/dto/MkDistributionPayDTO.java b/cash-common/cash-common-service/src/main/java/com/czg/order/dto/MkDistributionPayDTO.java index 5a263fd91..3ac7f8fb2 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/order/dto/MkDistributionPayDTO.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/order/dto/MkDistributionPayDTO.java @@ -29,4 +29,5 @@ public class MkDistributionPayDTO implements Serializable { private String buyerRemark; private BigDecimal amount; private String remark; + private String code; } diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionConfigServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionConfigServiceImpl.java index 21ac2b147..4636464d2 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionConfigServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkDistributionConfigServiceImpl.java @@ -49,6 +49,15 @@ public class MkDistributionConfigServiceImpl extends ServiceImpl pay(long userId, MkDistributionPayDTO payDTO) { + MkDistributionConfigVO detail = detail(payDTO.getShopId()); + AssertUtil.isTrue(detail.getIsEnable() != 1, "分销未开启"); + if (!TableValueConstant.DistributionConfig.OpenType.PAY.getCode().equals(detail.getOpenType())) { + throw new CzgException("当前未开启购买分销配置"); + } + + OrderPayment orderPayment = new OrderPayment().setShopId(payDTO.getShopId()).setSourceId(userId) + .setPayType("distribution").setOrderNo(payDTO.getPlatformType() + IdUtil.getSnowflakeNextId()).setAmount(detail.getPayAmount()); + orderPaymentService.save(orderPayment); + + return Map.of(); + } + + @Override + public Boolean cashPayOrder(long adminId, MkDistributionPayDTO payParam) { + ShopInfo shopInfo = shopInfoService.getById(payParam.getShopId()); + AssertUtil.isNull(shopInfo, "店铺不存在"); + BigDecimal amount = shopInfoService.updateAmount(shopInfo.getId(), payParam.getAmount()); + Long mainShopId = shopInfoService.getMainIdByShopId(shopInfo.getId()); + + distributionAmountFlowService.save(new MkDistributionAmountFlow() + .setType(payParam.getAmount().compareTo(BigDecimal.ZERO) < 0 ? TableValueConstant.DistributionAmountFlow.Type.MANUAL_SUB.getCode() : + TableValueConstant.DistributionAmountFlow.Type.MANUAL_RECHARGE.getCode()) + .setMainShopId(mainShopId).setShopId(shopInfo.getId()).setAmount(amount).setChangeAmount(payParam.getAmount()) + .setRemark(payParam.getRemark()).setOpAccount(StpKit.USER.getAccount())); + return true; + } + + @Override + public void open(Long userId, BigDecimal amount, Long shopId, Long sourceId) { + ShopUser shopUserInfo = shopUserService.getShopUserInfo(shopId, userId); + Long mainShopId = shopInfoService.getMainIdByShopId(shopId); + BigDecimal finalAmount = shopInfoService.updateAmount(shopId, amount); + distributionAmountFlowService.save(new MkDistributionAmountFlow() + .setType(TableValueConstant.DistributionAmountFlow.Type.OPEN.getCode()) + .setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(sourceId) + .setRemark("分销员购买").setOpAccount(StpKit.USER.getAccount())); + distributionUserService.addDistributionUser(new MkDistributionUser().setParentId(null).setShopId(shopId) + .setShopUserId(shopUserInfo.getId()).setOpeningMethod("付费开通")); + } + + + @Override + public void rechargeCallBack(Long userId, Long shopId, BigDecimal amount, Long paymentId) { + Long mainShopId = shopInfoService.getMainIdByShopId(shopId); + BigDecimal finalAmount = shopInfoService.updateAmount(shopId, amount); + distributionAmountFlowService.save(new MkDistributionAmountFlow() + .setType(TableValueConstant.DistributionAmountFlow.Type.SELF_RECHARGE.getCode()) + .setMainShopId(mainShopId).setShopId(shopId).setAmount(finalAmount).setChangeAmount(amount).setSourceId(paymentId) + .setRemark("自助充值").setOpAccount(StpKit.USER.getAccount())); + } } diff --git a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/DistributionPayServiceImpl.java b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/DistributionPayServiceImpl.java index 4dad40358..429fc68bc 100644 --- a/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/DistributionPayServiceImpl.java +++ b/cash-service/order-service/src/main/java/com/czg/service/order/service/impl/DistributionPayServiceImpl.java @@ -1,6 +1,7 @@ package com.czg.service.order.service.impl; import cn.hutool.core.util.IdUtil; +import cn.hutool.core.util.StrUtil; import com.czg.account.entity.ShopInfo; import com.czg.account.entity.ShopUser; import com.czg.account.entity.UserInfo; @@ -82,6 +83,11 @@ public class DistributionPayServiceImpl implements DistributionPayService { initInfo.setPayment(orderPayment).setShopUser(shopUserInfo) .setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId()); } + + if (StrUtil.isNotBlank(payParam.getCode())) { + String openId = wxService.getOpenId(payParam.getCode()); + initInfo.setOpenId(openId); + } return initInfo; }