AMS扣费

master
wet 2 years ago
parent 58fd91b96e
commit 14c514fa23

@ -0,0 +1,27 @@
using FreeSql.DatabaseModel;using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Newtonsoft.Json;
using FreeSql.DataAnnotations;
namespace Common.DJYModel
{
[JsonObject(MemberSerialization.OptIn), Table(Name = "Cust_Balance", DisableSyncStructure = true)]
public partial class CustBalance {
[JsonProperty, Column(DbType = "varchar(50)", IsPrimary = true, IsNullable = false)]
public string GID { get; set; } = Guid.NewGuid().ToString().ToUpper();
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal? Balance { get; set; }
[JsonProperty, Column(DbType = "varchar(50)")]
public string COMNAME { get; set; }
}
}

@ -0,0 +1,189 @@
using FreeSql.DatabaseModel;using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Newtonsoft.Json;
using FreeSql.DataAnnotations;
using Common.Extensions;
namespace Common.DJYModel
{
/// <summary>
///
/// </summary>
[JsonObject(MemberSerialization.OptIn), Table(Name = "Cust_Fee", DisableSyncStructure = true)]
public partial class CustFee {
[JsonProperty, Column(DbType = "varchar(50)", IsPrimary = true, IsNullable = false)]
public string GID { get; set; } = Guid.NewGuid().ToString().ToUpper();
[JsonProperty, Column(DbType = "varchar(5000)")]
public string BEIZHU { get; set; }
[JsonProperty, Column(DbType = "varchar(5000)")]
public string BEIZHU2 { get; set; }
/// <summary>
/// 一般是业务Gid
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string BSNO { get; set; }
/// <summary>
///业务订单编号
/// </summary>
[JsonProperty, Column(DbType = "varchar(30)")]
public string MBLNO { get; set; }
[JsonProperty, Column(DbType = "varchar(20)")]
public string BSSTATUS { get; set; }
/// <summary>
/// 业务类型
/// </summary>
[JsonProperty]
public int? BSTYPE { get; set; }
[JsonProperty, Column(DbType = "varchar(50)")]
public string CANGKU { get; set; }
[JsonProperty, Column(DbType = "varchar(30)")]
public string CARRIER { get; set; }
[JsonProperty, Column(DbType = "numeric(18,4)")]
public decimal? CBM { get; set; }
/// <summary>
/// 录入人公司ID
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string COMID { get; set; }
/// <summary>
/// 录入人公司
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string COMNAME { get; set; }
[JsonProperty, Column(InsertValueSql = "getdate()")]
public DateTime? CREATETIME { get; set; }
[JsonProperty, Column(DbType = "varchar(2000)")]
public string DESCRIPTION { get; set; }
[JsonProperty, Column(DbType = "varchar(100)")]
public string DESTINATION { get; set; }
[JsonProperty]
public DateTime? ETD { get; set; }
[JsonProperty, Column(DbType = "varchar(30)")]
public string FORWARDER { get; set; }
[JsonProperty, Column(DbType = "varchar(30)")]
public string HBLNO { get; set; }
[JsonProperty, Column(DbType = "numeric(18,4)")]
public decimal? KGS { get; set; }
[JsonProperty, Column(DbType = "varchar(20)")]
public string KINDPKGS { get; set; }
/// <summary>
/// 录入人
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string LURUREN { get; set; }
/// <summary>
/// 录入人ID
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string LURURENID { get; set; }
[JsonProperty, Column(DbType = "varchar(600)")]
public string MARKS { get; set; }
[JsonProperty, Column(DbType = "numeric(18,4)")]
public decimal? PKGS { get; set; }
[JsonProperty, Column(DbType = "varchar(100)")]
public string PORTDISCHARGE { get; set; }
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal? PRICE { get; set; }
/// <summary>
/// 发送公司
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string SENDCOM { get; set; }
[JsonProperty]
public DateTime? SENDTIME { get; set; }
[JsonProperty]
public int? SENDTYPE { get; set; }
/// <summary>
/// 发送人名
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string SENDUSER { get; set; }
/// <summary>
/// 发送人ID
/// </summary>
[JsonProperty, Column(DbType = "varchar(50)")]
public string SENDUSERID { get; set; }
[JsonProperty, Column(DbType = "varchar(60)")]
public string VESSEL { get; set; }
[JsonProperty, Column(DbType = "varchar(30)")]
public string VOYNO { get; set; }
/// <summary>
///箱量 根据 CtnrInfo计算
/// </summary>
public int CtnrCount { get; set; }
/// <summary>
///箱型箱量明细 尺寸*数量 多个逗号间隔
/// </summary>
public string CtnrInfo { get; set; }
/// <summary>
/// 是否可以信用支付 1 可以 0不允许 1的时候钱包金额不足可以负数
/// </summary>
[Column(IsIgnore =true)]
public int IsCredit { get; set; } = 0;
/// <summary>
/// 根据CtnrInfo计算箱量
/// </summary>
/// <returns></returns>
public int GetCtnrcount() {
var val = 0;
if (CtnrInfo.IsNotNull()) {
var list = CtnrInfo.Split(',').ToList();
list.ForEach(item =>
{
var it = item.Split('*');
if (it.Length == 2) {
if (it[1].Isint()) {
val += it[1].ToInt();
}
}
});
}
return val;
}
}
}

