refactor(mcwl): 重构资源模块并移除支付相关代码- 移除了 AliPayIntegration 和 OrderTradeController 类
- 更新了 ModelImageController 接口,使用新的 ModelImagePageRes 类作为参数 - 新增了 ModelImagePageRes 类,用于图片分页请求 - 更新了 ModelImageService接口和实现类,支持新的分页查询参数feature/my-invitation
parent
af200b9274
commit
511bd96d84
|
@ -1,42 +0,0 @@
|
||||||
package com.mcwl.web.controller.pay;
|
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import com.alipay.easysdk.factory.Factory;
|
|
||||||
import com.alipay.easysdk.kernel.Config;
|
|
||||||
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
|
|
||||||
import com.mcwl.pay.domain.OrderTrade;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付宝支付
|
|
||||||
|
|
||||||
*/
|
|
||||||
@Component
|
|
||||||
public class AliPayIntegration {
|
|
||||||
@Autowired
|
|
||||||
private Config config;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 调用支付宝预下订单接口
|
|
||||||
*
|
|
||||||
* @param tradeEntity 订单实体
|
|
||||||
* @return 二维码url
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public String pay(OrderTrade tradeEntity) throws Exception {
|
|
||||||
Factory.setOptions(config);
|
|
||||||
//调用支付宝的接口
|
|
||||||
AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace()
|
|
||||||
.preCreate(tradeEntity.getUserName(),
|
|
||||||
tradeEntity.getCode(),
|
|
||||||
tradeEntity.getPaymentAmount().toString());
|
|
||||||
// AlipayTradePrecreateResponse payResponse = Factory.Payment.FaceToFace().preCreate("订单主题:Mac笔记本", "LS123qwe123", "19999");
|
|
||||||
//参照官方文档响应示例,解析返回结果
|
|
||||||
String httpBodyStr = payResponse.getHttpBody();
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(httpBodyStr);
|
|
||||||
return jsonObject.getJSONObject("alipay_trade_precreate_response").get("qr_code").toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,179 +0,0 @@
|
||||||
package com.mcwl.web.controller.pay;
|
|
||||||
|
|
||||||
import cn.hutool.extra.qrcode.QrCodeUtil;
|
|
||||||
import com.alipay.easysdk.factory.Factory;
|
|
||||||
import com.alipay.easysdk.payment.common.models.AlipayTradeQueryResponse;
|
|
||||||
import com.mcwl.common.JSONUtils;
|
|
||||||
import com.mcwl.common.annotation.Anonymous;
|
|
||||||
import com.mcwl.common.core.controller.BaseController;
|
|
||||||
import com.mcwl.common.core.domain.AjaxResult;
|
|
||||||
import com.mcwl.common.core.page.TableDataInfo;
|
|
||||||
import com.mcwl.common.domain.IdsParam;
|
|
||||||
import com.mcwl.common.utils.SecurityUtils;
|
|
||||||
import com.mcwl.pay.domain.OrderTrade;
|
|
||||||
import com.mcwl.pay.service.OrderTradeService;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
import com.alipay.easysdk.kernel.Config;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.validation.annotation.Validated;
|
|
||||||
import org.springframework.web.bind.annotation.*;
|
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Author:ChenYan
|
|
||||||
* @Project:McWl
|
|
||||||
* @Package:com.mcwl.web.controller.pay
|
|
||||||
* @Filename:OrderTradeController
|
|
||||||
* @Description 支付模块
|
|
||||||
* @Date:2025/1/3 14:46
|
|
||||||
*/
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@RestController
|
|
||||||
@RequestMapping("/web/pay")
|
|
||||||
@Validated
|
|
||||||
public class OrderTradeController extends BaseController {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private Config config;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private OrderTradeService orderTradeService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private AliPayIntegration aliPayIntegration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询列表
|
|
||||||
*/
|
|
||||||
@GetMapping("/list")
|
|
||||||
public TableDataInfo list(OrderTrade orderTrade)
|
|
||||||
{
|
|
||||||
startPage();
|
|
||||||
List<OrderTrade> list = orderTradeService.selectMallProductList(orderTrade);
|
|
||||||
return getDataTable(list);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 新增
|
|
||||||
*/
|
|
||||||
@PostMapping("/add")
|
|
||||||
public AjaxResult add(@RequestBody OrderTrade orderTrade)
|
|
||||||
{
|
|
||||||
// 获取当前用户
|
|
||||||
Long userId = SecurityUtils.getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
return AjaxResult.warn("用户未登录");
|
|
||||||
}
|
|
||||||
orderTrade.setUserId(userId);
|
|
||||||
orderTrade.setCreateBy(getUsername());
|
|
||||||
return toAjax(orderTradeService.insertMallProduct(orderTrade));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 修改
|
|
||||||
*/
|
|
||||||
@PostMapping("/upda")
|
|
||||||
public AjaxResult upda(@RequestBody OrderTrade orderTrade)
|
|
||||||
{
|
|
||||||
// 获取当前用户
|
|
||||||
Long userId = SecurityUtils.getUserId();
|
|
||||||
if (userId == null) {
|
|
||||||
return AjaxResult.warn("用户未登录");
|
|
||||||
}
|
|
||||||
orderTrade.setUserId(userId);
|
|
||||||
orderTrade.setUpdateBy(getUsername());
|
|
||||||
return toAjax(orderTradeService.updateMallProduct(orderTrade));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除
|
|
||||||
*/
|
|
||||||
@PostMapping
|
|
||||||
public AjaxResult remove(@RequestBody IdsParam ids)
|
|
||||||
{
|
|
||||||
orderTradeService.deleteMallProductByIds(ids);
|
|
||||||
return success();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付接口
|
|
||||||
*
|
|
||||||
* @param tradeEntity 订单实体
|
|
||||||
* @param response 响应
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Anonymous
|
|
||||||
@PostMapping("/doPay")
|
|
||||||
public void doPay(@RequestBody OrderTrade tradeEntity, HttpServletResponse response) throws Exception {
|
|
||||||
String qrUrl = aliPayIntegration.pay(tradeEntity);
|
|
||||||
QrCodeUtil.generate(qrUrl, 300, 300, "png", response.getOutputStream());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("/queryTradeStatus")
|
|
||||||
public Object queryTradeStatus(@RequestParam String outTradeNo) throws Exception {
|
|
||||||
Factory.setOptions(config);
|
|
||||||
AlipayTradeQueryResponse query = Factory.Payment.Common().query(outTradeNo);
|
|
||||||
Map<String, Object> map = JSONUtils.jsonToMap(query.getHttpBody());
|
|
||||||
|
|
||||||
// 返回交易结果, 是否交易成功需要根据该对象中的 trade_status 来确定
|
|
||||||
// trade_status 的枚举值如下, 请见 https://opendocs.alipay.com/apis/api_1/alipay.trade.query
|
|
||||||
// WAIT_BUYER_PAY(交易创建,等待买家付款)
|
|
||||||
// TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)
|
|
||||||
// TRADE_SUCCESS(交易支付成功)
|
|
||||||
// TRADE_FINISHED(交易结束,不可退款)
|
|
||||||
// 当 trade_status 等于 TRADE_SUCCESS 或 TRADE_FINISHED 时, 表示支付成功
|
|
||||||
return map.get("alipay_trade_query_response");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付回调接口
|
|
||||||
* @param request
|
|
||||||
* @return
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
@Anonymous
|
|
||||||
@PostMapping("/notify") // 注意这里必须是POST接口
|
|
||||||
public String payNotify(HttpServletRequest request) throws Exception {
|
|
||||||
|
|
||||||
log.info("已经进入回调接口");
|
|
||||||
if (request.getParameter("trade_status").equals("TRADE_SUCCESS")) {
|
|
||||||
System.out.println("=========支付宝异步回调========");
|
|
||||||
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
Map<String, String[]> requestParams = request.getParameterMap();
|
|
||||||
for (String name : requestParams.keySet()) {
|
|
||||||
params.put(name, request.getParameter(name));
|
|
||||||
// System.out.println(name + " = " + request.getParameter(name));
|
|
||||||
}
|
|
||||||
|
|
||||||
String tradeNo = params.get("out_trade_no");
|
|
||||||
String gmtPayment = params.get("gmt_payment");
|
|
||||||
String alipayTradeNo = params.get("trade_no");
|
|
||||||
// 支付宝验签
|
|
||||||
if (Factory.Payment.Common().verifyNotify(params)) {
|
|
||||||
// 验签通过
|
|
||||||
System.out.println("交易名称: " + params.get("subject"));
|
|
||||||
System.out.println("交易状态: " + params.get("trade_status"));
|
|
||||||
System.out.println("支付宝交易凭证号: " + params.get("trade_no"));
|
|
||||||
System.out.println("商户订单号: " + params.get("out_trade_no"));
|
|
||||||
System.out.println("交易金额: " + params.get("total_amount"));
|
|
||||||
System.out.println("买家在支付宝唯一id: " + params.get("buyer_id"));
|
|
||||||
System.out.println("买家付款时间: " + params.get("gmt_payment"));
|
|
||||||
System.out.println("买家付款金额: " + params.get("buyer_pay_amount"));
|
|
||||||
// 更新订单状态
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "success";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -18,6 +18,7 @@ import com.mcwl.resource.domain.ModelImageComment;
|
||||||
import com.mcwl.resource.domain.ModelImageCommentLike;
|
import com.mcwl.resource.domain.ModelImageCommentLike;
|
||||||
import com.mcwl.resource.domain.ModelImageLike;
|
import com.mcwl.resource.domain.ModelImageLike;
|
||||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||||
|
import com.mcwl.resource.domain.dto.ModelImagePageRes;
|
||||||
import com.mcwl.resource.domain.dto.ModelImageRes;
|
import com.mcwl.resource.domain.dto.ModelImageRes;
|
||||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||||
import com.mcwl.resource.domain.vo.ModelImageVo;
|
import com.mcwl.resource.domain.vo.ModelImageVo;
|
||||||
|
@ -58,9 +59,9 @@ public class ModelImageController {
|
||||||
* 图片列表
|
* 图片列表
|
||||||
*/
|
*/
|
||||||
@PostMapping("/list")
|
@PostMapping("/list")
|
||||||
public TableDataInfo list(@RequestBody PageDomain pageDomain) {
|
public TableDataInfo list(@RequestBody ModelImagePageRes imagePageRes) {
|
||||||
|
|
||||||
return modelImageService.listByPage(pageDomain);
|
return modelImageService.listByPage(imagePageRes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.mcwl.resource.domain.dto;
|
||||||
|
|
||||||
|
import com.mcwl.common.core.page.PageDomain;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图片分页请求对象
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public class ModelImagePageRes extends PageDomain {
|
||||||
|
/**
|
||||||
|
* 用户id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 状态
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 开始时间
|
||||||
|
*/
|
||||||
|
private Date startTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 结束时间
|
||||||
|
*/
|
||||||
|
private Date endTime;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,7 @@ import com.mcwl.common.core.page.TableDataInfo;
|
||||||
import com.mcwl.resource.domain.ModelImage;
|
import com.mcwl.resource.domain.ModelImage;
|
||||||
import com.mcwl.resource.domain.ModelProduct;
|
import com.mcwl.resource.domain.ModelProduct;
|
||||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||||
|
import com.mcwl.resource.domain.dto.ModelImagePageRes;
|
||||||
import com.mcwl.resource.domain.dto.ModelImageRes;
|
import com.mcwl.resource.domain.dto.ModelImageRes;
|
||||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||||
|
@ -43,8 +44,8 @@ public interface ModelImageService extends IService<ModelImage> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
* @param pageDomain 分页参数
|
* @param imagePageRes 分页参数
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
TableDataInfo listByPage(PageDomain pageDomain);
|
TableDataInfo listByPage(ModelImagePageRes imagePageRes);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.mcwl.common.utils.StringUtils;
|
||||||
import com.mcwl.resource.domain.ModelImage;
|
import com.mcwl.resource.domain.ModelImage;
|
||||||
import com.mcwl.resource.domain.ModelImageComment;
|
import com.mcwl.resource.domain.ModelImageComment;
|
||||||
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
import com.mcwl.resource.domain.dto.ModelImageCommentRes;
|
||||||
|
import com.mcwl.resource.domain.dto.ModelImagePageRes;
|
||||||
import com.mcwl.resource.domain.dto.ModelImageRes;
|
import com.mcwl.resource.domain.dto.ModelImageRes;
|
||||||
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
import com.mcwl.resource.domain.vo.ModelImageCommentVo;
|
||||||
import com.mcwl.resource.domain.vo.ModelImageVo;
|
import com.mcwl.resource.domain.vo.ModelImageVo;
|
||||||
|
@ -92,6 +93,7 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取评论
|
* 获取评论
|
||||||
|
*
|
||||||
* @param imageId 图片id
|
* @param imageId 图片id
|
||||||
* @return 评论区
|
* @return 评论区
|
||||||
*/
|
*/
|
||||||
|
@ -116,25 +118,31 @@ public class ModelImageServiceImpl extends ServiceImpl<ModelImageMapper, ModelIm
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询
|
* 分页查询
|
||||||
* @param pageDomain 分页参数
|
*
|
||||||
|
* @param imagePageRes 分页参数
|
||||||
* @return 分页数据
|
* @return 分页数据
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public TableDataInfo listByPage(PageDomain pageDomain) {
|
public TableDataInfo listByPage(ModelImagePageRes imagePageRes) {
|
||||||
|
|
||||||
Page<ModelImage> page = new Page<>(pageDomain.getPageNum(), pageDomain.getPageSize());
|
Page<ModelImage> page = new Page<>(imagePageRes.getPageNum(), imagePageRes.getPageSize());
|
||||||
if (StringUtils.isEmpty(pageDomain.getOrderByColumn())) {
|
if (StringUtils.isEmpty(imagePageRes.getOrderByColumn())) {
|
||||||
pageDomain.setOrderByColumn("create_time");
|
imagePageRes.setOrderByColumn("create_time");
|
||||||
}
|
}
|
||||||
// 设置排序
|
// 设置排序
|
||||||
boolean isAsc = Objects.equals(pageDomain.getIsAsc(), "asc");
|
boolean isAsc = Objects.equals(imagePageRes.getIsAsc(), "asc");
|
||||||
OrderItem orderItem = new OrderItem(pageDomain.getOrderByColumn(), isAsc);
|
OrderItem orderItem = new OrderItem(imagePageRes.getOrderByColumn(), isAsc);
|
||||||
page.addOrder(orderItem);
|
page.addOrder(orderItem);
|
||||||
modelImageMapper.selectPage(page, null);
|
|
||||||
|
LambdaQueryWrapper<ModelImage> lqw = new LambdaQueryWrapper<>();
|
||||||
|
lqw.eq(imagePageRes.getStatus() != null, ModelImage::getStatus, imagePageRes.getStatus())
|
||||||
|
.eq(imagePageRes.getUserId() != null, ModelImage::getUserId, imagePageRes.getUserId())
|
||||||
|
.ge(imagePageRes.getStartTime() != null, ModelImage::getCreateTime, imagePageRes.getStartTime())
|
||||||
|
.le(imagePageRes.getEndTime() != null, ModelImage::getCreateTime, imagePageRes.getEndTime());
|
||||||
|
|
||||||
|
modelImageMapper.selectPage(page, lqw);
|
||||||
// 获取分页数据
|
// 获取分页数据
|
||||||
List<ModelImage> modelImageList = page.getRecords();
|
List<ModelImage> modelImageList = page.getRecords();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue