wzy
2021-01-10 16da0ad1fda1dffa3019425a6887d38ed4217f44
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
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
package com.matrix.system.shopXcx.action;
 
import com.matrix.component.wechat.externalInterface.common.WechatConfigure;
import com.matrix.core.anotations.RemoveRequestToken;
import com.matrix.core.anotations.SaveRequestToken;
import com.matrix.core.constance.MatrixConstance;
import com.matrix.core.constance.SystemErrorCode;
import com.matrix.core.constance.SystemMessageCode;
import com.matrix.core.exception.GlobleException;
import com.matrix.core.pojo.AjaxResult;
import com.matrix.core.pojo.PaginationVO;
import com.matrix.core.tools.*;
import com.matrix.component.redis.RedisUserLoginUtils;
import com.matrix.system.common.bean.SysUsers;
import com.matrix.system.common.constance.AppConstance;
 
import com.matrix.component.wechat.externalInterface.weixinUtil.WeixinServiceUtil;
import com.matrix.system.hive.action.util.QueryUtil;
import com.matrix.system.shopXcx.api.service.WxShopRefundRecordService;
import com.matrix.system.shopXcx.bean.*;
import com.matrix.system.shopXcx.dao.ShopCouponRecordDao;
import com.matrix.system.shopXcx.dao.ShopDeliveryInfoDao;
import com.matrix.system.shopXcx.dao.ShopOrderDao;
import com.matrix.system.shopXcx.dao.ShopRefundRecordDao;
import com.matrix.component.tools.WxTempLateMsgUtil;
import com.matrix.system.shopXcx.api.service.WXShopOrderService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
 
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
 
/**
 * @description 退款记录表
 * @author jiangyouyao
 * @date 2019-06-16 15:34
 */
@Controller
@RequestMapping(value = "admin/shopRefundRecord")
public class ShopRefundRecordAction {
 
    @Autowired
    private ShopRefundRecordDao shopRefundRecordDao;
    @Autowired
    private ShopOrderDao shopOrderDao;
    @Autowired
    private WeixinServiceUtil weixinServiceUtil;
    @Autowired
    private WXShopOrderService wxShopOrderService;
    @Autowired
    private ShopDeliveryInfoDao shopDeliveryInfoDao;
    @Autowired
    private RedisUserLoginUtils redisUserLoginUtils;
 
    @Autowired
    private ShopCouponRecordDao shopCouponRecordDao;
 
    @Autowired
    private WxShopRefundRecordService refundRecordService;
 
    //记录编辑前的值Before_Edit_Value
    public static final String BEV="ShopRefundRecord_BEV";
 
    @Value("${wx_pay_debug_onoff}")
    private boolean isDebug;
 
    /**
     * 列表显示
     */
    @RequestMapping(value =  "/showList")
    public @ResponseBody AjaxResult showList(ShopRefundRecord shopRefundRecord, PaginationVO pageVo) {
        QueryUtil.setQueryLimitCom(shopRefundRecord);
        List<ShopRefundRecord> dataList = shopRefundRecordDao.selectInPage(shopRefundRecord, pageVo);
        AjaxResult result = new AjaxResult(AjaxResult.STATUS_SUCCESS, dataList,
                shopRefundRecordDao.selectTotalRecord(shopRefundRecord));
        return result;
    }
       
