Browse Source

新增分佣

main
梁欣 2 weeks ago
parent
commit
5d55376ea7
  1. 3
      src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java
  2. 50
      src/main/java/com/gxwebsoft/common/core/utils/RequestUtil.java
  3. 35
      src/main/java/com/gxwebsoft/common/core/utils/WechatCertAutoConfig.java
  4. 2
      src/main/java/com/gxwebsoft/common/system/entity/User.java
  5. 126
      src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java
  6. 2
      src/main/java/com/gxwebsoft/shop/entity/ShopDealerOrder.java
  7. 3
      src/main/java/com/gxwebsoft/shop/entity/ShopGoods.java
  8. 1
      src/main/java/com/gxwebsoft/shop/service/ShopOrderGoodsService.java
  9. 9
      src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderGoodsServiceImpl.java
  10. 97
      src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java
  11. 4
      src/main/resources/application-prod.yml
  12. 2
      src/main/resources/application.yml

3
src/main/java/com/gxwebsoft/common/core/security/SecurityConfig.java

@ -73,7 +73,8 @@ public class SecurityConfig {
"/api/cms/form-record", "/api/cms/form-record",
"/api/shop/merchant-account/getMerchantAccountByPhone", "/api/shop/merchant-account/getMerchantAccountByPhone",
"/api/hjm/hjm-car/**", "/api/hjm/hjm-car/**",
"/api/chat/**"
"/api/chat/**",
"/api/shop/shop-order/test"
) )
.permitAll() .permitAll()
.anyRequest() .anyRequest()

50
src/main/java/com/gxwebsoft/common/core/utils/RequestUtil.java

@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.system.entity.DictData;
import com.gxwebsoft.common.system.entity.Payment; import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.entity.UserRole; import com.gxwebsoft.common.system.entity.UserRole;
@ -121,6 +122,24 @@ public class RequestUtil {
return null; return null;
} }
public User getByUserIdWithoutLogin(Integer userId) {
String path = "/system/user/getByUserId/" + userId;
try {
// 链式构建请求
String result = HttpRequest.get(getServerUrl().concat(path))
.header("Tenantid", TENANT_ID)
.timeout(20000)//超时,毫秒
.execute().body();
JSONObject jsonObject = JSONObject.parseObject(result);
System.out.println("jsonObject = " + jsonObject);
final String data = jsonObject.getString("data");
return JSONObject.parseObject(data, User.class);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
// 新增用户 // 新增用户
public boolean saveUserByPhone(ShopMerchantAccount merchantAccount) { public boolean saveUserByPhone(ShopMerchantAccount merchantAccount) {
String path = "/system/user/"; String path = "/system/user/";
@ -173,7 +192,6 @@ public class RequestUtil {
try { try {
// 链式构建请求 // 链式构建请求
final String result = HttpRequest.get(getServerUrl().concat("/system/user-referee/getReferee/" + userId)) final String result = HttpRequest.get(getServerUrl().concat("/system/user-referee/getReferee/" + userId))
.header("Authorization", ACCESS_TOKEN)
.header("Tenantid", TENANT_ID) .header("Tenantid", TENANT_ID)
.timeout(20000) .timeout(20000)
.execute().body(); .execute().body();
@ -202,6 +220,21 @@ public class RequestUtil {
} }
} }
// 更新用户信息
public void updateWithoutLogin(User user) {
String path = "/system/user/updateWithoutLogin";
try {
// 链式构建请求
final String body = HttpRequest.put(getServerUrl().concat(path))
.header("Tenantid", TENANT_ID)
.body(JSONUtil.toJSONString(user))
.timeout(20000)
.execute().body();
} catch (Exception e) {
e.printStackTrace();
}
}
public String getMpOrderQrCode(String orderNo) { public String getMpOrderQrCode(String orderNo) {
String path = "/wx-login/getOrderQRCode/"; String path = "/wx-login/getOrderQRCode/";
try { try {
@ -271,6 +304,21 @@ public class RequestUtil {
} }
} }
public ApiResult<?> pageDictData(Integer dictId) {
String path = "/system/dict-data/page";
try {
// 链式构建请求
final String body = HttpRequest.get(getServerUrl().concat(path).concat("?dictId=" + dictId))
.header("tenantId", TENANT_ID)
.timeout(20000)
.execute().body();
return JSONUtil.parseObject(body, ApiResult.class);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
// 余额支付通知 // 余额支付通知
public void pushBalancePayNotify(Transaction transaction, Payment payment) { public void pushBalancePayNotify(Transaction transaction, Payment payment) {
System.out.println("payment = " + payment); System.out.println("payment = " + payment);

35
src/main/java/com/gxwebsoft/common/core/utils/WechatCertAutoConfig.java

@ -3,11 +3,7 @@ package com.gxwebsoft.common.core.utils;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.gxwebsoft.common.core.config.ConfigProperties;
import javax.annotation.Resource;
/** /**
* 微信支付证书自动配置工具类 * 微信支付证书自动配置工具类
@ -20,15 +16,6 @@ import javax.annotation.Resource;
@Component @Component
public class WechatCertAutoConfig { public class WechatCertAutoConfig {
@Value("${spring.profiles.active:prod}")
private String activeProfile;
@Resource
private ConfigProperties configProperties;
@Resource
private ConfigProperties configProperties;
/** /**
* 创建微信支付自动证书配置 * 创建微信支付自动证书配置
* *
@ -75,35 +62,15 @@ public class WechatCertAutoConfig {
/** /**
* 使用默认开发环境配置创建自动证书配置 * 使用默认开发环境配置创建自动证书配置
* 根据当前环境自动选择证书路径
* 开发环境拼接规则配置文件upload-path + dev/wechat/ + 租户ID
* *
* @return 微信支付配置对象 * @return 微信支付配置对象
*/ */
public Config createDefaultDevConfig() { public Config createDefaultDevConfig() {
String merchantId = "1723321338"; String merchantId = "1723321338";
String privateKeyPath;
String privateKeyPath = "src/main/resources/certs/dev/wechat/apiclient_key.pem";
String merchantSerialNumber = "2B933F7C35014A1C363642623E4A62364B34C4EB"; String merchantSerialNumber = "2B933F7C35014A1C363642623E4A62364B34C4EB";
String apiV3Key = "0kF5OlPr482EZwtn9zGufUcqa7ovgxRL"; String apiV3Key = "0kF5OlPr482EZwtn9zGufUcqa7ovgxRL";
// 根据环境选择证书路径
if ("dev".equals(activeProfile)) {
// 开发环境:使用配置文件upload-path拼接证书路径
String uploadPath = configProperties.getUploadPath(); // 配置文件路径
String tenantId = "10550"; // 租户ID
String certPath = uploadPath + "dev/wechat/" + tenantId + "/";
privateKeyPath = certPath + "apiclient_key.pem";
log.info("开发环境:使用配置文件upload-path拼接证书路径");
log.info("配置文件upload-path: {}", uploadPath);
log.info("证书基础路径: {}", certPath);
log.info("私钥文件路径: {}", privateKeyPath);
} else {
// 生产环境:使用相对路径,由系统动态解析
privateKeyPath = "src/main/resources/certs/dev/wechat/apiclient_key.pem";
log.info("生产环境:使用相对证书路径 - {}", privateKeyPath);
}
return createAutoConfig(merchantId, privateKeyPath, merchantSerialNumber, apiV3Key); return createAutoConfig(merchantId, privateKeyPath, merchantSerialNumber, apiV3Key);
} }

2
src/main/java/com/gxwebsoft/common/system/entity/User.java

@ -119,7 +119,7 @@ public class User implements UserDetails {
private String payMoney; private String payMoney;
@Schema(description = "实际消费的金额(不含退款)") @Schema(description = "实际消费的金额(不含退款)")
private String expendMoney;
private BigDecimal expendMoney;
@Schema(description = "会员等级ID") @Schema(description = "会员等级ID")
private Integer gradeId; private Integer gradeId;

126
src/main/java/com/gxwebsoft/shop/controller/ShopOrderController.java

@ -6,14 +6,15 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.config.CertificateProperties; import com.gxwebsoft.common.core.config.CertificateProperties;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.utils.CertificateLoader;
import com.gxwebsoft.common.core.utils.WechatCertAutoConfig;
import com.gxwebsoft.common.core.utils.WechatPayConfigValidator;
import com.gxwebsoft.common.core.utils.*;
import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.DictData;
import com.gxwebsoft.common.system.entity.Payment; import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.shop.entity.ShopGoods;
import com.gxwebsoft.shop.service.ShopGoodsService;
import com.gxwebsoft.shop.service.ShopOrderGoodsService; import com.gxwebsoft.shop.service.ShopOrderGoodsService;
import com.gxwebsoft.shop.service.ShopOrderService; import com.gxwebsoft.shop.service.ShopOrderService;
import com.gxwebsoft.shop.service.OrderBusinessService; import com.gxwebsoft.shop.service.OrderBusinessService;
@ -39,7 +40,9 @@ import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -72,8 +75,20 @@ public class ShopOrderController extends BaseController {
private WechatCertAutoConfig wechatCertAutoConfig; private WechatCertAutoConfig wechatCertAutoConfig;
@Resource @Resource
private WechatPayConfigValidator wechatPayConfigValidator; private WechatPayConfigValidator wechatPayConfigValidator;
@Resource
private ShopGoodsService shopGoodsService;
@Value("${spring.profiles.active}") @Value("${spring.profiles.active}")
String active; String active;
@Resource
private RequestUtil requestUtil;
@Operation(summary = "分页查询订单")
@GetMapping("/test")
public ApiResult<?> test() {
requestUtil.setTenantId("10550");
User user = requestUtil.getByUserIdWithoutLogin(33035);
return success(user);
}
@Operation(summary = "分页查询订单") @Operation(summary = "分页查询订单")
@GetMapping("/page") @GetMapping("/page")
@ -99,17 +114,37 @@ public class ShopOrderController extends BaseController {
@Operation(summary = "添加订单") @Operation(summary = "添加订单")
@PostMapping() @PostMapping()
public ApiResult<?> save(@RequestBody OrderCreateRequest request) {
public ApiResult<?> save(@Valid @RequestBody OrderCreateRequest request) {
User loginUser = getLoginUser(); User loginUser = getLoginUser();
if (loginUser == null) { if (loginUser == null) {
return fail("用户未登录"); return fail("用户未登录");
} }
if (request.getTotalPrice() == null || request.getTotalPrice().compareTo(BigDecimal.ZERO) <= 0) {
if (request.getGoodsItems() != null && !request.getGoodsItems().isEmpty()) {
BigDecimal totalPrice = BigDecimal.ZERO;
int totalNum = 0;
for (OrderCreateRequest.OrderGoodsItem item : request.getGoodsItems()) {
ShopGoods goods = shopGoodsService.getById(item.getGoodsId().toString());
if (goods != null) {
BigDecimal price = goods.getPrice().multiply(new BigDecimal(item.getQuantity().toString()));
totalPrice = totalPrice.add(price);
totalNum += Integer.parseInt(item.getQuantity().toString());
}
}
request.setTotalPrice(totalPrice);
request.setPayPrice(totalPrice);
request.setTotalNum(totalNum);
request.setFormId(Integer.parseInt(request.getGoodsItems().get(0).getQuantity().toString()));
}
}
if (request.getTenantId() == null) {
request.setTenantId(getTenantId());
}
try { try {
Map<String, String> wxOrderInfo = orderBusinessService.createOrder(request, loginUser); Map<String, String> wxOrderInfo = orderBusinessService.createOrder(request, loginUser);
return success("下单成功", wxOrderInfo); return success("下单成功", wxOrderInfo);
} catch (Exception e) { } catch (Exception e) {
logger.error("创建订单失败 - 用户ID:{},请求:{}", loginUser.getUserId(), request, e);
logger.error("创建订单失败", e);
return fail(e.getMessage()); return fail(e.getMessage());
} }
} }
@ -206,12 +241,6 @@ public class ShopOrderController extends BaseController {
return fail("修复失败"); return fail("修复失败");
} }
@Operation(summary = "统计订单总金额")
@GetMapping("/total")
public ApiResult<BigDecimal> total() {
return success(shopOrderService.total());
}
@Schema(description = "异步通知") @Schema(description = "异步通知")
@PostMapping("/notify/{tenantId}") @PostMapping("/notify/{tenantId}")
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) { public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
@ -249,41 +278,40 @@ public class ShopOrderController extends BaseController {
// 创建通知配置 - 使用与下单方法相同的证书配置逻辑 // 创建通知配置 - 使用与下单方法相同的证书配置逻辑
NotificationConfig config; NotificationConfig config;
try { try {
if (active.equals("dev")) {
// 开发环境 - 使用配置文件的upload-path构建证书路径
String uploadPath = conf.getUploadPath();
String tenantCertPath = uploadPath + "dev/wechat/" + tenantId;
String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
logger.info("开发环境异步通知证书路径: {}", privateKeyPath);
logger.info("租户ID: {}, 证书目录: {}", tenantId, tenantCertPath);
// 检查证书文件是否存在
if (!certificateLoader.certificateExists(privateKeyPath)) {
logger.error("证书文件不存在: {}", privateKeyPath);
throw new RuntimeException("证书文件不存在: " + privateKeyPath);
}
String privateKey = certificateLoader.loadCertificatePath(privateKeyPath);
// 使用验证器获取有效的 APIv3 密钥
String apiV3Key = wechatPayConfigValidator.getValidApiV3Key(payment);
logger.info("私钥文件加载成功: {}", privateKey);
logger.info("使用APIv3密钥来源: {}", payment.getApiKey() != null && !payment.getApiKey().trim().isEmpty() ? "数据库配置" : "配置文件默认");
logger.info("APIv3密钥长度: {}", apiV3Key != null ? apiV3Key.length() : 0);
logger.info("商户证书序列号: {}", payment.getMerchantSerialNumber());
// 使用自动证书配置
config = new RSAAutoCertificateConfig.Builder()
.merchantId(payment.getMchId())
.privateKeyFromPath(privateKey)
.merchantSerialNumber(payment.getMerchantSerialNumber())
.apiV3Key(apiV3Key)
.build();
logger.info("✅ 开发环境使用自动证书配置创建通知解析器成功");
} else {
// if (active.equals("dev")) {
// // 开发环境 - 构建包含租户号的私钥路径
// String tenantCertPath = "dev/wechat/" + tenantId;
// String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
//
// logger.info("开发环境异步通知证书路径: {}", privateKeyPath);
// logger.info("租户ID: {}, 证书目录: {}", tenantId, tenantCertPath);
//
// // 检查证书文件是否存在
// if (!certificateLoader.certificateExists(privateKeyPath)) {
// logger.error("证书文件不存在: {}", privateKeyPath);
// throw new RuntimeException("证书文件不存在: " + privateKeyPath);
// }
//
// String privateKey = certificateLoader.loadCertificatePath(privateKeyPath);
//
// // 使用验证器获取有效的 APIv3 密钥
// String apiV3Key = wechatPayConfigValidator.getValidApiV3Key(payment);
//
// logger.info("私钥文件加载成功: {}", privateKey);
// logger.info("使用APIv3密钥来源: {}", payment.getApiKey() != null && !payment.getApiKey().trim().isEmpty() ? "数据库配置" : "配置文件默认");
// logger.info("APIv3密钥长度: {}", apiV3Key != null ? apiV3Key.length() : 0);
// logger.info("商户证书序列号: {}", payment.getMerchantSerialNumber());
//
// // 使用自动证书配置
// config = new RSAAutoCertificateConfig.Builder()
// .merchantId(payment.getMchId())
// .privateKeyFromPath(privateKey)
// .merchantSerialNumber(payment.getMerchantSerialNumber())
// .apiV3Key(apiV3Key)
// .build();
//
// logger.info("✅ 开发环境使用自动证书配置创建通知解析器成功");
// } else {
// 生产环境 - 使用自动证书配置 // 生产环境 - 使用自动证书配置
final String certRootPath = certConfig.getCertRootPath(); final String certRootPath = certConfig.getCertRootPath();
final String certBasePath = certRootPath + "/file"; final String certBasePath = certRootPath + "/file";
@ -304,7 +332,7 @@ public class ShopOrderController extends BaseController {
.build(); .build();
logger.info("✅ 生产环境使用自动证书配置创建通知解析器成功"); logger.info("✅ 生产环境使用自动证书配置创建通知解析器成功");
}
// }
} catch (Exception e) { } catch (Exception e) {
logger.error("❌ 创建通知配置失败 - 租户ID: {}, 商户号: {}", tenantId, payment.getMchId(), e); logger.error("❌ 创建通知配置失败 - 租户ID: {}, 商户号: {}", tenantId, payment.getMchId(), e);
logger.error("🔍 错误详情: {}", e.getMessage()); logger.error("🔍 错误详情: {}", e.getMessage());

2
src/main/java/com/gxwebsoft/shop/entity/ShopDealerOrder.java

@ -60,7 +60,7 @@ public class ShopDealerOrder implements Serializable {
private Integer isSettled; private Integer isSettled;
@Schema(description = "结算时间") @Schema(description = "结算时间")
private Integer settleTime;
private Long settleTime;
@Schema(description = "商城ID") @Schema(description = "商城ID")
private Integer tenantId; private Integer tenantId;

3
src/main/java/com/gxwebsoft/shop/entity/ShopGoods.java

@ -69,6 +69,9 @@ public class ShopGoods implements Serializable {
@Schema(description = "经销商价格") @Schema(description = "经销商价格")
private BigDecimal dealerPrice; private BigDecimal dealerPrice;
@Schema(description = "佣金")
private BigDecimal commission;
@Schema(description = "库存计算方式(10下单减库存 20付款减库存)") @Schema(description = "库存计算方式(10下单减库存 20付款减库存)")
private Integer deductStockType; private Integer deductStockType;

1
src/main/java/com/gxwebsoft/shop/service/ShopOrderGoodsService.java

@ -39,4 +39,5 @@ public interface ShopOrderGoodsService extends IService<ShopOrderGoods> {
*/ */
ShopOrderGoods getByIdRel(Integer id); ShopOrderGoods getByIdRel(Integer id);
List<ShopOrderGoods> getListByOrderId(Integer orderId);
} }

9
src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderGoodsServiceImpl.java

@ -1,5 +1,6 @@
package com.gxwebsoft.shop.service.impl; package com.gxwebsoft.shop.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.mapper.ShopOrderGoodsMapper; import com.gxwebsoft.shop.mapper.ShopOrderGoodsMapper;
import com.gxwebsoft.shop.service.ShopOrderGoodsService; import com.gxwebsoft.shop.service.ShopOrderGoodsService;
@ -44,4 +45,12 @@ public class ShopOrderGoodsServiceImpl extends ServiceImpl<ShopOrderGoodsMapper,
return param.getOne(baseMapper.selectListRel(param)); return param.getOne(baseMapper.selectListRel(param));
} }
@Override
public List<ShopOrderGoods> getListByOrderId(Integer orderId) {
return list(
new LambdaQueryWrapper<ShopOrderGoods>()
.eq(ShopOrderGoods::getOrderId, orderId)
);
}
} }

97
src/main/java/com/gxwebsoft/shop/service/impl/ShopOrderServiceImpl.java

@ -4,30 +4,25 @@
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.util.CollectionUtils;
import com.gxwebsoft.common.core.config.ConfigProperties; import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.config.CertificateProperties; import com.gxwebsoft.common.core.config.CertificateProperties;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.utils.CertificateLoader;
import com.gxwebsoft.common.core.utils.*;
import com.gxwebsoft.common.core.service.PaymentCacheService; import com.gxwebsoft.common.core.service.PaymentCacheService;
import com.gxwebsoft.common.core.utils.WechatPayDiagnostic;
import com.gxwebsoft.common.core.utils.WechatPayCertificateDiagnostic;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.system.entity.Payment; import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.entity.*;
import com.gxwebsoft.shop.service.*;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import com.gxwebsoft.common.system.service.PaymentService; import com.gxwebsoft.common.system.service.PaymentService;
import com.gxwebsoft.common.system.service.SettingService; import com.gxwebsoft.common.system.service.SettingService;
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.ShopOrderService;
import com.gxwebsoft.shop.entity.ShopOrder;
import com.gxwebsoft.shop.param.ShopOrderParam; import com.gxwebsoft.shop.param.ShopOrderParam;
import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAConfig; import com.wechat.pay.java.core.RSAConfig;
import com.wechat.pay.java.core.RSAPublicKeyConfig; import com.wechat.pay.java.core.RSAPublicKeyConfig;
import com.gxwebsoft.common.core.utils.WechatCertAutoConfig;
import com.wechat.pay.java.core.exception.ServiceException; import com.wechat.pay.java.core.exception.ServiceException;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.*; import com.wechat.pay.java.service.payments.jsapi.model.*;
@ -38,10 +33,8 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.sql.Date;
import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -62,6 +55,8 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
@Resource @Resource
private ShopOrderGoodsService shopOrderGoodsService; private ShopOrderGoodsService shopOrderGoodsService;
@Resource @Resource
private ShopGoodsService shopGoodsService;
@Resource
private PaymentService paymentService; private PaymentService paymentService;
@Resource @Resource
private SettingService settingService; private SettingService settingService;
@ -77,6 +72,12 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
private WechatPayDiagnostic wechatPayDiagnostic; private WechatPayDiagnostic wechatPayDiagnostic;
@Resource @Resource
private WechatPayCertificateDiagnostic certificateDiagnostic; private WechatPayCertificateDiagnostic certificateDiagnostic;
@Resource
private RequestUtil requestUtil;
@Resource
private ShopDealerOrderService shopDealerOrderService;
@Resource
private ShopDealerCapitalService shopDealerCapitalService;
@Override @Override
public PageResult<ShopOrder> pageRel(ShopOrderParam param) { public PageResult<ShopOrder> pageRel(ShopOrderParam param) {
@ -243,6 +244,61 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
@Override @Override
public void updateByOutTradeNo(ShopOrder order) { public void updateByOutTradeNo(ShopOrder order) {
baseMapper.updateByOutTradeNo(order); baseMapper.updateByOutTradeNo(order);
if (order.getTenantId().equals(10550)) {
requestUtil.setTenantId(order.getTenantId().toString());
ApiResult<?> partnerConditionReq = requestUtil.pageDictData(1460);
if (partnerConditionReq.getCode().equals(0) && partnerConditionReq.getData() != null) {
LinkedHashMap<String, Object> dictDataMap = (LinkedHashMap<String, Object>) partnerConditionReq.getData();
List<LinkedHashMap> dictDataList = (List<LinkedHashMap>) dictDataMap.get("list");
String dictDataCode = (String) dictDataList.get(0).get("dictDataCode");
BigDecimal partnerCondition = new BigDecimal(dictDataCode);
User user = requestUtil.getByUserIdWithoutLogin(order.getUserId());
if (user != null) {
user.setExpendMoney(user.getExpendMoney().add(order.getPayPrice()));
if (user.getExpendMoney().compareTo(partnerCondition) >= 0) {
user.setGradeId(3);
}
requestUtil.updateWithoutLogin(user);
// 上级
User parent = requestUtil.getParent(order.getUserId());
if (parent != null) {
List<ShopOrderGoods> shopOrderGoodsList = shopOrderGoodsService.getListByOrderId(order.getOrderId());
List<Integer> goodsIds = shopOrderGoodsList.stream().map(ShopOrderGoods::getGoodsId).toList();
List<ShopGoods> shopGoodsList = shopGoodsService.listByIds(goodsIds);
BigDecimal commission = BigDecimal.ZERO;
for (ShopOrderGoods shopOrderGoods : shopOrderGoodsList) {
ShopGoods shopGoods = shopGoodsList.stream().filter(sG -> sG.getGoodsId().equals(shopOrderGoods.getGoodsId())).findFirst().orElse(null);
if (shopGoods != null) {
commission = commission.add(shopGoods.getCommission().multiply(BigDecimal.valueOf(shopOrderGoods.getTotalNum())));
}
}
parent.setBalance(parent.getBalance().add(commission));
requestUtil.updateWithoutLogin(user);
// 分销订单
ShopDealerOrder shopDealerOrder = new ShopDealerOrder();
shopDealerOrder.setUserId(parent.getUserId());
shopDealerOrder.setOrderId(order.getOrderId());
shopDealerOrder.setOrderPrice(order.getTotalPrice());
shopDealerOrder.setFirstUserId(order.getUserId());
shopDealerOrder.setFirstMoney(commission);
shopDealerOrder.setIsSettled(1);
shopDealerOrder.setSettleTime(DateUtil.currentSeconds());
shopDealerOrderService.save(shopDealerOrder);
// 分销资明细
ShopDealerCapital shopDealerCapital = new ShopDealerCapital();
shopDealerCapital.setUserId(parent.getUserId());
shopDealerCapital.setOrderId(order.getOrderId());
shopDealerCapital.setFlowType(10);
shopDealerCapitalService.save(shopDealerCapital);
}
}
}
}
} }
/** /**
@ -304,9 +360,8 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
// 开发环境配置 - 使用自动证书配置 // 开发环境配置 - 使用自动证书配置
if (active.equals("dev")) { if (active.equals("dev")) {
// 开发环境 - 使用配置文件的upload-path构建证书路径
String uploadPath = config.getUploadPath();
String tenantCertPath = uploadPath + "dev/wechat/" + order.getTenantId();
// 构建包含租户号的证书路径: dev/wechat/{tenantId}/
String tenantCertPath = "dev/wechat/" + order.getTenantId();
String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile(); String privateKeyPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getPrivateKeyFile();
System.out.println("开发环境证书路径 - 租户ID: " + order.getTenantId()); System.out.println("开发环境证书路径 - 租户ID: " + order.getTenantId());
@ -396,9 +451,8 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
payment.getPubKeyId() != null && !payment.getPubKeyId().isEmpty()) { payment.getPubKeyId() != null && !payment.getPubKeyId().isEmpty()) {
try { try {
// 开发环境使用配置文件的upload-path构建公钥路径
String uploadPath = config.getUploadPath();
String tenantCertPath = uploadPath + "dev/wechat/" + order.getTenantId();
// 开发环境固定使用 wechatpay_public_key.pem
String tenantCertPath = "dev/wechat/" + order.getTenantId();
String pubKeyPath = tenantCertPath + "/wechatpay_public_key.pem"; String pubKeyPath = tenantCertPath + "/wechatpay_public_key.pem";
System.out.println("开发环境公钥文件路径: " + pubKeyPath); System.out.println("开发环境公钥文件路径: " + pubKeyPath);
@ -472,8 +526,7 @@ import com.gxwebsoft.common.core.service.PaymentCacheService;
System.err.println("⚠️ 开发环境回退到基础RSA配置..."); System.err.println("⚠️ 开发环境回退到基础RSA配置...");
try { try {
// 方案1:尝试使用RSA证书配置(需要商户证书文件) // 方案1:尝试使用RSA证书配置(需要商户证书文件)
String uploadPath = config.getUploadPath();
String tenantCertPath = uploadPath + "dev/wechat/" + order.getTenantId();
String tenantCertPath = "dev/wechat/" + order.getTenantId();
String apiclientCertPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getApiclientCertFile(); String apiclientCertPath = tenantCertPath + "/" + certConfig.getWechatPay().getDev().getApiclientCertFile();
if (certificateLoader.certificateExists(apiclientCertPath)) { if (certificateLoader.certificateExists(apiclientCertPath)) {

4
src/main/resources/application-prod.yml

@ -3,7 +3,7 @@
# 数据源配置 # 数据源配置
spring: spring:
datasource: datasource:
url: jdbc:mysql://1Panel-mysql-Bqdt:3306/website?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
url: jdbc:mysql://1Panel-mysql-Bqdt:3306/modules?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8
username: modules username: modules
password: 8YdLnk7KsPAyDXGA password: 8YdLnk7KsPAyDXGA
driver-class-name: com.mysql.cj.jdbc.Driver driver-class-name: com.mysql.cj.jdbc.Driver
@ -45,7 +45,7 @@ mqtt:
config: config:
# 生产环境接口 # 生产环境接口
server-url: https://server.websoft.top/api server-url: https://server.websoft.top/api
upload-path: /www/wwwroot/file.ws
upload-path: /www/wwwroot/file.ws/
# 阿里云OSS云存储 # 阿里云OSS云存储
endpoint: https://oss-cn-shenzhen.aliyuncs.com endpoint: https://oss-cn-shenzhen.aliyuncs.com

2
src/main/resources/application.yml

@ -4,7 +4,7 @@ server:
# 多环境配置 # 多环境配置
spring: spring:
profiles: profiles:
active: dev
active: prod
application: application:
name: server name: server

Loading…
Cancel
Save