后台管理 -> 订单管理完成;nginx配置文件限制ip并发数
This commit is contained in:
@@ -2,18 +2,31 @@ package com.cxyxiaomo.epp.shop.controller;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.cxyxiaomo.epp.PageTable.enums.AddType;
|
||||
import com.cxyxiaomo.epp.PageTable.enums.EditType;
|
||||
import com.cxyxiaomo.epp.PageTable.enums.FieldType;
|
||||
import com.cxyxiaomo.epp.PageTable.enums.SearchType;
|
||||
import com.cxyxiaomo.epp.PageTable.query.PageQuery;
|
||||
import com.cxyxiaomo.epp.PageTable.utils.FieldBuilder;
|
||||
import com.cxyxiaomo.epp.PageTable.utils.FieldMapperBuilder;
|
||||
import com.cxyxiaomo.epp.PageTable.utils.FieldRuleBuilder;
|
||||
import com.cxyxiaomo.epp.PageTable.utils.FieldRuleListBuilder;
|
||||
import com.cxyxiaomo.epp.common.enums.OrderStatus;
|
||||
import com.cxyxiaomo.epp.common.pojo.Order;
|
||||
import com.cxyxiaomo.epp.common.pojo.OrderDetail;
|
||||
import com.cxyxiaomo.epp.common.query.OrderQuery;
|
||||
import com.cxyxiaomo.epp.common.response.Res;
|
||||
import com.cxyxiaomo.epp.common.vo.GoodVO;
|
||||
import com.cxyxiaomo.epp.common.vo.OrderDetailVO;
|
||||
import com.cxyxiaomo.epp.common.vo.OrderVO;
|
||||
import com.cxyxiaomo.epp.shop.service.GoodService;
|
||||
import com.cxyxiaomo.epp.shop.service.OrderService;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -30,8 +43,8 @@ public class OrderController {
|
||||
/**
|
||||
* 小程序端创建订单
|
||||
*
|
||||
* @param userId 下单用户
|
||||
* @param orderList 下单商品 [ { goodId, count }, ... ]
|
||||
* @param params userId 下单用户
|
||||
* @param params orderList 下单商品 [ { goodId, count }, ... ]
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/miniprogram/createOrder")
|
||||
@@ -184,6 +197,12 @@ public class OrderController {
|
||||
return Res.success(success ? "支付成功" : "支付失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户取消订单
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/miniprogram/cancelOrder")
|
||||
@ResponseBody
|
||||
public Res cancelOrder(@RequestBody JSONObject params) {
|
||||
@@ -224,6 +243,107 @@ public class OrderController {
|
||||
return Res.success(success ? "取消成功" : "取消失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单发货
|
||||
*
|
||||
* @param orderId
|
||||
* @param expressId
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/manage/deliverOrder")
|
||||
@ResponseBody
|
||||
public Res deliverOrder(Long orderId, String expressId, String comment) {
|
||||
if (orderId == null || expressId == null || comment == null) {
|
||||
return Res.error("参数错误");
|
||||
}
|
||||
|
||||
if (expressId.equals("") && comment.equals("")) {
|
||||
return Res.error("运单号 和 发货备注 不可同时为空");
|
||||
}
|
||||
|
||||
// 查询订单详情
|
||||
Order order = orderService.getOrderById(orderId);
|
||||
if (order == null) {
|
||||
return Res.error("订单不存在");
|
||||
}
|
||||
|
||||
//判断是否可以发货
|
||||
OrderStatus orderStatus = OrderStatus.get(order.getOrderStatus());
|
||||
switch (orderStatus) {
|
||||
case PENDING:
|
||||
return Res.error("订单尚未支付,不可发货");
|
||||
case PROCESSING: // 订单未发货
|
||||
// 更新订单发货信息
|
||||
orderService.updateOrderShipInfo(orderId, expressId, comment);
|
||||
// 更新支付信息
|
||||
orderService.updateOrderStatus(orderId, OrderStatus.SHIPPED);
|
||||
return Res.success("发货成功");
|
||||
case SHIPPED: // 订单已发货,修改发货信息
|
||||
// 更新订单发货信息
|
||||
orderService.updateOrderShipInfo(orderId, expressId, comment);
|
||||
return Res.success("发货信息修改成功");
|
||||
case DELIVERED:
|
||||
return Res.error("订单已完成,无法再次发货");
|
||||
case CANCELLED:
|
||||
return Res.error("订单已取消,不可发货");
|
||||
default:
|
||||
return Res.error("当前订单状态不可发货");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理员取消订单
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/manage/cancelOrder")
|
||||
@ResponseBody
|
||||
public Res cancelOrderByManager(@RequestBody JSONObject params) {
|
||||
Long orderId = params.getLong("orderId");
|
||||
if (orderId == null) {
|
||||
return Res.error("参数错误");
|
||||
}
|
||||
|
||||
// 查询订单详情
|
||||
Order order = orderService.getOrderById(orderId);
|
||||
if (order == null) {
|
||||
return Res.error("订单不存在");
|
||||
}
|
||||
|
||||
//判断是否可以取消
|
||||
OrderStatus orderStatus = OrderStatus.get(order.getOrderStatus());
|
||||
switch (orderStatus) {
|
||||
case PENDING:
|
||||
// 更新订单发货信息
|
||||
orderService.updateOrderShipInfo(orderId, "", "管理员取消了您的订单,如有疑问请联系管理员");
|
||||
// 更新支付信息
|
||||
orderService.updateOrderStatus(orderId, OrderStatus.CANCELLED);
|
||||
return Res.success("操作成功");
|
||||
case PROCESSING:
|
||||
// 更新订单发货信息
|
||||
orderService.updateOrderShipInfo(orderId, "", "管理员取消了您的订单,费用已退回至您的帐户,如有疑问请联系管理员");
|
||||
// 更新支付信息
|
||||
orderService.updateOrderStatus(orderId, OrderStatus.CANCELLED);
|
||||
return Res.success("操作成功");
|
||||
case SHIPPED:
|
||||
return Res.error("订单已发货,不可取消");
|
||||
case DELIVERED:
|
||||
return Res.error("订单已送达,不可取消");
|
||||
case CANCELLED:
|
||||
return Res.error("订单已取消");
|
||||
default:
|
||||
return Res.error("当前订单状态无法取消");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订单确认收货
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/miniprogram/confirmOrder")
|
||||
@ResponseBody
|
||||
public Res confirmOrder(@RequestBody JSONObject params) {
|
||||
@@ -261,4 +381,189 @@ public class OrderController {
|
||||
|
||||
return Res.success(success ? "确认收货成功" : "确认收货失败");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取订单列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/manage/getOrderList")
|
||||
@ResponseBody
|
||||
public Res getOrderList(PageQuery pageQuery, OrderQuery orderQuery) {
|
||||
// 查询分页数据
|
||||
PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize());
|
||||
List<Order> orderList = orderService.getOrderList(orderQuery);
|
||||
PageInfo<Order> orderPageInfo = new PageInfo<>(orderList);
|
||||
List<Order> list = orderPageInfo.getList();
|
||||
List<OrderVO> voList = OrderVO.convertFrom(list);
|
||||
|
||||
// id列 字段名(区分大小写;以VO中的变量名为准)
|
||||
// 新增、修改弹窗时,使用该列作为主键列进行操作
|
||||
String idFieldName = "id";
|
||||
|
||||
// 当前管理页面
|
||||
String pageName = "订单管理";
|
||||
|
||||
// 指定前端表格显示列
|
||||
JSONArray columns = FieldBuilder.create()
|
||||
.add("userId", "userId", "用户ID", "",
|
||||
FieldType.TEXT, SearchType.INPUT, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("orderStatusCode", "orderStatusName", "订单状态", true,
|
||||
FieldType.TEXT, SearchType.SELECT, AddType.CAN_NOT_ADD, EditType.SELECT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, "订单状态",
|
||||
FieldRuleListBuilder.create()
|
||||
.add(FieldRuleBuilder.create("订单状态").required()),
|
||||
null
|
||||
)
|
||||
.add("orderPrice", "orderPrice", "订单价格", "",
|
||||
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("orderDate", "orderDate", "下单时间", "",
|
||||
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("payDate", "payDate", "支付时间", "",
|
||||
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("cancelDate", "cancelDate", "取消时间", "",
|
||||
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("shipDate", "shipDate", "发货时间", "",
|
||||
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("deliverDate", "deliverDate", "送达时间", "",
|
||||
FieldType.TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("expressId", "expressId", "运单号", "",
|
||||
FieldType.TEXT, SearchType.INPUT, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.add("comment", "comment", "发货备注", "",
|
||||
FieldType.LONG_TEXT, SearchType.CAN_NOT_SEARCH, AddType.CAN_NOT_ADD, EditType.CAN_NOT_EDIT,
|
||||
FieldBuilder.SEARCH_PLACEHOLDER_SAME_AS_FIELDNAME,
|
||||
null, null, null, null
|
||||
)
|
||||
.build();
|
||||
|
||||
// 指定需要翻译的字段
|
||||
OrderStatus[] orderStatusList = OrderStatus.values();
|
||||
HashMap<String, String> orderStatusMap = new HashMap<>(orderStatusList.length);
|
||||
for (OrderStatus orderStatus : orderStatusList) {
|
||||
orderStatusMap.put(orderStatus.getValue(), orderStatus.toString());
|
||||
}
|
||||
// build
|
||||
JSONArray fieldMapper = FieldMapperBuilder.create()
|
||||
.add("orderStatusCode", "orderStatusName", orderStatusMap)
|
||||
.build();
|
||||
|
||||
// 拼装返回结果
|
||||
JSONObject map = new JSONObject(6);
|
||||
map.put("total", orderPageInfo.getTotal());
|
||||
map.put("list", voList);
|
||||
map.put("columns", columns);
|
||||
map.put("fieldMapper", fieldMapper);
|
||||
map.put("idFieldName", idFieldName);
|
||||
map.put("pageName", pageName);
|
||||
|
||||
// 返回结果
|
||||
return Res.success(map);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * 编辑订单
|
||||
// *
|
||||
// * @return
|
||||
// */
|
||||
// @PostMapping("/manage/editOrder")
|
||||
// @ResponseBody
|
||||
// public Res editOrder(@ModelAttribute OrderVO OrderVO) {
|
||||
// Order Order = OrderVO.convertTo(OrderVO);
|
||||
//
|
||||
// // 先查询订单是否存在
|
||||
// Order existOrder = orderService.getOrderById(Order.getId());
|
||||
//
|
||||
// if (Order.getId() == null || Order.getId() < 1) {
|
||||
// // 新增订单
|
||||
// if (existOrder != null) {
|
||||
// return Res.error("订单已存在,操作失败");
|
||||
// }
|
||||
//
|
||||
// if (Order.getOrdersName() == null || "".equals(Order.getOrdersName())) {
|
||||
// return Res.error("订单名称不能为空");
|
||||
// }
|
||||
// Order.setId(null);
|
||||
// orderService.addOrder(Order);
|
||||
// } else {
|
||||
// // 修改订单
|
||||
// if (existOrder == null) {
|
||||
// return Res.error("订单不存在,操作失败");
|
||||
// }
|
||||
//
|
||||
// orderService.updateOrder(Order);
|
||||
// }
|
||||
// return Res.success(true);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 关闭订单
|
||||
// *
|
||||
// * @param id
|
||||
// * @return
|
||||
// */
|
||||
// @PostMapping("/manage/deleteOrder")
|
||||
// @ResponseBody
|
||||
// public Res deleteOrder(Long id) {
|
||||
// if (id == null || id <= 0) {
|
||||
// return Res.error("订单不存在,删除失败");
|
||||
// }
|
||||
// // 先查询订单是否存在
|
||||
// Order existOrder = orderService.getOrderById(id);
|
||||
// if (existOrder == null) {
|
||||
// return Res.error("订单不存在,删除失败");
|
||||
// }
|
||||
// boolean b = orderService.deleteOrder(existOrder.getId());
|
||||
// return Res.success(b);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 导出订单列表
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/manage/exportOrderList")
|
||||
@ResponseBody
|
||||
public Res exportOrderList(OrderQuery orderQuery) {
|
||||
List<Order> orderList = orderService.getOrderList(orderQuery);
|
||||
List<OrderVO> orderVOList = OrderVO.convertFrom(orderList);
|
||||
|
||||
// 当前时间
|
||||
Date now = Calendar.getInstance().getTime();
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||
String dateTime = format.format(now);
|
||||
|
||||
HashMap<String, Object> map = new HashMap<>();
|
||||
map.put("list", orderVOList);
|
||||
map.put("sheetName", "订单表-" + System.currentTimeMillis());
|
||||
map.put("fileName", "订单表_导出时间_" + dateTime);
|
||||
|
||||
return Res.success(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -27,13 +27,7 @@ public interface GoodDao {
|
||||
Integer deleteById(Integer id);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Manage
|
||||
public boolean addGood(Good good);
|
||||
|
||||
public boolean updateGood(Good good);
|
||||
|
@@ -2,6 +2,7 @@ package com.cxyxiaomo.epp.shop.dao;
|
||||
|
||||
import com.cxyxiaomo.epp.common.pojo.Order;
|
||||
import com.cxyxiaomo.epp.common.pojo.OrderDetail;
|
||||
import com.cxyxiaomo.epp.common.query.OrderQuery;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -62,6 +63,19 @@ public interface OrderDao {
|
||||
*/
|
||||
int updateOrderStatus(@Param("orderId") Long orderId, @Param("orderStatus") String orderStatus);
|
||||
|
||||
/**
|
||||
* 更新订单发货信息
|
||||
*
|
||||
* @param orderId
|
||||
* @param expressId
|
||||
* @param comment
|
||||
* @return
|
||||
*/
|
||||
int updateOrderShipInfo(@Param("orderId") Long orderId, @Param("expressId") String expressId, @Param("comment") String comment);
|
||||
|
||||
// 根据订单 ID 删除订单信息及订单详情信息
|
||||
int deleteOrderById(Long orderId);
|
||||
boolean deleteOrderById(Long orderId);
|
||||
|
||||
|
||||
public List<Order> getOrderList(OrderQuery orderQuery);
|
||||
}
|
||||
|
@@ -4,6 +4,7 @@ import com.cxyxiaomo.epp.common.enums.OrderStatus;
|
||||
import com.cxyxiaomo.epp.common.pojo.Good;
|
||||
import com.cxyxiaomo.epp.common.pojo.Order;
|
||||
import com.cxyxiaomo.epp.common.pojo.OrderDetail;
|
||||
import com.cxyxiaomo.epp.common.query.OrderQuery;
|
||||
import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
|
||||
import com.cxyxiaomo.epp.common.vo.OrderDetailVO;
|
||||
import com.cxyxiaomo.epp.shop.dao.GoodDao;
|
||||
@@ -132,4 +133,15 @@ public class OrderService {
|
||||
int affectRows = orderDao.updateOrderStatus(orderId, orderStatus.getValue());
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
public Boolean updateOrderShipInfo(Long orderId, String expressId, String comment) {
|
||||
int affectRows = orderDao.updateOrderShipInfo(orderId, expressId, comment);
|
||||
return affectRows > 0;
|
||||
}
|
||||
|
||||
|
||||
public List<Order> getOrderList(OrderQuery orderQuery) {
|
||||
return orderDao.getOrderList(orderQuery);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -95,7 +95,7 @@
|
||||
</update>
|
||||
|
||||
<!-- 根据订单 ID 删除订单信息及订单详情信息 -->
|
||||
<delete id="deleteOrderById" parameterType="java.lang.Integer">
|
||||
<delete id="deleteOrderById" parameterType="java.lang.Long">
|
||||
DELETE
|
||||
FROM `order`
|
||||
WHERE id = #{orderId};
|
||||
@@ -104,4 +104,39 @@
|
||||
-- FROM goods_order_details
|
||||
-- WHERE order_id = #{orderId};
|
||||
</delete>
|
||||
|
||||
|
||||
<!-- manage 相关的 SQL -->
|
||||
<select id="getOrderList" resultType="com.cxyxiaomo.epp.common.pojo.Order"
|
||||
parameterType="com.cxyxiaomo.epp.common.query.OrderQuery">
|
||||
SELECT * FROM `order`
|
||||
<where>
|
||||
<if test="id != null">
|
||||
AND id = #{id}
|
||||
</if>
|
||||
<if test="userId != null">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
<if test="orderStatusCode != null and orderStatusCode != ''">
|
||||
AND order_status = #{orderStatusCode}
|
||||
</if>
|
||||
<if test="expressId != null and expressId != ''">
|
||||
AND express_id = #{expressId}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<!-- 更新发货信息 -->
|
||||
<update id="updateOrderShipInfo" parameterType="com.cxyxiaomo.epp.common.pojo.Order">
|
||||
UPDATE `order`
|
||||
<set>
|
||||
<if test="expressId != null">
|
||||
express_id = #{expressId},
|
||||
</if>
|
||||
<if test="comment != null">
|
||||
`comment` = #{comment},
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{orderId}
|
||||
</update>
|
||||
</mapper>
|
||||
|
Reference in New Issue
Block a user