Commit f6943c01 authored by liudong1993's avatar liudong1993

1

parent 7455fbb4
......@@ -956,6 +956,186 @@ and DATE_FORMAT(b.PaymentTime,'%y-%m-%d')<DATE_FORMAT('{endDate}','%y-%m-%d') A
#endregion
#region 退款批量制单
/// <summary>
/// 批量制退款单
/// </summary>
/// <returns></returns>
public static bool AutoCreateFinanceRefund() {
try
{
//先查询规则
var financeConfigurineList = financeConfigurineRepository.GetList(new RB_Finance_Configurine_Extend { Type = 1 });
//根据规则中的小程序,查询订单详情信息
if (financeConfigurineList != null && financeConfigurineList.Any())
{
foreach (var item in financeConfigurineList)
{
if (item.StartTime.HasValue && item.StartTime < System.DateTime.Now)//判断开始时间是否大于当前时间
{
//查询今天是否已经生成了财务单据
var addFinance = false;
DateTime startDate = System.DateTime.Now.AddDays(-1);
var recordModel = financeRecordRepository.GetList(new RB_Finance_Record_Extend { TenantId = item.TenantId, MallBaseId = item.MallBaseId, Type = 3 }).OrderByDescending(x => x.CreateDate).FirstOrDefault();
if (recordModel == null)//今天没生成单据
{
if (Convert.ToDateTime(item.StartTime.Value.AddDays(item.IntervalDay ?? 0).ToString("yyyy-MM-dd 00:00:00")) <= Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd 00:00:00")))//判断开始时间加上执行周期是否等于当前日期
{
startDate = item.StartTime.Value;
addFinance = true;
}
}
else
{
if (Convert.ToDateTime(recordModel.CreateDate.Value.AddDays(item.IntervalDay ?? 0).ToString("yyyy-MM-dd 00:00:00")) <= Convert.ToDateTime(System.DateTime.Now.ToString("yyyy-MM-dd 00:00:00")))//判断最近一次执行的时间加上执行周期是否等于当前日期
{
startDate = recordModel.CreateDate.Value;
addFinance = true;
}
}
DateTime endDate = startDate.AddDays(item.IntervalDay ?? 0);//结束时间
if (addFinance)//满足今天执行的条件查询间隔周期的订单
{
//查询所有的退款
var olist = goods_OrderRepository.GetOrderRefunedCreateList(item.TenantId, item.MallBaseId, startDate.ToString("yyyy-MM-dd"), endDate.ToString("yyyy-MM-dd"));
//查询所有的售后退款
goods_OrderAfterSaleRepository.GetList(new RB_Goods_OrderAfterSale_Extend() { });
OrderRefundFinanceModule(olist);
}
}
}
}
return true;
}
catch (Exception ex)
{
Helper.LogHelper.Write("AutoCreateFinanceRefund:" + ex.Message);
return false;
}
}
/// <summary>
/// 生成退款单据
/// </summary>
/// <param name="omodel"></param>
/// <returns></returns>
public static bool OrderRefundFinanceModule(List<RB_Goods_Order_Extend> oList)
{
var flag = false;
try
{
//先查询规则
var financeConfigurineList = financeConfigurineRepository.GetList(new RB_Finance_Configurine_Extend { Type = 3 });
if (financeConfigurineList != null && financeConfigurineList.Any())
{
var item = financeConfigurineList.FirstOrDefault();
RB_Finance_Record_Extend record = new RB_Finance_Record_Extend();
record.MallBaseId = item.MallBaseId;
record.TenantId = item.TenantId;
record.Type = 1;
record.CreateDate = System.DateTime.Now;
record.RecordDetailList = new List<RB_Finance_RecordDetail>();
decimal TotalMoney = 0;
var detailList = new List<object>();
foreach (var omodel in oList)
{
decimal Money = omodel.Income ?? 0;
TotalMoney += Money;
//查询用户
var umodel = member_UserRepository.GetEntity(omodel.UserId);
if (umodel == null) { return false; }
string dstr = "客人付款:" + (omodel.Income ?? 0) + "金额,退款:" + (omodel.Income ?? 0);
detailList.Add(
new
{
CostTypeId = item.RefundCostTypeId,
Number = 1,
OriginalMoney = Money,
UnitPrice = Money,
Remark = "订单号:" + omodel.OrderNo + " " + dstr
}
);
RB_Finance_RecordDetail financeRecordDetail = new RB_Finance_RecordDetail
{
ID = 0,
RecordId = 0,
Type = record.Type,
TenantId = record.TenantId,
MallBaseId = record.MallBaseId,
FinanceId = 0,
CreateDate = record.CreateDate,
Name = "",
OrderId = omodel.OrderId,
OrderDetailId = 0,
GoodsPrice = 0,
FreightMoney = 0,
Unit_Price = Money,
Number = 1
};
record.RecordDetailList.Add(financeRecordDetail);
}
item.IsPublic = 8;//默认原路退款
string Remark = System.DateTime.Now.ToString("yyyy年MM月dd日") + " 自动生成财务单据";
var financeObj = new
{
CreateBy = Config.ExpendDirector,
item.IsPublic,
ClientType = 0,
ClientID = 0,
item.CurrencyId,
WBMoney = TotalMoney,
PayDate = DateTime.Now.ToString("yyyy-MM-dd"),
RB_Branch_Id = Config.ExpendBranchId,
TemplateId = item.WorkFlowId,
OrderSource = 16,
OtherType = 14,
ReFinanceId = 0,
Remark,
detailList
};
string sign = EncryptionHelper.AesEncrypt(JsonHelper.Serialize(financeObj), Config.FinanceKey);
var resultInfo = new
{
msg = sign
};
string apiResult = Mall.Common.Plugin.HttpHelper.HttpPost(Config.PaymentFinanceApi, JsonHelper.Serialize(resultInfo), "");
JObject parmsJob = JObject.Parse(apiResult);
string resultCode = parmsJob.GetStringValue("resultCode");
int frid = parmsJob.GetInt("data", 0);
if (resultCode == "1" && frid > 0)//新增记录
{
record.FinanceId = frid;
int recordId = financeRecordRepository.Insert(record);
Helper.LogHelper.Write("财务单据ID:" + frid + ",记录id:" + recordId + "订单数量:" + record.RecordDetailList.Count());
record.RecordDetailList.ForEach(x => x.RecordId = recordId);
record.RecordDetailList.ForEach(x => x.FinanceId = frid);
flag = financeRecordDetailRepository.InsertBatch(record.RecordDetailList);
}
Helper.LogHelper.Write(apiResult);
}
}
catch (Exception ex)
{
Helper.LogHelper.Write(ex.Message);
}
return flag;
}
#endregion
#region 七天自动是否下线
public static bool AutoReleaseTheOffline()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment