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.OrderGoodMapper;
|
import com.ruoyi.order.mapper.OrderMapper;
|
import com.ruoyi.order.service.OrderService;
|
import com.ruoyi.order.vo.OrderDetailVO;
|
import com.ruoyi.order.vo.OrderGoodsVO;
|
import com.ruoyi.order.vo.OrderVO;
|
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 org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.util.ArrayList;
|
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;
|
private OrderGoodMapper orderGoodMapper;
|
|
@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("订单不存在");
|
}
|
// 商品
|
List<OrderGood> orderGoods = orderGoodMapper.selectList(new LambdaQueryWrapper<OrderGood>()
|
.eq(OrderGood::getOrderId, orderId));
|
|
List<OrderGoodsVO> goodsList = new ArrayList<>();
|
for (OrderGood orderGood : orderGoods) {
|
String goodJson = orderGood.getGoodJson();
|
Goods goods = JSONObject.parseObject(goodJson, Goods.class);
|
|
OrderGoodsVO orderGoodsVO = new OrderGoodsVO();
|
orderGoodsVO.setGoodsId(orderGood.getGoodsId());
|
orderGoodsVO.setGoodsName(goods.getName());
|
orderGoodsVO.setType(goods.getType());
|
orderGoodsVO.setNum(orderGood.getNum());
|
orderGoodsVO.setGoodsPic(goods.getHomePagePicture());
|
orderGoodsVO.setSellingPrice(goods.getSellingPrice());
|
orderGoodsVO.setOriginalPrice(goods.getOriginalPrice());
|
goodsList.add(orderGoodsVO);
|
}
|
|
|
// 收货地址
|
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());
|
orderDetailVO.setGoodsList(goodsList);
|
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;
|
}
|
|
@Override
|
public void writeOff(String code) {
|
|
}
|
}
|