    /**
     * 新增
     */   
    @RemoveRequestToken    
       @RequestMapping(value =  "/addShopRefundRecord")
    public @ResponseBody AjaxResult addShopRefundRecord(ShopRefundRecord shopRefundRecord) {
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        shopRefundRecord.setCreateBy(user.getSuName());
        shopRefundRecord.setUpdateBy(user.getSuName());
        shopRefundRecord.setCompanyId(user.getCompanyId());
         int i=shopRefundRecordDao.insert(shopRefundRecord);
         if(i > 0){
             return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.ADD_SUCCES, "退款记录表");
         }else {
            throw new GlobleException(SystemErrorCode.DATA_ADD_FAIL);
        }
    }
 
 
    /**
     *
     * @Description (TODO 自定义数据绑定, 解决此问题)
     * @param binder
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(false);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
    }
 
    /**
     * 同意退款按钮
     */
    @RequestMapping(value = "/agreeRefund")
    public @ResponseBody AjaxResult agreeRefund(ShopRefundRecord shopRefundRecord) {
        //将申请退款状态改为等待用户填写物流单号
        Map<String, Object> modifyMap = new HashMap<>();
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        String suName = user.getSuName();
        modifyMap.put("id", shopRefundRecord.getId());
        modifyMap.put("refundStatus", AppConstance.WAIT_USER_WRITE_WAYBILLNO);
        modifyMap.put("auditStatus", AppConstance.REFUND_AUDITED_PASS);
        modifyMap.put("handler", suName);
        modifyMap.put("handingTime", new Date());
        int i = shopRefundRecordDao.updateByMap(modifyMap);
        if (i > 0) {
            //同意退款后发送微信提醒填写物流单号
            ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(shopRefundRecord.getId());
            sendRefundLogisticsInfoToUser(fundRecord);
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "操作成功", "退款记录表");
        } else {
            throw new GlobleException("操作失败");
        }
 
    }
 
    /**
     * 拒绝退款
     */
    @Transactional(rollbackFor = Exception.class)
    @RequestMapping(value = "/refundRefuse")
    public @ResponseBody AjaxResult refundRefuse(ShopRefundRecord shopRefundRecord) {
        //将拒绝理由加入退款表,将审核状态改为审核不通过
        Map<String, Object> modifyMap = new HashMap<>();
        SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
        String suName = user.getSuName();
        modifyMap.put("id", shopRefundRecord.getId());
        modifyMap.put("refundRefuseReason", shopRefundRecord.getRefundRefuseReason());
        modifyMap.put("auditStatus", AppConstance.REFUND_AUDITED_FAILED);
        modifyMap.put("handler", suName);
        modifyMap.put("handingTime", new Date());
        int i = shopRefundRecordDao.updateByMap(modifyMap);
        //将申请退款状态改为退款失败
        shopRefundRecordDao.updateRefundStatusByFail(shopRefundRecord.getId(), AppConstance.REFUND_FAIL);
        //如果运单号不等于null就将订单状态改为待收货3,为null就改为待配送2
        ShopRefundRecord record = new ShopRefundRecord();
        record = shopRefundRecordDao.selectById(shopRefundRecord.getId());
        Map<String, Object> modifyOrder = new HashMap<>();
        //如果运单号不等于null就将订单状态改为待收货3,为null就改为待配送2
        ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectByOrderId(record.getOrderId());
        ShopOrder order = shopOrderDao.selectById(record.getOrderId());
        if(null != order){
            //如果是门店自提就将订单状态改为待收货3
            if(AppConstance.SHIPPING_METHOD_SELF .equals(order.getShippingMethod()) ){
                modifyOrder.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE);
            }
            if(AppConstance.SHIPPING_METHOD_LOGISTING .equals(order.getShippingMethod()) && null != shopDeliveryInfo.getWaybillNo()){
                modifyOrder.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_RECEIVE);
            }
            if(AppConstance.SHIPPING_METHOD_LOGISTING .equals(order.getShippingMethod()) && null == shopDeliveryInfo.getWaybillNo()){
                modifyOrder.put("orderStatus", ShopOrder.ORDER_STATUS_WAIT_SEND);
            }
            modifyOrder.put("id", record.getOrderId());
            shopOrderDao.updateByMap(modifyOrder);
        }
        //退款拒绝后发送微信提醒
        sendFailedRefundInfoToUser(record);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "操作成功", "退款记录表");
        } else {
            throw new GlobleException("拒绝失败");
        }
    }
 
    /**
     * 确认退款(退款审核)
     */
    @Transactional(rollbackFor = Exception.class)
    @RemoveRequestToken
    @RequestMapping(value =  "/modifyShopRefundRecord")
    public @ResponseBody AjaxResult modifyShopRefundRecord(ShopRefundRecord newShopRefundRecord) {
        if(null != newShopRefundRecord.getRefundRefuseReason()){
            newShopRefundRecord.setRefundRefuseReason("");
        }
        ShopRefundRecord oldShopRefundRecord = WebUtil.getSessionAttribute(BEV);
            int i = 0;
            Map<String, Object> modifyMap = new HashMap<>();
            try {
                if (!ModelUtils.isModified(oldShopRefundRecord, newShopRefundRecord)) {
                    i = MatrixConstance.DML_SUCCESSS;
                }
                modifyMap = ModelUtils.comparePojo2Map(oldShopRefundRecord, newShopRefundRecord);
 
            } catch (Exception e) {
                throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL, e, newShopRefundRecord);
            }
            if (modifyMap.size() > 0) {
                //如果修改退款金额就判断是否超过了订单金额
                ShopRefundRecord cord = new ShopRefundRecord();
                cord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId());
                ShopOrder shopOrder = shopOrderDao.selectById(cord.getOrderId());
                BigDecimal orderMoney = shopOrder.getOrderMoney();
                if(null != modifyMap.get("refundMoney")){
                    BigDecimal refundMoney = new BigDecimal(modifyMap.get("refundMoney").toString());
                    if(refundMoney.compareTo( orderMoney)>0){
                        throw new GlobleException("退款金额不能大于订单金额");
                    }
                }
 
                SysUsers user = WebUtil.getSessionAttribute(MatrixConstance.LOGIN_KEY);
                String suName = user.getSuName();
                modifyMap.put("id", oldShopRefundRecord.getId());
                modifyMap.put("handler", suName);
                modifyMap.put("handingTime", new Date());
                shopRefundRecordDao.updateByMap(modifyMap);
 
            }
            Boolean flag = false;
            ShopRefundRecord shopRefundRecord = new ShopRefundRecord();
            shopRefundRecord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId());
            //仅退款
            if(AppConstance.REFUND .equals(shopRefundRecord.getRefundType())){
                LogUtil.debug("进入确认退款(仅退款)流程。。。", shopRefundRecord.getId());
                    //满足条件进行退款
                    Boolean aBoolean = refundToUser(oldShopRefundRecord.getId().toString(), shopRefundRecord);
                    flag = aBoolean;
                    if(flag){
                        //退款成功后发送微信提醒
                        ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId());
                        sendRefundInfoToUser(fundRecord);
                    }
                }
 
            //退货退款
            if(AppConstance.REFUND_GOODS .equals(shopRefundRecord.getRefundType())){
                //只有审核通过的数据才能进行退款
                if(!AppConstance.REFUND_AUDITED_PASS .equals(shopRefundRecord.getAuditStatus())){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有审核通过的数据才能进行退款");
                }
                //只有已收货的数据才能进行退款
                if(!AppConstance.GOODS_RECEIVED .equals(shopRefundRecord.getRefundGoodsStatus())){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有已收货的数据才能进行退款");
                }
                //退款成功的状态不能重复退款
                if(AppConstance.REFUND_SUCCESS.equals(shopRefundRecord.getRefundStatus())){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":该条订单已退款成功,不能重复退款");
                }
                //满足条件进行退款
                Boolean aBoolean = refundToUser(oldShopRefundRecord.getId().toString(), shopRefundRecord);
                flag = aBoolean;
                if(flag){
                    //退款成功后发送微信提醒
                    ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(oldShopRefundRecord.getId());
                    sendRefundInfoToUser(fundRecord);
                }
            }
 
            i = MatrixConstance.DML_SUCCESSS;
            WebUtil.removeSessionAttribute(BEV);
            if (flag) {
                return new AjaxResult(AjaxResult.STATUS_SUCCESS, "操作成功", "退款记录表");
            } else {
                throw new GlobleException("操作失败");
            }
 
    }
    
    
       /**
     * 进入修改界面
     */   
    @SaveRequestToken
       @RequestMapping(value =  "/editForm")
    public ModelAndView editForm(Integer id) {
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord();
        List<ShopRefundRecordDetails> shopRefundRecordDetails = new ArrayList<ShopRefundRecordDetails>();
        ModelAndView modelAndView = new ModelAndView("admin/shop/shopRefundRecord-form");
        if (id != null) {
            shopRefundRecord = shopRefundRecordDao.selectById(id);
            Integer orderId = shopRefundRecord.getOrderId();
            shopRefundRecordDetails = shopRefundRecordDao.selectDetailsById(orderId);
            WebUtil.setSessionAttribute(BEV, shopRefundRecord);
        }
        modelAndView.addObject("obj",shopRefundRecord);
        modelAndView.addObject("objDetails",shopRefundRecordDetails);
        return modelAndView;
    }
 
    /**
     * 进入退款详情界面
     */
    @SaveRequestToken
    @RequestMapping(value =  "/detailsForm")
    public ModelAndView detailsForm(Integer id) {
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord();
        List<ShopRefundRecordDetails> shopRefundRecordDetails = new ArrayList<ShopRefundRecordDetails>();
        ModelAndView modelAndView = new ModelAndView("admin/shop/shopRefundRecord-details");
        if (id != null) {
            shopRefundRecord = shopRefundRecordDao.selectById(id);
            Integer orderId = shopRefundRecord.getOrderId();
            shopRefundRecordDetails = shopRefundRecordDao.selectDetailsById(orderId);
            WebUtil.setSessionAttribute(BEV, shopRefundRecord);
        }
        modelAndView.addObject("obj",shopRefundRecord);
        modelAndView.addObject("objDetails",shopRefundRecordDetails);
        return modelAndView;
    }
 
 
    /**
     * 删除
     */  
     @RequestMapping(value = "/del")
    public @ResponseBody AjaxResult del(String keys) {
        List<String> ids = StringUtils.strToCollToString(keys, ",");
        int i =  shopRefundRecordDao.deleteByIds(ids);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, SystemMessageCode.DELETE_SUCCES, i);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_DELETE_FAIL);
        }
    }
 
    /**
     * 确认收货
     */
    @RequestMapping(value = "/confirmReceivingGoods")
    public @ResponseBody AjaxResult confirmReceivingGoods(String keys) {
        List<String> ids = StringUtils.strToCollToString(keys, ",");
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord();
        for(String id : ids){
            shopRefundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id));
            if(!AppConstance.REFUND_GOODS .equals(shopRefundRecord.getRefundType())){
                throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":不是退货退款类型,不能确认收货");
            }
            if(!AppConstance.REFUND_AUDITED_PASS .equals(shopRefundRecord.getAuditStatus())){
                throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":审核通过的数据才能确认收货");
            }
        }
        int i =  shopRefundRecordDao.updateRefundTypeByIds(ids, AppConstance.GOODS_RECEIVED);
        if (i > 0) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "成功收货", i);
        } else {
            throw new GlobleException(SystemErrorCode.DATA_UPDATE_FAIL);
        }
    }
 
    /**
     * 退款
     */
    @RequestMapping(value = "/confirmRefund")
    public @ResponseBody AjaxResult confirmRefund(String keys) {
        List<String> ids = StringUtils.strToCollToString(keys, ",");
        ShopRefundRecord shopRefundRecord = new ShopRefundRecord();
        Boolean flag = false;
        for(String id : ids){
            shopRefundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id));
            //仅退款
            if(AppConstance.REFUND .equals(shopRefundRecord.getRefundType())){
                if(!AppConstance.REFUND_AUDITED_PASS .equals(shopRefundRecord.getAuditStatus())){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有审核通过的数据才能进行退款");
                }
                //退款成功的状态不能重复退款
                if(AppConstance.REFUND_SUCCESS.equals(shopRefundRecord.getRefundStatus())){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":该条订单已退款成功,不能重复退款");
                }
                else{
                    //满足条件进行退款
                    Boolean aBoolean = refundToUser(id, shopRefundRecord);
                    flag = aBoolean;
                    if(flag){
                        //退款成功后发送微信提醒
                        ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id));
                        sendRefundInfoToUser(fundRecord);
                        refundRecordService.updateGroupBuyStatus(Long.parseLong(id));
                    }
                }
            }
 
            //退货退款
            if(AppConstance.REFUND_GOODS.equals(shopRefundRecord.getRefundType())){
                //只有审核通过的数据才能进行退款
                if(AppConstance.REFUND_AUDITED_PASS.equals(shopRefundRecord.getAuditStatus())){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有审核通过的数据才能进行退款");
                }
                //只有已收货的数据才能进行退款
                if(AppConstance.GOODS_RECEIVED.equals(shopRefundRecord.getRefundGoodsStatus()) ){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":只有已收货的数据才能进行退款");
                }
                //退款成功的状态不能重复退款
                if(AppConstance.REFUND_SUCCESS.equals(shopRefundRecord.getRefundStatus()) ){
                    throw new GlobleException("此条数据"+shopRefundRecord.getRefundNo()+":该条订单已退款成功,不能重复退款");
                }
                //满足条件进行退款
                Boolean aBoolean = refundToUser(id, shopRefundRecord);
                flag = aBoolean;
                if(flag){
                    //退款成功后发送微信提醒
                    ShopRefundRecord fundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id));
                    sendRefundInfoToUser(fundRecord);
                    refundRecordService.updateGroupBuyStatus(Long.parseLong(id));
                }
            }
        }
 
        if (flag) {
            return new AjaxResult(AjaxResult.STATUS_SUCCESS, "退款成功");
        } else {
            throw new GlobleException("退款失败");
        }
    }
 
    /**
     * 调用退款接口进行退款
     * @param id
     * @param shopRefundRecord
     */
    public Boolean refundToUser(String id,ShopRefundRecord shopRefundRecord){
        LogUtil.info("进入退款接口进行退款。。。", id);
        Boolean flag = false;
        //调用退款接口,将钱返给用户
        ShopOrder shopOrder = shopOrderDao.selectById(shopRefundRecord.getOrderId());
        if(null == shopOrder){
            throw new GlobleException("没有找到需要退款的订单信息");
        }
        //商户订单编号(原订单编号)
        String orderNo = shopOrder.getOrderNo();
        LogUtil.info("退款商户订单编号为{}", orderNo);
        //退款编号
        String refundNo = shopRefundRecord.getRefundNo();
        LogUtil.info("退款退款编号为{}", refundNo);
        //订单金额
        BigDecimal orderMoney = shopOrder.getOrderMoney();
        LogUtil.info("订单金额{}。", orderMoney);
        BigDecimal a1 = new BigDecimal(orderMoney.toString());
        BigDecimal aa = new BigDecimal(100);
        int orMoney = a1.multiply(aa).intValue();
        LogUtil.info("退款订单金额{}", orMoney);
        //Double orderMoney = 0.1 * 100;
        //退款金额
        BigDecimal refundMoney = shopRefundRecord.getRefundMoney();
        LogUtil.info("退款金额{}。", refundMoney);
        BigDecimal b1 = new BigDecimal(refundMoney.toString());
        BigDecimal bb = new BigDecimal(100);
        int reMoney = b1.multiply(bb).intValue();
        LogUtil.info("退款退款金额{}", reMoney);
 
 
 
        if (isDebug) {
            boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, 1, 1, null);
            flag = b;
        } else {
            LogUtil.info("开始调用退款接口。。。退款编号为{}", refundNo);
            boolean b = weixinServiceUtil.comRefund(orderNo, refundNo, orMoney, reMoney, null);
            flag = b;
        }
 
        if(flag){
            try{
                LogUtil.debug("退款成功,开始修改退款表和订单表状态。。。", id);
                //将申请退款状态改为成功退款
                shopRefundRecordDao.updateRefundStatusByIds(Integer.valueOf(id), AppConstance.REFUND_SUCCESS);
                //将审核状态改为审核通过
                Map<String, Object> modifyRefund = new HashMap<>();
                modifyRefund.put("id", Integer.valueOf(id));
                modifyRefund.put("auditStatus", AppConstance.REFUND_AUDITED_PASS);
                shopRefundRecordDao.updateByMap(modifyRefund);
                //退款成功后同时把优惠券退回到用户的账号中
                if (shopOrder.getDiscountAmount() != null && shopOrder.getDiscountAmount().compareTo(BigDecimal.ZERO) == 0) {
                    ShopCouponRecord shopCouponRecord = new ShopCouponRecord();
                    String userIds = shopRefundRecord.getUserId();
                    shopCouponRecord.setUserId(userIds);
                    shopCouponRecord.setOrderId(shopOrder.getId());
                    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("isUsing", AppConstance.MY_COUPON_NOT_USE);
                            modifyMap.put("orderId", 0);
                            shopCouponRecordDao.updateByMap(modifyMap);
                        }
                    }
                }
 
                //退款成功后加库存减销量
                shopRefundRecord = shopRefundRecordDao.selectById(Integer.valueOf(id));
                Integer orderId = shopRefundRecord.getOrderId();
                Integer orderStatus = shopOrder.getOrderStatus();
                Integer refundType = shopRefundRecord.getRefundType();
                //----当订单是物流、待配送、仅退款状态就不要加库存减销量
                //物流、待收货、仅退款不要加库存减销量
                ShopDeliveryInfo shopDeliveryInfo = shopDeliveryInfoDao.selectByOrderId(orderId);
                Boolean refundFlag = AppConstance.SHIPPING_METHOD_LOGISTING.equals("物流配送") && null != shopDeliveryInfo.getWaybillNo() && AppConstance.REFUND .equals(refundType) ;
                if(!refundFlag){
                    wxShopOrderService.updateStockAndVolumeById(orderId);
                }
 
                //将订单表的订单状态改为退款成功,更新退款费用
                Map<String, Object> modifyMap = new HashMap<>();
                modifyMap.put("id", shopRefundRecord.getOrderId());
                modifyMap.put("orderStatus", ShopOrder.ORDER_STATUS_MONEYBACK_SUCCESS);
                modifyMap.put("refundCharge", shopRefundRecord.getRefundMoney());
                shopOrderDao.updateByMap(modifyMap);
            }catch (Exception e){
                LogUtil.debug("退款成功,修改退款表和订单表状态出错。。。", id);
                e.printStackTrace();
            }
        }
        return flag;
    }
 
    //退款成功后发送微信提醒
    private int sendRefundInfoToUser(ShopRefundRecord shopRefundRecord) {
        ShopOrder order = shopOrderDao.selectById(shopRefundRecord.getOrderId());
        if (order == null) {
            throw new GlobleException("没有找到需要退款的订单信息");
        }
        List<String> msg = new ArrayList<>();
        //退款说明
        String refundExplain = "退款已经原路返回,具体到账时间可能会有1-3天延迟";
        msg.add(order.getOrderNo());
        msg.add(DateUtil.dateToString(shopRefundRecord.getRefundTime(),DateUtil.DATE_FORMAT_SS));
        msg.add(refundExplain);
        msg.add("商品名称");
        String formId = null;
        if(AppConstance.REFUND_GOODS.equals(shopRefundRecord.getRefundType()) && null != shopRefundRecord.getRefundTransactionNo()){
            formId = shopRefundRecord.getRefundTransactionNo();
        }else {
            formId = order.getWxOrderNo().split("=")[1];
        }
        String page = "pages/refunDetail/refunDetail?id=" + shopRefundRecord.getId() + "&&status=1" + "&&inform=1";
        int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(),
                page, WxTempLateMsgUtil.REFUND_SUCCESS, formId);
        return res;
    }
 
    //退款拒绝后发送微信提醒
    private int sendFailedRefundInfoToUser(ShopRefundRecord shopRefundRecord) {
        ShopOrder order = shopOrderDao.selectById(shopRefundRecord.getOrderId());
        if (order == null) {
            throw new GlobleException("没有找到拒绝退款的订单信息");
        }
        List<String> msg = new ArrayList<>();
        //退款说明
        String remarks = "如有疑问请联系客服";
        msg.add(order.getOrderNo());
        msg.add("商品名称");
        msg.add(shopRefundRecord.getRefundRefuseReason());
        msg.add(shopRefundRecord.getRefundCause());
        String formId = null;
        if(AppConstance.REFUND_GOODS .equals(shopRefundRecord.getRefundType()) && null != shopRefundRecord.getRefundTransactionNo()){
            formId = shopRefundRecord.getRefundTransactionNo();
        }else {
            formId = order.getWxOrderNo().split("=")[1];
        }
        String page = "pages/refunDetail/refunDetail?id=" + shopRefundRecord.getId() + "&&status=2" + "&&inform=1";
        int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(),
                page, WxTempLateMsgUtil.REFUND_FAILED, formId);
        return res;
    }
 
    //同意退款后发送微信提醒填写物流单号
    private int sendRefundLogisticsInfoToUser(ShopRefundRecord shopRefundRecord) {
        ShopOrder order = shopOrderDao.selectById(shopRefundRecord.getOrderId());
        if (order == null) {
            throw new GlobleException("没有找到发送微信提醒的订单信息");
        }
        List<String> msg = new ArrayList<>();
        //退款说明
        String remarks = "申请退款已审核通过,请尽快填写退货物流信息";
        msg.add(order.getOrderNo());
        msg.add("商品名称");
        msg.add("待退回");
        msg.add(remarks);
        String formId = order.getWxOrderNo().split("=")[1];
        String page = "pages/refunding/refunding?id=" + shopRefundRecord.getId() + "&&inform=1";
        int res = WxTempLateMsgUtil.sendWxTemplateMsg(msg, order.getUserId(),
                page, WxTempLateMsgUtil.WRITE_LOGISTICS, formId);
        return res;
    }
}