From 4b55eb4a50938ace45b2b2266caa0ce2aadfcd40 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 02 六月 2025 16:39:18 +0800
Subject: [PATCH] 小程序接口 详情

---
 ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/OrderController.java |  123 +++++++++++++++++++++-------------------
 1 files changed, 65 insertions(+), 58 deletions(-)

diff --git a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/OrderController.java b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/OrderController.java
index f9b70b9..4b98514 100644
--- a/ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/OrderController.java
+++ b/ruoyi-applet/src/main/java/com/ruoyi/web/controller/system/OrderController.java
@@ -1,9 +1,7 @@
 package com.ruoyi.web.controller.system;
 
 
-import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
 import com.github.binarywang.wxpay.exception.WxPayException;
@@ -25,9 +23,6 @@
 import org.springframework.web.bind.annotation.*;
 
 import javax.validation.Valid;
-import java.io.UnsupportedEncodingException;
-import java.math.BigDecimal;
-import java.net.MalformedURLException;
 
 @Slf4j
 @RestController
@@ -57,15 +52,16 @@
     @Autowired
     private TbAccountDetailService accountDetailService;
 
+    @Autowired
+    private TbUserService userService;
 
 
-
-    @ApiOperation(value = "获取我的订单",tags = {"订单模块"})
+    @ApiOperation(value = "获取我的订单", tags = {"订单模块"})
     @GetMapping("/getMyOrderList")
     public R<Page<MyPushCompanyListVo>> getMyOrderList(MyOrderListQuery query) {
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
-        Page<MyPushCompanyListVo> page = orderService.getMyOrderList(query,userId);
+        Page<MyPushCompanyListVo> page = orderService.getMyOrderList(query, userId);
         return R.ok(page);
     }
 
@@ -75,109 +71,126 @@
      * @param
      * @return
      */
