From d9b406d014755509639a44807ed10bc357e237ca Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期一, 02 十二月 2024 13:36:01 +0800
Subject: [PATCH] 1.t_app_user_shop表的实现

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java         |   15 +++
 ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserClientFallbackFactory.java |    8 +
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java                   |    9 +
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/OrderService.java                         |    4 
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java                |   62 +++++++++++-
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java             |   18 +++
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderType.java                              |   26 +++++
 ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderStatus.java                            |   32 ++++++
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java              |   57 +++++-----
 ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java  |    5 
 ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java  |   18 +++
 ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java            |   12 ++
 12 files changed, 224 insertions(+), 42 deletions(-)

diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserClientFallbackFactory.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserClientFallbackFactory.java
index 4b8bbb4..050669a 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserClientFallbackFactory.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/factory/AppUserClientFallbackFactory.java
@@ -2,9 +2,12 @@
 
 import com.ruoyi.account.api.feignClient.AppUserClient;
 import com.ruoyi.account.api.model.AppUser;
+import com.ruoyi.account.api.model.AppUserShop;
 import com.ruoyi.common.core.domain.R;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.cloud.openfeign.FallbackFactory;
+
+import java.util.List;
 
 /**
  * @author zhibing.pu
@@ -37,6 +40,11 @@
 				throw new RuntimeException("获取优惠券数量失败");
 			}
 
+			@Override
+			public R<List<AppUserShop>> getAppUserShop(Long userId) {
+				log.error("获取用户门店信息失败:{}", cause.getMessage());
+				throw new RuntimeException("获取用户门店信息失败");
+			}
 		};
 	}
 }
diff --git a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
index 8c625c3..57e4ac5 100644
--- a/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
+++ b/ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/feignClient/AppUserClient.java
@@ -2,11 +2,16 @@
 
 import com.ruoyi.account.api.factory.AppUserClientFallbackFactory;
 import com.ruoyi.account.api.model.AppUser;
+import com.ruoyi.account.api.model.AppUserShop;
 import com.ruoyi.common.core.constant.ServiceNameConstants;
 import com.ruoyi.common.core.domain.R;
 import org.springframework.cloud.openfeign.FeignClient;
+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.RequestParam;
+
+import java.util.List;
 
 /**
  * @author zhibing.pu
@@ -31,4 +36,11 @@
 
 	@PostMapping("/appUser/getCouponCount")
 	R<Long> getCouponCount(@RequestParam("userId")Long userId, @RequestParam("couponId") Integer couponId );
+
+	/**
+	 *  根据用户id查询用户门店信息
+	 */
+	@GetMapping("/appUserShop/shop/{userId}")
+	R<List<AppUserShop>> getAppUserShop(@PathVariable("userId") Long userId);
+
 }
diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java
new file mode 100644
index 0000000..11c9cc9
--- /dev/null
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/TechnicianClientFallbackFactory.java
@@ -0,0 +1,18 @@
+package com.ruoyi.other.api.factory;
+
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.other.api.domain.Technician;
+import com.ruoyi.other.api.feignClient.TechnicianClient;
+import org.springframework.cloud.openfeign.FallbackFactory;
+
+public class TechnicianClientFallbackFactory implements FallbackFactory<TechnicianClient> {
+    @Override
+    public TechnicianClient create(Throwable cause) {
+        return new TechnicianClient() {
+            @Override
+            public R<Technician> shopdetail(Integer techId) {
+                return R.fail("根据省市区获取地区价格配置失败:" + cause.getMessage());
+            }
+        };
+    }
+}
diff --git a/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java
new file mode 100644
index 0000000..5095d9b
--- /dev/null
+++ b/ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/TechnicianClient.java
@@ -0,0 +1,18 @@
+package com.ruoyi.other.api.feignClient;
+
+import com.ruoyi.common.core.constant.ServiceNameConstants;
+import com.ruoyi.common.core.domain.R;
+import com.ruoyi.other.api.domain.Technician;
+import com.ruoyi.other.api.factory.SystemConfigClientFallbackFactory;
+import com.ruoyi.other.api.factory.TechnicianClientFallbackFactory;
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+
+@FeignClient(contextId = "TechnicianClient", value = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = TechnicianClientFallbackFactory.class)
+public interface TechnicianClient {
+
+    @PostMapping("/technician/shop/detail")
+    R<Technician> shopdetail(@RequestParam Integer techId);
+}
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java
index 972475d..320d19b 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserShopController.java
@@ -1,6 +1,13 @@
 package com.ruoyi.account.controller;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.ruoyi.account.api.model.AppUserShop;
