package com.supersavedriving.user.modular.api;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.supersavedriving.user.core.common.annotion.ServiceLog;
|
import com.supersavedriving.user.core.util.ToolUtil;
|
import com.supersavedriving.user.modular.system.model.AppUser;
|
import com.supersavedriving.user.modular.system.model.Order;
|
import com.supersavedriving.user.modular.system.service.IAppUserService;
|
import com.supersavedriving.user.modular.system.service.IOrderService;
|
import com.supersavedriving.user.modular.system.util.PayMoneyUtil;
|
import com.supersavedriving.user.modular.system.util.ResultUtil;
|
import com.supersavedriving.user.modular.system.warpper.*;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.RestController;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.PrintWriter;
|
import java.util.Arrays;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.stream.Collectors;
|
|
/**
|
* 订单控制器
|
* @author pzb
|
* @Date 2023/2/28 11:24
|
*/
|
@RestController
|
@RequestMapping("")
|
public class OrderController {
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private IAppUserService appUserService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/queryServerOrder")
|
// @ServiceLog(name = "获取正在进行中的订单id", url = "/api/order/queryServerOrder")
|
@ApiOperation(value = "获取正在进行中的订单id", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper<List<Long>> queryServerOrder(){
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
AppUser appUser = appUserService.selectById(uid);
|
List<Integer> list = Arrays.asList(101, 102, 103, 104, 105, 106, 107, 201, 401);
|
List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("userPhone", appUser.getPhone()).eq("status", 1).in("state", list));
|
List<Long> collect = orders.stream().map(Order::getId).collect(Collectors.toList());
|
return ResponseWarpper.success(collect);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/getEstimatedCosts")
|
// @ServiceLog(name = "获取预估费用", url = "/api/order/getEstimatedCosts")
|
@ApiOperation(value = "获取预估费用", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper<EstimatedCostsWarpper> getEstimatedCosts(EstimatedCosts estimatedCosts){
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
ResultUtil<EstimatedCostsWarpper> estimatedCosts1 = orderService.getEstimatedCosts(uid, estimatedCosts);
|
return ResponseWarpper.success(estimatedCosts1);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/travelOrder")
|
// @ServiceLog(name = "用户下单/扫码下单", url = "/api/order/travelOrder")
|
@ApiOperation(value = "用户下单/扫码下单", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper travelOrder(TravelOrder travelOrder){
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
ResultUtil resultUtil = orderService.travelOrder(uid, travelOrder);
|
return ResponseWarpper.success(resultUtil);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/cancelOrder")
|
// @ServiceLog(name = "用户取消订单", url = "/api/order/cancelOrder")
|
@ApiOperation(value = "用户取消订单", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
|
@ApiImplicitParam(value = "取消原因", name = "cause", required = true, dataType = "string"),
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper cancelOrder(Long orderId, String cause){
|
if(null == orderId){
|
return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
|
}
|
if(ToolUtil.isEmpty(cause)){
|
return ResponseWarpper.success(ResultUtil.paranErr("cause"));
|
}
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
ResultUtil resultUtil = orderService.cancelOrder(uid, orderId, cause);
|
return ResponseWarpper.success(resultUtil);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/queryOrderInfo")
|
// @ServiceLog(name = "获取订单详情", url = "/api/order/queryOrderInfo")
|
@ApiOperation(value = "获取订单详情", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper<OrderInfoWarpper> queryOrderInfo(Long orderId){
|
if(null == orderId){
|
return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
|
}
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
OrderInfoWarpper orderInfoWarpper = orderService.queryOrderInfo(uid, orderId);
|
return ResponseWarpper.success(orderInfoWarpper);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/editOrderEndAddress")
|
// @ServiceLog(name = "修改终点", url = "/api/order/editOrderEndAddress")
|
@ApiOperation(value = "修改终点", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper editOrderEndAddress(EditOrderEndAddress editOrderEndAddress){
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
ResultUtil resultUtil = orderService.editOrderEndAddress(uid, editOrderEndAddress);
|
return ResponseWarpper.success(resultUtil);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/api/order/queryOrderPrice")
|
// @ServiceLog(name = "获取订单费用明细", url = "/api/order/queryOrderPrice")
|
@ApiOperation(value = "获取订单费用明细", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
|
@ApiImplicitParam(value = "是否余额抵扣(0=否,1=是)", name = "payType", required = true, dataType = "int"),
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper<OrderPriceWarpper> queryOrderPrice(Long orderId, Integer payType){
|
if(null == orderId){
|
return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
|
}
|
if(null == payType){
|
return ResponseWarpper.success(ResultUtil.paranErr("payType"));
|
}
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
OrderPriceWarpper orderPriceWarpper = orderService.queryOrderPrice(uid, orderId, payType);
|
return ResponseWarpper.success(orderPriceWarpper);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/queryPayCouponList")
|
// @ServiceLog(name = "获取支付页面优惠券选择列表", url = "/api/order/queryPayCouponList")
|
@ApiOperation(value = "获取支付页面优惠券选择列表", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper<List<CouponWarpper>> queryPayCouponList(Long orderId){
|
if(null == orderId){
|
return ResponseWarpper.success(ResultUtil.paranErr("orderId"));
|
}
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
List<CouponWarpper> list = orderService.queryPayCouponList(uid, orderId);
|
return ResponseWarpper.success(list);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
@ResponseBody
|
@PostMapping("/api/order/orderPayment")
|
// @ServiceLog(name = "订单完成后的支付操作", url = "/api/order/orderPayment")
|
@ApiOperation(value = "订单完成后的支付操作", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper orderPayment(OrderPayment orderPayment){
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
ResultUtil resultUtil = orderService.orderPayment(uid, orderPayment);
|
return ResponseWarpper.success(resultUtil);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
/**
|
* 订单微信支付回调处理
|
* @param request
|
* @param response
|
*/
|
@ResponseBody
|
@PostMapping("/base/order/orderPayCallback")
|
public void orderPayCallback(HttpServletRequest request, HttpServletResponse response){
|
try {
|
Map<String, String> map = payMoneyUtil.weixinpayCallback(request);
|
if(null != map){
|
String out_trade_no = map.get("out_trade_no");
|
String transaction_id = map.get("transaction_id");
|
String result = map.get("result");
|
String orderId = out_trade_no.substring(17);
|
ResultUtil resultUtil = orderService.orderPayCallback(orderId, transaction_id);
|
if(resultUtil.getCode() == 10000){
|
PrintWriter out = response.getWriter();
|
out.print(result);
|
out.flush();
|
out.close();
|
}
|
}
|
}catch (Exception e){
|
e.printStackTrace();
|
}
|
}
|
|
|
|
|
@ResponseBody
|
@PostMapping("/api/order/orderAppraise")
|
// @ServiceLog(name = "订单评价操作", url = "/api/order/orderAppraise")
|
@ApiOperation(value = "订单评价操作", tags = {"用户端-首页"}, notes = "")
|
@ApiImplicitParams({
|
@ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "long"),
|
@ApiImplicitParam(value = "评分", name = "score", required = true, dataType = "int"),
|
@ApiImplicitParam(value = "评价内容", name = "content", required = true, dataType = "string"),
|
@ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
|
})
|
public ResponseWarpper orderAppraise(Long orderId, Integer score, String content){
|
try {
|
Integer uid = appUserService.getUserByRequest();
|
if(null == uid){
|
return ResponseWarpper.success(ResultUtil.tokenErr());
|
}
|
ResultUtil resultUtil = orderService.orderAppraise(uid, orderId, score, content);
|
return ResponseWarpper.success(resultUtil);
|
}catch (Exception e){
|
e.printStackTrace();
|
return new ResponseWarpper(500, e.getMessage());
|
}
|
}
|
|
|
}
|