194 lines
8.2 KiB
Java
194 lines
8.2 KiB
Java
package cn.unizk.controller;
|
|
|
|
import cn.unizk.entity.po.*;
|
|
import cn.unizk.entity.vo.*;
|
|
import cn.unizk.enums.OrderAfterSaleStatus;
|
|
import cn.unizk.enums.OrderStatus;
|
|
import cn.unizk.enums.PlatformType;
|
|
import cn.unizk.exception.ServiceException;
|
|
import cn.unizk.mapper.MobileAppUserMapper;
|
|
import cn.unizk.mapper.MobileOrderItemMapper;
|
|
import cn.unizk.mapper.OrderReviewMapper;
|
|
import cn.unizk.service.ComboService;
|
|
import cn.unizk.service.ProductService;
|
|
import cn.unizk.service.SysOrderService;
|
|
import cn.unizk.utils.BeanCopyUtils;
|
|
import cn.unizk.utils.SecurityUtils;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import javax.annotation.Resource;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* @Author hao
|
|
* @Date 2025/9/4 18:16
|
|
* @Version 1.0
|
|
**/
|
|
@RestController
|
|
@RequestMapping("/pc/admin")
|
|
public class AdminOrderController {
|
|
|
|
@Resource
|
|
private SysOrderService sysOrderService;
|
|
@Resource
|
|
private ComboService comboService;
|
|
@Resource
|
|
private MobileOrderItemMapper mobileOrderItemMapper;
|
|
@Resource
|
|
private ProductService productService;
|
|
@Resource
|
|
private MobileAppUserMapper mobileAppUserMapper;
|
|
@Resource
|
|
private OrderReviewMapper reviewMapper;
|
|
|
|
@PostMapping("/orders")
|
|
public Page<MobileOrderVO> orders(@RequestBody UniPage<OrderReqVO> uniPage) {
|
|
return sysOrderService.orderList(uniPage);
|
|
|
|
}
|
|
|
|
@PostMapping("/editOrder")
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public ResultData editOrder(@RequestParam("orderId") String orderId, @RequestParam("optionType") Integer optionType) {
|
|
|
|
MobileOrder wxOrder = sysOrderService.getById(orderId);
|
|
if (Objects.isNull(wxOrder)) {
|
|
throw new ServiceException("该订单不存在");
|
|
}
|
|
if (optionType == 1) {
|
|
//发货
|
|
if (!OrderStatus.paid.name().equals(wxOrder.getStatus())) {
|
|
throw new ServiceException(String.format("%s状态订单不支持发货", OrderStatus.valueOf(wxOrder.getStatus()).getValue()));
|
|
}
|
|
if (wxOrder.getProductId() == null) {
|
|
throw new ServiceException("该订单商品为非实体商品,不支持发货");
|
|
}
|
|
wxOrder.setStatus(OrderStatus.shipped.name());
|
|
sysOrderService.updateById(wxOrder);
|
|
}
|
|
if (optionType == 2) {
|
|
//核销
|
|
if (!OrderStatus.paid.name().equals(wxOrder.getStatus()) && !OrderStatus.unverified.name().equals(wxOrder.getStatus())) {
|
|
throw new ServiceException(String.format("%s状态订单不支持核销", OrderStatus.valueOf(wxOrder.getStatus()).getValue()));
|
|
}
|
|
if (wxOrder.getComboId() == null) {
|
|
throw new ServiceException("该订单商品为实体商品,不支持核销");
|
|
}
|
|
wxOrder.setStatus(OrderStatus.verified.name());
|
|
sysOrderService.updateById(wxOrder);
|
|
}
|
|
/*if (optionType == 3){
|
|
if (!OrderStatus.request_refund.name().equals(wxOrder.getStatus())){
|
|
throw new ServiceException("该订单非申请退款,不能做退款操作!");
|
|
}
|
|
if (OrderStatus.refunded.name().equals(wxOrder.getStatus())){
|
|
throw new ServiceException("该订单已做退款处理");
|
|
}
|
|
wxOrder.setStatus(OrderStatus.refunded.name());
|
|
sysOrderService.updateById(wxOrder);
|
|
}*/
|
|
return ResultData.success();
|
|
}
|
|
|
|
@GetMapping("/getOrderStatistics")
|
|
public Map<String, Long> getOrderStatistics() {
|
|
List<MobileOrder> wxOrders = sysOrderService.getBaseMapper().selectList(null);
|
|
Map<String, Long> map = new HashMap<>();
|
|
map.put("A", (long) wxOrders.size());
|
|
long p = wxOrders.stream().filter(o -> o.getStoreId() == null).count();
|
|
map.put("P", p);
|
|
long s = wxOrders.stream().filter(o -> o.getStoreId() != null).count();
|
|
map.put("S", s);
|
|
return map;
|
|
}
|
|
|
|
@GetMapping("/orderDetail")
|
|
public MobileOrderDetailVO detail(@RequestParam("orderId") String orderId) {
|
|
MobileOrderDetailVO vo = new MobileOrderDetailVO();
|
|
MobileOrder wxOrder = sysOrderService.getById(orderId);
|
|
BeanUtils.copyProperties(wxOrder, vo);
|
|
if (vo.getComboId() != null) {
|
|
List<MobileOrderItemVO> list = new ArrayList<>();
|
|
Combo combo = comboService.getById(vo.getComboId());
|
|
MobileOrderItemVO product = new MobileOrderItemVO();
|
|
product.setImage(combo.getImage());
|
|
product.setProductName(combo.getComboName());
|
|
product.setSingleProductPrice(combo.getComboPrice());
|
|
list.add(product);
|
|
vo.setOrderItemVOS(list);
|
|
} else {
|
|
List<MobileOrderItem> wxOrderItems = mobileOrderItemMapper.selectList(new LambdaQueryWrapper<MobileOrderItem>().eq(MobileOrderItem::getMobileOrderId, vo.getOrderId()));
|
|
if (CollectionUtils.isNotEmpty(wxOrderItems)){
|
|
Collection<MobileOrderItemVO> itemVOS = BeanCopyUtils.copyArrays(wxOrderItems, MobileOrderItemVO::new);
|
|
for (MobileOrderItemVO itemVO : itemVOS) {
|
|
if (itemVO.getProductId() == null) {
|
|
continue;
|
|
}
|
|
JkProduct jkProduct = productService.getById(itemVO.getProductId());
|
|
itemVO.setProductName(jkProduct.getProductName());
|
|
itemVO.setImage(jkProduct.getProductImage());
|
|
itemVO.setSingleProductPrice(jkProduct.getProductPrice());
|
|
}
|
|
vo.setOrderItemVOS((List<MobileOrderItemVO>) itemVOS);
|
|
}
|
|
}
|
|
MobileAppUser one = mobileAppUserMapper.selectById(vo.getMobileUserId());
|
|
vo.setMobileAppUser(one);
|
|
return vo;
|
|
}
|
|
|
|
@PostMapping("/agreeRefund")
|
|
public ResultData refund(@RequestParam("orderId") String orderId,@RequestParam("platformType") String platformType) {
|
|
if (!PlatformType.WECHAT_MP.name().equals(platformType) && !PlatformType.APP.name().equals(platformType)){
|
|
throw new ServiceException("未知的平台类型");
|
|
}
|
|
return sysOrderService.agreeRefund(orderId,platformType);
|
|
}
|
|
|
|
@PostMapping("/afterSales")
|
|
public Page<MobileOrderVO> afterSales(@RequestBody UniPage<OrderReqVO> uniPage) {
|
|
return sysOrderService.afterSale(uniPage);
|
|
}
|
|
|
|
@GetMapping("/getDeliveryTotal")
|
|
public Map<String, Long> getDeliveryTotal() {
|
|
SysUser sysUser = SecurityUtils.getSysUser();
|
|
Map<String, Long> map = new HashMap<>();
|
|
Long ps = sysOrderService.getBaseMapper().selectCount(new LambdaQueryWrapper<MobileOrder>().eq(MobileOrder::getDeliveryWay, "配送")
|
|
.eq(MobileOrder::getAfterSaleStatus, 0));
|
|
map.put("配送", ps);
|
|
Long zt = sysOrderService.getBaseMapper().selectCount(new LambdaQueryWrapper<MobileOrder>().eq(MobileOrder::getDeliveryWay, "自提")
|
|
.eq(MobileOrder::getAfterSaleStatus, 0));
|
|
map.put("核销", zt);
|
|
return map;
|
|
}
|
|
|
|
@PostMapping("/refundRefusal")
|
|
public boolean refundRefusal(@RequestBody MobileOrder order) {
|
|
MobileOrder wxOrder = sysOrderService.getById(order.getOrderId());
|
|
if (Objects.isNull(wxOrder)) {
|
|
throw new ServiceException("无此订单");
|
|
}
|
|
wxOrder.setRejectReason(order.getRejectReason());
|
|
wxOrder.setAfterSaleStatus(OrderAfterSaleStatus.REJECT_TUI_KUAN.getKey());
|
|
return sysOrderService.updateById(wxOrder);
|
|
}
|
|
|
|
@GetMapping("/getOrderReview")
|
|
public List<OrderReview> getOrderReview(@RequestParam("orderId") String orderId) {
|
|
return reviewMapper.selectList(new LambdaQueryWrapper<OrderReview>().eq(OrderReview::getOrderId, orderId));
|
|
}
|
|
|
|
/* @PostMapping("/appOrders")
|
|
public Page<MobileOrderVO> appOrders(@RequestBody UniPage<OrderReqVO> uniPage) {
|
|
Page<MobileOrderVO> page = (Page<MobileOrderVO>) uniPage.getPage();
|
|
return page;
|
|
}*/
|
|
|
|
}
|