+import com.ruoyi.account.service.AppUserShopService;
+import com.ruoyi.common.core.domain.R;
 import org.springframework.web.bind.annotation.*;
+
+import javax.annotation.Resource;
+import java.util.List;
 
 
 /**
@@ -10,6 +17,14 @@
 @RestController
 @RequestMapping("/appUserShop")
 public class AppUserShopController {
+    @Resource
+    private AppUserShopService appUserShopService;
+
+    @GetMapping("/shop/{userId}")
+    public R<List<AppUserShop>> getAppUserShop(@PathVariable("userId") Long userId) {
+		return R.ok(appUserShopService.list(new LambdaQueryWrapper<AppUserShop>()
+                .eq(AppUserShop::getAppUserId,userId)));
+	}
 	
 
 	
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
index 7a8f0ab..a0873b2 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/controller/OrderController.java
@@ -1,6 +1,7 @@
 package com.ruoyi.order.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.order.service.OrderService;
@@ -11,6 +12,7 @@
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
+import model.Order;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -70,8 +72,11 @@
             @ApiImplicitParam(value = "分享id", name = "shareId", required = true, dataType = "int", paramType="query"),
     })
     @GetMapping("/check/{orderNumber}/{shopId}")
-    public R<Boolean> check(@PathVariable("orderNumber") String orderNumber, @PathVariable("shopId") Long shopId){
-        return R.ok(orderService.check(orderNumber, shopId));
+    public R<Boolean> check(@PathVariable("orderNumber") String orderNumber, @PathVariable("shopId") Integer shopId){
+        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+        Order order = orderService.getOne(new LambdaQueryWrapper<Order>()
+                .eq(Order::getOrderNumber, orderNumber));
+        return R.ok(orderService.check(order, shopId, loginUserApplet.getUserid()));
     }
 
     /**
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderStatus.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderStatus.java
new file mode 100644
index 0000000..c8cfe81
--- /dev/null
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderStatus.java
@@ -0,0 +1,32 @@
+package com.ruoyi.order.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum OrderStatus {
+    PENDING_SHIPMENT(1, "待发货"),
+    PENDING_RECEIPT(2, "待收货"),
+    PENDING_USE(3, "待使用"),
+    COMPLETED(4, "已完成"),
+    CANCELLED(5, "已取消"),
+    REFUNDED(6, "已退款"),
+    AFTER_SALE(7, "售后中");
+
+    private final int code;
+    private final String description;
+
+    OrderStatus(int code, String description) {
+        this.code = code;
+        this.description = description;
+    }
+
+    // 根据代码获取对应的OrderStatus
+    public static OrderStatus fromCode(int code) {
+        for (OrderStatus status : values()) {
+            if (status.getCode() == code) {
+                return status;
+            }
+        }
+        throw new IllegalArgumentException("Unknown order status code: " + code);
+    }
+}
\ No newline at end of file
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderType.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderType.java
new file mode 100644
index 0000000..c3a581f
--- /dev/null
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/enums/OrderType.java
@@ -0,0 +1,26 @@
+package com.ruoyi.order.enums;
+
+import lombok.Getter;
+
+@Getter
+public enum OrderType {
+    SERVICE(1, "服务单"),
+    GOOD(2, "商品单");
+
+    private final int code;
+    private final String description;
+
+    OrderType(int code, String description) {
+        this.code = code;
+        this.description = description;
+    }
+
+    public static OrderType fromCode(int code) {
+        for (OrderType type : OrderType.values()) {
+            if (type.getCode() == code) {
+                return type;
+            }
+        }
+        return null;
+    }
+}
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/OrderService.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/OrderService.java
index 6161981..60fda94 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/OrderService.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/OrderService.java
@@ -20,7 +20,7 @@
 
     OrderDetailVO getOrderDetail(Long orderId);
 
-    boolean check(String orderNumber, Long shopId);
+    boolean check(Order order, Integer shopId, Long userId);
 
-    void writeOff(String code);
+    void writeOff(String code,Integer shopId);
 }
diff --git a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
index d67a708..9155cbc 100644
--- a/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
+++ b/ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java
@@ -3,9 +3,15 @@
 import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.account.api.feignClient.AppUserClient;
+import com.ruoyi.account.api.model.AppUserShop;
 import com.ruoyi.account.api.model.UserAddress;
+import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.exception.ServiceException;
 import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.common.security.service.TokenService;
+import com.ruoyi.order.enums.OrderStatus;
+import com.ruoyi.order.enums.OrderType;
 import com.ruoyi.order.mapper.OrderGoodMapper;
 import com.ruoyi.order.mapper.OrderMapper;
 import com.ruoyi.order.service.OrderService;
@@ -15,13 +21,17 @@
 import com.ruoyi.other.api.domain.CouponInfo;
 import com.ruoyi.other.api.domain.Goods;
 import com.ruoyi.other.api.domain.OrderActivityInfo;
+import com.ruoyi.other.api.domain.Technician;
+import com.ruoyi.system.api.model.LoginUser;
 import model.Order;
 import model.OrderGood;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -35,7 +45,14 @@
 public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
     @Resource
     private OrderMapper orderMapper;
+    @Resource
     private OrderGoodMapper orderGoodMapper;
+    @Resource
+    private AppUserClient appUserClient;
+    @Resource
+    private TokenService tokenService;
+    @Resource
+    private Technician
 
     @Override
     public List<OrderVO> selectOrderListByUserId(Integer status, Long userId) {
@@ -115,15 +132,46 @@
     }
 
     @Override
-    public boolean check(String orderNumber, Long shopId) {
-        Order order = getOne(new LambdaQueryWrapper<Order>()
-                .eq(Order::getOrderNumber, orderNumber)
-                .eq(Order::getShopId, shopId));
-        return order != null;
+    public boolean check(Order order, Integer shopId, Long userId) {
+        R<List<AppUserShop>> r = appUserClient.getAppUserShop(userId);
+        if (r.getCode() != R.SUCCESS){
+            throw new ServiceException("获取用户门店信息失败");
+        }
+        List<AppUserShop> appUserShopList = r.getData();
+        if (appUserShopList == null || appUserShopList.isEmpty()){
+            return false;
+        }
+
+        // 判断用户是否拥有该门店
+        List<AppUserShop> userShopList = appUserShopList.stream()
+                .filter(appUserShop -> appUserShop.getShopId().equals(shopId))
+                .collect(Collectors.toList());
+        if (userShopList.isEmpty()){
+            return false;
+        }
+
+        // 判断订单是否属于该门店
+        if (order == null){
+            throw new ServiceException("订单不存在");
+        }
+
+        return order.getShopId().equals(shopId);
     }
 
     @Override
-    public void writeOff(String code) {
-
+    @Transactional(rollbackFor = Exception.class)
+    public void writeOff(String code,Integer shopId) {
+        LoginUser loginUserApplet = tokenService.getLoginUserApplet();
+        Order order = orderMapper.selectOne(new LambdaQueryWrapper<Order>()
+                .eq(Order::getOrderNumber, code));
+        boolean check = check(order, shopId, loginUserApplet.getUserid());
+        if (!check){
+            throw new ServiceException("订单不存在");
+        }
+        order.setOrderStatus(OrderStatus.COMPLETED.getCode());
+        orderMapper.updateById(order);
+        Integer orderType = order.getOrderType();
+        if (orderType.equals(OrderType.SERVICE.getCode())){
+        }
     }
 }
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java
index 77b58fa..d93d7bb 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/TechnicianController.java
@@ -79,36 +79,37 @@
             return R.ok(page);
         }
 
-                @PostMapping("/shop/detail")
-	            @ApiOperation(value = "获取门店的技师详情", tags = {"小程序-门店详情-技师预约"})
-	            public R<Technician> shopdetail(@RequestParam Integer techId){
-                //查出技师列表
-                   Technician technician = technicianService.getById(techId);
+    @PostMapping("/shop/detail")
+    @ApiOperation(value = "获取门店的技师详情", tags = {"小程序-门店详情-技师预约"})
+    public R<Technician> shopdetail(@RequestParam Integer techId) {
+        //查出技师列表
+        Technician technician = technicianService.getById(techId);
 
-                 //查出技师订单
-                R<List<Long>> orderIdsByTechId = orderClient.getOrderIdsByTechId(technician.getId());
-                if (orderIdsByTechId.getData().isEmpty()){
-                    technician.setGrade(new BigDecimal(0));
-                    technician.setServeCount(0);
-                    return R.ok(technician);
-                }
-                //查出技师评价
-                List<GoodsEvaluate> list = goodsEvaluateService.lambdaQuery().in(GoodsEvaluate::getOrderId, orderIdsByTechId.getData()).list();
+        //查出技师订单
+        R<List<Long>> orderIdsByTechId = orderClient.getOrderIdsByTechId(technician.getId());
+        if (orderIdsByTechId.getData().isEmpty()) {
+            technician.setGrade(new BigDecimal(0));
+            technician.setServeCount(0);
+            return R.ok(technician);
+        }
+        //查出技师评价
+        List<GoodsEvaluate> list = goodsEvaluateService.lambdaQuery().in(GoodsEvaluate::getOrderId, orderIdsByTechId.getData()).list();
 
-                //算出平均分并保留一位小数
-                BigDecimal avg = list.stream().map(GoodsEvaluate::getGrade).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(list.size()), 1, BigDecimal.ROUND_HALF_UP);
-                technician.setGrade(avg);
-                technician.setServeCount(orderIdsByTechId.getData().size());
-                    return R.ok(technician);
-                 }
-           @PostMapping("/shop/tech")
-	      @ApiOperation(value = "预约操作", tags = {"小程序-门店详情-技师预约"})
-	      public R<Technician> shoptech(@RequestBody TechnicianSubscribe subscribe){
-               Long userId = tokenService.getLoginUserApplet().getUserid();
-                subscribe.setAppUserId(userId);
-                technicianSubscribeService.save(subscribe);
-                return R.ok();
-           }
+        //算出平均分并保留一位小数
+        BigDecimal avg = list.stream().map(GoodsEvaluate::getGrade).reduce(BigDecimal.ZERO, BigDecimal::add).divide(new BigDecimal(list.size()), 1, BigDecimal.ROUND_HALF_UP);
+        technician.setGrade(avg);
+        technician.setServeCount(orderIdsByTechId.getData().size());
+        return R.ok(technician);
+    }
+
+    @PostMapping("/shop/tech")
+    @ApiOperation(value = "预约操作", tags = {"小程序-门店详情-技师预约"})
+    public R<Technician> shoptech(@RequestBody TechnicianSubscribe subscribe) {
+        Long userId = tokenService.getLoginUserApplet().getUserid();
+        subscribe.setAppUserId(userId);
+        technicianSubscribeService.save(subscribe);
+        return R.ok();
+    }
 
 
     /**
diff --git a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java
index 3220f8c..37f50fb 100644
--- a/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java
+++ b/ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/service/impl/TechnicianSubscribeServiceImpl.java
@@ -44,11 +44,10 @@
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public void subscribe(TechnicianSubscribe technicianSubscribe) {
+    public void subscribe(TechnicianSubscribe subscribe) {
         // 创建技师预约单
-        Long technicianId = technicianSubscribe.getTechnicianId();
+        Long technicianId = subscribe.getTechnicianId();
         Long userId = SecurityUtils.getUserId();
-        TechnicianSubscribe subscribe = new TechnicianSubscribe();
         subscribe.setAppUserId(userId);
         subscribe.setDelFlag(0);
         subscribe.setCreateTime(LocalDateTime.now());

--
Gitblit v1.7.1