xinyb
2024-07-18 80430d52f7716e3eb3e517dc96f94c4a6f9657bf
src/com/yc/sdk/shopping/action/Order.java
@@ -1,19 +1,5 @@
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;
@@ -21,13 +7,7 @@
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.entity.*;
import com.yc.sdk.shopping.service.CartIfc;
import com.yc.sdk.shopping.service.CurrencyIfc;
import com.yc.sdk.shopping.service.SettingIfc;
@@ -37,6 +17,18 @@
import com.yc.sdk.shopping.util.SettingKey;
import com.yc.sdk.shopping.util.StringReplaceUtil;
import com.yc.utils.SessionKey;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;
@Controller
@Scope("prototype")
@@ -140,7 +132,8 @@
      //将微信corpid组装成url
      //String wxQueryString = SettingKey.getQueryStringByWx(request);
      //boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
      String hostUrl = SettingKey.getHostUrl(request) ;
      //String hostUrl = SettingKey.getHostUrl(request) ;
      String hostUrlForImage = SettingKey.getHostUrlForImage(request) ;
      
      JsonObject json = new JsonObject();
      JsonObject errJson = new JsonObject();
@@ -152,11 +145,11 @@
      try {
         DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
         SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
         SettingEntity settingEntity = settingIfc.getSettingEntity() ;
         SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
         // 取网店 shopcccode
         ShopCcCodeEntity shopCcCodeEntity = ShopCcCode.getShopCcCode(settingEntity,request);
         //货币
         CurrencyEntity currencyEntity = currencyIfc.getUserCurrency(userCode);
         CurrencyEntity currencyEntity = new CurrencyEntity(request);
         
         //检查该客户是否存在
         if (cltCode != null && !"".equals(cltCode)) {
@@ -181,7 +174,7 @@
         if (isAllowPayable != null &&  !isAllowPayable.equals("")) {
            orderList = orderIfc.getOrderListByIsAllowPayable(cltCode,Integer.parseInt(isAllowPayable) ,shopCcCodeEntity.getShopCcCode()) ;   //待称重订单列表
         } else {
            orderList = orderIfc.getOrderList( cltCode,shopCcCodeEntity.getShopCcCode()) ;   //所有订单列表
            orderList = orderIfc.getOrderListWithDetailList( cltCode,shopCcCodeEntity.getShopCcCode()) ;   //所有订单列表
         }
         
         JsonArray orderListJsonArray = new JsonArray();
@@ -207,7 +200,12 @@
            orderEntityJsonObject.addProperty("GroupBy", groupBy);
             //订单行信息
                  List<OrderDetailEntity> orderDetailList = orderIfc.getOrderDetailList(cltCode,orderEntity.getDocCode()) ;
                  List<OrderDetailEntity> orderDetailList = null;
                 if (isAllowPayable != null &&  !isAllowPayable.equals("")) {
                    orderDetailList = orderIfc.getOrderDetailList(cltCode,orderEntity.getDocCode()) ;
                 } else {
                    orderDetailList = orderEntity.getOrderDetailList();
                 }
                  if (orderDetailList ==null||orderDetailList.size() == 0) {
                     continue ;
                  }
@@ -217,8 +215,15 @@
                  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("SumTotalMoney3",orderEntity.getSumTotalMoney3());  //优惠后订单总金额 ,由 PayableAmount 代替
//                  orderEntityJsonObject.addProperty("PayableAmount",orderEntity.getPayableAmount());  //优惠后订单总金额
            if (orderEntity.getFormId() == 120230 || orderEntity.getFormId() == 120234) {
               orderEntityJsonObject.addProperty("PayableAmount", orderEntity.getPayableAmount());  //优惠后订单总金额
               orderEntityJsonObject.addProperty("isShowReBuyingButton", true);   //再次购买
            } else {
               orderEntityJsonObject.addProperty("PayableAmount", (orderEntity.getSumTotalMoney2() - orderEntity.getReduceMoney()));  //优惠后订单总金额
               orderEntityJsonObject.addProperty("isShowReBuyingButton", false);   //再次购买
            }
                  orderEntityJsonObject.addProperty("ReduceMoney",orderEntity.getReduceMoney());  //优惠金额 
                  orderEntityJsonObject.addProperty("TransCosts",orderEntity.getTransCosts());  //运费 
                  orderEntityJsonObject.addProperty("HandlingCharges",orderEntity.getHandlingCharges());  //搬运费
@@ -227,7 +232,8 @@
                  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("Telephone",orderEntity.getTel());    //客户电话
                 orderEntityJsonObject.addProperty("Telephone2",orderEntity.getTel2());    //收货人电话
                 orderEntityJsonObject.addProperty("DeliveryMethod",orderEntity.getDeliveryMethod());
                 orderEntityJsonObject.addProperty("DeliveryDate",sdf.format(orderEntity.getDocDate()));
                 orderEntityJsonObject.addProperty("InvoiceType","电子普通发票");
@@ -268,7 +274,8 @@
                     OrderDetailEntity orderDetailEntity =  orderDetailList.get(i) ;
                     JsonObject orderDetailEntityJsonObject = new JsonObject();
                     //主图片
                     orderDetailEntityJsonObject.addProperty("PhotoPath",SettingKey.getUrl(hostUrl, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                     orderDetailEntityJsonObject.addProperty("PhotoPath",SettingKey.getUrl(hostUrlForImage, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                     orderDetailEntityJsonObject.addProperty("PhotoPathUrl",SettingKey.getUrl(hostUrlForImage, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                     /*   imgData.getImageUrl(orderDetailEntity.getPhotoPath(), settingEntity.getImageProductWidth(),
                              settingEntity.getImageProductHeight(), settingEntity.isShowProductOrgImage(),
                              settingEntity.isFromCached(), request)
@@ -372,7 +379,11 @@
                orderDetailEntityJsonObject.addProperty("skuName9", orderDetailEntity.getSkuName9());
                orderDetailEntityJsonObject.addProperty("skuId10", orderDetailEntity.getSkuId10());
                orderDetailEntityJsonObject.addProperty("skuName10", orderDetailEntity.getSkuName10());
               if (orderEntity.getFormId() == 120230 || orderEntity.getFormId() == 120234) {
                  orderDetailEntityJsonObject.addProperty("isShowReBuyingButton", true);   //再次购买
               } else {
                  orderDetailEntityJsonObject.addProperty("isShowReBuyingButton", false);   //再次购买
               }
                totalQuantity += orderDetailEntity.getDigit();
                itemCount ++ ;
                     orderDetailListJsonArray.add(orderDetailEntityJsonObject);
@@ -387,7 +398,7 @@
                    &&orderEntity.getIsAllowPayable()!=null&&orderEntity.getIsAllowPayable().equals(1)?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);
                  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("")) && (orderEntity.getFormId() == 120230 || orderEntity.getFormId() == 120234)?true:false);
                  
                  //是否显示:查看物流按钮
                  boolean isShowLogisticsButton = (orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(100)&& orderEntity.getLogisticsCode()!=null && !orderEntity.getLogisticsCode().equals("")?true:false);
@@ -496,6 +507,8 @@
            : (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);
      //String queryString = request.getQueryString();
      //System.out.println(this.getClass()+" queryString=" + queryString);
      
      //是否导购
      boolean isShopGuide = (session.getAttribute(SettingKey.isShopGuide)!=null ? (boolean)session.getAttribute(SettingKey.isShopGuide) :false );
@@ -503,7 +516,8 @@
      //将微信corpid组装成url
      //String wxQueryString = SettingKey.getQueryStringByWx(request);
      //boolean isMoblieBrowser = SettingKey.isMoblieBrowser(request);
      String hostUrl = SettingKey.getHostUrl(request) ;
      //String hostUrl = SettingKey.getHostUrl(request) ;
      String hostUrlForImage = SettingKey.getHostUrlForImage(request) ;
      DecimalFormat df = new DecimalFormat("0.00");
      //DecimalFormat df2 = new DecimalFormat("0");
      
@@ -513,9 +527,9 @@
      try {
         DataSourceEntity dataSourceEntity = MultiDataSource.getDataSourceMap( request) ;
         SpObserver.setDBtoInstance("_"+dataSourceEntity.getDbId());//切换数据源
         SettingEntity settingEntity = settingIfc.getSettingEntity() ;
         SettingEntity settingEntity = settingIfc.getSettingEntity(request) ;
         //货币
         CurrencyEntity currencyEntity = currencyIfc.getUserCurrency(userCode);
         CurrencyEntity currencyEntity = new CurrencyEntity(request);
         
         //检查该客户是否存在
         if (cltCode != null && !"".equals(cltCode)) {
@@ -529,7 +543,8 @@
         
         if (cltCode == null || "".equals(cltCode) )  {
            json.addProperty(SettingKey.CLTCODE,"");
            return ;
            //this.printJson(response, json.toString());
            //return;   //暂时不要 return ,因为点击小程序服务通知时,打开订单明细时可能是没有会话的,即 cltCode 为空值,注释by Johns Wang,2021-12-09
         }else {
            json.addProperty(SettingKey.CLTCODE,cltCode);
         }
@@ -581,11 +596,12 @@
          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("Telephone2",orderEntity.getCltCode().equals( cltCode)||isShopGuide?orderEntity.getTel2():StringReplaceUtil.getStarString2(orderEntity.getTel2(),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","电子普通发票");
@@ -600,8 +616,12 @@
          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("PayableSecondBalance",orderEntity.getPayableSecondBalance()!=null&& orderEntity.getPayableSecondBalance().intValue() >0?orderEntity.getPayableSecondBalance():0);   //下单后支付倒计时秒数
         if (orderEntity.getFormId() == 120230 || orderEntity.getFormId() == 120234) {
            json.addProperty("isShowReBuyingButton",true);   //再次购买
         } else {
            json.addProperty("isShowReBuyingButton",false);   //再次购买
         }
              //是否显示:支付按钮
          json.addProperty("isShowPayButton",cltCode.equals(orderEntity.getCltCode()) &&  orderEntity.getDocStatus()!=null&&orderEntity.getDocStatus().equals(0)
                &&orderEntity.getCltCode()!=null&&orderEntity.getCltCode().equals(cltCode)
@@ -609,7 +629,7 @@
              //是否显示:取消订单按钮 
          //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);
          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("")) && (orderEntity.getFormId() == 120230 || orderEntity.getFormId() == 120234)?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("") );
@@ -648,13 +668,15 @@
              
          double totalQuantity = 0 ; 
          int itemCount = 0 ;
         Integer exchangePointsQuantityTotal=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));
                 orderDetailEntityJsonObject.addProperty("PhotoPath",SettingKey.getUrl(hostUrlForImage, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                 orderDetailEntityJsonObject.addProperty("PhotoPathUrl",SettingKey.getUrl(hostUrlForImage, orderDetailEntity.getPhotoPathUrl(),  dataSourceEntity.getDbId()+"",null));
                 /*   imgData.getImageUrl(orderDetailEntity.getPhotoPath(), settingEntity.getImageProductWidth(),
                          settingEntity.getImageProductHeight(), settingEntity.isShowProductOrgImage(),
                          settingEntity.isFromCached(), request)
@@ -750,13 +772,20 @@
            orderDetailEntityJsonObject.addProperty("skuName9", orderDetailEntity.getSkuName9());
            orderDetailEntityJsonObject.addProperty("skuId10", orderDetailEntity.getSkuId10());
            orderDetailEntityJsonObject.addProperty("skuName10", orderDetailEntity.getSkuName10());
            if (orderEntity.getFormId() == 120230 || orderEntity.getFormId() == 120234) {
               orderDetailEntityJsonObject.addProperty("isShowReBuyingButton",true);   //再次购买
            } else {
               orderDetailEntityJsonObject.addProperty("isShowReBuyingButton",false);   //再次购买
            }
            //用来记录花了多少积分抵扣的
            exchangePointsQuantityTotal = (exchangePointsQuantityTotal + orderDetailEntity.getExchangePointsQuantity());
            orderDetailEntityJsonObject.addProperty("exchangePointsQuantity", orderDetailEntity.getExchangePointsQuantity());
            totalQuantity += orderDetailEntity.getDigit();
            itemCount ++ ;
                 orderDetailListJsonArray.add(orderDetailEntityJsonObject);
              }
          json.addProperty("exchangePointsQuantityTotal",exchangePointsQuantityTotal);//用来记录花了多少积分抵扣的(总抵扣积分)
          json.add("list", orderDetailListJsonArray);
          json.addProperty("TotalQuantity",df.format(totalQuantity));  //所有商品总“数量”
          json.addProperty("ItemCount",itemCount);    //有多少种类商品