提交订单接口基本开发
This commit is contained in:
parent
8d0f1d9f4b
commit
e150bde6b3
@ -2,13 +2,27 @@ package net.jieyuu.controller;
|
||||
|
||||
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.jieyuu.enums.ClientType;
|
||||
import net.jieyuu.enums.ProductOrderPayTypeEnum;
|
||||
import net.jieyuu.request.ConfirmOrderRequest;
|
||||
import net.jieyuu.service.ProductOrderService;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 前端控制器
|
||||
* 前端控制器
|
||||
* </p>
|
||||
*
|
||||
* @author jieyuu
|
||||
@ -16,8 +30,50 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
*/
|
||||
@Api("订单模块")
|
||||
@RestController
|
||||
@RequestMapping("/api/order/v1/")
|
||||
@RequestMapping("/api/order/v1")
|
||||
@Slf4j
|
||||
public class ProductOrderController {
|
||||
|
||||
@Autowired
|
||||
private ProductOrderService orderService;
|
||||
|
||||
@ApiOperation("提交订单")
|
||||
@PostMapping("confirm")
|
||||
public void confirmOrder(@ApiParam("订单对象") @RequestBody ConfirmOrderRequest confirmOrderRequest, HttpServletResponse response) {
|
||||
|
||||
JsonData jsonData = orderService.confirmOrder(orderService);
|
||||
if (jsonData.getCode() == 0) {
|
||||
//根据端类型选择返回类型
|
||||
String client = confirmOrderRequest.getClientType();
|
||||
String payType = confirmOrderRequest.getPayType();
|
||||
if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.ALIPAY.name())) {//如果是支付宝跳转网页,app除外
|
||||
log.info("创建支付宝订单成功:{}", confirmOrderRequest.toString());
|
||||
|
||||
if (client.equalsIgnoreCase(ClientType.H5.name())) {
|
||||
writeData(response, jsonData);
|
||||
} else if (client.equalsIgnoreCase(ClientType.APP.name())) {
|
||||
//app sdk支付 todo
|
||||
|
||||
}
|
||||
} else if (payType.equalsIgnoreCase(ProductOrderPayTypeEnum.WECHAT.name())) {//微信支付
|
||||
//todo 微信支付
|
||||
}
|
||||
|
||||
} else {
|
||||
log.error("创建订单失败{}:", jsonData.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private void writeData(HttpServletResponse response, JsonData jsonData) {
|
||||
|
||||
try {
|
||||
response.setContentType("text/html;charset=UTF8");
|
||||
response.getWriter().write(jsonData.getData().toString());
|
||||
response.getWriter().flush();
|
||||
} catch (IOException e) {
|
||||
log.error("写出html异常:{}", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,63 @@
|
||||
package net.jieyuu.request;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
public class ConfirmOrderRequest {
|
||||
|
||||
/**
|
||||
* 购物车使用的优惠券
|
||||
*/
|
||||
@JsonProperty("coupon_record_id")
|
||||
private Long couponRecordId;
|
||||
|
||||
/**
|
||||
* 最终购买的商品列表
|
||||
* 传递id, 数量从购物车中读取
|
||||
*/
|
||||
@JsonProperty("product_list")
|
||||
private List<Long> productList;
|
||||
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
@JsonProperty("pay_type")
|
||||
private String payType;
|
||||
|
||||
/**
|
||||
* 端类型
|
||||
*/
|
||||
@JsonProperty("client_type")
|
||||
private String clientType;
|
||||
|
||||
/**
|
||||
* 购物车使用的优惠券
|
||||
*/
|
||||
@JsonProperty("address_id")
|
||||
private Long addressId;
|
||||
|
||||
/**
|
||||
* 总价格,由前端传递,后端需要验价
|
||||
*/
|
||||
@JsonProperty("total_amount")
|
||||
private BigDecimal totalAmount;
|
||||
|
||||
/**
|
||||
* 实际支付价格
|
||||
* 若使用优惠券,就减去优惠券价格,否则和 totalAmount相同
|
||||
*/
|
||||
@JsonProperty("real_pay_amount")
|
||||
private BigDecimal realPayAmount;
|
||||
|
||||
/**
|
||||
* 防重令牌
|
||||
*/
|
||||
@JsonProperty("token")
|
||||
private String token;
|
||||
}
|
@ -2,6 +2,7 @@ package net.jieyuu.service;
|
||||
|
||||
import net.jieyuu.model.ProductOrderDO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@ -13,4 +14,12 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface ProductOrderService extends IService<ProductOrderDO> {
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
* @param orderService
|
||||
* @return
|
||||
*/
|
||||
JsonData confirmOrder(ProductOrderService orderService);
|
||||
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import net.jieyuu.model.ProductOrderDO;
|
||||
import net.jieyuu.mapper.ProductOrderMapper;
|
||||
import net.jieyuu.service.ProductOrderService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import net.jieyuu.utils.JsonData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@ -17,4 +18,9 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class ProductOrderServiceImpl extends ServiceImpl<ProductOrderMapper, ProductOrderDO> implements ProductOrderService {
|
||||
|
||||
@Override
|
||||
public JsonData confirmOrder(ProductOrderService orderService) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user