@ -0,0 +1,64 @@
using FreeSql.DatabaseModel;using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Newtonsoft.Json;
using FreeSql.DataAnnotations;
namespace Common.DJYModel
{
[JsonObject(MemberSerialization.OptIn), Table(Name = "Cust_Price", DisableSyncStructure = true)]
public partial class CustPrice {
[JsonProperty, Column(DbType = "varchar(50)", IsPrimary = true, IsNullable = false)]
public string GID { get; set; } = Guid.NewGuid().ToString().ToUpper();
[JsonProperty]
public int? BSTYPE { get; set; }
[JsonProperty, Column(DbType = "varchar(50)")]
public string COMID { get; set; }
[JsonProperty, Column(DbType = "varchar(100)")]
public string COMNAME { get; set; }
/// <summary>
/// 騰箇岱띨
/// </summary>
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal? GiftBalance { get; set; }
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal? PRICE { get; set; }
/// <summary>
/// pricef 롸데
/// </summary>
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal PRICEF { get; set; } = 0M;
/// <summary>
/// 행멍寮데
/// </summary>
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal PRICEFQG { get; set; } = 0M;
/// <summary>
/// 행멍롸데
/// </summary>
[JsonProperty, Column(DbType = "decimal(19,2)")]
public decimal PRICEQG { get; set; } = 0M;
[JsonProperty]
public int? SENDTYPE { get; set; }
[JsonProperty, Column(InsertValueSql = "getdate()")]
public DateTime? UPDATETIME { get; set; }
}
}

@ -0,0 +1,36 @@
using FreeSql.DatabaseModel;using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Newtonsoft.Json;
using FreeSql.DataAnnotations;
namespace Common.DJYModel
{
[JsonObject(MemberSerialization.OptIn), Table(Name = "Cust_Price_Detail", DisableSyncStructure = true)]
public partial class CustPriceDetail {
[JsonProperty, Column(DbType = "varchar(50)", IsPrimary = true, IsNullable = false)]
public string GID { get; set; }
[JsonProperty, Column(DbType = "varchar(50)")]
public string FORWARDER { get; set; }
[JsonProperty, Column(DbType = "varchar(50)", IsNullable = false)]
public string LINKGID { get; set; }
[JsonProperty, Column(DbType = "numeric(19,2)")]
public decimal? PRICE { get; set; } = 0M;
[JsonProperty, Column(DbType = "numeric(19,2)")]
public decimal? PRICEF { get; set; } = 0M;
[JsonProperty, Column(DbType = "varchar(200)")]
public string REMARK { get; set; }
}
}

@ -0,0 +1,27 @@
using Common.DJYModel;
using Common.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common.Djy
{
/// <summary>
/// 财务相关
/// </summary>
public interface IFinanceService : IsBase
{
/// <summary>
///消费扣费 并更新钱包 一定要指定 SENDUSERID 作为UserId标准
/// </summary>
/// <param name="Dto"></param>
/// <param name="ExpType">1判断钱包并执行扣款生成记录 2 验证钱包金额是否充足</param>
/// <returns></returns>
public ReturnResult<object> Expend(CustFee Dto, int ExpType);
}
}

@ -8,6 +8,7 @@ using Common;
using Common.Extensions;
using Common.Tools.Email;
using Common.Tools;
using Common.DJYModel;
namespace Common.DjyService
{
@ -63,8 +64,6 @@ namespace Common.DjyService
}
/// <summary>
///
/// </summary>

