支付
This commit is contained in:
parent
0a17381dc2
commit
80dc442528
@ -0,0 +1,125 @@
|
||||
package com.pixelai.api.pa.controller;
|
||||
|
||||
import com.aliyun.core.utils.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.base.annotation.SysLog;
|
||||
import com.base.helper.BaseController;
|
||||
import com.base.helper.Result;
|
||||
import com.pixelai.api.domain.apy.OrderPayAppService;
|
||||
import com.pixelai.api.pa.entity.PaOrder;
|
||||
import com.pixelai.api.pa.service.PaOrderService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.BindingResult;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.validation.Valid;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2025-01-19
|
||||
*/
|
||||
@Api(tags = "pa订单管理")
|
||||
@RestController
|
||||
@RequestMapping("/paOrder")
|
||||
public class PaOrderController extends BaseController {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(PaOrderController.class);
|
||||
@Autowired
|
||||
private PaOrderService entityService;
|
||||
@Autowired
|
||||
private OrderPayAppService payAppService;
|
||||
|
||||
@SysLog(action = "findByPage", value = "分页查询订单")
|
||||
@ApiOperation(value = "分页查询订单", notes = "分页查询订单")
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ApiImplicitParams({@ApiImplicitParam(name = "size", value = "分页大小", paramType = "query"),
|
||||
@ApiImplicitParam(name = "current", value = "当前页面:从1开始", paramType = "query")})
|
||||
public Result<IPage<PaOrder>> findByPage(final PaOrder example, final Page page) {
|
||||
IPage<PaOrder> records = entityService.page(example,page);
|
||||
return new Result(true, records);
|
||||
}
|
||||
|
||||
@SysLog(action = "one", value = "查询单个订单")
|
||||
@ApiOperation(value = "查询单个订单")
|
||||
@RequestMapping(value = "{id}", method = {RequestMethod.GET})
|
||||
@ApiImplicitParam(name = "id", value = "订单ID", required = true, paramType = "path")
|
||||
public Result one(@PathVariable final Integer id) {
|
||||
try {
|
||||
PaOrder entity = entityService.getById(id);
|
||||
return new Result(true, entity);
|
||||
} catch (Exception e) {
|
||||
LOG.error("查询单个订单失败", e);
|
||||
return new Result(false, new PaOrder());
|
||||
}
|
||||
}
|
||||
|
||||
@SysLog(action = "add", value = "添加订单")
|
||||
@ApiOperation(value = "添加订单")
|
||||
@RequestMapping(method = {RequestMethod.POST})
|
||||
public Result add(@Valid @RequestBody final PaOrder entity, final BindingResult result) {
|
||||
try {
|
||||
if (result.hasErrors()) {
|
||||
Map<String, String> map = this.getErrors(result);
|
||||
String errorMsg = map.entrySet().iterator().next().getValue();
|
||||
return new Result(false, "保存订单失败", errorMsg, map);
|
||||
} else {
|
||||
entityService.save(entity);
|
||||
return new Result(true, "成功保存订单", null);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("添加订单失败", e);
|
||||
return new Result(false, "保存订单失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ApiOperation(value = "全部订单")
|
||||
@RequestMapping(value = "all", method = RequestMethod.GET)
|
||||
public Result<List<PaOrder>> all(PaOrder example) {
|
||||
List<PaOrder> entitys = entityService.list(example);
|
||||
if (null != entitys) {
|
||||
return new Result<>(true, entitys);
|
||||
}
|
||||
return new Result<>(true, Collections.emptyList());
|
||||
}
|
||||
|
||||
@ApiOperation(value = "h5支付")
|
||||
@RequestMapping(value = "h5Pay", method = RequestMethod.GET)
|
||||
public Result h5Pay(PaOrder order,HttpServletRequest request) {
|
||||
// 调用业务逻辑获取支付 URL
|
||||
String h5Url = payAppService.h5Pay(order,request);
|
||||
// 如果没有获取到支付链接,返回失败的结果
|
||||
if (StringUtils.isBlank(h5Url)) {
|
||||
return new Result<>(false, "支付失败");
|
||||
}
|
||||
|
||||
// 返回成功的结果
|
||||
return new Result<>(true, h5Url);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "h5回调")
|
||||
@RequestMapping(value = "payNotify", method = RequestMethod.GET)
|
||||
public void payNotify(HttpServletRequest request) {
|
||||
try {
|
||||
payAppService.payNotify(request);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
16
src/main/java/com/pixelai/api/pa/dao/PaOrderMapper.java
Normal file
16
src/main/java/com/pixelai/api/pa/dao/PaOrderMapper.java
Normal file
@ -0,0 +1,16 @@
|
||||
package com.pixelai.api.pa.dao;
|
||||
|
||||
import com.pixelai.api.pa.entity.PaOrder;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Mapper 接口
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2025-01-19
|
||||
*/
|
||||
public interface PaOrderMapper extends BaseMapper<PaOrder> {
|
||||
|
||||
}
|
69
src/main/java/com/pixelai/api/pa/entity/PaOrder.java
Normal file
69
src/main/java/com/pixelai/api/pa/entity/PaOrder.java
Normal file
@ -0,0 +1,69 @@
|
||||
package com.pixelai.api.pa.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
import com.pixelai.api.pa.entity.enums.PayState;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
*
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2025-01-19
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Accessors(chain = true)
|
||||
@ApiModel(value="PaOrder", description="")
|
||||
public class PaOrder implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty(value = "用户 ID")
|
||||
private Integer memberId;
|
||||
|
||||
@ApiModelProperty(value = "订单号")
|
||||
private String orderNum;
|
||||
|
||||
@ApiModelProperty(value = "支付人账号")
|
||||
private String memberAccount;
|
||||
|
||||
@ApiModelProperty(value = "商家账号")
|
||||
private String merchantAccount;
|
||||
|
||||
@ApiModelProperty(value = "支付金额")
|
||||
private BigDecimal amount;
|
||||
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "支付用途")
|
||||
private String orderType;
|
||||
|
||||
@ApiModelProperty(value = "支付状态")
|
||||
private PayState payStatus;
|
||||
|
||||
@ApiModelProperty(value = "支付结果")
|
||||
private String result;
|
||||
|
||||
@ApiModelProperty(value = "状态(有效:t 无效:f)")
|
||||
private String state;
|
||||
|
||||
@ApiModelProperty(value = "1-5, 2-10, 3-20, 4-30, 5-50, 6-100")
|
||||
private String buyType;
|
||||
}
|
41
src/main/java/com/pixelai/api/pa/service/PaOrderService.java
Normal file
41
src/main/java/com/pixelai/api/pa/service/PaOrderService.java
Normal file
@ -0,0 +1,41 @@
|
||||
package com.pixelai.api.pa.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.pixelai.api.pa.entity.PaOrder;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务类
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2025-01-19
|
||||
*/
|
||||
public interface PaOrderService extends IService<PaOrder> {
|
||||
|
||||
/**
|
||||
* 条件查询
|
||||
* @param example
|
||||
* @return
|
||||
*/
|
||||
List<PaOrder> list(PaOrder example);
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
* @param example
|
||||
* @param page
|
||||
* @return
|
||||
*/
|
||||
IPage<PaOrder> page(PaOrder example, IPage page);
|
||||
|
||||
/**
|
||||
* 订单号查询订单
|
||||
* @param outTradeNo
|
||||
* @return
|
||||
*/
|
||||
PaOrder getOrderByTradeNo(String outTradeNo);
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
package com.pixelai.api.pa.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.pixelai.api.pa.dao.PaOrderMapper;
|
||||
import com.pixelai.api.pa.entity.PaOrder;
|
||||
import com.pixelai.api.pa.service.PaOrderService;
|
||||
import com.pixelai.config.WeChatConfig;
|
||||
import com.pixelai.utils.WeChatUtil;
|
||||
import com.wechat.pay.java.core.exception.MalformedMessageException;
|
||||
import com.wechat.pay.java.service.payments.h5.H5Service;
|
||||
import com.wechat.pay.java.service.payments.h5.model.*;
|
||||
import eu.bitwalker.useragentutils.UserAgent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.util.List;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
* </p>
|
||||
*
|
||||
* @author gjj
|
||||
* @since 2025-01-19
|
||||
*/
|
||||
@Service
|
||||
public class PaOrderServiceImpl extends ServiceImpl<PaOrderMapper, PaOrder> implements PaOrderService {
|
||||
|
||||
|
||||
@Override
|
||||
public List<PaOrder> list(PaOrder example) {
|
||||
return this.list(buildWrapper(example));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<PaOrder> page(PaOrder example, IPage page) {
|
||||
return this.page(page,buildWrapper(example));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PaOrder getOrderByTradeNo(String outTradeNo) {
|
||||
QueryWrapper<PaOrder> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("out_trade_no", outTradeNo);
|
||||
queryWrapper.eq("state", "t");
|
||||
return this.getOne(queryWrapper);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 构建查询
|
||||
*
|
||||
* @param example
|
||||
* @return
|
||||
*/
|
||||
private QueryWrapper<PaOrder> buildWrapper(PaOrder example) {
|
||||
QueryWrapper<PaOrder> wrapper = new QueryWrapper<>();
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
}
|
20
src/main/resources/mapper/PaOrderMapper.xml
Normal file
20
src/main/resources/mapper/PaOrderMapper.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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.pixelai.api.pa.dao.PaOrderMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="BaseResultMap" type="com.pixelai.api.pa.entity.PaOrder">
|
||||
<id column="id" property="id" />
|
||||
<result column="member_id" property="memberId" />
|
||||
<result column="order_num" property="orderNum" />
|
||||
<result column="member_account" property="memberAccount" />
|
||||
<result column="merchant_account" property="merchant account" />
|
||||
<result column="amount" property="amount" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="order_type" property="orderType" />
|
||||
<result column="pay_status" property="payStatus" />
|
||||
<result column="result" property="result" />
|
||||
<result column="state" property="state" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
Loading…
Reference in New Issue
Block a user