Helius
2021-03-10 087cd794187727bf9a34fcef3027cd56f6dec436
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
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
package com.matrix.system.shopXcx.api.service.impl;
 
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.matrix.biz.bean.BizUser;
import com.matrix.component.rabbitmq.RabiitMqTemplate;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.component.tools.WxUtils;
import com.matrix.component.wechat.externalInterface.protocol.paramProtocol.BrandWCPayRequestData;
import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.tools.LogUtil;
import com.matrix.core.tools.StringUtils;
import com.matrix.system.common.bean.BusParameterSettings;
import com.matrix.system.common.constance.AppConstance;
import com.matrix.system.common.dao.BusParameterSettingsDao;
import com.matrix.system.common.dao.CustomerDataDictionaryDao;
import com.matrix.system.common.interceptor.HostInterceptor;
import com.matrix.system.constance.Dictionary;
import com.matrix.system.hive.bean.ShoppingGoods;
import com.matrix.system.hive.dao.ShoppingGoodsDao;
import com.matrix.system.shopXcx.api.action.PayThreadPool;
import com.matrix.system.shopXcx.api.pojo.AddShopOrderPOJO;
import com.matrix.system.shopXcx.api.pojo.OrderInfoQueryPOJO;
import com.matrix.system.shopXcx.api.service.ShoppingCartService;
import com.matrix.system.shopXcx.api.service.WXShopOrderService;
import com.matrix.system.shopXcx.api.service.WxShopCouponService;
import com.matrix.system.shopXcx.api.tools.WxShopCouponUtil;
import com.matrix.system.shopXcx.api.tools.WxShopOrderUtil;
import com.matrix.system.shopXcx.api.vo.CouponReceiveInfoVO;
import com.matrix.system.shopXcx.api.vo.ShopCartBillVo;
import com.matrix.system.shopXcx.api.vo.ShopCartVo;
import com.matrix.system.shopXcx.bean.*;
import com.matrix.system.shopXcx.dao.*;
import com.matrix.system.shopXcx.dto.DiscountExplain;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.math.BigDecimal;
import java.util.*;
 
/**
 * @author jyy
 * @description 订单服务层
 * @date 2019-06-10 10:58
 */
@Service
public class WXShopOrderServiceImpl implements WXShopOrderService {
    @Autowired
    private WxShopOrderUtil wxShopOrderUtil;
    @Autowired
    private WxShopCouponUtil wxShopCouponUtil;
    @Autowired
    private RedisUserLoginUtils redisUserLoginUtils;
    @Autowired
    private WeixinServiceUtil weixinServiceUtil;
    @Autowired
    private ShopSkuDao shopSkuDao;
    @Autowired
    private ShopReceiveAddressDao shopReceiveAddressDao;
    @Autowired
    private ShopOrderDao shopOrderDao;
    @Autowired
    private ShopOrderDetailsDao shopOrderDetailsDao;
    @Autowired
    private ShopCouponDao shopCouponDao;
    @Autowired
    private ShopProductDao shopProductDao;
    @Autowired
    private ShopCouponRecordDao shopCouponRecordDao;
    @Autowired
    ShoppingGoodsDao shoppingGoodsDao;
    @Autowired
    ShoppingCartService shoppingCartService;
 
    @Autowired
    WxShopCouponService wxShopCouponService;
 
    @Autowired
    private ShopActivitiesGroupJoinDao shopActivitiesGroupJoinDao;
 
    @Autowired
    private ShopShoppingCartDao shoppingCartDao;
 
    @Autowired
    private ShopActivitiesGroupJoinUserDao shopActivitiesGroupJoinUserDao;
 
    @Autowired
    CustomerDataDictionaryDao dataDictionaryDao;
    @Value("${wx_pay_debug_onoff}")
    private boolean isDebug;
 
    @Autowired
    private BusParameterSettingsDao busParameterSettingsDao;
 
