using CRM.Core.BLL.Wx; using CRM.Core.DAL; using CRM.Core.Model; using CRM.Core.Model.Entity; using MySql.Data.MySqlClient; using System; using System.Collections.Generic; using System.Data; using System.Linq; using WX.CRM.Common; namespace Program_DingBan { /* * 复制订单表 wx_szzyorder_handle -- 找出实际退款的数据 select x.orderid,sum(x.refundprice),max(t.arrivalpay),sum(x.refundprice)/max(t.arrivalpay) 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 ; -- 修改没有更改订单状态的表为已退款 update wx_szzyorder_handle ww set ww.orderstatus=90 where ww.orderid in ( 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 ) */ 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 nianDic { get; set; } /// /// 是否 参与摊分 /// 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; } /// /// 公允加个 /// public double gongyunPrice { get; set; } } public class MainOrder { public string szzyorderid { get; set; } public string MainSzzyorderid { get; set; } } class Program { /// /// 二次审计版本2.0 /// /// public static void Main2(string[] args) { #region 第二版 //MainOrd(args);//订单定性 //MainTime(args);//订单时间计算 #endregion //MainModle(args);//订单模块计算 ModulePriceJiSuan();//计算金额 和天数 DingJinClear();//计算 苹果、魅族、华为平台支付扣除 手续费后金额 XinMeiti2_PriceJisuan();//新媒体二数据 //Upgrade_JiSuan2();//软件 补差升级计算(放弃) Console.WriteLine("全部执行ok================="); Console.ReadLine(); } /// /// 合并住ID的操作 /// /// public static void MainModle(string[] args) { Module_Order_BL bll = new Module_Order_BL(); using (zxdContext db = new zxdContext()) { var param = new List { }; MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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<'2021-10-1' order by a.username,a.otime2,a.price2 desc,a.id; "; DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, sql, param.ToArray()); List list = dataSet.Tables[0].ToList(); Dictionary> dic = new Dictionary>(); Dictionary dicxuhao = new Dictionary(); foreach (var item in list) { if (!dic.ContainsKey(item.username)) { item.xuhao = 1; dic.Add(item.username, new List() { 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(dic); //return; List addlist = new List(); Console.WriteLine("数据循环计算!"); ///根据用户循环模块订单数据 foreach (var item in dic) { foreach (var cd in item.Value)//本用户所有模块列表 { if (cd.price2 == 0) { //没钱订单模块排除 continue; } cd.MainSzzyorderid = cd.szzyorderid; addlist.Add(cd);//添加主订单 } } Console.WriteLine("入库成功数据:" + addlist.Count()); bll.BulkInsertToMysql("module_order_jisuan", addlist); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "truncate table module_order_jisuan_price;", param.ToArray());//清空中间表数据 Console.WriteLine("module_order_jisuan_price清理成功"); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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());//清空中间表数据 Console.WriteLine("插入计算数据成功!"); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "update module_order_jisuan set orderPrice=null;", param.ToArray());//清空中间表数据 Console.WriteLine("module_order_jisuan的orderPrice改成NULL成功"); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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());//清空中间表数据 Console.WriteLine("入库成功!"); } } public static void ModulePriceJiSuan() { Module_Order_BL bll = new Module_Order_BL(); using (zxdContext db = new zxdContext()) { //try //{ var param = new List { }; MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "truncate table module_price;", param.ToArray());//清空中间表数据 string sql = @"select a.* from module_order_jisuan a where a.otime2<'2021-10-01' order by a.username,a.otime2,a.price2 desc,a.id;"; DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, sql, param.ToArray()); List list = dataSet.Tables[0].ToList(); Dictionary> dic = new Dictionary>();//主订单作为key foreach (var item in list) { if (!dic.ContainsKey(item.MainSzzyorderid)) { dic.Add(item.MainSzzyorderid, new List() { item }); } else { dic[item.MainSzzyorderid].Add(item); } } List addlist = new List(); Console.WriteLine("数据循环计算!"); Dictionary midprodcut_moduleid = new Dictionary(); 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 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 List infoList = new List(); 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) { 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 = (midprodcut_moduleid.ContainsKey(Convert.ToInt32(infoitem.midproductid)) && midprodcut_moduleid[Convert.ToInt32(infoitem.midproductid)].ModeulId == infoitem.moduleid) ? Convert.ToDouble(infoitem.orderPrice) : Convert.ToDouble(0) }; 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) //{ // Console.WriteLine($"找不到的模块数据:{nodata.id}|{nodata.orderid}|{nodata.moduleid}|{nodata.szzyorderid}|mainid:{nodata.MainSzzyorderid}"); //} } Console.WriteLine("入库成功数据:" + addlist.Count()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "truncate table module_price_temp;", param.ToArray());//清空中间表数据 new Module_Price_BL().BulkInsertToMysql("module_price_temp", addlist); Console.WriteLine("module_price_temp插入成功"); //免费单补充 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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 );"); GifOrderJiSuan(); //计算 赠送订单关系 // //对冲天数 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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=0 //and not exists //( // select 1 from wx_szzyordermodulerefund x where x.szzyorderid=a.szzyorderid and x.ismorepay=0 //) //;"); //退款时间大于endtime2 对冲天数 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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=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.ZxdCRMConn, CommandType.Text, @" //update module_price t set t.channel=( // select aa.channel from module_order x // left join wx_szzyorder aa on aa.szzyorderid=x.szzyorderid // 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; //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.ZxdCRMConn, 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 ) );"); // Console.WriteLine("插入无端终止的模块数据"); // //计算 苹果、华为、魅族平台数据 // //复制金额数据 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.modulePrice2= t.modulePrice;"); // //计算金额至中间表 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"truncate table module_price_pingtai;"); // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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.ZxdCRMConn, 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.ZxdCRMConn, CommandType.Text, @"update module_price t set t.orderPrice=0,t.modulePrice=0,t.modulePrice2=0 where orderid=80075948;"); //修改一天摊分数据加 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.isoneday=1 where orderid in(select orderid from test_nowteacher)"); Console.WriteLine("入库成功!"); //} //catch //{ // throw; //} } } /// /// 赠送订单关系情况 /// private static void GifOrderJiSuan() { var param = new List { }; string sql = @"select a.* from module_price_temp a where a.otime2<'2021-10-01' order by a.username,a.otime2,a.orderPrice desc,a.id;"; DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, sql, param.ToArray()); List list = dataSet.Tables[0].ToList(); Dictionary> dic = new Dictionary>();//主订单作为key Dictionary dicxuhao = new Dictionary(); foreach (var item in list) { if (!dic.ContainsKey(item.username)) { item.xuhao = 1; dic.Add(item.username, new List() { 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 List moduleNeed = new List(); foreach (var item in dic) { foreach (Module_Price_Temp my in item.Value) { 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);//查找第一个有价订单集合体 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) { my.orderid = entry.orderid; moduleNeed.Add(my); } } } } } new Module_Price_Temp_BL().BulkInsertToMysql("module_price", moduleNeed); Console.WriteLine("module_price插入成功"); } /// /// 订单升级关系循环计算 /// public static void Moudle_Order_Upgrade(Dictionary> dic) { 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 t where t.otime is not null and t.otime<'2021-10-01' 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) ) order by otime;"; var param = new List { }; DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, sql, param.ToArray()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "truncate table Module_Order_Upgrad;", param.ToArray());//清空中间表数据 List list = dataSet.Tables[0].ToList(); Module_Order_Upgrad_BL bl = new Module_Order_Upgrad_BL(); List uplist = new List(); 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); 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, old_otime = old.otime, old_resid = old.resid, old_szzyorderid = old.szzyorderid, old_username = old.softusername }; 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); } } Console.WriteLine("升级关系订单数量:" + 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; } } /// /// 新媒体二金额下摊计算 /// public static void XinMeiti2_PriceJisuan() { Xinmeiti2_PricechangeHis_BL bl = new Xinmeiti2_PricechangeHis_BL(); var param = new List { }; //新媒体二数据excel导入后,进行starttime2、endtime2、opendays2、otime2 修改 #region 导入excel后进行 starttime2、endtime2、opendays2、otime2 修改 //将虚拟订单先删除 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"delete from module_price t where t.isVirOrder=1 and t.channel>=26800 and t.channel<26900;", param.ToArray()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"DROP TABLE IF EXISTS `xinmeiti2_time`;", param.ToArray());//清空中间表数据 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"create table xinmeiti2_time as select t.orderid,t.opendays2,t.starttime2,t.endtime2,a.实际开始时间,a.实际结束时间,a.`服务天数`,x.cname,x.softusername,x.subproductname,a.老师昵称 teacher,x.outorderno,x.arrivalpay,a.`实付金额(元)`,a.确认到款时间 from module_price t join wx_szzyorder x on x.orderid=t.orderid join xinmeiti2 a on x.outorderno=a.订单编号 #left join order_teacher tea on x.orderid=tea.orderid where t.channel>=26800 and t.channel<26900 #and t.opendays2<>a.`产品服务周期` #and x.arrivalpay<>a.`实付金额(元)` order by x.softusername,a.实际开始时间 ; ", param.ToArray()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.starttime2=(select x.`实际开始时间` from xinmeiti2_time x where x.orderid=t.orderid) where exists(select 1 from xinmeiti2_time x where x.orderid=t.orderid);", param.ToArray()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.endtime2=(select x.`实际结束时间` from xinmeiti2_time x where x.orderid=t.orderid) where exists(select 1 from xinmeiti2_time x where x.orderid=t.orderid);", param.ToArray()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.opendays2=(select x.`服务天数` from xinmeiti2_time x where x.orderid=t.orderid) where exists(select 1 from xinmeiti2_time x where x.orderid=t.orderid);", param.ToArray()); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.otime2=(select x.`确认到款时间` from xinmeiti2_time x where x.orderid=t.orderid) where exists(select 1 from xinmeiti2_time x where x.orderid=t.orderid);", param.ToArray()); #endregion //创建临时表 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"DROP TABLE IF EXISTS `xinmeiti2_pricechangehis`; CREATE TABLE `xinmeiti2_pricechangehis` ( `id` int(0) NOT NULL AUTO_INCREMENT, `orderid` int(0) NOT NULL, `targetOrderid` int(0) NULL DEFAULT NULL, `oldPrice` decimal(24, 4) NULL DEFAULT NULL, `changePrice` decimal(24, 4) NULL DEFAULT NULL, `newPrice` decimal(24, 4) NULL DEFAULT NULL, `type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL, `channel` int(0) NULL DEFAULT NULL, `opendays` int(0) NULL DEFAULT NULL, `serviceday_2` int(0) NULL DEFAULT NULL, `username` varchar(255) NULL DEFAULT NULL, `resid` varchar(255) NULL DEFAULT NULL, `realstarttime_2` datetime(0) NULL DEFAULT NULL, `realendtime_2` datetime(0) NULL DEFAULT NULL, `otime` datetime(0) NULL DEFAULT NULL, `nextstartime` datetime(0) NULL DEFAULT NULL, `szzyorderid` bigint(20) NULL DEFAULT NULL, `midproductid` int(11) NULL DEFAULT NULL, `ctime` datetime(0) NULL DEFAULT NULL, `teacher` varchar(255) NULL DEFAULT NULL, PRIMARY KEY(`id`) USING BTREE ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic; ", param.ToArray());//清空中间表数据 //MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "truncate table module_order_jisuan;", param.ToArray());//清空中间表数据 string sql = @"select x.orderid,x.szzyorderid,cc.teacher,x.ctime,x.softusername username,x.arrivalpay,x.channel,x.opendays,x.otime,x.arrivaltime,a.midproductid,x.resid,t.订单编号 outid_2,t.用户昵称 nickname_2,t.老师ID teacherid_2,t.老师昵称 teacher_2 ,t.`实付金额(元)` pay_2,t.确认到款时间 arrivaltime_2,t.实际开始时间 realstarttime_2,t.实际结束时间 realendtime_2,t.服务结束时间 realservicetime_2,t.服务天数 servericeday_2 from xinmeiti2 t join wx_szzyorder x on x.outorderno=t.订单编号 left join wx_szzysubproduct a on a.subproductid=x.subproductid left join order_teacher cc on cc.orderid=x.orderid where x.otime is not null and x.otime<'2021-10-01' and a.midproductid<>100700304 order by t.确认到款时间,x.otime; "; DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, sql, param.ToArray()); List list = dataSet.Tables[0].ToList(); Dictionary> dic = new Dictionary>(); Dictionary dicxuhao = new Dictionary(); foreach (var item in list) { if (!dic.ContainsKey(item.resid)) { item.xuhao = 1; dic.Add(item.resid, new List() { item }); dicxuhao.Add(item.resid, 1); } else { dicxuhao[item.resid] = dicxuhao[item.resid] + 1; item.xuhao = dicxuhao[item.resid]; dic[item.resid].Add(item); } } //100700303 股海擒龙专业版 //100700305 股海擒龙尊享版 //100700306 股海擒龙至尊版 ///根据用户循环 用户所有的订单 List histList = new List(); Module_Order_Upgrad_BL up_bl = new Module_Order_Upgrad_BL(); List uplist = new List(); foreach (var item in dic) { foreach (var ord in item.Value) { if (ord.servericeday_2 < ord.opendays && ord.midproductid != 100700306) { //&& m.realstarttime_2 == ord.realendtime_2 var nextBigOrd = item.Value.Where(m => m.xuhao > ord.xuhao && m.midproductid > ord.midproductid).OrderBy(m => m.xuhao).FirstOrDefault();// if (nextBigOrd != null) { var model = new CRM.Core.Model.EntityAudit.Module_Order_Upgrad { new_orderid = nextBigOrd.orderid, new_otime = nextBigOrd.otime, new_resid = nextBigOrd.resid, new_szzyorderid = nextBigOrd.szzyorderid, new_username = nextBigOrd.username, old_orderid = ord.orderid, old_otime = ord.otime, old_resid = ord.resid, old_szzyorderid = ord.szzyorderid, old_username = ord.username }; model.isbeclose = 1;// (ord.realendtime_2.Date < ord.realservicetime_2.Date)?1:0; uplist.Add(model); Xinmeiti2_PricechangeHis oldhist = new Xinmeiti2_PricechangeHis { orderid = ord.orderid, targetOrderid = nextBigOrd.orderid, channel = ord.channel, opendays = ord.opendays, serviceday_2 = ord.servericeday_2, oldPrice = ord.arrivalpay, newPrice = ord.arrivalpay - ((ord.opendays - ord.servericeday_2) * ord.arrivalpay / ord.opendays), changePrice = -((ord.opendays - ord.servericeday_2) * ord.arrivalpay / ord.opendays), type = "减金额", resid = ord.resid, username = ord.username, otime = ord.arrivaltime_2, realendtime_2 = ord.realendtime_2, realstarttime_2 = ord.realstarttime_2, nextstartime = nextBigOrd.realstarttime_2, ctime = ord.ctime, midproductid = ord.midproductid, szzyorderid = ord.szzyorderid, teacher = ord.teacher }; Xinmeiti2_PricechangeHis newhist = new Xinmeiti2_PricechangeHis { orderid = nextBigOrd.orderid, targetOrderid = nextBigOrd.orderid, channel = nextBigOrd.channel, opendays = nextBigOrd.opendays, serviceday_2 = nextBigOrd.servericeday_2, oldPrice = nextBigOrd.arrivalpay, changePrice = ((ord.opendays - ord.servericeday_2) * ord.arrivalpay / ord.opendays), newPrice = nextBigOrd.arrivalpay + ((ord.opendays - ord.servericeday_2) * ord.arrivalpay / ord.opendays), type = "加金额", resid = nextBigOrd.resid, username = nextBigOrd.username, otime = nextBigOrd.arrivaltime_2, realendtime_2 = nextBigOrd.realendtime_2, realstarttime_2 = nextBigOrd.realstarttime_2, teacher = nextBigOrd.teacher, szzyorderid = nextBigOrd.szzyorderid, midproductid = nextBigOrd.midproductid, ctime = nextBigOrd.ctime }; nextBigOrd.arrivalpay = nextBigOrd.arrivalpay + ((ord.opendays - ord.servericeday_2) * ord.arrivalpay / ord.opendays); histList.Add(oldhist); histList.Add(newhist); } } } } bl.BulkInsertToMysql("xinmeiti2_pricechangehis", histList); up_bl.BulkInsertToMysql("Module_Order_Upgrad", uplist);//新媒体二审计关系入库 //将向后摊分的钱修改进 module_price表 #region 将向后摊分的钱修改 进去module_price // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.modulePrice= t.modulePrice2+(select sum(x.changePrice) from xinmeiti2_pricechangehis x where x.orderid=t.orderid and x.type='加金额') //where exists (select 1 from xinmeiti2_pricechangehis x where x.orderid=t.orderid and x.type='加金额') and t.isVirOrder<>1 //;", param.ToArray()); // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update module_price t set t.opendays2= (select x.opendays from xinmeiti2_pricechangehis x where x.orderid=t.orderid and x.type='减金额') //where exists (select 1 from xinmeiti2_pricechangehis x where x.orderid=t.orderid and x.type='减金额') and t.isVirOrder<>1 //;", param.ToArray()); // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @" //INSERT INTO `module_price`(`orderid`, `szzyorderid`, `moduleid`, `starttime2`, `endtime2`, `otime2`, `ctime2`, `orderPrice`, `modulePrice`, `midproductid`, `username`, `opendays2`,`channel`,isVirOrder,modulePrice2) //select a.orderid,a.szzyorderid,CONCAT(a.midproductid,a.teacher), a.nextstartime, a.nextstartime,a.otime otime2, a.ctime, 0 orderPrice,a.changePrice modulePrice,a.midproductid,a.username,(a.serviceday_2-a.opendays) opendays2 //,a.channel,1 isVirOrder ,0 modulePrice2 from xinmeiti2_pricechangehis a //where a.type='减金额';", param.ToArray()); #endregion } /// /// 订金清洗 /// public static void DingJinClear() { //创建 金额清洗表 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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; "); //订金入库 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @" INSERT wx_order_payclear (payid,orderid,payprice,paydate,usedate,usestatus,usetype) select t.id payid,t.orderid,t.payprice,t.paydate,t.paydate usedate,0 usestatus,0 usetype from wx_szzyorderpay t where t.auditstatus=1 and t.orderid like '2%';"); //修改订金退款 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @" update wx_order_payclear x set x.useprice=(select t.refundprice from wx_szzyorderrefund t where x.orderid=t.orderid and t.auditstatus=1), x.usedate=(select t.audittime from wx_szzyorderrefund t where x.orderid=t.orderid and t.auditstatus=1), x.channel=(select t.channel from wx_szzyorderrefund t where x.orderid=t.orderid and t.auditstatus=1), x.usestatus=1, x.usetype=-1 where exists (select 1 from wx_szzyorderrefund t where x.orderid=t.orderid and t.auditstatus=1); "); //插入otime的正向数据 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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 ; "); //插入无otime退款数据 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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 x.orderstatus in(220,205,80,90) and t.auditstatus=1 and f.refundprice is not null ); "); //数据清理 MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"delete from wx_order_payclear t where t.usestatus=0; update wx_order_payclear t set t.useprice2=t.useprice; "); // //计算平台手续费后金额 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"drop table module_price_pingtai2;"); // //付款金额计算 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"create table module_price_pingtai2 //as //select a.id,b.paytype, //( //case //when b.paytype=11 then a.useprice*0.68607 //when b.paytype=12 then a.useprice*0.68760 //when b.paytype=13 then a.useprice*0.686 //end //) //modulePrice //from wx_order_payclear a //left join wx_szzyorderpay b on a.orderid = b.orderid //where paytype is not NULL and b.paytype in(11,12,13) //and a.usetype=1;"); // //退款金额计算 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"insert into module_price_pingtai2(id,paytype,modulePrice) //select a.id,b.refundtype, //( //case //when b.refundtype=11 then a.useprice*0.68607 //when b.refundtype=12 then a.useprice*0.68760 //when b.refundtype=13 then a.useprice*0.686 //end //) //modulePrice //from wx_order_payclear a //left join wx_szzyorderrefund b on a.orderid = b.orderid //where refundtype is not NULL and b.refundtype in(11,12,13) //#and b.auditstatus=1 //and a.usetype=-1 //;"); // // 修改数据 平台支付手续费后的金额 // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"update wx_order_payclear t set t.useprice=(select x.modulePrice from module_price_pingtai2 x where x.id=t.id) //where exists (select 1 from module_price_pingtai2 x where x.id=t.id);"); } /// /// 被关闭的订单,进行挪价值 /// public static void ModuleMovePrice() { using (zxdContext db = new zxdContext()) { } } static void MainOrd(string[] args) { Console.WriteLine("开始订单性质计算:"); var param = new List { }; MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"truncate table wx_szzyorder_redefine", param.ToArray()); WX_SzzyOrder_Redefine_BL bll = new WX_SzzyOrder_Redefine_BL(); using (zxdContext db = new zxdContext()) { //开通的订单 DateTime time = new DateTime(2021, 10, 1); string[] orderstats = { "220", "205", "80", "90" }; var openord = db.Wx_Szzyorder_Handle.Where(m => m.OTIME != null && orderstats.Contains(m.ORDERSTATUS) && m.OTIME < time);//有开通时间,表示已经开通了 var ordList22 = (from b in openord 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 select new NewOrd() { ord = b, midproduct = c.MidProductId.Value, teacher = userGroup.teacher }).OrderBy(m => m.ord.OTIME).ToList(); Console.WriteLine("总订单数:" + ordList22.Count()); Dictionary> dic = new Dictionary>(); Dictionary softOrdCount = new Dictionary(); foreach (var item in ordList22) { if (!dic.ContainsKey(item.ord.SOFTUSERNAME)) { item.xuhao = 1; dic.Add(item.ord.SOFTUSERNAME, new List() { 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(); Console.WriteLine("订单客户数:" + dic.Count()); var product = db.WX_SZZYSUBPRODUCT.ToList(); List addlist = new List(); 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 i = 0; int[] productids = { 100800201, 100800202 };//至尊版,至尊VIP int[] qinlongzhizhun = { 100800101, 100800201 };//擒龙版,至尊版 Console.WriteLine("客户:" + item.Key + "订单数:" + softOrdList.Count()); foreach (var myord in softOrdList)//本用户所有订单 { if (i == 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 }; addlist.Add(model); //db.WX_SzzyOrder_Redefine.Add(model); //db.SaveChanges(); //preModel = model;// } else { if (productids.Contains(myord.midproduct)) { if (myord.midproduct == 100800202)//至尊VIP { var ooo = softOrdList.Where(m => m.midproduct == 100800202 && m.ord.OTIME < myord.ord.OTIME);//之前是否还有至尊vip if (ooo.Count() == 0)//无至尊VIP { var bb = softOrdList.Where(m => qinlongzhizhun.Contains(m.midproduct) && m.ord.OTIME < myord.ord.OTIME);//之前是否还有至尊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);//之前是否还有至尊vip if (ooo.Count() == 0)//无至尊版本 { var bb = softOrdList.Where(m => m.midproduct == 100800101 && m.ord.OTIME < myord.ord.OTIME);//之前是否还有至尊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(); 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).ToList();//小于当前订单同类产品 的集合 } else { ooo = softOrdList.Where(m => m.midproduct == myord.midproduct && m.ord.OTIME < myord.ord.OTIME).ToList();//小于当前订单同类产品 的集合 } if (ooo.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); } //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++; } } Console.WriteLine("插入数据开始========" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); //int xuhao = 0; //foreach (var item in addlist) //{ // xuhao++; // item.xuhao = xuhao; //} bll.BulkInsertToMysql("wx_szzyorder_redefine", addlist); Console.WriteLine("数据插入成功!" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss")); } //Console.ReadLine(); } /// /// 计算时长 /// /// static void MainTime(string[] args) { Console.WriteLine("订单的时间计算:"); var param = new List { }; MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, @"truncate table wx_szzyorder_redefine_time", param.ToArray()); using (zxdContext db = new zxdContext()) { 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()//左关联(用户组/部门 关系表) 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));//有开通时间,表示已经开通了 var ordList22 = (from b in openord 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 select new NewOrd() { ord = b, midproduct = c.MidProductId.Value, teacher = userGroup.teacher }).OrderBy(m => m.ord.OTIME).ToList(); Console.WriteLine("总订单数:" + ordList22.Count()); Dictionary> dic = new Dictionary>(); foreach (var item in ordList22) { if (!dic.ContainsKey(item.ord.SOFTUSERNAME)) { dic.Add(item.ord.SOFTUSERNAME, new List() { item }); } else { dic[item.ord.SOFTUSERNAME].Add(item); } } Dictionary> redefineDic = new Dictionary>(); foreach (var item in redefineList) { if (!redefineDic.ContainsKey(item.entry.softusername)) { redefineDic.Add(item.entry.softusername, new List() { item }); } else { redefineDic[item.entry.softusername].Add(item); } } #region 正向数据时间计算=========================================== Console.WriteLine("正向数据时间计算开始"); foreach (var userredlist in redefineDic)//循环用户的所有订单 处理表 { //循环当前用户的计算订单列表 foreach (var item in userredlist.Value.OrderBy(m => m.entry.xuhao)) { Console.WriteLine("订单:" + item.entry.orderid + "," + item.entry.ordertype); //当前用户的订单列表 var list = dic[item.entry.softusername]; //当前订单的明细数据(订单表) var entry = list.FirstOrDefault(m => m.ord.ORDERID == item.entry.orderid); 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));//开通时间+赠送时间 } else if (item.entry.ordertype == "复购") { //时间延期,找到同类型未过期产品 的结束时间作为开始时间 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);//找出小于当前订单 } 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));//开通时间+赠送时间 //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; // } //} } 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)//找到最近的一个至尊或者擒龙版本进行时间结束 //{ //} } } } Console.WriteLine("正向数据时间计算完毕!"); #endregion #region 退款数据时间计算 Console.WriteLine("退款数据时间计算开始!"); //退款订单 DateTime time1 = new DateTime(2021, 10, 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 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 < time1 select new NewOrd() { ord = b, midproduct = c.MidProductId.Value, tuiTime = a.refunddate.Value,//退款审核时间 teacher = userGroup.teacher }).OrderBy(m => m.tuiTime).ToList(); foreach (var item in tuikorder) { var list = dic[item.ord.SOFTUSERNAME];//退款订单对应的用户所有订单信息 var nnx = redefineDic[item.ord.SOFTUSERNAME];//计算表 用户所有订单; var entry = nnx.FirstOrDefault(m => m.entry.orderid == item.ord.ORDERID);//当期的计算订单信息 entry.entry.statusname = "退款订单"; 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; if (entry.entry.orderid == 80207870) { Console.WriteLine("a,orderid:" + entry.entry.orderid + ":pre item.tuiTime:" + item.tuiTime.ToString("yyyy-MM-dd HH:mm:ss")); } entry.entry.endtime = item.tuiTime;//修改结束时间 string[] typelis = { "复购", "新订单" }; var preModelList = new List(); 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) { Console.WriteLine("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")); Console.WriteLine("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); } else { pre.entry.starttime = pre.entry.starttime.Value.AddDays(-ss); pre.entry.endtime = pre.entry.endtime.Value.AddDays(-ss);// item.tuiTime;//正在使用的订单结束时间==退款时间// } } } 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) { Console.WriteLine("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;//修改结束时间 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) { Console.WriteLine("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")); Console.WriteLine("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); } else { pre.entry.starttime = pre.entry.starttime.Value.AddDays(-ss); pre.entry.endtime = pre.entry.endtime.Value.AddDays(-ss); } //pre.entry.starttime = pre.entry.starttime.AddDays(-dayj); //pre.entry.endtime = pre.entry.endtime.AddDays(-dayj); } } ////退款订单 //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);//修改当前订单的结束时间 // } //} } Console.WriteLine("退款数据时间计算完毕!"); #endregion WX_SzzyOrder_Redefine_Time_BL bll = new WX_SzzyOrder_Redefine_Time_BL(); List addlist = new List(); foreach (var item in redefineDic) { foreach (var map in item.Value) { 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 }); } } Console.WriteLine("数据写入"); bll.BulkInsertToMysql("wx_szzyorder_redefine_time", addlist); Console.WriteLine("数据入库结束!"); Console.ReadLine(); } } /// /// 计算了时间 /// /// void MainOld(string[] args) { Console.WriteLine("开始计算:"); using (zxdContext db = new zxdContext()) { //开通的订单 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 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);//修改当前订单的结束时间 } } } } //Console.WriteLine(item.orderid); } //} //catch (Exception e) //{ // Console.WriteLine("出现错误:" +e.ToString()); //} } Console.ReadLine(); } /// /// 修改状态表数据 /// /// /// public static void UpdateWX_SzzyOrder_Redefine(zxdContext 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(); } public class Ord { public string softusername { get; set; } public decimal orderid { get; set; } /// /// 操作时间,订单开通时间,或者退款的审核时间 /// public DateTime optime { get; set; } /// /// TK:退款订单 /// OD:订单 /// 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 class WX_SzzyOrder_Redefine_MAP { public WX_SzzyOrder_Redefine entry { get; set; } public DateTime otime { get; set; } public string teacher { 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; } } #region 补差升级 /// /// 补差升级计算 /// // public static void Upgrade_JiSuan() // { // using (zxdContext db = new zxdContext()) // { // try // { // Module_Price_Upgrade_BL bl = new Module_Price_Upgrade_BL(); // var param = new List { }; // // MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, 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.ZxdCRMConn, CommandType.Text, sql, param.ToArray()); // DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, "select * from test_xxsss t;", param.ToArray()); // List list = dataSet.Tables[0].ToList(); // Dictionary> dic = new Dictionary>(); // Dictionary dicxuhao = new Dictionary(); // foreach (var item in list) // { // if (!dic.ContainsKey(item.username)) // { // item.xuhao = 1; // dic.Add(item.username, new List() { 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 histList = new List(); // 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 { }; Module_Price_Upgrade_BL bl = new Module_Price_Upgrade_BL(); MySqlDbHelper.ExecuteNonQuery(ConStringHelper.ZxdCRMConn, CommandType.Text, "truncate table Module_Price_Upgrade;", param.ToArray()); DataSet main = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, @"select t.szzyorderid,t.MainSzzyorderid,count(*)nc from module_order_jisuan t group by t.szzyorderid,t.MainSzzyorderid; ", param.ToArray()); List mainlist = main.Tables[0].ToList(); Dictionary orderMain = new Dictionary(); foreach (var item in mainlist) { if (!orderMain.ContainsKey(item.szzyorderid)) { orderMain.Add(item.szzyorderid, item.MainSzzyorderid); } } DataSet dataSet = MySqlDbHelper.DataQueray(ConStringHelper.ZxdCRMConn, CommandType.Text, @"select t.* from module_price t where t.moduleid in('1012','1011','1082','1018','1028','1010','1031','1038') order by otime2, modulePrice; ", param.ToArray()); List list = dataSet.Tables[0].ToList(); Dictionary> dic = new Dictionary>(); Dictionary dicxuhao = new Dictionary(); foreach (var item in list) { if (!dic.ContainsKey(item.username)) { item.xuhao = 1; dic.Add(item.username, new List() { 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 histList = new List(); ///循环用户 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); } } }