|
|
|
@ -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或者3;1表示“自有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("钱包金额充足");
|
|
|
|
|