@ -0,0 +1,171 @@
using Common.Djy;
using Common.DJYModel;
using Common.Entity;
using Common.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Common.DjyService
{
public class FinanceService : ServBase, IFinanceService
{
/// <summary>
///
/// </summary>
/// <param name="Dto"></param>
/// <param name="exptype">1验证是否可以扣款 2扣除操作 </param>
/// <returns></returns>
public ReturnResult<object> Expend(CustFee Dto,int exptype)
{
_LogsAdd("Expend消费检查和扣款","open",Dto);
var rs = new ReturnResult<object>();
try {
if (Dto == null) {
rs.Not("错误的null请求");
return rs;
}
if (Dto.BSNO.IsNull()) {
rs.Not("业务编号不能BSNO为空");
return rs;
}
if (Dto.MBLNO.IsNull()) {
rs.Not("主提单号不能为空!");
return rs;
}
if (Dto.BSTYPE == null || Dto.SENDTYPE == null) {
rs.Not("请求的业务类型和发送类型不能为空!");
return rs;
}
if (Dto.SENDUSERID.IsNotNull())
{
var userinfo = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == Dto.SENDUSERID).ToOne();
if (userinfo != null) {
Dto.SENDUSER = Dto.SENDUSER.IsNull()?userinfo.SHOWNAME : Dto.SENDUSER;
Dto.SENDUSERID = userinfo.GID;
Dto.SENDCOM = Dto.SENDCOM .IsNull() ?userinfo.COMNAME: Dto.SENDCOM;
}
}
if (Dto.LURURENID.IsNotNull()) {
var luser = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == Dto.LURURENID).ToOne();
if (luser != null) {
Dto.LURUREN = luser.SHOWNAME;
Dto.LURURENID = luser.GID;
Dto.COMNAME = luser.COMNAME;
Dto.COMID = luser.CompId;
}
}
Dto.GID = Guid.NewGuid().ToString();
Dto.SENDTIME = DateTime.Now;
Dto.CREATETIME = DateTime.Now;
if (Dto.CtnrCount == 0)
{//如果没有指定数量则根据 箱型箱量计算数量
Dto.CtnrCount = Dto.GetCtnrcount();
}
if (Dto.CtnrCount <= 0) {
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();
if (price == null) {
rs.Not("没有找到此业务的计费规则!");
return rs;
}
decimal _price = 0;
_price = (decimal)price.PRICE;
//合计支付
Dto.PRICE = _price* Dto.CtnrCount;
var PayInfo = new { Total = Dto.PRICE, Price = _price, Count = Dto.CtnrCount };
if (exptype == 1)
{
DbBus.Get(DbList.djydb).Transaction(() =>
{ //执行事务提交
//执行扣款
var payiscredit = false;
var userbal = DbBus.Get(DbList.djydb).Select<CustBalance>().Where(w => w.COMNAME == Dto.COMNAME).ToOne();
if (userbal == null)
{
throw new Exception("没有账户钱包!");
}
if (userbal.Balance < Dto.PRICE)
{
if (Dto.IsCredit == 1)
{
_LogsAdd("账户授信支付" + Dto.PRICE.ToString() + "_财务消费expend", Dto.BSNO, Dto);
payiscredit=true;
}
else
{
_LogsAdd("账户余额不足" + Dto.PRICE.ToString() + "_财务消费expend", Dto.BSNO, Dto);
throw new Exception("账户余额不足!" + Dto.PRICE + " " + Dto.COMNAME);
}
}
var upcount = DbBus.Get(DbList.djydb).Update<CustBalance>().Set(a => a.Balance - Dto.PRICE)
.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("消费记录写入失败!");
}
rs.Data = new{RunCount=addcount ,PayInfo};
rs.OK("扣费成功!");
if (payiscredit)
{
rs.Code = 450;
rs.Message = "钱包金额不足,授信支付成功!钱包余额"+(userbal.Balance-Dto.PRICE);
}
});
}
else {
if (DbBus.Get(DbList.djydb).Select<CustBalance>().Where(a => a.Balance >= Dto.PRICE && a.COMNAME == Dto.COMNAME).Count() > 0)
{
rs.Data = new {PayInfo };
rs.OK("钱包金额充足");
}
else {
rs.Data = new { PayInfo };
rs.Not("钱包金额不足");
}
}
}
catch(Exception ex)
{
rs.Not(ex.Message);
}
//rs.MemoData = Dto;
return rs;
}
}
}

