puzhibing
2024-08-28 fe2e226da5a7505b343517e828f0d8c3a496fb7a
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
package com.ruoyi.order.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.dto.GrantCouponDto;
import com.ruoyi.account.api.feignClient.AppCouponClient;
import com.ruoyi.account.api.feignClient.AppUserAddressClient;
import com.ruoyi.account.api.model.TAppUserAddress;
import com.ruoyi.common.core.domain.R;
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.model.TShoppingOrderRefund;
import com.ruoyi.order.api.query.ShoppingOrderQuery;
import com.ruoyi.order.api.query.TActivityStatisticsQuery;
import com.ruoyi.order.api.vo.ChargingOrderVO;
import com.ruoyi.order.api.vo.TActivityStatisticslVO;
import com.ruoyi.order.api.vo.TActivityVO;
import com.ruoyi.order.dto.*;
import com.ruoyi.order.mapper.TShoppingOrderMapper;
import com.ruoyi.order.service.TShoppingOrderRefundService;
import com.ruoyi.order.service.TShoppingOrderService;
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 com.ruoyi.payment.api.feignClient.AliPaymentClient;
import com.ruoyi.payment.api.feignClient.WxPaymentClient;
import com.ruoyi.payment.api.model.RefundReq;
import com.ruoyi.payment.api.model.RefundResp;
import com.ruoyi.payment.api.model.WxPaymentRefundModel;
import com.ruoyi.payment.api.vo.AliQueryOrder;
import com.ruoyi.payment.api.vo.NotifyV3PayDecodeRespBody;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
 
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
 
/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xiaochen
 * @since 2024-08-07
 */
@Service
public class TShoppingOrderServiceImpl extends ServiceImpl<TShoppingOrderMapper, TShoppingOrder> implements TShoppingOrderService {
    
    @Resource
    private TokenService tokenService;
    
    @Resource
    private GoodsClient goodsClient;
    
    @Resource
    private CouponClient couponClient;
    
    @Resource
    private AppUserAddressClient appUserAddressClient;
    @Resource
    private AppCouponClient appCouponClient;
    
    @Resource
    private WxPaymentClient wxPaymentClient;
    
    @Resource
    private AliPaymentClient aliPaymentClient;
    
