From 774b1973ef848ae91fd579735d863f95c070bc23 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng Date: Thu, 28 Sep 2023 18:03:37 +0800 Subject: [PATCH] =?UTF-8?q?ISF=E5=A2=9E=E5=8A=A0=E8=B4=AD=E4=B9=B0Bond?= =?UTF-8?q?=E9=9C=80=E6=B1=82=E5=BC=80=E5=8F=91=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E2=80=9CISF-bond=E4=BD=BF=E7=94=A8=E8=B4=B9=E2=80=9D?= =?UTF-8?q?=E7=9A=84=E6=89=A3=E8=B4=B9=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/Djy.Common/Const/BusinessType.cs | 23 +++++++ web/Djy.Common/DJYModel/CustFee.cs | 30 ++++++--- web/Djy.Common/Tools/EnumTools.cs | 24 +++++++ web/djy.IService/Djy/IFinanceService.cs | 4 +- web/djy.Service/DjyService/FinanceService.cs | 70 +++++++++++++++----- web/djy.Service/ISF/IsfService.cs | 21 +++++- 6 files changed, 142 insertions(+), 30 deletions(-) create mode 100644 web/Djy.Common/Const/BusinessType.cs diff --git a/web/Djy.Common/Const/BusinessType.cs b/web/Djy.Common/Const/BusinessType.cs new file mode 100644 index 0000000..cad7095 --- /dev/null +++ b/web/Djy.Common/Const/BusinessType.cs @@ -0,0 +1,23 @@ +namespace Common.Const +{ + /// + /// 大简云扣费项目代码常量 + /// + public static class BusinessType + { + /// + /// AMS申报项目代码;名称为“AMS申报” + /// + public const int AMS_REPORT = 15; + + /// + /// ISF申报代码;名称为“ISF申报” + /// + public const int ISF_REPORT = 16; + + /// + /// ISF-bond使用费代码;名称为“ISF-bond使用费” + /// + public const int ISF_BOUND = 26; + } +} diff --git a/web/Djy.Common/DJYModel/CustFee.cs b/web/Djy.Common/DJYModel/CustFee.cs index dcf4889..a23bd61 100644 --- a/web/Djy.Common/DJYModel/CustFee.cs +++ b/web/Djy.Common/DJYModel/CustFee.cs @@ -15,7 +15,8 @@ namespace Common.DJYModel /// [JsonObject(MemberSerialization.OptIn), Table(Name = "Cust_Fee", DisableSyncStructure = true)] - public partial class CustFee { + public partial class CustFee : ICloneable + { [JsonProperty, Column(DbType = "varchar(50)", IsPrimary = true, IsNullable = false)] public string GID { get; set; } = Guid.NewGuid().ToString().ToUpper(); @@ -43,10 +44,10 @@ namespace Common.DJYModel [JsonProperty, Column(DbType = "varchar(20)")] public string BSSTATUS { get; set; } - /// - /// ҵ - /// - [JsonProperty] + /// + /// ҵ + /// + [JsonProperty] public int? BSTYPE { get; set; } [JsonProperty, Column(DbType = "varchar(50)")] @@ -160,11 +161,20 @@ namespace Common.DJYModel /// [Column(IsIgnore =true)] public int IsCredit { get; set; } = 0; - /// - /// CtnrInfo - /// - /// - public int GetCtnrcount() { + + /// + /// ǰdz + /// + public object Clone() + { + return this.MemberwiseClone(); + } + + /// + /// CtnrInfo + /// + /// + public int GetCtnrcount() { var val = 0; if (CtnrInfo.IsNotNull()) { diff --git a/web/Djy.Common/Tools/EnumTools.cs b/web/Djy.Common/Tools/EnumTools.cs index fa67389..9258f6f 100644 --- a/web/Djy.Common/Tools/EnumTools.cs +++ b/web/Djy.Common/Tools/EnumTools.cs @@ -157,4 +157,28 @@ namespace Common.Tools URLExpireError = 407,//HTTP请求不合法 } + /// + /// Bond的使用类型 + /// + public enum BondOwnTypeEnum + { + /// + /// 使用自有Bond + /// + [EnumText("使用自有Bond")] + OWN = 1, + + /// + /// 使用CargoEDI的Bond + /// + [EnumText("使用CargoEDI的Bond")] + CargoEDI = 2, + + /// + /// 使用大简云的Bond + /// + [EnumText("使用大简云的Bond")] + DJY = 3 + } + } diff --git a/web/djy.IService/Djy/IFinanceService.cs b/web/djy.IService/Djy/IFinanceService.cs index 3b5784c..1149435 100644 --- a/web/djy.IService/Djy/IFinanceService.cs +++ b/web/djy.IService/Djy/IFinanceService.cs @@ -1,6 +1,7 @@ using Common; using Common.DJYModel; using Common.Entity; +using Common.Tools; using System; using System.Collections.Generic; using System.Linq; @@ -19,8 +20,9 @@ namespace djy.IService.Djy /// /// /// 1判断钱包并执行扣款生成记录 2 验证钱包金额是否充足 + /// bond是否自有;值是:1或者2或者3;1表示“自有BOND”,2表示“使用CargoEDI的BOND”,3表示“使用大简云的Bond”;当值为3时,需要额外扣除ISF-Bond使用费 /// - public ReturnResult Expend(CustFee Dto, int ExpType); + public ReturnResult Expend(CustFee Dto, int ExpType, BondOwnTypeEnum? bondOwnType); diff --git a/web/djy.Service/DjyService/FinanceService.cs b/web/djy.Service/DjyService/FinanceService.cs index 339f045..fa9aa70 100644 --- a/web/djy.Service/DjyService/FinanceService.cs +++ b/web/djy.Service/DjyService/FinanceService.cs @@ -1,7 +1,9 @@ using Common; +using Common.Const; using Common.DJYModel; using Common.Entity; using Common.Extensions; +using Common.Tools; using djy.IService.Djy; using System; using System.Collections.Generic; @@ -19,8 +21,9 @@ namespace djy.Service.DjyService /// /// /// 1验证是否可以扣款 2扣除操作 + /// bond是否自有;值是:1或者2或者3;1表示“自有BOND”,2表示“使用CargoEDI的BOND”,3表示“使用大简云的Bond”;当值为3时,需要额外扣除ISF-Bond使用费 /// - public ReturnResult Expend(CustFee Dto, int exptype) + public ReturnResult Expend(CustFee Dto, int exptype, BondOwnTypeEnum? bondOwnType = null) { _LogsAdd("Expend消费检查和扣款", "open", Dto); @@ -91,21 +94,35 @@ namespace djy.Service.DjyService rs.Not("数量不能小于1!"); return rs; } - var sql = DbBus.Get(DbList.djydb).Select().Where(w => w.BSTYPE == Dto.BSTYPE && w.SENDTYPE == Dto.SENDTYPE && w.COMID == Dto.COMID); - var price = sql.ToOne(); + decimal price_total = 0; // 总金额 + decimal price_report = 0; // ISF申报费价格 或 AMS申报费价格 + decimal price_bond = 0; // ISF-bond使用费价格 - if (price == null) + // 获取 ISF申报费价格 或 AMS申报费价格 的计费规则 + CustPrice cp1 = DbBus.Get(DbList.djydb).Select().Where(w => w.BSTYPE == Dto.BSTYPE && w.SENDTYPE == Dto.SENDTYPE && w.COMID == Dto.COMID).ToOne(); + if (cp1 == null) { rs.Not("没有找到此业务的计费规则!"); return rs; } - decimal _price = 0; + Dto.PRICE = price_report = (decimal)cp1.PRICE; + price_total += price_report; - _price = (decimal)price.PRICE; - //合计支付 - Dto.PRICE = _price; - var PayInfo = new { Total = Dto.PRICE, Price = _price, Count = Dto.CtnrCount }; + // 如果使用大简云Bond,则获取 BOND使用费单价 的计费规则 + if (bondOwnType == BondOwnTypeEnum.DJY) + { + CustPrice cp2 = DbBus.Get(DbList.djydb).Select().Where(w => w.BSTYPE == BusinessType.ISF_BOUND && w.SENDTYPE == 0 && w.COMID == Dto.COMID).ToOne(); + if (cp2 == null) + { + rs.Not("未找到BOND使用费单价,请联系大简云维护"); + return rs; + } + price_bond = (decimal)cp2.PRICE; + price_total += price_bond; + } + + var PayInfo = new { Total = price_total, Price = price_total, Count = Dto.CtnrCount }; if (exptype == 1) { DbBus.Get(DbList.djydb).Transaction(() => @@ -118,46 +135,65 @@ namespace djy.Service.DjyService throw new Exception("没有账户钱包!"); } - if (userbal.Balance < Dto.PRICE) + if (userbal.Balance < price_total) { + string log = $"总金额{price_total}(其中申报费用{price_report},ISF-bond使用费{price_bond})_财务消费expend"; if (Dto.IsCredit == 1) { - _LogsAdd("账户授信支付" + Dto.PRICE.ToString() + "_财务消费expend", Dto.BSNO, Dto); + _LogsAdd("账户授信支付," + log, Dto.BSNO, Dto); payiscredit = true; } else { - _LogsAdd("账户余额不足" + Dto.PRICE.ToString() + "_财务消费expend", Dto.BSNO, Dto); - throw new Exception("账户余额不足!" + Dto.PRICE + " " + Dto.COMNAME); + _LogsAdd("账户余额不足," + log, Dto.BSNO, Dto); + throw new Exception("账户余额不足!" + price_total + " " + Dto.COMNAME); } } - var upcount = DbBus.Get(DbList.djydb).Update().Set(a => a.Balance - Dto.PRICE) + var upcount = DbBus.Get(DbList.djydb).Update().Set(a => a.Balance - price_total) .Where(a => a.COMNAME == Dto.COMNAME).ExecuteAffrows(); //增加流水 var addcount = DbBus.Get(DbList.djydb).Insert(Dto).ExecuteAffrows(); - if (addcount < 1) { _LogsAdd("消费记录写入失败_财务消费expend", Dto.BSNO, Dto); throw new Exception("消费记录写入失败!"); } + + // 如果使用大简云Bond,增加ISF-bond使用费流水 + if (bondOwnType == BondOwnTypeEnum.DJY) + { + // 克隆 + CustFee custFeeBond = (CustFee)Dto.Clone(); + custFeeBond.GID = Guid.NewGuid().ToString(); + custFeeBond.PRICE = price_bond; + custFeeBond.BSTYPE = BusinessType.ISF_BOUND; + + var bondAddCount = DbBus.Get(DbList.djydb).Insert(custFeeBond).ExecuteAffrows(); + if (bondAddCount < 1) + { + _LogsAdd("消费记录流水(ISF-bond使用费)写入失败_财务消费expend", custFeeBond.BSNO, custFeeBond); + throw new Exception("消费记录流水(ISF-bond使用费)写入失败!"); + } + addcount += bondAddCount; + } + rs.Data = new { RunCount = addcount, PayInfo }; rs.OK("扣费成功!"); if (payiscredit) { rs.Code = 450; - rs.Message = "钱包金额不足,授信支付成功!钱包余额" + (userbal.Balance - Dto.PRICE); + rs.Message = "钱包金额不足,授信支付成功!钱包余额" + (userbal.Balance - price_total); } }); } else { - if (DbBus.Get(DbList.djydb).Select().Where(a => a.Balance >= Dto.PRICE && a.COMNAME == Dto.COMNAME).Count() > 0) + if (DbBus.Get(DbList.djydb).Select().Where(a => a.Balance >= price_total && a.COMNAME == Dto.COMNAME).Count() > 0) { rs.Data = new { PayInfo }; rs.OK("钱包金额充足"); diff --git a/web/djy.Service/ISF/IsfService.cs b/web/djy.Service/ISF/IsfService.cs index 652c908..f4c2a3d 100644 --- a/web/djy.Service/ISF/IsfService.cs +++ b/web/djy.Service/ISF/IsfService.cs @@ -353,6 +353,11 @@ namespace djy.Service.Isf if (msgType == "1" || msgType == "4") { + BondOwnTypeEnum? bondOwnType = master.BondOwnCode switch + { + "3" => BondOwnTypeEnum.DJY, + _ => null + }; ///扣费接口 var getfinrs = fin.Expend(new CustFee { @@ -365,7 +370,7 @@ namespace djy.Service.Isf BSNO = oid.ToString(), MBLNO = master.MBLNO.ToString(), } - , 0); + , 0, bondOwnType); if (!getfinrs.Status) { req.Code = 201; @@ -436,6 +441,9 @@ namespace djy.Service.Isf dic.Add("version", "1.0"); dic.Add("data", json.ToUrlEncodeString()); gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded); + + //var gethtmlTestObj = new { code = "T", msg = "成功", data = new { code = "1", msg = "成功" } }; + //gethtml = JsonConvert.SerializeObject(gethtmlTestObj); _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}:{gethtml}"); @@ -460,6 +468,10 @@ namespace djy.Service.Isf dic.Add("version", "1.0"); dic.Add("refId", oid); gethtml = await HttpHelp.Post(dic, url.PARAMVALUE, PsotType.Urlencoded); + + //var gethtmlTestObj = new { code = "T", msg = "成功", data = new { code = "1", msg = "成功" } }; + //gethtml = JsonConvert.SerializeObject(gethtmlTestObj); + _LogsAdd("SendDE", "post", $"ISF接口调用返回{oid}:{gethtml}"); } if (gethtml != null) @@ -579,6 +591,11 @@ namespace djy.Service.Isf if (msgType == "1") { + BondOwnTypeEnum? bondOwnType = master.BondOwnCode switch + { + "3" => BondOwnTypeEnum.DJY, + _ => null + }; var getfinrs = fin.Expend(new CustFee { SENDUSERID = user.GID, @@ -590,7 +607,7 @@ namespace djy.Service.Isf BSNO = oid.ToString(), MBLNO = master.MBLNO.ToString(), } - , 1); + , 1, bondOwnType); DbBus.Get(DbList.AMSCenter).Update().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "新增发送" }).Where(w => w.GID == oid).ExecuteAffrows(); } else if (msgType == "4")