Пример #1
0
        /// <summary>
        /// 申报商品
        /// </summary>
        /// <param name="decalreList">待申报商品列表,必须是同一个商家,不能超过10个商品</param>
        /// <returns></returns>
        public DeclareProductResult DeclareProduct(List <WaitDeclareProduct> decalreList)
        {
            DeclareProductResult result = new DeclareProductResult();

            //检查是否有数据
            if (decalreList == null || decalreList.Count <= 0)
            {
                return(result);
            }
            var group = decalreList.GroupBy(d => d.MerchantSysNo);

            //检查数据是否满足要求
            if (group.Count() > 1 || decalreList.Count > 10)
            {
                throw new BizException("待申报商品列表,必须是同一个商家,不能超过10个商品");
            }
            //获取商家取关务对接相关信息
            VendorCustomsInfo customsInfo = SODA.LoadVendorCustomsInfoByMerchant(decalreList.FirstOrDefault().MerchantSysNo);
            //获取待申报商品详细信息
            List <ProductDeclare> dataList = ObjectFactory <IIMBizInteract> .Instance.DeclareGetProduct(decalreList);

            #region 构造请求参数
            EasiPayRequestDeclareProduct requestInfo = new EasiPayRequestDeclareProduct();
            requestInfo.version      = AppSettingManager.GetSetting("SO", "EasiPayDeclareProductConfigVersion");
            requestInfo.commitTime   = DateTime.Now.ToString("yyyyMMddHHmmss");
            requestInfo.coName       = customsInfo.CBTMerchantName;
            requestInfo.coCode       = customsInfo.CBTSRC_NCode;
            requestInfo.serialNumber = this.CreateSerialNumber(requestInfo.coCode);
            requestInfo.Cargoes      = EntityConverter <ProductDeclare, EasiPayRequestDeclareProductDetail> .Convert(dataList, (s, t) =>
            {
                t.cargoCode        = s.ProductID;
                t.cargoBrand       = s.BrandName;
                t.cargoNameCh      = s.ProductName;
                t.cargoNameEh      = s.ProductNameEN;
                t.cargoModel       = s.ProductMode;
                t.cargoSpec        = s.Specifications;
                t.cargoPlace       = s.CountryName;
                t.cargoFunction    = s.Functions;
                t.cargoPurpose     = s.Purpose;
                t.cargoIngredient  = s.Component;
                t.cargoFactoryDate = s.ManufactureDate.ToString("yyyyMMdd");
                t.cargoUnit        = s.TaxUnit;
                t.cargoUnitNum     = s.TaxQty.ToString();
                t.cargoPrice       = s.CurrentPrice.ToString("F2");
                t.cargoGrossWT     = s.GrossWeight;
                t.cargoNetWT       = s.SuttleWeight;
                t.serverType       = s.BizType == TradeType.FTA ? "S02" : "S01";
                t.customsCode      = s.CustomsCode;
                t.copGNo           = s.ProductSKUNO;
                t.materialID       = s.SuppliesSerialNo;
                t.beianUnit        = s.ApplyUnit;
                t.beianQty         = s.ApplyQty.ToString();
            });

            requestInfo.operationCode = "1";
            requestInfo.spt           = "";
            #endregion
            #region 3.处理请求,解析请求结果
            string reqContent       = BuildPostReqData(requestInfo, customsInfo.CBTProductDeclareSecretKey);
            string note             = string.Empty;
            string strRequestResult = HttpPostRequest(AppSettingManager.GetSetting("SO", "EasiPayDeclareProductConfigRequestUrl"), reqContent);
            strRequestResult = CommonUtility.HttpUrlDecode(strRequestResult);
            EasiPayRequestResult requestResult = SerializationUtility.JsonDeserialize <EasiPayRequestResult>(strRequestResult);
            if (requestResult.status.ToLower().Equals("success"))
            {
                result.Success = true;
                try
                {
                    ObjectFactory <IIMBizInteract> .Instance.ProductBatchEntry(decalreList.Select(t => t.ProductSysNo).ToList(), "", ProductEntryStatus.Entry, ProductEntryStatusEx.Customs);
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
                note = "商品报关申请成功";
            }
            else
            {
                result.Message = requestResult.msg;
                note           = "商品报关申请失败:" + requestResult.msg;
            }
            #region 写系统Log
            ApplicationEventLog log = new ApplicationEventLog()
            {
                Source           = "JOB ProductDeclare",
                ReferenceIP      = ServiceContext.Current.ClientIP,
                EventType        = 8,
                HostName         = "JOB",
                EventTitle       = "ProductDeclare Request",
                EventMessage     = reqContent,
                LanguageCode     = "zh-CN",
                CompanyCode      = "8601",
                StoreCompanyCode = "8601",
                EventDetail      = note
            };
            ObjectFactory <ICommonBizInteract> .Instance.CreateApplicationEventLog(log);

            #endregion
            #endregion
            return(result);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// 支付申报
        /// </summary>
        /// <param name="entity"></param>
        /// <returns>true申报成功,false申报失败</returns>
        public bool DeclarePayment(WaitDeclareSO entity)
        {
            bool result = false;

            #region 获取支付信息
            SOPaymentDeclare data = SODA.DeclareGetPaymentInfoBySOSysNo(entity.SOSysNo);
            #endregion
            //检查是否需要进行支付申报,东方支付不需要进行支付申报
            if (data.PayTypeID == s_EasiPayID)
            {
                //东方支付不需要传,直接更新支付申报状态为申报成功
                SODA.DeclareUpdatePaymentDeclareInfo(entity.SOSysNo, null, 1);
                data = SODA.DeclareGetPaymentInfoBySOSysNo(entity.SOSysNo);
            }
            if (data.DeclareStatus.HasValue && data.DeclareStatus.Value == 1)
            {
                result = true;
            }
            else
            {
                #region 构造请求参数
                VendorCustomsInfo customsInfo = SODA.LoadVendorCustomsInfo(entity.SOSysNo);
                PayType           payType     = ObjectFactory <ICommonBizInteract> .Instance.GetPayType(data.PayTypeSysNo);

                EasiPayRequestDeclarePayment declarePayment = EntityConverter <SOPaymentDeclare, EasiPayRequestDeclarePayment> .Convert(data);

                declarePayment.Version      = "v1.0";
                declarePayment.CommitTime   = DateTime.Now.ToString("yyyyMMddhhmmss");
                declarePayment.CoCode       = payType.CBTMerchantCode;
                declarePayment.CoName       = payType.CBTMerchantName;
                declarePayment.MerchantCode = customsInfo.CBTMerchantCode;
                declarePayment.MerchantName = customsInfo.CBTMerchantName;
                declarePayment.SerialNumber = this.CreateSerialNumber(declarePayment.CoCode);
                declarePayment.IdentifyType = data.IDCardType == 0 ? "30" : "";//固定值30 身份证
                declarePayment.Birthday     = data.Birthday.ToString("yyyyMMdd");
                declarePayment.Sex          = data.Gender == 0 ? "F" : data.Gender == 1 ? "M" : "";
                declarePayment.PayID        = data.PayTransNumber.Substring(1).Trim();//因为支付有个前缀P
                #endregion
                #region 处理请求,解析请求结果
                string note             = string.Empty;
                string reqContent       = BuildPostReqData(declarePayment, payType.CBTSODeclarePaymentSecretKey);
                string strRequestResult = HttpPostRequest(AppSettingManager.GetSetting("SO", "EasiPayDeclarePaymentConfigRequestUrl"), reqContent);
                strRequestResult = CommonUtility.HttpUrlDecode(strRequestResult);
                EasiPayRequestResult requestResult = SerializationUtility.JsonDeserialize <EasiPayRequestResult>(strRequestResult);
                if (requestResult.status.ToLower().Equals("success"))
                {
                    result = true;
                    note   = "支付报关申请成功";
                }
                else
                {
                    note = "支付报关申请失败:" + requestResult.msg;
                }
                #region 写系统Log
                ApplicationEventLog log = new ApplicationEventLog()
                {
                    Source           = "JOB SODeclarePayment",
                    ReferenceIP      = ServiceContext.Current.ClientIP,
                    EventType        = 9,
                    HostName         = "JOB",
                    EventTitle       = "SODeclarePayment Request",
                    EventMessage     = reqContent,
                    LanguageCode     = "zh-CN",
                    CompanyCode      = "8601",
                    StoreCompanyCode = "8601",
                    EventDetail      = note,
                };
                ObjectFactory <ICommonBizInteract> .Instance.CreateApplicationEventLog(log);

                #endregion
                #endregion
                #region 更新支付状态
                SODA.DeclareUpdatePaymentDeclareInfo(entity.SOSysNo, declarePayment.SerialNumber, result ? 1 : 0);
                #endregion
            }
            return(result);
        }