    @Override
    public BigDecimal calculationPostage(BigDecimal payPrice,Long companyId) {
        BigDecimal postage = BigDecimal.ZERO;
        BusParameterSettings yf = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.PACKAGE_PRICE, companyId);
        BusParameterSettings myje = busParameterSettingsDao.selectCompanyParamByCode(AppConstance.FREE_PACKAGE_PRICE, companyId);
        if(yf!=null&&myje!=null){
            if (Double.parseDouble(myje.getParamValue()) > payPrice.doubleValue()) {
                postage = new BigDecimal(yf.getParamValue());
            }
        }
 
        return postage;
    }
 
 
 
 
    /**
     * 创建订单
     *
     * @param addShopOrderPOJO
     * @return
     * @throws Exception
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AjaxResult createShopOrder(AddShopOrderPOJO addShopOrderPOJO) throws Exception {
        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
 
 
        //校验收货地址
        ShopReceiveAddress shopReceiveAddress = shopReceiveAddressDao.selectById(addShopOrderPOJO.getReceiveAddrId());
        if (shopReceiveAddress == null) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择正确的收获地址");
        }
 
 
        List<ShopCartVo> cartList = shoppingCartService.findUserCartList(addShopOrderPOJO.getShopId());
        //购物车不能为空
        if (CollectionUtils.isEmpty(cartList)) {
            return new AjaxResult(AjaxResult.STATUS_FAIL, "请选择您需要购买的产品");
        }
 
 
        //取出购物车中选中的产品
        List<ShopShoppingCart> buyCart = new ArrayList<>();
        //取出购物车中没有参加店铺活动的产品,和参加了店铺活动但是活动没有达到标准的产品,用来计算是否可以使用优惠券
        List<ShopShoppingCart> notCouponuyCart = new ArrayList<>();
        for (ShopCartVo shopCartVo : cartList) {
            for (ShopShoppingCart shopShoppingCart : shopCartVo.getCartList()) {
                if (shopShoppingCart.getIsSelected() == 1) {
                    buyCart.add(shopShoppingCart);
                    if (shopCartVo.getCoupon() == null || !shopCartVo.isSatisfactionCoupon()) {
                        notCouponuyCart.add(shopShoppingCart);
                    }
                }
            }
        }
 
        //计算订单优惠信息
        DiscountExplain discountExplain = buildDiscountExplain(cartList, addShopOrderPOJO.getCouponReceiveId(), bizUser.getCompanyId());
 
 
        ShopOrder shopOrder = new ShopOrder();
        shopOrder.setCompanyId(bizUser.getCompanyId());
        shopOrder.setStoreId(Integer.parseInt(addShopOrderPOJO.getShopId().toString()));
        //默认设置为产品类型
        shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS);
 
        List<ShopOrderDetails> details = new ArrayList<>();
        Integer cartCount = 0;
        for (ShopShoppingCart shopShoppingCart : buyCart) {
            ShopOrderDetails shopOrderDetails = new ShopOrderDetails();
            shopOrderDetails.setCreateBy(AppConstance.SYSTEM_USER);
            shopOrderDetails.setUpdateBy(AppConstance.SYSTEM_USER);
            shopOrderDetails.setpId(shopShoppingCart.getCartProductId());
            shopOrderDetails.setsId(shopShoppingCart.getCartSkuId());
            shopOrderDetails.setPrice(shopShoppingCart.getPrice());
            shopOrderDetails.setCount(shopShoppingCart.getCartNumber());
            shopOrderDetails.setsTitle(shopShoppingCart.getTitle() + shopShoppingCart.getName());
            shopOrderDetails.setDiscountAmount(BigDecimal.ZERO);
            shopOrderDetails.setTotalPrice(shopOrderDetails.getPrice().multiply(BigDecimal.valueOf(shopOrderDetails.getCount())));
            details.add(shopOrderDetails);
            cartCount += shopOrderDetails.getCount();
 
            //查询绑定的产品是否为家居产品,如果已经含家具产品则不再比较
            if (ShopOrder.ORDER_TYPE_GOODS != shopOrder.getOrderType()) {
                ShopSku shopSku = shopSkuDao.selectById(shopShoppingCart.getCartSkuId());
                String stokCode = shopSku.getStockCode();
                if (StringUtils.isNotBlank(stokCode)) {
                    ShoppingGoods shoppingGoods = shoppingGoodsDao.selectById(Long.parseLong(stokCode));
                    if (shoppingGoods != null) {
                        //根据购买的产品设置订单类型
                        if (Dictionary.SHOPPING_GOODS_TYPE_JJCP.equals(shoppingGoods.getGoodType())) {
                            shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS);
                        } else {
 
                        }
                    } else {
                        shopOrder.setOrderType(ShopOrder.ORDER_TYPE_GOODS);
                    }
                }
            }
 
 
        }
 
        //校验商品是否限购
        wxShopOrderUtil.verifyProductLimitInfo(details, bizUser.getOpenId());
        //TODO 更新库存和销量 更新库存和销量[考虑和erp库存联动]
        wxShopOrderUtil.updateProductAndSkuInfo(details);
        //用户openId
        shopOrder.setUserId(bizUser.getOpenId());
        shopOrder.setCreateBy("微信小程序生成");
        shopOrder.setUpdateBy("微信小程序生成");
        shopOrder.setCommodityPrice(discountExplain.getBillPrice());
        shopOrder.setPurchaseQuantity(cartCount);
        //购买方式
        shopOrder.setShippingMethod(addShopOrderPOJO.getDeliverySelect());
        //生成订单号
        shopOrder.setOrderNo(WxUtils.getOrderNum());
        //设置支付状态
        shopOrder.setPayStatus(ShopOrder.ORDER_STATUS_WAIT_PAY);
        //设置订单状态
        shopOrder.setOrderStatus(ShopOrder.ORDER_PAY_STATUS_WAIT);
 
        //设置退款费用(注:下次优化从数据字典表获取)
        shopOrder.setRefundCharge(BigDecimal.ZERO);
        //客户电话
        shopOrder.setUserTel(shopReceiveAddress.getAddrTelephone());
        //客户姓名
        shopOrder.setUserName(shopReceiveAddress.getAddrLiaisonman());
        //备注
        shopOrder.setRemarks(addShopOrderPOJO.getRemarks());
        //删除标识
        shopOrder.setDelFlag(AppConstance.DATA_USEABLE);
        //微信订单号
        shopOrder.setWxOrderNo("");
        //微信支付结果
        shopOrder.setPayResult(ShopOrder.ORDER_WX_STATUS_WAIT_PAY);
        //如果没有提交购买方式或配送方式不是物流
        //获取邮费
        shopOrder.setPostage(discountExplain.getPostage());
        shopOrder.setOrderMoney(discountExplain.getPayPrice());
        Gson g = new GsonBuilder().create();
        shopOrder.setDiscountExplain(g.toJson(discountExplain));
        shopOrder.setDiscountAmount(discountExplain.getActivity().add(discountExplain.getCoupon()));
        shopOrder.setCompanyId(HostInterceptor.getCompanyId());
        shopOrderDao.insert(shopOrder);
 
        wxShopOrderUtil.insertSendPackageInfo(shopOrder, addShopOrderPOJO.getDeliverySelect(), shopReceiveAddress);
        //给订单详情表添加订单ID
        for (ShopOrderDetails shopOrderDetails : details) {
            shopOrderDetails.setOrderId(shopOrder.getId());
        }
        if (CollectionUtils.isNotEmpty(details)) {
            shopOrderDetailsDao.batchInsert(details);
        }
        //更新使用的优惠券状态
        if (addShopOrderPOJO.getCouponReceiveId() != null) {
            ShopCouponRecord record = new ShopCouponRecord();
            record.setIsUsing(AppConstance.MY_COUPON_USE);
            record.setOrderId(shopOrder.getId());
            record.setId(addShopOrderPOJO.getCouponReceiveId());
            shopCouponRecordDao.updateByModel(record);
        }
 
        //删除用户购物车选中的产品
        shoppingCartDao.deleteUserSelectCart(bizUser.getOpenId());
 
 
        BrandWCPayRequestData payData = startPayment(shopOrder);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(payData));
        result.putInMap("orderId", shopOrder.getId());
 
        return result;
    }
 
    @Override
    public DiscountExplain buildDiscountExplain(List<ShopCartVo> cartList, Integer receiveId, Long companyId) {
        ShopCartBillVo shopCartBill = shoppingCartService.buildShopCartBillVo(cartList);
        DiscountExplain discountExplain = new DiscountExplain();
        discountExplain.setActivity(shopCartBill.getBillCouponTotal());
        discountExplain.setBillPrice(shopCartBill.getSrcTotal());
        discountExplain.setPayPrice(shopCartBill.getBillTotal());
        //计算优惠券
        if (receiveId != null) {
            CouponReceiveInfoVO couponReceiveInfoVO = shopCouponRecordDao.selectMyCouponByReceiveId(receiveId);
            if (couponReceiveInfoVO != null) {
                BigDecimal payPrice = discountExplain.getPayPrice().subtract(couponReceiveInfoVO.getOffsetAmount());
                payPrice = payPrice.compareTo(BigDecimal.ZERO) < 0 ? BigDecimal.ZERO : payPrice;
                discountExplain.setPayPrice(payPrice);
                discountExplain.setCoupon(couponReceiveInfoVO.getOffsetAmount());
            }
        }
 
        discountExplain.setPostage(calculationPostage(discountExplain.getPayPrice(),companyId));
 
        //计算实际支付
        discountExplain.setPayPrice(discountExplain.getPayPrice().add(discountExplain.getPostage()));
        return discountExplain;
    }
 
 
    /**
     * 根据订单ID结算订单
     *
     * @param orderId
     * @return
     * @throws Exception
     */
    @Override
    public AjaxResult orderSettlement(int orderId) throws Exception {
        ShopOrder shopOrder = shopOrderDao.selectById(orderId);
        if (shopOrder == null) {
            throw new GlobleException("订单不存在!");
        }
        if (!shopOrder.getPayResult().equals(ShopOrder.ORDER_PAY_STATUS_WAIT)) {
            throw new GlobleException("该订单不是待支付状态!");
        }
        BrandWCPayRequestData payData = startPayment(shopOrder);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(payData));
        result.putInMap("orderId", shopOrder.getId());
        return result;
    }
 
    /**
     * 开始付款
     *
     * @param shopOrder
     * @return
     * @throws Exception
     */
    @Override
    public BrandWCPayRequestData startPayment(ShopOrder shopOrder) throws Exception {
        BigDecimal unit = new BigDecimal("100");
        BigDecimal money = new BigDecimal(shopOrder.getOrderMoney().toString());
        BrandWCPayRequestData payData;
        String productNames = wxShopOrderUtil.getProductNames(shopOrder.getUserId(), shopOrder.getId());
        LogUtil.debug(String.valueOf(isDebug));
        if (isDebug) {
            payData = weixinServiceUtil.createOrder("[测试]" + productNames, shopOrder.getOrderNo(),
                    1, shopOrder.getUserId(), String.valueOf(shopOrder.getId()));
        } else {
            payData = weixinServiceUtil.createOrder(productNames, shopOrder.getOrderNo(),
                    unit.multiply(money).intValue(), shopOrder.getUserId(), String.valueOf(shopOrder.getId()));
        }
        ShopOrder updateParam = new ShopOrder();
        updateParam.setId(shopOrder.getId());
        updateParam.setWxOrderNo(payData.getPrepay_id());
        shopOrderDao.updateByModel(updateParam);
        return payData;
    }
 
    /**
     * 根据订单状态等条件获取我的订单列表
     *
     * @param orderInfoQueryPOJO
     * @return
     */
    @Override
    public AjaxResult getMyOrderInfo(OrderInfoQueryPOJO orderInfoQueryPOJO) {
        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        orderInfoQueryPOJO.setSort("update_time");
        if (orderInfoQueryPOJO.getOffset() >= 1) {
            orderInfoQueryPOJO.setOffset((orderInfoQueryPOJO.getOffset() - 1) * orderInfoQueryPOJO.getLimit());
        }
        List<ShopOrder> result = shopOrderDao.selectMyOrderByStatus(bizUser.getOpenId(), orderInfoQueryPOJO);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, result);
    }
 
    /**
     * 根据订单ID查询订单详情
     *
     * @param orderId
     * @return
     */
    @Override
    public AjaxResult getOrderInfoById(Integer orderId) {
        BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
        ShopOrder shopOrder = shopOrderDao.selectOrderInfoById(bizUser.getOpenId(), orderId);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, Arrays.asList(shopOrder));
    }
 
    /**
     * 取消待付款订单
     *
     * @param orderId
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public AjaxResult cancelOrderWhenWaitPay(Integer orderId) {
        updateStockAndVolumeById(orderId);
        ShopOrder shopOrder = shopOrderDao.selectById(orderId);
        //如果订单不是待付款状态
        if (ShopOrder.ORDER_PAY_STATUS_WAIT != shopOrder.getOrderStatus()) {
            throw new GlobleException("该订单不是待付款状态!");
        }
        if (shopOrder.getDiscountAmount() != null && shopOrder.getDiscountAmount().compareTo(BigDecimal.ZERO) > 0) {
            ShopCouponRecord shopCouponRecord = new ShopCouponRecord();
            BizUser bizUser = redisUserLoginUtils.getLoginUser(BizUser.class);
            shopCouponRecord.setUserId(bizUser.getOpenId());
            shopCouponRecord.setOrderId(orderId);
            List<ShopCouponRecord> recordList = shopCouponRecordDao.selectByModel(shopCouponRecord);
            if (CollectionUtils.isNotEmpty(recordList)) {
                for (ShopCouponRecord record : recordList) {
                    Map<String, Object> modifyMap = new HashMap<>();
                    modifyMap.put("id", record.getId());
                    modifyMap.put("orderId", 0);
                    modifyMap.put("isUsing", AppConstance.MY_COUPON_NOT_USE);
                    shopCouponRecordDao.updateByMap(modifyMap);
                }
            }
        }
 
        ShopActivitiesGroupJoinUser joinUser = shopActivitiesGroupJoinUserDao.selectGroupJoinUserByOrderId(orderId.longValue());
        if (joinUser != null) {
            joinUser.setIsHasCancel(ShopActivitiesGroupJoinUser.IS_HAS_CANCEL_Y);
            shopActivitiesGroupJoinUserDao.updateByModel(joinUser);
            if (joinUser.getIsHead() == ShopActivitiesGroupJoinUser.USER_IS_HEAD_Y) {
                ShopActivitiesGroupJoin groupJoin = new ShopActivitiesGroupJoin();
                groupJoin.setId(joinUser.getGjId());
                groupJoin.setGjStatus(ShopActivitiesGroupJoin.ACTIVITIES_JOIN_FAIL);
                shopActivitiesGroupJoinDao.updateByModel(groupJoin);
            }
        }
 
        //构建需要修改订单信息Map
        Map<String, Object> modifyMap = new HashMap<>();
        modifyMap.put("id", orderId);
        modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_CANCEL);
        shopOrderDao.updateByMap(modifyMap);
 
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "订单取消成功!");
    }
 
    /**
     * 删除已取消订单
     *
     * @param orderId
     * @return
     */
    @Override
    public AjaxResult delOrderById(Integer orderId) {
        ShopOrder order = shopOrderDao.selectById(orderId);
        if (order == null) {
            throw new GlobleException("没有找到该订单!");
        }
        if (!order.getOrderStatus().equals(ShopOrder.ORDER_STATUS_CANCEL)) {
            throw new GlobleException("该订单不是取消状态,不能删除!");
        }
 
        //构建需要修改订单信息Map
        Map<String, Object> modifyMap = new HashMap<>();
        modifyMap.put("id", order.getId());
        modifyMap.put("delFlag", AppConstance.DATA_DISABLE);
        shopOrderDao.updateByMap(modifyMap);
 
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "删除成功!");
    }
 
    /**
     * 订单确认收货
     *
     * @param orderId
     * @return
     */
    @Override
    public AjaxResult confirmPackageById(Integer orderId) {
        ShopOrder shopOrder = shopOrderDao.selectById(orderId);
        //如果不是待收货状态
        if (ShopOrder.ORDER_STATUS_WAIT_RECEIVE != shopOrder.getOrderStatus()) {
            throw new GlobleException("该订单不是待收货状态!");
        }
        shopOrder.setOrderStatus(ShopOrder.ORDER_STATUS_WAIT_REMARK);
        shopOrderDao.updateByModel(shopOrder);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "订单收货成功!");
    }
 
    /**
     * 加库存减销量
     *
     * @param orderId
     * @return wlz
     */
    @Override
    public AjaxResult updateStockAndVolumeById(Integer orderId) {
        //通过订单ID查询订单详情
        List<ShopOrderDetails> shopOrderDetails = shopOrderDetailsDao.selectByOrderId(orderId);
        if (CollectionUtils.isNotEmpty(shopOrderDetails)) {
            for (ShopOrderDetails orderDetails : shopOrderDetails) {
                Integer count = orderDetails.getCount();
                Integer pId = orderDetails.getpId();
                Integer sId = orderDetails.getsId();
                ShopProduct shopProduct = shopProductDao.selectById(pId);
                //获取此产品的总展示销量和真实销量
                Integer dsVolume = shopProduct.getDsVolume();
                Integer rsVolume = shopProduct.getRsVolume();
                //退货减销量
                Integer updateDs = dsVolume - count;
                Integer updateRs = rsVolume - count;
                Map<String, Object> modifyMap = new HashMap<>();
                modifyMap.put("id", pId);
                modifyMap.put("dsVolume", updateDs);
                modifyMap.put("rsVolume", updateRs);
                shopProductDao.updateByMap(modifyMap);
 
                //加库存
                ShopSku shopSku = shopSkuDao.selectById(sId);
                Integer stock = shopSku.getStock();
                Integer updateStock = stock + count;
                Map<String, Object> modifyStock = new HashMap<>();
                modifyStock.put("id", sId);
                modifyStock.put("stock", updateStock);
                shopSkuDao.updateByMap(modifyStock);
            }
        }
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, "加库存减销量修改成功!");
    }
 
    /**
     * 查询订单支付状态
     *
     * @param orderId
     * @return
     */
    @Autowired
    RabiitMqTemplate rabiitMqTemplate;
 
    @Override
    public AjaxResult findOrderPayStatus(Integer orderId) {
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, "");
        result.putInMap("status", "err");
        result.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息(错误码:005)");
 
        ShopOrder order = shopOrderDao.selectById(orderId);
        if (order.getPayStatus().equals(ShopOrder.ORDER_PAY_STATUS_SUCCESS)) {
            result.putInMap("status", "success");
            result.putInMap("msg", "支付成功");
 
        } else if (order.getPayStatus().equals(ShopOrder.ORDER_PAY_STATUS_FAIL)) {
            result.putInMap("status", "err");
            result.putInMap("msg", "查询支付信息失败,请联系客服或者刷新支付信息");
        } else {
 
            LogUtil.debug("订单等待支付中={}。。。", orderId);
            PayThreadPool.waitThread(orderId, new Object());
            result = PayThreadPool.getThreadResult(orderId);
            LogUtil.debug("订单支付完成={}。。。", orderId);
 
        }
        ShopActivitiesGroupJoin groupBuyStatus = shopActivitiesGroupJoinDao.selectGroupBuyByOrderId(orderId);
        if (groupBuyStatus != null) {
            result.putInMap("groupBuyStatus", groupBuyStatus.getGjStatus());
            result.putInMap("gjId", groupBuyStatus.getId());
        }
        return result;
    }
 
}