-    @ApiOperation(value = "立即支付前填写信息",tags = {"订单模块"})
+    @ApiOperation(value = "立即支付前填写信息", tags = {"订单模块"})
     @PostMapping("/lastPayOrderData")
     public R<?> lastPayOrderData(@RequestBody @Valid AddBuyerCompanyInfoDto dto) {
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbOrder tbOrder = orderService.getById(dto.getOrderId());
 
-        if(dto.getNeedRename()==1){
-            if(StringUtils.isEmpty(dto.getBackupsName())){
+        if (dto.getNeedRename() == 1) {
+            if (StringUtils.isEmpty(dto.getBackupsName())) {
                 return R.fail("请填写备选名称");
             }
         }
 
-        if(!tbOrder.getUserId().equals(userId.toString())){
+        if (!tbOrder.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
-        if(tbOrder.getStatus()!=3){
+        if (tbOrder.getStatus() != 3) {
             return R.fail("订单状态错误");
         }
         TbCompany company = companyService.getById(tbOrder.getCompanyId());
         // 判断是否在支付前下架了  或者删除了
-        if(company==null || company.getStatus()!=1 || company.getIsDelete()==1){
+        if (company == null || company.getStatus() == 2 || company.getIsDelete() == 1) {
             return R.fail("该公司已下架或者删除");
         }
         long count = buyerCompanyInfoService.count(new LambdaQueryWrapper<TbBuyerCompanyInfo>().eq(TbBuyerCompanyInfo::getOrderId, dto.getOrderId()));
-        if(count>0){
+        if (count > 0) {
             return R.fail("请勿重复填写");
         }
-        orderService.lastPayOrderData(tbOrder,dto,userId,company);
+        orderService.lastPayOrderData(tbOrder, dto, userId, company);
         return R.ok();
     }
 
 
-
-    @ApiOperation(value = "立即支付",tags = {"订单模块"})
+    @ApiOperation(value = "立即支付", tags = {"订单模块"})
     @PostMapping("/payOrder")
     public R<WxPayMpOrderResult> payOrder(String orderId) {
-         if(StringUtils.isEmpty(orderId)){
+        if (StringUtils.isEmpty(orderId)) {
             R.fail("订单id不能为空");
         }
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbOrder tbOrder = orderService.getById(orderId);
-        if(!tbOrder.getUserId().equals(userId.toString())){
+        if (!tbOrder.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
-        if(tbOrder.getStatus()!=3){
+
+        TbUser user = userService.getById(userId);
+        if(StringUtils.isEmpty(user.getOpenId())){
+            return R.fail(602,"需要授权微信小程序");
+        }
+
+        if (tbOrder.getStatus() != 3) {
             return R.fail("订单状态错误");
         }
         TbCompany company = companyService.getById(tbOrder.getCompanyId());
         // 判断是否在支付前下架了  或者删除了
-        if(company==null || company.getStatus()!=1 || company.getIsDelete()==1){
+        if (company == null || company.getStatus() == 2 || company.getIsDelete() == 1) {
             return R.fail("该公司已下架或者删除");
         }
-        long count = buyerCompanyInfoService.count(new LambdaQueryWrapper<TbBuyerCompanyInfo>().eq(TbBuyerCompanyInfo::getOrderId,orderId));
-        if(count==0){
+        long count = buyerCompanyInfoService.count(new LambdaQueryWrapper<TbBuyerCompanyInfo>().eq(TbBuyerCompanyInfo::getOrderId, orderId));
+        if (count == 0) {
             return R.fail("请先填写信息");
         }
-        WxPayMpOrderResult result = orderService.payOrder(tbOrder,userId);
+        WxPayMpOrderResult result = orderService.payOrder(tbOrder, userId);
         return R.ok(result);
     }
 
 
-
-    @ApiOperation(value = "下单预定",tags = {"订单模块"})
+    @ApiOperation(value = "下单预定", tags = {"订单模块"})
     @PostMapping("/placeOrder")
     public synchronized R<?> placeOrder(String companyId) {
-        if(StringUtils.isEmpty(companyId)){
+        if (StringUtils.isEmpty(companyId)) {
             R.fail("id不能为空");
         }
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         // 查看现在是否可以单 判断这个公司是否上架  是否已经产生的了订单
         TbCompany company = companyService.getById(companyId);
-        if(company.getStatus()!=1){
+        if (company == null) {
+            return R.fail("公司不存在");
+        }
+        if (company.getUserId().equals(userId.toString())) {
+            return R.fail("不能预定自己发布的公司");
+        }
+
+        if (company.getStatus() == 2) {
             return R.fail("公司未上架");
         }
+        if (company.getStatus() == 3) {
+            return R.fail("公司已售卖");
+        }
+        if (company.getStatus() == 4) {
+            return R.fail("公司已被预定");
+        }
 //        long count = orderService.count(new LambdaQueryWrapper<TbOrder>().eq(TbOrder::getCompanyId, companyId).ne(TbOrder::getStatus, -1));
-        if (company.getStatus()==4) {
+        if (company.getStatus() == 4) {
             return R.fail("改公司已被预定");
         }
-        orderService.placeOrder(companyId,company,userId);
+        orderService.placeOrder(companyId, company, userId);
         return R.ok();
     }
 
 
-    @ApiOperation(value = "买家完成订单",tags = {"订单模块"})
+    @ApiOperation(value = "买家完成订单", tags = {"订单模块"})
     @PostMapping("/buyerSuccessOrder")
     public synchronized R<?> buyerSuccessOrder(String orderId) {
-        if(StringUtils.isEmpty(orderId)){
+        if (StringUtils.isEmpty(orderId)) {
             R.fail("订单id不能为空");
         }
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbOrder order = orderService.getById(orderId);
-        if(order==null){
+        if (order == null) {
             return R.fail("订单不存在");
         }
         TbCompany company = companyService.getById(order.getCompanyId());
         if (!order.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
-        if(order.getStatus()!=5){
+        if (order.getStatus() != 5) {
             return R.fail("该订单状态不能完成");
         }
         // 订单完成  商品已售卖
@@ -186,8 +199,7 @@
         company.setStatus(3);
 
         // 分佣
-        orderService.commission(order,company.getUserId());
-
+        orderService.commission(order, company.getUserId());
 
         // 卖家账户明细记录更新
         TbAccountDetail one = accountDetailService.getOne(new LambdaQueryWrapper<TbAccountDetail>().eq(TbAccountDetail::getOrderId, orderId).eq(TbAccountDetail::getCategory, 2));
@@ -202,46 +214,46 @@
     }
 
 
-    @ApiOperation(value = "买家回复进度",tags = {"订单模块"})
+    @ApiOperation(value = "买家回复进度", tags = {"订单模块"})
     @PostMapping("/buyerAddSchedule")
     public synchronized R<?> buyerAddSchedule(@RequestBody @Valid AddScheduleDto dto) {
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbOrder order = orderService.getById(dto.getOrderId());
-        if(order==null){
+        if (order == null) {
             return R.fail("订单不存在");
         }
         if (!order.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
-        if(order.getStatus()!=4){
+        if (order.getStatus() != 4) {
             return R.fail("该订单状态不能回复");
         }
-        scheduleService.buyerAddSchedule(dto,userId);
+        scheduleService.buyerAddSchedule(dto, userId);
         String userId1 = companyService.getById(order.getCompanyId()).getUserId();
 
-        messageService.addMessage("您的订单有新的回复", userId1,order.getId());
+        messageService.addMessage("您的订单有新的回复", userId1, order.getId());
         return R.ok();
 
     }
 
 
-    @ApiOperation(value = "买家取消订单",tags = {"订单模块"})
+    @ApiOperation(value = "买家取消订单", tags = {"订单模块"})
     @PostMapping("/buyerCancelOrder")
     public synchronized R<?> buyerCancelOrder(String orderId) {
-        if(StringUtils.isEmpty(orderId)){
+        if (StringUtils.isEmpty(orderId)) {
             R.fail("订单id不能为空");
         }
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbOrder order = orderService.getById(orderId);
-        if(order==null){
+        if (order == null) {
             return R.fail("订单不存在");
         }
         if (!order.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
-        if(order.getStatus()!=3){
+        if (order.getStatus() != 3) {
             return R.fail("该订单状态不能取消");
         }
         TbCompany company = companyService.getById(order.getCompanyId());
@@ -250,23 +262,22 @@
         order.setStatus(-1);
         order.updateById();
 
-        messageService.addMessage("您发布的订单买家已取消", company.getUserId(),order.getId());
+        messageService.addMessage("您发布的订单买家已取消", company.getUserId(), order.getId());
         return R.ok();
 
     }
 
 
-
-    @ApiOperation(value = "编辑办理进度",tags = {"发布模块"})
+    @ApiOperation(value = "编辑办理进度", tags = {"发布模块"})
     @PostMapping("/updateSchedule")
     public R<?> updateSchedule(@RequestBody @Valid EditScheduleDto dto) {
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbSchedule schedule = scheduleService.getById(dto.getScheduleId());
-        if(schedule==null){
+        if (schedule == null) {
             return R.fail("进度不存在");
         }
-        if(!schedule.getUserId().equals(userId.toString())){
+        if (!schedule.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
         schedule.setText(dto.getText());
@@ -276,24 +287,21 @@
     }
 
 
-    @ApiOperation(value = "删除办理进度",tags = {"发布模块"})
+    @ApiOperation(value = "删除办理进度", tags = {"发布模块"})
     @DeleteMapping("/delSchedule/{scheduleId}")
     public R<?> delSchedule(@PathVariable("scheduleId") String scheduleId) {
         LoginUser loginUser = tokenService.getLoginUser();
         Long userId = loginUser.getUserId();
         TbSchedule schedule = scheduleService.getById(scheduleId);
-        if(schedule==null){
+        if (schedule == null) {
             return R.fail("进度不存在");
         }
-        if(!schedule.getUserId().equals(userId.toString())){
+        if (!schedule.getUserId().equals(userId.toString())) {
             return R.fail("非法操作");
         }
         scheduleService.removeById(scheduleId);
         return R.ok();
     }
-
-
-
 
 
     /**
@@ -308,7 +316,6 @@
             throw new RuntimeException(e);
         }
     }
-
 
 
 }

--
Gitblit v1.7.1