From 3c12537ca918b1e388a229e90b3857823350f1b7 Mon Sep 17 00:00:00 2001
From: phpcjl <phpcjl@gmail.com>
Date: 星期五, 06 十二月 2024 11:29:45 +0800
Subject: [PATCH] 1.
---
ruoyi-service/ruoyi-order/src/main/java/com/ruoyi/order/service/impl/OrderServiceImpl.java | 98 +++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 90 insertions(+), 8 deletions(-)
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..f4029b3 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
@@ -1,13 +1,22 @@
package com.ruoyi.order.service.impl;
+import cn.hutool.core.collection.CollectionUtil;
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.model.Order;
+import com.ruoyi.order.model.OrderGood;
import com.ruoyi.order.service.OrderService;
import com.ruoyi.order.vo.OrderDetailVO;
import com.ruoyi.order.vo.OrderGoodsVO;
@@ -15,13 +24,17 @@
import com.ruoyi.other.api.domain.CouponInfo;
import com.ruoyi.other.api.domain.Goods;
import com.ruoyi.other.api.domain.OrderActivityInfo;
-import model.Order;
-import model.OrderGood;
+import com.ruoyi.other.api.domain.Technician;
+import com.ruoyi.other.api.feignClient.GoodsClient;
+import com.ruoyi.other.api.feignClient.TechnicianClient;
+import com.ruoyi.system.api.model.LoginUser;
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 +48,17 @@
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 TechnicianClient technicianClient;
+ @Resource
+ private GoodsClient goodsClient;
+
@Override
public List<OrderVO> selectOrderListByUserId(Integer status, Long userId) {
@@ -51,6 +74,7 @@
if (order == null){
throw new ServiceException("订单不存在");
}
+
// 商品
List<OrderGood> orderGoods = orderGoodMapper.selectList(new LambdaQueryWrapper<OrderGood>()
.eq(OrderGood::getOrderId, orderId));
@@ -70,6 +94,7 @@
orderGoodsVO.setOriginalPrice(goods.getOriginalPrice());
goodsList.add(orderGoodsVO);
}
+
// 收货地址
@@ -95,7 +120,17 @@
}
OrderDetailVO orderDetailVO = new OrderDetailVO();
+
+ if (CollectionUtil.isNotEmpty(orderGoods)){
+ String goodJson = orderGoods.get(0).getGoodJson();
+ Goods goods = JSONObject.parseObject(goodJson, Goods.class);
+ orderDetailVO.setDistributionMode(goods.getDistributionMode());
+ }
+
+
+
orderDetailVO.setId(order.getId());
+ orderDetailVO.setOrderStatus(order.getOrderStatus());
orderDetailVO.setPoint(order.getPoint());
orderDetailVO.setAddressId(userAddress.getId());
orderDetailVO.setRecieveName(userAddress.getRecieveName());
@@ -115,15 +150,62 @@
}
@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())){
+ R<Technician> shopdetail = technicianClient.shopdetail(order.getTechnicianId());
+ if (shopdetail.getCode() != R.SUCCESS){
+ throw new ServiceException("获取技师信息失败");
+ }
+ Technician technician = shopdetail.getData();
+ R<Void> r = technicianClient.updateStatus(2, technician.getId());
+ if (r.getCode() != R.SUCCESS){
+ throw new ServiceException("修改技师状态失败");
+ }
+ }
+ }
+
+
+
+ @Override
+ public void commission(Long orderId) {
}
}
--
Gitblit v1.7.1