admin
2020-04-29 a358495d588a844d9fb2e3e4a9b6c043274aac68
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
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
package com.yeshi.fanli.controller.client.v2;
 
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import javax.annotation.Resource;
 
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.DateUtil;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.NumberUtil;
 
import com.yeshi.fanli.dto.order.UserTeamLevel;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.HongBaoV2;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.bus.user.UserSystemCouponRecord;
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
import com.yeshi.fanli.entity.order.CommonOrder;
import com.yeshi.fanli.entity.order.CommonOrderGoods;
import com.yeshi.fanli.entity.order.ESOrder;
import com.yeshi.fanli.entity.order.HongBaoOrder;
import com.yeshi.fanli.entity.system.ConfigKeyEnum;
import com.yeshi.fanli.entity.system.SystemCoupon.CouponTypeEnum;
import com.yeshi.fanli.entity.taobao.TaoBaoWeiQuanOrder;
import com.yeshi.fanli.exception.order.CommonOrderException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.common.JumpDetailV2Service;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.count.HongBaoV2CountService;
import com.yeshi.fanli.service.inter.order.CommonOrderGoodsService;
import com.yeshi.fanli.service.inter.order.CommonOrderService;
import com.yeshi.fanli.service.inter.order.ESOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoOrderService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMapService;
import com.yeshi.fanli.service.inter.order.OrderHongBaoMoneyComputeService;
import com.yeshi.fanli.service.inter.order.tb.TaoBaoWeiQuanOrderService;
import com.yeshi.fanli.service.inter.user.UserCustomSettingsService;
import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponRecordService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.service.inter.user.invite.UserInviteService;
import com.yeshi.fanli.service.inter.user.vip.UserVIPInfoService;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.MoneyBigDecimalUtil;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.user.UserLevelUtil;
import com.yeshi.fanli.vo.order.CommonOrderVO;
import com.yeshi.fanli.vo.order.GoodsRebateVO;
import com.yeshi.fanli.vo.order.HongBaoCountVO;
import com.yeshi.fanli.vo.order.OrderCountVO;
import com.yeshi.fanli.vo.order.OrderRebateVO;
import com.yeshi.fanli.vo.user.UserInfoExtraVO;
import com.yeshi.fanli.vo.user.UserSettingsVO;
 
import net.sf.json.JSONObject;
 
@Controller
@RequestMapping("api/v2/user/order")
public class UserOrderControllerV2 {
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private UserInfoExtraService userInfoExtraService;
 
    @Resource
    private CommonOrderService commonOrderService;
 
    @Resource
    private HongBaoV2CountService hongBaoV2CountService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private UserCustomSettingsService userCustomSettingsService;
 
    @Resource
    private ESOrderService esOrderService;
 
    @Resource
    private UserVIPInfoService userVIPInfoService;
 
    @Resource
    private HongBaoV2Service hongBaoV2Service;
    
    @Resource
    private HongBaoOrderService hongBaoOrderService;
 
    @Resource
    private OrderHongBaoMoneyComputeService orderHongBaoMoneyComputeService;
 
    @Resource
    private CommonOrderGoodsService commonOrderGoodsService;
    
    @Resource
    private TaoBaoWeiQuanOrderService taoBaoWeiQuanOrderService;
    
    @Resource
    private JumpDetailV2Service jumpDetailV2Service;
    
    @Resource
    private UserSystemCouponRecordService userSystemCouponRecordService;
    
    @Resource
    private UserInviteService userInviteService;
    
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
    
    @Resource
    private OrderHongBaoMapService orderHongBaoMapService;
 
    /**
     * 订单列表
     * 
     * @param acceptData
     * @param page
     * @param uid
     * @param state
     *            状态:0全部 1-未到账 2-已到账 3-已失效 4已收货
     * @param type
     *            类型:1-返利订单 2-分享订单 3-邀请订单
     * @param orderState
     *            1有效订单 2 维权订单 3失效订单
     * @param orderNo
     *            订单号
     * @param startTime
     *            起始时间
     * @param endTime
     *            结束时间
     * @param slotTime
     *            时间段:1-最近三天 2-最近七天 3最近半月 4本月 5近三月 6近半年
     * @param dateType
     *            1-今日 2-昨天 3-本月 4-上个月 |
     * @param source 
     *             页面来源:welfareCore-福利中心、bonus -奖金统计(我的界面)
     * @param out
     */
    @RequestMapping(value = "getOrderList", method = RequestMethod.POST)
    public void getOrderList(AcceptData acceptData, Integer page, Long uid, Integer state, String type,
            Integer orderState, String orderNo, String startTime, String endTime, Integer slotTime, Integer dateType,
            Integer goodsType, String source, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        if (page == null || page < 1)
            page = 1;
 
        // 搜索内容、订单号
        if (!StringUtil.isNullOrEmpty(orderNo)
                && VersionUtil.greaterThan_2_0_6(acceptData.getPlatform(), acceptData.getVersion())) {
            searchOrder(acceptData, orderNo, page, uid, out);
            return;
        }
 
        // 转换状态
        if (state != null) {
            if (state == 0) {
                state = null; // 所有
            } else if (state == 4) {
                state = null;
                orderState = 4; // 已收货
            } else if (state == 5) {
                state = null;
                orderState = 2; // 已维权
            }
        }
        if (state != null && orderState != null && (orderState == 2 || orderState == 3)) {
            state = null;
        }
 
        // 订单类型
        Integer orderType = null;
        if (StringUtil.isNullOrEmpty(type)) {
            orderType = null;
        } else if (!"0".equalsIgnoreCase(type)) {
            orderType = Integer.parseInt(type);
        }
 
        if (goodsType != null && goodsType == 0)
            goodsType = null;
 
        // 筛选时间
        if (slotTime != null) {
            try {
                SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
 
                switch (slotTime) {
                case 1: // 最近三天
                    endTime = sd.format(new Date());
                    startTime = DateUtil.reduceDay(2, endTime);
                    break;
                case 2: // 最近七天
                    endTime = sd.format(new Date());
                    startTime = DateUtil.reduceDay(6, endTime);
                    break;
                case 3: // 最近15天 (半月)
                    endTime = sd.format(new Date());
                    startTime = DateUtil.reduceDay(14, endTime);
                    break;
                case 4: // 最近三十天 (本月)
                    dateType = 10;
                    break;
                case 5: // 最近九十天(近三月)
                    dateType = 11;
                    break;
                case 6: // 最近一百八十天(近半年)
                    dateType = 12;
                    break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
 
        if (endTime != null && endTime.trim().length() > 0) {
            endTime += " 23:59:59";
        }
 
        List<Integer> listSource = new ArrayList<>();
        if (goodsType != null) {
            listSource.add(goodsType);
        }
 
        try {
            // 筛选结果顶部统计
            String validMoney = "0.00";
            String invalidMoney = "0.00";
            if (page == 1) {
                BigDecimal predictMoney = hongBaoV2CountService.getRewardMoneyByToSearch(uid, dateType, orderType, 1,
                        orderNo, state, startTime, endTime, listSource);
                if (predictMoney != null)
                    validMoney = predictMoney.setScale(2, BigDecimal.ROUND_DOWN).toString();
 
                BigDecimal postSaleMoney = hongBaoV2CountService.getRewardMoneyByToSearch(uid, dateType, orderType, 2,
                        orderNo, state, startTime, endTime, listSource);
                if (postSaleMoney != null)
                    invalidMoney = postSaleMoney.setScale(2, BigDecimal.ROUND_DOWN).toString();
 
                if (orderType != null && dateType != null && dateType == 4) {
                    if (orderType == 1) {
                        dateType = 6; // 返利订单有效
                    } else {
                        dateType = 5; // 新版查询本月到账
                    }
                }
            }
            
            
            long count = 0L;
            List<CommonOrderVO> list = null;
            if (VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
                list = commonOrderService.getOrderList(acceptData, page, uid, state, orderType,
                        orderState, orderNo, startTime, endTime, dateType, listSource);
                count = commonOrderService.countOrderList(uid, state, orderType, orderState, orderNo,
                        startTime, endTime, dateType, listSource);
            } else {
                list = commonOrderService.getOrderByUid(acceptData, page, uid, state, orderType,
                        orderState, orderNo, startTime, endTime, dateType, listSource);
                count = commonOrderService.countGroupOrderNoByUid(uid, state, orderType, orderState, orderNo,
                        startTime, endTime, dateType, listSource);
            }
 
            // 判断是否需要显示订单找回提示 8秒内请求3次触发
            String orderFindUrl = null;
            if (state == null && page == 1) {
                if (redisManager.frequencyLimit("orderlist-" + acceptData.getDevice(), 8, 4) || count == 0L) {
                    orderFindUrl = configService.get(ConfigKeyEnum.orderFindNotifyUrl.getKey());
                }
            }
 
            JSONObject data = new JSONObject();
            data.put("count", count);
            data.put("result_list", JsonUtil.getApiCommonGson().toJson(list));
            data.put("helpUrl", configService.get(ConfigKeyEnum.orderListHelp.getKey()));
            data.put("validMoney", "¥ " + validMoney);
            data.put("invalidMoney", "¥ " + invalidMoney);
            data.put("findOrderHelpUrl", orderFindUrl);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (CommonOrderException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "查询失败"));
            LogHelper.errorDetailInfo(e);
        }
    }
 
    /**
     * 搜索订单
     * @param key
     * @param out
     */
    private void searchOrder(AcceptData acceptData, String key, Integer page, Long uid, PrintWriter out) {
        try {
            long count = 0;
            List<CommonOrderVO> list = null;
            if (NumberUtil.isNumeric(key.replace("-", ""))) {
                list = commonOrderService.getOrderByUid(acceptData, page, uid, null, null, null, key, null, null, null,
                        null);
            }
 
            if (list == null || list.size() == 0) {
                List<ESOrder> listES = esOrderService.query(key, uid.toString(), null);
                if (listES.size() != 0) {
                    list = commonOrderService.searchOrderByUid(acceptData, page, Constant.PAGE_SIZE, uid, listES);
                    count = commonOrderService.countSearchOrderByUid(uid, listES);
                }
            } else {
                count = list.size();
            }
 
            if (list == null) {
                list = new ArrayList<>();
            }
 
            JSONObject data = new JSONObject();
            data.put("count", count);
            data.put("result_list", JsonUtil.getApiCommonGson().toJson(list));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "查询失败"));
            e.printStackTrace();
            LogHelper.errorDetailInfo(e);
        }
    }
 
