fs-danaus
2021-03-05 a6a76f98715a5539c8fd77676d0ea1af5c9c5a4c
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
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
package com.yc.sdk.shopping.action;
 
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
 
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.yc.action.BaseAction;
import com.yc.entity.DataSourceEntity;
import com.yc.multiData.MultiDataSource;
import com.yc.multiData.SpObserver;
import com.yc.sdk.shopping.action.api.ShopCcCode;
import com.yc.sdk.shopping.entity.CurrencyEntity;
import com.yc.sdk.shopping.entity.CustomerEntity;
import com.yc.sdk.shopping.entity.GroupBuyingEntity;
import com.yc.sdk.shopping.entity.OrderDetailEntity;
import com.yc.sdk.shopping.entity.OrderEntity;
import com.yc.sdk.shopping.entity.SettingEntity;
import com.yc.sdk.shopping.entity.ShopCcCodeEntity;
import com.yc.sdk.shopping.service.CartIfc;
import com.yc.sdk.shopping.service.CurrencyIfc;
import com.yc.sdk.shopping.service.SettingIfc;
import com.yc.sdk.shopping.service.imagedata.ShoppingImageDataIfc;
import com.yc.sdk.shopping.service.order.OrderIfc;
import com.yc.sdk.shopping.service.register.AccountIfc;
import com.yc.sdk.shopping.util.SettingKey;
import com.yc.sdk.shopping.util.StringReplaceUtil;
import com.yc.utils.SessionKey;
 
@Controller
@Scope("prototype")
public class Order extends BaseAction{
    @Autowired
    OrderIfc orderIfc;
    
    @Autowired
    SettingIfc settingIfc ;
    @Autowired
    CartIfc cartIfc;
    @Autowired
    ShoppingImageDataIfc imgData ;
    @Autowired
    AccountIfc accountIfc ;
    @Autowired
    CurrencyIfc currencyIfc;
    
