2986 lines
178 KiB
C#
2986 lines
178 KiB
C#
using CRM.Core.BLL.Wx;
|
||
using CRM.Core.DAL;
|
||
using CRM.Core.Model;
|
||
using CRM.Core.Model.EntityAudit;
|
||
using MySql.Data.MySqlClient;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Diagnostics;
|
||
using System.Linq;
|
||
using WX.CRM.Common;
|
||
|
||
namespace CRM.Core.BLL.TransOrder
|
||
{
|
||
public class GenModule_Price
|
||
{
|
||
private static NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
|
||
|
||
/// <summary>
|
||
/// 开始时间
|
||
/// </summary>
|
||
public static DateTime starttime = new DateTime(2022, 5, 1);
|
||
|
||
/// <summary>
|
||
/// 结束时间
|
||
/// </summary>
|
||
public static DateTime endtime = new DateTime(2022, 6, 1);
|
||
|
||
public void Init_GenModule(DateTime startTime, DateTime endTime)
|
||
{
|
||
Stopwatch stopwatch = new Stopwatch();
|
||
stopwatch.Start();
|
||
try
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
param.Add(new MySqlParameter { ParameterName = "@v_starttime", DbType = DbType.DateTime, Value = startTime });
|
||
param.Add(new MySqlParameter { ParameterName = "@v_endtime", DbType = DbType.DateTime, Value = endTime });
|
||
Logger.Info(string.Format("module_order数据初始化,调用过程proc_module_pull,参数{0},{1}", startTime, endTime));
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.StoredProcedure, "proc_module_pull", param.ToArray());//初始化module_order表数据
|
||
stopwatch.Stop();
|
||
Logger.Info(string.Format("module_order数据初始化结束,耗时{0}ms", stopwatch.ElapsedMilliseconds));
|
||
|
||
stopwatch.Start();
|
||
Logger.Info(string.Format("proc_Order_pull数据初始化,proc_Order_pull,参数{0},{1}", startTime, endTime));
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.StoredProcedure, "proc_Order_pull", param.ToArray());//初始化module_order表数据
|
||
stopwatch.Stop();
|
||
Logger.Info(string.Format("proc_Order_pull数据初始化结束,耗时{0}ms", stopwatch.ElapsedMilliseconds));
|
||
|
||
stopwatch.Start();
|
||
Logger.Info(string.Format("GenModule_Price数据初始化,GenModule_Price,参数{0},{1}", startTime, endTime));
|
||
|
||
GenModule_PriceWorker(startTime, endTime);
|
||
stopwatch.Stop();
|
||
Logger.Info(string.Format("genModule_Price数据初始化结束,耗时{0}ms", stopwatch.ElapsedMilliseconds));
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Logger.Error(ex, "数据执行失败");
|
||
}
|
||
}
|
||
|
||
public void GenModule_PriceWorker(DateTime Starttime, DateTime Endtime)
|
||
{
|
||
try
|
||
{
|
||
starttime = Starttime;
|
||
endtime = Endtime;
|
||
|
||
#region 第二版
|
||
|
||
Stopwatch stopwatch = new Stopwatch();
|
||
stopwatch.Start();
|
||
InitChangeSomeOrder();
|
||
//初始化wx_szzyorder_handle
|
||
Initwx_szzyorder_handle();
|
||
Initwx_szzyorderrefund_MorePay();
|
||
|
||
//MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "delete from module_price where otime2>='" + starttime.ToString("yyyy-MM-dd") + "';");//清空中间表数据
|
||
Dictionary<string, List<module_Price_Group>> dic = GetModule_Price();//取module_price的group by 数据,作为之前的数据判断
|
||
|
||
MainOrd(dic);//订单定性(第一版)
|
||
|
||
//删除平台1已存在数据
|
||
DelPt1Order();
|
||
|
||
MainTime(dic);//订单时间计算(第一版)
|
||
|
||
#endregion 第二版
|
||
|
||
MainModle();//订单模块计算(第二版)
|
||
|
||
ModulePriceJiSuan();//计算金额 和天数(第二版)
|
||
|
||
DingJinClear();//计算 苹果、魅族、华为平台支付扣除 手续费后金额(第二版)
|
||
|
||
//XinMeiti2_PriceJisuan();//新媒体二数据(第二版)(废弃,采用XinMeiti2_ShengCheng版本)
|
||
|
||
//Upgrade_JiSuan2();//软件 补差升级计算(放弃)
|
||
XinMeiti2_ShengCheng();
|
||
|
||
XinMeiTi3();
|
||
|
||
//删除平台1数据
|
||
// Delpt1Data();
|
||
|
||
|
||
//补充wx_szzyorderpay_ext 和wx_szzyordermodulerefund数据
|
||
pullpayext();
|
||
|
||
//更新平台一ModulId
|
||
UpdatePt1ModulId();
|
||
|
||
//更新moduleprice的赠送单的主订单号。
|
||
updateOrderid_handlegift();
|
||
|
||
Logger.Info("全部执行ok=================");
|
||
stopwatch.Stop();
|
||
Logger.Info(string.Format("总耗时:{0}毫秒", stopwatch.ElapsedMilliseconds));
|
||
Console.ReadLine();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Logger.Error(ex, "数据执行失败");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新媒体二,从梁敏龙那里取数据过去
|
||
/// </summary>
|
||
public static void XinMeiti2_ShengCheng()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
//清理掉新媒体二的数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"delete from module_price where otime2>='" + starttime.ToString("yyyy-MM-dd") + "' and otime2<'" + endtime.ToString("yyyy-MM-dd") + "' and channel>=26800 and channel<=26899;", param.ToArray());
|
||
|
||
//插入主单数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"INSERT INTO module_price
|
||
(`orderid`, `szzyorderid`, `moduleid`, `starttime2`, `endtime2`, `otime2`, `ctime2`, `orderPrice`, `modulePrice`,
|
||
`midproductid`, `username`, `opendays2`, `isBu`, `isoneday`, `channel`, `modulePrice2`, `isVirOrder`, `isRunRefundIns`)
|
||
select t.orderid,x.szzyorderid,CONCAT(t.moduleid,'_',b.teachercard),t.begintime,t.endtime,x.otime,x.ctime,x.arrivalpay,x.arrivalpay,
|
||
t.moduleid,t.softusername,t.opendays,1,0,x.channel,null,0,20 from xinmeiti2_module_price t
|
||
left join wx_szzyorder x on x.orderid=t.orderid
|
||
left join order_teacher b on b.orderid=t.orderid
|
||
where x.otime>='" + starttime.ToString("yyyy-MM-dd") + "' and x.otime<'" + endtime.ToString("yyyy-MM-dd") + "';", param.ToArray());
|
||
//插入赠送订单数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"INSERT INTO module_price
|
||
(`orderid`, `szzyorderid`, `moduleid`, `starttime2`, `endtime2`, `otime2`, `ctime2`, `orderPrice`, `modulePrice`,
|
||
`midproductid`, `username`, `opendays2`, `isBu`, `isoneday`, `channel`, `modulePrice2`, `isVirOrder`, `isRunRefundIns`)
|
||
select x.mainorderid,t.orderid,CONCAT(t.moduleid,'_',b.teachercard),t.begintime,t.endtime,x.otime,x.ctime,0,0,
|
||
t.moduleid,t.softusername,t.opendays,1,0,x.channel,null,0,20 from xinmeiti2_module_price t
|
||
left join wx_szzyorder_handgift x on x.orderid=t.orderid
|
||
left join order_teacher b on b.orderid=t.orderid
|
||
where x.otime>='" + starttime.ToString("yyyy-MM-dd") + "' and x.otime<'" + endtime.ToString("yyyy-MM-dd") + "';", param.ToArray());
|
||
|
||
//修改开始时间
|
||
var sql = "update module_price t set t.starttime2=(select begintime from xinmeiti2_module_price x where x.orderid=t.orderid and x.begintime>='" + starttime.ToString("yyyy-MM-dd") + "') where exists(select 1 from xinmeiti2_module_price x where x.orderid=t.orderid and x.begintime>='" + starttime.ToString("yyyy-MM-dd") + "' );";
|
||
Logger.Info(sql);
|
||
var i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"新媒体2更新 module_price 开始时间{i}行");
|
||
|
||
//修改结束时间
|
||
sql = "update module_price t set t.endtime2=(select endtime from xinmeiti2_module_price x where x.orderid=t.orderid and x.endtime>='" + starttime.ToString("yyyy-MM-dd") + "') where exists(select 1 from xinmeiti2_module_price x where x.orderid=t.orderid and x.endtime>='" + starttime.ToString("yyyy-MM-dd") + "')";
|
||
Logger.Info(sql);
|
||
i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"新媒体2更新 module_price 结束时间{i}行");
|
||
|
||
Logger.Info("新媒体二执行完成");
|
||
}
|
||
|
||
public static void InitChangeSomeOrder()
|
||
{
|
||
Logger.Info("预调整数据");
|
||
//调整2980到平台一
|
||
var param = new List<MySqlParameter> { };
|
||
var sql = "update wx_szzyorderpay set channel='26001' where orderid in(80345087, 80362833, 80363995, 80364005, 80364010, 80364027, 80364041, 80364100, 80364114, 80364128, 80364330, 80364669, 80364676, 80364700, 80364713, 80364852, 80364993, 80365037, 80365136, 80365934, 80366509);";
|
||
var i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
Logger.Info(string.Format("update wx_szzyorderpay 影响{0}行", i));
|
||
sql = "update wx_szzyorderrefund set channel='26001' where orderid in(80345087, 80362833, 80363995, 80364005, 80364010, 80364027, 80364041, 80364100, 80364114, 80364128, 80364330, 80364669, 80364676, 80364700, 80364713, 80364852, 80364993, 80365037, 80365136, 80365934, 80366509);";
|
||
i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
Logger.Info(string.Format("update wx_szzyorderrefund 影响{0}行", i));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 新媒体三 首华update opendays
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static void XinMeiTi3()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
//清理掉新媒体三的数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"delete from module_price where otime2>='" + starttime.ToString("yyyy-MM-dd") + "' and otime2<'" + endtime.ToString("yyyy-MM-dd") + "' and channel>=27100 and channel<=27199;", param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"INSERT INTO module_price
|
||
(`orderid`, `szzyorderid`, `moduleid`, `starttime2`, `endtime2`, `otime2`, `ctime2`, `orderPrice`, `modulePrice`,
|
||
`midproductid`, `username`, `opendays2`, `isBu`, `isoneday`, `channel`, `modulePrice2`, `isVirOrder`, `isRunRefundIns`)
|
||
SELECT x.orderid,x.szzyorderid,x.module_id,x.starttime3,x.endtime3,x.otime,x.ctime,x.orderprice,x.arrivalpay,x.midproductid,x.softusername,x.opendays,1,0,'27100' as channel,null,x.isVirOrder, 20 From xinmeiti3 x
|
||
where x.otime>='" + starttime.ToString("yyyy-MM-dd") + "' and x.otime<'" + endtime.ToString("yyyy-MM-dd") + "';", param.ToArray());
|
||
//修改开始时间
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price t set t.starttime2=(select starttime3 from xinmeiti3 x where x.szzyorderid=t.szzyorderid and t.moduleid=x.module_id and x.starttime3>='" + starttime.ToString("yyyy-MM-dd") + "') where exists(select 1 from xinmeiti3 x where x.szzyorderid=t.szzyorderid and t.moduleid=x.module_id and x.starttime3>='" + starttime.ToString("yyyy-MM-dd") + @"' );", param.ToArray());
|
||
|
||
//修改结束时间
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price t set t.endtime2=(select endtime3 from xinmeiti3 x where x.szzyorderid=t.szzyorderid and t.moduleid=x.module_id and x.endtime3>='" + starttime.ToString("yyyy-MM-dd") + "') where exists(select 1 from xinmeiti3 x where x.szzyorderid=t.szzyorderid and t.moduleid=x.module_id and x.endtime3>='" + starttime.ToString("yyyy-MM-dd") + @"')", param.ToArray());
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"UPDATE module_price set isoneday=1 where orderid in (80208717,80246786,80247162,80247650)", param.ToArray());
|
||
|
||
Logger.Info("新媒体三执行完成");
|
||
}
|
||
|
||
public static Dictionary<string, List<module_Price_Group>> GetModule_Price()
|
||
{
|
||
string sql = @"select CONVERT((
|
||
case when t.channel>=25000 and t.channel<=26199 then
|
||
t.szzyorderid
|
||
else
|
||
t.orderid
|
||
end), DECIMAL)
|
||
orderid
|
||
,t.szzyorderid,max(t.starttime2) starttime2,max(t.endtime2) endtime2,max(t.otime2) otime2,max(t.midproductid) midproductid,
|
||
t.username,max(t.opendays2)opendays2,max(t.channel)channel,max(x.teacher)teacher from module_price t
|
||
left join Order_Teacher x on x.orderid=t.orderid
|
||
where t.otime2<'" + starttime.ToString("yyyy-MM-dd") + "' " + //是否就不用在查询之前删除
|
||
"group by t.orderid,t.szzyorderid,t.username order by t.otime2;";
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
List<module_Price_Group> list = dataSet.Tables[0].ToList<module_Price_Group>();
|
||
|
||
Dictionary<string, List<module_Price_Group>> dic = new Dictionary<string, List<module_Price_Group>>();
|
||
foreach (var item in list)
|
||
{
|
||
if (!dic.ContainsKey(item.username))
|
||
{
|
||
dic.Add(item.username, new List<module_Price_Group>() { item });
|
||
}
|
||
else
|
||
{
|
||
dic[item.username].Add(item);
|
||
}
|
||
}
|
||
return dic;
|
||
}
|
||
|
||
public static void Initwx_szzyorder_handle()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
//初始化wx_szzyorder_handle
|
||
//已在存储过程处理更新
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"truncate table wx_szzyorder_handle;", param.ToArray());
|
||
//MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into wx_szzyorder_handle select * from wx_szzyorder;", param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update wx_szzyorder_handle h
|
||
LEFT JOIN (
|
||
select x.orderid from wx_szzyorder t
|
||
join wx_szzyorderrefund x on x.orderid=t.orderid
|
||
where x.auditstatus=1 and t.orderstatus<>90
|
||
group by x.orderid
|
||
having (sum(x.refundprice)/max(t.arrivalpay))>0.3
|
||
) a on a.orderid=h.orderid
|
||
set h.orderstatus=90
|
||
where a.orderid is not null ", param.ToArray());
|
||
Logger.Info("Initwx_szzyorder_handle执行完成");
|
||
}
|
||
|
||
public static void Initwx_szzyorderrefund_MorePay()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
//初始化wx_szzyorder_handle
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update wx_szzyorderrefund set ismorepay=0;", param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update wx_szzyorderrefund xaa set xaa.ismorepay=1 where id in
|
||
(
|
||
select bbb.id from
|
||
(
|
||
select aa.arrivalpay,aa.needpay,x.* from wx_szzyorderrefund x
|
||
left join wx_szzyorder aa on aa.orderid=x.orderid
|
||
where x.orderid in
|
||
(
|
||
select t.orderid from wx_szzyorder t
|
||
where t.arrivalpay<>t.needpay
|
||
and t.arrivalpay>0
|
||
and t.otime is not null
|
||
) and x.auditstatus=1
|
||
and x.auditstatus=1
|
||
)bbb where (bbb.arrivalpay-bbb.needpay)=bbb.refundprice
|
||
) and xaa.refunddate<'2022-01-01';", param.ToArray());
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update wx_szzyorderrefund xaa set xaa.ismorepay=1 where orderid
|
||
in(
|
||
select bxx.orderid from (
|
||
select bbb.orderid,(max(bbb.arrivalpay)-max(bbb.needpay))chae,sum(bbb.refundprice)refundprice from
|
||
(
|
||
select aa.arrivalpay,aa.needpay,x.* from wx_szzyorderrefund x
|
||
left join wx_szzyorder aa on aa.orderid=x.orderid
|
||
where x.orderid in
|
||
(
|
||
select t.orderid from wx_szzyorder t
|
||
where t.arrivalpay<>t.needpay
|
||
and t.arrivalpay>0
|
||
and t.otime is not null
|
||
) and x.auditstatus=1
|
||
and x.auditstatus=1
|
||
and x.refunddate>'2022-01-01'
|
||
)bbb
|
||
group by bbb.orderid
|
||
)bxx where bxx.chae=bxx.refundprice
|
||
) and xaa.refunddate>='2022-01-01'
|
||
;", param.ToArray());
|
||
Logger.Info("Initwx_szzyorder_handle执行完成");
|
||
}
|
||
|
||
public static void Delpt1Data()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
//删除平台一数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"DELETE from module_price where channel BETWEEN 25000 and 26199;", param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"DELETE From wx_szzyorderpay_ext where channel BETWEEN 25000 and 26199;", param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"DELETE from wx_szzyordermodulerefund where channel BETWEEN 25000 and 26199;", param.ToArray());
|
||
|
||
Logger.Info("删除平台一数据执行完成");
|
||
}
|
||
|
||
public static void DelPt1Order()
|
||
{
|
||
var now = DateTime.Now;
|
||
var monone = new DateTime(now.Year, now.Month, 1);
|
||
if (starttime >= monone)
|
||
{
|
||
var sql = "DELETE From wx_szzyorder_redefine where orderid in (SELECT szzyorderid from (SELECT szzyorderid From module_price t where t.channel >= 25000 and t.channel <= 26199 and otime2<'" + starttime.ToString("yyyy-MM-dd") + "') as t)";
|
||
var i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"删除平台一 wx_szzyorder_redefine已存在数据{i}行");
|
||
}
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 更新平台1moduleId
|
||
/// </summary>
|
||
public static void UpdatePt1ModulId()
|
||
{
|
||
//var dic= price_dic.Values
|
||
var sql = "DELETE From module_price where channel>=25000 and channel<=26199 and otime2>='" + starttime.ToString("yyyy-MM-dd") + "' and orderid in ( SELECT orderid from (SELECT orderid From module_price t where t.channel >= 25000 and t.channel <= 26199 and otime2<'" + starttime.ToString("yyyy-MM-dd") + "' and orderid = szzyorderid) as t);";
|
||
var i= MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"删除平台一 module_price:{i}行");
|
||
|
||
var updatesql = "update wx_szzyordermodulerefund r LEFT JOIN module_price p on p.channel >= 25000 and p.channel <= 26199 and p.szzyorderid = r.orderid set r.orderid = p.orderid where r.refunddate >= '" + starttime.ToString("yyyy-MM-dd") + "' and r.channel >= 25000 and r.channel <= 26199 and p.orderid is not null; ";
|
||
i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, updatesql);
|
||
Logger.Info($"更新平台一 wx_szzyordermodulerefund:{i}行");
|
||
|
||
sql = "delete from wx_order_payclear where channel >= 25000 and channel <= 26199 and usedate<'" + starttime.ToString("yyyy-MM-dd") + "';";
|
||
i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"删除平台一 wx_order_payclear:{i}行");
|
||
|
||
sql = "insert into wx_order_payclear( payid, orderid, payprice, paydate, usedate, usestatus, usetype, useprice, useprice2, channel ) " +
|
||
"SELECT payid, orderid, payprice, paydate, usedate, usestatus, usetype, useprice, useprice2, channel FROM zxdcrm_audit_pt1.wx_order_payclear AS x where usedate < '" + starttime.ToString("yyyy-MM-dd") + "'; ";
|
||
i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"平台一插入 wx_order_payclear:{i}行");
|
||
|
||
sql = "DELETE From wx_order_payclear where channel>=25000 and channel<=26199 and usedate>='" + starttime.ToString("yyyy-MM-dd") + "' and orderid in ( SELECT orderid from (SELECT orderid From module_price t where t.channel >= 25000 and t.channel <= 26199 and otime2<'" + starttime.ToString("yyyy-MM-dd") + "' and orderid = szzyorderid) as t);";
|
||
i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"删除平台一插入 wx_order_payclear:{i}行");
|
||
|
||
Logger.Info("平台一数据处理完成");
|
||
}
|
||
|
||
public static void pullpayext()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
var sql = "DELETE From wx_szzyorderpay_ext where otime>= '" + starttime.ToString("yyyy-MM-dd") + "' and otime<'" + endtime.ToString("yyyy-MM-dd") + "'";
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into wx_szzyorderpay_ext
|
||
select o.orderid,o.arrivalpay,o.arrivalpay,0 costprice,o.arrivaltime paytime, o.channel,0 rate, 0 overpayprice,null realpayprice,o.otime
|
||
from wx_szzyorder o
|
||
where (
|
||
(o.orderstatus in(200,220,205,80,90) and o.otime is not null and o.otime < '" + endtime.ToString("yyyy-MM-dd") + "') ) " +
|
||
"and not exists(select 1 from wx_szzyorderpay_ext e where o.orderid = e.orderid);", param.ToArray());
|
||
|
||
var sqldelete = "DELETE From wx_szzyordermodulerefund where refunddate>= '" + starttime.ToString("yyyy-MM-dd") + "' and refunddate<'" + endtime.ToString("yyyy-MM-dd") + "'";
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sqldelete);
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"INSERT INTO `wx_szzyordermodulerefund`(`id`, `orderid`, `channel`, `refunddate`, `refundprice`, `refundtype`, `refundpercentage`, `account`, `username`, `midproductid`, `moduleid`, `szzyorderid`, `ismorepay`, `starttime2`, `endtime2`, `usedays`, `opendays2`, `price2`, `ctime2`, `otime2`, `arrivalpay`, `json_szzy_order_id`, `restday`, `module_openday`, `module_arrivalpay`, `module_refundprice`, `is_order`, `isoneday`, `module_refundprice_bk`, `is_deduction`)
|
||
select `id`, f.`orderid`, f.channel, f.audittime, `refundprice`, `refundtype`,1, `account`, o.softusername,null,null, f.orderid,f.ismorepay,null,null,0,0,0,null,f.audittime,0,null,0,0,0,0,0,0,0,0
|
||
from wx_szzyorderrefund f
|
||
join (select * from wx_szzyorder o where o.orderstatus in(220,205,80,90) and o.otime is not null and o.otime < '" + endtime.ToString("yyyy-MM-dd") + "' )o on f.orderid = o.orderid " +
|
||
"where f.auditstatus = 1 and f.audittime < '" + endtime.ToString("yyyy-MM-dd") + "' and not exists(select 1 from wx_szzyordermodulerefund f2 where f2.id = f.id)", param.ToArray());
|
||
|
||
//解决多付数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update wx_szzyorderpay_ext e set e.overpayprice = (
|
||
select sum(f.refundprice) refundprice from wx_szzyorderrefund f where f.ismorepay = 1 and e.orderid = f.orderid GROUP BY f.orderid
|
||
)
|
||
where exists(select 1 from wx_szzyorderrefund f where f.ismorepay = 1 and e.orderid = f.orderid GROUP BY f.orderid);", param.ToArray());
|
||
|
||
Logger.Info("pullpayext执行完成");
|
||
}
|
||
|
||
public static void updateOrderid_handlegift()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
var i = MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"UPDATE module_price p set p.orderid =( SELECT h.mainorderid from wx_szzyorder_handgift h where h.szzyorderid=p.szzyorderid and p.orderid!=h.mainorderid )
|
||
where EXISTS (SELECT h.mainorderid from wx_szzyorder_handgift h where h.szzyorderid=p.szzyorderid and p.orderid!=h.mainorderid)", param.ToArray());
|
||
|
||
Logger.Info(string.Format(" 更新moduleprice的赠送单的主订单号执行完成,影响{0}行", i));
|
||
}
|
||
|
||
/// <summary>
|
||
/// 第一版
|
||
/// </summary>
|
||
|
||
/// <param name="price_dic"></param>
|
||
private static void MainOrd(Dictionary<string, List<module_Price_Group>> price_dic)
|
||
{
|
||
Logger.Info("开始订单性质计算:");
|
||
var param = new List<MySqlParameter> { };
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"truncate table wx_szzyorder_redefine", param.ToArray());
|
||
WX_SzzyOrder_Redefine_BL bll = new WX_SzzyOrder_Redefine_BL();
|
||
using (AuditContext db = new AuditContext())
|
||
|
||
{
|
||
//string username = "dn0025327";
|
||
string[] orderstats = { "220", "205", "80", "90" };
|
||
var openord = from a in db.Wx_Szzyorder_Handle
|
||
join b in db.WX_SZZYORDER on a.ORDERID equals b.ORDERID
|
||
where b.OTIME != null
|
||
where orderstats.Contains(b.ORDERSTATUS)
|
||
where b.OTIME < endtime
|
||
where b.OTIME >= starttime
|
||
// where (b.CHANNEL < 25000 || b.CHANNEL > 26199)//排除掉平台一数据
|
||
//where a.SOFTUSERNAME == username
|
||
select a
|
||
;//有开通时间,表示已经开通了
|
||
|
||
var ordList22 = (from b in openord
|
||
join x in db.WX_SZZYORDER on b.ORDERID equals x.ORDERID
|
||
join c in db.WX_SZZYSUBPRODUCT on b.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
join userGroup in db.Order_Teacher on b.ORDERID equals userGroup.orderid into jiontemp
|
||
from userGroup in jiontemp.DefaultIfEmpty()//左关联(用户组/部门 关系表)
|
||
//join d in db.WX_SzzyOrderRefund on b.ORDERID equals d.orderid
|
||
//where b.ORDERSTATUS == "90"
|
||
//where d.auditstatus == 1
|
||
//where b.SOFTUSERNAME == "dn0024986"
|
||
select new NewOrd()
|
||
{
|
||
ord = b,
|
||
midproduct = c.MidProductId.Value,
|
||
teacher = userGroup.teacher,
|
||
old_otime = x.OTIME
|
||
}).OrderBy(m => m.old_otime).ToList();
|
||
Logger.Info("总订单数:" + ordList22.Count());
|
||
|
||
Dictionary<string, List<NewOrd>> dic = new Dictionary<string, List<NewOrd>>();
|
||
Dictionary<string, int> softOrdCount = new Dictionary<string, int>();
|
||
foreach (var item in ordList22)
|
||
{
|
||
if (!dic.ContainsKey(item.ord.SOFTUSERNAME))
|
||
{
|
||
item.xuhao = 1;
|
||
dic.Add(item.ord.SOFTUSERNAME, new List<NewOrd>() { item });
|
||
softOrdCount.Add(item.ord.SOFTUSERNAME, 1);
|
||
}
|
||
else
|
||
{
|
||
softOrdCount[item.ord.SOFTUSERNAME] = softOrdCount[item.ord.SOFTUSERNAME] + 1;
|
||
item.xuhao = softOrdCount[item.ord.SOFTUSERNAME];
|
||
dic[item.ord.SOFTUSERNAME].Add(item);
|
||
}
|
||
}
|
||
|
||
//var softuserlist = ordList22.GroupBy(m => m.ord.SOFTUSERNAME).Select(m => m.Key).ToList();
|
||
// Logger.Info("订单客户数:" + dic.Count());
|
||
var product = db.WX_SZZYSUBPRODUCT.ToList();
|
||
List<WX_SzzyOrder_Redefine> addlist = new List<WX_SzzyOrder_Redefine>();
|
||
|
||
foreach (var item in dic)//循环客户
|
||
{
|
||
//var softOrdList = openord.Where(m => m.SOFTUSERNAME == item).OrderBy(m => m.OTIME);
|
||
//var softOrdList2 = ordList22.Where(m => m.ord.SOFTUSERNAME == item).OrderBy(m => m.ord.OTIME).ToList();
|
||
//var softOrdList = from a in db.Wx_Szzyorder_Handle
|
||
// join c in db.WX_SZZYSUBPRODUCT on a.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
// where a.SOFTUSERNAME == item
|
||
// where a.OTIME != null
|
||
// where a.ARRIVALPAY > 1
|
||
// select new NewOrd()
|
||
// {
|
||
// midproduct = c.MidProductId.Value,
|
||
// ord = a
|
||
// };
|
||
var softOrdList = item.Value;
|
||
|
||
int[] productids = { 100800201, 100800202 };//至尊版,至尊VIP
|
||
int[] qinlongzhizhun = { 100800101, 100800201 };//擒龙版,至尊版
|
||
//Logger.Info("客户:" + item.Key + "订单数:" + softOrdList.Count());
|
||
if (item.Key.Equals("dn0446194"))
|
||
{
|
||
var a = 0;
|
||
}
|
||
foreach (var myord in softOrdList)//本用户所有订单
|
||
{
|
||
if (productids.Contains(myord.midproduct))
|
||
{
|
||
if (myord.midproduct == 100800202)//至尊VIP
|
||
{
|
||
var ooo = softOrdList.Where(m => m.midproduct == 100800202 && m.ord.OTIME <= myord.ord.OTIME && m.xuhao < myord.xuhao && m.ord.ORDERID != myord.ord.ORDERID);//之前是否还有至尊vip
|
||
if (ooo.Count() == 0)//无至尊VIP
|
||
{
|
||
var bb = softOrdList.Where(m => qinlongzhizhun.Contains(m.midproduct) && m.ord.OTIME <= myord.ord.OTIME && m.xuhao < myord.xuhao && m.ord.ORDERID != myord.ord.ORDERID);//之前是否还有至尊vip
|
||
if (bb.Count() == 0)
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "新订单",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(myord.ord.UPGRADEORDERIDS))
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "补差升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "产品升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
}
|
||
}
|
||
else//有至尊VIP
|
||
{
|
||
if (!string.IsNullOrEmpty(myord.ord.UPGRADEORDERIDS))
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "补差升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "复购",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
addlist.Add(model);
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{//100800201至尊版本
|
||
var ooo = softOrdList.Where(m => m.midproduct == 100800201 && m.ord.OTIME <= myord.ord.OTIME && m.xuhao < myord.xuhao && m.ord.ORDERID != myord.ord.ORDERID);//之前是否还有至尊vip
|
||
if (ooo.Count() == 0)//无至尊版本
|
||
{
|
||
var bb = softOrdList.Where(m => m.midproduct == 100800101 && m.ord.OTIME <= myord.ord.OTIME && m.xuhao < myord.xuhao && m.ord.ORDERID != myord.ord.ORDERID);//之前是否还有至尊vip
|
||
if (bb.Count() == 0)//无擒龙
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "新订单",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(myord.ord.UPGRADEORDERIDS))
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "补差升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "产品升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(myord.ord.UPGRADEORDERIDS))
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "补差升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "复购",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else//非至尊版,至尊VIP
|
||
{
|
||
var ooo = new List<NewOrd>();
|
||
//if ((myord.ord.CHANNEL >= 26800 && myord.ord.CHANNEL <= 26899) || (myord.ord.CHANNEL >= 26000 && myord.ord.CHANNEL <= 26199))//新媒体二、平台一
|
||
//{
|
||
ooo = softOrdList.Where(m => m.midproduct == myord.midproduct && m.teacher == myord.teacher && m.ord.OTIME <= myord.ord.OTIME && m.xuhao < myord.xuhao && m.ord.ORDERID != myord.ord.ORDERID).ToList();//小于当前订单同类产品 的集合
|
||
int oldCount = ooo.Count();
|
||
if (oldCount == 0)
|
||
{
|
||
if (price_dic.ContainsKey(myord.ord.SOFTUSERNAME))
|
||
{
|
||
oldCount = price_dic[myord.ord.SOFTUSERNAME].Where(m => m.midproductid == myord.midproduct && m.teacher == myord.teacher).Count();//查找老数据的数量
|
||
}
|
||
}
|
||
//}
|
||
//else
|
||
//{
|
||
// ooo = softOrdList.Where(m => m.midproduct == myord.midproduct && m.ord.OTIME < myord.ord.OTIME).ToList();//小于当前订单同类产品 的集合
|
||
//}
|
||
if (oldCount == 0)
|
||
{
|
||
if (!string.IsNullOrEmpty(myord.ord.UPGRADEORDERIDS))
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "新订单+升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "新订单",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
addlist.Add(model);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(myord.ord.UPGRADEORDERIDS))
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "复购+升级",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = myord.ord.ORDERID,
|
||
softusername = myord.ord.SOFTUSERNAME,
|
||
ordertype = "复购",
|
||
midproductid = myord.midproduct,
|
||
channel = myord.ord.CHANNEL,
|
||
arrivalpay = myord.ord.ARRIVALPAY,
|
||
giftdays = myord.ord.giftdays,
|
||
opendays = myord.ord.OPENDAYS,
|
||
otime = myord.ord.OTIME,
|
||
xuhao = myord.xuhao
|
||
};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
//db.SaveChanges();
|
||
addlist.Add(model);
|
||
}
|
||
//WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
//{
|
||
// orderid = myord.ord.ORDERID,
|
||
// softusername = myord.ord.SOFTUSERNAME,
|
||
// ordertype = "复购",
|
||
// midproductid = myord.midproduct
|
||
//};
|
||
////db.WX_SzzyOrder_Redefine.Add(model);
|
||
////db.SaveChanges();
|
||
//addlist.Add(model);
|
||
}
|
||
}
|
||
//}
|
||
//i++;
|
||
}
|
||
}
|
||
Logger.Info("wx_szzyorder_redefine插入数据开始======");
|
||
//int xuhao = 0;
|
||
//foreach (var item in addlist)
|
||
//{
|
||
// xuhao++;
|
||
// item.xuhao = xuhao;
|
||
//}
|
||
foreach (var item in addlist)
|
||
{
|
||
if (!item.starttime.HasValue) item.starttime = new DateTime();
|
||
if (!item.endtime.HasValue) item.endtime = new DateTime();
|
||
}
|
||
bll.BulkInsertToMysql("wx_szzyorder_redefine", addlist);
|
||
Logger.Info("wx_szzyorder_redefine数据插入成功!");
|
||
}
|
||
//Console.ReadLine();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算时长(第一版)
|
||
/// </summary>
|
||
|
||
private static void MainTime(Dictionary<string, List<module_Price_Group>> price_dic)
|
||
{
|
||
Logger.Info("订单的时间计算:");
|
||
var param = new List<MySqlParameter> { };
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"truncate table wx_szzyorder_redefine_time", param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"truncate table wx_szzyorder_redefine_time_update", param.ToArray());
|
||
using (AuditContext db = new AuditContext())
|
||
{
|
||
//string username = "dn0024986";
|
||
var redefineList = (from a in db.WX_SzzyOrder_Redefine
|
||
join b in db.Wx_Szzyorder_Handle on a.orderid equals b.ORDERID
|
||
join userGroup in db.Order_Teacher on b.ORDERID equals userGroup.orderid into jiontemp
|
||
from userGroup in jiontemp.DefaultIfEmpty()//左关联(用户组/部门 关系表)
|
||
//where a.softusername == username
|
||
select new WX_SzzyOrder_Redefine_MAP
|
||
{
|
||
entry = a,
|
||
otime = b.OTIME.Value,
|
||
teacher = userGroup.teacher
|
||
}
|
||
)
|
||
.OrderBy(m => m.otime).ToList();//定性好的数据
|
||
string[] orderstats = { "220", "205", "80", "90" };
|
||
// var openord = db.Wx_Szzyorder_Handle.Where(m => m.OTIME != null &&
|
||
// orderstats.Contains(m.ORDERSTATUS) && (m.CHANNEL < 25000 || m.CHANNEL > 26199));//有开通时间,表示已经开通了,排除了平台一的数据
|
||
var openord = db.Wx_Szzyorder_Handle.Where(m => m.OTIME != null && orderstats.Contains(m.ORDERSTATUS));
|
||
var openord2 = db.Wx_Szzyorder_Handle.Where(m => m.OTIME != null && orderstats.Contains(m.ORDERSTATUS));//所有数据,包括平台一(解决六合一用平台一的订单去升级)
|
||
var ordList22 = (from b in openord
|
||
join x in db.WX_SZZYORDER on b.ORDERID equals x.ORDERID
|
||
join c in db.WX_SZZYSUBPRODUCT on b.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
join userGroup in db.Order_Teacher on b.ORDERID equals userGroup.orderid into jiontemp
|
||
from userGroup in jiontemp.DefaultIfEmpty()//左关联(用户组/部门 关系表)
|
||
|
||
//join d in db.WX_SzzyOrderRefund on b.ORDERID equals d.orderid
|
||
//where b.ORDERSTATUS == "90"
|
||
//where d.auditstatus == 1
|
||
//where b.SOFTUSERNAME == item
|
||
//where b.SOFTUSERNAME == username
|
||
select new NewOrd()
|
||
{
|
||
ord = b,
|
||
midproduct = c.MidProductId.Value,
|
||
teacher = userGroup.teacher,
|
||
old_otime = x.OTIME
|
||
}).OrderBy(m => m.old_otime).ToList();
|
||
|
||
Logger.Info("总订单数:" + ordList22.Count());
|
||
Dictionary<string, List<NewOrd>> dic = new Dictionary<string, List<NewOrd>>();
|
||
|
||
foreach (var item in ordList22)
|
||
{
|
||
if (!dic.ContainsKey(item.ord.SOFTUSERNAME))
|
||
{
|
||
dic.Add(item.ord.SOFTUSERNAME, new List<NewOrd>() { item });
|
||
}
|
||
else
|
||
{
|
||
dic[item.ord.SOFTUSERNAME].Add(item);
|
||
}
|
||
}
|
||
Dictionary<string, List<WX_SzzyOrder_Redefine_MAP>> redefineDic = new Dictionary<string, List<WX_SzzyOrder_Redefine_MAP>>();
|
||
foreach (var item in redefineList)
|
||
{
|
||
item.tpe = 0;
|
||
if (!redefineDic.ContainsKey(item.entry.softusername))
|
||
{
|
||
redefineDic.Add(item.entry.softusername, new List<WX_SzzyOrder_Redefine_MAP>() { item });
|
||
}
|
||
else
|
||
{
|
||
redefineDic[item.entry.softusername].Add(item);
|
||
}
|
||
}
|
||
|
||
#region 正向数据时间计算===========================================
|
||
|
||
Logger.Info("正向数据时间计算开始");
|
||
foreach (var userredlist in redefineDic)//循环用户的所有订单 处理表
|
||
{
|
||
//循环当前用户的计算订单列表
|
||
foreach (var item in userredlist.Value.OrderBy(m => m.entry.xuhao))
|
||
{
|
||
try
|
||
{
|
||
//当前用户的订单列表
|
||
var list = dic[item.entry.softusername];
|
||
//当前订单的明细数据(订单表)
|
||
var entry = list.FirstOrDefault(m => m.ord.ORDERID == item.entry.orderid);
|
||
if (item.entry.ordertype.StartsWith("新订单"))
|
||
{
|
||
item.entry.starttime = entry.ord.OTIME.Value;
|
||
item.entry.endtime = entry.ord.OTIME.Value.AddDays(Convert.ToInt32(entry.ord.OPENDAYS.Value) + (entry.ord.giftdays.HasValue ? Convert.ToInt32(entry.ord.giftdays.Value) : 0));//开通时间+赠送时间
|
||
|
||
//if (item.entry.ordertype.EndsWith("+升级"))//关闭旧订单状态
|
||
//{
|
||
// var upids = Array.ConvertAll(entry.ord.UPGRADEORDERIDS.Split(','), decimal.Parse);//被升级的订单ID集合
|
||
// var beishengji = userredlist.Value.Where(m => upids.Contains(m.entry.orderid));
|
||
// foreach (var bei in beishengji)
|
||
// {
|
||
// if (bei.entry.starttime > item.entry.starttime)
|
||
// bei.entry.endtime = bei.entry.starttime;
|
||
// else
|
||
// bei.entry.endtime = item.entry.starttime;
|
||
|
||
// }
|
||
// var endlist = price_dic[item.entry.softusername].Where(m => upids.Contains(m.orderid)).ToList();
|
||
// foreach (var bei in endlist)
|
||
// {
|
||
// if (bei.endtime2 > item.entry.starttime)//当时间大于当前的订单的开始时间 需要终止时间 同时需要记录一下需要修改的数据
|
||
// {
|
||
// bei.endtime2 = item.entry.starttime;
|
||
// }
|
||
// }
|
||
//}
|
||
}
|
||
else if (item.entry.ordertype.StartsWith("复购"))
|
||
{
|
||
if(item.entry.orderid== 80437340)
|
||
{
|
||
var a = 0;
|
||
}
|
||
|
||
//时间延期,找到同类型未过期产品 的结束时间作为开始时间
|
||
|
||
//var xx = userredlist.Value.OrderByDescending(m => m.entry.xuhao).Where(m => m.entry.midproductid == item.entry.midproductid && m.otime == item.otime && m.entry.orderid != entry.ord.ORDERID);//出现相同的otime
|
||
WX_SzzyOrder_Redefine_MAP preorder = new WX_SzzyOrder_Redefine_MAP();
|
||
//if ((item.ord.CHANNEL >= 26800 && item.ord.CHANNEL <= 26899) || (item.ord.CHANNEL >= 26000 && item.ord.CHANNEL <= 26199))//新媒体二,平台一
|
||
//if (xx.Count() > 0)
|
||
//{
|
||
//出现Otime重复的,需要通过序号来判断
|
||
preorder = userredlist.Value.OrderByDescending(m => m.entry.xuhao).FirstOrDefault(m => m.entry.midproductid == item.entry.midproductid
|
||
&& m.entry.xuhao < item.entry.xuhao
|
||
&& m.entry.orderid != entry.ord.ORDERID
|
||
&& m.teacher == item.teacher);//找出小于当前订单
|
||
if (preorder == null)//如果找不到数据,就要从module_price 的group by表取数据
|
||
{
|
||
var info = price_dic[item.entry.softusername].Where(m => m.midproductid == item.entry.midproductid
|
||
&& m.orderid != entry.ord.ORDERID
|
||
&& m.teacher == item.teacher).LastOrDefault();
|
||
if (info != null)
|
||
preorder = new WX_SzzyOrder_Redefine_MAP()
|
||
{
|
||
teacher = info.teacher,
|
||
otime = info.otime2.Value,
|
||
entry = new WX_SzzyOrder_Redefine()
|
||
{
|
||
opendays = info.opendays2,
|
||
orderid = info.orderid,
|
||
otime = info.otime2,
|
||
channel = info.channel,
|
||
starttime = info.starttime2.Value,
|
||
endtime = info.endtime2.Value,
|
||
}
|
||
};
|
||
}
|
||
//}
|
||
//else
|
||
//{
|
||
// preorder = userredlist.Value.OrderByDescending(m => m.otime).FirstOrDefault(m => m.entry.midproductid == item.entry.midproductid
|
||
// && m.entry.otime < item.entry.otime
|
||
// && m.entry.orderid != entry.ord.ORDERID
|
||
// && m.teacher == item.teacher);//找出小于当前订单
|
||
//}
|
||
if (preorder.entry.endtime > entry.ord.OTIME)//如果上一个订单未到期
|
||
{
|
||
item.entry.starttime = preorder.entry.endtime;
|
||
item.entry.endtime = item.entry.starttime.Value.AddDays(Convert.ToInt32(entry.ord.OPENDAYS.Value) + (entry.ord.giftdays.HasValue ? Convert.ToInt32(entry.ord.giftdays.Value) : 0));//开通天数
|
||
}
|
||
else//如果已经到期,还是用自己的时间
|
||
{
|
||
item.entry.starttime = entry.ord.OTIME.Value;
|
||
item.entry.endtime = entry.ord.OTIME.Value.AddDays(Convert.ToInt32(entry.ord.OPENDAYS.Value) + (entry.ord.giftdays.HasValue ? Convert.ToInt32(entry.ord.giftdays.Value) : 0));//开通天数
|
||
}
|
||
}
|
||
else if (item.entry.ordertype == "补差升级")
|
||
{
|
||
//补差升级,用新产品的时长,结束上一个产品时长
|
||
//当前订单,用当前时间
|
||
|
||
item.entry.starttime = entry.ord.OTIME.Value;
|
||
item.entry.endtime = entry.ord.OTIME.Value.AddDays(Convert.ToInt32(entry.ord.OPENDAYS.Value) + (entry.ord.giftdays.HasValue ? Convert.ToInt32(entry.ord.giftdays.Value) : 0));//开通时间+赠送时间
|
||
|
||
//新媒体二 补差升级需要 计算开始时间和结束时间
|
||
//if (item.entry.channel >= 26800 && item.entry.channel <= 26899)
|
||
//{
|
||
// var upids = Array.ConvertAll(entry.ord.UPGRADEORDERIDS.Split(','), decimal.Parse);//被升级的订单ID集合
|
||
// var beishengji = userredlist.Value.Where(m => upids.Contains(m.entry.orderid));
|
||
// foreach (var bei in beishengji)
|
||
// {
|
||
// if (bei.entry.endtime > item.entry.starttime)//当时间大于当前的订单的开始时间 需要终止时间
|
||
// {
|
||
// bei.entry.endtime = item.entry.starttime;
|
||
// }
|
||
// }
|
||
|
||
// var endlist = price_dic[item.entry.softusername].Where(m => upids.Contains(m.orderid)).ToList();
|
||
// foreach (var bei in endlist)
|
||
// {
|
||
// if (bei.endtime2 > item.entry.starttime)//当时间大于当前的订单的开始时间 需要终止时间
|
||
// {
|
||
// bei.endtime2 = item.entry.starttime;
|
||
// }
|
||
// }
|
||
//}
|
||
}
|
||
else if (item.entry.ordertype == "产品升级")
|
||
{
|
||
//int[] productids = { 100800201, 100800202 };//至尊版,至尊VIP
|
||
//int[] qinlongzhizhun = { 100800101, 100800201 };//擒龙版,至尊版
|
||
|
||
item.entry.starttime = entry.ord.OTIME.Value;
|
||
item.entry.endtime = entry.ord.OTIME.Value.AddDays(Convert.ToInt32(entry.ord.OPENDAYS.Value) + (entry.ord.giftdays.HasValue ? Convert.ToInt32(entry.ord.giftdays.Value) : 0));//开通时间+赠送时间
|
||
//if (item.entry.midproductid == 100800202)//找到最近的一个至尊或者擒龙版本进行时间结束
|
||
//{
|
||
//}
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Logger.Error(e, "异常订单:" + item.entry.orderid + "," + item.entry.ordertype);
|
||
throw e;
|
||
}
|
||
}
|
||
}
|
||
Logger.Info("正向数据时间计算完毕!");
|
||
|
||
#endregion 正向数据时间计算===========================================
|
||
|
||
#region 退款+被升级订单 数据时间计算
|
||
|
||
Logger.Info("退款数据时间计算开始!");
|
||
|
||
List<WX_SzzyOrder_Redefine_Time> updateList = new List<WX_SzzyOrder_Redefine_Time>();
|
||
//退款订单
|
||
DateTime time1 = new DateTime(2021, 12, 16);
|
||
var tuikorder = (from a in db.WX_SzzyOrderRefund
|
||
join b in openord on a.orderid equals b.ORDERID
|
||
join c in db.WX_SZZYSUBPRODUCT on b.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
join userGroup in db.Order_Teacher on b.ORDERID equals userGroup.orderid into jiontemp
|
||
from userGroup in jiontemp.DefaultIfEmpty()//左关联(用户组/部门 关系表)
|
||
where b.ORDERSTATUS == "90"
|
||
where a.auditstatus == 1
|
||
where a.audittime < endtime
|
||
where a.audittime >= starttime
|
||
// where (a.channel < 25000 || a.channel > 26199)//排除平台一数据
|
||
select new NewOrd()
|
||
{
|
||
ord = b,
|
||
midproduct = c.MidProductId.Value,
|
||
tuiTime = a.refunddate.Value,//退款审核时间
|
||
teacher = userGroup.teacher,
|
||
type = "退款订单"
|
||
}).OrderBy(m => m.tuiTime).ToList();
|
||
|
||
#region 片段中加入 有升级关系的订单
|
||
|
||
string sql = @"select t.orderid,t.upgradeorderids,t.otime,t.softusername,t.channel from wx_szzyorder_handle t where t.otime>='" + starttime.ToString("yyyy-MM-dd") + "' and t.otime<'" + endtime.ToString("yyyy-MM-dd") + "' and t.upgradeorderids is not null and t.upgradeorderids <>'';";
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
List<upgradeorderidsInfo> uplist = dataSet.Tables[0].ToList<upgradeorderidsInfo>();
|
||
List<NewOrd> upneworderlist = new List<NewOrd>();
|
||
foreach (var item in uplist)
|
||
{
|
||
var upids = Array.ConvertAll(item.upgradeorderids.Split(','), decimal.Parse);//被升级的订单ID集合
|
||
foreach (var up in upids)
|
||
{
|
||
var oldOrd = openord2.FirstOrDefault(m => m.ORDERID == up);
|
||
if (oldOrd == null)
|
||
{
|
||
Logger.Error("找不到被升级的订单号:" + up);
|
||
}
|
||
upneworderlist.Add(
|
||
new NewOrd()
|
||
{
|
||
tuiTime = item.otime.Value,//退款审核时间
|
||
ord = oldOrd,
|
||
type = "被升级订单"
|
||
}
|
||
);
|
||
}
|
||
}
|
||
tuikorder.AddRange(upneworderlist);
|
||
|
||
tuikorder = tuikorder.OrderBy(m => m.tuiTime).ToList();
|
||
|
||
#endregion 片段中加入 有升级关系的订单
|
||
|
||
foreach (var item in tuikorder)
|
||
{
|
||
try
|
||
{
|
||
var list = dic[item.ord.SOFTUSERNAME];//退款订单对应的用户所有订单信息
|
||
//var nnxaa = redefineDic[item.ord.SOFTUSERNAME];//计算表 用户所有订单;
|
||
|
||
#region 将历史数据纳入查找
|
||
|
||
var nnx = new List<WX_SzzyOrder_Redefine_MAP>();
|
||
if (price_dic.ContainsKey(item.ord.SOFTUSERNAME))
|
||
{
|
||
foreach (var his in price_dic[item.ord.SOFTUSERNAME])
|
||
{
|
||
nnx.Add(new WX_SzzyOrder_Redefine_MAP
|
||
{
|
||
otime = his.otime2.Value,
|
||
teacher = his.teacher,
|
||
entry = new WX_SzzyOrder_Redefine()
|
||
{
|
||
opendays = his.opendays2,
|
||
otime = his.otime2,
|
||
channel = his.channel,
|
||
endtime = his.endtime2.Value,
|
||
starttime = his.starttime2.Value,
|
||
orderid = his.orderid,
|
||
midproductid = his.midproductid,
|
||
softusername = his.username,
|
||
},
|
||
tpe = 1,
|
||
isUpdate = 0
|
||
});
|
||
}
|
||
}
|
||
if (redefineDic.ContainsKey(item.ord.SOFTUSERNAME))
|
||
nnx.AddRange(redefineDic[item.ord.SOFTUSERNAME]);
|
||
|
||
#endregion 将历史数据纳入查找
|
||
|
||
var entry = nnx.FirstOrDefault(m => m.entry.orderid == item.ord.ORDERID);//当期的计算订单信息
|
||
if (entry == null)
|
||
{
|
||
Logger.Error(string.Format("entry is null item:{0}", item.ToJson()));
|
||
}
|
||
|
||
entry.entry.statusname = item.type;
|
||
if (entry.entry.endtime.Value.Date > item.tuiTime && entry.entry.starttime.Value.Date < item.tuiTime)//订单还在使用中
|
||
{
|
||
var dayj = (entry.entry.endtime.Value.Date - item.tuiTime.Date).Days;
|
||
|
||
entry.entry.endtime = item.tuiTime;//修改结束时间
|
||
entry.isUpdate = 1;//更改过
|
||
//string[] typelis = { "复购", "新订单" };
|
||
|
||
var preModelList = new List<WX_SzzyOrder_Redefine_MAP>();
|
||
if ((item.ord.CHANNEL >= 26800 && item.ord.CHANNEL <= 26899) || (item.ord.CHANNEL >= 26000 && item.ord.CHANNEL <= 26199))//新媒体二,平台一
|
||
{
|
||
preModelList = nnx.Where(m
|
||
=>
|
||
//typelis.Contains(m.entry.ordertype) &&
|
||
m.entry.midproductid == entry.entry.midproductid
|
||
&& entry.teacher == m.teacher
|
||
&& m.entry.starttime >= entry.entry.endtime
|
||
).OrderBy(m => m.entry.starttime).ToList();//上一个订单
|
||
}
|
||
else
|
||
{
|
||
preModelList = nnx.Where(m
|
||
=>
|
||
//typelis.Contains(m.entry.ordertype) &&
|
||
m.entry.midproductid == entry.entry.midproductid
|
||
&& m.entry.starttime >= entry.entry.endtime
|
||
).OrderBy(m => m.entry.starttime).ToList();//上一个订单
|
||
}
|
||
|
||
foreach (var pre in preModelList)
|
||
{
|
||
var ss = (pre.entry.starttime.Value.Date - pre.entry.otime.Value.Date).Days;//开始时间往后移动了多少天
|
||
if (pre.entry.orderid == 80207870 || pre.entry.orderid == 80206880)
|
||
{
|
||
Logger.Info("1,orderid:" + pre.entry.orderid + ":pre.entry.starttime:" + pre.entry.starttime.Value.ToString("yyyy-MM-dd HH:mm:ss") + ", pre.entry.endtime :" + pre.entry.endtime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
|
||
Logger.Info("1,orderid:" + pre.entry.orderid + ":ss:" + ss + ",dayj:" + dayj);
|
||
}
|
||
if (ss > dayj)
|
||
{
|
||
pre.entry.starttime = pre.entry.starttime.Value.AddDays(-dayj);
|
||
pre.entry.endtime = pre.entry.endtime.Value.AddDays(-dayj);
|
||
pre.isUpdate = 1;//更改过
|
||
}
|
||
else
|
||
{
|
||
pre.entry.starttime = pre.entry.starttime.Value.AddDays(-ss);
|
||
|
||
pre.entry.endtime = pre.entry.endtime.Value.AddDays(-ss);// item.tuiTime;//正在使用的订单结束时间==退款时间//
|
||
pre.isUpdate = 1;//更改过
|
||
}
|
||
}
|
||
}
|
||
else if (entry.entry.starttime.Value.Date > item.tuiTime)//订单未使用直接退款
|
||
{
|
||
var dayj = (entry.entry.starttime.Value.Date - item.tuiTime.Date).Days;//退款时间和本来时间的时间差
|
||
|
||
if (entry.entry.orderid == 80207870)
|
||
{
|
||
Logger.Info("b,orderid:" + entry.entry.orderid + ":pre item.tuiTime:" + item.tuiTime.ToString("yyyy-MM-dd HH:mm:ss"));
|
||
}
|
||
//entry.entry.starttime = item.tuiTime;//订单未使用开时间和结束时间都修改成退款时间
|
||
//entry.entry.endtime = item.tuiTime;//修改结束时间
|
||
entry.entry.endtime = entry.entry.starttime;//未使用直接退款直接使用starttime
|
||
entry.isUpdate = 1;//更改过
|
||
//string[] typelis = { "复购", "新订单" };
|
||
|
||
var preModelList = nnx.Where(m
|
||
=>
|
||
//typelis.Contains(m.entry.ordertype)&&
|
||
m.entry.midproductid == entry.entry.midproductid
|
||
&& m.entry.starttime > entry.entry.endtime
|
||
&& entry.teacher == m.teacher //如果没有老师,你也是null 一样能查找匹配
|
||
).OrderBy(m => m.entry.starttime);//上一个订单
|
||
|
||
foreach (var pre in preModelList)//之后的订单需要时间往前挪
|
||
{
|
||
//starttime永远大于otime
|
||
//var jsuandate = pre.entry.starttime.AddDays(-dayj);
|
||
//if (jsuandate < pre.otime)//如果比otime大,就用开通时间
|
||
//{
|
||
// pre.entry.starttime = jsuandate;
|
||
// pre.entry.endtime = pre.entry.endtime.AddDays(-dayj);
|
||
//}
|
||
//else
|
||
//{
|
||
// int shijiancha = (pre.entry.starttime.Date-pre.otime.Date).Days;//相差天数
|
||
// pre.entry.starttime = pre.otime;//开始时间必须>=otime,此时otime=starttime,endtime需要减去时间差
|
||
// pre.entry.endtime = pre.entry.endtime.AddDays(-shijiancha); //pre.otime.AddDays(Convert.ToInt32(pre.entry.opendays.Value) + (pre.entry.giftdays.HasValue ? Convert.ToInt32(pre.entry.giftdays.Value) : 0));//开通时间+赠送时间
|
||
//}
|
||
var ss = (pre.entry.starttime.Value.Date - pre.entry.otime.Value.Date).Days;
|
||
if (pre.entry.orderid == 80207870 || pre.entry.orderid == 80206880)
|
||
{
|
||
Logger.Info("2,orderid:" + pre.entry.orderid + ":pre.entry.starttime:" + pre.entry.starttime.Value.ToString("yyyy-MM-dd HH:mm:ss") + ", pre.entry.endtime :" + pre.entry.endtime.Value.ToString("yyyy-MM-dd HH:mm:ss"));
|
||
Logger.Info("2,orderid:" + pre.entry.orderid + ":ss:" + ss + ",dayj:" + dayj);
|
||
}
|
||
if (ss > dayj)
|
||
{
|
||
pre.entry.starttime = pre.entry.starttime.Value.AddDays(-dayj);
|
||
pre.entry.endtime = pre.entry.endtime.Value.AddDays(-dayj);
|
||
pre.isUpdate = 1;//更改过
|
||
}
|
||
else
|
||
{
|
||
pre.entry.starttime = pre.entry.starttime.Value.AddDays(-ss);
|
||
pre.entry.endtime = pre.entry.endtime.Value.AddDays(-ss);
|
||
pre.isUpdate = 1;//更改过
|
||
}
|
||
|
||
//pre.entry.starttime = pre.entry.starttime.AddDays(-dayj);
|
||
//pre.entry.endtime = pre.entry.endtime.AddDays(-dayj);
|
||
}
|
||
}
|
||
|
||
//将修改的数据写入缓存
|
||
foreach (var item2 in nnx)
|
||
{
|
||
if (item2.tpe == 0)
|
||
{
|
||
var xx = redefineDic[item.ord.SOFTUSERNAME].FirstOrDefault(m => m.entry.orderid == item2.entry.orderid);
|
||
xx.entry.starttime = item2.entry.starttime;
|
||
xx.entry.endtime = item2.entry.endtime;
|
||
}
|
||
else
|
||
{
|
||
if (item2.isUpdate == 1)
|
||
{
|
||
updateList.Add(new WX_SzzyOrder_Redefine_Time()
|
||
{
|
||
endtime = item2.entry.endtime.Value,
|
||
midproductid = item2.entry.midproductid,
|
||
orderid = item2.entry.orderid,
|
||
ordertype = item2.entry.ordertype,
|
||
softusername = item2.entry.softusername,
|
||
starttime = item2.entry.starttime.Value,
|
||
status = item2.entry.status,
|
||
statusname = item2.entry.statusname,
|
||
opendays = item2.entry.opendays,
|
||
giftdays = item2.entry.giftdays,
|
||
arrivalpay = item2.entry.arrivalpay,
|
||
channel = item2.entry.channel,
|
||
otime = item2.entry.otime,
|
||
xuhao = item2.entry.xuhao
|
||
});
|
||
var xx = price_dic[item.ord.SOFTUSERNAME].FirstOrDefault(m => m.orderid == item2.entry.orderid);
|
||
xx.starttime2 = item2.entry.starttime;
|
||
xx.endtime2 = item2.entry.endtime;
|
||
}
|
||
}
|
||
}
|
||
|
||
////退款订单
|
||
//var tuid = db.WX_SzzyOrder_Redefine.FirstOrDefault(m => m.orderid == item.orderid);
|
||
//if (tuid.endtime > item.optime && tuid.starttime < item.optime)
|
||
//{
|
||
// var dayj = (tuid.endtime.Date - item.optime.Date).Days;
|
||
// tuid.endtime = item.optime;
|
||
// UpdateWX_SzzyOrder_Redefine(db, tuid);//修改当前订单的结束时间
|
||
|
||
// var preModelList = db.WX_SzzyOrder_Redefine.Where(m => m.softusername == entry.SOFTUSERNAME && m.midproductid == item.midproduct && m.starttime > item.optime && m.orderid != tuid.orderid).OrderBy(m => m.endtime);//上一个订单
|
||
// foreach (var pre in preModelList)
|
||
// {
|
||
// pre.starttime = pre.starttime.AddDays(-dayj);
|
||
// pre.endtime = pre.endtime.AddDays(-dayj);
|
||
// UpdateWX_SzzyOrder_Redefine(db, pre);//修改当前订单的结束时间
|
||
// }
|
||
//}
|
||
//else if (tuid.starttime > item.optime)
|
||
//{
|
||
// var dayj = (tuid.endtime.Date - tuid.starttime.Date).Days;
|
||
// //tuid.starttime = item.starttime;
|
||
// tuid.endtime = tuid.starttime;
|
||
// UpdateWX_SzzyOrder_Redefine(db, tuid);//修改当前订单的结束时间
|
||
|
||
// var preModelList = db.WX_SzzyOrder_Redefine.Where(m => m.softusername == entry.SOFTUSERNAME && m.midproductid == item.midproduct && m.starttime > item.optime && m.orderid != tuid.orderid).OrderBy(m => m.endtime);//上一个订单
|
||
// foreach (var pre in preModelList)
|
||
// {
|
||
// pre.starttime = pre.starttime.AddDays(-dayj);
|
||
// pre.endtime = pre.endtime.AddDays(-dayj);
|
||
// UpdateWX_SzzyOrder_Redefine(db, pre);//修改当前订单的结束时间
|
||
// }
|
||
//}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Logger.Error(ex, String.Format("item:{0}", item.ToJson()));
|
||
throw ex;
|
||
}
|
||
}
|
||
Logger.Info("退款数据时间计算完毕!");
|
||
|
||
#endregion 退款+被升级订单 数据时间计算
|
||
|
||
WX_SzzyOrder_Redefine_Time_BL bll = new WX_SzzyOrder_Redefine_Time_BL();
|
||
List<WX_SzzyOrder_Redefine_Time> addlist = new List<WX_SzzyOrder_Redefine_Time>();
|
||
|
||
foreach (var item in redefineDic)
|
||
{
|
||
foreach (var map in item.Value)
|
||
{
|
||
if (map.tpe == 0)
|
||
{
|
||
addlist.Add(new WX_SzzyOrder_Redefine_Time()
|
||
{
|
||
endtime = map.entry.endtime.Value,
|
||
midproductid = map.entry.midproductid,
|
||
orderid = map.entry.orderid,
|
||
ordertype = map.entry.ordertype,
|
||
softusername = map.entry.softusername,
|
||
starttime = map.entry.starttime.Value,
|
||
status = map.entry.status,
|
||
statusname = map.entry.statusname,
|
||
opendays = map.entry.opendays,
|
||
giftdays = map.entry.giftdays,
|
||
arrivalpay = map.entry.arrivalpay,
|
||
channel = map.entry.channel,
|
||
otime = map.entry.otime,
|
||
xuhao = map.entry.xuhao
|
||
});
|
||
}
|
||
//else
|
||
//{
|
||
// updateList.Add(new WX_SzzyOrder_Redefine_Time()
|
||
// {
|
||
// endtime = map.entry.endtime,
|
||
// midproductid = map.entry.midproductid,
|
||
// orderid = map.entry.orderid,
|
||
// ordertype = map.entry.ordertype,
|
||
// softusername = map.entry.softusername,
|
||
// starttime = map.entry.starttime,
|
||
// status = map.entry.status,
|
||
// statusname = map.entry.statusname,
|
||
// opendays = map.entry.opendays,
|
||
// giftdays = map.entry.giftdays,
|
||
// arrivalpay = map.entry.arrivalpay,
|
||
// channel = map.entry.channel,
|
||
// otime = map.entry.otime,
|
||
// xuhao = map.entry.xuhao
|
||
|
||
// });
|
||
//}
|
||
}
|
||
}
|
||
Logger.Info("数据写入");
|
||
bll.BulkInsertToMysql("wx_szzyorder_redefine_time", addlist);
|
||
bll.BulkInsertToMysql("wx_szzyorder_redefine_time_update", updateList);
|
||
Logger.Info("数据入库结束!");
|
||
//注释原因,渠道判断是错误的
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price x set
|
||
//x.starttime2=(select starttime from wx_szzyorder_redefine_time_update t where t.orderid=x.orderid),
|
||
//x.endtime2=(select endtime from wx_szzyorder_redefine_time_update t where t.orderid=x.orderid)
|
||
//where
|
||
//exists(select 1 from wx_szzyorder_redefine_time_update t where t.orderid=x.orderid)
|
||
//and x.moduleid not in('1010','1028','1031','1038','1011','1012','1082','1018')
|
||
//and ((x.channel<25000 and x.channel>26199)#非平台一
|
||
//or(x.channel>27100 and x.channel>27199))#非新媒体三
|
||
//", param.ToArray());
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price x set
|
||
x.starttime2=(select starttime from wx_szzyorder_redefine_time_update t where t.orderid=x.orderid),
|
||
x.endtime2=(select endtime from wx_szzyorder_redefine_time_update t where t.orderid=x.orderid)
|
||
where
|
||
exists(select 1 from wx_szzyorder_redefine_time_update t where t.orderid=x.orderid)
|
||
and x.moduleid not in('1010','1028','1031','1038','1011','1012','1082','1018','1167','1162','1163','1183','1184','1185')
|
||
and x.channel not BETWEEN 25000 and 26199 #非平台一
|
||
and x.channel not BETWEEN 27100 and 27199 #首华
|
||
and x.channel not BETWEEN 26800 and 26899 #新媒体二
|
||
;", param.ToArray());
|
||
//Console.ReadLine();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 合并主ID的操作
|
||
/// </summary>
|
||
/// <param name=""></param>
|
||
public static void MainModle()
|
||
{
|
||
Module_Order_BL bll = new Module_Order_BL();
|
||
using (AuditContext db = new AuditContext())
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "truncate table module_order_jisuan;", param.ToArray());//清空中间表数据
|
||
string sql = @"select a.id,a.username,a.moduleid,a.szzyorderid,a.productcode2,a.starttime2,a.endtime2,a.usedays,a.subproductname2,a.opendays2,a.totaldays,a.price2,a.ctime2,a.otime2,ifnull(b.channel,a.channel2) channel2,a.status2,a.isrefund,a.canceluser,a.canceltime,a.returnPrice,b.arrivalpay,b.orderid,x.midproductid from module_order a
|
||
left join wx_szzyorder b on a.szzyorderid=b.szzyorderid
|
||
left join wx_szzysubproduct x on x.subproductid=b.subproductid
|
||
where a.otime2<'" + endtime.ToString("yyyy-MM-dd") + @"'
|
||
and a.otime2>='" + starttime.ToString("yyyy-MM-dd") + @"'
|
||
order by a.username,a.otime2,a.price2 desc,a.id;
|
||
";
|
||
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
List<Module_Order> list = dataSet.Tables[0].ToList<Module_Order>();
|
||
Dictionary<string, List<Module_Order>> dic = new Dictionary<string, List<Module_Order>>();
|
||
Dictionary<string, int> dicxuhao = new Dictionary<string, int>();
|
||
foreach (var item in list)
|
||
{
|
||
if (!dic.ContainsKey(item.username))
|
||
{
|
||
item.xuhao = 1;
|
||
dic.Add(item.username, new List<Module_Order>() { item });
|
||
dicxuhao.Add(item.username, 1);
|
||
}
|
||
else
|
||
{
|
||
dicxuhao[item.username] = dicxuhao[item.username] + 1;
|
||
item.xuhao = dicxuhao[item.username];
|
||
dic[item.username].Add(item);
|
||
}
|
||
}
|
||
|
||
//订单升级关系计算
|
||
Moudle_Order_Upgrade();
|
||
//return;
|
||
|
||
List<Module_Order> addlist = new List<Module_Order>();
|
||
Logger.Info("数据循环计算!");
|
||
///根据用户循环模块订单数据
|
||
foreach (var item in dic)
|
||
{
|
||
foreach (var cd in item.Value)//本用户所有模块列表
|
||
{
|
||
if (cd.price2 == 0)
|
||
{
|
||
//没钱订单模块排除
|
||
continue;
|
||
}
|
||
cd.MainSzzyorderid = cd.szzyorderid;
|
||
addlist.Add(cd);//添加主订单
|
||
}
|
||
}
|
||
Logger.Info("入库成功数据:" + addlist.Count());
|
||
bll.BulkInsertToMysql("module_order_jisuan", addlist);
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "truncate table module_order_jisuan_price;", param.ToArray());//清空中间表数据
|
||
Logger.Info("module_order_jisuan_price清理成功");
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into module_order_jisuan_price(id,orderPrice)
|
||
select waa.id,
|
||
(
|
||
select sum(wcc.arrivalpay) from wx_szzyorder wcc where wcc.szzyorderid in(select DISTINCT aw.szzyorderid from module_order_jisuan aw where aw.MainSzzyorderid=waa.MainSzzyorderid)
|
||
) orderPrice#计算金额
|
||
from module_order_jisuan waa where waa.id in(
|
||
select min(id) from module_order_jisuan w where w.szzyorderid in( select a.MainSzzyorderid from module_order_jisuan a) group by w.szzyorderid
|
||
);", param.ToArray());//清空中间表数据
|
||
Logger.Info("插入计算数据成功!");
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "update module_order_jisuan set orderPrice=null;", param.ToArray());//清空中间表数据
|
||
Logger.Info("module_order_jisuan的orderPrice改成NULL成功");
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_order_jisuan t set t.orderPrice=(select x.orderPrice from module_order_jisuan_price x where x.id=t.id )
|
||
where exists(select 1 from module_order_jisuan_price x where x.id = t.id );
|
||
", param.ToArray());//清空中间表数据
|
||
|
||
Logger.Info("入库成功!");
|
||
}
|
||
}
|
||
|
||
public static void ModulePriceJiSuan()
|
||
{
|
||
Module_Order_BL bll = new Module_Order_BL();
|
||
using (AuditContext db = new AuditContext())
|
||
{
|
||
//try
|
||
//{
|
||
var param = new List<MySqlParameter> { };
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "delete from module_price where otime2>='" + starttime.ToString("yyyy-MM-dd") + "';", param.ToArray());//清空中间表数据
|
||
|
||
string sql = @"select a.* from module_order_jisuan a
|
||
order by a.username,a.otime2,a.price2 desc,a.id;";
|
||
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
List<Module_Order> list = dataSet.Tables[0].ToList<Module_Order>();
|
||
Dictionary<string, List<Module_Order>> dic = new Dictionary<string, List<Module_Order>>();//主订单作为key
|
||
foreach (var item in list)
|
||
{
|
||
if (!dic.ContainsKey(item.MainSzzyorderid))
|
||
{
|
||
dic.Add(item.MainSzzyorderid, new List<Module_Order>() { item });
|
||
}
|
||
else
|
||
{
|
||
dic[item.MainSzzyorderid].Add(item);
|
||
}
|
||
}
|
||
|
||
List<CRM.Core.Model.EntityAudit.Module_Price> addlist = new List<CRM.Core.Model.EntityAudit.Module_Price>();
|
||
Logger.Info("数据循环计算!");
|
||
Dictionary<int, GongYunJia> midprodcut_moduleid = new Dictionary<int, GongYunJia>();
|
||
midprodcut_moduleid.Add(100800203, new GongYunJia() { ModeulId = "1012", IsTanFen = false, Price = 239200 });//汇金长赢
|
||
midprodcut_moduleid.Add(100800204, new GongYunJia() { ModeulId = "1011", IsTanFen = false, Price = 119200 });//龙虎大咖
|
||
midprodcut_moduleid.Add(100800106, new GongYunJia() { ModeulId = "1082", IsTanFen = false, Price = 9980 });//红心哥单独模块
|
||
midprodcut_moduleid.Add(100800104, new GongYunJia() { ModeulId = "1018", IsTanFen = false, Price = 2631.98 });//实训营
|
||
midprodcut_moduleid.Add(100800102, new GongYunJia() { ModeulId = "1028", IsTanFen = false, Price = 30581.00, });//研习班
|
||
//参与摊分的模块
|
||
midprodcut_moduleid.Add(100800101, new GongYunJia() { ModeulId = "1010", IsTanFen = true, Price = 9800 });//擒龙版
|
||
midprodcut_moduleid.Add(100800201, new GongYunJia() { ModeulId = "1031", IsTanFen = true, Price = 20000 });//至尊版
|
||
midprodcut_moduleid.Add(100800202, new GongYunJia() { ModeulId = "1038", IsTanFen = true, Price = 30000 });//至尊VIP
|
||
midprodcut_moduleid.Add(100800801, new GongYunJia() { ModeulId = "1167", IsTanFen = true, Price = 30000 });//至尊投研
|
||
//midprodcut_moduleid.Add(100900401, new GongYunJia() { ModeulId = "1162", IsTanFen = true, Price = 6000 });//东方回报1号组合策略报告(公允价格随便给的,单模块订单不会做分配)
|
||
//midprodcut_moduleid.Add(100900401, new GongYunJia() { ModeulId = "1163", IsTanFen = true, Price = 6000 });//东方回报1号跟踪服务(公允价格随便给的,单模块订单不会做分配)
|
||
Dictionary<string, string> youJia = new Dictionary<string, string>();//需要参与计算金额的模块,但是不存在公允价格
|
||
youJia.Add("1162", "1162");//东方回报1号组合策略报告
|
||
youJia.Add("1163", "1163");//东方回报1号跟踪服务
|
||
youJia.Add("1183", "1183");//东高投研之重要会议分析报告
|
||
youJia.Add("1184", "1184");//东高投研主题报告(三册)
|
||
youJia.Add("1185", "1185");//东高投研主题报告(二册)
|
||
|
||
var needTanModuleIds = midprodcut_moduleid.Values.Where(m => m.IsTanFen == true).Select(m => m.ModeulId).ToArray();
|
||
foreach (var item in dic)
|
||
{
|
||
//判断订单下所有模块是否在擒龙版,至尊版,至尊VIP
|
||
if (item.Value.Where(m => needTanModuleIds.Contains(m.moduleid)).Count() > 0)
|
||
{
|
||
//foreach (var cd in item.Value.OrderBy(m => m.xuhao))
|
||
//{
|
||
var MainOrder = item.Value.OrderBy(m => m.xuhao).FirstOrDefault();
|
||
|
||
double fenmu = 0;
|
||
//Dictionary<string, Modeule_Info>
|
||
List<Modeule_Info> infoList = new List<Modeule_Info>();
|
||
foreach (var mid in midprodcut_moduleid)
|
||
{
|
||
var xa1 = item.Value.Where(m => m.moduleid == mid.Value.ModeulId);
|
||
double m1 = Convert.ToDouble(xa1.Sum(m => m.opendays2));
|
||
if (m1 > 0)
|
||
{
|
||
infoList.Add(new Modeule_Info
|
||
{
|
||
endtime2 = xa1.Max(m => m.endtime2),
|
||
ModuleId = mid.Value.ModeulId,
|
||
opendays2 = Convert.ToInt32(m1),
|
||
starttime2 = xa1.Min(m => m.starttime2),
|
||
gongyunPrice = (mid.Value.IsTanFen ? mid.Value.Price : 0)
|
||
});
|
||
fenmu += (m1 * (mid.Value.IsTanFen ? mid.Value.Price : 0));
|
||
}
|
||
}
|
||
foreach (var infoitem in infoList)
|
||
{
|
||
CRM.Core.Model.EntityAudit.Module_Price price = new CRM.Core.Model.EntityAudit.Module_Price()
|
||
{
|
||
channel = MainOrder.channel2,
|
||
ctime2 = MainOrder.ctime2,
|
||
moduleid = infoitem.ModuleId,
|
||
szzyorderid = MainOrder.szzyorderid,
|
||
midproductid = MainOrder.midproductid,
|
||
orderid = MainOrder.orderid,
|
||
orderPrice = MainOrder.orderPrice,
|
||
otime2 = MainOrder.otime2,
|
||
username = MainOrder.username,
|
||
opendays2 = Convert.ToInt32(infoitem.opendays2),
|
||
starttime2 = infoitem.starttime2,
|
||
endtime2 = infoitem.endtime2,
|
||
modulePrice = needTanModuleIds.Contains(infoitem.ModuleId) ? ((Convert.ToDouble(MainOrder.orderPrice) * infoitem.gongyunPrice * infoitem.opendays2) / fenmu) : 0
|
||
};
|
||
price.modulePrice2 = Convert.ToDecimal(price.modulePrice);
|
||
addlist.Add(price);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var MainOrder = item.Value.OrderBy(m => m.xuhao).FirstOrDefault();
|
||
foreach (var infoitem in item.Value)
|
||
{
|
||
double modulePrice = 0;
|
||
if (youJia.ContainsKey(infoitem.moduleid))
|
||
{
|
||
modulePrice = Convert.ToDouble(infoitem.orderPrice);
|
||
}
|
||
else
|
||
{
|
||
modulePrice = (midprodcut_moduleid.ContainsKey(Convert.ToInt32(infoitem.midproductid)) && midprodcut_moduleid[Convert.ToInt32(infoitem.midproductid)].ModeulId == infoitem.moduleid) ? Convert.ToDouble(infoitem.orderPrice) : Convert.ToDouble(0);
|
||
}
|
||
CRM.Core.Model.EntityAudit.Module_Price price = new CRM.Core.Model.EntityAudit.Module_Price()
|
||
{
|
||
channel = MainOrder.channel2,
|
||
ctime2 = MainOrder.ctime2,
|
||
moduleid = infoitem.moduleid,
|
||
szzyorderid = MainOrder.szzyorderid,
|
||
midproductid = MainOrder.midproductid,
|
||
orderid = MainOrder.orderid,
|
||
orderPrice = MainOrder.orderPrice,
|
||
otime2 = MainOrder.otime2,
|
||
username = MainOrder.username,
|
||
opendays2 = Convert.ToInt32(infoitem.opendays2),
|
||
starttime2 = infoitem.starttime2,
|
||
endtime2 = infoitem.endtime2,
|
||
modulePrice = modulePrice
|
||
};
|
||
price.modulePrice2 = Convert.ToDecimal(price.modulePrice);
|
||
addlist.Add(price);
|
||
}
|
||
}
|
||
|
||
//string[] nomoduleid = { "1012", "1011", "1082", "1018", "1028", "1010", "1031", "1038" };
|
||
//var axa = item.Value.Where(bb => !nomoduleid.Contains(bb.moduleid)).ToList();//找出 没找到的模块数据
|
||
//foreach (var nodata in axa)
|
||
//{
|
||
// Logger.Info($"找不到的模块数据:{nodata.id}|{nodata.orderid}|{nodata.moduleid}|{nodata.szzyorderid}|mainid:{nodata.MainSzzyorderid}");
|
||
//}
|
||
}
|
||
|
||
Logger.Info("入库成功数据:" + addlist.Count());
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "truncate table module_price_temp;", param.ToArray());//清空中间表数据
|
||
new Module_Price_BL().BulkInsertToMysql("module_price_temp", addlist);
|
||
Logger.Info("module_price_temp插入成功");
|
||
//免费单补充
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into module_price_temp(szzyorderid,moduleid,starttime2,endtime2,otime2,ctime2,orderPrice,username,opendays2,modulePrice)
|
||
select szzyorderid,moduleid,starttime2,endtime2,otime2,ctime2,0,username,opendays2,0 from module_order w where w.id not in
|
||
(
|
||
select id from module_order_jisuan t
|
||
)and w.otime2>='" + starttime.ToString("yyyy-MM-dd") + "' and w.otime2<'" + endtime.ToString("yyyy-MM-dd") + "' ;");
|
||
|
||
//==========================赠送订单关系计算==============
|
||
GifOrderJiSuan();
|
||
|
||
//计算 赠送订单关系
|
||
|
||
// //对冲天数
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"INSERT INTO `module_price`(`orderid`, `szzyorderid`, `moduleid`, `starttime2`, `endtime2`, `otime2`, `ctime2`, `orderPrice`, `modulePrice`, `midproductid`, `username`, `opendays2`,`channel`)
|
||
//select b.orderid,a.szzyorderid, a.moduleid, a.endtime2, a.endtime2,a.endtime2 otime2, a.ctime2, 0 orderPrice,0 modulePrice,x.midproductid,a.username,a.usedays-a.opendays2 opendays2,ifnull(b.channel,a.channel2)channel from module_order a
|
||
//left join wx_szzyorder b on a.szzyorderid=b.szzyorderid
|
||
//left join wx_szzysubproduct x on x.subproductid=b.subproductid
|
||
//where a.usedays<a.opendays2 and a.usedays>=0
|
||
//and not exists
|
||
//(
|
||
// select 1 from wx_szzyordermodulerefund x where x.szzyorderid=a.szzyorderid and x.ismorepay=0
|
||
//)
|
||
//;");
|
||
|
||
//退款时间大于endtime2 对冲天数
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"INSERT INTO `module_price`(`orderid`, `szzyorderid`, `moduleid`, `starttime2`, `endtime2`, `otime2`, `ctime2`, `orderPrice`, `modulePrice`, `midproductid`, `username`, `opendays2`,`channel`)
|
||
//select b.orderid,a.szzyorderid, a.moduleid, a.endtime2, a.endtime2,a.endtime2 otime2,a.ctime2, 0 orderPrice,0 modulePrice,x.midproductid,a.username,a.usedays-a.opendays2 opendays2,
|
||
//ifnull(b.channel,a.channel2)channel from module_order a
|
||
//left join wx_szzyorder b on a.szzyorderid=b.szzyorderid
|
||
//left join wx_szzysubproduct x on x.subproductid=b.subproductid
|
||
//left join (select min(bb.refunddate) refunddate,orderid from wx_szzyorderrefund bb where bb.auditstatus=1 and bb.ismorepay=0 group by bb.orderid) xax on xax.orderid=b.orderid
|
||
//where a.usedays<a.opendays2 and a.usedays>=0
|
||
//and xax.orderid is not null
|
||
//and DATE_FORMAT(xax.refunddate,'%y%m%d')>DATE_FORMAT(a.endtime2,'%y%m%d')
|
||
//;");
|
||
// 修改赠送订单的渠道号
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"
|
||
update module_price t set t.channel=
|
||
(
|
||
select x.channel from wx_szzyorder x where x.orderid=t.orderid
|
||
)
|
||
where t.channel is null or t.channel =0;
|
||
|
||
update module_price t set t.channel=(
|
||
select x.channel2 from module_order x
|
||
where x.username=t.username and x.szzyorderid<>t.szzyorderid and x.price2>0 order by x.otime2 desc limit 1
|
||
)
|
||
where t.channel is null or t.channel=16000 ;
|
||
");
|
||
|
||
// 不在模块里面的订单,摊分数据 补充
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into module_price(
|
||
orderid, szzyorderid, moduleid, starttime2, endtime2, otime2, ctime2, orderPrice, modulePrice, midproductid, username, opendays2,isBu,channel
|
||
)
|
||
select a.orderid, b.szzyorderid,CONCAT(x.midproductid,ifnull(tea.teacher,'')) moduleid,a.starttime starttime2,a.endtime endtime2,a.otime otime2,b.ctime ctime2,
|
||
a.arrivalpay orderPrice,a.arrivalpay modulePrice,x.midproductid,a.softusername username,
|
||
if((b.opendays+ifnull(b.giftdays,0))=0,(xx.opendays+ifnull(xx.giftdays,0)),(b.opendays+ifnull(b.giftdays,0))) opendays2,1 isBu,b.channel
|
||
from wx_szzyorder_redefine_time a
|
||
left join wx_szzyorder_handle b on a.orderid=b.orderid
|
||
left join wx_szzyorder xx on xx.orderid=a.orderid
|
||
left join wx_szzysubproduct x on x.subproductid=b.subproductid
|
||
left join order_teacher tea on tea.orderid=a.orderid
|
||
where a.orderid not in
|
||
(
|
||
select orderid from wx_szzyorder where szzyorderid in(
|
||
select szzyorderid from module_order_jisuan where price2>0 group by szzyorderid
|
||
)
|
||
)
|
||
;");
|
||
|
||
// Logger.Info("插入无端终止的模块数据");
|
||
|
||
// //计算 苹果、华为、魅族平台数据 //复制金额数据
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text,
|
||
// @"update module_price t set t.modulePrice2= t.modulePrice;");
|
||
|
||
// //计算金额至中间表
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"truncate table module_price_pingtai;");
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"
|
||
//insert into module_price_pingtai(id,paytype,modulePrice)
|
||
//select a.id,b.paytype,
|
||
//(
|
||
//case
|
||
//when b.paytype=11 then a.modulePrice*0.68607
|
||
//when b.paytype=12 then a.modulePrice*0.68760
|
||
//when b.paytype=13 then a.modulePrice*0.686
|
||
//end
|
||
//)
|
||
//modulePrice
|
||
//from module_price a
|
||
//left join wx_szzyorderpay b on a.orderid = b.orderid
|
||
//where paytype is not NULL and b.paytype in(11,12,13);
|
||
//");
|
||
|
||
// //修改金额至正式表
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price t set t.modulePrice=(select x.modulePrice from module_price_pingtai x where x.id=t.id)
|
||
//where exists (select 1 from module_price_pingtai x where x.id=t.id);");
|
||
|
||
//MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price t set t.orderPrice=0,t.modulePrice=0,t.modulePrice2=0 where orderid=80075948;");
|
||
//修改一天摊分数据加
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"update module_price t set t.isoneday=1 where orderid in(select orderid from test_nowteacher)");
|
||
|
||
Logger.Info("入库成功!");
|
||
|
||
//}
|
||
//catch
|
||
//{
|
||
// throw;
|
||
//}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 赠送订单关系情况(第二版)
|
||
/// </summary>
|
||
private static void GifOrderJiSuan()
|
||
{
|
||
using (AuditContext db = new AuditContext())
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
|
||
string sql = @"select a.* from module_price_temp a
|
||
order by a.username,a.otime2,a.orderPrice desc,a.id;";
|
||
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
List<Module_Price_Temp> list = dataSet.Tables[0].ToList<Module_Price_Temp>();
|
||
Dictionary<string, List<Module_Price_Temp>> dic = new Dictionary<string, List<Module_Price_Temp>>();//主订单作为key
|
||
Dictionary<string, int> dicxuhao = new Dictionary<string, int>();
|
||
foreach (var item in list)
|
||
{
|
||
if (!dic.ContainsKey(item.username))
|
||
{
|
||
item.xuhao = 1;
|
||
dic.Add(item.username, new List<Module_Price_Temp>() { item });
|
||
dicxuhao.Add(item.username, 1);
|
||
}
|
||
else
|
||
{
|
||
dicxuhao[item.username] = dicxuhao[item.username] + 1;
|
||
item.xuhao = dicxuhao[item.username];
|
||
dic[item.username].Add(item);
|
||
}
|
||
}
|
||
string[] needJiSuan = { "1010", "1031", "1038" };//1010,1031,1038
|
||
|
||
string[] gemok8 = { "1010", "1028", "1031", "1038", "1011", "1012", "1082", "1018", "1167", "1162", "1163", "1183", "1184", "1185" };
|
||
string[] notmoduleid = { "1162", "1183", "1184", "1185" };
|
||
List<Module_Price_Temp> moduleNeed = new List<Module_Price_Temp>();
|
||
foreach (var item in dic)
|
||
{
|
||
foreach (Module_Price_Temp my in item.Value)
|
||
{
|
||
my.id = 0;
|
||
if (my.orderid.HasValue && my.orderid.Value > 0)//有价订单跳过
|
||
{
|
||
if (my.modulePrice > 0)//必须是有价模块才入库
|
||
moduleNeed.Add(my);//有价订单直接入库
|
||
continue;
|
||
}
|
||
|
||
var entry = item.Value.LastOrDefault(m => m.xuhao < my.xuhao && m.orderPrice > 0 && !notmoduleid.Contains(m.moduleid));//查找第一个有价订单集合体
|
||
if (entry == null)
|
||
{
|
||
var oldprice = db.Module_Price.Where(m => gemok8.Contains(m.moduleid) && !notmoduleid.Contains(m.moduleid) && m.orderPrice > 0 && m.username == my.username).OrderByDescending(m => m.otime2).FirstOrDefault();
|
||
if (oldprice != null)
|
||
entry = new Module_Price_Temp()
|
||
{
|
||
orderid = oldprice.orderid,
|
||
szzyorderid = oldprice.szzyorderid,
|
||
channel = oldprice.channel,
|
||
modulePrice = Convert.ToDecimal(oldprice.modulePrice)
|
||
};
|
||
}
|
||
if (entry == null)//找不到前面的有价订单
|
||
{
|
||
continue;
|
||
}
|
||
else
|
||
{
|
||
//赠送订单计算 如果是1010,1031,1038 需要查找目标订单ID
|
||
if (needJiSuan.Contains(my.moduleid))
|
||
{
|
||
my.orderid = entry.orderid;
|
||
moduleNeed.Add(my);
|
||
}
|
||
else
|
||
{
|
||
var modulelist = item.Value.Where(m => m.szzyorderid == entry.szzyorderid);//所有模块
|
||
var count = modulelist.Where(m => m.moduleid == my.moduleid && m.modulePrice > 0).Count();//主模块金额大于零
|
||
if (count == 0)
|
||
{
|
||
count = db.Module_Price.Where(m => gemok8.Contains(m.moduleid) && m.username == entry.username && m.szzyorderid == entry.szzyorderid && m.moduleid == my.moduleid && m.modulePrice > 0).Count();//从旧数据中查找
|
||
}
|
||
if (count > 0)
|
||
{
|
||
my.orderid = entry.orderid;
|
||
moduleNeed.Add(my);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
new Module_Price_Temp_BL().BulkInsertToMysql("module_price", moduleNeed);
|
||
Logger.Info("module_price插入成功");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 订单升级关系循环计算
|
||
/// </summary>
|
||
public static void Moudle_Order_Upgrade()
|
||
{
|
||
using (AuditContext db = new AuditContext())
|
||
|
||
{
|
||
#region 数据源用全量数据跑
|
||
|
||
string sql2 = @"select a.id,a.username,a.moduleid,a.szzyorderid,a.productcode2,a.starttime2,a.endtime2,a.usedays,a.subproductname2,a.opendays2,a.totaldays,a.price2,a.ctime2,a.otime2,ifnull(b.channel,a.channel2) channel2,a.status2,a.isrefund,a.canceluser,a.canceltime,a.returnPrice,b.arrivalpay,b.orderid,x.midproductid,b.resid from module_order a
|
||
left join wx_szzyorder b on a.szzyorderid=b.szzyorderid
|
||
left join wx_szzysubproduct x on x.subproductid=b.subproductid
|
||
where a.otime2<'" + endtime.ToString("yyyy-MM-dd") + @"'
|
||
order by a.username,a.otime2,a.price2 desc,a.id;
|
||
";
|
||
|
||
DataSet dataSet2 = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql2);
|
||
List<Module_Order> list2 = dataSet2.Tables[0].ToList<Module_Order>();
|
||
Dictionary<string, List<Module_Order>> dic = new Dictionary<string, List<Module_Order>>();
|
||
Dictionary<string, int> dicxuhao2 = new Dictionary<string, int>();
|
||
foreach (var item in list2)
|
||
{
|
||
if (!dic.ContainsKey(item.username))
|
||
{
|
||
item.xuhao = 1;
|
||
dic.Add(item.username, new List<Module_Order>() { item });
|
||
dicxuhao2.Add(item.username, 1);
|
||
}
|
||
else
|
||
{
|
||
dicxuhao2[item.username] = dicxuhao2[item.username] + 1;
|
||
item.xuhao = dicxuhao2[item.username];
|
||
dic[item.username].Add(item);
|
||
}
|
||
}
|
||
|
||
#endregion 数据源用全量数据跑
|
||
|
||
//string sql = @"select t.resid,t.orderid,t.subproductid,t.subproductname,t.needpay,t.upgradeorderids,t.szzyorderid,t.ctime,t.otime,t.arrivalpay,t.softusername
|
||
//from wx_szzyorder_handle t
|
||
//where t.otime is not null
|
||
//and t.otime>='" + starttime.ToString("yyyy-MM-dd") + @"'
|
||
//and t.otime<'" + endtime.ToString("yyyy-MM-dd") + @"'
|
||
//and
|
||
//(
|
||
// (t.channel>=2000 and t.channel<=2199)
|
||
// or
|
||
// (t.channel>=2400 and t.channel<=2499)
|
||
// or
|
||
// (t.channel>=2200 and t.channel<=2399)
|
||
// or
|
||
// (t.channel>=1000 and t.channel<=1099)
|
||
// or
|
||
// (t.channel>=2500 and t.channel<=2599)
|
||
// or
|
||
// (t.channel>=3000 and t.channel<=3099)
|
||
// or
|
||
// (t.channel>=4000 and t.channel<=4999)
|
||
// or
|
||
// (t.channel>=5000 and t.channel<=5999)
|
||
// or
|
||
// (t.channel>=26800 and t.channel<=26899)#呱呱平台运营中心
|
||
//)
|
||
//order by otime;";
|
||
string sql = @"select t.resid,t.orderid,t.subproductid,t.subproductname,t.needpay,t.upgradeorderids,t.szzyorderid,t.ctime,t.otime,t.arrivalpay,t.softusername
|
||
from wx_szzyorder_handle t
|
||
where t.otime is not null
|
||
and t.otime>='" + starttime.ToString("yyyy-MM-dd") + @"'
|
||
and t.otime<'" + endtime.ToString("yyyy-MM-dd") + @"'
|
||
|
||
order by otime;";
|
||
var param = new List<MySqlParameter> { };
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "delete from Module_Order_Upgrad where new_otime>='" + starttime.ToString("yyyy-MM-dd") + "' and new_otime<'" + endtime.ToString("yyyy-MM-dd") + "';", param.ToArray());//清空中间表数据
|
||
List<Ord_Upgrade> list = dataSet.Tables[0].ToList<Ord_Upgrade>();
|
||
Module_Order_Upgrad_BL bl = new Module_Order_Upgrad_BL();
|
||
List<CRM.Core.Model.EntityAudit.Module_Order_Upgrad> uplist = new List<CRM.Core.Model.EntityAudit.Module_Order_Upgrad>();
|
||
foreach (var item in list)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(item.upgradeorderids))
|
||
{
|
||
continue;//本单不是升级单,就直接跳过
|
||
}
|
||
var upgradids = item.upgradeorderids.Split(',');//分割数据
|
||
|
||
foreach (var upid in upgradids)
|
||
{
|
||
if (string.IsNullOrWhiteSpace(upid))
|
||
{
|
||
continue;
|
||
}
|
||
var orderid = Convert.ToInt32(upid);
|
||
//var old = list.FirstOrDefault(m => m.orderid == orderid);
|
||
if (dic.ContainsKey(item.softusername))
|
||
{
|
||
var old = dic[item.softusername].FirstOrDefault(m => m.orderid == orderid);
|
||
if (old == null)
|
||
{
|
||
old = list2.FirstOrDefault(m => m.orderid == orderid);//实在同用户名找不到,就从所有的数据中查找
|
||
}
|
||
if (old == null)
|
||
{
|
||
var xxold = db.Wx_Szzyorder_Handle.FirstOrDefault(m => m.ORDERID == orderid);
|
||
old = new Module_Order()
|
||
{
|
||
orderid = Convert.ToInt32(xxold.ORDERID),
|
||
otime2 = xxold.OTIME,
|
||
username = xxold.SOFTUSERNAME,
|
||
szzyorderid = xxold.SZZYORDERID.ToString()
|
||
};
|
||
}
|
||
var model = new CRM.Core.Model.EntityAudit.Module_Order_Upgrad
|
||
{
|
||
new_orderid = item.orderid,
|
||
new_otime = item.otime,
|
||
new_resid = item.resid,
|
||
new_szzyorderid = item.szzyorderid,
|
||
new_username = item.softusername,
|
||
old_orderid = old.orderid.Value,
|
||
old_otime = old.otime2,
|
||
//old_resid = old.resid,
|
||
old_szzyorderid = Convert.ToInt64(old.szzyorderid),
|
||
old_username = old.username
|
||
};
|
||
string szzyorderid = model.old_szzyorderid.ToString();
|
||
model.isbeclose = dic[model.old_username].Where(m => m.szzyorderid == szzyorderid && m.opendays2 > m.usedays).Count() > 0 ? 1 : 0;
|
||
uplist.Add(model);
|
||
}
|
||
else
|
||
{
|
||
var old = db.Wx_Szzyorder_Handle.FirstOrDefault(m => m.ORDERID == orderid);
|
||
//var old = dic[item.softusername].FirstOrDefault(m => m.orderid == orderid);
|
||
var model = new CRM.Core.Model.EntityAudit.Module_Order_Upgrad
|
||
{
|
||
new_orderid = item.orderid,
|
||
new_otime = item.otime,
|
||
new_resid = item.resid,
|
||
new_szzyorderid = item.szzyorderid,
|
||
new_username = item.softusername,
|
||
old_orderid = Convert.ToInt32(old.ORDERID),
|
||
old_otime = old.OTIME,
|
||
//old_resid = old.resid,
|
||
old_szzyorderid = Convert.ToInt64(old.SZZYORDERID),
|
||
old_username = old.SOFTUSERNAME
|
||
};
|
||
string szzyorderid = model.old_szzyorderid.ToString();
|
||
model.isbeclose = 1;
|
||
uplist.Add(model);
|
||
}
|
||
}
|
||
}
|
||
|
||
Logger.Info("升级关系订单数量:" + uplist.Count());
|
||
bl.BulkInsertToMysql("Module_Order_Upgrad", uplist);
|
||
}
|
||
}
|
||
|
||
public class Ord_Upgrade
|
||
{
|
||
public string resid { get; set; }
|
||
public int orderid { get; set; }
|
||
public int subproductid { get; set; }
|
||
public string subproductname { get; set; }
|
||
public decimal needpay { get; set; }
|
||
public string upgradeorderids { get; set; }
|
||
public long szzyorderid { get; set; }
|
||
public DateTime? ctime { get; set; }
|
||
public DateTime? otime { get; set; }
|
||
public decimal arrivalpay { get; set; }
|
||
public string softusername { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 订金清洗
|
||
/// </summary>
|
||
public static void DingJinClear()
|
||
{
|
||
Logger.Info("开始处理wx_order_payclear:");
|
||
//创建 金额清洗表
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"DROP TABLE IF EXISTS `wx_order_payclear`;
|
||
CREATE TABLE `wx_order_payclear` (
|
||
`id` int(0) NOT NULL AUTO_INCREMENT,
|
||
`payid` int(0) NULL DEFAULT 0,
|
||
`orderid` int(0) NULL DEFAULT NULL COMMENT '订单号',
|
||
`payprice` decimal(10, 2) NULL DEFAULT NULL COMMENT '支付金额',
|
||
`paydate` datetime(0) NULL DEFAULT NULL COMMENT '支付时间',
|
||
`usedate` datetime(0) NULL DEFAULT NULL COMMENT '支付时间',
|
||
`usestatus` int(0) NOT NULL DEFAULT 0 COMMENT 'usestatus=0 未使用 usestatus=1 已使用',
|
||
`usetype` int(0) NOT NULL DEFAULT 0 COMMENT 'usertype=0 只付款 usertype=1 正向使用 usertype=-1 退款',
|
||
`useprice` decimal(24, 6) NULL DEFAULT NULL COMMENT '计算了苹果支付、魅族支付、华为支付手续费后的金额',
|
||
`useprice2` decimal(24, 6) NULL DEFAULT NULL COMMENT '原始金额',
|
||
`channel` int(0) NULL DEFAULT NULL COMMENT '渠道',
|
||
PRIMARY KEY (`id`) USING BTREE,
|
||
INDEX `ix_orderid`(`orderid`) USING BTREE
|
||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
|
||
");
|
||
Logger.Info("开始处理wx_order_payclear:插入otime的正向数据");
|
||
//#插入otime的正向数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @" insert into wx_order_payclear(payid,orderid,payprice,paydate,usedate,usestatus,usetype,useprice,channel)
|
||
select t.id payid,t.orderid,t.payprice,t.paydate,x.otime,1,1,t.payprice,t.channel from wx_szzyorderpay t
|
||
join wx_szzyorder x on x.orderid=t.orderid
|
||
where x.otime is not null
|
||
and x.orderstatus in(220,205,80,90)
|
||
and t.auditstatus=1;");
|
||
Logger.Info("开始处理wx_order_payclear:插入无otime退款数据");
|
||
// 插入有otime虚拟退款负数数据
|
||
var sql = @"insert into wx_order_payclear(payid, orderid, usedate, usestatus, usetype, useprice, channel)
|
||
select 0,xass.orderid,xass.audittime,1,-1,-xass.refundprice,xass.channel from wx_szzyorderrefund xass where xass.id in(
|
||
select DISTINCT f.id #,t.id payid,t.orderid,t.payprice,t.paydate,f.refunddate usedate,1 usestatus,1,f.refundprice
|
||
from wx_szzyorderpay t
|
||
join wx_szzyorder x on x.orderid = t.orderid
|
||
left join(select ax.*from wx_szzyorderrefund ax where ax.auditstatus = 1 and ax.isacturalrefund = 0) f on f.orderid = t.orderid
|
||
where x.otime is not null
|
||
and t.auditstatus = 1
|
||
and f.refundprice is not null ); ";
|
||
var i= MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info($"开始处理wx_order_payclear:插入有otime虚拟退款负数数据,影响{i}");
|
||
|
||
//插入无otime退款数据
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into wx_order_payclear(payid,orderid,usedate,usestatus,usetype,useprice,channel)
|
||
select 0,xass.orderid,xass.audittime,1,-1,xass.refundprice,xass.channel from wx_szzyorderrefund xass where xass.id in(
|
||
select DISTINCT f.id #,t.id payid,t.orderid,t.payprice,t.paydate,f.refunddate usedate,1 usestatus,1,f.refundprice
|
||
from wx_szzyorderpay t
|
||
join wx_szzyorder x on x.orderid=t.orderid
|
||
left join(select ax.* from wx_szzyorderrefund ax where ax.auditstatus=1) f on f.orderid=t.orderid
|
||
where x.otime is null
|
||
and t.auditstatus=1
|
||
and f.refundprice is not null
|
||
);");
|
||
Logger.Info("开始处理wx_order_payclear:插入余额退款数据");
|
||
//余额退款
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into wx_order_payclear(payid,orderid,usedate,usestatus,usetype,useprice,channel)
|
||
select 0,t.orderid,t.audittime,1,-1,t.refundprice,t.channel
|
||
from wx_szzyorderrefund t where t.isdelete=0 and t.auditstatus=1 and t.orderid like'2%';");
|
||
|
||
//更新呱呱历史数据
|
||
|
||
sql = "update wx_order_payclear p LEFT JOIN module_price m on m.orderid=p.orderid set p.usedate=m.otime2 where MONTh(m.otime2)<>MONTh(p.usedate) and m.modulePrice>0 and (p.channel >= 26800 and p.channel <= 26899) ";
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql);
|
||
Logger.Info("开始处理wx_order_payclear:更新呱呱历史数据usedate");
|
||
//重置平台一paycalear
|
||
// Logger.Info("开始处理wx_order_payclear:重置平台一paycalear");
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"delete from wx_order_payclear where channel >= 25000 and channel <= 26199;");
|
||
// MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, @"insert into wx_order_payclear( payid, orderid, payprice, paydate, usedate, usestatus, usetype, useprice, useprice2, channel )
|
||
// SELECT payid, orderid, payprice, paydate, usedate, usestatus, usetype, useprice, useprice2, channel FROM zxdcrm_audit_pt1.wx_order_payclear AS x");
|
||
|
||
Logger.Info("结束处理wx_order_payclear:");
|
||
}
|
||
|
||
/// <summary>
|
||
/// 被关闭的订单,进行挪价值
|
||
/// </summary>
|
||
public static void ModuleMovePrice()
|
||
{
|
||
using (AuditContext db = new AuditContext())
|
||
{
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 计算了时间
|
||
/// </summary>
|
||
/// <param name="args"></param>
|
||
private void MainOld(string[] args)
|
||
{
|
||
Logger.Info("开始计算:");
|
||
using (AuditContext db = new AuditContext())
|
||
{
|
||
//开通的订单
|
||
var openord = db.Wx_Szzyorder_Handle.Where(m => m.OTIME != null && m.ARRIVALPAY > 1);//有开通时间,表示已经开通了
|
||
//退款订单
|
||
var tuikorder = from a in db.WX_SzzyOrderRefund
|
||
join b in openord on a.orderid equals b.ORDERID
|
||
join c in db.WX_SZZYSUBPRODUCT on b.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
where b.ORDERSTATUS == "90"
|
||
where a.auditstatus == 1
|
||
// where a.channel < 25000 where a.channel > 26199
|
||
select new Ord
|
||
{
|
||
orderid = a.orderid,
|
||
optime = a.audittime.Value,
|
||
type = "TK",
|
||
midproduct = c.MidProductId.Value,
|
||
softusername = b.SOFTUSERNAME
|
||
};
|
||
//将退款订单和 开通的订单进行合并成一个集合
|
||
var allord = (from b in openord
|
||
join c in db.WX_SZZYSUBPRODUCT on b.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
select new Ord
|
||
{
|
||
orderid = b.ORDERID,
|
||
optime = b.OTIME.Value,
|
||
type = "OD",
|
||
midproduct = c.MidProductId.Value,
|
||
softusername = b.SOFTUSERNAME
|
||
}).Union(
|
||
tuikorder
|
||
)
|
||
;
|
||
var ordList2 = allord.OrderBy(m => m.optime).ToList();
|
||
foreach (var item in ordList2)
|
||
{
|
||
if (item.type == "OD")
|
||
{
|
||
item.optime = item.optime.Date;
|
||
}
|
||
else
|
||
{
|
||
item.optime = item.optime.Date.AddSeconds(1);
|
||
}
|
||
}
|
||
var ordList = ordList2.OrderBy(m => m.optime).ToList();
|
||
//try
|
||
//{
|
||
foreach (var item in ordList)
|
||
{
|
||
/*
|
||
新订单 金额累加,叠加时长
|
||
复购 擒龙版买擒龙版,至尊版买至尊版 金额累加,叠加时长
|
||
时长升级 补差价升级高时长版本 金额累加,时长用新订单时长
|
||
产品升级 擒龙版买至尊版 金额累加,时长用新订单时长
|
||
退复购 退绝对金额,减该订单时长;剩余价值低于0,时长清零
|
||
退时长升级 退绝对金额,减该订单时长;剩余价值低于0,时长清零
|
||
退产品升级 退绝对金额,时长不变;剩余价值低于0,时长清零
|
||
产品状态 :
|
||
在用 1
|
||
未使用 2
|
||
用完 3
|
||
退款 4
|
||
被升级 5
|
||
擒龙买至尊 6
|
||
|
||
擒龙版ID:100800101
|
||
至尊版本ID:100800201
|
||
*/
|
||
//普通订单
|
||
var entry = db.Wx_Szzyorder_Handle.FirstOrDefault(m => m.ORDERID == item.orderid);
|
||
|
||
//升级订单判断
|
||
if (!string.IsNullOrEmpty(entry.UPGRADEORDERIDS))
|
||
{
|
||
//var uporders = Array.ConvertAll(entry.UPGRADEORDERIDS.Split(','), decimal.Parse); ;
|
||
//var uporderList = db.WX_SzzyOrder_Redefine.Where(m => uporders.Contains(m.orderid)).ToList();//被升级的订单
|
||
//foreach (var up in uporderList)//循环被升级的订单
|
||
//{
|
||
// if (up.endtime > entry.OTIME.Value)
|
||
// {
|
||
// up.endtime = entry.OTIME.Value;
|
||
// UpdateWX_SzzyOrder_Redefine(db, up);//将被升级的订单修改数据
|
||
|
||
// var rdlist = db.WX_SzzyOrder_Redefine.Where(m => m.softusername ==
|
||
// up.softusername && m.midproductid == up.midproductid && m.starttime >
|
||
// entry.OTIME.Value); foreach (var rd in rdlist) { } }
|
||
|
||
//}
|
||
|
||
//WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
//{
|
||
// orderid = item.orderid,
|
||
// softusername = item.softusername,
|
||
// ordertype = "升级订单",
|
||
// starttime = entry.OTIME.Value,
|
||
// endtime = entry.OTIME.Value.AddDays(Convert.ToInt32(entry.OPENDAYS.Value) + (entry.giftdays.HasValue ? Convert.ToInt32(entry.giftdays.Value) : 0))//开通时间+赠送时间
|
||
//};
|
||
//db.WX_SzzyOrder_Redefine.Add(model);
|
||
}
|
||
else//非升级订单
|
||
{
|
||
//订单
|
||
if (item.type == "OD")
|
||
{
|
||
var oldOrd = (from b in openord
|
||
join c in db.WX_SZZYSUBPRODUCT on b.SUBPRODUCTID equals c.SUBPRODUCTID
|
||
where b.SOFTUSERNAME == item.softusername
|
||
where b.OTIME < item.optime
|
||
where b.UPGRADEORDERIDS != null
|
||
where b.UPGRADEORDERIDS != ""
|
||
//where c.MidProductId == item.midproduct
|
||
select new NewOrd()
|
||
{
|
||
ord = b,
|
||
midproduct = c.MidProductId.Value
|
||
}
|
||
).ToList();
|
||
if (oldOrd.Count() == 0)//新订单
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = item.orderid,
|
||
softusername = item.softusername,
|
||
ordertype = "新订单",
|
||
starttime = entry.OTIME.Value,
|
||
endtime = entry.OTIME.Value.AddDays(Convert.ToInt32(entry.OPENDAYS.Value) + (entry.giftdays.HasValue ? Convert.ToInt32(entry.giftdays.Value) : 0))//开通时间+赠送时间
|
||
,
|
||
midproductid = item.midproduct
|
||
};
|
||
db.WX_SzzyOrder_Redefine.Add(model);
|
||
db.SaveChanges();
|
||
}
|
||
else//复购
|
||
{
|
||
var nowlist = oldOrd.Where(m => m.midproduct == item.midproduct);//当前分类一样
|
||
if (nowlist.Count() == 0)//非同类型产品
|
||
{ //当前订单为至尊版本
|
||
if (item.midproduct == 100800201)
|
||
{
|
||
var qinlonglist = oldOrd.Where(m => m.midproduct == 100800101);//擒龙版订单
|
||
if (qinlonglist.Count() > 0)//如果有擒龙版订单
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = item.orderid,
|
||
softusername = item.softusername,
|
||
ordertype = "擒龙复购至尊",
|
||
starttime = entry.OTIME.Value,
|
||
endtime = entry.OTIME.Value.AddDays(Convert.ToInt32(entry.OPENDAYS.Value) + (entry.giftdays.HasValue ? Convert.ToInt32(entry.giftdays.Value) : 0))//开通时间+赠送时间
|
||
,
|
||
midproductid = item.midproduct
|
||
};
|
||
db.WX_SzzyOrder_Redefine.Add(model);
|
||
db.SaveChanges();
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = item.orderid,
|
||
softusername = item.softusername,
|
||
ordertype = "至尊版新单",
|
||
starttime = entry.OTIME.Value,
|
||
endtime = entry.OTIME.Value.AddDays(Convert.ToInt32(entry.OPENDAYS.Value) + (entry.giftdays.HasValue ? Convert.ToInt32(entry.giftdays.Value) : 0))//开通时间+赠送时间
|
||
,
|
||
midproductid = item.midproduct
|
||
};
|
||
db.WX_SzzyOrder_Redefine.Add(model);
|
||
db.SaveChanges();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = item.orderid,
|
||
softusername = item.softusername,
|
||
ordertype = "新订单",
|
||
starttime = entry.OTIME.Value,
|
||
endtime = entry.OTIME.Value.AddDays(Convert.ToInt32(entry.OPENDAYS.Value) + (entry.giftdays.HasValue ? Convert.ToInt32(entry.giftdays.Value) : 0))//开通时间+赠送时间
|
||
,
|
||
midproductid = item.midproduct
|
||
};
|
||
db.WX_SzzyOrder_Redefine.Add(model);
|
||
db.SaveChanges();
|
||
}
|
||
}//同类型产品复购
|
||
else
|
||
{
|
||
var preModel = db.WX_SzzyOrder_Redefine.Where(m => m.softusername == entry.SOFTUSERNAME && m.midproductid == item.midproduct).OrderByDescending(m => m.endtime).FirstOrDefault();//上一个订单
|
||
if (preModel != null)
|
||
{
|
||
WX_SzzyOrder_Redefine model = new WX_SzzyOrder_Redefine()
|
||
{
|
||
orderid = item.orderid,
|
||
softusername = item.softusername,
|
||
ordertype = "同类产品复购",
|
||
starttime = preModel.endtime,
|
||
endtime = preModel.endtime.Value.AddDays(Convert.ToInt32(entry.OPENDAYS.Value) + (entry.giftdays.HasValue ? Convert.ToInt32(entry.giftdays.Value) : 0))//开通时间+赠送时间
|
||
,
|
||
midproductid = item.midproduct
|
||
};
|
||
db.WX_SzzyOrder_Redefine.Add(model);
|
||
db.SaveChanges();
|
||
}
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//退款订单
|
||
var tuid = db.WX_SzzyOrder_Redefine.FirstOrDefault(m => m.orderid == item.orderid);
|
||
if (tuid.endtime > item.optime && tuid.starttime < item.optime)
|
||
{
|
||
var dayj = (tuid.endtime.Value.Date - item.optime.Date).Days;
|
||
tuid.endtime = item.optime;
|
||
UpdateWX_SzzyOrder_Redefine(db, tuid);//修改当前订单的结束时间
|
||
|
||
var preModelList = db.WX_SzzyOrder_Redefine.Where(m => m.softusername == entry.SOFTUSERNAME && m.midproductid == item.midproduct && m.starttime > item.optime && m.orderid != tuid.orderid).OrderBy(m => m.endtime);//上一个订单
|
||
foreach (var pre in preModelList)
|
||
{
|
||
pre.starttime = pre.starttime.Value.AddDays(-dayj);
|
||
pre.endtime = pre.endtime.Value.AddDays(-dayj);
|
||
UpdateWX_SzzyOrder_Redefine(db, pre);//修改当前订单的结束时间
|
||
}
|
||
}
|
||
else if (tuid.starttime > item.optime)
|
||
{
|
||
var dayj = (tuid.endtime.Value.Date - tuid.starttime.Value.Date).Days;
|
||
//tuid.starttime = item.starttime;
|
||
tuid.endtime = tuid.starttime;
|
||
UpdateWX_SzzyOrder_Redefine(db, tuid);//修改当前订单的结束时间
|
||
|
||
var preModelList = db.WX_SzzyOrder_Redefine.Where(m => m.softusername == entry.SOFTUSERNAME && m.midproductid == item.midproduct && m.starttime > item.optime && m.orderid != tuid.orderid).OrderBy(m => m.endtime);//上一个订单
|
||
foreach (var pre in preModelList)
|
||
{
|
||
pre.starttime = pre.starttime.Value.AddDays(-dayj);
|
||
pre.endtime = pre.endtime.Value.AddDays(-dayj);
|
||
UpdateWX_SzzyOrder_Redefine(db, pre);//修改当前订单的结束时间
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//Logger.Info(item.orderid);
|
||
}
|
||
//}
|
||
//catch (Exception e)
|
||
//{
|
||
// Logger.Info("出现错误:" +e.ToString());
|
||
//}
|
||
}
|
||
//Console.ReadLine();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 修改状态表数据
|
||
/// </summary>
|
||
/// <param name="db"></param>
|
||
/// <param name="model"></param>
|
||
public static void UpdateWX_SzzyOrder_Redefine(AuditContext db, WX_SzzyOrder_Redefine model)
|
||
{
|
||
var entry = db.WX_SzzyOrder_Redefine.FirstOrDefault(m => m.orderid == model.orderid);
|
||
entry.ordertype = model.ordertype;
|
||
entry.softusername = model.softusername;
|
||
entry.starttime = model.starttime;
|
||
entry.endtime = model.endtime;
|
||
entry.status = model.status;
|
||
entry.statusname = model.statusname;
|
||
db.SaveChanges();
|
||
}
|
||
|
||
#region 补差升级
|
||
|
||
/// <summary>
|
||
/// 补差升级计算
|
||
/// </summary>
|
||
// public static void Upgrade_JiSuan() { using (AuditContext db = new AuditContext()) { try
|
||
// { Module_Price_Upgrade_BL bl = new Module_Price_Upgrade_BL(); var param = new
|
||
// List<MySqlParameter> { }; // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn,
|
||
// CommandType.Text, @"DROP TABLE IF EXISTS `test_fuopendays`; //CREATE TABLE
|
||
// `test_fuopendays` ( // `szzyorderid` varchar(50) CHARACTER SET utf8mb4 COLLATE
|
||
// utf8mb4_general_ci NULL DEFAULT NULL, // `opendays2` int(0) NULL DEFAULT NULL COMMENT
|
||
// '开通(天)', // `MainSzzyorderid` varchar(100) CHARACTER SET utf8 COLLATE utf8_general_ci
|
||
// NULL DEFAULT NULL, // INDEX `IX_MainSzzyorderid`(`MainSzzyorderid`) USING BTREE //)
|
||
// ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT =
|
||
// Dynamic; //SET FOREIGN_KEY_CHECKS = 1;
|
||
|
||
// //insert into test_fuopendays(szzyorderid,opendays2,MainSzzyorderid)
|
||
// //select tt.szzyorderid,tt.opendays2,t2.MainSzzyorderid from module_price tt
|
||
// //join module_order_jisuan t2 on tt.szzyorderid=t2.szzyorderid where tt.opendays2<0;
|
||
// //truncate table Module_Price_Upgrade;
|
||
// //drop table IF EXISTS `test_xxsss`;
|
||
// //", param.ToArray());
|
||
// string sql = @"
|
||
//create table test_xxsss
|
||
//as
|
||
//select x.id,orderid,szzyorderid,moduleid,starttime2,endtime2,otime2,ctime2,orderPrice,modulePrice,midproductid,
|
||
//username,opendays2,isBu,isoneday,channel,modulePrice2,isVirOrder,isRunRefundIns,
|
||
//(
|
||
//select if(count(*)=0,0,1) from module_price tt
|
||
//where tt.szzyorderid=x.szzyorderid and tt.opendays2<0
|
||
//)+
|
||
//(
|
||
//select if(count(*)=0,0,1) from test_fuopendays s2
|
||
//where x.szzyorderid =s2.MainSzzyorderid
|
||
//)
|
||
//jiancount ,
|
||
//DATEDIFF(x.endtime2,x.starttime2) useday
|
||
//from module_price x
|
||
//where x.username in
|
||
//(
|
||
// select t.username from module_price t
|
||
// where DATEDIFF(t.endtime2,t.starttime2)<>t.opendays2
|
||
// and t.moduleid in('1012','1011','1082','1018','1028','1010','1031','1038')
|
||
// and t.opendays2<0
|
||
//)
|
||
//and x.moduleid in('1012','1011','1082','1018','1028','1010','1031','1038')
|
||
//and x.opendays2>0
|
||
//order by x.username,x.otime2;";
|
||
// // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, sql, param.ToArray());
|
||
// DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, "select * from test_xxsss t;", param.ToArray());
|
||
// List<Module_Price_Upgrade> list = dataSet.Tables[0].ToList<Module_Price_Upgrade>();
|
||
// Dictionary<string, List<Module_Price_Upgrade>> dic = new Dictionary<string, List<Module_Price_Upgrade>>();
|
||
// Dictionary<string, int> dicxuhao = new Dictionary<string, int>();
|
||
// foreach (var item in list)
|
||
// {
|
||
// if (!dic.ContainsKey(item.username))
|
||
// {
|
||
// item.xuhao = 1;
|
||
// dic.Add(item.username, new List<Module_Price_Upgrade>() { item });
|
||
// dicxuhao.Add(item.username, 1);
|
||
// }
|
||
// else
|
||
// {
|
||
// dicxuhao[item.username] = dicxuhao[item.username] + 1;
|
||
// item.xuhao = dicxuhao[item.username];
|
||
// dic[item.username].Add(item);
|
||
// }
|
||
// }
|
||
// List<Module_Price_Upgrade> histList = new List<Module_Price_Upgrade>();
|
||
// foreach (var item in dic)
|
||
// {
|
||
// foreach (var ord in item.Value)
|
||
// {
|
||
// if (ord.jiancount > 0)
|
||
// {
|
||
// //&& m.realstarttime_2 == ord.realendtime_2
|
||
// var nextBigOrd = item.Value.Where(m => m.xuhao > ord.xuhao && m.moduleid == ord.moduleid && m.modulePrice > 0).OrderBy(m => m.xuhao).FirstOrDefault();//下一个订单模块
|
||
// if (nextBigOrd != null)
|
||
// {
|
||
// if (ord.useday == ord.opendays2)
|
||
// {
|
||
// continue;
|
||
// }
|
||
// Module_Price_Upgrade oldhist = new Module_Price_Upgrade
|
||
// {
|
||
// orderid = ord.orderid,
|
||
// targetOrderid = nextBigOrd.orderid,
|
||
// jiancount = ord.jiancount,
|
||
// moduleid = ord.moduleid,
|
||
// changePrice = -((ord.opendays2 - ord.useday) * ord.modulePrice / ord.opendays2),
|
||
// channel = ord.channel,
|
||
// opendays2 = ord.useday - ord.opendays2,//补充复天数
|
||
// modulePrice = ord.modulePrice,
|
||
// useday = ord.useday,
|
||
// endtime2 = ord.endtime2,
|
||
// ctime2 = ord.ctime2,
|
||
// id = ord.id,
|
||
// isBu = ord.isBu,
|
||
// isoneday = ord.isoneday,
|
||
// isRunRefundIns = ord.isRunRefundIns,
|
||
// isVirOrder = ord.isVirOrder,
|
||
// midproductid = ord.midproductid,
|
||
// modulePrice2 = ord.modulePrice2,
|
||
// orderPrice = ord.orderPrice,
|
||
// otime2 = ord.otime2,
|
||
// starttime2 = ord.starttime2,
|
||
// szzyorderid = ord.szzyorderid,
|
||
// type = "减金额",
|
||
// username = ord.username,
|
||
// xuhao = ord.xuhao
|
||
// };
|
||
// Module_Price_Upgrade newhist = new Module_Price_Upgrade
|
||
// {
|
||
// orderid = nextBigOrd.orderid,
|
||
// targetOrderid = nextBigOrd.orderid,
|
||
// jiancount = nextBigOrd.jiancount,
|
||
// moduleid = nextBigOrd.moduleid,
|
||
// changePrice = ((ord.opendays2 - ord.useday) * ord.modulePrice / ord.opendays2),
|
||
// channel = nextBigOrd.channel,
|
||
// opendays2 = nextBigOrd.opendays2,//
|
||
// modulePrice = nextBigOrd.modulePrice,
|
||
// useday = nextBigOrd.useday,
|
||
// endtime2 = nextBigOrd.endtime2,
|
||
// ctime2 = nextBigOrd.ctime2,
|
||
// id = nextBigOrd.id,
|
||
// isBu = nextBigOrd.isBu,
|
||
// isoneday = nextBigOrd.isoneday,
|
||
// isRunRefundIns = nextBigOrd.isRunRefundIns,
|
||
// isVirOrder = nextBigOrd.isVirOrder,
|
||
// midproductid = nextBigOrd.midproductid,
|
||
// modulePrice2 = nextBigOrd.modulePrice2,
|
||
// orderPrice = nextBigOrd.orderPrice,
|
||
// otime2 = nextBigOrd.otime2,
|
||
// starttime2 = nextBigOrd.starttime2,
|
||
// szzyorderid = nextBigOrd.szzyorderid,
|
||
// type = "加金额",
|
||
// username = nextBigOrd.username,
|
||
// xuhao = nextBigOrd.xuhao
|
||
// };
|
||
// nextBigOrd.modulePrice = nextBigOrd.modulePrice + ((ord.opendays2 - ord.useday) * ord.modulePrice / ord.opendays2);
|
||
// histList.Add(oldhist);
|
||
// histList.Add(newhist);
|
||
// }
|
||
// else
|
||
// {
|
||
// if (ord.useday == ord.opendays2)
|
||
// {
|
||
// continue;
|
||
// }
|
||
// Module_Price_Upgrade oldhist = new Module_Price_Upgrade
|
||
// {
|
||
// orderid = ord.orderid,
|
||
// targetOrderid = null,
|
||
// jiancount = ord.jiancount,
|
||
// moduleid = ord.moduleid,
|
||
// changePrice = 0,
|
||
// channel = ord.channel,
|
||
// opendays2 = ord.useday - ord.opendays2,//补充复天数
|
||
// modulePrice = ord.modulePrice,
|
||
// useday = ord.useday,
|
||
// endtime2 = ord.endtime2,
|
||
// ctime2 = ord.ctime2,
|
||
// id = ord.id,
|
||
// isBu = ord.isBu,
|
||
// isoneday = ord.isoneday,
|
||
// isRunRefundIns = ord.isRunRefundIns,
|
||
// isVirOrder = ord.isVirOrder,
|
||
// midproductid = ord.midproductid,
|
||
// modulePrice2 = ord.modulePrice2,
|
||
// orderPrice = ord.orderPrice,
|
||
// otime2 = ord.otime2,
|
||
// starttime2 = ord.starttime2,
|
||
// szzyorderid = ord.szzyorderid,
|
||
// type = "减天数",
|
||
// username = ord.username,
|
||
// xuhao = ord.xuhao
|
||
// };
|
||
// histList.Add(oldhist);
|
||
// }
|
||
// }
|
||
|
||
// } } bl.BulkInsertToMysql("Module_Price_Upgrade", histList); } catch (Exception e) { throw
|
||
// e; } }
|
||
|
||
// }
|
||
|
||
#endregion 补差升级
|
||
|
||
public static void Upgrade_JiSuan2()
|
||
{
|
||
var param = new List<MySqlParameter> { };
|
||
|
||
Module_Price_Upgrade_BL bl = new Module_Price_Upgrade_BL();
|
||
|
||
MySqlDbHelper.ExecuteNonQuery(ConStringHelper.AuditConn, CommandType.Text, "truncate table Module_Price_Upgrade;", param.ToArray());
|
||
DataSet main = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, @"select t.szzyorderid,t.MainSzzyorderid,count(*)nc from module_order_jisuan t group by t.szzyorderid,t.MainSzzyorderid; ", param.ToArray());
|
||
List<MainOrder> mainlist = main.Tables[0].ToList<MainOrder>();
|
||
Dictionary<string, string> orderMain = new Dictionary<string, string>();
|
||
foreach (var item in mainlist)
|
||
{
|
||
if (!orderMain.ContainsKey(item.szzyorderid))
|
||
{
|
||
orderMain.Add(item.szzyorderid, item.MainSzzyorderid);
|
||
}
|
||
}
|
||
|
||
DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.AuditConn, CommandType.Text, @"select t.* from module_price t
|
||
where t.moduleid in('1012','1011','1082','1018','1028','1010','1031','1038','1167','1162','1163','1183','1184','1185')
|
||
order by otime2, modulePrice; ", param.ToArray());
|
||
List<Module_Price_M> list = dataSet.Tables[0].ToList<Module_Price_M>();
|
||
Dictionary<string, List<Module_Price_M>> dic = new Dictionary<string, List<Module_Price_M>>();
|
||
Dictionary<string, int> dicxuhao = new Dictionary<string, int>();
|
||
foreach (var item in list)
|
||
{
|
||
if (!dic.ContainsKey(item.username))
|
||
{
|
||
item.xuhao = 1;
|
||
dic.Add(item.username, new List<Module_Price_M>() { item });
|
||
dicxuhao.Add(item.username, 1);
|
||
}
|
||
else
|
||
{
|
||
dicxuhao[item.username] = dicxuhao[item.username] + 1;
|
||
item.xuhao = dicxuhao[item.username];
|
||
dic[item.username].Add(item);
|
||
}
|
||
}
|
||
List<Module_Price_Upgrade> histList = new List<Module_Price_Upgrade>();
|
||
///循环用户 module_price 数据
|
||
foreach (var item in dic)
|
||
{
|
||
foreach (Module_Price_M ord in item.Value)
|
||
{
|
||
if (ord.opendays2 < 0)//发现小于零的数据
|
||
{
|
||
if (!orderMain.ContainsKey(ord.szzyorderid))
|
||
{
|
||
Module_Price_Upgrade oldhist = new Module_Price_Upgrade
|
||
{
|
||
orderid = ord.orderid,
|
||
targetOrderid = null,
|
||
jiancount = 0,
|
||
moduleid = ord.moduleid,
|
||
changePrice = 0,//金额
|
||
channel = ord.channel,
|
||
opendays2 = ord.opendays2,//补充复天数
|
||
modulePrice = ord.modulePrice,
|
||
endtime2 = ord.endtime2,
|
||
ctime2 = ord.ctime2,
|
||
id = ord.id,
|
||
isBu = ord.isBu,
|
||
isoneday = ord.isoneday,
|
||
midproductid = ord.midproductid,
|
||
modulePrice2 = ord.modulePrice2,
|
||
orderPrice = ord.orderPrice,
|
||
otime2 = ord.otime2,
|
||
starttime2 = ord.starttime2,
|
||
szzyorderid = ord.szzyorderid,
|
||
type = "减天数2",
|
||
username = ord.username,
|
||
xuhao = ord.xuhao
|
||
};
|
||
histList.Add(oldhist);
|
||
continue;
|
||
}
|
||
string ManOrderid = orderMain[ord.szzyorderid];//主ID
|
||
|
||
var nextBigOrd = item.Value.Where(m => m.moduleid == ord.moduleid && m.xuhao > ord.xuhao && m.modulePrice > 0).OrderBy(m => m.xuhao).FirstOrDefault();//查找下一个数据
|
||
if (nextBigOrd != null)
|
||
{
|
||
var prvBigOrd = item.Value.Where(m => m.moduleid == ord.moduleid && m.szzyorderid == ManOrderid && m.xuhao < ord.xuhao && m.modulePrice > 0).OrderBy(m => m.xuhao).FirstOrDefault();//上一个订单
|
||
if (prvBigOrd == null)
|
||
{
|
||
Module_Price_Upgrade oldhist = new Module_Price_Upgrade
|
||
{
|
||
orderid = ord.orderid,
|
||
targetOrderid = null,
|
||
jiancount = 0,
|
||
moduleid = ord.moduleid,
|
||
changePrice = 0,//金额
|
||
channel = ord.channel,
|
||
opendays2 = ord.opendays2,//补充复天数
|
||
modulePrice = ord.modulePrice,
|
||
endtime2 = ord.endtime2,
|
||
ctime2 = ord.ctime2,
|
||
id = ord.id,
|
||
isBu = ord.isBu,
|
||
isoneday = ord.isoneday,
|
||
midproductid = ord.midproductid,
|
||
modulePrice2 = ord.modulePrice2,
|
||
orderPrice = ord.orderPrice,
|
||
otime2 = ord.otime2,
|
||
starttime2 = ord.starttime2,
|
||
szzyorderid = ord.szzyorderid,
|
||
type = "减天数1",
|
||
username = ord.username,
|
||
xuhao = ord.xuhao
|
||
};
|
||
histList.Add(oldhist);
|
||
}
|
||
else
|
||
{
|
||
Module_Price_Upgrade oldhist = new Module_Price_Upgrade
|
||
{
|
||
orderid = ord.orderid,
|
||
targetOrderid = nextBigOrd.orderid,
|
||
jiancount = 0,
|
||
moduleid = ord.moduleid,
|
||
changePrice = ord.opendays2 * prvBigOrd.modulePrice / prvBigOrd.opendays2,
|
||
channel = ord.channel,
|
||
opendays2 = ord.opendays2,//补充复天数
|
||
modulePrice = ord.modulePrice,
|
||
endtime2 = ord.endtime2,
|
||
ctime2 = ord.ctime2,
|
||
id = ord.id,
|
||
isBu = ord.isBu,
|
||
isoneday = ord.isoneday,
|
||
midproductid = ord.midproductid,
|
||
modulePrice2 = ord.modulePrice2,
|
||
orderPrice = ord.orderPrice,
|
||
otime2 = ord.otime2,
|
||
starttime2 = ord.starttime2,
|
||
szzyorderid = ord.szzyorderid,
|
||
type = "减金额",
|
||
username = ord.username,
|
||
xuhao = ord.xuhao
|
||
};
|
||
Module_Price_Upgrade newhist = new Module_Price_Upgrade
|
||
{
|
||
orderid = nextBigOrd.orderid,
|
||
targetOrderid = nextBigOrd.orderid,
|
||
jiancount = 0,
|
||
moduleid = nextBigOrd.moduleid,
|
||
changePrice = -ord.opendays2 * prvBigOrd.modulePrice / prvBigOrd.opendays2,
|
||
channel = nextBigOrd.channel,
|
||
opendays2 = nextBigOrd.opendays2,//
|
||
modulePrice = nextBigOrd.modulePrice,
|
||
endtime2 = nextBigOrd.endtime2,
|
||
ctime2 = nextBigOrd.ctime2,
|
||
id = nextBigOrd.id,
|
||
isBu = nextBigOrd.isBu,
|
||
isoneday = nextBigOrd.isoneday,
|
||
midproductid = nextBigOrd.midproductid,
|
||
modulePrice2 = nextBigOrd.modulePrice2,
|
||
orderPrice = nextBigOrd.orderPrice,
|
||
otime2 = nextBigOrd.otime2,
|
||
starttime2 = nextBigOrd.starttime2,
|
||
szzyorderid = nextBigOrd.szzyorderid,
|
||
type = "加金额",
|
||
username = nextBigOrd.username,
|
||
xuhao = nextBigOrd.xuhao
|
||
};
|
||
nextBigOrd.modulePrice = nextBigOrd.modulePrice - ord.opendays2 * prvBigOrd.modulePrice / prvBigOrd.opendays2;
|
||
histList.Add(oldhist);
|
||
histList.Add(newhist);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Module_Price_Upgrade oldhist = new Module_Price_Upgrade
|
||
{
|
||
orderid = ord.orderid,
|
||
targetOrderid = null,
|
||
jiancount = 0,
|
||
moduleid = ord.moduleid,
|
||
changePrice = 0,//金额
|
||
channel = ord.channel,
|
||
opendays2 = ord.opendays2,//补充复天数
|
||
modulePrice = ord.modulePrice,
|
||
endtime2 = ord.endtime2,
|
||
ctime2 = ord.ctime2,
|
||
id = ord.id,
|
||
isBu = ord.isBu,
|
||
isoneday = ord.isoneday,
|
||
midproductid = ord.midproductid,
|
||
modulePrice2 = ord.modulePrice2,
|
||
orderPrice = ord.orderPrice,
|
||
otime2 = ord.otime2,
|
||
starttime2 = ord.starttime2,
|
||
szzyorderid = ord.szzyorderid,
|
||
type = "减天数2",
|
||
username = ord.username,
|
||
xuhao = ord.xuhao
|
||
};
|
||
histList.Add(oldhist);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
bl.BulkInsertToMysql("Module_Price_Upgrade", histList);
|
||
}
|
||
|
||
public class module_Price_Group
|
||
{
|
||
public decimal orderid { get; set; }
|
||
public string szzyorderid { get; set; }
|
||
|
||
public DateTime? starttime2 { get; set; }
|
||
public DateTime? endtime2 { get; set; }
|
||
public DateTime? otime2 { get; set; }
|
||
public int midproductid { get; set; }
|
||
public string username { get; set; }
|
||
public int? opendays2 { get; set; }
|
||
public int? channel { get; set; }
|
||
public string teacher { get; set; }
|
||
}
|
||
|
||
public class upgradeorderidsInfo
|
||
{
|
||
public int orderid { get; set; }
|
||
public string upgradeorderids { get; set; }
|
||
public DateTime? otime { get; set; }
|
||
public string softusername { get; set; }
|
||
public int channel { get; set; }
|
||
}
|
||
|
||
public class Ord
|
||
{
|
||
public string softusername { get; set; }
|
||
public decimal orderid { get; set; }
|
||
|
||
/// <summary>
|
||
/// 操作时间,订单开通时间,或者退款的审核时间
|
||
/// </summary>
|
||
public DateTime optime { get; set; }
|
||
|
||
/// <summary>
|
||
/// TK:退款订单 OD:订单
|
||
/// </summary>
|
||
public string type { get; set; }
|
||
|
||
public int midproduct { get; set; }
|
||
}
|
||
|
||
public class NewOrd
|
||
{
|
||
public Wx_Szzyorder_Handle ord { get; set; }
|
||
public int midproduct { get; set; }
|
||
public DateTime tuiTime { get; set; }
|
||
public string teacher { get; set; }
|
||
public int xuhao { get; set; }
|
||
public DateTime? old_otime { get; set; }
|
||
public string type { get; set; }
|
||
}
|
||
|
||
public class WX_SzzyOrder_Redefine_MAP
|
||
{
|
||
public WX_SzzyOrder_Redefine entry { get; set; }
|
||
|
||
public DateTime otime { get; set; }
|
||
public string teacher { get; set; }
|
||
|
||
/// <summary>
|
||
/// 0需要入库的,1需要修改的
|
||
/// </summary>
|
||
public int tpe { get; set; }
|
||
|
||
public int isUpdate { get; set; }
|
||
}
|
||
|
||
public class Module_Price_M
|
||
{
|
||
public string MainSzzyorderid { get; set; }
|
||
public int id { get; set; }
|
||
public int? orderid { get; set; }
|
||
public string szzyorderid { get; set; }
|
||
public string moduleid { get; set; }
|
||
public DateTime? starttime2 { get; set; }
|
||
public DateTime? endtime2 { get; set; }
|
||
public DateTime? otime2 { get; set; }
|
||
public DateTime? ctime2 { get; set; }
|
||
public decimal? orderPrice { get; set; }
|
||
public decimal? modulePrice { get; set; }
|
||
public int? midproductid { get; set; }
|
||
public string username { get; set; }
|
||
public int? opendays2 { get; set; }
|
||
public int? isBu { get; set; }
|
||
public int? isoneday { get; set; }
|
||
public int? channel { get; set; }
|
||
public decimal? modulePrice2 { get; set; }
|
||
public int xuhao { get; set; }
|
||
}
|
||
|
||
public class XinMeiti2
|
||
{
|
||
public int orderid { get; set; }
|
||
public string username { get; set; }
|
||
public decimal arrivalpay { get; set; }
|
||
public int channel { get; set; }
|
||
public int opendays { get; set; }
|
||
public DateTime otime { get; set; }
|
||
public DateTime arrivaltime { get; set; }
|
||
public int midproductid { get; set; }
|
||
public string outid_2 { get; set; }
|
||
public string nickname_2 { get; set; }
|
||
public string teacherid_2 { get; set; }
|
||
public string teacher_2 { get; set; }
|
||
public string pay_2 { get; set; }
|
||
public DateTime arrivaltime_2 { get; set; }
|
||
public DateTime realstarttime_2 { get; set; }
|
||
public DateTime realservicetime_2 { get; set; }
|
||
public DateTime realendtime_2 { get; set; }
|
||
public int servericeday_2 { get; set; }
|
||
public int xuhao { get; set; }
|
||
public string resid { get; set; }
|
||
public DateTime? ctime { get; set; }
|
||
public long szzyorderid { get; set; }
|
||
public string teacher { get; set; }
|
||
}
|
||
|
||
//public class Xinmeiti2_PriceChangeHis
|
||
//{
|
||
// public int orderid { get; set; }
|
||
// public int targetOrderid { get; set; }
|
||
// public decimal oldPrice { get; set; }
|
||
// public decimal changePrice { get; set; }
|
||
// public decimal newPrice { get; set; }
|
||
// public string type { get; set; }
|
||
// public int channel { get; set; }
|
||
// public int opendays { get; set; }
|
||
// public int serviceday_2 { get; set; }
|
||
//}
|
||
public class GongYunJia
|
||
{
|
||
public string ModeulId { get; set; }
|
||
public double Price { get; set; }
|
||
public Dictionary<string, double> nianDic { get; set; }
|
||
|
||
/// <summary>
|
||
/// 是否 参与摊分
|
||
/// </summary>
|
||
public bool IsTanFen { get; set; }
|
||
}
|
||
|
||
public class Modeule_Info
|
||
{
|
||
public string ModuleId { get; set; }
|
||
public int opendays2 { get; set; }
|
||
public DateTime? starttime2 { get; set; }
|
||
public DateTime? endtime2 { get; set; }
|
||
public double modulePrice { get; set; }
|
||
|
||
/// <summary>
|
||
/// 公允加个
|
||
/// </summary>
|
||
public double gongyunPrice { get; set; }
|
||
}
|
||
|
||
public class MainOrder
|
||
{
|
||
public string szzyorderid { get; set; }
|
||
public string MainSzzyorderid { get; set; }
|
||
}
|
||
}
|
||
} |