后端:创建订单时,创建支付交易记录

This commit is contained in:
YunaiV 2019-04-20 23:48:26 +08:00
parent 5785827748
commit 3a27ae5d96
8 changed files with 126 additions and 29 deletions

View File

@ -45,10 +45,12 @@
<version>2.9.7</version> <version>2.9.7</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hibernate.validator</groupId> <groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId> <artifactId>hibernate-validator</artifactId>
<version>6.0.15.Final</version> <!-- <version>5.4.3.Final</version>-->
<version>6.0.16.Final</version>
</dependency> </dependency>
<!--<dependency>--> <!--<dependency>-->
<!--<groupId>com.baomidou</groupId>--> <!--<groupId>com.baomidou</groupId>-->
<!--<artifactId>mybatis-plus-support</artifactId>--> <!--<artifactId>mybatis-plus-support</artifactId>-->
@ -84,5 +86,4 @@
</dependencies> </dependencies>
</project> </project>

View File

@ -14,7 +14,8 @@
"vant": "^1.3.1", "vant": "^1.3.1",
"vue": "^2.5.17", "vue": "^2.5.17",
"vue-router": "^3.0.1", "vue-router": "^3.0.1",
"vuex": "^3.1.0" "vuex": "^3.1.0",
"pingpp-js": "^2.2.13"
}, },
"devDependencies": { "devDependencies": {
"@vue/cli-plugin-babel": "^3.4.1", "@vue/cli-plugin-babel": "^3.4.1",

View File

@ -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>

View File

@ -57,10 +57,11 @@ public class UsersOrderController {
@PostMapping("create_order") @PostMapping("create_order")
@ApiOperation("创建订单") @ApiOperation("创建订单")
public CommonResult<OrderCreateBO> createOrder(@RequestBody @Validated OrderCreatePO orderCreatePO) { public CommonResult<OrderCreateBO> createOrder(@RequestBody @Validated OrderCreatePO orderCreatePO,
HttpServletRequest request) {
Integer userId = UserSecurityContextHolder.getContext().getUserId(); Integer userId = UserSecurityContextHolder.getContext().getUserId();
OrderCreateDTO orderCreateDTO = OrderConvertAPP.INSTANCE.convert(orderCreatePO); OrderCreateDTO orderCreateDTO = OrderConvertAPP.INSTANCE.convert(orderCreatePO);
orderCreateDTO.setUserId(userId); orderCreateDTO.setUserId(userId).setIp(HttpUtil.getIp(request));
return orderService.createOrder(orderCreateDTO); return orderService.createOrder(orderCreateDTO);
} }

View File

@ -11,6 +11,6 @@ public class PayAppId {
/** /**
* 电商 * 电商
*/ */
public static final String APP_ID_1024 = "1024"; public static final String APP_ID_SHOP_ORDER = "POd4RC6a";
} }

View File

@ -1,6 +1,7 @@
package cn.iocoder.mall.order.biz.service; package cn.iocoder.mall.order.biz.service;
import cn.iocoder.common.framework.constant.DeletedStatusEnum; 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.util.ServiceExceptionUtil;
import cn.iocoder.common.framework.vo.CommonResult; import cn.iocoder.common.framework.vo.CommonResult;
import cn.iocoder.mall.order.api.OrderService; 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.OrderErrorCodeEnum;
import cn.iocoder.mall.order.api.constant.OrderHasReturnExchangeEnum; import cn.iocoder.mall.order.api.constant.OrderHasReturnExchangeEnum;
import cn.iocoder.mall.order.api.constant.OrderStatusEnum; 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.api.dto.*;
import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum; import cn.iocoder.mall.order.biz.constants.OrderDeliveryTypeEnum;
import cn.iocoder.mall.order.biz.constants.OrderRecipientTypeEnum; 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.dao.*;
import cn.iocoder.mall.order.biz.dataobject.*; import cn.iocoder.mall.order.biz.dataobject.*;
import cn.iocoder.mall.pay.api.PayTransactionService; 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.ProductSpuService;
import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO; import cn.iocoder.mall.product.api.bo.ProductSkuDetailBO;
import cn.iocoder.mall.user.api.UserAddressService; import cn.iocoder.mall.user.api.UserAddressService;
@ -41,9 +45,9 @@ import java.util.stream.Collectors;
public class OrderServiceImpl implements OrderService { public class OrderServiceImpl implements OrderService {
/** /**
* 支付过期时间 15 分钟 * 支付过期时间 120 分钟
*/ */
public static final int PAY_EXPIRE_TIME = 15; public static final int PAY_EXPIRE_TIME = 120;
@Autowired @Autowired
private OrderMapper orderMapper; private OrderMapper orderMapper;
@ -64,7 +68,7 @@ public class OrderServiceImpl implements OrderService {
private CartServiceImpl cartService; private CartServiceImpl cartService;
@Reference @Reference
private UserAddressService userAddressService; private UserAddressService userAddressService;
@Reference @Reference(validation = "true")
private PayTransactionService payTransactionService; private PayTransactionService payTransactionService;
@Override @Override
@ -187,7 +191,7 @@ public class OrderServiceImpl implements OrderService {
} }
@Override @Override
@Transactional @Transactional // TODO 芋艿先不考虑分布式事务的问题
public CommonResult<OrderCreateBO> createOrder(OrderCreateDTO orderCreateDTO) { public CommonResult<OrderCreateBO> createOrder(OrderCreateDTO orderCreateDTO) {
Integer userId = orderCreateDTO.getUserId(); Integer userId = orderCreateDTO.getUserId();
List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems(); List<OrderCreateItemDTO> orderItemDTOList = orderCreateDTO.getOrderItems();
@ -245,6 +249,9 @@ public class OrderServiceImpl implements OrderService {
.setPresentTotal(priceItem.getPresentTotal()); .setPresentTotal(priceItem.getPresentTotal());
} }
// TODO 芋艿标记优惠劵使用
// TODO 芋艿扣除库存
// order // order
// TODO: 2019-04-11 Sin 订单号需要生成规则 // TODO: 2019-04-11 Sin 订单号需要生成规则
@ -310,19 +317,10 @@ public class OrderServiceImpl implements OrderService {
orderItemMapper.insert(orderItemDOList); orderItemMapper.insert(orderItemDOList);
// 创建预订单 // 创建预订单
// TODO sin 支付订单 orderSubject 暂时取第一个子订单商品信息 CommonResult<PayTransactionBO> createPayTransactionResult = createPayTransaction(orderDO, orderItemDOList, orderCreateDTO.getIp());
// String orderSubject = orderItemDOList.get(0).getSkuName(); if (calcOrderPriceResult.isError()) {
// Date expireTime = DateUtil.addDate(Calendar.MINUTE, PAY_EXPIRE_TIME); return CommonResult.error(calcOrderPriceResult);
// 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("")
// );
// if (commonResult.isError()) { // if (commonResult.isError()) {
// //手动开启事务回滚 // //手动开启事务回滚
@ -352,6 +350,23 @@ public class OrderServiceImpl implements OrderService {
return cartService.calcOrderPrice(calcOrderPriceDTO); 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 @Override
public CommonResult updateOrderItem(OrderItemUpdateDTO orderUpdateDTO) { public CommonResult updateOrderItem(OrderItemUpdateDTO orderUpdateDTO) {
OrderItemDO orderItemDO = OrderItemConvert.INSTANCE.convert(orderUpdateDTO); OrderItemDO orderItemDO = OrderItemConvert.INSTANCE.convert(orderUpdateDTO);

View File

@ -2,11 +2,11 @@ package cn.iocoder.mall.pay.api.dto;
import lombok.Data; import lombok.Data;
import lombok.experimental.Accessors; 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.DecimalMin;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
@ -36,18 +36,18 @@ public class PayTransactionCreateDTO implements Serializable {
* 订单商品名 * 订单商品名
*/ */
@NotEmpty(message = "商品名不能为空") @NotEmpty(message = "商品名不能为空")
@Size(max = 32, message = "商品名不能超过32") @Length(max = 32, message = "商品名不能超过32")
private String orderSubject; private String orderSubject;
/** /**
* 订单商品描述 * 订单商品描述
*/ */
@NotEmpty(message = "商品描述不能为空") @NotEmpty(message = "商品描述不能为空")
@Size(max = 128, message = "商品描述长度不能超过128") @Length(max = 128, message = "商品描述长度不能超过128")
private String orderDescription; private String orderDescription;
/** /**
* 订单备注 * 订单备注
*/ */
@Size(max = 256, message = "商品描述长度不能超过256") @Length(max = 256, message = "商品描述长度不能超过256")
private String orderMemo; private String orderMemo;
/** /**
* 支付金额单位 * 支付金额单位

25
pom.xml
View File

@ -26,6 +26,7 @@
<packaging>pom</packaging> <packaging>pom</packaging>
<properties> <properties>
<springboot.version>2.1.3.RELEASE</springboot.version>
<com.alibab.dubbo.version>2.6.5</com.alibab.dubbo.version> <com.alibab.dubbo.version>2.6.5</com.alibab.dubbo.version>
<mysql-connector-java.version>5.1.47</mysql-connector-java.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> <dubbo-spring-boot-starter.version>0.2.1.RELEASE</dubbo-spring-boot-starter.version>
@ -118,6 +119,30 @@
<groupId>org.apache.rocketmq</groupId> <groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-starter</artifactId> <artifactId>rocketmq-spring-boot-starter</artifactId>
<version>${rocketmq-spring-boot-starter.version}</version> <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> </dependency>
</dependencies> </dependencies>