新增:微信支付及回调

This commit is contained in:
gxwebsoft
2024-05-11 16:15:42 +08:00
parent 04933e5a2e
commit 8ea313d7c8
33 changed files with 2453 additions and 181 deletions

View File

@@ -53,7 +53,8 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
"/api/wx-login/loginByMpWxPhone",
"/api/wxWorkQrConnect",
"/api/sys/user-plan-log/wx-pay/**",
"/api/wx-official/**"
"/api/wx-official/**",
"/lvQ4EoivKJ.txt"
)
.permitAll()
.anyRequest()

View File

@@ -73,10 +73,10 @@ public class SocketIOConfig implements InitializingBean {
config.setKeyStorePassword("123456"); // 设置证书密码
// 启动socket服务
SocketIOServer server = new SocketIOServer(config);
server.addListeners(socketIOHandler);
server.start();
ClientCache.setSocketIOServer(server);
logger.debug("Netty SocketIO启动{}:{}",host,port);
// SocketIOServer server = new SocketIOServer(config);
// server.addListeners(socketIOHandler);
// server.start();
// ClientCache.setSocketIOServer(server);
// logger.debug("Netty SocketIO启动{}:{}",host,port);
}
}

View File

@@ -1,10 +1,12 @@
package com.gxwebsoft.common.system.controller;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.Company;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.CompanyService;
import com.gxwebsoft.common.system.service.OrderInfoService;
import com.gxwebsoft.common.system.service.OrderService;
import com.gxwebsoft.common.system.entity.Order;
import com.gxwebsoft.common.system.param.OrderParam;
@@ -36,6 +38,8 @@ public class OrderController extends BaseController {
private OrderService orderService;
@Resource
private CompanyService companyService;
@Resource
private OrderInfoService orderInfoService;
@PreAuthorize("hasAuthority('sys:order:list')")
@OperationLog
@@ -69,21 +73,34 @@ public class OrderController extends BaseController {
@ApiOperation("添加订单")
@PostMapping()
public ApiResult<?> save(@RequestBody Order order) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
order.setUserId(loginUser.getUserId());
// 记录当前登录用户id
User loginUser = getLoginUser();
long timeMillis = System.currentTimeMillis();
long orderNo = IdUtil.getSnowflakeNextId();
if (loginUser != null) {
order.setUserId(loginUser.getUserId());
order.setOpenid(loginUser.getOpenid());
}
order.setOrderNo(Long.toString(orderNo));
order.setRealName(loginUser.getRealName());
order.setStartTime(timeMillis / 1000);
order.setAddTime(timeMillis / 1000);
order.setPhone(loginUser.getPhone());
order.setVersion(10);
if (orderService.save(order)) {
order.getOrderInfoList().forEach(d -> {
d.setOid(order.getOrderId());
d.setTimeFlag(timeMillis);
d.setVersion(10);
d.setOrderTime(timeMillis / 1000);
});
orderInfoService.saveBatch(order.getOrderInfoList());
// 创建微信订单
if (order.getPayType().equals(1)) {
return success("下单成功",orderService.createWxOrder(order));
}
if (orderService.save(order)) {
System.out.println("order = " + order);
// 延长到期时间
final Company company = companyService.getByTenantIdRel(order.getTenantId());
company.setStatus(1);
// company.setExpirationTime(new Date());
companyService.updateById(company);
return success("添加成功");
}
return fail("添加失败");
}
return fail("下单失败");
}
@PreAuthorize("hasAuthority('sys:order:update')")

View File

@@ -0,0 +1,138 @@
package com.gxwebsoft.common.system.controller;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.OrderInfoService;
import com.gxwebsoft.common.system.entity.OrderInfo;
import com.gxwebsoft.common.system.param.OrderInfoParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 控制器
*
* @author 科技小王子
* @since 2024-05-10 18:02:54
*/
@Api(tags = "管理")
@RestController
@RequestMapping("/api/system/order-info")
public class OrderInfoController extends BaseController {
@Resource
private OrderInfoService orderInfoService;
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
@OperationLog
@ApiOperation("分页查询")
@GetMapping("/page")
public ApiResult<PageResult<OrderInfo>> page(OrderInfoParam param) {
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(orderInfoService.page(page, page.getWrapper()));
// 使用关联查询
//return success(orderInfoService.pageRel(param));
}
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
@OperationLog
@ApiOperation("查询全部")
@GetMapping()
public ApiResult<List<OrderInfo>> list(OrderInfoParam param) {
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
return success(orderInfoService.list(page.getOrderWrapper()));
// 使用关联查询
//return success(orderInfoService.listRel(param));
}
@PreAuthorize("hasAuthority('sys:orderInfo:list')")
@OperationLog
@ApiOperation("根据id查询")
@GetMapping("/{id}")
public ApiResult<OrderInfo> get(@PathVariable("id") Integer id) {
return success(orderInfoService.getById(id));
// 使用关联查询
//return success(orderInfoService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('sys:orderInfo:save')")
@OperationLog
@ApiOperation("添加")
@PostMapping()
public ApiResult<?> save(@RequestBody OrderInfo orderInfo) {
// 记录当前登录用户id
User loginUser = getLoginUser();
if (loginUser != null) {
}
if (orderInfoService.save(orderInfo)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('sys:orderInfo:update')")
@OperationLog
@ApiOperation("修改")
@PutMapping()
public ApiResult<?> update(@RequestBody OrderInfo orderInfo) {
if (orderInfoService.updateById(orderInfo)) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('sys:orderInfo:remove')")
@OperationLog
@ApiOperation("删除")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
if (orderInfoService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('sys:orderInfo:save')")
@OperationLog
@ApiOperation("批量添加")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<OrderInfo> list) {
if (orderInfoService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('sys:orderInfo:update')")
@OperationLog
@ApiOperation("批量修改")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<OrderInfo> batchParam) {
if (batchParam.update(orderInfoService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('sys:orderInfo:remove')")
@OperationLog
@ApiOperation("批量删除")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (orderInfoService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -0,0 +1,150 @@
package com.gxwebsoft.common.system.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.Merchant;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.service.PaymentService;
import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.param.PaymentParam;
import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.annotation.OperationLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
/**
* 支付方式控制器
*
* @author 科技小王子
* @since 2024-05-11 12:39:11
*/
@Api(tags = "支付方式管理")
@RestController
@RequestMapping("/api/system/payment")
public class PaymentController extends BaseController {
@Resource
private PaymentService paymentService;
@Resource
private RedisUtil redisUtil;
@PreAuthorize("hasAuthority('sys:payment:list')")
@OperationLog
@ApiOperation("分页查询支付方式")
@GetMapping("/page")
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));
}
@PreAuthorize("hasAuthority('sys:payment:list')")
@OperationLog
@ApiOperation("查询全部支付方式")
@GetMapping()
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));
}
@PreAuthorize("hasAuthority('sys:payment:list')")
@OperationLog
@ApiOperation("根据id查询支付方式")
@GetMapping("/{id}")
public ApiResult<Payment> get(@PathVariable("id") Integer id) {
return success(paymentService.getById(id));
// 使用关联查询
//return success(paymentService.getByIdRel(id));
}
@PreAuthorize("hasAuthority('sys:payment:save')")
@OperationLog
@ApiOperation("添加支付方式")
@PostMapping()
public ApiResult<?> save(@RequestBody Payment payment) {
if (paymentService.count(new LambdaQueryWrapper<Payment>().eq(Payment::getCode,payment.getCode())) > 0) {
return fail(payment.getName() + "已存在");
}
if (paymentService.save(payment)) {
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
redisUtil.set(key,payment);
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('sys:payment:update')")
@OperationLog
@ApiOperation("修改支付方式")
@PutMapping()
public ApiResult<?> update(@RequestBody Payment payment) {
if (paymentService.updateById(payment)) {
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
redisUtil.set(key,payment);
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('sys:payment:remove')")
@OperationLog
@ApiOperation("删除支付方式")
@DeleteMapping("/{id}")
public ApiResult<?> remove(@PathVariable("id") Integer id) {
final Payment payment = paymentService.getById(id);
System.out.println("payment = " + payment);
String key = "Payment:" + payment.getCode() + ":" + getTenantId();
redisUtil.delete(key);
if (paymentService.removeById(id)) {
return success("删除成功");
}
return fail("删除失败");
}
@PreAuthorize("hasAuthority('sys:payment:save')")
@OperationLog
@ApiOperation("批量添加支付方式")
@PostMapping("/batch")
public ApiResult<?> saveBatch(@RequestBody List<Payment> list) {
if (paymentService.saveBatch(list)) {
return success("添加成功");
}
return fail("添加失败");
}
@PreAuthorize("hasAuthority('sys:payment:update')")
@OperationLog
@ApiOperation("批量修改支付方式")
@PutMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody BatchParam<Payment> batchParam) {
if (batchParam.update(paymentService, "id")) {
return success("修改成功");
}
return fail("修改失败");
}
@PreAuthorize("hasAuthority('sys:payment:remove')")
@OperationLog
@ApiOperation("批量删除支付方式")
@DeleteMapping("/batch")
public ApiResult<?> removeBatch(@RequestBody List<Integer> ids) {
if (paymentService.removeByIds(ids)) {
return success("删除成功");
}
return fail("删除失败");
}
}

View File

@@ -0,0 +1,19 @@
package com.gxwebsoft.common.system.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "域名所有权验证")
@RestController
@RequestMapping("/lvQ4EoivKJ.txt")
public class VerifyTxt {
@ApiOperation("域名所有权验证")
@GetMapping()
public String verify(){
return "cbfbfe827744f1ebfaf03bfe2a0def6a";
}
}

View File

@@ -268,7 +268,12 @@ public class WxLoginController extends BaseController {
final String response = HttpUtil.get(apiUrl,map);
System.out.println("response = " + response);
final JSONObject jsonObject = JSONObject.parseObject(response);
return fail("更新失败",null);
final String openid = jsonObject.getString("openid");
jsonObject.getString("session_key");
jsonObject.getString("unionid");
System.out.println("openid = " + openid);
System.out.println("loginUser = " + loginUser);
return success("获取成功",jsonObject);
}
@ApiOperation("获取微信小程序码")

View File

@@ -0,0 +1,148 @@
package com.gxwebsoft.common.system.controller;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayApiException;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.utils.AlipayConfigUtil;
import com.gxwebsoft.common.core.utils.CommonUtil;
import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.system.entity.Order;
import com.gxwebsoft.common.system.entity.Setting;
import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.common.system.mapper.SettingMapper;
import com.gxwebsoft.common.system.param.SettingParam;
import com.gxwebsoft.common.system.service.OrderInfoService;
import com.gxwebsoft.common.system.service.OrderService;
import com.gxwebsoft.common.system.service.SettingService;
import com.gxwebsoft.common.system.service.UserService;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.core.notification.RSANotificationConfig;
import com.wechat.pay.java.service.partnerpayments.jsapi.model.Transaction;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.Map;
import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_NO_PAY;
import static com.gxwebsoft.common.core.constants.OrderConstants.PAY_STATUS_SUCCESS;
/**
* 会员特权购买记录表控制器
*
* @author 科技小王子
* @since 2023-06-20 18:07:50
*/
@Api(tags = "会员特权购买记录表管理")
@RestController
@RequestMapping("/api/love/user-plan-log")
public class WxPayNotifyController extends BaseController {
@Resource
private OrderService orderService;
@Resource
private ConfigProperties config;
@Resource
private SettingMapper settingMapper;
@ApiModelProperty("异步通知")
@PostMapping("/wx-pay/notify/{tenantId}")
public String wxNotify(@RequestHeader Map<String, String> header, @RequestBody String body, @PathVariable("tenantId") Integer tenantId) {
System.out.println("异步通知*************** = ");
System.out.println("request header = " + header);
System.out.println("request body = " + body);
System.out.println("tenantId = " + tenantId);
// 获取支付配置信息用于解密
final SettingParam param = new SettingParam();
param.setSettingKey("payment");
param.setTenantId(tenantId);
final String uploadPath = config.getUploadPath(); // 服务器本地路径
final Setting payment = settingMapper.getBySettingKeyIgnore(param);
final JSONObject jsonObject = JSONObject.parseObject(payment.getContent());
final String apiV3key = jsonObject.getString("wechatApiKey");
final String apiclientCert = uploadPath.concat("file").concat(jsonObject.getString("apiclientCert"));
// System.out.println("apiV3key ====== " + apiV3key);
// System.out.println("payment ===== " + payment);
com.wechat.pay.java.core.notification.RequestParam requestParam = new com.wechat.pay.java.core.notification.RequestParam.Builder()
.serialNumber(header.get("wechatpay-serial"))
.nonce(header.get("wechatpay-nonce"))
.signature(header.get("wechatpay-signature"))
.timestamp(header.get("wechatpay-timestamp"))
.body(body)
.build();
// 如果已经初始化了 RSAAutoCertificateConfig可直接使用
// 没有的话,则构造一个
NotificationConfig config = new RSANotificationConfig.Builder()
.apiV3Key(apiV3key)
.certificatesFromPath(apiclientCert)
.build();
// 初始化 NotificationParser
NotificationParser parser = new NotificationParser(config);
// 以支付通知回调为例,验签、解密并转换成 Transaction
try {
Transaction transaction = parser.parse(requestParam, Transaction.class);
final String outTradeNo = transaction.getOutTradeNo();
final String transactionId = transaction.getTransactionId();
final Integer total = transaction.getAmount().getTotal();
final String tradeStateDesc = transaction.getTradeStateDesc();
// final Transaction.TradeStateEnum tradeState = transaction.getTradeState();
// final Transaction.TradeTypeEnum tradeType = transaction.getTradeType();
// System.out.println("transaction = " + transaction);
// System.out.println("tradeStateDesc = " + tradeStateDesc);
// System.out.println("tradeType = " + tradeType);
// System.out.println("tradeState = " + tradeState);
// System.out.println("outTradeNo = " + outTradeNo);
// System.out.println("amount = " + total);
if (StrUtil.equals("支付成功", tradeStateDesc)) {
// 1. 查询要处理的订单
Order order = orderService.getByOutTradeNo(outTradeNo);
// 2. 已支付则跳过
if (order.getPayStatus().equals(PAY_STATUS_SUCCESS)) {
return "SUCCESS";
}
// 2. 未支付则处理更新订单状态
if (order.getPayStatus().equals(PAY_STATUS_NO_PAY)) {
// 5. TODO 处理订单状态
order.setPayStatus(PAY_STATUS_SUCCESS);
order.setPayTime(DateUtil.date());
order.setTransactionId(transactionId);
// 实际付款金额Integer除以100后转BigDecimal
DecimalFormat df = new DecimalFormat("0.00");
final String format = df.format(total / 100);
order.setPayPrice(new BigDecimal(format));
orderService.updateByOutTradeNo(order);
return "SUCCESS";
}
}
} catch (Exception $e) {
System.out.println($e.getMessage());
}
return "fail";
}
}

View File

@@ -72,9 +72,18 @@ public class Merchant implements Serializable {
@ApiModelProperty(value = "资质图片")
private String files;
@ApiModelProperty(value = "营业时间")
private String businessTime;
@ApiModelProperty(value = "商户简介")
private String content;
@ApiModelProperty(value = "是否自营")
private Integer ownStore;
@ApiModelProperty(value = "每小时价格")
private BigDecimal price;
@ApiModelProperty(value = "是否推荐")
private Integer recommend;

View File

@@ -7,6 +7,7 @@ import com.baomidou.mybatisplus.annotation.*;
import java.time.LocalDateTime;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -66,9 +67,15 @@ public class Order implements Serializable {
@ApiModelProperty(value = "联系电话")
private String phone;
@ApiModelProperty(value = "订单总额")
private BigDecimal totalPrice;
@ApiModelProperty(value = "付款时间")
private Date payTime;
@ApiModelProperty(value = "1微信支付2积分3支付宝4现金5POS机6VIP月卡7VIP年卡8VIP次卡9IC月卡10IC年卡11IC次卡12免费13VIP充值卡14IC充值卡15积分支付16VIP季卡17IC季卡")
private Integer payType;
@ApiModelProperty(value = "支付流水号")
private String transactionId;
@@ -130,6 +137,19 @@ public class Order implements Serializable {
@ApiModelProperty(value = "修改时间")
private Date updateTime;
@ApiModelProperty(value = "用于微信支付")
@TableField(exist = false)
private String openid;
@ApiModelProperty(value = "预约详情开始时间数组")
private Long startTime;
@ApiModelProperty(value = "下单时间")
private Long addTime;
@ApiModelProperty(value = "系统版本")
private Integer version;
@ApiModelProperty(value = "租户名称")
@TableField(exist = false)
private String tenantName;
@@ -138,4 +158,8 @@ public class Order implements Serializable {
@TableField(exist = false)
private Integer companyId;
@ApiModelProperty(value = "订单详情")
@TableField(exist = false)
private List<OrderInfo> orderInfoList;
}

View File

@@ -0,0 +1,94 @@
package com.gxwebsoft.common.system.entity;
import java.math.BigDecimal;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import java.io.Serializable;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author 科技小王子
* @since 2024-05-10 18:02:54
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "OrderInfo对象", description = "")
@TableName("sys_order_info")
public class OrderInfo implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "关联订单表id")
private Integer oid;
@ApiModelProperty(value = "关联场馆id")
private Integer sid;
@ApiModelProperty(value = "关联场地id")
private Integer fid;
@ApiModelProperty(value = "场馆")
private String siteName;
@ApiModelProperty(value = "场地")
private String fieldName;
@ApiModelProperty(value = "预约时间段")
private String dateTime;
@ApiModelProperty(value = "单价")
private BigDecimal price;
@ApiModelProperty(value = "儿童价")
private BigDecimal childrenPrice;
@ApiModelProperty(value = "成人人数")
private Integer adultNum;
@ApiModelProperty(value = "儿童人数")
private Integer childrenNum;
@ApiModelProperty(value = "1已付款2未付款3无需付款或占用状态")
private Integer payStatus;
@ApiModelProperty(value = "是否免费1免费、2收费")
private Integer isFree;
@ApiModelProperty(value = "是否支持儿童票1支持2不支持")
private Integer isChildren;
@ApiModelProperty(value = "预订类型1全场2半场")
private Integer type;
@ApiModelProperty(value = "组合数据:日期+时间段+场馆id+场地id")
private String mergeData;
@ApiModelProperty(value = "开场时间")
private Integer startTime;
@ApiModelProperty(value = "下单时间")
private Long orderTime;
@ApiModelProperty(value = "毫秒时间戳")
private Long timeFlag;
@ApiModelProperty(value = "系统版本")
private Integer version;
@ApiModelProperty(value = "是否删除, 0否, 1是")
@TableLogic
private Integer deleted;
@ApiModelProperty(value = "租户id")
private Integer tenantId;
}

View File

@@ -0,0 +1,85 @@
package com.gxwebsoft.common.system.entity;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.TableLogic;
import java.io.Serializable;
import java.util.Date;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 支付方式
*
* @author 科技小王子
* @since 2024-05-11 12:39:11
*/
@Data
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "Payment对象", description = "支付方式")
@TableName("sys_payment")
public class Payment implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "ID")
@TableId(value = "id", type = IdType.AUTO)
private Integer id;
@ApiModelProperty(value = "支付方式")
private String name;
@ApiModelProperty(value = "标识")
private String code;
@ApiModelProperty(value = "支付图标")
private String image;
@ApiModelProperty(value = "微信商户号类型 1普通商户2子商户")
private Integer wechatType;
@ApiModelProperty(value = "应用ID")
private String appId;
@ApiModelProperty(value = "商户号")
private String mchId;
@ApiModelProperty(value = "设置APIv3密钥")
private String apiKey;
@ApiModelProperty(value = "证书文件 (CERT)")
private String apiclientCert;
@ApiModelProperty(value = "证书文件 (KEY)")
private String apiclientKey;
@ApiModelProperty(value = "商户证书序列号")
private String merchantSerialNumber;
@ApiModelProperty(value = "备注")
private String comments;
@ApiModelProperty(value = "文章排序(数字越小越靠前)")
private Integer sortNumber;
@ApiModelProperty(value = "状态, 0未启用, 1启用")
private Boolean status;
@ApiModelProperty(value = "是否删除, 0否, 1是")
@TableLogic
private Integer deleted;
@ApiModelProperty(value = "租户id")
private Integer tenantId;
@ApiModelProperty(value = "注册时间")
private Date createTime;
@ApiModelProperty(value = "修改时间")
private Date updateTime;
}

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.common.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.common.system.entity.OrderInfo;
import com.gxwebsoft.common.system.param.OrderInfoParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Mapper
*
* @author 科技小王子
* @since 2024-05-10 18:02:54
*/
public interface OrderInfoMapper extends BaseMapper<OrderInfo> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<OrderInfo>
*/
List<OrderInfo> selectPageRel(@Param("page") IPage<OrderInfo> page,
@Param("param") OrderInfoParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<OrderInfo> selectListRel(@Param("param") OrderInfoParam param);
}

View File

@@ -1,5 +1,6 @@
package com.gxwebsoft.common.system.mapper;
import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.common.system.entity.Order;
@@ -34,4 +35,10 @@ public interface OrderMapper extends BaseMapper<Order> {
*/
List<Order> selectListRel(@Param("param") OrderParam param);
@InterceptorIgnore(tenantLine = "true")
List<Order> getByOutTradeNo(OrderParam param);
@InterceptorIgnore(tenantLine = "true")
void updateByOutTradeNo(@Param("param") Order outTradeNo);
}

View File

@@ -0,0 +1,37 @@
package com.gxwebsoft.common.system.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.param.PaymentParam;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* 支付方式Mapper
*
* @author 科技小王子
* @since 2024-05-11 12:39:11
*/
public interface PaymentMapper extends BaseMapper<Payment> {
/**
* 分页查询
*
* @param page 分页对象
* @param param 查询参数
* @return List<Payment>
*/
List<Payment> selectPageRel(@Param("page") IPage<Payment> page,
@Param("param") PaymentParam param);
/**
* 查询全部
*
* @param param 查询参数
* @return List<User>
*/
List<Payment> selectListRel(@Param("param") PaymentParam param);
}

View File

@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.common.system.mapper.OrderInfoMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM sys_order_info a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.oid != null">
AND a.oid = #{param.oid}
</if>
<if test="param.sid != null">
AND a.sid = #{param.sid}
</if>
<if test="param.fid != null">
AND a.fid = #{param.fid}
</if>
<if test="param.siteName != null">
AND a.site_name LIKE CONCAT('%', #{param.siteName}, '%')
</if>
<if test="param.fieldName != null">
AND a.field_name LIKE CONCAT('%', #{param.fieldName}, '%')
</if>
<if test="param.dateTime != null">
AND a.date_time LIKE CONCAT('%', #{param.dateTime}, '%')
</if>
<if test="param.price != null">
AND a.price = #{param.price}
</if>
<if test="param.childrenPrice != null">
AND a.children_price = #{param.childrenPrice}
</if>
<if test="param.adultNum != null">
AND a.adult_num = #{param.adultNum}
</if>
<if test="param.childrenNum != null">
AND a.children_num = #{param.childrenNum}
</if>
<if test="param.payStatus != null">
AND a.pay_status = #{param.payStatus}
</if>
<if test="param.isFree != null">
AND a.is_free = #{param.isFree}
</if>
<if test="param.isChildren != null">
AND a.is_children = #{param.isChildren}
</if>
<if test="param.type != null">
AND a.type = #{param.type}
</if>
<if test="param.mergeData != null">
AND a.merge_data LIKE CONCAT('%', #{param.mergeData}, '%')
</if>
<if test="param.startTime != null">
AND a.start_time = #{param.startTime}
</if>
<if test="param.orderTime != null">
AND a.order_time = #{param.orderTime}
</if>
<if test="param.timeFlag != null">
AND a.time_flag LIKE CONCAT('%', #{param.timeFlag}, '%')
</if>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.OrderInfo">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.OrderInfo">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -123,4 +123,14 @@
<include refid="selectSql"></include>
</select>
<!-- 按OutTradeNo查询 -->
<select id="getByOutTradeNo" resultType="com.gxwebsoft.common.system.entity.Order">
<include refid="selectSql"></include>
</select>
<!-- 更新订单状态 -->
<select id="updateByOutTradeNo" resultType="com.gxwebsoft.common.system.entity.Order">
UPDATE sys_order SET pay_status = #{param.payStatus},pay_time = #{param.payTime},pay_price = #{param.payPrice},transaction_id = #{param.transactionId} WHERE order_no = #{param.orderNo}
</select>
</mapper>

View File

@@ -0,0 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.gxwebsoft.common.system.mapper.PaymentMapper">
<!-- 关联查询sql -->
<sql id="selectSql">
SELECT a.*
FROM sys_payment a
<where>
<if test="param.id != null">
AND a.id = #{param.id}
</if>
<if test="param.name != null">
AND a.name LIKE CONCAT('%', #{param.name}, '%')
</if>
<if test="param.code != null">
AND a.code = #{param.code}
</if>
<if test="param.wechatType != null">
AND a.wechat_type = #{param.wechatType}
</if>
<if test="param.appId != null">
AND a.app_id LIKE CONCAT('%', #{param.appId}, '%')
</if>
<if test="param.mchId != null">
AND a.mch_id LIKE CONCAT('%', #{param.mchId}, '%')
</if>
<if test="param.apiKey != null">
AND a.api_key LIKE CONCAT('%', #{param.apiKey}, '%')
</if>
<if test="param.apiclientCert != null">
AND a.apiclient_cert LIKE CONCAT('%', #{param.apiclientCert}, '%')
</if>
<if test="param.apiclientKey != null">
AND a.apiclient_key LIKE CONCAT('%', #{param.apiclientKey}, '%')
</if>
<if test="param.merchantSerialNumber != null">
AND a.merchant_serial_number LIKE CONCAT('%', #{param.merchantSerialNumber}, '%')
</if>
<if test="param.comments != null">
AND a.comments LIKE CONCAT('%', #{param.comments}, '%')
</if>
<if test="param.sortNumber != null">
AND a.sort_number = #{param.sortNumber}
</if>
<if test="param.status != null">
AND a.status = #{param.status}
</if>
<if test="param.deleted != null">
AND a.deleted = #{param.deleted}
</if>
<if test="param.deleted == null">
AND a.deleted = 0
</if>
<if test="param.createTimeStart != null">
AND a.create_time &gt;= #{param.createTimeStart}
</if>
<if test="param.createTimeEnd != null">
AND a.create_time &lt;= #{param.createTimeEnd}
</if>
</where>
</sql>
<!-- 分页查询 -->
<select id="selectPageRel" resultType="com.gxwebsoft.common.system.entity.Payment">
<include refid="selectSql"></include>
</select>
<!-- 查询全部 -->
<select id="selectListRel" resultType="com.gxwebsoft.common.system.entity.Payment">
<include refid="selectSql"></include>
</select>
</mapper>

View File

@@ -0,0 +1,101 @@
package com.gxwebsoft.common.system.param;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.math.BigDecimal;
/**
* 查询参数
*
* @author 科技小王子
* @since 2024-05-10 18:02:54
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "OrderInfoParam对象", description = "查询参数")
public class OrderInfoParam extends BaseParam {
private static final long serialVersionUID = 1L;
@QueryField(type = QueryType.EQ)
private Integer id;
@ApiModelProperty(value = "关联订单表id")
@QueryField(type = QueryType.EQ)
private Integer oid;
@ApiModelProperty(value = "关联场馆id")
@QueryField(type = QueryType.EQ)
private Integer sid;
@ApiModelProperty(value = "关联场地id")
@QueryField(type = QueryType.EQ)
private Integer fid;
@ApiModelProperty(value = "场馆")
private String siteName;
@ApiModelProperty(value = "场地")
private String fieldName;
@ApiModelProperty(value = "预约时间段")
private String dateTime;
@ApiModelProperty(value = "单价")
@QueryField(type = QueryType.EQ)
private BigDecimal price;
@ApiModelProperty(value = "儿童价")
@QueryField(type = QueryType.EQ)
private BigDecimal childrenPrice;
@ApiModelProperty(value = "成人人数")
@QueryField(type = QueryType.EQ)
private Boolean adultNum;
@ApiModelProperty(value = "儿童人数")
@QueryField(type = QueryType.EQ)
private Boolean childrenNum;
@ApiModelProperty(value = "1已付款2未付款3无需付款或占用状态")
@QueryField(type = QueryType.EQ)
private Boolean payStatus;
@ApiModelProperty(value = "是否免费1免费、2收费")
@QueryField(type = QueryType.EQ)
private Boolean isFree;
@ApiModelProperty(value = "是否支持儿童票1支持2不支持")
@QueryField(type = QueryType.EQ)
private Boolean isChildren;
@ApiModelProperty(value = "预订类型1全场2半场")
@QueryField(type = QueryType.EQ)
private Boolean type;
@ApiModelProperty(value = "组合数据:日期+时间段+场馆id+场地id")
private String mergeData;
@ApiModelProperty(value = "开场时间")
@QueryField(type = QueryType.EQ)
private Integer startTime;
@ApiModelProperty(value = "下单时间")
@QueryField(type = QueryType.EQ)
private Integer orderTime;
@ApiModelProperty(value = "毫秒时间戳")
private Long timeFlag;
@ApiModelProperty(value = "是否删除, 0否, 1是")
@QueryField(type = QueryType.EQ)
private Integer deleted;
}

View File

@@ -0,0 +1,73 @@
package com.gxwebsoft.common.system.param;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.gxwebsoft.common.core.annotation.QueryField;
import com.gxwebsoft.common.core.annotation.QueryType;
import com.gxwebsoft.common.core.web.BaseParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 支付方式查询参数
*
* @author 科技小王子
* @since 2024-05-11 12:39:11
*/
@Data
@EqualsAndHashCode(callSuper = false)
@JsonInclude(JsonInclude.Include.NON_NULL)
@ApiModel(value = "PaymentParam对象", description = "支付方式查询参数")
public class PaymentParam extends BaseParam {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "ID")
@QueryField(type = QueryType.EQ)
private Integer id;
@ApiModelProperty(value = "支付方式")
private String name;
@ApiModelProperty(value = "标识")
@QueryField(type = QueryType.EQ)
private Integer code;
@ApiModelProperty(value = "微信商户号类型 1普通商户2子商户")
@QueryField(type = QueryType.EQ)
private Integer wechatType;
@ApiModelProperty(value = "应用ID")
private String appId;
@ApiModelProperty(value = "商户号")
private String mchId;
@ApiModelProperty(value = "设置APIv3密钥")
private String apiKey;
@ApiModelProperty(value = "证书文件 (CERT)")
private String apiclientCert;
@ApiModelProperty(value = "证书文件 (KEY)")
private String apiclientKey;
@ApiModelProperty(value = "商户证书序列号")
private String merchantSerialNumber;
@ApiModelProperty(value = "备注")
private String comments;
@ApiModelProperty(value = "文章排序(数字越小越靠前)")
@QueryField(type = QueryType.EQ)
private Integer sortNumber;
@ApiModelProperty(value = "状态, 0启用, 1禁用")
@QueryField(type = QueryType.EQ)
private Boolean status;
@ApiModelProperty(value = "是否删除, 0否, 1是")
@QueryField(type = QueryType.EQ)
private Integer deleted;
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.common.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.OrderInfo;
import com.gxwebsoft.common.system.param.OrderInfoParam;
import java.util.List;
/**
* Service
*
* @author 科技小王子
* @since 2024-05-10 18:02:54
*/
public interface OrderInfoService extends IService<OrderInfo> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<OrderInfo>
*/
PageResult<OrderInfo> pageRel(OrderInfoParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<OrderInfo>
*/
List<OrderInfo> listRel(OrderInfoParam param);
/**
* 根据id查询
*
* @param id
* @return OrderInfo
*/
OrderInfo getByIdRel(Integer id);
}

View File

@@ -5,6 +5,7 @@ import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Order;
import com.gxwebsoft.common.system.param.OrderParam;
import java.util.HashMap;
import java.util.List;
/**
@@ -39,4 +40,9 @@ public interface OrderService extends IService<Order> {
*/
Order getByIdRel(Integer orderId);
HashMap<String, String> createWxOrder(Order order);
Order getByOutTradeNo(String outTradeNo);
void updateByOutTradeNo(Order order);
}

View File

@@ -0,0 +1,42 @@
package com.gxwebsoft.common.system.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.param.PaymentParam;
import java.util.List;
/**
* 支付方式Service
*
* @author 科技小王子
* @since 2024-05-11 12:39:11
*/
public interface PaymentService extends IService<Payment> {
/**
* 分页关联查询
*
* @param param 查询参数
* @return PageResult<Payment>
*/
PageResult<Payment> pageRel(PaymentParam param);
/**
* 关联查询全部
*
* @param param 查询参数
* @return List<Payment>
*/
List<Payment> listRel(PaymentParam param);
/**
* 根据id查询
*
* @param id ID
* @return Payment
*/
Payment getByIdRel(Integer id);
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.common.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.OrderInfoMapper;
import com.gxwebsoft.common.system.service.OrderInfoService;
import com.gxwebsoft.common.system.entity.OrderInfo;
import com.gxwebsoft.common.system.param.OrderInfoParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* Service实现
*
* @author 科技小王子
* @since 2024-05-10 18:02:54
*/
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {
@Override
public PageResult<OrderInfo> pageRel(OrderInfoParam param) {
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>(param);
//page.setDefaultOrder("create_time desc");
List<OrderInfo> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<OrderInfo> listRel(OrderInfoParam param) {
List<OrderInfo> list = baseMapper.selectListRel(param);
// 排序
PageParam<OrderInfo, OrderInfoParam> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public OrderInfo getByIdRel(Integer id) {
OrderInfoParam param = new OrderInfoParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}

View File

@@ -1,14 +1,31 @@
package com.gxwebsoft.common.system.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.core.config.ConfigProperties;
import com.gxwebsoft.common.core.utils.RedisUtil;
import com.gxwebsoft.common.system.entity.OrderInfo;
import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.mapper.OrderMapper;
import com.gxwebsoft.common.system.service.OrderService;
import com.gxwebsoft.common.system.entity.Order;
import com.gxwebsoft.common.system.param.OrderParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.service.PaymentService;
import com.gxwebsoft.common.system.service.SettingService;
import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAConfig;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.Amount;
import com.wechat.pay.java.service.payments.jsapi.model.Payer;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
/**
@@ -19,29 +36,127 @@ import java.util.List;
*/
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
@Resource
private ConfigProperties config;
@Resource
private SettingService settingService;
@Resource
private RedisUtil redisUtil;
@Resource
private PaymentService paymentService;
@Override
public PageResult<Order> pageRel(OrderParam param) {
PageParam<Order, OrderParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
List<Order> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public PageResult<Order> pageRel(OrderParam param) {
PageParam<Order, OrderParam> page = new PageParam<>(param);
page.setDefaultOrder("create_time desc");
List<Order> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<Order> listRel(OrderParam param) {
List<Order> list = baseMapper.selectListRel(param);
// 排序
PageParam<Order, OrderParam> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public List<Order> listRel(OrderParam param) {
List<Order> list = baseMapper.selectListRel(param);
// 排序
PageParam<Order, OrderParam> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public Order getByIdRel(Integer orderId) {
OrderParam param = new OrderParam();
param.setOrderId(orderId);
return param.getOne(baseMapper.selectListRel(param));
}
@Override
public Order getByIdRel(Integer orderId) {
OrderParam param = new OrderParam();
param.setOrderId(orderId);
return param.getOne(baseMapper.selectListRel(param));
}
/**
* 创建微信支付
*
* @param order
* @return
*/
@Override
public HashMap<String, String> createWxOrder(Order order) {
final String uploadPath = config.getUploadPath(); // 服务器本地路径
final HashMap<String, String> orderInfo = new HashMap<>();
// 微信小程序(微信支付)
String key = "Payment:wxPay:".concat(order.getTenantId().toString());
final Payment payment = redisUtil.get(key, Payment.class);
System.out.println("payment1 = " + payment);
final JSONObject mpWx = settingService.getBySettingKey("mp-weixin");
// final JSONObject payment = settingService.getBySettingKey("payment");
// 计算金额
BigDecimal decimal = order.getTotalPrice();
final BigDecimal multiply = decimal.multiply(new BigDecimal(100));
// 将 BigDecimal 转换为 Integer
Integer money = multiply.intValue();
final String appId = mpWx.getString("appId");
final String mchId = payment.getMchId();
final String openid = order.getOpenid(); // openid
final String notifyUrl = config.getServerUrl() + "/love/user-plan-log/wx-pay/notify/" + order.getTenantId(); // 异步通知地址
final String privateKey = uploadPath.concat("file").concat(payment.getApiclientKey()); // 秘钥证书
final String apiclientCert = uploadPath.concat("file").concat(payment.getApiclientCert());
final String merchantSerialNumber = payment.getMerchantSerialNumber(); // 证书序列号
final String apiV3key = payment.getApiKey();
System.out.println("privateKey = " + privateKey);
System.out.println("apiclientCert = " + apiclientCert);
System.out.println("merchantSerialNumber = " + merchantSerialNumber);
System.out.println("apiV3key = " + apiV3key);
System.out.println("mchId = " + mchId);
System.out.println("appId = " + appId);
Config config =
new RSAConfig.Builder()
.merchantId(mchId)
.privateKeyFromPath(privateKey)
.merchantSerialNumber(merchantSerialNumber)
.wechatPayCertificatesFromPath(apiclientCert)
.build();
// 构建service
JsapiServiceExtension service = new JsapiServiceExtension.Builder().config(config).build();
// 跟之前下单示例一样,填充预下单参数
PrepayRequest request = new PrepayRequest();
Amount amount = new Amount();
amount.setTotal(money);
amount.setCurrency("CNY");
request.setAmount(amount);
request.setAppid(appId);
request.setMchid(mchId);
OrderInfo desc = order.getOrderInfoList().get(0);
request.setDescription(desc.getSiteName().concat(desc.getFieldName()).concat(desc.getDateTime()));
request.setNotifyUrl(notifyUrl);
request.setOutTradeNo(order.getOrderNo());
request.setAttach(order.getTenantId().toString());
final Payer payer = new Payer();
payer.setOpenid(openid);
request.setPayer(payer);
System.out.println("request2 = " + request);
PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
System.out.println("response = " + response);
orderInfo.put("provider", "wxpay");
orderInfo.put("timeStamp", response.getTimeStamp());
orderInfo.put("nonceStr", response.getNonceStr());
orderInfo.put("package", response.getPackageVal());
orderInfo.put("signType", "RSA");
orderInfo.put("paySign", response.getPaySign());
return orderInfo;
}
@Override
public Order getByOutTradeNo(String outTradeNo) {
OrderParam param = new OrderParam();
param.setOrderNo(outTradeNo);
return param.getOne(baseMapper.getByOutTradeNo(param));
}
@Override
public void updateByOutTradeNo(Order order) {
baseMapper.updateByOutTradeNo(order);
}
}

View File

@@ -0,0 +1,47 @@
package com.gxwebsoft.common.system.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.common.system.mapper.PaymentMapper;
import com.gxwebsoft.common.system.service.PaymentService;
import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.param.PaymentParam;
import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 支付方式Service实现
*
* @author 科技小王子
* @since 2024-05-11 12:39:11
*/
@Service
public class PaymentServiceImpl extends ServiceImpl<PaymentMapper, Payment> implements PaymentService {
@Override
public PageResult<Payment> pageRel(PaymentParam param) {
PageParam<Payment, PaymentParam> page = new PageParam<>(param);
//page.setDefaultOrder("create_time desc");
List<Payment> list = baseMapper.selectPageRel(page, param);
return new PageResult<>(list, page.getTotal());
}
@Override
public List<Payment> listRel(PaymentParam param) {
List<Payment> list = baseMapper.selectListRel(param);
// 排序
PageParam<Payment, PaymentParam> page = new PageParam<>();
//page.setDefaultOrder("create_time desc");
return page.sortRecords(list);
}
@Override
public Payment getByIdRel(Integer id) {
PaymentParam param = new PaymentParam();
param.setId(id);
return param.getOne(baseMapper.selectListRel(param));
}
}