feat:商品 订单 支付模块
parent
dcce7b4b29
commit
6f45a85b95
|
@ -16,7 +16,11 @@
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alipay.sdk</groupId>
|
||||||
|
<artifactId>alipay-easysdk</artifactId>
|
||||||
|
<version>2.2.0</version>
|
||||||
|
</dependency>
|
||||||
<!-- spring-boot-devtools -->
|
<!-- spring-boot-devtools -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
@ -73,6 +77,12 @@
|
||||||
<artifactId>mcwl-common</artifactId>
|
<artifactId>mcwl-common</artifactId>
|
||||||
<version>3.8.8</version>
|
<version>3.8.8</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- 支付模块-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-pay</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</dependency>
|
||||||
<!-- 资源中心模块-->
|
<!-- 资源中心模块-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.mcwl</groupId>
|
<groupId>com.mcwl</groupId>
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package com.mcwl.web.controller.pay;
|
||||||
|
|
||||||
|
import com.alipay.easysdk.payment.facetoface.models.AlipayTradePrecreateResponse;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alipay.easysdk.factory.Factory;
|
||||||
|
import com.mcwl.pay.domain.OrderTrade;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import com.alipay.easysdk.kernel.Config;
|
||||||
|
/**
|
||||||
|
* 支付宝支付
|
||||||
|
|
||||||
|
*/
|
||||||
|
@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.getCode(),
|
||||||
|
tradeEntity.getPaymentAmount().toString());
|
||||||
|
//参照官方文档响应示例,解析返回结果
|
||||||
|
String httpBodyStr = payResponse.getHttpBody();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(httpBodyStr);
|
||||||
|
return jsonObject.getJSONObject("alipay_trade_precreate_response").get("qr_code").toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
package com.mcwl.web.controller.pay;
|
||||||
|
|
||||||
|
import cn.hutool.extra.qrcode.QrCodeUtil;
|
||||||
|
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.interfaces.NoLogin;
|
||||||
|
import com.mcwl.common.utils.SecurityUtils;
|
||||||
|
import com.mcwl.pay.domain.OrderTrade;
|
||||||
|
import com.mcwl.pay.service.OrderTradeService;
|
||||||
|
import com.mcwl.resource.domain.MallProduct;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.util.CollectionUtils;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.mcwl.common.utils.PageUtils.startPage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.web.controller.pay
|
||||||
|
* @Filename:OrderTradeController
|
||||||
|
* @Description 支付模块
|
||||||
|
* @Date:2025/1/3 14:46
|
||||||
|
*/
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/web/pay")
|
||||||
|
@Validated
|
||||||
|
public class OrderTradeController extends BaseController {
|
||||||
|
|
||||||
|
@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
|
||||||
|
*/
|
||||||
|
@NoLogin
|
||||||
|
@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());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
package com.mcwl.web.controller.rabbitmq.config;
|
||||||
|
|
||||||
|
import com.alipay.easysdk.kernel.Config;
|
||||||
|
import com.mcwl.common.config.BusinessConfig;
|
||||||
|
import com.mcwl.common.domain.AliPayProperties;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.common.config
|
||||||
|
* @Filename:AliPayConfig
|
||||||
|
* @Description 支付宝配置
|
||||||
|
* @Date:2025/1/3 18:45
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class AliPayConfig {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private BusinessConfig businessConfig;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public Config config() {
|
||||||
|
AliPayProperties aliPayConfig = businessConfig.getAliPayConfig();
|
||||||
|
Config config = new Config();
|
||||||
|
config.protocol = aliPayConfig.getProtocol();
|
||||||
|
config.gatewayHost = aliPayConfig.getGatewayHost();
|
||||||
|
config.signType = aliPayConfig.getSignType();
|
||||||
|
config.appId = aliPayConfig.getAppId();
|
||||||
|
config.merchantPrivateKey = aliPayConfig.getPrivateKey();
|
||||||
|
config.alipayPublicKey = aliPayConfig.getPublicKey();
|
||||||
|
config.notifyUrl = aliPayConfig.getNotifyUrl();
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,9 +6,11 @@ import com.mcwl.common.core.domain.AjaxResult;
|
||||||
import com.mcwl.common.core.page.TableDataInfo;
|
import com.mcwl.common.core.page.TableDataInfo;
|
||||||
import com.mcwl.common.domain.IdsParam;
|
import com.mcwl.common.domain.IdsParam;
|
||||||
import com.mcwl.resource.domain.MallProduct;
|
import com.mcwl.resource.domain.MallProduct;
|
||||||
import com.mcwl.resource.service.MallProductService;
|
|
||||||
import com.mcwl.resource.domain.vo.MallProductVo;
|
import com.mcwl.resource.domain.vo.MallProductVo;
|
||||||
|
import com.mcwl.resource.service.MallProductService;
|
||||||
|
import com.mcwl.web.controller.common.OssUtil;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -35,6 +37,51 @@ public class MallProductController extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* 图片
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/file")
|
||||||
|
public AjaxResult Malifile(@RequestParam MultipartFile file){
|
||||||
|
|
||||||
|
String s = OssUtil.uploadMultipartFile(file);
|
||||||
|
return AjaxResult.success(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* zip
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/zipUrlFile")
|
||||||
|
public AjaxResult zipUrlFile(@RequestParam MultipartFile file){
|
||||||
|
String s = OssUtil.uploadMultipartFile(file);
|
||||||
|
return AjaxResult.success(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* 下载zip
|
||||||
|
* @param file
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@PostMapping("/zipUrl")
|
||||||
|
public AjaxResult zipUrl(@RequestParam MultipartFile file){
|
||||||
|
String s = OssUtil.uploadMultipartFile(file);
|
||||||
|
return AjaxResult.success(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询商品列表
|
* 查询商品列表
|
||||||
*/
|
*/
|
||||||
|
@ -50,12 +97,14 @@ public class MallProductController extends BaseController {
|
||||||
/**
|
/**
|
||||||
* 获取详细信息
|
* 获取详细信息
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/{jobId}")
|
@GetMapping(value = "/{id}")
|
||||||
public AjaxResult getInfo(@PathVariable("jobId") Long jobId)
|
public AjaxResult getInfo(@PathVariable("id") Long jobId)
|
||||||
{
|
{
|
||||||
return success(mallProductRuleInfoService.selectMallProductById(jobId));
|
return success(mallProductRuleInfoService.selectMallProductById(jobId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增
|
* 新增
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.mcwl.web.core.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跨域配置
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
|
||||||
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||||
|
corsConfiguration.addAllowedOrigin("*");
|
||||||
|
corsConfiguration.addAllowedHeader("*");
|
||||||
|
corsConfiguration.addAllowedMethod("*");
|
||||||
|
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
|
||||||
|
return new CorsFilter(urlBasedCorsConfigurationSource);
|
||||||
|
}
|
||||||
|
}
|
|
@ -172,3 +172,15 @@ aliyun:
|
||||||
accessKeyId: LTAI5tSHZZ8wHJRP8X4r9TXT
|
accessKeyId: LTAI5tSHZZ8wHJRP8X4r9TXT
|
||||||
accessKeySecret: F82IVNx0IGJ3AnP6gSIfcyql1HCXIH
|
accessKeySecret: F82IVNx0IGJ3AnP6gSIfcyql1HCXIH
|
||||||
policy : https://ybl2112.oss-cn-beijing.aliyuncs.com/
|
policy : https://ybl2112.oss-cn-beijing.aliyuncs.com/
|
||||||
|
|
||||||
|
|
||||||
|
mall:
|
||||||
|
mgt:
|
||||||
|
aliPayConfig:
|
||||||
|
protocol: https
|
||||||
|
gatewayHost: openapi-sandbox.dl.alipaydev.com
|
||||||
|
signType: RSA2
|
||||||
|
appId: 9021000138607290
|
||||||
|
privateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCarcUREqQVHIYq4FBuqvcYxOxsuUI3gOphRXcN0k/hIUV7fcfO9ivui99pJihbou9MmC22FM7hzFMHHl4GvZQJuw/GgJlnh9T/SlfS9Awlr0nbzVtXYOd7Os1EM4Jry2PW3zkvaWMvO3DfcYU47bqN8aw+vVBhSVeVhq41zKkH9k8UPw6Ny4WmVUHje84ykf1uBR8AqPxEeDIYD79CGGLtGLECuHoeRsVpGrNmZxwmcen1Bwf8oWiM68+Ein3S/pV69ED6x74+/WDJO71IHUJN+1DclLVXWVGriUenUzTVrAhh8RHgtF5J+t4K24qrGpbsryXzuYJ/p872ieI2oFnLAgMBAAECggEAVfbziiyJAq6qplOqgAcGcz6mgzpm4cAFAvB/XTAgcudx3VMnZA+OlPIpxR+O2Hbydegxp3tjCzzqfA9VhHuCNfI/rzuzhkWIjCV+L+Cwi5UjAETeWe6iV+tzP089UbllEHtZJc91bz+i2JwXxW7h+pdw+iFu9dK0GYcTdRT8cE6FVkBtRikUMA/bAQ4f5umF/vv5yx2XsyfCJddyI2eKIOQQ3FZ27/EEvj+hkWFGj+hcTO0zchCzYudaUyhVanJfPOTMeQrh5J9d13HXQYH0qPT4NYrLSXPjl04zAhWyZQw50kFMpkYnog0i9E9XWESSBXilALd2hITmRAj8MPqi8QKBgQDmJ4P5Fa88nvBoPvpjkevcoOP7EzokvsJuw9QHwr7mKwY5/uTrDkHmgy0iIQJ7BQmYOTW+CcwAcaquQwZrdauxsto5sG+Vle62e9FIGxqsCqrzqRS3bKY2NHUS33Ep43lA9Uz07wYchFHs17e4rTidotaWd+ONhGu2zi44vXZOMwKBgQCsDHr1fDoKplRnJ9Na+YkkpG86lGvHW8R/69dn4ur89mCGhFyexLrSA1NggAMYT9pADg4G2jYvsPa+0ynV4rg8fmvfgpO9dvv3UoOGBxxdzaxNlIdb5LsuyQMN6wcWNSQFH9qDt9nyZ5BLCQXd/DJLMtgLSBpAYi+HZD1E4Zv+CQKBgQCaDZslr+ES56QtcvIwkazZigvvtCf4DoOglo2nADC9adEKItZhi7KKtAUS0huR8oZAkRKq+G3HYk4HxK9YYHQjRn8RnEqkSq51ER29cP8CZ0WUQPmv6Ra8M5KlplBd5Hf2BfuT+yYREnSv3piIEdJSmXufTfJPeHKM8yc3LYIxxwKBgFnjK1qWTLzDqdU7OXGObdh3EKXKZYUCrOcokKH2LE99aXDeNoW8wt52XllMiFFrZtuQfEOYPjcsfb21FWZpzVfNtQ5Ral7Si1HsCks769YWXq8pqo6YMjN/UdkzscAog2kp+0BWDchX00tgq3APEze2mKlMQmrg4XQbKueR964BAoGBAMA5mWyKVfphQ2SsOrYSF5hQ7PBaTT/gLLU2CWBcCXge4oO7dd3MIsd2+7cJG9uYPiSgJdLGqmVfet4pBXNd4znYjHunRr6BukTZzQSNujn0j2fr3SDN46vuqVjYsPF05hGWy3XH5NflrTHq7RO6qkqcqxdaSCRZO7a9G+ckzvx/
|
||||||
|
publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjehzFgsbjUfksMRBGsYGi/ycg5/SMP8jmGMbRWbiVmDVKO8GdVI0StLZvfLi8ozUPcGrJzQL3HaXx+b88JXQPJ2ftUiBvQnoAf+qzWKqsqXo40uuy6DZc+0LAGoxup2WyFp4YcIf+XFMJBSGmQaGSqYs3Lx49/aWI1uFTzBL4YF4X7ckXm6Cl2xr5gD1Gl1twbKIyeDnAZal2Eego4pLwFkcP6jZFaAY0V3YqTfhZLAl5NK+K4BCB2iQPOiK6Qr5XMRhnUVQVeZr5T9PmYf1GyncBIWgUaZlmGNq6Yup2trQW/mEqDqzeek4N3NuoORdZ2JBAnLdqAjQyRBrQAnkbQIDAQAA
|
||||||
|
notifyUrl: http://susan.net.cn/notify
|
||||||
|
|
|
@ -17,12 +17,18 @@
|
||||||
</description>
|
</description>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!--OSS-->
|
<!--OSS-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.aliyun.oss</groupId>
|
<groupId>com.aliyun.oss</groupId>
|
||||||
<artifactId>aliyun-sdk-oss</artifactId>
|
<artifactId>aliyun-sdk-oss</artifactId>
|
||||||
<version>3.17.4</version>
|
<version>3.17.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.zxing</groupId>
|
||||||
|
<artifactId>core</artifactId>
|
||||||
|
<version>3.4.1</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>commons-fileupload</groupId>
|
<groupId>commons-fileupload</groupId>
|
||||||
<artifactId>commons-fileupload</artifactId>
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
package com.mcwl.common.config;
|
||||||
|
|
||||||
|
import com.mcwl.common.config.properties.QuartzThreadPoolProperties;
|
||||||
|
import com.mcwl.common.domain.AliPayProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.common.config
|
||||||
|
* @Filename:BusinessConfig
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 18:46
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@ConfigurationProperties(prefix = "mall.mgt")
|
||||||
|
public class BusinessConfig {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 动态定时任务线程池配置
|
||||||
|
*/
|
||||||
|
private QuartzThreadPoolProperties QuartzThreadPoolConfig = new QuartzThreadPoolProperties();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 商品搜索index名称
|
||||||
|
*/
|
||||||
|
private String productEsIndexName = "product-es-index-v1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 支付宝支付相关配置
|
||||||
|
*/
|
||||||
|
private AliPayProperties aliPayConfig = new AliPayProperties();
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.mcwl.common.config.properties;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class QuartzThreadPoolProperties {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 核心线程数
|
||||||
|
*/
|
||||||
|
private int corePoolSize = 8;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 最大线程数
|
||||||
|
*/
|
||||||
|
private int maxPoolSize = 10;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 队列大小
|
||||||
|
*/
|
||||||
|
private int queueSize = 200;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 空闲线程回收时间,多少秒
|
||||||
|
*/
|
||||||
|
private int keepAliveSeconds = 30;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 线程前缀
|
||||||
|
*/
|
||||||
|
private String threadNamePrefix = "QuartzThread";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.mcwl.common.domain;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.common.domain
|
||||||
|
* @Filename:AliPayProperties
|
||||||
|
* @Description 支付宝支付配置
|
||||||
|
* @Date:2025/1/3 18:45
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class AliPayProperties {
|
||||||
|
|
||||||
|
private String protocol;
|
||||||
|
private String gatewayHost;
|
||||||
|
private String signType;
|
||||||
|
private String appId;
|
||||||
|
private String privateKey;
|
||||||
|
private String publicKey;
|
||||||
|
private String notifyUrl;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
package com.mcwl.common.interfaces;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 无需登录注解
|
||||||
|
*
|
||||||
|
* @author 陈妍
|
||||||
|
*/
|
||||||
|
@Target(ElementType.METHOD)
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface NoLogin {
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl</artifactId>
|
||||||
|
<version>3.8.8</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>mcwl-pay</artifactId>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>8</maven.compiler.source>
|
||||||
|
<maven.compiler.target>8</maven.compiler.target>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<description>
|
||||||
|
pay支付模块
|
||||||
|
</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- 通用工具-->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mcwl</groupId>
|
||||||
|
<artifactId>mcwl-common</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>${mybatis-plus.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
|
@ -0,0 +1,94 @@
|
||||||
|
package com.mcwl.pay.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.mcwl.common.core.domain.BaseEntity;
|
||||||
|
import com.mcwl.common.interfaces.MaxMoney;
|
||||||
|
import com.mcwl.common.interfaces.MinMoney;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.pay.domain
|
||||||
|
* @Filename:OrderTrade
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 14:15
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
@TableName("order_trade")
|
||||||
|
public class OrderTrade extends BaseEntity {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ID
|
||||||
|
*/
|
||||||
|
@TableId
|
||||||
|
private Long id;
|
||||||
|
/**
|
||||||
|
* 订单编码
|
||||||
|
*/
|
||||||
|
private String code;
|
||||||
|
/**
|
||||||
|
* 用户ID
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
/**
|
||||||
|
* 商品ID
|
||||||
|
*/
|
||||||
|
private Integer productId;
|
||||||
|
/**
|
||||||
|
* 商品名称
|
||||||
|
*/
|
||||||
|
private String productName;
|
||||||
|
/**
|
||||||
|
* 用户名称
|
||||||
|
*/
|
||||||
|
private String userName;
|
||||||
|
/**
|
||||||
|
* 支付方式第三方支付平台返回的交易流水号
|
||||||
|
*/
|
||||||
|
private String paymentMethod;
|
||||||
|
/**
|
||||||
|
* 支付方式
|
||||||
|
*/
|
||||||
|
private Integer transactionId;
|
||||||
|
/**
|
||||||
|
* 下单时间
|
||||||
|
*/
|
||||||
|
@JsonFormat(pattern = "yyyy-mm-dd")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-mm-dd")
|
||||||
|
private Date orderTime;
|
||||||
|
/**
|
||||||
|
* 订单状态 1:下单 2:支付 3:完成 4:取消
|
||||||
|
*/
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Integer orderStatus;
|
||||||
|
/**
|
||||||
|
* 支付状态 1:待支付 2:已支付 3:退款
|
||||||
|
*/
|
||||||
|
@NotNull(message = "状态不能为空")
|
||||||
|
private Integer payStatus;
|
||||||
|
/**
|
||||||
|
* 总金额
|
||||||
|
*/
|
||||||
|
@NotNull(message = "总金额不能为空")
|
||||||
|
@MinMoney(value = 0, message = "总金额不能小于0")
|
||||||
|
@MaxMoney(value = 100000, message = "总金额必须小于100000")
|
||||||
|
private Integer totalAmount;
|
||||||
|
/**
|
||||||
|
* 付款金额
|
||||||
|
*/
|
||||||
|
@NotNull(message = "付款金额不能为空")
|
||||||
|
@MinMoney(value = 0, message = "付款金额不能小于0")
|
||||||
|
@MaxMoney(value = 100000, message = "付款金额必须小于100000")
|
||||||
|
private Integer paymentAmount;
|
||||||
|
}
|
|
@ -0,0 +1,102 @@
|
||||||
|
package com.mcwl.pay.domain;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.pay.domain
|
||||||
|
* @Filename:PaymentResult
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 17:30
|
||||||
|
*/
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@Data
|
||||||
|
public class PaymentResult {
|
||||||
|
private boolean success;
|
||||||
|
private String message;
|
||||||
|
private String transactionId;
|
||||||
|
private String errorCode;
|
||||||
|
private BigDecimal amount;
|
||||||
|
private String currency;
|
||||||
|
private String paymentMethod;
|
||||||
|
private LocalDateTime timestamp;
|
||||||
|
private Map<String, Object> extraData;
|
||||||
|
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private final PaymentResult result = new PaymentResult();
|
||||||
|
|
||||||
|
public Builder setSuccess(boolean success) {
|
||||||
|
result.success = success;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setMessage(String message) {
|
||||||
|
result.message = message;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setTransactionId(String transactionId) {
|
||||||
|
result.transactionId = transactionId;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setErrorCode(String errorCode) {
|
||||||
|
result.errorCode = errorCode;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setAmount(BigDecimal amount) {
|
||||||
|
result.amount = amount;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setCurrency(String currency) {
|
||||||
|
result.currency = currency;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setPaymentMethod(String paymentMethod) {
|
||||||
|
result.paymentMethod = paymentMethod;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setTimestamp(LocalDateTime timestamp) {
|
||||||
|
result.timestamp = timestamp;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setExtraData(Map<String, Object> extraData) {
|
||||||
|
result.extraData = extraData;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PaymentResult build() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PaymentResult{" +
|
||||||
|
"success=" + success +
|
||||||
|
", message='" + message + '\'' +
|
||||||
|
", transactionId='" + transactionId + '\'' +
|
||||||
|
", errorCode='" + errorCode + '\'' +
|
||||||
|
", amount=" + amount +
|
||||||
|
", currency='" + currency + '\'' +
|
||||||
|
", paymentMethod='" + paymentMethod + '\'' +
|
||||||
|
", timestamp=" + timestamp +
|
||||||
|
", extraData=" + extraData +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,33 @@
|
||||||
|
package com.mcwl.pay.domain.enums;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.pay.domain
|
||||||
|
* @Filename:PaymentStatus
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 17:24
|
||||||
|
*/
|
||||||
|
|
||||||
|
public enum PaymentStatus {
|
||||||
|
|
||||||
|
PENDING("待支付"),
|
||||||
|
COMPLETED("已支付"),
|
||||||
|
FAILED("支付失败"),
|
||||||
|
REFUNDED("已退款");
|
||||||
|
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
PaymentStatus(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return name() + "(" + description + ")";
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.mcwl.pay.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.mcwl.pay.domain.OrderTrade;
|
||||||
|
import com.mcwl.pay.domain.PaymentResult;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.pay.mapper
|
||||||
|
* @Filename:OrderTradeMapper
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 14:51
|
||||||
|
*/
|
||||||
|
@Mapper
|
||||||
|
public interface OrderTradeMapper extends BaseMapper<OrderTrade> {
|
||||||
|
|
||||||
|
PaymentResult chargeCard(Integer totalAmount, String paymentMethod);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.mcwl.pay.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.mcwl.common.domain.IdsParam;
|
||||||
|
import com.mcwl.pay.domain.OrderTrade;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.pay.service
|
||||||
|
* @Filename:OrderTradeService
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 14:51
|
||||||
|
*/
|
||||||
|
public interface OrderTradeService extends IService<OrderTrade> {
|
||||||
|
List<OrderTrade> selectMallProductList(OrderTrade orderTrade);
|
||||||
|
|
||||||
|
int insertMallProduct(OrderTrade orderTrade);
|
||||||
|
|
||||||
|
void deleteMallProductByIds(IdsParam ids);
|
||||||
|
|
||||||
|
int updateMallProduct(OrderTrade orderTrade);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
package com.mcwl.pay.service.impl;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mcwl.common.domain.IdsParam;
|
||||||
|
import com.mcwl.common.utils.StringUtils;
|
||||||
|
import com.mcwl.pay.domain.OrderTrade;
|
||||||
|
import com.mcwl.pay.domain.PaymentResult;
|
||||||
|
import com.mcwl.pay.domain.enums.PaymentStatus;
|
||||||
|
import com.mcwl.pay.mapper.OrderTradeMapper;
|
||||||
|
import com.mcwl.pay.service.OrderTradeService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:ChenYan
|
||||||
|
* @Project:McWl
|
||||||
|
* @Package:com.mcwl.pay.service.impl
|
||||||
|
* @Filename:OrderTradeServiceImpl
|
||||||
|
* @Description TODO
|
||||||
|
* @Date:2025/1/3 14:51
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class OrderTradeServiceImpl extends ServiceImpl<OrderTradeMapper, OrderTrade> implements OrderTradeService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderTradeMapper orderTradeMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<OrderTrade> selectMallProductList(OrderTrade orderTrade) {
|
||||||
|
// 创建一个 LambdaQueryWrapper 实例
|
||||||
|
LambdaQueryWrapper<OrderTrade> queryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
|
||||||
|
// 使用非空检查来添加查询条件
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getCode())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getCode, orderTrade.getCode());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getUserId())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getUserId, orderTrade.getUserId());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getProductId())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getProductId, orderTrade.getProductId());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getProductName())) {
|
||||||
|
queryWrapper.like(OrderTrade::getProductName, orderTrade.getProductName());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getUserName())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getUserName, orderTrade.getUserName());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getOrderTime())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getOrderTime, orderTrade.getOrderTime());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getOrderStatus())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getOrderStatus, orderTrade.getOrderStatus());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getPayStatus())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getPayStatus, orderTrade.getPayStatus());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getTotalAmount())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getTotalAmount, orderTrade.getTotalAmount());
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotNull(orderTrade.getPaymentAmount())) {
|
||||||
|
queryWrapper.eq(OrderTrade::getPaymentAmount, orderTrade.getPaymentAmount());
|
||||||
|
}
|
||||||
|
|
||||||
|
return orderTradeMapper.selectList(queryWrapper);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertMallProduct(OrderTrade orderTrade) {
|
||||||
|
PaymentResult paymentResult = orderTradeMapper.chargeCard(orderTrade.getTotalAmount(), orderTrade.getPaymentMethod());
|
||||||
|
|
||||||
|
if (paymentResult.isSuccess()) {
|
||||||
|
// 支付成功后的处理:更新订单状态、生成激活码、更新用户权限等
|
||||||
|
orderTrade.setOrderStatus(PaymentStatus.COMPLETED.ordinal());
|
||||||
|
|
||||||
|
// 保存订单
|
||||||
|
return orderTradeMapper.insert(orderTrade);
|
||||||
|
} else {
|
||||||
|
// 支付失败处理...
|
||||||
|
orderTrade.setOrderStatus(PaymentStatus.FAILED.ordinal());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteMallProductByIds(IdsParam ids) {
|
||||||
|
orderTradeMapper.deleteBatchIds(ids.getIds());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateMallProduct(OrderTrade orderTrade) {
|
||||||
|
return orderTradeMapper.updateById(orderTrade);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -28,11 +28,11 @@ public class MallProduct extends BaseEntity {
|
||||||
* ID
|
* ID
|
||||||
*/
|
*/
|
||||||
@TableId
|
@TableId
|
||||||
private Integer productId;
|
private Long productId;
|
||||||
/**
|
/**
|
||||||
* 用户ID
|
* 用户ID
|
||||||
*/
|
*/
|
||||||
private Integer userId;
|
private Long userId;
|
||||||
/**
|
/**
|
||||||
* 商品名称
|
* 商品名称
|
||||||
*/
|
*/
|
||||||
|
|
1
pom.xml
1
pom.xml
|
@ -239,6 +239,7 @@
|
||||||
<module>mcwl-myInvitation</module>
|
<module>mcwl-myInvitation</module>
|
||||||
<module>mcwl-resource</module>
|
<module>mcwl-resource</module>
|
||||||
<module>mcwl-memberCenter</module>
|
<module>mcwl-memberCenter</module>
|
||||||
|
<module>mcwl-pay</module>
|
||||||
</modules>
|
</modules>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue