后端:创建订单时,创建支付交易记录
This commit is contained in:
parent
5785827748
commit
3a27ae5d96
|
@ -45,10 +45,12 @@
|
|||
<version>2.9.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate.validator</groupId>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>6.0.15.Final</version>
|
||||
<!-- <version>5.4.3.Final</version>-->
|
||||
<version>6.0.16.Final</version>
|
||||
</dependency>
|
||||
|
||||
<!--<dependency>-->
|
||||
<!--<groupId>com.baomidou</groupId>-->
|
||||
<!--<artifactId>mybatis-plus-support</artifactId>-->
|
||||
|
@ -84,5 +86,4 @@
|
|||
|
||||
</dependencies>
|
||||
|
||||
|
||||
</project>
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
"vant": "^1.3.1",
|
||||
"vue": "^2.5.17",
|
||||
"vue-router": "^3.0.1",
|
||||
"vuex": "^3.1.0"
|
||||
"vuex": "^3.1.0",
|
||||
"pingpp-js": "^2.2.13"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/cli-plugin-babel": "^3.4.1",
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
<template>
|
||||
<div>
|
||||
<van-cell-group>
|
||||
<van-cell title="优惠劵编号" :value="couponTemplate.id" />
|
||||
<van-cell title="优惠劵名" :value="couponTemplate.title"/>
|
||||
</van-cell-group>
|
||||
<van-button slot="button" size="small" type="primary" @click="onFetchClick">领取优惠劵</van-button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getCouponTemplate, doAddCouponCard } from '../../api/promotion';
|
||||
import { Dialog } from 'vant';
|
||||
import { setLoginToken } from '../../utils/cache';
|
||||
|
||||
export default {
|
||||
|
||||
data() {
|
||||
return {
|
||||
couponTemplate: {
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
let id = this.$route.query.id;
|
||||
let response = getCouponTemplate(id);
|
||||
response.then(data => {
|
||||
this.couponTemplate = data;
|
||||
});
|
||||
},
|
||||
|
||||
methods: {
|
||||
onFetchClick: function () {
|
||||
let that = this;
|
||||
let id = this.$route.query.id;
|
||||
let response = doAddCouponCard(id);
|
||||
response.then(data => {
|
||||
Dialog.alert({
|
||||
title: '系统提示',
|
||||
message: '领取成功',
|
||||
beforeClose: function (action, done) {
|
||||
// 关闭弹窗
|
||||
done();
|
||||
// 跳转到我的优惠劵
|
||||
that.$router.push('/user/coupon');
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
</script>
|
|
@ -57,10 +57,11 @@ public class UsersOrderController {
|
|||
|
||||
@PostMapping("create_order")
|
||||
@ApiOperation("创建订单")
|
||||
public CommonResult<OrderCreateBO> createOrder(@RequestBody @Validated OrderCreatePO orderCreatePO) {
|
||||
public CommonResult<OrderCreateBO> createOrder(@RequestBody @Validated OrderCreatePO orderCreatePO,
|
||||
HttpServletRequest request) {
|
||||
Integer userId = UserSecurityContextHolder.getContext().getUserId();
|
||||
OrderCreateDTO orderCreateDTO = OrderConvertAPP.INSTANCE.convert(orderCreatePO);
|
||||
orderCreateDTO.setUserId(userId);
|
||||
orderCreateDTO.setUserId(userId).setIp(HttpUtil.getIp(request));
|
||||
return orderService.createOrder(orderCreateDTO);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,6 @@ public class PayAppId {
|
|||
/**
|
||||
* 电商
|
||||
*/
|
||||
public static final String APP_ID_1024 = "1024";
|
||||
public static final String APP_ID_SHOP_ORDER = "POd4RC6a";
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.iocoder.mall.order.biz.service;
|
||||
|
||||
import cn.iocoder.common.framework.constant.DeletedStatusEnum;
|
||||
import cn.iocoder.common.framework.util.DateUtil;
|
||||
import cn.iocoder.common.framework.util.ServiceExceptionUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.order.api.OrderService;
|
||||
|
@ -8,6 +9,7 @@ import cn.iocoder.mall.order.api.bo.*;
|
|||
import cn.iocoder.mall.order.api.constant.OrderErrorCodeEnum;
|
||||
import cn.iocoder.mall.order.api.constant.OrderHasReturnExchangeEnum;
|
||||
import cn.iocoder.mall.order.api.constant.OrderStatusEnum;
|
||||
import cn.iocoder.mall.order.api.constant.PayAppId;
|
||||
import cn.iocoder.mall.order.api.dto.*;
|
||||
import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum;
|
||||
import cn.iocoder.mall.order.biz.constants.OrderRecipientTypeEnum;
|
||||
|
@ -15,6 +17,8 @@ import cn.iocoder.mall.order.biz.convert.*;
|
|||
import cn.iocoder.mall.order.biz.dao.*;
|
||||
import cn.iocoder.mall.order.biz.dataobject.*;
|
||||
import cn.iocoder.mall.pay.api.PayTransactionService;
|
||||
import cn.iocoder.mall.pay.api.bo.PayTransactionBO;
|
||||
import cn.iocoder.mall.pay.api.dto.PayTransactionCreateDTO;
|
||||
import cn.iocoder.mall.product.api.ProductSpuService;
|
||||
import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO;
|
||||
import cn.iocoder.mall.user.api.UserAddressService;
|
||||
|
@ -41,9 +45,9 @@ import java.util.stream.Collectors;
|
|||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
/**
|
||||
* 支付过期时间 15 分钟
|
||||
* 支付过期时间 120 分钟
|
||||
*/
|
||||
public static final int PAY_EXPIRE_TIME = 15;
|
||||
public static final int PAY_EXPIRE_TIME = 120;
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
|
@ -64,7 +68,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
private CartServiceImpl cartService;
|
||||
@Reference
|
||||
private UserAddressService userAddressService;
|
||||
@Reference
|
||||
@Reference(validation = "true")
|
||||
private PayTransactionService payTransactionService;
|
||||
|
||||
@Override
|
||||
|
@ -187,7 +191,7 @@ public class OrderServiceImpl implements OrderService {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional // TODO 芋艿,先不考虑分布式事务的问题
|
||||
public CommonResult<OrderCreateBO> createOrder(OrderCreateDTO orderCreateDTO) {
|
||||
Integer userId = orderCreateDTO.getUserId();
|
||||
List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems();
|
||||
|
@ -245,6 +249,9 @@ public class OrderServiceImpl implements OrderService {
|
|||
.setPresentTotal(priceItem.getPresentTotal());
|
||||
}
|
||||
|
||||
// TODO 芋艿,标记优惠劵使用
|
||||
// TODO 芋艿,扣除库存
|
||||
|
||||
// order
|
||||
|
||||
// TODO: 2019-04-11 Sin 订单号需要生成规则
|
||||
|
@ -310,19 +317,10 @@ public class OrderServiceImpl implements OrderService {
|
|||
orderItemMapper.insert(orderItemDOList);
|
||||
|
||||
// 创建预订单
|
||||
// TODO sin 支付订单 orderSubject 暂时取第一个子订单商品信息
|
||||
// String orderSubject = orderItemDOList.get(0).getSkuName();
|
||||
// Date expireTime = DateUtil.addDate(Calendar.MINUTE, PAY_EXPIRE_TIME);
|
||||
// CommonResult commonResult = payTransactionService.createTransaction(
|
||||
// new PayTransactionCreateDTO()
|
||||
// .setCreateIp(orderCreateDTO.getIp())
|
||||
// .setAppId(PayAppId.APP_ID_1024)
|
||||
// .setExpireTime(expireTime)
|
||||
// .setPrice(orderDO.getPayAmount())
|
||||
// .setOrderSubject(orderSubject)
|
||||
// .setOrderMemo(orderDO.getRemark())
|
||||
// .setOrderDescription("")
|
||||
// );
|
||||
CommonResult<PayTransactionBO> createPayTransactionResult = createPayTransaction(orderDO, orderItemDOList, orderCreateDTO.getIp());
|
||||
if (calcOrderPriceResult.isError()) {
|
||||
return CommonResult.error(calcOrderPriceResult);
|
||||
}
|
||||
|
||||
// if (commonResult.isError()) {
|
||||
// //手动开启事务回滚
|
||||
|
@ -352,6 +350,23 @@ public class OrderServiceImpl implements OrderService {
|
|||
return cartService.calcOrderPrice(calcOrderPriceDTO);
|
||||
}
|
||||
|
||||
private CommonResult<PayTransactionBO> createPayTransaction(OrderDO order, List<OrderItemDO> orderItems, String ip) {
|
||||
// TODO sin 支付订单 orderSubject 暂时取第一个子订单商品信息
|
||||
String orderSubject = orderItems.get(0).getSkuName();
|
||||
Date expireTime = DateUtil.addDate(Calendar.MINUTE, PAY_EXPIRE_TIME);
|
||||
return payTransactionService.createTransaction(
|
||||
new PayTransactionCreateDTO()
|
||||
.setCreateIp(ip)
|
||||
.setAppId(PayAppId.APP_ID_SHOP_ORDER)
|
||||
.setOrderId(order.getId().toString())
|
||||
.setExpireTime(expireTime)
|
||||
.setPrice(order.getPresentPrice())
|
||||
.setOrderSubject(orderSubject)
|
||||
.setOrderMemo("测试备注") // TODO 芋艿,后面补充
|
||||
.setOrderDescription("测试描述") // TODO 芋艿,后面补充
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult updateOrderItem(OrderItemUpdateDTO orderUpdateDTO) {
|
||||
OrderItemDO orderItemDO = OrderItemConvert.INSTANCE.convert(orderUpdateDTO);
|
||||
|
|
|
@ -2,11 +2,11 @@ package cn.iocoder.mall.pay.api.dto;
|
|||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import javax.validation.constraints.DecimalMin;
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -36,18 +36,18 @@ public class PayTransactionCreateDTO implements Serializable {
|
|||
* 订单商品名
|
||||
*/
|
||||
@NotEmpty(message = "商品名不能为空")
|
||||
@Size(max = 32, message = "商品名不能超过32")
|
||||
@Length(max = 32, message = "商品名不能超过32")
|
||||
private String orderSubject;
|
||||
/**
|
||||
* 订单商品描述
|
||||
*/
|
||||
@NotEmpty(message = "商品描述不能为空")
|
||||
@Size(max = 128, message = "商品描述长度不能超过128")
|
||||
@Length(max = 128, message = "商品描述长度不能超过128")
|
||||
private String orderDescription;
|
||||
/**
|
||||
* 订单备注
|
||||
*/
|
||||
@Size(max = 256, message = "商品描述长度不能超过256")
|
||||
@Length(max = 256, message = "商品描述长度不能超过256")
|
||||
private String orderMemo;
|
||||
/**
|
||||
* 支付金额,单位:分。
|
||||
|
|
25
pom.xml
25
pom.xml
|
@ -26,6 +26,7 @@
|
|||
<packaging>pom</packaging>
|
||||
|
||||
<properties>
|
||||
<springboot.version>2.1.3.RELEASE</springboot.version>
|
||||
<com.alibab.dubbo.version>2.6.5</com.alibab.dubbo.version>
|
||||
<mysql-connector-java.version>5.1.47</mysql-connector-java.version>
|
||||
<dubbo-spring-boot-starter.version>0.2.1.RELEASE</dubbo-spring-boot-starter.version>
|
||||
|
@ -118,6 +119,30 @@
|
|||
<groupId>org.apache.rocketmq</groupId>
|
||||
<artifactId>rocketmq-spring-boot-starter</artifactId>
|
||||
<version>${rocketmq-spring-boot-starter.version}</version>
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <artifactId>hibernate-validator</artifactId>-->
|
||||
<!-- <groupId>org.hibernate.validator</groupId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
<!-- <exclusions>-->
|
||||
<!-- <exclusion>-->
|
||||
<!-- <artifactId>hibernate-validator</artifactId>-->
|
||||
<!-- <groupId>org.hibernate.validator</groupId>-->
|
||||
<!-- </exclusion>-->
|
||||
<!-- </exclusions>-->
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
Loading…
Reference in New Issue