Commit cfb7aaee authored by 吴春's avatar 吴春
parents 4896c7e4 b77446f4
......@@ -179,6 +179,10 @@ INNER JOIN rb_member_user mu on mu.Id=oas.UserId
{
where += $" and oas.{nameof(RB_Goods_OrderAfterSale.Type)}={dmodel.Type}";
}
if (dmodel.ReOrderStatus > 0)
{
where += $" and oas.{nameof(RB_Goods_OrderAfterSale.ReOrderStatus)}={(int)dmodel.ReOrderStatus}";
}
if (!string.IsNullOrEmpty(dmodel.ReOrderNo))
{
where += $" and oas.{nameof(RB_Goods_OrderAfterSale.ReOrderNo)} like '%{dmodel.ReOrderNo}%'";
......
......@@ -488,6 +488,22 @@ GROUP BY oc.OrderId";
return Get<RB_Goods_Order_Extend>(sql).ToList();
}
/// <summary>
/// 获取已退款 待制单的订单列表
/// </summary>
/// <param name="tenantId"></param>
/// <param name="mallBaseId"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public List<RB_Goods_Order_Extend> GetOrderRefunedCreateList(int tenantId, int mallBaseId, string startTime, string endTime)
{
string sql = $@"SELECT * FROM rb_goods_order o
WHERE o.TenantId={tenantId} and o.MallBaseId={mallBaseId} and o.OrderStatus = 7 AND o.PaymentTime IS NOT NULL AND DATE_FORMAT(o.PaymentTime,'%Y-%m-%d') <> DATE_FORMAT(o.CancelTime,'%Y-%m-%d') AND o.CancelTime>='{startTime}' AND o.CancelTime <'{endTime}'";
return Get<RB_Goods_Order_Extend>(sql).ToList();
}
#region 数据统计-数据概况
/// <summary>
/// 数据概况
......
......@@ -963,6 +963,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()
......
......@@ -181,5 +181,72 @@ namespace Test.Helper
}
}
#region 处理徐总说的二级返佣
/// <summary>
/// 返佣
/// </summary>
public static void SetOrderTwoCommissionData()
{
string citySql = $@"
SELECT o.OrderId,o.OrderNo,od.Id AS DetailId,o.UserId,u.`Name`,o.Income,o.Consignee,o.Mobile,o.ShoppingAddress,od.GoodsName,od.Specification,od.Final_Price,
od.Number,
CASE WHEN d1.Id IS NULL THEN d2.OneCommission * od.Number ELSE d1.OneCommission * od.Number END AS OneCommission,
CASE WHEN d1.Id IS NULL THEN d2.TwoCommission * od.Number ELSE d1.TwoCommission * od.Number END AS TwoCommission
FROM rb_goods_order o
INNER JOIN rb_goods_orderdetail od on o.OrderId=od.OrderId
INNER JOIN rb_member_user u on o.UserId = u.Id
LEFT JOIN rb_goods_distributioncommission d1 on d1.GoodsId=od.GoodsId AND d1.DistributorGrade=74 and d1.SpecificationSort=od.SpecificationSort
LEFT JOIN rb_goods_distributioncommission d2 on d2.GoodsId=od.GoodsId AND d2.DistributorGrade=74 and d2.SpecificationSort=''
WHERE o.OrderId in(
SELECT t.OrderId FROM(
SELECT cm.OrderId,cm.UserId FROM rb_goods_ordercommission cm WHERE CommissionState = 2 AND TenantId =1 AND MallBaseId =1
GROUP BY cm.OrderId,cm.UserId
)t GROUP BY t.OrderId HAVING COUNT(0)=1)
AND o.OrderId >=34137 and o.OrderId <=80622 and o.OrderId <> 63803 AND o.OrderId <> 63839
AND o.UserId in(
SELECT Id FROM rb_member_user WHERE SuperiorId BETWEEN 1 and 20
) AND o.UserId <> 39370
ORDER BY o.OrderId ASC ";
DataSet OrderCommList = MySqlHelper.ExecuteDataset(MySqlHelper.defaultConnection, System.Data.CommandType.Text, citySql, null);
string Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
foreach (DataRow item in OrderCommList.Tables[0].Rows)
{
int OrderId = Convert.ToInt32(item["OrderId"].ToString());
int DetailId = Convert.ToInt32(item["DetailId"].ToString());
int UserId = Convert.ToInt32(item["UserId"].ToString());
decimal TwoCommission = Convert.ToDecimal(item["TwoCommission"].ToString());
if (TwoCommission > 0)
{
//插入返佣
string InertComm = $@"
insert into rb_goods_ordercommission (OrderId,OrderDetailId,UserId,Grade,Commission,IsGoodsDistribution,CommissionState,Remark,TenantId,MallBaseId,CreateDate,UpdateDate,Type,IsRemit)
values ({OrderId},{DetailId},{UserId},2,{TwoCommission},2,2,'补充二级返佣',1,1,'{Time}','{Time}',1,2)
";
var InertCommResult = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, InertComm, null);
if (InertCommResult > 0)
{
string UserComm = $@"update rb_distributor_info set TotalCommission=TotalCommission+{TwoCommission},CommissionWithdrawal=CommissionWithdrawal+{TwoCommission}";
var UserCommResult = MySqlHelper.ExecuteNonQuery(MySqlHelper.defaultConnection, System.Data.CommandType.Text, UserComm, null);
if (UserCommResult <= 0)
{
Console.WriteLine("更新用户返佣失败 OrderId:" + OrderId + ",DetailId:" + DetailId + ",UserId:" + UserId + " TwoCommission:" + TwoCommission);
}
}
else
{
Console.WriteLine("返佣插入失败 OrderId:" + OrderId + ",DetailId:" + DetailId + ",UserId:" + UserId + " TwoCommission:" + TwoCommission);
}
}
else
{
Console.WriteLine("OrderId:" + OrderId + ",DetailId:" + DetailId + ",UserId:" + UserId + " TwoCommission:" + TwoCommission);
}
}
}
#endregion
}
}
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