@ -55,6 +55,6 @@ namespace djy.Paas.IService
Task<Response> SendDE(string Gid, string userid, string docType);
Response SaveReceipt(AMSReturnDto retdto);
Response SaveReceipt(AMSReturnDto retdto,string Key);
}
}

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace djy.Model.AmsDto
{
public class AMSReturnDto
{
public string businessId { get; set; }
public string content { get; set; }
public string status { get; set; }
}
}

@ -345,20 +345,52 @@ namespace djy.Service.Ams
/// <param name="docType"></param>
public async Task<Response> SendDE(string Gid, string userid,string docType)
{
Response req = new Response();
try
{
string[] id = Gid.Split(',');
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
foreach (string oid in id)
{
if (oid != "")
{
var docContent = "";
var user = DbBus.Get(DbList.djydb).Select<User>().Where(w => w.GID == userid).ToOne();
var fin = new FinanceService();
var master = DbBus.Get(DbList.AMSCenter).Select<AMS_Master>().Where(x => (x.IsDel == false || x.IsDel == null) && x.CompID == user.CompId && x.GID == oid).ToOne();
if (docType!= "AMSD") {
if (docType != "AMSD")
{
#region docContent 新增 重发 修改
if (docType == "AMSAR" && !(master.ReportState == "已删除" || master.MateState == "匹配失败"))
{
req.Code = 200;
req.Message = "当前状态不能重发!如有疑问,请联系相关客服!";
return req;
}
if (docType == "AMSAR"||docType== "AMSDOC")
{
var getfinrs = fin.Expend(new CustFee
{
SENDUSERID = userid,
LURURENID = userid,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 0);
if (!getfinrs.Status) {
req.Code = 200;
req.Message = getfinrs.Message;
return req;
}
}
var cARRIERIDList = DbBus.Get(DbList.Common).Select<MappingCarrier>().Where(map => map.Module == "AMS").ToList();
var portList = DbBus.Get(DbList.Common).Select<CodePort>().ToList();
var containerTypeList = DbBus.Get(DbList.Common).Select<MappingCtn>().Where(map => map.Module == "AMS").ToList();
@ -457,7 +489,6 @@ namespace djy.Service.Ams
req.Code = 200;
req.Message = "已删除单据不可以再次删除";
return req;
}
AMSDDto aMSDDto = new AMSDDto();
aMSDDto.fromdea = "n";
@ -562,10 +593,34 @@ namespace djy.Service.Ams
if (docType == "AMSDOC")
{
var getfinrs = fin.Expend(new CustFee
{
SENDUSERID = userid,
LURURENID = userid,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 1);
DbBus.Get(DbList.AMSCenter).Update<AMS_Master>().Set(w => new AMS_Master { ReportState = "已申报", NewNotice="新增发送成功"}).Where(w => w.GID == oid).ExecuteAffrows();
}
else if (docType == "AMSAR")
{
var getfinrs = fin.Expend(new CustFee
{
SENDUSERID = userid,
LURURENID = userid,
CtnrCount = 1,
CtnrInfo = string.Empty,
BSTYPE = 15,
SENDTYPE = 0,
BSNO = oid.ToString(),
MBLNO = master.MBLNO.ToString(),
}
, 1);
DbBus.Get(DbList.AMSCenter).Update<AMS_Master>().Set(w => new AMS_Master { ReportState = "已申报", NewNotice = "重发成功"}).Where(w => w.GID == oid).ExecuteAffrows();
}
@ -580,9 +635,6 @@ namespace djy.Service.Ams
}
}
}
#endregion
@ -593,7 +645,6 @@ namespace djy.Service.Ams
req.Code = 200;
req.Message = "操作成功";
return req;
}
catch (Exception ex)
{
@ -609,11 +660,14 @@ namespace djy.Service.Ams
public Response SaveReceipt(AMSReturnDto retdto)
public Response SaveReceipt(AMSReturnDto retdto,string Key)
{
Response req = new Response();
try
{
_LogsAdd("SaveReceipt", "post", $"AMS接口推送{JsonConvert.SerializeObject(retdto)}");
return req;

@ -262,7 +262,7 @@ namespace djy_AmsApi.Controllers
[HttpPost("Receipt")]
public Response SaveReceipt(AMSReturnDto retdto,string Key=null)
{
return ser.SaveReceipt(retdto);
return ser.SaveReceipt(retdto,Key);
}
#endregion

Loading…
Cancel
Save