无关风月
2025-04-28 e1399ade3e27ef74ed58d56dbbb2bf77604ff5af
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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.feignClient.AppUserClient;
import com.ruoyi.account.api.feignClient.AppUserIntegralChangeClient;
import com.ruoyi.account.api.model.TAppUser;
import com.ruoyi.account.api.model.TAppUserAddress;
import com.ruoyi.account.api.model.TAppUserIntegralChange;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.api.model.TExchangeOrder;
import com.ruoyi.order.api.model.TShoppingOrder;
import com.ruoyi.order.api.query.ShoppingOrderQuery;
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 org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * <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;
 
    @Resource
    private AppUserClient appUserClient;
    
    @Resource
    private AppUserIntegralChangeClient appUserIntegralChangeClient;
    
    
    
    
    /**
     * 获取小程序兑换记录
     * @param query
     * @return
     */
    @Override
    public Map<String, Object> getMyExchangeOrder(GetMyExchangeOrder query) {
        Long userid = tokenService.getLoginUserApplet().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());
        }
        long count = this.count(wrapper);
        Integer pageCurr = (query.getPageCurr() - 1) * query.getPageSize();
        List<TExchangeOrder> list = this.list(wrapper.orderByDesc(TExchangeOrder::getCreateTime).last(" limit " + pageCurr + "," + 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();
                if(null != goods){
                    name = goods.getName();
                    imgUrl = goods.getCoverPicture();
                }
            }else{
                TCoupon coupon = couponClient.getCouponById1(tExchangeOrder.getCouponId()).getData();
                if(null != coupon){
                    name = coupon.getName();
                    imgUrl = coupon.getCoverPicture();
                }
            }
            exchangeOrderList.setName(name);
            exchangeOrderList.setImgUrl(imgUrl);
            pageList.add(exchangeOrderList);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("list", pageList);
        map.put("total", count);
        return map;
    }
    
    
    /**
     * 获取兑换订单详情
     * @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());
        if(null != exchangeOrder.getAppUserAddressId()){
            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();
            if(null != goods){
                name = goods.getName();
                imgUrl = goods.getCoverPicture();
            }
        }else{
            TCoupon coupon = couponClient.getCouponById1(exchangeOrder.getCouponId()).getData();
            if(null != coupon){
                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());
        if(null != exchangeOrder.getConsignerTime()){
            info.setDeliveryTime(exchangeOrder.getConsignerTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
        if(null != exchangeOrder.getReceivingTime()){
            info.setFinishTime(exchangeOrder.getReceivingTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
        return info;
    }
 
    @Override
    public PageInfo<TExchangeOrder> pageList(ShoppingOrderQuery query) {
        String startTime1 = null;
        String startTime2 = null;
 
 
        if (StringUtils.hasLength(query.getStartTime())){
            String[] split = query.getStartTime().split(" - ");
            startTime1 = split[0];
            startTime2 = split[1];
        }
        PageInfo<TExchangeOrder> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        List<TExchangeOrder> list = this.baseMapper.pageList(pageInfo,query,startTime1,startTime2);
        for (TExchangeOrder tShoppingOrder : list) {
            tShoppingOrder.setUid(tShoppingOrder.getId().toString());
            switch (tShoppingOrder.getOrderType()){
                case 1:
                    TGoods data = goodsClient.getGoodsById(tShoppingOrder.getGoodsId()).getData();
                    if (data!=null){
                        tShoppingOrder.setName(data.getName());
                    }
                    break;
                case 2:
                    TCoupon data1 = couponClient.getCouponById1(tShoppingOrder.getCouponId()).getData();
                    if (data1!=null){
                        tShoppingOrder.setName(data1.getName());
                    }
                    break;
            }
            if (tShoppingOrder.getAppUserId() != null){
                TAppUser data = appUserClient.getUserById(tShoppingOrder.getAppUserId()).getData();
                if (data!=null){
                    tShoppingOrder.setPhone(data.getPhone());
                }
            }
        }
        pageInfo.setRecords(list);
        return pageInfo;
    }
    
}