|
|
@@ -0,0 +1,214 @@
|
|
|
+package com.study.mall.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.study.mall.common.exception.BizCodeEnum;
|
|
|
+import com.study.mall.common.exception.RRException;
|
|
|
+import com.study.mall.common.utils.CommonResult;
|
|
|
+import com.study.mall.common.utils.PageParam;
|
|
|
+import com.study.mall.common.utils.PageUtils;
|
|
|
+import com.study.mall.dto.AdminOrderQueryDTO;
|
|
|
+import com.study.mall.dto.ConfirmOrderDTO;
|
|
|
+import com.study.mall.dto.CreateOrderDTO;
|
|
|
+import com.study.mall.dto.OrderModifyPriceDTO;
|
|
|
+import com.study.mall.dto.OrderRefundDTO;
|
|
|
+import com.study.mall.dto.OrderStatisticsQueryDTO;
|
|
|
+import com.study.mall.service.OrderInfoService;
|
|
|
+import com.study.mall.vo.ConfirmOrderVO;
|
|
|
+import com.study.mall.vo.CreateOrderVO;
|
|
|
+import com.study.mall.vo.OrderDetailForAdminVO;
|
|
|
+import com.study.mall.vo.OrderDetailForUserVO;
|
|
|
+import com.study.mall.vo.OrderListForAdminVO;
|
|
|
+import com.study.mall.vo.OrderListForUserVO;
|
|
|
+import com.study.mall.vo.OrderStatisticsVO;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.PutMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 订单
|
|
|
+ *
|
|
|
+ * @author codingliang
|
|
|
+ * @email codingliang@gmail.com
|
|
|
+ * @date 2023-09-01 09:43:35
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+@RequestMapping("order")
|
|
|
+public class OrderController {
|
|
|
+
|
|
|
+ private final OrderInfoService orderInfoService;
|
|
|
+
|
|
|
+ public OrderController(OrderInfoService orderInfoService) {
|
|
|
+ this.orderInfoService = orderInfoService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认订单
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("user/order/confirm")
|
|
|
+ public CommonResult<ConfirmOrderVO> confirmOrder(@RequestBody @Validated ConfirmOrderDTO dto) {
|
|
|
+ if ("1".equals(dto.getType())) {
|
|
|
+ if (ObjectUtil.hasEmpty(dto.getGoodId(), dto.getNum())) {
|
|
|
+ throw new RRException(BizCodeEnum.PARAMETER_ERROR, "商品id、数量不能为空");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ConfirmOrderVO confirmOrder = orderInfoService.confirmOrder(dto);
|
|
|
+ return CommonResult.ok().setResult(confirmOrder);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 提交订单
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @PostMapping("user/order/submit")
|
|
|
+ public CommonResult<CreateOrderVO> submitOrder(@RequestBody @Validated CreateOrderDTO dto) {
|
|
|
+ CreateOrderVO vo = orderInfoService.submitOrder(dto);
|
|
|
+
|
|
|
+ return CommonResult.ok().setResult(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单列表(app端)
|
|
|
+ * @param orderState 订单状态,默认为7
|
|
|
+ * @apiNote 订单列表(app端),orderState可选值:1等待付款、2等待发货、3等待收货、4等待评论、5完成、7全部
|
|
|
+ */
|
|
|
+ @GetMapping("user/list")
|
|
|
+ public CommonResult<PageUtils<OrderListForUserVO>> userPage(PageParam pageParam, @RequestParam(defaultValue = "7") String orderState){
|
|
|
+ PageUtils page = orderInfoService.userPage(pageParam, orderState);
|
|
|
+
|
|
|
+ return CommonResult.ok().setResult(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单详情
|
|
|
+ * @param id 订单id
|
|
|
+ * @apiNote 用户端订单详情
|
|
|
+ */
|
|
|
+ @GetMapping("user/info/{id}")
|
|
|
+ public CommonResult<OrderDetailForUserVO> orderDetailForUser(@PathVariable("id") Long id){
|
|
|
+ OrderDetailForUserVO vo = orderInfoService.orderDetailForUser(id);
|
|
|
+
|
|
|
+ return CommonResult.ok().setResult(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 取消订单
|
|
|
+ * @param id 订单id
|
|
|
+ * @return
|
|
|
+ * @apiNote 用户端取消订单,注意订单支付后不可取消
|
|
|
+ */
|
|
|
+ @PutMapping("user/cancel/{id}")
|
|
|
+ public CommonResult<Void> cancelOrder(@PathVariable("id") Long id) {
|
|
|
+ orderInfoService.cancelOrder(id);
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 确认收货
|
|
|
+ * @param id 订单id
|
|
|
+ * @return
|
|
|
+ * @apiNote 用户确认收货
|
|
|
+ */
|
|
|
+ @PutMapping("user/receipt/{id}")
|
|
|
+ public CommonResult<Void> receiptOrder(@PathVariable("id") Long id) {
|
|
|
+ orderInfoService.receiptOrder(id);
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 申请退款
|
|
|
+ * @param id 订单id
|
|
|
+ * @return
|
|
|
+ * @apiNote 用户申请退款,只有待发货状态的订单才能申请退款
|
|
|
+ */
|
|
|
+ @PutMapping("user/apply/refund/{id}")
|
|
|
+ public CommonResult<Void> applyRefund(@PathVariable("id") Long id, @RequestBody OrderRefundDTO refundDTO) {
|
|
|
+ orderInfoService.applyRefund(id, refundDTO);
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除订单
|
|
|
+ * @param id 订单id
|
|
|
+ * @apiNote 用户端删除订单,注意订单在取消状态下才能被删除
|
|
|
+ */
|
|
|
+ @DeleteMapping("user/delete/{id}")
|
|
|
+ public CommonResult<Void> deleteOrder(@PathVariable("id") Long id){
|
|
|
+ orderInfoService.deleteOrder(id);
|
|
|
+
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单列表(管理端)
|
|
|
+ * @param pageParam
|
|
|
+ * @param queryDTO 查询参数
|
|
|
+ * @return 管理端查询订单列表
|
|
|
+ */
|
|
|
+ @GetMapping("admin/list")
|
|
|
+ public CommonResult<PageUtils<OrderListForAdminVO>> adminPage(PageParam pageParam, AdminOrderQueryDTO queryDTO){
|
|
|
+ PageUtils page = orderInfoService.adminPage(pageParam, queryDTO);
|
|
|
+
|
|
|
+ return CommonResult.ok().setResult(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单详情(管理端)
|
|
|
+ * @param id 订单id
|
|
|
+ * @return 管理端查询订单详情
|
|
|
+ */
|
|
|
+ @GetMapping("admin/info/{id}")
|
|
|
+ public CommonResult<OrderDetailForAdminVO> orderDetailForAdmin(@PathVariable Long id){
|
|
|
+ OrderDetailForAdminVO vo = orderInfoService.orderDetailForAdmin(id);
|
|
|
+
|
|
|
+ return CommonResult.ok().setResult(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单统计
|
|
|
+ * @param queryDTO 查询条件
|
|
|
+ * @return
|
|
|
+ * @apiNote 查询指定范围时间内订指定状态的所有订单总金额。state可选值:2等待发货、3等待收货、4等待评论、5完成,如果不传,则查询所有状态为2、3、4、5的所有订单总金额
|
|
|
+ */
|
|
|
+ @GetMapping("admin/order-statistics")
|
|
|
+ public CommonResult<OrderStatisticsVO> orderStatistics(OrderStatisticsQueryDTO queryDTO) {
|
|
|
+ OrderStatisticsVO vo = orderInfoService.orderStatistics(queryDTO);
|
|
|
+ return CommonResult.ok().setResult(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单改价(管理端)
|
|
|
+ * @param modifyPriceDTO
|
|
|
+ * @return
|
|
|
+ * @apiNote 只有待付款状态下的订单才能改价
|
|
|
+ */
|
|
|
+ @PutMapping("admin/modify-price")
|
|
|
+ public CommonResult<OrderDetailForAdminVO> modifyPrice(@RequestBody @Validated OrderModifyPriceDTO modifyPriceDTO){
|
|
|
+ orderInfoService.modifyPrice(modifyPriceDTO);
|
|
|
+
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 订单商品列表
|
|
|
+ * @param id 订单id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("admin/order/goods/{id}")
|
|
|
+ public CommonResult<List<OrderListForUserVO.OrderDetailVO>> orderGoods(@PathVariable Long id) {
|
|
|
+ List<OrderListForUserVO.OrderDetailVO> vo = orderInfoService.orderGoodsList(id);
|
|
|
+ return CommonResult.ok().setResult(vo);
|
|
|
+ }
|
|
|
+}
|