luodangjia
2025-02-07 8ffeb751b3a694e8d1cb6a21bec855f6c49b31b6
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
@@ -9,6 +9,7 @@
import com.ruoyi.account.api.model.UserAddress;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.core.web.page.TableDataInfo;
@@ -29,15 +30,22 @@
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.*;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotBlank;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
@@ -234,18 +242,33 @@
    @PostMapping("/byUserId")
    public R<List<Order>> byUserId(@RequestParam("appUserId") Long appUserId,@RequestParam("shopId") Long shopId){
        return R.ok(orderService.lambdaQuery().eq(Order::getAppUserId, appUserId).eq(Order::getShopId, shopId).list());
    public R<List<Order>> byUserId(@RequestParam("appUserId") Long appUserId,@RequestParam("shopId") Integer shopId){
        List<Order> list = orderService.lambdaQuery()
                .eq(Order::getAppUserId, appUserId)
                .eq(null != shopId && -1 != shopId, Order::getShopId, shopId)
                .eq(Order::getPayStatus, 2)
                .isNull(Order::getRefundStatus)
                .eq(Order::getDelFlag, 0)
                .notIn(Order::getOrderStatus, 5, 6).list();
        return R.ok(list);
    }
    @PostMapping("/byShopId")
    public R<List<Order>> byShopId(@RequestParam("shopId") Integer shopId){
        return R.ok(orderService.lambdaQuery().isNotNull(Order::getEndTime).eq(Order::getShopId, shopId).in(Order::getOrderStatus,4,7,8).list());
        return R.ok(orderService.lambdaQuery().isNotNull(Order::getEndTime).eq(Order::getShopId, shopId).list());
    }
    @PostMapping("/byShopIdAndUserId")
    public R<List<Order>> byShopIdAndUserId(@RequestParam("appUserId") Long appUserId,@RequestParam("shopId") Integer shopId){
        List<Order> list = orderService.lambdaQuery().isNotNull(Order::getEndTime)
                .eq(null != shopId && -1 != shopId, Order::getShopId, shopId)
                .eq(Order::getAppUserId, appUserId)
                .eq(Order::getPayStatus, 2)
                .isNull(Order::getRefundStatus)
                .eq(Order::getDelFlag, 0)
                .notIn(Order::getOrderStatus, 5, 6).list();
        return R.ok(list);
    }
    
    @PostMapping("/confirmDelivery")
    @ApiOperation(value = "已发货操作", tags = {"管理后台-订单管理"})
@@ -297,6 +320,7 @@
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        List<Order> orderList = orderService.list(new LambdaQueryWrapper<Order>()
                        .ne(Order::getOrderStatus,5)
                .eq(sysUser.getRoleType() == 2, Order::getShopId, sysUser.getObjectId())
                .between(Order::getCreateTime, LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")), LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")))
                .orderByAsc(Order::getCreateTime));
@@ -321,14 +345,14 @@
            for (Order order : value) {
                if (order.getOrderType().equals(1)) {
                    serviceTotal++;
                    serviceTotalMoney = serviceTotalMoney.add(order.getPaymentAmount());
                    serviceTotalMoney = serviceTotalMoney.add(order.getTotalAmount());
                    total++;
                    totalMoney = totalMoney.add(order.getPaymentAmount());
                }else if (order.getOrderType().equals(2) && 1 == order.getDistributionMode()){
                    totalMoney = totalMoney.add(order.getTotalAmount());
                }else if (order.getOrderType().equals(2)){
                    singleTotal++;
                    singleTotalMoney = singleTotalMoney.add(order.getPaymentAmount());
                    singleTotalMoney = singleTotalMoney.add(order.getTotalAmount());
                    total++;
                    totalMoney = totalMoney.add(order.getPaymentAmount());
                    totalMoney = totalMoney.add(order.getTotalAmount());
                }
            }
            orderStatisticsDetail.setDate(key);
@@ -355,7 +379,7 @@
                        } catch (ParseException e) {
                            throw new RuntimeException(e);
                        }
                    }).reversed())
                    }))
                    .collect(Collectors.toList());
            orderStatistics.setOrderStatisticsDetailList(sortedDetails);
        }
@@ -492,5 +516,43 @@
        orderService.updateById(order);
        return R.ok();
    }
    /**
     * 导入物流信息
     */
    @PostMapping("/importExpress")
    public R importExpress(@RequestBody String url){
        JSONObject jsonObject = JSONObject.parseObject(url);
        String url2 = jsonObject.getString("url");
        orderService.importExpress(url2);
        return R.ok();
    }
    /**
     * 导出订单信息
     */
    @GetMapping("/exportExpress")
    public void exportExpress(HttpServletResponse response,OrderPageList orderPage){
        PageInfo<OrderPageListVo> orderPageList = orderService.getOrderPageList(orderPage);
        List<OrderPageListVo> list = orderPageList.getRecords();
        ExcelUtil<OrderPageListVo> util = new ExcelUtil<OrderPageListVo>(OrderPageListVo.class);
        util.exportExcel(response, list, "订单数据");
    }
    /**
     * 获取用户订单数量
     * @param appUserId
     * @return
     */
    @PostMapping("/getOrderCountByAppUserId")
    public R<Long> getOrderCountByAppUserId(@RequestParam("id") Long appUserId){
        long count = orderService.count(new LambdaQueryWrapper<Order>().eq(Order::getDelFlag, 0)
                .eq(Order::getAppUserId, appUserId).in(Order::getOrderStatus, Arrays.asList(1, 2, 3, 4, 7, 8))
                .eq(Order::getPayStatus, 2));
        return R.ok(count);
    }
}