コード例 #1
0
ファイル: EasiPayProcessor.cs プロジェクト: sanlonezhang/ql
        /// <summary>
        /// 申报订单
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool DeclareSO(WaitDeclareSO entity)
        {
            bool result = false;

            #region 0.先进行支付申报,申报成功再执行订单申报
            if (!this.DeclarePayment(entity))
            {
                return(result);
            }
            #endregion

            #region 1.单笔值计算
            DeclareOrderInfo  declareOrderInfo = SODA.DeclareGetOrderInfoBySOSysNo(entity.SOSysNo);
            VendorCustomsInfo customsInfo      = SODA.LoadVendorCustomsInfo(entity.SOSysNo);
            PayType           payType          = ObjectFactory <ICommonBizInteract> .Instance.GetPayTypeByID(declareOrderInfo.PayTypeID);

            if (declareOrderInfo == null || declareOrderInfo.SOItemList == null || declareOrderInfo.SOItemList.Count == 0)
            {
                return(result);
            }
            decimal allCargoTotalPrice = 0m;
            string  cargoDescript      = "";
            decimal totalTariffAmount  = 0m;
            decimal otherPrice         = Math.Abs(declareOrderInfo.Amount.PrepayAmt) * -1;
            List <EasiPayRequestDeclareOrderCargoes> cargoesList = new List <EasiPayRequestDeclareOrderCargoes>();

            foreach (var item in declareOrderInfo.SOItemList)
            {
                cargoDescript     += (string.IsNullOrEmpty(cargoDescript) ? "" : ";") + (item.ProductName.Replace("#", "").Replace("%", "").Replace("&", "").Replace("+", "") + "描述");
                totalTariffAmount += item.TariffAmt * item.Quantity;
                item.ProductName   = item.ProductName.Replace("#", "").Replace("%", "").Replace("&", "").Replace("+", "");
                //折扣除不尽时,把多余的作为OtherPrice上送
                decimal currOtherPrice = Math.Abs(item.DiscountAmt) % item.Quantity;
                otherPrice += currOtherPrice * -1;
                //Item上是商品本身的价格,需要排除折扣
                decimal unitPrice = item.OriginalPrice - ((Math.Abs(item.DiscountAmt) - currOtherPrice) / item.Quantity);
                unitPrice           = decimal.Parse(unitPrice.ToString("F2"));
                otherPrice         += Math.Abs(item.PromotionDiscount * item.Quantity) * -1;
                allCargoTotalPrice += unitPrice * item.Quantity;
                cargoesList.Add(new EasiPayRequestDeclareOrderCargoes()
                {
                    cargoName       = item.ProductName,
                    cargoCode       = item.EntryCode,
                    cargoNum        = item.Quantity,
                    cargoUnitPrice  = decimal.Parse(unitPrice.ToString("F2")),
                    cargoTotalPrice = decimal.Parse((unitPrice * item.Quantity).ToString("F2")),
                    cargoTotalTax   = decimal.Parse((item.TariffAmt * item.Quantity).ToString("F2"))
                });
            }
            //积分支付作为其他金额报关
            otherPrice += Math.Abs(declareOrderInfo.Amount.PointPay * 1.00m / 100.00m) * -1;
            #endregion

            #region 2.构造请求业务数据
            int serialNumber = SODA.CreateSODeclareRecordsSysNo();
            EasiPayRequestDeclareOrder requestInfo = new EasiPayRequestDeclareOrder();
            requestInfo.version           = AppSettingManager.GetSetting("SO", "EasiPayDeclareOrderConfigVersion");
            requestInfo.commitTime        = DateTime.Now.ToString("yyyyMMddHHmmss");
            requestInfo.coName            = customsInfo.CBTMerchantName;
            requestInfo.coCode            = customsInfo.CBTSRC_NCode;
            requestInfo.MerchantSecretKey = customsInfo.CBTSODeclareSecretKey;
            requestInfo.serialNumber      = serialNumber.ToString();
            requestInfo.merchantOrderId   = entity.SOSysNo.ToString();
            requestInfo.assBillNo         = entity.TrackingNumber;
            requestInfo.orderCommitTime   = declareOrderInfo.OrderDate.ToString("yyyyMMddHHmmss");
            //发件信息,从Appsetting配置中取(改为从仓库表中读取 by cavin 2014-12-02)
            //仓库编号
            //string warehouseNumber = declareOrderInfo.SOItemList[0].WarehouseNumber.Trim();
            requestInfo.senderName        = declareOrderInfo.senderName;        //AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderName", warehouseNumber));
            requestInfo.senderTel         = declareOrderInfo.senderTel;         // AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderTel", warehouseNumber));
            requestInfo.senderCompanyName = declareOrderInfo.senderCompanyName; // AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderCompanyName", warehouseNumber));
            requestInfo.senderAddr        = declareOrderInfo.senderAddr;        // AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderAddr", warehouseNumber));
            requestInfo.senderZip         = declareOrderInfo.senderZip;         // AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderZip", warehouseNumber));
            requestInfo.senderCity        = declareOrderInfo.senderCity;        // AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderCity", warehouseNumber));
            requestInfo.senderProvince    = declareOrderInfo.senderProvince;    // AppSettingManager.GetSetting("SO", string.Format("EasiPayDeclareOrderConfig_Sender_{0}_SenderProvince", warehouseNumber));
            //发件地国家,需要适配三位国家代码
            requestInfo.senderCountry      = declareOrderInfo.SOItemList.FirstOrDefault().CountryCode;
            requestInfo.cargoDescript      = string.IsNullOrEmpty(cargoDescript) ? "无商品信息简述" : cargoDescript;
            requestInfo.allCargoTotalPrice = decimal.Parse(allCargoTotalPrice.ToString("F2"));
            requestInfo.allCargoTotalTax   = decimal.Parse(totalTariffAmount.ToString("F2"));
            requestInfo.expressPrice       = decimal.Parse(declareOrderInfo.Amount.ShipPrice.ToString("F2"));
            requestInfo.otherPrice         = decimal.Parse(otherPrice.ToString("F2"));
            requestInfo.recPerson          = string.IsNullOrWhiteSpace(declareOrderInfo.ReceiveName) ? "无" : declareOrderInfo.ReceiveName;
            requestInfo.recPhone           = string.IsNullOrWhiteSpace(declareOrderInfo.ReceiveCellPhone) ? "无" : declareOrderInfo.ReceiveCellPhone;
            requestInfo.recCountry         = "中国";
            requestInfo.recProvince        = string.IsNullOrWhiteSpace(declareOrderInfo.ReceiveProvinceName) ? "无" : declareOrderInfo.ReceiveProvinceName;
            requestInfo.recCity            = string.IsNullOrWhiteSpace(declareOrderInfo.ReceiveCityName) ? "无" : declareOrderInfo.ReceiveCityName;
            requestInfo.recAddress         = string.IsNullOrWhiteSpace(declareOrderInfo.ReceiveAddress) ? "无" : declareOrderInfo.ReceiveAddress;
            //为空
            requestInfo.recZip        = "";
            requestInfo.serverType    = declareOrderInfo.StockType == BizEntity.Common.TradeType.FTA ? "S02" : "S01";
            requestInfo.custCode      = declareOrderInfo.CustomsCode;
            requestInfo.operationCode = AppSettingManager.GetSetting("SO", "EasiPayDeclareOrderConfigOperationCode");
            //为空
            requestInfo.spt             = "";
            requestInfo.cargoes         = cargoesList;
            requestInfo.payMethod       = AppSettingManager.GetSetting("SO", "EasiPayDeclareOrderConfigPayMethod");
            requestInfo.payMerchantName = payType.CBTMerchantName;
            requestInfo.payMerchantCode = payType.CBTMerchantCode;
            //支付总金额=全部商品合计总价+税费+物流运费+其他金额(其他金额为负数)-余额支付金额
            requestInfo.payAmount = decimal.Parse((allCargoTotalPrice + totalTariffAmount + declareOrderInfo.Amount.ShipPrice + otherPrice).ToString("F2"));
            requestInfo.payCUR    = customsInfo.PayCurrencyCode;
            requestInfo.payID     = string.IsNullOrWhiteSpace(declareOrderInfo.PayInfo.SerialNumber) ? "" : declareOrderInfo.PayInfo.SerialNumber.Substring(1).Trim();//因为支付有个前缀P
            requestInfo.payTime   = declareOrderInfo.PayInfo.PayProcessTime.Trim();
            #endregion

            #region 3.处理请求,解析请求结果
            SOLogInfo soLogInfo = new SOLogInfo()
            {
                UserSysNo     = 3025,
                IP            = "Delcare SO Job",
                OperationType = ECCentral.BizEntity.Common.BizLogType.Sale_SO_Update,
                SOSysNo       = entity.SOSysNo,
                Note          = "",
                CompanyCode   = "8601"
            };
            string reqContent       = BuildPostReqData(requestInfo, requestInfo.MerchantSecretKey);
            string strRequestResult = HttpPostRequest(AppSettingManager.GetSetting("SO", "EasiPayDeclareOrderConfigRequestUrl"), reqContent);
            strRequestResult = CommonUtility.HttpUrlDecode(strRequestResult);
            EasiPayRequestResult requestResult = SerializationUtility.JsonDeserialize <EasiPayRequestResult>(strRequestResult);
            if (requestResult.status.ToLower().Equals("success"))
            {
                result         = true;
                soLogInfo.Note = "订单报关申报提交成功";
            }
            else
            {
                soLogInfo.Note = string.Format("订单报关申报提交失败:{0}", requestResult.errorMsg);
            }
            ObjectFactory <ISOLogDA> .Instance.InsertSOLog(soLogInfo);

            #region 写系统Log
            ApplicationEventLog log = new ApplicationEventLog()
            {
                Source           = "JOB SODeclare",
                ReferenceIP      = ServiceContext.Current.ClientIP,
                EventType        = 8,
                HostName         = "JOB",
                EventTitle       = "SODeclare Request",
                EventMessage     = reqContent,
                LanguageCode     = "zh-CN",
                CompanyCode      = "8601",
                StoreCompanyCode = "8601",
                EventDetail      = soLogInfo.Note,
            };
            ObjectFactory <ICommonBizInteract> .Instance.CreateApplicationEventLog(log);

            #endregion
            #endregion

            #region 4.提交申报申请成功,创建申报记录
            if (result)
            {
                SODeclareRecords declareRecord = new SODeclareRecords()
                {
                    SysNo          = serialNumber,
                    SOSysNo        = entity.SOSysNo,
                    TrackingNumber = entity.TrackingNumber
                };
                SODA.CreateSODeclareRecords(declareRecord);
            }
            #endregion

            return(result);
        }