    @Resource
    private TShoppingOrderRefundService shoppingOrderRefundService;
    
    
    
 
    @Override
    public TActivityVO activityStatistics(TActivityStatisticsQuery dto) {
        TActivityVO res = new TActivityVO();
 
 
 
        PageInfo<TActivityStatisticslVO> pageInfo = new PageInfo<>(dto.getPageCurr(),dto.getPageSize());
        List<TActivityStatisticslVO> list = this.baseMapper.activityStatistics(pageInfo,dto);
        list.sort((o1, o2) -> o2.getCreateTime().compareTo(o1.getCreateTime()));
        // 优惠券金额
        BigDecimal coupon = new BigDecimal("0");
        // 会员抵扣金额
        BigDecimal discount = new BigDecimal("0");
        // 会员活动金额
        BigDecimal vipActivity = new BigDecimal("0");
        // 赠送会员
        BigDecimal grantVip = new BigDecimal("0");
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
        for (TActivityStatisticslVO tActivityStatisticslVO : list) {
            // 判断享有了哪些类型
            switch (tActivityStatisticslVO.getOrderType()){
                case 1:
                    StringBuilder stringBuilder = new StringBuilder();
 
                    // 充电订单 优惠券金额大于0
                    if (tActivityStatisticslVO.getCouponDiscountAmount()!=null
                            &&
                        (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){
                        coupon = coupon.add(tActivityStatisticslVO.getCouponDiscountAmount());
                        stringBuilder.append("优惠券抵扣").append("+");
                }
                    if (tActivityStatisticslVO.getVipDiscountAmount()!=null
                            &&
                            (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){
                        discount = discount.add(tActivityStatisticslVO.getVipDiscountAmount());
                        stringBuilder.append("会员抵扣").append("+");
                    }
                    stringBuilder.deleteCharAt(stringBuilder.length()-1);
                    tActivityStatisticslVO.setType(stringBuilder.toString());
                    tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime()));
                    break;
                case 2:
                    StringBuilder stringBuilder1 = new StringBuilder();
 
                    // 购物订单 优惠券金额大于0
                    if (tActivityStatisticslVO.getCouponDiscountAmount()!=null
                            &&
                            (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){
                        coupon = coupon.add(tActivityStatisticslVO.getCouponDiscountAmount());
                        stringBuilder1.append("优惠券抵扣").append("+");
                    }
                    if (tActivityStatisticslVO.getVipDiscountAmount()!=null
                            &&
                            (tActivityStatisticslVO.getVipDiscountAmount().compareTo(BigDecimal.ZERO)>0)){
                        discount = discount.add(tActivityStatisticslVO.getVipDiscountAmount());
                        stringBuilder1.append("会员抵扣").append("+");
                    }
                    stringBuilder1.deleteCharAt(stringBuilder1.length()-1);
                    tActivityStatisticslVO.setType(stringBuilder1.toString());
                    tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime()));
                    break;
                case 3:
                    // 会员订单 优惠金额大于0
                    if (tActivityStatisticslVO.getVipDiscountAmount()!=null
                            &&
                            (tActivityStatisticslVO.getCouponDiscountAmount().compareTo(BigDecimal.ZERO)>0)){
                        vipActivity = vipActivity.add(tActivityStatisticslVO.getVipDiscountAmount());
                    }
                    tActivityStatisticslVO.setType("会员活动");
                    tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime()));
                    break;
                case 4:
                    // 赠送会员订单 如果支付金额为0 那么就是后台赠送的会员
                    if (tActivityStatisticslVO.getPaymentAmount().compareTo(BigDecimal.ZERO)==0){
                        grantVip = grantVip.add(tActivityStatisticslVO.getOrderAmount());
                        tActivityStatisticslVO.setType("赠送会员");
                        tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime()));
                    }else{
                        // 赠送
                        grantVip = grantVip.add(tActivityStatisticslVO.getVipDiscountAmount());
                        tActivityStatisticslVO.setType("赠送会员");
                        tActivityStatisticslVO.setTime(simpleDateFormat.format(tActivityStatisticslVO.getCreateTime()));
                    }
                    break;
            }
        }
        pageInfo.setRecords(list);
        res.setList(pageInfo);
        res.setTotal(coupon.add(discount).add(vipActivity).add(grantVip));
        res.setCoupon(coupon);
        res.setDiscount(discount);
        res.setVipActivity(vipActivity);
        res.setGrantVip(grantVip);
        return res;
    }
    
    
    /**
     * 获取小程序商城购买订单列表
     * @param query
     * @return
     */
    @Override
    public List<MyShoppingOrderList> getMyShoppingOrderList(GetMyShoppingOrderList query) {
        Long userId = tokenService.getLoginUserApplet().getUserId();
        LambdaQueryWrapper<TShoppingOrder> wrapper = new LambdaQueryWrapper<TShoppingOrder>().eq(TShoppingOrder::getDelFlag, 0)
                .eq(TShoppingOrder::getAppUserId, userId);
        if(query.getStatus() != 0){
            wrapper.eq(TShoppingOrder::getStatus, query.getStatus());
        }
        List<TShoppingOrder> list = this.list(wrapper.orderByDesc(TShoppingOrder::getCreateTime).last(" limit " + query.getPageCurr() + ", " + query.getPageSize()));
        List<MyShoppingOrderList> pageList = new ArrayList<>();
        for (TShoppingOrder tShoppingOrder : list) {
            MyShoppingOrderList myShoppingOrderList = new MyShoppingOrderList();
            myShoppingOrderList.setId(tShoppingOrder.getId().toString());
            String name = "";
            String imgUrl = "";
            if(tShoppingOrder.getOrderType() == 1){
                TGoods goods = goodsClient.getGoodsById(tShoppingOrder.getGoodsId()).getData();
                name = goods.getName();
                imgUrl = goods.getCoverPicture();
            }else{
                TCoupon coupon = couponClient.getCouponById1(tShoppingOrder.getCouponId()).getData();
                name = coupon.getName();
                imgUrl = coupon.getCoverPicture();
            }
            myShoppingOrderList.setName(name);
            myShoppingOrderList.setImgUrl(imgUrl);
            myShoppingOrderList.setStatus(tShoppingOrder.getStatus());
            BigDecimal unitPrice = tShoppingOrder.getPaymentAmount().divide(new BigDecimal(tShoppingOrder.getPurchaseQuantity())).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            myShoppingOrderList.setUnitPrice(unitPrice);
            myShoppingOrderList.setNumber(tShoppingOrder.getPurchaseQuantity());
            myShoppingOrderList.setPaymentAmount(tShoppingOrder.getPaymentAmount());
            myShoppingOrderList.setOrderType(tShoppingOrder.getOrderType());
            pageList.add(myShoppingOrderList);
        }
        return pageList;
    }
    
    
    /**
     * 获取购买订单详情
     * @param id
     * @return
     */
    @Override
    public MyShoppingOrderInfo getMyShoppingOrderInfo(String id) {
        TShoppingOrder shoppingOrder = this.getById(id);
        MyShoppingOrderInfo info = new MyShoppingOrderInfo();
        info.setId(id);
        info.setStatus(shoppingOrder.getStatus());
        TAppUserAddress userAddress = appUserAddressClient.getAppUserAddressById(shoppingOrder.getAppUserAddressId()).getData();
        info.setConsignee(userAddress.getName());
        info.setPhone(userAddress.getPhone());
        info.setAddress(userAddress.getAddress());
        info.setExpressCompany(shoppingOrder.getExpressCompany());
        info.setExpressNumber(shoppingOrder.getExpressNumber());
        String name = "";
        String imgUrl = "";
        if(shoppingOrder.getOrderType() == 1){
            TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData();
            name = goods.getName();
            imgUrl = goods.getCoverPicture();
        }else{
            TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getCouponId()).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.setNumber(shoppingOrder.getPurchaseQuantity());
        BigDecimal unitPrice = shoppingOrder.getPaymentAmount().divide(new BigDecimal(shoppingOrder.getPurchaseQuantity())).setScale(2, BigDecimal.ROUND_HALF_EVEN);
        info.setUnitPrice(unitPrice);
        info.setCode(shoppingOrder.getCode());
        info.setCreateTime(shoppingOrder.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        info.setOrderAmount(shoppingOrder.getOrderAmount());
        info.setPaymentAmount(shoppingOrder.getPaymentAmount());
        info.setRemark(shoppingOrder.getRemark());
        if(null != shoppingOrder.getConsignerTime()){
            info.setDeliveryTime(shoppingOrder.getConsignerTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
        if(null != shoppingOrder.getReceivingTime()){
            info.setFinishTime(shoppingOrder.getReceivingTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        }
        return info;
    }
    
    
    /**
     * 取消订单
     * @param id
     * @return
     */
    @Override
    public AjaxResult cancelOrder(String id) {
        TShoppingOrder shoppingOrder = this.getById(id);
        if(shoppingOrder.getStatus() == 2){
            return AjaxResult.error("订单已发货,不能取消");
        }
        if(shoppingOrder.getStatus() == 3){
            return AjaxResult.error("订单已完成,不能取消");
        }
        //退款状态并且所有金额退完
        List<TShoppingOrderRefund> list = shoppingOrderRefundService.list(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getShoppingOrderId, id).eq(TShoppingOrderRefund::getRefundStatus, 2));
        BigDecimal bigDecimal = list.stream().map(TShoppingOrderRefund::getRefundAmount).reduce(BigDecimal.ZERO, BigDecimal::add).setScale(2, RoundingMode.HALF_EVEN);
        if(shoppingOrder.getPaymentAmount().compareTo(bigDecimal) == 0 && shoppingOrder.getStatus() == 4){
            return AjaxResult.error("订单已取消,不能重复操作");
        }
    
        //退款金额
        BigDecimal refundAmount = shoppingOrder.getPaymentAmount().subtract(bigDecimal);
    
        //先查询第三方订单状态订单是否退款
        //支付方式(1=微信,2=支付宝)
        Integer paymentType = shoppingOrder.getPaymentType();
        if(1 == paymentType){
            NotifyV3PayDecodeRespBody data = wxPaymentClient.queryOrderInfo(shoppingOrder.getCode()).getData();
            String trade_state = data.getTrade_state();
            if("NOTPAY".equals(trade_state) || "REVOKED".equals(trade_state) || "PAYERROR".equals(trade_state)){
                return AjaxResult.error("订单还未支付,不能操作退款");
            }
            if("CLOSED".equals(trade_state)){
                return AjaxResult.error("订单支付已关闭,不能操作退款");
            }
            if("USERPAYING".equals(trade_state)){
                return AjaxResult.error("订单正在支付中,不能操作退款");
            }
        }
        if(2 == paymentType){
            AliQueryOrder aliQueryOrder = aliPaymentClient.query(shoppingOrder.getCode()).getData();
            String tradeStatus = aliQueryOrder.getTradeStatus();
            if("TRADE_CLOSED".equals(tradeStatus)){
                return AjaxResult.error("订单还未支付,不能操作退款");
            }
            if("TRADE_FINISHED".equals(tradeStatus)){
                return AjaxResult.error("订单支付已关闭,不能操作退款");
            }
            if("WAIT_BUYER_PAY".equals(tradeStatus)){
                return AjaxResult.error("订单正在支付中,不能操作退款");
            }
        }
        //退款成功后需要判断商品库存类型后决定是否需要回退库存
        //加redis锁处理高并发
        //构建退款明细
        TShoppingOrderRefund shoppingOrderRefund = new TShoppingOrderRefund();
        shoppingOrderRefund.setPayTime(shoppingOrder.getPayTime());
        shoppingOrderRefund.setPayCode(shoppingOrder.getSerialNumber());
        shoppingOrderRefund.setPayType(shoppingOrder.getPaymentType());
        shoppingOrderRefund.setShoppingOrderId(shoppingOrder.getId());
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        shoppingOrderRefund.setRefundCode("GDF" + sdf.format(new Date()) + (Math.random() * 1000));
        shoppingOrderRefund.setRefundAmount(refundAmount);
        shoppingOrderRefund.setRefundStatus(1);
        shoppingOrderRefund.setCode(shoppingOrder.getCode());
        shoppingOrderRefund.setRefundTitle("取消订单");
        shoppingOrderRefund.setRefundContent("取消订单");
        shoppingOrderRefund.setRefundReason("取消订单");
        shoppingOrderRefund.setRefundRemark("全额退款");
        shoppingOrderRefund.setRefundTotalAmount(refundAmount.add(bigDecimal));
        shoppingOrderRefund.setPayAmount(shoppingOrder.getPaymentAmount());
        if(1 == paymentType){
            WxPaymentRefundModel model = new WxPaymentRefundModel();
            model.setOut_trade_no(shoppingOrder.getCode());
            model.setOut_refund_no(shoppingOrderRefund.getRefundCode());
            model.setReason("取消订单");
            model.setNotify_url("http://127.0.0.1:9000/order/t-shopping-order/cancelShoppingOrderWxRefund");
            WxPaymentRefundModel.RefundAmount amount = new WxPaymentRefundModel.RefundAmount();
            amount.setRefund(refundAmount.multiply(new BigDecimal(100)).intValue());
            amount.setTotal(shoppingOrder.getPaymentAmount().multiply(new BigDecimal(100)).intValue());
            amount.setCurrency("CNY");
            model.setAmount(amount);
            R<String> orderR = wxPaymentClient.refundOrderR(model);
            if(200 == orderR.getCode()){
                shoppingOrderRefundService.save(shoppingOrderRefund);
            }
        }
        if(2 == paymentType){
            RefundReq dto = new RefundReq();
            dto.setOutTradeNo(shoppingOrder.getCode());
            dto.setOutRequestNo(shoppingOrderRefund.getCode());
            dto.setRefundAmount(refundAmount.toString());
            dto.setRefundReason("取消订单");
            RefundResp resp = aliPaymentClient.refund(dto).getData();
            if(null != resp){
                SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-DDTHH:mm:ss+TIMEZONE");
                AjaxResult success = cancelShoppingOrderWxRefund(resp.getOutTradeNo(), resp.getTradeNo(), "SUCCESS", sdf1.format(new Date()));
                if(success.isSuccess()){
                    shoppingOrderRefundService.save(shoppingOrderRefund);
                }
            }
        }
        return AjaxResult.success();
    }
    
    
    /**
     * 商城订单取消订单微信退款处理
     * @param out_refund_no 退款单号
     * @param refund_id 退款流水号
     * @param refund_status 退款状态 SUCCESS:退款成功  CLOSED:退款关闭  ABNORMAL:退款异常
     * @param success_time 退款成功时间
     * @return
     */
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)//分布式事务
    public AjaxResult cancelShoppingOrderWxRefund(String out_refund_no, String refund_id, String refund_status, String success_time) {
        if("SUCCESS".equals(refund_status)){
            TShoppingOrderRefund one = shoppingOrderRefundService.getOne(new LambdaQueryWrapper<TShoppingOrderRefund>().eq(TShoppingOrderRefund::getRefundCode, out_refund_no));
            one.setRefundSerialNumber(refund_id);
            one.setRefundTime(LocalDateTime.parse(success_time, DateTimeFormatter.ofPattern("yyyy-MM-DDTHH:mm:ss+TIMEZONE")));
            shoppingOrderRefundService.updateById(one);
            //判断是否需要回退库存
            TShoppingOrder shoppingOrder = this.getById(one.getShoppingOrderId());
            //商品
            if(shoppingOrder.getOrderType() == 1){
                // todo 需完善redis锁
                //redis锁 和支付使用同一个锁
                TGoods goods = goodsClient.getGoodsById(shoppingOrder.getGoodsId()).getData();
                Integer inventory = goods.getInventory();
                if(-1 != inventory){
                    goods.setInventory(inventory + shoppingOrder.getPurchaseQuantity());
                    goodsClient.updateGoods(goods);
                }
                //解锁
            }
            //优惠券
            if(shoppingOrder.getOrderType() == 2){
                //redis锁
                TCoupon coupon = couponClient.getCouponById1(shoppingOrder.getCouponId()).getData();
                Integer inventory = coupon.getInventoryQuantity();
                if(-1 != inventory){
                    coupon.setInventoryQuantity(inventory + shoppingOrder.getPurchaseQuantity());
                    couponClient.updateCoupon(coupon);
                }
                //解锁
            }
        }
        return AjaxResult.success();
    }
    
    /**
     * 获取未开票的订单列表
     * @param query
     * @return
     */
    @Override
    public List<MyShoppingOrderList> getNoInvoicedOrder(GetNoInvoicedOrder query) {
        Long userId = tokenService.getLoginUserApplet().getUserId();
        List<TShoppingOrder> list = this.baseMapper.getNoInvoicedOrder(userId, query.getMonth(), query.getPageCurr(), query.getPageSize());
        List<MyShoppingOrderList> pageList = new ArrayList<>();
        for (TShoppingOrder tShoppingOrder : list) {
            MyShoppingOrderList myShoppingOrderList = new MyShoppingOrderList();
            myShoppingOrderList.setId(tShoppingOrder.getId().toString());
            String name = "";
            String imgUrl = "";
            if(tShoppingOrder.getOrderType() == 1){
                TGoods goods = goodsClient.getGoodsById(tShoppingOrder.getGoodsId()).getData();
                name = goods.getName();
                imgUrl = goods.getCoverPicture();
            }else{
                TCoupon coupon = couponClient.getCouponById1(tShoppingOrder.getGoodsId()).getData();
                name = coupon.getName();
                imgUrl = coupon.getCoverPicture();
            }
            myShoppingOrderList.setName(name);
            myShoppingOrderList.setImgUrl(imgUrl);
            myShoppingOrderList.setStatus(tShoppingOrder.getStatus());
            BigDecimal unitPrice = tShoppingOrder.getPaymentAmount().divide(new BigDecimal(tShoppingOrder.getPurchaseQuantity())).setScale(2, BigDecimal.ROUND_HALF_EVEN);
            myShoppingOrderList.setUnitPrice(unitPrice);
            myShoppingOrderList.setNumber(tShoppingOrder.getPurchaseQuantity());
            myShoppingOrderList.setPaymentAmount(tShoppingOrder.getPaymentAmount());
            myShoppingOrderList.setCreateTime(tShoppingOrder.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy.MM.dd HH:mm:ss")));
            pageList.add(myShoppingOrderList);
        }
        return pageList;
    }
 
    @Override
    public void callBack(String code,String outTradeNo) {
        //改变订单状态
        TShoppingOrder shoppingOrder = this.baseMapper.selectOne(Wrappers.lambdaQuery(TShoppingOrder.class).eq(TShoppingOrder::getCode, code));
        shoppingOrder.setPaymentStatus(2);
        shoppingOrder.setSerialNumber(outTradeNo);
        this.updateById(shoppingOrder);
        //如果是优惠券,赠送优惠券
        if (shoppingOrder.getOrderType()==2){
            GrantCouponDto grantCouponDto = new GrantCouponDto();
            grantCouponDto.setType(3);
            grantCouponDto.setUserIds(String.valueOf(shoppingOrder.getAppUserId()));
            grantCouponDto.setCouponId(shoppingOrder.getCouponId());
            grantCouponDto.setWaysToObtain(2);
            grantCouponDto.setEndTime(LocalDateTime.now());
            appCouponClient.grantCoupon(grantCouponDto);
        }
    }
 
    @Override
    public PageInfo<TShoppingOrder> 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<TShoppingOrder> pageInfo = new PageInfo<>(query.getPageCurr(),query.getPageSize());
        List<TShoppingOrder> list = this.baseMapper.pageList(pageInfo,query,startTime1,startTime2);
 
        pageInfo.setRecords(list);
        return pageInfo;
    }
}