无关风月
2024-08-16 85a21fdb54fa06f2fa6e25e763ec5337e85295e7
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.ruoyi.order.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.feignClient.AppUserAddressClient;
import com.ruoyi.account.api.model.TAppUserAddress;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.model.TExchangeOrder;
import com.ruoyi.order.dto.ExchangeOrderGoodsInfo;
import com.ruoyi.order.dto.GetMyExchangeOrder;
import com.ruoyi.order.dto.MyExchangeOrderList;
import com.ruoyi.order.mapper.TExchangeOrderMapper;
import com.ruoyi.order.service.TExchangeOrderService;
import com.ruoyi.other.api.domain.TCoupon;
import com.ruoyi.other.api.domain.TGoods;
import com.ruoyi.other.api.feignClient.CouponClient;
import com.ruoyi.other.api.feignClient.GoodsClient;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-07
 */
@Service
public class TExchangeOrderServiceImpl extends ServiceImpl<TExchangeOrderMapper, TExchangeOrder> implements TExchangeOrderService {
    
    @Resource
    private TokenService tokenService;
    
    @Resource
    private GoodsClient goodsClient;
    
    @Resource
    private CouponClient couponClient;
    
    @Resource
    private AppUserAddressClient appUserAddressClient;
    
    
    
    
    
    
    /**
     * 获取小程序兑换记录
     * @param query
     * @return
     */
    @Override
    public List<MyExchangeOrderList> getMyExchangeOrder(GetMyExchangeOrder query) {
        Long userid = tokenService.getLoginUser().getUserid();
        LambdaQueryWrapper<TExchangeOrder> wrapper = new LambdaQueryWrapper<TExchangeOrder>().eq(TExchangeOrder::getDelFlag, 0).eq(TExchangeOrder::getAppUserId, userid);
        if(query.getStatus() == 0){
            wrapper.ne(TExchangeOrder::getStatus, 4);
        }else{
            wrapper.eq(TExchangeOrder::getStatus, query.getStatus());
        }
        List<TExchangeOrder> list = this.list(wrapper.orderByDesc(TExchangeOrder::getCreateTime).last(" limit " + query.getPageCurr() + "," + query.getPageSize()));
        List<MyExchangeOrderList> pageList = new ArrayList<>();
        for (TExchangeOrder tExchangeOrder : list) {
            MyExchangeOrderList exchangeOrderList = new MyExchangeOrderList();
            exchangeOrderList.setId(tExchangeOrder.getId().toString());
            exchangeOrderList.setUnitPoints(tExchangeOrder.getPoints() / tExchangeOrder.getPurchaseQuantity());
            exchangeOrderList.setPoints(tExchangeOrder.getPoints());
            exchangeOrderList.setPurchaseQuantity(tExchangeOrder.getPurchaseQuantity());
            exchangeOrderList.setOrderType(tExchangeOrder.getOrderType());
            exchangeOrderList.setStatus(tExchangeOrder.getStatus());
            String name = "";
            String imgUrl = "";
            if(tExchangeOrder.getOrderType() == 1){
                TGoods goods = goodsClient.getGoodsById(tExchangeOrder.getGoodsId()).getData();
                name = goods.getName();
                imgUrl = goods.getCoverPicture();
            }else{
                TCoupon coupon = couponClient.getCouponById(tExchangeOrder.getGoodsId()).getData();
                name = coupon.getName();
                imgUrl = coupon.getCoverPicture();
            }
            exchangeOrderList.setName(name);
            exchangeOrderList.setImgUrl(imgUrl);
            pageList.add(exchangeOrderList);
        }
        return pageList;
    }
    
    
    /**
     * 获取兑换订单详情
     * @param id
     * @return
     */
    @Override
    public ExchangeOrderGoodsInfo getGoodsExchangeOrder(String id) {
        TExchangeOrder exchangeOrder = this.getById(id);
        ExchangeOrderGoodsInfo info = new ExchangeOrderGoodsInfo();
        info.setId(id);
        info.setStatus(exchangeOrder.getStatus());
        TAppUserAddress userAddress = appUserAddressClient.getAppUserAddressById(exchangeOrder.getAppUserAddressId()).getData();
        info.setConsignee(userAddress.getName());
        info.setPhone(userAddress.getPhone());
        info.setAddress(userAddress.getAddress());
        info.setExpressCompany(exchangeOrder.getExpressCompany());
        info.setExpressNumber(exchangeOrder.getExpressNumber());
        String name = "";
        String imgUrl = "";
        if(exchangeOrder.getOrderType() == 1){
            TGoods goods = goodsClient.getGoodsById(exchangeOrder.getGoodsId()).getData();
            name = goods.getName();
            imgUrl = goods.getCoverPicture();
        }else{
            TCoupon coupon = couponClient.getCouponById(exchangeOrder.getGoodsId()).getData();
            info.setCouponType(coupon.getType());
            info.setDays(coupon.getDays());
            info.setEndTime(coupon.getEndTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
            name = coupon.getName();
            imgUrl = coupon.getCoverPicture();
        }
        info.setName(name);
        info.setImgUrl(imgUrl);
        info.setPurchaseQuantity(exchangeOrder.getPurchaseQuantity());
        info.setUnitPoints(exchangeOrder.getPoints() / exchangeOrder.getPurchaseQuantity());
        info.setCode(exchangeOrder.getCode());
        info.setCreateTime(exchangeOrder.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        info.setPoints(exchangeOrder.getPoints());
        info.setRemark(exchangeOrder.getRemark());
        info.setDeliveryTime(exchangeOrder.getConsignerTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        info.setFinishTime(exchangeOrder.getReceivingTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        return info;
    }
}