ISF增加购买Bond需求开发:增加对“ISF-bond使用费”的扣费逻辑

master
zhangxiaofeng 1 year ago
parent c122537f7b
commit 774b1973ef

@ -0,0 +1,23 @@
namespace Common.Const
{
/// <summary>
/// 大简云扣费项目代码常量
/// </summary>
public static class BusinessType
{
/// <summary>
/// AMS申报项目代码名称为“AMS申报”
/// </summary>
public const int AMS_REPORT = 15;
/// <summary>
/// ISF申报代码名称为“ISF申报”
/// </summary>
public const int ISF_REPORT = 16;
/// <summary>
/// ISF-bond使用费代码名称为“ISF-bond使用费”
/// </summary>
public const int ISF_BOUND = 26;
}
}

@ -15,7 +15,8 @@ namespace Common.DJYModel
/// </summary>
[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; }
/// <summary>
/// 业务类型
/// </summary>
[JsonProperty]
/// <summary>
/// 业务类型 见<see cref="Common.Const.BusinessType"/>
/// </summary>
[JsonProperty]
public int? BSTYPE { get; set; }
[JsonProperty, Column(DbType = "varchar(50)")]
@ -160,11 +161,20 @@ namespace Common.DJYModel
/// </summary>
[Column(IsIgnore =true)]
public int IsCredit { get; set; } = 0;
/// <summary>
/// 根据CtnrInfo计算箱量
/// </summary>
/// <returns></returns>
public int GetCtnrcount() {
/// <summary>
/// 创建当前对象的浅表副本
/// </summary>
public object Clone()
{
return this.MemberwiseClone();
}
/// <summary>
/// 根据CtnrInfo计算箱量
/// </summary>
/// <returns></returns>
public int GetCtnrcount() {
var val = 0;
if (CtnrInfo.IsNotNull()) {

@ -157,4 +157,28 @@ namespace Common.Tools
URLExpireError = 407,//HTTP请求不合法
}
/// <summary>
/// Bond的使用类型
/// </summary>
public enum BondOwnTypeEnum
{
/// <summary>
/// 使用自有Bond
/// </summary>
[EnumText("使用自有Bond")]
OWN = 1,
/// <summary>
/// 使用CargoEDI的Bond
/// </summary>
[EnumText("使用CargoEDI的Bond")]
CargoEDI = 2,
/// <summary>
/// 使用大简云的Bond
/// </summary>
[EnumText("使用大简云的Bond")]
DJY = 3
}
}

@ -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
/// </summary>
/// <param name="Dto"></param>
/// <param name="ExpType">1判断钱包并执行扣款生成记录 2 验证钱包金额是否充足</param>
/// <param name="bondOwnType">bond是否自有值是1或者2或者31表示“自有BOND”2表示“使用CargoEDI的BOND”3表示“使用大简云的Bond”当值为3时需要额外扣除ISF-Bond使用费</param>
/// <returns></returns>
public ReturnResult<object> Expend(CustFee Dto, int ExpType);
public ReturnResult<object> Expend(CustFee Dto, int ExpType, BondOwnTypeEnum? bondOwnType);

@ -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
/// </summary>
/// <param name="Dto"></param>
/// <param name="exptype">1验证是否可以扣款 2扣除操作 </param>
/// <param name="bondOwnType">bond是否自有值是1或者2或者31表示“自有BOND”2表示“使用CargoEDI的BOND”3表示“使用大简云的Bond”当值为3时需要额外扣除ISF-Bond使用费</param>
/// <returns></returns>
public ReturnResult<object> Expend(CustFee Dto, int exptype)
public ReturnResult<object> 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<CustPrice>().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<CustPrice>().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<CustPrice>().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<CustBalance>().Set(a => a.Balance - Dto.PRICE)
var upcount = DbBus.Get(DbList.djydb).Update<CustBalance>().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<CustBalance>().Where(a => a.Balance >= Dto.PRICE && a.COMNAME == Dto.COMNAME).Count() > 0)
if (DbBus.Get(DbList.djydb).Select<CustBalance>().Where(a => a.Balance >= price_total && a.COMNAME == Dto.COMNAME).Count() > 0)
{
rs.Data = new { PayInfo };
rs.OK("钱包金额充足");

@ -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<ISF_Master>().Set(w => new ISF_Master { ReportState = "已提交", NewNotice = "新增发送" }).Where(w => w.GID == oid).ExecuteAffrows();
}
else if (msgType == "4")

Loading…
Cancel
Save