优化:支付功能(10550)

This commit is contained in:
2025-07-26 14:23:08 +08:00
parent b0b1d28927
commit 29ee53f79d
4 changed files with 29 additions and 39 deletions

View File

@@ -132,31 +132,24 @@ public class PaymentController extends BaseController {
@ApiOperation("分页查询支付方式") @ApiOperation("分页查询支付方式")
@GetMapping("/page") @GetMapping("/page")
public ApiResult<PageResult<Payment>> page(PaymentParam param) { public ApiResult<PageResult<Payment>> page(PaymentParam param) {
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time asc");
return success(paymentService.page(page, page.getWrapper()));
// 使用关联查询 // 使用关联查询
// return success(paymentService.pageRel(param)); return success(paymentService.pageRel(param));
} }
@PreAuthorize("hasAuthority('sys:payment:list')") @PreAuthorize("hasAuthority('sys:payment:list')")
@ApiOperation("查询全部支付方式") @ApiOperation("查询全部支付方式")
@GetMapping() @GetMapping()
public ApiResult<List<Payment>> list(PaymentParam param) { public ApiResult<List<Payment>> list(PaymentParam param) {
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time asc");
return success(paymentService.list(page.getOrderWrapper()));
// 使用关联查询 // 使用关联查询
//return success(paymentService.listRel(param)); return success(paymentService.listRel(param));
} }
@PreAuthorize("hasAuthority('sys:payment:list')") @PreAuthorize("hasAuthority('sys:payment:list')")
@ApiOperation("根据id查询支付方式") @ApiOperation("根据id查询支付方式")
@GetMapping("/{id}") @GetMapping("/{id}")
public ApiResult<Payment> get(@PathVariable("id") Integer id) { public ApiResult<Payment> get(@PathVariable("id") Integer id) {
return success(paymentService.getById(id));
// 使用关联查询 // 使用关联查询
//return success(paymentService.getByIdRel(id)); return success(paymentService.getByIdRel(id));
} }
@PreAuthorize("hasAuthority('sys:payment:save')") @PreAuthorize("hasAuthority('sys:payment:save')")

View File

@@ -40,31 +40,24 @@ public class SettingController extends BaseController {
@ApiOperation("分页查询系统设置") @ApiOperation("分页查询系统设置")
@GetMapping("/page") @GetMapping("/page")
public ApiResult<PageResult<Setting>> page(SettingParam param) { public ApiResult<PageResult<Setting>> page(SettingParam param) {
PageParam<Setting, SettingParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(settingService.page(page, page.getWrapper()));
// 使用关联查询 // 使用关联查询
//return success(settingService.pageRel(param)); return success(settingService.pageRel(param));
} }
@PreAuthorize("hasAuthority('sys:setting:save')") @PreAuthorize("hasAuthority('sys:setting:save')")
@ApiOperation("查询全部系统设置") @ApiOperation("查询全部系统设置")
@GetMapping() @GetMapping()
public ApiResult<List<Setting>> list(SettingParam param) { public ApiResult<List<Setting>> list(SettingParam param) {
PageParam<Setting, SettingParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(settingService.list(page.getOrderWrapper()));
// 使用关联查询 // 使用关联查询
//return success(settingService.listRel(param)); return success(settingService.listRel(param));
} }
@PreAuthorize("hasAuthority('sys:setting:save')") @PreAuthorize("hasAuthority('sys:setting:save')")
@ApiOperation("根据id查询系统设置") @ApiOperation("根据id查询系统设置")
@GetMapping("/{id}") @GetMapping("/{id}")
public ApiResult<Setting> get(@PathVariable("id") Integer id) { public ApiResult<Setting> get(@PathVariable("id") Integer id) {
return success(settingService.getById(id));
// 使用关联查询 // 使用关联查询
//return success(settingService.getByIdRel(id)); return success(settingService.getByIdRel(id));
} }
@PreAuthorize("hasAuthority('sys:setting:save')") @PreAuthorize("hasAuthority('sys:setting:save')")

View File

@@ -5,7 +5,7 @@
<!-- 关联查询sql --> <!-- 关联查询sql -->
<sql id="selectSql"> <sql id="selectSql">
SELECT a.* SELECT a.*
FROM sys_setting a FROM gxwebsoft_core.sys_setting a
<where> <where>
<if test="param.settingKey != null"> <if test="param.settingKey != null">
AND a.setting_key = #{param.settingKey} AND a.setting_key = #{param.settingKey}

View File

@@ -10,7 +10,9 @@
import com.gxwebsoft.common.core.exception.BusinessException; import com.gxwebsoft.common.core.exception.BusinessException;
import com.gxwebsoft.common.core.utils.RedisUtil; import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.system.entity.Payment; import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.param.PaymentParam;
import com.gxwebsoft.common.system.service.PaymentService; import com.gxwebsoft.common.system.service.PaymentService;
import com.gxwebsoft.common.system.service.SettingService;
import com.gxwebsoft.shop.entity.ShopOrderGoods; import com.gxwebsoft.shop.entity.ShopOrderGoods;
import com.gxwebsoft.shop.mapper.ShopOrderMapper; import com.gxwebsoft.shop.mapper.ShopOrderMapper;
import com.gxwebsoft.shop.service.ShopOrderGoodsService; import com.gxwebsoft.shop.service.ShopOrderGoodsService;
@@ -56,6 +58,8 @@
private ShopOrderGoodsService shopOrderGoodsService; private ShopOrderGoodsService shopOrderGoodsService;
@Resource @Resource
private PaymentService paymentService; private PaymentService paymentService;
@Resource
private SettingService settingService;
public static String privateKeyPath = "/Users/gxwebsoft/Downloads/ef7f7e0430cb47019d06b93f885bf95f/apiclient_key.pem"; public static String privateKeyPath = "/Users/gxwebsoft/Downloads/ef7f7e0430cb47019d06b93f885bf95f/apiclient_key.pem";
public static String privateCertPath = "/Users/gxwebsoft/JAVA/com.gxwebsoft.core/src/main/resources/cert/apiclient_cert.pem"; public static String privateCertPath = "/Users/gxwebsoft/JAVA/com.gxwebsoft.core/src/main/resources/cert/apiclient_cert.pem";
@@ -99,8 +103,6 @@
public HashMap<String, String> createWxOrder(ShopOrder order) { public HashMap<String, String> createWxOrder(ShopOrder order) {
// 后台微信支付配置信息 // 后台微信支付配置信息
final Payment payment = getPayment(order); final Payment payment = getPayment(order);
// 微信小程序信息
final JSONObject wxConfig = getWxConfig(order);
// 返回的订单数据 // 返回的订单数据
final HashMap<String, String> orderInfo = new HashMap<>(); final HashMap<String, String> orderInfo = new HashMap<>();
// 构建service // 构建service
@@ -116,7 +118,7 @@
amount.setTotal(money); amount.setTotal(money);
amount.setCurrency("CNY"); amount.setCurrency("CNY");
request.setAmount(amount); request.setAmount(amount);
request.setAppid(wxConfig.getString("appId")); request.setAppid(payment.getAppId());
request.setMchid(payment.getMchId()); request.setMchid(payment.getMchId());
request.setDescription(order.getComments()); request.setDescription(order.getComments());
request.setOutTradeNo(order.getOrderNo()); request.setOutTradeNo(order.getOrderNo());
@@ -199,28 +201,24 @@
if (ObjectUtil.isNotEmpty(payment)) { if (ObjectUtil.isNotEmpty(payment)) {
return payment; return payment;
} }
return paymentService.getOne(new LambdaQueryWrapper<Payment>().eq(Payment::getType, order.getType()).last("LIMIT 1")); final PaymentParam paymentParam = new PaymentParam();
} paymentParam.setType(order.getPayType());
final List<Payment> payments = paymentService.listRel(paymentParam);
public JSONObject getWxConfig(ShopOrder order) { return payments.get(0);
// 微信小程序(微信支付)
String key = "mp-weixin:".concat(order.getTenantId().toString());
final String string = redisUtil.get(key);
return JSONObject.parseObject(string);
} }
public JsapiServiceExtension getWxService(ShopOrder order) { public JsapiServiceExtension getWxService(ShopOrder order) {
Integer payType = order.getPayType(); // Integer payType = order.getPayType();
final String uploadPath = config.getUploadPath(); // 服务器本地路径 final String uploadPath = config.getUploadPath(); // 服务器本地路径
final HashMap<String, String> orderInfo = new HashMap<>(); // final HashMap<String, String> orderInfo = new HashMap<>();
// 微信小程序(微信支付) // 微信小程序(微信支付)
String key = "mp-weixin:".concat(order.getTenantId().toString()); // String key = "mp-weixin:".concat(order.getTenantId().toString());
final String string = redisUtil.get(key); // final String string = redisUtil.get(key);
// System.out.println("string = " + string); // System.out.println("string = " + string);
final JSONObject mpWx = JSONObject.parseObject(string); // final JSONObject mpWx = JSONObject.parseObject(string);
// System.out.println("mpWx = " + mpWx); // System.out.println("mpWx = " + mpWx);
String key2 = "Payment:".concat(payType.toString()).concat(":").concat(order.getTenantId().toString()); // String key2 = "Payment:".concat(payType.toString()).concat(":").concat(order.getTenantId().toString());
final Payment payment = redisUtil.get(key2, Payment.class); final Payment payment = getPayment(order);
if (ObjectUtil.isEmpty(payment)) { if (ObjectUtil.isEmpty(payment)) {
throw new BusinessException("请完成支付配置"); throw new BusinessException("请完成支付配置");
} }
@@ -228,12 +226,18 @@
String privateKey = uploadPath.concat("/file").concat(payment.getApiclientKey()); // 秘钥证书 String privateKey = uploadPath.concat("/file").concat(payment.getApiclientKey()); // 秘钥证书
String apiclientCert = uploadPath.concat("/file").concat(payment.getApiclientCert()); String apiclientCert = uploadPath.concat("/file").concat(payment.getApiclientCert());
String pubKey = uploadPath.concat("/file").concat(payment.getPubKey()); // 公钥证书 String pubKey = uploadPath.concat("/file").concat(payment.getPubKey()); // 公钥证书
// 开发环境配置 // 开发环境配置
if (active.equals("dev")) { if (active.equals("dev")) {
privateKey = privateKeyPath; privateKey = privateKeyPath;
apiclientCert = wechatpayCertPath; apiclientCert = wechatpayCertPath;
} }
// 生成环境配置
if (active.equals("prod")) {
}
// 兼容公钥 // 兼容公钥
Config config; Config config;
if (payment.getPubKey() != null && !payment.getPubKey().isEmpty()) { if (payment.getPubKey() != null && !payment.getPubKey().isEmpty()) {