luodangjia
2024-11-28 36ce1f3549df46609b4e3bc0bf0810bd0c85277e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.ruoyi.order.service.impl;
 
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.model.UserAddress;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.order.mapper.OrderMapper;
import com.ruoyi.order.service.OrderService;
import com.ruoyi.order.vo.OrderDetailVO;
import com.ruoyi.order.vo.OrderVO;
import com.ruoyi.other.api.domain.CouponInfo;
import com.ruoyi.other.api.domain.OrderActivityInfo;
import model.Order;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author luodangjia
 * @since 2024-11-21
 */
@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private OrderMapper orderMapper;
 
    @Override
    public List<OrderVO> selectOrderListByUserId(Integer status, Long userId) {
        return orderMapper.selectOrderListByUserId(status, userId);
    }
 
 
 
 
    @Override
    public OrderDetailVO getOrderDetail(Long orderId) {
        Order order = orderMapper.selectById(orderId);
        if (order == null){
            throw new ServiceException("订单不存在");
        }
        // 收货地址
        String addressJson = order.getAddressJson();
        UserAddress userAddress = new UserAddress();
        if (StringUtils.isNotEmpty(addressJson)){
            userAddress = JSONObject.parseObject(addressJson, UserAddress.class);
 
        }
 
        // 优惠券
        String couponJson = order.getCouponJson();
        CouponInfo couponInfo = new CouponInfo();
        if (StringUtils.isNotEmpty(couponJson)){
            couponInfo = JSONObject.parseObject(couponJson, CouponInfo.class);
        }
 
        // 参与活动
        String activityJson = order.getActivityJson();
        OrderActivityInfo orderActivityInfo = new OrderActivityInfo();
        if (StringUtils.isNotEmpty(activityJson)){
            orderActivityInfo = JSONObject.parseObject(activityJson, OrderActivityInfo.class);
        }
 
        OrderDetailVO orderDetailVO = new OrderDetailVO();
        orderDetailVO.setId(order.getId());
        orderDetailVO.setPoint(order.getPoint());
        orderDetailVO.setAddressId(userAddress.getId());
        orderDetailVO.setRecieveName(userAddress.getRecieveName());
        orderDetailVO.setRecievePhone(userAddress.getRecievePhone());
        orderDetailVO.setRecieveAddress(userAddress.getRecieveAddress());
        orderDetailVO.setOrderNumber(order.getOrderNumber());
        orderDetailVO.setCreateTime(order.getCreateTime());
        orderDetailVO.setTotalAmount(order.getTotalAmount());
        orderDetailVO.setCouponName(couponInfo.getCouponName());
        orderDetailVO.setActivityName(orderActivityInfo.getActivityName());
        orderDetailVO.setCouponAmount(order.getDiscountTotalAmount());
        orderDetailVO.setExpressAmount(order.getExpressAmount());
        orderDetailVO.setPointAmount(order.getGetPoint());
        orderDetailVO.setPaymentAmount(order.getPaymentAmount());
        return orderDetailVO;
    }
 
    @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;
    }
}