    /**
     * 修改单据状态,客户删单,单据对客户隐藏
     * 
     * @param request
     * @param response
     */
    @RequestMapping("/shopping/orderDelete.do")
    public void orderDelete(HttpServletRequest request,
            HttpServletResponse response) {
        HttpSession session = request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        String docCode=request.getParameter(SettingKey.DOCCODE)==null?"":request.getParameter(SettingKey.DOCCODE);
        String cltCode = (session.getAttribute(SettingKey.CLTCODE)==null?"":(String)session.getAttribute(SettingKey.CLTCODE));
        String hostUrl = SettingKey.getHostUrl(request);
        // 将微信corpid组装成url
        String wxQueryString = SettingKey.getQueryStringByWx(request);
        boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
        //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID);
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
 
 
             Boolean issuccess = orderIfc.deleteSalesOrder(cltCode,docCode);
            if (!issuccess) {
                json.addProperty("success", "删除订单失败!");
                json.addProperty("state", issuccess ? "success": "falied");
                this.printJson(response, json.toString());
                return;
            }
            json.addProperty("state", issuccess ? "success": "falied");
            json.addProperty("success", "删除订单成功!");
            String redirect = hostUrl
                    + "/shopping/"
                    + (isMoblieBrowser ? "mobile/" : "")
                    + "account/order.jsp?"+ SettingKey.DOCCODE + "="
                    + docCode
                    + ""
                    + (wxQueryString == null || "".equals(wxQueryString) ? ""
                            : "&" + wxQueryString);
            json.addProperty("redirect", redirect);
            this.printJson(response, json.toString());
            return;
        } catch (DataAccessException e) {
 
            e.printStackTrace();
            errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } catch (Exception e) {
            e.printStackTrace();
            errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        } finally {
            SpObserver.setDBtoInstance();
        }
    }
    
    @RequestMapping("/shopping/orderlist.do")
    public void getOrderList(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session=request.getSession();
        //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID);
        String cltCode = (session.getAttribute(SettingKey.CLTCODE)==null?"":(String)session.getAttribute(SettingKey.CLTCODE));
        String userCode = (session.getAttribute(SessionKey.USERCODE) == null ? "" 
                : (String)session.getAttribute(SessionKey.USERCODE));
        
        //String isShowOnlyApproving = request.getParameter("isShowOnlyApproving") ;   //是否只显示导购称重审核的订单
        String isAllowPayable = request.getParameter("isAllowPayable") ;   //是否可支付:0 不能支付(只显示导购称重审核的订单),1可支付(只显示待客户支付的订单),2已支付
        
        //是否导购
        boolean isShopGuide = (session.getAttribute(SettingKey.isShopGuide)!=null ? (boolean)session.getAttribute(SettingKey.isShopGuide) :false );
 
 
        //将微信corpid组装成url
        //String wxQueryString = SettingKey.getQueryStringByWx(request);
        //boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
        String hostUrl = SettingKey.getHostUrl(request) ;  
        
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd") ;
        SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm") ;
        DecimalFormat df = new DecimalFormat("0.00");
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
            SettingEntity settingEntity = settingIfc.getSettingEntity() ;
            // 取网店 shopcccode
            ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
            //货币
            CurrencyEntity currencyEntity = currencyIfc.getUserCurrency(userCode);
            
            //检查该客户是否存在
            if (cltCode != null && !"".equals(cltCode)) {
                
                CustomerEntity customerEntity = accountIfc.getLoginInfoByCltCode(cltCode,cltCode,cltCode);
                if (customerEntity==null || customerEntity.getCltCode()==null||customerEntity.getCltCode().equals("")) {
                    cltCode = null;
                    session.removeAttribute(SettingKey.CLTCODE);
                }
            }
            
            if (cltCode == null || "".equals(cltCode) )  {
                json.addProperty(SettingKey.CLTCODE,"");
                return ;
            }else {
                json.addProperty(SettingKey.CLTCODE,cltCode);
            }
            
            
            //所有订单头信息 
            List<OrderEntity> orderList = null;
            if (isAllowPayable != null &&  !isAllowPayable.equals("")) {
                orderList = orderIfc.getOrderListByIsAllowPayable(cltCode,Integer.parseInt(isAllowPayable) ,shopCcCodeEntity.getShopCcCode()) ;   //待称重订单列表
            } else {
                orderList = orderIfc.getOrderList( cltCode,shopCcCodeEntity.getShopCcCode()) ;   //所有订单列表 
            }
            
            JsonArray orderListJsonArray = new JsonArray();
            for(int k = 0 ;orderList != null&&orderList.size()>0&& k < orderList.size();k++) {
                OrderEntity orderEntity = orderList.get(k) ;
                JsonObject orderEntityJsonObject = new JsonObject();
                //status : 0 所有,1.待付款,2.待收货,3.已完成,4.已取消
                String groupBy = "所有" ;
                if (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(0)) {
                    groupBy = "待付款";
                }
                
                if (orderList.get(k).getDocStatus().equals(100) && orderEntity.getFaHuoStatus()!=null&&!orderEntity.getFaHuoStatus().equals("")) {
                    groupBy = "待收货";
                }
 
                if (orderList.get(k).getDocStatus().equals(100) && orderList.get(k).isReceiptGoodsByCustomer()) {
                    groupBy = "已完成";
                }
                if (orderList.get(k).getDocStatus().equals(-200)) {
                    groupBy = "已取消";
                }
                orderEntityJsonObject.addProperty("GroupBy", groupBy);
 
                 //订单行信息
                   List<OrderDetailEntity> orderDetailList = orderIfc.getOrderDetailList(cltCode,orderEntity.getDocCode()) ;
                   if (orderDetailList ==null||orderDetailList.size() == 0) {
                       continue ;
                   }
                   orderEntityJsonObject.addProperty(SettingKey.DOCCODE, orderEntity.getDocCode());
                   orderEntityJsonObject.addProperty("FormId", orderEntity.getFormId());
                   orderEntityJsonObject.addProperty("DocType", orderEntity.getDocType());  //单据类型:微信订单 、微信团购订单
                   orderEntityJsonObject.addProperty("CcCode", orderEntity.getCcCode());
                   orderEntityJsonObject.addProperty("CcName", orderEntity.getCcName());
                   orderEntityJsonObject.addProperty("SumTotalMoney2",orderEntity.getSumTotalMoney2());  //优惠前订单总金额 
                   orderEntityJsonObject.addProperty("SumTotalMoney3",orderEntity.getSumTotalMoney3());  //优惠后订单总金额 ,由 PayableAmount 代替
                   orderEntityJsonObject.addProperty("PayableAmount",orderEntity.getPayableAmount());  //优惠后订单总金额 
                   orderEntityJsonObject.addProperty("ReduceMoney",orderEntity.getReduceMoney());  //优惠金额 
                   orderEntityJsonObject.addProperty("TransCosts",orderEntity.getTransCosts());  //运费 
                   orderEntityJsonObject.addProperty("HandlingCharges",orderEntity.getHandlingCharges());  //搬运费
                   
                   orderEntityJsonObject.addProperty("Currency",orderEntity.getCurrency());  //币种 
                   orderEntityJsonObject.addProperty("CurrencySign",orderEntity.getCurrencySign());   //货币符号
                   orderEntityJsonObject.addProperty("Address",orderEntity.getPropertyAddress());  //地址 
                   orderEntityJsonObject.addProperty("LinkMan",orderEntity.getLinkMan() != null &&!"".equals(orderEntity.getLinkMan())?orderEntity.getLinkMan(): orderEntity.getCltName());   //联系人
                   orderEntityJsonObject.addProperty("Telephone",orderEntity.getTel());    //联系人电话
                   orderEntityJsonObject.addProperty("DeliveryMethod",orderEntity.getDeliveryMethod());
                   orderEntityJsonObject.addProperty("DeliveryDate",sdf.format(orderEntity.getDocDate()));
                   orderEntityJsonObject.addProperty("InvoiceType","电子普通发票");
                   orderEntityJsonObject.addProperty("HDMemo",orderEntity.getHdMemo());
                   
                   
                   orderEntityJsonObject.addProperty("LogisticsCode",orderEntity.getLogisticsCode());  //物流单号
                   orderEntityJsonObject.addProperty("ShipperCode",orderEntity.getShipperCode());   //快递公司编号
                   orderEntityJsonObject.addProperty("ShipperName",orderEntity.getShipperName());   //快递公司名称
                   orderEntityJsonObject.addProperty("isAllowPayable",orderEntity.getIsAllowPayable());  //是否可支付 isAllowPayable 状态: 0.不能支付,1.可支付,2.已支付 ,3.正在退款,4.已退款,5.无需支付
                   orderEntityJsonObject.addProperty("DocStatus",orderEntity.getDocStatus());   //单据状态 
                   
                   orderEntityJsonObject.addProperty("DocDate",orderEntity.getDocDate()==null?"":sdf.format(orderEntity.getDocDate()));
                   orderEntityJsonObject.addProperty("EnterDate",orderEntity.getEnterDate()==null?"":sdf2.format(orderEntity.getEnterDate()));
                   orderEntityJsonObject.addProperty("PreSendDate",orderEntity.getPreSendDate()==null?"":sdf3.format(orderEntity.getPreSendDate()));
                   orderEntityJsonObject.addProperty("PayableSecondBalance",orderEntity.getPayableSecondBalance()!=null&& orderEntity.getPayableSecondBalance().intValue() >0?orderEntity.getPayableSecondBalance():0);   //下单后支付倒计时秒数 
                   orderEntityJsonObject.addProperty("GroupBuyingDocCode",orderEntity.getGroupBuyingDocCode());   //团购订单号 
                   orderEntityJsonObject.addProperty("GroupBuyingMembers",orderEntity.getGroupBuyingMembers());   //需要多少人成团
                   orderEntityJsonObject.addProperty("GroupBuyingHasMembers",orderEntity.getGroupBuyingHasMembers());   //已有多少人成团
                   orderEntityJsonObject.addProperty("GroupBuyingMembersBalance",orderEntity.getGroupBuyingMembersBalance());   //还差多少人成团
                
                   //获取单据状态描述
                   String docStatusDesc = null;
                   if (orderEntity.getFormId()!=null&&orderEntity.getFormId().intValue() == 120238) {
                       docStatusDesc = orderEntity.getHeXiaoStatus();
                       if (docStatusDesc==null||"".equals(docStatusDesc)) {
                           docStatusDesc = "待核销";
                    }
                   }else {
                       docStatusDesc = getDocStatusDescription(orderEntity) ; 
                   }
                   
                   orderEntityJsonObject.addProperty("DocStatusDesc", docStatusDesc);
                   double totalQuantity = 0 ;
                   int itemCount = 0 ;
                   JsonArray orderDetailListJsonArray = new JsonArray();
                   for (int i =0;orderDetailList != null && i < orderDetailList.size();i++) { 
                       OrderDetailEntity orderDetailEntity =  orderDetailList.get(i) ;
                       JsonObject orderDetailEntityJsonObject = new JsonObject();
                       //主图片
                       orderDetailEntityJsonObject.addProperty("PhotoPath",SettingKey.getUrl(hostUrl, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                          /*    imgData.getImageUrl(orderDetailEntity.getPhotoPath(), settingEntity.getImageProductWidth(),
                                      settingEntity.getImageProductHeight(), settingEntity.isShowProductOrgImage(),
                                      settingEntity.isFromCached(), request)
                                      + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString));
                       */
                       
                       if (settingEntity.isShowBrand()) {
                           orderDetailEntityJsonObject.addProperty("Brand", orderDetailEntity.getBrand());
                    }
                       if (settingEntity.isShowMatName()) {
                           orderDetailEntityJsonObject.addProperty("MatName", orderDetailEntity.getMatName());
                    }
                       orderDetailEntityJsonObject.addProperty("MatCode", orderDetailEntity.getMatCode());
                       orderDetailEntityJsonObject.addProperty("isShowMatCode", settingEntity.isShowMatCode());
                       orderDetailEntityJsonObject.addProperty("isShowMatName", settingEntity.isShowMatName());
                       orderDetailEntityJsonObject.addProperty("isShowSpecial", settingEntity.isShowSpecial());
                       orderDetailEntityJsonObject.addProperty("isShowPrice", settingEntity.isShowPrice());
                       orderDetailEntityJsonObject.addProperty("isShowPoints", settingEntity.isShowPoints());
                       orderDetailEntityJsonObject.addProperty("isShowBrand", settingEntity.isShowBrand());
                       orderDetailEntityJsonObject.addProperty("StockDisplay", settingEntity.getStockDisplay());
                    
                       orderDetailEntityJsonObject.addProperty("ShopMatCode", orderDetailEntity.getShopMatCode());
 
                    if (settingEntity.isShowSpecial()) {
                        orderDetailEntityJsonObject.addProperty("Special", orderDetailEntity.getSpecial());
                    }
                    
                    if (settingEntity.isStartupMatName2()) {
                        orderDetailEntityJsonObject.addProperty("MatName2Label", settingEntity.getMatName2Label());
                        orderDetailEntityJsonObject.addProperty("MatName2", orderDetailEntity.getMatName2());
                    }
 
                    if (settingEntity.isStartupMatName3()) {
                        orderDetailEntityJsonObject.addProperty("MatName3Label", settingEntity.getMatName3Label());
                        orderDetailEntityJsonObject.addProperty("MatName3", orderDetailEntity.getMatName3());
                    }
 
                    if (settingEntity.isStartupMatName4()) {
                        orderDetailEntityJsonObject.addProperty("MatName4Label", settingEntity.getMatName4Label());
                        orderDetailEntityJsonObject.addProperty("MatName4", orderDetailEntity.getMatName4());
                    }
                    
                    if (orderDetailEntity.getOptionJson() !=null && !"".equals(orderDetailEntity.getOptionJson()))  {
                        //Map<String,Object> lists=gson.fromJson(cartEntity.getOptionJson(),new TypeToken<Map<String,Object>>(){}.getType());
                        orderDetailEntityJsonObject.addProperty("OptionJson", orderDetailEntity.getOptionJson()) ; //gson.toJson(settingEntity));
                    }
                    
                    if (settingEntity.isShowPrice()) {
                        orderDetailEntityJsonObject.addProperty("Price", orderDetailEntity.getPrice() ); // 实际价格
                        orderDetailEntityJsonObject.addProperty("Currency", currencyEntity.getCurrency());
                        orderDetailEntityJsonObject.addProperty("CurrencySign", currencyEntity.getCurrencySign());
                    }
                    
                    //取出导购上传的图片
                    JsonArray orderDetailImageJsonArray = new JsonArray();
                    if (orderDetailEntity.getImages() != null && !"".equals(orderDetailEntity.getImages())) {
                        String unids[] = orderDetailEntity.getImages().split(";") ;
                        String unid = unids[0] ;
                        for (int m = 0 ;m < unids.length;m++) {
                            if (m == 0) continue ; 
                            String seq = unids[m] ;
                            JsonObject unidSeqJson = new JsonObject();
                            unidSeqJson.addProperty(SettingKey.UNID,unid) ;
                            unidSeqJson.addProperty("seq",seq) ;
                            unidSeqJson.addProperty("url",imgData.getImageUrl(unid +";" + seq, settingEntity.getImageProductWidth(),
                                      settingEntity.getImageProductHeight(), settingEntity.isShowProductOrgImage(),
                                      settingEntity.isFromCached(), request) ) ;
                            orderDetailImageJsonArray.add(unidSeqJson) ;
                        }
                    }
                    orderDetailEntityJsonObject.add("Images",orderDetailImageJsonArray) ;
                    
                    orderDetailEntityJsonObject.addProperty("Quantity", orderDetailEntity.getDigit()) ;
                    orderDetailEntityJsonObject.addProperty("RowId", orderDetailEntity.getRowId());
                       //是否显示:退货按钮 
                    orderDetailEntityJsonObject.addProperty("isShowReturnButton", cltCode.equals(orderEntity.getCltCode()) && orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&orderDetailEntity.getPickDigit() != 0 && (orderDetailEntity.getTuiHuoKaiDanStatusItem()==null ||"".equals(orderDetailEntity.getTuiHuoKaiDanStatusItem()))  ?true:false);
 
                    orderDetailEntityJsonObject.addProperty("skuId1", orderDetailEntity.getSkuId1());
                    orderDetailEntityJsonObject.addProperty("skuName1", orderDetailEntity.getSkuName1());
                    orderDetailEntityJsonObject.addProperty("skuId2", orderDetailEntity.getSkuId2());
                    orderDetailEntityJsonObject.addProperty("skuName2", orderDetailEntity.getSkuName2());
                    orderDetailEntityJsonObject.addProperty("skuId3", orderDetailEntity.getSkuId3());
                    orderDetailEntityJsonObject.addProperty("skuName3", orderDetailEntity.getSkuName3());
                    orderDetailEntityJsonObject.addProperty("skuId4", orderDetailEntity.getSkuId4());
                    orderDetailEntityJsonObject.addProperty("skuName4", orderDetailEntity.getSkuName4());
                    orderDetailEntityJsonObject.addProperty("skuId5", orderDetailEntity.getSkuId5());
                    orderDetailEntityJsonObject.addProperty("skuName5", orderDetailEntity.getSkuName5());
                    orderDetailEntityJsonObject.addProperty("skuId6", orderDetailEntity.getSkuId6());
                    orderDetailEntityJsonObject.addProperty("skuName6", orderDetailEntity.getSkuName6());
                    orderDetailEntityJsonObject.addProperty("skuId7", orderDetailEntity.getSkuId7());
                    orderDetailEntityJsonObject.addProperty("skuName7", orderDetailEntity.getSkuName7());
                    orderDetailEntityJsonObject.addProperty("skuId8", orderDetailEntity.getSkuId8());
                    orderDetailEntityJsonObject.addProperty("skuName8", orderDetailEntity.getSkuName8());
                    orderDetailEntityJsonObject.addProperty("skuId9", orderDetailEntity.getSkuId9());
                    orderDetailEntityJsonObject.addProperty("skuName9", orderDetailEntity.getSkuName9());
                    orderDetailEntityJsonObject.addProperty("skuId10", orderDetailEntity.getSkuId10());
                    orderDetailEntityJsonObject.addProperty("skuName10", orderDetailEntity.getSkuName10());
 
                    totalQuantity += orderDetailEntity.getDigit();
                    itemCount ++ ;
                       orderDetailListJsonArray.add(orderDetailEntityJsonObject);
                   }
                   orderEntityJsonObject.addProperty("TotalQuantity",df.format(totalQuantity));  //所有商品总“数量”
                   orderEntityJsonObject.addProperty("ItemCount",itemCount);    //有多少种类商品
                   orderEntityJsonObject.add("OrderDetailList", orderDetailListJsonArray);
                   
                   //是否显示:支付按钮
                   orderEntityJsonObject.addProperty("isShowPayButton",cltCode.equals(orderEntity.getCltCode()) &&  orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(0)
                        &&orderEntity.getCltCode()!=null&&orderEntity.getCltCode().equals(cltCode)
                        &&orderEntity.getIsAllowPayable()!=null&&orderEntity.getIsAllowPayable().equals(1)?true:false);
 
                   //是否显示:取消订单按钮 
                   //orderEntityJsonObject.addProperty("isShowCancelButton", orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&orderEntity.getIsAllowPayable()!=null&&orderEntity.getIsAllowPayable().intValue() == 2 && (orderEntity.getFaHuoStatus()==null || orderEntity.getFaHuoStatus().equals(""))?true:false);
                   orderEntityJsonObject.addProperty("isShowCancelButton",settingEntity.isAllowReturnOrder()&& cltCode.equals(orderEntity.getCltCode()) && orderEntity.getDocStatus()!=null&&(orderEntity.getDocStatus().equals(100)||orderEntity.getDocStatus().equals(0)) && (orderEntity.getFaHuoStatus()==null || orderEntity.getFaHuoStatus().equals(""))?true:false);
                   
                   //是否显示:查看物流按钮
                   boolean isShowLogisticsButton = (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&& orderEntity.getLogisticsCode()!=null && !orderEntity.getLogisticsCode().equals("")?true:false);
                   orderEntityJsonObject.addProperty("isShowLogisticsButton",(cltCode.equals(orderEntity.getCltCode())||isShopGuide)&&isShowLogisticsButton&&orderEntity.getShipperCode()!=null&& !orderEntity.getShipperCode().equals("") );
                   //是否显示:收货按钮
                   orderEntityJsonObject.addProperty("isShowReceiptButton", cltCode.equals(orderEntity.getCltCode()) && isShowLogisticsButton && 
                           orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&!orderEntity.isReceiptGoodsByCustomer() ?true:false);
                   
                   //是否显示:删除按钮
                   orderEntityJsonObject.addProperty("isShowDeleteButton",  orderEntity.getDocStatus().equals(0) ||(orderEntity.getDocStatus()!=null &&orderEntity.getDocStatus().equals(-200)) ||(orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&orderEntity.isReceiptGoodsByCustomer()) ?true:false);
                   //generateOrderProcess : 0.生成订单可立即支付 ,1.生成订单,导购审核后才能支付(适用于生鲜类卖家,卖牛肉牛排的 ,他们按份卖,客户下单 时1份,假设1份 500克,实际卖出时是按称重卖的,可能有 510克,那最后付款也是按 510克付。)
                   //orderEntityJsonObject.addProperty("generateOrderProcess",settingEntity.getGenerateOrderProcess() );
 
                orderListJsonArray.add(orderEntityJsonObject);    
            }
            
            json.add("list", orderListJsonArray);
            this.printJson(response, json.toString());
            
            return ;
        }catch(DataAccessException e ) {
            e.printStackTrace();
            errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch(Exception e){
            e.printStackTrace();
            errJson.addProperty("warning", e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }finally {
            SpObserver.setDBtoInstance();
        }
        
    }
 
    
    
    private String getDocStatusDescription(OrderEntity orderEntity) {
        if (orderEntity.getDocStatus().equals(-200)) {
            return "已取消";
        }
        
           if (orderEntity.getDocStatus().equals(0)) {
               //是否可支付 isAllowPayable 状态: 0.不能支付,1.可支付,2.已支付 ,3.正在退款,4.已退款,5.无需支付
               if (orderEntity.getIsAllowPayable().equals(0)) {
                   return "待卖家确认";
               }else if (orderEntity.getIsAllowPayable().equals(1)) {
                   return "待买家付款";
               }else if (orderEntity.getIsAllowPayable().equals(2)) {
                   return "待商家发货" ; // "买家已付款";
               }else if (orderEntity.getIsAllowPayable().equals(3)) {
                   return "正在退款";
               }else if (orderEntity.getIsAllowPayable().equals(4)){
                   return "已退款";
               }else if (orderEntity.getIsAllowPayable().equals(5)){
                   return "待商家发货";
               }
               
        }
 
           
           if (orderEntity.getDocStatus().equals(100)) { 
               if (orderEntity.getTuiHuoKaiDanDoccode()!=null&&!orderEntity.getTuiHuoKaiDanDoccode().equals("")) {
                if (orderEntity.getTuiHuoRuKuDoccode() == null || "".equals(orderEntity.getTuiHuoRuKuDoccode())) {
                    return "已申请退货";
                }else {
                    return orderEntity.getTuiHuoKaiDanStatus().replace("开单","");  //"已全部退货"  ,"部分退货";
                }
            } 
               
            if ((orderEntity.getFaHuoStatus()!=null&&!orderEntity.getFaHuoStatus().equals(""))||orderEntity.isReceiptGoodsByCustomer() ) { 
                if (orderEntity.isReceiptGoodsByCustomer() || (orderEntity.getFaHuoLastDateDays() != null && orderEntity.getFaHuoLastDateDays().intValue() > 15)) {
                    return "交易完成";   //最后发货日期大于 15 天,则认为买家已经收货 
                }else {
                    return "卖家已发货";
                }
            }
            
            if (orderEntity.getIsAllowPayable().equals(2)) {
                   return "待商家发货" ;  //"买家已付款";
               }else if (orderEntity.getIsAllowPayable().equals(3)) {
                   return "正在退款";
               }else if (orderEntity.getIsAllowPayable().equals(4)){
                   return "已退款";
               }else if (orderEntity.getIsAllowPayable().equals(5)){
                   return "待商家发货";
               }
        } 
           return "交易完成" ;
    }
    
    @RequestMapping("/shopping/orderdetail.do")
    public void getOrderDetail(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session=request.getSession();
        //String dbId = (String) session.getAttribute(SessionKey.SHOPPING_DBID);
        String cltCode = (session.getAttribute(SettingKey.CLTCODE)==null?"":(String)session.getAttribute(SettingKey.CLTCODE));
        String userCode = (session.getAttribute(SessionKey.USERCODE) == null ? "" 
                : (String)session.getAttribute(SessionKey.USERCODE));
        String docCode=request.getParameter(SettingKey.DOCCODE)==null?"":request.getParameter(SettingKey.DOCCODE);
        String formId=request.getParameter(SettingKey.FORMID)==null?"":request.getParameter(SettingKey.FORMID);
        
        //是否导购
        boolean isShopGuide = (session.getAttribute(SettingKey.isShopGuide)!=null ? (boolean)session.getAttribute(SettingKey.isShopGuide) :false );
        
        //将微信corpid组装成url
        //String wxQueryString = SettingKey.getQueryStringByWx(request);
        //boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
        String hostUrl = SettingKey.getHostUrl(request) ;  
        DecimalFormat df = new DecimalFormat("0.00");
        
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
            SettingEntity settingEntity = settingIfc.getSettingEntity() ;
            //货币
            CurrencyEntity currencyEntity = currencyIfc.getUserCurrency(userCode);
            
            //检查该客户是否存在
            if (cltCode != null && !"".equals(cltCode)) {
                
                CustomerEntity customerEntity = accountIfc.getLoginInfoByCltCode(cltCode,cltCode,cltCode);
                if (customerEntity==null || customerEntity.getCltCode()==null||customerEntity.getCltCode().equals("")) {
                    cltCode = null;
                    session.removeAttribute(SettingKey.CLTCODE);
                }
            }
            
            if (cltCode == null || "".equals(cltCode) )  {
                json.addProperty(SettingKey.CLTCODE,"");
                return ;
            }else {
                json.addProperty(SettingKey.CLTCODE,cltCode);
            }
            
            
            OrderEntity orderEntity=  orderIfc.getOrderHeaderEntity( cltCode,docCode,formId != null&&!"".equals(formId)?Integer.parseInt(formId):null) ;
            if (orderEntity == null) {
                errJson.addProperty("warning", "订单【" + docCode+"】不存在" );
                json.add("error", errJson);
                this.printJson(response, json.toString());
                return;
            }
            
            //获取单据状态描述
               String docStatusDesc = null;
               if (orderEntity.getFormId()!=null&&orderEntity.getFormId().intValue() == 120238) {
                   docStatusDesc = orderEntity.getHeXiaoStatus();
                   if (docStatusDesc==null||"".equals(docStatusDesc)) {
                       docStatusDesc = "待核销";
                }
               }else {
                   docStatusDesc = getDocStatusDescription(orderEntity) ; 
               }
               
            
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd") ;
            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
            SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm") ;
            json.addProperty("StatusDesc", docStatusDesc);
            json.addProperty(SettingKey.DOCCODE,orderEntity.getDocCode());
            json.addProperty("FormId", orderEntity.getFormId());
            json.addProperty("CcCode", orderEntity.getCcCode());
            json.addProperty("CcName", orderEntity.getCcName());
            json.addProperty("DocDate",orderEntity.getDocDate()==null?"":sdf.format(orderEntity.getDocDate()));
            json.addProperty("EnterDate",orderEntity.getEnterDate()==null?"":sdf2.format(orderEntity.getEnterDate()));
            json.addProperty("PayMethod", orderEntity.getWeiXinPayAmount()!=0?"微信支付":"余额支付");
            json.addProperty("SumTotalMoney2",orderEntity.getSumTotalMoney2());  //优惠前订单总金额 
            json.addProperty("SumTotalMoney3",orderEntity.getSumTotalMoney3());  //优惠后订单总金额  ,由 PayableAmount 代替
            json.addProperty("PayableAmount",orderEntity.getPayableAmount());  //优惠后订单总金额 
            json.addProperty("ReduceMoney",orderEntity.getReduceMoney());  //优惠金额 
            json.addProperty("TransCosts",orderEntity.getTransCosts());  //运费 
            json.addProperty("HandlingCharges",orderEntity.getHandlingCharges());  //搬运费
 
            json.addProperty("Currency",orderEntity.getCurrency());
            json.addProperty("CurrencySign",orderEntity.getCurrencySign());
            
            //客户名称、电话、地址加密
            json.addProperty("Address",orderEntity.getCltCode().equals( cltCode)||isShopGuide?orderEntity.getPropertyAddress() : StringReplaceUtil.getStarString2(orderEntity.getPropertyAddress(),orderEntity.getPropertyAddress().length() - 10,0) );
            String linkMan = orderEntity.getLinkMan() != null &&!"".equals(orderEntity.getLinkMan())?orderEntity.getLinkMan(): orderEntity.getCltName();
               json.addProperty("LinkMan",orderEntity.getCltCode().equals( cltCode)||isShopGuide?linkMan : StringReplaceUtil.getStarString2(linkMan,1,0));   //联系人
            json.addProperty("Telephone",orderEntity.getCltCode().equals( cltCode)||isShopGuide?orderEntity.getTel():StringReplaceUtil.getStarString2(orderEntity.getTel(),3,4));
            
            json.addProperty("AddressName",orderEntity.getCltCode().equals( cltCode)||isShopGuide?orderEntity.getFullAddressName():StringReplaceUtil.getStarString2(orderEntity.getFullAddressName(),orderEntity.getFullAddressName().length() - 5,0));
            json.addProperty("Street",orderEntity.getCltCode().equals( cltCode)||isShopGuide?orderEntity.getStreet():StringReplaceUtil.getStarString2(orderEntity.getStreet(),orderEntity.getStreet().length() - 5,0));
            json.addProperty("FullAddress",orderEntity.getCltCode().equals( cltCode)||isShopGuide?orderEntity.getFullAddress():StringReplaceUtil.getStarString2(orderEntity.getFullAddress(),orderEntity.getFullAddress().length() - 5,0));
            
            json.addProperty("DeliveryMethod",orderEntity.getDeliveryMethod());
            json.addProperty("DeliveryDate",sdf.format(orderEntity.getDocDate()));
            json.addProperty("InvoiceType","电子普通发票");
            json.addProperty("HDMemo",orderEntity.getHdMemo());
            json.addProperty("isAllowPayable",orderEntity.getIsAllowPayable());
            json.addProperty("LogisticsCode",orderEntity.getLogisticsCode());   //物流单号 
            json.addProperty("LogisticsCodeState",orderEntity.getLogisticsCodeState());   //物流状态 
            json.addProperty("ShipperCode",orderEntity.getShipperCode());    //快递公司编号
            json.addProperty("ShipperName",orderEntity.getShipperName());    //快递公司名称
            json.addProperty("isReceiptGoodsByCustomer",orderEntity.isReceiptGoodsByCustomer());   //客户是否已经点击收货 
            json.addProperty("ReceiptGoodsTime",orderEntity.getReceiptGoodsTime()==null?"":sdf2.format(orderEntity.getReceiptGoodsTime()));  //客户收货时间
            json.addProperty("DocStatus",orderEntity.getDocStatus());
            json.addProperty("CltCode",orderEntity.getCltCode());
            json.addProperty("PreSendDate",orderEntity.getPreSendDate()==null?"":sdf3.format(orderEntity.getPreSendDate()));   //送货时间
            json.addProperty("PayableSecondBalance",orderEntity.getPayableSecondBalance()!=null&& orderEntity.getPayableSecondBalance().intValue() >0?orderEntity.getPayableSecondBalance():0);   //下单后支付倒计时秒数 
            
               //是否显示:支付按钮
            json.addProperty("isShowPayButton",cltCode.equals(orderEntity.getCltCode()) &&  orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(0)
                    &&orderEntity.getCltCode()!=null&&orderEntity.getCltCode().equals(cltCode)
                    &&orderEntity.getIsAllowPayable()!=null&&orderEntity.getIsAllowPayable().equals(1)?true:false);
 
               //是否显示:取消订单按钮 
            //json.addProperty("isShowCancelButton", orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&orderEntity.getIsAllowPayable()!=null&&orderEntity.getIsAllowPayable().intValue() == 2 &&(orderEntity.getFaHuoStatus()==null || orderEntity.getFaHuoStatus().equals(""))?true:false);
            json.addProperty("isShowCancelButton",settingEntity.isAllowReturnOrder()&&cltCode.equals(orderEntity.getCltCode()) &&  orderEntity.getDocStatus()!=null&&(orderEntity.getDocStatus().equals(100)||orderEntity.getDocStatus().equals(0)) && (orderEntity.getFaHuoStatus()==null || orderEntity.getFaHuoStatus().equals(""))?true:false);
               //是否显示:查看物流按钮
               boolean isShowLogisticsButton = (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&& orderEntity.getLogisticsCode()!=null && ! orderEntity.getLogisticsCode().equals("")?true:false);
               json.addProperty("isShowLogisticsButton",(cltCode.equals(orderEntity.getCltCode())||isShopGuide)&&isShowLogisticsButton &&orderEntity.getShipperCode()!=null&& !orderEntity.getShipperCode().equals("") );
               
               //是否显示:收货按钮
               json.addProperty("isShowReceiptButton", cltCode.equals(orderEntity.getCltCode()) && isShowLogisticsButton && 
                       orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&!orderEntity.isReceiptGoodsByCustomer() ?true:false);
               //是否显示:删除按钮
               json.addProperty("isShowDeleteButton", orderEntity.getDocStatus().equals(0)||(orderEntity.getDocStatus()!=null &&orderEntity.getDocStatus().equals(-200)) || (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&orderEntity.isReceiptGoodsByCustomer()) ?true:false);
 
               //generateOrderProcess : 0.生成订单可立即支付 ,1.生成订单,导购审核后才能支付(适用于生鲜类卖家,卖牛肉牛排的 ,他们按份卖,客户下单 时1份,假设1份 500克,实际卖出时是按称重卖的,可能有 510克,那最后付款也是按 510克付。)
                //json.addProperty("generateOrderProcess",settingEntity.getGenerateOrderProcess() );
                
               //分享时的状态 statusWhenSharing :1 已下单等待称重,2.已称重等待客户支付,3.客户已支付等待发货,4.已完成(包括发货、签收)
               int statusWhenSharing = 1 ;
               if (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(0)) {
                   //是否可支付 isAllowPayable 状态: 0.不能支付,1.可支付,2.已支付 ,3.正在退款,4.已退款,5.无需支付
                   if (orderEntity.getIsAllowPayable()!= null && orderEntity.getIsAllowPayable().intValue() == 0 ) {
                       statusWhenSharing = 1; 
                   } else if ( orderEntity.getIsAllowPayable()!= null && orderEntity.getIsAllowPayable().intValue() == 1) {
                       statusWhenSharing = 2 ;
                   } else {
                       statusWhenSharing = 3 ;
                   }
               }
               
               if (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)) {
                   if (orderEntity.getFaHuoStatus() == null || "".equals(orderEntity.getFaHuoStatus())) {
                       statusWhenSharing = 3 ;
                   }else {
                       statusWhenSharing = 4 ;
                   }
               }
               
               json.addProperty("StatusWhenSharing", statusWhenSharing);
               
            double totalQuantity = 0 ; 
            int itemCount = 0 ;
            List<OrderDetailEntity> orderDetailList = orderIfc.getOrderDetailList(cltCode,docCode) ;
            JsonArray orderDetailListJsonArray = new JsonArray();
            for (int i =0;orderDetailList != null && i < orderDetailList.size();i++) { 
                   OrderDetailEntity orderDetailEntity =  orderDetailList.get(i) ;
                   JsonObject orderDetailEntityJsonObject = new JsonObject();
                   //主图片
                   orderDetailEntityJsonObject.addProperty("PhotoPath",SettingKey.getUrl(hostUrl, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                      /*    imgData.getImageUrl(orderDetailEntity.getPhotoPath(), settingEntity.getImageProductWidth(),
                                  settingEntity.getImageProductHeight(), settingEntity.isShowProductOrgImage(),
                                  settingEntity.isFromCached(), request)
                                  + (wxQueryString == null || "".equals(wxQueryString) ? "" : "?" + wxQueryString));
                   */
                   
                   if (settingEntity.isShowMatName()) {
                       orderDetailEntityJsonObject.addProperty("MatName", orderDetailEntity.getMatName());
                }
                   
                   orderDetailEntityJsonObject.addProperty("MatCode", orderDetailEntity.getMatCode());
                   orderDetailEntityJsonObject.addProperty("isShowMatCode", settingEntity.isShowMatCode());
                   orderDetailEntityJsonObject.addProperty("isShowMatName", settingEntity.isShowMatName());
                   orderDetailEntityJsonObject.addProperty("isShowSpecial", settingEntity.isShowSpecial());
                   orderDetailEntityJsonObject.addProperty("isShowPrice", settingEntity.isShowPrice());
                   orderDetailEntityJsonObject.addProperty("isShowPoints", settingEntity.isShowPoints());
                   orderDetailEntityJsonObject.addProperty("isShowBrand", settingEntity.isShowBrand());
                   orderDetailEntityJsonObject.addProperty("StockDisplay", settingEntity.getStockDisplay());
                   
                   //是否显示:退货按钮 
                   orderDetailEntityJsonObject.addProperty("isShowReturnButton", settingEntity.isAllowReturnOrder()&&cltCode.equals(orderEntity.getCltCode()) &&  orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&&orderDetailEntity.getPickDigit() != 0 && (orderDetailEntity.getTuiHuoKaiDanStatusItem()==null ||"".equals(orderDetailEntity.getTuiHuoKaiDanStatusItem()))  ?true:false);
 
                   //最小起订数量
                   orderDetailEntityJsonObject.addProperty("Mininum", orderDetailEntity.getMininum());
                    
                if (settingEntity.isShowSpecial()) {
                    orderDetailEntityJsonObject.addProperty("Special", orderDetailEntity.getSpecial());
                }
                
                
                if (orderDetailEntity.getOptionJson() !=null && !"".equals(orderDetailEntity.getOptionJson()))  {
                    //Map<String,Object> lists=gson.fromJson(cartEntity.getOptionJson(),new TypeToken<Map<String,Object>>(){}.getType());
                    orderDetailEntityJsonObject.addProperty("OptionJson", orderDetailEntity.getOptionJson()) ; //gson.toJson(settingEntity));
                }
                
                if (settingEntity.isShowPrice()) {
                    orderDetailEntityJsonObject.addProperty("Price", orderDetailEntity.getPrice() ); // 实际价格
                    orderDetailEntityJsonObject.addProperty("Currency", currencyEntity.getCurrency());
                    orderDetailEntityJsonObject.addProperty("CurrencySign", currencyEntity.getCurrencySign());
                }
                
                orderDetailEntityJsonObject.addProperty("TotalMoney", orderDetailEntity.getTotalMoney() ); // 当前商品金额
                orderDetailEntityJsonObject.addProperty("ReduceAmount", orderDetailEntity.getReduceAmount() ); // 优惠金额
                orderDetailEntityJsonObject.addProperty("ChargesAmount", orderDetailEntity.getChargesAmount() ); // 增加的费用
                orderDetailEntityJsonObject.addProperty("BalanceAmount", orderDetailEntity.getBalanceAmount() ); // 订单行实付金额 = 当前商品金额 - 优惠金额 + 增加的费用
                orderDetailEntityJsonObject.addProperty("ReturningAmount", orderDetailEntity.getReturningAmount() ); // 订单行可退款项 = 当前商品金额 - 优惠金额 
                
                //取出导购上传的图片
                JsonArray orderDetailImageJsonArray = new JsonArray();
                if (orderDetailEntity.getImages() != null && !"".equals(orderDetailEntity.getImages())) {
                    String unids[] = orderDetailEntity.getImages().split(";") ;
                    String unid = unids[0] ;
                    for (int m = 0 ;m < unids.length;m++) {
                        if (m == 0) continue ; 
                        String seq = unids[m] ;
                        JsonObject unidSeqJson = new JsonObject();
                        unidSeqJson.addProperty(SettingKey.UNID,unid) ;
                        unidSeqJson.addProperty("seq",seq) ;
                        unidSeqJson.addProperty("url",imgData.getImageUrl(unid +";" + seq, settingEntity.getImageProductWidth(),
                                  settingEntity.getImageProductHeight(), settingEntity.isShowProductOrgImage(),
                                  settingEntity.isFromCached(), request) ) ;
                        orderDetailImageJsonArray.add(unidSeqJson) ;
                    }
                }
                orderDetailEntityJsonObject.add("Images",orderDetailImageJsonArray) ;
                
                orderDetailEntityJsonObject.addProperty("Quantity", orderDetailEntity.getDigit()) ;
                orderDetailEntityJsonObject.addProperty("RowId", orderDetailEntity.getRowId());
                
                orderDetailEntityJsonObject.addProperty("skuId1", orderDetailEntity.getSkuId1());
                orderDetailEntityJsonObject.addProperty("skuName1", orderDetailEntity.getSkuName1());
                orderDetailEntityJsonObject.addProperty("skuId2", orderDetailEntity.getSkuId2());
                orderDetailEntityJsonObject.addProperty("skuName2", orderDetailEntity.getSkuName2());
                orderDetailEntityJsonObject.addProperty("skuId3", orderDetailEntity.getSkuId3());
                orderDetailEntityJsonObject.addProperty("skuName3", orderDetailEntity.getSkuName3());
                orderDetailEntityJsonObject.addProperty("skuId4", orderDetailEntity.getSkuId4());
                orderDetailEntityJsonObject.addProperty("skuName4", orderDetailEntity.getSkuName4());
                orderDetailEntityJsonObject.addProperty("skuId5", orderDetailEntity.getSkuId5());
                orderDetailEntityJsonObject.addProperty("skuName5", orderDetailEntity.getSkuName5());
                orderDetailEntityJsonObject.addProperty("skuId6", orderDetailEntity.getSkuId6());
                orderDetailEntityJsonObject.addProperty("skuName6", orderDetailEntity.getSkuName6());
                orderDetailEntityJsonObject.addProperty("skuId7", orderDetailEntity.getSkuId7());
                orderDetailEntityJsonObject.addProperty("skuName7", orderDetailEntity.getSkuName7());
                orderDetailEntityJsonObject.addProperty("skuId8", orderDetailEntity.getSkuId8());
                orderDetailEntityJsonObject.addProperty("skuName8", orderDetailEntity.getSkuName8());
                orderDetailEntityJsonObject.addProperty("skuId9", orderDetailEntity.getSkuId9());
                orderDetailEntityJsonObject.addProperty("skuName9", orderDetailEntity.getSkuName9());
                orderDetailEntityJsonObject.addProperty("skuId10", orderDetailEntity.getSkuId10());
                orderDetailEntityJsonObject.addProperty("skuName10", orderDetailEntity.getSkuName10());
                
                
                totalQuantity += orderDetailEntity.getDigit();
                itemCount ++ ;
                   orderDetailListJsonArray.add(orderDetailEntityJsonObject);
               }
            
            json.add("list", orderDetailListJsonArray);
            json.addProperty("TotalQuantity",df.format(totalQuantity));  //所有商品总“数量”
            json.addProperty("ItemCount",itemCount);    //有多少种类商品
            json.addProperty("GroupBuyingDocCode",orderEntity.getGroupBuyingDocCode());   //团购订单号 
            json.addProperty("GroupBuyingHasMembers",orderEntity.getGroupBuyingHasMembers()!=null&& orderEntity.getGroupBuyingHasMembers().intValue() >0?orderEntity.getGroupBuyingHasMembers():0);   //已经成团人数 
            Integer groupBuyingMembersBalance = 0;
            if (orderEntity.getGroupBuyingDocCode()!=null && !"".equals(orderEntity.getGroupBuyingDocCode())) {
                OrderDetailEntity  orderDetailEntity =  orderDetailList != null&&orderDetailList.size()>0? orderDetailList.get(0):null;
                if (orderDetailEntity != null && orderDetailEntity.getGroupBuyingMembers()!=null && orderEntity.getGroupBuyingHasMembers()!=null) {
                    //已成团人数 - 成团人数 
                    groupBuyingMembersBalance =  orderEntity.getGroupBuyingHasMembers().intValue() - orderDetailEntity.getGroupBuyingMembers().intValue() ;
                }
            }
            json.addProperty("GroupBuyingMembersBalance",groupBuyingMembersBalance);   //团购余额:还差多少人成团 
            
            //显示拼团详细人员列表
            List<GroupBuyingEntity>groupBuyingList = orderIfc.getGroupBuyingOrderList( orderEntity.getGroupBuyingDocCode()) ;
            JsonArray groupBuyingListJsonArray = new JsonArray();
            for (int i = 0; groupBuyingList !=null && i < groupBuyingList.size(); i++) {
                GroupBuyingEntity groupBuyingEntity = groupBuyingList.get(i);
                JsonObject groupBuyingEntityJsonObject = new JsonObject();
                groupBuyingEntityJsonObject.addProperty("OpenId", groupBuyingEntity.getOpenId());
                groupBuyingEntityJsonObject.addProperty("NickName", groupBuyingEntity.getNickName());
                groupBuyingEntityJsonObject.addProperty("NickName", groupBuyingEntity.getNickName());
                groupBuyingEntityJsonObject.addProperty("Headimgurl", groupBuyingEntity.getHeadimgurl());
                groupBuyingEntityJsonObject.addProperty("WeiXinAvatarUnid", groupBuyingEntity.getWeiXinAvatarUnid());
                groupBuyingEntityJsonObject.addProperty("EnterDate", sdf3.format(groupBuyingEntity.getEnterDate()));
                groupBuyingEntityJsonObject.addProperty("isGroupBuyingMaster", groupBuyingEntity.isGroupBuyingMaster());
                groupBuyingListJsonArray.add(groupBuyingEntityJsonObject);
            }
            json.add("groupBuyingList", groupBuyingListJsonArray);
            
            
            this.printJson(response, json.toString());
            
            return ;
            
        }catch(DataAccessException e ) {
            e.printStackTrace();
            errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch(Exception e){
            e.printStackTrace();
            errJson.addProperty("warning", e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }finally {
            SpObserver.setDBtoInstance();
        }
    }
    
    @RequestMapping("/shopping/groupBuyingOrderList.do")
    public void groupBuyingOrderList(HttpServletRequest request,HttpServletResponse response) {
        //HttpSession session=request.getSession();
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd HH:mm") ;
        String groupBuyingDocCode = request.getParameter(SettingKey.GROUPBUYINGDOCCODE);
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
            //显示拼团详细人员列表
            List<GroupBuyingEntity>groupBuyingList = orderIfc.getGroupBuyingOrderList( groupBuyingDocCode) ;
            JsonArray groupBuyingListJsonArray = new JsonArray();
            for (int i = 0; groupBuyingList !=null && i < groupBuyingList.size(); i++) {
                GroupBuyingEntity groupBuyingEntity = groupBuyingList.get(i);
                JsonObject groupBuyingEntityJsonObject = new JsonObject();
                groupBuyingEntityJsonObject.addProperty("OpenId", groupBuyingEntity.getOpenId());
                groupBuyingEntityJsonObject.addProperty("NickName", groupBuyingEntity.getNickName());
                groupBuyingEntityJsonObject.addProperty("NickName", groupBuyingEntity.getNickName());
                groupBuyingEntityJsonObject.addProperty("Headimgurl", groupBuyingEntity.getHeadimgurl());
                groupBuyingEntityJsonObject.addProperty("WeiXinAvatarUnid", groupBuyingEntity.getWeiXinAvatarUnid());
                groupBuyingEntityJsonObject.addProperty("EnterDate", sdf3.format(groupBuyingEntity.getEnterDate()));
                groupBuyingEntityJsonObject.addProperty("isGroupBuyingMaster", groupBuyingEntity.isGroupBuyingMaster());
                groupBuyingListJsonArray.add(groupBuyingEntityJsonObject);
            }
            json.add("groupBuyingList", groupBuyingListJsonArray);
            this.printJson(response, json.toString());
            
            return ;
            
        }catch(DataAccessException e ) {
            e.printStackTrace();
            errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch(Exception e){
            e.printStackTrace();
            errJson.addProperty("warning", e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }finally {
            SpObserver.setDBtoInstance();
        }
    }
    
    @RequestMapping("/shopping/orderReceipt.do")
    public void updateOrderReceipt(HttpServletRequest request,HttpServletResponse response) {
        HttpSession session=request.getSession();
        String cltCode = (session.getAttribute(SettingKey.CLTCODE)==null?"":(String)session.getAttribute(SettingKey.CLTCODE));
        //String userCode = (session.getAttribute(SessionKey.USERCODE) == null ? "" 
        //        : (String)session.getAttribute(SessionKey.USERCODE));
        String docCode=request.getParameter(SettingKey.DOCCODE)==null?"":request.getParameter(SettingKey.DOCCODE);
        //将微信corpid组装成url
        //String wxQueryString = SettingKey.getQueryStringByWx(request);
        //boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
        //String hostUrl = SettingKey.getHostUrl(request) ;  
        
        JsonObject json = new JsonObject();
        JsonObject errJson = new JsonObject();
        
        try {
            DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
            SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
            
            //检查该客户是否存在
            if (cltCode != null && !"".equals(cltCode)) {
                
                CustomerEntity customerEntity = accountIfc.getLoginInfoByCltCode(cltCode,cltCode,cltCode);
                if (customerEntity==null || customerEntity.getCltCode()==null||customerEntity.getCltCode().equals("")) {
                    cltCode = null;
                    session.removeAttribute(SettingKey.CLTCODE);
                }
            }
            
            if (cltCode == null || "".equals(cltCode) )  {
                json.addProperty(SettingKey.CLTCODE,"");
                return ;
            }else {
                json.addProperty(SettingKey.CLTCODE,cltCode);
            }
            boolean ret = orderIfc.updateOrderReceipt(cltCode,docCode) ;
            
            json.addProperty("state", ret ? "success": "falied");
            this.printJson(response, json.toString());
            return;    
            
        }catch(DataAccessException e ) {
            e.printStackTrace();
            errJson.addProperty("warning", e.getCause() != null ?e.getCause().getMessage():e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }catch(Exception e){
            e.printStackTrace();
            errJson.addProperty("warning", e.getMessage());
            json.add("error", errJson);
            this.printJson(response, json.toString());
            return;
        }finally {
            SpObserver.setDBtoInstance();
        }
    }
}