55 Commits

Author SHA1 Message Date
6b3fb08036 打印 单价 2026-01-17 11:24:44 +08:00
484ffb07e5 多余 controller 2026-01-17 10:32:10 +08:00
e9ef1b0fac 支付参数 2026-01-17 10:25:19 +08:00
04be17d63e 暂时限制开通 2026-01-17 09:55:05 +08:00
21da0a344c Merge branch 'test' into prod
# Conflicts:
#	cash-api/account-server/src/main/java/com/czg/controller/admin/AuthorizationController.java
#	cash-api/order-server/src/main/java/com/czg/controller/DistributionPayController.java
#	cash-service/order-service/src/main/java/com/czg/service/order/service/impl/OrderInfoCustomServiceImpl.java
#	cash-service/order-service/src/main/java/com/czg/service/order/service/impl/PayServiceImpl.java
2026-01-17 09:52:55 +08:00
656db661ab 进件关联 2026-01-16 18:20:06 +08:00
4498108fb5 进件关联 2026-01-16 17:55:03 +08:00
235c442c6d 进件关联 2026-01-16 17:49:52 +08:00
592cc99db4 进件关联 2026-01-16 17:42:02 +08:00
f8db70ca43 支付回调问题 2026-01-16 16:24:41 +08:00
1f6593c957 进件查询问题 2026-01-16 16:16:48 +08:00
b22b9bd4d6 进件查询问题 2026-01-16 16:15:17 +08:00
d6ef8cfba9 店铺名称问题 2026-01-16 09:57:44 +08:00
gong
0fbe490178 微信支付 进件增加 h5支付域名 2026-01-15 16:04:22 +08:00
d693bb0dd3 Merge remote-tracking branch 'origin/test' into test 2026-01-15 15:46:14 +08:00
b6e3d109fc 常量 2026-01-15 15:45:57 +08:00
gong
b83c53fe04 微信退款 退款中处理4 2026-01-15 15:40:42 +08:00
gong
5b617b653b 微信退款 退款中处理3 2026-01-15 15:39:28 +08:00
gong
4866784afe 微信退款 退款中处理 2026-01-15 15:36:32 +08:00
gong
97bf69eb31 微信退款 退款中处理 2026-01-15 15:31:57 +08:00
gong
aca48f84d9 微信支付回调日期格式化 2026-01-15 15:17:57 +08:00
9834c59fc7 常量 2026-01-15 14:31:26 +08:00
c151a0188d 支付参数5 2026-01-15 14:15:32 +08:00
2c417daa3f 支付参数5 2026-01-15 14:12:57 +08:00
b3a161d643 支付参数4 2026-01-15 14:08:57 +08:00
df72bad0dc Merge remote-tracking branch 'origin/test' into test 2026-01-15 14:05:06 +08:00
071e7f5c82 支付参数3 2026-01-15 14:04:36 +08:00
gong
2259818ae1 修改查询订单状态封装 2026-01-15 14:04:36 +08:00
5541ed5da4 支付参数2 2026-01-15 14:01:10 +08:00
9143331267 支付参数 2026-01-15 13:54:06 +08:00
gong
98dfda0bca 修改退款申请封装 2026-01-15 13:32:55 +08:00
ee25493570 支付参数 2026-01-15 11:32:49 +08:00
a59ea2e841 获取进件信息 2026-01-15 11:05:33 +08:00
01aad45a2b 定时任务 修改进件信息处理 2026-01-15 10:47:51 +08:00
b8a6ce495c 定时任务 修改进件信息处理 2026-01-15 10:38:58 +08:00
gong
cdd012c2fe shopid 为1 2026-01-15 10:23:29 +08:00
gong
7f64a64dc8 shopid 为空 2026-01-15 10:17:58 +08:00
7351188660 支付平台 2026-01-15 09:52:30 +08:00
feee0f8534 去除<?> 2026-01-14 19:18:03 +08:00
gong
c4cb2989b3 集成 封装处理 2026-01-14 18:43:20 +08:00
c48c0f6d7d 常量 2026-01-14 18:31:52 +08:00
bfff341d17 团购扫码 token获取信息 2026-01-14 17:48:59 +08:00
e301f996ad 导入问题 2026-01-14 17:46:18 +08:00
af0df0d378 报错 2026-01-14 17:40:19 +08:00
721819c3e8 团购扫码 token获取信息 2026-01-14 17:35:13 +08:00
b473c82e4f 多余导入 2026-01-14 17:17:19 +08:00
1b975c2164 支付调整 2026-01-14 17:09:57 +08:00
f85ac0815b 计算成本价问题 2026-01-05 14:31:32 +08:00
80fb367673 统计 2026-01-05 11:30:16 +08:00
574c73d0b5 shop_user查询多个的问题 2026-01-05 09:37:45 +08:00
cb18aa5670 退款问题 2025-12-26 17:09:34 +08:00
da3447cd0b 异步执行退款额外问题 2025-12-26 16:21:59 +08:00
9e946443ec sql问题 2025-12-26 16:18:17 +08:00
71ffdede19 分销退款问题 2025-12-26 16:02:31 +08:00
353404dde4 显式抛出 2025-12-26 14:53:38 +08:00
55 changed files with 882 additions and 587 deletions

View File

@@ -1,27 +1,18 @@
package com.czg.controller.admin;
import cn.hutool.http.server.HttpServerRequest;
import cn.hutool.http.server.HttpServerResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.czg.account.dto.SysLoginDTO;
import com.czg.account.entity.ShopInfo;
import com.czg.account.service.*;
import com.czg.account.entity.SysUser;
import com.czg.account.service.AuthorizationService;
import com.czg.account.service.ShopInfoService;
import com.czg.account.service.SysUserService;
import com.czg.account.vo.LoginVO;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaStaffCheckPermission;
import com.czg.config.RabbitPublisher;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
@@ -35,11 +26,9 @@ public class AuthorizationController {
@Resource
private AuthorizationService authorizationService;
@Resource
private PermissionService permissionService;
@Resource
private ShopInfoService shopInfoService;
@Resource
private ShopStaffService shopStaffService;
private SysUserService sysUserService;
/**
@@ -77,27 +66,6 @@ public class AuthorizationController {
return CzgResult.success(StpKit.USER.getPermissionList());
}
@Resource
RabbitPublisher rabbitPublisher;
@Resource
ShopTableService shopTableService;
@GetMapping("test")
public CzgResult<?> login(HttpServletRequest request, HttpServletResponse response) throws IOException {
// shopTableService.createQrCode(1L, 1, response, request);
// rabbitPublisher.sendOrderPrintMsg("552");
// printMqListener.orderPrint("1");
// return CzgResult.success(Map.of("token", StpKit.USER.getShopId()));
return CzgResult.success(StpKit.USER.getLoginId());
}
@GetMapping("test1")
public CzgResult<?> login1() throws IOException {
authorizationService.switchTo(86L);
return CzgResult.success(StpKit.USER.getLoginId());
}
/**
* 核销获取 信息使用
@@ -105,14 +73,11 @@ public class AuthorizationController {
*/
@GetMapping("/userInfo")
public CzgResult<Map<String, Object>> getUserInfo() {
String account = StpKit.USER.getAccount();
ShopInfo shopInfo = shopInfoService.queryChain()
.select(ShopInfo::getId, ShopInfo::getShopName)
.eq(ShopInfo::getId, StpKit.USER.getShopId()).one();
if (account.contains("@")) {
account = account.split("@")[1];
}
Map<String, Object> map = Map.of("shopId", shopInfo.getId(), "shopName", shopInfo.getShopName(), "account", account);
SysUser one = sysUserService.queryChain().eq(SysUser::getId, StpKit.USER.getShopId()).one();
Map<String, Object> map = Map.of("shopId", shopInfo.getId(), "shopName", shopInfo.getShopName(), "account", one.getAccount());
return CzgResult.success(map);
}
}

View File

@@ -3,12 +3,13 @@ package com.czg.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.CzgPayUtils;
import com.czg.PayCst;
import com.czg.PolyPayUtils;
import com.czg.constant.PayChannelCst;
import com.czg.constants.PayTypeConstants;
import com.czg.dto.req.WechatNotifyReqDto;
import com.czg.dto.req.WechatPayNotifyDataDto;
import com.czg.entity.CzgBaseRespParams;
import com.czg.entity.PolyBaseResp;
import com.czg.exception.CzgException;
import com.czg.market.entity.MkShopConsumeDiscountRecord;
import com.czg.market.service.MkDistributionUserService;
@@ -18,6 +19,7 @@ import com.czg.order.entity.OrderInfo;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderInfoCustomService;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.PayNotifyRespDTO;
import com.czg.service.market.service.impl.AppWxServiceImpl;
import com.czg.third.wechat.WechatReqUtils;
import com.czg.utils.AssertUtil;
@@ -75,6 +77,8 @@ public class NotifyController {
log.info("【微信支付回调】解密数据 {}", decrypted);
WechatPayNotifyDataDto dataDto = JSONObject.parseObject(decrypted, WechatPayNotifyDataDto.class);
PayNotifyRespDTO respDTO = dataDto.convertToPayNotifyRespDTO();
orderInfoCustomService.payCallBackOrder(respDTO.getMchOrderNo(), respDTO, PayChannelCst.NATIVE, 0);
return "success";
} else if (PayCst.Platform.ALIPAY.equalsIgnoreCase(platform)) {
// 支付宝
@@ -105,11 +109,11 @@ public class NotifyController {
@RequestMapping("/payCallBack")
public String notifyCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "支付回调数据为空");
log.info("支付回调数据为:{}", czg);
orderInfoCustomService.payCallBackOrder(czg.getString("mchOrderNo"), czg, 0);
public String notifyCallBack(@RequestBody PolyBaseResp respParams) {
PayNotifyRespDTO respDTO = PolyPayUtils.getNotifyResp(respParams);
AssertUtil.isNull(respDTO, "支付回调数据为空");
log.info("支付回调数据为:{}", respDTO);
orderInfoCustomService.payCallBackOrder(respDTO.getMchOrderNo(), respDTO, PayChannelCst.POLY, 0);
return SUCCESS;
}
@@ -131,12 +135,15 @@ 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");
String signature = request.getHeader("Wechatpay-Signature");
// String timestamp = request.getHeader("Wechatpay-Timestamp");
// String nonce = request.getHeader("Wechatpay-Nonce");
// String serialNo = request.getHeader("Wechatpay-Serial");
// String signature = request.getHeader("Wechatpay-Signature");
String result = IoUtil.readUtf8(request.getInputStream());
JSONObject jsonObject = JSONObject.parseObject(result);
JSONObject resource = jsonObject.getJSONObject("resource");
@@ -171,8 +178,8 @@ public class NotifyController {
@RequestMapping("/refundCallBack")
public String refundCallBack(@RequestBody CzgBaseRespParams respParams) {
JSONObject czg = CzgPayUtils.getCzg(respParams);
public String refundCallBack(@RequestBody PolyBaseResp respParams) {
JSONObject czg = PolyPayUtils.getCzg(respParams);
AssertUtil.isNull(czg, "退款回调数据为空");
log.info("退款回调数据为:{}", czg);
orderInfoCustomService.refundCallBackOrder(czg.getString("mchOrderNo"), czg);

View File

@@ -3,7 +3,6 @@ package com.czg.controller.admin;
import com.alibaba.fastjson2.JSONObject;
import com.czg.EntryManager;
import com.czg.annotation.Debounce;
import com.czg.config.RabbitPublisher;
import com.czg.dto.req.AggregateMerchantDto;
import com.czg.dto.resp.WechatBankBranchRespDto;
import com.czg.order.entity.ShopDirectMerchant;
@@ -33,9 +32,6 @@ public class EntryManagerController {
@Resource
private EntryManagerTask entryManagerTask;
@Resource
private RabbitPublisher rabbitPublisher;
/**
* ocr识别填充
* 阿里 ocr识别图片
@@ -68,12 +64,6 @@ public class EntryManagerController {
return CzgResult.success(EntryManager.queryBankBranchList(bankAliceCode, cityCode));
}
@GetMapping("test")
public CzgResult<Void> test(String shopId, String licenceNo) {
rabbitPublisher.sendEntryManagerMsg(shopId + ":" + licenceNo);
return CzgResult.success();
}
/**
* 获取进件列表
*/
@@ -87,8 +77,8 @@ public class EntryManagerController {
* 获取进件信息
*/
@GetMapping
public CzgResult<AggregateMerchantVO> getEntry(Long shopId, String licenceNo) {
return CzgResult.success(shopDirectMerchantService.getEntry(shopId, licenceNo));
public CzgResult<AggregateMerchantVO> getEntry(Long shopId) {
return CzgResult.success(shopDirectMerchantService.getEntry(shopId));
}
/**
@@ -98,8 +88,8 @@ public class EntryManagerController {
*/
@GetMapping("queryEntry")
@Debounce(value = "#shopId", interval = 1000 * 60 * 3)
public CzgResult<Boolean> queryEntry(Long shopId, String licenceNo) {
entryManagerTask.entryManager(shopId, licenceNo);
public CzgResult<Boolean> queryEntry(Long shopId) {
entryManagerTask.entryManager(shopId);
return CzgResult.success();
}

View File

@@ -2,11 +2,12 @@ package com.czg.controller.admin;
import com.czg.annotation.SaAdminCheckPermission;
import com.czg.annotation.SaAdminCheckRole;
import com.czg.constant.PayChannelCst;
import com.czg.exception.CzgException;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
@@ -45,15 +46,18 @@ public class ShopMerchantController {
@SaAdminCheckPermission(parentName = "支付参数信息", value = "shopMerchant:edit", name = "商户支付信息修改")
@PutMapping
public CzgResult<Boolean> edit(@RequestBody ShopMerchantDTO shopMerchant) {
shopMerchant.setShopId(StpKit.USER.getShopId());
if (shopMerchant != null && shopMerchant.getChannel() != null && shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
throw new CzgException("原生支付渠道暂未开通");
}
return CzgResult.success(shopMerchantService.editEntry(shopMerchant, true));
}
/**
* 获取当前店铺的主店进件信息
*/
@SaAdminCheckRole("管理员")
@GetMapping("getMainMerchant")
public CzgResult<ShopDirectMerchant> getMainMerchant() {
return CzgResult.success(shopMerchantService.getMainMerchant(StpKit.USER.getShopId()));
public CzgResult<ShopDirectMerchant> getMainMerchant(Long shopId) {
return CzgResult.success(shopMerchantService.getMainMerchant(shopId));
}
}

View File

@@ -1,7 +1,9 @@
package com.czg.controller.pay;
import com.czg.annotation.Debounce;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.order.entity.OrderPayment;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.QueryOrderRespDTO;
import com.czg.resp.CzgResult;
import com.czg.service.order.dto.VipMemberPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
@@ -10,6 +12,7 @@ import com.czg.service.order.service.PayService;
import com.czg.service.order.service.ShopUserPayService;
import com.czg.utils.AssertUtil;
import com.czg.utils.ServletUtil;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.validation.annotation.Validated;
@@ -32,6 +35,9 @@ public class VipPayController {
@Resource
private ShopUserPayService shopUserPayService;
@Resource
private OrderPaymentService paymentService;
/**
* 现金充值
* 如果shop_info的 is_member_in_pwd=1 则pwd必填 店铺操作密码
@@ -73,9 +79,6 @@ public class VipPayController {
/**
* 智慧充值
* @param request
* @param rechargeDTO
* @return
*/
@PostMapping("/recharge")
@Debounce(value = "#rechargeDTO.shopUserId")
@@ -89,9 +92,6 @@ public class VipPayController {
/**
* 会员购买支付
* @param request
* @param payParam
* @return
*/
@PostMapping("/ltPayMember")
@Debounce(value = "#payParam.shopUserId")
@@ -168,10 +168,16 @@ public class VipPayController {
public CzgResult<String> queryOrderStatus(Long shopId, String payOrderNo) {
AssertUtil.isNull(shopId, "店铺id不能为空");
AssertUtil.isBlank(payOrderNo, "支付单号不能为空");
OrderPayment payment = paymentService.getOne(QueryWrapper.create().eq(OrderPayment::getOrderNo, payOrderNo));
if (payment == null) {
return CzgResult.failure("支付单号不存在");
}
CzgResult<String> result = CzgResult.success();
CzgResult<CzgBaseResp> queryPayOrder = payService.queryPayOrder(shopId, null, payOrderNo);
if (queryPayOrder.getCode() == 200 && queryPayOrder.getData() != null) {
String state = queryPayOrder.getData().getState();
CzgResult<QueryOrderRespDTO> queryPayOrder = payService.queryPayOrder(shopId, null, payOrderNo, payment.getPlatformType());
if (queryPayOrder.isSuccess() && queryPayOrder.getData() != null) {
String state = queryPayOrder.getData().getStatus();
result.setData(state);
switch (state) {
case "TRADE_AWAIT" -> result.setMsg("等待用户付款");

View File

@@ -75,7 +75,7 @@ public class EntryManagerMqListener {
ThreadContext.put("traceId", String.valueOf(shopId));
log.info("进件2MQ对接开始shopId:{}", msg);
// 安全转换shopId
AggregateMerchantVO entry = shopDirectMerchantService.getEntry(shopId, split[1]);
AggregateMerchantVO entry = shopDirectMerchantService.getEntry(shopId);
log.info("进件3MQ对接开始shopId:{}", msg);
if (entry != null) {
EntryManager.uploadParamImage(entry);

View File

@@ -2,19 +2,18 @@ package com.czg.task;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.EntryManager;
import com.czg.PayCst;
import com.czg.constant.PayChannelCst;
import com.czg.dto.resp.QueryStatusResp;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.pay.AlipayAuthInfoDto;
import com.czg.pay.NativeMerchantDTO;
import com.czg.service.order.service.ShopDirectMerchantService;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@@ -30,7 +29,7 @@ import java.util.List;
public class EntryManagerTask {
@Resource
private ShopDirectMerchantService shopDirectMerchantService;
@DubboReference
@Resource
private ShopMerchantService shopMerchantService;
//每10分钟查一次
@@ -38,17 +37,16 @@ public class EntryManagerTask {
public void run() {
log.info("进件查询,定时任务执行");
long start = System.currentTimeMillis();
entryManager(null, null);
entryManager(null);
log.info("进件查询,定时任务执行完毕,耗时:{}ms", start - System.currentTimeMillis());
}
/**
* 查询状态为待处理、待签约、待审核的进件
*/
public void entryManager(Long shopId, String licenceNo) {
public void entryManager(Long shopId) {
List<ShopDirectMerchant> list = shopDirectMerchantService.list(QueryWrapper.create()
.eq(ShopDirectMerchant::getShopId, shopId)
.eq(ShopDirectMerchant::getLicenceNo, licenceNo)
.in(ShopDirectMerchant::getWechatStatus, PayCst.EntryStatus.NEED_QUERY_LIST)
.or(ShopDirectMerchant::getAlipayStatus).in(PayCst.EntryStatus.NEED_QUERY_LIST));
if (CollUtil.isEmpty(list)) {
@@ -79,16 +77,20 @@ public class EntryManagerTask {
}
shopDirectMerchantService.updateById(shopDirectMerchant);
if (StrUtil.isNotBlank(wechatMerchantId) || StrUtil.isNotBlank(alipayMerchantId)) {
ShopMerchantDTO shopMerchantDTO = new ShopMerchantDTO();
shopMerchantDTO.setShopId(shopId);
shopMerchantDTO.setChannel(PayChannelCst.NATIVE);
shopMerchantDTO.setRelatedLicenceNo(licenceNo);
// ShopMerchantDTO shopMerchantDTO = new ShopMerchantDTO();
// shopMerchantDTO.setShopId(shopId);
// shopMerchantDTO.setChannel(PayChannelCst.NATIVE);
// shopMerchantDTO.setRelatedId(shopDirectMerchant.getShopId());
NativeMerchantDTO nativeMerchantDTO = new NativeMerchantDTO();
nativeMerchantDTO.setWechatMerchantId(wechatMerchantId);
nativeMerchantDTO.setAlipayMerchantId(alipayMerchantId);
shopMerchantDTO.setNativeMerchantDTO(nativeMerchantDTO);
shopMerchantDTO.setNativeMerchantDTO(nativeMerchantDTO);
shopMerchantService.editEntry(shopMerchantDTO, false);
if (StrUtil.isNotBlank(shopDirectMerchant.getAlipayAuthInfo())) {
AlipayAuthInfoDto alipayAuthInfoDto = JSONObject.parseObject(shopDirectMerchant.getAlipayAuthInfo(), AlipayAuthInfoDto.class);
nativeMerchantDTO.setAlipayAuthInfo(alipayAuthInfoDto);
}
// shopMerchantDTO.setNativeMerchantDTO(nativeMerchantDTO);
// shopMerchantService.editEntry(shopMerchantDTO, false);
shopMerchantService.upMerchant(shopDirectMerchant.getShopId(), nativeMerchantDTO);
}
}
}

View File

@@ -50,9 +50,8 @@ public class FastJson2Config implements WebMvcConfigurer {
// 设置支持的媒体类型
List<MediaType> supportedMediaTypes = new ArrayList<>();
supportedMediaTypes.add(MediaType.APPLICATION_JSON);
supportedMediaTypes.add(MediaType.APPLICATION_JSON_UTF8);
converter.setSupportedMediaTypes(supportedMediaTypes);
// 将转换器添加到 Spring MVC 的消息转换器列表中
converters.add(0, converter);
converters.addFirst(converter);
}
}

View File

@@ -10,7 +10,7 @@
<artifactId>cash-common-service</artifactId>
<packaging>jar</packaging>
<name>global-service</name>
<name>common-service</name>
<url>https://maven.apache.org</url>

View File

@@ -1,7 +0,0 @@
package com.czg.account.service;
/**
* @author Administrator
*/
public interface PermissionService {
}

View File

@@ -79,9 +79,27 @@ public interface ParamCodeCst {
* 超掌柜支付回调地址
* <p>支付宝/微信支付完成后,支付平台回调我方系统的地址</p>
*/
// public static String PAY_CZG_NOTIFY_URL = "pay_czg_notify_url";
public static String NATIVE_PAY_NOTIFY_URL = "native_pay_notify_url";
public static String NATIVE_REFUND_NOTIFY_URL = "native_refund_notify_url";
/**
* 超掌柜支付域名
* <p>超掌柜支付相关接口的根域名</p>
*/
public static String POLY_DOMAIN = "poly_domain";
public static String POLY_PAY_NOTIFY_URL = "poly_pay_notify_url";
public static String POLY_REFUND_NOTIFY_URL = "poly_refund_notify_url";
/**
* 微信原生回调地址
* <p>微信原生支付接口的回调地址(区别于超掌柜封装的回调)</p>
*/
public static String NATIVE_NOTIFY_URL = "native_notify_url";
/**
* 店铺订单支付BaseUrl
* <p>店铺订单支付页面的基础域名</p>
*/
public static String SHOP_ORDER_PAY_BASE_URL = "shop_order_pay_base_url";
/**
* 排队到号通知
*/
@@ -113,11 +131,6 @@ public interface ParamCodeCst {
*/
public static String SMS_FEE = "sms_fee";
/**
* 店铺订单支付BaseUrl
* <p>店铺订单支付页面的基础域名</p>
*/
public static String SHOP_ORDER_PAY_BASE_URL = "shop_order_pay_base_url";
/**
* 平台名称
@@ -125,30 +138,12 @@ public interface ParamCodeCst {
*/
public static String PLATE_NAME = "plate_name";
/**
* 超掌柜退款回调地址
* <p>支付平台处理退款后,回调我方系统的地址</p>
*/
public static String PAY_CZG_REFUND_NOTIFY_URL = "pay_czg_refund_notify_url";
/**
* 超掌柜支付域名
* <p>超掌柜支付相关接口的根域名</p>
*/
public static String PAY_CZG_DOMAIN = "pay_czg_domain";
/**
* 叫号页面地址
* <p>餐厅叫号系统的前端页面地址</p>
*/
public static String CALL_PAGE_URL = "call_page_url";
/**
* 微信原生回调地址
* <p>微信原生支付接口的回调地址(区别于超掌柜封装的回调)</p>
*/
public static String NATIVE_NOTIFY_URL = "native_notify_url";
/**
* 公众号关注位置
* <p>公众号关注入口的展示位置可选值mine-我的页面、order-订单页面、eat-就餐页面</p>

View File

@@ -43,4 +43,30 @@ public interface SystemConstants {
*/
public static final String CUSTOM = "custom";
}
/**
* 三方支付类型
*/
class PayType {
/**
* 微信支付
*/
public static final String WECHAT = "wechatPay";
/**
* 支付宝支付
*/
public static final String ALIPAY = "alipay";
/**
* 微信小程序支付
*/
public static final String WECHAT_APP_ID = "wxd88fffa983758a30";
/**
* 支付宝小程序支付
*/
public static final String ALIPAY_APP_ID = "2021004145625815";
}
}

View File

@@ -1,6 +1,7 @@
package com.czg.market.service;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
import com.czg.market.dto.MkShopRechargeDTO;
import com.czg.market.vo.MkShopRechargeShopListVO;
import com.czg.market.vo.MkShopRechargeVO;
@@ -21,7 +22,7 @@ import java.util.List;
*/
public interface MkShopRechargeService extends IService<MkShopRecharge> {
MkShopRechargeVO detail(Long shopId);
MkShopRechargeVO detail(Long shopId) throws CzgException;
MkShopRechargeVO detailApp(Long shopId);

View File

@@ -24,6 +24,10 @@ public class MkDistributionPayDTO implements Serializable {
private Long shopId;
private String platformType = "DIS";
private Long userId;
/**
* 支付类型
* {@link com.czg.constants.SystemConstants.PayType}
*/
private String payType;
private String returnUrl;
private String buyerRemark;

View File

@@ -21,9 +21,9 @@ public class ShopMerchantDTO {
private String channel;
/**
* 聚合支付商户
* native 必填 对应 tb_shop_direct_merchant 的 licence_no 营业执照
* native 必填 对应 tb_shop_direct_merchant 的 shopId
*/
private String relatedLicenceNo;
private Long relatedId;
/**
* 原生支付参数
*/

View File

@@ -47,6 +47,11 @@ public class OrderPayment implements Serializable {
*/
private String channel;
/**
* 平台类型
* {@link com.czg.PayCst.Platform}
*/
private String platformType;
/**
* 来源Id 订单Id或充值id
*/
@@ -88,7 +93,7 @@ public class OrderPayment implements Serializable {
*/
private String tradeNumber;
@Column(onUpdateValue = "now()")
// @Column(onUpdateValue = "now()")
private LocalDateTime payTime;
/**
@@ -146,10 +151,11 @@ public class OrderPayment implements Serializable {
}
public static OrderPayment refund(@NonNull Long shopId, @NonNull Long sourceId, @NotBlank String sourceType,
@NotBlank String orderNo, @NonNull BigDecimal amount, Long relatedId) {
@NotBlank String orderNo, @NonNull BigDecimal amount, Long relatedId, String platformType) {
OrderPayment orderPayment = getInstance(shopId, sourceId, sourceType, orderNo, amount, null, relatedId);
orderPayment.setPayType(PayTypeConstants.PayType.REFUND);
orderPayment.setPayStatus(PayTypeConstants.PayStatus.INIT);
orderPayment.setPlatformType(platformType);
return orderPayment;
}

View File

@@ -20,7 +20,7 @@ import java.time.LocalDateTime;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Table("tb_shop_merchant2")
@Table("tb_shop_merchant")
public class ShopMerchant implements Serializable {
@Serial
@@ -41,9 +41,18 @@ public class ShopMerchant implements Serializable {
/**
* 聚合支付商户
* native 必填 对应 tb_shop_direct_merchant 的 licence_no 营业执照
* native 必填 对应 tb_shop_direct_merchant 的 shopId
*/
private String relatedLicenceNo;
private Long relatedId;
/**
* 微信appid
*/
private String wechatAppId;
/**
* 支付宝appid
*/
private String alipayAppId;
/**
* 聚合支付参数

View File

@@ -12,9 +12,9 @@ import com.czg.order.enums.PayEnums;
import com.czg.order.vo.HistoryOrderPrintVo;
import com.czg.order.vo.HistoryOrderVo;
import com.czg.order.vo.OrderInfoVo;
import com.czg.pay.PayNotifyRespDTO;
import com.czg.resp.CzgResult;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
import jakarta.validation.constraints.NotBlank;
import org.jetbrains.annotations.NotNull;
@@ -44,7 +44,7 @@ public interface OrderInfoCustomService {
CzgResult<Object> mergeOrder(MergeOrderDTO param);
void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson, int retryCount);
void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount);
void refundCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson);

View File

@@ -3,9 +3,10 @@ package com.czg.order.service;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.entity.ShopMerchant;
import com.czg.pay.NativeMerchantDTO;
import com.mybatisflex.core.service.IService;
import java.io.Serializable;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
/**
* 第三方商户进件 服务层。
@@ -22,8 +23,14 @@ public interface ShopMerchantService extends IService<ShopMerchant> {
*/
Boolean editEntry(ShopMerchantDTO shopMerchantParam, boolean isUp);
@Override
ShopMerchant getById(Serializable id);
/**
* 已绑定的支付
* 更新商户支付参数
*/
void upMerchant(@NotBlank Long relatedId, @NotNull NativeMerchantDTO nativeMerchantDTO);
ShopMerchant getByShopId(Long shopId);
ShopDirectMerchant getMainMerchant(Long shopId);

View File

@@ -7,7 +7,7 @@ import lombok.NonNull;
* @author ww
*/
@Data
public class CzgPayBaseReq<T> {
public class CzgPayBaseReq {
//必填范围
/**
* 订单标题
@@ -63,6 +63,7 @@ public class CzgPayBaseReq<T> {
/**
* 支付类型
* {@link com.czg.constants.SystemConstants.PayType}
*/
private String payType;
/**
@@ -83,9 +84,9 @@ public class CzgPayBaseReq<T> {
private String subAppid;
/**
* 额外参数
* 支付条码
*/
private T data;
private String authCode;
public CzgPayBaseReq() {
@@ -106,27 +107,27 @@ public class CzgPayBaseReq<T> {
this.notifyUrl = notifyUrl;
}
public static CzgPayBaseReq<?> ltPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
public static CzgPayBaseReq ltPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
, @NonNull String payType, @NonNull String openId, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, payType, openId, clientIp);
return new CzgPayBaseReq(mchOrderNo, detail, amount, payType, openId, clientIp);
}
public static CzgPayBaseReq<?> h5PayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, null, null, clientIp);
public static CzgPayBaseReq h5PayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
return new CzgPayBaseReq(mchOrderNo, detail, amount, null, null, clientIp);
}
public static CzgPayBaseReq<?> jsPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
public static CzgPayBaseReq jsPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount
, @NonNull String payType, @NonNull String openId, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, payType, openId, clientIp);
return new CzgPayBaseReq(mchOrderNo, detail, amount, payType, openId, clientIp);
}
public static CzgPayBaseReq<?> scanPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
return new CzgPayBaseReq<>(mchOrderNo, detail, amount, null, null, clientIp);
public static CzgPayBaseReq scanPayReq(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String clientIp) {
return new CzgPayBaseReq(mchOrderNo, detail, amount, null, null, clientIp);
}
public static CzgPayBaseReq<String> microPay(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String authCode) {
CzgPayBaseReq<String> stringReq = new CzgPayBaseReq<>(mchOrderNo, detail, amount, null, null, null);
stringReq.setData(authCode);
public static CzgPayBaseReq microPay(@NonNull String mchOrderNo, @NonNull String detail, @NonNull Long amount, @NonNull String authCode) {
CzgPayBaseReq stringReq = new CzgPayBaseReq(mchOrderNo, detail, amount, null, null, null);
stringReq.setAuthCode(authCode);
return stringReq;
}
}

View File

@@ -50,16 +50,22 @@ public class CzgRefundReq {
*/
private String notifyUrl;
/**
* 支付平台
*/
private String platform;
/**
* payOrderId和mchOrderNo 二选一 必填
*/
public CzgRefundReq(@NonNull String mchRefundNo, @NonNull String refundReason, @NonNull Long refundAmount,
@NonNull Long orderTotalAmount, String mchOrderNo, String extParam) {
@NonNull Long orderTotalAmount, String mchOrderNo, String extParam, String platform) {
this.mchRefundNo = mchRefundNo;
this.refundReason = refundReason;
this.refundAmount = refundAmount;
this.orderTotalAmount = orderTotalAmount;
this.mchOrderNo = mchOrderNo;
this.extParam = extParam;
this.platform = platform;
}
}

View File

@@ -0,0 +1,67 @@
package com.czg.pay;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 统一支付回调响应数据
* @author yjjie
* @date 2026/1/15 09:16
*/
@Data
@Accessors(chain = true)
public class PayNotifyRespDTO {
/**
* 商户订单号
*/
private String mchOrderNo;
/**
* 三方订单号
*/
private String thirdOrderNo;
/**
* 订单状态
* INIT - 订单初始化;
* TRADE_AWAIT - 待支付;
* TRADE_SUCCESS - 支付成功;
* TRADE_FAIL -支付失败;
* TRADE_CANCEL -交易取消;
* TRADE_REFUND -已退款;
* REFUND_ING - 退款中;
* TRADE_CLOSE -订单关闭
*/
private String status;
/**
* 支付平台
*/
private String platform;
/**
* 订单金额 分
*/
private Long amount;
/**
* 扩展数据
*/
private String extData;
/**
* 支付成功时间
*/
private String paySuccessTime;
/**
* 错误信息
*/
private String errorMsg;
/**
* 回调原始数据
*/
private String originalData;
}

View File

@@ -18,12 +18,6 @@ public class PolyMerchantDTO {
@NotEmpty(message = "商户秘钥不为空")
private String appSecret;
// 支付密码
@NotEmpty(message = "支付密码不为空")
// @NotEmpty(message = "支付密码不为空")
private String payPassword;
// 微信appid
@NotEmpty(message = "微信appid")
private String wechatSmallAppid;
// 支付宝appid
@NotEmpty(message = "支付宝appid")
private String alipaySmallAppid;
}

View File

@@ -0,0 +1,39 @@
package com.czg.pay;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 查询订单响应参数
* @author yjjie
* @date 2026/1/15 13:56
*/
@Data
@Accessors(chain = true)
public class QueryOrderRespDTO {
/**
* 订单号
*/
private String orderNo;
/**
* 状态
*/
private String status;
/**
* 金额
*/
private Long amount;
/**
* 错误信息
*/
private String errorMsg;
/**
* 原始响应数据
*/
private String originResp;
}

View File

@@ -0,0 +1,59 @@
package com.czg.pay;
import lombok.Data;
import lombok.experimental.Accessors;
/**
* 退款相应数据
* @author yjjie
* @date 2026/1/15 11:00
*/
@Data
@Accessors(chain = true)
public class RefundRespDTO {
/**
* 退款状态
* INIT初始化
* ING退款中
* SUCCESS退款成功
* FAIL退款失败
* CLOSE退款关闭
*/
private String status;
/**
* 退款金额
*/
private Long refundAmount;
/**
* 退款时间
*/
private String refundTime;
/**
* 三方退款订单号
*/
private String thirdRefundNo;
/**
* 商户退款订单号
*/
private String merchantRefundNo;
/**
* 退款失败原因
*/
private String errMessage;
/**
* 退款相应原始数据
*/
private String originalData;
/**
* 退款平台
*/
private String platform;
}

View File

@@ -37,6 +37,11 @@
</exclusion>
</exclusions>
</dependency>
<!-- 短信 -->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
@@ -45,10 +50,6 @@
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.fastjson2</groupId>
<artifactId>fastjson2</artifactId>

View File

@@ -59,4 +59,8 @@ public class CzgResult<T> implements Serializable {
public static <T> CzgResult<T> failure(CzgRespCode respCode) {
return new CzgResult<>(respCode.getCode(), respCode.getMsg(), null);
}
public boolean isSuccess() {
return code == 200;
}
}

View File

@@ -27,11 +27,11 @@ public interface PayCst {
/**
* 微信
*/
public static final String WECHAT = "wechat";
public static final String WECHAT = "WECHAT";
/**
* 支付宝
*/
public static final String ALIPAY = "alipay";
public static final String ALIPAY = "ALIPAY";
}
/**

View File

@@ -1,8 +1,8 @@
package com.czg;
import com.czg.dto.req.PayParamsDto;
import com.czg.dto.req.RefundParamsDto;
import com.czg.constants.SystemConstants;
import com.czg.exception.CzgException;
import com.czg.pay.*;
import com.czg.third.alipay.AlipayIsvPayManager;
import com.czg.third.wechat.WechatPayManager;
@@ -20,13 +20,11 @@ public class PayManager {
* @param paramsDto 参数
* @return 结果
*/
public static Map<String, Object> jsapiPay(PayParamsDto paramsDto) {
paramsDto.verifyParams();
if (PayCst.Platform.WECHAT.equals(paramsDto.getPlatform())) {
return WechatPayManager.jsapiPay(null, paramsDto);
} else if (PayCst.Platform.ALIPAY.equals(paramsDto.getPlatform())) {
return AlipayIsvPayManager.jsapiPay(null, paramsDto);
public static Map<String, Object> jsapiPay(CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
if (SystemConstants.PayType.WECHAT.equals(paramsDto.getPayType())) {
return WechatPayManager.jsapiPay(null, paramsDto, merchantDTO);
} else if (SystemConstants.PayType.ALIPAY.equals(paramsDto.getPayType())) {
return AlipayIsvPayManager.jsapiPay(null, paramsDto, merchantDTO);
} else {
throw new CzgException("不支持的支付平台");
}
@@ -38,13 +36,11 @@ public class PayManager {
* @param paramsDto 参数
* @return 结果
*/
public static Map<String, Object> barPay(PayParamsDto paramsDto) {
paramsDto.verifyParams();
if (PayCst.Platform.WECHAT.equals(paramsDto.getPlatform())) {
return WechatPayManager.barPay(null, paramsDto);
} else if (PayCst.Platform.ALIPAY.equals(paramsDto.getPlatform())) {
return AlipayIsvPayManager.barPay(null, paramsDto);
public static Map<String, Object> barPay(CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
if (SystemConstants.PayType.WECHAT.equals(paramsDto.getPayType())) {
return WechatPayManager.barPay(null, paramsDto, merchantDTO);
} else if (SystemConstants.PayType.ALIPAY.equals(paramsDto.getPayType())) {
return AlipayIsvPayManager.barPay(null, paramsDto, merchantDTO);
} else {
throw new CzgException("不支持的支付平台");
}
@@ -53,11 +49,11 @@ public class PayManager {
/**
* 查询订单状态
*/
public static Map<String, Object> queryOrderStatus(String platform, String orderNo, String subMerchantId) {
if (PayCst.Platform.WECHAT.equals(platform)) {
return WechatPayManager.queryOrder(null, orderNo, subMerchantId);
} else if (PayCst.Platform.ALIPAY.equals(platform)) {
return AlipayIsvPayManager.queryOrder(null, orderNo, subMerchantId);
public static QueryOrderRespDTO queryOrderStatus(String platform, String orderNo, NativeMerchantDTO merchantDTO) {
if (SystemConstants.PayType.WECHAT.equals(platform)) {
return WechatPayManager.queryOrder(null, orderNo, merchantDTO);
} else if (SystemConstants.PayType.ALIPAY.equals(platform)) {
return AlipayIsvPayManager.queryOrder(null, orderNo, merchantDTO);
} else {
throw new CzgException("不支持的支付平台");
}
@@ -66,38 +62,16 @@ public class PayManager {
/**
* 退款
*/
public static Map<String, Object> refund(String platform, RefundParamsDto paramsDto) {
if (PayCst.Platform.WECHAT.equals(platform)) {
return WechatPayManager.refundOrder(null, paramsDto);
} else if (PayCst.Platform.ALIPAY.equals(platform)) {
return AlipayIsvPayManager.refundOrder(null, paramsDto);
public static RefundRespDTO refund(CzgRefundReq paramsDto, String notifyUrl, NativeMerchantDTO merchantDTO) {
if (PayCst.Platform.WECHAT.equals(paramsDto.getPlatform())) {
return WechatPayManager.refundOrder(null, paramsDto, notifyUrl, merchantDTO);
} else if (PayCst.Platform.ALIPAY.equals(paramsDto.getPlatform())) {
return AlipayIsvPayManager.refundOrder(null, paramsDto, notifyUrl, merchantDTO);
} else {
throw new CzgException("不支持的支付平台");
}
}
public static void main(String[] args) {
// jsapiPay(new PayParamsDto()
// .setPlatform(PayCst.Platform.ALIPAY)
// .setAppId("2021004145625815")
// .setOpenId("123123123")
// .setOrderNo("1111231231213")
// .setTitle("1213")
// .setMerchantId("123312321")
// .setBody("1213")
// .setAmount(1000L)
// .setPayParams("{\"app_auth_token\": \"ssss\"}")
// .setNotifyUrl("https://www.baidu.com"));
jsapiPay(new PayParamsDto()
.setPlatform(PayCst.Platform.WECHAT)
.setAppId("wxd88fffa983758a30")
.setOpenId("or1l86yipGvwyfPhrKIAcQuSfAV8")
.setOrderNo("1111231231213")
.setTitle("1213")
.setMerchantId("1738216504")
.setBody("1213")
.setAmount(1000L)
.setPayParams("{\"app_auth_token\": \"ssss\"}")
.setNotifyUrl("https://www.baidu.com"));
}
}

View File

@@ -1,8 +1,13 @@
package com.czg.dto.req;
import com.alibaba.fastjson2.annotation.JSONField;
import com.czg.PayCst;
import com.czg.pay.PayNotifyRespDTO;
import lombok.Data;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
/**
* @author yjjie
* @date 2025/12/23 22:21
@@ -115,4 +120,38 @@ public class WechatPayNotifyDataDto {
public Long getPayAmount() {
return Long.valueOf(amount.getTotal());
}
public PayNotifyRespDTO convertToPayNotifyRespDTO() {
ZonedDateTime zonedDateTime = ZonedDateTime.parse(successTime);
DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String time = zonedDateTime.format(outputFormatter);
PayNotifyRespDTO respDTO = new PayNotifyRespDTO()
.setMchOrderNo(outTradeNo)
.setThirdOrderNo(transactionId)
.setAmount(getPayAmount())
.setPlatform(PayCst.Platform.WECHAT)
.setExtData(attach)
.setPaySuccessTime(time)
.setErrorMsg(tradeStateDesc);
switch (tradeState) {
case "SUCCESS":
respDTO.setStatus("TRADE_SUCCESS");
break;
case "CLOSED":
respDTO.setStatus("TRADE_CLOSE");
break;
case "USERPAYING":
respDTO.setStatus("TRADE_AWAIT");
break;
case "NOTPAY":
respDTO.setStatus("TRADE_CANCEL");
break;
default:
respDTO.setStatus("TRADE_FAIL");
break;
}
return respDTO;
}
}

View File

@@ -5,12 +5,12 @@ import com.alipay.v3.ApiException;
import com.alipay.v3.api.AlipayTradeApi;
import com.alipay.v3.model.AlipayTradeCreateModel;
import com.alipay.v3.model.AlipayTradeCreateResponseModel;
import com.alipay.v3.model.AlipayTradePayModel;
import com.alipay.v3.model.ExtendParams;
import com.alipay.v3.util.model.CustomizedParams;
import com.czg.PayCst;
import com.czg.dto.req.PayParamsDto;
import com.czg.dto.req.RefundParamsDto;
import com.czg.exception.CzgException;
import com.czg.pay.*;
import com.czg.third.alipay.dto.config.AlipayConfigDto;
import lombok.extern.slf4j.Slf4j;
@@ -31,23 +31,23 @@ public class AlipayIsvPayManager {
* @param configDto 配置
* @param paramsDto 参数
*/
public static Map<String, Object> jsapiPay(AlipayConfigDto configDto, PayParamsDto paramsDto) {
public static Map<String, Object> jsapiPay(AlipayConfigDto configDto, CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
try {
AlipayClient.setApiClient(configDto);
AlipayTradeApi api = new AlipayTradeApi();
AlipayTradeCreateModel model = new AlipayTradeCreateModel();
model.setOutTradeNo(paramsDto.getOrderNo());
model.setOutTradeNo(paramsDto.getMchOrderNo());
model.setProductCode("JSAPI_PAY");
model.setOpAppId(paramsDto.getAppId());
model.setOpBuyerOpenId(paramsDto.getOpenId());
model.setOpAppId(merchantDTO.getAlipayMerchantId());
model.setOpBuyerOpenId(paramsDto.getUserId());
model.setTotalAmount(getYuanAmountByFen(paramsDto.getAmount()));
model.setSubject(paramsDto.getTitle());
model.setSubject(paramsDto.getSubject());
model.setBody(paramsDto.getBody());
model.setNotifyUrl(paramsDto.getNotifyUrl() + "/" + PayCst.Platform.ALIPAY);
model.setExtendParams(new ExtendParams());
CustomizedParams customizedParams = new CustomizedParams();
customizedParams.setAppAuthToken(paramsDto.getAlipayAuthInfo().getAppAuthToken());
customizedParams.setAppAuthToken(merchantDTO.getAlipayAuthInfo().getAppAuthToken());
AlipayTradeCreateResponseModel responseModel = api.create(model, customizedParams);
log.info("支付宝 jsapi 支付结果: {}", responseModel);
@@ -69,10 +69,26 @@ public class AlipayIsvPayManager {
* @param configDto 配置
* @param paramsDto 参数
*/
public static Map<String, Object> barPay(AlipayConfigDto configDto, PayParamsDto paramsDto) {
public static Map<String, Object> barPay(AlipayConfigDto configDto, CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
try {
AlipayClient.setApiClient(configDto);
// 构造请求参数以调用接口
AlipayTradeApi api = new AlipayTradeApi();
AlipayTradePayModel data = new AlipayTradePayModel();
data.setOutTradeNo(paramsDto.getMchOrderNo());
data.setTotalAmount(getYuanAmountByFen(paramsDto.getAmount()));
data.setSubject(paramsDto.getSubject());
// 设置支付授权码
data.setAuthCode(merchantDTO.getAlipayAuthInfo().getAppAuthToken());
// 设置支付场景
data.setScene("bar_code");
// 设置产品码
data.setProductCode("FACE_TO_FACE_PAYMENT");
data.setAuthCode(paramsDto.getAuthCode());
// AlipayTradeCreateResponseModel responseModel = api.create(data);
return new JSONObject();
// } catch (ApiException e) {
// String body = e.getResponseBody();
@@ -85,12 +101,12 @@ public class AlipayIsvPayManager {
}
}
public static Map<String, Object> queryOrder(AlipayConfigDto configDto, String orderNo, String subMerchantId) {
return new HashMap<>();
public static QueryOrderRespDTO queryOrder(AlipayConfigDto configDto, String orderNo, NativeMerchantDTO merchantDTO) {
return new QueryOrderRespDTO();
}
public static Map<String, Object> refundOrder(AlipayConfigDto configDto, RefundParamsDto paramsDto) {
return new HashMap<>();
public static RefundRespDTO refundOrder(AlipayConfigDto configDto, CzgRefundReq paramsDto, String notifyUrl, NativeMerchantDTO merchantDTO) {
return new RefundRespDTO();
}
/**

View File

@@ -15,9 +15,7 @@ import com.czg.third.wechat.dto.req.entry.*;
import com.czg.third.wechat.dto.req.entry.business.WechatEntryBusinessReqDto;
import com.czg.third.wechat.dto.req.entry.business.WechatEntryIdentityReqDto;
import com.czg.third.wechat.dto.req.entry.business.WechatEntryLicenseReqDto;
import com.czg.third.wechat.dto.req.entry.business.sales.WechatEntryMiniProgramReqDto;
import com.czg.third.wechat.dto.req.entry.business.sales.WechatEntrySalesInfoReqDto;
import com.czg.third.wechat.dto.req.entry.business.sales.WechatEntryStoreInfoReqDto;
import com.czg.third.wechat.dto.req.entry.business.sales.*;
import com.czg.third.wechat.dto.req.entry.id.WechatEntryIdCardReqDto;
import com.czg.third.wechat.dto.resp.WechatAuditDetail;
import com.czg.third.wechat.dto.resp.WechatQueryStateResp;
@@ -319,6 +317,9 @@ public class WechatEntryManager {
WechatEntryMiniProgramReqDto miniProgramInfo = new WechatEntryMiniProgramReqDto();
miniProgramInfo.setMiniProgramAppid("wxd88fffa983758a30");
salesInfo.setMiniProgramInfo(miniProgramInfo);
WechatEntryWebInfoReqDto webInfo = new WechatEntryWebInfoReqDto();
webInfo.setDomain("https://invoice.sxczgkj.cn/pay/");
salesInfo.setWebInfo(webInfo);
businessReqInfo.setSalesInfo(salesInfo);
entryParams.setBusinessInfo(businessReqInfo);

View File

@@ -5,9 +5,8 @@ import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.PayCst;
import com.czg.dto.req.PayParamsDto;
import com.czg.dto.req.RefundParamsDto;
import com.czg.exception.CzgException;
import com.czg.pay.*;
import com.czg.third.wechat.dto.config.WechatPayConfigDto;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.cipher.Signer;
@@ -45,31 +44,31 @@ public class WechatPayManager {
* @param configDto 配置
* @param paramsDto 参数
*/
public static Map<String, Object> jsapiPay(WechatPayConfigDto configDto, PayParamsDto paramsDto) {
public static Map<String, Object> jsapiPay(WechatPayConfigDto configDto, CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
if (configDto == null) {
configDto = WechatPayConfigDto.getDefaultConfig();
}
try {
JSONObject reqData = new JSONObject();
reqData.put("sp_appid", paramsDto.getAppId());
reqData.put("sp_appid", paramsDto.getSubAppid());
reqData.put("sp_mchid", configDto.getMerchantId());
reqData.put("sub_mchid", paramsDto.getMerchantId());
reqData.put("description", paramsDto.getTitle());
reqData.put("out_trade_no", paramsDto.getOrderNo());
reqData.put("sub_mchid", merchantDTO.getWechatMerchantId());
reqData.put("description", paramsDto.getSubject());
reqData.put("out_trade_no", paramsDto.getMchOrderNo());
reqData.put("notify_url", paramsDto.getNotifyUrl() + "/" + PayCst.Platform.WECHAT);
reqData.put("attach", paramsDto.getExtData());
reqData.put("attach", paramsDto.getExtParam());
JSONObject amount = new JSONObject();
amount.put("total", paramsDto.getAmount());
reqData.put("amount", amount);
JSONObject payer = new JSONObject();
payer.put("sp_openid", paramsDto.getOpenId());
payer.put("sp_openid", paramsDto.getUserId());
reqData.put("payer", payer);
String string = WechatReqUtils.postReq(configDto, "/v3/pay/partner/transactions/jsapi", reqData.toJSONString());
log.info("微信支付请求结果: orderNo = {}, res = {}", paramsDto.getOrderNo(), string);
log.info("微信支付请求结果: orderNo = {}, res = {}", paramsDto.getMchOrderNo(), string);
JSONObject object = JSONObject.parseObject(string);
@@ -77,23 +76,23 @@ public class WechatPayManager {
String nonceStr = NonceUtil.createNonce(32);
String packageVal = "prepay_id=" + object.getString("prepay_id");
String message =
paramsDto.getAppId() + "\n" + timestamp + "\n" + nonceStr + "\n" + packageVal + "\n";
paramsDto.getSubAppid() + "\n" + timestamp + "\n" + nonceStr + "\n" + packageVal + "\n";
Config config = WechatConfig.getRsaConfig(configDto);
Signer signer = config.createSigner();
String sign = signer.sign(message).getSign();
JSONObject res = new JSONObject();
res.put("appId", paramsDto.getAppId());
res.put("appId", paramsDto.getSubAppid());
res.put("timeStamp", String.valueOf(timestamp));
res.put("nonceStr", nonceStr);
res.put("package", packageVal);
res.put("signType", "RSA");
res.put("paySign", sign);
log.info("微信支付签名结果: orderNo = {}, res = {}", paramsDto.getOrderNo(), res);
log.info("微信支付签名结果: orderNo = {}, res = {}", paramsDto.getMchOrderNo(), res);
return res;
} catch (Exception e) {
log.error("微信支付异常: orderNo = {}, e = {}", paramsDto.getOrderNo(), e.getMessage());
log.error("微信支付异常: orderNo = {}, e = {}", paramsDto.getMchOrderNo(), e.getMessage());
throw new CzgException("微信支付异常");
}
}
@@ -105,7 +104,7 @@ public class WechatPayManager {
* @param configDto 配置
* @param paramsDto 参数
*/
public static Map<String, Object> barPay(WechatPayConfigDto configDto, PayParamsDto paramsDto) {
public static Map<String, Object> barPay(WechatPayConfigDto configDto, CzgPayBaseReq paramsDto, NativeMerchantDTO merchantDTO) {
try {
if (configDto == null) {
configDto = WechatPayConfigDto.getDefaultConfig();
@@ -119,28 +118,28 @@ public class WechatPayManager {
// 添加根元素
Element xml = document.addElement("xml");
addElementIfNotEmpty(xml, "appid", paramsDto.getAppId());
payMap.put("appid", paramsDto.getAppId());
addElementIfNotEmpty(xml, "appid", paramsDto.getSubAppid());
payMap.put("appid", paramsDto.getSubAppid());
addElementIfNotEmpty(xml, "mch_id", configDto.getMerchantId());
payMap.put("mch_id", configDto.getMerchantId());
addElementIfNotEmpty(xml, "sub_mch_id", paramsDto.getMerchantId());
payMap.put("sub_mch_id", paramsDto.getMerchantId());
addElementIfNotEmpty(xml, "sub_mch_id", merchantDTO.getWechatMerchantId());
payMap.put("sub_mch_id", merchantDTO.getWechatMerchantId());
addElementIfNotEmpty(xml, "nonce_str", nonceStr);
payMap.put("nonce_str", nonceStr);
addElementIfNotEmpty(xml, "body", paramsDto.getTitle());
payMap.put("body", paramsDto.getTitle());
addElementIfNotEmpty(xml, "out_trade_no", paramsDto.getOrderNo());
payMap.put("out_trade_no", paramsDto.getOrderNo());
addElementIfNotEmpty(xml, "body", paramsDto.getSubject());
payMap.put("body", paramsDto.getSubject());
addElementIfNotEmpty(xml, "out_trade_no", paramsDto.getMchOrderNo());
payMap.put("out_trade_no", paramsDto.getMchOrderNo());
addElementIfNotEmpty(xml, "total_fee", paramsDto.getAmount());
payMap.put("total_fee", paramsDto.getAmount());
addElementIfNotEmpty(xml, "spbill_create_ip", paramsDto.getClientIp());
payMap.put("spbill_create_ip", paramsDto.getClientIp());
addElementIfNotEmpty(xml, "auth_code", paramsDto.getBarCode());
payMap.put("auth_code", paramsDto.getBarCode());
addElementIfNotEmpty(xml, "auth_code", paramsDto.getAuthCode());
payMap.put("auth_code", paramsDto.getAuthCode());
if (StrUtil.isNotBlank(paramsDto.getExtData())) {
addElementIfNotEmpty(xml, "attach", paramsDto.getExtData());
payMap.put("attach", paramsDto.getExtData());
if (StrUtil.isNotBlank(paramsDto.getExtParam())) {
addElementIfNotEmpty(xml, "attach", paramsDto.getExtParam());
payMap.put("attach", paramsDto.getExtParam());
}
String sign = signBarPayParam(configDto, payMap);
@@ -154,10 +153,10 @@ public class WechatPayManager {
log.info("微信条码支付参数:{}", xmlStr);
String post = HttpUtil.post(BAR_PAY_URL, xmlStr);
log.info("微信条码支付请求结果: orderNo = {}, res = {}", paramsDto.getOrderNo(), post);
log.info("微信条码支付请求结果: orderNo = {}, res = {}", paramsDto.getMchOrderNo(), post);
JSONObject res = new JSONObject();
res.put("orderNo", paramsDto.getOrderNo());
res.put("orderNo", paramsDto.getMchOrderNo());
SAXReader saxReader = new SAXReader();
Document read = saxReader.read(stringToInputStream(post));
@@ -171,7 +170,7 @@ public class WechatPayManager {
if (StrUtil.isNotBlank(errCode)) {
if ("SYSTEMERROR".equals(errCode) || "BANKERROR".equals(errCode) || "USERPAYING".equals(errCode)) {
// 等待结果
log.info("微信条码支付等待结果: orderNo = {}, err {}", paramsDto.getOrderNo(), errCodeDes);
log.info("微信条码支付等待结果: orderNo = {}, err {}", paramsDto.getMchOrderNo(), errCodeDes);
res.put("status", "TRADE_AWAIT");
return res;
}
@@ -181,19 +180,19 @@ public class WechatPayManager {
}
if (!PAY_SUCCESS.equals(returnCode)) {
log.error("微信条码支付失败: orderNo = {}, msg = {}", paramsDto.getOrderNo(), rootElement.elementText("return_msg"));
log.error("微信条码支付失败: orderNo = {}, msg = {}", paramsDto.getMchOrderNo(), rootElement.elementText("return_msg"));
res.put("status", "TRADE_FAIL");
return res;
}
// 支付成功
log.info("微信条码支付成功: orderNo = {}, msg = {}", paramsDto.getOrderNo(), rootElement.elementText("return_msg"));
log.info("微信条码支付成功: orderNo = {}, msg = {}", paramsDto.getMchOrderNo(), rootElement.elementText("return_msg"));
res.put("status", "TRADE_SUCCESS");
return res;
} catch (CzgException e) {
throw e;
} catch (Exception e) {
log.error("微信条码支付异常: orderNo = {}, e = {}", paramsDto.getOrderNo(), e.getMessage());
log.error("微信条码支付异常: orderNo = {}, e = {}", paramsDto.getMchOrderNo(), e.getMessage());
throw new CzgException("微信支付异常");
}
}
@@ -203,7 +202,7 @@ public class WechatPayManager {
*
* @param configDto 配置
* @param orderNo 订单号
* @param subMerchantId 子商户号
* @param merchantDTO 支付商户信息
* SUCCESS支付成功
* REFUND转入退款
* NOTPAY未支付
@@ -212,34 +211,35 @@ public class WechatPayManager {
* USERPAYING用户支付中仅付款码支付会返回
* PAYERROR支付失败仅付款码支付会返回
*/
public static Map<String, Object> queryOrder(WechatPayConfigDto configDto, String orderNo, String subMerchantId) {
public static QueryOrderRespDTO queryOrder(WechatPayConfigDto configDto, String orderNo, NativeMerchantDTO merchantDTO) {
try {
if (configDto == null) {
configDto = WechatPayConfigDto.getDefaultConfig();
}
String resp = WechatReqUtils.getReq(configDto, "/v3/pay/partner/transactions/out-trade-no/" + orderNo,
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", subMerchantId));
Map.of("sp_mchid", configDto.getMerchantId(), "sub_mchid", merchantDTO.getWechatMerchantId()));
log.info("微信查询订单,订单号:{} 响应:{}", orderNo, resp);
JSONObject res = new JSONObject();
res.put("orderNo", orderNo);
QueryOrderRespDTO queryOrderRespDTO = new QueryOrderRespDTO()
.setOrderNo(orderNo)
.setOriginResp(resp);
JSONObject object = JSONObject.parseObject(resp);
String tradeState = object.getString("trade_state");
res.put("message", object.getString("trade_state_desc"));
queryOrderRespDTO.setErrorMsg(object.getString("trade_state_desc"));
if (PAY_SUCCESS.equals(tradeState)) {
res.put("status", "TRADE_SUCCESS");
return res;
queryOrderRespDTO.setStatus("TRADE_SUCCESS");
return queryOrderRespDTO;
}
if ("USERPAYING".equals(tradeState)) {
res.put("status", "TRADE_AWAIT");
return res;
queryOrderRespDTO.setStatus("TRADE_AWAIT");
return queryOrderRespDTO;
}
res.put("status", "TRADE_FAIL");
return res;
queryOrderRespDTO.setStatus("TRADE_FAIL");
return queryOrderRespDTO;
} catch (Exception e) {
log.error("微信查询订单异常: orderNo = {}, e = {}", orderNo, e.getMessage());
throw new CzgException("微信查询订单异常");
@@ -256,64 +256,69 @@ public class WechatPayManager {
* PROCESSING: 退款处理中
* ABNORMAL: 退款异常,退款到银行发现用户的卡作废或者冻结了,导致原路退款银行卡失败,可前往服务商平台-交易中心,手动处理此笔退款
*/
public static Map<String, Object> refundOrder(WechatPayConfigDto configDto, RefundParamsDto paramsDto) {
public static RefundRespDTO refundOrder(WechatPayConfigDto configDto, CzgRefundReq paramsDto, String notifyUrl, NativeMerchantDTO merchantDTO) {
try {
if (configDto == null) {
configDto = WechatPayConfigDto.getDefaultConfig();
}
JSONObject refundParam = new JSONObject();
refundParam.put("sub_mchid", paramsDto.getMerchantId());
refundParam.put("out_trade_no", paramsDto.getOrderNo());
refundParam.put("out_refund_no", paramsDto.getRefundOrderNo());
refundParam.put("sub_mchid", merchantDTO.getWechatMerchantId());
refundParam.put("out_trade_no", paramsDto.getMchOrderNo());
refundParam.put("out_refund_no", paramsDto.getMchRefundNo());
refundParam.put("reason", paramsDto.getRefundReason());
refundParam.put("notify_url", paramsDto.getRefundNotifyUrl() + "/" + PayCst.Platform.WECHAT);
refundParam.put("notify_url", notifyUrl + "/" + PayCst.Platform.WECHAT);
JSONObject amount = new JSONObject();
amount.put("total", paramsDto.getOrderAmount());
amount.put("total", paramsDto.getOrderTotalAmount());
amount.put("refund", paramsDto.getRefundAmount());
amount.put("currency", "CNY");
refundParam.put("amount", amount);
String resp = WechatReqUtils.postReq(configDto, "/v3/refund/domestic/refunds", refundParam.toJSONString());
log.info("微信退款,订单号:{} 响应:{}", paramsDto.getOrderNo(), resp);
log.info("微信退款,订单号:{} 响应:{}", paramsDto.getMchOrderNo(), resp);
JSONObject object = JSONObject.parseObject(resp);
JSONObject res = new JSONObject();
res.put("mchRefundNo", object.getString("out_refund_no"));
res.put("refundOrderId", object.getString("refund_id"));
res.put("oriPayOrderId", object.getString("out_trade_no"));
res.put("mercNo", paramsDto.getMerchantId());
res.put("refundReason", paramsDto.getRefundReason());
res.put("payType", PayCst.Platform.WECHAT);
res.put("refundTime", object.getString("success_time"));
switch (object.getString("status")) {
case "SUCCESS":
res.put("status", "SUCCESS");
break;
case "CLOSED":
res.put("status", "CLOSED");
break;
case "PROCESSING":
res.put("status", "ING");
break;
case "ABNORMAL":
res.put("status", "INIT");
break;
default:
res.put("status", "FAIL");
break;
}
JSONObject resAmount = object.getJSONObject("amount");
if (resAmount != null) {
res.put("refundAmt", resAmount.getLong("refund"));
res.put("oriAmount", resAmount.getLong("total"));
String code = object.getString("code");
String status = object.getString("status");
if ("INVALID_REQUEST".equalsIgnoreCase(code) || StrUtil.isNotBlank(status)) {
throw new CzgException("微信退款失败:" + object.getString("message"));
}
return res;
RefundRespDTO respDTO = new RefundRespDTO()
.setMerchantRefundNo(object.getString("out_refund_no"))
.setThirdRefundNo(object.getString("refund_id"))
.setRefundTime(object.getString("success_time"))
.setOriginalData(resp)
.setPlatform(PayCst.Platform.WECHAT);
JSONObject resAmount = object.getJSONObject("amount");
if (resAmount != null) {
respDTO.setRefundAmount(resAmount.getLong("refund"));
}
switch (status) {
case "SUCCESS":
case "PROCESSING":
respDTO.setStatus("SUCCESS");
break;
case "CLOSED":
respDTO.setStatus("CLOSED");
break;
case "ABNORMAL":
respDTO.setStatus("INIT");
break;
default:
respDTO.setStatus("FAIL");
break;
}
return respDTO;
} catch (CzgException e) {
throw e;
} catch (Exception e) {
log.error("微信退款异常: orderNo = {}, e = {}", paramsDto.getOrderNo(), e.getMessage());
log.error("微信退款异常: orderNo = {} ", paramsDto.getMchOrderNo(), e);
throw new CzgException("微信退款异常");
}
}
@@ -368,13 +373,13 @@ public class WechatPayManager {
// Map<String, Object> sss1 = queryOrder(null, "sa101293120sss1", "1738216504");
// System.out.println(sss1);
refundOrder(null, new RefundParamsDto()
.setMerchantId("1738216504")
.setOrderNo("sa101293120sss1")
.setRefundOrderNo("sa101293120sss1")
.setOrderAmount(1L)
.setRefundAmount(1L)
.setRefundReason("测试")
.setRefundNotifyUrl("https://www.baidu.com"));
// refundOrder(null, new RefundParamsDto()
// .setMerchantId("1738216504")
// .setOrderNo("sa101293120sss1")
// .setRefundOrderNo("sa101293120sss1")
// .setOrderAmount(1L)
// .setRefundAmount(1L)
// .setRefundReason("测试")
// .setRefundNotifyUrl("https://www.baidu.com"));
}
}

View File

@@ -10,10 +10,12 @@ import com.alibaba.fastjson2.JSONObject;
import com.alibaba.fastjson2.TypeReference;
import com.czg.entity.PolyBaseReq;
import com.czg.entity.PolyBaseResp;
import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.entity.resp.*;
import com.czg.enums.CzgPayEnum;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.PayNotifyRespDTO;
import com.czg.resp.CzgRespCode;
import com.czg.resp.CzgResult;
import com.czg.utils.AssertUtil;
@@ -40,7 +42,7 @@ public class PolyPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgH5PayResp>
*/
public static CzgResult<Map<String, Object>> h5Pay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
public static CzgResult<Map<String, Object>> h5Pay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.H5_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgH5PayResp.class));
}
@@ -52,7 +54,7 @@ public class PolyPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgJsPayResp>
*/
public static CzgResult<Map<String, Object>> jsPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
public static CzgResult<Map<String, Object>> jsPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.JS_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgJsPayResp.class));
}
@@ -64,7 +66,7 @@ public class PolyPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgLtPayResp>
*/
public static CzgResult<Map<String, Object>> ltPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
public static CzgResult<Map<String, Object>> ltPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.LT_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgLtPayResp.class));
}
@@ -76,7 +78,7 @@ public class PolyPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgScanPayResp>
*/
public static CzgResult<Map<String, Object>> scanPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
public static CzgResult<Map<String, Object>> scanPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.SCAN_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgScanPayResp.class));
}
@@ -88,7 +90,7 @@ public class PolyPayUtils {
* @param appSecret 应用密钥 tb_shop_merchant 表中的 app_secret
* CzgResult<CzgMicroPayResp>
*/
public static CzgResult<Map<String, Object>> microPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq<?> bizData) {
public static CzgResult<Map<String, Object>> microPay(@NonNull String domain, @NonNull String appId, @NonNull String appSecret, CzgPayBaseReq bizData) {
return execPayResult(sendPolyPay(domain.concat(CzgPayEnum.MICRO_PAY.getUri()), PolyBaseReq.getInstance(appId, appSecret, bizData), CzgMicroPayResp.class));
}
@@ -158,6 +160,32 @@ public class PolyPayUtils {
}
/**
* 回调数据处理
*/
public static PayNotifyRespDTO getNotifyResp(PolyBaseResp respParams) {
AssertUtil.isNull(respParams, "聚合交易 回调数据为空");
log.info("聚合交易请求响应,{}", respParams);
if (!"000000".equals(respParams.getCode())) {
log.error("聚合回调响应失败,{}", respParams);
return null;
}
CzgPayNotifyDTO dto = JSONObject.parseObject(respParams.getBizData(), CzgPayNotifyDTO.class);
return new PayNotifyRespDTO()
.setMchOrderNo(dto.getMchOrderNo())
.setThirdOrderNo(dto.getPayOrderId())
.setAmount(dto.getAmount())
.setPlatform(dto.getPayType())
.setExtData(dto.getExtParam())
.setPaySuccessTime(dto.getPayTime())
.setErrorMsg("")
.setStatus(dto.getState())
.setOriginalData(respParams.getBizData());
}
/**
* 默认Post
*

View File

@@ -29,6 +29,7 @@ import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.util.*;
@@ -41,7 +42,7 @@ import java.util.stream.Collectors;
* @author zs
* @since 2025-02-21
*/
@DubboService
@Service
public class CallTableServiceImpl extends ServiceImpl<CallTableMapper, CallTable> implements CallTableService {
@DubboReference
private SysParamsService sysParamsService;

View File

@@ -1,11 +0,0 @@
package com.czg.service.account.service.impl;
import com.czg.account.service.PermissionService;
import org.springframework.stereotype.Service;
/**
* @author zs
*/
@Service
public class PermissionServiceImpl implements PermissionService {
}

View File

@@ -17,7 +17,6 @@ import com.czg.constants.ParamCodeCst;
import com.czg.constants.ShopSwitchTypeEnum;
import com.czg.constants.SystemConstants;
import com.czg.exception.CzgException;
import com.czg.order.service.ShopMerchantService;
import com.czg.resp.CzgResult;
import com.czg.sa.MyStpLogic;
import com.czg.sa.StpKit;
@@ -78,8 +77,6 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
private FreeDineConfigService freeDineConfigService;
@Resource
private ShopConfigService shopConfigService;
@Resource
private ShopMerchantService shopMerchantService;
@DubboReference
private SysParamsService sysParamsService;
@@ -256,6 +253,7 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
@Override
@CacheEvict(key = "#shopInfoEditDTO.id")
public Boolean edit(ShopInfoEditDTO shopInfoEditDTO) {
shopInfoEditDTO.setIsMemberPrice(null);
ShopInfo shopInfo;
if (!StpKit.USER.isAdmin()) {
shopInfo = queryChain().eq(ShopInfo::getId, StpKit.USER.getShopId()).one();
@@ -322,8 +320,6 @@ public class ShopInfoServiceImpl extends ServiceImpl<ShopInfoMapper, ShopInfo> i
rabbitPublisher.sendOrderDetailStatusMsg(shopInfo.getId().toString(), "shopInfoUpdate");
return true;
}
return false;
}

View File

@@ -26,8 +26,6 @@ import com.czg.market.vo.InviteUserVO;
import com.czg.market.vo.MkDistributionConfigVO;
import com.czg.order.dto.MkDistributionPayDTO;
import com.czg.order.entity.OrderInfo;
import com.czg.market.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.sa.StpKit;
import com.czg.service.market.enums.OrderStatusEnums;
import com.czg.service.market.mapper.MkDistributionUserMapper;
@@ -685,22 +683,15 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
.ne(MkDistributionFlow::getStatus, TableValueConstant.DistributionFlow.Status.REFUND.getCode()));
list.forEach(item -> {
MkDistributionFlow refundFlow = BeanUtil.copyProperties(item, MkDistributionFlow.class);
refundFlow.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
refundFlow.setSourceId(item.getId());
refundFlow.setId(null);
refundFlow.setCreateTime(DateUtil.date().toLocalDateTime());
refundFlow.setUpdateTime(DateUtil.date().toLocalDateTime());
if (TableValueConstant.DistributionFlow.Status.PENDING.getCode().equals(item.getStatus())) {
item.setStatus(TableValueConstant.DistributionFlow.Status.SUCCESS.getCode());
// updateIncome(item.getRewardAmount().negate(), BigDecimal.ZERO, BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
item.setStatus(TableValueConstant.DistributionFlow.Status.REFUND.getCode());
distributionFlowService.updateById(item);
mapper.updateIncome(item.getRewardAmount().negate(), null, null, item.getDistributionUserId(), item.getShopId());
} else {
// 执行扣款
updateIncome(BigDecimal.ZERO, item.getRewardAmount().negate(), BigDecimal.ZERO, item.getDistributionUserId(), item.getUserId(), item.getShopUserId(), item.getShopId(), item.getLevel());
updateShopInfoAmount(item.getShopId(), item.getRewardAmount(), orderId, TableValueConstant.DistributionAmountFlow.Type.REFUND, "分销回退");
}
distributionFlowService.save(refundFlow);
});
}
@@ -738,6 +729,13 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
distributionDeliverService.save(deliver);
}
/**
* 分销金额修改
*
* @param pendingIncome 待入账金额
* @param receivedIncome 已入账
* @param withdrawIncome 已提现
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void updateIncome(BigDecimal pendingIncome, BigDecimal receivedIncome, BigDecimal withdrawIncome, Long id, Long userId, Long shopUserId, Long shopId, Integer isOne) {

View File

@@ -72,7 +72,7 @@ public class MkShopRechargeServiceImpl extends ServiceImpl<MkShopRechargeMapper,
}
@Override
public MkShopRechargeVO detail(Long shopId) {
public MkShopRechargeVO detail(Long shopId) throws CzgException{
shopId = shopInfoService.getMainIdByShopId(shopId);
ShopInfo shopInfo = shopInfoService.getById(shopId);
if (shopInfo.getMainId() != null) {

View File

@@ -45,36 +45,33 @@
order by a.create_time desc
</select>
<select id="totalAmount" resultType="java.math.BigDecimal">
select sum(a.amount) from mk_distribution_flow as a
left join mk_distribution_user as d on d.id=a.distribution_user_id
left join tb_shop_user as b on a.shop_user_id=b.id
left join tb_shop_user as c on c.id=a.shop_user_id
select sum(a.reward_amount)
from mk_distribution_flow as a
left join tb_shop_user as b on a.shop_user_id = b.id
where a.shop_id=#{shopId}
<if test="id != null">
and a.shop_user_id=#{id}
</if>
<if test="userId != null">
and a.user_id=#{userId}
</if>
<if test="status != null and status != ''">
and a.status=#{status}
</if>
<if test="type != null and type != ''">
and a.type=#{type}
</if>
<if test="startTime != null">
and a.create_time>=#{startTime}
</if>
<if test="endTime != null">
and a.create_time&lt;=#{endTime}
</if>
<if test="status != null and status != ''">
and a.status=#{status}
</if>
<if test="key != null and key != ''">
and (
b.nick_name like concat('%',#{key},'%')
or b.id like concat('%',#{key},'%')
or c.id like concat('%',#{key},'%')
or c.nick_name like concat('%',#{key},'%')
)
</if>
<if test="id != null">
and d.id=#{id}
</if>
<if test="type != null and type != ''">
and a.type=#{type}
</if>
<if test="userId != null">
and d.user_id=#{userId}
</if>
</select>
</mapper>

View File

@@ -5,16 +5,24 @@
<mapper namespace="com.czg.service.market.mapper.MkDistributionUserMapper">
<update id="updateIncome">
update mk_distribution_user
set
<set>
<if test="pendingIncome != null">
total_income = total_income + #{pendingIncome},
</if>
<if test="receivedIncome != null">
total_income = total_income + #{receivedIncome},
</if>
pending_income = pending_income + #{pendingIncome},
received_income = received_income + #{receivedIncome},
withdrawn_income = withdrawn_income + #{withdrawIncome}
<if test="pendingIncome != null">
pending_income = pending_income + #{pendingIncome},
</if>
<if test="receivedIncome != null">
received_income = received_income + #{receivedIncome},
</if>
<if test="withdrawIncome != null">
withdrawn_income = withdrawn_income + #{withdrawIncome}
</if>
</set>
where id = #{id} and shop_id = #{shopId}
</update>

View File

@@ -261,7 +261,7 @@ public interface PrinterImpl {
// data.append("<OUT:15>");
// data.append("<BR>");
// 18个空格 12
data.append(getFormatLabel("品名 数量 小计 ", signLabelInfo.s))
data.append(getFormatLabel("品名 数量 单价 ", signLabelInfo.s))
.append(signLabelInfo.br);
// data.append("<S>品名 数量 小计</S><BR>");
data.append(getFormatLabel("--------------------------------", signLabelInfo.s))

View File

@@ -1,12 +1,12 @@
package com.czg.service.order.service;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.QueryOrderRespDTO;
import com.czg.pay.RefundRespDTO;
import com.czg.resp.CzgResult;
import lombok.NonNull;
@@ -26,7 +26,7 @@ public interface PayService {
Long initPayment(OrderPayment payment);
//-----------------------------------------------------------------付款 ----------------------------------------------------------
CzgResult<Map<String, Object>> pay(@NonNull Long shopId, CzgPayEnum payType, CzgPayBaseReq<?> bizData);
CzgResult<Map<String, Object>> pay(@NonNull Long shopId, CzgPayEnum payType, CzgPayBaseReq bizData);
//-----------------------------------------------------------------积分商品/拼团 付款 ----------------------------------------------------------
/**
@@ -44,7 +44,7 @@ public interface PayService {
* 退款
* 目前订单 会员 使用
*/
CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData);
CzgResult<RefundRespDTO> refund(@NonNull Long shopId, CzgRefundReq bizData);
/**
* 统一退款接口
* 目前 拼团商品 积分商品 套餐推广 使用
@@ -67,7 +67,7 @@ public interface PayService {
* @param payOrderId 平台订单号
* @param mchOrderNo 商户订单号
*/
CzgResult<CzgBaseResp> queryPayOrder(Long shopId, String payOrderId, String mchOrderNo);
CzgResult<QueryOrderRespDTO> queryPayOrder(Long shopId, String payOrderId, String mchOrderNo, String platform);
/**
* 退款查询
@@ -75,5 +75,5 @@ public interface PayService {
* @param mchRefundNo 商户退款订单号 二选一
* @param refundOrderId 平台退款订单号 二选一
*/
CzgResult<CzgRefundResp> queryRefund(Long shopId, String mchRefundNo, String refundOrderId);
CzgResult<RefundRespDTO> queryRefund(Long shopId, String mchRefundNo, String refundOrderId);
}

View File

@@ -29,7 +29,7 @@ public interface ShopDirectMerchantService extends IService<ShopDirectMerchant>
/**
* 获取进件信息
*/
AggregateMerchantVO getEntry(Long shopId, String licenceNo);
AggregateMerchantVO getEntry(Long shopId);
/**
* 申请进件

View File

@@ -7,6 +7,7 @@ import com.czg.account.service.ShopUserService;
import com.czg.account.service.UserInfoService;
import com.czg.constant.TableValueConstant;
import com.czg.constants.PayTypeConstants;
import com.czg.constants.SystemConstants;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.market.service.MkDistributionConfigService;
@@ -82,7 +83,7 @@ public class DistributionPayServiceImpl implements DistributionPayService {
} else {
UserInfo userInfo = userInfoService.getById(userId);
initInfo.setPayment(orderPayment).setShopUser(shopUserInfo)
.setOpenId("aliPay".equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
.setOpenId(SystemConstants.PayType.ALIPAY.equals(payParam.getPayType()) ? userInfo.getAlipayOpenId() : userInfo.getWechatOpenId());
}
return initInfo;
}

View File

@@ -6,7 +6,10 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.exceptions.ValidateException;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.core.util.*;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
@@ -17,9 +20,8 @@ import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst;
import com.czg.constant.MarketConstants;
import com.czg.constant.TableValueConstant;
import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.entity.notify.CzgRefundNotifyDTO;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.notify.CzgRefundNotifyDTO;
import com.czg.enums.ShopTableStatusEnum;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
@@ -40,6 +42,7 @@ import com.czg.order.entity.OrderPayment;
import com.czg.order.enums.PayEnums;
import com.czg.order.service.*;
import com.czg.order.vo.*;
import com.czg.pay.PayNotifyRespDTO;
import com.czg.product.entity.Product;
import com.czg.product.service.ProductRpcService;
import com.czg.product.service.ProductService;
@@ -50,7 +53,6 @@ import com.czg.service.order.enums.OrderStatusEnums;
import com.czg.service.order.mapper.OrderInfoCustomMapper;
import com.czg.service.order.print.PrinterHandler;
import com.czg.utils.*;
import com.czg.utils.PageUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
@@ -1028,13 +1030,12 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
@Override
@Transactional
public void payCallBackOrder(@NotBlank String orderNo, @NotNull JSONObject resultJson, int retryCount) {
CzgPayNotifyDTO czgCallBackDto = JSONObject.parseObject(resultJson.toString(), CzgPayNotifyDTO.class);
public void payCallBackOrder(@NotBlank String orderNo, @NotNull PayNotifyRespDTO notifyRespDTO, String channel, int retryCount) {
OrderPayment payment = paymentService.getOne(new QueryWrapper().eq(OrderPayment::getOrderNo, orderNo));
if (payment == null) {
if (retryCount < MAX_RETRIES) {
log.info("支付记录不存在,第 {} 次重试,将在 {} 秒后进行", retryCount + 1, DELAY);
executorService.schedule(() -> payCallBackOrder(orderNo, resultJson, retryCount + 1), DELAY, TimeUnit.SECONDS);
executorService.schedule(() -> payCallBackOrder(orderNo, notifyRespDTO, channel, retryCount + 1), DELAY, TimeUnit.SECONDS);
} else {
log.error("订单支付回调失败, 达到最大重试次数, 支付记录不存在, orderNo: {}", orderNo);
}
@@ -1044,10 +1045,12 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
log.info("订单处理过payment id{}", payment.getId());
return;
}
payment.setTradeNumber(czgCallBackDto.getPayOrderId());
payment.setRespJson(resultJson.toString());
payment.setTradeNumber(notifyRespDTO.getThirdOrderNo());
payment.setRespJson(notifyRespDTO.getOriginalData());
payment.setPayStatus(PayTypeConstants.PayStatus.FAIL);
if ("TRADE_SUCCESS".equals(czgCallBackDto.getState())) {
payment.setPlatformType(notifyRespDTO.getPlatform());
payment.setChannel(channel);
if ("TRADE_SUCCESS".equals(notifyRespDTO.getStatus())) {
payment.setPayStatus(PayTypeConstants.PayStatus.SUCCESS);
if (PayTypeConstants.SourceType.ORDER.equals(payment.getSourceType())) {
OrderInfo orderInfo = orderInfoService.getById(payment.getSourceId());
@@ -1055,8 +1058,8 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
log.error("订单支付回调失败,订单不存在,支付记录Id,{}", payment.getId());
return;
}
upOrderInfo(orderInfo, new BigDecimal(czgCallBackDto.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.DOWN),
DateUtil.parseLocalDateTime(czgCallBackDto.getPayTime()), payment.getId(), null);
upOrderInfo(orderInfo, new BigDecimal(notifyRespDTO.getAmount()).divide(new BigDecimal(100), 2, RoundingMode.DOWN),
DateUtil.parseLocalDateTime(notifyRespDTO.getPaySuccessTime()), payment.getId(), null);
if (orderInfo.getUserId() != null) {
// 分销员升级等级
distributionUserService.costUpgradeLevelBefore(orderInfo.getUserId(), orderInfo.getShopId());
@@ -1066,14 +1069,14 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
} else if (PayTypeConstants.SourceType.MEMBER_IN.equals(payment.getSourceType()) || PayTypeConstants.SourceType.FREE.equals(payment.getSourceType())) {
boolean isFree = PayTypeConstants.SourceType.FREE.equals(payment.getSourceType());
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
OrderInfo orderInfo = null;
OrderInfo orderInfo;
if (shopUser == null) {
log.error("会员充值失败会员不存在会员id{}", payment.getSourceId());
} else {
ShopUserFlowBizEnum bizEnum;
if ("WECHAT".equals(czgCallBackDto.getPayType())) {
if ("WECHAT".equals(notifyRespDTO.getPlatform())) {
bizEnum = ShopUserFlowBizEnum.WECHAT_IN;
} else if ("ALIPAY".equals(czgCallBackDto.getPayType())) {
} else if ("ALIPAY".equals(notifyRespDTO.getPlatform())) {
bizEnum = ShopUserFlowBizEnum.ALIPAY_IN;
} else {
bizEnum = ShopUserFlowBizEnum.CASH_IN;
@@ -1089,7 +1092,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
.setType(1)
.setBizEnum(ShopUserFlowBizEnum.FREE_IN)
.setRelationId(orderInfo.getId())
.setMoney(BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN));
.setMoney(BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN));
shopUserService.updateMoney(shopUserMoneyEditDTO);
upOrderInfo(orderInfo, BigDecimal.ZERO,
LocalDateTime.now(), null, PayEnums.FREE_PAY);
@@ -1111,7 +1114,7 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
LocalDateTime.now(), null, PayEnums.VIP_PAY);
}
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
BigDecimal.valueOf(czgCallBackDto.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
payment.getId(), payment.getSourceType(), bizEnum, orderInfo == null);
}
}

View File

@@ -17,7 +17,6 @@ import com.czg.account.service.UserInfoService;
import com.czg.config.RabbitPublisher;
import com.czg.config.RedisCst;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
@@ -38,6 +37,7 @@ import com.czg.order.service.OrderInfoCustomService;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.RefundRespDTO;
import com.czg.resp.CzgResult;
import com.czg.service.RedisService;
import com.czg.service.order.dto.OrderPayParamDTO;
@@ -512,21 +512,21 @@ public class OrderPayServiceImpl implements OrderPayService {
OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败支付记录不存在");
Long refundId = payService.initPayment(OrderPayment.refund(shopId, orderId, PayTypeConstants.SourceType.ORDER,
refPayOrderNo, refundAmount, payment.getId()));
refPayOrderNo, refundAmount, payment.getId(), payment.getPlatformType()));
CzgResult<CzgRefundResp> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
if (refund.getData() != null && refund.getData().getNote() != null) {
throw new CzgException(refund.getData().getNote());
CzgResult<RefundRespDTO> refund = payService.refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(PayService.MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), "", payment.getPlatformType()));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getStatus())) {
if (refund.getData() != null && refund.getData().getErrMessage() != null) {
throw new CzgException(refund.getData().getErrMessage());
}
throw new CzgException(refund.getMsg());
} else {
paymentService.updateChain()
.eq(OrderPayment::getId, refundId)
.set(OrderPayment::getPayTime, refund.getData().getRefundTime())
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
.set(OrderPayment::getTradeNumber, refund.getData().getThirdRefundNo())
.set(OrderPayment::getRespJson, refund.getData().getOriginalData())
.update();
}
}

View File

@@ -6,20 +6,21 @@ import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter;
import com.czg.PayAdapterFactory;
import com.czg.order.entity.ShopMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.constant.PayChannelCst;
import com.czg.constants.ParamCodeCst;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.constants.SystemConstants;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.order.dto.LtPayOtherDTO;
import com.czg.order.entity.OrderPayment;
import com.czg.order.entity.ShopMerchant;
import com.czg.order.service.OrderPaymentService;
import com.czg.order.service.ShopMerchantService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.QueryOrderRespDTO;
import com.czg.pay.RefundRespDTO;
import com.czg.resp.CzgResult;
import com.czg.service.order.mapper.OrderPaymentMapper;
import com.czg.service.order.service.PayService;
@@ -44,7 +45,7 @@ import java.util.Map;
@Service
public class PayServiceImpl implements PayService {
@DubboReference
@Resource
private ShopMerchantService shopMerchantService;
@DubboReference
private SysParamsService sysParamsService;
@@ -54,7 +55,7 @@ public class PayServiceImpl implements PayService {
private OrderPaymentMapper paymentMapper;
@Override
public CzgResult<Map<String, Object>> pay(@NonNull Long shopId, CzgPayEnum payType, CzgPayBaseReq<?> bizData) {
public CzgResult<Map<String, Object>> pay(@NonNull Long shopId, CzgPayEnum payType, CzgPayBaseReq bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
@@ -63,6 +64,10 @@ public class PayServiceImpl implements PayService {
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
}
bizData.setSubAppid(SystemConstants.PayType.ALIPAY.equals(bizData.getPayType()) ? shopMerchant.getAlipayAppId() : shopMerchant.getWechatAppId());
if (payType.equals(CzgPayEnum.MICRO_PAY)) {
checkMicroPay(bizData, shopMerchant);
}
return adapter.pay(payType, payData, getDomain(), getNotifyUrl(shopMerchant.getChannel()), bizData);
}
@@ -80,17 +85,18 @@ public class PayServiceImpl implements PayService {
}
@Override
public CzgResult<CzgRefundResp> refund(@NonNull Long shopId, CzgRefundReq bizData) {
public CzgResult<RefundRespDTO> refund(@NonNull Long shopId, CzgRefundReq bizData) {
ShopMerchant shopMerchant = getMerchant(shopId);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
payData = shopMerchant.getNativePayJson();
bizData.setNotifyUrl(sysParamsService.getSysParamValue(ParamCodeCst.System.NATIVE_REFUND_NOTIFY_URL));
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
bizData.setNotifyUrl(sysParamsService.getSysParamValue(ParamCodeCst.System.POLY_REFUND_NOTIFY_URL));
}
// bizData.setNotifyUrl(sysParamsService.getSysParamValue(ParamCodeCst.System.PAY_CZG_REFUND_NOTIFY_URL));
return adapter.refund(getDomain(), payData, "", bizData);
return adapter.refund(getDomain(), payData, bizData);
}
@Override
@@ -99,17 +105,18 @@ public class PayServiceImpl implements PayService {
@NonNull String refundReason, @NonNull BigDecimal refundAmount) {
OrderPayment payment = paymentService.getById(payOrderId);
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
Long refundId = initPayment(OrderPayment.refund(shopId, sourceId, payment.getSourceType(), refPayOrderNo, refundAmount, payment.getId()));
CzgResult<CzgRefundResp> refund = refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
Long refundId = initPayment(OrderPayment.refund(shopId, sourceId, payment.getSourceType(), refPayOrderNo, refundAmount, payment.getId(), payment.getPlatformType()));
CzgResult<RefundRespDTO> refund = refund(shopId, new CzgRefundReq(refPayOrderNo, refundReason, refundAmount.multiply(MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), "", payment.getPlatformType()));
OrderPayment uOrderPayment = new OrderPayment();
uOrderPayment.setRespJson(JSONObject.toJSONString(refund.getData()));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getStatus())) {
uOrderPayment.setPayStatus(PayTypeConstants.PayStatus.FAIL);
} else {
uOrderPayment.setTradeNumber(refund.getData().getRefundOrderId());
uOrderPayment.setTradeNumber(refund.getData().getThirdRefundNo());
uOrderPayment.setPayStatus(PayTypeConstants.PayStatus.SUCCESS);
uOrderPayment.setPayTime(LocalDateTimeUtil.parse(refund.getData().getRefundTime(), "yyyy-MM-dd HH:mm:ss"));
uOrderPayment.setRespJson(refund.getData().getOriginalData());
}
paymentService.update(uOrderPayment, QueryWrapper.create().eq(OrderPayment::getId, refundId));
}
@@ -122,16 +129,17 @@ public class PayServiceImpl implements PayService {
AssertUtil.isNull(payment, "退款失败,支付记录不存在");
Long refundCompensate = initPayment(OrderPayment.refundCompensate(refundPayment.getShopId(), refundPayment.getSourceId(),
payment.getSourceType(), refPayOrderNo, refundPayment.getAmount(), refundPayment.getId()));
CzgResult<CzgRefundResp> refund = refund(payment.getShopId(), new CzgRefundReq(refPayOrderNo, "退款补偿", refundPayment.getAmount().multiply(MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), ""));
CzgResult<RefundRespDTO> refund = refund(payment.getShopId(), new CzgRefundReq(refPayOrderNo, "退款补偿", refundPayment.getAmount().multiply(MONEY_RATE).longValue(),
payment.getAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getOrderNo(), "", payment.getPlatformType()));
OrderPayment uOrderPayment = new OrderPayment();
uOrderPayment.setTradeNumber(refund.getData().getRefundOrderId());
uOrderPayment.setTradeNumber(refund.getData().getThirdRefundNo());
uOrderPayment.setRespJson(JSONObject.toJSONString(refund.getData()));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getStatus())) {
uOrderPayment.setPayStatus(PayTypeConstants.PayStatus.FAIL);
} else {
uOrderPayment.setPayStatus(PayTypeConstants.PayStatus.SUCCESS);
uOrderPayment.setPayTime(LocalDateTimeUtil.parse(refund.getData().getRefundTime(), "yyyy-MM-dd HH:mm:ss"));
uOrderPayment.setRespJson(refund.getData().getOriginalData());
}
paymentService.update(uOrderPayment, QueryWrapper.create().eq(OrderPayment::getId, refundPayment.getId()));
paymentService.update(uOrderPayment, QueryWrapper.create().eq(OrderPayment::getId, refundCompensate));
@@ -139,7 +147,7 @@ public class PayServiceImpl implements PayService {
@Override
@Transactional
public CzgResult<CzgBaseResp> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo) {
public CzgResult<QueryOrderRespDTO> queryPayOrder(@NonNull Long shopId, String payOrderId, String mchOrderNo, String platform) {
ShopMerchant shopMerchant = getMerchant(shopId);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
@@ -148,12 +156,12 @@ public class PayServiceImpl implements PayService {
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
payData = shopMerchant.getPolyPayJson();
}
return adapter.queryPayOrder(getDomain(), payData, payOrderId, mchOrderNo);
return adapter.queryPayOrder(getDomain(), payData, payOrderId, mchOrderNo, platform);
}
@Override
@Transactional
public CzgResult<CzgRefundResp> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
public CzgResult<RefundRespDTO> queryRefund(@NonNull Long shopId, String mchRefundNo, String refundOrderId) {
ShopMerchant shopMerchant = getMerchant(shopId);
PayAdapter adapter = PayAdapterFactory.getAdapter(shopMerchant.getChannel());
String payData = null;
@@ -173,30 +181,26 @@ public class PayServiceImpl implements PayService {
}
private ShopMerchant getMerchant(Long shopId) {
try {
ShopMerchant shopMerchant = shopMerchantService.getById(shopId);
if (shopMerchant == null || StrUtil.isBlank(shopMerchant.getChannel())) {
throw new CzgException("暂未开通支付");
}
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
if (StrUtil.isNotBlank(shopMerchant.getNativePayJson())) {
throw new CzgException("原生支付未开通");
}
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
if (StrUtil.isNotBlank(shopMerchant.getPolyPayJson())) {
throw new CzgException("聚合支付未开通");
}
} else {
throw new CzgException("暂不支持的支付渠道");
}
return shopMerchant;
} catch (Exception e) {
throw new CzgException("暂未开通支付");
ShopMerchant shopMerchant = shopMerchantService.getByShopId(shopId);
if (shopMerchant == null || StrUtil.isBlank(shopMerchant.getChannel())) {
throw new CzgException("暂未开通支付!");
}
if (shopMerchant.getChannel().equals(PayChannelCst.NATIVE)) {
if (StrUtil.isBlank(shopMerchant.getNativePayJson())) {
throw new CzgException("原生支付未开通");
}
} else if (shopMerchant.getChannel().equals(PayChannelCst.POLY)) {
if (StrUtil.isBlank(shopMerchant.getPolyPayJson())) {
throw new CzgException("聚合支付未开通");
}
} else {
throw new CzgException("暂不支持的支付渠道");
}
return shopMerchant;
}
private String getDomain() {
return sysParamsService.getSysParamValue(ParamCodeCst.System.PAY_CZG_DOMAIN);
return sysParamsService.getSysParamValue(ParamCodeCst.System.POLY_DOMAIN);
}
private String getNotifyUrl(String channel) {
@@ -211,4 +215,27 @@ public class PayServiceImpl implements PayService {
}
return notifyUrl;
}
private void checkMicroPay(CzgPayBaseReq bizData, ShopMerchant shopMerchant) {
String data = bizData.getAuthCode();
AssertUtil.isBlank(data, "扫码失败,请重试");
if (data.length() > 26) {
throw new CzgException("支付失败,不支持的条码");
}
String firstTwoDigitsStr = data.substring(0, 2);
// 将截取的字符串转换为整数
int firstTwoDigits = Integer.parseInt(firstTwoDigitsStr);
// 判断范围
if (firstTwoDigits >= 10 && firstTwoDigits <= 15) {
//微信支付
bizData.setSubAppid(shopMerchant.getWechatAppId());
bizData.setPayType(SystemConstants.PayType.WECHAT);
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
//支付宝支付
bizData.setSubAppid(shopMerchant.getAlipayAppId());
bizData.setPayType(SystemConstants.PayType.ALIPAY);
} else {
throw new CzgException("扫描码非法或暂不支持");
}
}
}

View File

@@ -64,9 +64,8 @@ public class ShopDirectMerchantServiceImpl extends ServiceImpl<ShopDirectMerchan
}
@Override
public AggregateMerchantVO getEntry(Long shopId, String licenceNo) {
public AggregateMerchantVO getEntry(Long shopId) {
ShopDirectMerchant merchant = getOne(query()
.eq(ShopDirectMerchant::getLicenceNo, licenceNo)
.eq(ShopDirectMerchant::getShopId, shopId));
if (merchant == null) {
return null;

View File

@@ -3,26 +3,28 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.service.ShopInfoService;
import com.czg.constant.PayChannelCst;
import com.czg.constants.SystemConstants;
import com.czg.order.dto.ShopMerchantDTO;
import com.czg.order.entity.ShopDirectMerchant;
import com.czg.order.entity.ShopMerchant;
import com.czg.order.service.ShopMerchantService;
import com.czg.pay.AlipayAuthInfoDto;
import com.czg.pay.NativeMerchantDTO;
import com.czg.pay.PolyMerchantDTO;
import com.czg.service.order.mapper.ShopMerchantMapper;
import com.czg.service.order.service.ShopDirectMerchantService;
import com.czg.utils.AssertUtil;
import com.czg.utils.CzgStrUtils;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.io.Serializable;
/**
* 第三方商户进件 服务层实现。
*
@@ -41,21 +43,21 @@ public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, Sho
@Override
public ShopMerchantDTO detail(Long shopId) {
ShopMerchantDTO shopMerchantVO = new ShopMerchantDTO();
ShopMerchant one = queryChain().eq(ShopMerchant::getShopId, shopId).one();
ShopMerchant one = getOne(query().eq(ShopMerchant::getShopId, shopId));
if (one == null) {
return null;
}
shopMerchantVO.setShopId(shopId);
shopMerchantVO.setChannel(one.getChannel());
shopMerchantVO.setRelatedLicenceNo(one.getRelatedLicenceNo());
shopMerchantVO.setRelatedId(one.getRelatedId());
if (StrUtil.isNotBlank(one.getNativePayJson())) {
shopMerchantVO.setNativeMerchantDTO(JSONObject.parseObject(one.getNativePayJson(), NativeMerchantDTO.class));
}
if (StrUtil.isNotBlank(one.getPolyPayJson())) {
shopMerchantVO.setPolyMerchantDTO(JSONObject.parseObject(one.getPolyPayJson(), PolyMerchantDTO.class));
}
if (StrUtil.isNotBlank(one.getRelatedLicenceNo())) {
shopMerchantVO.setShopDirectMerchant(shopDirectMerchantService.getOne(query().eq(ShopDirectMerchant::getLicenceNo, one.getRelatedLicenceNo())));
if (one.getRelatedId() != null) {
shopMerchantVO.setShopDirectMerchant(shopDirectMerchantService.getOne(query().eq(ShopDirectMerchant::getShopId, one.getRelatedId())));
}
return shopMerchantVO;
}
@@ -73,40 +75,65 @@ public class ShopMerchantServiceImpl extends ServiceImpl<ShopMerchantMapper, Sho
ShopMerchant shopMerchant = getOne(query().eq(ShopMerchant::getShopId, shopMerchantParam.getShopId()));
if (shopMerchant == null) {
shopMerchant = new ShopMerchant();
shopMerchant.setChannel(shopMerchantParam.getChannel());
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
if (PayChannelCst.NATIVE.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
} else if (PayChannelCst.POLY.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getPolyMerchantDTO() != null) {
shopMerchant.setPolyPayJson(JSONObject.toJSONString(shopMerchantParam.getPolyMerchantDTO()));
shopMerchant.setAlipayAppId(SystemConstants.PayType.ALIPAY_APP_ID);
shopMerchant.setWechatAppId(SystemConstants.PayType.WECHAT_APP_ID);
shopMerchant.setRelatedId(shopMerchantParam.getShopId());
}
shopMerchant.setShopId(shopMerchantParam.getShopId());
if (isUp) {
shopMerchant.setChannel(CzgStrUtils.getStrOrNull(shopMerchantParam.getChannel()));
shopMerchant.setRelatedId(shopMerchantParam.getRelatedId());
if (shopMerchantParam.getRelatedId() == null || !shopMerchantParam.getRelatedId().equals(shopMerchant.getRelatedId())) {
ShopDirectMerchant shopDirectMerchant = shopDirectMerchantService.getById(shopMerchantParam.getRelatedId());
if (shopDirectMerchant != null) {
NativeMerchantDTO nativeMerchantDTO = new NativeMerchantDTO();
nativeMerchantDTO.setWechatMerchantId(shopDirectMerchant.getWechatMerchantId());
nativeMerchantDTO.setAlipayMerchantId(shopDirectMerchant.getAlipayMerchantId());
if (StrUtil.isNotBlank(shopDirectMerchant.getAlipayAuthInfo())) {
AlipayAuthInfoDto alipayAuthInfoDto = JSONObject.parseObject(shopDirectMerchant.getAlipayAuthInfo(), AlipayAuthInfoDto.class);
nativeMerchantDTO.setAlipayAuthInfo(alipayAuthInfoDto);
}
shopMerchant.setNativePayJson(JSONObject.toJSONString(nativeMerchantDTO));
} else {
shopMerchant.setNativePayJson(null);
shopMerchant.setWechatAppId(null);
shopMerchant.setAlipayAppId(null);
}
}
} else if (isUp) {
shopMerchant.setChannel(shopMerchantParam.getChannel());
shopMerchant.setShopId(shopMerchantParam.getShopId());
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
if (PayChannelCst.NATIVE.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
} else if (PayChannelCst.POLY.equals(shopMerchantParam.getChannel()) && shopMerchantParam.getPolyMerchantDTO() != null) {
if (shopMerchantParam.getPolyMerchantDTO() != null) {
shopMerchant.setPolyPayJson(JSONObject.toJSONString(shopMerchantParam.getPolyMerchantDTO()));
}
} else {
//不是新增且不是修改 只有进件完成会进入这里
if (StrUtil.isBlank(shopMerchant.getRelatedLicenceNo())) {
shopMerchant.setRelatedLicenceNo(shopMerchantParam.getRelatedLicenceNo());
//只有进件会进入这里
if (shopMerchant.getRelatedId() == null) {
shopMerchant.setRelatedId(shopMerchantParam.getShopId());
}
if (StrUtil.isBlank(shopMerchant.getNativePayJson()) && shopMerchantParam.getNativeMerchantDTO() != null) {
shopMerchant.setNativePayJson(JSONObject.toJSONString(shopMerchantParam.getNativeMerchantDTO()));
}
}
return saveOrUpdate(shopMerchant);
if (shopMerchant.getId() == null) {
return save(shopMerchant);
} else {
return updateById(shopMerchant, false);
}
}
@Cacheable(key = "#id")
@Override
public ShopMerchant getById(Serializable id) {
ShopMerchant shopMerchant = getMapper().selectOneById(id);
AssertUtil.isNull(shopMerchant, "暂未开通支付");
@CacheEvict(allEntries = true)
public void upMerchant(@NotBlank Long relatedId, @NotNull NativeMerchantDTO nativeMerchantDTO) {
ShopMerchant upShopMerchant = new ShopMerchant();
upShopMerchant.setAlipayAppId(nativeMerchantDTO.getAlipayMerchantId());
upShopMerchant.setWechatAppId(nativeMerchantDTO.getWechatMerchantId());
upShopMerchant.setNativePayJson(JSONObject.toJSONString(nativeMerchantDTO));
update(upShopMerchant, query().eq(ShopMerchant::getRelatedId, relatedId));
}
@Cacheable(key = "#shopId")
@Override
public ShopMerchant getByShopId(Long shopId) {
ShopMerchant shopMerchant = getOne(query().eq(ShopMerchant::getShopId, shopId));
AssertUtil.isNull(shopMerchant, "暂未开通支付.");
return shopMerchant;
}

View File

@@ -2,12 +2,10 @@ package com.czg.service.order.service.impl;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.SecureUtil;
import com.alibaba.fastjson2.JSONObject;
import com.czg.account.dto.shopuser.ShopUserMoneyEditDTO;
import com.czg.account.entity.*;
import com.czg.account.service.*;
import com.czg.constants.PayTypeConstants;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.CzgException;
@@ -26,6 +24,7 @@ import com.czg.order.service.OrderInfoCustomService;
import com.czg.order.service.OrderPaymentService;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.RefundRespDTO;
import com.czg.resp.CzgResult;
import com.czg.service.order.dto.VipMemberPayParamDTO;
import com.czg.service.order.dto.VipPayParamDTO;
@@ -312,19 +311,19 @@ public class ShopUserServiceImpl implements ShopUserPayService {
}
String refPayOrderNo = "REFVIP" + IdUtil.getSnowflakeNextId();
refPaymentId = payService.initPayment(OrderPayment.refund(refPayParam.getShopId(), shopUser.getId(), PayTypeConstants.SourceType.MEMBER_IN,
refPayOrderNo, refPayParam.getRefAmount(), inFlow.getId()));
CzgResult<CzgRefundResp> refund = payService.refund(refPayParam.getShopId(), new CzgRefundReq(refPayOrderNo, refPayParam.getRemark(),
refPayOrderNo, refPayParam.getRefAmount(), inFlow.getId(), payment.getPlatformType()));
CzgResult<RefundRespDTO> refund = payService.refund(refPayParam.getShopId(), new CzgRefundReq(refPayOrderNo, refPayParam.getRemark(),
refPayParam.getRefAmount().multiply(PayService.MONEY_RATE).longValue(), payment.getAmount().multiply(PayService.MONEY_RATE).longValue(),
payment.getOrderNo(), ""));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getState())) {
payment.getOrderNo(), "", payment.getPlatformType()));
if (refund.getCode() != 200 || refund.getData() == null || !"SUCCESS".equals(refund.getData().getStatus())) {
throw new CzgException(refund.getMsg());
} else {
paymentService.updateChain()
.eq(OrderPayment::getId, refPaymentId)
.set(OrderPayment::getPayTime, refund.getData().getRefundTime())
.set(OrderPayment::getTradeNumber, refund.getData().getRefundOrderId())
.set(OrderPayment::getTradeNumber, refund.getData().getThirdRefundNo())
.set(OrderPayment::getPayStatus, PayTypeConstants.PayStatus.SUCCESS)
.set(OrderPayment::getRespJson, JSONObject.toJSONString(refund.getData()))
.set(OrderPayment::getRespJson, refund.getData().getOriginalData())
.update();
}
}

View File

@@ -1,12 +1,7 @@
package com.czg;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.pay.NativeMerchantDTO;
import com.czg.pay.PolyMerchantDTO;
import com.czg.pay.*;
import com.czg.resp.CzgResult;
import jakarta.validation.constraints.NotBlank;
import lombok.NonNull;
@@ -39,12 +34,12 @@ public interface PayAdapter {
* @param bizData 业务数据
*/
CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, @NotBlank String payData, @NotBlank String domain,
@NotBlank String notifyUrl, CzgPayBaseReq<?> bizData);
@NotBlank String notifyUrl, CzgPayBaseReq bizData);
CzgResult<CzgRefundResp> refund(@NotBlank String domain, @NotBlank String payData, String notifyUrl, CzgRefundReq bizData);
CzgResult<RefundRespDTO> refund(@NotBlank String domain, @NotBlank String payData, CzgRefundReq bizData);
CzgResult<CzgBaseResp> queryPayOrder(@NotBlank String domain, @NotBlank String payData, String payOrderId, String mchOrderNo);
CzgResult<QueryOrderRespDTO> queryPayOrder(@NotBlank String domain, @NotBlank String payData, String payOrderId, String mchOrderNo, String platform);
CzgResult<CzgRefundResp> queryRefund(@NotBlank String domain, @NotBlank String payData, String mchRefundNo, String refundOrderId);
CzgResult<RefundRespDTO> queryRefund(@NotBlank String domain, @NotBlank String payData, String mchRefundNo, String refundOrderId);
}

View File

@@ -2,14 +2,11 @@ package com.czg.impl;
import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter;
import com.czg.PayManager;
import com.czg.constant.PayChannelCst;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.NativeMerchantDTO;
import com.czg.pay.*;
import com.czg.resp.CzgResult;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
@@ -32,24 +29,21 @@ public class NativePayAdapter implements PayAdapter {
}
@Override
public CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, String payData, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
public CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, String payData, String domain, String notifyUrl, CzgPayBaseReq bizData) {
try {
NativeMerchantDTO polyMerchantDTO = JSONObject.parseObject(payData, NativeMerchantDTO.class);
switch (payType) {
NativeMerchantDTO merchantDTO = getMerchantDTO(payData);
return switch (payType) {
// case H5_PAY:
// return h5Pay(polyMerchantDTO, domain, notifyUrl, bizData);
// case JS_PAY:
// return jsPay(polyMerchantDTO, domain, notifyUrl, bizData);
// case LT_PAY:
// return ltPay(polyMerchantDTO, domain, notifyUrl, bizData);
// return h5Pay(merchantDTO, domain, notifyUrl, bizData);
case JS_PAY -> jsPay(merchantDTO, notifyUrl, bizData);
case LT_PAY -> jsPay(merchantDTO, notifyUrl, bizData);
// case SCAN_PAY:
// return scanPay(polyMerchantDTO, domain, notifyUrl, bizData);
// case MICRO_PAY:
// //扫码支付 扫描码
// return microPay(polyMerchantDTO, domain, notifyUrl, (CzgPayBaseReq<String>) bizData);
default:
throw new CzgException("原生支付不支持该支付方式: " + bizData.getPayType());
}
// return scanPay(merchantDTO, domain, notifyUrl, bizData);
case MICRO_PAY ->
//扫码支付 扫描码
barPay(merchantDTO, notifyUrl, bizData);
default -> throw new CzgException("原生支付不支持该支付方式: " + bizData.getPayType());
};
} catch (Exception e) {
log.error("聚合支付处理失败: {}", e.getMessage(), e);
return CzgResult.failure("聚合支付处理失败: " + e.getMessage());
@@ -57,17 +51,34 @@ public class NativePayAdapter implements PayAdapter {
}
@Override
public CzgResult<CzgRefundResp> refund(String domain, String payData, String notifyUrl, CzgRefundReq bizData) {
return null;
public CzgResult<RefundRespDTO> refund(String domain, String payData, CzgRefundReq bizData) {
NativeMerchantDTO merchantDTO = getMerchantDTO(payData);
return CzgResult.success(PayManager.refund(bizData, bizData.getNotifyUrl(), merchantDTO));
}
@Override
public CzgResult<CzgBaseResp> queryPayOrder(String domain, String payData, String payOrderId, String mchOrderNo) {
return null;
public CzgResult<QueryOrderRespDTO> queryPayOrder(String domain, String payData, String payOrderId, String mchOrderNo, String platform) {
NativeMerchantDTO merchantDTO = getMerchantDTO(payData);
QueryOrderRespDTO respDTO = PayManager.queryOrderStatus(platform, mchOrderNo, merchantDTO);
return CzgResult.success(respDTO);
}
@Override
public CzgResult<CzgRefundResp> queryRefund(String domain, String payData, String mchRefundNo, String refundOrderId) {
public CzgResult<RefundRespDTO> queryRefund(String domain, String payData, String mchRefundNo, String refundOrderId) {
return null;
}
private CzgResult<Map<String, Object>> jsPay(NativeMerchantDTO merchantDTO, String notifyUrl, CzgPayBaseReq bizData) {
bizData.setNotifyUrl(notifyUrl);
return CzgResult.success(PayManager.jsapiPay(bizData, merchantDTO));
}
private CzgResult<Map<String, Object>> barPay(NativeMerchantDTO merchantDTO, String notifyUrl, CzgPayBaseReq bizData) {
bizData.setNotifyUrl(notifyUrl);
return CzgResult.success(PayManager.barPay(bizData, merchantDTO));
}
private NativeMerchantDTO getMerchantDTO(String payData) {
return JSONObject.parseObject(payData, NativeMerchantDTO.class);
}
}

View File

@@ -4,13 +4,12 @@ import com.alibaba.fastjson2.JSONObject;
import com.czg.PayAdapter;
import com.czg.PolyPayUtils;
import com.czg.constant.PayChannelCst;
import com.czg.constants.SystemConstants;
import com.czg.entity.resp.CzgBaseResp;
import com.czg.entity.resp.CzgRefundResp;
import com.czg.enums.CzgPayEnum;
import com.czg.exception.CzgException;
import com.czg.pay.CzgPayBaseReq;
import com.czg.pay.CzgRefundReq;
import com.czg.pay.PolyMerchantDTO;
import com.czg.pay.*;
import com.czg.resp.CzgResult;
import com.czg.utils.AssertUtil;
import jakarta.validation.constraints.NotBlank;
@@ -31,7 +30,7 @@ public class PolyPayAdapter implements PayAdapter {
@Override
public CzgResult<Map<String, Object>> pay(@NonNull CzgPayEnum payType, @NotBlank String payData, @NotBlank String domain,
@NotBlank String notifyUrl, CzgPayBaseReq<?> bizData) {
@NotBlank String notifyUrl, CzgPayBaseReq bizData) {
try {
PolyMerchantDTO polyMerchantDTO = JSONObject.parseObject(payData, PolyMerchantDTO.class);
return switch (payType) {
@@ -39,8 +38,8 @@ public class PolyPayAdapter implements PayAdapter {
case JS_PAY -> jsPay(polyMerchantDTO, domain, notifyUrl, bizData);
case LT_PAY -> ltPay(polyMerchantDTO, domain, notifyUrl, bizData);
case SCAN_PAY -> scanPay(polyMerchantDTO, domain, notifyUrl, bizData);
case MICRO_PAY -> microPay(polyMerchantDTO, domain, notifyUrl, (CzgPayBaseReq<String>) bizData);
default -> throw new CzgException("聚合支付不支持该支付方式: " + bizData.getPayType());
case MICRO_PAY -> microPay(polyMerchantDTO, domain, notifyUrl, bizData);
default -> throw new CzgException("聚合支付不支持该支付方式: " + payType);
};
} catch (Exception e) {
log.error("聚合支付处理失败: {}", e.getMessage(), e);
@@ -50,71 +49,77 @@ public class PolyPayAdapter implements PayAdapter {
@Override
public CzgResult<CzgRefundResp> refund(@NotBlank String domain, @NotBlank String payData, String notifyUrl, CzgRefundReq bizData) {
public CzgResult<RefundRespDTO> refund(@NotBlank String domain, @NotBlank String payData, CzgRefundReq bizData) {
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
bizData.setNotifyUrl(notifyUrl);
return PolyPayUtils.refundOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
CzgResult<CzgRefundResp> result = PolyPayUtils.refundOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
return convertRefundResp(result);
}
@Override
public CzgResult<CzgBaseResp> queryPayOrder(@NotBlank String payData, @NotBlank String domain, String payOrderId, String mchOrderNo) {
public CzgResult<QueryOrderRespDTO> queryPayOrder(@NotBlank String payData, @NotBlank String domain, String payOrderId, String mchOrderNo, String platform) {
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
PolyPayUtils.queryPayOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
return null;
CzgResult<CzgBaseResp> result = PolyPayUtils.queryPayOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), payOrderId, mchOrderNo);
if (result.isSuccess()) {
QueryOrderRespDTO respDTO = new QueryOrderRespDTO()
.setStatus(result.getData().getState())
.setOrderNo(result.getData().getMchOrderNo())
.setAmount(result.getData().getAmount())
.setErrorMsg("")
.setOriginResp(JSONObject.toJSONString(result.getData()));
return CzgResult.success(respDTO);
}
return CzgResult.failure(result.getMsg());
}
@Override
public CzgResult<CzgRefundResp> queryRefund(@NotBlank String payData, @NotBlank String domain, String mchRefundNo, String refundOrderId) {
public CzgResult<RefundRespDTO> queryRefund(@NotBlank String payData, @NotBlank String domain, String mchRefundNo, String refundOrderId) {
PolyMerchantDTO shopMerchant = JSONObject.parseObject(payData, PolyMerchantDTO.class);
return PolyPayUtils.queryRefundOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
CzgResult<CzgRefundResp> result = PolyPayUtils.queryRefundOrder(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), mchRefundNo, refundOrderId);
return convertRefundResp(result);
}
private CzgResult<Map<String, Object>> h5Pay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
private CzgResult<Map<String, Object>> h5Pay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq bizData) {
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.h5Pay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private CzgResult<Map<String, Object>> jsPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
bizData.setSubAppid("aliPay".equals(bizData.getPayType()) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序");
bizData.setPayType("aliPay".equals(bizData.getPayType()) ? "ALIPAY" : "WECHAT");
private CzgResult<Map<String, Object>> jsPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq bizData) {
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + (SystemConstants.PayType.ALIPAY.equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序");
bizData.setPayType(SystemConstants.PayType.ALIPAY.equals(bizData.getPayType()) ? "ALIPAY" : "WECHAT");
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.jsPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private CzgResult<Map<String, Object>> ltPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
bizData.setSubAppid("aliPay".equals(bizData.getPayType()) ? shopMerchant.getAlipaySmallAppid() : shopMerchant.getWechatSmallAppid());
private CzgResult<Map<String, Object>> ltPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq bizData) {
AssertUtil.isBlank(bizData.getSubAppid(), "暂不可用,请联系商家配置" + ("aliPay".equals(bizData.getPayType()) ? "支付宝" : "微信") + "小程序");
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.ltPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private CzgResult<Map<String, Object>> scanPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<?> bizData) {
private CzgResult<Map<String, Object>> scanPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq bizData) {
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
return PolyPayUtils.scanPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private CzgResult<Map<String, Object>> microPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq<String> bizData) {
AssertUtil.isBlank(bizData.getData(), "扫码失败,请重试");
if (bizData.getData().length() > 26) {
throw new CzgException("支付失败,不支持的条码");
}
private CzgResult<Map<String, Object>> microPay(PolyMerchantDTO shopMerchant, String domain, String notifyUrl, CzgPayBaseReq bizData) {
bizData.polyBase(shopMerchant.getStoreId(), notifyUrl);
String firstTwoDigitsStr = bizData.getData().substring(0, 2);
// 将截取的字符串转换为整数
int firstTwoDigits = Integer.parseInt(firstTwoDigitsStr);
// 判断范围
if (firstTwoDigits >= 10 && firstTwoDigits <= 15) {
//微信支付
bizData.setSubAppid(shopMerchant.getWechatSmallAppid());
} else if (firstTwoDigits >= 25 && firstTwoDigits <= 30) {
//支付宝支付
bizData.setSubAppid(shopMerchant.getAlipaySmallAppid());
} else {
throw new CzgException("扫描码非法或暂不支持");
}
return PolyPayUtils.microPay(domain, shopMerchant.getAppId(), shopMerchant.getAppSecret(), bizData);
}
private CzgResult<RefundRespDTO> convertRefundResp(CzgResult<CzgRefundResp> result) {
if (result.isSuccess()) {
RefundRespDTO respDTO = new RefundRespDTO()
.setStatus(result.getData().getState())
.setMerchantRefundNo(result.getData().getMchRefundNo())
.setThirdRefundNo(result.getData().getRefundOrderId())
.setPlatform(result.getData().getPayType())
.setRefundAmount(result.getData().getRefundAmt())
.setRefundTime(result.getData().getRefundTime())
.setOriginalData(result.getData().getExtParam());
return CzgResult.success(respDTO);
}
return CzgResult.failure(result.getMsg());
}
}

View File

@@ -8,7 +8,6 @@ import cn.hutool.core.util.StrUtil;
import com.czg.product.entity.Product;
import com.czg.product.entity.ProductStockFlow;
import com.czg.product.service.ProductStockFlowService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ConsInfoMapper;
import com.czg.service.product.mapper.ProductMapper;
import com.czg.service.product.mapper.ProductStockFlowMapper;
@@ -44,15 +43,7 @@ public class ProductStockFlowServiceImpl extends ServiceImpl<ProductStockFlowMap
Long shopId = entity.getShopId();
BigDecimal afterNumber = entity.getAfterNumber();
Product product = productMapper.selectOneById(entity.getProductId());
String shopName = "";
try {
shopName = StpKit.USER.getShopName();
} catch (Exception e) {
log.error("获取店铺名称失败");
}
if (StrUtil.isEmpty(shopName)) {
shopName = productMapper.getShopName(shopId);
}
String shopName = productMapper.getShopName(shopId);
BigDecimal warnLine = Convert.toBigDecimal(product.getWarnLine());
// 库存小于警告值,发送消息提醒
if (NumberUtil.isLess(afterNumber, warnLine)) {