    /**
     * 用户订单统计
     * 
     * @param acceptData
     * @param uid
     *            用户id
     *    type 类型:0全部、1淘宝 2京东、拼多多
     * @param out
     */
    @RequestMapping(value = "getOrderCount", method = RequestMethod.POST)
    public void getOrderCount(AcceptData acceptData, Long uid, Integer type, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "请求参数不正确"));
            return;
        }
 
        try {
            UserInfo user = userInfoService.selectByPKey(uid);
            if (user == null) {
                out.print(JsonUtil.loadFalseResult(1, "用户不存在"));
                return;
            }
 
            UserInfo userInfo = UserUtil.filterForClientUser(user);
            UserInfoExtraVO userInfoExtra = userInfoExtraService.getInfoExtraVOByUid(user.getId());
            if (userInfoExtra != null && userInfoExtra.getUserRank() != null) {
                userInfo.setRankIcon(userInfoExtra.getUserRank().getIcon());
                userInfo.setRankNamePicture(userInfoExtra.getUserRank().getPicture());
            }
            JSONObject data = new JSONObject();
            data.put("userInfo", userInfo);
 
            List<Integer> listSource = new ArrayList<>();
            if (type == null || type == 0) {
                OrderCountVO total = commonOrderService.getOrderCount(uid, null, null);
                data.put("total", total.getSelf() + total.getShared() + total.getInvite());
                data.put("self", total.getSelf());
                data.put("shared", total.getShared());
                data.put("invite", total.getInvite());
            } else {
                data.put("total", 0);
                data.put("self", 0);
                data.put("shared", 0);
                data.put("invite", 0);
 
                listSource.add(type);
            }
 
            // 今天
            OrderCountVO today = commonOrderService.getOrderCount(uid, 1, listSource);
            today.setTotal(today.getSelf() + today.getShared() + today.getInvite());
            // 昨天
            OrderCountVO yesterday = commonOrderService.getOrderCount(uid, 2, listSource);
            yesterday.setTotal(yesterday.getSelf() + yesterday.getShared() + yesterday.getInvite());
            // 本月
            OrderCountVO thisMonth = commonOrderService.getOrderCount(uid, 3, listSource);
            thisMonth.setTotal(thisMonth.getSelf() + thisMonth.getShared() + thisMonth.getInvite());
            // 上月
            OrderCountVO lastMonth = commonOrderService.getOrderCount(uid, 4, listSource);
            lastMonth.setTotal(lastMonth.getSelf() + lastMonth.getShared() + lastMonth.getInvite());
 
            data.put("today", today);
            data.put("yesterday", yesterday);
            data.put("thisMonth", thisMonth);
            data.put("lastMonth", lastMonth);
            out.print(JsonUtil.loadTrueResult(data));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "获取信息失败"));
            e.printStackTrace();
        }
    }
 
    /**
     * 统计奖金
     * @param acceptData
     * @param uid
     * @param dateType  1-今日 2-昨天 3-本月 4-上个月
     * @param out
     */
    @RequestMapping(value = "getBonusCount", method = RequestMethod.POST)
    public void getBonusCount(AcceptData acceptData, Long uid, Integer dateType, PrintWriter out) {
        if (uid == null) {
            out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
            return;
        }
 
        boolean show = false;
        UserSettingsVO settings = null;
        try {
            settings = userCustomSettingsService.getMySettings(uid);
        } catch (Exception e) {
        }
 
        // 验证是否显示模块
        if (settings != null && settings.getNoBonusCount() != null) {
            if (settings.getNoBonusCount() == 1) {
                show = false;
            } else if (settings.getNoBonusCount() == 0) {
                show = true;
            }
        } else {
            show = hongBaoV2CountService.getHongBaoCount(uid, null) > 0;
        }
 
        BigDecimal selfMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 1, null);
        BigDecimal shareMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 2, null);
        
        JSONObject data = new JSONObject();
        data.put("show", show);
        data.put("selfMoney", selfMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
        data.put("shareMoney", shareMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
        
        
        BigDecimal teamMoney = new BigDecimal(0);
        if (!VersionUtil.greaterThan_2_1(acceptData.getPlatform(), acceptData.getVersion())) {
            teamMoney = hongBaoV2CountService.getRewardMoneyToCount(uid, dateType, 3, null);
        } else {
            BigDecimal bonus = null;
            BigDecimal dividend = null;  // TODO 分红统计
            if (dateType == 4) { // 已到账
                dividend = new BigDecimal(0);
                bonus = hongBaoV2CountService.geBonusByuid(uid, dateType, 3, 2);
            } else { // 未失效
                bonus = hongBaoV2CountService.geBonusByuid(uid, dateType, 3, 4);
            }
            
            dividend = new BigDecimal(0);
            // 总团队奖励
            teamMoney = bonus.add(dividend);
        }
        data.put("inviteMoney", teamMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    
    /**
     * 返利说明
     * @param acceptData
     * @param uid
     * @param orderNo
     * @param sourceType
     * @param out
     */
    @RequestMapping(value = "getReBateInfo")
    public void getReBateInfo(String callback, AcceptData acceptData, Long uid, String orderNo, Integer sourceType,
            PrintWriter out) {
        if (uid == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户未登录"));
            return;
        }
 
        UserInfo user = userInfoService.selectByPKey(uid);
        if (user == null) {
            JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户不存在"));
            return;
        }
 
        // 红包信息
        List<HongBaoOrder> hoList = hongBaoOrderService.listDetailByOrderIdAndSourceTypeAndUid(orderNo, sourceType, uid);
        HongBaoCountVO hongBaoCountVO = hongBaoOrderService.getHongBaoCountVO(hoList);
        
        Integer hongBaoState = hongBaoCountVO.getCurrentState();
        String stateDesc = "";
        String predictDesc = "";
        if (HongBaoV2.STATE_KELINGQU == hongBaoState || HongBaoV2.STATE_BUKELINGQU == hongBaoState) {
            stateDesc = "未到账";
            predictDesc = "预估";
        } else if (HongBaoV2.STATE_YILINGQU == hongBaoState) {
            stateDesc = "已到账";
        } else if (HongBaoV2.STATE_SHIXIAO == hongBaoState) {
            stateDesc = "已失效";
        }
        
        int type = 0;
        String typeName = "";
        int hongBaoType = hoList.get(0).getHongBaoV2().getType();
        if (HongBaoV2.TYPE_ZIGOU == hongBaoType || 2 == hongBaoType) {
            type = 1;
            typeName = "返利";
        } else if (HongBaoV2.TYPE_SHARE_GOODS == hongBaoType) {
            type = 2;
            typeName = "奖金";
        } else if (HongBaoV2.TYPE_SHARE_YIJI == hongBaoType || HongBaoV2.TYPE_SHARE_ERJI == hongBaoType
                || HongBaoV2.TYPE_YAOQING == hongBaoType || HongBaoV2.TYPE_YIJI == hongBaoType
                || HongBaoV2.TYPE_ERJI == hongBaoType) {
            type = 3;
            typeName = "收益";
        } 
        
        List<Long> goodsIdList = new ArrayList<>();
        if (hoList != null)
            for (HongBaoOrder hongBaoOrder : hoList) {
                if (hongBaoOrder.getCommonOrder() != null)
                    goodsIdList.add(hongBaoOrder.getCommonOrder().getCommonOrderGoods().getId());
            }
 
        Map<Long, CommonOrderGoods> orderGoodsMap = new HashMap<>();
        List<CommonOrderGoods> goodsList = commonOrderGoodsService.listByByPrimaryKeys(goodsIdList);
        if (goodsList != null)
            for (CommonOrderGoods goods : goodsList)
                orderGoodsMap.put(goods.getId(), goods);
        
        
        OrderRebateVO orderRebateVO = new OrderRebateVO();
        // 红包信息
        BigDecimal hongBao = hongBaoCountVO.getValidMoney();
        if (sourceType == Constant.SOURCE_TYPE_TAOBAO) {
            List<TaoBaoWeiQuanOrder> listWQ = taoBaoWeiQuanOrderService.getWeiQuanSuccessOrders(orderNo);
            if (listWQ != null && listWQ.size() > 0) {
                BigDecimal weiQuanMoney = commonOrderService.getWeiQuanMoney(listWQ, sourceType, uid);
                
                orderRebateVO.setWq(true);
                orderRebateVO.setWqMoney("¥"+ weiQuanMoney.setScale(2, BigDecimal.ROUND_DOWN));
                if (hongBao.compareTo(weiQuanMoney) > 0) {
                    orderRebateVO.setWqDesc("部分售后退回");
                } else {
                    orderRebateVO.setWqDesc("售后退回");
                }
                // 计算剩余红包
                hongBao = MoneyBigDecimalUtil.sub(hongBao, weiQuanMoney);
            }
        }
        
        // 红包获得者
        HongBaoV2 hongBaoV2 = hoList.get(0).getHongBaoV2();
        UserLevelEnum userLevel = UserLevelUtil.getByOrderRank(hongBaoV2.getUrank());
        if (userLevel == null)
            userLevel = UserLevelEnum.daRen;
        UserLevelEnum upperLevel =  UserLevelEnum.superVIP;
            
        // 订单购买者
        CommonOrder commonOrder1 = hoList.get(0).getCommonOrder();
        Date downTime = commonOrder1.getThirdCreateTime();
        UserLevelEnum buyer = UserLevelUtil.getByOrderRank(commonOrder1.getUrank());
        if (buyer == null) {
            buyer = UserLevelEnum.daRen;
        }
        
        BigDecimal upperTotalMoney = new BigDecimal(0);
        List<GoodsRebateVO> voList = new ArrayList<>();
        for (HongBaoOrder hongBaoOrder : hoList) {
            if (hongBaoOrder.getHongBaoV2().getState() == HongBaoV2.STATE_SHIXIAO)
                hongBaoOrder.getHongBaoV2().setMoney(new BigDecimal(0));
        
            GoodsRebateVO goodsVO = new GoodsRebateVO();
            
            // 标题、图片
            CommonOrder commonOrder = hongBaoOrder.getCommonOrder();
            if (orderGoodsMap.get(commonOrder.getCommonOrderGoods().getId()) != null) {
                goodsVO.setTitle(orderGoodsMap.get(commonOrder.getCommonOrderGoods().getId()).getTitle());
                goodsVO.setPicture(orderGoodsMap.get(commonOrder.getCommonOrderGoods().getId()).getPicture());
            }
            
            // 实付款
            BigDecimal payment = hongBaoOrder.getCommonOrder().getPayment();
            // 若已结算 -显示结算金额
            Integer orderState = hongBaoOrder.getCommonOrder().getState();
            if (hongBaoOrder.getCommonOrder().getSettlement() != null 
                    && (orderState == CommonOrder.STATE_JS || orderState == CommonOrder.STATE_WQ))
                payment = hongBaoOrder.getCommonOrder().getSettlement();
            if (payment == null)
                payment = new BigDecimal(0);
            goodsVO.setActualPay("¥" + payment.setScale(2, BigDecimal.ROUND_DOWN));
            
            BigDecimal fanli = hongBaoOrder.getHongBaoV2().getMoney();
            // 基础佣金
            BigDecimal commission = orderHongBaoMoneyComputeService.computeBaseFanliMoney(commonOrder);
            goodsVO.setCommision("¥" +commission.setScale(2, BigDecimal.ROUND_DOWN));
        
            // 平台补贴  = 返利 - 基础佣金
            goodsVO.setSubsidy("¥" + fanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN));
            //  达人补贴
            if (userLevel != UserLevelEnum.daRen) {
                BigDecimal darenFanli = orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, UserLevelEnum.daRen);
                goodsVO.setOriginSubsidy("¥" + darenFanli.subtract(commission).setScale(2, BigDecimal.ROUND_DOWN) + "");
            }
            
            if (type == 3) { // 奖金
                goodsVO.setBonus("¥" + fanli.setScale(2, BigDecimal.ROUND_DOWN) +"");
            }
            
            voList.add(goodsVO);
            
            if (type == 1 ) {
                upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeFanliMoney(commonOrder, upperLevel));
            } else if (type == 2) {
                upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeShareMoney(commonOrder, upperLevel));
            } else if (type == 3) {
                List<UserTeamLevel> bossLevelList = new ArrayList<>();
                if (hongBaoV2.getType() == HongBaoV2.TYPE_YIJI || hongBaoV2.getType() == HongBaoV2.TYPE_SHARE_YIJI) {
                    bossLevelList.add(new UserTeamLevel(null, UserLevelEnum.superVIP));
                    upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeFirstInviteMoney(commonOrder,
                            buyer, bossLevelList));
                } else {
                    Integer bRank = hongBaoV2Service.getDirectBossUrankByPid(hongBaoOrder.getHongBaoV2().getParent().getId());
                    UserLevelEnum directBoss = UserLevelUtil.getByOrderRank(bRank);
                    if (directBoss == null) {
                        directBoss = UserLevelEnum.daRen;
                    }
                    bossLevelList.add(new UserTeamLevel(null, directBoss));
                    bossLevelList.add(new UserTeamLevel(null, UserLevelEnum.superVIP));
                    upperTotalMoney = upperTotalMoney.add(orderHongBaoMoneyComputeService.computeSecondInviteMoney(commonOrder,
                            buyer, bossLevelList));
                }
            }
        }
        
        
        orderRebateVO.setFanLiDesc(predictDesc + typeName);
        orderRebateVO.setFanLi("¥" + hongBao.setScale(2, BigDecimal.ROUND_DOWN));
        orderRebateVO.setType(type);
        orderRebateVO.setStateDesc(stateDesc);
        orderRebateVO.setListGoods(voList);
        if (downTime.getTime() < Constant.NEW_ORDER_FANLI_RULE_TIME) {
            orderRebateVO.setUserLevel(UserLevelEnum.superVIP.name()); // 隐藏
        } else {
            orderRebateVO.setUserLevel(userLevel.name());
        }
        
        // 超级会员返利
        if (upperLevel != null) {
            orderRebateVO.setUpperFanLi("¥" + upperTotalMoney);
            orderRebateVO.setJumpLink(upperLevel.getDetailLink());
        }
 
        int freeState = 0;
        boolean rewardSuccess = false;
        List<String> listNo = new ArrayList<String>();
        listNo.add(orderNo);
        List<UserSystemCouponRecord> useRecord = userSystemCouponRecordService.getRecordByOrderNoList(sourceType, listNo);
        if (useRecord != null && useRecord.size() > 0) {
            for (UserSystemCouponRecord couponRecord : useRecord) {
                Integer state = couponRecord.getState();
                String cType = couponRecord.getCouponType();
                if (CouponTypeEnum.rebatePercentCoupon.name().equals(cType) && UserSystemCouponRecord.STATE_SUCCESS == state) {
                    rewardSuccess = true;
                    break;
                } else if (CouponTypeEnum.freeCoupon.name().equals(cType) || CouponTypeEnum.welfareFreeCoupon.name().equals(cType)
                        || CouponTypeEnum.freeCouponBuy.name().equals(cType)) {
                    freeState = state;
                    break;
                }
            }
        }
        
        if (rewardSuccess) {  // 已使用奖励券
            JSONObject params = new JSONObject();
            params.put("orderNo", orderNo);
            params.put("goodsType", sourceType + "");
            BigDecimal couponMoney = orderHongBaoMapService.getCouponHongbaoByOrderNo(orderNo, uid);
            if (couponMoney == null) {
                couponMoney = new BigDecimal(0);
            }
            orderRebateVO.setCouponType(1);
            orderRebateVO.setCouponUse(true);
            orderRebateVO.setCouponText("奖励成功");
            orderRebateVO.setCouponDesc("已再返¥" +couponMoney.setScale(2, BigDecimal.ROUND_DOWN));
            orderRebateVO.setCouponParams(params.toString());
            orderRebateVO.setCouponJumpDetail(jumpDetailV2Service.getByTypeCache("rewardCouponDetail"));
        } else if (freeState > 0) { // 已使用免单券
            JSONObject params = new JSONObject();
            params.put("orderNo", orderNo);
            params.put("goodsType", sourceType + "");
            orderRebateVO.setCouponType(2);
            orderRebateVO.setCouponUse(true);
            orderRebateVO.setCouponParams(params.toString());
            orderRebateVO.setCouponJumpDetail(jumpDetailV2Service.getByTypeCache("freeCouponDetail"));
            if (UserSystemCouponRecord.STATE_FREE_ON == freeState) {
                orderRebateVO.setCouponText("免单中");
            } else if (UserSystemCouponRecord.STATE_SUCCESS == freeState) {
                orderRebateVO.setCouponText("免单成功");
            } else if (UserSystemCouponRecord.STATE_FAIL_RULE == freeState
                    || UserSystemCouponRecord.STATE_FAIL_DRAWBACK == freeState) {
                orderRebateVO.setCouponText("免单失败");
            }
        } else {
            Date accountTime = hongBaoV2.getGetTime();
            // 到账时间 -红包金额限制
            if (accountTime != null && hongBao.compareTo(Constant.REWARD_COUPON_LIMIT_MONEY) <= 0) { 
                boolean vip = userInviteService.verifyVIP(uid);
                Date endDay = DateUtil.plusDayDate(Constant.COUPON_REWARD_LIMIT_DAY, accountTime);
                long currentTime = java.lang.System.currentTimeMillis();
                if (endDay.getTime() > currentTime && !vip) {
                    UserSystemCouponRecord couponRecord = userSystemCouponRecordService.getRecordByOrderNo(orderNo, null);
                    if (couponRecord == null) {
                        orderRebateVO.setCoupon(true);
                        orderRebateVO.setCouponType(1);
                        orderRebateVO.setCouponText("立即使用");
                        orderRebateVO.setCouponDesc("返利再返");
                    }
                }
            }
        }
        
        JSONObject data = new JSONObject();
        data.put("result", orderRebateVO);
        JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
    }
    
}