using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Linq; using System.Text; using TradeModel; using NetLibrary.Data; using NetLibrary; using NetLibrary.Log; using TradeData; using NetLibrary.OnlineTrade; using NPOI.SS.UserModel; using System.ComponentModel.Design; using System.Drawing; using System.Runtime.Remoting.Metadata.W3cXsd2001; using System.Collections; using System.Web.Instrumentation; using Aspose.Pdf.Operators; using NPOI.HSSF.Model; using Aspose.Pdf; using System.Security.Cryptography; using static System.Runtime.CompilerServices.RuntimeHelpers; using System.Web; using BarcodeLib; using System.Net.Sockets; using NPOI.HSSF.Record.Formula.Functions; using ZXing; using NPOI.HSSF.Util; using System.Data.SqlClient; using Lazop.Api; namespace TradeManageNew { public class DataNew { public static List AmazonGroupPeoples = new List() { 60, 69, 182, 190, 200, 213, 216, 221, 204, 205, 206, 207, 208, 209, 210, 212, 215, 222, 229, 230, 231, 232, 233, 234, 235, 236 };//个人销售数据页面需要显示的亚马逊销售人员 #region 查询我得店铺 public static List GetMyShop(string Name, int UserId) { List list = null; string tsql = @" select * FROM JC_Shop where Master LIKE '%'+@Name+'%' OR ShopUser LIKE '%'+@Name+'%' order by ShopId"; if (UserId == 1 || UserId == 53) tsql = @" select * FROM JC_Shop where CompanyId=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Name", DbType.String, Name); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询我得店铺 public static List GetMyShop22() { List list = null; string tsql = @" select * FROM JC_Shop where CompanyId=1 order by PlatType,shopname"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 查询我得店铺 public static List GetMateShop() { List list = null; string tsql = @" SELECT DISTINCT b.ShopId,b.ShopName FROM HW_UserBuyDetail a inner JOIN JC_Shop b ON a.ShopId=b.ShopId order by ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 保存赔款申请 public static int SaveBackMoneyApply2(int BackState, DT_OrderBackMoneyApply Model) { string tsql = @" declare @BackAdvise3 nvarchar(1000),@BackAdvise4 nvarchar(1000),@IsRead int set @IsRead=1 select top 1 @Id=Id,@BackAdvise3=isnull(BackAdvise,''),@BackAdvise4=isnull(BackAdvise2,'') from DT_OrderBackMoneyApply where OrderId=@OrderId if @BackAdvise<>'' and @BackAdvise3<>@BackAdvise begin set @IsRead=0 end if @BackAdvise2<>'' and @BackAdvise3<>@BackAdvise2 begin set @IsRead=2 end if @Id>0 begin Update [DT_OrderBackMoneyApply] set [GoodsCode]=@GoodsCode,[BackReason1]=@BackReason1,[BackReason2]=@BackReason2,[BackReason3]=@BackReason3,[Remark]=@Remark,[OrderPrice]=@OrderPrice,[BackPrice]=@BackPrice,[PlanPrice]=@PlanPrice,[FactPrice]=@FactPrice,[DeptName]=@DeptName,[DeptRemark]=@DeptRemark,[ShopId]=@ShopId,[MoneyCode1]=@MoneyCode1,[MoneyCode2]=@MoneyCode2,[MoneyCode3]=@MoneyCode3,[MoneyCode4]=@MoneyCode4,BackDate=@BackDate,ImageIds=@ImageIds,[PostCode]=@PostCode,[PostFee]=@PostFee,[BackState]=@BackState,[PostFee2]=@PostFee2,[BackState2]=@BackState2,[BackType]=@BackType,[OrderState]=@OrderState,[GoodState]=@GoodState,[BackAdvise]=@BackAdvise,[BackAdvise2]=@BackAdvise2,IsRead=@IsRead where Id=@Id end else begin INSERT INTO [DT_OrderBackMoneyApply]([OrderId],[OrderCode],[GoodsCode],[BackReason1],[BackReason2],[BackReason3],[Remark],[OrderPrice],[BackPrice],[PlanPrice],[FactPrice],[InName],[InUserId],[DeptName],[DeptRemark],[CompanyRemark],[CompanyRemark2],[CompanyName1],[Indate],[CompanyDate1],[CompanyDate2],[CompanyAgree1],[CompanyAgree2],[CompanyUserId],[ShopId],[MoneyCode1],[MoneyCode2],[MoneyCode3],[MoneyCode4],[ImageIds],[BackDate],[PostCode],[PostFee],[PostFee2],[BackState],[BackState2],[BackType],[OrderState],[GoodState],[BackAdvise],[BackAdvise2])values(@OrderId,@OrderCode,@GoodsCode,@BackReason1,@BackReason2,@BackReason3,@Remark,@OrderPrice,@BackPrice,@PlanPrice,@FactPrice,@InName,@InUserId,@DeptName,@DeptRemark,@CompanyRemark,@CompanyRemark2,@CompanyName1,@Indate,@CompanyDate1,@CompanyDate2,@CompanyAgree1,@CompanyAgree2,@CompanyUserId,@ShopId,@MoneyCode1,@MoneyCode2,@MoneyCode3,@MoneyCode4,@ImageIds,@BackDate,@PostCode,@PostFee,@PostFee2,@BackState,@BackState2,@BackType,@OrderState,@GoodState,@BackAdvise,@BackAdvise2) set @Id=SCOPE_IDENTITY() end select @Id"; if (BackState == 0) { tsql = @" delete from DT_OrderBackMoneyApply where OrderId=@OrderId select 1 "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@BackReason1", DbType.String, Model.BackReason1); db.AddInParameter(cmd, "@BackReason2", DbType.String, Model.BackReason2); db.AddInParameter(cmd, "@BackReason3", DbType.String, Model.BackReason3); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OrderPrice", DbType.Decimal, Model.OrderPrice); db.AddInParameter(cmd, "@BackPrice", DbType.Decimal, Model.BackPrice); db.AddInParameter(cmd, "@PlanPrice", DbType.Decimal, Model.PlanPrice); db.AddInParameter(cmd, "@FactPrice", DbType.Decimal, Model.FactPrice); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@DeptName", DbType.String, Model.DeptName); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@CompanyRemark", DbType.String, Model.CompanyRemark); db.AddInParameter(cmd, "@CompanyRemark2", DbType.String, Model.CompanyRemark2); db.AddInParameter(cmd, "@CompanyName1", DbType.String, Model.CompanyName1); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Model.Indate); db.AddInParameter(cmd, "@CompanyDate1", DbType.DateTime, Model.CompanyDate1); db.AddInParameter(cmd, "@CompanyDate2", DbType.DateTime, Model.CompanyDate2); db.AddInParameter(cmd, "@CompanyAgree1", DbType.String, Model.CompanyAgree1); db.AddInParameter(cmd, "@CompanyAgree2", DbType.String, Model.CompanyAgree2); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@MoneyCode1", DbType.String, Model.MoneyCode1); db.AddInParameter(cmd, "@MoneyCode2", DbType.String, Model.MoneyCode2); db.AddInParameter(cmd, "@MoneyCode3", DbType.String, Model.MoneyCode3); db.AddInParameter(cmd, "@MoneyCode4", DbType.String, Model.MoneyCode4); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@CompanyUserId", DbType.String, Model.CompanyUserId); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@PostCode", DbType.String, Model.PostCode); db.AddInParameter(cmd, "@BackState", DbType.Int32, Model.BackState); db.AddInParameter(cmd, "@ImageIds", DbType.String, Model.ImageIds); db.AddInParameter(cmd, "@PostFee2", DbType.Decimal, Model.PostFee2); db.AddInParameter(cmd, "@BackState2", DbType.Int32, Model.BackState2); db.AddInParameter(cmd, "@BackType", DbType.Int32, Model.BackType); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@GoodState", DbType.Int32, Model.GoodState); db.AddInParameter(cmd, "@BackAdvise", DbType.String, Model.BackAdvise); db.AddInParameter(cmd, "@BackAdvise2", DbType.String, Model.BackAdvise2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询赔款 public static List GetListDT_OrderBackUnRead2() { List list = null; string tsql = @" SELECT * FROM dbo.DT_OrderBackMoneyApply WHERE isnull(IsRead,0)=2 order by Indate desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable dt = db.ExecuteDataTable(cmd); list = dt.ToList(); return list; } #endregion #region 修改采购单 public static void UpdateChaseStateForHWC(int ChaseId, int PostState) { string tsql = @" update CG_PurchaseHWC set PostState=@PostState where ChaseId=@ChaseId update CG_PurchaseGoodsHWC set PState=@PostState where ChaseId=@ChaseId and PState<6 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); db.AddInParameter(cmd, "@PostState", DbType.Int32, PostState); db.ExecuteNonQuery(cmd); } #endregion public static List GetPurchaseGoodsForHWC(int ChaseId) { string query = " select a.Id,C.GoodsId,a.ChaseId,PostionCode=isnull(a.PostionCode,''),GoodsCode=isnull(c.GoodsCode,''),c.GoodsOldCode,a.GoodsDetailId,GoodsNum=b.GoodsNum,a.GoodsPrice,a.LockNum,a.IsOrder,a.CompanyId,a.InGoodsNum,DetailId=a.GoodsDetailId,Price=b.Price,OldBuyNum=a.GoodsNum,BuyNum=a.GoodsNum,BuyMoney=a.GoodsPrice,c.GoodsName,b.TypeCode,b.SKU1,b.TypeDesc,b.GoodsPlanNum,b.GoodsInNum,GoodsLeftNum=b.GoodsNum+b.GoodsInNum-b.GoodsPlanNum,ErrorNum=0,Error='',c.FirstImgUrl,SJOutNum=isnull(a.SJOutNum,0),OutInNum=isnull(a.OutInNum,0) from CG_PurchaseGoodsHWC a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.ChaseId=@ChaseId order by c.GoodsId,b.TypeCode "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@ChaseId", DbType.Int32, ChaseId); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } public static List GetPurchaseGoodsOutHWC(int ChaseId) { string query = " select a.Id,b.DetailId,c.GoodsCode,c.GoodsName,b.TypeDesc,FirstImgUrl=case when b.FirstImgUrl is not null or b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end,SJOutNum=isnull(SJOutNum,0), a.OutNum,a.OutInNum,Solid=isnull(c.Solid,0),a.GoodsPrice,a.GoodsNum,IsAdd=0 from CG_PurchaseGoodsHWC a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.ChaseId=@ChaseId order by c.GoodsId,b.TypeCode "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@ChaseId", DbType.Int32, ChaseId); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } public static List GetOrderGoodsPostionList(string OrderIds) { string query = @" select a.*,b.StoreId,b.PostionId,b.KCNum into #ls from DT_OrderGoods a with(nolock) inner join HW_GoodsInDetail b with(nolock) on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") select a.OrderId,c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,d.PostionCode,GoodsNum=a.Num,c.GoodsId,OldTypeDesc=b.SKU1,LockNum=d.SortNo from (select OrderId,DetailId,PostionId,Num=sum(KCNum) from #ls group by OrderId,DetailId,PostionId)a inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId --inner join #ls e on a.OrderId=e.OrderId and a.DetailId=e.DetailId inner join CK_StorePostion d with(nolock) on a.PostionId=d.PostionId order by d.SortNo,d.PostionCode,c.GoodsCode drop table #ls"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@OrderIds", DbType.String, OrderIds); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } public static List GetOrderGoodsPostionHWC2(string OrderIds) { string query = @" select a.OrderId,c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,d.PostionCode,GoodsNum=a.Num,c.GoodsId,OldTypeDesc=b.SKU1,LockNum=d.SortNo from (select a.OrderId,a.DetailId,b.PostionId,Num=sum(b.KCNum) from DT_OrderGoods a inner join HW_GoodsInDetailHWC b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") group by a.OrderId,a.DetailId,b.PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join (select * from DT_OrderGoods where OrderId in (" + OrderIds + @")) e on a.OrderId=e.OrderId and a.DetailId=e.DetailId inner join CK_StorePostion d on a.PostionId=d.PostionId order by d.SortNo,d.PostionCode,c.GoodsCode"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@OrderIds", DbType.String, OrderIds); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } #region 查询订单明细匹配库位 public static List GetOrderGoodsPostionList22(string OrderIds) { List list = null; string tsql = @" select c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,d.PostionCode,GoodsNum=a.Num,OldTypeDesc=b.SKU1,LockNum=d.SortNo from ( select a.DetailId,b.PostionId,Num=sum(b.KCNum) from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") group by a.DetailId,b.PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId order by d.SortNo,d.PostionCode,c.GoodsCode,a.Num desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配库位 public static List GetOrderGoodsInfos(string OrderIds) { List list = null; string tsql = @" select a.OrderId,c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,a.GoodsNum,OldTypeDesc=b.SKU1,Weight=case when c.Weight2 is not null then c.Weight2 when c.Weight is not null then c.Weight*0.035274 else 0 end,c.Long2,c.Width2,c.Height2,c.Long,c.Width,c.Height from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId where a.OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物 public static List GetPurchaseGoodsOut2(int ChaseId) { List list = null; string tsql = @" select a.Id,c.GoodsCode,c.GoodsName,b.TypeDesc,FirstImgUrl=case when b.FirstImgUrl is not null or b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end,SJOutNum=isnull(SJOutNum,0), a.OutNum,a.OutInNum,Solid=isnull(c.Solid,0),a.GoodsPrice,a.GoodsNum,IsAdd=0,GoodsRate=isnull(a.GoodsRate,0) from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.GJChaseId=@ChaseId order by c.GoodsId,b.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询采购货物 public static List GetPurchaseGoodsForTM3(int ChaseId) { List list = null; string tsql = @" select a.Id,C.GoodsId,a.ChaseId,PostionCode=isnull(a.PostionCode,''),GoodsCode=isnull(c.GoodsCode,''),c.GoodsOldCode,a.GoodsDetailId,GoodsNum=b.GoodsNum,a.GoodsPrice,a.LockNum,a.IsOrder,a.CompanyId,a.InGoodsNum,DetailId=a.GoodsDetailId,Price=b.Price,OldBuyNum=a.GoodsNum,BuyNum=a.GoodsNum,BuyMoney=a.GoodsPrice,c.GoodsName,b.TypeCode,b.SKU1,b.TypeDesc,b.GoodsPlanNum,b.GoodsInNum,GoodsLeftNum=b.GoodsNum+b.GoodsInNum-b.GoodsPlanNum,ErrorNum=0,Error='',c.FirstImgUrl,SJOutNum=isnull(a.SJOutNum,0),OutInNum=isnull(a.OutInNum,0),GoodsRate=isnull(a.GoodsRate,0) from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.GJChaseId=@ChaseId order by c.GoodsId,b.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询未分配合并订单 public static List GetNoFPOrderList2(int CompanyId) { List list = null; string tsql = @" select a.JoinOrderCode from DT_OrderInfo a left join DT_OrderGoods b on a.OrderId=b.OrderId and b.DetailId>0 where CompanyId=@CompanyId and a.State=1 and a.IsJoin=1 and (b.Id is null or a.PostState=2)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public static List GetMateOrderGoodsInForHWC(int DetailId, int StoreId) { List list = null; string tsql = @" select *,b.PostionCode from HW_GoodsInDetailHWC a inner join CK_StorePostion b on a.PostionId=b.PostionId where DetailId=@DetailId and b.StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by b.SortNo,a.KCNum desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的库存 public static List GetNowKCGoodsHWC(int CompanyId, int orderstate, int StoreId) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId,b.PostionCode from HW_GoodsInDetailHWC a inner join CK_StorePostion b on a.PostionId=b.PostionId where a.CompanyId=@CompanyId and OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.CompanyId=@CompanyId and c.MateState=0 and c.PostState=0 and c.State=1 and c.FPDate is not null) order by b.SortNo,a.KCNum desc"; } else { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId,b.PostionCode from HW_GoodsInDetailHWC a inner join CK_StorePostion b on a.PostionId=b.PostionId where a.CompanyId=@CompanyId and OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.CompanyId=@CompanyId and c.MateState=0 and c.State=1 and c.FPDate is not null) order by b.SortNo,a.KCNum desc"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改要自动匹配的订单货物 public static void UpdateOrderGoodsLockForHWC(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],HWCFee,CompanyId) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.KCNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId],HWCFee,CompanyId from [HW_GoodsInDetailHWC] where InId=" + md2.InId + @" update HW_GoodsInDetailHWC set KCNum=KCNum-" + md2.KCNum + " where InId=" + md2.InId + @" update HW_GoodsInDetailHWC set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=@MateState where JoinOrderCode=@JoinOrderCode "; } else tsql += @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public static void UpdateOrderGoodsLockForHWC(int OrderId, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],CompanyId) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.OrderNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId],CompanyId from [HW_GoodsInDetailHWC] where InId=" + md2.InId + " and KCNum>=" + md2.OrderNum + @" update HW_GoodsInDetailHWC set KCNum=KCNum-" + md2.OrderNum + " where InId=" + md2.InId + " and KCNum>=" + md2.OrderNum + @" update HW_GoodsInDetailHWC set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != null && JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=2 where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set MateState=2 where JoinOrderCode=@JoinOrderCode "; } else if (OrderId > 0) { tsql += @" update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderInfonew set MateState=2 where OrderId=@OrderId "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListDT_OrderInfoForHWC(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'))a"; } else if (SKU != "") sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId and (b.SKU1 like '%" + SKU + "%' or b.SKU2 like '%" + SKU + @"%' or b.SKU3 like '%" + SKU + @"%' or b.SKU4 like '%" + SKU + @"%' or b.SKU5 like '%" + SKU + @"%'))a"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,PlatId=c.PlatType,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Post,PostFee=a.Fee1,a.RevAddr,a.RevPostCode,a.RevCity,a.PostInfo,BoxFee=a.Fee2"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListHWC(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.ChaseId,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=a.GoodsSKU,CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,productImgUrl= case when a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc from DT_OrderGoods a inner join DT_OrderInfo d with(nolock) on a.OrderId=d.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.* from HW_GoodsInfo c with(nolock) inner join HW_GoodsDetail d with(nolock) on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListHWC2(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.ChaseId,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=a.GoodsSKU,CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,productImgUrl= case when a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc from DT_OrderGoods a inner join DT_OrderInfo d with(nolock) on a.OrderId=d.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.* from HW_GoodsInfo c with(nolock) inner join HW_GoodsDetail d with(nolock) on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分分配库存的订单 public static List GetLockPartOrderListForHWC(int CompanyId, string OrderIds, string JoinOrderCodes, int orderstate, int StoreId, string OrderBy) { List list = null; string tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.OrderId in (" + OrderIds + ") and a.State=1 and a.MateState<=1 order by " + OrderBy; if (JoinOrderCodes != "") tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyIdand (a.OrderId in (" + OrderIds + ") or JoinOrderCode in (" + JoinOrderCodes + ")) and a.State=1 and a.MateState<=1 order by " + OrderBy; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要部分匹配的订单货物 public static List GetLockPartOrderGoodsForHWC(int CompanyId, string OrderIds, string JoinOrderCodes, int StoreId, int orderstate) { List list = null; string tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and c.DetailId>0 and a.State=1 and a.OrderId in (" + OrderIds + ") and a.MateState<=1"; if (JoinOrderCodes != "") tsql = @" select c.*,a.JoinOrderCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and c.DetailId>0 and a.State=1 and (a.OrderId in (" + OrderIds + ") or a.JoinOrderCode in (" + JoinOrderCodes + ")) and a.MateState<=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 删除订单 public static void DeleteOrderHWC(int OrderId, int InUserId) { string tsql = @" update DT_OrderInfo set state=0,updatedate=getdate(),InUserId=@InUserId where OrderId=@OrderId update DT_OrderInfoNew set state=0,updatedate=getdate(),InUserId=@InUserId where OrderId=@OrderId update b set b.OrderGoodsId=0,CKDetailId=0 from DT_OrderGoods a inner Join HW_GoodsInDetailHWC b on a.id=b.OrderGoodsId where a.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, InUserId); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询物流的订单 public static List GetListDT_OrderInfoExpressHWC(int IsTrack, string TrackCode, string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%')"; else if (SKU != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (b.SKU1 like '%" + SKU + "%' or b.SKU2 like '%" + SKU + "%' or b.SKU3 like '%" + SKU + "%')"; string sql2 = "DT_OrderXXInfo"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax, ErrorInfo='',b.OrderState,b.Post,b.PostFee,PostInfo='',b.LogisticsId,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,ShopName=c.ShopName,a.IsSpare,LocalPost='',b.CountryCode"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfo with (nolock) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId left join jc_shop c with (nolock) on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId left join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 删除订单 public static void DeleteOrderForHWC(string OrderIds) { string tsql = @" update b set b.OrderGoodsId=0,CKDetailId=0 from DT_OrderGoods a inner join HW_GoodsInDetailHWC b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") delete from DT_OrderXXInfo where OrderId in (" + OrderIds + @") delete from DT_OrderXXInfoNew where OrderId in (" + OrderIds + @") delete from DT_OrderInfo where OrderId in (" + OrderIds + @") delete from DT_OrderInfoNew where OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion public static int SaveBackGoodsIn(DT_BackGoodsNew Model) { string tsql = @" declare @StoreId int,@PostionId int set @PostionId=0 if @InType=1 and @TrackCode is not null and @TrackCode<>'' and (select count(0) from DT_BackGoods where DetailId=@DetailId and Num=@Num and InType=@InType and TrackCode=@TrackCode and DATEDIFF(day,InDate,GETDATE())<=3)>0 begin select -1 end else begin if @PostionCode<>'' begin select @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode end if @InType=1 and @PostionId=0 begin select 0 end else begin declare @SKU nvarchar(50) select top 1 @SKU=isnull(SKU1,'') from HW_GoodsDetail where DetailId=@DetailId set @SKU=@SKU+'['+cast(@Num as nvarchar(10))+']' select top 1 @OrderId=OrderId from DT_OrderInfo where PlatOrderCode=@OrderCode and state>0 if @OrderId>0 begin set @State=1 update DT_OrderInfo set OrderState2=1 where OrderId=@OrderId end if @InType=1 --入库 begin declare @HWCFee money,@PostPrice money,@Price money select top 1 @Price=[Price],@PostPrice=[PostPrice],@HWCFee=[HWCFee] from [HW_GoodsInDetail] where DetailId=@DetailId order by InId desc INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],[OldNum],[Companyid],[HWCFee]) values(@DetailId,0,@StoreId,@PostionId,@Price,@PostPrice,GETDATE(),@InUserId,0,@Num,null,0,0,@Num,1,@HWCFee) update HW_GoodsDetail set GoodsNum=GoodsNum+@Num where DetailId=@DetailId end INSERT INTO [DT_BackGoods]([InDate],[InUserId],[ImgIds],[TrackCode],[OrderCode],[GoodsState],[State],[ImgUrl],[GoodsCode],[Num],[PostionCode],[OrderId],[ImgUrl2],[ImgUrl3],[ImgUrl4],[ImgUrl5],[DetailId],[InType]) values(@InDate,@InUserId,@ImgIds,@TrackCode,@OrderCode,@GoodsState,@State,@ImgUrl,@SKU,@Num,@PostionCode,@OrderId,@ImgUrl2,@ImgUrl3,@ImgUrl4,@ImgUrl5,@DetailId,@InType) set @Id=SCOPE_IDENTITY() select Id=@Id end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@ImgIds", DbType.String, Model.ImgIds); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsState", DbType.Int32, Model.GoodsState); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@ImgUrl", DbType.String, Model.ImgUrl); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ImgUrl2", DbType.String, Model.ImgUrl2); db.AddInParameter(cmd, "@ImgUrl3", DbType.String, Model.ImgUrl3); db.AddInParameter(cmd, "@ImgUrl4", DbType.String, Model.ImgUrl4); db.AddInParameter(cmd, "@ImgUrl5", DbType.String, Model.ImgUrl5); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@InType", DbType.Int32, Model.InType); return Convert.ToInt32(db.ExecuteScalar(cmd)); } public static int SaveBackGoodsInReturnMid(DT_BackGoodsNew Model) { string tsql = @" if @TrackCode is not null and @TrackCode<>'' and (select count(0) from DT_OrderReturn where DetailId=@DetailId and InType=@InType and tracking_id=@TrackCode and ScanState=1)>0 begin select -1 end else begin update DT_OrderReturn set ScanDate=GETDATE(),ScanState=2,ScanUserId=@InUserId,PostionCode=@PostionCode,InType=@InType,ImgUrl=@ImgUrl,ImgUrl2=@ImgUrl2,ImgUrl3=@ImgUrl3,ImgUrl4=@ImgUrl4,ImgUrl5=@ImgUrl5 where DetailId=@DetailId and tracking_id=@TrackCode select 1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@ImgIds", DbType.String, Model.ImgIds); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsState", DbType.Int32, Model.GoodsState); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@ImgUrl", DbType.String, Model.ImgUrl); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ImgUrl2", DbType.String, Model.ImgUrl2); db.AddInParameter(cmd, "@ImgUrl3", DbType.String, Model.ImgUrl3); db.AddInParameter(cmd, "@ImgUrl4", DbType.String, Model.ImgUrl4); db.AddInParameter(cmd, "@ImgUrl5", DbType.String, Model.ImgUrl5); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@InType", DbType.Int32, Model.InType); return Convert.ToInt32(db.ExecuteScalar(cmd)); } public static int SaveBackGoodsInReturn(DT_BackGoodsNew Model) { string tsql = @" declare @StoreId int,@PostionId int set @PostionId=0 if @TrackCode is not null and @TrackCode<>'' and (select count(0) from DT_OrderReturn where DetailId=@DetailId and InType=@InType and tracking_id=@TrackCode and ScanState=1)>0 begin select -1 end else if @PostionCode='' begin if @ImgUrl<>'' begin update DT_OrderReturn set ScanDate=GETDATE(),ScanState=1,ScanUserId=@InUserId,PostionCode='',InType=@InType,ImgUrl=@ImgUrl,ImgUrl2=@ImgUrl2,ImgUrl3=@ImgUrl3,ImgUrl4=@ImgUrl4,ImgUrl5=@ImgUrl5 where DetailId=@DetailId and tracking_id=@TrackCode end else begin update DT_OrderReturn set ScanDate=GETDATE(),ScanState=1,ScanUserId=@InUserId,PostionCode='',InType=@InType where DetailId=@DetailId and tracking_id=@TrackCode end select 1 end else begin if @PostionCode<>'' begin select @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @PostionId=0 begin select 0 end else begin if @ImgUrl<>'' begin update DT_OrderReturn set ScanDate=GETDATE(),ScanState=1,ScanUserId=@InUserId,PostionCode=@PostionCode,InType=@InType,ImgUrl=@ImgUrl,ImgUrl2=@ImgUrl2,ImgUrl3=@ImgUrl3,ImgUrl4=@ImgUrl4,ImgUrl5=@ImgUrl5 where DetailId=@DetailId and tracking_id=@TrackCode end else begin update DT_OrderReturn set ScanDate=GETDATE(),ScanState=1,ScanUserId=@InUserId,PostionCode=@PostionCode,InType=@InType where DetailId=@DetailId and tracking_id=@TrackCode end declare @HWCFee money,@PostPrice money,@Price money select top 1 @Price=[Price],@PostPrice=[PostPrice],@HWCFee=[HWCFee] from [HW_GoodsInDetail] where DetailId=@DetailId order by InId desc INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],[OldNum],[Companyid],[HWCFee]) values(@DetailId,0,@StoreId,@PostionId,@Price,@PostPrice,GETDATE(),@InUserId,0,@Num,null,0,0,@Num,1,@HWCFee) update HW_GoodsDetail set GoodsNum=GoodsNum+@Num where DetailId=@DetailId select 1 end end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@ImgIds", DbType.String, Model.ImgIds); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@GoodsState", DbType.Int32, Model.GoodsState); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@ImgUrl", DbType.String, Model.ImgUrl); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ImgUrl2", DbType.String, Model.ImgUrl2); db.AddInParameter(cmd, "@ImgUrl3", DbType.String, Model.ImgUrl3); db.AddInParameter(cmd, "@ImgUrl4", DbType.String, Model.ImgUrl4); db.AddInParameter(cmd, "@ImgUrl5", DbType.String, Model.ImgUrl5); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@InType", DbType.Int32, Model.InType); return Convert.ToInt32(db.ExecuteScalar(cmd)); } public static int Save_BackGoods2(DT_BackGoodsNew Model) { string query = @" if @Id>0 begin Update [DT_BackGoods] set [InDate]=@InDate,[InUserId]=@InUserId,[ImgIds]=@ImgIds,[TrackCode]=@TrackCode,[OrderCode]=@OrderCode,[GoodsState]=@GoodsState,[State]=@State,[ImgUrl]=@ImgUrl,[GoodsCode]=@GoodsCode,[Num]=@Num,[PostionCode]=@PostionCode,[OrderId]=@OrderId,[ImgUrl2]=@ImgUrl2,[ImgUrl3]=@ImgUrl3,[ImgUrl4]=@ImgUrl4,[ImgUrl5]=@ImgUrl5,[DetailId]=@DetailId where Id=@Id end else begin INSERT INTO [DT_BackGoods]([InDate],[InUserId],[ImgIds],[TrackCode],[OrderCode],[GoodsState],[State],[ImgUrl],[GoodsCode],[Num],[PostionCode],[OrderId],[ImgUrl2],[ImgUrl3],[ImgUrl4],[ImgUrl5],[DetailId]) values(@InDate,@InUserId,@ImgIds,@TrackCode,@OrderCode,@GoodsState,@State,@ImgUrl,@GoodsCode,@Num,@PostionCode,@OrderId,@ImgUrl2,@ImgUrl3,@ImgUrl4,@ImgUrl5,@DetailId) set @Id=SCOPE_IDENTITY() end if @OrderCode<>'' begin update DT_OrderBackMoneyApply set PostCode=@TrackCode,BackState=@GoodsState where OrderCode=@OrderCode end select @Id"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@Id", DbType.Int32, Model.Id); database.AddInParameter(sqlStringCommand, "@InDate", DbType.DateTime, Model.InDate); database.AddInParameter(sqlStringCommand, "@InUserId", DbType.Int32, Model.InUserId); database.AddInParameter(sqlStringCommand, "@ImgIds", DbType.String, Model.ImgIds); database.AddInParameter(sqlStringCommand, "@TrackCode", DbType.String, Model.TrackCode); database.AddInParameter(sqlStringCommand, "@OrderCode", DbType.String, Model.OrderCode); database.AddInParameter(sqlStringCommand, "@GoodsState", DbType.Int32, Model.GoodsState); database.AddInParameter(sqlStringCommand, "@State", DbType.Int32, Model.State); database.AddInParameter(sqlStringCommand, "@ImgUrl", DbType.String, Model.ImgUrl); database.AddInParameter(sqlStringCommand, "@GoodsCode", DbType.String, Model.GoodsCode); database.AddInParameter(sqlStringCommand, "@Num", DbType.Int32, Model.Num); database.AddInParameter(sqlStringCommand, "@PostionCode", DbType.String, Model.PostionCode); database.AddInParameter(sqlStringCommand, "@OrderId", DbType.Int32, Model.OrderId); database.AddInParameter(sqlStringCommand, "@ImgUrl2", DbType.String, Model.ImgUrl2); database.AddInParameter(sqlStringCommand, "@ImgUrl3", DbType.String, Model.ImgUrl3); database.AddInParameter(sqlStringCommand, "@ImgUrl4", DbType.String, Model.ImgUrl4); database.AddInParameter(sqlStringCommand, "@ImgUrl5", DbType.String, Model.ImgUrl5); database.AddInParameter(sqlStringCommand, "@DetailId", DbType.Int32, Model.DetailId); database.AddInParameter(sqlStringCommand, "@InType", DbType.Int32, Model.InType); return Convert.ToInt32(database.ExecuteScalar(sqlStringCommand)); } public static int IsStorePostionCode2(string PostionCode, int DetailId, int Num) { string query = @" declare @PostionId int,@KCNum int set @PostionId=0 select @PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @PostionId>0 begin select @KCNum=isnull(SUM(KCNum),0) from HW_GoodsInDetail where DetailId=@DetailId and PostionId=@PostionId and OrderGoodsId=0 and KCNum>0 if @KCNum<@Num set @PostionId=-1 end select @PostionId "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@DetailId", DbType.Int32, DetailId); database.AddInParameter(sqlStringCommand, "@PostionCode", DbType.String, PostionCode); database.AddInParameter(sqlStringCommand, "@Num", DbType.Int32, Num); return Convert.ToInt32(database.ExecuteScalar(sqlStringCommand)); } public static void UpdateFBAPostionCode(int PostionId, int DetailId, int Num) { string query = @" declare @KCNum int select @KCNum=isnull(SUM(KCNum),0) from HW_GoodsInDetail where DetailId=@DetailId and PostionId=@PostionId and OrderGoodsId=0 and KCNum>0 update HW_GoodsInDetail set OrderGoodsId=-1,UpDateTime=getdate(),CKDetailId=-1 where DetailId=@DetailId and PostionId=@PostionId if @KCNum-@Num>0 begin INSERT INTO [HW_GoodsInDetail] ([DetailId] ,[ChaseId] ,[StoreId] ,[PostionId] ,[Price] ,[PostPrice] ,[InDate] ,[InUserId] ,[OrderGoodsId] ,[KCNum] ,[UpDateTime] ,[RKDetailId] ,[CKDetailId] ,[OldNum] ,[Companyid] ,[HWCFee]) select top 1 [DetailId] ,[ChaseId] ,[StoreId] ,[PostionId] ,[Price] ,[PostPrice] ,[InDate] ,[InUserId] ,[OrderGoodsId]=0 ,KCNum=@KCNum-@Num ,UpDateTime=getdate() ,[RKDetailId] ,CKDetailId=0 ,OldNum=@KCNum-@Num ,[Companyid] ,[HWCFee] from HW_GoodsInDetail where DetailId=@DetailId and PostionId=@PostionId order by InId desc end "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@DetailId", DbType.Int32, DetailId); database.AddInParameter(sqlStringCommand, "@PostionId", DbType.Int32, PostionId); database.AddInParameter(sqlStringCommand, "@Num", DbType.Int32, Num); database.ExecuteNonQuery(sqlStringCommand); } #region 查询订单明细匹配 public static List GetOrderGoodsList2(string OrderIds) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,f.GoodsName,f.GoodsCode,Weight=case when e.Weight is not null then e.Weight else f.Weight end,f.Weight2,f.Height,f.Long,f.Width,f.Height2,f.Long2,f.Width2,GoodsSKU=e.sku1,g.sendname from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId inner join jc_shop g on d.shopid=g.shopid where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsList3(int OrderId) { List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,f.GoodsName,f.GoodsCode,Weight=case when e.Weight is not null then e.Weight else f.Weight end,f.Weight2,f.Height,f.Long,f.Width,f.Height2,f.Long2,f.Width2,GoodsSKU=e.sku1,a.PostInfo from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存订单跟踪码申请 public static void SaveTrackCodeApply(DT_TrackCodeApplyNew Model) { string tsql = @" select top 1 @LogisticsId=LogisticsId from JC_Express where ExpressId=@PostId if @PostError is not null and @PostError<>'' begin update DT_OrderXXInfo set LogisticsId=@LogisticsId,PostError=@PostError,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set LogisticsId=@LogisticsId,PostError=@PostError,Post=@PostId where OrderId=@OrderId end else begin update DT_OrderXXInfo set LogisticsId=@LogisticsId,PostError=null,TrackState=1,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set LogisticsId=@LogisticsId,PostError=null,TrackState=1,Post=@PostId where OrderId=@OrderId end INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode],[SKU],[Weight],[Long],[Width],[Height],[OrderCode2],LabelUrl)values(@PostId,@TrackType,@TrackCode,@TrackCode2,@GetDate,@InName,@OrderId,@State,@UpdateTime,@OrderCode,@SKU,@Weight,@Long,@Width,@Height,@OrderCode2,@LabelUrl) set @Id=SCOPE_IDENTITY() "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, Model.LogisticsId); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackType", DbType.Int32, Model.TrackType); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@TrackCode2", DbType.String, Model.TrackCode2); db.AddInParameter(cmd, "@GetDate", DbType.DateTime, Model.GetDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, Model.IsSpare); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@PostError", DbType.String, Model.PostError); db.AddInParameter(cmd, "@LabelUrl", DbType.String, Model.LabelUrl); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@Weight", DbType.String, Model.Weight2); db.AddInParameter(cmd, "@Long", DbType.String, Model.Long); db.AddInParameter(cmd, "@Width", DbType.String, Model.Width); db.AddInParameter(cmd, "@Height", DbType.String, Model.Height); db.AddInParameter(cmd, "@OrderCode2", DbType.String, Model.OrderCode2); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单跟踪码申请 public static void SaveTrackCodeApply2(DT_TrackCodeApplyNew Model) { string tsql = @" if(select count(0) from DT_TrackCodeApply where OrderId=@OrderId and state=1)=0 begin select top 1 @LogisticsId=LogisticsId from JC_Express where ExpressId=@PostId if @PostError is not null and @PostError<>'' begin update DT_OrderXXInfo set LogisticsId=@LogisticsId,PostError=@PostError,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set LogisticsId=@LogisticsId,PostError=@PostError,Post=@PostId where OrderId=@OrderId end else begin update DT_OrderXXInfo set LogisticsId=@LogisticsId,PostError=null,TrackState=1,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set LogisticsId=@LogisticsId,PostError=null,TrackState=1,Post=@PostId where OrderId=@OrderId end INSERT INTO [DT_TrackCodeApply]([PostId],[TrackType],[TrackCode],[TrackCode2],[GetDate],[InName],[OrderId],[State],[UpdateTime],[OrderCode],[SKU],[Weight],[Long],[Width],[Height],[OrderCode2],LabelUrl)values(@PostId,@TrackType,@TrackCode,@TrackCode2,@GetDate,@InName,@OrderId,@State,@UpdateTime,@OrderCode,@SKU,@Weight,@Long,@Width,@Height,@OrderCode2,@LabelUrl) set @Id=SCOPE_IDENTITY() end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, Model.LogisticsId); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackType", DbType.Int32, Model.TrackType); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@TrackCode2", DbType.String, Model.TrackCode2); db.AddInParameter(cmd, "@GetDate", DbType.DateTime, Model.GetDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@UpdateTime", DbType.DateTime, Model.UpdateTime); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@IsSpare", DbType.Int32, Model.IsSpare); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@PostError", DbType.String, Model.PostError); db.AddInParameter(cmd, "@LabelUrl", DbType.String, Model.LabelUrl); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@Weight", DbType.String, Model.Weight2); db.AddInParameter(cmd, "@Long", DbType.String, Model.Long); db.AddInParameter(cmd, "@Width", DbType.String, Model.Width); db.AddInParameter(cmd, "@Height", DbType.String, Model.Height); db.AddInParameter(cmd, "@OrderCode2", DbType.String, Model.OrderCode2); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单跟踪码申请 public static void UpdateAutoTrack(int OrderId, string PostError) { string tsql = @" update DT_OrderXXInfo set IsAutoTrack=1,PostError=@PostError where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostError", DbType.String, PostError); db.ExecuteNonQuery(cmd); } #endregion #region 查询订单跟踪码 public static List GetOrderTrackCodeNew(int OrderId, string JoinOrderCode) { List list = null; string tsql = @" if @JoinOrderCode<>'' begin select a.Id,a.PostId,a.TrackType,a.TrackCode,a.TrackCode2,a.GetDate,a.InName,a.OrderId,a.State,a.UpdateTime,a.OrderCode,a.OldPostFee,a.ScanState,TrackTypeName=case when a.TrackType=3 then '空包裹' else '' end,convert(nvarchar(100), b.Weight) as Weight,b.PostFee,ScanDate=b.InDate,a.SKU,Weight2=a.Weight,a.Long,a.Width,a.Height,a.OrderCode2,ScanName=c.Name from DT_TrackCodeApply a with(nolock) left join DT_TrackCodeScan b with(nolock) on a.OrderId=b.OrderId and a.TrackCode=b.TrackCode left Join JC_UserInfo c with(nolock) on b.SureUserId=c.UserId where a.OrderCode=@JoinOrderCode and a.state=1 end else begin select a.Id,a.PostId,a.TrackType,a.TrackCode,a.TrackCode2,a.GetDate,a.InName,a.OrderId,a.State,a.UpdateTime,a.OrderCode,a.OldPostFee,a.ScanState,TrackTypeName=case when a.TrackType=3 then '空包裹' else '' end,convert(nvarchar(100), b.Weight) as Weight,b.PostFee,ScanDate=b.InDate,a.SKU,Weight2=a.Weight,a.Long,a.Width,a.Height,a.OrderCode2,ScanName=c.Name from DT_TrackCodeApply a with(nolock) left join DT_TrackCodeScan b with(nolock) on a.OrderId=b.OrderId and a.TrackCode=b.TrackCode left Join JC_UserInfo c with(nolock) on b.SureUserId=c.UserId where a.OrderId=@OrderId and a.state=1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 删除订单跟踪码 public static void DeleteTrackCodeApply(int orderid) { var sql = @" update DT_OrderXXInfo set TrackState=0 where OrderId=@OrderId update DT_OrderXXInfoNew set TrackState=0 where OrderId=@OrderId update DT_TrackCodeApply set State=0 where OrderId=@OrderId "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, orderid); db.ExecuteNonQuery(cmd); } #endregion #region 返回订单Model public static List GetOrderPrintListForFedex(string OrderIds, int PrintType) { List list = null; string tsql = @" if @PrintType=0 begin select a.* from ( select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo, b.BuyRemark,b.Post,b.PostFee,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode,SKU=e.SKU from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") and isnull(a.IsJoin,0)=0 union select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo, b.BuyRemark,b.Post,b.PostFee,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode,a.JoinOrderCode,SKU=e.SKU from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType<3 inner join JC_Shop d on a.ShopId=d.ShopId where a.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1))a inner join ( select OrderId,detailid=MAX(a.detailid),GoodsCode=max(c.GoodsCode) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId in (" + OrderIds + @") group by a.OrderId)b on a.OrderId=b.OrderId order by b.GoodsCode,b.detailid select * from ( select a.Id,a.OrderId,GoodsNum=isnull(e.kcnum,a.GoodsNum),d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=isnull(f.PostionCode,'no'),bb.TypeCode,a.OldTypeCode,a.OldTypeDesc,GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end,f.SortNo from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId left join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId left join CK_StorePostion f on e.PostionId=f.PostionId where d.OrderId in (" + OrderIds + @") and isnull(d.IsJoin,0)=0 union select a.Id,a.OrderId,GoodsNum=isnull(e.kcnum,a.GoodsNum),d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,GoodsCode=case when c.GoodsCode is null or c.GoodsCode='' then c.GoodsOldCode else c.GoodsCode end,c.GoodsName,c.BGPrice,PostionDesc=isnull(f.PostionCode,'no'),bb.TypeCode,a.OldTypeCode,a.OldTypeDesc,GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end,f.SortNo from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId left join (select PostionId,DetailId,OrderGoodsId,kcnum=SUM(kcnum) from HW_GoodsInDetail where OrderGoodsId>0 group by PostionId,DetailId,OrderGoodsId)e on a.DetailId=e.DetailId and a.Id=e.OrderGoodsId left join CK_StorePostion f on e.PostionId=f.PostionId where d.JoinOrderCode in (select distinct JoinOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @") and IsJoin=1))a order by a.SortNo,a.PostionDesc,a.GoodsNum desc end else begin select a.OrderId,d.ShopName,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevPostCode,b.Post,b.PostFee,b.RevProvince,b.RevCity,b.RevArea,b.CountryCode,b.CountryName,a.IsSpare,e.TrackCode,e.TrackCode2,e.OrderCode,a.PlatOrderCode from DT_OrderInfo a inner join DT_OrderBlank b on a.OrderId=b.OrderId inner join DT_TrackCodeApply e on a.OrderId=e.OrderId and e.state=1 and e.TrackType=3 inner join JC_Shop d on a.ShopId=d.ShopId where a.OrderId in (" + OrderIds + @") select a.OrderId,a.GoodsNum,d.JoinOrderCode,GoodsPrice=d.TotalPrice,d.RMBPrice,bb.Weight,bb.SKU1,bb.TypeDesc,c.GoodsEnglisgName,c.GoodsCode,c.GoodsName,c.BGPrice,PostionDesc='',GoodsUrl=case when bb.FirstImgUrl is not null and bb.FirstImgUrl<>'' then bb.FirstImgUrl else c.FirstImgUrl end from DT_OrderGoods a inner join HW_GoodsDetail bb on a.DetailId=bb.DetailId inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join HW_GoodsInfo c on bb.GoodsId=c.GoodsId where d.OrderId in (" + OrderIds + @") end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PrintType", DbType.Int32, PrintType); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (ds.Tables.Count > 1) { var glist = ds.Tables[1].ToList(); if (glist != null && list != null && list.Count > 0) { foreach (var md in list) { if (md.JoinOrderCode != null && md.JoinOrderCode != "") { var GoodsList = glist.FindAll(n => n.JoinOrderCode == md.JoinOrderCode); md.GoodsList = GoodsList; } else { var GoodsList = glist.FindAll(n => n.OrderId == md.OrderId); md.GoodsList = GoodsList; } } } } return list; } #endregion #region 保存 public static int Save_OtherFee(CK_OtherFeeNew Model) { string tsql = @" if @Id>0 begin Update [CK_OtherFee] set [FeeDetailId]=@FeeDetailId,[Num]=@Num,[FeeRate]=@FeeRate,[TotalFee]=@TotalFee,[CompanyId]=@CompanyId,[InDate]=@InDate,[InUserId]=@InUserId,[FeeDate]=@FeeDate,[OffRate]=@OffRate,[FeeName]=@FeeName,[FeeName2]=@FeeName2,[FeeRemark]=@FeeRemark,[DoneDate]=@DoneDate where Id=@Id end else begin INSERT INTO [CK_OtherFee]([FeeDetailId],[Num],[FeeRate],[TotalFee],[CompanyId],[InDate],[InUserId],[FeeDate],[OffRate],[FeeName],[FeeName2],[FeeRemark],[DoneDate])values(@FeeDetailId,@Num,@FeeRate,@TotalFee,@CompanyId,@InDate,@InUserId,@FeeDate,@OffRate,@FeeName,@FeeName2,@FeeRemark,@DoneDate) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@FeeDetailId", DbType.Int32, Model.FeeDetailId); db.AddInParameter(cmd, "@Num", DbType.Decimal, Model.Num); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@TotalFee", DbType.Decimal, Model.TotalFee); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@FeeDate", DbType.DateTime, Model.FeeDate); db.AddInParameter(cmd, "@OffRate", DbType.Decimal, Model.OffRate); db.AddInParameter(cmd, "@FeeName", DbType.String, Model.FeeName); db.AddInParameter(cmd, "@FeeName2", DbType.String, Model.FeeName2); db.AddInParameter(cmd, "@FeeRemark", DbType.String, Model.FeeRemark); db.AddInParameter(cmd, "@DoneDate", DbType.DateTime, Model.DoneDate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion public static List GetListOtherFee(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 service = new QueryService2 { Tsql = @"select Id=cast(a.Id as int),a.FeeDetailId,a.Num,a.FeeRate,a.TotalFee,a.CompanyId,a.InDate,a.InUserId,a.FeeDate,a.OffRate,b.CompanyName,c.Name,a.FeeName,a.FeeName2,a.FeeRemark,a.DoneDate from CK_OtherFee a inner join JC_Company b on a.CompanyId=b.CompanyId inner join JC_UserInfo c on a.InUserId=c.UserId" }; service.Tsql = service.Tsql + " " + service.Filter(where); service.PageIndex = PageIndex; service.PageSize = PageSize; if (string.IsNullOrEmpty(Sort)) { service.Sort = "a.Id desc"; } else { service.Sort = Sort; } string text = service.GetText(); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddOutParameter(sqlStringCommand, "@RowCount", DbType.Int32, 4); DataTable tb = database.ExecuteDataTable(sqlStringCommand); RowCount = Convert.ToInt32(sqlStringCommand.Parameters["@RowCount"].Value); return tb.ToList(); } public static List GetListOtherFeeList(DateTime? SDate, DateTime? EDate, int CompanyId) { List list = null; string tsql = @" select a.*,b.CompanyName from ( select CompanyId,FeeDate2=CONVERT(varchar(10),FeeDate, 120),TotalFee=SUM(isnull(TotalFee,0)) from CK_OtherFee where (@CompanyId=0 or CompanyId=@CompanyId) and FeeDate>=@SDate and FeeDate<@EDate group by CompanyId,CONVERT(varchar(10),FeeDate, 120))a inner join JC_Company b on a.CompanyId=b.CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } public static List GetListOtherFeeList2(DateTime? SDate, DateTime? EDate, int CompanyId) { List list = null; string tsql = @" select * from CK_OtherFee where (@CompanyId=0 or CompanyId=@CompanyId) and FeeDate>=@SDate and FeeDate<@EDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } public static List GetListFeeDetailOther(int CompanyId) { string query = @"select FeeTypeName=e.Name,FeeName=c.YLChar2,FeeDesc=c.YLChar3,c.FeeRate,c.OffRate,FeeDetailId=c.Id from JC_Company a inner join CK_FeeList b on a.FeeId=b.Id inner join CK_FeeDetail c on b.Id=c.FeeId left join JC_BaseCodeDetail e on c.feetype=e.sortno and e.keyname='FYLX' where isnull(IsAuto,0)=0 and a.CompanyId=@CompanyId "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@CompanyId", DbType.Int32, CompanyId); return database.ExecuteDataTable(sqlStringCommand).ToList(); } #region 读取物流渠道 public static List GetExpressPostList(int CompanyID, int LogisticsId) { string tsql = @" if(select count(0) from JC_ExpressPost a inner join JC_Express c on a.ExpressID=c.ExpressID where a.CompanyId=@CompanyID and a.IsUse=1 and (@LogisticsId=0 or LogisticsId=@LogisticsId))>0 begin select c.ExpressID,c.Name,c.PrintTemplateName from JC_ExpressPost a inner join JC_Express c on a.ExpressID=c.ExpressID where a.CompanyId=@CompanyID and a.IsUse=1 and (@LogisticsId=0 or LogisticsId=@LogisticsId) order by c.LogisticsId end else begin select c.ExpressID,c.Name,c.PrintTemplateName from JC_ExpressPost a inner join JC_Express c on a.ExpressID=c.ExpressID where a.CompanyId=0 and a.IsUse=1 and (@LogisticsId=0 or LogisticsId=@LogisticsId) order by c.LogisticsId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, LogisticsId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 获取物流对象 public static JC_ExpressPost GetExpressModel(int CompanyId, int ExpressID) { JC_ExpressPost model = null; string tsql = @" if(select count(0) from [JC_ExpressPost] a inner join JC_Express c on a.ExpressID=c.ExpressID where a.ExpressID=@ExpressID and a.CompanyId=@CompanyId)>0 begin select a.ExpressPostID,a.ExpressID,a.CompanyId,a.Name,c.PostType,a.IsUse,a.UserCode,a.CheckCode,a.operationtype,a.customercode,a.vipcode,a.clcttype,a.DefaultAddr,a.client_id,a.client_secret,a.refresh_token,a.GetTime,a.Code,a.redirect_uri,c.EName,c.LogisticsId from [JC_ExpressPost] a inner join JC_Express c on a.ExpressID=c.ExpressID where a.ExpressID=@ExpressID and a.CompanyId=@CompanyId end else begin select a.ExpressPostID,a.ExpressID,a.CompanyId,a.Name,c.PostType,a.IsUse,a.UserCode,a.CheckCode,a.operationtype,a.customercode,a.vipcode,a.clcttype,a.DefaultAddr,a.client_id,a.client_secret,a.refresh_token,a.GetTime,a.Code,a.redirect_uri,c.EName,c.LogisticsId from [JC_ExpressPost] a inner join JC_Express c on a.ExpressID=c.ExpressID where a.ExpressID=@ExpressID and a.CompanyId=0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@ExpressID", DbType.Int32, ExpressID); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 读取平台 public static List GetPlatBaseCode(int CompanyID, string KeyName) { string tsql = @" select *,UseState=Remark from JC_BaseCodeDetail where KeyName=@KeyName and IsUse=1 order by SortNo "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@KeyName", DbType.String, KeyName); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取物流对象 public static JC_Express GetExpressModel2(int ExpressId, int CompanyId) { JC_Express model = null; string tsql = @" if(select count(0) from JC_Express a inner join JC_ExpressPost b on a.ExpressId=b.ExpressId where a.Expressid=@ExpressId and b.CompanyId=@CompanyId)>0 begin select a.*,b.DefaultAddr,b.UserCode from JC_Express a inner join JC_ExpressPost b on a.ExpressId=b.ExpressId where a.Expressid=@ExpressId and b.CompanyId=@CompanyId end else begin select a.*,b.DefaultAddr,b.UserCode from JC_Express a inner join JC_ExpressPost b on a.ExpressId=b.ExpressId where a.Expressid=@ExpressId and b.CompanyId=0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExpressId", DbType.Int32, ExpressId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 保存店铺数据 public static int SaveShopData(JC_ShopDataNew Model) { string tsql = @" select top 1 @Id=Id from JC_ShopData where ShopId=@ShopId and datediff(day,InDate,@InDate)=0 if @Id>0 begin Update [JC_ShopData] set [GoodRate]=@GoodRate,[ODR]=@ODR,[DSRGoods]=@DSRGoods,[DSRService]=@DSRService,[DSRPost]=@DSRPost,[USDUseMoney]=@USDUseMoney,[USDNoMoney]=@USDNoMoney,[RMBUseMoney]=@RMBUseMoney,[RMBNoMoney]=@RMBNoMoney,[ShopId]=@ShopId,[InUserId]=@InUserId,[InName]=@InName,[InforViolate]=@InforViolate,[PropertyViolate]=@PropertyViolate,[OtherViolate]=@OtherViolate,Rate1=@Rate1,Rate2=@Rate2,Rate3=@Rate3,Rate4=@Rate4,Rate5=@Rate5,Rate6=@Rate6,FeeDate=@FeeDate,TXFee=@TXFee,Rate7=@Rate7,Rate8=@Rate8 where Id=@Id end else begin INSERT INTO [JC_ShopData]([GoodRate],[ODR],[DSRGoods],[DSRService],[DSRPost],[USDUseMoney],[USDNoMoney],[RMBUseMoney],[RMBNoMoney],[ShopId],[InDate],[InUserId],[InName],[InforViolate],[PropertyViolate],[OtherViolate],Rate1,Rate2,Rate3,Rate4,Rate5,Rate6,FeeDate,TXFee,Rate7,Rate8)values(@GoodRate,@ODR,@DSRGoods,@DSRService,@DSRPost,@USDUseMoney,@USDNoMoney,@RMBUseMoney,@RMBNoMoney,@ShopId,@InDate,@InUserId,@InName,@InforViolate,@PropertyViolate,@OtherViolate,@Rate1,@Rate2,@Rate3,@Rate4,@Rate5,@Rate6,@FeeDate,@TXFee,@Rate7,@Rate8) set @Id=SCOPE_IDENTITY() end if @FeeDate is not null begin update JC_Shop set FeeDate=@FeeDate,TXFee=@TXFee where ShopId=@ShopId end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@GoodRate", DbType.Decimal, Model.GoodRate); db.AddInParameter(cmd, "@ODR", DbType.Decimal, Model.ODR); db.AddInParameter(cmd, "@DSRGoods", DbType.Decimal, Model.DSRGoods); db.AddInParameter(cmd, "@DSRService", DbType.Decimal, Model.DSRService); db.AddInParameter(cmd, "@DSRPost", DbType.Decimal, Model.DSRPost); db.AddInParameter(cmd, "@USDUseMoney", DbType.Decimal, Model.USDUseMoney); db.AddInParameter(cmd, "@USDNoMoney", DbType.Decimal, Model.USDNoMoney); db.AddInParameter(cmd, "@RMBUseMoney", DbType.Decimal, Model.RMBUseMoney); db.AddInParameter(cmd, "@RMBNoMoney", DbType.Decimal, Model.RMBNoMoney); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InforViolate", DbType.Decimal, Model.InforViolate); db.AddInParameter(cmd, "@PropertyViolate", DbType.Decimal, Model.PropertyViolate); db.AddInParameter(cmd, "@OtherViolate", DbType.Decimal, Model.OtherViolate); db.AddInParameter(cmd, "@Rate1", DbType.Decimal, Model.Rate1); db.AddInParameter(cmd, "@Rate2", DbType.Decimal, Model.Rate2); db.AddInParameter(cmd, "@Rate3", DbType.Decimal, Model.Rate3); db.AddInParameter(cmd, "@Rate4", DbType.Decimal, Model.Rate4); db.AddInParameter(cmd, "@Rate5", DbType.Decimal, Model.Rate5); db.AddInParameter(cmd, "@Rate6", DbType.Decimal, Model.Rate6); db.AddInParameter(cmd, "@Rate7", DbType.Decimal, Model.Rate7); db.AddInParameter(cmd, "@Rate8", DbType.Decimal, Model.Rate8); db.AddInParameter(cmd, "@FeeDate", DbType.DateTime, Model.FeeDate); db.AddInParameter(cmd, "@TXFee", DbType.Decimal, Model.TXFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询店铺数据 public static List GetListJC_ShopData2(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.GoodRate,a.ODR,a.DSRGoods,a.DSRService,a.DSRPost,a.USDUseMoney,a.USDNoMoney,a.RMBUseMoney,a.RMBNoMoney,a.ShopId,a.InDate,a.InUserId,a.InName,b.ShopName,a.InforViolate,a.PropertyViolate,a.OtherViolate,a.Rate1,a.Rate2,a.Rate3,a.Rate4,a.Rate5,a.Rate6,a.FeeDate,FeeDate=isnull(a.FeeDate,b.FeeDate),a.TXFee,a.Rate7,a.Rate8"; ser.Tables = @"JC_ShopData a inner join jc_shop b on a.shopid=b.shopid"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 修改不允许发货 public static void UpdatePostState2(int OrderId) { string tsql = @" update DT_OrderInfo set PostState=2,UpdateDate=getdate() where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 统计总金额 public static List GetCountListReport10(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,1)) from DT_OrderInfo a where a.CompanyId=@CompanyId and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,1)) from DT_OrderInfo a where a.CompanyId=@CompanyId and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计总金额 public static List GetCountListReportNew10(int Type, int PlatId, int ShopId, string shopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,1)) from DT_OrderInfo a where a.CompanyId=@CompanyId and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + shopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,1)) from DT_OrderInfo a where a.CompanyId=@CompanyId and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + shopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计总金额扣除佣金 public static List GetCountListReport(int Type, int platid, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and (@platid=0 or a.platid=@platid) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and (@platid=0 or a.platid=@platid) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@platid", DbType.String, platid); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计总金额扣除佣金 public static List GetCountListReportNew(int Type, int platid, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and (@platid=0 or a.platid=@platid) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and (@platid=0 or a.platid=@platid) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@platid", DbType.String, platid); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计预估总金额 public static List GetCountListReport2(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计预估总金额 public static List GetCountListReportNew2(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计实际总金额 public static List GetCountListReport3(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 统计实际总金额 public static List GetCountListReportNew3(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 预计成本 public static List GetCountListReport4(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee2,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee2,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 预计成本 public static List GetCountListReportNew4(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee2,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee2,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 实际成本 public static List GetCountListReport5(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee3,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee3,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 实际成本 public static List GetCountListReportNew5(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee3,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee3,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 预计运费 public static List GetCountListReport6(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee11,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee11,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 预计运费 public static List GetCountListReportNew6(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee11,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee11,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 ora.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 实际运费 public static List GetCountListReport7(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @"select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 实际运费 public static List GetCountListReportNew7(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 预估利润 public static List GetCountListReport8(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { // tsql = @" select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee2,0)-isnull(b.fee11,0)) from DT_OrderInfo a //inner join DT_OrderXXInfo b on a.OrderId=b.OrderId // where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@ShopId=0 or a.ShopId=@ShopId) and a.OrderDate>=@SDate and a.OrderDate<@EDate // group by convert(nvarchar(10),OrderDate,120)"; tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),Price= SUM(isnull(b.fee1,0)-isnull(b.fee2,0)-isnull(b.fee11,0)-isnull(b.fee12,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @"select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee2,0)-isnull(b.fee11,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 预估利润 public static List GetCountListReportNew8(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { // tsql = @" select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee2,0)-isnull(b.fee11,0)) from DT_OrderInfo a //inner join DT_OrderXXInfo b on a.OrderId=b.OrderId // where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@ShopId=0 or a.ShopId=@ShopId) and a.OrderDate>=@SDate and a.OrderDate<@EDate // group by convert(nvarchar(10),OrderDate,120)"; tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price= SUM(isnull(b.fee1,0)-isnull(b.fee2,0)-isnull(b.fee11,0)-isnull(b.fee12,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee2,0)-isnull(b.fee11,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee2>0 and b.Fee11>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 实际利润 public static List GetCountListReport9(int Type, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @" select OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee3,0)-isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @"select OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee3,0)-isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId=@ShopId) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 实际利润 public static List GetCountListReportNew9(int Type, int PlatId, int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; if (Type == 1) { tsql = @" select PlatId=a.ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee3,0)-isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(10),OrderDate,120)"; } else if (Type == 2) { tsql = @"select PlatId=a.ShopId,OrderDate=convert(nvarchar(7),OrderDate,120),Price=SUM(isnull(b.fee1,0)-isnull(b.fee3,0)-isnull(b.fee4,0)) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and b.fee3>0 and b.Fee4>0 and (@PlatId=0 or a.PlatId=@PlatId) and (@ShopId=0 or a.ShopId in (" + ShopIds + @")) and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by a.ShopId,convert(nvarchar(7),OrderDate,120)"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.String, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 计算 public static void GetCountSum(DateTime? SDate) { string tsql = ""; tsql = @" --扣除佣金 update b set b.Fee1=dbo.MoneyUSDChange(a.TotalPrice*dbo.PlatFeeRate(a.platid),MoneyCode,1) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderDate>=@SDate and a.State>0 and a.State<3 and a.CompanyId=1 --预估成本 update b set b.Fee2=a.fee2 from ( select a.OrderId,fee2=sum(dbo.MoneyUSDChange(isnull(d.InPrice,0)*b.GoodsNum,'CNY',1)+65*isnull(d.Solid,0)*b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.OrderDate>=@SDate and a.State>0 and a.State<3 and a.CompanyId=1 group by a.OrderId)a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId --实际成本 update b set b.Fee3=a.fee3 from ( select a.OrderId,fee3=sum(dbo.MoneyUSDChange((isnull(c.Price,0)+isnull(c.PostPrice,0))*b.GoodsNum,'CNY',1)+isnull(c.HWCFee,0)*b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsInDetail c on b.Id=c.OrderGoodsId where a.OrderDate>=@SDate and a.State>0 and a.State<3 and a.CompanyId=1 group by a.OrderId)a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId --实际运费 update b set b.Fee4=a.fee4 from ( select a.OrderId,fee4=sum(isnull(b.PostFee,0)) from DT_OrderInfo a inner join DT_TrackCodeScan b on a.OrderId=b.OrderId where a.OrderDate>=@SDate and a.State>0 and a.State<3 and a.CompanyId=1 group by a.OrderId)a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId --预估运费 update b set b.Fee11=a.fee6 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId and a.Fee6>0 where a.OrderDate>=@SDate and a.State>0 and a.State<3 and a.CompanyId=1 update b set b.Fee11=a.fee7 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId and a.Fee7>0 and a.Fee7=@SDate and a.State>0 and a.State<3 and a.CompanyId=1 update b set b.Fee11=a.fee8 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId and a.Fee8>0 and a.Fee8=@SDate and a.State>0 and a.State<3 and a.CompanyId=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListHW_GoodsDetail(int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) { where = new RefParameterCollection(); } QueryService service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=case when isnull(a.GoodsInNum,0)>=isnull(a.GoodsInNum2,0) then isnull(a.GoodsInNum,0)-isnull(a.GoodsInNum2,0) else 0 end,GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end" }; if (StoreId > 0) { service.Tables = "HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId"; } else { service.Tables = "HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId"; } service.Filter = where.GetWhere(CommandType.Text); service.PageIndex = PageIndex; service.PageSize = PageSize; service.Sort = Sort; service.KeyName = "DetailId"; string text = service.GetText(); where.AddOutParameter("RowCount", DbType.Int32); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddInParameter(sqlStringCommand, where); DataTable tb = database.ExecuteDataTable(sqlStringCommand); RowCount = Convert.ToInt32(sqlStringCommand.Parameters["@RowCount"].Value); return tb.ToList(); } #endregion #region 分页查询 public static List GetListHW_GoodsDetailNew(int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) { where = new RefParameterCollection(); } QueryService service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=case when isnull(a.GoodsInNum,0)>=isnull(a.GoodsInNum2,0) then isnull(a.GoodsInNum,0)-isnull(a.GoodsInNum2,0) else 0 end,GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=isnull(CGNum,0)" }; if (StoreId > 0) { service.Tables = "HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId"; } else { service.Tables = "HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId"; } service.Filter = where.GetWhere(CommandType.Text); service.PageIndex = PageIndex; service.PageSize = PageSize; service.Sort = Sort; service.KeyName = "DetailId"; string text = service.GetText(); where.AddOutParameter("RowCount", DbType.Int32); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddInParameter(sqlStringCommand, where); DataTable tb = database.ExecuteDataTable(sqlStringCommand); RowCount = Convert.ToInt32(sqlStringCommand.Parameters["@RowCount"].Value); return tb.ToList(); } #endregion #region 分页查询 public static List GetListHW_GoodsDetailNew22(int platid, int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) { where = new RefParameterCollection(); } QueryService service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0)-isnull(a.BHNum3,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date,IsSP=isnull(a.IsSP,0),SalesType=isnull(SalesType,-1),b.MName,d.groupname,b.IsExamine,GoodsHJNum_FBA=isnull(a.GoodsHJNum_FBA,0),b.SubsidyFee,e.YuGuJiaGe,a.TemuPrice,a.ManuaPrice " }; if (platid == 3) { service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0)-isnull(a.BHNum3,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date,IsSP=isnull(a.IsSP,0),SalesType=isnull(SalesType,-1),MName=b.groupname_ebay,d.groupname,b.IsExamine,GoodsHJNum_FBA=isnull(a.GoodsHJNum_FBA,0),b.SubsidyFee,e.YuGuJiaGe,a.TemuPrice,a.ManuaPrice " }; } else if (platid == 6) { service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0)-isnull(a.BHNum3,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date,IsSP=isnull(a.IsSP,0),SalesType=isnull(SalesType,-1),MName=b.groupname_wlmart,d.groupname,b.IsExamine,GoodsHJNum_FBA=isnull(a.GoodsHJNum_FBA,0),b.SubsidyFee,e.YuGuJiaGe,a.TemuPrice,a.ManuaPrice " }; } else if (platid == 15) { service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0)-isnull(a.BHNum3,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date,IsSP=isnull(a.IsSP,0),SalesType=isnull(SalesType,-1),MName=b.groupname_shopify,d.groupname,b.IsExamine,GoodsHJNum_FBA=isnull(a.GoodsHJNum_FBA,0),b.SubsidyFee,e.YuGuJiaGe,a.TemuPrice,a.ManuaPrice " }; } else if (platid == 18) { service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0)-isnull(a.BHNum3,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date,IsSP=isnull(a.IsSP,0),SalesType=isnull(SalesType,-1),MName=b.groupname_wayfair,d.groupname,b.IsExamine,GoodsHJNum_FBA=isnull(a.GoodsHJNum_FBA,0),b.SubsidyFee,e.YuGuJiaGe,a.TemuPrice,a.ManuaPrice " }; } else if (platid == 21) { service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0)-isnull(a.BHNum3,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date,IsSP=isnull(a.IsSP,0),SalesType=isnull(SalesType,-1),MName=b.groupname_sheIn,d.groupname,b.IsExamine,GoodsHJNum_FBA=isnull(a.GoodsHJNum_FBA,0),b.SubsidyFee,e.YuGuJiaGe,a.TemuPrice,a.ManuaPrice " }; } if (StoreId > 0) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId left join JC_UserInfo d with(nolock) on b.muserid=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; if (platid == 3) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId left join JC_UserInfo d with(nolock) on b.guserid_ebay=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 6) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId left join JC_UserInfo d with(nolock) on b.guserid_wlmart=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 15) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId left join JC_UserInfo d with(nolock) on b.guserid_shopify=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 18) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId left join JC_UserInfo d with(nolock) on b.guserid_wayfair=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 21) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId left join JC_UserInfo d with(nolock) on b.guserid_sheIn=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } } else { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join JC_UserInfo d with(nolock) on b.muserid=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; if (platid == 3) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join JC_UserInfo d with(nolock) on b.guserid_ebay=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 6) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join JC_UserInfo d with(nolock) on b.guserid_wlmart=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 15) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join JC_UserInfo d with(nolock) on b.guserid_shopify=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 18) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join JC_UserInfo d with(nolock) on b.guserid_wayfair=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } else if (platid == 21) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join JC_UserInfo d with(nolock) on b.guserid_sheIn=d.UserId left join TemuChengBen e with(nolock) on a.[GoodsId]=e.[GoodsId] "; } } service.Filter = where.GetWhere(CommandType.Text); service.PageIndex = PageIndex; service.PageSize = PageSize; service.Sort = Sort; service.KeyName = "DetailId"; string text = service.GetText(); where.AddOutParameter("RowCount", DbType.Int32); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddInParameter(sqlStringCommand, where); DataTable tb = database.ExecuteDataTable(sqlStringCommand); RowCount = Convert.ToInt32(sqlStringCommand.Parameters["@RowCount"].Value); return tb.ToList(); } #endregion #region 分页查询 public static List GetListHW_GoodsDetailNew2(int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) { where = new RefParameterCollection(); } QueryService service = new QueryService { Fields = "DetailId=cast(a.DetailId as int),a.GoodsId,a.TypeCode,a.TypeDesc,a.SKU1,a.SKU2,a.SKU3,a.SKU4,a.SKU5,a.Weight,GoodsNum=isnull(a.GoodsNum,0),a.GoodsLockNum,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,GoodsInNum3=isnull(a.GoodsInNum,0),GoodsInNum2=isnull(a.GoodsInNum2,0),GoodsHJNum=isnull(a.GoodsHJNum,0),GoodsHJNum2=isnull(a.GoodsHJNum2,0),GoodsHJNum3=isnull(a.GoodsHJNum3,0),a.GoodsHJNum4,a.Price,a.GoodsImageIds,FirstImgUrl=case when a.FirstImgUrl is null or a.FirstImgUrl='' then b.FirstImgUrl else a.FirstImgUrl end,a.UpdateDate,a.UpdateName,a.GoodsRemark,a.SaleDays,a.AvgTime,a.SafeNum,b.Solid,a.BGPrice,a.SKU6,a.SKU7,a.SKU8,a.SKU9,a.SKU10,b.GoodsCode,b.GoodsName,b.SupplierId,LeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)+isnull(a.GoodsInNum2,0)-isnull(a.GoodsPlanNum,0),LeftNumW=isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0),LeftNumE=isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0),b.Cert,b.JYPrice,OutNum=isnull(a.GoodsBackNum,0),SJOutNum=isnull(a.GoodsBackNum2,0),MinBuyNum=isnull(a.GoodsBackNum3,0),AutoPlan=DATEDIFF(day,b.LastOrderDate,GETDATE()),NoGoods=isnull(b.IsSure,0),YCState=case when a.IsYC=1 then '显示SKU' else '隐藏SKU' end,CGNum=case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end,GoodsBackNum4=isnull(a.GoodsBackNum4,0),GoodsBackNum5=isnull(a.GoodsBackNum5,0),GoodsBackNum6=isnull(a.GoodsBackNum6,0),GoodsHJNum5=isnull(a.GoodsHJNum5,0),GoodsHJNum6=isnull(a.GoodsHJNum6,0),GoodsHJNum7=isnull(a.GoodsHJNum7,0),GoodsHJNum8=isnull(a.GoodsHJNum8,0),GoodsHJNum9=isnull(a.GoodsHJNum9,0),GoodsHJNum10=isnull(a.GoodsHJNum10,0),GoodsHJNum11=isnull(a.GoodsHJNum11,0),WestNum=isnull(a.WestNum,0),EastNum=isnull(a.EastNum,0),GoodsHJNum12=isnull(a.GoodsHJNum12,0),GoodsHJNum13=isnull(a.GoodsHJNum13,0),GoodsHJNum14=isnull(a.GoodsHJNum14,0),GoodsHJNum15=isnull(a.GoodsHJNum15,0),JHDays=isnull(b.JHDays,0),FHPlan=isnull(FHPlan,0),CGNum2=isnull(CGNum2,0),CGNum3=isnull(CGNum3,0),bhremark,a.BHNum1,a.BHNum2,a.BHNum3,a.JH_Date" }; if (StoreId > 0) { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join (select distinct DetailId from HW_GoodsInDetail where StoreId=" + StoreId + ")c on a.DetailId=c.DetailId"; } else { service.Tables = "HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId"; } service.Filter = where.GetWhere(CommandType.Text); service.PageIndex = PageIndex; service.PageSize = PageSize; service.Sort = Sort; service.KeyName = "DetailId"; string text = service.GetText(); where.AddOutParameter("RowCount", DbType.Int32); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddInParameter(sqlStringCommand, where); DataTable tb = database.ExecuteDataTable(sqlStringCommand); RowCount = Convert.ToInt32(sqlStringCommand.Parameters["@RowCount"].Value); return tb.ToList(); } #endregion #region 查询订单货物明细 public static List GetOrderGoodsListNew(int OrderId) { //Weight2 用于预估运费 List list = null; string tsql = @" select a.Id,a.OrderId,d.PlatId,a.DetailId,a.GoodsNum,GoodsPrice=isnull(c.FeeRate,0),a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,SKUState=case when a.DetailId>0 then '已经分配' else '未分配' end,GoodsName=case when c.GoodsName is null then a.GoodsName else c.GoodsName+'('+c.GoodsEnglisgName+')' end,productImgUrl=case when productImgUrl is not null and productImgUrl<>'' then productImgUrl else '../images/no.jpg' end,TypeDesc=a.GoodsDesc,GoodsDesc=case when a.detailid<=0 then '' when a.detailid>0 and c.GoodsCode is not null and c.GoodsCode<>'' then c.GoodsCode+' '+b.TypeCode+'['+b.TypeDesc+']' else c.GoodsOldCode+' '+b.TypeCode+'['+b.TypeDesc+']' end,a.OldNum,c.GoodsCode,GoodsId=isnull(c.GoodsId,0),OldTypeDesc=case when a.OldTypeDesc is not null and a.OldTypeDesc<>'' then '改为'+a.OldTypeDesc+'发' else '' end,a.OldTypeCode,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,InPrice=isnull(c.InPrice,0),c.Solid, Weight2=case when a.Fee6>0 and (a.Fee60 and (a.Fee70 and (a.Fee80 and (d.Fee60 and (d.Fee70 and (d.Fee8(); return list; } #endregion public static void GetGoodsFee() { string query = @"update c set c.TotalWeight=b.Weight,c.PostFee=b.PostFee from DT_OrderInfo a inner join (select OrderId,Weight=SUM(Weight),PostFee=SUM(PostFee) from DT_TrackCodeScan group by OrderId)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on a.OrderId=c.OrderId where a.IsJoin=0 and b.PostFee>0 and isnull(c.PostFee,0)<=0 --计算成本 update a set a.GoodsFee=b.Price*a.GoodsNum from DT_OrderGoods a inner join HW_GoodsInDetail b on a.Id=b.OrderGoodsId inner join DT_OrderInfo c on a.OrderId=c.OrderId where a.GoodsFee is null and b.Price>0 update a set a.HWCFee=170*c.Solid from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.StoreId in (5,6) and a.HWCFee is null and c.Solid>0 update b set b.TCFee=a.hwcfee*b.GoodsNum from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id where a.KCNum>0 and a.hwcfee>0 and b.TCFee is null update a set a.Fee3=TCFee from DT_OrderInfo a inner join(select OrderId,TCFee=SUM(isnull(TCFee,0)) from DT_OrderGoods group by OrderId)b on a.OrderId=b.OrderId where b.TCFee>0 and a.Fee3 is null --海外在途 update a set a.GoodsInNum2=b.GoodsNum from HW_GoodsDetail a inner join (select b.GoodsDetailId,GoodsNum=SUM(b.SJOutNum-isnull(b.OutInNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId where isnull(b.OutInNum,0)b.GoodsNum "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.ExecuteDataTable(sqlStringCommand); } public static void GetGoodsBack() { string query = @"update b set b.GoodsBackNum=a.GoodsNum from ( select d.DetailId,GoodsNum=SUM(c.GoodsNum) from DT_OrderBackMoneyApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on b.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId where a.BackType=0 group by d.DetailId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.ExecuteDataTable(sqlStringCommand); } #region 保存订单扫描记录 public static void SaveTrackCodeScan3(DT_TrackCodeScan Model) { string tsql = @" select top 1 @Id=Id from DT_TrackCodeScan where TrackCode=@TrackCode if @TrackId>0 begin update DT_TrackCodeApply set ScanState=1 where Id=@TrackId end if @Id>0 begin Update [DT_TrackCodeScan] set [PostId]=@PostId,[TrackCode]=@TrackCode,[InDate]=@InDate,[InName]=@InName,[OrderCode]=@OrderCode,[OrderId]=@OrderId,[BagUserId]=@BagUserId,[Weight]=@Weight,[ScanUserId]=@ScanUserId,Count=isnull(Count,0)+1 where Id=@Id end else begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[Weight],[IsSure],[SureDate],[SureUserId],[ScanUserId],Count)values(@PostId,@TrackCode,@InDate,@InName,@OrderCode,@OrderId,@BagUserId,@Weight,@IsSure,@SureDate,@SureUserId,@ScanUserId,@Count) set @Id=SCOPE_IDENTITY() end update DT_OrderBlank set state=3,PostDate=getdate(),Weight=@Weight,PostFee=@PostFee where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@BagUserId", DbType.Int32, Model.BagUserId); db.AddInParameter(cmd, "@Weight", DbType.Int32, Model.Weight); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OldPostFee", DbType.Decimal, Model.OldPostFee); db.AddInParameter(cmd, "@Count", DbType.Int32, Model.Count); db.AddInParameter(cmd, "@IsSure", DbType.Int32, Model.IsSure); db.AddInParameter(cmd, "@SureDate", DbType.DateTime, Model.SureDate); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@TrackId", DbType.Int32, Model.TrackId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@IsCSM", DbType.String, Model.IsCSM); db.ExecuteNonQuery(cmd); } #endregion #region 导入跟踪码 public static int ImportTrackCode(string TrackCode, decimal PostFee, decimal? PostFee2) { string tsql = @" declare @OrderId int,@OrderCode nvarchar(50) select @OrderId=OrderId,@OrderCode=OrderCode from DT_TrackCodeApply where state=1 and (REPLACE(TrackCode,' ','')=@TrackCode or TrackCode2=@TrackCode) if @OrderId>0 begin update DT_OrderInfo set Fee1=isnull(Fee1,0)+@PostFee,Fee2=isnull(Fee2,0)+@PostFee2 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=PostFee+@PostFee where OrderId=@OrderId if(select count(0) from DT_TrackCodeScan where REPLACE(TrackCode,' ','')=@TrackCode)>0 update DT_TrackCodeScan set PostFee=@PostFee,OldPostFee=@PostFee where REPLACE(TrackCode,' ','')=@TrackCode else begin INSERT INTO [dbo].[DT_TrackCodeScan] ([PostId] ,[TrackCode] ,[InDate] ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId] ,[Weight] ,[PostFee] ,[OldPostFee]) select [PostId] ,[TrackCode] ,[InDate]=GETDATE() ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId]=1 ,[Weight]=0 ,[PostFee]=@PostFee ,[OldPostFee]=@PostFee from DT_TrackCodeApply where State=1 and REPLACE(TrackCode,' ','')=@TrackCode end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@PostFee2", DbType.Decimal, PostFee2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion public static List GetFedexOrderList2(string OrderIds) { string query = " select b.* from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.OrderId in (" + OrderIds + ")"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); return database.ExecuteDataTable(sqlStringCommand).ToList(); } public static List GetFedexOrderGoodsList(string OrderIds) { string query = " select a.Id,a.OrderId,a.GoodsNum,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,InPrice=isnull(c.InPrice,0) from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId where OrderId in (" + OrderIds + ")"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } #region 返回列表 public static List GetListOrderTrackCodeApply(string Ids) { //string tsql = "select a.Id,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,a.OrderPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.CompanyUserId,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,a.ImageIds,a.BackDate,a.PostCode,a.PostFee,a.PostFee2,a.BackState,a.BackState2,a.BackType,a.OrderState,a.GoodState,a.BackAdvise,a.BackAdvise2,a.State from DT_OrderBackMoneyApply"; string tsql = "select a.Id,a.PostId,a.TrackType,a.TrackCode,a.TrackCode2,a.GetDate,a.InName,a.OrderId,a.State,a.UpdateTime,a.OrderCode,a.OldPostFee,a.ScanState,a.ScanDate,a.LabelUrl,a.SKU,a.OrderCode2 from DT_TrackCodeApply a with(nolock) where state=1 and OrderId in (" + Ids + ") order by orderid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListOrderBackMoneyApply(string Ids) { //string tsql = "select a.Id,a.OrderId,a.OrderCode,a.GoodsCode,a.BackReason1,a.BackReason2,a.BackReason3,a.Remark,a.OrderPrice,a.BackPrice,a.PlanPrice,a.FactPrice,a.InName,a.InUserId,a.DeptName,a.DeptRemark,a.CompanyRemark,a.CompanyRemark2,a.CompanyName1,a.Indate,a.CompanyDate1,a.CompanyDate2,a.CompanyAgree1,a.CompanyAgree2,a.CompanyUserId,a.ShopId,a.MoneyCode1,a.MoneyCode2,a.MoneyCode3,a.MoneyCode4,a.ImageIds,a.BackDate,a.PostCode,a.PostFee,a.PostFee2,a.BackState,a.BackState2,a.BackType,a.OrderState,a.GoodState,a.BackAdvise,a.BackAdvise2,a.State from DT_OrderBackMoneyApply"; string tsql = "select * from DT_OrderBackMoneyApply with(nolock) where OrderId in (" + Ids + ") order by OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 导入货物海外仓 public static int ExcelSaveGoodsHWC(HW_GoodsExcelModel2 Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUImport"); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsEnglishName", DbType.String, Model.GoodsEngLishName); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, Model.Weight2); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Link1", DbType.String, Model.Link1); db.AddInParameter(cmd, "@LinkName1", DbType.String, Model.LinkName1); db.AddInParameter(cmd, "@Link2", DbType.String, Model.Link2); db.AddInParameter(cmd, "@LinkName2", DbType.String, Model.LinkName2); db.AddInParameter(cmd, "@Link3", DbType.String, Model.Link3); db.AddInParameter(cmd, "@LinkName3", DbType.String, Model.LinkName3); db.AddInParameter(cmd, "@Link4", DbType.String, Model.Link4); db.AddInParameter(cmd, "@LinkName4", DbType.String, Model.LinkName4); db.AddInParameter(cmd, "@ImgUrl", DbType.String, Model.ImgUrl); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物明细列表 public static List GetGoodsDetail(int GoodsId) { List list = null; string tsql = @" select *,LeftNum=GoodsNum+GoodsInNum-GoodsPlanNum,NoGoodsState=case when NoGoods=1 then '是' else '否' end from HW_GoodsDetail where GoodsId=@GoodsId ORDER BY TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存货物明细 /// /// 保存货物明细 /// public static int SaveGoodsDetail(HW_GoodsDetailNew Model) { string tsql = @" if @DetailId>0 begin Update [HW_GoodsDetail] set [GoodsId]=@GoodsId,[TypeCode]=@TypeCode,[TypeDesc]=@TypeDesc,[SKU1]=@SKU1,[SKU2]=@SKU2,[SKU3]=@SKU3,[SKU4]=@SKU4,[SKU5]=@SKU5,[SKU6]=@SKU6,[SKU7]=@SKU7,[SKU8]=@SKU8,SKU9=@SKU9,SKU10=@SKU10,SKU11=@SKU11,SKU12=@SKU12,SKU13=@SKU13,SKU14=@SKU14,SKU15=@SKU15,[Weight]=@Weight,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[MinBuyNum]=@MinBuyNum,[Price]=@Price,[GoodsImageIds]=@GoodsImageIds,[FirstImgUrl]=@FirstImgUrl,[UpdateDate]=@UpdateDate,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[SaleDays]=@SaleDays,[AvgTime]=@AvgTime,[SafeNum]=@SafeNum,[Solid]=@Solid,Barcode=@Barcode where DetailId=@DetailId end else begin INSERT INTO [HW_GoodsDetail]([GoodsId],[TypeCode],[TypeDesc],[SKU1],[SKU2],[SKU3],[SKU4],[SKU5],[SKU6],[SKU7],[SKU8],[Weight],[AutoPlan],[NoGoods],[MinBuyNum],[GoodsNum],[GoodsLockNum],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[Price],[GoodsImageIds],[FirstImgUrl],[UpdateDate],[UpdateName],[GoodsRemark],[SaleDays],[AvgTime],[SafeNum],[Solid],SKU9,SKU10,SKU11,SKU12,SKU13,SKU14,SKU15,Barcode)values(@GoodsId,@TypeCode,@TypeDesc,@SKU1,@SKU2,@SKU3,@SKU4,@SKU5,@SKU6,@SKU7,@SKU8,@Weight,@AutoPlan,@NoGoods,@MinBuyNum,@GoodsNum,@GoodsLockNum,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@Price,@GoodsImageIds,@FirstImgUrl,@UpdateDate,@UpdateName,@GoodsRemark,@SaleDays,@AvgTime,@SafeNum,@Solid,@SKU9,@SKU10,@SKU11,@SKU12,@SKU13,@SKU14,@SKU15,@Barcode) set @DetailId=@@IDENTITY end select @DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@TypeCode", DbType.String, Model.TypeCode); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@SKU2", DbType.String, Model.SKU2); db.AddInParameter(cmd, "@SKU3", DbType.String, Model.SKU3); db.AddInParameter(cmd, "@SKU4", DbType.String, Model.SKU4); db.AddInParameter(cmd, "@SKU5", DbType.String, Model.SKU5); db.AddInParameter(cmd, "@SKU6", DbType.String, Model.SKU6); db.AddInParameter(cmd, "@SKU7", DbType.String, Model.SKU7); db.AddInParameter(cmd, "@SKU8", DbType.String, Model.SKU8); db.AddInParameter(cmd, "@SKU9", DbType.String, Model.SKU9); db.AddInParameter(cmd, "@SKU10", DbType.String, Model.SKU10); db.AddInParameter(cmd, "@SKU11", DbType.String, Model.SKU11); db.AddInParameter(cmd, "@SKU12", DbType.String, Model.SKU12); db.AddInParameter(cmd, "@SKU13", DbType.String, Model.SKU13); db.AddInParameter(cmd, "@SKU14", DbType.String, Model.SKU14); db.AddInParameter(cmd, "@SKU15", DbType.String, Model.SKU15); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@MinBuyNum", DbType.Int32, Model.MinBuyNum); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@SaleDays", DbType.Decimal, Model.SaleDays); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@Barcode", DbType.String, Model.Barcode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 读取首页订单数 public static DT_DefaultDataNew GetDefaultDataForTM3(int CompanyID, DateTime? PreDate, DateTime? SDate, DateTime? EDate) { DT_DefaultDataNew model = null; string tsql = @" declare @Solid Decimal(18,2),@Solid3 Decimal(18,2),@Solid4 Decimal(18,2),@Solid2 Decimal(18,2),@Solid6 Decimal(18,2),@Solid5 Decimal(18,2) select @Solid=isnull(sum(isnull(d.Solid,0)*b.GoodsNum),0) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=1 and a.state>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<=@EDate select @Solid3=isnull(sum(isnull(d.Solid,0)*b.GoodsNum),0) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock)on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId where a.CompanyId=1 and a.state>0 and a.State<3 and e.StoreId=6 and a.OrderDate>=@SDate and a.OrderDate<=@EDate select @Solid4=isnull(sum(isnull(d.Solid,0)*b.GoodsNum),0) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId where a.CompanyId=1 and a.state>0 and a.State<3 and e.StoreId=11 and a.OrderDate>=@SDate and a.OrderDate<=@EDate select @Solid2 =isnull(sum(isnull(d.Solid,0)*b.GoodsNum),0) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=1 and a.PostState=1 and a.state>0 and a.State<3 and datediff(day,a.PostDate,@PreDate)=0 select @Solid5 =isnull(sum(isnull(d.Solid,0)*b.GoodsNum),0) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId inner join DT_OrderXXInfo e on a.OrderId=e.OrderId where a.CompanyId=1 and a.PostState=1 and a.state>0 and a.State<3 and e.StoreId=6 and datediff(day,a.PostDate,@PreDate)=0 select @Solid6 =isnull(sum(isnull(d.Solid,0)*b.GoodsNum),0) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId where a.CompanyId=1 and a.PostState=1 and a.state>0 and a.State<3 and e.StoreId=11 and datediff(day,a.PostDate,@PreDate)=0 select SiglePrice=@Solid,TotalPrice=@Solid2,SiglePrice2=@Solid3,SiglePrice3=@Solid4,SiglePrice4=@Solid5,SiglePrice5=@Solid6 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@PreDate", DbType.DateTime, PreDate); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet tb = db.ExecuteDataSet(cmd); if (tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); return model; } #endregion #region 读取首页编号 public static List GetDefaultDataForCode(int CompanyID, DateTime? SDate, DateTime? EDate) { string tsql = @" select top 3 Num1=b.GoodsCode,Num2=b.FirstImgUrl,Num3=a.GoodsNum from ( select d.GoodsId,GoodsNum=SUM(b.GoodsNum) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by d.GoodsId)a inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId order by a.GoodsNum desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 读取首页编号 public static List GetDefaultDataForCode2(int CompanyID, DateTime? SDate, DateTime? EDate) { string tsql = @" select top 3 Num1=b.GoodsCode,Num2=b.FirstImgUrl,Num4=a.Price from ( select d.GoodsId,Price=SUM(dbo.MoneyUSDChange(a.TotalPrice,a.moneycode,a.companyId)) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate group by d.GoodsId)a inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId order by a.Price desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 按s首页日期返回订单数 public static List GetDefaultCountListFromMonth(DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select ShopId,Month=DATEPART(month,OrderDate),Num=COUNT(0) from DT_OrderInfo with(nolock) where CompanyId=@CompanyId and State>0 and State<3 and OrderDate>=@SDate group by shopId,DATEPART(month,OrderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单数 public static List GetDefaultCountListFromMonthPT(DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select PlatId,Month=DATEPART(month,OrderDate),Num=COUNT(0) from DT_OrderInfo with(nolock) where CompanyId=@CompanyId and State>0 and State<3 and OrderDate>=@SDate group by PlatId,DATEPART(month,OrderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单数 public static List GetDefaultCountListFromMonth2(DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select ShopId=0,Month=DATEPART(month,OrderDate),Num=COUNT(0) from DT_OrderInfo with(nolock) where CompanyId=@CompanyId and State>0 and State<3 and OrderDate>=@SDate group by DATEPART(month,OrderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单金额 public static List GetDefaultCountListFromMonthPrice(DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select ShopId,Month=DATEPART(month,OrderDate),Price=SUM(dbo.MoneyUSDChange(TotalPrice,moneycode,companyid)) from DT_OrderInfo with(nolock) where CompanyId=@CompanyId and State>0 and State<3 and OrderDate>=@SDate group by shopId,DATEPART(month,OrderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单金额 public static List GetDefaultCountListFromMonthPTPrice(DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select PlatId,Month=DATEPART(month,OrderDate),Price=SUM(dbo.MoneyUSDChange(TotalPrice,moneycode,companyid)) from DT_OrderInfo with(nolock) where CompanyId=@CompanyId and State>0 and State<3 and OrderDate>=@SDate group by PlatId,DATEPART(month,OrderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 按s首页日期返回订单金额 public static List GetDefaultCountListFromMonthPrice2(DateTime? SDate, DateTime? EDate, int CompanyId) { string tsql = ""; List list = null; tsql = @"select ShopId=0,Month=DATEPART(month,OrderDate),Price=SUM(dbo.MoneyUSDChange(TotalPrice,moneycode,companyid)) from DT_OrderInfo with(nolock) where CompanyId=@CompanyId and State>0 and State<3 and OrderDate>=@SDate group by DATEPART(month,OrderDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public static List Get_OrderUser2(int IsBJ, int CompanyId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, string OrderCode, string TrackCode, string Name, int OffType, decimal? OffFee) { List list = null; string sql = ""; if (OffFee > 0 && OffType == 1) { sql = " a.Fee9>0 and isnull(c.PostFee,0)-isnull(a.Fee9,0)>@OffFee and "; } if (OffFee > 0 && OffType == 2) { sql = " c.PostFee>0 and isnull(a.Fee9,0)-isnull(c.PostFee,0)>@OffFee and "; } string tsql = @" select a.*,PostFee=c.PostFee,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.RevFax,c.StoreId,c.TrackCode2 into #DT_OrderUserNew from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where (@ShopId=0 or ShopId=@ShopId) and CompanyId=1 and a.State>0 and a.State<3 and OrderDate>=@SDate and OrderDate<@EDate if @IsBJ=1 begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=a.PostFee,a.Fee2,a.Fee3,a.Fee4,a.PostInfo,a.CountryName,a.RevProvince,a.RevCity,a.RevName,a.RevFax,a.StoreId,a.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),a.Fee11,a.Fee12,a.Fee13,BJState=a.OrderName,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee from #DT_OrderUserNew a inner join (select distinct e.OrderId from DT_OrderGoods e with(nolock) inner join HW_GoodsDetail b with(nolock) on e.DetailId=b.DetailId inner join HW_GoodsInfo f with(nolock) on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId where a.OrderName='标记回看' and " + sql + @" a.CompanyId=@CompanyId and (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or a.TrackCode2=@TrackCode) and (@Name='' or a.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) end else begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=a.PostFee,a.Fee2,a.Fee3,a.Fee4,a.PostInfo,a.CountryName,a.RevProvince,a.RevCity,a.RevName,a.RevFax,a.StoreId,a.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),a.Fee11,a.Fee12,a.Fee13,BJState=a.OrderName,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee from #DT_OrderUserNew a inner join (select distinct e.OrderId from DT_OrderGoods e with(nolock) inner join HW_GoodsDetail b with(nolock) on e.DetailId=b.DetailId inner join HW_GoodsInfo f with(nolock) on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId where a.CompanyId=@CompanyId and " + sql + @" (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or a.TrackCode2=@TrackCode) and (@Name='' or a.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) end drop table #DT_OrderUserNew "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@IsBJ", DbType.Int32, IsBJ); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); db.AddInParameter(cmd, "@OffFee", DbType.Decimal, OffFee); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public static List Get_OrderUser2_bak(int IsBJ, int CompanyId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, string OrderCode, string TrackCode, string Name, int OffType, decimal? OffFee) { List list = null; string sql = ""; if (OffFee > 0 && OffType == 1) { sql = " a.Fee9>0 and isnull(c.PostFee,0)-isnull(a.Fee9,0)>@OffFee and "; } if (OffFee > 0 && OffType == 2) { sql = " c.PostFee>0 and isnull(a.Fee9,0)-isnull(c.PostFee,0)>@OffFee and "; } string tsql = @" select * into #DT_OrderUserNew from DT_OrderInfo with(nolock) where (@ShopId=0 or ShopId=@ShopId) and CompanyId=1 and State>0 and State<3 and OrderDate>=@SDate and OrderDate<@EDate if @IsBJ=1 begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.RevFax,c.StoreId,c.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),a.Fee11,a.Fee12,a.Fee13,BJState=a.OrderName,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee from #DT_OrderUserNew a inner join (select distinct e.OrderId from DT_OrderGoods e with(nolock) inner join HW_GoodsDetail b with(nolock) on e.DetailId=b.DetailId inner join HW_GoodsInfo f with(nolock) on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where a.OrderName='标记回看' and " + sql + @" a.CompanyId=@CompanyId and (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) end else begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.RevFax,c.StoreId,c.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),a.Fee11,a.Fee12,a.Fee13,BJState=a.OrderName,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee from #DT_OrderUserNew a inner join (select distinct e.OrderId from DT_OrderGoods e with(nolock) inner join HW_GoodsDetail b with(nolock) on e.DetailId=b.DetailId inner join HW_GoodsInfo f with(nolock) on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where a.CompanyId=@CompanyId and " + sql + @" (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) end drop table #DT_OrderUserNew "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@IsBJ", DbType.Int32, IsBJ); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); db.AddInParameter(cmd, "@OffFee", DbType.Decimal, OffFee); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public static List Get_OrderUser3(int IsBJ, int CompanyId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, string OrderCode, string TrackCode, string Name, int OffType, decimal? OffFee) { List list = null; List list2 = null; string sql = ""; if (OffFee > 0 && OffType == 1) { sql = " a.Fee9>0 and isnull(c.PostFee,0)-isnull(a.Fee9,0)>@OffFee and "; } if (OffFee > 0 && OffType == 2) { sql = " c.PostFee>0 and isnull(a.Fee9,0)-isnull(c.PostFee,0)>@OffFee and "; } string tsql = @" select * into #DT_OrderUserNew from DT_OrderInfo with(nolock) where (@ShopId=0 or ShopId=@ShopId) and CompanyId=1 and State>0 and State<3 and OrderDate>=@SDate and OrderDate<@EDate if @IsBJ=1 begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),a.Fee11,a.Fee12,a.Fee13,BJState=a.OrderName from #DT_OrderUserNew a inner join (select distinct e.OrderId from DT_OrderGoods e with(nolock) inner join HW_GoodsDetail b with(nolock) on e.DetailId=b.DetailId inner join HW_GoodsInfo f with(nolock) on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where a.OrderName='标记回看' and " + sql + @" a.CompanyId=@CompanyId and (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) end else begin select a.OrderId,a.PlatId,a.ShopId,a.PlatOrderCode,a.GoodsNum,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,OrderState2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,escrowFee=isnull(a.escrowFee,0),a.Fee11,a.Fee12,a.Fee13,BJState=a.OrderName from #DT_OrderUserNew a inner join (select distinct e.OrderId from DT_OrderGoods e with(nolock) inner join HW_GoodsDetail b with(nolock) on e.DetailId=b.DetailId inner join HW_GoodsInfo f with(nolock) on b.GoodsId=f.GoodsId where @GoodsCode='' or f.GoodsCode=@GoodsCode)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where a.CompanyId=@CompanyId and " + sql + @" (@OrderState=-1 or a.OrderState2=@OrderState) and (@OrderCode='' or a.PlatOrderCode like '%'+@OrderCode+'%') and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') and (@PlatId=0 or a.PlatId=@PlatId) end select a.OrderId,a.GoodsFee,GoodsCode=e.GoodsCode+'['+isnull(d.sku1,'')+']',d.TypeDesc,e.GoodsName,a.TCFee,a.GoodsNum,ImgUrl=e.FirstImgUrl,FeeRate=a.GoodsRate,a.Id from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail d with(nolock) on a.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join #DT_OrderUserNew f with(nolock) on a.OrderId=f.OrderId where f.CompanyId=@CompanyId and (@GoodsCode='' or e.GoodsCode=@GoodsCode) and (@PlatId=0 or f.PlatId=@PlatId) order by OrderId drop table #DT_OrderUserNew "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@IsBJ", DbType.Int32, IsBJ); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); db.AddInParameter(cmd, "@OffFee", DbType.Decimal, OffFee); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (ds.Tables.Count > 1) list2 = ds.Tables[1].ToList(); if (list2 != null && list != null) { foreach (var md in list) { var glist = list2.FindAll(n => n.OrderId == md.OrderId); md.glist = glist; } } return list; } #endregion #region 查询我的订单 public static List Get_OrderUser(int IsBJ, int CompanyId, int OrderState, int PlatId, int ShopId, int UserId, DateTime? SDate, DateTime? EDate, string GoodsCode, string OrderCode, string TrackCode, string Name, int OffType, decimal? OffFee) { List list = null; string sql = ""; if (OffFee > 0 && OffType == 1) { sql = " a.Fee9>0 and isnull(c.PostFee,0)-isnull(a.Fee9,0)>@OffFee and "; } if (OffFee > 0 && OffType == 2) { sql = " c.PostFee>0 and isnull(a.Fee9,0)-isnull(c.PostFee,0)>@OffFee and "; } string tsql = @" select * into #DT_OrderUserNew from DT_OrderInfo with(nolock) where (@ShopId=0 or ShopId=@ShopId) and CompanyId=1 and State>0 and State<3 and OrderDate>=@SDate and OrderDate<@EDate if @IsBJ=1 begin select a.OrderId,a.PlatId,a.ShopId,a.GoodsNum,a.PlatOrderCode,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.TrackCode2,c.RevFax,c.StoreId,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,a.Fee11,a.Fee12,a.Fee13,OrderState2,escrowFee=isnull(a.escrowFee,0),BJState=a.OrderName,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee from #DT_OrderUserNew a inner join ( select distinct d.OrderId from HW_GoodsUser a with(nolock) inner join HW_GoodsInfo f with(nolock) on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b with(nolock) on f.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join #DT_OrderUserNew d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@PlatId=0 or d.PlatId=@PlatId) and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and (@OrderCode='' or d.PlatOrderCode like '%'+@OrderCode+'%') and a.UserId=@UserId)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where a.OrderName='标记回看' and " + sql + @" (@OrderState=-1 or a.OrderState2=@OrderState) and (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') order by a.OrderDate end else begin select a.OrderId,a.PlatId,a.ShopId,a.GoodsNum,a.PlatOrderCode,a.JoinOrderCode,a.InDate,a.PostDate,a.OrderDate,a.TotalPrice,a.MoneyCode,PostFee=c.PostFee,a.Fee2,a.Fee3,a.Fee4,PostInfo=d.Name,c.CountryName,c.RevProvince,c.RevCity,c.RevName,c.RevFax,c.StoreId,c.TrackCode2,a.GoodsState,a.Fee5,a.Fee6,a.Fee7,a.Fee8,OrderState2,escrowFee=isnull(a.escrowFee,0),BJState=a.OrderName,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee from #DT_OrderUserNew a inner join ( select distinct d.OrderId from HW_GoodsUser a with(nolock) inner join HW_GoodsInfo f with(nolock) on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b with(nolock) on f.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join #DT_OrderUserNew d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@PlatId=0 or d.PlatId=@PlatId) and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and (@OrderCode='' or d.PlatOrderCode like '%'+@OrderCode+'%') and a.UserId=@UserId)b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId left join JC_Express d with(nolock) on c.Post=d.ExpressID where (@OrderState=-1 or a.OrderState2=@OrderState) and " + sql + @" (@TrackCode='' or c.TrackCode2=@TrackCode) and (@Name='' or c.RevName like '%'+@Name+'%') order by a.OrderDate end drop table #DT_OrderUserNew "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@IsBJ", DbType.Int32, IsBJ); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); db.AddInParameter(cmd, "@OffFee", DbType.Decimal, OffFee); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询物品销量 public static List Get_OrderGoodsNum(int CompanyId, DateTime? SDate, DateTime? EDate, string GoodsCode) { List list = null; string tsql = @" select a.OrderDate,b.GoodsNum,d.GoodsCode from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.CompanyId=@CompanyId and a.State>0 and a.State<3 and a.OrderDate>=@SDate and a.OrderDate<@EDate and d.GoodsCode=@GoodsCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion public static void UpdateOtherFeeNew(DateTime InDate, int CompanyId) { string query = @"declare @r nvarchar(3000),@totalfee money set @r='' select @r=@r+';'+isnull(FeeName,0)+'金额:['+cast(totalfee as nvarchar(8))+']' from CK_OtherFee where CompanyId=@CompanyId and DATEDIFF(day,FeeDate,@InDate)=0 select @totalfee=SUM(totalfee) from CK_OtherFee where CompanyId=@CompanyId and DATEDIFF(day,FeeDate,@InDate)=0 delete from CK_FeeReport where CompanyId=@CompanyId and FeeType=9 and DATEDIFF(day,InDate,@InDate)=0 INSERT INTO [CK_FeeReport]([InDate],[FeeType],[TotalFee],[FeeDesc],[CompanyId],[Num],[Num2],[Dec],[Dec2]) select InDate=@InDate,9,totalfee=@totalfee,r=@r,@CompanyId,0,0,@totalfee,0 "; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@InDate", DbType.DateTime, InDate); database.AddInParameter(sqlStringCommand, "@CompanyId", DbType.Int32, CompanyId); database.ExecuteNonQuery(sqlStringCommand); } public static List GetListFeeDetailOther2(int CompanyId, DateTime? FeeDate) { string query = @"select FeeTypeName=e.Name,FeeName=c.YLChar2,FeeDesc=c.YLChar3,c.FeeRate,c.OffRate,FeeDetailId=c.Id,d.Id,d.TotalFee,d.Num,d.FeeName2,d.FeeRemark,d.DoneDate from JC_Company a inner join CK_FeeList b on a.FeeId=b.Id inner join CK_FeeDetail c on b.Id=c.FeeId inner join CK_OtherFee d on c.Id=d.FeeDetailId left join JC_BaseCodeDetail e on c.feetype=e.sortno and e.keyname='FYLX' where isnull(IsAuto,0)=0 and a.CompanyId=@CompanyId and datediff(day,d.FeeDate,@FeeDate)=0"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@CompanyId", DbType.Int32, CompanyId); database.AddInParameter(sqlStringCommand, "@FeeDate", DbType.DateTime, FeeDate); return database.ExecuteDataTable(sqlStringCommand).ToList(); } #region 保存 public static int SaveUserInfo(JC_UserInfo Model) { string tsql = @" if @UserId>0 begin Update [JC_UserInfo] set [Name]=@Name,[SpellName]=@SpellName,[EnglishName]=@EnglishName,[Sex]=@Sex,[UserName]=@UserName,[Password]=@Password,[State]=@State,[CompanyId]=@CompanyId,[UserCode]=@UserCode,[Photo]=@Photo,[UpdateDate]=@UpdateDate,[Duty]=@Duty,[Mobile1]=@Mobile1,[Mobile2]=@Mobile2,[Mobile3]=@Mobile3,[UserCard]=@UserCard,DeptName=@DeptName where UserId=@UserId delete from JC_DepartUser where UserId=@UserId end else begin INSERT INTO [JC_UserInfo]([Name],[SpellName],[EnglishName],[Sex],[UserName],[Password],[UserType],[State],[CompanyId],[UserCode],[Photo],[UpdateDate],[Duty],[Mobile1],[Mobile2],[Mobile3],[UserCard],DeptName,[InDate],LoginCount,IsLogin)values(@Name,@SpellName,@EnglishName,@Sex,@UserName,@Password,@UserType,@State,@CompanyId,@UserCode,@Photo,@UpdateDate,@Duty,@Mobile1,@Mobile2,@Mobile3,@UserCard,@DeptName,@UpdateDate,0,1) set @UserId=SCOPE_IDENTITY() end select @UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@Name", DbType.String, Model.Name); db.AddInParameter(cmd, "@SpellName", DbType.String, Model.SpellName); db.AddInParameter(cmd, "@EnglishName", DbType.String, Model.EnglishName); db.AddInParameter(cmd, "@Sex", DbType.String, Model.Sex); db.AddInParameter(cmd, "@UserName", DbType.String, Model.UserName); db.AddInParameter(cmd, "@Password", DbType.String, Model.Password); db.AddInParameter(cmd, "@UserType", DbType.String, Model.UserType); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@UserCode", DbType.String, Model.UserCode); db.AddInParameter(cmd, "@Photo", DbType.String, Model.Photo); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, DateTime.Now); db.AddInParameter(cmd, "@Duty", DbType.String, Model.Duty); db.AddInParameter(cmd, "@Mobile1", DbType.String, Model.Mobile1); db.AddInParameter(cmd, "@Mobile2", DbType.String, Model.Mobile2); db.AddInParameter(cmd, "@Mobile3", DbType.String, Model.Mobile3); db.AddInParameter(cmd, "@UserCard", DbType.String, Model.UserCard); db.AddInParameter(cmd, "@DeptName", DbType.String, Model.DeptName); Model.UserId = Convert.ToInt32(db.ExecuteScalar(cmd)); return Model.UserId.Value; } #endregion #region 分页查询 public static List GetListJC_UserInfo(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"UserId=cast(a.UserId as int),a.Name,a.SpellName,a.EnglishName,a.Sex,a.UserName,a.Password,a.UserType,a.State,a.CompanyId,a.UserCode,a.LoginCount,a.LastLoginTime,a.LastLoginIp,a.Photo,a.UpdateDate,a.Duty,a.Mobile1,a.Mobile2,a.Mobile3,a.UserCard,a.InDate,a.DeptName,b.CompanyName"; ser.Tables = @"JC_UserInfo a inner join jc_Company b on a.CompanyId=b.CompanyId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "UserId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); foreach (var model in ListModel) { if (model.State == 0) model.StateName = "删除"; if (model.State == 1) model.StateName = "正常"; if (model.State == 2) model.StateName = "限制登录"; if (model.State == 3) model.StateName = "离职"; } return ListModel; } #endregion #region 登录 public static JC_UserInfo LoginNew(string UserName, string PassWord, string LoginIp, int IsNB) { string tsql = @" declare @UserID int,@Name nvarchar(20),@UserType nvarchar(5) if @IsNB=1 or (select count(0) from [JC_InnerIp] where InnerIp=@LoginIp and InnerIp Is not null)>0 begin select top 1 @UserID=UserID from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserName=@UserName and a.PassWord=@PassWord and UserType<>'H' and a.State=1 and b.State=1 end else begin select top 1 @UserID=UserID from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserName=@UserName and a.PassWord=@PassWord and UserType<>'H' and a.State=1 and b.State=1 and a.IsLogin=1 end select a.UserID,a.Name,a.UserType,a.CompanyId,CompanyName=b.SimpleName,a.DeptId,a.Duty,UserCard=isnull(a.RoomAddr,0),a.Mobile3 from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserID=@UserID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, UserName); db.AddInParameter(cmd, "@PassWord", DbType.String, PassWord); db.AddInParameter(cmd, "@LoginIp", DbType.String, LoginIp); db.AddInParameter(cmd, "@IsNB", DbType.String, IsNB); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } #endregion #region 登录 public static JC_UserInfo LoginNew2(string UserName, string PassWord) { string tsql = @" declare @UserID int select top 1 @UserID=UserID from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserName=@UserName and a.PassWord=@PassWord and UserType<>'P' and a.State=1 and b.State=1 and a.IsLogin=1 select a.UserID,a.Name,a.UserType,a.CompanyId,CompanyName=b.SimpleName,a.DeptId,a.Duty from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserID=@UserID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, UserName); db.AddInParameter(cmd, "@PassWord", DbType.String, PassWord); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } #endregion #region 读取用户 public static List GetListCustom(int UserId) { string tsql = "select ID=UserId,Name from JC_UserInfo where UserType<>'P' and CompanyID=1 and State=1"; if (UserId > 1) { tsql = "select ID=UserId,Name from JC_UserInfo where UserId=" + UserId + " and State=1"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 分页动态条件查询 public static List GetListCompany(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select CompanyId=cast(a.CompanyId as int),a.CompanyCode,a.ParentCompanyId,a.CompanyName,a.SimpleName,a.CompanyType,a.Address,a.Phone,a.Fax,a.Email,a.HomePage,a.ChargeName,a.Shen,a.Shi,a.Qu,a.CompanyDesc,a.State,a.PostCode,a.province,a.city,a.county,a.street,a.EnglishAddress,a.CompanyEnglishName,a.ChargeEnglishName,a.WeightRate,a.PersonFee,a.ApiKey,a.FeeId,a.KHUserId,UserName='',PassWord='',KHName=b.Name,a.HJFee,a.HJYGFee,a.NowFee from JC_Company a left join Jc_userInfo b on a.KHUserId=b.UserId"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.CompanyId desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 读取用户 public static JC_UserInfo GetUserInfoMd(int CompanyId) { string tsql = "select top 1 * from JC_UserInfo where CompanyID=@CompanyId and State=1 order by UserId"; JC_UserInfo model = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 保存 public static int SaveUserInfo2(JC_UserInfo2 Model) { string tsql = @" select top 1 @UserId=UserId from JC_UserInfo where CompanyId=@CompanyId and state=1 order by UserId if @UserId>0 begin Update [JC_UserInfo] set [Name]=@Name,[SpellName]=@SpellName,[EnglishName]=@EnglishName,[Sex]=@Sex,[UserName]=@UserName,[Password]=@Password,[UserType]=@UserType,[State]=@State,[CompanyId]=@CompanyId,[UserCode]=@UserCode,[LoginCount]=@LoginCount,[LastLoginTime]=@LastLoginTime,[LastLoginIp]=@LastLoginIp,[Photo]=@Photo,[UpdateDate]=@UpdateDate,[Duty]=@Duty,[Mobile1]=@Mobile1,[Mobile2]=@Mobile2,[Mobile3]=@Mobile3,[UserCard]=@UserCard,[InDate]=@InDate,[DeptName]=@DeptName,[IDCard]=@IDCard,[SchoolLevel]=@SchoolLevel,[School]=@School,[BornDate]=@BornDate,[BornAddr]=@BornAddr,[ContractDate]=@ContractDate,[JoinDate]=@JoinDate,[FormalDate]=@FormalDate,[IsMarry]=@IsMarry,[IsBaby]=@IsBaby,[HuKou]=@HuKou,[HuKouAddr]=@HuKouAddr,[NowAddr]=@NowAddr,[IsRoom]=@IsRoom,[RoomAddr]=@RoomAddr,[Political]=@Political,[DeptId]=@DeptId,[Traffic]=@Traffic,[QQ]=@QQ,[Email]=@Email,[EmployeeType]=@EmployeeType,[Holidays]=@Holidays,[IsLogin]=@IsLogin,[WorkDesc]=@WorkDesc,[AnnualDay]=@AnnualDay,[MoodDay]=@MoodDay where UserId=@UserId end else begin INSERT INTO [JC_UserInfo]([Name],[SpellName],[EnglishName],[Sex],[UserName],[Password],[UserType],[State],[CompanyId],[UserCode],[LoginCount],[LastLoginTime],[LastLoginIp],[Photo],[UpdateDate],[Duty],[Mobile1],[Mobile2],[Mobile3],[UserCard],[InDate],[DeptName],[IDCard],[SchoolLevel],[School],[BornDate],[BornAddr],[ContractDate],[JoinDate],[FormalDate],[IsMarry],[IsBaby],[HuKou],[HuKouAddr],[NowAddr],[IsRoom],[RoomAddr],[Political],[DeptId],[Traffic],[QQ],[Email],[EmployeeType],[Holidays],[IsLogin],[WorkDesc],[AnnualDay],[MoodDay])values(@Name,@SpellName,@EnglishName,@Sex,@UserName,@Password,@UserType,@State,@CompanyId,@UserCode,@LoginCount,@LastLoginTime,@LastLoginIp,@Photo,@UpdateDate,@Duty,@Mobile1,@Mobile2,@Mobile3,@UserCard,@InDate,@DeptName,@IDCard,@SchoolLevel,@School,@BornDate,@BornAddr,@ContractDate,@JoinDate,@FormalDate,@IsMarry,@IsBaby,@HuKou,@HuKouAddr,@NowAddr,@IsRoom,@RoomAddr,@Political,@DeptId,@Traffic,@QQ,@Email,@EmployeeType,@Holidays,@IsLogin,@WorkDesc,@AnnualDay,@MoodDay) set @UserId=SCOPE_IDENTITY() end select @UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@Name", DbType.String, Model.Name); db.AddInParameter(cmd, "@SpellName", DbType.String, Model.SpellName); db.AddInParameter(cmd, "@EnglishName", DbType.String, Model.EnglishName); db.AddInParameter(cmd, "@Sex", DbType.String, Model.Sex); db.AddInParameter(cmd, "@UserName", DbType.String, Model.UserName); db.AddInParameter(cmd, "@Password", DbType.String, Model.Password); db.AddInParameter(cmd, "@UserType", DbType.String, Model.UserType); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@UserCode", DbType.String, Model.UserCode); db.AddInParameter(cmd, "@LoginCount", DbType.Int32, Model.LoginCount); db.AddInParameter(cmd, "@LastLoginTime", DbType.DateTime, Model.LastLoginTime); db.AddInParameter(cmd, "@LastLoginIp", DbType.String, Model.LastLoginIp); db.AddInParameter(cmd, "@Photo", DbType.String, Model.Photo); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@Duty", DbType.String, Model.Duty); db.AddInParameter(cmd, "@Mobile1", DbType.String, Model.Mobile1); db.AddInParameter(cmd, "@Mobile2", DbType.String, Model.Mobile2); db.AddInParameter(cmd, "@Mobile3", DbType.String, Model.Mobile3); db.AddInParameter(cmd, "@UserCard", DbType.String, Model.UserCard); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@DeptName", DbType.String, Model.DeptName); db.AddInParameter(cmd, "@IDCard", DbType.String, Model.IDCard); db.AddInParameter(cmd, "@SchoolLevel", DbType.String, Model.SchoolLevel); db.AddInParameter(cmd, "@School", DbType.String, Model.School); db.AddInParameter(cmd, "@BornDate", DbType.DateTime, Model.BornDate); db.AddInParameter(cmd, "@BornAddr", DbType.String, Model.BornAddr); db.AddInParameter(cmd, "@ContractDate", DbType.DateTime, Model.ContractDate); db.AddInParameter(cmd, "@JoinDate", DbType.DateTime, Model.JoinDate); db.AddInParameter(cmd, "@FormalDate", DbType.DateTime, Model.FormalDate); db.AddInParameter(cmd, "@IsMarry", DbType.String, Model.IsMarry); db.AddInParameter(cmd, "@IsBaby", DbType.String, Model.IsBaby); db.AddInParameter(cmd, "@HuKou", DbType.String, Model.HuKou); db.AddInParameter(cmd, "@HuKouAddr", DbType.String, Model.HuKouAddr); db.AddInParameter(cmd, "@NowAddr", DbType.String, Model.NowAddr); db.AddInParameter(cmd, "@IsRoom", DbType.Int32, Model.IsRoom); db.AddInParameter(cmd, "@RoomAddr", DbType.String, Model.RoomAddr); db.AddInParameter(cmd, "@Political", DbType.String, Model.Political); db.AddInParameter(cmd, "@DeptId", DbType.Int32, Model.DeptId); db.AddInParameter(cmd, "@Traffic", DbType.String, Model.Traffic); db.AddInParameter(cmd, "@QQ", DbType.String, Model.QQ); db.AddInParameter(cmd, "@Email", DbType.String, Model.Email); db.AddInParameter(cmd, "@EmployeeType", DbType.String, Model.EmployeeType); db.AddInParameter(cmd, "@Holidays", DbType.Int32, Model.Holidays); db.AddInParameter(cmd, "@IsLogin", DbType.Int32, Model.IsLogin); db.AddInParameter(cmd, "@WorkDesc", DbType.String, Model.WorkDesc); db.AddInParameter(cmd, "@AnnualDay", DbType.Int32, Model.AnnualDay); db.AddInParameter(cmd, "@MoodDay", DbType.Int32, Model.MoodDay); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_Company(JC_CompanyNew Model) { string tsql = @" if @CompanyId>0 begin Update [JC_Company] set [CompanyCode]=@CompanyCode,[ParentCompanyId]=@ParentCompanyId,[CompanyName]=@CompanyName,[SimpleName]=@SimpleName,[CompanyType]=@CompanyType,[Address]=@Address,[Phone]=@Phone,[Fax]=@Fax,[Email]=@Email,[HomePage]=@HomePage,[ChargeName]=@ChargeName,[Shen]=@Shen,[Shi]=@Shi,[Qu]=@Qu,[CompanyDesc]=@CompanyDesc,[State]=@State,[PostCode]=@PostCode,[province]=@province,[city]=@city,[county]=@county,[street]=@street,[EnglishAddress]=@EnglishAddress,[CompanyEnglishName]=@CompanyEnglishName,[ChargeEnglishName]=@ChargeEnglishName,[WeightRate]=@WeightRate,[PersonFee]=@PersonFee,[ApiKey]=@ApiKey,[FeeId]=@FeeId,KHUserId=@KHUserId where CompanyId=@CompanyId end else begin INSERT INTO [JC_Company]([CompanyCode],[ParentCompanyId],[CompanyName],[SimpleName],[CompanyType],[Address],[Phone],[Fax],[Email],[HomePage],[ChargeName],[Shen],[Shi],[Qu],[CompanyDesc],[State],[PostCode],[province],[city],[county],[street],[EnglishAddress],[CompanyEnglishName],[ChargeEnglishName],[WeightRate],[PersonFee],[ApiKey],FeeId,KHUserId)values(@CompanyCode,@ParentCompanyId,@CompanyName,@SimpleName,@CompanyType,@Address,@Phone,@Fax,@Email,@HomePage,@ChargeName,@Shen,@Shi,@Qu,@CompanyDesc,@State,@PostCode,@province,@city,@county,@street,@EnglishAddress,@CompanyEnglishName,@ChargeEnglishName,@WeightRate,@PersonFee,@ApiKey,@FeeId,@KHUserId) set @CompanyId=SCOPE_IDENTITY() end select @CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyID); db.AddInParameter(cmd, "@CompanyCode", DbType.String, Model.CompanyCode); db.AddInParameter(cmd, "@ParentCompanyId", DbType.Int32, Model.ParentCompanyId); db.AddInParameter(cmd, "@CompanyName", DbType.String, Model.CompanyName); db.AddInParameter(cmd, "@SimpleName", DbType.String, Model.SimpleName); db.AddInParameter(cmd, "@CompanyType", DbType.Int32, Model.CompanyType); db.AddInParameter(cmd, "@Address", DbType.String, Model.Address); db.AddInParameter(cmd, "@Phone", DbType.String, Model.Phone); db.AddInParameter(cmd, "@Fax", DbType.String, Model.Fax); db.AddInParameter(cmd, "@Email", DbType.String, Model.Email); db.AddInParameter(cmd, "@HomePage", DbType.String, Model.HomePage); db.AddInParameter(cmd, "@ChargeName", DbType.String, Model.ChargeName); db.AddInParameter(cmd, "@Shen", DbType.String, Model.Shen); db.AddInParameter(cmd, "@Shi", DbType.String, Model.Shi); db.AddInParameter(cmd, "@Qu", DbType.String, Model.Qu); db.AddInParameter(cmd, "@CompanyDesc", DbType.String, Model.CompanyDesc); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@PostCode", DbType.String, Model.PostCode); db.AddInParameter(cmd, "@province", DbType.String, Model.province); db.AddInParameter(cmd, "@city", DbType.String, Model.city); db.AddInParameter(cmd, "@county", DbType.String, Model.county); db.AddInParameter(cmd, "@street", DbType.String, Model.street); db.AddInParameter(cmd, "@EnglishAddress", DbType.String, Model.EnglishAddress); db.AddInParameter(cmd, "@CompanyEnglishName", DbType.String, Model.CompanyEnglishName); db.AddInParameter(cmd, "@ChargeEnglishName", DbType.String, Model.ChargeEnglishName); db.AddInParameter(cmd, "@WeightRate", DbType.Int32, Model.WeightRate); db.AddInParameter(cmd, "@PersonFee", DbType.Decimal, Model.PersonFee); db.AddInParameter(cmd, "@ApiKey", DbType.String, Model.ApiKey); db.AddInParameter(cmd, "@FeeId", DbType.Int32, Model.FeeId); db.AddInParameter(cmd, "@KHUserId", DbType.Int32, Model.KHUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 读取全部或单个机构 public static List GetListCompany1(int CompanyID, int UserId) { string tsql = @" if @UserId=1 begin select ID=CompanyID,Name=CompanyName from JC_Company where CompanyID>1 and State=1 end else if @UserId>0 and (select count(0) from JC_Company where State=1 and KHUserId=@UserId)>0 begin select ID=CompanyID,Name=CompanyName from JC_Company where State=1 and KHUserId=@UserId end else begin select ID=CompanyID,Name=CompanyName from JC_Company where CompanyID>1 and State=1 end "; if (CompanyID > 0) { tsql = "select ID=CompanyId,Name=CompanyName from JC_Company where CompanyID=" + CompanyID + " and State=1"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取全部或单个机构 public static List GetListCompany3(int CompanyID, int UserId) { string tsql = @" if @UserId=1 begin select ID=CompanyID,Name=CompanyName from JC_Company where CompanyID>1 and State=1 end else if @UserId>0 and (select count(0) from JC_Company where State=1 and KHUserId=@UserId)>0 begin select ID=CompanyID,Name=CompanyName from JC_Company where State=1 and KHUserId=@UserId end else begin select ID=CompanyID,Name=CompanyName from JC_Company where CompanyID>1 and State=1 end"; if (CompanyID > 1) { tsql = "select ID=CompanyId,Name=CompanyName from JC_Company where CompanyID=" + CompanyID + " and State=1"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取全部或单个机构 public static List GetListCompany2(int CompanyID, int UserId) { string tsql = @" if @UserId=1 begin select ID=CompanyID,Name=CompanyName from JC_Company where CompanyID>1 and State=1 end else if @UserId>0 and (select count(0) from JC_Company where State=1 and CompanyId>1 and KHUserId=@UserId)>0 begin select ID=CompanyID,Name=CompanyName from JC_Company where State=1 and CompanyId>1 and KHUserId=@UserId end else begin select ID=CompanyID,Name=CompanyName from JC_Company where State=1 and CompanyId=@CompanyID end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取菜单 public static List GetListMenu2(int UserID, int CompanyId) { string tsql = @" declare @UserType nvarchar(10) select top 1 @UserType=UserType from JC_UserInfo where UserID=@UserID if @UserType='M' begin select * from JC_MenuList2 where IsUse=1 and id not in (select id from JC_MenuList2 where CompanyId is not null and CompanyId<>@CompanyId) order by SortNo end else begin if (select count(0) from JC_Company where State=1 and CompanyId>1 and KHUserId=@UserId)>0 begin select * from JC_MenuList2 where IsUse=1 and PopedomType>0 order by SortNo end else if @CompanyId=1 begin select * from JC_MenuList2 where IsUse=1 and PopedomType>1 order by SortNo end else if @CompanyId>1 begin select * from JC_MenuList2 where IsUse=1 and PopedomType>0 and PopedomType<5 order by SortNo end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserID", DbType.Int32, UserID); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 分页查询 public static List GetListGoodsUser22(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.GoodsId,a.UserId,a.grade,a.ShopId,b.Name,c.ShopName,d.GoodsCode,d.FirstImgUrl,GoodsNum=(select SUM(isnull(GoodsNum,0)) from HW_GoodsDetail where GoodsId=a.GoodsId) "; ser.Tables = @"HW_GoodsUser a with(nolock) inner join jc_userinfo b with(nolock) on a.UserId=b.UserId inner join jc_shop c with(nolock) on a.shopid=c.shopid inner join Hw_GoodsInfo d with(nolock) on a.GoodsId=d.GoodsId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListGoodsUser(int? Days, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); if (Days > 0) { ser.Fields = @"Id=cast(a.Id as int),a.GoodsId,a.UserId,a.ShopId,b.Name,d.GoodsCode,d.FirstImgUrl,GoodsNum=isnull(e.GoodsNum,0),GoodsHJNum=isnull(e.GoodsHJNum,0),GoodsHJNum2=isnull(e.GoodsHJNum2,0),GoodsHJNum3=isnull(e.GoodsHJNum3,0),GoodsHJNum4=isnull(e.GoodsHJNum4,0),d.LastOrderDate,Days=DATEDIFF(day,d.LastOrderDate,GETDATE()),b.UserName,a.grade"; ser.Tables = @"HW_GoodsUser a with(nolock) inner join jc_userinfo b with(nolock) on a.UserId=b.UserId inner join (select * from Hw_GoodsInfo with(nolock) where LastOrderDate is null or DATEDIFF(day,LastOrderDate,GETDATE())>=" + Days + @")d on a.GoodsId=d.GoodsId inner join (select GoodsId,GoodsNum=SUM(isnull(GoodsNum,0)),GoodsHJNum=SUM(isnull(GoodsHJNum,0)),GoodsHJNum2=SUM(isnull(GoodsHJNum2,0)),GoodsHJNum3=SUM(isnull(GoodsHJNum3,0)),GoodsHJNum4=SUM(isnull(GoodsHJNum4,0)) from HW_GoodsDetail with(nolock) group by GoodsId)e on d.GoodsId=e.GoodsId "; } else { ser.Fields = @"Id=cast(a.Id as int),a.GoodsId,a.UserId,a.ShopId,b.Name,d.GoodsCode,d.FirstImgUrl,GoodsNum=isnull(e.GoodsNum,0),GoodsHJNum=isnull(e.GoodsHJNum,0),GoodsHJNum2=isnull(e.GoodsHJNum2,0),GoodsHJNum3=isnull(e.GoodsHJNum3,0),GoodsHJNum4=isnull(e.GoodsHJNum4,0),d.LastOrderDate,Days=DATEDIFF(day,d.LastOrderDate,GETDATE()),b.UserName,a.grade"; ser.Tables = @"HW_GoodsUser a with(nolock) inner join jc_userinfo b with(nolock) on a.UserId=b.UserId inner join Hw_GoodsInfo d with(nolock) on a.GoodsId=d.GoodsId inner join (select GoodsId,GoodsNum=SUM(isnull(GoodsNum,0)),GoodsHJNum=SUM(isnull(GoodsHJNum,0)),GoodsHJNum2=SUM(isnull(GoodsHJNum2,0)),GoodsHJNum3=SUM(isnull(GoodsHJNum3,0)),GoodsHJNum4=SUM(isnull(GoodsHJNum4,0)) from HW_GoodsDetail with(nolock) group by GoodsId)e on d.GoodsId=e.GoodsId "; } ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region public static void UpdateGoodsGrade(int id, string grade) { string tsql = @" update HW_GoodsUser set grade=@grade where id=@id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@grade", DbType.String, grade); db.ExecuteNonQuery(cmd); } #endregion #region public static void UpdateGoodsUser(int shopid, string name, int userid) { string tsql = @" update a set a.UserId=@userid from HW_GoodsUser a inner join JC_UserInfo b on a.UserId=b.UserId where b.Name=@name and (@shopid=0 or shopid=@shopid) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@name", DbType.String, name); db.ExecuteNonQuery(cmd); EditGoodsUser(); } #endregion #region public static void EditGoodsUser() { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("UpdateGoodsUser"); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListGoodsUser2(int Type, int UserId, DateTime? Sdate, DateTime? Edate) { string tsql = @"select b.Name,b.UserName,c.GoodsCode,GoodsNum=isnull(c.GoodsNum,0),GoodsHJNum=e.GoodsNum,c.LastOrderDate,c.FirstImgUrl from HW_GoodsUser a inner join JC_UserInfo b on a.UserId=b.UserId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId inner join (select a.GoodsId,GoodsNum=SUM(c.GoodsNum) from HW_GoodsUser a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join HW_GoodsDetail e on b.GoodsId=e.GoodsId inner join DT_OrderGoods c on e.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where a.UserId=@UserId and d.CompanyId=1 and d.State>0 and d.State<3 and d.OrderDate>=@Sdate and d.OrderDate<@Edate group by a.GoodsId)e on a.GoodsId=e.GoodsId where a.UserId=@UserId"; if (Type == 2) { tsql = @"select b.Name,b.UserName,c.GoodsCode,GoodsNum=isnull(c.GoodsNum,0),GoodsHJNum=isnull(e.GoodsNum,0),c.LastOrderDate,c.FirstImgUrl from HW_GoodsUser a inner join JC_UserInfo b on a.UserId=b.UserId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId left join (select a.GoodsId,GoodsNum=SUM(c.GoodsNum) from HW_GoodsUser a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join HW_GoodsDetail e on b.GoodsId=e.GoodsId inner join DT_OrderGoods c on e.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where a.UserId=@UserId and d.CompanyId=1 and d.State>0 and d.State<3 and d.OrderDate>=@Sdate and d.OrderDate<@Edate group by a.GoodsId)e on a.GoodsId=e.GoodsId where a.UserId=@UserId and e.GoodsId is null"; } if (Type == 0) { tsql = @"select b.Name,b.UserName,c.GoodsCode,GoodsNum=isnull(c.GoodsNum,0),GoodsHJNum=isnull(e.GoodsNum,0),c.LastOrderDate,c.FirstImgUrl from HW_GoodsUser a inner join JC_UserInfo b on a.UserId=b.UserId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId left join (select a.GoodsId,GoodsNum=SUM(c.GoodsNum) from HW_GoodsUser a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join HW_GoodsDetail e on b.GoodsId=e.GoodsId inner join DT_OrderGoods c on e.DetailId=c.DetailId inner join DT_OrderInfo d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where a.UserId=@UserId and d.CompanyId=1 and d.State>0 and d.State<3 and d.OrderDate>=@Sdate and d.OrderDate<@Edate group by a.GoodsId)e on a.GoodsId=e.GoodsId where a.UserId=@UserId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@Sdate", DbType.DateTime, Sdate); db.AddInParameter(cmd, "@Edate", DbType.DateTime, Edate); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region public static void UpdateGoodsDays() { string tsql = @" update a set a.LastOrderDate=b.OrderDate from HW_GoodsInfo a inner join ( select d.GoodsId,OrderDate=MAX(a.OrderDate) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where DATEDIFF(day, a.OrderDate,getdate())<2 group by d.GoodsId)b on a.GoodsId=b.GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region public static void UpdateGoodsFees() { string tsql = @" update HW_GoodsInfo set tcrate=0.03 from HW_GoodsInfo where DATEDIFF(month,InDate,GETDATE())<=15 and tcrate<>0.03 update HW_GoodsInfo set tcrate=0.02 from HW_GoodsInfo where DATEDIFF(month,InDate,GETDATE())>15 and DATEDIFF(month,InDate,GETDATE())<27 and tcrate<>0.02 update HW_GoodsInfo set tcrate=0.01 from HW_GoodsInfo where DATEDIFF(month,InDate,GETDATE())>=27 and DATEDIFF(month,InDate,GETDATE())<36 and tcrate<>0.01 update HW_GoodsInfo set tcrate=0.005 from HW_GoodsInfo where DATEDIFF(month,InDate,GETDATE())>=36 and tcrate<>0.005 update HW_GoodsInfo set tcrate=0.005 from HW_GoodsInfo where tcrate<>0.005 and isnull(KFName,'')<>'' and KFName<>KFName2 update a set a.goodsid=c.GoodsId,a.shopid=d.ShopId from DT_AdFee a inner join DT_OrderGoods b on a.adasin=b.productImgUrl inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join DT_OrderInfo d on b.OrderId=d.OrderId where ISNULL(a.goodsid,0)=0 update a set a.goodsid=b.goodsid from DT_AdFee a inner join HW_GoodsInfo b on a.adsku=b.GoodsCode where ISNULL(a.goodsid,0)=0 select distinct adsku into #ls_sku from DT_AdFee where ISNULL(goodsid,0)=0 select id=dbo.MateSKU(adsku,1),adsku into #ls_sku2 from #ls_sku update c set c.goodsid=b.GoodsId from #ls_sku2 a inner join HW_GoodsDetail b on a.id=b.DetailId inner join DT_AdFee c on a.adsku=c.adsku where ISNULL(c.goodsid,0)=0 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 删除机构 public static void DeleteJC_Company(int CompanyId) { string tsql = @" delete from JC_Company where CompanyId=@CompanyId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 计算合计 public static void SumKC(int CompanyId) { string tsql = @"delete from HW_GoodsInDetail2 where companyid=@companyid if @CompanyId>1 begin INSERT INTO [HW_GoodsInDetail2] ([DetailId] ,[StoreId] ,[PostionId] ,[InDate] ,[InUserId] ,[KCNum] ,[UpDateTime],companyid) select DetailId,StoreId,PostionId,GETDATE(),1,KCNum=SUM(KCNum),null,companyid=@CompanyId from HW_GoodsInDetailHWC where StoreId=6 and companyid=@CompanyId and OrderGoodsId=0 and KCNum>0 group by StoreId,PostionId,DetailId end else begin INSERT INTO [HW_GoodsInDetail2] ([DetailId] ,[StoreId] ,[PostionId] ,[InDate] ,[InUserId] ,[KCNum] ,[UpDateTime],companyid) select DetailId,StoreId,PostionId,GETDATE(),1,KCNum=SUM(KCNum),null,companyid=@CompanyId from HW_GoodsInDetail where StoreId=6 and OrderGoodsId=0 and KCNum>0 group by StoreId,PostionId,DetailId end update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join (select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where CompanyId=@CompanyId and isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsNum<>b.GoodsNum "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 刷新库存 public static void UpdateGoodsNumHWC(int GoodsId) { string tsql = @" update HW_GoodsDetail set GoodsNum=0,GoodsInNum=0,GoodsPlanNum=0 where GoodsId=@GoodsId update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsPlanNum<>b.GoodsNum and a.GoodsId=@GoodsId update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsNum<>b.GoodsNum and a.GoodsId=@GoodsId update a set a.GoodsInNum=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.GoodsNum-isnull(b.InGoodsNum,0)-isnull(b.BackNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId where a.IsDelete=0 and isnull(IsGJ,0)=0 and isnull(a.IsFactory,0)=0 and isnull(a.IsBH,0)=0 and a.State<3 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId where a.GoodsInNum<>b.GoodsNum and a.GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 计算仓储费 public static void SumStoreFee(DateTime InDate, int CompanyId) { string tsql = @" --declare @InDate datetime,@CompanyId int --set @InDate='2018-04-12' --set @CompanyId=3 delete from CK_FeeReport where FeeType=1 and DATEDIFF(day,InDate,@InDate)=0 and CompanyId=@CompanyId INSERT INTO [CK_FeeReport] ([InDate] ,[FeeType] ,[TotalFee] ,[FeeDesc] ,[CompanyId] ,[Num] ,[Num2] ,[Dec] ,[Dec2]) select CONVERT(nvarchar(10),@InDate,120),1,price=isnull(a.Solid,0)*isnull(b.FeeRate,0),'库存立方'+CAST(isnull(a.Solid,0) as nvarchar(10)),a.CompanyId,a.KCNum,0,isnull(a.Solid2,0),null from ( select a.CompanyId,Solid=sum(isnull(c.Solid,0)*a.KCNum),KCNum=SUM(a.KCNum),Solid2=SUM(isnull(c.Solid,0)) from HW_GoodsInDetailHWC a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.companyid=@CompanyId and a.KCNum>0 and CKDetailId=0 and a.InDate<=@InDate group by a.CompanyId)a inner join ( select a.FeeRate,c.CompanyId from CK_FeeDetail a inner join CK_FeeList b on a.FeeId=b.Id inner join JC_Company c on b.Id=c.FeeId where a.FeeType=1)b on a.CompanyId=b.CompanyId where a.CompanyId=@CompanyId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.ExecuteNonQuery(cmd); } #endregion #region 计算入库操作费 public static void SumInDoFee(DateTime InDate, int CompanyId) { string tsql = @" delete from CK_FeeReport where FeeType=6 and CompanyId=@CompanyId and DATEDIFF(day,InDate,@InDate)=0 INSERT INTO [CK_FeeReport] ([InDate] ,[FeeType] ,[TotalFee] ,[FeeDesc] ,[CompanyId] ,[Num] ,[Num2] ,[Dec] ,[Dec2]) select CONVERT(nvarchar(10),GETDATE(),120),1,price=isnull(KCNum,0)*isnull(b.FeeRate,0),'入库接件数:'+CAST(isnull(KCNum,0) as nvarchar(10)),a.CompanyId,a.KCNum,0,isnull(KCNum,0),null from ( select CompanyId,KCNum=SUM(KCNum) from HW_GoodsInDetailHWC where CompanyId=@CompanyId and DATEDIFF(day,InDate,@InDate)=0 and OrderGoodsId>=0 group by CompanyId )a inner join ( select a.FeeRate,c.CompanyId from CK_FeeDetail a inner join CK_FeeList b on a.FeeId=b.Id inner join JC_Company c on b.Id=c.FeeId where a.FeeType=6 and c.CompanyId=@CompanyId)b on a.CompanyId=b.CompanyId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.ExecuteNonQuery(cmd); } #endregion #region 计算运费 public static void SumPostFee(int CompanyId) { string tsql = @" delete from CK_FeeReport where FeeType=4 and CompanyId=@CompanyId and DATEDIFF(day,InDate,getdate())<200 INSERT INTO [CK_FeeReport] ([InDate] ,[FeeType] ,[TotalFee] ,[FeeDesc] ,[CompanyId] ,[Num] ,[Num2] ,[Dec] ,[Dec2]) select CONVERT(varchar(10),a.indate,120),4,postfee=SUM(a.postfee),'发货单数:'+cast(count(0) as nvarchar(10)),CompanyId=@CompanyId,count(0),null,postfee1=SUM(a.postfee),null from DT_TrackCodeScan a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and datediff(day,a.indate,getdate())<200 and a.PostFee>0 group by CONVERT(varchar(10),a.indate,120) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.ExecuteNonQuery(cmd); } #endregion #region 查询库存 public static List GetListGoodsInDetailHWC(int CompanyID, string SKU, string PostionCode) { string tsql = @" declare @DetailId int,@PostionId int set @DetailId=0 set @PostionId=0 select @DetailId=a.DetailId from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (a.SKU1=@SKU or a.SKU2=@SKU or a.SKU3=@SKU or a.SKU4=@SKU or a.SKU5=@SKU or a.SKU6=@SKU) select @PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode if @DetailId=0 begin select InId=-1 end else if @PostionId=0 begin select InId=-2 end else begin select * from HW_GoodsInDetailHWC where DetailId=@DetailId and PostionId=@PostionId and CompanyID=@CompanyID and OrderGoodsId=0 and KCNum>0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 保存 public static int Save_GoodsInDetailHWC2(HW_GoodsInDetailHWC Model) { string tsql = @" Update [HW_GoodsInDetailHWC] set [DetailId]=@DetailId,[ChaseId]=@ChaseId,[StoreId]=@StoreId,[PostionId]=@PostionId,[Price]=@Price,[PostPrice]=@PostPrice,[InDate]=@InDate,[InUserId]=@InUserId,[OrderGoodsId]=@OrderGoodsId,[KCNum]=@KCNum,[UpDateTime]=@UpDateTime,[RKDetailId]=@RKDetailId,[CKDetailId]=@CKDetailId,[OldNum]=@OldNum,[HWCFee]=@HWCFee,[CompanyId]=@CompanyId where InId=@InId select @InId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InId", DbType.Int32, Model.InId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@OrderGoodsId", DbType.Int32, Model.OrderGoodsId); db.AddInParameter(cmd, "@KCNum", DbType.Int32, Model.KCNum); db.AddInParameter(cmd, "@UpDateTime", DbType.DateTime, Model.UpDateTime); db.AddInParameter(cmd, "@RKDetailId", DbType.Int32, Model.RKDetailId); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, Model.CKDetailId); db.AddInParameter(cmd, "@OldNum", DbType.Int32, Model.OldNum); db.AddInParameter(cmd, "@HWCFee", DbType.Decimal, Model.HWCFee); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询库存 public static DataTable GetListGoodsInDetailHWC2(int CompanyID) { string tsql = @" select a.DetailId,a.PostionId,a.KCNum,d.PostionCode,d.PostionBox,c.GoodsName,c.GoodsCode,b.SKU1,b.TypeDesc,KCNum2='' from ( select a.DetailId,a.PostionId,KCNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where a.CompanyId=@CompanyID and KCNum>0 and OrderGoodsId=0 group by a.DetailId,a.PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 分页查询 public static List GetListJC_ShopForHWC(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"ShopId=cast(a.ShopId as int),a.ShopName,PlatName=[dbo].[GetPlatName](a.ShopId),a.PlatType,a.DeptId,a.InDate,a.CompanyId,a.RequestMaxNumber,a.RequestNumber,a.Appkey,a.DeveKey,a.RefreshToken,a.AccessToken,a.Country,a.RefreshTokenSaveTime,a.AccessTokenUpdateTime,a.IsFba,a.IsAutoReadData,a.OutDay,DeptName=b.CompanyName,a.Master,a.Buyer,a.ShopUser"; ser.Tables = @"JC_Shop a inner join JC_Company b on a.CompanyId=b.CompanyId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "ShopId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 读取店铺 public static List GetShopList(int CompanyID, int PlatType) { string tsql = @" select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where CompanyId=@CompanyId and (@PlatType=0 or PlatType=@PlatType) order by PlatType "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion public static CK_OtherFee Delete_OtherFee(int Id) { CK_OtherFee model = null; string tsql = @" select * from CK_OtherFee where Id=@Id delete from CK_OtherFee where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #region 查询订单货物明细 public static List GetOrderGoodsPostionCodeHWC(int OrderId) { List list = null; string tsql = @" select d.PlatId,b.Id,c.PostionCode,Price=isnull(a.Price,0),PostPrice=isnull(a.PostPrice,0),HWCFee=isnull(a.HWCFee,0) from HW_GoodsInDetailHWC a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join CK_StorePostion c on a.PostionId=c.PostionId inner join DT_OrderInfo d on b.OrderId=d.OrderId where b.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 获取物流对象 public static JC_ExpressPost GetExpressModel(int ExpressID) { JC_ExpressPost model = null; string tsql = @"select a.ExpressPostID,a.ExpressID,a.CompanyId,a.Name,c.PostType,a.IsUse,a.UserCode,a.CheckCode,a.operationtype,a.customercode,a.vipcode,a.clcttype,a.DefaultAddr,a.client_id,a.client_secret,a.refresh_token,a.GetTime,a.Code,a.redirect_uri,c.EName,c.LogisticsId from [JC_ExpressPost] a inner join JC_Express c on a.ExpressID=c.ExpressID where a.ExpressID=@ExpressID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ExpressID", DbType.Int32, ExpressID); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询要自动分配库存的订单 public static List GetLockOrderListForHWC(int CompanyId, int orderstate, int StoreId, string OrderBy) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,IsMate=0,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and a.State=1 and a.MateState=0 and a.poststate=0 order by " + OrderBy; } else { tsql = @" select a.OrderId,a.ShopId,b.RevCountry,a.IsFba,a.JoinOrderCode,IsMate=0,d.ShopName from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join JC_Shop d on a.ShopId=d.ShopId where a.CompanyId=@CompanyId and a.FPDate is not null and a.MoneyState=1 and a.State=1 and a.MateState=0 order by " + OrderBy; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物 public static List GetLockOrderGoodsForHWC(int CompanyId, int StoreId, int orderstate) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @" select c.*,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and a.State=1 and a.MateState=0 and a.poststate=0"; } else { tsql = @" select c.*,a.JoinOrderCode,IsMate=0 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and a.State=1 and a.MateState=0"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion public static List GetOrderGoodsPostionHWC(string OrderIds) { string query = @" select a.OrderId,c.GoodsCode,c.GoodsOldCode,c.GoodsName,b.TypeCode,b.TypeDesc,d.PostionCode,GoodsNum=a.Num,c.GoodsId,OldTypeDesc=b.SKU1 from (select a.OrderId,a.DetailId,b.PostionId,Num=sum(b.KCNum) from DT_OrderGoods a inner join HW_GoodsInDetailHWC b on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + @") group by a.OrderId,a.DetailId,b.PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join DT_OrderGoods e on a.OrderId=e.OrderId and a.DetailId=e.DetailId inner join CK_StorePostion d on a.PostionId=d.PostionId"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@OrderIds", DbType.String, OrderIds); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } #region 保存订单扫描记录 public static void SaveTrackCodeScanHWC(int orderid, DateTime InDate, int BagUserId) { string tsql = @" declare @Id int select top 1 @Id=Id from DT_TrackCodeScan where OrderId=@orderid if @Id>0 begin Update [DT_TrackCodeScan] set [InDate]=@InDate where Id=@Id end else begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[ScanUserId],Count) select PostId,TrackCode,InDate=@InDate,'',OrderCode,OrderId,@BagUserId,@BagUserId,1 from DT_TrackCodeApply where State=1 and OrderId=@orderid end update DT_OrderInfo set state=2,poststate=1,PostDate=@InDate,PrintState=1,PrintDate=isnuLL(PrintDate,@InDate) where orderid=@orderid update DT_OrderInfonew set state=2,poststate=1,PostDate=@InDate,PrintState=1,PrintDate=isnuLL(PrintDate,@InDate) where orderid=@orderid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.AddInParameter(cmd, "@BagUserId", DbType.Int32, BagUserId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单打印 public static int UpdateOrderPrintHWC(HW_GoodsOutRecord Model) { string tsql = @" INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId],IsDelete,OrderId) values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId,@IsDelete,@OrderId) set @OutId=SCOPE_IDENTITY() INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId]) select @OutId,GoodsNum,DetailId,0,0 from DT_OrderGoods where OrderId=@OrderId update a set a.CKDetailId=d.Id from HW_GoodsInDetailHWC a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join HW_GoodsOutList c on b.OrderId=c.OrderId inner join HW_GoodsOutDetail d on c.OutId=d.OutId and b.DetailId=d.DetailId where b.OrderId=@OrderId update DT_OrderInfo set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update DT_OrderInfoNew set PrintState=1,PrintDate=getdate() where OrderId=@OrderId update b set b.GoodsPlanNum=b.GoodsPlanNum-a.GoodsNum,b.GoodsNum=b.GoodsNum-a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion public static decimal GetInFee(int CompanyId) { string tsql = @"select Fee=isnull(SUM(Inusdfee),0) from JC_CompanyFee where CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); decimal a = Convert.ToDecimal(db.ExecuteScalar(cmd)); return a; } public static decimal GetOutFee(int CompanyId) { string tsql = @"select Fee=isnull(SUM(TotalFee),0) from CK_FeeReport where CompanyId=@CompanyId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); decimal a = Convert.ToDecimal(db.ExecuteScalar(cmd)); return a; } public static decimal GetOutFeeType(int CompanyId, int FeeType) { string tsql = @"select Fee=SUM(fee2) from DT_OrderInfo where CompanyId=@CompanyId and State>0 and State<3"; if (FeeType == 7) tsql = @"select Fee=SUM(fee1) from DT_OrderInfo where CompanyId=@CompanyId and State>0 and State<3"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@FeeType", DbType.Int32, FeeType); decimal a = Convert.ToDecimal(db.ExecuteScalar(cmd)); return a; } public static CK_FeeReport GetOutFeeCount(int CompanyId) { CK_FeeReport model = null; string tsql = @" declare @Num int ,@Num2 int select @Num=count(0) from DT_OrderInfo where CompanyId=@CompanyId and State>0 and State<3 select @Num2=count(0) from DT_OrderInfo where CompanyId=@CompanyId and State>0 and State<3 and isnull(fee2,0)=0 select Num2=@Num2,Num=@Num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #region 返回费用 public static List GetListFeeReport(int CompanyId, int FeeType, DateTime? SDate, DateTime? EDate) { //string tsql = "select a.Id,a.statename,a.Num,a.code,a.color,a.Price from DT_USMap"; string tsql = @" select a.Id,a.InDate,a.FeeType,a.TotalFee,a.FeeDesc,a.CompanyId,a.Num,a.Num2,a.Dec,Dec2=isnull(a.NoFee,0),FeeName=b.Name from CK_FeeReport a inner join JC_BaseCodeDetail b on a.FeeType=b.SortNo and b.KeyName='FYLX' where a.CompanyId=@CompanyId and (@FeeType=0 or FeeType=@FeeType) and Indate>=@SDate and Indate<@EDate order by Indate desc,FeeType"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@FeeType", DbType.Int32, FeeType); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回费用 public static List GetListNoFeeReport(int topNum, int CompanyId, int Id) { //string tsql = "select a.Id,a.statename,a.Num,a.code,a.color,a.Price from DT_USMap"; string tsql = @" select top " + topNum + @" a.Id,a.InDate,a.FeeType,a.TotalFee,a.FeeDesc,a.CompanyId,a.Num,a.Num2,a.Dec,Dec2=isnull(a.NoFee,0) from CK_FeeReport a where CompanyId=@CompanyId and a.TotalFee>0 and NoFee=TotalFee order by a.InDate desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回费用 public static void UpdateNoFee(int CompanyId) { //string tsql = "select a.Id,a.statename,a.Num,a.code,a.color,a.Price from DT_USMap"; string tsql = @" delete from CK_FeeReport where isnull(TotalFee,0)=0 update CK_FeeReport set NoFee=TotalFee where CompanyId=@CompanyId and isnull(NoFee,0) GetListCompanyFee(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select Id=cast(a.Id as int),a.InDate,a.InName,a.InFee,a.InUSDFee,a.CompanyId,b.CompanyName from JC_CompanyFee a inner join jc_Company b on a.CompanyId=b.CompanyId "; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 删除 public static void Delete_CompanyFee(int Id) { string tsql = @" delete from JC_CompanyFee where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 查询库存 public static DataTable GetList_GoodsLeftListHWC(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"a.*,GoodsNum=isnull(a.UseGoodsNum,0),LockNum=isnull(g.LockGoodsNum,0),UseGoodsNum=isnull(a.UseGoodsNum,0),c.StoreName,c.StoreCode,PostionDesc=d.PostionDesc+'['+d.PostionCode+']',d.PostionCode,NewPostionCode='',f.GoodsName,f.GoodsCode,f.GoodsOldCode,f.CompanyId,TypeCode=e.SKU1,e.TypeDesc,pk='',OutNum=0,IsOut='false'"; ser.Tables = @"HW_GoodsDetail e inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId inner join (select a.DetailId,a.StoreId,a.PostionId,UseGoodsNum=sum(KCNum) from HW_GoodsInDetailHWC a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderGoodsId=0 and isnull(CKDetailId,0)=0 group by a.DetailId,a.StoreId,a.PostionId)a on e.DetailId=a.DetailId left join (select a.DetailId,a.StoreId,a.PostionId,LockGoodsNum=sum(KCNum) from HW_GoodsInDetailHWC a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderGoodsId<>0 and isnull(CKDetailId,0)=0 group by a.DetailId,a.StoreId,a.PostionId)g on a.DetailId=g.DetailId and a.PostionId=g.PostionId inner join CK_StoreHouse c on a.StoreId=c.StoreId inner join CK_StorePostion d on a.PostionId=d.PostionId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 移库 public static int UpdateGoodsPostionCodeHWC(int StoreId, int DetailId, int PostionId, string PostionCode, int GoodsNum) { string tsql = @" declare @NewPostionId int,@NewStoreId int select top 1 @NewPostionId=PostionId,@NewStoreId=StoreId from CK_StorePostion where PostionCode=@PostionCode --while @GoodsNum>0 and @NewPostionId>0 --begin --update HW_GoodsInDetail set PostionId=@NewPostionId,UpDateTime=getdate() where inid in (select top 1 InId from HW_GoodsInDetail where StoreId=@StoreId and PostionId=@PostionId and DetailId=@DetailId and OrderGoodsId=0 order by InId) --set @GoodsNum=@GoodsNum-1 --end declare @OldInId int,@InId int,@KCNum int while @GoodsNum>0 begin set @OldInId=0 select top 1 @OldInId=InId,@KCNum=KCNum from HW_GoodsInDetailHWC where OrderGoodsId=0 and PostionId=@PostionId and DetailId=@DetailId if @OldInId>0 and @GoodsNum>=@KCNum begin update HW_GoodsInDetailHWC set StoreId=@NewStoreId,PostionId=@NewPostionId where InId=@OldInId end else if @OldInId>0 and @GoodsNum<@KCNum begin INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],CompanyId) select [DetailId],[ChaseId],StoreId=@NewStoreId,PostionId=@NewPostionId,[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId,KCNum=@GoodsNum,getdate(),[RKDetailId],CKDetailId,CompanyId from [HW_GoodsInDetailHWC] where InId=@OldInId update HW_GoodsInDetailHWC set KCNum=KCNum-@GoodsNum where InId=@OldInId end if @OldInId=0 begin set @GoodsNum=0 end else begin set @GoodsNum=@GoodsNum-@KCNum end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); db.AddInParameter(cmd, "@GoodsNum", DbType.String, GoodsNum); int a = db.ExecuteNonQuery(cmd); return a; } #endregion #region 保存出库货物对应批次 public static int SaveGoodsOutInnerForHWC(int DetailId, int PostionId, int StoreId, int GoodsNum, int CKDetailId) { string tsql = @" declare @OldInId int,@InId int,@KCNum int,@OutNum int set @OutNum=0 while @GoodsNum>0 begin set @OldInId=0 select top 1 @OldInId=InId,@KCNum=KCNum from HW_GoodsInDetailHWC where OrderGoodsId=0 and PostionId=@PostionId and DetailId=@DetailId if @OldInId>0 and @GoodsNum=@KCNum begin update HW_GoodsInDetailHWC set OrderGoodsId=-1,CKDetailId=@CKDetailId where InId=@OldInId set @OutNum=@OutNum+@KCNum end else if @OldInId>0 and @GoodsNum<@KCNum begin INSERT INTO [HW_GoodsInDetailHWC]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId]) select [DetailId],[ChaseId],StoreId=@StoreId,PostionId=@PostionId,[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=-1,KCNum=@GoodsNum,getdate(),[RKDetailId],CKDetailId=@CKDetailId from [HW_GoodsInDetailHWC] where InId=@OldInId update HW_GoodsInDetailHWC set KCNum=KCNum-@GoodsNum where InId=@OldInId set @OutNum=@OutNum+@GoodsNum end else if @OldInId>0 and @GoodsNum>@KCNum begin update HW_GoodsInDetailHWC set OrderGoodsId=-1,CKDetailId=@CKDetailId,UpDateTime=getdate() where InId=@OldInId set @OutNum=@OutNum+@KCNum end if @OldInId=0 begin set @GoodsNum=0 end else begin set @GoodsNum=@GoodsNum-@KCNum end end update HW_GoodsDetail set GoodsNum=GoodsNum-@OutNum where DetailId=@DetailId select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, CKDetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回货物Model public static HW_Goods GetGoodsModel(int GoodsId) { HW_Goods model = null; string tsql = "select a.GoodsId,a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,a.GoodsNum,a.GoodsLockNum,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,a.GoodsOutNum,a.GoodsInNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.Supplier,a.DeptRemark,a.NoticeDays,a.GoodsInfo,a.DefaultCity,a.PageFee,a.PostPrice,a.GoodsSupplyCode,a.BGPrice,a.GoodNote,a.NoticeShop,a.GoodsHJNum,a.GoodsHJNum2,a.NetWeight,a.Long,a.Width,a.Height,a.BoxRate,a.Cert,a.UpOff,a.FeeRate,a.JYPrice,a.Long2,a.Width2,a.Height2,a.Weight2,a.GoodsInNum2,a.LastOrderDate,State=isnull(a.IsSure,0) from HW_GoodsInfo a where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 审核重量 public static void Update_GoodsSure(int GoodsId, int IsSure) { string tsql = @" update HW_GoodsInfo set IsSure=@IsSure where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@IsSure", DbType.Int32, IsSure); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListFeeDetail(int FeeId) { //string tsql = "select a.Id,a.FeeId,a.FeeType,a.FeeRate,a.OffRate,a.MoneyCode,a.FeeUnit,a.SInt,a.EInt,a.SDec,a.EDec,a.Sort,a.YLInt1,a.YLInt2,a.YLDec1,a.YLDec2,a.YLChar1,a.YLChar2,a.YLChar3 from CK_FeeDetail"; string tsql = @" if(select count(0) from CK_FeeDetail where FeeId=@FeeId)=0 begin INSERT INTO [CK_FeeDetail]([FeeId],[FeeType],[FeeRate],[OffRate],[MoneyCode],[FeeUnit],[SInt],[EInt],[SDec],[EDec],[Sort],[YLInt1],[YLInt2],[YLDec1],[YLDec2],[YLChar1],[YLChar2],[YLChar3],IsAuto) select FeeId=@FeeId,[FeeType],[FeeRate],0,[MoneyCode],[FeeUnit],[SInt],[EInt],[SDec],[EDec],[Sort],[YLInt1],[YLInt2],[YLDec1],[YLDec2],[YLChar1],[YLChar2],[YLChar3],IsAuto from CK_FeeDetail where IsAuto=1 end select a.Id,a.FeeId,a.FeeType,a.FeeRate,a.OffRate,a.MoneyCode,a.FeeUnit,a.SInt,a.EInt,a.SDec,a.EDec,a.Sort,a.YLInt1,a.YLInt2,a.YLDec1,a.YLDec2,a.YLChar1,a.YLChar2,a.YLChar3,IsAuto=isnull(IsAuto,0),FeeTypeName=b.Name from CK_FeeDetail a left join JC_BaseCodeDetail b on a.FeeType=b.SortNo and b.keyname='FYLX' where FeeId=@FeeId order by FeeType "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@FeeId", DbType.Int32, FeeId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsStar(string GoodsIds) { //string tsql = "select a.Id,a.GoodsId,a.ShopId,a.Url,a.Star1,a.Star2,a.Star3,a.Star4,a.Star5,a.Star6,a.LastDate,a.LastDate2 from HW_GoodsStar"; string tsql = @"select a.Id,a.GoodsId,a.ShopId,a.Url,Star1=isnull(a.Star1,0),Star2=isnull(a.Star2,0),Star3=isnull(a.Star3,0),Star4=isnull(a.Star4,0),Star5=isnull(a.Star5,0),Star6=isnull(a.Star6,0),a.LastDate,a.LastDate2,b.ShopName from HW_GoodsStar a inner join JC_Shop b on a.ShopId=b.ShopId where a.GoodsId in (" + GoodsIds + ") order by isnull(a.Star6,0) desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListShopList(int ShopId, DateTime? SDate) { string tsql = @"select * from VW_Orders where shopid=@ShopId and state>0 and state<3 and DATEDIFF(day,OrderDate,@SDate)=0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListShopList2(int ShopId, DateTime? SDate) { string tsql = @"select * from VW_Orders where shopid=@ShopId and state>0 and state<3 and DATEDIFF(day,OrderDate,@SDate)=0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListGoodsUserOrder(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate) { string tsql = @" --调整数量 UPDATE a SET a.GoodsNum=b.GoodsNum from DT_OrderInfo a INNER JOIN ( select OrderId,GoodsNum=SUM(GoodsNum) FROM DT_OrderGoods group BY OrderId)b ON a.OrderId=b.OrderId WHERE a.State>0 and a.State<3 and a.GoodsNum<>b.GoodsNum select b.OrderId,d.GoodsId,e.UserId,b.PlatId,b.ShopId,b.TotalPrice,d.InPrice,d.Solid,a.GoodsNum,b.Fee6,b.Fee7,b.Fee8,b.Fee11,b.Fee12,b.Fee13,b.Fee14,GoodsOrderFee=isnull(a.GoodsOrderFee,0),f.RevFax,FeeRate=isnull(d.FeeRate,0),GoodsNum2=isnull(b.GoodsNum,0),Weight=isnull(d.Weight2,0) FROM DT_OrderGoods a with(nolock) INNER JOIN DT_OrderInfo b with(nolock) ON a.OrderId=b.OrderId inner JOIN HW_GoodsDetail c with(nolock) ON a.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) ON c.GoodsId=d.GoodsId inner JOIN HW_GoodsUser e with(nolock) ON b.ShopId=e.ShopId AND d.GoodsId=e.GoodsId INNER JOIN DT_OrderXXInfo f with(nolock) ON a.OrderId=f.OrderId WHERE b.State>0 AND b.State<3 AND (@PlatId=0 or b.PlatId=@PlatId) and (@ShopId=0 or b.ShopId=@ShopId) and b.OrderDate>=@SDate and b.OrderDate<@EDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListGoodsUserOrder2(int PlatId, int ShopId, DateTime? SDate, DateTime? EDate) { string tsql = @" select e.UserId,b.shopid,GoodsNum=COUNT(distinct b.PlatOrderCode) FROM DT_OrderGoods a with(nolock) INNER JOIN DT_OrderInfo b with(nolock) ON a.OrderId=b.OrderId inner JOIN HW_GoodsDetail c with(nolock) ON a.DetailId=c.DetailId inner JOIN HW_GoodsUser e with(nolock) ON b.ShopId=e.ShopId AND c.GoodsId=e.GoodsId WHERE b.State>0 AND b.State<3 AND (@PlatId=0 or b.PlatId=@PlatId) and (@ShopId=0 or b.ShopId=@ShopId) and b.OrderDate>=@SDate and b.OrderDate<@EDate group by e.UserId,b.shopid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListGoodsUserFee(int PlatId, int ShopId, string Name) { string tsql = @"SELECT a.*,b.ShopName,c.Name FROM (select UserId,ShopId,GNum=COUNT(DISTINCT GoodsId) FROM HW_GoodsUser group BY UserId,ShopId)a inner JOIN JC_Shop b ON a.ShopId=b.ShopId INNER JOIN JC_UserInfo c on a.UserId=c.UserId WHERE c.State=1 AND (@PlatId=0 OR b.PlatType=@PlatId) AND (@ShopId=0 OR b.ShopId=@ShopId) and (@Name='' or c.Name LIKE '%'+@Name+'%') order by c.name,b.PlatType,a.GNum desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@Name", DbType.String, Name); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 查询要自动匹配的库存 public static List GetNowKCGoods5(int orderstate, int StoreId, int StoreId2) { List list = null; string tsql = ""; if (orderstate == 1) { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId,b.PostionCode,b.SortNo from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where OrderGoodsId=0 and isnull(e.NoGoods,0)=0 and isnull(f.NoGoods,0)=0 and a.KCNum>0 and a.StoreId=@StoreId2 and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.MateState=0 and c.PostState=0 and c.State=1 and d.StoreId=@StoreId and c.FPDate is not null) order by a.DetailId,b.SortNo,a.PostionId"; } else { tsql = @"select a.InId,a.KCNum,LockNum=0,a.DetailId,IsMate=0,OrderNum=0,a.StoreId,a.PostionId,b.PostionCode,b.SortNo from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where OrderGoodsId=0 and isnull(e.NoGoods,0)=0 and isnull(f.NoGoods,0)=0 and a.KCNum>0 and a.StoreId=@StoreId2 and a.DetailId in (select DetailId from DT_OrderGoods a inner join DT_OrderInfo c on a.OrderId=c.OrderId inner join DT_OrderXXInfo d on c.OrderId=d.OrderId where c.MateState=0 and c.State=1 and d.StoreId=@StoreId and c.FPDate is not null) order by a.DetailId,b.SortNo,a.PostionId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderstate", DbType.Int32, orderstate); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@StoreId2", DbType.Int32, StoreId2); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public static List GetMateOrderGoodsInForTM34(int DetailId, int StoreId) { List list = null; string tsql = @" select *,b.PostionCode from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where isnull(e.NoGoods,0)=0 and isnull(f.NoGoods,0)=0 and a.DetailId=@DetailId and b.StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by a.DetailId,b.SortNo,a.PostionId,a.KCNum "; // if(StoreId==6) // tsql = @" //select *,b.PostionCode from HW_GoodsInDetail a //inner join CK_StorePostion b on a.PostionId=b.PostionId //inner join HW_GoodsDetail e on a.DetailId=e.DetailId //inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId //where isnull(e.NoGoods,0)=0 and isnull(f.NoGoods,0)=0 and a.DetailId=@DetailId and b.StoreId in (6,9) and OrderGoodsId=0 and KCNum>0 order by a.DetailId,b.SortNo,a.PostionId,a.KCNum //"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询要自动匹配的订单货物仓库入库货物记录 public static List GetMateOrderGoodsInForTM35(int DetailId, int StoreId, string ShopName) { List list = null; string tsql = @" select *,b.PostionCode from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail e on a.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where isnull(e.NoGoods,0)=0 and isnull(f.NoGoods,0)=0 and a.DetailId=@DetailId and b.PostionCode=@ShopName and b.StoreId=@StoreId and OrderGoodsId=0 and KCNum>0 order by b.SortNo,a.KCNum "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@ShopName", DbType.String, ShopName); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 分页查询发往海外仓货物 public static List GetListOutGoodsInfo(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),d.ChaseCode,d.InDate,c.GoodsCode,c.GoodsName,b.TypeDesc,FirstImgUrl=case when b.FirstImgUrl is not null or b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end,SJOutNum=a.OutNum-isnull(a.TJOutNum,0),OutNum=isnull(a.OutNum,0)-isnull(a.SJOutNum,0),a.OutInNum,c.Solid,a.GoodsPrice,a.GoodsNum,IsAdd=1,GoodsRate=isnull(c.FeeRate,0) "; ser.Tables = @"CG_PurchaseGoods a inner join CG_Purchase d on a.ChaseId=d.ChaseId inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询发往海外仓货物 public static List GetListOutGoodsInfo2(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),d.ChaseCode,d.BuyCode,d.InDate,c.GoodsCode,c.GoodsName,b.TypeDesc,FirstImgUrl=case when b.FirstImgUrl is not null or b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end,SJOutNum=a.OutNum-isnull(a.TJOutNum,0), OutNum=a.GoodsNum-isnull(a.InGoodsNum,0)-isnull(a.TJOutNum,0),a.OutInNum,c.Solid,a.GoodsPrice,a.GoodsNum,IsAdd=1,GoodsRate=isnull(c.FeeRate,0) "; ser.Tables = @"CG_PurchaseGoods a inner join CG_Purchase d on a.ChaseId=d.ChaseId inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion public static List GetListOutGoodsInfo22(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) { where = new RefParameterCollection(); } string text = new QueryService { Fields = "Id=0,a.detailId,b.GoodsCode,b.GoodsName,a.TypeDesc,FirstImgUrl=case when b.FirstImgUrl is not null or b.FirstImgUrl<>'' then b.FirstImgUrl else a.FirstImgUrl end,SKU=a.SKU1,Solid=isnull(b.Solid,0),GoodsPrice=isnull(b.InPrice,0)", Tables = "HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId", Filter = where.GetWhere(CommandType.Text), PageIndex = PageIndex, PageSize = PageSize, Sort = Sort, KeyName = "GoodsId" }.GetText(); where.AddOutParameter("RowCount", DbType.Int32); Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddInParameter(sqlStringCommand, where); DataTable tb = database.ExecuteDataTable(sqlStringCommand); RowCount = Convert.ToInt32(sqlStringCommand.Parameters["@RowCount"].Value); return tb.ToList(); } #region 保存海外仓 /// /// 保存海外仓 /// public static int UpdateHWCGoods2(HW_GoodsHWCOutDetailNew Model) { string tsql = @" if(select count(0) from CG_PurchaseGoods where Id=@Id and GJChaseId>0)>0 begin update CG_PurchaseGoods set TJOutNum=isnull(TJOutNum,0)+@SJOutNum where Id=@Id INSERT INTO [CG_PurchaseGoods]([ChaseId],[GoodsCode],[GoodsDetailId],[GoodsNum],[GoodsPrice],[LockNum],[IsOrder],[CompanyId],[InGoodsNum],[ErrorNum],[Error],[BackNum],[PostionCode],[BoxNum],[BarCode],[OrderId],[OutNum],[SJOutNum],[OutInNum],[GJChaseId],[PState],[TJOutNum],OldId,GoodsRate) select [ChaseId]=0,[GoodsCode],[GoodsDetailId],[GoodsNum],[GoodsPrice],[LockNum],[IsOrder],[CompanyId],0,[ErrorNum],[Error],[BackNum],[PostionCode],[BoxNum],[BarCode],[OrderId],OutNum=@SJOutNum,SJOutNum=@SJOutNum,0,GJChaseId=@GJChaseId,PState=@PState,TJOutNum=@SJOutNum,Id=@Id,GoodsRate=@GoodsRate from [CG_PurchaseGoods] where Id=@Id end else begin update CG_PurchaseGoods set SJOutNum=@SJOutNum,TJOutNum=@SJOutNum,PState=@PState,GJChaseId=@GJChaseId,GoodsRate=@GoodsRate where Id=@Id end if @GoodsRate>0 begin declare @DetailId int set @DetailId=0 select @DetailId=GoodsDetailId from CG_PurchaseGoods where Id=@Id update a set a.FeeRate=@GoodsRate from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where b.DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PState", DbType.Int32, Model.PState); db.AddInParameter(cmd, "@GJChaseId", DbType.Int32, Model.GJChaseId); db.AddInParameter(cmd, "@SJOutNum", DbType.Int32, Model.SJOutNum); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, Model.GoodsRate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存海外仓 /// /// 保存海外仓 /// public static int UpdateHWCGoods22(HW_GoodsHWCOutDetailNew Model) { string tsql = @" declare @DetailId int set @DetailId=0 select @DetailId=GoodsDetailId from CG_PurchaseGoods where Id=@Id update CG_PurchaseGoods set TJOutNum=isnull(TJOutNum,0)+@SJOutNum where Id=@Id if(select count(0) from CG_PurchaseGoods where GJChaseId=@GJChaseId and GoodsDetailId=@DetailId)=0 begin INSERT INTO [CG_PurchaseGoods]([ChaseId],[GoodsCode],[GoodsDetailId],[GoodsNum],[GoodsPrice],[LockNum],[IsOrder],[CompanyId],[InGoodsNum],[ErrorNum],[Error],[BackNum],[PostionCode],[BoxNum],[BarCode],[OrderId],[OutNum],[SJOutNum],[OutInNum],[GJChaseId],[PState],[TJOutNum],OldId,GoodsRate,Chase_Code) select [ChaseId]=0,[GoodsCode],[GoodsDetailId],[GoodsNum],[GoodsPrice],[LockNum],[IsOrder],[CompanyId],0,[ErrorNum],[Error],[BackNum],[PostionCode],[BoxNum],[BarCode],[OrderId],OutNum=@SJOutNum,SJOutNum=@SJOutNum,0,GJChaseId=@GJChaseId,PState=@PState,0,Id=@Id,GoodsRate=@GoodsRate,Chase_Code=@Chase_Code from [CG_PurchaseGoods] where Id=@Id end else begin update CG_PurchaseGoods set SJOutNum=isnull(SJOutNum,0)+@SJOutNum where GJChaseId=@GJChaseId and GoodsDetailId=@DetailId end if @GoodsRate>0 begin update a set a.FeeRate=@GoodsRate from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where b.DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PState", DbType.Int32, Model.PState); db.AddInParameter(cmd, "@GJChaseId", DbType.Int32, Model.GJChaseId); db.AddInParameter(cmd, "@SJOutNum", DbType.Int32, Model.SJOutNum); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, Model.GoodsRate); db.AddInParameter(cmd, "@Chase_Code", DbType.String, Model.Chase_Code); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存海外仓 /// /// 保存海外仓 /// public static int UpdateHWCGoods2222(HW_GoodsHWCOutDetailNew Model) { string tsql = @" declare @DetailId int set @DetailId=0 select @DetailId=GoodsDetailId from CG_PurchaseGoods where Id=@Id update CG_PurchaseGoods set TJOutNum=isnull(TJOutNum,0)+@SJOutNum where Id=@Id if(select count(0) from CG_PurchaseGoods where GJChaseId=@GJChaseId and GoodsDetailId=@DetailId and isnull(Chase_Code,'')=@Chase_Code)=0 begin INSERT INTO [CG_PurchaseGoods]([ChaseId],[GoodsCode],[GoodsDetailId],[GoodsNum],[GoodsPrice],[LockNum],[IsOrder],[CompanyId],[InGoodsNum],[ErrorNum],[Error],[BackNum],[PostionCode],[BoxNum],[BarCode],[OrderId],[OutNum],[SJOutNum],[OutInNum],[GJChaseId],[PState],[TJOutNum],OldId,GoodsRate,Chase_Code) select [ChaseId]=0,[GoodsCode],[GoodsDetailId],[GoodsNum],[GoodsPrice],[LockNum],[IsOrder],[CompanyId],0,[ErrorNum],[Error],[BackNum],[PostionCode],[BoxNum],[BarCode],[OrderId],OutNum=@SJOutNum,SJOutNum=@SJOutNum,0,GJChaseId=@GJChaseId,PState=@PState,0,Id=@Id,GoodsRate=@GoodsRate,Chase_Code=@Chase_Code from [CG_PurchaseGoods] where Id=@Id end else begin update CG_PurchaseGoods set SJOutNum=isnull(SJOutNum,0)+@SJOutNum where GJChaseId=@GJChaseId and GoodsDetailId=@DetailId end if @GoodsRate>0 begin update a set a.FeeRate=@GoodsRate from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where b.DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PState", DbType.Int32, Model.PState); db.AddInParameter(cmd, "@GJChaseId", DbType.Int32, Model.GJChaseId); db.AddInParameter(cmd, "@SJOutNum", DbType.Int32, Model.SJOutNum); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, Model.GoodsRate); db.AddInParameter(cmd, "@Chase_Code", DbType.String, Model.Chase_Code); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存海外仓 /// /// 保存海外仓 /// public static int UpdateHWCGoods(HW_GoodsHWCOutDetailNew Model) { string tsql = @" declare @OldId int select @OldId=OldId from CG_PurchaseGoods where Id=@Id update CG_PurchaseGoods set SJOutNum=@SJOutNum,PState=@PState,GJChaseId=@GJChaseId,TJOutNum=@SJOutNum,GoodsRate=@GoodsRate where Id=@Id if @OldId>0 begin declare @Num int select @Num=sum(isnull(SJOutNum,0)) from CG_PurchaseGoods where OldId=@OldId update CG_PurchaseGoods set TJOutNum=isnull(SJOutNum,0)+@Num where Id=@OldId end if @GoodsRate>0 begin declare @DetailId int set @DetailId=0 select @DetailId=GoodsDetailId from CG_PurchaseGoods where Id=@Id update a set a.FeeRate=@GoodsRate from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where b.DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PState", DbType.Int32, Model.PState); db.AddInParameter(cmd, "@GJChaseId", DbType.Int32, Model.GJChaseId); db.AddInParameter(cmd, "@SJOutNum", DbType.Int32, Model.SJOutNum); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, Model.GoodsRate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存海外仓 /// /// 保存海外仓 /// public static int UpdateHWCGoods222(HW_GoodsHWCOutDetailNew Model) { string tsql = @" declare @OldId int select @OldId=OldId from CG_PurchaseGoods where Id=@Id update CG_PurchaseGoods set SJOutNum=@SJOutNum,PState=@PState,GJChaseId=@GJChaseId,GoodsRate=@GoodsRate where Id=@Id if @OldId>0 begin declare @Num int select @Num=sum(isnull(SJOutNum,0)) from CG_PurchaseGoods where OldId=@OldId update CG_PurchaseGoods set TJOutNum=isnull(SJOutNum,0)+@Num where Id=@OldId end if @GoodsRate>0 begin declare @DetailId int set @DetailId=0 select @DetailId=GoodsDetailId from CG_PurchaseGoods where Id=@Id update a set a.FeeRate=@GoodsRate from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where b.DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PState", DbType.Int32, Model.PState); db.AddInParameter(cmd, "@GJChaseId", DbType.Int32, Model.GJChaseId); db.AddInParameter(cmd, "@SJOutNum", DbType.Int32, Model.SJOutNum); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, Model.GoodsRate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 采购货物明细修改 public static void SaveInchaseGoodsForTM2(int ChaseId, int UserId, decimal? Price, decimal? PostPrice, int GoodsDetailId, int InGoodsNum, int RKId, string Error, string PostionCode, int PostState, decimal? GoodsRate) { string tsql = @" declare @Id int,@StoreId int,@PostionId int,@SJOutNum int,@OutInNum int select top 1 @Id=Id,@SJOutNum=SJOutNum,@OutInNum=isnull(OutInNum,0) from CG_PurchaseGoods where GoodsDetailId=@GoodsDetailId and GJChaseId=@ChaseId if @PostionCode<>'' begin select top 1 @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode update CG_Purchase set PostionCode=@PostionCode where ChaseId=@ChaseId end if @PState<7 and @SJOutNum=@OutInNum+@InGoodsNum begin set @PState=7 end if @PState<6 and @SJOutNum>@OutInNum+@InGoodsNum begin set @PState=6 end Update [CG_PurchaseGoods] set [InGoodsNum]=isnull(InGoodsNum,0)+@InGoodsNum,[OutInNum]=isnull(OutInNum,0)+@InGoodsNum,[Error]=@Error,PState=@PState where Id=@Id if @InGoodsNum>0 begin INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[UpDateTime],RKDetailId,KCNum,OldNum,GoodsRate) values(@GoodsDetailId,@ChaseId,@StoreId,@PostionId,@Price,@PostPrice,getdate(),@InUserId,0,null,@RKId,@InGoodsNum,@InGoodsNum,@GoodsRate) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@RKId", DbType.Int32, RKId); db.AddInParameter(cmd, "@GoodsDetailId", DbType.Int32, GoodsDetailId); db.AddInParameter(cmd, "@InGoodsNum", DbType.Int32, InGoodsNum); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); db.AddInParameter(cmd, "@Error", DbType.String, Error); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); db.AddInParameter(cmd, "@InUserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, PostPrice); db.AddInParameter(cmd, "@PState", DbType.Int32, PostState); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, GoodsRate); db.ExecuteNonQuery(cmd); } #endregion #region 采购货物明细修改 public static void SaveInchaseGoodsForTM3(int Id, int ChaseId, int UserId, decimal? Price, decimal? PostPrice, int GoodsDetailId, int InGoodsNum, int RKId, string Error, string PostionCode, int PostState, decimal? GoodsRate) { string tsql = @" declare @StoreId int,@PostionId int,@SJOutNum int,@OutInNum int select top 1 @SJOutNum=SJOutNum,@OutInNum=isnull(OutInNum,0) from CG_PurchaseGoods where Id=@Id if @PostionCode<>'' begin select top 1 @StoreId=StoreId,@PostionId=PostionId from CK_StorePostion where PostionCode=@PostionCode update CG_Purchase set PostionCode=@PostionCode where ChaseId=@ChaseId end if @PState<7 and @SJOutNum=@OutInNum+@InGoodsNum begin set @PState=7 end if @PState<6 and @SJOutNum>@OutInNum+@InGoodsNum begin set @PState=6 end Update [CG_PurchaseGoods] set [OutInNum]=isnull(OutInNum,0)+@InGoodsNum,[Error]=@Error,PState=@PState where Id=@Id if @InGoodsNum>0 begin INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[UpDateTime],RKDetailId,KCNum,OldNum,GoodsRate) values(@GoodsDetailId,@ChaseId,@StoreId,@PostionId,@Price,@PostPrice,getdate(),@InUserId,0,null,@RKId,@InGoodsNum,@InGoodsNum,@GoodsRate) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@RKId", DbType.Int32, RKId); db.AddInParameter(cmd, "@GoodsDetailId", DbType.Int32, GoodsDetailId); db.AddInParameter(cmd, "@InGoodsNum", DbType.Int32, InGoodsNum); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); db.AddInParameter(cmd, "@Error", DbType.String, Error); db.AddInParameter(cmd, "@PostionCode", DbType.String, PostionCode); db.AddInParameter(cmd, "@InUserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Price); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, PostPrice); db.AddInParameter(cmd, "@PState", DbType.Int32, PostState); db.AddInParameter(cmd, "@GoodsRate", DbType.Decimal, GoodsRate); db.ExecuteNonQuery(cmd); } #endregion #region 查询我的订单 public static List Get_OrderGoods(int CompanyId, int PlatId, int ShopId, int UserId, DateTime? SDate, DateTime? EDate, string GoodsCode) { List list = null; string tsql = @" select * into #DT_OrderInfoUserGoods from DT_OrderInfo where (@ShopId=0 or ShopId=@ShopId) and CompanyId=1 and State>0 and State<3 and OrderDate>=@SDate and OrderDate<@EDate select a.OrderId,a.GoodsFee,GoodsCode=e.GoodsCode+'['+isnull(d.sku1,'')+']',d.TypeDesc,e.SortName,e.GoodsName,a.TCFee,a.GoodsNum,ImgUrl=e.FirstImgUrl,FeeRate=a.GoodsRate,a.Id,a.ckfee,a.mdfee,a.adfee from DT_OrderGoods a inner join ( select distinct d.OrderId from HW_GoodsUser a with(nolock) inner join HW_GoodsInfo f with(nolock) on a.GoodsId=f.GoodsId inner join HW_GoodsDetail b with(nolock) on f.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join #DT_OrderInfoUserGoods d on c.OrderId=d.OrderId and a.ShopId=d.ShopId where d.CompanyId=@CompanyId and (@PlatId=0 or d.PlatId=@PlatId) and (@GoodsCode='' or f.GoodsCode=@GoodsCode) and a.UserId=@UserId)b on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on a.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId drop table #DT_OrderInfoUserGoods "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单货物明细 public static List GetOrderGoodsPostionCode(int OrderId) { List list = null; string tsql = @" select d.PlatId,b.Id,c.PostionCode,Price=isnull(a.Price,0),PostPrice=isnull(a.PostPrice,0),HWCFee=isnull(a.HWCFee,0),InPrice=isnull(f.InPrice,0),GoodsPrice=isnull(a.GoodsRate,0) from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join CK_StorePostion c on a.PostionId=c.PostionId inner join DT_OrderInfo d on b.OrderId=d.OrderId left join HW_GoodsDetail e on b.DetailId=e.DetailId left join HW_GoodsInfo f on e.GoodsId=f.GoodsId where b.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询我的订单 public static List Get_OrderGoods2(int CompanyId, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode) { List list = null; string tsql = @" select * into #DT_OrderInfoUserGoods from DT_OrderInfo where (@ShopId=0 or ShopId=@ShopId) and CompanyId=1 and State>0 and State<3 and OrderDate>=@SDate and OrderDate<@EDate select a.OrderId,a.GoodsFee,GoodsCode=e.GoodsCode+'['+isnull(d.sku1,'')+']',d.TypeDesc,e.SortName,e.GoodsName,a.TCFee,a.GoodsNum,ImgUrl=e.FirstImgUrl,FeeRate=a.GoodsRate,a.Id,a.ckfee,a.mdfee,a.adfee from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail d with(nolock) on a.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join #DT_OrderInfoUserGoods f with(nolock) on a.OrderId=f.OrderId where f.CompanyId=@CompanyId and (@GoodsCode='' or e.GoodsCode=@GoodsCode) and (@PlatId=0 or f.PlatId=@PlatId) order by OrderId drop table #DT_OrderInfoUserGoods "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 隐藏 public static void Update_GoodsShow(int DetailId, int IsYC) { string tsql = @" update HW_GoodsDetail set IsYC=@IsYC where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@IsYC", DbType.Int32, IsYC); db.ExecuteNonQuery(cmd); } #endregion #region 保存采购数量 public static void Update_CGGoodsNum2(int DetailId, int Num, int Num2, int FHPlan, string bhremark) { string tsql = @" update HW_GoodsDetail set CGNum2=@Num,CGNum3=@Num2,FHPlan=@FHPlan,bhremark=@bhremark where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@FHPlan", DbType.Int32, FHPlan); db.AddInParameter(cmd, "@Num", DbType.Int32, Num); db.AddInParameter(cmd, "@Num2", DbType.Int32, Num2); db.AddInParameter(cmd, "@bhremark", DbType.String, bhremark); db.ExecuteNonQuery(cmd); } #endregion #region 保存采购数量 public static void Update_CGGoodsNum(int DetailId, int Num) { string tsql = @" update HW_GoodsDetail set CGNum=@Num where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@Num", DbType.Int32, Num); db.ExecuteNonQuery(cmd); } #endregion #region 保存采购数量 public static void Update_CGGoodsNum2(int DetailId, int Num) { string tsql = @" update HW_GoodsDetail set CGNum=isnull(CGNum,0)+@Num where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@Num", DbType.Int32, Num); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单采购时间 public static void UpdateOrderBuyDateForTM2(int OrderId, int GoodsNum) { string tsql = @" if(select COUNT(0) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@OrderId and isnull(b.GoodsNum,0)+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0)>0)>0 begin update DT_OrderInfo set BuyDate=GETDATE() where OrderId=@OrderId and BuyDate is null update DT_OrderInfonew set BuyDate=GETDATE() where OrderId=@OrderId and BuyDate is null update DT_OrderInfo set GoodsNum=@GoodsNum where OrderId=@OrderId update DT_OrderInfonew set GoodsNum=@GoodsNum where OrderId=@OrderId end else begin update DT_OrderInfo set BuyDate=null,GoodsNum=@GoodsNum where OrderId=@OrderId update DT_OrderInfonew set BuyDate=null,GoodsNum=@GoodsNum where OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListCGGoodsInfoForNeed(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsOldCode,a.SortId,SupplierName=a.SupplierId,a.SortName,a.GoodsName,a.Position,b.AvgTime,a.State,a.CompanyId,b.DetailId,b.TypeCode,b.TypeDesc,b.NoGoods,b.MinBuyNum,b.GoodsNum,b.GoodsLockNum,b.GoodsPlanNum,GoodsOutNum=isnull(b.GoodsOutNum,0),b.SafeNum,b.GoodsInNum,b.Price,b.GoodsImageIds,b.FirstImgUrl,LeftNum=CGNum,b.SKU1,a.Supplier"; // if (DayBuy != "") // ser.Tables = @"HW_GoodsInfo a inner join (select * from HW_GoodsDetail where GoodsNum<" + DayBuy + @")b on a.GoodsId=b.GoodsId //inner join HW_GoodsSort c on a.SortId=c.SortId //"; // else ser.Tables = @"HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListCGGoodsInfoForNeedYW(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsOldCode,a.SortId,SupplierName=a.SupplierId,a.SortName,a.GoodsName,a.Position,b.AvgTime,a.State,a.CompanyId,b.DetailId,b.TypeCode,b.TypeDesc,b.NoGoods,b.MinBuyNum,b.GoodsNum,b.GoodsLockNum,b.GoodsPlanNum,GoodsOutNum=isnull(b.GoodsOutNum,0),b.SafeNum,b.GoodsInNum,b.Price,b.GoodsImageIds,b.FirstImgUrl,LeftNum=(isnull(b.GoodsPlanNum, 0)-isnull(b.GoodsNum, 0)-isnull(b.GoodsInNum, 0)),b.SKU1,a.Supplier"; // if (DayBuy != "") // ser.Tables = @"HW_GoodsInfo a inner join (select * from HW_GoodsDetail where GoodsNum<" + DayBuy + @")b on a.GoodsId=b.GoodsId //inner join HW_GoodsSort c on a.SortId=c.SortId //"; // else ser.Tables = @"HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 查询货物明细列表 public static List GetGoodsSPDetailForNeed(string Ids) { List list = null; string tsql = @" select a.DetailId,a.TypeCode,a.TypeDesc,a.SKU1,a.GoodsNum,a.GoodsInNum,a.GoodsPlanNum,a.SafeNum,BuyNum=isnull(a.CGNum,0),b.GoodsCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price is not null and a.Price>0 then a.Price else b.NowPrice end,b.FirstImgUrl,b.GoodsOldCode,b.GoodsId,GRemark=b.GoodsRemark,b.DeptRemark,b.NoticeDays from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.DetailId in (" + Ids + ") order by b.GoodsCode,a.TypeCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改货物采购数量 public static void UpdateBuyCGNum(int DetailId, int OldNum, int NewNum) { string tsql = @" if @OldNum>0 begin update HW_GoodsDetail set CGNum=isnull(CGNum,0)+@OldNum where DetailId=@DetailId end if @NewNum>0 begin if(select count(0) from HW_GoodsDetail where DetailId=@DetailId and isnull(CGNum,0)>=@NewNum)>0 begin update HW_GoodsDetail set CGNum=CGNum-@NewNum where DetailId=@DetailId end else begin update HW_GoodsDetail set CGNum=0 where DetailId=@DetailId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@OldNum", DbType.Int32, OldNum); db.AddInParameter(cmd, "@NewNum", DbType.Int32, NewNum); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物采购数量 public static void UpdateBuyBFNum1(int DetailId, int Num) { string tsql = @" if @BHNum1=0 begin update HW_GoodsDetail set BHNum1=null where DetailId=@DetailId end else begin update HW_GoodsDetail set BHNum1=@BHNum1 where DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@BHNum1", DbType.Int32, Num); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物采购数量 public static void UpdateBuyBFNum2(int DetailId, int Num) { string tsql = @" if @BHNum2=0 begin update HW_GoodsDetail set BHNum2=null where DetailId=@DetailId end else begin update HW_GoodsDetail set BHNum2=@BHNum2 where DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@BHNum2", DbType.Int32, Num); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物采购数量 public static void UpdateBuyBFNum4(int DetailId, int Num) { string tsql = @" if @BHNum3=0 begin update HW_GoodsDetail set BHNum3=null where DetailId=@DetailId end else begin update HW_GoodsDetail set BHNum3=@BHNum3 where DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@BHNum3", DbType.Int32, Num); db.ExecuteNonQuery(cmd); } #endregion #region 保存货物店铺 public static int SaveShopForTM(HW_Shop Model) { string tsql = @" set @Id=0 select top 1 @Id=Id from HW_Shop where [GoodsId]=@GoodsId and [ShopId]=@ShopId if @Id=0 begin INSERT INTO [HW_Shop]([GoodsId],[ShopId],InName,InDate)values(@GoodsId,@ShopId,@InName,getdate()) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改货物采购数量 public static void UpdateBuyBFNum3(int DetailId, DateTime? JH_Date) { string tsql = @" update HW_GoodsDetail set JH_Date=@JH_Date where DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@JH_Date", DbType.DateTime, JH_Date); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物采购数量 public static void UpdateBuyBFNum(int DetailId, int Num, int Num2) { string tsql = @" update HW_GoodsDetail set BHNum1=@BHNum1,BHNum2=@BHNum2 where DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@BHNum1", DbType.Int32, Num); db.AddInParameter(cmd, "@BHNum2", DbType.Int32, Num2); db.ExecuteNonQuery(cmd); } #endregion #region 修改 public static void UpdateSalesType(int DetailId, int SalesType) { string tsql = @" update HW_GoodsDetail set SalesType=@SalesType where DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@SalesType", DbType.Int32, SalesType); db.ExecuteNonQuery(cmd); } #endregion #region 修改 public static void UpdateIsExamine(int goodsId, int isExamine) { string tsql = @" update HW_GoodsInfo set IsExamine=@isExamine where GoodsId=@goodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@isExamine", DbType.Int32, isExamine); db.AddInParameter(cmd, "@goodsId", DbType.Int32, goodsId); db.ExecuteNonQuery(cmd); } #endregion #region 修改货物采购数量 public static void UpdateClearBFNum() { string tsql = @" update HW_GoodsDetail set BHNum1=null,BHNum2=null,JH_Date=null where isnull(BHNum1,0)>0 or isnull(BHNum2,0)>0 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListBFNum(int CK) { //string tsql = "select a.Id,a.OrderId,a.Sku,a.Weight,a.Long,a.Width,a.Height,a.Fee1,a.Fee2,a.Fee3,a.InDate,a.InUserId from DT_SpareFee"; string tsql = @"select SKU1,b.Solid,BHNum=a.BHNum1,TSolid=isnull(b.Solid,0)*a.BHNum1,Cert='',a.JH_Date from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId = b.GoodsId where BHNum1> 0"; if (CK == 1) tsql = @"select SKU1,b.Solid,BHNum=a.BHNum2,TSolid=isnull(b.Solid,0)*a.BHNum2,Cert='',a.JH_Date from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId = b.GoodsId where BHNum2> 0"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回扫描订单Model public static HW_GoodsDetailNew GetGoodsModelForBF(int DetailId) { HW_GoodsDetailNew model = null; string tsql = @" select BHNum1,BHNum2 from HW_GoodsDetail where detailid=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.String, DetailId); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 读取首页订单数 public static DT_DefaultData2 GetDefaultDataForTM3(int CompanyID) { DT_DefaultData2 model = null; string tsql = @" declare @Num1 int,@TSoild1 Decimal(18,2),@Price1 Decimal(18,2),@Num11 int,@TSoild11 Decimal(18,2),@Price11 Decimal(18,2),@Num2 int,@TSoild2 Decimal(18,2),@Price2 Decimal(18,2),@Num3 int,@TSoild3 Decimal(18,2),@Price3 Decimal(18,2),@Num4 int,@TSoild4 Decimal(18,2),@Price4 Decimal(18,2),@Num5 int,@TSoild5 Decimal(18,2),@Price5 Decimal(18,2),@Num6 int,@TSoild6 Decimal(18,2),@Price6 Decimal(18,2) select @Num1=sum(b.GoodsNum-ISNULL(b.InGoodsNum,0)-ISNULL(b.TJOutNum,0)),@TSoild1=sum(isnull(d.Solid,0)*(b.GoodsNum-ISNULL(b.InGoodsNum,0)-ISNULL(b.TJOutNum,0))),@Price1=sum(isnull(b.GoodsPrice,0)*(b.GoodsNum-ISNULL(b.InGoodsNum,0)-ISNULL(b.TJOutNum,0))) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c with(nolock)on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock)on c.GoodsId=d.GoodsId where a.CompanyID=1 and ISNULL(b.IsOrder,-1)=-1 and a.IsDelete=0 and a.State<3 and a.GoodsState<2 and isnull(a.IsGJ,0)=0 and b.GoodsNum-ISNULL(b.InGoodsNum,0)-ISNULL(b.TJOutNum,0)>0 select @Num11=sum(b.GoodsNum-ISNULL(b.ErrorNum,0)-ISNULL(b.OutNum,0)),@TSoild11=sum(isnull(d.Solid,0)*(b.GoodsNum-ISNULL(b.ErrorNum,0)-ISNULL(b.OutNum,0))),@Price11=sum(isnull(b.GoodsPrice,0)*(b.GoodsNum-ISNULL(b.ErrorNum,0)-ISNULL(b.OutNum,0))) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c with(nolock) on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyID=@CompanyID and ISNULL(b.IsOrder,-1)=-1 and a.IsDelete=0 and a.State<3 and a.GoodsState<2 and isnull(a.IsGJ,0)=0 and ISNULL(b.OutNum,0)>0 select @Num6=sum(b.SJOutNum),@TSoild6=sum(isnull(d.Solid,0)*b.SJOutNum),@Price6=sum(isnull(b.GoodsPrice,0)*b.SJOutNum) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.GJChaseId inner join HW_GoodsDetail c with(nolock) on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyID=@CompanyID and a.IsDelete=0 and a.IsGJ=1 and a.PostState=0 select @Num2=sum(b.SJOutNum),@TSoild2=sum(isnull(d.Solid,0)*b.SJOutNum),@Price2=sum(isnull(b.GoodsPrice,0)*b.SJOutNum) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId inner join HW_GoodsDetail c on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.CompanyID=@CompanyID and a.IsDelete=0 and a.IsGJ=1 and a.PostState=3 select @Num3=sum(ISNULL(b.SJOutNum,0)-ISNULL(b.OutInNum,0)),@TSoild3=sum(isnull(d.Solid,0)*(ISNULL(b.SJOutNum,0)-ISNULL(b.OutInNum,0))),@Price3=sum(isnull(b.GoodsPrice,0)*(ISNULL(b.SJOutNum,0)-ISNULL(b.OutInNum,0))) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.GJChaseId inner join HW_GoodsDetail c with(nolock) on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyID=1 and a.IsDelete=0 and a.IsGJ=1 and ISNULL(b.SJOutNum,0)-ISNULL(b.OutInNum,0)>0 select @Num4=sum(b.SJOutNum),@TSoild4=sum(isnull(d.Solid,0)*b.SJOutNum),@Price4=sum(isnull(b.GoodsPrice,0)*b.SJOutNum) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.GJChaseId inner join HW_GoodsDetail c with(nolock) on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock)on c.GoodsId=d.GoodsId where a.CompanyID=@CompanyID and a.IsDelete=0 and a.IsGJ=1 and a.PostState=5 select @Num5=sum(b.SJOutNum-ISNULL(b.OutInNum,0)),@TSoild5=sum(isnull(d.Solid,0)*(b.SJOutNum-ISNULL(b.OutInNum,0))),@Price5=sum(isnull(b.GoodsPrice,0)*(b.SJOutNum-ISNULL(b.OutInNum,0))) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.GJChaseId inner join HW_GoodsDetail c with(nolock) on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock)on c.GoodsId=d.GoodsId where a.CompanyID=@CompanyID and a.IsDelete=0 and a.IsGJ=1 and a.PostState=6 select Num1=isnull(@Num1,0)+isnull(@Num11,0),TSoild1=isnull(@TSoild1,0)+isnull(@TSoild11,0),Price1=isnull(@Price1,0)+isnull(@Price11,0),Num2=isnull(@Num2,0),TSoild2=isnull(@TSoild2,0),Price2=isnull(@Price2,0),Num3=isnull(@Num3,0),TSoild3=isnull(@TSoild3,0),Price3=isnull(@Price3,0),Num4=isnull(@Num4,0),TSoild4=isnull(@TSoild4,0),Price4=isnull(@Price4,0),Num5=isnull(@Num5,0),TSoild5=isnull(@TSoild5,0),Price5=isnull(@Price5,0),Num6=isnull(@Num6,0),TSoild6=isnull(@TSoild6,0),Price6=isnull(@Price6,0) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); DataSet tb = db.ExecuteDataSet(cmd); if (tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); return model; } #endregion #region 查询我的订单 public static List Get_OrderGoodsForBack(string OrderIds) { List list = null; string tsql = @" select Fee1=isnull(b.PostPrice,0)*b.KCNum,GDFee=isnull(b.Price,0)*b.KCNum,Fee2=isnull(b.HWCFee,0)*b.KCNum,a.OrderId from DT_OrderGoods a with(nolock) inner join HW_GoodsInDetail b with(nolock) on a.Id=b.OrderGoodsId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 读取店铺 public static List GetShopListUser(int UserId, int PlatType, string UserType, string AllShop) { string tsql = @" select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where ShopId IN (SELECT ShopId from JC_ShopUser WHERE UserId=@UserId) and (@PlatType=0 or PlatType=@PlatType) order by PlatType "; if (AllShop == "1" || UserType == "M" || UserType == "S" || UserId == 48 || UserId == 51) tsql = @" select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where CompanyId=1 and (@PlatType=0 or PlatType=@PlatType) order by PlatType "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 删除 public static void Delete_SpareFee(int OrderId) { string tsql = @" update DT_SpareFee set InDate=null where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Delete_SpareFee3(int Id) { string tsql = @" delete from DT_SpareFee where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Delete_SpareFee2(int OrderId) { string tsql = @" delete from DT_SpareFee where OrderId=@OrderId and InDate is null"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Sum_SpareFee(int PostId, int OrderId, string PostType) { string tsql = @" update DT_OrderInfo set Fee6=( select SUM(isnull(fee1,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostType == "FEDEX_GROUND") tsql = @" update DT_OrderInfo set Fee7=( select SUM(isnull(fee2,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostType == "GROUND_HOME_DELIVERY") tsql = @" update DT_OrderInfo set Fee8=( select SUM(isnull(fee3,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostType == "FEDEX_2_DAY") tsql = @" update DT_OrderInfo set Fee10=( select SUM(isnull(fee4,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostId == 237) { tsql = @" update DT_OrderInfo set Fee11=( select SUM(isnull(fee11,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostType == "FEDEX_GROUND") tsql = @" update DT_OrderInfo set Fee12=( select SUM(isnull(fee22,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostType == "GROUND_HOME_DELIVERY") tsql = @" update DT_OrderInfo set Fee13=( select SUM(isnull(fee33,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; if (PostType == "FEDEX_2_DAY") tsql = @" update DT_OrderInfo set Fee14=( select SUM(isnull(fee44,0)) from DT_SpareFee where OrderId=@OrderId) where OrderId=@OrderId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListSpareFee(int OrderId) { //string tsql = "select a.Id,a.OrderId,a.Sku,a.Weight,a.Long,a.Width,a.Height,a.Fee1,a.Fee2,a.Fee3,a.InDate,a.InUserId from DT_SpareFee"; string tsql = "select * from DT_SpareFee where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_SpareFee(DT_SpareFee Model) { string tsql = @" if @Id>0 begin Update [DT_SpareFee] set [OrderId]=@OrderId,[Sku]=@Sku,[Weight]=@Weight,[Long]=@Long,[Width]=@Width,[Height]=@Height,[Fee1]=@Fee1,[Fee2]=@Fee2,[Fee3]=@Fee3,[InDate]=@InDate,[InUserId]=@InUserId where Id=@Id end else begin INSERT INTO [DT_SpareFee]([OrderId],[Sku],[Weight],[Long],[Width],[Height],[Fee1],[Fee2],[Fee3],[InDate],[InUserId])values(@OrderId,@Sku,@Weight,@Long,@Width,@Height,@Fee1,@Fee2,@Fee3,@InDate,@InUserId) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@Sku", DbType.String, Model.Sku); db.AddInParameter(cmd, "@Weight", DbType.String, Model.Weight); db.AddInParameter(cmd, "@Long", DbType.String, Model.Long); db.AddInParameter(cmd, "@Width", DbType.String, Model.Width); db.AddInParameter(cmd, "@Height", DbType.String, Model.Height); db.AddInParameter(cmd, "@Fee1", DbType.Decimal, Model.Fee1); db.AddInParameter(cmd, "@Fee2", DbType.Decimal, Model.Fee2); db.AddInParameter(cmd, "@Fee3", DbType.Decimal, Model.Fee3); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改要自动匹配的订单货物 public static void UpdateOrderGoodsLockForTM3(int OrderId, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],HWCFee,GoodsRate) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.OrderNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId],HWCFee,GoodsRate from [HW_GoodsInDetail] where InId=" + md2.InId + " and KCNum>=" + md2.OrderNum + @" update HW_GoodsInDetail set KCNum=KCNum-" + md2.OrderNum + " where InId=" + md2.InId + " and KCNum>=" + md2.OrderNum + @" update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != null && JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=2 where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set MateState=2 where JoinOrderCode=@JoinOrderCode INSERT INTO [HW_UserMate]([OrderId],[InDate],[IsDel],[JoinOrderCode])values(0,getdate(),0,@JoinOrderCode) --if @StoreId>0 --begin --update b set StoreId=@StoreId from DT_OrderInfo a --inner join DT_OrderXXInfo b on a.OrderId=b.OrderId --where a.JoinOrderCode=@JoinOrderCode --update b set StoreId=@StoreId from DT_OrderInfoNew a --inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId --where a.JoinOrderCode=@JoinOrderCode --end "; } else if (OrderId > 0) { tsql += @" update DT_OrderInfo set MateState=2 where OrderId=@OrderId update DT_OrderInfonew set MateState=2 where OrderId=@OrderId INSERT INTO [HW_UserMate]([OrderId],[InDate],[IsDel],[JoinOrderCode])values(@OrderId,getdate(),0,null) --if @StoreId>0 --begin --update DT_OrderXXInfo set StoreId=@StoreId where OrderId=@OrderId --update DT_OrderXXInfoNew set StoreId=@StoreId where OrderId=@OrderId --end "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 修改要自动匹配的订单货物 public static void UpdateOrderGoodsLockForTM2(int OrderId, int MateState, decimal GoodsFee, decimal PostFee, string JoinOrderCode, List list) { //return; string tsql = ""; if (list != null) { foreach (var md2 in list) { tsql += @" INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],HWCFee,GoodsRate) select [DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=" + md2.OrderGoodsId + ",KCNum=" + md2.KCNum + ",UpDateTime=getdate(),[RKDetailId],[CKDetailId],HWCFee,GoodsRate from [HW_GoodsInDetail] where InId=" + md2.InId + @" update HW_GoodsInDetail set KCNum=KCNum-" + md2.KCNum + " where InId=" + md2.InId + @" update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=1 where KCNum=0 and InId=" + md2.InId + ""; } } if (JoinOrderCode != "") { tsql += @" update DT_OrderInfo set MateState=@MateState where JoinOrderCode=@JoinOrderCode update DT_OrderInfoNew set MateState=@MateState where JoinOrderCode=@JoinOrderCode INSERT INTO [HW_UserMate]([OrderId],[InDate],[IsDel],[JoinOrderCode])values(0,getdate(),0,@JoinOrderCode) "; } else tsql += @" update DT_OrderInfo set MateState=@MateState where OrderId=@OrderId update DT_OrderInfoNew set MateState=@MateState where OrderId=@OrderId INSERT INTO [HW_UserMate]([OrderId],[InDate],[IsDel],[JoinOrderCode])values(@OrderId,getdate(),0,null) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsFee", DbType.Decimal, GoodsFee); db.AddInParameter(cmd, "@MateState", DbType.Int32, MateState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 修改声明发货状态 public static void SaveBackOrderCodeState(int OrderId) { string tsql = @" update DT_OrderXXInfo set TrackDate=getdate() where OrderId=@OrderId update DT_OrderXXInfoNew set TrackDate=getdate() where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 查询要订单货物 public static List GetBackGoodsList(string OrderIds) { List list = null; string tsql = @" select GoodsDesc,GoodsNum,OrderId from DT_OrderGoods where OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回扫描订单Model public static DT_OrderScanModel GetScanOrderModelForTM3(string OrderCode) { DT_OrderScanModel model = null; string tsql = @" declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int set @OrderId=0 select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and TrackCode=@OrderCode order by Id desc if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=0 from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and isnull(ScanState,0)=1 and a.OrderCode=@OrderCode order by Id desc end if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and a.OrderCode=@OrderCode order by Id desc end --select @JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=State from DT_OrderInfo --where OrderId=@OrderId if @OrderId>0 and @PrintState=1 and @State>0 and @State<3 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=d.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode from DT_OrderGoods a inner join DT_OrderInfo e on a.OrderId=e.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where e.JoinOrderCode=@JoinOrderCode select Id,TrackCode,ScanState=isnull(ScanState,0) from DT_TrackCodeApply where State=1 and OrderCode=@JoinOrderCode end else begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode,FirstImgUrl=case when c.FirstImgUrl is not null and c.FirstImgUrl<>'' then c.FirstImgUrl else '../images/notp.png' end from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId select a.Id,a.TrackCode,ScanState=isnull(ScanState,0),ScanDate=b.InDate,b.Weight from DT_TrackCodeApply a left join DT_TrackCodeScan b on a.TrackCode=b.TrackCode where a.State=1 and a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model public static DT_OrderScanModel GetScanOrderModelForTM4(string OrderCode, string OrderCode2) { DT_OrderScanModel model = null; string tsql = @" declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int set @OrderId=0 select top 1 @TrackCode=a.TrackCode,@PostId=a.PostId,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and TrackCode=@OrderCode order by Id desc if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@PostId=a.PostId,@OrderCode=b.PlatOrderCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=0 from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and isnull(ScanState,0)=1 and a.OrderCode=@OrderCode2 order by Id desc end if @OrderId=0 begin select top 1 @TrackCode=a.TrackCode,@PostId=a.PostId,@OrderCode=b.PlatOrderCode,@OrderId=a.OrderId,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and a.OrderCode=@OrderCode2 order by Id desc end --select @JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=State from DT_OrderInfo --where OrderId=@OrderId if @OrderId>0 and @PrintState=1 and @State>0 and @State<3 begin select top 1 a.OrderId,a.PostState,a.PostDate,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=d.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@OrderId if @JoinOrderCode is not null and @JoinOrderCode<>'' begin select c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.Weight,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode from DT_OrderGoods a inner join DT_OrderInfo e on a.OrderId=e.OrderId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where e.JoinOrderCode=@JoinOrderCode end else begin select GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); //if (tb.Tables.Count > 2) // model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 保存订单扫描记录 public static void SaveTrackCodeScan(DT_TrackCodeScan Model) { string tsql = @" if(select count(0) from DT_TrackCodeScan where TrackCode=@TrackCode)=0 begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[ScanUserId],Count) values(@PostId,@TrackCode,getdate(),'',@OrderCode,@OrderId,@ScanUserId,@ScanUserId,1) end else begin update DT_TrackCodeScan set InDate=getdate(),count=Count+1 where TrackCode=@TrackCode end if @JoinOrderCode<>'' begin if @Id>0 begin update DT_OrderInfo set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode end end else begin if @Id>0 begin update DT_OrderInfo set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单扫描记录 public static void SaveTrackCodeScan2(DT_TrackCodeScan Model) { string tsql = @" if(select count(0) from DT_TrackCodeScan where TrackCode=@TrackCode)=0 begin INSERT INTO [DT_TrackCodeScan]([PostId],[TrackCode],[InDate],[InName],[OrderCode],[OrderId],[BagUserId],[ScanUserId],SureUserId,Count) values(@PostId,@TrackCode,getdate(),'',@OrderCode,@OrderId,@ScanUserId,@ScanUserId,@SureUserId,1) end else begin update DT_TrackCodeScan set InDate=getdate(),count=Count+1,SureUserId=@SureUserId where TrackCode=@TrackCode end if @JoinOrderCode<>'' begin if @Id>0 begin update DT_OrderInfo set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode update DT_OrderInfonew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where JoinOrderCode=@JoinOrderCode end end else begin if @Id>0 begin update DT_OrderInfo set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId end else begin update DT_OrderInfo set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId update DT_OrderInfoNew set state=2,poststate=1,PostDate=getdate(),PrintState=1,PrintDate=isnuLL(PrintDate,GETDATE()) where orderid=@OrderId end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 保存订单扫描记录 public static void SaveTrackCodeScan5(DT_TrackCodeScan Model) { string tsql = @" if(select count(0) from DT_TrackCodeScan with(nolock) where TrackCode=@TrackCode)>0 begin update DT_TrackCodeScan set InDate=getdate(),count=Count+1,SureUserId=@SureUserId where TrackCode=@TrackCode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@PostId", DbType.Int32, Model.PostId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@SureUserId", DbType.Int32, Model.SureUserId); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.ExecuteNonQuery(cmd); } #endregion #region 返回扫描订单Model public static DT_OrderScanModel GetScanOrderModelForTM5(string OrderCode, string OrderCode2) { DT_OrderScanModel model = null; string tsql = @" declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int set @OrderId=0 select top 1 @TrackCode=a.TrackCode,@PostId=a.PostId,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0) from DT_TrackCodeApply a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.State=1 and TrackCode=@OrderCode order by Id desc if @OrderId=0 begin select OrderId=0 select Id=b.DetailId,c.GoodsName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,GoodsNum=1,TrackCode='',FirstImgUrl='' from HW_GoodsDetail b inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=1 and (c.GoodsCode=@OrderCode2 or c.GoodsOldCode=@OrderCode2 or b.SKU1=@OrderCode2) end else begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=d.Name from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId inner join JC_Express d on b.Post=d.ExpressID where a.OrderId=@OrderId select Id=b.DetailId,GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,a.GoodsNum,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); //if (tb.Tables.Count > 2) // model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model(退货中间步骤) public static DT_OrderScanModel GetScanOrderModelForReturnMid(string OrderCode, string OrderCode2, int UserId) { DT_OrderScanModel model = null; string tsql = @" --declare @OrderCode nvarchar(50),@OrderCode2 nvarchar(50) --set @OrderCode='1Z266E819066489986' declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int,@DetailId int,@num int,@OldPostionCode nvarchar(50),@PostInfo nvarchar(50) set @OrderId=0 select top 1 @TrackCode=a.tracking_id,@PostInfo=return_carrier,@PostId=0,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0),@DetailId=a.DetailId,@num=a.return_quantity,@OldPostionCode=a.OldPostionCode from DT_OrderReturn a inner join DT_OrderInfo b on a.OrderId=b.OrderId where isnull(a.ScanState,0)=0 and (tracking_id=@OrderCode or tracking_id=@OrderCode2) order by Id desc declare @WorkDesc nvarchar(50),@storeId int select @WorkDesc=WorkDesc from JC_UserInfo where UserId=@UserId set @storeId=6 if @WorkDesc='东仓' begin set @storeId=11 end set @OldPostionCode='LS' if @OrderId>0 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=@PostInfo,OrderName=@OldPostionCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.OrderId=@OrderId select Id=b.DetailId,GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,GoodsNum=@num,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId and a.DetailId=@DetailId select TrackCode='LS',TrackCode2='LS',TrackType=2 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model(退货中间步骤) xsx public static DT_OrderScanModel GetScanOrderModelForReturnMid_250203(string OrderCode, string OrderCode1, string OrderCode2, string OrderCode3, string OrderCode4, string OrderCode5, int UserId) { DT_OrderScanModel model = null; string tsql = @" --declare @OrderCode nvarchar(50),@OrderCode2 nvarchar(50) --set @OrderCode='1Z266E819066489986' declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int,@DetailId int,@num int,@OldPostionCode nvarchar(50),@PostInfo nvarchar(50) set @OrderId=0 select top 1 @TrackCode=a.tracking_id,@PostInfo=return_carrier,@PostId=0,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0),@DetailId=a.DetailId,@num=a.return_quantity,@OldPostionCode=a.OldPostionCode from DT_OrderReturn a inner join DT_OrderInfo b on a.OrderId=b.OrderId where isnull(a.ScanState,0)=0 and (tracking_id=@OrderCode or tracking_id=@OrderCode1 or tracking_id=@OrderCode2 or tracking_id=@OrderCode3 or tracking_id=@OrderCode4 or tracking_id=@OrderCode5) order by Id desc declare @WorkDesc nvarchar(50),@storeId int select @WorkDesc=WorkDesc from JC_UserInfo where UserId=@UserId set @storeId=6 if @WorkDesc='东仓' begin set @storeId=11 end set @OldPostionCode='LS' if @OrderId>0 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=@PostInfo,OrderName=@OldPostionCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.OrderId=@OrderId select Id=b.DetailId,GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,GoodsNum=@num,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId and a.DetailId=@DetailId select TrackCode='LS',TrackCode2='LS',TrackType=2 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode1", DbType.String, OrderCode1); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); db.AddInParameter(cmd, "@OrderCode3", DbType.String, OrderCode3); db.AddInParameter(cmd, "@OrderCode4", DbType.String, OrderCode4); db.AddInParameter(cmd, "@OrderCode5", DbType.String, OrderCode5); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 智能库存temu筛选 public static List GetTemuSKUData(OuterService.ShageService.GetDataList input, out int rowCount) { //int PageSize, int PageIndex, string GoodsCode, string Name, bool? IsNegative, int PageSize = input.PageSize; int PageIndex = input.PageIndex; string GoodsCode = input.GoodsCode; string Name = input.Name; bool? IsNegative = input.IsNegative; int? Day = input.Day; int? S_SaleNum = input.S_SaleNum; int? E_SaleNum = input.E_SaleNum; int? StoreHouse = input.StoreHouse; int? S_LeftNum = input.S_LeftNum; int? E_LeftNum = input.E_LeftNum; DateTime? S_OrderDate = new DateTime(2023, 4, 1, 0, 0, 0, 0); DateTime? E_OrderDate = DateTime.Today; List model = null; #region string sqlPage = string.Empty; string where = string.Empty; string Where_OrderDate = string.Empty; if (PageSize < 10000) { if (PageIndex > 1) { sqlPage = " and row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; } else { sqlPage = " and row between 1 and " + PageIndex * PageSize; } } if (!string.IsNullOrEmpty(GoodsCode)) { where += " and GoodsCode like '%" + GoodsCode + "%' "; } if (!string.IsNullOrEmpty(Name)) { where += " and Name like '%" + Name + "%' "; } if (IsNegative!=null && IsNegative==true) { where += " and GrossProfit <= 0 "; } if (Day!=null) { if (S_SaleNum==null) { S_SaleNum = 0; } if (E_SaleNum==null) { E_SaleNum = 9999999; } switch (Day) { case 0: where += " and isnull(tall.SaleNum,0) between " + S_SaleNum + " and " + E_SaleNum; break; case 1: where += " and isnull(t1.SaleNum,0) between " + S_SaleNum +" and " + E_SaleNum; break; case 2: where += " and isnull(t2.SaleNum,0) between " + S_SaleNum + " and " + E_SaleNum; break; case 3: where += " and isnull(t3.SaleNum,0) between " + S_SaleNum + " and " + E_SaleNum; break; case 7: where += " and isnull(t7.SaleNum,0) between " + S_SaleNum + " and " + E_SaleNum; break; case 14: where += " and isnull(t14.SaleNum,0) between " + S_SaleNum + " and " + E_SaleNum; break; case 30: where += " and isnull(t30.SaleNum,0) between " + S_SaleNum + " and " + E_SaleNum; break; } } if (StoreHouse != null) { if (S_LeftNum == null) { S_LeftNum = 0; } if (E_LeftNum == null) { E_LeftNum = 9999999; } switch (StoreHouse) { case 0: where += " and sumall.LeftNumAll between " + S_LeftNum + " and " + E_LeftNum; break; case 1: where += " and sumall.LeftNumW between " + S_LeftNum + " and " + E_LeftNum; break; case 2: where += " and sumall.LeftNumE between " + S_LeftNum + " and " + E_LeftNum; break; } } if (input.S_OrderDate != null && input.E_OrderDate != null) { S_OrderDate = input.S_OrderDate; E_OrderDate = input.E_OrderDate; } Where_OrderDate = " and CONVERT(date, a.OrderDate) >=CONVERT(date,@sDate) and CONVERT(date, a.OrderDate) <= CONVERT(date,@eDate)"; #endregion string tsql = @"select count(1) count from ( select ROW_NUMBER() OVER(order by t30.SaleNum desc) row,a.GoodsId, b.GoodsCode,c.Name,a.YuGuJiaGe as temuChengben,b.JYPrice ,Gr.GrossProfit,isnull(t1.SaleNum,0) as SaleNum1,isnull(t2.SaleNum,0) as SaleNum2,isnull(t3.SaleNum,0) as SaleNum3,isnull(t7.SaleNum,0) as SaleNum7,isnull(t14.SaleNum,0) as SaleNum14,isnull(t30.SaleNum,0) as SaleNum30,isnull(tall.SaleNum,0) GoodsHJNum,sumall.LeftNumW,sumall.LeftNumE,'' as PositionAge,sumall.LeftNumAll from [dbo].[TemuChengBen] a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join JC_UserInfo c on a.mUserId=c.UserId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=1 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t1 on a.GoodsId=t1.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=2 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t2 on a.GoodsId=t2.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=3 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t3 on a.GoodsId=t3.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=7 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t7 on a.GoodsId=t7.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=14 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t14 on a.GoodsId=t14.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t30 on a.GoodsId=t30.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) tall on a.GoodsId=tall.GoodsId left join (select a.GoodsId,sum(GoodsHJNum) as GoodsHJNum,LeftNumW= sum(isnull(a.WestNum,0)), LeftNumE=sum(isnull(a.EastNum,0) ),LeftNumAll= sum(isnull(a.WestNum,0))+sum(isnull(a.EastNum,0) ) from HW_GoodsDetail a inner join [TemuChengBen] b on a.goodsid=b.GoodsId group by a.GoodsId) sumall on a.GoodsId=sumall.GoodsId left join (select GoodsId,sum(GrossProfit) as GrossProfit from ( select a.orderid,isnull(e.GoodsId,0) GoodsId , CONVERT(DECIMAL(10, 2),a.TotalPrice-isnull(b.yj,0)-isnull(a.escrowFee,0)-(isnull(b.cb,0)+isnull(b.hwsf,0))/isnull(b.moneyrate,1)-isnull(b.yf,0)-isnull(b.tc,0)-isnull(a.DR_PostFee,0)-isnull(a.Other_Fee,0)+isnull(a.DR_SSFee,0)-ISNULL(b.md,0)+Isnull( b.SubsidyFee,0)-isnull(a.Ad_Fee,0)) GrossProfit from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods g on a.OrderId=g.OrderId inner join HW_GoodsDetail e on g.DetailId=e.DetailId left Join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and a.PlatId=23 " + Where_OrderDate + @")t group by GoodsId) Gr on a.GoodsId=Gr.GoodsId where 1=1 " + where + @") t where 1=1 " + @"select GoodsId,GoodsCode,Name,temuChengben,JYPrice,GrossProfit,SaleNum1,SaleNum2,SaleNum3,SaleNum7,SaleNum14,SaleNum30,GoodsHJNum,LeftNumW,LeftNumE, PositionAge,LeftNumAll from ( select ROW_NUMBER() OVER(order by t30.SaleNum desc) row,a.GoodsId, b.GoodsCode,c.Name,a.YuGuJiaGe as temuChengben,b.JYPrice ,Gr.GrossProfit,isnull(t1.SaleNum,0) as SaleNum1,isnull(t2.SaleNum,0) as SaleNum2,isnull(t3.SaleNum,0) as SaleNum3,isnull(t7.SaleNum,0) as SaleNum7,isnull(t14.SaleNum,0) as SaleNum14,isnull(t30.SaleNum,0) as SaleNum30,isnull(tall.SaleNum,0) GoodsHJNum,sumall.LeftNumW,sumall.LeftNumE,'' as PositionAge,sumall.LeftNumAll from [dbo].[TemuChengBen] a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join JC_UserInfo c on a.mUserId=c.UserId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=1 and a.PlatId=23 " + Where_OrderDate + @" ) t group by t.GoodsId ) t1 on a.GoodsId=t1.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=2 and a.PlatId=23 "+ Where_OrderDate + @" ) t group by t.GoodsId ) t2 on a.GoodsId=t2.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=3 and a.PlatId=23 "+ Where_OrderDate + @" ) t group by t.GoodsId ) t3 on a.GoodsId=t3.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=7 and a.PlatId=23 "+ Where_OrderDate + @" ) t group by t.GoodsId ) t7 on a.GoodsId=t7.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=14 and a.PlatId=23 "+ Where_OrderDate + @" ) t group by t.GoodsId ) t14 on a.GoodsId=t14.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 and a.PlatId=23 "+ Where_OrderDate + @" ) t group by t.GoodsId ) t30 on a.GoodsId=t30.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and a.PlatId=23 "+ Where_OrderDate + @" ) t group by t.GoodsId ) tall on a.GoodsId=tall.GoodsId left join (select a.GoodsId,sum(GoodsHJNum) as GoodsHJNum,LeftNumW= sum(isnull(a.WestNum,0)), LeftNumE=sum(isnull(a.EastNum,0) ),LeftNumAll= sum(isnull(a.WestNum,0))+sum(isnull(a.EastNum,0) ) from HW_GoodsDetail a inner join [TemuChengBen] b on a.goodsid=b.GoodsId group by a.GoodsId) sumall on a.GoodsId=sumall.GoodsId left join (select GoodsId,sum(GrossProfit) as GrossProfit from ( select a.orderid,isnull(e.GoodsId,0) GoodsId , CONVERT(DECIMAL(10, 2),a.TotalPrice-isnull(b.yj,0)-isnull(a.escrowFee,0)-(isnull(b.cb,0)+isnull(b.hwsf,0))/isnull(b.moneyrate,1)-isnull(b.yf,0)-isnull(b.tc,0)-isnull(a.DR_PostFee,0)-isnull(a.Other_Fee,0)+isnull(a.DR_SSFee,0)-ISNULL(b.md,0)+Isnull( b.SubsidyFee,0)-isnull(a.Ad_Fee,0)) GrossProfit from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods g on a.OrderId=g.OrderId inner join HW_GoodsDetail e on g.DetailId=e.DetailId left Join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and a.PlatId=23 "+ Where_OrderDate + @")t group by GoodsId) Gr on a.GoodsId=Gr.GoodsId where 1=1 " + where + @") t where 1=1 " + sqlPage + " order by GoodsHJNum desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sDate", DbType.DateTime, S_OrderDate); db.AddInParameter(cmd, "@eDate", DbType.DateTime, Convert.ToDateTime(E_OrderDate).AddDays(1)); DataSet tb = db.ExecuteDataSet(cmd); rowCount = (int)tb.Tables[0].Rows[0]["count"]; if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[1].Rows.Count > 0) model = tb.Tables[1].ToList(); } return model; } #endregion #region 智能库存temu筛选 根据sku显示各个店铺毛利 public static List GetTemuShopGrossProfit(int GoodsId) { List model = null; string where = string.Empty; if (GoodsId>0) { where = " and e.GoodsId=" + GoodsId + " "; } //string tsql = @"select count(1) count from [dbo].[TemuChengBen] a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join JC_UserInfo c on a.mUserId=c.UserId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=1 ) t group by t.GoodsId ) t1 on a.GoodsId=t1.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=2 ) t group by t.GoodsId ) t2 on a.GoodsId=t2.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=3 ) t group by t.GoodsId ) t3 on a.GoodsId=t3.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=7 ) t group by t.GoodsId ) t7 on a.GoodsId=t7.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=14 ) t group by t.GoodsId ) t14 on a.GoodsId=t14.GoodsId left join ( select t.GoodsId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId,isnull(e.GoodsId,0) GoodsId ,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail e on b.DetailId=e.DetailId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 ) t group by t.GoodsId ) t30 on a.GoodsId=t30.GoodsId left join (select a.GoodsId,sum(GoodsHJNum) as GoodsHJNum,LeftNumW= sum(isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0)), LeftNumE=sum(isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0) ) from HW_GoodsDetail a inner join [TemuChengBen] b on a.goodsid=b.GoodsId group by a.GoodsId) sumall on a.GoodsId=sumall.GoodsId" string tsql = @"select ShopName,sum(GrossProfit) as GrossProfit from ( select a.orderid,OrderCode,sh.ShopName,isnull(e.GoodsId,0) GoodsId , CONVERT(DECIMAL(10, 2),a.TotalPrice-isnull(b.yj,0)-isnull(a.escrowFee,0)-(isnull(b.cb,0)+isnull(b.hwsf,0))/isnull(b.moneyrate,1)-isnull(b.yf,0)-isnull(b.tc,0)-isnull(a.DR_PostFee,0)-isnull(a.Other_Fee,0)+isnull(a.DR_SSFee,0)-ISNULL(b.md,0)+Isnull( b.SubsidyFee,0)-isnull(a.Ad_Fee,0)) GrossProfit from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods g on a.OrderId=g.OrderId inner join HW_GoodsDetail e on g.DetailId=e.DetailId left Join DT_Fees b with(nolock) on a.OrderId=b.orderid left join JC_Shop sh on a.ShopId=sh.ShopId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and a.PlatId=23 " + where +@" ) t group by ShopName "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet tb = db.ExecuteDataSet(cmd); //rowCount = (int)tb.Tables[0].Rows[0]["count"]; if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].ToList(); } return model; } #endregion #region 返回扫描订单Model public static DT_OrderScanModel GetScanOrderModelForReturnFinal(string OrderCode, string OrderCode2, int UserId) { DT_OrderScanModel model = null; string tsql = @" --declare @OrderCode nvarchar(50),@OrderCode2 nvarchar(50) --set @OrderCode='1Z266E819066489986' declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int,@DetailId int,@num int,@OldPostionCode nvarchar(50),@PostInfo nvarchar(50) set @OrderId=0 select top 1 @TrackCode=a.tracking_id,@PostInfo=return_carrier,@PostId=0,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0),@DetailId=a.DetailId,@num=a.return_quantity,@OldPostionCode=a.OldPostionCode from DT_OrderReturn a inner join DT_OrderInfo b on a.OrderId=b.OrderId where (isnull(a.ScanState,0)=0 or isnull(a.ScanState,0)=2) and (tracking_id=@OrderCode or tracking_id=@OrderCode2) order by Id desc declare @WorkDesc nvarchar(50),@storeId int select @WorkDesc=WorkDesc from JC_UserInfo where UserId=@UserId set @storeId=6 if @WorkDesc='东仓' begin set @storeId=11 end select top 1 @OldPostionCode=b.PostionCode from HW_GoodsInDetail a with(nolock) inner join CK_StorePostion b with(nolock) on a.PostionId=b.PostionId where DetailId=@DetailId and CKDetailId>0 and OrderGoodsId>0 and a.StoreId=@storeId order by UpDateTime desc if @OrderId>0 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=@PostInfo,OrderName=@OldPostionCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.OrderId=@OrderId select Id=b.DetailId,GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,GoodsNum=@num,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId and a.DetailId=@DetailId --select TrackCode=@OldPostionCode,TrackCode2=@OldPostionCode,TrackType=1 --union all select TrackCode=b.PostionCode,TrackCode2=b.PostionCode,TrackType=2 from CK_StoreHouse a inner join CK_StorePostion b on a.StoreId=b.StoreId where a.StoreType=5 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model xsx public static DT_OrderScanModel GetScanOrderModelForReturnFinal_250123(string OrderCode, string OrderCode1, string OrderCode2, string OrderCode3, string OrderCode4, string OrderCode5, int UserId) { DT_OrderScanModel model = null; string tsql = @" --declare @OrderCode nvarchar(50),@OrderCode2 nvarchar(50) --set @OrderCode='1Z266E819066489986' declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int,@DetailId int,@num int,@OldPostionCode nvarchar(50),@PostInfo nvarchar(50) set @OrderId=0 select top 1 @TrackCode=a.tracking_id,@PostInfo=return_carrier,@PostId=0,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0),@DetailId=a.DetailId,@num=a.return_quantity,@OldPostionCode=a.OldPostionCode from DT_OrderReturn a inner join DT_OrderInfo b on a.OrderId=b.OrderId where (isnull(a.ScanState,0)=0 or isnull(a.ScanState,0)=2) and (tracking_id=@OrderCode or tracking_id=@OrderCode1 or tracking_id=@OrderCode2 or tracking_id=@OrderCode3 or tracking_id=@OrderCode4 or tracking_id=@OrderCode5) order by Id desc declare @WorkDesc nvarchar(50),@storeId int select @WorkDesc=WorkDesc from JC_UserInfo where UserId=@UserId set @storeId=6 if @WorkDesc='东仓' begin set @storeId=11 end select top 1 @OldPostionCode=b.PostionCode from HW_GoodsInDetail a with(nolock) inner join CK_StorePostion b with(nolock) on a.PostionId=b.PostionId where DetailId=@DetailId and CKDetailId>0 and OrderGoodsId>0 and a.StoreId=@storeId order by UpDateTime desc if @OrderId>0 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=@PostInfo,OrderName=@OldPostionCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.OrderId=@OrderId select Id=b.DetailId,GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,GoodsNum=@num,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId and a.DetailId=@DetailId --select TrackCode=@OldPostionCode,TrackCode2=@OldPostionCode,TrackType=1 --union all select TrackCode=b.PostionCode,TrackCode2=b.PostionCode,TrackType=2 from CK_StoreHouse a inner join CK_StorePostion b on a.StoreId=b.StoreId where a.StoreType=5 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode1", DbType.String, OrderCode1); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); db.AddInParameter(cmd, "@OrderCode3", DbType.String, OrderCode3); db.AddInParameter(cmd, "@OrderCode4", DbType.String, OrderCode4); db.AddInParameter(cmd, "@OrderCode5", DbType.String, OrderCode5); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 返回扫描订单Model public static DT_OrderScanModel GetScanOrderModelForReturn(string OrderCode, string OrderCode2, int UserId) { DT_OrderScanModel model = null; string tsql = @" --declare @OrderCode nvarchar(50),@OrderCode2 nvarchar(50) --set @OrderCode='1Z266E819066489986' declare @TrackCode nvarchar(50),@OrderId int,@JoinOrderCode nvarchar(50),@TrackId int,@MateState int,@PrintState int,@State int,@OrderState int,@PostId int,@DetailId int,@num int,@OldPostionCode nvarchar(50),@PostInfo nvarchar(50) set @OrderId=0 select top 1 @TrackCode=a.tracking_id,@PostInfo=return_carrier,@PostId=0,@OrderId=a.OrderId,@OrderCode=b.PlatOrderCode,@JoinOrderCode=JoinOrderCode,@PrintState=PrintState,@MateState=MateState,@State=b.State,@TrackId=a.Id,@OrderState=isnull(ScanState,0),@DetailId=a.DetailId,@num=a.return_quantity,@OldPostionCode=a.OldPostionCode from DT_OrderReturn a inner join DT_OrderInfo b on a.OrderId=b.OrderId where isnull(a.ScanState,0)=0 and (tracking_id=@OrderCode or tracking_id=@OrderCode2) order by Id desc declare @WorkDesc nvarchar(50),@storeId int select @WorkDesc=WorkDesc from JC_UserInfo where UserId=@UserId set @storeId=6 if @WorkDesc='东仓' begin set @storeId=11 end select top 1 @OldPostionCode=b.PostionCode from HW_GoodsInDetail a with(nolock) inner join CK_StorePostion b with(nolock) on a.PostionId=b.PostionId where DetailId=@DetailId and CKDetailId>0 and OrderGoodsId>0 and a.StoreId=@storeId order by UpDateTime desc if @OrderId>0 begin select top 1 a.OrderId,a.PostState,a.OrderId,a.PlatOrderCode,TrackCode=@TrackCode,b.TotalWeight,b.PostFee,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,RevFax=b.RevPostCode,b.Post,b.CountryCode,WeightRate=20,a.State,a.JoinOrderCode,TrackId=@TrackId,a.PrintDate,b.ErrorInfo,s.ShopName,OrderState=@OrderState,PostInfo=@PostInfo,OrderName=@OldPostionCode from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join dbo.JC_Shop s ON a.ShopId=s.ShopId where a.OrderId=@OrderId select Id=b.DetailId,GoodsName=c.GoodsEnglisgName,c.GoodsCode,GoodsOldCode=b.SKU1,b.TypeCode,b.TypeDesc,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2*0.0625 else isnull(c.Weight,0)*0.0022046 end,GoodsPrice=b.Price,GoodsNum=@num,TrackCode=@TrackCode,FirstImgUrl='' from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@OrderId and a.DetailId=@DetailId --select TrackCode=@OldPostionCode,TrackCode2=@OldPostionCode,TrackType=1 --union all select TrackCode=b.PostionCode,TrackCode2=b.PostionCode,TrackType=2 from CK_StoreHouse a inner join CK_StorePostion b on a.StoreId=b.StoreId where a.StoreType=5 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); DataSet tb = db.ExecuteDataSet(cmd); if (tb != null) { if (tb.Tables.Count > 0 && tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); if (tb.Tables.Count > 1) model.GoodsList = tb.Tables[1].ToList(); if (tb.Tables.Count > 2) model.TrackList = tb.Tables[2].ToList(); } return model; } #endregion #region 分页查询 public static List GetListHW_GoodsInRecordForTM2(int TJ, string RKYY, string Name, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.InCode,a.InReason,a.Remark,a.InNum,a.InUserId,a.InDate,a.InName,a.CompanyId,b.ChaseCode"; string sql1 = ""; if (RKYY != "") sql1 += " InReason in (" + RKYY + ") and "; if (Name != "") { if (TJ == 1) { ser.Tables = @"(select * from HW_GoodsInRecord where " + sql1 + @" id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsCode='" + Name + "' or e.GoodsOldCode='" + Name + "'))a"; } else if (TJ == 2) { ser.Tables = @"(select * from HW_GoodsInRecord where " + sql1 + @" id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsName like '%" + Name + "%'))a"; } else if (TJ == 3) { ser.Tables = @"(select * from HW_GoodsInRecord where " + sql1 + @" id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + Name + "' or b.SKU2='" + Name + "' or b.SKU3='" + Name + "' or b.SKU4='" + Name + "' or b.SKU5='" + Name + "'))a"; } else if (TJ == 4) { ser.Tables = @"(select * from HW_GoodsInRecord where " + sql1 + @" id in (select distinct a.inid from HW_GoodsInRecordDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where b.PostionCode='" + Name + "' or b.PostionDesc='" + Name + "'))a"; } } else if (RKYY != "") ser.Tables = @"(select * from HW_GoodsInRecord a where InReason in (" + RKYY + ") )a"; else ser.Tables = @"HW_GoodsInRecord a"; ser.Tables += " left join CG_Purchase b on a.ChaseId=b.ChaseId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询出库记录 public static List GetListHW_GoodsOutListForTM(int TJ, string CKYY, string Name, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OutId=cast(a.OutId as int),a.OutCode,a.OutReason,a.Remark,a.OutNum,a.InUserId,a.InDate,a.InName,b.PlatOrderCode"; string sql1 = ""; if (CKYY != "") sql1 += " OutReason in (" + CKYY + ") and "; if (Name != "") { if (TJ == 1) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsCode='" + Name + "' or e.GoodsOldCode='" + Name + "'))a"; } else if (TJ == 2) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsName like '%" + Name + "%'))a"; } else if (TJ == 3) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + Name + "' or b.SKU2='" + Name + "' or b.SKU3='" + Name + "' or b.SKU4='" + Name + "' or b.SKU5='" + Name + "'))a"; } else if (TJ == 4) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where b.PostionCode='" + Name + "' or b.PostionDesc='" + Name + "'))a"; } } else if (CKYY != "") ser.Tables = @"(select * from HW_GoodsOutList a where OutReason in (" + CKYY + ") )a"; else ser.Tables = @"HW_GoodsOutList a"; ser.Tables += " left join DT_OrderInfo b on a.OrderId=b.OrderId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OutId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 获取导出的出库记录 public static List GetImportHW_GoodsOutList(int TJ, string CKYY, string Name, DateTime? sdate, DateTime? edate) { var filt = " where a.IsDelete=0 "; switch (TJ) { case 1: filt += " and (f.GoodsCode like '%" + Name + "%' or f.GoodsOldCode like '%" + Name + "%')"; break; case 2: filt += " and f.GoodsName like '%" + Name + "%'"; break; case 3: filt += " and d.SKU1 like '%" + Name + "%'"; break; case 4: filt += " and e.PostionCode like '%" + Name + "%'"; break; case 6: filt += " and a.OutCode like '%" + Name + "%'"; break; case 7: filt += " and c.OrderCode like '%" + Name + "%'"; break; } if (!string.IsNullOrEmpty(CKYY)) { filt += " and a.OutReason in (" + CKYY.TrimEnd(',') + ")"; } if (sdate.HasValue) { filt += " and CONVERT(date, a.InDate)>='" + sdate.Value.ToString("yyyy-MM-dd") + "'"; } if (edate.HasValue) { filt += " and CONVERT(date, a.InDate)<='" + edate.Value.ToString("yyyy-MM-dd") + "'"; } filt += " order by a.OutId desc"; var sql = @"select a.OutId,a.OutReason,c.OrderCode,d.SKU1 SKU,a.InDate ,b.OutNum,e.PostionCode from HW_GoodsOutList a inner join HW_GoodsOutDetail b on a.OutId=b.OutId left join DT_OrderInfo c on a.OrderId=c.orderid inner join HW_GoodsDetail d on b.DetailId=d.DetailId inner join HW_GoodsInfo f on d.GoodsId=f.goodsid left join CK_StorePostion e on b.PostionId=e.PostionId "; sql += filt; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListPP(string OrderIds) { List list = null; string tsql = @" select a.OrderId,GoodsNum=d.KCNum,GoodsPrice=isnull(d.Price,0)+isnull(d.PostPrice,0),Solid=isnull(d.HWCFee,0),TCFee=isnull(d.GoodsRate,0) from DT_OrderGoods a inner join HW_GoodsInDetail d on a.Id=d.OrderGoodsId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsList(string OrderIds) { //TCFee 作为税费字段 List list = null; string tsql = @" select a.OrderId,a.GoodsNum,GoodsPrice=isnull(e.InPrice,0),Solid2=isnull(e.Solid,0),TCFee=isnull(e.FeeRate,0),JoinOrderCode=f.RevFax,Weight=e.Weight2,a.DetailId,a.ckfee,a.mdfee,a.adfee from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail d with(nolock) on a.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo f with(nolock) on a.OrderId=f.OrderId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListtj(string OrderIds) { //TCFee 作为税费字段 List list = null; string tsql = @" select a.OrderId,a.GoodsNum,GoodsPrice=isnull(e.InPrice,0),Solid2=isnull(e.Solid,0),TCFee=isnull(e.FeeRate,0),JoinOrderCode=f.RevFax,Weight=e.Weight2,a.DetailId,a.ckfee,a.mdfee,a.adfee from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail d with(nolock) on a.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo f with(nolock) on a.OrderId=f.OrderId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetAmGoodsList(string OrderCodes) { List list = null; string tsql = @" select a.GoodsNum,b.OrderCode,GoodsDesc=OrderItemId,a.GoodsSKU from API_OrderGoods a inner join API_OrderInfo b on a.OrderId=b.OrderId where b.OrderCode in (" + OrderCodes + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCodes", DbType.String, OrderCodes); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存 public static int Save_USMap(DT_USMapNew Model) { string tsql = @" if @Id>0 begin Update [DT_USMap] set [statename]=@statename,[ename]=@ename,[Num]=@Num,[code]=@code,[color]=@color,[Price]=@Price,[StoreId]=@StoreId,[IsEast]=@IsEast where Id=@Id end else begin INSERT INTO [DT_USMap]([statename],[ename],[Num],[code],[color],[Price],[StoreId],[IsEast])values(@statename,@ename,@Num,@code,@color,@Price,@StoreId,@IsEast) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@statename", DbType.String, Model.statename); db.AddInParameter(cmd, "@ename", DbType.String, Model.ename); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@code", DbType.String, Model.code); db.AddInParameter(cmd, "@color", DbType.String, Model.color); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@IsEast", DbType.Int32, Model.IsEast); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListUSMap(string statename, int StoreId, int IsEast) { //string tsql = "select a.Id,a.statename,a.ename,a.Num,a.code,a.color,a.Price,a.StoreId,a.IsEast from DT_USMap"; string tsql = @"select a.*,b.StoreName from DT_USMap a left join CK_StoreHouse b on a.StoreId=b.StoreId where (@statename='' or statename=@statename or code=@statename) and (@StoreId=0 or a.StoreId=@StoreId) and (@IsEast=0 or IsEast=@IsEast)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@statename", DbType.String, statename); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@IsEast", DbType.Int32, IsEast); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListUSMap3() { //string tsql = "select a.Id,a.statename,a.ename,a.Num,a.code,a.color,a.Price,a.StoreId,a.IsEast from DT_USMap"; string tsql = @"select * from DT_USMap"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListUSMap4(string OrderIds) { //string tsql = "select a.Id,a.statename,a.ename,a.Num,a.code,a.color,a.Price,a.StoreId,a.IsEast from DT_USMap"; string tsql = @"select a.OrderId,b.StoreId,a.Fee6,a.Fee7,a.Fee8,a.Fee10,a.Fee11,a.Fee12,a.Fee13,a.Fee14 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListNew(string OrderIds) { //BGPrice 作 货物税费 List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.ChaseId,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=b.TypeDesc,CKGoodsNum=b.GoodsNum,GoodsInNum=isnull(b.GoodsInNum,0),GoodsInNum2=isnull(b.GoodsInNum2,0),GoodsInNum3=case when isnull(b.GoodsInNum,0)-isnull(b.GoodsInNum2,0)>0 then isnull(b.GoodsInNum,0)-isnull(b.GoodsInNum2,0) else 0 end,GoodsLeftNum=b.GoodsNum+isnull(b.GoodsInNum,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,d.PlatId,productImgUrl2=a.productImgUrl,productImgUrl=case when d.PlatId<>2 and a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc,a.GoodsFee,a.TCFee,GoodsPrice=b.InPrice,b.Solid2,BGPrice=b.FeeRate from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.*,c.InPrice,Solid2=c.Solid,FeeRate=isnull(c.FeeRate,0) from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListNew2(string OrderIds) { //BGPrice 作 货物税费 //GoodsFee=a.GoodsFee+isnull(a.GoodsRate,0)*0.01*a.GoodsFee 货物税费加上去 List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=b.TypeDesc,CKGoodsNum=isnull(b.WestNum,0),SpareNum=isnull(b.EastNum,0),GoodsInNum=isnull(b.GoodsInNum,0),GoodsInNum2=isnull(b.GoodsHJNum14,0),ChaseId=isnull(b.GoodsHJNum15,0),GoodsInNum3=isnull(b.GoodsInNum,0),GoodsLeftNum=isnull(b.WestNum,0)+isnull(b.EastNum,0)+isnull(b.GoodsHJNum14,0)+isnull(b.GoodsHJNum15,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,d.PlatId,productImgUrl2=a.productImgUrl,productImgUrl=case when d.PlatId<>2 and a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc,GoodsFee=a.GoodsFee+isnull(a.GoodsRate,0)*0.01*a.GoodsFee,a.TCFee,GoodsPrice=case when f.Price is not null and f.Price>0 then f.Price+isnull(f.PostPrice,0) else b.InPrice end,b.Solid2,BGPrice=b.FeeRate,JoinOrderCode=e.RevFax,Weight=isnull(b.Weight2,0),PostionCode=cast(isnull(b.GoodsHJNum11,0) as nvarchar(10)) from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on a.OrderId=e.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.*,c.InPrice,Solid2=c.Solid,FeeRate=isnull(c.FeeRate,0),c.Weight2 from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId left join (select OrderGoodsId,Price=MAX(price),PostPrice=MAX(PostPrice) from HW_GoodsInDetail where OrderGoodsId>0 group by OrderGoodsId) f on a.Id=f.OrderGoodsId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListNew2_New(string OrderIds) { //BGPrice 作 货物税费 //GoodsFee=a.GoodsFee+isnull(a.GoodsRate,0)*0.01*a.GoodsFee 货物税费加上去 List list = null; string tsql = @" select z.*,u.Name as mname,u.GroupName from ( select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=b.TypeDesc,CKGoodsNum=isnull(b.WestNum,0),SpareNum=isnull(b.EastNum,0),GoodsInNum=isnull(b.GoodsInNum,0),GoodsInNum2=isnull(b.GoodsHJNum14,0),ChaseId=isnull(b.GoodsHJNum15,0),GoodsInNum3=isnull(b.GoodsInNum,0),GoodsLeftNum=isnull(b.WestNum,0)+isnull(b.EastNum,0)+isnull(b.GoodsHJNum14,0)+isnull(b.GoodsHJNum15,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,d.PlatId,productImgUrl2=a.productImgUrl,productImgUrl=case when d.PlatId<>2 and a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc,GoodsFee=a.GoodsFee+isnull(a.GoodsRate,0)*0.01*a.GoodsFee,a.TCFee,GoodsPrice=case when f.Price is not null and f.Price>0 then f.Price+isnull(f.PostPrice,0) else b.InPrice end,b.Solid2,BGPrice=b.FeeRate,JoinOrderCode=e.RevFax,Weight=isnull(b.Weight2,0),PostionCode=cast(isnull(b.GoodsHJNum11,0) as nvarchar(10)),a.adfee,case when d.PlatId=2 then b.muserid when d.PlatId=3 then b.guserid_ebay when d.PlatId=6 then b.guserid_wlmart when d.PlatId=15 then b.guserid_shopify when d.PlatId=18 then b.guserid_wayfair when d.PlatId=21 then b.guserid_sheIn when d.PlatId=22 then b.guserid_tiktok when d.Platid=23 then b.guserid_temu end muserid ,b.WestNum,b.EastNum from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on a.OrderId=e.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.*,c.InPrice,Solid2=c.Solid,FeeRate=isnull(c.FeeRate,0),c.Weight2,c.muserid,c.guserid_wlmart,c.guserid_shopify,c.guserid_ebay,c.guserid_wayfair,c.guserid_sheIn ,c.guserid_tiktok,c.guserid_temu from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId left join (select OrderGoodsId,Price=MAX(price),PostPrice=MAX(PostPrice) from HW_GoodsInDetail where OrderGoodsId>0 group by OrderGoodsId) f on a.Id=f.OrderGoodsId where a.OrderId in (" + OrderIds + ")) z left join JC_UserInfo u on z.muserid=u.UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsListNew4(string OrderIds) { //BGPrice 作 货物税费 //GoodsFee=a.GoodsFee+isnull(a.GoodsRate,0)*0.01*a.GoodsFee 货物税费加上去 List list = null; string tsql = @" select a.Id,a.OrderId,a.DetailId,a.GoodsNum,a.RMBMoney,a.MoneyCode,LockNum=case when d.matestate=2 then a.GoodsNum else 0 end,a.PostInfo,GoodsName=case when b.DetailId is not null then b.GoodsName else a.GoodsName end, GoodsSKU=b.TypeDesc,CKGoodsNum=isnull(b.WestNum,0),SpareNum=isnull(b.EastNum,0),GoodsInNum=isnull(b.GoodsInNum,0),GoodsInNum2=isnull(b.GoodsHJNum14,0),ChaseId=isnull(b.GoodsHJNum15,0),GoodsInNum3=isnull(b.GoodsInNum,0),GoodsLeftNum=isnull(b.WestNum,0)+isnull(b.EastNum,0)+isnull(b.GoodsHJNum14,0)+isnull(b.GoodsHJNum15,0)-isnull(b.GoodsPlanNum,0), OutNum=case when d.State=2 then a.GoodsNum else 0 end,d.PlatId,productImgUrl2=a.productImgUrl,productImgUrl=case when d.PlatId<>2 and a.productImgUrl is not null and a.productImgUrl<>'' then a.productImgUrl when b.FirstImgUrl is not null and b.FirstImgUrl<>'' then b.FirstImgUrl else b.ImgUrl end,a.GoodsDesc,b.GoodsCode,b.GoodsOldCode,b.GoodsId,b.TypeCode,b.TypeDesc,a.OldTypeCode,a.OldTypeDesc,GoodsFee=a.GoodsFee+isnull(a.GoodsRate,0)*0.01*a.GoodsFee,a.TCFee,GoodsPrice=b.InPrice,b.Solid2,BGPrice=b.FeeRate,JoinOrderCode=e.RevFax,Weight=isnull(b.Weight2,0),PostionCode=cast(isnull(b.GoodsHJNum11,0) as nvarchar(10)) from DT_OrderGoods a inner join DT_OrderInfo d on a.OrderId=d.OrderId inner join DT_OrderXXInfo e on a.OrderId=e.OrderId left join (select c.GoodsName,c.GoodsCode,c.GoodsOldCode,ImgUrl=c.FirstImgUrl,d.*,c.InPrice,Solid2=c.Solid,FeeRate=isnull(c.FeeRate,0),c.Weight2 from HW_GoodsInfo c inner join HW_GoodsDetail d on c.GoodsId=d.GoodsId)b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderIds", DbType.String, OrderIds); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询订单明细匹配 public static List GetOrderGoodsCodeData() { //BGPrice 作 货物税费 List list = null; string tsql = @"select * from [DD_GoodsCodeData] with(nolock) where id in ( select id=MAX(id) from [DD_GoodsCodeData] with(nolock) where Int3>0 group by ShopId,GoodsId,asin) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 修改数量 public static void UpdateGoodsOutNum() { string tsql = @" update HW_GoodsDetail set GoodsHJNum=0 where GoodsHJNum is null update HW_GoodsDetail set GoodsHJNum2=0 where GoodsHJNum2 is null --累计销量 update a set a.GoodsHJNum=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State<3 group by b.DetailId)b on a.DetailId=b.DetailId --最近30天销量 update a set a.GoodsHJNum2=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 group by b.DetailId)b on a.DetailId=b.DetailId --W仓最近30天销量 update a set a.GoodsHJNum12=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where c.StoreId in (6,9) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 group by b.DetailId)b on a.DetailId=b.DetailId --E仓最近30天销量 update a set a.GoodsHJNum13=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where c.StoreId=11 and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 group by b.DetailId)b on a.DetailId=b.DetailId --最近10天销量 update a set a.GoodsHJNum3=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=10 group by b.DetailId)b on a.DetailId=b.DetailId --最近20天销量 update a set a.GoodsHJNum4=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=20 group by b.DetailId)b on a.DetailId=b.DetailId --最近10天销量东部 update a set a.GoodsHJNum5=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId=11 and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=10 group by b.DetailId)b on a.DetailId=b.DetailId --最近20天销量东部 update a set a.GoodsHJNum6=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId=11 and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=20 group by b.DetailId)b on a.DetailId=b.DetailId --最近30天销量东部 update a set a.GoodsHJNum7=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId=11 and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 group by b.DetailId)b on a.DetailId=b.DetailId --最近10天销量西部 update a set a.GoodsHJNum8=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId in (6,9) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=10 group by b.DetailId)b on a.DetailId=b.DetailId --最近20天销量西部 update a set a.GoodsHJNum9=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId in (6,9) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=20 group by b.DetailId)b on a.DetailId=b.DetailId --最近30天销量西部 update a set a.GoodsHJNum10=b.Num from HW_GoodsDetail a inner join ( select b.DetailId,Num=sum(b.GoodsNum) from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId in (6,9) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())<=30 group by b.DetailId)b on a.DetailId=b.DetailId update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsPlanNum<>b.GoodsNum --E订单需求 update a set a.GoodsPlanNumE=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId where c.StoreId=11 and a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsPlanNumE<>b.GoodsNum --W订单需求 update a set a.GoodsPlanNumW=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId where c.StoreId=6 and a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsPlanNumW<>b.GoodsNum --东西库存 update a set a.WestNum=b.Num from HW_GoodsDetail a inner join (select DetailId,Num=sum(KCNum) from HW_GoodsInDetail where KCNum>0 and CKDetailId=0 and StoreId in (6,9,18) group by DetailId)b on a.DetailId=b.DetailId update a set a.EastNum=b.Num from HW_GoodsDetail a inner join (select DetailId,Num=sum(KCNum) from HW_GoodsInDetail where KCNum>0 and CKDetailId=0 and StoreId=11 group by DetailId)b on a.DetailId=b.DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 刷新库存 public static void UpdateGoodsNumNew(int GoodsId) { string tsql = @" --调整库存 --update HW_GoodsDetail set GoodsNum=0,GoodsInNum=0,GoodsPlanNum=0,GoodsInNum2=0 update CG_PurchaseGoods set InGoodsNum=GoodsNum where InGoodsNum>GoodsNum update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsPlanNum<>b.GoodsNum update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetail a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsNum<>b.GoodsNum --海外仓 update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join (select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsNum<>b.GoodsNum update a set a.GoodsInNum=b.GoodsNum-ISNULL(c.OutInNum,0) from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.GoodsNum-isnull(b.InGoodsNum,0)-isnull(b.BackNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId where a.IsDelete=0 and isnull(IsGJ,0)=0 and isnull(a.IsFactory,0)=0 and isnull(a.IsBH,0)=0 and a.State<3 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId left join ( select a.GoodsDetailId,SJOutNum=SUM(SJOutNum),OutInNum=SUM(OutInNum) from CG_PurchaseGoods a where OldId>0 group by a.GoodsDetailId)c on b.GoodsDetailId=c.GoodsDetailId where a.GoodsInNum<>b.GoodsNum-ISNULL(c.SJOutNum,0) --海外在途 update a set a.GoodsInNum2=b.GoodsNum+ISNULL(lnum,0) from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.SJOutNum-isnull(b.OutInNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId where isnull(b.OutInNum,0)<=b.SJOutNum and a.IsDelete=0 and isnull(IsGJ,0)=1 and OldId is null group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId left join ( select a.GoodsDetailId,SJOutNum=SUM(SJOutNum),OutInNum=SUM(OutInNum),lnum=SUM(SJOutNum)-SUM(OutInNum) from CG_PurchaseGoods a where OldId>0 group by a.GoodsDetailId)c on b.GoodsDetailId=c.GoodsDetailId where isnull(a.GoodsInNum2,0)<>b.GoodsNum+ISNULL(lnum,0) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 刷新库存 public static void UpdateGoodsNumNew2(int GoodsId) { string tsql = @" update HW_GoodsDetail set GoodsNum=0,GoodsInNum=0,GoodsPlanNum=0,GoodsInNum2=0,GoodsHJNum11=0 where GoodsId=@GoodsId --调整库存 update CG_PurchaseGoods set InGoodsNum=GoodsNum where InGoodsNum>GoodsNum update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsId=@GoodsId and a.GoodsPlanNum<>b.GoodsNum update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetail a where isnull(CKDetailId,0)=0 and a.StoreId in (6,9) group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsId=@GoodsId and a.GoodsNum<>b.GoodsNum --海外仓 update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join (select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId where a.GoodsId=@GoodsId and a.GoodsNum<>b.GoodsNum update a set a.TJOutNum2=a.SJOutNum+b.OutNum from CG_PurchaseGoods a inner join ( select OldId,OutNum=SUM(isnull(SJOutNum,0)) from CG_PurchaseGoods group by OldId)b on a.id=b.oldid update CG_PurchaseGoods set OutNum=TJOutNum2 where OutNum0 and TJOutNum>0 update CG_PurchaseGoods set OutNum=TJOutNum2 where OutNum0 and TJOutNum2>0 --海外在途 update a set a.GoodsInNum2=b.GoodsNum+ISNULL(lnum,0) from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.SJOutNum-isnull(b.OutInNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId where isnull(b.OutInNum,0)<=b.SJOutNum and a.IsDelete=0 and isnull(IsGJ,0)=1 and OldId is null group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId left join ( select a.GoodsDetailId,SJOutNum=SUM(SJOutNum),OutInNum=SUM(OutInNum),lnum=SUM(SJOutNum)-SUM(OutInNum) from CG_PurchaseGoods a where OldId>0 group by a.GoodsDetailId)c on b.GoodsDetailId=c.GoodsDetailId where a.GoodsId=@GoodsId and isnull(a.GoodsInNum2,0)<>b.GoodsNum+ISNULL(lnum,0) --生产中 update a set a.GoodsInNum=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.GoodsNum-ISNULL(b.TJOutNum,0)-ISNULL(b.InGoodsNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId where a.IsDelete=0 and a.State<3 and a.GoodsState<2 and a.ChaseId>0 and b.GoodsNum-ISNULL(b.TJOutNum,0)-ISNULL(b.InGoodsNum,0)>0 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId where b.GoodsNum>0 and a.GoodsId=@GoodsId --国内未设置发到海外 update a set a.GoodsHJNum11=b.Num from HW_GoodsDetail a inner join ( select DetailId,Num=SUM(KCNum) from HW_GoodsInDetail where StoreId=8 and OrderGoodsId=0 and KCNum>0 group by DetailId)b on a.DetailId=b.DetailId where a.GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); } #endregion #region 刷新库存 public static void UpdateGoodsNumNew33(int ChaseId) { string tsql = @" --update HW_GoodsDetail set GoodsNum=0,GoodsInNum=0,GoodsPlanNum=0,GoodsInNum2=0,GoodsHJNum11=0 where GoodsId=@GoodsId --调整库存 --declare @ChaseId int --set @ChaseId=1 update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods c ON a.DetailId=c.GoodsDetailId where c.ChaseId=@ChaseId and a.GoodsPlanNum<>b.GoodsNum update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetail a where isnull(CKDetailId,0)=0 and a.StoreId in (6,9) group by a.DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods c ON a.DetailId=c.GoodsDetailId where c.ChaseId=@ChaseId and a.GoodsNum<>b.GoodsNum --海外仓 update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join (select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods c ON a.DetailId=c.GoodsDetailId where c.ChaseId=@ChaseId and a.GoodsNum<>b.GoodsNum update a set a.TJOutNum2=a.SJOutNum+b.OutNum from CG_PurchaseGoods a inner join ( select OldId,OutNum=SUM(isnull(SJOutNum,0)) from CG_PurchaseGoods group by OldId)b on a.id=b.oldid WHERE a.ChaseId=@ChaseId --update CG_PurchaseGoods set OutNum=TJOutNum2 where OutNum0 and TJOutNum>0 --update CG_PurchaseGoods set OutNum=TJOutNum2 where OutNum0 and TJOutNum2>0 --海外在途 update a set a.GoodsInNum2=b.GoodsNum+ISNULL(lnum,0) from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.SJOutNum-isnull(b.OutInNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId where isnull(b.OutInNum,0)<=b.SJOutNum and a.IsDelete=0 and isnull(IsGJ,0)=1 and OldId is null group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId inner JOIN CG_PurchaseGoods d ON a.DetailId=d.GoodsDetailId left join ( select a.GoodsDetailId,SJOutNum=SUM(SJOutNum),OutInNum=SUM(OutInNum),lnum=SUM(SJOutNum)-SUM(OutInNum) from CG_PurchaseGoods a where OldId>0 group by a.GoodsDetailId)c on b.GoodsDetailId=c.GoodsDetailId where d.ChaseId=@ChaseId and isnull(a.GoodsInNum2,0)<>b.GoodsNum+ISNULL(lnum,0) --生产中 update a set a.GoodsInNum=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.GoodsNum-ISNULL(b.TJOutNum,0)-ISNULL(b.InGoodsNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId where a.IsDelete=0 and a.State<3 and a.GoodsState<2 and a.ChaseId>0 and b.GoodsNum-ISNULL(b.TJOutNum,0)-ISNULL(b.InGoodsNum,0)>0 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId where b.GoodsNum>0 and a.GoodsId=@GoodsId --国内未设置发到海外 update a set a.GoodsHJNum11=b.Num from HW_GoodsDetail a inner join ( select DetailId,Num=SUM(KCNum) from HW_GoodsInDetail where StoreId=8 and OrderGoodsId=0 and KCNum>0 group by DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods d ON a.DetailId=d.GoodsDetailId where d.ChaseId=@ChaseId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); db.ExecuteNonQuery(cmd); } #endregion #region 刷新库存 public static void UpdateGoodsNumNew4(int ChaseId) { string tsql = @" --update HW_GoodsDetail set GoodsNum=0,GoodsInNum=0,GoodsPlanNum=0,GoodsInNum2=0,GoodsHJNum11=0 where GoodsId=@GoodsId --调整库存 --declare @ChaseId int --set @ChaseId=1 update a set a.GoodsPlanNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId where a.DetailId>0 and b.State=1 and b.PrintState=0 group by a.DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods c ON a.DetailId=c.GoodsDetailId where c.ChaseId=@ChaseId and a.GoodsPlanNum<>b.GoodsNum update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join ( select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetail a where isnull(CKDetailId,0)=0 and a.StoreId in (6,9) group by a.DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods c ON a.DetailId=c.GoodsDetailId where c.ChaseId=@ChaseId and a.GoodsNum<>b.GoodsNum --海外仓 update a set a.GoodsNum=b.GoodsNum from HW_GoodsDetail a inner join (select a.DetailId,GoodsNum=SUM(a.KCNum) from HW_GoodsInDetailHWC a where isnull(CKDetailId,0)=0 group by a.DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods c ON a.DetailId=c.GoodsDetailId where c.ChaseId=@ChaseId and a.GoodsNum<>b.GoodsNum update a set a.TJOutNum2=a.SJOutNum+b.OutNum from CG_PurchaseGoods a inner join ( select OldId,OutNum=SUM(isnull(SJOutNum,0)) from CG_PurchaseGoods group by OldId)b on a.id=b.oldid WHERE a.ChaseId=@ChaseId --update CG_PurchaseGoods set OutNum=TJOutNum2 where OutNum0 and TJOutNum>0 --update CG_PurchaseGoods set OutNum=TJOutNum2 where OutNum0 and TJOutNum2>0 --海外在途 update a set a.GoodsInNum2=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.SJOutNum-isnull(b.OutInNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId where a.ChaseId=1 and isnull(b.OutInNum,0)<=b.SJOutNum and a.IsDelete=0 and isnull(IsGJ,0)=1 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId --生产中 update a set a.GoodsInNum=b.GoodsNum from HW_GoodsDetail a inner join ( select b.GoodsDetailId,GoodsNum=SUM(b.GoodsNum-ISNULL(b.TJOutNum,0)-ISNULL(b.InGoodsNum,0)) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId where a.IsDelete=0 and a.ChaseId=@ChaseId and b.GoodsNum-ISNULL(b.TJOutNum,0)-ISNULL(b.InGoodsNum,0)>0 group by b.GoodsDetailId)b on a.DetailId=b.GoodsDetailId where b.GoodsNum>0 --国内未设置发到海外 update a set a.GoodsHJNum11=b.Num from HW_GoodsDetail a inner join ( select DetailId,Num=SUM(KCNum) from HW_GoodsInDetail where StoreId=8 and OrderGoodsId=0 and KCNum>0 group by DetailId)b on a.DetailId=b.DetailId inner JOIN CG_PurchaseGoods d ON a.DetailId=d.GoodsDetailId where d.ChaseId=@ChaseId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); db.ExecuteNonQuery(cmd); } #endregion #region 自动申请跟踪码 public static string UpdateOrderNum() { string tsql = @" update a set a.GoodsNum=b.GoodsNum from DT_OrderInfo a inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods group by OrderId)b on a.OrderId=b.OrderId where datediff(day,a.InDate,getdate())<=2 and a.GoodsNum<>b.GoodsNum"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); return ""; } #endregion #region 自动申请跟踪码 public static DT_OrderExpressModelNew GetAutoCode(int PostType) { try { string tsql = ""; if (PostType == 1)//FedexSMART_POST(业远) 三种里面如果最便宜是S, 就用S tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)=0 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and datediff(day,a.InDate,getdate())<=3 and ((a.Fee6>0 and a.Fee60 and a.Fee110 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and datediff(day,a.InDate,getdate())<=3 and ((a.Fee6>0 and a.Fee60 and a.Fee110 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and datediff(day,a.InDate,getdate())<=3 and ((a.Fee7>0 and a.Fee6>a.Fee7) or (a.Fee12>0 and a.Fee11>a.Fee12)) and (c.RevFax='COMMERCIAL' or c.RevFax='OFFICE')"; if (PostType == 4)//Fedex_GROUND(业远) 超过70L, 就用GROUND tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)=0 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(e.Weight2,0)*0.0625>=70 and isnull(c.TrackState,0)=0 and datediff(day,a.InDate,getdate())<=3"; if (PostType == 5)//Fedex_HOME_DELIVERY(业远) 如果是RESIDENTIAL, smart 贵, 就走home devlivery, tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)=0 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and datediff(day,a.InDate,getdate())<=3 and ((a.Fee8 >0 and a.Fee6>a.Fee8) or (a.Fee13 >0 and a.Fee11>a.Fee13)) and c.RevFax='Residential'"; DT_OrderExpressModelNew model = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } catch (Exception exception) { ErrorFollow.TraceWrite("GetAutoCode", "", exception.Message); return null; } } #endregion #region 自动申请跟踪码 public static DT_OrderExpressModelNew GetAutoCodeNew(int PostType, int StoreId) { try { string tsql = ""; if (StoreId == 6) { if (PostType == 1)//FedexSMART_POST(业远) 三种里面如果最便宜是S, 就用S tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId,k.sendname,a.PlatId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join jc_shop k with(nolock) on a.shopid=k.shopid inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where c.storeid in (6,16) and isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)<>1 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee6>0 and a.Fee61 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee6>0 and a.Fee61 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee7>0 and a.Fee6>a.Fee7 and (c.RevFax='COMMERCIAL' or c.RevFax='OFFICE') order by isnull(c.IsAutoTrack,0) desc"; if (PostType == 4)//Fedex_GROUND(业远) 超过70L, 就用GROUND tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId,k.sendname,a.PlatId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join jc_shop k with(nolock) on a.shopid=k.shopid inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where c.storeid in (6,16) and isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)<>1 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(e.Weight2,0)*0.0625>=70 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) order by isnull(c.IsAutoTrack,0) desc"; if (PostType == 5)//Fedex_HOME_DELIVERY(业远) 如果是RESIDENTIAL, smart 贵, 就走home devlivery, tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId,k.sendname,a.PlatId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join jc_shop k with(nolock) on a.shopid=k.shopid inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where c.storeid in (6,16) and isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)<>1 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee8 >0 and a.Fee6>a.Fee8 and c.RevFax='Residential' order by isnull(c.IsAutoTrack,0) desc"; } else { if (PostType == 1)//FedexSMART_POST(业远) 三种里面如果最便宜是S, 就用S tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId,k.sendname,a.PlatId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join jc_shop k with(nolock) on a.shopid=k.shopid inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where c.storeid=11 and isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)<>1 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee11>0 and a.Fee111 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee11>0 and a.Fee111 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee12>0 and a.Fee11>a.Fee12 and (c.RevFax='COMMERCIAL' or c.RevFax='OFFICE') order by isnull(c.IsAutoTrack,0) desc"; if (PostType == 4)//Fedex_GROUND(业远) 超过70L, 就用GROUND tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId,k.sendname,a.PlatId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join jc_shop k with(nolock) on a.shopid=k.shopid inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where c.storeid=11 and isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)<>1 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(e.Weight2,0)*0.0625>=70 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) order by isnull(c.IsAutoTrack,0) desc"; if (PostType == 5)//Fedex_HOME_DELIVERY(业远) 如果是RESIDENTIAL, smart 贵, 就走home devlivery, tsql = @" select top 1 SKU=d.SKU1,c.RevFax,Weight=e.Weight2,e.Long2,e.Weight2,e.Height2,e.Width2,b.GoodsNum,a.OrderId,a.PlatOrderCode,c.RevCountry,c.RevProvince,c.RevCity,c.RevArea,c.RevAddr,c.RevPhone,c.RevMoblie,c.RevName,c.RevPostCode,c.StoreId,k.sendname,a.PlatId from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId inner join jc_shop k with(nolock) on a.shopid=k.shopid inner join ( select OrderId,GoodsNum=SUM(GoodsNum) from DT_OrderGoods with(nolock) group by OrderId)g on a.OrderId=g.OrderId where c.storeid=11 and isnull(a.IsJoin,0)=0 and isnull(c.IsAutoTrack,0)<>1 and a.MateState>0 and a.PostState=0 and a.CompanyId=1 and g.GoodsNum=1 and e.Weight2>0 and e.Long2>0 and e.Width2>0 and e.Height2>0 and isnull(c.TrackState,0)=0 and (c.IsAutoTrack=2 or datediff(day,a.InDate,getdate())<=3) and a.Fee13 >0 and a.Fee11>a.Fee13 and c.RevFax='Residential' order by isnull(c.IsAutoTrack,0) desc"; } DT_OrderExpressModelNew model = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } catch (Exception exception) { ErrorFollow.TraceWrite("GetAutoCode", "", exception.Message); return null; } } #endregion #region 自动申请跟踪码 public static string GetAutoCode2() { string tsql = @" select top 1 a.fee6,a.fee7,a.fee8,a.FeeLog,c.RevFax,e.Weight,isnull(e.Weight,0)*0.0022046,a.InDate from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId where a.CompanyId=1 and a.GoodsNum=1 and isnull(c.TrackState,0)=0 and datediff(day,a.InDate,getdate())<=2 and a.Fee6='2019-05-20' and a.Fee6>a.Fee8 and a.PlatId=2 and c.RevFax='Residential' select a.fee6,a.fee7,a.fee8,a.FeeLog,c.RevFax,e.Weight,isnull(e.Weight,0)*0.0022046 from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId where a.CompanyId=1 and a.GoodsNum=1 and a.InDate>='2019-05-20' and a.Fee6>a.Fee7 and a.PlatId=2 and (c.RevFax='COMMERCIAL' or c.RevFax='OFFICE') select a.fee6,a.fee7,a.fee8,a.FeeLog,c.RevFax,e.Weight from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail d with(nolock) on b.DetailId=d.DetailId inner join HW_GoodsInfo e with(nolock) on d.GoodsId=e.GoodsId inner join DT_OrderXXInfo c with(nolock) on a.OrderId=c.OrderId where a.CompanyId=1 and a.GoodsNum=1 and a.InDate>='2019-05-20' and a.Fee6 GetListDT_PrintOrderInfoForTM2(int CompanyId, string TrackCode, string GoodsName, int IsWeight, string Code, string PostionCode, int IsSku, int GM, int PrintState, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select distinct OrderId into #printlist from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%')"; if (GoodsName != "" && Code != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsCode='" + GoodsName + "' or c.GoodsOldCode='" + GoodsName + "') and b.TypeCode='" + Code + "'"; if (sql1 == "" && PostionCode != "") { if (PrintState == 0) sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where CKDetailId=0 and c.PostionCode like '" + PostionCode + "%'"; else sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%'"; } else if (sql1 != "" && PostionCode != "") { if (PrintState == 0) sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where CKDetailId=0 and c.PostionCode like '" + PostionCode + "%'"; else { sql1 += @" delete from #printlist where orderid not in ( select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%') "; } } if (GM == 1) { if (sql1 != "") { sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where OldTypeCode is not null and OldTypeCode<>'' and a.OrderId not in (select OrderId from #printlist) "; } else { sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where OldTypeCode is not null and OldTypeCode<>''"; } } else if (GM == 0) { if (sql1 != "") { sql1 += @" insert into #printlist select distinct a.OrderId from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where (OldTypeCode is null or OldTypeCode='') and a.OrderId not in (select OrderId from #printlist) "; } else { sql1 = @" select distinct a.OrderId into #printlist from DT_OrderGoods a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where (OldTypeCode is null or OldTypeCode='')"; } } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.PrintDate,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo,ErrorInfo='',b.OrderState,b.FeeType,b.Post,TrackCode='', b.LogisticsId,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.RevPostCode,b.PostError,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare"; if (sql1 != "") ser.Tables = @"DT_OrderInfoNew a with (nolock) inner join #printlist d on a.OrderId=d.OrderId inner join DT_OrderXXInfoNew b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfoNew a with (nolock) inner join DT_OrderXXInfoNew b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = 1; ser.PageSize = 3000; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListDT_PrintOrderInfoForTM(int CompanyId, string TrackCode, string GoodsName, int IsWeight, string Code, string PostionCode, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (TrackCode != "") { sql1 = @"select OrderId into #printlist from DT_TrackCodeApply where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%')"; if (GoodsName != "" && Code != "") sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where (c.GoodsCode='" + GoodsName + "' or c.GoodsOldCode='" + GoodsName + "') and b.TypeCode='" + Code + "'"; if (sql1 == "" && PostionCode != "") { sql1 = @"select distinct a.OrderId into #printlist from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%'"; } else if (sql1 != "" && PostionCode != "") { sql1 += @" delete from #printlist where orderid not in ( select distinct a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsInDetail b with (nolock) on a.Id=b.OrderGoodsId inner join CK_StorePostion c with (nolock) on b.PostionId=c.PostionId where c.PostionCode like '" + PostionCode + "%') "; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.PrintState,PrintStateName=case when a.PrintState=1 then '已打印' else '未打印' end,a.PrintDate,a.MateState,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.SendInfo,ErrorInfo='',b.OrderState,b.FeeType,b.Post,TrackCode='', b.LogisticsId,ShopName=c.ShopName,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,b.RevProvince,b.RevCity,b.RevArea,b.PostError,b.RevPostCode,b.CountryCode,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,b.SendAddr,TrackStateName=case when b.TrackState=1 then '已上传' else '未上传' end,b.TrackState,a.IsSpare"; if (sql1 != "") ser.Tables = @"DT_OrderInfo a with (nolock) inner join #printlist d on a.OrderId=d.OrderId inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 读取主管店铺 public static List GetShopListFPage(int UserId, int PlatType, string UserType) { string tsql = @" select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where ShopId IN (SELECT ShopId from JC_ShopUser WHERE SType='M' and UserId=@UserId) and (@PlatType=0 or PlatType=@PlatType) order by PlatType "; if (UserType == "M" || UserType == "S") tsql = @" if(select count(0) from JC_Shop where CompanyId=1 and (PlatType=2 or PlatType=6))>4 begin select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where CompanyId=1 and (PlatType=2 or PlatType=6) and (@PlatType=0 or PlatType=@PlatType) order by PlatType end else begin select ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade from JC_Shop where CompanyId=1 and (@PlatType=0 or PlatType=@PlatType) order by PlatType end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取库存 public static List GetKCNumList(int StoreId, string SKU) { string tsql = @" select c.GoodsCode,b.SKU1,GoodsNum=a.Num,c.Solid,TotalSolid=isnull(c.Solid,0)*a.Num,c.FirstImgUrl,a.DetailId from ( select a.DetailId,Num=SUM(a.KCNum) from HW_GoodsInDetail a where a.OrderGoodsId=0 and a.KCNum>0 and a.StoreId=@StoreId group by a.DetailId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=1 and (@SKU='' or b.SKU1 like '%'+@SKU+'%') order by b.SKU1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取库存 public static List GetStoreList() { string tsql = @" select * from CK_StoreHouse where IsUse=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 保存货物 /// /// 保存货物 /// public static int SaveGoodsInfoForTM(HW_Goods Model) { string tsql = @" if @GoodsId>0 begin Update [HW_GoodsInfo] set GoodsOldCode=@GoodsOldCode,[SupplierId]=@SupplierId,Supplier=@Supplier,[GoodsName]=@GoodsName,[GoodsEnglisgName]=@GoodsEnglisgName,[GoodsNum]=@GoodsNum,[GoodsLockNum]=@GoodsLockNum,[InPrice]=@InPrice,[NowPrice]=@NowPrice,[Weight]=@Weight,[Weight2]=@Weight2,[WeightUnit]=@WeightUnit,[Solid]=@Solid,[SolidUnit]=@SolidUnit,[Position]=@Position,[UpdateDate]=@UpdateDate,[FirstImgUrl]=@FirstImgUrl,[GoodsImageIds]=@GoodsImageIds,[CompanyId]=@CompanyId,[GoodsPlanNum]=@GoodsPlanNum,[GoodsOutNum]=@GoodsOutNum,[GoodsInNum]=@GoodsInNum,[SafeNum]=@SafeNum,[HGCode]=@HGCode,[HGCompanyCode]=@HGCompanyCode,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[AvgTime]=@AvgTime,[State]=@State,[DeptRemark]=@DeptRemark,[NoticeDays]=@NoticeDays,[GoodsInfo]=@GoodsInfo,[DefaultCity]=@DefaultCity,[PageFee]=@PageFee,[PostPrice]=@PostPrice,GoodsSupplyCode=@GoodsSupplyCode,BGPrice=@BGPrice,NoticeShop=@NoticeShop,[NetWeight]=@NetWeight,[Long]=@Long,[Width]=@Width,[Height]=@Height,[Long2]=@Long2,[Width2]=@Width2,[Height2]=@Height2,[BoxRate]=@BoxRate,Cert=@Cert,FeeRate=@FeeRate,JYPrice=@JYPrice where GoodsId=@GoodsId end else begin --select @GoodsNo=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId=@SortId INSERT INTO [HW_GoodsInfo]([GoodsCode],[GoodsEg],[GoodsNo],[GoodsOldCode],[SortId],[SortName],[SupplierId],[GoodsName],[GoodsEnglisgName],[GoodsNum],[GoodsLockNum],[InPrice],[NowPrice],[Weight],[WeightUnit],[Solid],[SolidUnit],[Position],[InDate],[UpdateDate],[FirstImgUrl],[GoodsImageIds],[CompanyId],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[SafeNum],[HGCode],[HGCompanyCode],[UpdateName],[GoodsRemark],[AutoPlan],[NoGoods],[AvgTime],[State],[DeptRemark],[NoticeDays],[GoodsInfo],[DefaultCity],[PageFee],[PostPrice],GoodsSupplyCode,BGPrice,NoticeShop,[NetWeight],[Long],[Width],[Height],[BoxRate],Cert,FeeRate,JYPrice)values(@GoodsCode,@GoodsEg,@GoodsNo,@GoodsOldCode,@SortId,@SortName,@SupplierId,@GoodsName,@GoodsEnglisgName,@GoodsNum,@GoodsLockNum,@InPrice,@NowPrice,@Weight,@WeightUnit,@Solid,@SolidUnit,@Position,@InDate,@UpdateDate,@FirstImgUrl,@GoodsImageIds,@CompanyId,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@SafeNum,@HGCode,@HGCompanyCode,@UpdateName,@GoodsRemark,@AutoPlan,@NoGoods,@AvgTime,@State,@DeptRemark,@NoticeDays,@GoodsInfo,@DefaultCity,@PageFee,@PostPrice,@GoodsSupplyCode,@BGPrice,@NoticeShop,@NetWeight,@Long,@Width,@Height,@BoxRate,@Cert,@FeeRate,@JYPrice) set @GoodsId=SCOPE_IDENTITY() update XP_GoodsSelect set GoodsCode=@GoodsCode,IsAdd=1 where Id=@XPId INSERT INTO [HW_GoodsCode]([EnglishCode],[GoodsNo]) values(@GoodsEg,@GoodsNo) end select @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsOldCode", DbType.String, Model.GoodsOldCode); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@SupplierId", DbType.String, Model.SupplierId); db.AddInParameter(cmd, "@Supplier", DbType.Int32, Model.Supplier); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, Model.GoodsEnglisgName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, Model.InPrice); db.AddInParameter(cmd, "@NowPrice", DbType.Decimal, Model.NowPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, Model.Weight2); db.AddInParameter(cmd, "@WeightUnit", DbType.String, Model.WeightUnit); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@SolidUnit", DbType.String, Model.SolidUnit); db.AddInParameter(cmd, "@Position", DbType.Int32, Model.Position); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@HGCode", DbType.String, Model.HGCode); db.AddInParameter(cmd, "@HGCompanyCode", DbType.String, Model.HGCompanyCode); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@NoticeDays", DbType.Int32, Model.NoticeDays); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, Model.GoodsInfo); db.AddInParameter(cmd, "@DefaultCity", DbType.String, Model.DefaultCity); db.AddInParameter(cmd, "@PageFee", DbType.Decimal, Model.PageFee); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@GoodsSupplyCode", DbType.String, Model.GoodsSupplyCode); db.AddInParameter(cmd, "@BGPrice", DbType.Decimal, Model.BGPrice); db.AddInParameter(cmd, "@NoticeShop", DbType.String, Model.NoticeShop); db.AddInParameter(cmd, "@XPId", DbType.Int32, Model.XPId); db.AddInParameter(cmd, "@NetWeight", DbType.Decimal, Model.NetWeight); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@Long2", DbType.Decimal, Model.Long2); db.AddInParameter(cmd, "@Width2", DbType.Decimal, Model.Width2); db.AddInParameter(cmd, "@Height2", DbType.Decimal, Model.Height2); db.AddInParameter(cmd, "@BoxRate", DbType.Int32, Model.BoxRate); db.AddInParameter(cmd, "@Cert", DbType.String, Model.Cert); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@JYPrice", DbType.Decimal, Model.JYPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物 /// /// 保存货物 /// public static int SaveGoodsInfoForTMNew(HW_GoodsNew Model) { string tsql = @" if @GoodsId>0 begin Update [HW_GoodsInfo] set GoodsOldCode=@GoodsOldCode,SortId=@SortId,SortId1=@SortId1,SortId2=@SortId2,[SupplierId]=@SupplierId,Supplier=@Supplier,[GoodsName]=@GoodsName,[GoodsEnglisgName]=@GoodsEnglisgName,[GoodsNum]=@GoodsNum,[GoodsLockNum]=@GoodsLockNum,[InPrice]=@InPrice,[NowPrice]=@NowPrice,[Weight]=@Weight,[Weight2]=@Weight2,[WeightUnit]=@WeightUnit,[Solid]=@Solid,[SolidUnit]=@SolidUnit,[Position]=@Position,[UpdateDate]=@UpdateDate,[FirstImgUrl]=@FirstImgUrl,[GoodsImageIds]=@GoodsImageIds,[CompanyId]=@CompanyId,[GoodsPlanNum]=@GoodsPlanNum,[GoodsOutNum]=@GoodsOutNum,[GoodsInNum]=@GoodsInNum,[SafeNum]=@SafeNum,[HGCode]=@HGCode,[HGCompanyCode]=@HGCompanyCode,[UpdateName]=@UpdateName,[GoodsRemark]=@GoodsRemark,[AutoPlan]=@AutoPlan,[NoGoods]=@NoGoods,[AvgTime]=@AvgTime,[State]=@State,[DeptRemark]=@DeptRemark,[NoticeDays]=@NoticeDays,[GoodsInfo]=@GoodsInfo,[DefaultCity]=@DefaultCity,[PageFee]=@PageFee,[PostPrice]=@PostPrice,GoodsSupplyCode=@GoodsSupplyCode,BGPrice=@BGPrice,NoticeShop=@NoticeShop,[NetWeight]=@NetWeight,[Long]=@Long,[Width]=@Width,[Height]=@Height,[Long2]=@Long2,[Width2]=@Width2,[Height2]=@Height2,[BoxRate]=@BoxRate,Cert=@Cert,FeeRate=@FeeRate,JYPrice=@JYPrice,BoxNum=@BoxNum,BoxStoreCode=@BoxStoreCode,JHDays=@JHDays,KFName=@KFName,KFName2=@KFName2,SortName=@SortName,SubsidyFee=@SubsidyFee where GoodsId=@GoodsId end else begin --select @GoodsNo=isnull(max(GoodsNo),0)+1 from HW_GoodsInfo where SortId=@SortId INSERT INTO [HW_GoodsInfo]([GoodsCode],[GoodsEg],[GoodsNo],[GoodsOldCode],[SortId],SortId1,SortId2,[SortName],[SupplierId],[GoodsName],[GoodsEnglisgName],[GoodsNum],[GoodsLockNum],[InPrice],[NowPrice],[Weight],[Weight2],[WeightUnit],[Solid],[SolidUnit],[Position],[InDate],[UpdateDate],[FirstImgUrl],[GoodsImageIds],[CompanyId],[GoodsPlanNum],[GoodsOutNum],[GoodsInNum],[SafeNum],[HGCode],[HGCompanyCode],[UpdateName],[GoodsRemark],[AutoPlan],[NoGoods],[AvgTime],[State],[DeptRemark],[NoticeDays],[GoodsInfo],[DefaultCity],[PageFee],[PostPrice],GoodsSupplyCode,BGPrice,NoticeShop,[NetWeight],[Long],[Width],[Height],[Long2],[Width2],[Height2],[BoxRate],Cert,FeeRate,JYPrice,BoxNum,BoxStoreCode,JHDays,KFName,KFName2,SubsidyFee)values(@GoodsCode,@GoodsEg,@GoodsNo,@GoodsOldCode,@SortId,@SortId1,@SortId2,@SortName,@SupplierId,@GoodsName,@GoodsEnglisgName,@GoodsNum,@GoodsLockNum,@InPrice,@NowPrice,@Weight,@Weight2,@WeightUnit,@Solid,@SolidUnit,@Position,@InDate,@UpdateDate,@FirstImgUrl,@GoodsImageIds,@CompanyId,@GoodsPlanNum,@GoodsOutNum,@GoodsInNum,@SafeNum,@HGCode,@HGCompanyCode,@UpdateName,@GoodsRemark,@AutoPlan,@NoGoods,@AvgTime,@State,@DeptRemark,@NoticeDays,@GoodsInfo,@DefaultCity,@PageFee,@PostPrice,@GoodsSupplyCode,@BGPrice,@NoticeShop,@NetWeight,@Long,@Width,@Height,@Long2,@Width2,@Height2,@BoxRate,@Cert,@FeeRate,@JYPrice,@BoxNum,@BoxStoreCode,@JHDays,@KFName,@KFName2,@SubsidyFee) set @GoodsId=SCOPE_IDENTITY() update XP_GoodsSelect set GoodsCode=@GoodsCode,IsAdd=1 where Id=@XPId INSERT INTO [HW_GoodsCode]([EnglishCode],[GoodsNo]) values(@GoodsEg,@GoodsNo) end select @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsOldCode", DbType.String, Model.GoodsOldCode); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@SortId1", DbType.Int32, Model.SortId1); db.AddInParameter(cmd, "@SortId2", DbType.String, Model.SortId2); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName); db.AddInParameter(cmd, "@SupplierId", DbType.String, Model.SupplierId); db.AddInParameter(cmd, "@Supplier", DbType.Int32, Model.Supplier); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, Model.GoodsEnglisgName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsLockNum", DbType.Int32, Model.GoodsLockNum); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, Model.InPrice); db.AddInParameter(cmd, "@NowPrice", DbType.Decimal, Model.NowPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, Model.Weight2); db.AddInParameter(cmd, "@WeightUnit", DbType.String, Model.WeightUnit); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@SolidUnit", DbType.String, Model.SolidUnit); db.AddInParameter(cmd, "@Position", DbType.Int32, Model.Position); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@UpdateDate", DbType.DateTime, Model.UpdateDate); db.AddInParameter(cmd, "@FirstImgUrl", DbType.String, Model.FirstImgUrl); db.AddInParameter(cmd, "@GoodsImageIds", DbType.String, Model.GoodsImageIds); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsPlanNum", DbType.Int32, Model.GoodsPlanNum); db.AddInParameter(cmd, "@GoodsOutNum", DbType.Int32, Model.GoodsOutNum); db.AddInParameter(cmd, "@GoodsInNum", DbType.Int32, Model.GoodsInNum); db.AddInParameter(cmd, "@SafeNum", DbType.Int32, Model.SafeNum); db.AddInParameter(cmd, "@HGCode", DbType.String, Model.HGCode); db.AddInParameter(cmd, "@HGCompanyCode", DbType.String, Model.HGCompanyCode); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); db.AddInParameter(cmd, "@GoodsRemark", DbType.String, Model.GoodsRemark); db.AddInParameter(cmd, "@AutoPlan", DbType.Int32, Model.AutoPlan); db.AddInParameter(cmd, "@NoGoods", DbType.Int32, Model.NoGoods); db.AddInParameter(cmd, "@AvgTime", DbType.Decimal, Model.AvgTime); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@DeptRemark", DbType.String, Model.DeptRemark); db.AddInParameter(cmd, "@NoticeDays", DbType.Int32, Model.NoticeDays); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, Model.GoodsInfo); db.AddInParameter(cmd, "@DefaultCity", DbType.String, Model.DefaultCity); db.AddInParameter(cmd, "@PageFee", DbType.Decimal, Model.PageFee); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@GoodsSupplyCode", DbType.String, Model.GoodsSupplyCode); db.AddInParameter(cmd, "@BGPrice", DbType.Decimal, Model.BGPrice); db.AddInParameter(cmd, "@NoticeShop", DbType.String, Model.NoticeShop); db.AddInParameter(cmd, "@XPId", DbType.Int32, Model.XPId); db.AddInParameter(cmd, "@NetWeight", DbType.Decimal, Model.NetWeight); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@Long2", DbType.Decimal, Model.Long2); db.AddInParameter(cmd, "@Width2", DbType.Decimal, Model.Width2); db.AddInParameter(cmd, "@Height2", DbType.Decimal, Model.Height2); db.AddInParameter(cmd, "@BoxRate", DbType.Int32, Model.BoxRate); db.AddInParameter(cmd, "@Cert", DbType.String, Model.Cert); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@JYPrice", DbType.Decimal, Model.JYPrice); db.AddInParameter(cmd, "@BoxNum", DbType.Int32, Model.BoxNum); db.AddInParameter(cmd, "@BoxStoreCode", DbType.String, Model.BoxStoreCode); db.AddInParameter(cmd, "@JHDays", DbType.Int32, Model.JHDays); db.AddInParameter(cmd, "@KFName", DbType.String, Model.KFName); db.AddInParameter(cmd, "@KFName2", DbType.String, Model.KFName2); db.AddInParameter(cmd, "@SubsidyFee", DbType.Decimal, Model.SubsidyFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除货物店铺 public static void DeleteShopForTM(string Ids, int GoodsId, string Name) { string tsql = ""; if (Ids != "") { tsql = @"delete from HW_Shop where GoodsId=@GoodsId and InName=@Name and Id not in (" + Ids + ")"; } else tsql = @"delete from HW_Shop where GoodsId=@GoodsId and InName=@Name "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.ExecuteNonQuery(cmd); } #endregion public static List GetFedexOrderList2(DateTime? SDate, DateTime? EDate) { string query = @" select top 30 a.OrderId,a.PlatOrderCode,b.RevAddr,b.RevCity,b.RevPhone,b.RevMail,b.RevMoblie,b.RevName,b.RevArea,b.RevPostCode,b.RevProvince,b.RevProvinceCode,b.RevPostCode,b.RevCountry,b.CountryCode from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId inner join DT_USMap c on b.RevProvinceCode=c.code where c.IsEast=1 and b.CountryCode='US' and a.OrderDate>=@SDate and a.OrderDate<@EDate and a.OrderId not in ( select OrderId from DT_Fedex)"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@SDate", DbType.DateTime, SDate); database.AddInParameter(sqlStringCommand, "@EDate", DbType.DateTime, EDate); return database.ExecuteDataTable(sqlStringCommand).ToList(); } #region 保存 public static void Save_Fedex(int OrderId) { string tsql = @" if(select count(0) from DT_Fedex where OrderId=@OrderId)=0 begin INSERT INTO [DT_Fedex]([OrderId])values(@OrderId) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static void UpdateFedexSpare() { string tsql = @" update a set fee6=b.fee11 from DT_Fedex a inner join ( select OrderId,fee11=SUM(isnull(fee11,0)) from DT_SpareFee group by OrderId)b on a.OrderId=b.OrderId where b.fee11>0 update a set fee7=b.fee22 from DT_Fedex a inner join ( select OrderId,fee22=SUM(isnull(fee22,0)) from DT_SpareFee group by OrderId)b on a.OrderId=b.OrderId where b.fee22>0 update a set fee8=b.fee33 from DT_Fedex a inner join ( select OrderId,fee33=SUM(isnull(fee33,0)) from DT_SpareFee group by OrderId)b on a.OrderId=b.OrderId where b.fee33>0 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 运费对比 public static List GetPostFee(DateTime? SDate, DateTime? EDate) { string tsql = @" select b.PlatOrderCode,a.fee6,a.fee7,a.fee8,fee66=b.fee6,fee77=b.fee7,fee88=b.fee8,c.RevProvinceCode,c.RevCity,c.RevAddr,b.OrderDate,c.Post,c.RevFax from DT_Fedex a inner join DT_OrderInfo b on a.orderid=b.OrderId inner join DT_OrderXXInfo c on b.OrderId=c.OrderId where b.state>1 and b.state<3 and b.OrderDate>=@SDate and b.OrderDate<@EDate and c.post in (228,233,234) order by b.OrderDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 保存 public static int Save_DayData(CK_DayData Model) { string tsql = @" if @Id>0 begin Update [CK_DayData] set [DataDate]=@DataDate,[LabelNum]=@LabelNum,[ScanNum]=@ScanNum,[NoPostNum]=@NoPostNum,[BackNum]=@BackNum,[WorkNum]=@WorkNum,[LeaveNum]=@LeaveNum,[Crash]=@Crash,[Note1]=@Note1,[Note2]=@Note2,[Note3]=@Note3,[Note4]=@Note4,[Note5]=@Note5,[Note6]=@Note6,[Note7]=@Note7,[Note8]=@Note8,[Int1]=@Int1,[Int2]=@Int2,[Int3]=@Int3,[Int4]=@Int4,[Int5]=@Int5,[Dec1]=@Dec1,[Dec2]=@Dec2,[Dec3]=@Dec3 where Id=@Id end else begin INSERT INTO [CK_DayData]([InName],[InDate],[DataDate],[LabelNum],[ScanNum],[NoPostNum],[BackNum],[WorkNum],[LeaveNum],[Crash],[Note1],[Note2],[Note3],[Note4],[Note5],[Note6],[Note7],[Note8],[Int1],[Int2],[Int3],[Int4],[Int5],[Dec1],[Dec2],[Dec3])values(@InName,@InDate,@DataDate,@LabelNum,@ScanNum,@NoPostNum,@BackNum,@WorkNum,@LeaveNum,@Crash,@Note1,@Note2,@Note3,@Note4,@Note5,@Note6,@Note7,@Note8,@Int1,@Int2,@Int3,@Int4,@Int5,@Dec1,@Dec2,@Dec3) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@DataDate", DbType.DateTime, Model.DataDate); db.AddInParameter(cmd, "@LabelNum", DbType.Int32, Model.LabelNum); db.AddInParameter(cmd, "@ScanNum", DbType.Int32, Model.ScanNum); db.AddInParameter(cmd, "@NoPostNum", DbType.Int32, Model.NoPostNum); db.AddInParameter(cmd, "@BackNum", DbType.Int32, Model.BackNum); db.AddInParameter(cmd, "@WorkNum", DbType.Int32, Model.WorkNum); db.AddInParameter(cmd, "@LeaveNum", DbType.Int32, Model.LeaveNum); db.AddInParameter(cmd, "@Crash", DbType.Decimal, Model.Crash); db.AddInParameter(cmd, "@Note1", DbType.String, Model.Note1); db.AddInParameter(cmd, "@Note2", DbType.String, Model.Note2); db.AddInParameter(cmd, "@Note3", DbType.String, Model.Note3); db.AddInParameter(cmd, "@Note4", DbType.String, Model.Note4); db.AddInParameter(cmd, "@Note5", DbType.String, Model.Note5); db.AddInParameter(cmd, "@Note6", DbType.String, Model.Note6); db.AddInParameter(cmd, "@Note7", DbType.String, Model.Note7); db.AddInParameter(cmd, "@Note8", DbType.String, Model.Note8); db.AddInParameter(cmd, "@Int1", DbType.Int32, Model.Int1); db.AddInParameter(cmd, "@Int2", DbType.Int32, Model.Int2); db.AddInParameter(cmd, "@Int3", DbType.Int32, Model.Int3); db.AddInParameter(cmd, "@Int4", DbType.Int32, Model.Int4); db.AddInParameter(cmd, "@Int5", DbType.Int32, Model.Int5); db.AddInParameter(cmd, "@Dec1", DbType.Decimal, Model.Dec1); db.AddInParameter(cmd, "@Dec2", DbType.Decimal, Model.Dec2); db.AddInParameter(cmd, "@Dec3", DbType.Decimal, Model.Dec3); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_DayData(int Id) { string tsql = @" delete from CK_DayData where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static CK_DayData GetModel_DayData(int Id) { CK_DayData model = null; //string tsql = "select a.Id,a.InName,a.InDate,a.DataDate,a.LabelNum,a.ScanNum,a.NoPostNum,a.BackNum,a.WorkNum,a.LeaveNum,a.Crash,a.Note1,a.Note2,a.Note3,a.Note4,a.Note5,a.Note6,a.Note7,a.Note8,a.Int1,a.Int2,a.Int3,a.Int4,a.Int5,a.Dec1,a.Dec2,a.Dec3 from CK_DayData"; string tsql = @" select * from CK_DayData where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 分页查询 public static List GetListDayData(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.InName,a.InDate,a.DataDate,a.LabelNum,a.ScanNum,a.NoPostNum,a.BackNum,a.WorkNum,a.LeaveNum,a.Crash,a.Note1,a.Note2,a.Note3,a.Note4,a.Note5,a.Note6,a.Note7,a.Note8,a.Int1,a.Int2,a.Int3,a.Int4,a.Int5,a.Dec1,a.Dec2,a.Dec3"; ser.Tables = @"CK_DayData a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 多条件普通查询 public static List GetListDayData(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); //ser.Fields = "a.Id,a.InName,a.InDate,a.DataDate,a.LabelNum,a.ScanNum,a.NoPostNum,a.BackNum,a.WorkNum,a.LeaveNum,a.Crash,a.Note1,a.Note2,a.Note3,a.Note4,a.Note5,a.Note6,a.Note7,a.Note8,a.Int1,a.Int2,a.Int3,a.Int4,a.Int5,a.Dec1,a.Dec2,a.Dec3"; ser.Fields = "a.*"; ser.Tables = @"CK_DayData a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.KeyName = "Id"; ser.Sort = Sort; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsImg(string DetailIds) { //string tsql = "select a.Id,a.InName,a.InDate,a.DataDate,a.LabelNum,a.ScanNum,a.NoPostNum,a.BackNum,a.WorkNum,a.LeaveNum,a.Crash,a.Note1,a.Note2,a.Note3,a.Note4,a.Note5,a.Note6,a.Note7,a.Note8,a.Int1,a.Int2,a.Int3,a.Int4,a.Int5,a.Dec1,a.Dec2,a.Dec3 from CK_DayData"; string tsql = @"SELECT DetailId,FirstImgUrl=case when b.FirstImgUrl IS NOT NULL AND b.FirstImgUrl<>'' THEN b.FirstImgUrl ELSE a.FirstImgUrl end FROM HW_GoodsInfo a inner JOIN HW_GoodsDetail b ON a.GoodsId=b.GoodsId WHERE b.DetailId IN (" + DetailIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListDayData() { //string tsql = "select a.Id,a.InName,a.InDate,a.DataDate,a.LabelNum,a.ScanNum,a.NoPostNum,a.BackNum,a.WorkNum,a.LeaveNum,a.Crash,a.Note1,a.Note2,a.Note3,a.Note4,a.Note5,a.Note6,a.Note7,a.Note8,a.Int1,a.Int2,a.Int3,a.Int4,a.Int5,a.Dec1,a.Dec2,a.Dec3 from CK_DayData"; string tsql = "select * from CK_DayData"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListUserBuyNum2(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select Id=cast(a.Id as int),a.ShopId,a.UserId,a.InDate,a.CheckSate,a.CheckDate,a.CheckUserId,a.CheckResult,a.Type,b.Name from HW_UserBuyNum a inner join jc_userinfo b on a.UserId=b.UserId"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListDayData(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select Id=cast(a.Id as int),a.InName,a.InDate,a.DataDate,a.LabelNum,a.ScanNum,a.NoPostNum,a.BackNum,a.WorkNum,a.LeaveNum,a.Crash,a.Note1,a.Note2,a.Note3,a.Note4,a.Note5,a.Note6,a.Note7,a.Note8,a.Int1,a.Int2,a.Int3,a.Int4,a.Int5,a.Dec1,a.Dec2,a.Dec3 from CK_DayData a"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 判断是否重复 public static bool CheckName_DayData(int Id, string Name) { string tsql = @"select count(0) from CK_DayData where Id<>@Id and Name=@Name"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@Name", DbType.String, Name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a == 0) return true; return false; } #endregion #region 分页查询 public static List GetListUserBuyNum(int StoreId, string StoreName, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.DetailId as int),a.DetailId,StoreId=" + StoreId + ",StoreName='" + StoreName + "',a.KCNum,NowNum=isnull(d.NowNum,0),c.GoodsCode,SKU=b.SKU1,c.GoodsName,LeftNum=CASE WHEN a.KCNum>isnull(d.NowNum,0) THEN a.KCNum-isnull(d.NowNum,0) ELSE 0 end,c.FirstImgUrl"; ser.Tables = @"(select DetailId,KCNum=SUM(KCNum) FROM HW_GoodsInDetail where StoreId=" + StoreId + @" and OrderGoodsId=0 AND KCNum>0 GROUP BY DetailId)a inner JOIN HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN HW_GoodsInfo c ON b.GoodsId=c.GoodsId left JOIN ( SELECT DetailId,NowNum=SUM(isnull(InNum,0)-isnull(MateNum,0)) FROM HW_UserBuyDetail where StoreId=" + StoreId + @" and isnull(InNum,0)-isnull(MateNum,0)>0 GROUP BY DetailId)d ON a.DetailId=d.DetailId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_UserBuyNum(HW_UserBuyNum Model) { string tsql = @" if @Id>0 begin Update [HW_UserBuyNum] set [ShopId]=@ShopId,[UserId]=@UserId,[InDate]=@InDate,[CheckSate]=@CheckSate,[CheckDate]=@CheckDate,[CheckUserId]=@CheckUserId,[CheckResult]=@CheckResult,Type=@Type where Id=@Id end else begin INSERT INTO [HW_UserBuyNum]([ShopId],[UserId],[InDate],[CheckSate],[CheckDate],[CheckUserId],[CheckResult],Type)values(@ShopId,@UserId,@InDate,@CheckSate,@CheckDate,@CheckUserId,@CheckResult,@Type) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@CheckSate", DbType.Int32, Model.CheckSate); db.AddInParameter(cmd, "@CheckDate", DbType.DateTime, Model.CheckDate); db.AddInParameter(cmd, "@CheckUserId", DbType.Int32, Model.CheckUserId); db.AddInParameter(cmd, "@CheckResult", DbType.String, Model.CheckResult); db.AddInParameter(cmd, "@Type", DbType.Int32, Model.Type); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_UserBuyDetail(int Type, HW_UserBuyDetail Model) { string tsql = @" declare @Num1 int,@Num2 int select @Num1=SUM(KCNum) FROM HW_GoodsInDetail where StoreId=@StoreId and DetailId=@DetailId and OrderGoodsId=0 AND KCNum>0 SELECT @Num2=SUM(InNum-MateNum) FROM HW_UserBuyDetail where (InNum-MateNum)>0 and StoreId=@StoreId and DetailId=@DetailId if (@Num1-@Num2-@InNum)<0 begin select Id=@Num1-@Num2 end else begin if @Id>0 begin Update [HW_UserBuyDetail] set [MastId]=@MastId,[DetailId]=@DetailId,[StoreId]=@StoreId,[BuyNum]=@BuyNum,[CheckNum]=@CheckNum,[MateNum]=@MateNum,[InDate]=@InDate,InNum=@InNum where Id=@Id end else begin INSERT INTO [HW_UserBuyDetail]([MastId],[DetailId],[StoreId],[BuyNum],[CheckNum],[MateNum],[InDate],InNum,ShopId)values(@MastId,@DetailId,@StoreId,@BuyNum,@CheckNum,@MateNum,@InDate,@InNum,@ShopId) set @Id=SCOPE_IDENTITY() end select -100000 end "; if (Type == 2) tsql = @" if @Id>0 begin Update [HW_UserBuyDetail] set [MastId]=@MastId,[DetailId]=@DetailId,[StoreId]=@StoreId,[BuyNum]=@BuyNum,[CheckNum]=@CheckNum,[MateNum]=@MateNum,[InDate]=@InDate,InNum=@InNum where Id=@Id end else begin INSERT INTO [HW_UserBuyDetail]([MastId],[DetailId],[StoreId],[BuyNum],[CheckNum],[MateNum],[InDate],InNum,ShopId)values(@MastId,@DetailId,@StoreId,@BuyNum,@CheckNum,@MateNum,@InDate,@InNum,@ShopId) set @Id=SCOPE_IDENTITY() end select -100000 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@MastId", DbType.Int32, Model.MastId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@BuyNum", DbType.Int32, Model.BuyNum); db.AddInParameter(cmd, "@CheckNum", DbType.Int32, Model.CheckNum); db.AddInParameter(cmd, "@MateNum", DbType.Int32, Model.MateNum); db.AddInParameter(cmd, "@InNum", DbType.Int32, Model.InNum); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询我的货物 public static List GetListMyUserBuyNum22(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.DetailId as int),f.StoreName,e.ShopId,a.StoreId,a.DetailId,e.ShopName,e.ShopUser,d.GoodsCode,d.GoodsName,SKU=c.SKU1,a.InNum,a.NowNum,FirstImgUrl=case when c.FirstImgUrl IS NOT NULL AND c.FirstImgUrl<>'' THEN c.FirstImgUrl ELSE d.FirstImgUrl end,a.MateNum"; ser.Tables = @"(select b.ShopId,b.StoreId,b.DetailId,InNum=sum(isnull(b.InNum,0)),MateNum=sum(isnull(b.MateNum,0)),NowNum=sum(isnull(b.InNum,0)-isnull(b.MateNum,0)) FROM HW_UserBuyNum a inner JOIN HW_UserBuyDetail b ON a.Id=b.MastId GROUP BY b.ShopId,b.StoreId,b.DetailId)a inner JOIN HW_GoodsDetail c ON a.DetailId=c.DetailId INNER JOIN HW_GoodsInfo d ON c.GoodsId=d.GoodsId INNER JOIN JC_Shop e ON a.ShopId=e.ShopId INNER JOIN CK_StoreHouse f ON a.StoreId=f.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询我的货物 public static List GetListMyUserBuyNum(int UserId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.DetailId as int),f.StoreName,e.ShopId,a.StoreId,a.DetailId,e.ShopName,e.ShopUser,d.GoodsCode,d.GoodsName,SKU=c.SKU1,a.InNum,a.NowNum,FirstImgUrl=case when c.FirstImgUrl IS NOT NULL AND c.FirstImgUrl<>'' THEN c.FirstImgUrl ELSE d.FirstImgUrl end,a.MateNum"; ser.Tables = @"(select b.ShopId,b.StoreId,b.DetailId,InNum=sum(isnull(b.InNum,0)),MateNum=sum(isnull(b.MateNum,0)),NowNum=sum(isnull(b.InNum,0)-isnull(b.MateNum,0)) FROM HW_UserBuyNum a inner JOIN HW_UserBuyDetail b ON a.Id=b.MastId where a.UserId=@UserId GROUP BY b.ShopId,b.StoreId,b.DetailId)a inner JOIN HW_GoodsDetail c ON a.DetailId=c.DetailId INNER JOIN HW_GoodsInfo d ON c.GoodsId=d.GoodsId INNER JOIN JC_Shop e ON a.ShopId=e.ShopId INNER JOIN CK_StoreHouse f ON a.StoreId=f.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListUserBuyDetail(string Ids) { //string tsql = "select a.Id,a.MastId,a.DetailId,a.StoreId,a.BuyNum,a.CheckNum,a.MateNum,a.InDate,a.InNum,a.ChaseId,a.ShopId from HW_UserBuyDetail"; string tsql = @"select a.*,f.StoreName,e.ShopName,FirstImgUrl=case when b.FirstImgUrl IS NOT NULL AND b.FirstImgUrl<>'' THEN b.FirstImgUrl ELSE c.FirstImgUrl end,SKU=b.SKU1,c.GoodsCode from HW_UserBuyDetail a INNER JOIN HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN HW_GoodsInfo c ON b.GoodsId=c.GoodsId INNER JOIN CK_StoreHouse f ON a.StoreId=f.StoreId INNER JOIN JC_Shop e ON a.ShopId=e.ShopId where a.MastId in (" + Ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询货物列表 public static List GetListUserBuy(int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.DetailId as int),f.StoreName,e.ShopId,a.DetailId,e.ShopName,e.ShopUser,d.GoodsCode,d.GoodsName,c.SKU1,a.InNum,a.NowNum,FirstImgUrl=case when c.FirstImgUrl IS NOT NULL AND c.FirstImgUrl<>'' THEN c.FirstImgUrl ELSE d.FirstImgUrl end"; ser.Tables = @"(select ShopId,StoreId,DetailId,InNum=sum(isnull(InNum,0)),NowNum=sum(isnull(InNum,0)-isnull(MateNum,0)) FROM HW_UserBuyDetail where StoreId=@StoreId GROUP BY ShopId,StoreId,DetailId)a inner JOIN HW_GoodsDetail c ON a.DetailId=c.DetailId INNER JOIN HW_GoodsInfo d ON c.GoodsId=d.GoodsId INNER JOIN JC_Shop e ON a.ShopId=e.ShopId INNER JOIN CK_StoreHouse f ON a.StoreId=f.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion // #region 保存 // public static int Save_UserBuyNum(HW_UserBuyNum Model) // { // string tsql = @" //declare @Num1 int,@Num2 int //select @Num1=SUM(KCNum) FROM HW_GoodsInDetail where //StoreId=@StoreId and DetailId=@DetailId and OrderGoodsId=0 AND KCNum>0 //SELECT @Num2=SUM(NowNum) FROM HW_UserBuyNum where NowNum>0 and StoreId=@StoreId and DetailId=@DetailId //if (@Num1-@Num2-@BuyNum)<0 //begin //select -1 //end //else //begin //if @Id>0 //begin //Update [HW_UserBuyNum] set [ShopId]=@ShopId,[UserId]=@UserId,[StoreId]=@StoreId,[DetailId]=@DetailId,[BuyNum]=@BuyNum,[CheckNum]=@CheckNum,[NowNum]=@NowNum,[InDate]=@InDate,[CheckSate]=@CheckSate,[CheckDate]=@CheckDate,[CheckUserId]=@CheckUserId,[CheckResult]=@CheckResult where Id=@Id //end //else //begin //INSERT INTO [HW_UserBuyNum]([ShopId],[UserId],[StoreId],[DetailId],[BuyNum],[CheckNum],[NowNum],[InDate],[CheckSate],[CheckDate],[CheckUserId],[CheckResult])values(@ShopId,@UserId,@StoreId,@DetailId,@BuyNum,@CheckNum,@NowNum,@InDate,@CheckSate,@CheckDate,@CheckUserId,@CheckResult) //set @Id=SCOPE_IDENTITY() //end //select @Id //end //"; // Database db = DatabaseFactory.CreateDatabase(); // DbCommand cmd = db.GetSqlStringCommand(tsql); // db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); // db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); // db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); // db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); // db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); // db.AddInParameter(cmd, "@BuyNum", DbType.Int32, Model.BuyNum); // db.AddInParameter(cmd, "@CheckNum", DbType.Int32, Model.CheckNum); // db.AddInParameter(cmd, "@NowNum", DbType.Int32, Model.NowNum); // db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); // db.AddInParameter(cmd, "@CheckSate", DbType.Int32, Model.CheckSate); // db.AddInParameter(cmd, "@CheckDate", DbType.DateTime, Model.CheckDate); // db.AddInParameter(cmd, "@CheckUserId", DbType.Int32, Model.CheckUserId); // db.AddInParameter(cmd, "@CheckResult", DbType.String, Model.CheckResult); // int a = Convert.ToInt32(db.ExecuteScalar(cmd)); // return a; // } // #endregion #region 删除 public static void Delete_UserBuyNum(int Id) { string tsql = @" delete from HW_UserBuyDetail where MastId=@Id delete from HW_UserBuyNum where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 判断是否能删除 public static bool CheckName_UserBuyNum(int Id) { string tsql = @"if(select count(0) from HW_UserBuyDetail where MastId=@Id and MateNum>0)=0 begin select count(0) from HW_UserBuyNum where Id=@Id and datediff(day,InDate,getdate())>0 --第二天不能删除 end else begin select 1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a == 0) return true; return false; } #endregion #region 修改 public static void Update_UserBuyDetail(int Id, int ShopId, int Num) { string tsql = @" declare @MId int select @MId=MastId from where Id=@Id if(select count(0) from HW_UserBuyDetail where MastId=@MId and ShopId=@ShopId)>0 begin update HW_UserBuyDetail set InNum=InNum+@Num where MastId=@MId and ShopId=@ShopId end else begin INSERT INTO [HW_UserBuyDetail]([MastId],[DetailId],[StoreId],[BuyNum],[CheckNum],[MateNum],[InDate],[InNum],[ChaseId],[ShopId]) select [MastId],[DetailId],[StoreId],[BuyNum]=@Num,[CheckNum]=@Num,[MateNum]=0,[InDate],[InNum]=@Num,[ChaseId],ShopId=@ShopId from HW_UserBuyDetail where Id=@Id end update "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@ShopId", DbType.String, ShopId); db.AddInParameter(cmd, "@Num", DbType.Int32, Num); db.ExecuteNonQuery(cmd); } #endregion public static List GetShopGoodsNum(int ShopId, int DetailId) { string tsql = @"select * from "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } public static List GetKCShopGoodsNum(int StoreId, int StoreId2) { string tsql = @"select a.DetailId,a.StoreId,a.ShopId,NowNum=sum(a.InNum-isnull(a.MateNum,0)),MateNum=0 FROM HW_UserBuyDetail a inner JOIN ( select DISTINCT a.ShopId,c.DetailId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=1 and a.MoneyState=1 and a.FPDate is not null and c.DetailId>0 and b.StoreId=@StoreId and a.State=1 and a.MateState=0)b ON a.ShopId=b.ShopId AND a.DetailId=b.DetailId WHERE a.InNum-isnull(a.MateNum,0)>0 AND a.StoreId=@StoreId2 group by a.StoreId,a.ShopId,a.DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@StoreId2", DbType.Int32, StoreId2); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #region 查询要部分分配库存的订单 public static List GetKCShopGoodsNumPart(int CompanyId, string OrderIds, string JoinOrderCodes, int StoreId) { List list = null; string tsql = @" select a.DetailId,a.StoreId,a.ShopId,NowNum=sum(a.InNum-isnull(a.MateNum,0)),MateNum=0 FROM HW_UserBuyDetail a inner JOIN ( select DISTINCT a.ShopId,c.DetailId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and a.OrderId in (" + OrderIds + @") and a.State=1 and a.MateState<=1)b ON a.ShopId=b.ShopId AND a.DetailId=b.DetailId WHERE a.InNum-isnull(a.MateNum,0)>0 AND a.StoreId=@StoreId group by a.StoreId,a.ShopId,a.DetailId"; if (JoinOrderCodes != "") tsql = @" select a.DetailId,a.StoreId,a.ShopId,NowNum=sum(a.InNum-isnull(a.MateNum,0)),MateNum=0 FROM HW_UserBuyDetail a inner JOIN ( select DISTINCT a.ShopId,c.DetailId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.orderid=b.orderid inner join DT_OrderGoods c on a.orderid=c.orderid where a.CompanyId=@CompanyId and (a.OrderId in (" + OrderIds + ") or JoinOrderCode in (" + JoinOrderCodes + @")) and a.State=1 and a.MateState<=1)b ON a.ShopId=b.ShopId AND a.DetailId=b.DetailId WHERE a.InNum-isnull(a.MateNum,0)>0 AND a.StoreId=@StoreId group by a.StoreId,a.ShopId,a.DetailId "; // if (StoreId == 6) // { // tsql = @" //select a.DetailId,a.StoreId,a.ShopId,NowNum=sum(a.InNum-isnull(a.MateNum,0)),MateNum=0 FROM HW_UserBuyDetail a //inner JOIN ( //select DISTINCT a.ShopId,c.DetailId from DT_OrderInfo a //inner join DT_OrderXXInfo b on a.orderid=b.orderid //inner join DT_OrderGoods c on a.orderid=c.orderid //where a.CompanyId=@CompanyId and a.OrderId in (" + OrderIds + @") and a.State=1 and a.MateState<=1)b ON a.ShopId=b.ShopId AND a.DetailId=b.DetailId //WHERE a.InNum-isnull(a.MateNum,0)>0 AND a.StoreId in (6,9) group by a.StoreId,a.ShopId,a.DetailId"; // if (JoinOrderCodes != "") // tsql = @" //select a.DetailId,a.StoreId,a.ShopId,NowNum=sum(a.InNum-isnull(a.MateNum,0)),MateNum=0 FROM HW_UserBuyDetail a //inner JOIN ( //select DISTINCT a.ShopId,c.DetailId from DT_OrderInfo a //inner join DT_OrderXXInfo b on a.orderid=b.orderid //inner join DT_OrderGoods c on a.orderid=c.orderid //where a.CompanyId=@CompanyId and (a.OrderId in (" + OrderIds + ") or JoinOrderCode in (" + JoinOrderCodes + @")) and a.State=1 and a.MateState<=1)b ON a.ShopId=b.ShopId AND a.DetailId=b.DetailId //WHERE a.InNum-isnull(a.MateNum,0)>0 AND a.StoreId in (6,9) group by a.StoreId,a.ShopId,a.DetailId //"; // } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion public static List GetShopGoodsNumNoMate(int StoreId) { string tsql = @"select *,AddNum=0,NowNum=InNum-isnull(MateNum,0) from HW_UserBuyDetail where StoreId=@StoreId and InNum-isnull(MateNum,0)>0 order by InDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } public static List GetShopGoodsNumNoMate3() { string tsql = @"select top 1000 *,AddNum=0,NowNum=MateNum from HW_UserBuyDetail where MateNum>0 order by InDate desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } public static List GetShopGoodsNumNoMate4(string Ids) { string tsql = @"select top 1000 *,AddNum=0,NowNum=MateNum from HW_UserBuyDetail where DetailId in (" + Ids + ") and MateNum>0 order by InDate desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } public static List GetShopGoodsNumNoMate2(int StoreId, int ShopId, int DetailId) { string tsql = @"select *,AddNum=0 from HW_UserBuyDetail where StoreId=@StoreId and InNum-isnull(MateNum,0)>0 and ShopId=@ShopId and DetailId=@DetailId order by InDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #region 修改匹配 public static void UpdateUserBuyNumMate(int Id, int AddNum) { string tsql = @"update HW_UserBuyDetail set MateNum=isnull(MateNum,0)+@AddNum where Id=@Id INSERT INTO [HW_UserGoodsMate]([UserDetailId],[MateNum],[MateDate])values(@Id,@AddNum,getdate()) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@AddNum", DbType.Int32, AddNum); db.ExecuteNonQuery(cmd); } #endregion #region 修改匹配 public static void UpdateUserBuyNumMate2(int Id, int AddNum, int ShopId, int ShopId2) { string tsql = @" declare @MastId int,@DetailId int select top 1 @MastId=MastId,@DetailId=DetailId from HW_UserBuyDetail where Id=@Id if(select count(0) from HW_UserBuyDetail where ShopId=@ShopId2 and MastId=@MastId and DetailId=@DetailId)>0 begin update HW_UserBuyDetail set InNum=InNum+@AddNum where ShopId=@ShopId2 and MastId=@MastId and DetailId=@DetailId end else begin INSERT INTO [HW_UserBuyDetail]([MastId],[DetailId],[StoreId],[BuyNum],[CheckNum],[MateNum],[InDate],[InNum],[ChaseId],[ShopId],OldShopId,OldDate) select [MastId],[DetailId],[StoreId],BuyNum=@AddNum,CheckNum=@AddNum,0,getdate(),InNum=@AddNum,[ChaseId],[ShopId]=@ShopId2,ShopId2=@ShopId,InDate from [HW_UserBuyDetail] where Id=@Id end update HW_UserBuyDetail set InNum=InNum-@AddNum where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@AddNum", DbType.Int32, AddNum); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@ShopId2", DbType.Int32, ShopId2); db.ExecuteNonQuery(cmd); } #endregion #region 修改匹配 public static void UpdateUserBuyNumMate3(int Id, int AddNum) { string tsql = @"update HW_UserBuyDetail set MateNum=isnull(MateNum,0)-@AddNum where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@AddNum", DbType.Int32, AddNum); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询货物列表 public static List GetListUserBuyAll(int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.DetailId as int),f.StoreName,e.ShopId,a.DetailId,e.ShopName,ShopUser=isnull(Master,'')+' '+isnull(e.ShopUser,''),d.GoodsCode,d.GoodsName,SKU=c.SKU1,GoodsNum=b.KCNum,Solid=isnull(d.Solid,0)*NowNum,d.JYPrice,InPrice=dbo.MoneyUSDChange(isnull(d.InPrice,0),'RMB',1),TotalPrice=dbo.MoneyUSDChange(isnull(d.InPrice,0),'RMB',1)*a.NowNum,OrderDays=DATEDIFF(day,d.LastOrderDate,GETDATE()),a.InNum,a.NowNum,FirstImgUrl=case when c.FirstImgUrl IS NOT NULL AND c.FirstImgUrl<>'' THEN c.FirstImgUrl ELSE d.FirstImgUrl end,a.MateNum"; ser.Tables = @"#HW_GoodsBuy2 a inner join #HW_GoodsKC2 b on a.DetailId=b.DetailId inner JOIN HW_GoodsDetail c ON a.DetailId=c.DetailId INNER JOIN HW_GoodsInfo d ON c.GoodsId=d.GoodsId INNER JOIN JC_Shop e ON a.ShopId=e.ShopId INNER JOIN CK_StoreHouse f ON a.StoreId=f.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = @" select StoreId,DetailId,KCNum=SUM(KCNum) INTO #HW_GoodsKC2 FROM HW_GoodsInDetail where KCNum>0 AND OrderGoodsId=0 and StoreId=@StoreId GROUP BY StoreId,DetailId select StoreId,ShopId,DetailId,InNum=sum(isnull(InNum,0)),MateNum=sum(isnull(MateNum,0)),NowNum=sum(isnull(InNum,0)-isnull(MateNum,0)) INTO #HW_GoodsBuy2 FROM HW_UserBuyDetail where InNum>0 and StoreId=@StoreId GROUP BY StoreId,ShopId,DetailId " + ser.GetText(); tsql += " drop TABLE #HW_GoodsKC2 drop TABLE #HW_GoodsBuy2 "; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 获取合计 public static HW_UserBuyDetail GetUserBuyAllSum(int StoreId, int ShopId, string GoodsCode, int Num) { HW_UserBuyDetail model = null; string tsql = @" declare @GoodsNum int,@NowNum int,@TSolid decimal(8,2),@JYPrice decimal(8,2) select @GoodsNum=SUM(KCNum) FROM HW_GoodsInDetail a INNER JOIN HW_UserBuyDetail d ON a.DetailId=d.DetailId inner JOIN HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN HW_GoodsInfo c ON b.GoodsId=c.GoodsId where KCNum>0 AND d.InNum>0 AND OrderGoodsId=0 and (@ShopId=0 or d.ShopId=@ShopId) and a.StoreId=@StoreId AND (@GoodsCode='' or c.GoodsCode LIKE '%'+@GoodsCode+'%') select @NowNum=sum(isnull(InNum,0)-isnull(MateNum,0)),@TSolid=sum((InNum-isnull(MateNum,0))*isnull(c.Solid,0)),@JYPrice=sum((InNum-isnull(MateNum,0))*dbo.MoneyUSDChange(isnull(c.InPrice,0),'RMB',1)) FROM HW_UserBuyDetail a inner JOIN HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN HW_GoodsInfo c ON b.GoodsId=c.GoodsId where InNum>0 and StoreId=@StoreId AND (@ShopId=0 or a.ShopId=@ShopId) AND (@GoodsCode='' or c.GoodsCode LIKE '%'+@GoodsCode+'%') select GoodsNum=@GoodsNum,NowNum=@NowNum,TSolid=@TSolid,JYPrice=@JYPrice "; if (Num > 0) tsql = @" declare @GoodsNum int,@NowNum int,@TSolid decimal(8,2),@JYPrice decimal(8,2) select @GoodsNum=SUM(KCNum) FROM HW_GoodsInDetail a INNER JOIN HW_UserBuyDetail d ON a.DetailId=d.DetailId inner JOIN HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN HW_GoodsInfo c ON b.GoodsId=c.GoodsId where KCNum>0 AND d.InNum>0 and d.InNum-isnull(d.MateNum,0)>0 AND OrderGoodsId=0 and (@ShopId=0 or d.ShopId=@ShopId) and a.StoreId=@StoreId AND (@GoodsCode='' or c.GoodsCode LIKE '%'+@GoodsCode+'%') select @NowNum=sum(isnull(InNum,0)-isnull(MateNum,0)),@TSolid=sum((InNum-isnull(MateNum,0))*isnull(c.Solid,0)),@JYPrice=sum((InNum-isnull(MateNum,0))*dbo.MoneyUSDChange(isnull(c.InPrice,0),'RMB',1)) FROM HW_UserBuyDetail a inner JOIN HW_GoodsDetail b ON a.DetailId=b.DetailId INNER JOIN HW_GoodsInfo c ON b.GoodsId=c.GoodsId where InNum>0 and StoreId=@StoreId and a.InNum-isnull(a.MateNum,0)>0 AND (@ShopId=0 or a.ShopId=@ShopId) AND (@GoodsCode='' or c.GoodsCode LIKE '%'+@GoodsCode+'%') select GoodsNum=@GoodsNum,NowNum=@NowNum,TSolid=@TSolid,JYPrice=@JYPrice "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@Num", DbType.Int32, Num); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 获取合计 public static HW_UserBuyDetail GetUserBuyAllSum2(int StoreId) { HW_UserBuyDetail model = null; string tsql = @" SELECT Solid=sum((a.KCNum-isnull(b.NowNum,0))*isnull(d.Solid,0)),InPrice=dbo.MoneyUSDChange(sum((a.KCNum-isnull(b.NowNum,0))*isnull(d.InPrice,0)),'RMB',1) FROM ( SELECT DetailId,KCNum=SUM(KCNum) FROM HW_GoodsInDetail where StoreId=@StoreId AND OrderGoodsId=0 AND KCNum>0 GROUP BY DetailId)a inner JOIN HW_GoodsDetail c ON a.DetailId=c.DetailId INNER JOIN HW_GoodsInfo d ON c.GoodsId=d.GoodsId LEFT JOIN ( SELECT DetailId,NowNum=SUM(InNum-isnull(MateNum,0)) FROM HW_UserBuyDetail where InNum-isnull(MateNum,0)>0 AND StoreId=@StoreId GROUP BY DetailId)b ON a.DetailId=b.DetailId WHERE a.KCNum-isnull(b.NowNum,0)>0 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 分页查询货物列表 public static List GetListUserBuyAll2(int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.DetailId as int),f.StoreName,a.DetailId,d.GoodsCode,d.GoodsName,SKU=c.SKU1,GoodsNum=a.KCNum,Solid=isnull(d.Solid,0)*isnull(NowNum,0),d.JYPrice,InPrice=dbo.MoneyUSDChange(isnull(d.InPrice,0),'RMB',1),TotalPrice=dbo.MoneyUSDChange(isnull(d.InPrice,0),'RMB',1)*isnull(b.NowNum,0),OrderDays=DATEDIFF(day,d.LastOrderDate,GETDATE()),InNum=isnull(b.InNum,0),NowNum=isnull(b.NowNum,0),FirstImgUrl=case when c.FirstImgUrl IS NOT NULL AND c.FirstImgUrl<>'' THEN c.FirstImgUrl ELSE d.FirstImgUrl end,MateNum=isnull(b.MateNum,0),Solid=isnull(d.Solid,0)"; ser.Tables = @"#HW_GoodsKC a LEFT JOIN #HW_GoodsBuy b on a.StoreId=b.StoreId AND a.DetailId=b.DetailId inner JOIN HW_GoodsDetail c ON a.DetailId=c.DetailId INNER JOIN HW_GoodsInfo d ON c.GoodsId=d.GoodsId INNER JOIN CK_StoreHouse f ON a.StoreId=f.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = @" select StoreId,DetailId,KCNum=SUM(KCNum) INTO #HW_GoodsKC FROM HW_GoodsInDetail where KCNum>0 AND OrderGoodsId=0 GROUP BY StoreId,DetailId select StoreId,DetailId,InNum=sum(isnull(InNum,0)),MateNum=sum(isnull(MateNum,0)),NowNum=sum(isnull(InNum,0)-isnull(MateNum,0)) INTO #HW_GoodsBuy FROM HW_UserBuyDetail where InNum>0 GROUP BY StoreId,DetailId " + ser.GetText(); tsql += " drop TABLE #HW_GoodsKC drop TABLE #HW_GoodsBuy "; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询货物列表 public static List GetListStoreSoild(string StoreName, int StoreId, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.PostionCode,Solid=isnull(b.Solid,0),StoreName='" + StoreName + "'"; ser.Tables = @"CK_StorePostion a left join #HW_Solid b on a.PostionId=b.PostionId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.PostionCode"; string tsql = @" select b.PostionId,Solid=SUM(isnull(d.Solid,0)*a.KCNum) into #HW_Solid from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.KCNum>0 and a.StoreId=" + StoreId + " and a.OrderGoodsId=0 group by b.PostionId " + ser.GetText(); tsql += " drop TABLE #HW_Solid "; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion public static List GetListUserFee(DateTime? SDate, DateTime? EDate, int ShopId) { List list = null; string tsql = @" select * from CK_FeeReportYY where (@ShopId=0 or ShopId=@ShopId) and InDate>=@SDate and InDate<@EDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } public static List GetListUserShop(int ShopId) { List list = null; string tsql = @" select * from JC_Shop where CompanyId=1 and (@ShopId=0 or ShopId=@ShopId)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #region 返回列表 public static List GetListUserMate(string OrderIds, string JoinOrderCode) { //string tsql = "select a.Id,a.OrderId,a.InDate,a.IsDel,a.JoinOrderCode from HW_UserMate"; string tsql = "select * from HW_UserMate where IsDel=0 and (OrderId In (" + OrderIds + @") Or JoinOrderCode in (" + JoinOrderCode + "))"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 修改匹配 public static void UpdateUserMate(string OrderIds, string JoinOrderCode) { string tsql = @" update HW_UserMate set IsDel=1 where IsDel=0 and (OrderId In (" + OrderIds + @") Or JoinOrderCode in (" + JoinOrderCode + "))"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetCancelGoodsKC(string Ids) { //string tsql = "select a.Id,a.OrderId,a.InDate,a.IsDel,a.JoinOrderCode from HW_UserMate"; string tsql = @"select a.StoreId,a.DetailId,c.ShopId,MateNum=sum(a.KCNum) from HW_GoodsInDetail a inner JOIN DT_OrderGoods b ON a.OrderGoodsId=b.Id INNER JOIN DT_OrderInfo c ON b.OrderId=c.OrderId WHERE a.KCNum>0 and c.OrderId in (" + Ids + ") group by c.ShopId,a.StoreId,a.DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetShopBuyNum(int StoreId) { //string tsql = "select a.Id,a.OrderId,a.InDate,a.IsDel,a.JoinOrderCode from HW_UserMate"; string tsql = @"SELECT ShopId,DetailId,NowNum=SUM(InNum-isnull(MateNum,0)) FROM HW_UserBuyDetail where StoreId=@StoreId AND InNum>0 GROUP BY ShopId,DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询海外批次 public static List GetListCG_PurchaseForHWC(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"ChaseId=cast(a.ChaseId as int),a.ChaseCode,a.BuyCode,a.GoodsState,a.PostFee,a.Remark, a.ErrorInfo,a.InDate,a.BackDate,a.BuyDate,a.DoneDate,a.Supplier,a.SupplierName,a.SupplierPhone,a.InName,a.InUserId,a.Account,a.IsDelete,a.State,a.CompanyId,a.CheckUid,a.CheckContent,a.CheckDate,a.GoodsNum,a.GoodsMoney,checkstate=case when a.state=0 then '未审批' when a.state=1 then '审批通过' when a.state=2 then '审批不通过' when a.state=3 then '采购单结束' end,ReveState=case when a.PostState=0 then '未出运'when a.PostState=3 then '准备出运' when a.PostState=4 then '出运海上' when a.PostState=5 then '出运海外' when a.PostState=6 then '部分入库' when a.PostState=7 then '全部入库' else '未出运' end,TSoild=isnull(a.TSoild,0),a.TCFee5,a.TCFee6"; ser.Tables = @"CG_Purchase a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "ChaseId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询海外批次 public static List GetListCG_PurchaseForHWC2(string Code, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"ChaseId=cast(a.ChaseId as int),a.ChaseCode,a.BuyCode,a.GoodsState,a.PostFee,a.Remark, a.ErrorInfo,a.InDate,a.BackDate,a.BuyDate,a.DoneDate,a.Supplier,a.SupplierName,a.SupplierPhone,a.InName,a.InUserId,a.Account,a.IsDelete,a.State,a.CompanyId,a.CheckUid,a.CheckContent,a.CheckDate,a.GoodsNum,a.GoodsMoney,checkstate=case when a.state=0 then '未审批' when a.state=1 then '审批通过' when a.state=2 then '审批不通过' when a.state=3 then '采购单结束' end,ReveState=case when a.PostState=0 then '未出运'when a.PostState=3 then '准备出运' when a.PostState=4 then '出运海上' when a.PostState=5 then '出运海外' when a.PostState=6 then '部分入库' when a.PostState=7 then '全部入库' else '未出运' end,TSoild=isnull(a.TSoild,0),a.TCFee5,a.TCFee6,a.StoreId"; if (Code != "") { ser.Tables = @"(select * from CG_Purchase with(nolock) where ChaseId in (select distinct GJChaseId from CG_PurchaseGoods with(nolock) where GJChaseId>0 and GoodsCode like '%" + Code + "%'))a "; } else ser.Tables = @"CG_Purchase a with(nolock)"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "ChaseId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion public static JC_PostAddress GetAddressModel22(int AddrId) { JC_PostAddress address = null; string query = "select * from JC_PostAddress where Id=@AddrId"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@AddrId", DbType.Int32, AddrId); DataTable table = database.ExecuteDataTable(sqlStringCommand); if (table.Rows.Count > 0) { address = table.Rows[0].ToModel(); } return address; } public static List GetFedexOrderGoodsListSPare(string OrderIds) { string tsql = "select * from DT_SpareFee where OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #region 分页查询 public static List GetListDT_OrderInfoForUser_New(int CompanyId, DateTime? SDate, string GoodsName, string Name, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (Name != "") { sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.detailId=c.detailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and b.ShopId=d.ShopId inner join jc_userinfo e on d.UserId=e.UserId where e.name='" + Name + "'"; if (SDate != null) sql1 += " and b.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } // if (IsSku == 0 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 0 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsName like '%" + GoodsName + "%'"; // else // if (IsSku == 0 && SKU != "") // sql1 = sql1 + " a.DetailId=0"; // else if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId>0"; // else // if (IsSku == 1 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0 and GoodsSKU like '%" + GoodsName + "%'"; // else // if (IsSku == 1 && SKU != "") // sql1 = sql1 + " a.DetailId>0"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListDT_OrderInfoForUser(int CompanyId, DateTime? SDate, string GoodsName, string Name, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (Name != "") { sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.detailId=c.detailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and b.ShopId=d.ShopId inner join jc_userinfo e on d.UserId=e.UserId where e.name='" + Name + "'"; if (SDate != null) sql1 += " and b.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' "; } // if (IsSku == 0 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 0 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsName like '%" + GoodsName + "%'"; // else // if (IsSku == 0 && SKU != "") // sql1 = sql1 + " a.DetailId=0"; // else if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId>0"; // else // if (IsSku == 1 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0 and GoodsSKU like '%" + GoodsName + "%'"; // else // if (IsSku == 1 && SKU != "") // sql1 = sql1 + " a.DetailId>0"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 导出库存 public static DataTable GetList_GoodsLeftExcel(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); ser.Fields = @"a.DetailId,a.PostionId,a.GoodsNum,a.LockNum,LeftNum=a.GoodsNum-a.LockNum,c.GoodsName,c.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,e.StoreName,d.PostionCode,d.PostionDesc,pk='',c.Solid,Solid2=(a.GoodsNum-a.LockNum)*isnull(c.Solid,0)"; ser.Tables = @"(select DetailId,PostionId,GoodsNum=SUM(GoodsNum),LockNum=SUM(LockNum) from ( select DetailId,PostionId,GoodsNum=sum(KCNum),LockNum=0 from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,PostionId union select DetailId,PostionId,GoodsNum=0,LockNum=sum(KCNum) from HW_GoodsInDetail where CKDetailId=0 and OrderGoodsId>0 group by DetailId,PostionId)a group by DetailId,PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId inner join CK_StoreHouse e on d.StoreId=e.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 返回订单Model public static DT_OrderModel GetOrderModel(int OrderId) { DT_OrderModel model = null; string tsql = @"select a.*, b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,ShopName=[dbo].[GetShopName](a.ShopId),b.CountryCode,b.CountryName,b.PostError,b.SendAddr,b.PostOneCode,b.LogisticsId,b.RevProvinceCode,a.Fee6,a.Fee7,a.Fee8,BoxFee=a.Fee10 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回temu费用 public static List GetOrdertemuFee(int OrderId) { string tsql = @"select * from TemuOrderPostFee where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回订单Model public static DT_OrderModelNew GetOrderModel2(int OrderId) { DT_OrderModelNew model = null; string tsql = @"select a.*, b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,ShopName=[dbo].[GetShopName](a.ShopId),b.CountryCode,b.CountryName,b.PostError,b.SendAddr,b.PostOneCode,b.LogisticsId,b.RevProvinceCode,a.Fee6,a.Fee7,a.Fee8,BoxFee=a.Fee10,a.Fee11,a.Fee12,a.Fee13,a.Fee14,a.FactOrderFee,a.FactOrderCommison,a.FactOrderFax,b.Zone,a.UpsFeeR,a.UpsFeeE,isnull(a.IsSyncToWMS,1) IsSyncToWMS,a.UpsFeeE1,a.UpsFeeE2,a.UpsFeeW1,a.UpsFeeW2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 修改发货仓库 public static int UpdateSendStore(int OrderId, int StoreId) { string tsql = @" declare @OldStoreId int select top 1 @OldStoreId=StoreId from DT_OrderXXInfo with(nolock) where OrderId=@OrderId if @OldStoreId<>@StoreId begin if(select count(0) from DT_TrackCodeApply with(nolock) where OrderId=@OrderId and State=1)=0 begin update DT_OrderXXInfo set StoreId=@StoreId where OrderId=@OrderId update DT_OrderXXInfoNew set StoreId=@StoreId where OrderId=@OrderId select 0 end else begin select 1 end end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存采购 /// /// 保存采购 /// public static int SavePurchaseForTM2(CG_PurchaseNew Model) { string tsql = @" if @ChaseId>0 begin Update [CG_Purchase] set [BuyCode]=@BuyCode,[PostFee]=@PostFee,[Remark]=@Remark,[ErrorInfo]=@ErrorInfo,[BuyDate]=@BuyDate,[DoneDate]=@DoneDate,[Supplier]=@Supplier,[SupplierName]=@SupplierName,[SupplierPhone]=@SupplierPhone,[InName]=@InName,[InUserId]=@InUserId,[Account]=@Account,[IsDelete]=@IsDelete,[State]=@State,[CompanyId]=@CompanyId,[CheckUid]=@CheckUid,[CheckContent]=@CheckContent,[CheckDate]=@CheckDate,[GoodsNum]=@GoodsNum,[GoodsMoney]=@GoodsMoney,[IsFactory]=@IsFactory,[IsBH]=@IsBH,[PostState]=@PostState,[PostDate]=@PostDate,[BackDate]=@BackDate,[PostionCode]=@PostionCode,[IsError]=@IsError,[IsGJ]=@IsGJ,[TCFee1]=@TCFee1,[TCFee2]=@TCFee2,[TCFee3]=@TCFee3,[TCFee4]=@TCFee4,[TCFee5]=@TCFee5,[TCFee6]=@TCFee6,[TSoild]=@TSoild,StoreId=@StoreId where ChaseId=@ChaseId end else begin INSERT INTO [CG_Purchase]([ChaseCode],[BuyCode],[GoodsState],[PostFee],[Remark],[ErrorInfo],[InDate],[BuyDate],[DoneDate],[Supplier],[SupplierName],[SupplierPhone],[InName],[InUserId],[Account],[IsDelete],[State],[CompanyId],[CheckUid],[CheckContent],[CheckDate],[GoodsNum],[GoodsMoney],[IsFactory],[IsBH],IsGJ,BackDate,TCFee1,TCFee2,TCFee3,TCFee4,TCFee5,TCFee6,TSoild,StoreId)values(@ChaseCode,@BuyCode,@GoodsState,@PostFee,@Remark,@ErrorInfo,@InDate,@BuyDate,@DoneDate,@Supplier,@SupplierName,@SupplierPhone,@InName,@InUserId,@Account,@IsDelete,@State,@CompanyId,@CheckUid,@CheckContent,@CheckDate,@GoodsNum,@GoodsMoney,@IsFactory,@IsBH,@IsGJ,@BackDate,@TCFee1,@TCFee2,@TCFee3,@TCFee4,@TCFee5,@TCFee6,@TSoild,@StoreId) set @ChaseId=@@IDENTITY end select @ChaseId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@ChaseCode", DbType.String, Model.ChaseCode); db.AddInParameter(cmd, "@BuyCode", DbType.String, Model.BuyCode); db.AddInParameter(cmd, "@GoodsState", DbType.Int32, Model.GoodsState); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@BuyDate", DbType.DateTime, Model.BuyDate); db.AddInParameter(cmd, "@DoneDate", DbType.DateTime, Model.DoneDate); db.AddInParameter(cmd, "@Supplier", DbType.String, Model.Supplier); db.AddInParameter(cmd, "@SupplierName", DbType.String, Model.SupplierName); db.AddInParameter(cmd, "@SupplierPhone", DbType.String, Model.SupplierPhone); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@Account", DbType.String, Model.Account); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@CheckUid", DbType.Int32, Model.CheckUid); db.AddInParameter(cmd, "@CheckContent", DbType.String, Model.CheckContent); db.AddInParameter(cmd, "@CheckDate", DbType.DateTime, Model.CheckDate); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsMoney", DbType.Decimal, Model.GoodsMoney); db.AddInParameter(cmd, "@IsFactory", DbType.Int32, Model.IsFactory); db.AddInParameter(cmd, "@IsBH", DbType.Int32, Model.IsBH); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@PostDate", DbType.DateTime, Model.PostDate); db.AddInParameter(cmd, "@IsCheck", DbType.Int32, Model.IsCheck); db.AddInParameter(cmd, "@BackDate", DbType.DateTime, Model.BackDate); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@IsError", DbType.Int32, Model.IsError); db.AddInParameter(cmd, "@IsGJ", DbType.Int32, Model.IsGJ); db.AddInParameter(cmd, "@TCFee1", DbType.Decimal, Model.TCFee1); db.AddInParameter(cmd, "@TCFee2", DbType.Decimal, Model.TCFee2); db.AddInParameter(cmd, "@TCFee3", DbType.Decimal, Model.TCFee3); db.AddInParameter(cmd, "@TCFee4", DbType.Decimal, Model.TCFee4); db.AddInParameter(cmd, "@TCFee5", DbType.Decimal, Model.TCFee5); db.AddInParameter(cmd, "@TCFee6", DbType.Decimal, Model.TCFee6); db.AddInParameter(cmd, "@TSoild", DbType.Decimal, Model.TSoild); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public static List GetListDT_OrderInfoForTM(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 0 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 0 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsName like '%" + GoodsName + "%'"; // else // if (IsSku == 0 && SKU != "") // sql1 = sql1 + " a.DetailId=0"; // else if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId>0"; // else // if (IsSku == 1 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0 and GoodsSKU like '%" + GoodsName + "%'"; // else // if (IsSku == 1 && SKU != "") // sql1 = sql1 + " a.DetailId>0"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 读取首页订单数 public static DT_DefaultDataNew GetDefaultDataForTM2(int CompanyID, DateTime? InDate, DateTime? PreDate, DateTime? SDate, DateTime? EDate) { DT_DefaultDataNew model = null; string tsql = @" declare @Num int,@TotalPrice Decimal(18,2),@SiglePrice Decimal(18,2),@TotalPriceUSD Decimal(18,2),@TotalPriceUSD2 Decimal(18,2),@SiglePriceUSD Decimal(18,2),@BuyMoney Decimal(18,2),@Num2 int,@Num3 int,@Num4 money,@Num5 money,@Num6 money,@Num7 money,@Num9 int,@Num10 money,@Num11 int,@Num12 int,@Num13 int,@Num14 int,@Num15 int,@Num16 int,@Num17 int,@BackPrice Decimal(18,2),@MRate Decimal(18,4),@Num18 int,@Num19 Decimal(18,1),@Num20 Decimal(18,1),@Num21 Decimal(18,1) select @Num=COUNT(*) from DT_OrderInfo with(nolock) where CompanyId=@CompanyID and state>0 and OrderDate>=@SDate and OrderDate<@EDate select @Num12=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and OrderDate>=@SDate and OrderDate<@EDate and b.StoreId=6 select @Num13=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and OrderDate>=@SDate and OrderDate<@EDate and b.StoreId=11 select @Num18=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and OrderDate>=@SDate and OrderDate<@EDate and b.StoreId=5 select @TotalPrice=SUM(RMBPrice),@TotalPriceUSD=SUM(dbo.MoneyUSDChange(TotalPrice,MoneyCode,1)) from DT_OrderInfo with(nolock) where CompanyId=@CompanyID and state>0 and state<3 and OrderDate>=@SDate and OrderDate<@EDate select @TotalPriceUSD2=SUM(dbo.MoneyUSDChange(TotalPrice,MoneyCode,1)) from DT_OrderInfo with(nolock) where CompanyId=@CompanyID and state>0 and state<3 and datediff(day,OrderDate,getdate())=0 select @SiglePrice=@TotalPrice/@Num select @SiglePriceUSD=@TotalPriceUSD/@Num --set @MRate=6.7 --select top 1 @MRate=MRate from JC_Money where MCode='USD' --set @TotalPriceUSD=@TotalPrice/@MRate --set @SiglePriceUSD=@SiglePrice/@MRate select @Num2=COUNT(*) from DT_OrderInfo with(nolock) where CompanyId=@CompanyID and state>0 and state<3 and datediff(day,InDate,@InDate)=0 select @Num14=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and datediff(day,a.InDate,@InDate)=0 and b.StoreId=6 select @Num15=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state>0 and a.state<3 and datediff(day,a.InDate,@InDate)=0 and b.StoreId=11 select @Num3=COUNT(*) from DT_OrderInfo with(nolock) where CompanyId=@CompanyID and state=2 and datediff(day,PostDate,@PreDate)=0 select @Num19=SUM(b.GoodsNum*ISNULL(d.Solid,0)) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=@CompanyID and a.state=2 and datediff(day,PostDate,@PreDate)=0 select @Num16=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state=2 and datediff(day,a.PostDate,@PreDate)=0 and b.StoreId=6 select @Num20=SUM(b.GoodsNum*ISNULL(d.Solid,0)) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=@CompanyID and a.state=2 and datediff(day,PostDate,@PreDate)=0 and e.StoreId=6 select @Num17=COUNT(*) from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and a.state=2 and datediff(day,a.PostDate,@PreDate)=0 and b.StoreId=11 select @Num21=SUM(b.GoodsNum*ISNULL(d.Solid,0)) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyId=@CompanyID and a.state=2 and datediff(day,PostDate,@PreDate)=0 and e.StoreId=11 select @Num10=sum((b.GoodsNum-b.InGoodsNum)*b.GoodsPrice) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.ChaseId where a.IsDelete=0 and a.GoodsState<2 and a.State<3 and b.InGoodsNum-1 select @Num7=SUM(Price*KCNum) from HW_GoodsInDetail with(nolock) where CKDetailId=0 --select @Num9=COUNT(0) from DT_OrderInfoNew where State=1 and FPDate is not null and MoneyState=1 and PostState=0 and BuyDate is not null select @Num9=COUNT(0) from DT_OrderInfoNew with(nolock) where State=1 and PostState=0 select @Num11=COUNT(0) from DT_OrderInfo a with(nolock) inner join DT_OrderBagBack b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and DATEDIFF(day,b.InDate,GETDATE())<=7 select @BackPrice=SUM(a.TotalPrice) from DT_OrderInfo a with(nolock) inner join DT_OrderBagBack b with(nolock) on a.OrderId=b.OrderId where a.CompanyId=@CompanyID and DATEDIFF(day,b.InDate,GETDATE())<=7 select Num=isnull(@Num,0),Num15=isnull(@Num15,0),Num16=isnull(@Num16,0),Num17=isnull(@Num17,0),Num12=isnull(@Num12,0),Num13=isnull(@Num13,0),Num14=isnull(@Num14,0),TotalPrice=isnull(@TotalPrice,0),SiglePrice=isnull(@SiglePrice,0),TotalPriceUSD=isnull(@TotalPriceUSD,0),TotalPriceUSD2=isnull(@TotalPriceUSD2,0),SiglePriceUSD=isnull(@SiglePriceUSD,0),Num2=isnull(@Num2,0),Num3=isnull(@Num3,0),Num4=isnull(@Num4,0),Num5=isnull(@Num5,0),Num6=isnull(@Num6,0),Num7=isnull(@Num7,0),Num9=isnull(@Num9,0),Num10=isnull(@Num10,0),Num11=isnull(@Num11,0),BackPrice=isnull(@BackPrice,0),Num18=isnull(@Num18,0),Num19=isnull(@Num19,0),Num20=isnull(@Num20,0),Num21=isnull(@Num21,0) select top 3 a.RMBPrice,b.ShopName from ( select ShopId,RMBPrice=SUM(RMBPrice) from DT_OrderInfo with(nolock) where State>0 and State<3 and DATEDIFF(day,OrderDate,@PreDate)=0 group by ShopId)a inner join JC_Shop b with(nolock) on a.ShopId=b.ShopId order by a.RMBPrice desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@PreDate", DbType.DateTime, PreDate); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet tb = db.ExecuteDataSet(cmd); if (tb.Tables[0].Rows.Count > 0) model = tb.Tables[0].Rows[0].ToModel(); string shop = ""; if (tb.Tables[1].Rows.Count > 0) { for (int i = 0; i < tb.Tables[1].Rows.Count; i++) { //shop += tb.Tables[1].Rows[i]["ShopName"].ToString() + "【" + tb.Tables[1].Rows[i]["RMBPrice"].ToString() + "】 "; shop += tb.Tables[1].Rows[i]["ShopName"].ToString() + " "; } } model.Num8 = shop.Trim(); return model; } #endregion #region 保存 public static int Save_JZLink(HW_JZLink Model) { string tsql = @" if @Id>0 begin Update [HW_JZLink] set [GoodsId]=@GoodsId,[LinkUrl]=@LinkUrl,[Price]=@Price,[Sort]=@Sort,[Price2]=@Price2,[Price3]=@Price3,[Remark]=@Remark,[Remark2]=@Remark2,[Remark3]=@Remark3,ShopId=@ShopId where Id=@Id end else begin INSERT INTO [HW_JZLink]([GoodsId],[LinkUrl],[Price],[Sort],[Price2],[Price3],[Remark],[Remark2],[Remark3],ShopId)values(@GoodsId,@LinkUrl,@Price,@Sort,@Price2,@Price3,@Remark,@Remark2,@Remark3,@ShopId) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@LinkUrl", DbType.String, Model.LinkUrl); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@Sort", DbType.String, Model.Sort); db.AddInParameter(cmd, "@Price2", DbType.Decimal, Model.Price2); db.AddInParameter(cmd, "@Price3", DbType.Decimal, Model.Price3); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@Remark2", DbType.String, Model.Remark2); db.AddInParameter(cmd, "@Remark3", DbType.String, Model.Remark3); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_JZLink(int Id) { string tsql = @" delete from HW_JZLink where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static HW_JZLink GetModel_JZLink(int Id) { HW_JZLink model = null; //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @" select * from HW_JZLink where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 返回列表 public static List GetListJZLink(int GoodsId, int UserId) { //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @" if @UserId>0 begin select * from HW_JZLink where GoodsId=@GoodsId and shopid in (select ShopId from JC_ShopUser where UserId=@UserId and (SType='M' or SType='S')) end else begin select * from HW_JZLink where GoodsId=@GoodsId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListJZLinkOrder(string OrderIds) { //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @"select distinct d.*,a.OrderId from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId inner join HW_JZLink d with(nolock) on c.GoodsId=d.GoodsId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static int DeletelPostFee(int GoodsId) { string tsql = @" delete from HW_PostFee where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.ExecuteNonQuery(cmd); return 1; } #endregion #region 返回列表 public static HW_PostFee GetModelPostFee(int GoodsId) { HW_PostFee model = null; //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @" select * from HW_PostFee where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 保存 public static int Save_Goods(DD_Goods Model) { string tsql = @" select top 1 @GoodsId=GoodsId from HW_GoodsInfo where GoodsCode=@GoodsCode and CompanyId=1 if @GoodsId>0 and @Id>0 begin update [DD_Goods] set ShopId=@ShopId,GoodsId=@GoodsId,Url=@Url where Id=@Id end else if @GoodsId>0 and (select count(0) from DD_Goods where ShopId=@ShopId and GoodsId=@GoodsId)=0 begin INSERT INTO [DD_Goods]([InDate],[InName],[ShopId],[GoodsId],Url,Url2)values(@InDate,@InName,@ShopId,@GoodsId,@Url,@Url2) set @Id=SCOPE_IDENTITY() end else begin set @Id=0 end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@Url", DbType.String, Model.Url); db.AddInParameter(cmd, "@Url2", DbType.String, Model.Url2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_Goods(int Id) { string tsql = @" delete from DD_Goods where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static DD_Goods GetModel_Goods(int Id) { DD_Goods model = null; //string tsql = "select a.Id,a.InDate,a.InName,a.ShopId,a.GoodsId from DD_Goods"; string tsql = @" select * from DD_Goods where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 分页查询 public static List GetListGoods(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.InDate,a.InName,a.ShopId,a.GoodsId"; ser.Tables = @"DD_Goods a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 多条件普通查询 public static List GetListGoods(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); //ser.Fields = "a.Id,a.InDate,a.InName,a.ShopId,a.GoodsId"; ser.Fields = "a.*"; ser.Tables = @"DD_Goods a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.KeyName = "Id"; ser.Sort = Sort; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoods(int ShopId) { //string tsql = "select a.Id,a.InDate,a.InName,a.ShopId,a.GoodsId from DD_Goods"; string tsql = "select a.GoodsId,b.GoodsCode from DD_Goods a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where a.ShopId=@ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListGoods(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select Id=cast(a.Id as int),a.InDate,a.InName,a.ShopId,a.GoodsId,c.ShopName,b.GoodsCode,a.Url,a.Url2 from DD_Goods a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId inner join JC_Shop c on a.ShopId=c.ShopId"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 判断是否重复 public static bool CheckName_Goods(int Id, string Name) { string tsql = @"select count(0) from DD_Goods where Id<>@Id and Name=@Name"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@Name", DbType.String, Name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a == 0) return true; return false; } #endregion #region 保存 public static int Save_GoodsCodeData(DD_GoodsCodeData Model) { string tsql = @" select @Id=Id from DD_GoodsCodeData where ShopId=@ShopId and GoodsId=@GoodsId and datediff(day,OrderDate,@OrderDate)=0 if @Id>0 begin Update [DD_GoodsCodeData] set [ShopId]=@ShopId,[GoodsId]=@GoodsId,[InDate]=@InDate,[OrderDate]=@OrderDate,[GoodsCode]=@GoodsCode,[Dec1]=@Dec1,[Dec2]=@Dec2,[Dec3]=@Dec3,[Dec4]=@Dec4,[Dec5]=@Dec5,[Dec6]=@Dec6,[Dec7]=@Dec7,[Int1]=@Int1,[Int2]=@Int2,[Int3]=@Int3,[Str1]=@Str1,[Str2]=@Str2,[Str3]=@Str3,[Str4]=@Str4,[Int4]=@Int4,[Int5]=@Int5,[Str5]=@Str5,[Str6]=@Str6,[Str7]=@Str7,[Str8]=@Str8,[Str9]=@Str9,[Str10]=@Str10,[Int6]=@Int6,[Int7]=@Int7,[Int8]=@Int8,[Int9]=@Int9,[Int10]=@Int10,[Dec8]=@Dec8,[Dec9]=@Dec9,[Dec10]=@Dec10 where Id=@Id end else begin INSERT INTO [DD_GoodsCodeData]([ShopId],[GoodsId],[InDate],[OrderDate],[GoodsCode],[Dec1],[Dec2],[Dec3],[Dec4],[Dec5],[Dec6],[Dec7],[Int1],[Int2],[Int3],[Str1],[Str2],[Str3],[Str4],[Int4],[Int5],[Str5],[Str6],[Str7],[Str8],[Str9],[Str10],[Int6],[Int7],[Int8],[Int9],[Int10],[Dec8],[Dec9],[Dec10])values(@ShopId,@GoodsId,@InDate,@OrderDate,@GoodsCode,@Dec1,@Dec2,@Dec3,@Dec4,@Dec5,@Dec6,@Dec7,@Int1,@Int2,@Int3,@Str1,@Str2,@Str3,@Str4,@Int4,@Int5,@Str5,@Str6,@Str7,@Str8,@Str9,@Str10,@Int6,@Int7,@Int8,@Int9,@Int10,@Dec8,@Dec9,@Dec10) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@Dec1", DbType.Decimal, Model.Dec1); db.AddInParameter(cmd, "@Dec2", DbType.Decimal, Model.Dec2); db.AddInParameter(cmd, "@Dec3", DbType.Decimal, Model.Dec3); db.AddInParameter(cmd, "@Dec4", DbType.Decimal, Model.Dec4); db.AddInParameter(cmd, "@Dec5", DbType.Decimal, Model.Dec5); db.AddInParameter(cmd, "@Dec6", DbType.Decimal, Model.Dec6); db.AddInParameter(cmd, "@Dec7", DbType.Decimal, Model.Dec7); db.AddInParameter(cmd, "@Int1", DbType.Int32, Model.Int1); db.AddInParameter(cmd, "@Int2", DbType.Int32, Model.Int2); db.AddInParameter(cmd, "@Int3", DbType.Int32, Model.Int3); db.AddInParameter(cmd, "@Str1", DbType.String, Model.Str1); db.AddInParameter(cmd, "@Str2", DbType.String, Model.Str2); db.AddInParameter(cmd, "@Str3", DbType.String, Model.Str3); db.AddInParameter(cmd, "@Str4", DbType.String, Model.Str4); db.AddInParameter(cmd, "@Int4", DbType.Int32, Model.Int4); db.AddInParameter(cmd, "@Int5", DbType.Int32, Model.Int5); db.AddInParameter(cmd, "@Str5", DbType.String, Model.Str5); db.AddInParameter(cmd, "@Str6", DbType.String, Model.Str6); db.AddInParameter(cmd, "@Str7", DbType.String, Model.Str7); db.AddInParameter(cmd, "@Str8", DbType.String, Model.Str8); db.AddInParameter(cmd, "@Str9", DbType.String, Model.Str9); db.AddInParameter(cmd, "@Str10", DbType.String, Model.Str10); db.AddInParameter(cmd, "@Int6", DbType.Int32, Model.Int6); db.AddInParameter(cmd, "@Int7", DbType.Int32, Model.Int7); db.AddInParameter(cmd, "@Int8", DbType.Int32, Model.Int8); db.AddInParameter(cmd, "@Int9", DbType.Int32, Model.Int9); db.AddInParameter(cmd, "@Int10", DbType.Int32, Model.Int10); db.AddInParameter(cmd, "@Dec8", DbType.Decimal, Model.Dec8); db.AddInParameter(cmd, "@Dec9", DbType.Decimal, Model.Dec9); db.AddInParameter(cmd, "@Dec10", DbType.Decimal, Model.Dec10); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_GoodsCodeData(int Id) { string tsql = @" delete from DD_GoodsCodeData where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static DD_GoodsCodeData GetModel_GoodsCodeData(int Id) { DD_GoodsCodeData model = null; //string tsql = "select a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4 from DD_GoodsCodeData"; string tsql = @" select * from DD_GoodsCodeData where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 分页查询 public static List GetListGoodsCodeData(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4"; ser.Tables = @"DD_GoodsCodeData a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 多条件普通查询 public static List GetListGoodsCodeData(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); //ser.Fields = "a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4"; ser.Fields = "a.*"; ser.Tables = @"DD_GoodsCodeData a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.KeyName = "Id"; ser.Sort = Sort; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListGoodsCodeData(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select Id=cast(a.Id as int),a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4,a.Int4,a.Int5,a.Str5,a.Str6,a.Str7,a.Str8,a.Str9,a.Str10,a.Int6,a.Int7,a.Int8,a.Int9,a.Int10,a.Dec8,a.Dec9,a.Dec10 from DD_GoodsCodeData a"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 判断是否重复 public static bool CheckName_GoodsCodeData(int Id, string Name) { string tsql = @"select count(0) from DD_GoodsCodeData where Id<>@Id and Name=@Name"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.AddInParameter(cmd, "@Name", DbType.String, Name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a == 0) return true; return false; } #endregion #region 计算数据 public static void SumGoodsCodeData() { string tsql = @"select OrderDate=convert(nvarchar(10),OrderDate,120),b.ShopId,c.GoodsId,GoodsNum=SUM(a.GoodsNum),GoodsPrice=SUM(isnull(a.GoodsPrice,b.TotalPrice)) into #GoodsData from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where DATEDIFF(day,b.OrderDate,GETDATE())<30 group by convert(nvarchar(10),OrderDate,120),b.ShopId,c.GoodsId update b set b.dec2=a.GoodsPrice,b.int4=a.GoodsNum from #GoodsData a inner join DD_GoodsCodeData b on a.shopid=b.ShopId and a.GoodsId=b.GoodsId and DATEDIFF(DAY,a.OrderDate,b.OrderDate)=0 drop table #GoodsData"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListGoodsCodeData(DateTime SDate, DateTime EDate, int GoodsId) { //string tsql = "select a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4 from DD_GoodsCodeData"; string tsql = "select * from DD_GoodsCodeData where GoodsId=@GoodsId and OrderDate>=@SDate and OrderDate<@EDate order by OrderDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsCodeData2(DateTime SDate, DateTime EDate, int GoodsId) { //string tsql = "select a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4 from DD_GoodsCodeData"; string tsql = "select a.*,b.ShopName from DD_GoodsCodeData a inner join jc_shop b on a.shopid=b.shopid where (@GoodsId=-1 or a.GoodsId=@GoodsId) and a.OrderDate>=@SDate and a.OrderDate<@EDate order by a.GoodsId,a.OrderDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询库存 public static List GetList_GoodsLeftPostion(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.GoodsId,e.StoreName,d.PostionCode,c.GoodsCode,a.GoodsNum,a.Soild,c.GoodsName"; ser.Tables = @"(select a.StoreId,a.PostionId,c.GoodsId,GoodsNum=sum(KCNum),Soild=SUM(isnull(c.Solid,0)*a.KCNum) from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderGoodsId=0 and a.KCNum>0 group by a.StoreId,a.PostionId,c.GoodsId)a inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId inner join CK_StoreHouse e on d.StoreId=e.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.PostionId,a.GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 读取菜单 public static List GetListMenuNew(int UserID, int CompanyId) { string tsql = @" declare @UserType nvarchar(10) select top 1 @UserType=UserType from JC_UserInfo where UserID=@UserID if @UserType='S' or @UserType='M' begin select * from JC_MenuList where IsUse=1 and id not in (select id from JC_MenuList where CompanyId is not null and CompanyId<>@CompanyId) order by SortNo end else begin if(select COUNT(0) from JC_RoleInfo a inner join JC_RoleUser b on a.RoleId=b.RoleId inner join JC_RoleMenu c on a.RoleId=c.RoleID where b.UserId=@UserID)>0 begin select * from JC_MenuList where IsUse=1 and ModuleNo in ( select distinct c.ModuleNo from JC_RoleInfo a inner join JC_RoleUser b on a.RoleId=b.RoleId inner join JC_RoleMenu c on a.RoleId=c.RoleID where b.UserId=@UserID and c.PopedomType>0) order by SortNo end else begin select *,css='ico_edit' from JC_MenuList where IsUse=1 and PopedomType>0 order by SortNo end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserID", DbType.Int32, UserID); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 登录 public static UserModel PdaLogin(string UserName, string PassWord) { string tsql = @" declare @UserID int,@Name nvarchar(20),@UserType nvarchar(5) select top 1 @UserID=UserID from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserName=@UserName and a.PassWord=@PassWord and a.State=1 and b.State=1 select a.UserId,a.Name from JC_UserInfo a inner join JC_Company b on a.CompanyId=b.CompanyId where a.UserID=@UserID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, UserName); db.AddInParameter(cmd, "@PassWord", DbType.String, PassWord); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } #endregion #region 登录 public static UserModel PdaSacnLogin(string UserCode) { string tsql = @" select a.UserId,a.Name,case when a.WorkDesc='东仓' then 'E' when a.WorkDesc='西仓' then 'W' else '' end WorkDesc from JC_UserInfo a where a.UserCode=@UserCode and state=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserCode", DbType.String, UserCode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } #endregion #region 删除海外仓 /// /// 删除海外仓 /// public static int DeleteHWCGoods(int ChaseId) { string tsql = @" update b set b.TJOutNum=b.TJOutNum-a.SJOutNum from CG_PurchaseGoods a inner join CG_PurchaseGoods b on a.OldId=b.Id where a.GJChaseId=@ChaseId delete from CG_Purchase where ChaseId=@ChaseId update CG_PurchaseGoods set SJOutNum=0,PState=0,GJChaseId=0 where GJChaseId=@ChaseId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, ChaseId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region /// /// /// public static int UpdateOrderTrackState() { string tsql = @" update b set b.TrackState=1 from DT_OrderInfoNew a inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId where b.TrackState=0 and a.JoinOrderCode in ( select distinct JoinOrderCode from DT_OrderInfoNew a inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId where IsJoin=1 and b.TrackState=1) update b set b.TrackState=1 from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where b.TrackState=0 and a.JoinOrderCode in ( select distinct JoinOrderCode from DT_OrderInfoNew a inner join DT_OrderXXInfoNew b on a.OrderId=b.OrderId where IsJoin=1 and b.TrackState=1) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListGoodsCodeData3(int ShopId, string GoodsCode, DateTime? SDate, int UserId) { //string tsql = "select a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4,a.Int4,a.Int5,a.Str5,a.Str6,a.Str7,a.Str8,a.Str9,a.Str10,a.Int6,a.Int7,a.Int8,a.Int9,a.Int10,a.Dec8,a.Dec9,a.Dec10 from DD_GoodsCodeData"; string tsql = @"select d.Url,c.ShopName,b.GoodsCode,d.InName,a.Id,ShopId=d.ShopId,GoodsId=d.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4,a.Int4,a.Int5,a.Str5,a.Str6,a.Str7,a.Str8,a.Str9,a.Str10,a.Int6,a.Int7,a.Int8,a.Int9,a.Int10,a.Dec8,a.Dec9,a.Dec10 from DD_Goods d inner join HW_GoodsInfo b on d.GoodsId=b.GoodsId inner join JC_Shop c on d.ShopId=c.ShopId left join ( select * from DD_GoodsCodeData where DATEDIFF(day,Orderdate,@SDate)=0)a on d.ShopId=a.ShopId and d.GoodsId=a.GoodsId where (@ShopId=0 or d.ShopId=@ShopId) and (@GoodsCode='' or b.GoodsCode like '%'+@GoodsCode+'%') order by d.ShopId,d.GoodsId "; if (UserId > 1 && UserId != 48) { tsql = @"select d.Url,c.ShopName,b.GoodsCode,d.InName,a.Id,ShopId=d.ShopId,GoodsId=d.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4,a.Int4,a.Int5,a.Str5,a.Str6,a.Str7,a.Str8,a.Str9,a.Str10,a.Int6,a.Int7,a.Int8,a.Int9,a.Int10,a.Dec8,a.Dec9,a.Dec10 from DD_Goods d inner join HW_GoodsInfo b on d.GoodsId=b.GoodsId inner join JC_Shop c on d.ShopId=c.ShopId left join ( select * from DD_GoodsCodeData where DATEDIFF(day,Orderdate,@SDate)=0)a on d.ShopId=a.ShopId and d.GoodsId=a.GoodsId where (@ShopId=0 or d.ShopId=@ShopId) and d.shopid in (select ShopId from JC_ShopUser where UserId=@UserId and (SType='M' or SType='S')) and (@GoodsCode='' or b.GoodsCode like '%'+@GoodsCode+'%') order by d.ShopId,d.GoodsId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回Model public static DD_Goods GetModel_GoodsCodeDataUrl(int ShopId, string GoodsCode) { DD_Goods model = null; //string tsql = "select a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4 from DD_GoodsCodeData"; string tsql = @" select top 1 URL=a.productImgUrl from DT_OrderGoods a inner join DT_OrderInfo b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where b.PlatId=2 and d.GoodsCode=@GoodsCode and b.ShopId=@ShopId order by a.Id desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 返回列表 public static List GetListGoodsNum(int Num, string ChaseCode, string GoodsCode) { //string tsql = "select a.Id,a.ShopId,a.GoodsId,a.InDate,a.OrderDate,a.GoodsCode,a.Dec1,a.Dec2,a.Dec3,a.Dec4,a.Dec5,a.Dec6,a.Dec7,a.Int1,a.Int2,a.Int3,a.Str1,a.Str2,a.Str3,a.Str4,a.Int4,a.Int5,a.Str5,a.Str6,a.Str7,a.Str8,a.Str9,a.Str10,a.Int6,a.Int7,a.Int8,a.Int9,a.Int10,a.Dec8,a.Dec9,a.Dec10 from DD_GoodsCodeData"; string tsql = @"select b.Id,GoodsOldCode=a.BuyCode,b.GoodsCode,GoodsName=c.SKU1,b.GoodsNum,b.InGoodsNum,OutNum=isnull(b.TJOutNum,0),GoodsLeftNum=b.GoodsNum-isnull(b.InGoodsNum,0)-isnull(b.TJOutNum,0) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c ON b.GoodsDetailId=c.DetailId where b.GoodsNum-isnull(b.InGoodsNum,0)-isnull(b.TJOutNum,0)>0 and (@ChaseCode='' or a.BuyCode=@ChaseCode) and (@GoodsCode='' or b.GoodsCode like '%'+@GoodsCode+'%' or c.SKU1 like '%'+@GoodsCode+'%') order by a.ChaseCode,b.GoodsCode "; if (Num == 0) tsql = @"select b.Id,GoodsOldCode=a.BuyCode,b.GoodsCode,GoodsName=c.SKU1,b.GoodsNum,b.InGoodsNum,OutNum=isnull(b.TJOutNum,0),GoodsLeftNum=b.GoodsNum-isnull(b.InGoodsNum,0)-isnull(b.TJOutNum,0) from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c ON b.GoodsDetailId=c.DetailId where (@ChaseCode='' or a.BuyCode=@ChaseCode) and (@GoodsCode='' or b.GoodsCode like '%'+@GoodsCode+'%' or c.SKU1 like '%'+@GoodsCode+'%') order by a.ChaseCode,b.GoodsCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ChaseCode", DbType.String, ChaseCode); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_PurchaseGoods(CG_PurchaseGoods Model) { string tsql = @" if @Id>0 begin Update [CG_PurchaseGoods] set [GoodsNum]=@GoodsNum,[InGoodsNum]=@InGoodsNum,[TJOutNum]=@TJOutNum where Id=@Id end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ChaseId", DbType.Int32, Model.ChaseId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsDetailId", DbType.Int32, Model.GoodsDetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, Model.GoodsPrice); db.AddInParameter(cmd, "@LockNum", DbType.Int32, Model.LockNum); db.AddInParameter(cmd, "@IsOrder", DbType.Int32, Model.IsOrder); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InGoodsNum", DbType.Int32, Model.InGoodsNum); db.AddInParameter(cmd, "@TJOutNum", DbType.Int32, Model.OutNum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static void UpdateCGStoreNum() { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("UpdateCGStoreNum"); db.ExecuteNonQuery(cmd); } #endregion #region 查询货物链接列表 public static List GetGoodsBuyLink(int GoodsId, int UserId) { List list = null; string tsql = @" if(select count(0) from HW_BuyLink a inner join JC_Shop b on a.LinkDesc=b.ShopName where GoodsId=@GoodsId)=0 begin select * from HW_BuyLink where GoodsId=@GoodsId end else if @UserId>1 begin select * from HW_BuyLink where GoodsId=@GoodsId and LinkDesc in (select b.ShopName from JC_ShopUser a inner join JC_Shop b on a.ShopId=b.ShopId where UserId=@UserId and (SType='M' or SType='S')) end else begin select * from HW_BuyLink where GoodsId=@GoodsId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 设置不允许发货 public static void SetNoPost(int OrderId, int PostState) { string tsql = @"update DT_OrderInfo set PostState=@PostState where OrderId=@OrderId update DT_OrderInfoNew set PostState=@PostState where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostState", DbType.Int32, PostState); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListDT_OrderInfoForTM2_New(int CompanyId, string MName, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount, string groupName = "") { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; //if (MName != "") // NoGoodsSql += " and isnull(c.MName,'')='" + MName + "'"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods with (nolock) where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (sql1 == "" && ((IsDH > -1) || MName != "" || groupName != "")) { sql1 = @"select distinct z.OrderId into #OrderTemp from ( select b.OrderId,b.muserid,u.Name as MName, u.GroupName from ( select a.OrderId , case when d.PlatId=2 then muserid when d.PlatId=3 then guserid_ebay when d.PlatId=6 then guserid_wlmart when d.PlatId=15 then guserid_shopify when d.PlatId=18 then guserid_wayfair when d.PlatId=21 then guserid_sheIn when d.PlatId=22 then guserid_tiktok when d.PlatId=23 then guserid_temu end muserid from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId inner join DT_OrderInfo d with (nolock) on a.OrderId=d.OrderId where c.CompanyId=1 " + NoGoodsSql + " ) b left join JC_UserInfo u on b.muserid=u.UserId ) z where 1=1 "; //添加组长筛选 if (!string.IsNullOrEmpty(MName)) sql1 = sql1 + " and z.MName='" + MName + "'"; if (!string.IsNullOrEmpty(groupName)) sql1 = sql1 + " and z.groupname='" + groupName + "'"; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee,a.OrderOutDate,SaleUserId=a.WLSS,a.RevAddr,a.RevCity,a.RevPostCode,a.RevMoblie,a.RevPhone,a.RevCountry,a.StoreId,a.UpsFeeR,a.UpsFeeE,a.Fee11,a.Fee12,a.Fee13,a.RevFax as AddressType"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListDT_OrderInfoForTM2(int CompanyId, string MName, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (MName != "") NoGoodsSql += " and isnull(c.MName,'')='" + MName + "'"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods with (nolock) where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (sql1 == "" && ((IsDH > -1) || MName != "")) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee,a.OrderOutDate,SaleUserId=a.WLSS,a.RevAddr,a.RevCity,a.RevPostCode,a.RevMoblie,a.RevPhone,a.RevCountry,a.StoreId"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListDT_OrderInfoForTM222(int CompanyId, string GoodsName, string KTSKU, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string sql2 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and c.GoodsCode like '" + KTSKU + "%' and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods with (nolock) where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; sql2 = @" select a.OrderId into #OrderTemp2 from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.GoodsCode like '" + KTSKU + "%' "; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with (nolock) on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee,a.OrderOutDate,SaleUserId=a.WLSS"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join #OrderTemp2 d on a.orderid=d.orderid inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp2 b on a.orderid=b.orderid inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "" || sql2 != "") tsql = sql1 + sql2 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int UpdateGoodsBox(int GoodsId, int BoxNum, string BoxStoreCode) { string tsql = @" Update [CG_PurchaseGoods] set [BoxNum]=@BoxNum,[BoxStoreCode]=@BoxStoreCode where GoodsId=@GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@BoxNum", DbType.Int32, BoxNum); db.AddInParameter(cmd, "@BoxStoreCode", DbType.String, BoxStoreCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回货物Model public static HW_GoodsNew GetGoodsModelNew(int GoodsId) { HW_GoodsNew model = null; string tsql = "select * from HW_GoodsInfo where GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 保存 public static int Save_BlackName(DT_BlackName Model) { string tsql = @" if @id>0 begin Update [DT_BlackName] set [RevName]=@RevName,[RevCountry]=@RevCountry,[RevProvince]=@RevProvince,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevCity]=@RevCity,[orderid]=@orderid,[userid]=@userid where id=@id end else begin INSERT INTO [DT_BlackName]([RevName],[RevCountry],[RevProvince],[RevAddr],[RevPhone],[RevMoblie],[RevCity],[orderid],[userid])values(@RevName,@RevCountry,@RevProvince,@RevAddr,@RevPhone,@RevMoblie,@RevCity,@orderid,@userid) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@orderid", DbType.String, Model.orderid); db.AddInParameter(cmd, "@userid", DbType.Int32, Model.userid); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页动态条件查询 public static List GetListBlackName(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select id=cast(a.id as int),a.RevName,a.RevCountry,a.RevProvince,a.RevAddr,a.RevPhone,a.RevMoblie,a.RevCity,a.orderid,a.userid,c.ShopName from DT_BlackName a with(nolock) inner join DT_OrderInfo b with(nolock) on a.orderid=b.PlatOrderCode inner join JC_Shop c with(nolock) on b.ShopId=c.ShopId "; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 删除 public static void Delete_BlackName(int id) { string tsql = @" delete from DT_BlackName where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Delete_PostVote(int OrderId) { string tsql = @" declare @Id int select top 1 @Id=Id from DT_PostVote where OrderId=@OrderId delete from DT_PostVote where Id=@Id delete from DT_PostVoteDetail where mid=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Delete_PostVoteDetail(int Id) { string tsql = @" delete from DT_PostVoteDetail where mid=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static DT_PostVote GetModel_PostVote(int OrderId) { DT_PostVote model = null; //string tsql = "select a.Id,a.OrderId,a.trackcode,a.ActualWeightAmount,a.ActualWeightUnits,a.RatedWeightAmount,a.DimLength,a.DimWidth,a.DimHeight,a.DimDivisor,a.DimUnit,a.ZoneCode,a.bigdifference,a.result,a.sku,a.indate,a.inname,a.fee1,a.fee2,a.fee3,a.fee4,a.fee5,a.int1,a.int2,a.int3,a.str1,a.str2,a.str3 from DT_PostVote"; string tsql = @" declare @Id int select top 1 @Id=Id from DT_PostVote where OrderId=@OrderId select * from DT_PostVote where Id=@Id select * from DT_PostVoteDetail where mid=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); model.list = ds.Tables[1].ToList(); } return model; } #endregion #region 返回Model public static DT_PostVote GetModel_PostVote2(int Id) { DT_PostVote model = null; //string tsql = "select a.Id,a.OrderId,a.trackcode,a.ActualWeightAmount,a.ActualWeightUnits,a.RatedWeightAmount,a.DimLength,a.DimWidth,a.DimHeight,a.DimDivisor,a.DimUnit,a.ZoneCode,a.bigdifference,a.result,a.sku,a.indate,a.inname,a.fee1,a.fee2,a.fee3,a.fee4,a.fee5,a.int1,a.int2,a.int3,a.str1,a.str2,a.str3 from DT_PostVote"; string tsql = @" select * from DT_PostVote where Id=@Id select * from DT_PostVoteDetail where mid=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); model.list = ds.Tables[1].ToList(); } return model; } #endregion #region 保存 public static int Save_PostVote(DT_PostVote Model) { string tsql = @" select top 1 @Id=Id from DT_PostVote where OrderId=@OrderId if @Id>0 begin Update [DT_PostVote] set [OrderId]=@OrderId,[trackcode]=@trackcode,[ActualWeightAmount]=@ActualWeightAmount,[ActualWeightUnits]=@ActualWeightUnits,[RatedWeightAmount]=@RatedWeightAmount,[RatedWeightUnits]=@RatedWeightUnits,[DimLength]=@DimLength,[DimWidth]=@DimWidth,[DimHeight]=@DimHeight,[DimDivisor]=@DimDivisor,[DimUnit]=@DimUnit,[ZoneCode]=@ZoneCode,[bigdifference]=@bigdifference,[result]=@result,[sku]=@sku,[inname]=@inname,[fee1]=@fee1,[fee2]=@fee2,[fee3]=@fee3,[fee4]=@fee4,[fee5]=@fee5,[int1]=@int1,[int2]=@int2,[int3]=@int3,[str1]=@str1,[str2]=@str2,[str3]=@str3,[NetChargeAmount]=@NetChargeAmount,[estimatefee]=@estimatefee where Id=@Id delete from DT_PostVoteDetail where mid=@Id end else begin INSERT INTO [DT_PostVote]([OrderId],[trackcode],[ActualWeightAmount],[ActualWeightUnits],[RatedWeightAmount],[RatedWeightUnits],[DimLength],[DimWidth],[DimHeight],[DimDivisor],[DimUnit],[ZoneCode],[bigdifference],[result],[sku],[indate],[inname],[fee1],[fee2],[fee3],[fee4],[fee5],[int1],[int2],[int3],[str1],[str2],[str3],[NetChargeAmount],[estimatefee])values(@OrderId,@trackcode,@ActualWeightAmount,@ActualWeightUnits,@RatedWeightAmount,@RatedWeightUnits,@DimLength,@DimWidth,@DimHeight,@DimDivisor,@DimUnit,@ZoneCode,@bigdifference,@result,@sku,@indate,@inname,@fee1,@fee2,@fee3,@fee4,@fee5,@int1,@int2,@int3,@str1,@str2,@str3,@NetChargeAmount,@estimatefee) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@trackcode", DbType.String, Model.trackcode); db.AddInParameter(cmd, "@ActualWeightAmount", DbType.Decimal, Model.ActualWeightAmount); db.AddInParameter(cmd, "@ActualWeightUnits", DbType.String, Model.ActualWeightUnits); db.AddInParameter(cmd, "@RatedWeightAmount", DbType.Decimal, Model.RatedWeightAmount); db.AddInParameter(cmd, "@RatedWeightUnits", DbType.String, Model.RatedWeightUnits); db.AddInParameter(cmd, "@DimLength", DbType.Decimal, Model.DimLength); db.AddInParameter(cmd, "@DimWidth", DbType.Decimal, Model.DimWidth); db.AddInParameter(cmd, "@DimHeight", DbType.Decimal, Model.DimHeight); db.AddInParameter(cmd, "@DimDivisor", DbType.Decimal, Model.DimDivisor); db.AddInParameter(cmd, "@DimUnit", DbType.String, Model.DimUnit); db.AddInParameter(cmd, "@ZoneCode", DbType.Decimal, Model.ZoneCode); db.AddInParameter(cmd, "@bigdifference", DbType.Decimal, Model.bigdifference); db.AddInParameter(cmd, "@result", DbType.String, Model.result); db.AddInParameter(cmd, "@sku", DbType.String, Model.sku); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@fee1", DbType.Decimal, Model.fee1); db.AddInParameter(cmd, "@fee2", DbType.Decimal, Model.fee2); db.AddInParameter(cmd, "@fee3", DbType.Decimal, Model.fee3); db.AddInParameter(cmd, "@fee4", DbType.Decimal, Model.fee4); db.AddInParameter(cmd, "@fee5", DbType.Decimal, Model.fee5); db.AddInParameter(cmd, "@int1", DbType.Int32, Model.int1); db.AddInParameter(cmd, "@int2", DbType.Int32, Model.int2); db.AddInParameter(cmd, "@int3", DbType.Int32, Model.int3); db.AddInParameter(cmd, "@str1", DbType.String, Model.str1); db.AddInParameter(cmd, "@str2", DbType.String, Model.str2); db.AddInParameter(cmd, "@str3", DbType.String, Model.str3); db.AddInParameter(cmd, "@NetChargeAmount", DbType.Decimal, Model.NetChargeAmount); db.AddInParameter(cmd, "@estimatefee", DbType.Decimal, Model.estimatefee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); tsql = @"INSERT INTO [DT_PostVoteDetail]([mid],[TrackingIDChargDescription],[TrackingIDChargeAmount])values(@mid,@TrackingIDChargDescription,@TrackingIDChargeAmount)"; cmd = db.GetSqlStringCommand(tsql); foreach (var item in Model.list) { cmd.Parameters.Clear(); db.AddInParameter(cmd, "@mid", DbType.Int32, a); db.AddInParameter(cmd, "@TrackingIDChargDescription", DbType.String, item.TrackingIDChargDescription); db.AddInParameter(cmd, "@TrackingIDChargeAmount", DbType.Decimal, item.TrackingIDChargeAmount); db.ExecuteNonQuery(cmd); } return a; } #endregion #region 保存 public static int Save_PostVote3(DT_PostVote Model) { string tsql = @" select top 1 @OrderId=OrderId from DT_TrackCodeApply where State=1 and TrackCode=@trackcode if @OrderId>0 begin update DT_OrderInfo set WLSS=1 where OrderId=@OrderId select top 1 @Id=Id from DT_PostVote where OrderId=@OrderId if @Id>0 begin Update [DT_PostVote] set [OrderId]=@OrderId,[trackcode]=@trackcode,[ActualWeightAmount]=@ActualWeightAmount,[ActualWeightUnits]=@ActualWeightUnits,[RatedWeightAmount]=@RatedWeightAmount,[RatedWeightUnits]=@RatedWeightUnits,[DimLength]=@DimLength,[DimWidth]=@DimWidth,[DimHeight]=@DimHeight,[DimDivisor]=@DimDivisor,[DimUnit]=@DimUnit,[ZoneCode]=@ZoneCode,[bigdifference]=@bigdifference,[result]=@result,[sku]=@sku,[inname]=@inname,[fee1]=@fee1,[fee2]=@fee2,[fee3]=@fee3,[fee4]=@fee4,[fee5]=@fee5,[int1]=@int1,[int2]=@int2,[int3]=@int3,[str1]=@str1,[str2]=@str2,[str3]=@str3,[NetChargeAmount]=@NetChargeAmount,[estimatefee]=@estimatefee where Id=@Id delete from DT_PostVoteDetail where mid=@Id end else begin INSERT INTO [DT_PostVote]([OrderId],[trackcode],[ActualWeightAmount],[ActualWeightUnits],[RatedWeightAmount],[RatedWeightUnits],[DimLength],[DimWidth],[DimHeight],[DimDivisor],[DimUnit],[ZoneCode],[bigdifference],[result],[sku],[indate],[inname],[fee1],[fee2],[fee3],[fee4],[fee5],[int1],[int2],[int3],[str1],[str2],[str3],[NetChargeAmount],[estimatefee])values(@OrderId,@trackcode,@ActualWeightAmount,@ActualWeightUnits,@RatedWeightAmount,@RatedWeightUnits,@DimLength,@DimWidth,@DimHeight,@DimDivisor,@DimUnit,@ZoneCode,@bigdifference,@result,@sku,@indate,@inname,@fee1,@fee2,@fee3,@fee4,@fee5,@int1,@int2,@int3,@str1,@str2,@str3,@NetChargeAmount,@estimatefee) set @Id=SCOPE_IDENTITY() end select @Id end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@trackcode", DbType.String, Model.trackcode); db.AddInParameter(cmd, "@ActualWeightAmount", DbType.Decimal, Model.ActualWeightAmount); db.AddInParameter(cmd, "@ActualWeightUnits", DbType.String, Model.ActualWeightUnits); db.AddInParameter(cmd, "@RatedWeightAmount", DbType.Decimal, Model.RatedWeightAmount); db.AddInParameter(cmd, "@RatedWeightUnits", DbType.String, Model.RatedWeightUnits); db.AddInParameter(cmd, "@DimLength", DbType.Decimal, Model.DimLength); db.AddInParameter(cmd, "@DimWidth", DbType.Decimal, Model.DimWidth); db.AddInParameter(cmd, "@DimHeight", DbType.Decimal, Model.DimHeight); db.AddInParameter(cmd, "@DimDivisor", DbType.Decimal, Model.DimDivisor); db.AddInParameter(cmd, "@DimUnit", DbType.String, Model.DimUnit); db.AddInParameter(cmd, "@ZoneCode", DbType.Decimal, Model.ZoneCode); db.AddInParameter(cmd, "@bigdifference", DbType.Decimal, Model.bigdifference); db.AddInParameter(cmd, "@result", DbType.String, Model.result); db.AddInParameter(cmd, "@sku", DbType.String, Model.sku); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@fee1", DbType.Decimal, Model.fee1); db.AddInParameter(cmd, "@fee2", DbType.Decimal, Model.fee2); db.AddInParameter(cmd, "@fee3", DbType.Decimal, Model.fee3); db.AddInParameter(cmd, "@fee4", DbType.Decimal, Model.fee4); db.AddInParameter(cmd, "@fee5", DbType.Decimal, Model.fee5); db.AddInParameter(cmd, "@int1", DbType.Int32, Model.int1); db.AddInParameter(cmd, "@int2", DbType.Int32, Model.int2); db.AddInParameter(cmd, "@int3", DbType.Int32, Model.int3); db.AddInParameter(cmd, "@str1", DbType.String, Model.str1); db.AddInParameter(cmd, "@str2", DbType.String, Model.str2); db.AddInParameter(cmd, "@str3", DbType.String, Model.str3); db.AddInParameter(cmd, "@NetChargeAmount", DbType.Decimal, Model.NetChargeAmount); db.AddInParameter(cmd, "@estimatefee", DbType.Decimal, Model.estimatefee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.list != null && Model.list.Count > 0) { tsql = @"INSERT INTO [DT_PostVoteDetail]([mid],[TrackingIDChargDescription],[TrackingIDChargeAmount])values(@mid,@TrackingIDChargDescription,@TrackingIDChargeAmount)"; cmd = db.GetSqlStringCommand(tsql); foreach (var item in Model.list) { cmd.Parameters.Clear(); db.AddInParameter(cmd, "@mid", DbType.Int32, a); db.AddInParameter(cmd, "@TrackingIDChargDescription", DbType.String, item.TrackingIDChargDescription); db.AddInParameter(cmd, "@TrackingIDChargeAmount", DbType.Decimal, item.TrackingIDChargeAmount); db.ExecuteNonQuery(cmd); } } return a; } #endregion #region 保存 public static int Save_OrderFee(string OrderCode, decimal FactOrderFee, decimal FactOrderCommison, decimal FactOrderFax) { string tsql = @" update DT_OrderInfo set FactOrderFee=@FactOrderFee,FactOrderCommison=@FactOrderCommison,FactOrderFax=@FactOrderFax where PlatOrderCode=@PlatOrderCode select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@FactOrderFee", DbType.Decimal, FactOrderFee); db.AddInParameter(cmd, "@FactOrderCommison", DbType.String, FactOrderCommison); db.AddInParameter(cmd, "@FactOrderFax", DbType.Decimal, FactOrderFax); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 修改订单状态 public static void UpdateOrderWLSS(int orderid, int WLSS) { string tsql = @" update DT_OrderInfo set WLSS=@WLSS where orderid=@orderid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.AddInParameter(cmd, "@WLSS", DbType.Int32, WLSS); db.ExecuteNonQuery(cmd); } #endregion #region 查询货物链接列表 public static List GetGoodsLink(int Num) { List list = null; string tsql = @" SELECT top " + Num + @" Url,a.GoodsId,a.ShopId,a.Id from DD_Goods a left join DD_GoodsCodeData b on a.GoodsId=b.GoodsId and a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,getdate())=0 where isnull(a.sync,0)=0 and Url is not null and Url<>'' and b.Id is null "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物链接列表 public static List GetGoodsLink2(int Num) { List list = null; string tsql = @" SELECT top " + Num + @" Url=a.[asin],a.GoodsId,a.ShopId,a.Id,c.Appkey,c.DeveKey,c.AccessToken,c.RefreshToken,c.Country,c.Code from [DD_GoodsPM] a with(nolock) left join jc_shop c with(nolock) on a.shopid=c.shopid --left join DD_GoodsCodeData b with(nolock) on a.GoodsId=b.GoodsId and a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,getdate())=0 where c.PlatType=2 and isnull(a.sync,0)=0 order by a.shopid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物排名趋势 public static List GetGoodsLinkPM(int GoodsId, int ShopId, DateTime SDate, DateTime EDate) { List list = null; string tsql = @" select * from DD_GoodsCodeData with(nolock) where Int2>0 and ShopId=@ShopId and GoodsId=@GoodsId and InDate>=@SDate and InDate<@EDate order by InDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物排名趋势 public static List GetGoodsLinkPMForAsin(string ASIN, int ShopId, DateTime SDate, DateTime EDate) { List list = null; string tsql = @" select * from DD_GoodsCodeData with(nolock) where Int2>0 and ShopId=@ShopId and asin=@ASIN and InDate>=@SDate and InDate<@EDate order by InDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@ASIN", DbType.String, ASIN); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物链接列表 public static void AddDD_GoodsPM() { List list = null; string tsql = @" INSERT INTO [dbo].[DD_GoodsPM] ([indate] ,[shopid] ,[goodsid] ,[asin] ,[sync],detailid) select getdate(),ShopId,GoodsId,productImgUrl,0,detailid from ( select distinct c.GoodsId,b.ShopId,a.productImgUrl,a.detailid from DT_OrderGoods a with(nolock) inner join DT_OrderInfo b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on a.DetailId=c.DetailId left join [DD_GoodsPM] d with(nolock) on b.ShopId=d.ShopId and a.productImgUrl=d.[asin] where b.PlatId=2 and a.productImgUrl is not null and a.productImgUrl<>'' and d.id is null)a "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static int Save_GoodsCodeData2(DD_GoodsCodeData Model) { string tsql = @" declare @pm int set @pm=0 set @Id=0 select @Id=Id from DD_GoodsCodeData with(nolock) where ShopId=@ShopId and GoodsId=@GoodsId and asin=@asin and datediff(day,OrderDate,@OrderDate)=0 select top 1 @pm=Int3 from DD_GoodsCodeData with(nolock) where ShopId=@ShopId and asin=@asin and GoodsId=@GoodsId and datediff(day,OrderDate,@OrderDate)>0 order by InDate desc if @pm>@Int3 --上升 begin set @Int10=1 --平 end if @pm=@Int3 --下降 begin set @Int10=2 end if @pm<@Int3 begin set @Int10=3 end if @Id>0 begin update DD_GoodsCodeData set Int2=@Int2,Int3=@Int3,Int10=@Int10 where id=@Id and Int3>@Int3 end else begin INSERT INTO [DD_GoodsCodeData]([ShopId],[GoodsId],[InDate],[OrderDate],[GoodsCode],[Dec1],[Dec2],[Dec3],[Dec4],[Dec5],[Dec6],[Dec7],[Int1],[Int2],[Int3],[Str1],[Str2],[Str3],[Str4],[Int4],[Int5],[Str5],[Str6],[Str7],[Str8],[Str9],[Str10],[Int6],[Int7],[Int8],[Int9],[Int10],[Dec8],[Dec9],[Dec10],asin)values(@ShopId,@GoodsId,@InDate,@OrderDate,@GoodsCode,@Dec1,@Dec2,@Dec3,@Dec4,@Dec5,@Dec6,@Dec7,@Int1,@Int2,@Int3,@Str1,@Str2,@Str3,@Str4,@Int4,@Int5,@Str5,@Str6,@Str7,@Str8,@Str9,@Str10,@Int6,@Int7,@Int8,@Int9,@Int10,@Dec8,@Dec9,@Dec10,@asin) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@asin", DbType.String, Model.asin); db.AddInParameter(cmd, "@Dec1", DbType.Decimal, Model.Dec1); db.AddInParameter(cmd, "@Dec2", DbType.Decimal, Model.Dec2); db.AddInParameter(cmd, "@Dec3", DbType.Decimal, Model.Dec3); db.AddInParameter(cmd, "@Dec4", DbType.Decimal, Model.Dec4); db.AddInParameter(cmd, "@Dec5", DbType.Decimal, Model.Dec5); db.AddInParameter(cmd, "@Dec6", DbType.Decimal, Model.Dec6); db.AddInParameter(cmd, "@Dec7", DbType.Decimal, Model.Dec7); db.AddInParameter(cmd, "@Int1", DbType.Int32, Model.Int1); db.AddInParameter(cmd, "@Int2", DbType.Int32, Model.Int2); db.AddInParameter(cmd, "@Int3", DbType.Int32, Model.Int3); db.AddInParameter(cmd, "@Str1", DbType.String, Model.Str1); db.AddInParameter(cmd, "@Str2", DbType.String, Model.Str2); db.AddInParameter(cmd, "@Str3", DbType.String, Model.Str3); db.AddInParameter(cmd, "@Str4", DbType.String, Model.Str4); db.AddInParameter(cmd, "@Int4", DbType.Int32, Model.Int4); db.AddInParameter(cmd, "@Int5", DbType.Int32, Model.Int5); db.AddInParameter(cmd, "@Str5", DbType.String, Model.Str5); db.AddInParameter(cmd, "@Str6", DbType.String, Model.Str6); db.AddInParameter(cmd, "@Str7", DbType.String, Model.Str7); db.AddInParameter(cmd, "@Str8", DbType.String, Model.Str8); db.AddInParameter(cmd, "@Str9", DbType.String, Model.Str9); db.AddInParameter(cmd, "@Str10", DbType.String, Model.Str10); db.AddInParameter(cmd, "@Int6", DbType.Int32, Model.Int6); db.AddInParameter(cmd, "@Int7", DbType.Int32, Model.Int7); db.AddInParameter(cmd, "@Int8", DbType.Int32, Model.Int8); db.AddInParameter(cmd, "@Int9", DbType.Int32, Model.Int9); db.AddInParameter(cmd, "@Int10", DbType.Int32, Model.Int10); db.AddInParameter(cmd, "@Dec8", DbType.Decimal, Model.Dec8); db.AddInParameter(cmd, "@Dec9", DbType.Decimal, Model.Dec9); db.AddInParameter(cmd, "@Dec10", DbType.Decimal, Model.Dec10); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static void Save_DD_GoodsSync(int Id) { string tsql = @" update DD_Goods set sync=1 where id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static void Save_DD_GoodsSync2(int Id) { string tsql = @" update DD_GoodsPM set sync=1 where id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 分页动态条件查询 public static List GetListPostVote(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select Id=cast(a.Id as int),a.OrderId,a.trackcode,a.ActualWeightAmount,a.ActualWeightUnits,a.RatedWeightAmount,a.RatedWeightUnits,a.DimLength,a.DimWidth,a.DimHeight,a.DimDivisor,a.DimUnit,a.ZoneCode,a.bigdifference,a.result,a.sku,a.indate,a.inname,a.fee1,a.fee2,a.fee3,a.fee4,a.fee5,a.int1,a.int2,a.int3,a.str1,a.str2,a.str3,a.NetChargeAmount,a.estimatefee,OrderCode=b.PlatOrderCode from DT_PostVote a with(nolock) inner join DT_OrderInfo b with(nolock) on a.orderid=b.orderid"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_PostVote2(DT_PostVote Model) { string tsql = @" if @Id>0 begin Update [DT_PostVote] set [trackcode]=@trackcode,[ActualWeightAmount]=@ActualWeightAmount,[ActualWeightUnits]=@ActualWeightUnits,[RatedWeightAmount]=@RatedWeightAmount,[RatedWeightUnits]=@RatedWeightUnits,[DimLength]=@DimLength,[DimWidth]=@DimWidth,[DimHeight]=@DimHeight,[DimDivisor]=@DimDivisor,[DimUnit]=@DimUnit,[ZoneCode]=@ZoneCode,[bigdifference]=@bigdifference,[result]=@result,[sku]=@sku,[fee1]=@fee1,[fee2]=@fee2,[fee3]=@fee3,[fee4]=@fee4,[fee5]=@fee5,[int1]=@int1,[int2]=@int2,[int3]=@int3,[str1]=@str1,[str2]=@str2,[str3]=@str3,[NetChargeAmount]=@NetChargeAmount,[estimatefee]=@estimatefee where Id=@Id end else begin INSERT INTO [DT_PostVote]([OrderId],[trackcode],[ActualWeightAmount],[ActualWeightUnits],[RatedWeightAmount],[RatedWeightUnits],[DimLength],[DimWidth],[DimHeight],[DimDivisor],[DimUnit],[ZoneCode],[bigdifference],[result],[sku],[indate],[inname],[fee1],[fee2],[fee3],[fee4],[fee5],[int1],[int2],[int3],[str1],[str2],[str3],[NetChargeAmount],[estimatefee])values(@OrderId,@trackcode,@ActualWeightAmount,@ActualWeightUnits,@RatedWeightAmount,@RatedWeightUnits,@DimLength,@DimWidth,@DimHeight,@DimDivisor,@DimUnit,@ZoneCode,@bigdifference,@result,@sku,@indate,@inname,@fee1,@fee2,@fee3,@fee4,@fee5,@int1,@int2,@int3,@str1,@str2,@str3,@NetChargeAmount,@estimatefee) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@trackcode", DbType.String, Model.trackcode); db.AddInParameter(cmd, "@ActualWeightAmount", DbType.Decimal, Model.ActualWeightAmount); db.AddInParameter(cmd, "@ActualWeightUnits", DbType.String, Model.ActualWeightUnits); db.AddInParameter(cmd, "@RatedWeightAmount", DbType.Decimal, Model.RatedWeightAmount); db.AddInParameter(cmd, "@RatedWeightUnits", DbType.String, Model.RatedWeightUnits); db.AddInParameter(cmd, "@DimLength", DbType.Decimal, Model.DimLength); db.AddInParameter(cmd, "@DimWidth", DbType.Decimal, Model.DimWidth); db.AddInParameter(cmd, "@DimHeight", DbType.Decimal, Model.DimHeight); db.AddInParameter(cmd, "@DimDivisor", DbType.Decimal, Model.DimDivisor); db.AddInParameter(cmd, "@DimUnit", DbType.String, Model.DimUnit); db.AddInParameter(cmd, "@ZoneCode", DbType.Decimal, Model.ZoneCode); db.AddInParameter(cmd, "@bigdifference", DbType.Decimal, Model.bigdifference); db.AddInParameter(cmd, "@result", DbType.String, Model.result); db.AddInParameter(cmd, "@sku", DbType.String, Model.sku); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@fee1", DbType.Decimal, Model.fee1); db.AddInParameter(cmd, "@fee2", DbType.Decimal, Model.fee2); db.AddInParameter(cmd, "@fee3", DbType.Decimal, Model.fee3); db.AddInParameter(cmd, "@fee4", DbType.Decimal, Model.fee4); db.AddInParameter(cmd, "@fee5", DbType.Decimal, Model.fee5); db.AddInParameter(cmd, "@int1", DbType.Int32, Model.int1); db.AddInParameter(cmd, "@int2", DbType.Int32, Model.int2); db.AddInParameter(cmd, "@int3", DbType.Int32, Model.int3); db.AddInParameter(cmd, "@str1", DbType.String, Model.str1); db.AddInParameter(cmd, "@str2", DbType.String, Model.str2); db.AddInParameter(cmd, "@str3", DbType.String, Model.str3); db.AddInParameter(cmd, "@NetChargeAmount", DbType.Decimal, Model.NetChargeAmount); db.AddInParameter(cmd, "@estimatefee", DbType.Decimal, Model.estimatefee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static void updateTrackCodecount() { string tsql = @" update b set b.IsSDan=a.num from ( select OrderId,num=COUNT(0) from DT_TrackCodeApply a where a.GetDate>=GETDATE()-1 and State=1 group by OrderId having COUNT(0)>1)a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.IsSDan is null update b set b.IsSDan=a.num from ( select OrderId,num=COUNT(0) from DT_TrackCodeApply a where a.GetDate>=GETDATE()-1 and State=1 group by OrderId having COUNT(0)>1)a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.IsSDan is null"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static int Save_ProductionPlan(HW_ProductionPlan Model) { string tsql = @" select @detailid=b.DetailId,@goodsid=a.goodsid from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where a.CompanyId=1 and b.SKU1=@goodscode if @detailid is null or @detailid=0 begin select 0 end else begin if @id>0 begin Update [HW_ProductionPlan] set [year]=@year,[weeksort]=@weeksort,[weeknum]=@weeknum,[indate]=@indate,[inname]=@inname,[goodsid]=@goodsid,[detailid]=@detailid where id=@id end else begin INSERT INTO [HW_ProductionPlan]([year],[weeksort],[weeknum],[indate],[inname],[goodsid],[detailid])values(@year,@weeksort,@weeknum,@indate,@inname,@goodsid,@detailid) set @id=SCOPE_IDENTITY() end select @id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); //db.AddInParameter(cmd, "@year", DbType.Int32, Model.year); //db.AddInParameter(cmd, "@weeksort", DbType.Int32, Model.weeksort); //db.AddInParameter(cmd, "@weeknum", DbType.Int32, Model.weeknum); //db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@goodsid", DbType.Int32, Model.goodsid); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@goodscode", DbType.String, Model.goodscode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_ProductionPlan2(HW_ProductionPlan Model) { string tsql = @" select @detailid=b.DetailId,@goodsid=a.goodsid from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where a.CompanyId=1 and b.SKU1=@goodscode if @detailid is null or @detailid=0 begin select 0 end else begin select top 1 @id=id from HW_ProductionPlan where [detailid]=@detailid if @id>0 begin Update [HW_ProductionPlan] set [goodscode]=@goodscode,[inname]=@inname,[goodsid]=@goodsid,[detailid]=@detailid where id=@id end else begin INSERT INTO [HW_ProductionPlan]([goodscode],[inname],[goodsid],[detailid])values(@goodscode,@inname,@goodsid,@detailid) set @id=SCOPE_IDENTITY() end select @id end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@goodscode", DbType.String, Model.goodscode); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@goodsid", DbType.Int32, Model.goodsid); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int delete_ProductionDetail(int mid) { string tsql = @" delete from HW_ProductionDetail where mid=@mid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@mid", DbType.Int32, mid); db.ExecuteNonQuery(cmd); return 1; } #endregion #region 保存 public static int Save_ProductionDetail2(HW_ProductionDetail Model) { string tsql = @" INSERT INTO [HW_ProductionDetail]([mid],[sdate],[edate],[weekname],[weeknum])values(@mid,@sdate,@edate,@weekname,@weeknum) set @id=SCOPE_IDENTITY() select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@mid", DbType.Int32, Model.mid); db.AddInParameter(cmd, "@sdate", DbType.DateTime, Model.sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, Model.edate); db.AddInParameter(cmd, "@weekname", DbType.String, Model.weekname); db.AddInParameter(cmd, "@weeknum", DbType.Int32, Model.weeknum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_ProductionDetail(HW_ProductionDetail Model) { string tsql = @" select @Id=Id from HW_ProductionDetail where mid=@mid and sdate=@sdate and edate=@edate if @id>0 begin Update [HW_ProductionDetail] set [mid]=@mid,[sdate]=@sdate,[edate]=@edate,[weekname]=@weekname,[weeknum]=@weeknum where id=@id end else begin INSERT INTO [HW_ProductionDetail]([mid],[sdate],[edate],[weekname],[weeknum])values(@mid,@sdate,@edate,@weekname,@weeknum) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@mid", DbType.Int32, Model.mid); db.AddInParameter(cmd, "@sdate", DbType.DateTime, Model.sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, Model.edate); db.AddInParameter(cmd, "@weekname", DbType.String, Model.weekname); db.AddInParameter(cmd, "@weeknum", DbType.Int32, Model.weeknum); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListProductionPlan() { //string tsql = "select a.id,a.year,a.weeksort,a.weeknum,a.indate,a.inname,a.goodsid,a.detailid from HW_ProductionPlan"; string tsql = "select * from HW_ProductionPlan"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListProductionPlan(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select id=cast(b.detailId as int),c.goodscode,c.goodsid,b.detailid,imgurl=c.FirstImgUrl,c.Solid,tnum1=isnull(b.GoodsInNum,0),tsoild=isnull(c.Solid,0)*isnull(b.GoodsInNum,0),WestNum=isnull(b.WestNum,0),EastNum=isnull(b.EastNum,0) from HW_GoodsDetail b with(nolock) inner join HW_GoodsInfo c with(nolock) on b.goodsid=c.goodsid"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "b.detailId desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListProductionDetail(string mids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = "select * from HW_ProductionDetail where mid in (" + mids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListProductionDetail2(int mid) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = "select * from HW_ProductionDetail where mid=@Id order by sdate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, mid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 删除 public static void Delete_ProductionDetail(int Id) { string tsql = @" delete from HW_ProductionDetail where id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Delete_Production(int Id) { string tsql = @" delete from HW_ProductionPlan where id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static HW_ProductionDetail GetModel_ProductionDetail(int id, string weekname) { HW_ProductionDetail model = null; //string tsql = "select a.Id,a.OrderId,a.trackcode,a.ActualWeightAmount,a.ActualWeightUnits,a.RatedWeightAmount,a.DimLength,a.DimWidth,a.DimHeight,a.DimDivisor,a.DimUnit,a.ZoneCode,a.bigdifference,a.result,a.sku,a.indate,a.inname,a.fee1,a.fee2,a.fee3,a.fee4,a.fee5,a.int1,a.int2,a.int3,a.str1,a.str2,a.str3 from DT_PostVote"; string tsql = @" select top 1 a.*,goodscode=b.sku1 from HW_ProductionDetail a inner join HW_GoodsDetail b on a.Mid=b.detailid where a.Mid=@Id and a.weekname=@weekname"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@weekname", DbType.String, weekname); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 修改申请状态 public static void updateAutoTrack(int OrderId) { string tsql = @" update DT_OrderXXInfo set IsAutoTrack=2 where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 插入提示消息 public static void SaveImpotMess() { string tsql = @" declare @platordercode nvarchar(100) set @platordercode='' select top 1 @platordercode=platordercode from DT_OrderInfo where InDate>=GETDATE()-5 and State=1 group by platordercode having COUNT(0)>1 if @platordercode<>'' begin INSERT INTO [JC_OpenMess]([Content],[IsRead],[OpenDate],[Target],[Type],[UserType],[UserId]) select @platordercode+'有重复订单导入注意处理',0,getdate(),0,1,'P',UserId from JC_UserInfo where State=1 and CompanyId=1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region public static void SaveGoodsPlan() { string tsql = @" update a set a.url=b.LinkUrl from HW_GoodsUser a inner join ( select a.GoodsId,c.ShopId,a.LinkUrl from HW_BuyLink a with(nolock) inner join JC_Shop c with(nolock) on a.LinkDesc=c.ShopName )b on a.GoodsId=b.GoodsId and a.ShopId=b.ShopId where isnull(a.url,'')='' "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 货号分配 public static int SetGroupName(int guserid, int userid, string groupname) { string tsql = @" update jc_userinfo set guserid=@guserid,groupname=@groupname where userid=@userid update HW_GoodsInfo set groupname=@groupname where muserid=@userid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@guserid", DbType.Int32, guserid); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@groupname", DbType.String, groupname); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页动态条件查询 public static List GetListGoodsUserPlanCount(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select Id=cast(a.DetailId as int),FirstImgUrl=case when isnull(a.FirstImgUrl,'')='' then b.FirstImgUrl else a.FirstImgUrl end,SKU1=case when a.SKU1 is null or a.SKU1='' then b.GoodsCode else a.SKU1 end,b.mname,a.GoodsHJNum2,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=DATEDIFF(day,b.LastOrderDate,GETDATE()),c.OutDays2,c.Price,c.Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,d.groupname from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId = b.GoodsId inner join JC_UserInfo d with(nolock) on b.muserid=d.UserId left join HW_GoodsUserPlanCount c with(nolock) on a.DetailId = c.DetailId"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.SKU1"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListGoodsPlan_bak(int platid, string name, int IsFP, int IsLJ, string where, int cdtj, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); string sql2 = ""; if (cdtj == 1) //一个月未出单 { sql2 = @" select distinct c.GoodsId,a.ShopId into #ls from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsExtra d with(nolock) on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and d.RKDate is not null and a.OrderDate>=d.RKDate and a.OrderDate0 and a.State<3 and d.RKDate is not null and a.OrderDate>=d.RKDate and a.OrderDate'')"; } if (IsLJ == 0) { tj += @" and goodsid in (select distinct a.goodsid from HW_GoodsUser a with(nolock) where isnull(url,'')='')"; } if (name != "") { tj += @" and goodsid in (select distinct a.GoodsId from HW_GoodsUser a with(nolock) inner join JC_UserInfo b with(nolock) on a.UserId=b.UserId where b.State=1 and b.Name like '%" + name + @"%')"; } if (sql2 != "") { tj += " and goodsid in (select a.GoodsId from #ls2) "; } if (platid == 2) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,a.muserid,a.mname,a.Leaveword from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid"; else if (platid == 3) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_ebay,mname=groupname_ebay,a.Leaveword from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid"; else if (platid == 6) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_wlmart,mname=groupname_wlmart from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid"; if (tj != "") { tj = tj.Substring(4); if (platid == 2) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,a.muserid,a.mname,a.Leaveword from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid"; else if (platid == 3) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_ebay,mname=groupname_ebay,a.Leaveword from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid"; else if (platid == 3) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_wlmart,mname=groupname_wlmart ,a.Leaveword from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid"; } ser.Tsql = ser.Tsql + " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.GoodsId desc"; } else { ser.Sort = Sort; } string tsql = sql2 + ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListGoodsPlan(int platid, string name, int IsFP, int IsLJ, string where, int cdtj, int iskc, int shopId, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); string sql2 = ""; string tableName = ""; if (cdtj == 1) //一个月未出单 { tableName = "#ls2"; sql2 = @" select distinct c.GoodsId,a.ShopId into #ls from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsExtra d with(nolock) on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and d.RKDate is not null and a.OrderDate>=d.RKDate and a.OrderDate0 and a.State<3 and d.RKDate is not null and a.OrderDate>=d.RKDate and a.OrderDate0"; } else { sql2 += @" select distinct GoodsId into #ls3 from ( select goodsid,LeftNumW=sum(isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0)),LeftNumE=sum(isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0)) from HW_GoodsDetail a where goodsid in (select goodsid from #ls2) group by GoodsId ) t where (t.LeftNumW+t.LeftNumE)>0"; } } if (shopId != 0) //只显示该店铺下面售卖的商品 { tableName = "#ls4"; if (string.IsNullOrEmpty(sql2)) { sql2 += @" select distinct GoodsId into #ls4 from HW_BuyLink a inner join JC_Shop b on a.LinkDesc=b.ShopName where ShopId=" + shopId + " "; } else if (iskc == 1) { sql2 += @" select distinct GoodsId into #ls4 from HW_BuyLink a inner join JC_Shop b on a.LinkDesc=b.ShopName where a.GoodsId in (select goodsid from #ls3) and ShopId=" + shopId + " "; } else { sql2 += @" select distinct GoodsId into #ls4 from HW_BuyLink a inner join JC_Shop b on a.LinkDesc=b.ShopName where a.GoodsId in (select goodsid from #ls2) and ShopId=" + shopId + " "; } } string tj = ""; if (IsFP == 1) { tj += @" and goodsid in (select distinct a.GoodsId from HW_GoodsUser a with(nolock) inner join JC_UserInfo b with(nolock) on a.UserId=b.UserId inner join JC_Shop c with(nolock) on a.ShopId=c.ShopId where b.State=1)"; } if (IsFP == 0) { tj += @" and goodsid not in (select distinct a.GoodsId from HW_GoodsUser a with(nolock) inner join JC_UserInfo b with(nolock) on a.UserId=b.UserId inner join JC_Shop c with(nolock) on a.ShopId=c.ShopId where b.State=1)"; } if (IsLJ == 1 && IsFP != 1) { tj += @" and goodsid in (select distinct a.GoodsId from HW_GoodsUser a with(nolock) inner join JC_UserInfo b with(nolock) on a.UserId=b.UserId inner join JC_Shop c with(nolock) on a.ShopId=c.ShopId where b.State=1) and goodsid not in (select distinct a.goodsid from HW_GoodsUser a where isnull(url,'')='')"; } else if (IsLJ == 1) { tj += @" and goodsid not in (select distinct a.goodsid from HW_GoodsUser a with(nolock) where isnull(url,'')='')"; } else if (IsLJ == 2) { tj += @" and goodsid in (select distinct a.goodsid from HW_GoodsUser a with(nolock) where isnull(url,'')<>'')"; } if (IsLJ == 0) { tj += @" and goodsid in (select distinct a.goodsid from HW_GoodsUser a with(nolock) where isnull(url,'')='')"; } if (name != "") { tj += @" and goodsid in (select distinct a.GoodsId from HW_GoodsUser a with(nolock) inner join JC_UserInfo b with(nolock) on a.UserId=b.UserId where b.State=1 and b.Name like '%" + name + @"%')"; } if (sql2 != "") { tj += " and goodsid in (select GoodsId from " + tableName + ") "; } if (platid == 2) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,a.muserid,a.mname,a.Leaveword,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2, Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount ,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 3) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_ebay,mname=groupname_ebay,Leaveword=a.Leaveword_ebay,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 6) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_wlmart,mname=groupname_wlmart,Leaveword=a.LeaveWord_walmart,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 15) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_shopify,mname=groupname_shopify,Leaveword=a.LeaveWord_shopify,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 18) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_wayfair,mname=groupname_wayfair,Leaveword=a.LeaveWord_wayfair,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 21) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_sheIn,mname=groupname_sheIn,Leaveword=a.LeaveWord_shein,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 22) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_tiktok,mname=groupname_tiktok,Leaveword=a.LeaveWord_tiktok,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 23) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_temu,mname=groupname_temu,Leaveword=a.LeaveWord_temu,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; if (tj != "") { tj = tj.Substring(4); if (platid == 2) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,a.muserid,a.mname,a.Leaveword,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark ,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 3) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_ebay,mname=groupname_ebay,Leaveword=a.Leaveword_ebay,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark ,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 6) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_wlmart,mname=groupname_wlmart,Leaveword=a.LeaveWord_walmart,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,GETDATE()),c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 15) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_shopify,mname=groupname_shopify,Leaveword=a.LeaveWord_shopify,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 18) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_wayfair,mname=groupname_wayfair,Leaveword=a.LeaveWord_wayfair,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark ,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 21) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_sheIn,mname=groupname_sheIn,Leaveword=a.LeaveWord_shein,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark ,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 22) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_tiktok,mname=groupname_tiktok,Leaveword=a.LeaveWord_tiktok,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark ,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; else if (platid == 23) ser.Tsql = @"select id=cast(a.GoodsId as int),a.goodscode,imgurl=a.FirstImgUrl,a.Solid,JDDate=isnull(b.JDDate,a.InDate),b.PZDate,b.SJDate,b.RKDate,b.YPDate,b.BuyName,b.TPDate,b.Date1,b.Date2,IsEnd=isnull(a.IsEnd,0),EndName=case when isend=1 then '恢复' else '结束' end,muserid=guserid_temu,mname=groupname_temu,Leaveword=a.LeaveWord_temu,a.Leaveword_cg,a.GoodsHJNum2,a.GoodsHJNum3,a.GoodsHJNum4,a.GoodsMonthHJPrice,a.GoodsWeekHJNum,a.GoodsWeekHJPrice,NoOutDays=Case when DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE())<=0 then 0 else DATEDIFF(day,IsNull(a.LastOrderDate,GETDATE()),GETDATE()) end ,c.OutDays2,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1-0.05)) Price,Convert(decimal(12,2), IsNull(a.JYPrice,0)*(1+0.05)) Price2,c.Price3,c.Price4,c.Price5,c.Price6,c.Price7,c.Price8,c.Num,c.Num2,c.Num3,c.Num4,c.Num5,c.Num6,c.Num7,c.ShopNames,c.PlanInfo,c.AdviseInfo,c.Remark ,a.PlanCount,a.EditPlanCount from (select * from HW_GoodsInfo a with(nolock) where " + tj + @")a left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId"; } ser.Tsql = ser.Tsql + " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.GoodsId desc"; } else { ser.Sort = Sort; } string tsql = sql2 + ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsPlanDetail(string mids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select a.*,b.Name,PlatId=c.PlatType,c.ShopName from HW_GoodsUser a with(nolock) inner join JC_UserInfo b with(nolock) on a.UserId=b.UserId inner join JC_Shop c with(nolock) on a.ShopId=c.ShopId where b.State=1 and GoodsId in (" + mids + ") order by a.GoodsId,c.PlatType,a.shopid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsPlanDetail2(string mids, int platid) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; // string tsql = @" //select ShopName=c.ShopName,a.GoodsId,url=a.LinkUrl,Name=c.Master,c.shopid from HW_BuyLink a with(nolock) //inner join JC_Shop c with(nolock) on a.LinkDesc=c.ShopName //where GoodsId in (" + mids + ") and c.plattype=@platid order by a.GoodsId,c.PlatType,c.shopid"; //改为一个商品在一个店铺只取一条链接 string tsql = @"select ShopName=c.ShopName,a.GoodsId,url=a.LinkUrl,Name=c.Master,c.shopid from HW_BuyLink a inner join JC_Shop c on a.LinkDesc=c.ShopName where LinkId in (select MAX(LinkId) from HW_BuyLink a with(nolock) inner join JC_Shop c with(nolock) on a.LinkDesc=c.ShopName where GoodsId in (" + mids + ") and c.plattype=2 group by GoodsId,LinkDesc) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListFeeCompute(string mids) { //string tsql = "select a.Id,a.GoodsId,a.ShopId,a.WeekFee1,a.WeekFee2,a.WeekLR1,a.WeekLR2,a.NextFee,a.PreDayFee1 from AD_FeeCompute"; string tsql = "select * from AD_FeeCompute where GoodsId in (" + mids + ") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsDetailLeftNum(string mids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select goodsid,LeftNumW=sum(isnull(a.WestNum,0)+isnull(a.GoodsHJNum14,0)-isnull(a.GoodsPlanNumW,0)), StockAndOnloadNumW=CONVERT(nvarchar(100), SUM(isnull(a.WestNum,0)-isnull(a.GoodsPlanNumW,0)))+'/'+ CONVERT(nvarchar(100), SUM(ISNULL(a.GoodsHJNum14,0))) , LeftNumE=sum(isnull(a.EastNum,0)+isnull(a.GoodsHJNum15,0)-isnull(a.GoodsPlanNumE,0)), StockAndOnloadNumE=CONVERT(nvarchar(100), SUM(isnull(a.EastNum,0)-isnull(a.GoodsPlanNumE,0)))+'/'+ CONVERT(nvarchar(100), SUM(ISNULL(a.GoodsHJNum15,0))) from HW_GoodsDetail a where a.GoodsId in (" + mids + ") group by GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsPlanUrl(string mids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select LinkId=b.ShopId,a.LinkUrl,a.GoodsId from HW_BuyLink a inner join JC_Shop b on a.LinkDesc=b.ShopName where a.GoodsId in (" + mids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsShop(int platid) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select * from JC_Shop a where CompanyId=1 and isnull(State,1)=1 and (@platid=0 or a.plattype=@platid) order by PlatType,ShopName"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsShopTH(int platid) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select * from JC_Shop a where (@platid=0 or a.plattype=@platid) order by PlatType,ShopName"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsShopCount(DateTime SDate, DateTime EDate) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select c.GoodsId,a.PlatId,a.ShopId,Num=count(distinct a.PlatOrderCode) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsExtra d with(nolock) on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and d.RKDate is not null and a.BuyDate>=d.RKDate and a.buydate ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsShopCount3(string mids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select c.GoodsId,a.PlatId,a.ShopId,Num=count(distinct a.PlatOrderCode) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsExtra d with(nolock) on c.GoodsId=d.GoodsId where c.GoodsId in (" + mids + ") and a.State>0 and a.State<3 and d.RKDate is not null and a.OrderDate>=d.RKDate and a.OrderDate ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsShopCount4(string mids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select c.GoodsId,a.PlatId,a.ShopId,Num=count(distinct a.PlatOrderCode) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsExtra d with(nolock) on c.GoodsId=d.GoodsId where c.GoodsId in (" + mids + ") and a.State>0 and a.State<3 and d.RKDate is not null and a.OrderDate>=d.RKDate and a.OrderDate ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsShopCount2(int GoodsId, int ShopId, int Year) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select Month=DATEPART(month,a.BuyDate),GoodsNum=sum(b.GoodsNum) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId where a.State>0 and a.State<3 and c.GoodsId=@GoodsId and ShopId=@ShopId and DATEPART(year,BuyDate)=@Year group by DATEPART(month,a.BuyDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@Year", DbType.Int32, Year); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_GoodsExtra(HW_GoodsExtra Model) { string tsql = @" if(select count(0) from HW_GoodsExtra where GoodsId=@GoodsId)>0 begin Update [HW_GoodsExtra] set [JDDate]=@JDDate,[SJDate]=@SJDate,[TPDate]=@TPDate,[YPDate]=@YPDate,[PZDate]=@PZDate,[RKDate]=@RKDate,[BuyName]=@BuyName,[Date1]=@Date1,[Date2]=@Date2,[Date3]=@Date3,[Str1]=@Str1,[Str2]=@Str2,[Str3]=@Str3 where GoodsId=@GoodsId end else begin INSERT INTO [HW_GoodsExtra](GoodsId,[JDDate],[SJDate],[TPDate],[YPDate],[PZDate],[RKDate],[BuyName],[Date1],[Date2],[Date3],[Str1],[Str2],[Str3])values(@GoodsId,@JDDate,@SJDate,@TPDate,@YPDate,@PZDate,@RKDate,@BuyName,@Date1,@Date2,@Date3,@Str1,@Str2,@Str3) end select @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@JDDate", DbType.DateTime, Model.JDDate); db.AddInParameter(cmd, "@SJDate", DbType.DateTime, Model.SJDate); db.AddInParameter(cmd, "@TPDate", DbType.DateTime, Model.TPDate); db.AddInParameter(cmd, "@YPDate", DbType.DateTime, Model.YPDate); db.AddInParameter(cmd, "@PZDate", DbType.DateTime, Model.PZDate); db.AddInParameter(cmd, "@RKDate", DbType.DateTime, Model.RKDate); db.AddInParameter(cmd, "@BuyName", DbType.String, Model.BuyName); db.AddInParameter(cmd, "@Date1", DbType.DateTime, Model.Date1); db.AddInParameter(cmd, "@Date2", DbType.DateTime, Model.Date2); db.AddInParameter(cmd, "@Date3", DbType.DateTime, Model.Date3); db.AddInParameter(cmd, "@Str1", DbType.String, Model.Str1); db.AddInParameter(cmd, "@Str2", DbType.String, Model.Str2); db.AddInParameter(cmd, "@Str3", DbType.String, Model.Str3); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListGoodsUserInfo(string name) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select UserId,Name from JC_UserInfo where (@name='' or name like '%'+@name+'%') and CompanyId=1 and State=1 and UserType='P' order by Name"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@name", DbType.String, name); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_GoodsUser(HW_GoodsUser Model) { string tsql = @" if @UserId=0 begin delete from [HW_GoodsUser] where [GoodsId]=@GoodsId and [ShopId]=@ShopId update HW_GoodsInfo set mname='' where GoodsId=@GoodsId end select top 1 @Id=Id from HW_GoodsUser where [GoodsId]=@GoodsId and [ShopId]=@ShopId if @Id>0 begin Update [HW_GoodsUser] set [GoodsId]=@GoodsId,[UserId]=@UserId,[ShopId]=@ShopId where Id=@Id end else begin INSERT INTO [HW_GoodsUser]([GoodsId],[UserId],[ShopId])values(@GoodsId,@UserId,@ShopId) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int UpdateIsEnd(int GoodsId, int IsEnd) { string tsql = @" Update [HW_GoodsInfo] set IsEnd=@IsEnd where GoodsId=@GoodsId select GoodsId=@GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@IsEnd", DbType.Int32, IsEnd); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_FeeDetailNew(CK_FeeDetailNew Model) { string tsql = @" if @Id>0 begin Update [CK_FeeDetail] set [FeeId]=@FeeId,[FeeType]=@FeeType,[FeeRate]=@FeeRate,[OffRate]=@OffRate,[MoneyCode]=@MoneyCode,[FeeUnit]=@FeeUnit,[SInt]=@SInt,[EInt]=@EInt,[SDec]=@SDec,[EDec]=@EDec,[Sort]=@Sort,[YLInt1]=@YLInt1,[YLInt2]=@YLInt2,[YLDec1]=@YLDec1,[YLDec2]=@YLDec2,[YLChar1]=@YLChar1,[YLChar2]=@YLChar2,[YLChar3]=@YLChar3 where Id=@Id end else begin INSERT INTO [CK_FeeDetail]([FeeId],[FeeType],[FeeRate],[OffRate],[MoneyCode],[FeeUnit],[SInt],[EInt],[SDec],[EDec],[Sort],[YLInt1],[YLInt2],[YLDec1],[YLDec2],[YLChar1],[YLChar2],[YLChar3])values(@FeeId,@FeeType,@FeeRate,@OffRate,@MoneyCode,@FeeUnit,@SInt,@EInt,@SDec,@EDec,@Sort,@YLInt1,@YLInt2,@YLDec1,@YLDec2,@YLChar1,@YLChar2,@YLChar3) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@FeeId", DbType.Int32, Model.FeeId); db.AddInParameter(cmd, "@FeeType", DbType.Int32, Model.FeeType); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@OffRate", DbType.Decimal, Model.OffRate); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@FeeUnit", DbType.String, Model.FeeUnit); db.AddInParameter(cmd, "@SInt", DbType.Int32, Model.SInt); db.AddInParameter(cmd, "@EInt", DbType.Int32, Model.EInt); db.AddInParameter(cmd, "@SDec", DbType.Decimal, Model.SDec); db.AddInParameter(cmd, "@EDec", DbType.Decimal, Model.EDec); db.AddInParameter(cmd, "@Sort", DbType.Int32, Model.Sort); db.AddInParameter(cmd, "@YLInt1", DbType.Int32, Model.YLInt1); db.AddInParameter(cmd, "@YLInt2", DbType.Int32, Model.YLInt2); db.AddInParameter(cmd, "@YLDec1", DbType.Decimal, Model.YLDec1); db.AddInParameter(cmd, "@YLDec2", DbType.Decimal, Model.YLDec2); db.AddInParameter(cmd, "@YLChar1", DbType.String, Model.YLChar1); db.AddInParameter(cmd, "@YLChar2", DbType.String, Model.YLChar2); db.AddInParameter(cmd, "@YLChar3", DbType.String, Model.YLChar3); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_ErrorJH(int JHError, string JHRemark, int OrderId) { string tsql = @" Update [DT_OrderInfo] set [JHError]=@JHError,[JHRemark]=@JHRemark where OrderId=@OrderId select @OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@JHError", DbType.Int32, JHError); db.AddInParameter(cmd, "@JHRemark", DbType.String, JHRemark); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static void Save_StorePostion(CK_StorePostion Model) { string tsql = @" if(select count(0) from CK_StorePostion where StoreId=@StoreId and PostionCode=@PostionCode)=0 begin INSERT INTO [dbo].[CK_StorePostion] ([StoreId] ,[PostionCode] ,[PostionDesc] ,[Remark] ,[IsLS] ,[SortNo] ,[PostionBox] ) values(@StoreId ,@PostionCode ,@PostionDesc ,'' ,0 ,1 ,1 ) end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@PostionDesc", DbType.String, Model.PostionDesc); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListGoodsPlanUrlCount(string name) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select a.UserId,c.Name,Num1=COUNT(0),Num2=0 into #HW_GoodsUser_ls from HW_GoodsUser a with(nolock) inner join JC_Shop b on a.ShopId=b.ShopId inner join JC_UserInfo c on a.UserId=c.UserId where c.State=1 group by a.UserId,c.Name update a set a.Num2=b.Num2 from #HW_GoodsUser_ls a inner join ( select a.UserId,Num2=COUNT(0) from HW_GoodsUser a with(nolock) inner join JC_Shop b on a.ShopId=b.ShopId inner join JC_UserInfo c on a.UserId=c.UserId where c.State=1 and a.url is null group by a.UserId)b on a.UserId=b.UserId select *,Num3=Num1-isnull(Num2,0) from #HW_GoodsUser_ls where (@name='' or name=@name) drop table #HW_GoodsUser_ls"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@name", DbType.String, name); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static decimal GetListTotalPrice(DateTime Indate) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select TJ=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a with(nolock) where DATEDIFF(day,a.OrderDate,@Indate)=0 and a.State>0 and a.State<3"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Indate); decimal hj = Convert.ToDecimal(db.ExecuteScalar(cmd)); return hj; } #endregion #region 返回列表 public static decimal GetListTotalPrice2(DateTime Indate, DateTime EDate) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select TJ=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a with(nolock) where a.OrderDate>=@Indate and a.OrderDate<@EDate and a.State>0 and a.State<3"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Indate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); decimal hj = Convert.ToDecimal(db.ExecuteScalar(cmd)); return hj; } #endregion #region 返回列表 public static List GetListGoodsDays(DateTime Indate) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select a.OrderId,b.DetailId,days=DATEDIFF(day,c.InDate,isnull(a.PrintDate,a.indate)) from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsInDetail c with(nolock) on b.Id=c.OrderGoodsId where DATEDIFF(day,a.OrderDate,@Indate)=0 and a.State>0 and a.State<3"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Indate", DbType.DateTime, Indate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListJHUser() { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select * from JC_UserInfo where State=1 and UserCode>=100001 order by UserCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion // #region 返回列表 // public static List GetListJHUser() // { // //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; // string tsql = @" //select b.name,COUNT(0) from DT_TrackCodeScan a with(nolock) //inner join JC_UserInfo b with(nolock) on a.SureUserId=b.UserId //where a.InDate>='2020-10-01' and a.InDate<'2020-10-08' group by b.name"; // Database db = DatabaseFactory.CreateDatabase(); // DbCommand cmd = db.GetSqlStringCommand(tsql); // DataTable tb = db.ExecuteDataTable(cmd); // List ListModel = tb.ToList(); // return ListModel; // } // #endregion #region 返回列表 public static List GetListGoodsStoreCount(int StoreId, string sku) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @"select a.*,TJSolid=isnull(c.Solid,0)*a.KCNum,c.Solid,TJPrice=c.InPrice*a.KCNum,c.InPrice,FirstImgUrl=isnull(c.FirstImgUrl,b.FirstImgUrl),GoodsCode=b.sku1 from ( select DetailId,KCNum=SUM(KCNum) from HW_GoodsInDetail with(nolock) where StoreId=@StoreId and KCNum>0 and CKDetailId=0 group by DetailId)a inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId where @sku='' or c.GoodsCode like '%'+@sku+'%' or b.sku1 like '%'+@sku+'%' order by c.GoodsCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@sku", DbType.String, sku); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询库存 public static List GetList_GoodsLeftForTMNew(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.DetailId,a.PostionId,a.GoodsNum,a.LockNum,LeftNum=DATEDIFF(DAY,a.indate,GETDATE()),c.GoodsName,c.GoodsCode,c.GoodsOldCode,TypeCode=b.sku1,b.TypeDesc,e.StoreName,d.PostionCode,d.PostionDesc,c.FirstImgUrl,a.DoPrice,a.price,c.Solid"; ser.Tables = @"(select DetailId,PostionId,GoodsNum=SUM(GoodsNum),LockNum=SUM(LockNum),indate=min(indate),DoPrice=MAX(DoPrice),price=MAX(price) from ( select DetailId,PostionId,GoodsNum=sum(KCNum),LockNum=0,indate=MIN(indate),DoPrice=MAX(isnull(DoPrice,0)),price=MAX(ISNULL(Price,0)) from HW_GoodsInDetail with(nolock) where OrderGoodsId=0 group by DetailId,PostionId union select DetailId,PostionId,GoodsNum=0,LockNum=sum(KCNum),indate=MIN(indate),DoPrice=MAX(isnull(DoPrice,0)),price=MAX(ISNULL(Price,0)) from HW_GoodsInDetail with(nolock) where CKDetailId=0 and OrderGoodsId>0 group by DetailId,PostionId)a group by DetailId,PostionId)a inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId inner join CK_StorePostion d with(nolock) on a.PostionId=d.PostionId inner join CK_StoreHouse e with(nolock) on d.StoreId=e.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "a.DetailId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int UpDoPrice(int PostionId, int DetailId, decimal doprice) { string tsql = @" Update [HW_GoodsInDetail] set doprice=@doprice where PostionId=@PostionId and DetailId=@DetailId and kcnum>0 and OrderGoodsId=0 select DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@doprice", DbType.Decimal, doprice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public static List GetListPrice(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"id=cast(a.id as int),a.code,a.name,offdec,offdec2,a.dec1,a.dec2,a.dec3,a.dec4,a.dec5,a.dec6,a.dec7,dec8,dec9,offimg,a.dec10,a.dec11,a.dec12,a.dec13,a.dec14,a.dec15,a.dec16,a.dec17,a.dec18,a.dec19,a.dec20,a.dec21,a.dec22,a.dec23,a.dec24,a.dec25,a.dec26,a.dec27,a.dec28,a.dec29,a.dec30,a.dec31,a.dec32,a.dec33,a.dec34,a.dec35,a.indate,a.datadate"; ser.Tables = @"(select a.id,a.code,a.name,offdec=dec3-dec2,offdec2=case when dec2>0 then cast((dec3-dec2)*100/dec2 as decimal(8,2)) else 0 end,a.dec1,a.dec2,a.dec3,a.dec4,a.dec5,a.dec6,a.dec7,dec8=isnull(a.dec8,0)/100,dec9=isnull(a.dec9,0)/10000,offimg=case when a.dec3-a.dec2>0 then '../image/sjt.png' when a.dec3-a.dec2<0 then '../image/xjt.png' else '../image/pjt.png' end,a.dec10,a.dec11,a.dec12,a.dec13,a.dec14,a.dec15,a.dec16,a.dec17,a.dec18,a.dec19,a.dec20,a.dec21,a.dec22,a.dec23,a.dec24,a.dec25,a.dec26,a.dec27,a.dec28,a.dec29,a.dec30,a.dec31,a.dec32,a.dec33,a.dec34,a.dec35,a.indate,a.datadate from GP_Price a)a "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_AdFee(DT_AdFee Model) { string tsql = @" select top 1 @id=id from DT_AdFee where datediff(day,addate,@addate)=0 and adname=@adname and adname2=@adname2 and adname3=@adname3 and adsku=@adsku and adasin=@adasin and num1=@num1 and num2=@num2 and dec3=@dec3 and dec2=@dec2 if @id>0 begin Update [DT_AdFee] set [addate]=@addate,[adname]=@adname,[adname2]=@adname2,[adname3]=@adname3,[moneycode]=@moneycode,[adsku]=@adsku,[adasin]=@adasin,[num1]=@num1,[num2]=@num2,[num3]=@num3,[num4]=@num4,[num5]=@num5,[num6]=@num6,[dec1]=@dec1,[dec2]=@dec2,[dec3]=@dec3,[dec4]=@dec4,[dec5]=@dec5,[dec6]=@dec6,[dec7]=@dec7,[dec8]=@dec8,[dec9]=@dec9,[dec10]=@dec10 where id=@id end else begin INSERT INTO [DT_AdFee]([addate],[adname],[adname2],[adname3],[moneycode],[adsku],[adasin],[num1],[num2],[num3],[num4],[num5],[num6],[dec1],[dec2],[dec3],[dec4],[dec5],[dec6],[dec7],[dec8],[dec9],[dec10],[indate],[inname])values(@addate,@adname,@adname2,@adname3,@moneycode,@adsku,@adasin,@num1,@num2,@num3,@num4,@num5,@num6,@dec1,@dec2,@dec3,@dec4,@dec5,@dec6,@dec7,@dec8,@dec9,@dec10,@indate,@inname) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@addate", DbType.DateTime, Model.addate); db.AddInParameter(cmd, "@adname", DbType.String, Model.adname); db.AddInParameter(cmd, "@adname2", DbType.String, Model.adname2); db.AddInParameter(cmd, "@adname3", DbType.String, Model.adname3); db.AddInParameter(cmd, "@moneycode", DbType.String, Model.moneycode); db.AddInParameter(cmd, "@adsku", DbType.String, Model.adsku); db.AddInParameter(cmd, "@adasin", DbType.String, Model.adasin); db.AddInParameter(cmd, "@num1", DbType.Int32, Model.num1); db.AddInParameter(cmd, "@num2", DbType.Int32, Model.num2); db.AddInParameter(cmd, "@num3", DbType.Int32, Model.num3); db.AddInParameter(cmd, "@num4", DbType.Int32, Model.num4); db.AddInParameter(cmd, "@num5", DbType.Int32, Model.num5); db.AddInParameter(cmd, "@num6", DbType.Int32, Model.num6); db.AddInParameter(cmd, "@dec1", DbType.Decimal, Model.dec1); db.AddInParameter(cmd, "@dec2", DbType.Decimal, Model.dec2); db.AddInParameter(cmd, "@dec3", DbType.Decimal, Model.dec3); db.AddInParameter(cmd, "@dec4", DbType.Decimal, Model.dec4); db.AddInParameter(cmd, "@dec5", DbType.Decimal, Model.dec5); db.AddInParameter(cmd, "@dec6", DbType.Decimal, Model.dec6); db.AddInParameter(cmd, "@dec7", DbType.Decimal, Model.dec7); db.AddInParameter(cmd, "@dec8", DbType.Decimal, Model.dec8); db.AddInParameter(cmd, "@dec9", DbType.Decimal, Model.dec9); db.AddInParameter(cmd, "@dec10", DbType.Decimal, Model.dec10); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_AdFee2(DT_AdFee2 Model) { string tsql = @" select top 1 @id=id from DT_AdFee2 where datediff(day,addate,@addate)=0 and datediff(day,addate2,@addate2)=0 and adname=@adname and adname2=@adname2 and adname3=@adname3 and adsku=@adsku and adasin=@adasin and num1=@num1 and num2=@num2 and dec3=@dec3 and dec2=@dec2 if @id>0 begin Update [DT_AdFee2] set [addate]=@addate,[addate2]=@addate2,[adname]=@adname,[adname2]=@adname2,[adname3]=@adname3,[moneycode]=@moneycode,[adsku]=@adsku,[adasin]=@adasin,[num1]=@num1,[num2]=@num2,[num3]=@num3,[num4]=@num4,[num5]=@num5,[num6]=@num6,[dec1]=@dec1,[dec2]=@dec2,[dec3]=@dec3,[dec4]=@dec4,[dec5]=@dec5,[dec6]=@dec6,[dec7]=@dec7,[dec8]=@dec8,[dec9]=@dec9,[dec10]=@dec10 where id=@id end else begin INSERT INTO [DT_AdFee2]([addate],[addate2],[adname],[adname2],[adname3],[moneycode],[adsku],[adasin],[num1],[num2],[num3],[num4],[num5],[num6],[dec1],[dec2],[dec3],[dec4],[dec5],[dec6],[dec7],[dec8],[dec9],[dec10],[indate],[inname])values(@addate,@addate2,@adname,@adname2,@adname3,@moneycode,@adsku,@adasin,@num1,@num2,@num3,@num4,@num5,@num6,@dec1,@dec2,@dec3,@dec4,@dec5,@dec6,@dec7,@dec8,@dec9,@dec10,@indate,@inname) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@addate", DbType.DateTime, Model.addate); db.AddInParameter(cmd, "@addate2", DbType.DateTime, Model.addate2); db.AddInParameter(cmd, "@adname", DbType.String, Model.adname); db.AddInParameter(cmd, "@adname2", DbType.String, Model.adname2); db.AddInParameter(cmd, "@adname3", DbType.String, Model.adname3); db.AddInParameter(cmd, "@moneycode", DbType.String, Model.moneycode); db.AddInParameter(cmd, "@adsku", DbType.String, Model.adsku); db.AddInParameter(cmd, "@adasin", DbType.String, Model.adasin); db.AddInParameter(cmd, "@num1", DbType.Int32, Model.num1); db.AddInParameter(cmd, "@num2", DbType.Int32, Model.num2); db.AddInParameter(cmd, "@num3", DbType.Int32, Model.num3); db.AddInParameter(cmd, "@num4", DbType.Int32, Model.num4); db.AddInParameter(cmd, "@num5", DbType.Int32, Model.num5); db.AddInParameter(cmd, "@num6", DbType.Int32, Model.num6); db.AddInParameter(cmd, "@dec1", DbType.Decimal, Model.dec1); db.AddInParameter(cmd, "@dec2", DbType.Decimal, Model.dec2); db.AddInParameter(cmd, "@dec3", DbType.Decimal, Model.dec3); db.AddInParameter(cmd, "@dec4", DbType.Decimal, Model.dec4); db.AddInParameter(cmd, "@dec5", DbType.Decimal, Model.dec5); db.AddInParameter(cmd, "@dec6", DbType.Decimal, Model.dec6); db.AddInParameter(cmd, "@dec7", DbType.Decimal, Model.dec7); db.AddInParameter(cmd, "@dec8", DbType.Decimal, Model.dec8); db.AddInParameter(cmd, "@dec9", DbType.Decimal, Model.dec9); db.AddInParameter(cmd, "@dec10", DbType.Decimal, Model.dec10); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListGoodsStoreCount(int ShopId, string goodscode, DateTime? sdate, DateTime? edate, decimal fje) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @" select a.shopid,DetailId=max(b.DetailId),proudctid=b.productImgUrl,ordernum=count(distinct PlatOrderCode),goodsNum=sum(b.GoodsNum),yf=SUM(dbo.[GetOrderPostFee](a.OrderId)),TotalPrice=sum(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId)) into #DT_OrderInfo_ls from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId where a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate and a.PlatId=2 and ISNULL(b.productImgUrl,'')<>'' and dbo.[GetOrderPostFee](a.OrderId)>0 group by a.shopid,b.productImgUrl select adasin,ggf=sum(dec3),ggzxl=sum(num1),ggdjl=sum(num2) into #DT_OrderInfo_ls2 from DT_AdFee a where addate>=@sdate and addate<@edate group by adasin select e.ShopName,b.GoodsCode,DetailId=isnull(c.DetailId,0),a.SKU1,c.proudctid,b.FirstImgUrl,c.TotalPrice,yj=c.TotalPrice*0.15,cb=b.InPrice*c.goodsNum/6.6,c.ordernum,c.goodsNum,cbsf=b.InPrice*c.goodsNum*isnull(b.FeeRate,0)*0.01/6.6,c.yf,tc=170*isnull(b.Solid,0)*c.goodsNum,md=c.ordernum*0.6,ckf=c.TotalPrice*" + fje + @",d.* into #DT_OrderInfo_ls3 from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId left join #DT_OrderInfo_ls c with(nolock) on a.DetailId=c.DetailId left join #DT_OrderInfo_ls2 d with(nolock) on c.proudctid=d.adasin left join jc_shop e with(nolock) on c.shopid=e.shopid where b.GoodsCode like '%'+@goodscode+'%' and (@ShopId=0 or e.shopid=@ShopId) select *,ml1=TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf,ml2=TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf-isnull(ggf,0),mll1= case when TotalPrice>0 then (TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf)*100/TotalPrice else 0 end,mll2= case when TotalPrice>0 then (TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf-isnull(ggf,0))*100/TotalPrice else 0 end from #DT_OrderInfo_ls3 drop table #DT_OrderInfo_ls,#DT_OrderInfo_ls2,#DT_OrderInfo_ls3 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); db.AddInParameter(cmd, "@goodscode", DbType.String, goodscode); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsStoreCount3(string goodscode, DateTime? sdate, DateTime? edate) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @" select SKU1=adsku,proudctid=adasin,ggf=sum(dec3),ggzxl=sum(num1),ggdjl=sum(num2),ml1=0-sum(dec3) from DT_AdFee a with(nolock) where (@goodscode='' or a.adsku like '%'+@goodscode+'%') and dec3>0 and addate>=@sdate and addate<@edate and adasin not in (select distinct b.productImgUrl from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId where b.productImgUrl is not null and a.PlatId=2 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate) group by adsku,adasin "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); db.AddInParameter(cmd, "@goodscode", DbType.String, goodscode); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsStoreCount4(string adasin, DateTime? sdate, DateTime? edate, decimal fje) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @" select OrderDate=convert(nvarchar(10),a.addate,120),SKU1=adsku,proudctid=adasin,ggf=sum(dec3),ggzxl=sum(num1),ggdjl=sum(num2),ml1=0-sum(dec3) from DT_AdFee a with(nolock) where a.adasin=@adasin and addate>=@sdate and addate<@edate group by convert(nvarchar(10),addate,120),adsku,adasin "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); db.AddInParameter(cmd, "@adasin", DbType.String, adasin); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsStoreCount2(string adasin, DateTime? sdate, DateTime? edate, decimal fje) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @" select OrderDate=convert(nvarchar(10),a.OrderDate,120),DetailId=max(b.DetailId),proudctid=b.productImgUrl,ordernum=count(distinct PlatOrderCode),goodsNum=sum(b.GoodsNum),yf=SUM(dbo.[GetOrderPostFee](a.OrderId)),TotalPrice=sum(dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId)) into #DT_OrderInfo_ls from DT_OrderInfo a with(nolock) inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId where ISNULL(b.productImgUrl,'')=@adasin and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate and a.PlatId=2 and ISNULL(b.productImgUrl,'')<>'' and dbo.[GetOrderPostFee](a.OrderId)>0 group by convert(nvarchar(10),a.OrderDate,120),b.productImgUrl select adasin,addate=convert(nvarchar(10),addate,120),ggf=sum(dec3),ggzxl=sum(num1),ggdjl=sum(num2) into #DT_OrderInfo_ls2 from DT_AdFee a where addate>=@sdate and addate<@edate group by convert(nvarchar(10),addate,120),adasin select OrderDate,b.GoodsCode,a.SKU1,c.proudctid,b.FirstImgUrl,c.TotalPrice,yj=c.TotalPrice*0.15,cb=b.InPrice*c.goodsNum/6.6,c.ordernum,c.goodsNum,cbsf=b.InPrice*c.goodsNum*isnull(b.FeeRate,0)*0.01/6.6,c.yf,tc=130*isnull(b.Solid,0)*c.goodsNum,md=c.ordernum*0.6,ckf=c.TotalPrice*" + fje + @",d.* into #DT_OrderInfo_ls3 from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId inner join #DT_OrderInfo_ls c with(nolock) on a.DetailId=c.DetailId left join #DT_OrderInfo_ls2 d with(nolock) on c.proudctid=d.adasin and c.OrderDate=d.addate where c.proudctid=@adasin select *,ml1=TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf,ml2=TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf-isnull(ggf,0),mll1= case when TotalPrice>0 then (TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf)*100/TotalPrice else 0 end,mll2= case when TotalPrice>0 then (TotalPrice*0.85-cb-cbsf-yf-tc-md-ckf-isnull(ggf,0))*100/TotalPrice else 0 end from #DT_OrderInfo_ls3 drop table #DT_OrderInfo_ls,#DT_OrderInfo_ls2,#DT_OrderInfo_ls3 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); db.AddInParameter(cmd, "@adasin", DbType.String, adasin); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListAddr(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"id=cast(a.id as int),a.name,a.country,a.provice,a.city,a.addr,a.postcode,a.phone,a.mobile,a.indate,a.maildate,a.mailcount,a.acount,a.remark,a.ordernum,a.orderprice,a.lastdate,a.printdate"; ser.Tables = @"DT_Addr a with(nolock)"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListAddrMail(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"id=cast(a.id as int),a.addrid,a.maildate,a.printdate,a.mailcontent,a.postdate,a.printname,a.postname,a.state,statename=case when a.state=0 then '未打印' when a.state=1 then '打印未寄出' when a.state=2 then '已寄出' end,b.name,b.country,b.provice,b.city,b.addr,b.postcode,b.phone,b.mobile"; ser.Tables = @"DT_AddrMail a with(nolock) inner join DT_Addr b with(nolock) on a.addrid=b.id"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_AddrMail(DT_AddrMail Model) { string tsql = @" if(select count(0) from DT_AddrMail where [addrid]=@addrid and state<2)>0 begin select 0 end else begin INSERT INTO [DT_AddrMail]([addrid],[maildate],[printdate],[mailcontent],[postdate],[printname],[postname],[state])values(@addrid,@maildate,@printdate,@mailcontent,@postdate,@printname,@postname,@state) set @id=SCOPE_IDENTITY() update DT_Addr set maildate=getdate(),mailcount=isnull(mailcount,0)+1 where id=@addrid select 1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@addrid", DbType.Int32, Model.addrid); db.AddInParameter(cmd, "@maildate", DbType.DateTime, Model.maildate); db.AddInParameter(cmd, "@printdate", DbType.DateTime, Model.printdate); db.AddInParameter(cmd, "@mailcontent", DbType.String, Model.mailcontent); db.AddInParameter(cmd, "@postdate", DbType.DateTime, Model.postdate); db.AddInParameter(cmd, "@printname", DbType.String, Model.printname); db.AddInParameter(cmd, "@postname", DbType.String, Model.postname); db.AddInParameter(cmd, "@state", DbType.Int32, Model.state); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_price(string code, decimal? price, decimal? rate, DateTime? sdate, DateTime? edate) { string sql = ""; if (sdate != null) sql += " and a.InDate>='" + sdate.Value.ToString("yyyy-MM-dd") + "'"; if (edate != null) sql += " and a.InDate<'" + edate.Value.AddDays(1).ToString("yyyy-MM-dd") + "'"; string tsql = @" declare @goodsid int select @goodsid=GoodsId from HW_GoodsInfo where goodscode=@code or GoodsOldCode=@code if @goodsid>0 begin if @price>=0 and @rate>=0 begin update a set a.Price=@price,a.GoodsRate=@rate from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.GoodsId=@goodsid " + sql + @" end else if @price>=0 begin update a set a.Price=@price from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.GoodsId=@goodsid " + sql + @" end else if @rate>=0 begin update a set a.GoodsRate=@rate from HW_GoodsInDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.GoodsId=@goodsid " + sql + @" end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@code", DbType.String, code); db.AddInParameter(cmd, "@price", DbType.Decimal, price); db.AddInParameter(cmd, "@rate", DbType.Decimal, rate); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Update_AddrMail(int id, int state, string name) { string tsql = @" if @state=1 begin update DT_AddrMail set state=@state,printdate=getdate(),printname=@name where id=@id and state=0 end else begin update DT_AddrMail set state=@state,postdate=getdate(),postname=@name where id=@id end select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@name", DbType.String, name); db.AddInParameter(cmd, "@state", DbType.Int32, state); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_AddrMail(int id) { string tsql = @" delete from DT_AddrMail where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static int GetModel_OrderFee2() { //DT_OrderFees model = null; //string tsql = "select a.Id,a.OrderId,a.trackcode,a.ActualWeightAmount,a.ActualWeightUnits,a.RatedWeightAmount,a.DimLength,a.DimWidth,a.DimHeight,a.DimDivisor,a.DimUnit,a.ZoneCode,a.bigdifference,a.result,a.sku,a.indate,a.inname,a.fee1,a.fee2,a.fee3,a.fee4,a.fee5,a.int1,a.int2,a.int3,a.str1,a.str2,a.str3 from DT_PostVote"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GetOrderFees2"); db.ExecuteNonQuery(cmd); return 1; } #endregion #region 返回Model public static DT_OrderFees GetModel_OrderFee(int orderid) { DT_OrderFees model = null; //string tsql = "select a.Id,a.OrderId,a.trackcode,a.ActualWeightAmount,a.ActualWeightUnits,a.RatedWeightAmount,a.DimLength,a.DimWidth,a.DimHeight,a.DimDivisor,a.DimUnit,a.ZoneCode,a.bigdifference,a.result,a.sku,a.indate,a.inname,a.fee1,a.fee2,a.fee3,a.fee4,a.fee5,a.int1,a.int2,a.int3,a.str1,a.str2,a.str3 from DT_PostVote"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GetOrderFees"); db.AddInParameter(cmd, "@OrderId", DbType.Int32, orderid); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 计算仓储费 public static void updatestorefee(DateTime sdate, DateTime edate) { string tsql = @" update b set b.ckfee=DATEDIFF(DAY,c.InDate,c.UpDateTime)*b.GoodsNum*0.5*isnull(e.Solid,0),b.mdfee=b.GoodsNum*0.6 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsInDetail c on b.Id=c.OrderGoodsId inner join HW_GoodsDetail d on b.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId where a.OrderDate>=@sdate and a.OrderDate<@edate select c.adasin,dad=c.dec3/a.GoodsNum into #dt_adfee_ls from ( select a.productImgUrl,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a with(nolock) inner join DT_OrderInfo b with(nolock) on a.OrderId=b.OrderId where b.OrderDate>=@sdate and b.OrderDate<@edate group by a.productImgUrl)a inner join ( select adasin,dec3=SUM(dec3) from DT_AdFee where addate>=@sdate and addate<@edate group by adasin)c on a.productImgUrl=c.adasin update a set a.adfee=c.dad*a.GoodsNum from DT_OrderGoods a with(nolock) inner join DT_OrderInfo b with(nolock) on a.OrderId=b.OrderId inner join #dt_adfee_ls c with(nolock) on a.productImgUrl=c.adasin where b.OrderDate>=@sdate and b.OrderDate<@edate drop table #dt_adfee_ls "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); db.ExecuteNonQuery(cmd); } #endregion #region 保存退款 public static int Save_BackFee(string OrderCode, decimal BackFee) { string tsql = @" Update [DT_OrderInfo] set [DR_BackFee]=@BackFee,DR_BackFeeDate=getdate() where PlatOrderCode=@OrderCode select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@BackFee", DbType.Decimal, BackFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 读取人员 public static List GetKFUserInfo() { string tsql = @"select distinct a.UserId,Name from JC_UserInfo a inner join HW_GoodsInfo b on a.Name=b.kfname where a.state=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 保存退货运费 public static int Save_BackPostFee(DT_TrackCodeApply md) { string tsql = @" declare @OrderId int,@id int,@OldPostFee2 decimal(18,2) select top 1 @OrderId=OrderId from DT_OrderInfo where PlatOrderCode=@OrderCode select @id=id,@OldPostFee2=isnull(OldPostFee,0) from DT_TrackCodeApply where TrackCode=@TrackCode and TrackType=3 and state=1 if @id>0 begin update DT_TrackCodeApply set OldPostFee=@OldPostFee where id=@id update DT_OrderInfo set DR_PostFee=isnull(DR_PostFee,0)+@OldPostFee-@OldPostFee2,DR_PostFeeDate=getdate() where OrderId=@OrderId end else begin INSERT INTO [dbo].[DT_TrackCodeApply] ([PostId] ,[TrackType] ,[TrackCode] ,[GetDate] ,[InName] ,[OrderId] ,[State] ,[OrderCode] ,[OldPostFee] ) values(3,3,@TrackCode,GETDATE(),'退货导入',@OrderId,1,@OrderCode,@OldPostFee) update DT_OrderInfo set DR_PostFee=isnull(DR_PostFee,0)+@OldPostFee,DR_PostFeeDate=getdate() where OrderId=@OrderId end select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, md.TrackCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, md.OrderCode); db.AddInParameter(cmd, "@OldPostFee", DbType.Decimal, md.PostFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存申诉赔款 public static int Save_SSPostFee(DT_TrackCodeApply md) { string tsql = @" declare @OrderId int,@id int,@SSPostFee2 decimal(18,2) select top 1 @id=id,@SSPostFee2=isnull(SSPostFee,0),@OrderId=OrderId from DT_TrackCodeApply where TrackCode=@TrackCode and state=1 if @id>0 begin update [DT_TrackCodeApply] set SSPostFee=@SSPostFee,caseid=@caseid where id=@id update DT_OrderInfo set DR_SSFee=isnull(DR_SSFee,0)+@SSPostFee-@SSPostFee2,DR_SSFeeDate=getdate() where OrderId=@OrderId end select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, md.TrackCode); db.AddInParameter(cmd, "@caseid", DbType.String, md.TrackCode2); db.AddInParameter(cmd, "@SSPostFee", DbType.Decimal, md.PostFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存其他费用 public static int Save_OthersFee(string name, string goodscode, decimal je, DateTime sdt, DateTime edt, int isfg) { string tsql = @" declare @goodid int,@userid int,@Num int,@pje decimal(18,4) set @goodid=0 set @userid=0 select @goodid=GoodsId from HW_GoodsInfo where GoodsCode=@goodscode or GoodsOldCode=@goodscode if @goodid=0 begin select -1 return end select @userid=userid from JC_UserInfo where Name=@name and State=1 if @userid=0 begin select -2 return end select @Num=COUNT(0) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and c.GoodsId=@goodid and d.UserId=@userid if @Num=0 begin select -3 select @Num=COUNT(0) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid set @pje=@je/@Num if @isfg=1 --覆盖 begin update a set a.Other_Fee=@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid end else if @isfg=0 begin update a set a.Other_Fee=isnull(a.Other_Fee,0)+@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid end return end set @pje=@je/@Num if @isfg=1 --覆盖 begin update a set a.Other_Fee=@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and c.GoodsId=@goodid and d.UserId=@userid end else if @isfg=0 begin update a set a.Other_Fee=isnull(a.Other_Fee,0)+@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and c.GoodsId=@goodid and d.UserId=@userid end select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@name", DbType.String, name); db.AddInParameter(cmd, "@goodscode", DbType.String, goodscode); db.AddInParameter(cmd, "@je", DbType.Decimal, je); db.AddInParameter(cmd, "@sdt", DbType.DateTime, sdt); db.AddInParameter(cmd, "@edt", DbType.DateTime, edt); db.AddInParameter(cmd, "@isfg", DbType.Int32, isfg); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存广告费用 public static int Save_AdFeeNew(string name, string goodscode, decimal je, DateTime sdt, DateTime edt, int isfg) { string tsql = @" declare @goodid int,@userid int,@Num int,@pje decimal(18,4) set @goodid=0 set @userid=0 set @pje=0 select @userid=userid from JC_UserInfo where Name=@name and State=1 if @userid=0 begin select -2 return end select @Num=COUNT(0) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid if @Num>0 begin set @pje=@je/@Num end if @isfg=1 --覆盖 begin update a set a.Ad_Fee=@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid end else if @isfg=0 begin update a set a.Ad_Fee=isnull(a.Ad_Fee,0)+@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid end select -3 return select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@name", DbType.String, name); db.AddInParameter(cmd, "@goodscode", DbType.String, goodscode); db.AddInParameter(cmd, "@je", DbType.Decimal, je); db.AddInParameter(cmd, "@sdt", DbType.DateTime, sdt); db.AddInParameter(cmd, "@edt", DbType.DateTime, edt); db.AddInParameter(cmd, "@isfg", DbType.Int32, isfg); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存广告费用 public static int Save_AdFeeNew2(string name, string goodscode, decimal je, DateTime sdt, DateTime edt, int isfg) { string tsql = @" declare @goodid int,@userid int,@Num int,@pje decimal(18,4) set @goodid=0 set @userid=0 set @pje=0 --select @goodid=GoodsId from HW_GoodsInfo where GoodsCode=@goodscode or GoodsOldCode=@goodscode --if @goodid=0 --begin --select -1 --return --end select @userid=userid from JC_UserInfo where Name=@name and State=1 if @userid=0 begin select -2 return end --select @Num=COUNT(0) from DT_OrderInfo a --inner join DT_OrderGoods b on a.OrderId=b.OrderId --inner join HW_GoodsDetail c on b.DetailId=c.DetailId --inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId --where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and c.GoodsId=@goodid --and d.UserId=@userid --if @Num=0 --begin select @Num=COUNT(0) from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid if @Num>0 begin set @pje=@je/@Num end if @isfg=1 --覆盖 begin update a set a.Ad_Fee=@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid end else if @isfg=0 begin update a set a.Ad_Fee=isnull(a.Ad_Fee,0)+@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and d.UserId=@userid end select -3 return end else if @Num>0 begin set @pje=@je/@Num if @isfg=1 --覆盖 begin update a set a.Ad_Fee=@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and c.GoodsId=@goodid and d.UserId=@userid end else if @isfg=0 begin update a set a.Ad_Fee=isnull(a.Ad_Fee,0)+@pje from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsUser d on c.GoodsId=d.GoodsId and a.ShopId=d.ShopId where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt and c.GoodsId=@goodid and d.UserId=@userid end end select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@name", DbType.String, name); db.AddInParameter(cmd, "@goodscode", DbType.String, goodscode); db.AddInParameter(cmd, "@je", DbType.Decimal, je); db.AddInParameter(cmd, "@sdt", DbType.DateTime, sdt); db.AddInParameter(cmd, "@edt", DbType.DateTime, edt); db.AddInParameter(cmd, "@isfg", DbType.Int32, isfg); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 计算运费 public static void ComputerPostFees(string orderids) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @" update a set a.Country=b.Code from JC_PostFeeDetail a inner join JC_Country b on a.Country=b.EnglishName update a set a.Country=b.Code from JC_PostFeeDetail a inner join JC_Country b on a.CountryName=b.Name select b.Id,e.CountryCode,e.zone,Weight=isnull(c.Weight,d.Weight)*b.GoodsNum,e.Post,a.OrderId from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.OrderId in (" + orderids.TrimEnd(',') + @") select b.*,a.ExpressID from JC_PostFee a inner join JC_PostFeeDetail b on a.Id=b.FeeId order by b.FeeId,b.SWeight select a.OrderId from DT_OrderInfo a with(nolock) where a.OrderId in (" + orderids.TrimEnd(',') + @") select * from JC_Money "; if (orderids == "") { tsql = @" select b.Id,e.CountryCode,e.zone,Weight=d.Weight*b.GoodsNum,e.Post,a.OrderId from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where isnull(a.fee7,0)=0 and datediff(day,a.indate,getdate())<100 select b.*,a.ExpressID from JC_PostFee a inner join JC_PostFeeDetail b on a.Id=b.FeeId order by b.FeeId,b.SWeight select a.OrderId from DT_OrderInfo a with(nolock) where isnull(a.fee7,0)=0 and datediff(day,a.indate,getdate())<100 select * from JC_Money "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet tb = db.ExecuteDataSet(cmd); List ListModel = tb.Tables[0].ToList(); List ListModel2 = tb.Tables[1].ToList(); List ListModel3 = tb.Tables[2].ToList(); List ListModel4 = tb.Tables[3].ToList(); if (ListModel3 != null && ListModel != null && ListModel2 != null) { foreach (var omd in ListModel3) { decimal tfee = 0; var glist = ListModel.FindAll(n => n.OrderId == omd.OrderId); if (glist == null) continue; foreach (var md in glist) { if (md.Weight == null) continue; decimal fee = 0; decimal w = 0; if (md.Weight != null) w = md.Weight.Value; if (ListModel2 != null) { var fmd = ListModel2.FindAll(n => n.ExpressId == md.Post && n.CountryCode == md.CountryCode && n.Groups == md.zone); if (fmd == null || fmd.Count == 0) { fmd = ListModel2.FindAll(n => n.ExpressId == md.Post && n.CountryCode == md.CountryCode && n.Groups == null); } if (fmd == null || fmd.Count == 0) { fmd = ListModel2.FindAll(n => n.ExpressId == md.Post && n.CountryCode == md.CountryCode); } if (fmd != null && fmd.Count > 0) { decimal MRate = 1; decimal MRate2 = 1; var feemd = ListModel4.Find(n => n.MCode == fmd[0].MoneyCode); var feemd2 = ListModel4.Find(n => n.MCode == "USD"); if (feemd != null) { MRate = feemd.MRate.Value; } if (feemd2 != null) { MRate2 = feemd2.MRate.Value; } foreach (var ffmd in fmd) { // ffmd.WeightType = 2; if (ffmd.WeightType == 1)//首重 { if (ffmd.FeeRate != null) { if (w < ffmd.EWeight.Value) { fee += ffmd.FeeRate.Value * w; } else { fee += ffmd.FeeRate.Value * ffmd.EWeight.Value; } } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = w - ffmd.EWeight.Value; } else if (ffmd.WeightType == 3 && ffmd.SWeight <= w && w < ffmd.EWeight)//区间 { if (ffmd.FeeRate != null) { fee = ffmd.FeeRate.Value * w; } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = 0; } else if (w > 0 && ffmd.WeightType == 2)//续重 { if ((w + ffmd.SWeight) <= ffmd.EWeight)//结束在这个范围 { decimal ww = w; //if (ffmd.offunit != null && ffmd.offunit > 0) //{ // if (w % ffmd.offunit == 0) // ww = w / ffmd.offunit.Value; // else // ww = w / ffmd.offunit.Value + 1; //} if (ffmd.FeeRate != null) { fee += ffmd.FeeRate.Value * ww; } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = 0; } else if (w > 0) { decimal ww = 0; ww = ffmd.EWeight.Value - ffmd.SWeight.Value; if (ffmd.FeeRate != null) { fee += ffmd.FeeRate.Value * ww; } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = w - ww; } } } fee = fee * MRate / MRate2;//转美金 } } tfee += fee; if (fee > 0) { UpdateGoodsPostFee(md.Id.Value, fee); } } if (tfee > 0) { UpdateOrderPostFee(omd.OrderId.Value, tfee); } } } } #endregion #region 计算运费(单个订单) public static decimal? ComputerPostFeeOne(int OrderId) { //string tsql = "select a.id,a.mid,a.sdate,a.edate,a.weekname,a.weeknum from HW_ProductionDetail"; string tsql = @" update a set a.Country=b.Code from JC_PostFeeDetail a inner join JC_Country b on a.Country=b.EnglishName update a set a.Country=b.Code from JC_PostFeeDetail a inner join JC_Country b on a.CountryName=b.Name select b.Id,e.CountryCode,e.zone,Weight=isnull(c.Weight,d.Weight)*b.GoodsNum,e.Post,a.OrderId from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo e with(nolock) on a.OrderId=e.OrderId inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId inner join HW_GoodsDetail c with(nolock) on b.DetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.OrderId=@OrderId select b.*,a.ExpressID from JC_PostFee a inner join JC_PostFeeDetail b on a.Id=b.FeeId order by b.FeeId,b.SWeight select * from JC_Money "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet tb = db.ExecuteDataSet(cmd); List ListModel = tb.Tables[0].ToList(); List ListModel2 = tb.Tables[1].ToList(); List ListModel3 = tb.Tables[2].ToList(); decimal tfee = 0; decimal iserror = 0; if (ListModel != null) { foreach (var md in ListModel) { if (md.Weight == null) continue; decimal fee = 0; decimal w = 0; if (md.Weight != null) w = md.Weight.Value; if (ListModel2 != null) { var fmd = ListModel2.FindAll(n => n.ExpressId == md.Post && n.CountryCode == md.CountryCode && n.Groups == md.zone); if (fmd == null || fmd.Count == 0) { fmd = ListModel2.FindAll(n => n.ExpressId == md.Post && n.CountryCode == md.CountryCode && n.Groups == null); } if (fmd == null || fmd.Count == 0) { fmd = ListModel2.FindAll(n => n.ExpressId == md.Post && n.CountryCode == md.CountryCode); } if (fmd != null && fmd.Count > 0) { decimal MRate = 1; decimal MRate2 = 1; var feemd = ListModel3.Find(n => n.MCode == fmd[0].MoneyCode); var feemd2 = ListModel3.Find(n => n.MCode == "USD"); if (feemd != null) { MRate = feemd.MRate.Value; } if (feemd2 != null) { MRate2 = feemd2.MRate.Value; } foreach (var ffmd in fmd) { // ffmd.WeightType = 2; if (ffmd.WeightType == 1)//首重 { if (ffmd.FeeRate != null) { if (w < ffmd.EWeight.Value) { fee += ffmd.FeeRate.Value * w; } else { fee += ffmd.FeeRate.Value * ffmd.EWeight.Value; } } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = w - ffmd.EWeight.Value; } else if (ffmd.WeightType == 3 && ffmd.SWeight <= w && w < ffmd.EWeight)//区间 { if (ffmd.FeeRate != null) { fee = ffmd.FeeRate.Value * w; } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = 0; } else if (w > 0 && ffmd.WeightType == 2)//续重 { if ((w + ffmd.SWeight) <= ffmd.EWeight)//结束在这个范围 { decimal ww = w; //if (ffmd.offunit != null && ffmd.offunit > 0) //{ // if (w % ffmd.offunit == 0) // ww = w / ffmd.offunit.Value; // else // ww = w / ffmd.offunit.Value + 1; //} if (ffmd.FeeRate != null) { fee += ffmd.FeeRate.Value * ww; } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = 0; } else if (w > 0) { decimal ww = 0; ww = ffmd.EWeight.Value - ffmd.SWeight.Value; if (ffmd.FeeRate != null) { fee += ffmd.FeeRate.Value * ww; } if (ffmd.FeePrice != null) fee += ffmd.FeePrice.Value; if (ffmd.CodeFee != null) fee += ffmd.CodeFee.Value; w = w - ww; } } } fee = fee * MRate / MRate2;//转美金 } } tfee += fee; if (fee > 0) { UpdateGoodsPostFee(md.Id.Value, fee); } else { iserror = 1; } } } if (tfee > 0 && iserror == 0) { UpdateOrderPostFee(OrderId, tfee); } return tfee; } #endregion #region 保存 public static void UpdateGoodsPostFee(int id, decimal fee) { string tsql = @" update DT_OrderGoods set Fee7=@fee where ID=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@fee", DbType.Decimal, fee); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static void UpdateOrderPostFee(int OrderId, decimal fee) { string tsql = @" update DT_OrderInfo set Fee7=@fee where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@fee", DbType.Decimal, fee); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static void UpdateOrderPostId(int OrderId, int PostId) { string tsql = @" update DT_OrderxxInfo set Zone=[dbo].[GetOrderZone](@OrderId) where OrderId=@OrderId and Zone is null update DT_OrderXXInfo set Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set Post=@PostId where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.ExecuteNonQuery(cmd); } #endregion #region 修改订单地址 public static void UpdateOrderAddr2(DT_OrderModel Model) { string tsql = @" Update [DT_OrderXXInfo] set [RevName]=@RevName,CustomID=@CustomID,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName,Zone=@Zone where OrderId=@OrderId Update [DT_OrderXXInfoNew] set [RevName]=@RevName,CustomID=@CustomID,[RevCountry]=@RevCountry,RevMail=@RevMail,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,[RevMoblie]=@RevMoblie,[RevPostCode]=@RevPostCode,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,CountryCode=@CountryCode,CountryName=@CountryName where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@CountryCode", DbType.String, Model.CountryCode); db.AddInParameter(cmd, "@CountryName", DbType.String, Model.CountryName); db.AddInParameter(cmd, "@Zone", DbType.String, Model.PostOneCode); db.ExecuteNonQuery(cmd); } #endregion #region 读取人员 public static List GetJC_PostGroup(int orderid) { string tsql = @" declare @CountryCode nvarchar(50) select @CountryCode=CountryCode from DT_OrderXXInfo where orderid=@OrderId select distinct Groups from JC_PostFeeDetail where Groups is not null and CountryCode=@CountryCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, orderid); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 删除 public static void Delete_GoodsBFPlan(int year, int detailid, int sjout) { string tsql = @" delete from HW_GoodsBFPlan where year=@year and detailid=@detailid and isnull(sjout,0)=@sjout "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@detailid", DbType.Int32, detailid); db.AddInParameter(cmd, "@year", DbType.Int32, year); db.AddInParameter(cmd, "@sjout", DbType.Int32, sjout); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static int Save_GoodsBFPlan(HW_GoodsBFPlan Model) { string tsql = @" if @id>0 begin Update [HW_GoodsBFPlan] set [GoodsId]=@GoodsId,[detailid]=@detailid,[weekno]=@weekno,[year]=@year,[sdate]=@sdate,[edate]=@edate,[cgsl]=@cgsl,[indate]=@indate,[inname]=@inname,[outname]=@outname,[outdate]=@outdate,remark=@remark where id=@id end else begin INSERT INTO [HW_GoodsBFPlan]([GoodsId],[detailid],[weekno],[year],[sdate],[edate],[cgsl],[indate],[inname],[sjout],[ischeck],[outname],[outdate],[remark],[checknote])values(@GoodsId,@detailid,@weekno,@year,@sdate,@edate,@cgsl,@indate,@inname,@sjout,@ischeck,@outname,@outdate,@remark,@checknote) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@weekno", DbType.Int32, Model.weekno); db.AddInParameter(cmd, "@year", DbType.Int32, Model.year); db.AddInParameter(cmd, "@sdate", DbType.DateTime, Model.sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, Model.edate); db.AddInParameter(cmd, "@cgsl", DbType.Int32, Model.cgsl); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@sjout", DbType.Int32, Model.sjout); db.AddInParameter(cmd, "@ischeck", DbType.Int32, Model.ischeck); db.AddInParameter(cmd, "@outname", DbType.String, Model.outname); db.AddInParameter(cmd, "@outdate", DbType.DateTime, Model.outdate); db.AddInParameter(cmd, "@checknote", DbType.String, Model.checknote); db.AddInParameter(cmd, "@remark", DbType.String, Model.remark); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region public static void UpdateGoodsBFPlan(int detailid, int FHPlan) { string tsql = @" update HW_GoodsDetail set FHPlan=@FHPlan where detailid=@detailid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@detailid", DbType.Int32, detailid); db.AddInParameter(cmd, "@FHPlan", DbType.Int32, FHPlan); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListGoodsBFPlan(int year, int detailid, int sjout) { //string tsql = "select a.id,a.GoodsId,a.weekno,a.year,a.sdate,a.edate,a.cgsl,a.indate,a.inname from HW_GoodsBFPlan"; string tsql = "select * from HW_GoodsBFPlan where year=@year and detailid=@detailid and isnull(sjout,0)=@sjout "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@year", DbType.Int32, year); db.AddInParameter(cmd, "@detailid", DbType.Int32, detailid); db.AddInParameter(cmd, "@sjout", DbType.Int32, sjout); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 复制订单 public static int CopyOrderForTM2(int OrderId) { string tsql = @" declare @NewOrderId int INSERT INTO [DT_OrderInfo]([OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select [OrderLevel],[PlatId],[ShopId],OrderCode='C'+OrderCode,PlatOrderCode='C'+PlatOrderCode,JoinOrderCode=null,[OrderName],IsJoin=0,[GoodsCode],[GoodsName],[GoodsNum],0,0,[MoneyCode],[MoneyState],[MoneyDate],PostState=0,PostDate=null,PrintState=0,PrintDate=0,MateState=0,State=1,OrderDate,InDate=getdate(),[InUserId],UpdateDate=null,[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],0,0,[logisticsAmount],escrowFee=0,0,null,null,null,null,0,[FPDate] from DT_OrderInfo where OrderId=@OrderId set @NewOrderId=SCOPE_IDENTITY() INSERT INTO [DT_OrderXXInfo]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[LogisticsId]) select OrderId=@NewOrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],0,null,0,LogisticsId from DT_OrderXXInfo where OrderId=@OrderId INSERT INTO [DT_OrderInfoNew](OrderId,[OrderLevel],[PlatId],[ShopId],[OrderCode],[PlatOrderCode],[JoinOrderCode],[OrderName],[IsJoin],[GoodsCode],[GoodsName],[GoodsNum],[TotalPrice],[RMBPrice],[MoneyCode],[MoneyState],[MoneyDate],[PostState],[PostDate],[PrintState],[PrintDate],[MateState],[State],[OrderDate],[InDate],[InUserId],[UpdateDate],[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],[IsSpare],[NoBuy],[logisticsAmount],[escrowFee],[IsSDan],[BuyDate],[JoinDate],[IsJoinAddr],[SaleState],[IsBlank],[FPDate]) select @NewOrderId,[OrderLevel],[PlatId],[ShopId],OrderCode='C'+OrderCode,PlatOrderCode='C'+PlatOrderCode,JoinOrderCode=null,[OrderName],IsJoin=0,[GoodsCode],[GoodsName],[GoodsNum],0,0,[MoneyCode],[MoneyState],[MoneyDate],PostState=0,PostDate=null,PrintState=0,PrintDate=0,MateState=0,State=1,OrderDate,InDate=getdate(),[InUserId],UpdateDate=null,[SaleUserId],[CompanyId],[IsFba],[OrderOutDate],0,0,[logisticsAmount],escrowFee=0,0,null,null,null,null,0,[FPDate] from DT_OrderInfo where OrderId=@OrderId INSERT INTO [DT_OrderXXInfoNew]([OrderId],[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],[PostFee],[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],[TrackState],[TrackDate],[IsLeaveWord],[LogisticsId]) select OrderId=@NewOrderId,[TotalWeight],[TotalSoild],[MoneyType],[CustomID],[SKU],[RevName],[RevCountry],[RevAddr],[RevPhone],[RevMoblie],[RevMail],[RevFax],[RevPostCode],[SendInfo],[ErrorInfo],[BuyRemark],[LeaveWord],[FeeType],[IsRegister],[Post],PostFee=0.01,[BoxFee],[GoodsFee],[BankCode],[BankNo],[CustomBankCode],[CustomType],[ErrorImage],[Channel],[GoodsAddr],[TrackCode],[StoreId],[PostInfo],[OrderState],[RevProvince],[RevCity],[RevArea],[PostError],[CountryCode],[CountryName],[SendAddr],0,null,0,LogisticsId from DT_OrderXXInfo where OrderId=@OrderId INSERT INTO [DT_OrderGoods]([OrderId],[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],[LockNum],[ChaseId],[GoodsSKU],[GoodsName],[PostInfo],[OutNum],[productImgUrl],[GoodsDesc],[GoodsCode],[OldNum]) select OrderId=@NewOrderId,[DetailId],[GoodsNum],[GoodsPrice],[RMBMoney],[MoneyCode],0,0,[GoodsSKU],[GoodsName],[PostInfo],0,[productImgUrl],[GoodsDesc],[GoodsCode],0 from DT_OrderGoods where OrderId=@OrderId select @NewOrderId update b set b.GoodsPlanNum=b.GoodsPlanNum+a.GoodsNum from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId=@NewOrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region public static string Get_ChaseLsCode(int chaseid) { string tsql = @" select top 1 LsCode from CG_Purchase with(nolock) where chaseid=@chaseid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@chaseid", DbType.Int32, chaseid); string a = Convert.ToString(db.ExecuteScalar(cmd)); return a; } #endregion #region public static void update_ChaseLsCode(string LsCode, int chaseid) { string tsql = @" update CG_Purchase set LsCode=@LsCode where chaseid=@chaseid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@LsCode", DbType.String, LsCode); db.AddInParameter(cmd, "@chaseid", DbType.Int32, chaseid); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListCG_Purchase(int GoodsType, string Name, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); string Name1 = ""; string Name2 = ""; if (Name != "" && Name.Contains(' ')) { Name1 = Name.Split(' ')[0]; Name2 = Name.Split(' ')[1]; } string sql1 = ""; if (Name1 != "" && Name2 != "") { sql1 = @"select a.ChaseId into #chasetemp1 from (select a.ChaseId from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=1 and (c.GoodsCode like '%" + Name1 + "%' or c.GoodsOldCode like '%" + Name1 + "%') and b.TypeCode='" + Name2 + @"' union select a.ChaseId from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=1 and (c.GoodsCode like '%" + Name1 + "%' or c.GoodsOldCode like '%" + Name1 + "%') and (c.GoodsName like '%" + Name2 + "%' or b.TypeDesc like '%" + Name2 + @"%'))a "; } else if (GoodsType == 3 && Name != "") sql1 += @" select distinct a.ChaseId into #chasetemp1 from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.GoodsName like '%" + Name + "%' or c.GoodsOldCode like '%" + Name + "%' or c.GoodsCode like '%" + Name + "%' or b.TypeDesc like '%" + Name + "%'"; else if (GoodsType == 5 && Name != "") sql1 += @" select distinct a.ChaseId into #chasetemp1 from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.GoodsSupplyCode like '%" + Name + "%' "; else if (GoodsType == 6 && Name != "") sql1 += @" select distinct ChaseId into #chasetemp1 from CG_PurchasePost where PostCode like '%" + Name + "%' "; ser.Fields = @"ChaseId=cast(a.ChaseId as int),a.ChaseCode,a.BuyCode,a.GoodsState,a.PostFee,a.Remark,a.ErrorInfo,a.InDate,a.BuyDate,a.DoneDate,a.BackDate,a.Supplier,a.SupplierName,a.SupplierPhone,a.InName,a.InUserId,a.Account,a.IsDelete,a.State,a.CompanyId,a.CheckUid,CheckContent=a.LsCode,a.CheckDate,a.GoodsNum,a.GoodsMoney,checkstate=case when a.state=0 then '未审批' when a.state=1 then '审批通过' when a.state=2 then '审批不通过' when a.state=3 then '采购单结束' end,ReveState=case when a.GoodsState=0 then '未到货' when a.GoodsState=1 then '部分到货' when a.GoodsState=2 then '全部到货' when a.GoodsState=3 then '到货异常' end,PostStateName=case when a.PostState=1 then '在途' when a.PostState=2 then '签收' when a.PostState=3 then '停滞' else '无物流' end,b.InGoodsNum"; if (sql1 != "") ser.Tables = @"(select * from CG_Purchase where ChaseId in (select ChaseId from #chasetemp1))a inner join (select ChaseId,InGoodsNum=SUM(isnull(InGoodsNum,0)) from CG_PurchaseGoods group by ChaseId)b on a.ChaseId=b.ChaseId "; else ser.Tables = @"CG_Purchase a inner join (select ChaseId,InGoodsNum=SUM(isnull(InGoodsNum,0)) from CG_PurchaseGoods group by ChaseId)b on a.ChaseId=b.ChaseId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "ChaseId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); // db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion public static List GetListHW_GoodsInfoNewForTM(int CompanyId, string SKU, int IsDH, int IsBH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (@SKU='' or a.SKU1 like '%'+@SKU+'%' or a.SKU2 like '%'+@SKU+'%' or a.SKU3 like '%'+@SKU+'%' or a.SKU4 like '%'+@SKU+'%' or a.SKU5 like '%'+@SKU+'%' or a.SKU6 like '%'+@SKU+'%' or a.TypeCode like '%'+@SKU+'%' or a.TypeDesc like '%'+@SKU+'%' or b.GoodsName like '%'+@SKU+'%' or b.GoodsCode like '%'+@SKU+'%') and (@IsDH=0 or a.NoGoods=1) and (@IsSafe=0 or a.SafeNum>0) "; string[] templist = SKU.Split(' '); if (templist.Length > 1) { tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId WHERE (a.TypeCode LIKE '%" + templist[0] + @"%' OR a.TypeDesc LIKE '%" + templist[0] + @"%' OR b.GoodsCode LIKE '%" + templist[0] + @"%' OR b.GoodsOldCode LIKE '%" + templist[0] + @"%' OR b.GoodsName LIKE '%" + templist[0] + @"%') and (a.TypeCode LIKE '%" + templist[1] + @"%' OR a.TypeDesc LIKE '%" + templist[1] + @"%' OR b.GoodsCode LIKE '%" + templist[1] + @"%' OR b.GoodsOldCode LIKE '%" + templist[1] + @"%' OR b.GoodsName LIKE '%" + templist[1] + @"%') "; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,b.GoodsNum,GoodsOutNum=isnull(b.GoodsNum,0)+isnull(b.GoodsInNum2,0),GoodsInNum2=isnull(b.GoodsInNum2,0),b.GoodsInNum,b.LeftNum,b.GoodsHJNum2,b.GoodsHJNum3,b.GoodsHJNum4,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,b.GoodsHJNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.State,NoGoodsState=case when a.NoGoods=1 then '是' else '否' end,a.Cert,a.UpOff,NoticeDays=case when b.GoodsHJNum2-isnull(b.GoodsNum,0)-isnull(b.GoodsInNum2,0)>0 then b.GoodsHJNum2/3 else 0 end,GoodsInNum3=isnull(b.GoodsInNum,0),IsNull(a.IsYC,0) IsYC,Case when IsNull(a.IsYC,0)=0 then '隐藏' else '显示' end YCXS "; if (SKU != "" || IsDH == 1 || IsBH == 1) { ser.Tables = @"(select * from HW_GoodsInfo a with(nolock) where GoodsId in (" + tsql1 + @"))a left join ( select GoodsId,GoodsNum=isnull(SUM(GoodsNum),0),GoodsHJNum=isnull(SUM(GoodsHJNum),0),GoodsHJNum2=isnull(SUM(GoodsHJNum2),0),GoodsHJNum3=isnull(SUM(GoodsHJNum3),0),GoodsHJNum4=isnull(SUM(GoodsHJNum4),0),GoodsInNum=isnull(SUM(GoodsInNum),0),GoodsInNum2=isnull(SUM(GoodsInNum2),0),LeftNum=isnull(SUM(GoodsNum),0)+isnull(SUM(GoodsInNum2),0)-isnull(SUM(GoodsPlanNum),0) from HW_GoodsDetail with(nolock) group by GoodsId)b on a.GoodsId=b.GoodsId"; } else ser.Tables = @"HW_GoodsInfo a with(nolock) left join ( select GoodsId,GoodsNum=isnull(SUM(GoodsNum),0),GoodsHJNum=isnull(SUM(GoodsHJNum),0),GoodsHJNum2=isnull(SUM(GoodsHJNum2),0),GoodsInNum=isnull(SUM(GoodsInNum),0),GoodsHJNum3=isnull(SUM(GoodsHJNum3),0),GoodsHJNum4=isnull(SUM(GoodsHJNum4),0),GoodsInNum2=isnull(SUM(GoodsInNum2),0),LeftNum=isnull(SUM(GoodsNum),0)+isnull(SUM(GoodsInNum2),0)-isnull(SUM(GoodsPlanNum),0) from HW_GoodsDetail with(nolock) group by GoodsId)b on a.GoodsId=b.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@IsDH", DbType.Int32, IsDH); db.AddInParameter(cmd, "@IsSafe", DbType.Int32, IsBH); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #region 读取所有未处理的订单 public static List GetExpressSelect2(int PlatId) { List list = null; string tsql = @"select a.*,b.EnglishName from WL_ExpressSelect a left join JC_Country b on a.Country=b.Code where a.PlatId=@PlatId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); DataTable tb = db.ExecuteDataTable(cmd); list = tb.ToList(); return list; } #endregion #region ebay判断订单号是否重复 public static bool CheckJoinOrderCode3(int PlatType, string OrderCode, string OrderCode2, int OrderState) { string tsql = @" declare @OldOrderState int,@OrderId int set @OrderId=0 select top 1 @OldOrderState=isnull(OrderState,1),@OrderId=OrderId from API_OrderInfo where PlatType=@PlatType and (OrderCode=@OrderCode or PlatOrderCode=@OrderCode or OrderCode=@OrderCode2 or PlatOrderCode=@OrderCode2) if @OrderId>0 begin if @OldOrderState<>@OrderState begin update API_OrderInfo set state=0,OrderState=@OrderState where OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@OrderCode2", DbType.String, OrderCode2); db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a == 0) return true; return false; } #endregion #region 保存各平台数据 public static void SaveOrderModel2(int? CompanyId, int ShopId, string ShopName, int PlatType, int IsFba, List ListModel) { if (ListModel == null) return; var wllist = GetExpressSelect2(PlatType); foreach (var item in ListModel) { if (item.PlatOrderCode == "114-0802624-9887421" || item.OrderCode == "114-8187062-0093850") { string asfsffs = ""; } try { int OrderState = 1; item.OrderState = 1; //if (item.OrderState != null) // OrderState = item.OrderState.Value; if (PlatType == 1 && item.OutOrderDate != null) { if (API_OrderInfoService.CheckJoinOrderCode1(PlatType, item.OrderCode, OrderState, item.OutOrderDate.Value) == false) continue; } else if (PlatType == 3) { string oid = item.OrderCode; //if (item.PlatOrderCode != null && item.PlatOrderCode != "" && item.PlatOrderCode.Length > 5) string oid2 = item.PlatOrderCode; // item.OrderCode = oid; // item.PlatOrderCode = oid; if (DataNew.CheckJoinOrderCode3(PlatType, oid, oid2, OrderState) == false) continue; } else if (API_OrderInfoService.CheckJoinOrderCode(PlatType, item.OrderCode, OrderState) == false) continue; if (item.MoneyCode == "") item.MoneyCode = null; API_OrderInfo model = new API_OrderInfo(); model.ShopId = ShopId; model.ShopName = ShopName; model.OrderCode = item.OrderCode; model.PlatOrderCode = item.PlatOrderCode; model.HBOrderCode = item.HBOrderCode; model.TotalPrice = item.TotalPrice; model.MoneyCode = item.MoneyCode; model.OrderDate = item.OrderDate; model.CustomID = item.BuyerID; model.RevName = item.BuyerName; model.RevCountry = item.BuyerCountry; model.RevAddr = item.BuyerAddr; model.RevPhone = item.BuyerPhone; model.RevMobile = item.BuyerMobile; model.RevMail = item.BuyerMail; model.RevFax = item.BuyerFax; model.RevZip = item.BuyerZip; model.RevProvince = item.BuyerProvince; model.RevCity = item.BuyerCity; model.RevArea = item.BuyerArea; model.BuyRemark = item.OrderRemark; model.LeaveWord = item.LeaveWord; model.PayDate = item.PayDate; model.OutOrderDate = item.OutOrderDate; model.PlatType = PlatType; model.IsFba = IsFba; model.escrowFee = item.escrowFee; // model.loanAmount = item.loanAmount; model.logisticsAmount = item.logisticsAmount; model.PostInfo = item.PostInfo; if (wllist != null) { if (PlatType == 1) { //if(model.OrderCode=="72568607625211") //{ // string ddfsf = ""; //} var md = wllist.Find(n => n.ShopId == model.ShopId && n.PostInfo == model.PostInfo && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md == null) md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == model.PostInfo && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md == null) md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == model.PostInfo && n.Country == "0"); if (md == null) md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == "0" && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md != null) { model.LogisticsId = md.LogisticsId; model.ExpressId = md.ExpressId; } } else if (PlatType == 2) { var md = wllist.Find(n => n.PostInfo == model.PostInfo); if (md == null) md = wllist.Find(n => n.PostInfo == "0" && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md == null) md = wllist.Find(n => n.PostInfo == model.PostInfo && n.Country == "0"); if (md != null) { model.LogisticsId = md.LogisticsId; model.ExpressId = md.ExpressId; } } else if (PlatType >= 3 && PlatType <= 5) { var md = wllist.Find(n => n.ShopId == model.ShopId && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md == null) md = wllist.Find(n => n.ShopId == 0 && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md == null) md = wllist.Find(n => n.ShopId == 0 && n.Country == "0"); if (md != null) { model.LogisticsId = md.LogisticsId; model.ExpressId = md.ExpressId; } } else if (PlatType == 6) { var md = wllist.Find(n => n.PostInfo == model.PostInfo); //var md = wllist.Find(n => n.ShopId == model.ShopId && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); if (md == null) md = wllist.Find(n => n.ShopId == 0 && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry)); //if (md == null) //md = wllist.Find(n => n.ShopId == 0 && n.Country == "0"); if (md != null) { model.LogisticsId = md.LogisticsId; model.ExpressId = md.ExpressId; } } if (model.ExpressId == 7 || model.ExpressId == 65 || model.ExpressId == 67) //修改分配级别 { model.OrderLevel = 6; } } if (item.OrderState == null) model.OrderState = 1; else model.OrderState = item.OrderState; model.ListModel = new List(); int HJNum = 0; foreach (var item2 in item.ListModel) { API_OrderGoods check2 = null; if (item2.MoneyCode == "") item2.MoneyCode = null; API_OrderGoods model2 = new API_OrderGoods(); model2.productImgUrl = item2.productImgUrl; model2.GoodsNum = item2.GoodsNum; model2.GoodsPrice = item2.GoodsPrice; model2.MoneyCode = item2.MoneyCode; model2.GoodsName = item2.GoodsName; model2.GoodsDesc = item2.TypeDesc; model2.OrderItemId = item2.OrderItemId; if (item2.GoodsSKU == null) item2.GoodsSKU = ""; model2.GoodsSKU = item2.GoodsSKU; if (item2.GoodsSKU.Contains('{')) { // model2.GoodsSKU = item2.GoodsSKU.Substring(0, item2.GoodsSKU.IndexOf('{')).Trim(); string Num = item2.GoodsSKU.Substring(item2.GoodsSKU.IndexOf('{') + 1, item2.GoodsSKU.Length - item2.GoodsSKU.IndexOf('{') - 2); model2.OldNum = item2.GoodsNum; int GNum = 0; if (int.TryParse(Num.Trim(), out GNum) == true) model2.GoodsNum = GNum * model2.OldNum; } if (model.PlatType == 1) { string GoodsCode = item2.GoodsName.Trim().Replace(',', ' '); if (model2.GoodsSKU.Contains('-')) { string[] skulist = model2.GoodsSKU.Split('-'); // model2.GoodsDesc += " " + model2.GoodsSKU; // model2.GoodsSKU = skulist[1].Trim(); GoodsCode = skulist[0].Trim(); } else { if (GoodsCode.Contains(' ')) { GoodsCode = GoodsCode.Substring(GoodsCode.LastIndexOf(' ') + 1); model2.GoodsCode = GoodsCode; } } if (item2.TypeDesc != null && item2.TypeDesc != "") model2.GoodsName += "[" + item2.TypeDesc + "]"; model2.GoodsCode = GoodsCode; } model2.PostInfo = item2.PostInfo; if (model.PlatType == 1) { if (model2.GoodsCode != null && model2.GoodsCode != "") check2 = model.ListModel.Find(o => o.GoodsSKU == model2.GoodsSKU && o.GoodsCode == model2.GoodsCode); } else { check2 = model.ListModel.Find(o => o.GoodsSKU == item2.GoodsSKU); } HJNum += item2.GoodsNum.Value; if (check2 == null) { model.ListModel.Add(model2); } else { check2.GoodsNum = check2.GoodsNum + item2.GoodsNum; } } try { model.GoodsNum = HJNum; API_OrderInfoService.Save(CompanyId, model); } catch (Exception ex) { ErrorFollow.TraceWrite("保存各平台数据", "SaveOrderModel.Save", ex.Message + ";OrderCode:" + model.OrderCode); return; } } catch (Exception ex) { ErrorFollow.TraceWrite("保存各平台数据", "SaveOrderModel.Save", ex.Message); } } } #endregion #region 返回Model public static List GetOrderFees(string OrderIds) { List list = null; string tsql = @"select a.orderid,a.PlatId, a.TotalPrice,escrowFee=isnull(a.escrowFee,0),DR_BackFee=isnull(a.DR_BackFee,0),DR_PostFee=isnull(a.DR_PostFee,0),DR_SSFee=isnull(a.DR_SSFee,0),Ad_Fee=isnull(a.Ad_Fee,0),Other_Fee=isnull(a.Other_Fee,0),yj=isnull(b.yj,0),yf=isnull(b.yf,0),cb=isnull(b.cb,0),hwsf=isnull(b.hwsf,0),sjyf=isnull(b.sjyf,0),sjcb=isnull(b.sjcb,0),sjhwsf=isnull(b.sjhwsf,0),tc=isnull(b.tc,0),moneyrate=isnull(b.moneyrate,0),md=ISNULL(b.md,0),ck=ISNULL(b.ck,0),sjtc=isnull(b.sjtc,0), Isnull( b.SubsidyFee,0) SubsidyFee from DT_OrderInfo a with(nolock) left Join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回Model public static void GetModel_OrderFeeML() { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("ComputerOrderFees_WL"); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static void ComputerOrderFee_Order(int orderid) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("ComputerOrderFee_Order"); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static List GetYCOrders(string OrderIds) { List list = null; string tsql = @"select a.*,b.RevName,b.RevAddr,b.RevMoblie,b.RevPhone,b.RevPostCode,b.RevProvince,b.RevCity,b.RevCountry,b.RevFax,b.RevMail,b.CountryCode,b.PostInfo,b.RevArea,TrackCode=c.TrackCode from DT_OrderInfo a with(nolock) left Join DT_OrderXXInfo b with(nolock) on a.OrderId=b.orderid left join DT_TrackCodeApply c with(nolock) on a.OrderId=c.OrderId and c.State=1 where a.OrderId in (" + OrderIds + @") select TypeCode=b.SKU1,c.Weight,c.GoodsEnglisgName,c.GoodsName,a.* from DT_OrderGoods a left join HW_GoodsDetail b on a.DetailId=b.DetailId left join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId in (" + OrderIds + @") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); if (list != null) { var glist = ds.Tables[1].ToList(); if (glist != null) { foreach (var md in list) { var gmd = glist.FindAll(n => n.OrderId == md.OrderId); md.GoodsList = gmd; } } } return list; } #endregion #region 保存 public static int Save_YCLog(DT_YCLog Model) { string tsql = @" if @id>0 begin Update [DT_YCLog] set [orderid]=@orderid,[YC_OrderCode]=@YC_OrderCode,[YC_Result]=@YC_Result,[YC_Post]=@YC_Post,[indate]=@indate,[inname]=@inname where id=@id end else begin INSERT INTO [DT_YCLog]([orderid],[YC_OrderCode],[YC_Result],[YC_Post],[indate],[inname])values(@orderid,@YC_OrderCode,@YC_Result,@YC_Post,@indate,@inname) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@orderid", DbType.Int32, Model.orderid); db.AddInParameter(cmd, "@YC_OrderCode", DbType.String, Model.YC_OrderCode); db.AddInParameter(cmd, "@YC_Result", DbType.String, Model.YC_Result); db.AddInParameter(cmd, "@YC_Post", DbType.String, Model.YC_Post); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region public static void Update_YCOrder(int id, int YC_TS, string YC_Result) { string tsql = @" update DT_OrderInfoNew set YC_TS=@YC_TS,YC_Result=@YC_Result where orderid=@id update DT_OrderInfo set YC_TS=@YC_TS,YC_Result=@YC_Result where orderid=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@YC_TS", DbType.Int32, YC_TS); db.AddInParameter(cmd, "@YC_Result", DbType.String, YC_Result); db.ExecuteNonQuery(cmd); } #endregion #region 导入跟踪码 public static int ImportTrackCodeYC(int PostId, int LogisticsId, string OrderCode, string TrackCode, string Name) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin if(select count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and state=1)=0 begin INSERT INTO [dbo].[DT_TrackCodeApply] ([PostId] ,[TrackType] ,[TrackCode] ,[TrackCode2] ,[GetDate] ,[InName] ,[OrderId] ,[State] ,[UpdateTime] ,[OrderCode] ,[OldPostFee] ,[ScanState] ,[ScanDate]) values(@PostId,1,@TrackCode,null,getdate(),@Name,@OrderId,1,null,@OrderCode,null,0,null) update DT_OrderXXInfo set PostError=null,TrackState=1,LogisticsId=@LogisticsId,Post=@PostId where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1,LogisticsId=@LogisticsId,Post=@PostId where OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, LogisticsId); db.AddInParameter(cmd, "@Name", DbType.String, Name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询需要匹配的订单 public static List GetListDT_OrderInfoMate2(string GoodsName, string SKU, int IsSku, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; if (GoodsName != "") sql1 = @"select distinct a.OrderId from DT_OrderGoods a WITH(NOLOCK) inner join HW_GoodsDetail b WITH(NOLOCK) on a.DetailId=b.DetailId inner join HW_GoodsInfo c WITH(NOLOCK) on b.GoodsId=c.GoodsId where c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + "%' or c.GoodsOldCode like '%" + GoodsName + "%' or b.Sku1 like '%" + GoodsName + "%' "; //if (SKU != "") // sql1 = "select distinct OrderId from DT_OrderGoods where GoodsSKU like '%" + SKU + "%'"; //if (IsSku == 1 && sql1 == "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0"; //else // if (IsSku == 1 && sql1 != "") // sql1 = sql1 + " and a.DetailId>0"; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.OrderLevel,a.PlatId,a.ShopId,a.OrderCode,a.PlatOrderCode,a.JoinOrderCode,a.OrderName,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsCode,a.GoodsName,a.GoodsNum,a.TotalPrice,a.MoneyState,a.MoneyDate,a.PostState,a.PostDate,a.PrintState,a.MateState,MateStateName=case when a.MateState=0 then '未匹配' when a.MateState=1 then '部分匹配' when a.MateState=2 then '全部匹配' end,a.State,a.OrderDate,a.InDate,a.InUserId,a.UpdateDate,a.SaleUserId,a.CompanyId,b.RevCountry, ErrorInfo='',b.OrderState,b.Post,b.PostFee,b.PostInfo,CountryName=case when b.CountryName is null then b.RevCountry else b.CountryName end,c.ShopName,TrackStateName=a.YC_Result,a.YC_TS"; if (sql1 != "") { ser.Tables = @"(select * from DT_OrderInfoNew WITH(NOLOCK) where OrderId in (" + sql1 + "))a inner join DT_OrderXXInfoNew b WITH(NOLOCK) on a.OrderId=b.OrderId inner join jc_shop c WITH(NOLOCK) on a.ShopId=c.ShopId"; } else ser.Tables = @"DT_OrderInfoNew a WITH(NOLOCK) inner join DT_OrderXXInfoNew b WITH(NOLOCK) on a.OrderId=b.OrderId inner join jc_shop c WITH(NOLOCK) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 导入货物 public static int ExcelSaveGoodsSKUNEW(HW_GoodsExcelModel2 Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GoodsSKUImportNew"); db.AddInParameter(cmd, "@SortName", DbType.String, Model.SortName1); db.AddInParameter(cmd, "@SortId", DbType.Int32, Model.SortId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.GoodsCode); db.AddInParameter(cmd, "@GoodsEg", DbType.String, Model.GoodsEg); db.AddInParameter(cmd, "@GoodsNo", DbType.Int32, Model.GoodsNo); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsEnglishName", DbType.String, Model.GoodsEngLishName); db.AddInParameter(cmd, "@SKU1", DbType.String, Model.SKU1); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, Model.Weight2); db.AddInParameter(cmd, "@NetWeight", DbType.Decimal, Model.NetWeight); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@Long2", DbType.Decimal, Model.Long2); db.AddInParameter(cmd, "@Height2", DbType.Decimal, Model.Height2); db.AddInParameter(cmd, "@Width2", DbType.Decimal, Model.Width2); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TypeDesc", DbType.String, Model.TypeDesc); db.AddInParameter(cmd, "@Link1", DbType.String, Model.Link1); db.AddInParameter(cmd, "@LinkName1", DbType.String, Model.LinkName1); db.AddInParameter(cmd, "@Link2", DbType.String, Model.Link2); db.AddInParameter(cmd, "@LinkName2", DbType.String, Model.LinkName2); db.AddInParameter(cmd, "@Link3", DbType.String, Model.Link3); db.AddInParameter(cmd, "@LinkName3", DbType.String, Model.LinkName3); db.AddInParameter(cmd, "@Link4", DbType.String, Model.Link4); db.AddInParameter(cmd, "@LinkName4", DbType.String, Model.LinkName4); db.AddInParameter(cmd, "@ImgUrl", DbType.String, Model.ImgUrl); db.AddInParameter(cmd, "@Solid", DbType.Decimal, Model.Solid); db.AddInParameter(cmd, "@KFName", DbType.String, Model.KFName); db.AddInParameter(cmd, "@KFName2", DbType.String, Model.KFName2); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, Model.GoodsInfo); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@BoxRate", DbType.Decimal, Model.BoxRate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回skuModel public static HW_GoodsDetail GetGoodsDetailModel(string GoodsCode) { HW_GoodsDetail model = null; string tsql = @"select top 1 b.* from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId where b.SKU1 not like 'S-%' and (b.SKU1=@GoodsCode or a.GoodsCode=@GoodsCode or a.GoodsoldCode=@GoodsCode)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 验证 public static int IsChaseCode(string sku, string chasecode) { string tsql = @" declare @DetailId int set @DetailId=0 select @DetailId=detailid from HW_GoodsDetail where SKU1=@sku if @DetailId=0 begin select 0 end else if(select count(0) from CG_PurchaseGoods a inner join CG_Purchase d on a.ChaseId=d.ChaseId where d.IsDelete=0 and (d.ChaseCode=@chasecode or d.BuyCode=@chasecode) and a.GoodsDetailId=@DetailId)=0 begin select -1 end else begin select DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sku", DbType.String, sku); db.AddInParameter(cmd, "@chasecode", DbType.String, chasecode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 验证采购 public static List GetOutGoodsList(string sku, string chasecode, int outnum, int DetailId) { List list = null; string tsql = @" select Id=cast(a.Id as int),d.ChaseCode,d.InDate,c.GoodsCode,c.GoodsName,b.TypeDesc,FirstImgUrl=case when b.FirstImgUrl is not null or b.FirstImgUrl<>'' then b.FirstImgUrl else c.FirstImgUrl end,SJOutNum=a.OutNum-isnull(a.TJOutNum,0), OutNum=a.GoodsNum-isnull(a.InGoodsNum,0)-isnull(a.TJOutNum,0),a.OutInNum,c.Solid,a.GoodsPrice,a.GoodsNum,IsAdd=1,GoodsRate=isnull(c.FeeRate,0) from CG_PurchaseGoods a inner join CG_Purchase d on a.ChaseId=d.ChaseId inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where d.IsDelete=0 and a.GoodsNum-isnull(a.InGoodsNum,0)-isnull(a.TJOutNum,0)-@outnum>=0 and (d.ChaseCode=@chasecode or d.BuyCode=@chasecode) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sku", DbType.String, sku); db.AddInParameter(cmd, "@chasecode", DbType.String, chasecode); db.AddInParameter(cmd, "@outnum", DbType.Int32, outnum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存货物链接 /// /// 保存货物链接 /// public static int SaveBuyLink(HW_BuyLinkNew Model) { string tsql = @" if @LinkId>0 begin Update [HW_BuyLink] set [GoodsId]=@GoodsId,[LinkUrl]=@LinkUrl,[LinkName]=@LinkName,[LinkDesc]=@LinkDesc,Num=@Num,PM=@PM where LinkId=@LinkId end else begin INSERT INTO [HW_BuyLink]([GoodsId],[LinkUrl],[LinkName],[LinkDesc],Num,PM)values(@GoodsId,@LinkUrl,@LinkName,@LinkDesc,@Num,@PM) set @LinkId=@@IDENTITY end select @LinkId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@LinkId", DbType.Int32, Model.LinkId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@LinkUrl", DbType.String, Model.LinkUrl); db.AddInParameter(cmd, "@LinkName", DbType.String, Model.LinkName); db.AddInParameter(cmd, "@LinkDesc", DbType.String, Model.LinkDesc); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@PM", DbType.Int32, Model.PM); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListMBLinkOrder(string OrderIds) { //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @"select SKU1=c.GoodsCode,f.*,a.OrderId,GoodsHJNum2=f.Num2,e.ShopId from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c with(nolock) on b.GoodsId=c.GoodsId inner join DT_OrderInfo d with(nolock) on a.OrderId=d.OrderId inner join JC_Shop e with(nolock) on d.ShopId=e.ShopId left join (select GoodsId,LinkDesc,Num=MAX(Num),PM=MAX(PM),Num2=MAX(Num2) from HW_BuyLink group by GoodsId,LinkDesc)f on c.GoodsId=f.GoodsId and e.ShopName=f.LinkDesc where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListShopdata(int PlatType) { //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @"select a.*,PlatName=b.name from JC_Shop a inner join JC_BaseCodeDetail b on a.PlatType=b.SortNo and KeyName='ptlx' where (@PlatType=0 or PlatType=@PlatType)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回skuModel public static JC_ShopDataNew GetListShopDayFee(int ShopId) { JC_ShopDataNew model = null; string tsql = @"select top 1 * from JC_ShopData where ShopId=@ShopId order by InDate desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回列表 public static List GetListShopNo(int PlatType) { //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @"select distinct a.ShopNo,a.LoginName,PlatName=b.name from JC_Shop a inner join JC_BaseCodeDetail b on a.PlatType=b.SortNo and KeyName='ptlx' where ISNULL(ShopNo,'')<>'' and (@PlatType=0 or PlatType=@PlatType) order by a.ShopNo "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListShopMoney(DateTime? sdt, DateTime? edt) { //string tsql = "select a.Id,a.GoodsId,a.LinkUrl,a.Price,a.Sort,a.Price2,a.Price3,a.Remark,a.Remark2,a.Remark3 from HW_JZLink"; string tsql = @"select b.*,a.TotalPrice from ( select ShopId,TotalPrice=sum(dbo.MoneyUSDChange(TotalPrice,MoneyCode,1)) from DT_OrderInfo a with(nolock) where a.State>0 and a.State<3 and a.OrderDate>=@sdt and a.OrderDate<@edt group by ShopId)a inner join jc_shop b on a.ShopId=b.ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdt", DbType.DateTime, sdt); db.AddInParameter(cmd, "@edt", DbType.DateTime, edt); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 查询采购货物明细列表 public static List GetGoodsSPDetailFromSupplie(int Supplier) { List list = null; string tsql = ""; tsql = @" select a.*,BuyNum=case when (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))>=0 then 0 else isnull(a.GoodsPlanNum,0)-isnull(a.GoodsNum,0)-isnull(a.GoodsInNum,0) end,b.GoodsCode,b.GoodsOldCode,b.GoodsName,GoodsLeftNum=isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0),BuyMoney=case when a.Price>0 then a.Price else b.NowPrice end from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where (isnull(a.GoodsNum,0)+isnull(a.GoodsInNum,0)-isnull(a.GoodsPlanNum,0))<0 and b.Supplier=@Supplier order by b.GoodsId,a.TypeCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Supplier", DbType.Int32, Supplier); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物批次列表 public static List GetGoodsOutDetailNew(int CompanyId, string GoodsCode, string TypeCode, int StoreId) { List list = null; string tsql = @" select a.*,c.GoodsName,C.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.SKU1,d.StoreName,PostionDesc=isnull(e.PostionCode,'无'),Price=cast(c.SalePrice*1.09 as decimal(18,2)),FinalPrice=cast(c.SalePrice*1.09 as decimal(18,2)),commission=cast(isnull(c.SalePrice,0)*1.09*0.05 as decimal(18,2)),OffPrice=cast(0 as decimal(18,2)),c.FirstImgUrl from (select DetailId,StoreId,PostionId=ISNULL(PostionId,0),GoodsNum=sum(KCNum) from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,StoreId,PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StoreHouse d on a.StoreId=d.StoreId inner join CK_StorePostion e on a.PostionId=e.PostionId where c.CompanyId=@CompanyId and a.storeid=@StoreId and (c.GoodsCode=@GoodsCode or c.GoodsOldCode=@GoodsCode or b.SKU1=@GoodsCode or c.GoodsName=@GoodsCode) and (@TypeCode='' or b.TypeCode=@TypeCode) order by e.sortno "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@TypeCode", DbType.String, TypeCode); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物批次列表 public static List GetGoodsOutDetailNew2(string BarCode) { List list = null; string tsql = @" declare @detailid int,@PostionCode nvarchar(50),@return_quantity int,@rid int set @detailid=0 set @rid =0 select top 1 @detailid=detailid,@PostionCode =PostionCode,@return_quantity=return_quantity,@rid=id from DT_OrderReturn where BarCode=@BarCode and isnull(sale_outid,0)=0 select a.DetailId,rid=@rid,a.StoreId,a.PostionId,GoodsNum=case when a.GoodsNum>@return_quantity then @return_quantity else a.GoodsNum end ,c.GoodsName,C.GoodsCode,c.GoodsOldCode,b.TypeCode,b.TypeDesc,b.SKU1,d.StoreName,PostionDesc=isnull(e.PostionCode,'无'),Price=cast(c.SalePrice*1.09 as decimal(18,2)),FinalPrice=cast(c.SalePrice*1.09 as decimal(18,2)),commission=cast(isnull(c.SalePrice,0)*1.09*0.05 as decimal(18,2)),OffPrice=cast(0 as decimal(18,2)),c.FirstImgUrl from (select DetailId,StoreId,PostionId=ISNULL(PostionId,0),GoodsNum=sum(KCNum) from HW_GoodsInDetail where OrderGoodsId=0 group by DetailId,StoreId,PostionId)a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId inner join CK_StoreHouse d on a.StoreId=d.StoreId inner join CK_StorePostion e on a.PostionId=e.PostionId where c.CompanyId=1 and e.PostionCode=@PostionCode and b.DetailId=@DetailId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@BarCode", DbType.String, BarCode); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物批次列表 public static List GetBuyGoodsList(string ids) { List list = null; string tsql = @" select a.ChaseCode,a.BuyDate,c.SKU1,b.GoodsNum,b.GoodsPrice,ReveState=case when a.GoodsState=0 then '未到货' when a.GoodsState=1 then '部分到货' when a.GoodsState=2 then '全部到货' when a.GoodsState=3 then '到货异常' end,a.ErrorInfo,a.BuyCode,a.PostFee,a.GoodsMoney from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=b.ChaseId inner join HW_GoodsDetail c on b.GoodsDetailId=c.DetailId where a.ChaseId in (" + ids + @") order by a.ChaseCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存货物出库明细 public static void DeleteGoodsOutDetailBuy(int outid) { string tsql = @" delete from [HW_GoodsOutDetail] where [OutId]=@OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, outid); db.ExecuteNonQuery(cmd); } #endregion #region 保存货物出库明细 public static int SaveGoodsOutDetailBuy(HW_GoodsOutCKNew Model, int state) { string tsql = @" if @Id>0 begin Update [HW_GoodsOutDetail] set [OutId]=@OutId,[OutNum]=@OutNum,[DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId,Price=@Price,OffPrice=@OffPrice where Id=@Id end else begin INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId],Price,OffPrice)values(@OutId,@OutNum,@DetailId,@StoreId,@PostionId,@Price,@OffPrice) set @Id=SCOPE_IDENTITY() end if @rid>0 and @state=2 --关联退货 begin update DT_OrderReturn set sale_outid=@Id,sale_price=@Price*(1-@OffPrice*0.01) where id=@rid end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@state", DbType.Int32, state); db.AddInParameter(cmd, "@rid", DbType.Int32, Model.rid); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@OffPrice", DbType.Decimal, Model.OffPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物出库明细 public static int SaveGoodsOutDetailBuy_NM(HW_GoodsOutCKNew Model, int state) { string tsql = @" if @Id>0 begin Update [HW_GoodsOutDetail] set [OutId]=@OutId,[OutNum]=@OutNum,[DetailId]=@DetailId,[StoreId]=@StoreId,[PostionId]=@PostionId,Price=@Price,OffPrice=@OffPrice where Id=@Id end else begin INSERT INTO [HW_GoodsOutDetail]([OutId],[OutNum],[DetailId],[StoreId],[PostionId],Price,OffPrice)values(@OutId,@OutNum,@DetailId,@StoreId,@PostionId,@Price,@OffPrice) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@state", DbType.Int32, state); db.AddInParameter(cmd, "@rid", DbType.Int32, Model.rid); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, Model.PostionId); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@OffPrice", DbType.Decimal, Model.OffPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物出库记录 public static int SaveGoodsOutBuy(HW_GoodsOutRecordBuy Model) { string tsql = @" if @OutId>0 begin Update [HW_GoodsOutList] set [OutCode]=@OutCode,[OutReason]=@OutReason,[Remark]=@Remark,[OutNum]=@OutNum,[InUserId]=@InUserId,[InDate]=@InDate,[InName]=@InName,[CompanyId]=@CompanyId,IsDelete=@IsDelete,OrderId=@OrderId,Price=@Price,BuyName=@BuyName,BuyPhone=@BuyPhone,StoreName=@StoreName,StoreId=@StoreId where OutId=@OutId end else begin INSERT INTO [HW_GoodsOutList]([OutCode],[OutReason],[Remark],[OutNum],[InUserId],[InDate],[InName],[CompanyId],IsDelete,OrderId,Price,BuyName,BuyPhone,StoreId,StoreName)values(@OutCode,@OutReason,@Remark,@OutNum,@InUserId,@InDate,@InName,@CompanyId,@IsDelete,@OrderId,@Price,@BuyName,@BuyPhone,@StoreId,@StoreName) set @OutId=SCOPE_IDENTITY() end select @OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, Model.OutId); db.AddInParameter(cmd, "@OutCode", DbType.String, Model.OutCode); db.AddInParameter(cmd, "@OutReason", DbType.String, Model.OutReason); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@OutNum", DbType.Int32, Model.OutNum); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@InName", DbType.String, Model.InName); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@IsDelete", DbType.Int32, Model.IsDelete); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@BuyName", DbType.String, Model.BuyName); db.AddInParameter(cmd, "@BuyPhone", DbType.String, Model.BuyPhone); db.AddInParameter(cmd, "@StoreName", DbType.String, Model.StoreName); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存货物出库记录 public static int UpdateGoodsOutBuyNM(int OutId, int state, string PayType) { string tsql = @" Update [HW_GoodsOutList] set IsDelete=@state,PayType=@PayType where OutId=@OutId select @OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); db.AddInParameter(cmd, "@state", DbType.Int32, state); db.AddInParameter(cmd, "@PayType", DbType.String, PayType); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询出库记录 public static List GetListHW_GoodsOutListBuy(int TJ, string CKYY, string Name, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OutId=cast(a.OutId as int),a.OutCode,a.OutReason,a.Remark,a.OutNum,a.InUserId,a.InDate,a.InName,a.BuyName,a.BuyPhone,a.Price,commission=isnull(a.Price,0)*0.05,state=case when a.isdelete=0 or a.isdelete=3 then 'Unshipped' else 'shipped' end,a.StoreId,a.StoreName,a.PayType,a.isdelete"; string sql1 = ""; if (CKYY != "") sql1 += " OutReason in (" + CKYY + ") and "; if (Name != "") { if (TJ == 1) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsCode='" + Name + "' or e.GoodsOldCode='" + Name + "' or b.sku1='" + Name + "'))a"; } else if (TJ == 2) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId where e.GoodsName like '%" + Name + "%'))a"; } else if (TJ == 3) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where b.SKU1='" + Name + "' or b.SKU2='" + Name + "' or b.SKU3='" + Name + "' or b.SKU4='" + Name + "' or b.SKU5='" + Name + "'))a"; } else if (TJ == 4) { ser.Tables = @"(select * from HW_GoodsOutList where " + sql1 + @" OutId in (select distinct a.OutId from HW_GoodsOutDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId where b.PostionCode='" + Name + "' or b.PostionDesc='" + Name + "'))a"; } } ser.Tables = @"(select * from HW_GoodsOutList a with(nolock) where OutReason in (" + CKYY + ") )a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OutId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回出库明细 public static List GetOutCKDetailListForTM(int OutId) { List list = null; string tsql = @" select a.*,e.GoodsId,e.GoodsCode,e.GoodsOldCode,e.GoodsName,b.TypeCode,b.SKU1,b.TypeDesc,FinalPrice=a.Price*(1-isnull(a.OffPrice,0)*0.01)*a.OutNum,PostionDesc=d.PostionCode from HW_GoodsOutDetail a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId where a.OutId=@OutId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 返回出库Model public static HW_GoodsOutRecordBuy GetOutCKModelBuy(int OutId) { HW_GoodsOutRecordBuy model = null; string tsql = "select * from HW_GoodsOutList where OutId=@OutId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion public static int iskc(int PostionId, int DetailId) { string tsql = " select KCNum=sum(KCNum) from HW_GoodsInDetail where OrderGoodsId=0 and PostionId=@PostionId and DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #region 返回出库明细 public static List GetOutCKDetailListBuyExcel(int OutId) { List list = null; string tsql = @" select a.*,e.GoodsId,e.GoodsCode,e.GoodsOldCode,e.GoodsName,b.TypeCode,b.SKU1,b.TypeDesc,FinalPrice=a.Price*(1-isnull(a.OffPrice,0)*0.01)*a.OutNum,PostionDesc=d.PostionCode,f.OutCode,f.BuyName,f.BuyPhone,Total=f.Price from HW_GoodsOutDetail a inner join HW_GoodsOutList f on a.OutId=f.OutId inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo e on b.GoodsId=e.GoodsId inner join CK_StorePostion d on a.PostionId=d.PostionId where a.OutId=@OutId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存 public static int Save_OrderReturn(DT_OrderReturn Model) { string tsql = @" select top 1 @orderid=orderid from DT_OrderInfo where PlatOrderCode=@ordercode select top 1 @detailid=detailid from DT_OrderGoods where productImgUrl=@asin and orderid=@orderid declare @OldPostionCode nvarchar(50) select top 1 @OldPostionCode=d.PostionCode from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsInDetail c on b.Id=c.OrderGoodsId inner join CK_StorePostion d on c.PostionId=d.PostionId where a.OrderId=@orderid and b.DetailId=@detailid if(select count(0) from DT_OrderReturn with(nolock) where ordercode=@ordercode and asin=@asin)=0 begin INSERT INTO[DT_OrderReturn] ([orderid],[ordercode],[asin],[return_reason_code],[merchant_sku],[in_policy],[return_quantity],[resolution],[refund_amount],[tracking_id],[return_carrier],[label_cost],[order_date],[return_request_date],[return_request_status],[ScanDate],[InType],[ScanState],[ScanUserId],[remark],[PostionCode],[detailid],OldPostionCode,barcode) values(@orderid, @ordercode, @asin, @return_reason_code, @merchant_sku, @in_policy, @return_quantity, @resolution, @refund_amount, @tracking_id, @return_carrier, @label_cost, @order_date, @return_request_date, @return_request_status, @ScanDate, @InType, @ScanState, @ScanUserId, @remark, @PostionCode, @detailid,@OldPostionCode,@barcode) set @id = SCOPE_IDENTITY() end else begin update DT_OrderReturn set tracking_id=@tracking_id where ordercode=@ordercode and asin=@asin and isnull(tracking_id,'')='' end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@orderid", DbType.Int32, Model.orderid); db.AddInParameter(cmd, "@ordercode", DbType.String, Model.ordercode); db.AddInParameter(cmd, "@asin", DbType.String, Model.asin); db.AddInParameter(cmd, "@return_reason_code", DbType.String, Model.return_reason_code); db.AddInParameter(cmd, "@merchant_sku", DbType.String, Model.merchant_sku); db.AddInParameter(cmd, "@in_policy", DbType.String, Model.in_policy); db.AddInParameter(cmd, "@return_quantity", DbType.Int32, Model.return_quantity); db.AddInParameter(cmd, "@resolution", DbType.String, Model.resolution); db.AddInParameter(cmd, "@refund_amount", DbType.Decimal, Model.refund_amount); db.AddInParameter(cmd, "@tracking_id", DbType.String, Model.tracking_id); db.AddInParameter(cmd, "@return_carrier", DbType.String, Model.return_carrier); db.AddInParameter(cmd, "@label_cost", DbType.Decimal, Model.label_cost); db.AddInParameter(cmd, "@order_date", DbType.DateTime, Model.order_date); db.AddInParameter(cmd, "@return_request_date", DbType.DateTime, Model.return_request_date); db.AddInParameter(cmd, "@return_request_status", DbType.String, Model.return_request_status); db.AddInParameter(cmd, "@ScanDate", DbType.DateTime, Model.ScanDate); db.AddInParameter(cmd, "@InType", DbType.String, Model.InType); db.AddInParameter(cmd, "@ScanState", DbType.String, Model.ScanState); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@remark", DbType.String, Model.remark); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@barcode", DbType.String, Model.barcode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_OrderReturnExcel(DT_OrderReturn Model) { string tsql = @" select top 1 @orderid=orderid,@order_date=OrderDate from DT_OrderInfo where PlatOrderCode=@ordercode select top 1 @detailid=detailid from HW_GoodsDetail where SKU1=@merchant_sku or SKU2=@merchant_sku or SKU3=@merchant_sku or SKU4=@merchant_sku if @detailid=0 or @orderid=0 begin select 0 end else begin if(select count(0) from DT_OrderReturn with(nolock) where ordercode=@ordercode and detailid=@detailid and tracking_id=@tracking_id)=0 begin INSERT INTO[DT_OrderReturn] ([orderid],[ordercode],[asin],[return_reason_code],[merchant_sku],[in_policy],[return_quantity],[resolution],[refund_amount],[tracking_id],[return_carrier],[label_cost],[order_date],[return_request_date],[return_request_status],[ScanDate],[InType],[ScanState],[ScanUserId],[remark],[PostionCode],[detailid],OldPostionCode,barcode) values(@orderid, @ordercode, @asin, @return_reason_code, @merchant_sku, @in_policy, @return_quantity, @resolution, @refund_amount, @tracking_id, @return_carrier, @label_cost, @order_date, @return_request_date, @return_request_status, @ScanDate, @InType, @ScanState, @ScanUserId, @remark, @PostionCode, @detailid,'',@barcode) set @id = SCOPE_IDENTITY() end select 1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@orderid", DbType.Int32, Model.orderid); db.AddInParameter(cmd, "@ordercode", DbType.String, Model.ordercode); db.AddInParameter(cmd, "@asin", DbType.String, Model.asin); db.AddInParameter(cmd, "@return_reason_code", DbType.String, Model.return_reason_code); db.AddInParameter(cmd, "@merchant_sku", DbType.String, Model.merchant_sku); db.AddInParameter(cmd, "@in_policy", DbType.String, Model.in_policy); db.AddInParameter(cmd, "@return_quantity", DbType.Int32, Model.return_quantity); db.AddInParameter(cmd, "@resolution", DbType.String, Model.resolution); db.AddInParameter(cmd, "@refund_amount", DbType.Decimal, Model.refund_amount); db.AddInParameter(cmd, "@tracking_id", DbType.String, Model.tracking_id); db.AddInParameter(cmd, "@return_carrier", DbType.String, Model.return_carrier); db.AddInParameter(cmd, "@label_cost", DbType.Decimal, Model.label_cost); db.AddInParameter(cmd, "@order_date", DbType.DateTime, Model.order_date); db.AddInParameter(cmd, "@return_request_date", DbType.DateTime, Model.return_request_date); db.AddInParameter(cmd, "@return_request_status", DbType.String, Model.return_request_status); db.AddInParameter(cmd, "@ScanDate", DbType.DateTime, Model.ScanDate); db.AddInParameter(cmd, "@InType", DbType.String, Model.InType); db.AddInParameter(cmd, "@ScanState", DbType.String, Model.ScanState); db.AddInParameter(cmd, "@ScanUserId", DbType.Int32, Model.ScanUserId); db.AddInParameter(cmd, "@remark", DbType.String, Model.remark); db.AddInParameter(cmd, "@PostionCode", DbType.String, Model.PostionCode); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@barcode", DbType.String, Model.barcode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public static List GetListOrderReturn(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"id=cast(a.id as int),c.ShopName,c.ShopId,order_amount=b.TotalPrice,Img_Url=f.FirstImgUrl,d.Name,a.orderid,a.ordercode,a.asin,a.return_reason_code,a.merchant_sku,a.in_policy,a.return_quantity,a.resolution,a.refund_amount,a.tracking_id,a.return_carrier,a.label_cost,a.order_date,a.return_request_date,a.return_request_status,a.ScanDate,a.InType,a.ScanState,a.ScanUserId,a.remark,a.PostionCode,a.detailid,a.BarCode,a.ImgUrl,a.ImgUrl2,a.ImgUrl3,a.ImgUrl4,a.ImgUrl5,Case when WorkDesc='东仓' then 'E' when WorkDesc='西仓' then 'W' else '' end StoreName,IsNull(a.IsOfferUp,0) IsOfferUp, IsNull(a.IsMaketPlace,0) IsMaketPlace "; ser.Tables = @"DT_OrderReturn a with(nolock) left join DT_OrderInfo b with(nolock) on a.orderid=b.OrderId left join JC_Shop c with(nolock) on b.ShopId=c.ShopId left Join JC_UserInfo d with(nolock) on a.ScanUserId=d.UserId left join HW_GoodsDetail e with(nolock) on a.detailid=e.DetailId left join HW_GoodsInfo f with(nolock) on e.GoodsId=f.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存货物出库明细 public static void updatetracking_id(int id, string tracking_id, int isOfferUp, int isMaketPlace) { string tsql = @" update [DT_OrderReturn] set tracking_id=@tracking_id,isOfferUp=@isOfferUp,isMaketPlace=@isMaketPlace where [id]=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@tracking_id", DbType.String, tracking_id); db.AddInParameter(cmd, "@isOfferUp", DbType.Int32, isOfferUp); db.AddInParameter(cmd, "@isMaketPlace", DbType.Int32, isMaketPlace); db.ExecuteNonQuery(cmd); } #endregion public static int OrderAdd_HWC(DT_OrderInfo_HWC Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderAdd_HWC"); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode); db.AddInParameter(cmd, "@OrderName", DbType.String, Model.OrderName); db.AddInParameter(cmd, "@PlatId", DbType.Int32, Model.PlatId); db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId); db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID); db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName); db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr); db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone); db.AddInParameter(cmd, "@RevMoblie", DbType.String, Model.RevMoblie); db.AddInParameter(cmd, "@RevPostCode", DbType.String, Model.RevPostCode); db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry); db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince); db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity); db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea); db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail); db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, Model.PostFee); db.AddInParameter(cmd, "@OrderDate", DbType.DateTime, Model.OrderDate); db.AddInParameter(cmd, "@PayState", DbType.String, Model.PayState); db.AddInParameter(cmd, "@PayDate", DbType.DateTime, Model.PayDate); db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord); db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo); db.AddInParameter(cmd, "@InUserId", DbType.Int32, Model.InUserId); db.AddInParameter(cmd, "@TrackCode", DbType.String, Model.TrackCode); db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode); db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@StoreCode", DbType.String, Model.StoreCode); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a > 0 && Model.GoodsList != null) { foreach (var md in Model.GoodsList) { md.OrderId = a; OrderGoodsAdd_HWC(md); } } return a; } #region 导入订单货物 public static void OrderGoodsAdd_HWC(Order_GoodsInfoModel_HWC Model) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderGoodsAdd_HWC"); db.AddInParameter(cmd, "@OrderId", DbType.String, Model.OrderId); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsCode", DbType.String, Model.SKU); db.AddInParameter(cmd, "@GoodsNum ", DbType.Int32, Model.GoodsNum); db.AddInParameter(cmd, "@GoodsName", DbType.String, Model.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, Model.GoodsENName); db.AddInParameter(cmd, "@Weight", DbType.Decimal, Model.Weight); db.AddInParameter(cmd, "@Long", DbType.Decimal, Model.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, Model.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, Model.Height); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.ExecuteNonQuery(cmd); } #endregion public static int IsCompany(string apikey) { string tsql = @" declare @CompanyId int select @CompanyId=0 select @CompanyId=CompanyId from JC_Company where apikey=@apikey select CompanyId=@CompanyId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@apikey", DbType.String, apikey); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } public static int CancelOrder(string ordercode, int CompanyId) { string tsql = @" declare @PrintState int set @PrintState=-1 select top 1 @PrintState=isnull(PrintState,0) from DT_OrderInfo where CompanyId=@CompanyId and PlatOrderCode=@ordercode and State>0 and State<3 if @PrintState=-1 begin select -1 end else if @PrintState>0 begin select 0 end else begin update DT_OrderInfo set state=0 where CompanyId=@CompanyId and PlatOrderCode=@ordercode update DT_OrderInfoNew set state=0 where CompanyId=@CompanyId and PlatOrderCode=@ordercode end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ordercode", DbType.String, ordercode); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } public static decimal IsFee(int CompanyId) { string tsql = @" update a set a.hjfee=b.infee from JC_Company a inner join ( select CompanyId,infee=SUM(InUSDFee) from JC_CompanyFee where CompanyId=@CompanyId group by CompanyId)b on a.CompanyId=b.CompanyId update a set a.hjygfee=b.fee1 from JC_Company a inner join ( select CompanyId,fee1=SUM(isnull(fee1,0)) from DT_OrderInfo where CompanyId=@CompanyId and State>0 and State<3 group by CompanyId)b on a.CompanyId=b.CompanyId select leftfee=isnull(hjfee,0)-isnull(hjygfee,0) from JC_Company where CompanyId=@CompanyId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); decimal a = Convert.ToDecimal(db.ExecuteScalar(cmd)); return a; } #region 返回Model public static CK_FeeReportNew2 GetHWCCZFee(int companyid) { CK_FeeReportNew2 model = null; string tsql = "select HJCZFee=isnull(hjfee,0),hjygfee=isnull(hjygfee,0) from JC_Company where companyid=@companyid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@companyid", DbType.Int32, companyid); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 导入跟踪码 public static int ImportTrackCodeClear(string TrackCode) { string tsql = @" declare @OrderId int,@OrderCode nvarchar(50) select @OrderId=OrderId,@OrderCode=OrderCode from DT_TrackCodeApply where state=1 and (REPLACE(TrackCode,' ','')=@TrackCode or TrackCode2=@TrackCode) if @OrderId>0 begin update DT_OrderInfo set Fee2=0 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0 where OrderId=@OrderId select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public static int ImportTrackCodeNew(string TrackCode, decimal PostFee, decimal? PostFee2) { string tsql = @" declare @OrderId int,@OrderCode nvarchar(50) select @OrderId=OrderId,@OrderCode=OrderCode from DT_TrackCodeApply where state=1 and (REPLACE(TrackCode,' ','')=@TrackCode or TrackCode2=@TrackCode) if @OrderId>0 begin update DT_OrderInfo set Fee2=@PostFee where OrderId=@OrderId update DT_OrderXXInfo set PostFee=PostFee+@PostFee where OrderId=@OrderId if(select count(0) from DT_TrackCodeScan where TrackCode=@TrackCode)>0 update DT_TrackCodeScan set PostFee=@PostFee,OldPostFee=@PostFee where REPLACE(TrackCode,' ','')=@TrackCode else begin INSERT INTO [dbo].[DT_TrackCodeScan] ([PostId] ,[TrackCode] ,[InDate] ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId] ,[Weight] ,[PostFee] ,[OldPostFee]) select [PostId] ,[TrackCode] ,[InDate]=GETDATE() ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId]=1 ,[Weight]=0 ,[PostFee]=@PostFee ,[OldPostFee]=@PostFee from DT_TrackCodeApply where State=1 and REPLACE(TrackCode,' ','')=@TrackCode end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); db.AddInParameter(cmd, "@PostFee2", DbType.Decimal, PostFee2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public static int ImportTrackCode2Clear(string OrderCode) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin update DT_OrderInfo set Fee2=0 where OrderId=@OrderId update DT_OrderXXInfo set PostFee=0 where OrderId=@OrderId select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 导入跟踪码 public static int ImportTrackCode2(string OrderCode, string TrackCode, decimal PostFee) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin update DT_OrderInfo set Fee2=@PostFee where OrderId=@OrderId update DT_OrderXXInfo set PostFee=isnull(PostFee,0)+@PostFee,TrackState=1,LogisticsId=11,Post=221 where OrderId=@OrderId if(select count(0) from DT_TrackCodeApply where state=1 and OrderId=@OrderId)=0 begin INSERT INTO [dbo].[DT_TrackCodeApply] ([PostId] ,[TrackType] ,[TrackCode] ,[TrackCode2] ,[GetDate] ,[InName] ,[OrderId] ,[State] ,[UpdateTime] ,[OrderCode] ,[OldPostFee] ,[ScanState] ,[ScanDate]) VALUES (221 ,1 ,@TrackCode ,null ,GETDATE() ,'' ,@OrderId ,1 ,null ,@OrderCode ,null ,null ,null ) end if(select count(0) from DT_TrackCodeScan where OrderId=@OrderId)>0 update DT_TrackCodeScan set PostFee=@PostFee,OldPostFee=@PostFee where OrderId=@OrderId else begin INSERT INTO [dbo].[DT_TrackCodeScan] ([PostId] ,[TrackCode] ,[InDate] ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId] ,[Weight] ,[PostFee] ,[OldPostFee]) select [PostId] ,[TrackCode] ,[InDate]=GETDATE() ,[InName] ,[OrderCode] ,[OrderId] ,[BagUserId]=1 ,[Weight]=0 ,[PostFee]=@PostFee ,[OldPostFee]=@PostFee from DT_TrackCodeApply where State=1 and OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, PostFee); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListUSOrder(string GoodsCode, DateTime? SDate, DateTime? EDate) { //string tsql = "select a.Id,a.statename,a.Num,a.code,a.color,a.Price from DT_USMap"; string tsql = @" select b.RevProvinceCode,Num=COUNT(0),Price=SUM(a.totalprice) into #map_ls from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where b.CountryCode='US' and a.OrderDate>=@SDate and a.OrderDate<@EDate and a.State>0 and a.State<3 group by b.RevProvinceCode select a.Id,statename=a.code,a.ename,name=a.code,a.code,value=isnull(b.Num,1),num=isnull(b.Num,0),Price=isnull(b.Price,0) from DT_USMap a left join #map_ls b on a.code=b.RevProvinceCode order by isnull(b.Num,0) desc,isnull(b.Price,0) desc drop table #map_ls"; if (GoodsCode != "") { tsql = @"select a.Id,a.statename,a.ename,name=a.code,a.code,value=isnull(b.Num,0),num=isnull(b.Num,0),Price=isnull(b.Price,0) from DT_USMap a left join ( select b.RevProvinceCode,Num=COUNT(0),Price=SUM(a.totalprice) from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId inner join DT_OrderGoods c on a.OrderId=c.OrderId inner join HW_GoodsDetail d on c.DetailId=d.DetailId inner join HW_GoodsInfo e on d.GoodsId=e.GoodsId where b.CountryCode='US' and e.GoodsCode like '%'+@GoodsCode+'%' and a.OrderDate>=@SDate and a.OrderDate<@EDate and a.State>0 and a.State<3 group by b.RevProvinceCode)b on a.code=b.RevProvinceCode order by isnull(b.Num,0) desc,isnull(b.Price,0) desc"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion public static JC_ShopDataNew GetStoreFeeCount() { JC_ShopDataNew model = null; string tsql = @" select a.KCNum,dj=(isnull(a.Price,0)+ISNULL(a.postprice,0))/6.3,tc=case when b.TCFee5>0 and b.TSoild>0 then b.TCFee5/b.TSoild else 200 end,FeeRate=isnull(d.FeeRate,0),Solid=isnull(d.Solid,0) into #ls from HW_GoodsInDetail a with(nolock) left join CG_Purchase b with(nolock) on a.ChaseId=b.ChaseId left join HW_GoodsDetail c with(nolock) on a.DetailId=c.DetailId left join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.StoreId=6 and KCNum>0 and OrderGoodsId=0 select a.KCNum,dj=(isnull(a.Price,0)+ISNULL(a.postprice,0))/6.3,tc=case when b.TCFee5>0 and b.TSoild>0 then b.TCFee5/b.TSoild else 200 end,FeeRate=isnull(d.FeeRate,0),Solid=isnull(d.Solid,0) into #ls2 from HW_GoodsInDetail a with(nolock) left join CG_Purchase b with(nolock) on a.ChaseId=b.ChaseId left join HW_GoodsDetail c with(nolock) on a.DetailId=c.DetailId left join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.StoreId=11 and KCNum>0 and OrderGoodsId=0 declare @Rate1 decimal(18,2),@Rate2 decimal(18,2) select @Rate1=sum(KCNum*(dj+dj*FeeRate*0.01)+tc*KCNum*Solid) from #ls select @Rate2=sum(KCNum*(dj+dj*FeeRate*0.01)+tc*KCNum*Solid) from #ls2 select Rate1=@Rate1,Rate2=@Rate2 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #region 返回列表 public static List GetListOpenMess(int UserId) { //string tsql = "select a.Id,a.OrderId,a.Sku,a.Weight,a.Long,a.Width,a.Height,a.Fee1,a.Fee2,a.Fee3,a.InDate,a.InUserId from DT_SpareFee"; string tsql = @" declare @id int select top 1 @id=id from JC_OpenMess where userid=@UserId and OpenDate<=getdate() and isread=0 and Type=4 if @id>0 begin update JC_OpenMess set isread=1,ReadDate=getdate() where id=@id select * from JC_OpenMess where id=@id end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 插入提示消息 public static void SaveIOpenMess(int UserId, string info) { string tsql = @"INSERT INTO [JC_OpenMess]([Content],[IsRead],[OpenDate],[Target],[Type],[UserType],[UserId]) values(@info,0,getdate(),0,4,'P',@UserId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@info", DbType.String, info); db.ExecuteNonQuery(cmd); } #endregion #region 返回列表 public static List GetListStoreYC(DateTime? InDate) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("OrderStore_Compare"); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 查询货物排名列表 public static List GetGoodsPM(int ShopId, DateTime InDate, DateTime InDate2) { List list = null; string tsql = @" SELECT a.shopid,a.goodsid,pm=int3 into #ls from [DD_GoodsPM] a with(nolock) inner join DD_GoodsCodeData b with(nolock) on a.asin=b.asin and a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,@InDate)=0 SELECT a.shopid,a.goodsid,pm=int3 into #ls2 from [DD_GoodsPM] a with(nolock) inner join DD_GoodsCodeData b with(nolock) on a.asin=b.asin and a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,@InDate2)=0 select a.shopid,b.shopname,num1=SUM(num1),num2=SUM(num2),num3=SUM(num3),num4=SUM(num4),num5=SUM(num5),num6=SUM(num6),num11=SUM(num11),num22=SUM(num22),num33=SUM(num33),num44=SUM(num44),num55=SUM(num55),num66=SUM(num66),num7=SUM(num7) from ( SELECT a.shopid,Num1=COUNT(0),Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls a where a.pm<=3 group by a.shopid union SELECT a.shopid,Num1=0,Num2=COUNT(0),Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls a where a.pm>=4 and a.pm<=50 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=COUNT(0),Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls a where a.pm>=51 and a.pm<=100 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=COUNT(0),Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls a where a.pm>=101 and a.pm<=150 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=COUNT(0),Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls a where a.pm>=151 and a.pm<=200 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=COUNT(0),Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls a where a.pm>=201 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=COUNT(0),Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls2 a where a.pm<=3 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=COUNT(0),Num33=0,Num44=0,Num55=0,Num66=0,Num7=0 from #ls2 a where a.pm>=4 and a.pm<=50 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=COUNT(0),Num44=0,Num55=0,Num66=0,Num7=0 from #ls2 a where a.pm>=51 and a.pm<=100 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=COUNT(0),Num55=0,Num66=0,Num7=0 from #ls2 a where a.pm>=101 and a.pm<=150 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=COUNT(0),Num66=0,Num7=0 from #ls2 a where a.pm>=151 and a.pm<=200 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=COUNT(0),Num7=0 from #ls2 a where a.pm>=201 group by a.shopid union SELECT a.shopid,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,Num6=0,Num11=0,Num22=0,Num33=0,Num44=0,Num55=0,Num66=0,Num7=COUNT(0) from [DD_GoodsPM] a where state=1 group by a.shopid )a inner join JC_Shop b on a.shopid=b.ShopId where (@ShopId=0 or a.shopid=@ShopId) group by a.shopid,b.shopname drop table #ls, #ls2 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@InDate2", DbType.DateTime, InDate2); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物排名列表 public static List GetGoodsPMCount(int ShopId, DateTime InDate, DateTime InDate2) { List list = null; string tsql = @" SELECT a.shopid,b.InDate,b.int3 from [DD_GoodsPM] a with(nolock) inner join DD_GoodsCodeData b with(nolock) on a.asin=b.asin and a.ShopId=b.ShopId where a.shopid=@ShopId and int3>0 and b.InDate>=@InDate and b.InDate<@InDate2 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@InDate2", DbType.DateTime, InDate2); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 查询货物排名列表 public static List GetGoodsPM2(int ShopId, DateTime InDate, string GoodsCode, int pm1, int pm2) { List list = null; string tsql = @" SELECT c.ShopName,GoodsCode=d.sku1,a.asin,Num1=b.Int2,Num2=b.Int3 from [DD_GoodsPM] a with(nolock) inner join DD_GoodsCodeData b with(nolock) on a.asin=b.asin and a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,@InDate)=0 inner join JC_Shop c on a.shopid=c.ShopId inner join HW_GoodsDetail d on a.detailid=d.detailid where a.shopid=@ShopId and (@pm1=0 or b.int3>=@pm1) and (@pm2=0 or b.int3<=@pm2) and (@GoodsCode='' or d.sku1=@GoodsCode) order by b.int3 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); db.AddInParameter(cmd, "@InDate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@GoodsCode", DbType.String, GoodsCode); db.AddInParameter(cmd, "@pm1", DbType.Int32, pm1); db.AddInParameter(cmd, "@pm2", DbType.Int32, pm2); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存 public static int Save_GoodsPM(DD_GoodsPM Model) { string tsql = @" if @id>0 begin Update [DD_GoodsPM] set [indate]=@indate,[shopid]=@shopid,[goodsid]=@goodsid,[asin]=@asin,[sync]=@sync,[detailid]=@detailid,[state]=@state where id=@id end else begin INSERT INTO [DD_GoodsPM]([indate],[shopid],[goodsid],[asin],[sync],[detailid],[state])values(@indate,@shopid,@goodsid,@asin,@sync,@detailid,@state) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@shopid", DbType.Int32, Model.shopid); db.AddInParameter(cmd, "@goodsid", DbType.Int32, Model.goodsid); db.AddInParameter(cmd, "@asin", DbType.String, Model.asin); db.AddInParameter(cmd, "@sync", DbType.Int32, Model.sync); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@state", DbType.Int32, Model.state); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_GoodsPMExcel(DD_GoodsPM Model) { string tsql = @" select top 1 @shopid=shopid from jc_shop where shopname=@shopname select top 1 @detailid=DetailId,@goodsid=goodsid from HW_GoodsDetail where SKU1=@sku or SKU2=@sku or SKU3=@sku or SKU4=@sku or SKU5=@sku or SKU6=@sku or SKU7=@sku if @shopid is null begin select -1 end else if @detailid is null begin select -2 end else if (select count(0) from DD_GoodsPM where asin=@asin and state=1)=0 begin INSERT INTO [DD_GoodsPM]([indate],[shopid],[goodsid],[asin],[sync],[detailid],[state])values(@indate,@shopid,@goodsid,@asin,@sync,@detailid,@state) set @id=SCOPE_IDENTITY() select 1 end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@shopid", DbType.Int32, Model.shopid); db.AddInParameter(cmd, "@shopname", DbType.String, Model.shopname); db.AddInParameter(cmd, "@goodsid", DbType.Int32, Model.goodsid); db.AddInParameter(cmd, "@sku", DbType.String, Model.sku); db.AddInParameter(cmd, "@asin", DbType.String, Model.asin); db.AddInParameter(cmd, "@sync", DbType.Int32, Model.sync); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@state", DbType.Int32, Model.state); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_GoodsPM(int id) { string tsql = @" delete from DD_GoodsPM where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 分页动态条件查询 public static List GetListGoodsPM(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select id=cast(a.id as int),a.indate,a.shopid,a.goodsid,a.asin,a.sync,a.detailid,a.state,b.shopname,sku=c.sku1 from DD_GoodsPM a inner join jc_shop b on a.shopid=b.shopid inner join HW_GoodsDetail c on a.detailid=c.detailid"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListApiOrders() { //string tsql = "select a.Id,a.OrderId,a.Sku,a.Weight,a.Long,a.Width,a.Height,a.Fee1,a.Fee2,a.Fee3,a.InDate,a.InUserId from DT_SpareFee"; string tsql = @" select ShopId=a.OrderId,Code=a.OrderCode,b.Appkey,b.DeveKey from API_OrderInfo a inner join JC_Shop b on a.ShopId=b.ShopId where a.InDate>='2022-04-28' and b.PlatType=2 and a.escrowFee is null "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 删除 public static void UpdatetApiOrders(int id, decimal escrowFee) { string tsql = @" update API_OrderInfo set escrowFee=@escrowFee where OrderId=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, escrowFee); db.ExecuteNonQuery(cmd); } #endregion #region 处理重复 订单 public static void DoApiOrders(string ordercode) { string tsql = @" declare @orderid int select top 1 @orderid=orderid from DT_OrderInfo where PlatOrderCode=@ordercode and state=1 update DT_OrderInfo set PostState=1 where PlatOrderCode=@ordercode and state=2 and PostState=0 if @orderid>0 begin delete from DT_OrderInfo where orderid=@orderid delete from DT_OrderInfonew where orderid=@orderid exec dbo.OrderAddForTM @orderid,1,1 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ordercode", DbType.String, ordercode); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void UpdatetGoodsIsSP(int id, Boolean? issp) { string tsql = @" update HW_GoodsDetail set issp=@issp where DetailId=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@issp", DbType.Boolean, issp); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static int Save_LXOrder(string code, decimal TotalPrice) { string tsql = @" update API_OrderInfo set TotalPrice=@TotalPrice,BuyRemark='-4' where OrderCode=@code select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@code", DbType.String, code); db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, TotalPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_LXShop(string code, string name) { string tsql = @" INSERT INTO [dbo].[LxShop] ([code] ,[name]) VALUES (@code,@name) select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@code", DbType.String, code); db.AddInParameter(cmd, "@name", DbType.String, name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回Model public static JC_LXShop GetLXShopModel(int ShopId) { JC_LXShop model = null; string tsql = "select * from JC_Shop where ShopId=@ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 读取店铺 public static List GetListLXShop(int PlatType) { string tsql = "select * from JC_Shop where (@PlatType=0 or PlatType=@PlatType) and IsAutoReadData=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取ebook菜单 public static List GetListMenuBook(int UserID, int CompanyId) { string tsql = @" declare @UserType nvarchar(10) select top 1 @UserType=UserType from JC_UserInfo where UserID=@UserID if @UserType='S' or @UserType='M' begin select * from JC_MenuList where IsUse=5 and id not in (select id from JC_MenuList where CompanyId is not null and CompanyId<>@CompanyId) order by SortNo end else begin if(select COUNT(0) from JC_RoleInfo a inner join JC_RoleUser b on a.RoleId=b.RoleId inner join JC_RoleMenu c on a.RoleId=c.RoleID where b.UserId=@UserID)>0 begin select * from JC_MenuList where IsUse=5 and ModuleNo in ( select distinct c.ModuleNo from JC_RoleInfo a inner join JC_RoleUser b on a.RoleId=b.RoleId inner join JC_RoleMenu c on a.RoleId=c.RoleID where b.UserId=@UserID and c.PopedomType>0) order by SortNo end else begin select *,css='ico_edit' from JC_MenuList where IsUse=5 and PopedomType>0 order by SortNo end end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserID", DbType.Int32, UserID); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取畅想编号 public static DataTable GetListCXCP2(DateTime st) { string tsql = @"select cpbh,zwpm,ywpm,pzms,b.bzcd,b.bzkd,b.bzgd,b.bzrl,mxmz,cgdj,tsl1,bzgd1,yytp,b.mz,b.nhcd,b.nhkd,b.nhgd,b.mz1,b.jz1,b.wxtj1 from cp a inner join cpprice b on a.RecordID=b.ParentID where Created>=@st or LastModified>=@st"; Database db = DatabaseFactory.CreateDatabase("ConnectionString2"); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@st", DbType.DateTime, st); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 读取畅想编号 public static DataTable GetListCXCP(DateTime st) { string tsql = @"select cpbh,zwpm,bzcd,bzkd,bzgd,mxjz1,mxmz1,cgdj,hl1,yytp,SerialID from xpzl a where LastModified>=@st or bjrq>=@st"; Database db = DatabaseFactory.CreateDatabase("ConnectionString2"); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@st", DbType.DateTime, st); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 读取畅想价格 public static DataTable GetListCXCPPrice(Int64 SerialID) { string tsql = @"select gj,hl12 from cejs where SerialID=@SerialID"; Database db = DatabaseFactory.CreateDatabase("ConnectionString2"); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SerialID", DbType.Int64, SerialID); DataTable tb = db.ExecuteDataTable(cmd); return tb; } #endregion #region 读取畅想价格(东南亚) public static void SaveCXGoods(HW_GoodsNew md) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("CXGoodsAdd"); db.AddInParameter(cmd, "@FileName", DbType.String, ""); db.AddInParameter(cmd, "@FileUrl", DbType.String, md.FirstImgUrl); db.AddInParameter(cmd, "@GoodsCode", DbType.String, md.GoodsCode); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.AddInParameter(cmd, "@TypeDesc", DbType.String, md.GoodsInfo); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, md.InPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, md.Weight); db.AddInParameter(cmd, "@Long", DbType.Decimal, md.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, md.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, md.Height); db.AddInParameter(cmd, "@BoxRate", DbType.Int32, md.BoxRate); db.AddInParameter(cmd, "@JYSales", DbType.String, md.JYSales); db.ExecuteNonQuery(cmd); } #endregion #region 读取畅想价格(业元) public static void SaveCXGoods_yy(HW_GoodsNew md) { Database db = DatabaseFactory.CreateDatabase("ConnectionString3"); DbCommand cmd = db.GetStoredProcCommand("CXGoodsAdd2"); db.AddInParameter(cmd, "@FileName", DbType.String, ""); db.AddInParameter(cmd, "@FileUrl", DbType.String, md.FirstImgUrl); db.AddInParameter(cmd, "@GoodsCode", DbType.String, md.GoodsCode); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.AddInParameter(cmd, "@GoodsEnglisgName", DbType.String, md.GoodsEnglisgName); db.AddInParameter(cmd, "@TypeDesc", DbType.String, md.GoodsInfo); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, md.InPrice); db.AddInParameter(cmd, "@Weight", DbType.Decimal, md.Weight); db.AddInParameter(cmd, "@Long", DbType.Decimal, md.Long); db.AddInParameter(cmd, "@Width", DbType.Decimal, md.Width); db.AddInParameter(cmd, "@Height", DbType.Decimal, md.Height); db.AddInParameter(cmd, "@Weight2", DbType.Decimal, md.Weight2); db.AddInParameter(cmd, "@Long2", DbType.Decimal, md.Long2); db.AddInParameter(cmd, "@Width2", DbType.Decimal, md.Width2); db.AddInParameter(cmd, "@Height2", DbType.Decimal, md.Height2); db.AddInParameter(cmd, "@Solid", DbType.Decimal, md.Solid); db.AddInParameter(cmd, "@NetWeight", DbType.Decimal, md.NetWeight); db.AddInParameter(cmd, "@BoxRate", DbType.Int32, md.BoxRate); db.AddInParameter(cmd, "@GoodsInfo", DbType.String, md.GoodsInfo); db.AddInParameter(cmd, "@CKG", DbType.Decimal, md.CKG); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, md.FeeRate); db.ExecuteNonQuery(cmd); } #endregion #region 数据字典 #region 保存 public static int Save_BaseCodeDetail(JC_BaseCodeDetailNew Model) { string tsql = @" if @Code>0 begin Update [JC_BaseCodeDetail] set [KeyName]=@KeyName,[Name]=@Name,[IsUse]=@IsUse,[Remark]=@Remark,[SortNo]=@SortNo,[CompanyId]=@CompanyId where Code=@Code end else begin INSERT INTO [JC_BaseCodeDetail]([KeyName],[Name],[IsUse],[Remark],[SortNo],[CompanyId])values(@KeyName,@Name,@IsUse,@Remark,@SortNo,@CompanyId) set @Code=SCOPE_IDENTITY() end select @Code"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.Int32, Model.Code); db.AddInParameter(cmd, "@KeyName", DbType.String, Model.KeyName); db.AddInParameter(cmd, "@Name", DbType.String, Model.Name); db.AddInParameter(cmd, "@IsUse", DbType.Int32, Model.IsUse); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); db.AddInParameter(cmd, "@SortNo", DbType.Int32, Model.SortNo); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_BaseCodeDetail(int Code) { string tsql = @" update JC_BaseCodeDetail set IsUse=0 where Code=@Code"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.Int32, Code); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static JC_BaseCodeDetailNew GetModel_BaseCodeDetail(int Code) { JC_BaseCodeDetailNew model = null; //string tsql = "select a.Code,a.KeyName,a.Name,a.IsUse,a.Remark,a.SortNo,a.CompanyId from JC_BaseCodeDetail"; string tsql = @" select * from JC_BaseCodeDetail where Code=@Code"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.Int32, Code); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 分页查询 public static List GetListBaseCodeDetail(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Code=cast(a.Code as int),a.KeyName,a.Name,a.IsUse,a.Remark,a.SortNo,a.CompanyId"; ser.Tables = @"JC_BaseCodeDetail a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Code"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 多条件普通查询 public static List GetListBaseCodeDetail(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); //ser.Fields = "a.Code,a.KeyName,a.Name,a.IsUse,a.Remark,a.SortNo,a.CompanyId"; ser.Fields = "a.*"; ser.Tables = @"JC_BaseCodeDetail a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.KeyName = "Code"; ser.Sort = Sort; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListBaseCodeDetail(string keyname) { //string tsql = "select a.Code,a.KeyName,a.Name,a.IsUse,a.Remark,a.SortNo,a.CompanyId from JC_BaseCodeDetail"; string tsql = "select * from JC_BaseCodeDetail where keyname=@keyname and isuse=1 order by sortno"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@keyname", DbType.String, keyname); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListBaseCodeDetail(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select Code=cast(a.Code as int),a.KeyName,a.Name,a.IsUse,a.Remark,a.SortNo,a.CompanyId from JC_BaseCodeDetail a"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.Code desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 判断是否重复 public static bool CheckName_BaseCodeDetail(int Code, string Name) { string tsql = @"select count(0) from JC_BaseCodeDetail where Code<>@Code and Name=@Name"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Code", DbType.Int32, Code); db.AddInParameter(cmd, "@Name", DbType.String, Name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); if (a == 0) return true; return false; } #endregion #endregion #region 读取店铺 public static List GetShopAllList(int CompanyID, int PlatType) { string tsql = @" select * from JC_Shop where (@PlatType=0 or PlatType=@PlatType) order by PlatType "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID); db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 结束采购明细 public static void Update_PurchaseGoodsDetail(int id) { string tsql = @" update CG_PurchaseGoods set IsOrder=GoodsNum,GoodsNum=ISNULL(InGoodsNum,0)+ISNULL(TJOutNum,0) where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 查询采购明细 public static List GetchaseGoodsList(string Ids) { List list = null; string tsql = @" select a.Id,FirstImgUrl=case when b.FirstImgUrl is not null then b.FirstImgUrl else c.FirstImgUrl end, a.ChaseId,c.GoodsId,c.GoodsOldCode,a.GoodsCode,a.GoodsDetailId,a.GoodsNum,a.GoodsPrice,a.LockNum,a.IsOrder,a.CompanyId,InGoodsNum=isnull(a.InGoodsNum,0),a.Error,c.GoodsName,b.SKU1,b.TypeDesc,b.TypeCode,OutNum=isnull(a.TJOutNum,0) from CG_PurchaseGoods a inner join HW_GoodsDetail b on a.GoodsDetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.ChaseId in (" + Ids + ") order by c.GoodsId,b.TypeCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Ids", DbType.String, Ids); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 结束采购明细 public static void Delete_CFSKU(int detailid) { string tsql = @" delete from HW_CFSKU where DetailId=@DetailId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, detailid); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static int Save_CFSKU(int detailid, string sku, string inname) { string tsql = @" declare @DetailId2 int set @DetailId2=0 select top 1 @DetailId2=DetailId from HW_GoodsDetail where sku1=@sku if @DetailId2=0 begin select top 1 @DetailId2=DetailId from HW_GoodsDetail where sku2=@sku or sku2=@sku or sku3=@sku or sku4=@sku or sku5=@sku or sku6=@sku or sku7=@sku or sku8=@sku or sku9=@sku or sku10=@sku or sku11=@sku or sku12=@sku or sku13=@sku end if @DetailId2>0 begin INSERT INTO [HW_CFSKU]([DetailId],[DetailId2],[InDate],[InName])values(@DetailId,@DetailId2,getdate(),@InName) end select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, detailid); db.AddInParameter(cmd, "@sku", DbType.String, sku); db.AddInParameter(cmd, "@InName", DbType.String, inname); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_PersonOrder(DT_PersonOrder Model) { string tsql = @" if @id>0 begin Update [DT_PersonOrder] set [indate]=@indate,[inname]=@inname,[inuserid]=@inuserid,[buyname]=@buyname,[buyphone]=@buyphone,[buyaddr]=@buyaddr,[buymobile]=@buymobile,[moneyprice]=@moneyprice,[moneycode]=@moneycode,[storeid]=@storeid,[storename]=@storename,[offprice]=@offprice,[remark]=@remark where id=@id delete from DT_PersonGoods where orderid=@id end else begin INSERT INTO [DT_PersonOrder]([indate],[inname],[inuserid],[buyname],[buyphone],[buyaddr],[buymobile],[moneyprice],[moneycode],[storeid],[storename],[offprice],[remark])values(@indate,@inname,@inuserid,@buyname,@buyphone,@buyaddr,@buymobile,@moneyprice,@moneycode,@storeid,@storename,@offprice,@remark) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@inuserid", DbType.Int32, Model.inuserid); db.AddInParameter(cmd, "@buyname", DbType.String, Model.buyname); db.AddInParameter(cmd, "@buyphone", DbType.String, Model.buyphone); db.AddInParameter(cmd, "@buyaddr", DbType.String, Model.buyaddr); db.AddInParameter(cmd, "@buymobile", DbType.String, Model.buymobile); db.AddInParameter(cmd, "@moneyprice", DbType.Decimal, Model.moneyprice); db.AddInParameter(cmd, "@moneycode", DbType.String, Model.moneycode); db.AddInParameter(cmd, "@storeid", DbType.Int32, Model.storeid); db.AddInParameter(cmd, "@storename", DbType.String, Model.storename); db.AddInParameter(cmd, "@offprice", DbType.Decimal, Model.offprice); db.AddInParameter(cmd, "@remark", DbType.String, Model.remark); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); tsql = @"INSERT INTO [DT_PersonGoods]([orderid],[detailid],[goodsnum],[sku],[price])values(@orderid,@detailid,@goodsnum,@sku,@price)"; cmd = db.GetSqlStringCommand(tsql); foreach (var item in Model.ListModel) { cmd.Parameters.Clear(); db.AddInParameter(cmd, "@orderid", DbType.Int32, a); db.AddInParameter(cmd, "@detailid", DbType.Int32, item.detailid); db.AddInParameter(cmd, "@goodsnum", DbType.Int32, item.goodsnum); db.AddInParameter(cmd, "@sku", DbType.String, item.sku); db.AddInParameter(cmd, "@price", DbType.Decimal, item.price); db.ExecuteNonQuery(cmd); } return a; } #endregion #region 删除 public static void Delete_PersonOrder(int id) { string tsql = @" delete from DT_PersonOrder where id=@id delete from DT_PersonGoods where orderid=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 分页动态条件查询 public static List GetListPersonOrder(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select id=cast(a.id as int),a.indate,a.inname,a.inuserid,a.buyname,a.buyphone,a.buyaddr,a.buymobile,a.moneyprice,a.moneycode,a.storeid,a.storename,a.offprice,a.remark from DT_PersonOrder a"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListDT_PersonGoods(int orderid) { //string tsql = "select a.id,a.indate,a.inname,a.inuserid,a.buyname,a.buyphone,a.buyaddr,a.buymobile,a.moneyprice,a.moneycode,a.storeid,a.storename,a.offprice,a.remark from DT_PersonOrder"; string tsql = "select * from DT_PersonGoods where orderid=@orderid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回Model public static DT_FeesTC GetModel_FeesTC() { DT_FeesTC model = null; //string tsql = "select a.id,a.tc_fee,a.indate,a.state from DT_FeesTC"; string tsql = @" select * from DT_FeesTC where state=1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 保存出库货物对应批次 public static int SaveGoodsOutInnerForNMLock(int DetailId, int PostionId, int StoreId, int GoodsNum, int CKDetailId) { string tsql = @" declare @OldInId int,@InId int,@KCNum int,@OutNum int set @OutNum=0 while @GoodsNum>0 begin set @OldInId=0 select top 1 @OldInId=InId,@KCNum=KCNum from HW_GoodsInDetail where OrderGoodsId=0 and PostionId=@PostionId and DetailId=@DetailId if @OldInId>0 and @GoodsNum=@KCNum begin update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=0,CKLookDetailId=@CKDetailId where InId=@OldInId set @OutNum=@OutNum+@KCNum end else if @OldInId>0 and @GoodsNum<@KCNum begin INSERT INTO [HW_GoodsInDetail]([DetailId],[ChaseId],[StoreId],[PostionId],[Price],[PostPrice],[InDate],[InUserId],[OrderGoodsId],[KCNum],[UpDateTime],[RKDetailId],[CKDetailId],CKLookDetailId) select [DetailId],[ChaseId],StoreId=@StoreId,PostionId=@PostionId,[Price],[PostPrice],[InDate],[InUserId],OrderGoodsId=-1,KCNum=@GoodsNum,getdate(),[RKDetailId],CKDetailId=0,CKDetailId=@CKDetailId from [HW_GoodsInDetail] where InId=@OldInId update HW_GoodsInDetail set KCNum=KCNum-@GoodsNum where InId=@OldInId set @OutNum=@OutNum+@GoodsNum end else if @OldInId>0 and @GoodsNum>@KCNum begin update HW_GoodsInDetail set OrderGoodsId=-1,CKDetailId=0,CKLookDetailId=@CKDetailId,UpDateTime=getdate() where InId=@OldInId set @OutNum=@OutNum+@KCNum end if @OldInId=0 begin set @GoodsNum=0 end else begin set @GoodsNum=@GoodsNum-@KCNum end end select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostionId", DbType.Int32, PostionId); db.AddInParameter(cmd, "@StoreId", DbType.Int32, StoreId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, GoodsNum); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, CKDetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存出库货物对应批次 public static int SaveGoodsOutInnerForNMOut(int CKDetailId) { string tsql = @" update HW_GoodsInDetail set CKDetailId=CKLookDetailId,UpDateTime=getdate() where CKLookDetailId=@CKDetailId select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CKDetailId", DbType.Int32, CKDetailId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 取消订单 public static int DeleteNMOrder(int OutId, string Remark) { string tsql = @" update b set b.OrderGoodsId=0 from HW_GoodsOutDetail a inner join HW_GoodsInDetail b on a.Id=b.CKLookDetailId where a.OutId=@OutId update HW_GoodsOutList set IsDelete=1,Remark=isnull(Remark,'')+@Remark where OutId=@OutId select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OutId", DbType.Int32, OutId); db.AddInParameter(cmd, "@Remark", DbType.String, Remark); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region public static int GetGoodsOutMess(int UserId) { string tsql = @" if @UserId=132 begin select Num=COUNT(0) from HW_GoodsOutList where OutReason='南美直销' and storeid=6 and IsDelete=3 end else if @UserId=176 begin select Num=COUNT(0) from HW_GoodsOutList where OutReason='南美直销' and storeid=11 and IsDelete=3 end else if @UserId=1 begin select Num=COUNT(0) from HW_GoodsOutList where OutReason='南美直销' and IsDelete=3 end else begin select Num=0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region public static decimal GetGoodsKCTJNum() { string tsql = @" declare @tj decimal(18,2) set @tj =0 select @tj=sum(a.KCNum*isnull(e.Solid,0)) from HW_GoodsInDetail a left join CG_PurchaseGoods b on a.ChaseId=b.GJChaseId and a.DetailId=b.GoodsDetailId left join CG_Purchase c on b.GJChaseId=c.ChaseId left join HW_GoodsDetail d on b.GoodsDetailId=d.DetailId left join HW_GoodsInfo e on d.GoodsId=e.GoodsId where a.ChaseId>0 and c.BuyDate>='2021-09-01' and c.BuyDate<'2022-07-15' and a.KCNum>0 and OrderGoodsId=0 select tj=isnull(@tj,0) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); decimal a = Convert.ToDecimal(db.ExecuteScalar(cmd)); return a; } #endregion #region public static DT_DefaultDataNew GetNMOrderTJ() { string tsql = @" declare @Num4 decimal(18,2),@Num5 decimal(18,2),@Num6 decimal(18,2),@Num7 decimal(18,2),@Num19 decimal(18,2) select @Num4=sum(price) from HW_GoodsOutList where OutReason='南美直销' and isdelete<>1 select @Num5=sum(price) from HW_GoodsOutList where OutReason='南美直销' and storeid=6 and isdelete<>1 select @Num6=sum(price) from HW_GoodsOutList where OutReason='南美直销' and storeid=11 and isdelete<>1 select @Num7=sum(price) from HW_GoodsOutList where OutReason='南美直销' and isdelete=3 select @Num19=sum(price) from HW_GoodsOutList where OutReason='南美直销' and isdelete=4 select Num4=isnull(@Num4,0), Num5=isnull(@Num5,0), Num6=isnull(@Num6,0), Num7=isnull(@Num7,0), Num19=isnull(@Num19,0) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); DT_DefaultDataNew model = null; if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 取消订单 public static int UpdateOrderReturn(int id, string ordercode) { string tsql = @" declare @OrderId int select top 1 @OrderId=OrderId from DT_OrderInfo where PlatOrderCode=@ordercode and state>0 and state<3 if @OrderId>0 begin update DT_OrderReturn set ordercode2=ordercode,ordercode=@ordercode, OrderId=@OrderId where id=@id select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@ordercode", DbType.String, ordercode); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回人员列表 public static List GetListUserSelect() { //string tsql = "select a.id,a.indate,a.inname,a.inuserid,a.buyname,a.buyphone,a.buyaddr,a.buymobile,a.moneyprice,a.moneycode,a.storeid,a.storename,a.offprice,a.remark from DT_PersonOrder"; string tsql = "select * from JC_UserInfo where State=1 and UserType='P' order by name desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 货号分配 public static int UpdateGoodsMate(int platid, int goodsid, int userid, string name) { string tsql = @" if @platid=2 begin update HW_GoodsInfo set muserid=@userid,mname=@name where goodsid=@goodsid end else if @platid=3 begin update HW_GoodsInfo set guserid_ebay=@userid,groupname_ebay=@name where goodsid=@goodsid end else if @platid=6 begin update HW_GoodsInfo set guserid_wlmart=@userid,groupname_wlmart=@name where goodsid=@goodsid end else if @platid=15 begin update HW_GoodsInfo set guserid_shopify=@userid,groupname_shopify=@name where goodsid=@goodsid end else if @platid=18 begin update HW_GoodsInfo set guserid_wayfair=@userid,groupname_wayfair=@name where goodsid=@goodsid end else if @platid=21 begin update HW_GoodsInfo set guserid_sheIn=@userid,groupname_sheIn=@name where goodsid=@goodsid end else if @platid=22 begin update HW_GoodsInfo set guserid_tiktok=@userid,groupname_tiktok=@name where goodsid=@goodsid end else if @platid=23 begin update HW_GoodsInfo set guserid_temu=@userid,groupname_temu=@name where goodsid=@goodsid IF EXISTS ( select 1 FROM TemuChengBen where goodsid=@goodsid) BEGIN update TemuChengBen set mUserId=@userid where goodsid=@goodsid END else BEGIN insert into TemuChengBen([GoodsId],[JinJia],[YunFei],[TouCheng],[HuoWuShuiFei],[YuGuJiaGe] ,[CreateUserId],[CreateTime],[mUserId]) select goodsid, CONVERT(DECIMAL(10, 2), InPrice/6.3) AS jinjia ,null, CONVERT(DECIMAL(10, 2), Solid*130) AS shuifei,CONVERT(DECIMAL(10, 2), FeeRate*InPrice*0.01/6.3) AS shuifei,null,@userid ,GETDATE(),@userid from HW_GoodsInfo where GoodsId=@goodsid END end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); db.AddInParameter(cmd, "@goodsid", DbType.Int32, goodsid); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@name", DbType.String, name); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 查询货物明分类 public static List GetGoodsSort(int CompanyId) { List list = null; string tsql = @" select * from HW_GoodsSort where IsUse=1 and CompanyId=@CompanyId order by ParentCode,SortNo "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存 public static int Save_GoodsUserPlanCount(HW_GoodsUserPlanCount Model) { string tsql = @" select top 1 @Id=Id from HW_GoodsUserPlanCount where GoodsId=@GoodsId if @Id>0 begin Update [HW_GoodsUserPlanCount] set [GoodsId]=@GoodsId,[DetailId]=@DetailId,[NoOutDays]=@NoOutDays,[OutDays2]=@OutDays2,[Price]=@Price,[Price2]=@Price2,[Price3]=@Price3,[Price4]=@Price4,[Price5]=@Price5,[Price6]=@Price6,[Price7]=@Price7,[Price8]=@Price8,[Num]=@Num,[Num2]=@Num2,[Num3]=@Num3,[Num4]=@Num4,[Num5]=@Num5,[Num6]=@Num6,[Num7]=@Num7,[ShopNames]=@ShopNames,[PlanInfo]=@PlanInfo,[AdviseInfo]=@AdviseInfo,[Remark]=@Remark where Id=@Id end else begin INSERT INTO [HW_GoodsUserPlanCount]([GoodsId],[DetailId],[NoOutDays],[OutDays2],[Price],[Price2],[Price3],[Price4],[Price5],[Price6],[Price7],[Price8],[Num],[Num2],[Num3],[Num4],[Num5],[Num6],[Num7],[ShopNames],[PlanInfo],[AdviseInfo],[Remark])values(@GoodsId,@DetailId,@NoOutDays,@OutDays2,@Price,@Price2,@Price3,@Price4,@Price5,@Price6,@Price7,@Price8,@Num,@Num2,@Num3,@Num4,@Num5,@Num6,@Num7,@ShopNames,@PlanInfo,@AdviseInfo,@Remark) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@DetailId", DbType.Int32, Model.DetailId); db.AddInParameter(cmd, "@NoOutDays", DbType.Int32, Model.NoOutDays); db.AddInParameter(cmd, "@OutDays2", DbType.Int32, Model.OutDays2); db.AddInParameter(cmd, "@Price", DbType.Decimal, Model.Price); db.AddInParameter(cmd, "@Price2", DbType.Decimal, Model.Price2); db.AddInParameter(cmd, "@Price3", DbType.Decimal, Model.Price3); db.AddInParameter(cmd, "@Price4", DbType.Decimal, Model.Price4); db.AddInParameter(cmd, "@Price5", DbType.Decimal, Model.Price5); db.AddInParameter(cmd, "@Price6", DbType.Decimal, Model.Price6); db.AddInParameter(cmd, "@Price7", DbType.Decimal, Model.Price7); db.AddInParameter(cmd, "@Price8", DbType.Decimal, Model.Price8); db.AddInParameter(cmd, "@Num", DbType.Int32, Model.Num); db.AddInParameter(cmd, "@Num2", DbType.Int32, Model.Num2); db.AddInParameter(cmd, "@Num3", DbType.Int32, Model.Num3); db.AddInParameter(cmd, "@Num4", DbType.Int32, Model.Num4); db.AddInParameter(cmd, "@Num5", DbType.Int32, Model.Num5); db.AddInParameter(cmd, "@Num6", DbType.Int32, Model.Num6); db.AddInParameter(cmd, "@Num7", DbType.Int32, Model.Num7); db.AddInParameter(cmd, "@ShopNames", DbType.String, Model.ShopNames); db.AddInParameter(cmd, "@PlanInfo", DbType.String, Model.PlanInfo); db.AddInParameter(cmd, "@AdviseInfo", DbType.String, Model.AdviseInfo); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回Model public static HW_GoodsUserPlanCount GetModel_GoodsUserPlanCount(int Id) { HW_GoodsUserPlanCount model = null; //string tsql = "select a.Id,a.GoodsId,a.DetailId,a.NoOutDays,a.OutDays2,a.Price,a.Price2,a.Price3,a.Price4,a.Price5,a.Price6,a.Price7,a.Price8,a.Num,a.Num2,a.Num3,a.Num4,a.Num5,a.Num6,a.Num7,a.ShopNames,a.PlanInfo,a.AdviseInfo,a.Remark from HW_GoodsUserPlanCount"; string tsql = @" select * from HW_GoodsUserPlanCount where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 返回Model public static int GetModel_UserDept(int UserId) { string tsql = @" select DeptId=isnull(DeptId,0) from JC_UserInfo where UserId=@UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); int deptid = Convert.ToInt32(db.ExecuteScalar(cmd)); return deptid; } #endregion #region 读取人员 public static List GetListUserInfoFromDept(int deptid) { string tsql = "select * from JC_UserInfo where state=1 and deptid in (1,27,32)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@deptid", DbType.Int32, deptid); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取人员 public static List GetListUserInfoFromDept2(int deptid, int groupid) { string tsql = @" select * from JC_UserInfo where state=1 and deptid=@deptid and (@groupid=0 or guserid=@groupid)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@deptid", DbType.Int32, deptid); db.AddInParameter(cmd, "@groupid", DbType.Int32, groupid); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取人员 public static List GetListUserInfoFromGroup(int UserId) { string tsql = @" if @UserId=1 or @UserId=51 or @UserId=53 begin select distinct UserId=guserid,Name=groupname from JC_UserInfo where state=1 and guserid>0 end else if(select count(0) from JC_UserInfo where state=1 and userid=@UserId and guserid>0)>0 begin select distinct UserId=guserid,Name=groupname from JC_UserInfo where state=1 and userid=@UserId and guserid>0 end else begin select UserId=-1,Name='无分组' from JC_UserInfo where state=1 and userid=@UserId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取人员 public static List GetListUserInfoFromGroup2(int UserId, int iscp) { string tsql = @" if @UserId=1 or @UserId=51 or @UserId=53 or @UserId=225 or @UserId=114 or @iscp=0 begin select * from JC_UserInfo where state=1 and deptid in (1,27,32,33) end else if(select count(0) from JC_UserInfo where state=1 and guserid=@UserId)>0 begin select UserId,Name from JC_UserInfo where state=1 and userid=@UserId union select UserId,Name from JC_UserInfo where state=1 and guserid=@UserId and userid<>@UserId end else begin select UserId,Name from JC_UserInfo where state=1 and userid=@UserId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@iscp", DbType.Int32, iscp); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取人员 public static List GetListUserInfoFromGroup3(int UserId, int groupid) { string tsql = @" if @UserId=1 or @UserId=51 or @UserId=53 begin select * from JC_UserInfo where state=1 and deptid=1 and (@groupid=-1 or guserid=@groupid) end else if(select count(0) from JC_UserInfo where state=1 and guserid=@UserId)>0 begin select UserId,Name from JC_UserInfo where state=1 and userid=@UserId union select UserId,Name from JC_UserInfo where state=1 and guserid=@UserId and userid<>@UserId end else begin select UserId,Name from JC_UserInfo where state=1 and userid=@UserId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@groupid", DbType.Int32, groupid); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 读取店铺 public static List GetUserGoodsScore_bak(int UserId, DateTime? sdate, DateTime? edate) { string tsql = @" --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.muserid,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3 from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId declare @MRate decimal(8,2) set @MRate=6.5 select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-ck-md-thf-thyf-ggf-qtfy+wlssf,ymxml=(zje-escrowFee-yj-yf-cb-hwsf-tc-thf-thyf-ggf-qtfy+wlssf)*@MRate,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-ck-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end into #ls_fee4 from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a select b.Name,b.GroupName,amzonzje=a.zje,amzonml=a.ml,amzonmll=a.mll,c.GoodsCode,c.FirstImgUrl,amzonjf=case when a.zje>=100000 and mll>=15 then 40000 when a.zje>=100000 and mll>=10 and mll<15 then 20000 when a.zje>=100000 and mll>=5 and mll<10 then 15000 when a.zje>=100000 and mll>=0 and mll<5 then 10000 when a.zje>=10000 and a.zje<100000 and mll>=15 then 2000 when a.zje>=10000 and a.zje<100000 and mll>=10 and mll<15 then 800 when a.zje>=10000 and a.zje<100000 and mll>=5 and mll<10 then 600 when a.zje>=10000 and a.zje<100000 and mll>=0 and mll<5 then 400 when a.zje>=1000 and a.zje<10000 and mll>=0 then 50 when a.zje>=500 and a.zje<1000 then 1 when a.zje>=0 and a.zje<500 then 0.01 else 0 end from #ls_fee4 a inner join JC_UserInfo b on a.UserId=b.UserId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.state=1 and b.deptid=1 and (@UserId=0 or b.UserId=@UserId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); return ds.Tables[0].ToList(); } #endregion #region 读取店铺 public static List GetUserGoodsScore(int UserId, DateTime? sdate, DateTime? edate, int SNum, int ENum) { string tsql = @" declare @edate1 datetime,@edate2 datetime,@edate3 datetime --set @sdate='2023-04-01' --set @edate='2023-04-30' set @edate1=DATEADD(day,7,@sdate) set @edate2=DATEADD(day,14,@sdate) set @edate3=DATEADD(day,21,@sdate) --drop table #ls_fee_tj select a.GoodsId,b.Name,b.UserId,b.GroupName,a.IsExamine,lastMonth1JE=CAST(0.00 as decimal(18,2)),lastMonth2JE=CAST(0.00 as decimal(18,2)),lastMonth3JE=CAST(0.00 as decimal(18,2)),amzonzjeweek1=cast(0.00 as decimal(18,2)),amzonzjeweek2=cast(0.00 as decimal(18,2)),amzonzjeweek3=cast(0.00 as decimal(18,2)),amzonzje=cast(0.00 as decimal(18,2)),amzonmlweek1=cast(0.00 as decimal(18,2)),amzonmlweek2=cast(0.00 as decimal(18,2)),amzonmlweek3=cast(0.00 as decimal(18,2)),amzonml=cast(0.00 as decimal(18,2)),amzonmllweek1=cast(0.00 as decimal(18,2)),amzonmllweek2=cast(0.00 as decimal(18,2)),amzonmllweek3=cast(0.00 as decimal(18,2)),amzonmll=cast(0.00 as decimal(18,2)),a.GoodsCode,a.FirstImgUrl,amzonjf=cast(0.00 as decimal(18,2)) into #ls_fee_tj from HW_GoodsInfo a inner join jc_userinfo b on a.muserid=b.userid where b.state=1 and b.deptid=1 if @edate1<=@edate begin --第一周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week1 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate1 select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_fee2_week1 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and d.OrderDate>=@sdate and d.OrderDate<@edate1 group by a.GoodsId,a.muserid,d.OrderId --计算总金额 update c set c.amzonzjeweek1=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --计算毛利 yf和cb大于0的参与计算 update c set c.amzonmlweek1=cast(b.ml as decimal(18,2)),c.amzonmllweek1=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate2<=@edate begin --第2周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate2 select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_fee2_week2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and d.OrderDate>=@sdate and d.OrderDate<@edate2 group by a.GoodsId,a.muserid,d.OrderId update c set c.amzonzjeweek2=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek2=cast(b.ml as decimal(18,2)),c.amzonmllweek2=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate3<=@edate begin --第3周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week3 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate3 select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_fee2_week3 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and d.OrderDate>=@sdate and d.OrderDate<@edate3 group by a.GoodsId,a.muserid,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_week3 from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId update c set c.amzonzjeweek3=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek3=cast(b.ml as decimal(18,2)),c.amzonmllweek3=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.muserid,d.OrderId update c set c.amzonzje=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonml=cast(b.ml as decimal(18,2)),c.amzonmll=cast(b.mll as decimal(18,2)),c.amzonjf=case when c.amzonzje>=100000 and mll>=15 then 40000 when c.amzonzje>=100000 and mll>=10 and mll<15 then 20000 when c.amzonzje>=100000 and mll>=5 and mll<10 then 15000 when c.amzonzje>=100000 and mll>=0 and mll<5 then 10000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=15 then 2000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=10 and mll<15 then 800 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=5 and mll<10 then 600 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=0 and mll<5 then 400 when c.amzonzje>=1000 and c.amzonzje<10000 and mll>=0 then 50 when c.amzonzje>=500 and c.amzonzje<1000 then 1 when c.amzonzje>=0 and c.amzonzje<500 then 0.01 else 0 end from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前一月订单数据 select a.OrderId,a.TotalPrice into #ls_month1_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month1_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth1JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month1_fee2 a inner join #ls_month1_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前二月订单数据 select a.OrderId,a.TotalPrice into #ls_month2_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month2_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth2JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month2_fee2 a inner join #ls_month2_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前三月订单数据 select a.OrderId,a.TotalPrice into #ls_month3_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=2 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month3_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=2 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth3JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month3_fee2 a inner join #ls_month3_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId select * from #ls_fee_tj where (@UserId=0 or UserId=@UserId) and (@SNum=-1 or amzonjf>=@SNum) and (@ENum=-1 or amzonjf<=@ENum) order by UserId,GoodsCode select Name,UserId,Num=COUNT(0),KHNum=0,DHNum=0,WDNum=0,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,HJ=sum(amzonjf),month1Num=0,month2Num=0,month3Num=0 into #ls_num from #ls_fee_tj where @UserId=0 or UserId=@UserId group by UserId,Name update a set a.Num5=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num4=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=10000 and amzonzje<100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num3=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=1000 and amzonzje<10000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num2=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=500 and amzonzje<1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num1=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje<500 and IsExamine=1 group by UserId)b on a.UserId=b.UserId --更新个人商品考核数量 update a set a.KHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.DHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=2 group by UserId)b on a.UserId=b.UserId update a set a.WDNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=3 group by UserId)b on a.UserId=b.UserId update a set a.month1Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth1JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month2Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth2JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month3Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth3JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId select *,TGRate=case when KHNum>0 then cast((Num3+Num4+Num5)*100/KHNum as decimal(18,0)) else 0 end ,Last3MonthRate=CONVERT(nvarchar(10),case when month1Num>0 then CAST( month1Num*100/KHNum as decimal(12,0)) else 0 end) +'/'+ CONVERT(nvarchar(10), case when month2Num>0 then CAST( month2Num*100/KHNum as decimal(12,0)) else 0 end )+'/'+ convert(nvarchar(10), case when month3Num>0 then CAST( month3Num*100/KHNum as decimal(12,0)) else 0 end) from #ls_num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SNum", DbType.Int32, SNum); db.AddInParameter(cmd, "@ENum", DbType.Int32, ENum); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); List list = ds.Tables[0].ToList(); var datalist = ds.Tables[1].ToList(); if (list != null && list.Count > 0) list[0].Data2 = datalist; return list; } #endregion #region 读取店铺 public static List GetUserGoodsScore3(int UserId, DateTime? sdate, DateTime? edate, int SNum, int ENum) { string tsql = @" declare @edate1 datetime,@edate2 datetime,@edate3 datetime --set @sdate='2023-04-01' --set @edate='2023-04-30' set @edate1=DATEADD(day,7,@sdate) set @edate2=DATEADD(day,14,@sdate) set @edate3=DATEADD(day,21,@sdate) --drop table #ls_fee_tj select a.GoodsId,b.Name,b.UserId,b.GroupName,a.IsExamine,lastMonth1JE=CAST(0.00 as decimal(18,2)),lastMonth2JE=CAST(0.00 as decimal(18,2)),lastMonth3JE=CAST(0.00 as decimal(18,2)),amzonzjeweek1=cast(0.00 as decimal(18,2)),amzonzjeweek2=cast(0.00 as decimal(18,2)),amzonzjeweek3=cast(0.00 as decimal(18,2)),amzonzje=cast(0.00 as decimal(18,2)),amzonmlweek1=cast(0.00 as decimal(18,2)),amzonmlweek2=cast(0.00 as decimal(18,2)),amzonmlweek3=cast(0.00 as decimal(18,2)),amzonml=cast(0.00 as decimal(18,2)),amzonmllweek1=cast(0.00 as decimal(18,2)),amzonmllweek2=cast(0.00 as decimal(18,2)),amzonmllweek3=cast(0.00 as decimal(18,2)),amzonmll=cast(0.00 as decimal(18,2)),a.GoodsCode,a.FirstImgUrl,amzonjf=cast(0.00 as decimal(18,2)) into #ls_fee_tj from HW_GoodsInfo a inner join jc_userinfo b on a.guserid_ebay=b.userid where b.state=1 if @edate1<=@edate begin --第一周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week1 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate1 select UserId=a.guserid_ebay,d.OrderId,a.GoodsId into #ls_fee2_week1 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.guserid_ebay>0 and d.OrderDate>=@sdate and d.OrderDate<@edate1 group by a.GoodsId,a.guserid_ebay,d.OrderId --计算总金额 update c set c.amzonzjeweek1=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --计算毛利 yf和cb大于0的参与计算 update c set c.amzonmlweek1=cast(b.ml as decimal(18,2)),c.amzonmllweek1=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate2<=@edate begin --第2周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate2 select UserId=a.guserid_ebay,d.OrderId,a.GoodsId into #ls_fee2_week2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.guserid_ebay>0 and d.OrderDate>=@sdate and d.OrderDate<@edate2 group by a.GoodsId,a.guserid_ebay,d.OrderId update c set c.amzonzjeweek2=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek2=cast(b.ml as decimal(18,2)),c.amzonmllweek2=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate3<=@edate begin --第3周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week3 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate3 select UserId=a.guserid_ebay,d.OrderId,a.GoodsId into #ls_fee2_week3 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.guserid_ebay>0 and d.OrderDate>=@sdate and d.OrderDate<@edate3 group by a.GoodsId,a.guserid_ebay,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_week3 from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId update c set c.amzonzjeweek3=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek3=cast(b.ml as decimal(18,2)),c.amzonmllweek3=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.guserid_ebay,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.guserid_ebay>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.guserid_ebay,d.OrderId update c set c.amzonzje=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonml=cast(b.ml as decimal(18,2)),c.amzonmll=cast(b.mll as decimal(18,2)),c.amzonjf=case when c.amzonzje>=100000 and mll>=15 then 40000 when c.amzonzje>=100000 and mll>=10 and mll<15 then 20000 when c.amzonzje>=100000 and mll>=5 and mll<10 then 15000 when c.amzonzje>=100000 and mll>=0 and mll<5 then 10000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=15 then 2000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=10 and mll<15 then 800 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=5 and mll<10 then 600 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=0 and mll<5 then 400 when c.amzonzje>=1000 and c.amzonzje<10000 and mll>=0 then 50 when c.amzonzje>=500 and c.amzonzje<1000 then 1 when c.amzonzje>=0 and c.amzonzje<500 then 0.01 else 0 end from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前一月订单数据 select a.OrderId,a.TotalPrice into #ls_month1_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month1_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth1JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month1_fee2 a inner join #ls_month1_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前二月订单数据 select a.OrderId,a.TotalPrice into #ls_month2_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month2_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth2JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month2_fee2 a inner join #ls_month2_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前三月订单数据 select a.OrderId,a.TotalPrice into #ls_month3_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=3 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month3_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=3 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth3JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month3_fee2 a inner join #ls_month3_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId select * from #ls_fee_tj where (@UserId=0 or UserId=@UserId) and (@SNum=-1 or amzonjf>=@SNum) and (@ENum=-1 or amzonjf<=@ENum) order by UserId,GoodsCode select Name,UserId,Num=COUNT(0),KHNum=0,DHNum=0,WDNum=0,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,HJ=sum(amzonjf),month1Num=0,month2Num=0,month3Num=0 into #ls_num from #ls_fee_tj where @UserId=0 or UserId=@UserId group by UserId,Name update a set a.Num5=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num4=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=10000 and amzonzje<100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num3=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=1000 and amzonzje<10000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num2=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=500 and amzonzje<1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num1=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje<500 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.KHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.DHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=2 group by UserId)b on a.UserId=b.UserId update a set a.WDNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=3 group by UserId)b on a.UserId=b.UserId update a set a.month1Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth1JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month2Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth2JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month3Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth3JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId select *,TGRate=case when KHNum>0 then cast((Num3+Num4+Num5)*100/KHNum as decimal(18,0)) else 0 end ,Last3MonthRate=CONVERT(nvarchar(10),case when month1Num>0 then CAST( month1Num*100/KHNum as decimal(12,0)) else 0 end) +'/'+ CONVERT(nvarchar(10), case when month2Num>0 then CAST( month2Num*100/KHNum as decimal(12,0)) else 0 end )+'/'+ convert(nvarchar(10), case when month3Num>0 then CAST( month3Num*100/KHNum as decimal(12,0)) else 0 end) from #ls_num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SNum", DbType.Int32, SNum); db.AddInParameter(cmd, "@ENum", DbType.Int32, ENum); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); List list = ds.Tables[0].ToList(); var datalist = ds.Tables[1].ToList(); if (list != null && list.Count > 0) list[0].Data2 = datalist; return list; } #endregion #region 读取店铺 public static List GetUserGoodsScore6(int UserId, DateTime? sdate, DateTime? edate, int SNum, int ENum) { string tsql = @" declare @edate1 datetime,@edate2 datetime,@edate3 datetime --set @sdate='2023-04-01' --set @edate='2023-04-30' set @edate1=DATEADD(day,7,@sdate) set @edate2=DATEADD(day,14,@sdate) set @edate3=DATEADD(day,21,@sdate) --drop table #ls_fee_tj select a.GoodsId,b.Name,b.UserId,b.GroupName,a.IsExamine,lastMonth1JE=CAST(0.00 as decimal(18,2)),lastMonth2JE=CAST(0.00 as decimal(18,2)),lastMonth3JE=CAST(0.00 as decimal(18,2)),amzonzjeweek1=cast(0.00 as decimal(18,2)),amzonzjeweek2=cast(0.00 as decimal(18,2)),amzonzjeweek3=cast(0.00 as decimal(18,2)),amzonzje=cast(0.00 as decimal(18,2)),amzonmlweek1=cast(0.00 as decimal(18,2)),amzonmlweek2=cast(0.00 as decimal(18,2)),amzonmlweek3=cast(0.00 as decimal(18,2)),amzonml=cast(0.00 as decimal(18,2)),amzonmllweek1=cast(0.00 as decimal(18,2)),amzonmllweek2=cast(0.00 as decimal(18,2)),amzonmllweek3=cast(0.00 as decimal(18,2)),amzonmll=cast(0.00 as decimal(18,2)),a.GoodsCode,a.FirstImgUrl,amzonjf=cast(0.00 as decimal(18,2)) into #ls_fee_tj from HW_GoodsInfo a inner join jc_userinfo b on a.guserid_wlmart=b.userid where b.state=1 if @edate1<=@edate begin --第一周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week1 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate1 select UserId=a.guserid_wlmart,d.OrderId,a.GoodsId into #ls_fee2_week1 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.guserid_wlmart>0 and d.OrderDate>=@sdate and d.OrderDate<@edate1 group by a.GoodsId,a.guserid_wlmart,d.OrderId --计算总金额 update c set c.amzonzjeweek1=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --计算毛利 yf和cb大于0的参与计算 update c set c.amzonmlweek1=cast(b.ml as decimal(18,2)),c.amzonmllweek1=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate2<=@edate begin --第2周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate2 select UserId=a.guserid_wlmart,d.OrderId,a.GoodsId into #ls_fee2_week2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.guserid_wlmart>0 and d.OrderDate>=@sdate and d.OrderDate<@edate2 group by a.GoodsId,a.guserid_wlmart,d.OrderId update c set c.amzonzjeweek2=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek2=cast(b.ml as decimal(18,2)),c.amzonmllweek2=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate3<=@edate begin --第3周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week3 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate3 select UserId=a.guserid_wlmart,d.OrderId,a.GoodsId into #ls_fee2_week3 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.guserid_wlmart>0 and d.OrderDate>=@sdate and d.OrderDate<@edate3 group by a.GoodsId,a.guserid_wlmart,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_week3 from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId update c set c.amzonzjeweek3=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek3=cast(b.ml as decimal(18,2)),c.amzonmllweek3=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.guserid_wlmart,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.guserid_wlmart>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.guserid_wlmart,d.OrderId update c set c.amzonzje=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonml=cast(b.ml as decimal(18,2)),c.amzonmll=cast(b.mll as decimal(18,2)),c.amzonjf=case when c.amzonzje>=100000 and mll>=15 then 40000 when c.amzonzje>=100000 and mll>=10 and mll<15 then 20000 when c.amzonzje>=100000 and mll>=5 and mll<10 then 15000 when c.amzonzje>=100000 and mll>=0 and mll<5 then 10000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=15 then 2000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=10 and mll<15 then 800 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=5 and mll<10 then 600 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=0 and mll<5 then 400 when c.amzonzje>=1000 and c.amzonzje<10000 and mll>=0 then 50 when c.amzonzje>=500 and c.amzonzje<1000 then 1 when c.amzonzje>=0 and c.amzonzje<500 then 0.01 else 0 end from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前一月订单数据 select a.OrderId,a.TotalPrice into #ls_month1_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month1_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth1JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month1_fee2 a inner join #ls_month1_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前二月订单数据 select a.OrderId,a.TotalPrice into #ls_month2_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month2_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth2JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month2_fee2 a inner join #ls_month2_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前三月订单数据 select a.OrderId,a.TotalPrice into #ls_month3_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=6 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month3_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=6 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth3JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month3_fee2 a inner join #ls_month3_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId select * from #ls_fee_tj where (@UserId=0 or UserId=@UserId) and (@SNum=-1 or amzonjf>=@SNum) and (@ENum=-1 or amzonjf<=@ENum) order by UserId,GoodsCode select Name,UserId,Num=COUNT(0),KHNum=0,DHNum=0,WDNum=0,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,HJ=sum(amzonjf),month1Num=0,month2Num=0,month3Num=0 into #ls_num from #ls_fee_tj where @UserId=0 or UserId=@UserId group by UserId,Name update a set a.Num5=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num4=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=10000 and amzonzje<100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num3=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=1000 and amzonzje<10000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num2=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=500 and amzonzje<1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num1=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje<500 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.KHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.DHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=2 group by UserId)b on a.UserId=b.UserId update a set a.WDNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=3 group by UserId)b on a.UserId=b.UserId update a set a.month1Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth1JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month2Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth2JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month3Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth3JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId select *,TGRate=case when KHNum>0 then cast((Num3+Num4+Num5)*100/KHNum as decimal(18,0)) else 0 end,Last3MonthRate=CONVERT(nvarchar(10),case when month1Num>0 then CAST( month1Num*100/KHNum as decimal(12,0)) else 0 end) +'/'+ CONVERT(nvarchar(10), case when month2Num>0 then CAST( month2Num*100/KHNum as decimal(12,0)) else 0 end )+'/'+ convert(nvarchar(10), case when month3Num>0 then CAST( month3Num*100/KHNum as decimal(12,0)) else 0 end) from #ls_num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SNum", DbType.Int32, SNum); db.AddInParameter(cmd, "@ENum", DbType.Int32, ENum); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); List list = ds.Tables[0].ToList(); var datalist = ds.Tables[1].ToList(); if (list != null && list.Count > 0) list[0].Data2 = datalist; return list; } #endregion #region 读取店铺 public static List GetUserGoodsScore15(int UserId, DateTime? sdate, DateTime? edate, int SNum, int ENum) { string tsql = @" declare @edate1 datetime,@edate2 datetime,@edate3 datetime --set @sdate='2023-04-01' --set @edate='2023-04-30' set @edate1=DATEADD(day,7,@sdate) set @edate2=DATEADD(day,14,@sdate) set @edate3=DATEADD(day,21,@sdate) --drop table #ls_fee_tj select a.GoodsId,b.Name,b.UserId,b.GroupName,a.IsExamine,lastMonth1JE=CAST(0.00 as decimal(18,2)),lastMonth2JE=CAST(0.00 as decimal(18,2)),lastMonth3JE=CAST(0.00 as decimal(18,2)),amzonzjeweek1=cast(0.00 as decimal(18,2)),amzonzjeweek2=cast(0.00 as decimal(18,2)),amzonzjeweek3=cast(0.00 as decimal(18,2)),amzonzje=cast(0.00 as decimal(18,2)),amzonmlweek1=cast(0.00 as decimal(18,2)),amzonmlweek2=cast(0.00 as decimal(18,2)),amzonmlweek3=cast(0.00 as decimal(18,2)),amzonml=cast(0.00 as decimal(18,2)),amzonmllweek1=cast(0.00 as decimal(18,2)),amzonmllweek2=cast(0.00 as decimal(18,2)),amzonmllweek3=cast(0.00 as decimal(18,2)),amzonmll=cast(0.00 as decimal(18,2)),a.GoodsCode,a.FirstImgUrl,amzonjf=cast(0.00 as decimal(18,2)) into #ls_fee_tj from HW_GoodsInfo a inner join jc_userinfo b on a.guserid_shopify=b.userid where b.state=1 if @edate1<=@edate begin --第一周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week1 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate1 select UserId=a.guserid_shopify,d.OrderId,a.GoodsId into #ls_fee2_week1 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.guserid_shopify>0 and d.OrderDate>=@sdate and d.OrderDate<@edate1 group by a.GoodsId,a.guserid_shopify,d.OrderId --计算总金额 update c set c.amzonzjeweek1=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --计算毛利 yf和cb大于0的参与计算 update c set c.amzonmlweek1=cast(b.ml as decimal(18,2)),c.amzonmllweek1=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate2<=@edate begin --第2周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate2 select UserId=a.guserid_shopify,d.OrderId,a.GoodsId into #ls_fee2_week2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.guserid_shopify>0 and d.OrderDate>=@sdate and d.OrderDate<@edate2 group by a.GoodsId,a.guserid_shopify,d.OrderId update c set c.amzonzjeweek2=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek2=cast(b.ml as decimal(18,2)),c.amzonmllweek2=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate3<=@edate begin --第3周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week3 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate3 select UserId=a.guserid_shopify,d.OrderId,a.GoodsId into #ls_fee2_week3 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.guserid_shopify>0 and d.OrderDate>=@sdate and d.OrderDate<@edate3 group by a.GoodsId,a.guserid_shopify,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_week3 from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId update c set c.amzonzjeweek3=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek3=cast(b.ml as decimal(18,2)),c.amzonmllweek3=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.guserid_shopify,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.guserid_shopify>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.guserid_shopify,d.OrderId update c set c.amzonzje=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonml=cast(b.ml as decimal(18,2)),c.amzonmll=cast(b.mll as decimal(18,2)),c.amzonjf=case when c.amzonzje>=100000 and mll>=15 then 40000 when c.amzonzje>=100000 and mll>=10 and mll<15 then 20000 when c.amzonzje>=100000 and mll>=5 and mll<10 then 15000 when c.amzonzje>=100000 and mll>=0 and mll<5 then 10000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=15 then 2000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=10 and mll<15 then 800 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=5 and mll<10 then 600 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=0 and mll<5 then 400 when c.amzonzje>=1000 and c.amzonzje<10000 and mll>=0 then 50 when c.amzonzje>=500 and c.amzonzje<1000 then 1 when c.amzonzje>=0 and c.amzonzje<500 then 0.01 else 0 end from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前一月订单数据 select a.OrderId,a.TotalPrice into #ls_month1_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month1_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth1JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month1_fee2 a inner join #ls_month1_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前二月订单数据 select a.OrderId,a.TotalPrice into #ls_month2_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month2_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth2JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month2_fee2 a inner join #ls_month2_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前三月订单数据 select a.OrderId,a.TotalPrice into #ls_month3_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=15 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month3_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=15 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth3JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month3_fee2 a inner join #ls_month3_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId select * from #ls_fee_tj where (@UserId=0 or UserId=@UserId) and (@SNum=-1 or amzonjf>=@SNum) and (@ENum=-1 or amzonjf<=@ENum) order by UserId,GoodsCode select Name,UserId,Num=COUNT(0),KHNum=0,DHNum=0,WDNum=0,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,HJ=sum(amzonjf),month1Num=0,month2Num=0,month3Num=0 into #ls_num from #ls_fee_tj where @UserId=0 or UserId=@UserId group by UserId,Name update a set a.Num5=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num4=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=10000 and amzonzje<100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num3=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=1000 and amzonzje<10000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num2=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=500 and amzonzje<1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num1=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje<500 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.KHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.DHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=2 group by UserId)b on a.UserId=b.UserId update a set a.WDNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=3 group by UserId)b on a.UserId=b.UserId update a set a.month1Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth1JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month2Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth2JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month3Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth3JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId select *,TGRate=case when KHNum>0 then cast((Num3+Num4+Num5)*100/KHNum as decimal(18,0)) else 0 end ,Last3MonthRate=CONVERT(nvarchar(10),case when month1Num>0 then CAST( month1Num*100/KHNum as decimal(12,0)) else 0 end) +'/'+ CONVERT(nvarchar(10), case when month2Num>0 then CAST( month2Num*100/KHNum as decimal(12,0)) else 0 end )+'/'+ convert(nvarchar(10), case when month3Num>0 then CAST( month3Num*100/KHNum as decimal(12,0)) else 0 end) from #ls_num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SNum", DbType.Int32, SNum); db.AddInParameter(cmd, "@ENum", DbType.Int32, ENum); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); List list = ds.Tables[0].ToList(); var datalist = ds.Tables[1].ToList(); if (list != null && list.Count > 0) list[0].Data2 = datalist; return list; } #endregion #region 读取店铺 public static List GetUserGoodsScore18(int UserId, DateTime? sdate, DateTime? edate, int SNum, int ENum) { string tsql = @" declare @edate1 datetime,@edate2 datetime,@edate3 datetime --set @sdate='2023-04-01' --set @edate='2023-04-30' set @edate1=DATEADD(day,7,@sdate) set @edate2=DATEADD(day,14,@sdate) set @edate3=DATEADD(day,21,@sdate) --drop table #ls_fee_tj select a.GoodsId,b.Name,b.UserId,b.GroupName,a.IsExamine,lastMonth1JE=CAST(0.00 as decimal(18,2)),lastMonth2JE=CAST(0.00 as decimal(18,2)),lastMonth3JE=CAST(0.00 as decimal(18,2)),amzonzjeweek1=cast(0.00 as decimal(18,2)),amzonzjeweek2=cast(0.00 as decimal(18,2)),amzonzjeweek3=cast(0.00 as decimal(18,2)),amzonzje=cast(0.00 as decimal(18,2)),amzonmlweek1=cast(0.00 as decimal(18,2)),amzonmlweek2=cast(0.00 as decimal(18,2)),amzonmlweek3=cast(0.00 as decimal(18,2)),amzonml=cast(0.00 as decimal(18,2)),amzonmllweek1=cast(0.00 as decimal(18,2)),amzonmllweek2=cast(0.00 as decimal(18,2)),amzonmllweek3=cast(0.00 as decimal(18,2)),amzonmll=cast(0.00 as decimal(18,2)),a.GoodsCode,a.FirstImgUrl,amzonjf=cast(0.00 as decimal(18,2)) into #ls_fee_tj from HW_GoodsInfo a inner join jc_userinfo b on a.guserid_wayfair=b.userid where b.state=1 if @edate1<=@edate begin --第一周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week1 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate1 select UserId=a.guserid_wayfair,d.OrderId,a.GoodsId into #ls_fee2_week1 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.guserid_wayfair>0 and d.OrderDate>=@sdate and d.OrderDate<@edate1 group by a.GoodsId,a.guserid_wayfair,d.OrderId --计算总金额 update c set c.amzonzjeweek1=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --计算毛利 yf和cb大于0的参与计算 update c set c.amzonmlweek1=cast(b.ml as decimal(18,2)),c.amzonmllweek1=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate2<=@edate begin --第2周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate2 select UserId=a.guserid_wayfair,d.OrderId,a.GoodsId into #ls_fee2_week2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.guserid_wayfair>0 and d.OrderDate>=@sdate and d.OrderDate<@edate2 group by a.GoodsId,a.guserid_wayfair,d.OrderId update c set c.amzonzjeweek2=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek2=cast(b.ml as decimal(18,2)),c.amzonmllweek2=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate3<=@edate begin --第3周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week3 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate3 select UserId=a.guserid_wayfair,d.OrderId,a.GoodsId into #ls_fee2_week3 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.guserid_wayfair>0 and d.OrderDate>=@sdate and d.OrderDate<@edate3 group by a.GoodsId,a.guserid_wayfair,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_week3 from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId update c set c.amzonzjeweek3=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek3=cast(b.ml as decimal(18,2)),c.amzonmllweek3=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.guserid_wayfair,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.guserid_wayfair>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.guserid_wayfair,d.OrderId update c set c.amzonzje=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonml=cast(b.ml as decimal(18,2)),c.amzonmll=cast(b.mll as decimal(18,2)),c.amzonjf=case when c.amzonzje>=100000 and mll>=15 then 40000 when c.amzonzje>=100000 and mll>=10 and mll<15 then 20000 when c.amzonzje>=100000 and mll>=5 and mll<10 then 15000 when c.amzonzje>=100000 and mll>=0 and mll<5 then 10000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=15 then 2000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=10 and mll<15 then 800 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=5 and mll<10 then 600 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=0 and mll<5 then 400 when c.amzonzje>=1000 and c.amzonzje<10000 and mll>=0 then 50 when c.amzonzje>=500 and c.amzonzje<1000 then 1 when c.amzonzje>=0 and c.amzonzje<500 then 0.01 else 0 end from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前一月订单数据 select a.OrderId,a.TotalPrice into #ls_month1_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month1_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth1JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month1_fee2 a inner join #ls_month1_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前二月订单数据 select a.OrderId,a.TotalPrice into #ls_month2_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month2_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth2JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month2_fee2 a inner join #ls_month2_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前三月订单数据 select a.OrderId,a.TotalPrice into #ls_month3_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=18 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month3_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=18 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth3JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month3_fee2 a inner join #ls_month3_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId select * from #ls_fee_tj where (@UserId=0 or UserId=@UserId) and (@SNum=-1 or amzonjf>=@SNum) and (@ENum=-1 or amzonjf<=@ENum) order by UserId,GoodsCode select Name,UserId,Num=COUNT(0),KHNum=0,DHNum=0,WDNum=0,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,HJ=sum(amzonjf),month1Num=0,month2Num=0,month3Num=0 into #ls_num from #ls_fee_tj where @UserId=0 or UserId=@UserId group by UserId,Name update a set a.Num5=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num4=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=10000 and amzonzje<100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num3=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=1000 and amzonzje<10000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num2=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=500 and amzonzje<1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num1=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje<500 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.KHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.DHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=2 group by UserId)b on a.UserId=b.UserId update a set a.WDNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=3 group by UserId)b on a.UserId=b.UserId update a set a.month1Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth1JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month2Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth2JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month3Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth3JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId select *,TGRate=case when KHNum>0 then cast((Num3+Num4+Num5)*100/KHNum as decimal(18,0)) else 0 end ,Last3MonthRate=CONVERT(nvarchar(10),case when month1Num>0 then CAST( month1Num*100/KHNum as decimal(12,0)) else 0 end) +'/'+ CONVERT(nvarchar(10), case when month2Num>0 then CAST( month2Num*100/KHNum as decimal(12,0)) else 0 end )+'/'+ convert(nvarchar(10), case when month3Num>0 then CAST( month3Num*100/KHNum as decimal(12,0)) else 0 end) from #ls_num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SNum", DbType.Int32, SNum); db.AddInParameter(cmd, "@ENum", DbType.Int32, ENum); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); List list = ds.Tables[0].ToList(); var datalist = ds.Tables[1].ToList(); if (list != null && list.Count > 0) list[0].Data2 = datalist; return list; } #endregion #region 读取店铺 public static List GetUserGoodsScore21(int UserId, DateTime? sdate, DateTime? edate, int SNum, int ENum) { string tsql = @" declare @edate1 datetime,@edate2 datetime,@edate3 datetime --set @sdate='2023-04-01' --set @edate='2023-04-30' set @edate1=DATEADD(day,7,@sdate) set @edate2=DATEADD(day,14,@sdate) set @edate3=DATEADD(day,21,@sdate) --drop table #ls_fee_tj select a.GoodsId,b.Name,b.UserId,b.GroupName,a.IsExamine,lastMonth1JE=CAST(0.00 as decimal(18,2)),lastMonth2JE=CAST(0.00 as decimal(18,2)),lastMonth3JE=CAST(0.00 as decimal(18,2)),amzonzjeweek1=cast(0.00 as decimal(18,2)),amzonzjeweek2=cast(0.00 as decimal(18,2)),amzonzjeweek3=cast(0.00 as decimal(18,2)),amzonzje=cast(0.00 as decimal(18,2)),amzonmlweek1=cast(0.00 as decimal(18,2)),amzonmlweek2=cast(0.00 as decimal(18,2)),amzonmlweek3=cast(0.00 as decimal(18,2)),amzonml=cast(0.00 as decimal(18,2)),amzonmllweek1=cast(0.00 as decimal(18,2)),amzonmllweek2=cast(0.00 as decimal(18,2)),amzonmllweek3=cast(0.00 as decimal(18,2)),amzonmll=cast(0.00 as decimal(18,2)),a.GoodsCode,a.FirstImgUrl,amzonjf=cast(0.00 as decimal(18,2)) into #ls_fee_tj from HW_GoodsInfo a inner join jc_userinfo b on a.guserid_sheIn=b.userid where b.state=1 if @edate1<=@edate begin --第一周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week1 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate1 select UserId=a.guserid_sheIn,d.OrderId,a.GoodsId into #ls_fee2_week1 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.guserid_sheIn>0 and d.OrderDate>=@sdate and d.OrderDate<@edate1 group by a.GoodsId,a.guserid_sheIn,d.OrderId --计算总金额 update c set c.amzonzjeweek1=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --计算毛利 yf和cb大于0的参与计算 update c set c.amzonmlweek1=cast(b.ml as decimal(18,2)),c.amzonmllweek1=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week1 a inner join #ls_fee_week1 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate2<=@edate begin --第2周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week2 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate2 select UserId=a.guserid_sheIn,d.OrderId,a.GoodsId into #ls_fee2_week2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.guserid_sheIn>0 and d.OrderDate>=@sdate and d.OrderDate<@edate2 group by a.GoodsId,a.guserid_sheIn,d.OrderId update c set c.amzonzjeweek2=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek2=cast(b.ml as decimal(18,2)),c.amzonmllweek2=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week2 a inner join #ls_fee_week2 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end if @edate3<=@edate begin --第3周订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee_week3 from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate3 select UserId=a.guserid_sheIn,d.OrderId,a.GoodsId into #ls_fee2_week3 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.guserid_sheIn>0 and d.OrderDate>=@sdate and d.OrderDate<@edate3 group by a.GoodsId,a.guserid_sheIn,d.OrderId select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_week3 from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId update c set c.amzonzjeweek3=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonmlweek3=cast(b.ml as decimal(18,2)),c.amzonmllweek3=cast(b.mll as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2_week3 a inner join #ls_fee_week3 b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId end --本月订单数据 select a.OrderId,a.ShopId,a.PlatId,a.PlatOrderCode,a.OrderCode,a.OrderDate,a.InDate,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.MoneyCode,a.GoodsNum,thf=DR_BackFee,thyf=DR_PostFee,wlssf=DR_SSFee,qtfy=Other_Fee,ggf=Ad_Fee,b.yj,yf=case when c.PostFee>0 then c.PostFee else isnull(b.yf,0) end,cb=case when b.sjcb>0 then b.sjcb/isnull(b.moneyrate,1) else ISNULL(b.cb,0)/isnull(b.moneyrate,1) end,hwsf=case when b.sjhwsf>0 then b.sjhwsf/isnull(b.moneyrate,1) else isnull(b.hwsf,0)/isnull(b.moneyrate,1) end,b.ck,b.md,tc=case when isnull(b.sjtc,0)>0 then b.sjtc else b.tc end into #ls_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and a.OrderDate>=@sdate and a.OrderDate<@edate select UserId=a.guserid_sheIn,d.OrderId,a.GoodsId into #ls_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.guserid_sheIn>0 and d.OrderDate>=@sdate and d.OrderDate<@edate group by a.GoodsId,a.guserid_sheIn,d.OrderId update c set c.amzonzje=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId update c set c.amzonml=cast(b.ml as decimal(18,2)),c.amzonmll=cast(b.mll as decimal(18,2)),c.amzonjf=case when c.amzonzje>=100000 and mll>=15 then 40000 when c.amzonzje>=100000 and mll>=10 and mll<15 then 20000 when c.amzonzje>=100000 and mll>=5 and mll<10 then 15000 when c.amzonzje>=100000 and mll>=0 and mll<5 then 10000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=15 then 2000 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=10 and mll<15 then 800 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=5 and mll<10 then 600 when c.amzonzje>=10000 and c.amzonzje<100000 and mll>=0 and mll<5 then 400 when c.amzonzje>=1000 and c.amzonzje<10000 and mll>=0 then 50 when c.amzonzje>=500 and c.amzonzje<1000 then 1 when c.amzonzje>=0 and c.amzonzje<500 then 0.01 else 0 end from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf,mll=case when zje>0 then (zje-escrowFee-yj-yf-cb-hwsf-tc-md-thf-thyf-ggf-qtfy+wlssf)*100.00/zje else 0 end from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice),escrowFee=SUM(b.escrowFee),yj=SUM(isnull(yj,0)),yf=SUM(isnull(yf,0)),cb=SUM(isnull(cb,0)),hwsf=SUM(isnull(hwsf,0)),tc=SUM(isnull(tc,0)),ck=SUM(isnull(ck,0)),md=SUM(isnull(md,0)),thf=SUM(isnull(thf,0)),thyf=SUM(isnull(thyf,0)),qtfy=SUM(isnull(qtfy,0)),ggf=SUM(isnull(ggf,0)),wlssf=SUM(isnull(wlssf,0)) from #ls_fee2 a inner join #ls_fee b on a.OrderId=b.OrderId where b.yf>0 and b.cb>0 group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前一月订单数据 select a.OrderId,a.TotalPrice into #ls_month1_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month1_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-1,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth1JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month1_fee2 a inner join #ls_month1_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前二月订单数据 select a.OrderId,a.TotalPrice into #ls_month2_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month2_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-2,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth2JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month2_fee2 a inner join #ls_month2_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId --前三月订单数据 select a.OrderId,a.TotalPrice into #ls_month3_fee from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo c with(nolock) on a.orderid=c.orderid left join DT_Fees b with(nolock) on a.OrderId=b.orderid where a.PlatId=21 and a.State>0 and a.State<3 and CONVERT(nvarchar(7),a.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) select UserId=a.muserid,d.OrderId,a.GoodsId into #ls_month3_fee2 from HW_GoodsInfo a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.GoodsId=b.GoodsId inner join DT_OrderGoods c with(nolock) on b.DetailId=c.DetailId inner join DT_OrderInfo d with(nolock) on c.OrderId=d.OrderId where d.PlatId=21 and d.State>0 and d.State<3 and a.muserid>0 and CONVERT(nvarchar(7),d.OrderDate,23)=CONVERT(nvarchar(7),DATEADD(month,-3,getdate()),23) group by a.GoodsId,a.muserid,d.OrderId update c set c.lastMonth3JE=cast(b.zje as decimal(18,2)) from #ls_fee_tj c inner join (select a.GoodsId,a.UserId,zje from ( select a.GoodsId,a.UserId,zje=SUM(b.TotalPrice) from #ls_month3_fee2 a inner join #ls_month3_fee b on a.OrderId=b.OrderId group by a.GoodsId,a.UserId)a)b on c.goodsid=b.GoodsId select * from #ls_fee_tj where (@UserId=0 or UserId=@UserId) and (@SNum=-1 or amzonjf>=@SNum) and (@ENum=-1 or amzonjf<=@ENum) order by UserId,GoodsCode select Name,UserId,Num=COUNT(0),KHNum=0,DHNum=0,WDNum=0,Num1=0,Num2=0,Num3=0,Num4=0,Num5=0,HJ=sum(amzonjf),month1Num=0,month2Num=0,month3Num=0 into #ls_num from #ls_fee_tj where @UserId=0 or UserId=@UserId group by UserId,Name update a set a.Num5=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num4=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=10000 and amzonzje<100000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num3=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=1000 and amzonzje<10000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num2=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje>=500 and amzonzje<1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.Num1=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where amzonzje<500 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.KHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.DHNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=2 group by UserId)b on a.UserId=b.UserId update a set a.WDNum=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where IsExamine=3 group by UserId)b on a.UserId=b.UserId update a set a.month1Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth1JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month2Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth2JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId update a set a.month3Num=b.Num from #ls_num a inner join (select UserId,Num=COUNT(0) from #ls_fee_tj where lastMonth3JE>=1000 and IsExamine=1 group by UserId)b on a.UserId=b.UserId select *,TGRate=case when KHNum>0 then cast((Num3+Num4+Num5)*100/KHNum as decimal(18,0)) else 0 end,Last3MonthRate=CONVERT(nvarchar(10),case when month1Num>0 then CAST( month1Num*100/KHNum as decimal(12,0)) else 0 end) +'/'+ CONVERT(nvarchar(10), case when month2Num>0 then CAST( month2Num*100/KHNum as decimal(12,0)) else 0 end )+'/'+ convert(nvarchar(10), case when month3Num>0 then CAST( month3Num*100/KHNum as decimal(12,0)) else 0 end) from #ls_num "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@SNum", DbType.Int32, SNum); db.AddInParameter(cmd, "@ENum", DbType.Int32, ENum); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sdate); db.AddInParameter(cmd, "@edate", DbType.DateTime, edate); DataSet ds = db.ExecuteDataSet(cmd); List list = ds.Tables[0].ToList(); var datalist = ds.Tables[1].ToList(); if (list != null && list.Count > 0) list[0].Data2 = datalist; return list; } #endregion #region 保存 public static int Save_OrderLTLFee(int OrderId, decimal FeeLTL) { string tsql = @" Update [DT_OrderInfo] set [FeeLTL]=@FeeLTL where OrderId=@OrderId exec [dbo].[ComputerOrderFee_Order] @OrderId select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@FeeLTL", DbType.Decimal, FeeLTL); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_OrderLTLFeeAndPostFee(int OrderId, decimal FeeLTL) { string tsql = @" Update [DT_OrderInfo] set [FeeLTL]=@FeeLTL where OrderId=@OrderId exec [dbo].[ComputerOrderFee_Order] @OrderId Update [DT_OrderXXInfo] set PostFee=@FeeLTL where OrderId=@OrderId Update [DT_Fees] set sjyf=@FeeLTL where Orderid=@OrderId select 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@FeeLTL", DbType.Decimal, FeeLTL); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public static List GetListJC_UserInfoForTM(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"UserId=cast(a.UserId as int),a.Name,a.SpellName,a.EnglishName,a.Sex,a.UserName,a.Password,a.UserType,a.State,a.CompanyId,a.UserCode,a.LoginCount,a.LastLoginTime,a.LastLoginIp,a.Photo,a.UpdateDate,a.Duty,a.Mobile1,a.Mobile2,a.Mobile3,a.UserCard,a.InDate,a.DeptName,a.SchoolLevel,a.School,a.BornDate,a.BornAddr,a.ContractDate,a.IsMarry,a.IsBaby,a.HuKou,a.HuKouAddr,a.NowAddr,a.JoinDate,a.FormalDate,a.IsRoom,a.RoomAddr,a.Political,a.DeptId,a.Traffic,a.QQ,a.Email,a.EmployeeType,StateName=case when a.state=1 then '在职' when a.state=2 then '离职' else '其它' end,a.IDCard,a.Holidays,a.IsLogin,WorkDesc=a.GroupName,a.guserid"; ser.Tables = @"JC_UserInfo a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "UserId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 标记LTL数量 public static void UpdateOrderLTL(int OrderId) { string tsql = @" update DT_OrderInfo set PostState=3 where OrderId=@OrderId and state<>2 update DT_OrderInfoNew set PostState=3 where OrderId=@OrderId and state<>2 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 标记LTL数量 public static void UpdateOrderLTLBack(int OrderId) { string tsql = @" update DT_OrderInfo set PostState=0 where OrderId=@OrderId and PostState=3 update DT_OrderInfoNew set PostState=0 where OrderId=@OrderId and PostState=3 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.ExecuteNonQuery(cmd); } #endregion #region 保存 public static int Save_GoodsLeaveWord(HW_GoodsLeaveWord Model) { string tsql = @" if @id<>0 begin select top 1 @id=id from HW_GoodsLeaveWord where goodsid=@goodsid and leavetype=@leavetype order by id desc if @id>0 begin Update [HW_GoodsLeaveWord] set [isread]=1 where id=@id if @leavetype=1 begin if @platid=2 begin update HW_GoodsInfo set LeaveWord=null where goodsid=@goodsid end else if @platid=3 begin update HW_GoodsInfo set LeaveWord_ebay=null where goodsid=@goodsid end else if @platid=6 begin update HW_GoodsInfo set LeaveWord_walmart=null where goodsid=@goodsid end else if @platid=15 begin update HW_GoodsInfo set LeaveWord_shopify=null where goodsid=@goodsid end else if @platid=18 begin update HW_GoodsInfo set LeaveWord_wayfair=null where goodsid=@goodsid end else if @platid=21 begin update HW_GoodsInfo set LeaveWord_shein=null where goodsid=@goodsid end end else begin update HW_GoodsInfo set LeaveWord_cg=null where goodsid=@goodsid end end end else begin INSERT INTO [HW_GoodsLeaveWord]([leaveword],[inname],[indate],[isread],[goodsid],leavetype,platid)values(@leaveword,@inname,@indate,@isread,@goodsid,@leavetype,@platid) set @id=SCOPE_IDENTITY() if @leavetype=1 begin if @platid=2 begin update HW_GoodsInfo set LeaveWord=@leaveword2 where goodsid=@goodsid end else if @platid=3 begin update HW_GoodsInfo set LeaveWord_ebay=@leaveword2 where goodsid=@goodsid end else if @platid=6 begin update HW_GoodsInfo set LeaveWord_walmart=@leaveword2 where goodsid=@goodsid end else if @platid=15 begin update HW_GoodsInfo set LeaveWord_shopify=@leaveword2 where goodsid=@goodsid end else if @platid=18 begin update HW_GoodsInfo set LeaveWord_wayfair=@leaveword2 where goodsid=@goodsid end else if @platid=21 begin update HW_GoodsInfo set LeaveWord_shein=@leaveword2 where goodsid=@goodsid end end else begin update HW_GoodsInfo set LeaveWord_cg=@leaveword2 where goodsid=@goodsid end end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@leaveword", DbType.String, Model.leaveword); db.AddInParameter(cmd, "@leaveword2", DbType.String, Model.leaveword2); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@indate", DbType.String, Model.indate); db.AddInParameter(cmd, "@isread", DbType.Int32, Model.isread); db.AddInParameter(cmd, "@goodsid", DbType.Int32, Model.goodsid); db.AddInParameter(cmd, "@leavetype", DbType.Int32, Model.leavetype); db.AddInParameter(cmd, "@platid", DbType.Int32, Model.platid); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 返回列表 public static List GetListGoodsLeaveWord(int goodsid, int leavetype, int platid) { //string tsql = "select a.id,a.leaveword,a.inname,a.indate,a.isread,a.goodsid from HW_GoodsLeaveWord"; string tsql = @" if @leavetype=1 begin select * from HW_GoodsLeaveWord where goodsid=@goodsid and leavetype=@leavetype and platid=@platid end else begin select * from HW_GoodsLeaveWord where goodsid=@goodsid and leavetype=@leavetype end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@goodsid", DbType.Int32, goodsid); db.AddInParameter(cmd, "@leavetype", DbType.Int32, leavetype); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 计算商品一周的广告花费 public static decimal GetGoodWeekAdSpend(int goodid, int storeid) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GetGoodWeekADSpendAmountByDate"); db.AddInParameter(cmd, "@goodId", DbType.Int32, goodid); db.AddInParameter(cmd, "@storeId", DbType.Int32, storeid); var obj = db.ExecuteScalar(cmd); return obj == DBNull.Value ? 0 : Convert.ToDecimal(obj); } public static List GetAllGoodWeekAdSpend() { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("GetAllGoodsLastWeekADSpend"); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取店铺商品周ACOS /// /// 获取店铺商品周ACOS /// /// /// /// /// /// /// /// /// public static List GetStoreGoodWeekAcos(int userId, string name, string shopName, string goodCode, string master, DateTime startDate, DateTime endDate, int pageIndex, int pageSize, out int rowCount, out decimal? hjSpned, out decimal? hj_ad_sale, out decimal? hjweeklr) { string sqlFil = ""; if (!string.IsNullOrEmpty(shopName)) sqlFil += " and c.name=@shopName"; if (!string.IsNullOrEmpty(goodCode)) sqlFil += " and ( b.local_sku like '%'+@goodCode+'%' or b.local_name like '%'+@goodCode+'%' or b.seller_sku like '%'+@goodCode+'%' )"; var sql = @"select t.ShopName,SKU,GoodName,MSKU,spend,ad_sale,ACOS from ( select c.name ShopName, b.local_sku SKU,b.local_name GoodName,b.seller_sku MSKU,convert(decimal(12,2), ABS(SUM(isnull(spend,0)))) Spend,convert(decimal(12,2), SUM(isnull(ad_sales_amount,0))) ad_sale , case when ABS(SUM(isnull(spend,0)))=0 and SUM(isnull(ad_sales_amount,0))=0 then 0 when ABS(SUM(isnull(spend,0)))=0 and SUM(isnull(ad_sales_amount,0))!=0 then 0 when ABS(SUM(isnull(spend,0)))!=0 and SUM(isnull(ad_sales_amount,0))=0 then 100.00 else CONVERT(decimal(12,2),(ABS(SUM(isnull(spend,0)))/SUM(isnull(ad_sales_amount,0)))*100) end ACOS from [192.168.1.187].UpGoods.dbo.LxERP_ProductPerformance a left join [192.168.1.187].UpGoods.dbo.LxERP_Price_List b on a.ID=b.LxERP_ProductPerformance_ID left join [192.168.1.187].UpGoods.dbo.LxERP_Amazon_Shop c on a.sid=c.sid where summary_field='asin' and RequestDate>=@startDate and RequestDate<=@endDate " + sqlFil + " group by a.sid,c.name, local_sku,b.local_name,seller_sku) t where t.ACOS>=50"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopName", DbType.String, shopName); db.AddInParameter(cmd, "@goodCode", DbType.String, goodCode); db.AddInParameter(cmd, "@startDate", DbType.DateTime, startDate); db.AddInParameter(cmd, "@endDate", DbType.DateTime, endDate); DataTable tb = db.ExecuteDataTable(cmd); var allListModel = tb.ToList(); var goodsMasters = GetAllGoodsMasterList(); foreach (var item in allListModel) { if (string.IsNullOrEmpty(item.SKU)) { item.Master = ""; } else { var gm = goodsMasters.Find(r => r.GoodsCode.Equals(item.SKU, StringComparison.OrdinalIgnoreCase)); item.Master = gm == null ? "" : gm.UserName; } } if (!string.IsNullOrEmpty(master)) { allListModel = allListModel.Where(r => r.Master.Contains(master)).ToList(); } if (userId != 1 && userId != 51)//管理员账号看所有,否则只能自己看自己的数据 { allListModel = allListModel.Where(r => !string.IsNullOrEmpty(r.Master) && r.Master.Equals(name, StringComparison.OrdinalIgnoreCase)).ToList(); } var ListModel = allListModel.Skip((pageIndex - 1) * 30).Take(pageSize).ToList(); rowCount = allListModel.Count(); hjSpned = allListModel.Sum(r => r.spend); hj_ad_sale = allListModel.Sum(r => r.ad_sale); var weekLRs = GetAllGoodsLRList(); decimal _weekrl = 0; foreach (var item in allListModel) { var weeklr = weekLRs.Find(r => r.ShopName.ToLower() == item.ShopName.ToLower() && r.GoodsCode == item.SKU); if (weeklr != null) { _weekrl = _weekrl + ((weeklr.WeekLR2.HasValue ? weeklr.WeekLR2.Value : 0) - (weeklr.WeekFee2.HasValue ? weeklr.WeekFee2.Value : 0)); item.WeekLR = (weeklr.WeekLR2.HasValue ? weeklr.WeekLR2.Value : 0) - (weeklr.WeekFee2.HasValue ? weeklr.WeekFee2.Value : 0); } else { item.WeekLR = null; } } hjweeklr = _weekrl; return ListModel; } /// /// 获取到所有的店铺信息 /// /// public static List GetAllShopList() { string query = "\r\nselect ShopId,ShopName,PlatType,DeptId,InDate,CompanyId,LevelGrade,Master from JC_Shop order by PlatType\r\n"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); DataTable tb = database.ExecuteDataTable(sqlStringCommand); return tb.ToList(); } /// /// 获取到所有的商品利润信息 /// /// public static List GetAllGoodsLRList() { string query = "\r\nselect a.*,b.ShopName,c.GoodsCode from AD_FeeCompute a left join JC_Shop b on a.ShopId=b.ShopId left join HW_GoodsInfo c on a.GoodsId=c.GoodsId\r\n"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); DataTable tb = database.ExecuteDataTable(sqlStringCommand); return tb.ToList(); } /// /// 获取到所有的商品负责人信息 /// /// public static List GetAllGoodsMasterList() { string query = "\r\nselect a.GoodsCode, b.Name UserName from HW_GoodsInfo a left join JC_UserInfo b on a.muserid=b.UserId where ISNULL(muserid,-2)<>-2 and muserid!=-1 and ISNULL(GoodsCode,'0')<>'0' group by a.GoodsCode,b.Name\r\n"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); DataTable tb = database.ExecuteDataTable(sqlStringCommand); return tb.ToList(); } /// /// 获取店铺负责人每个人周ACOS超过50的数量 /// /// /// /// /// /// /// public static List GetMasterStoreGoodAcosCountsList(int userid, string userName, DateTime startDate, DateTime endDate, int pageIndex, int pageSize, out int rowCount) { var sql = @"select g.Name as Master,COUNT(1) as Count from ( select SKU from ( select c.name ShopName, b.local_sku SKU,b.local_name GoodName,b.seller_sku MSKU,convert(decimal(12,2), ABS(SUM(isnull(spend,0)))) Spend,convert(decimal(12,2), SUM(isnull(ad_sales_amount,0))) ad_sale , case when ABS(SUM(isnull(spend,0)))=0 and SUM(isnull(ad_sales_amount,0))=0 then 0 when ABS(SUM(isnull(spend,0)))=0 and SUM(isnull(ad_sales_amount,0))!=0 then 0 when ABS(SUM(isnull(spend,0)))!=0 and SUM(isnull(ad_sales_amount,0))=0 then 100.00 else CONVERT(decimal(12,2),(ABS(SUM(isnull(spend,0)))/SUM(isnull(ad_sales_amount,0)))*100) end ACOS from [192.168.1.187].UpGoods.dbo.LxERP_ProductPerformance a left join [192.168.1.187].UpGoods.dbo.LxERP_Price_List b on a.ID=b.LxERP_ProductPerformance_ID left join [192.168.1.187].UpGoods.dbo.LxERP_Amazon_Shop c on a.sid=c.sid where summary_field='asin' and RequestDate>=@startDate and RequestDate<=@endDate group by a.sid,c.name, local_sku,b.local_name,seller_sku ) t where t.ACOS>=50 ) t2 left join HW_GoodsInfo f on t2.SKU=f.GoodsCode left join JC_UserInfo g on f.muserid=g.UserId group by g.Name order by Count desc "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.DateTime, startDate); db.AddInParameter(cmd, "@endDate", DbType.DateTime, endDate); DataTable tb = db.ExecuteDataTable(cmd); var allListModel = tb.ToList(); var listModel = new List(); if (userid == 1 || userid == 51) { listModel = allListModel; } else { listModel = allListModel.Where(r => !string.IsNullOrEmpty(r.Master) && r.Master.Equals(userName, StringComparison.OrdinalIgnoreCase)).ToList(); } rowCount = listModel.Count; return listModel; } #endregion #region 分页查询采购单商品详情列表 public static List GetCG_PurchaseGoodsCGPCList(int strType, string strValue, int state, int goodsState, string dateType, DateTime? startDate, DateTime? endDate, int PageIndex, int PageSize, out int rowCount) { var listModel = new List(); var sqlFil = " where 1=1 "; if (!string.IsNullOrEmpty(strValue)) { switch (strType) { case 0: sqlFil += " and a.ChaseCode like '%" + strValue.Trim() + "%'"; break; case 1: sqlFil += " and a.BuyCode like '%" + strValue.Trim() + "%'"; break; case 2: sqlFil += " and b.GoodsCode like '%" + strValue.Trim() + "%'"; break; case 3: sqlFil += " and c.GoodsName like '%" + strValue.Trim() + "%'"; break; } } if (state != -1) sqlFil += " and a.State=" + state; if (goodsState != -1) sqlFil += " and a.GoodsState=" + goodsState; if (startDate.HasValue) sqlFil += " and convert(date, " + dateType + ") >='" + startDate.Value.ToString("yyyy-MM-dd") + "'"; if (endDate.HasValue) sqlFil += " and convert(date," + dateType + ") <='" + endDate.Value.ToString("yyyy-MM-dd") + "'"; var sqlCount = @"select COUNT(1) from CG_Purchase a left join CG_PurchaseGoods b on a.ChaseId=b.ChaseId left join HW_GoodsInfo c on b.GoodsCode=c.GoodsCode " + sqlFil; Database db = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand1 = db.GetSqlStringCommand(sqlCount); var countObj = db.ExecuteScalar(sqlStringCommand1); rowCount = countObj != null ? (int)countObj : 0; var sql = @"select ChaseId,ChaseCode,BuyCode,GoodsCode,GoodsName,BuyDate,DoneDate,InGoodsNum,GoodsNum,GoodsPrice,TotalPrice,SingleCube,TotalCube,GoodsState,State ,case when GoodsState=0 then '未到货' when GoodsState=1 then '部分到货' when GoodsState=2 then '全部到货' when GoodsState=3 then '到货异常' end GoodsStateName, case when state=0 then '未审批' when state=1 then '审批通过' when state=2 then '审批不通过' when state=3 then '采购单结束' end StateName from ( select ROW_NUMBER() Over(order by a.BuyDate desc) row ,a.ChaseId,a.ChaseCode,a.BuyCode ,b.GoodsCode ,c.GoodsName , a.BuyDate ,a.DoneDate ,b.InGoodsNum , b.GoodsNum ,b.GoodsPrice ,b.GoodsNum*b.GoodsPrice TotalPrice,convert(decimal(12,2), c.Long*c.Width*c.Height/1000000) SingleCube,CONVERT(decimal(12,2), c.Long*c.Width*c.Height*b.GoodsNum/1000000) TotalCube,a.TSoild, a.GoodsState,a.State from CG_Purchase a left join CG_PurchaseGoods b on a.ChaseId=b.ChaseId left join HW_GoodsInfo c on b.GoodsCode=c.GoodsCode " + sqlFil + " ) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(sql); return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList(); } #endregion #region 查询采购单商品采购总金额和总立方 public static void GetCG_GoodsCGPCPriceAndCube(int strType, string strValue, int state, int goodsState, string dateType, DateTime? startDate, DateTime? endDate, out decimal totalPrice, out decimal totalCube) { var sqlFil = " where 1=1 "; if (!string.IsNullOrEmpty(strValue)) { switch (strType) { case 0: sqlFil += " and a.ChaseCode like '%" + strValue.Trim() + "%'"; break; case 1: sqlFil += " and a.BuyCode like '%" + strValue.Trim() + "%'"; break; case 2: sqlFil += " and b.GoodsCode like '%" + strValue.Trim() + "%'"; break; case 3: sqlFil += " and c.GoodsName like '%" + strValue.Trim() + "%'"; break; } } if (state != -1) sqlFil += " and a.State=" + state; if (goodsState != -1) sqlFil += " and a.GoodsState=" + goodsState; if (startDate.HasValue) sqlFil += " and convert(date, " + dateType + ") >='" + startDate.Value.ToString("yyyy-MM-dd") + "'"; if (endDate.HasValue) sqlFil += " and convert(date," + dateType + ") <='" + endDate.Value.ToString("yyyy-MM-dd") + "'"; var sql = @"select Convert(decimal(12,2),Sum(ISNULL(TotalPrice,0))) totalPrice, Convert(decimal(12,2),Sum(ISNULL(TotalCube,0))) totalCube from ( select b.GoodsNum*b.GoodsPrice TotalPrice,CONVERT(decimal(12,2), c.Long*c.Width*c.Height*b.GoodsNum/1000000) TotalCube from CG_Purchase a left join CG_PurchaseGoods b on a.ChaseId=b.ChaseId left join HW_GoodsInfo c on b.GoodsCode=c.GoodsCode " + sqlFil + " ) t"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(sql); var dt = database.ExecuteDataTable(sqlStringCommand); if (dt != null && dt.Rows.Count > 0) { totalPrice = !string.IsNullOrEmpty(dt.Rows[0]["totalPrice"].ToString()) ? Convert.ToDecimal(dt.Rows[0]["totalPrice"]) : 0; totalCube = !string.IsNullOrEmpty(dt.Rows[0]["totalCube"].ToString()) ? Convert.ToDecimal(dt.Rows[0]["totalCube"]) : 0; } else { totalPrice = 0; totalCube = 0; } } #endregion #region 保存财务每天必填资金流数据 public static int SaveFinanceFundData(FinanceFundData Model) { string tsql = @" select top 1 @Id=Id from FinanceFund where datediff(day,InDate,@InDate)=0 if @Id>0 begin Update [FinanceFund] set WI=@WI,EI=@EI,OI=@OI,KI=@KI,BA=@BA,CA=@CA,FAM=@FAM,FN=@FN,FD=@FD,Rate=@Rate,TOTAL=@TOTAL where Id=@Id end else begin INSERT INTO [FinanceFund](InDate,WI,EI,OI,KI,BA,CA,FAM,FN,FD,Rate,TOTAL,CreateUserId,CreateTime)values(@InDate,@WI,@EI,@OI,@KI,@BA,@CA,@FAM,@FN,@FD,@Rate,@TOTAL,@CreateUserId,GETDATE()) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.ID); db.AddInParameter(cmd, "@InDate", DbType.DateTime, Model.InDate); db.AddInParameter(cmd, "@WI", DbType.Decimal, Model.WI); db.AddInParameter(cmd, "@EI", DbType.Decimal, Model.EI); db.AddInParameter(cmd, "@OI", DbType.Decimal, Model.OI); db.AddInParameter(cmd, "@KI", DbType.Decimal, Model.KI); db.AddInParameter(cmd, "@BA", DbType.Decimal, Model.BA); db.AddInParameter(cmd, "@CA", DbType.Decimal, Model.CA); db.AddInParameter(cmd, "@FAM", DbType.Decimal, Model.FAM); db.AddInParameter(cmd, "@FN", DbType.Decimal, Model.FN); db.AddInParameter(cmd, "@FD", DbType.Decimal, Model.FD); db.AddInParameter(cmd, "@Rate", DbType.Decimal, Model.Rate); db.AddInParameter(cmd, "@TOTAL", DbType.Decimal, Model.TOTAL); db.AddInParameter(cmd, "@CreateUserId", DbType.Int32, Model.CreateUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 获取财务每天必填资金流数据 public static List GetFinanceFundDataList(DateTime? SDate, DateTime? EDate, int PageSize, int PageIndex, out int RowCount) { var sqlFile = " where 1=1 "; if (SDate.HasValue) sqlFile += " and convert(date, InDate)>='" + SDate.Value.Date + "'"; if (EDate.HasValue) sqlFile += " and convert(date,InDate)<='" + EDate.Value.Date + "'"; var sql = @" select COUNT(1) count from FinanceFund " + sqlFile + " select ID, InDateStr,InDate, WI,EI,OI,KI,BA,CA,FAM,FN,FD,Rate,TOTAL from (select ROW_NUMBER() OVER(order by Indate desc) row, ID, convert(nvarchar(20), InDate,23) InDateStr,InDate, WI,EI,OI,KI,BA,CA,FAM,FN,FD,Rate,TOTAL from FinanceFund " + sqlFile + " ) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); RowCount = (int)ds.Tables[0].Rows[0]["count"]; var listModel = new List(); if (ds.Tables[1].Rows.Count > 0) { listModel = ds.Tables[1].ToList(); } return listModel; } #endregion #region 删除财务每天必填资金流数据 public static void DeleteFinanceFundData(int id) { string tsql = @" delete from FinanceFund where ID=@id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 获取财务每天必填资金流中的E仓,业远仓,在途,冻结等价值数据 public static FinanceFundMoneyData GetFinanceFundMoneyData(int companyID) { var sql = @"--RANCHO价值 select a.KCNum,dj=(isnull(a.Price,0)+ISNULL(a.postprice,0))/6.3,tc=case when b.TCFee5>0 and b.TSoild>0 then b.TCFee5/b.TSoild else 200 end,FeeRate=isnull(d.FeeRate,0),Solid=isnull(d.Solid,0) into #ls from HW_GoodsInDetail a with(nolock) left join CG_Purchase b with(nolock) on a.ChaseId=b.ChaseId left join HW_GoodsDetail c with(nolock) on a.DetailId=c.DetailId left join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.StoreId=6 and KCNum>0 and OrderGoodsId=0 --E仓美东的价值 select a.KCNum,dj=(isnull(a.Price,0)+ISNULL(a.postprice,0))/6.3,tc=case when b.TCFee5>0 and b.TSoild>0 then b.TCFee5/b.TSoild else 200 end,FeeRate=isnull(d.FeeRate,0),Solid=isnull(d.Solid,0) into #ls2 from HW_GoodsInDetail a with(nolock) left join CG_Purchase b with(nolock) on a.ChaseId=b.ChaseId left join HW_GoodsDetail c with(nolock) on a.DetailId=c.DetailId left join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.StoreId=11 and KCNum>0 and OrderGoodsId=0 --业远仓的价值 select a.KCNum,dj=(isnull(a.Price,0)+ISNULL(a.postprice,0)),tc=case when b.TCFee5>0 and b.TSoild>0 then b.TCFee5/b.TSoild else 200 end,FeeRate=isnull(d.FeeRate,0),Solid=isnull(d.Solid,0) into #ls3 from HW_GoodsInDetail a with(nolock) left join CG_Purchase b with(nolock) on a.ChaseId=b.ChaseId left join HW_GoodsDetail c with(nolock) on a.DetailId=c.DetailId left join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.StoreId=8 and KCNum>0 and OrderGoodsId=0 declare @RCRate decimal(18,2),@ECRate decimal(18,2),@YYCRate decimal(18,2) select @RCRate=sum(KCNum*(dj+dj*FeeRate*0.01)+tc*KCNum*Solid) from #ls select @ECRate=sum(KCNum*(dj+dj*FeeRate*0.01)+tc*KCNum*Solid) from #ls2 select @YYCRate=SUM(KCNum*(dj+dj*FeeRate*0.01)+tc*KCNum*Solid) from #ls3 --在途价值 declare @ZTPrice decimal(18,2) select @ZTPrice=sum(isnull(b.GoodsPrice,0)*(ISNULL(b.SJOutNum,0)-ISNULL(b.OutInNum,0))) from CG_Purchase a with(nolock) inner join CG_PurchaseGoods b with(nolock) on a.ChaseId=b.GJChaseId inner join HW_GoodsDetail c with(nolock) on b.GoodsDetailId=c.DetailId inner join HW_GoodsInfo d with(nolock) on c.GoodsId=d.GoodsId where a.CompanyID=@CompanyID and a.IsDelete=0 and a.IsGJ=1 and ISNULL(b.SJOutNum,0)-ISNULL(b.OutInNum,0)>0 --所有冻结金额 declare @DJMoney decimal(18,2) select @DJMoney= CONVERT(decimal(12,2), SUM(ISNULL(originalTotalCurrencyAmount,0))) from [192.168.1.187].[UpGoods].dbo.LxERP_SettlementSummaryData where processingStatus='Open' and accountType='Standard' select RCRate=@RCRate,ECRate=@ECRate,YYCRate=@YYCRate,ZTPrice=@ZTPrice,DJMoney=@DJMoney"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(sql); database.AddInParameter(sqlStringCommand, "@CompanyID", DbType.Int32, companyID); DataTable table = database.ExecuteDataTable(sqlStringCommand); var rmodel = new FinanceFundMoneyData(); if (table.Rows.Count > 0) { rmodel = table.Rows[0].ToModel(); } return rmodel; } #endregion #region 获取昨天汇率 public static decimal GetLastDayFinanceFundRateData() { var sql = @"select top 1 Rate from FinanceFund order by InDate desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var obj = db.ExecuteScalar(cmd); return obj == null ? 0 : Convert.ToDecimal(obj); } #endregion #region 获取昨天汇总 public static decimal GetLastDayFinanceFundTotalData() { var sql = @"select top 1 TOTAL from FinanceFund order by InDate desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var obj = db.ExecuteScalar(cmd); return obj == null ? 0 : Convert.ToDecimal(obj); } #endregion #region 获取订单详情页广告花费,当天的订单取前一天的广告花费 public static decimal GetOrderAdFeeByOrderID(int orderid) { //var orderSql = @"select CONVERT(nvarchar(100), OrderDate,23) OrderDate,ShopId ,PlatId from DT_OrderInfo where OrderId=" + orderid; //Database db1 = DatabaseFactory.CreateDatabase(); //DbCommand cmd1 = db1.GetSqlStringCommand(orderSql); //var dt1 = db1.ExecuteDataTable(cmd1); ////不是亚马逊平台的订单,广告费无法计算,直接为0 //if (dt1.Rows[0]["PlatId"].ToString() != "2") // return 0; //var sql = @"select sum (AvgTotalAdfee) AvgTotalAdfee from( // --找到当天亚马逊平台的店铺售出该Goodsid的总数量,把总广告费/出售的全部数量*该订单中的商品数量=该订单中商品花费的广告费 // select t1.OrderDate,t1.ShopId,t1.GoodsId,t1.GoodsNum , ISNULL( t2.adfee,0) TotalAdfee,CONVERT(decimal(12,2),(ISNULL(t2.adfee,0)/(select SUM(f.GoodsNum) from DT_OrderGoods f inner join HW_GoodsDetail g on f.DetailId=g.DetailId inner join DT_OrderInfo h on f.OrderId=h.OrderId where g.GoodsId=t1.GoodsId and CONVERT(date,OrderDate)=@OrderDate and h.PlatId=2 group by goodsid))*t1.GoodsNum) AvgTotalAdfee from ( // --找到当前订单中每种商品的数量 // select CONVERT(nvarchar(100),a.OrderDate,23) as OrderDate, a.ShopId,c.GoodsId ,SUM(b.GoodsNum) GoodsNum from DT_OrderInfo a // inner join DT_OrderGoods b on a.OrderId=b.OrderId // inner join HW_GoodsDetail c on b.DetailId=c.DetailId // where a.OrderId=@orderid group by CONVERT(nvarchar(100),a.OrderDate,23),a.ShopId,c.GoodsId // ) t1 left join (select CONVERT(nvarchar(100),DATEADD(day,1,addate),23) addate,goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))=@OrderDate group by addate,goodsid ) t2 on t1.OrderDate=t2.addate and t1.GoodsId=t2.goodsid) t3"; //Database db = DatabaseFactory.CreateDatabase(); //DbCommand cmd = db.GetSqlStringCommand(sql); //db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); //db.AddInParameter(cmd, "@OrderDate", DbType.Date, Convert.ToDateTime(dt1.Rows[0]["OrderDate"]).Date); //var obj = db.ExecuteScalar(cmd); var sql = @"select SUM(ISNULL(adfee,0)) TotalAdfee from DT_OrderGoods where OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, orderid); var obj = db.ExecuteScalar(cmd); return obj == null ? 0 : Convert.ToDecimal(obj); } #endregion #region 获取订单列表页每个商品的广告花费 public static List GetOrderListGoodsAdFeeByOrderID(string orderids) { var sql = @"select t1.OrderDate,t1.ShopId,t1.GoodsId,t1.GoodsNum , ISNULL( t2.adfee,0) TotalAdfee,case when ISNULL(t1.GoodsNum,0)<=0 then ISNULL( t2.adfee,0) else CONVERT(decimal(12,2),ISNULL(t2.adfee,0)/t1.GoodsNum) end AvgAdfee from ( select t.OrderDate,t.ShopId,t.GoodsId,SUM(t.GoodsNum) GoodsNum from ( select CONVERT(nvarchar(100),a.OrderDate,23) as OrderDate, a.ShopId,c.GoodsId , b.GoodsNum from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId where a.OrderId in (" + orderids + ")) t group by OrderDate,ShopId,GoodsId ) t1 left join " + " (select CONVERT(nvarchar(100),DATEADD(day,1,addate),23) addate,shopid,goodsid,SUM(adfeenew) adfee from AD_FeeList group by addate,shopid,goodsid ) t2 on t1.OrderDate=t2.addate and t1.ShopId=t2.shopid and t1.GoodsId=t2.goodsid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsLeaveWordFromDate(DateTime? sdt, DateTime? edt, int platid, string content) { //string tsql = "select a.id,a.leaveword,a.inname,a.indate,a.isread,a.goodsid from HW_GoodsLeaveWord"; string tsql = "select distinct goodsid from HW_GoodsLeaveWord where indate>=@sdt and indate<@edt and platid=@platid and leavetype=1 and (@content='' or leaveword like '%" + content + "%')"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdt", DbType.DateTime, sdt); db.AddInParameter(cmd, "@edt", DbType.DateTime, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); db.AddInParameter(cmd, "@content", DbType.String, content); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsOrdersFromDate(DateTime? sdt, DateTime? edt, string goodsids, int platid) { //string tsql = "select a.id,a.leaveword,a.inname,a.indate,a.isread,a.goodsid from HW_GoodsLeaveWord"; string tsql = @"select c.GoodsId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a with(nolock) inner join DT_OrderInfo b with(nolock) on a.OrderId = b.OrderId inner join HW_GoodsDetail c with(nolock) on a.DetailId = c.DetailId where b.State > 0 and b.State < 3 and b.PlatId=@platid and b.OrderDate >=@sdt and b.OrderDate <@edt and c.GoodsId in (" + goodsids + ") group by c.GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sdt", DbType.DateTime, sdt); db.AddInParameter(cmd, "@edt", DbType.DateTime, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回个人每天的销售数据 public static List GetPeopleDaySaleDatasList(int userid, DateTime? sdt, DateTime? edt) { var sqlFilt = ""; if (userid != 0) sqlFilt += " where a.guserid=" + userid; // var sql = @" // --获取到每天运营一组和二组所有人员的广告花费 // select ISNULL(addate,RequestDate) addate,ISNULL(guserid,UserId) guserid,adfee into #ls_1 from ( // select t.addate,t.guserid,ABS(SUM(t.adfee)) adfee from ( // select a.shopid,a.goodsid,CONVERT(date, addate) addate, adfee, b.PlatType, // case when b.PlatType=2 then muserid when b.PlatType=3 then guserid_ebay when b.PlatType=6 then guserid_wlmart when b.PlatType=15 then guserid_shopify // when b.PlatType=18 then guserid_wayfair when b.PlatType=21 then guserid_sheIn end guserid // from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where CONVERT(date, a.addate)>=@startDate and CONVERT(date, a.addate)<=@endDate) t // group by t.addate,t.guserid) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a // Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b // where a.UserId in (60, 69, 181, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222 )) t2 on t1.guserid=t2.UserId and t1.addate=t2.RequestDate // select t.OrderDate,t.guserid,COUNT(distinct t.OrderId) OrderNum,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice into #ls_2 from ( // select CONVERT(date, a.OrderDate) OrderDate,a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice, // case when a.PlatId=2 then muserid when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify // when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid // from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId // where a.State>0 and a.State<3 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) t group by t.OrderDate,t.guserid // select CONVERT(date, a.OrderDate) OrderDate,f.guserid, // Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- // (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR into #ls_3 // from DT_OrderInfo a with(nolock) // left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId // left join DT_Fees c with(nolock) on a.OrderId=c.orderid // left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId // left join jc_shop e on d.ShopId=e.ShopId // left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,case when z.PlatId=2 then muserid when z.PlatId=3 then guserid_ebay when z.PlatId=6 then guserid_wlmart when z.PlatId=15 then guserid_shopify when z.PlatId=18 then guserid_wayfair when z.PlatId=21 then guserid_sheIn end guserid // from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId // where z.State>0 and z.State<3 and CONVERT(date,z.OrderDate)>=@startDate and CONVERT(date,z.OrderDate)<=@endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId // where a.State>0 and a.State<3 and CONVERT(date,a.OrderDate)>=@startDate and CONVERT(date,a.OrderDate)<=@endDate group by CONVERT(date, a.OrderDate) ,f.guserid // select t1.OrderDate,t1.muserid, sum(isnull(t2.adfee,0)) AdFee into #ls_4 from ( // select CONVERT(nvarchar(100),a1.OrderDate,23) as OrderDate,c1.GoodsId ,SUM(b1.GoodsNum) GoodsNum,muserid from DT_OrderInfo a1 // inner join DT_OrderGoods b1 on a1.OrderId=b1.OrderId // inner join HW_GoodsDetail c1 on b1.DetailId=c1.DetailId // inner join HW_GoodsInfo d1 on c1.GoodsId=d1.GoodsId // where CONVERT(date,a1.OrderDate)>=@startDate and CONVERT(date,a1.OrderDate)<=@endDate and PlatId=2 group by CONVERT(nvarchar(100),a1.OrderDate,23),muserid,c1.GoodsId) t1 // left join (select CONVERT(nvarchar(100),DATEADD(day,1,addate),23) addate,goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))>=@startDate and CONVERT(date, DATEADD(day,1,addate))<=@endDate group by addate,goodsid) t2 // on t1.OrderDate=t2.addate and t1.GoodsId=t2.goodsid group by t1.OrderDate,t1.muserid //"; var sql = @"select guserid,SUM(adfee) adfee into #ls_1 from ( select ISNULL(guserid,UserId) guserid,adfee from ( select t.addate,t.guserid,ABS(SUM(t.adfee)) adfee from ( select a.shopid,a.goodsid,CONVERT(date, addate) addate, adfee, b.PlatType,muserid guserid from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where b.PlatType=2 and CONVERT(date, a.addate)>=@startDate and CONVERT(date, a.addate)<=@endDate) t group by t.addate,t.guserid) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.addate=t2.RequestDate ) t group by guserid --select t.guserid,COUNT(distinct t.OrderId) OrderNum,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice into #ls_2 from ( --select CONVERT(date, a.OrderDate) OrderDate,a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice,muserid guserid --from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId --where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) t group by t.guserid select tt.guserid,COUNT(distinct tt.OrderId) OrderNum,SUM(tt.GoodsNum) GoodsNum,SUM(tt.TotalPrice) TotalPrice into #ls_2 from ( select ROW_NUMBER() over(partition by orderid,guserid order by goodsNum) row, t.* from ( select CONVERT(date, a.OrderDate) OrderDate,a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice,muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.CompanyId=1 and a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) t)tt group by guserid --未去除广告费的利润 select f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR ,SUM(ISNULL(c.SubsidyFee,0)) SubsidyFee into #ls_3 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,muserid guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>=@startDate and CONVERT(date,z.OrderDate)<=@endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>=@startDate and CONVERT(date,a.OrderDate)<=@endDate group by f.guserid --所有订单商品的广告费 select t1.muserid, sum(isnull(t2.adfee,0)) AdFee into #ls_4 from ( select d1.muserid, d1.GoodsId from DT_OrderInfo a1 inner join DT_OrderGoods b1 on a1.OrderId=b1.OrderId inner join HW_GoodsDetail c1 on b1.DetailId=c1.DetailId inner join HW_GoodsInfo d1 on c1.GoodsId=d1.GoodsId where CONVERT(date,a1.OrderDate)>=@startDate and CONVERT(date,a1.OrderDate)<=@endDate and PlatId=2 group by d1.muserid,d1.GoodsId ) t1 left join (select goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))>=@startDate and CONVERT(date, DATEADD(day,1,addate))<=@endDate group by goodsid) t2 on t1.GoodsId=t2.goodsid group by t1.muserid select b.muserid UserId, SUM(Ad_Order_Quantity) AdOrdersNum,SUM(Ad_Order_Amount) AdOrderAmount into #ls_5 from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by muserid --仓储费 select muserid UserId,SUM(StockSolidNum)*0.5 TotalSolidFee into #ls_6 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date,a.InDate)>=@startDate and CONVERT(date,a.indate)<=@endDate group by muserid "; sql += " \r\n select ROW_NUMBER() over(order by b.TotalPrice desc) row,2 PlatId, a.guserid UserId,c.Name,c.GroupName,c.guserid GroupUserId, a.adfee AdFee,b.OrderNum OrdersNum,b.GoodsNum,b.TotalPrice as SalePrice,convert(decimal(12,2), d.LR) as NetProfit,AdOrdersNum,AdOrderAmount,case when IsNull(AdOrdersNum,0)=0 or IsNull(b.OrderNum,0)=0 then 0 else convert(decimal(12,2), (AdOrdersNum*1.00/b.OrderNum)*(d.LR-e.AdFee)) end AdOrderLR ,HJLR=ISNULL(d.LR,0)- isnull(a.adfee,0)-ISNULL(g.TotalSolidFee,0),d.SubsidyFee from #ls_1 a left join #ls_2 b on a.guserid=b.guserid left join JC_UserInfo c on a.guserid=c.UserId left join #ls_3 d on a.guserid=d.guserid left join #ls_4 e on a.guserid=e.muserid left join #ls_5 f on a.guserid=f.UserId left join #ls_6 g on a.guserid=g.UserId " + sqlFilt; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt.Value.Date); db.AddInParameter(cmd, "@endDate", DbType.Date, edt.Value.Date); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取个人广告花费详情 public static List GetPeopleAdFeeDetailList(int userid, DateTime? sDate, DateTime? eDate) { //var filt = ""; //if (sDate.HasValue) // filt += " and CONVERT(date, addate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "' "; //if(eDate.HasValue) // filt+= " and CONVERT(date, addate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "' "; //var sql = @" select ShopName,GoodsCode,GoodsName,SUM(AdFee) AdFee from( // select a.shopid,c.ShopName,a.goodsid,b.GoodsCode,b.GoodsName, ABS(a.adfee) AdFee, // case when c.PlatType=2 then muserid when c.PlatType=3 then guserid_ebay when c.PlatType=6 then guserid_wlmart when c.PlatType=15 then guserid_shopify // when c.PlatType=18 then guserid_wayfair when c.PlatType=21 then guserid_sheIn end guserid // from AD_FeeList a inner join HW_GoodsInfo b on a.goodsid =b.GoodsId inner join JC_Shop c on a.shopid=c.ShopId where 1=1 " + filt + " ) t where t.guserid=" + userid + " group by ShopName,GoodsCode,GoodsName,AdFee,guserid"; var sql = @"--广告 select a.goodsid, sum( ABS(a.adfee)) AdFee into #ls_1 from AD_FeeList a inner join HW_GoodsInfo b on a.goodsid =b.GoodsId where 1=1 and CONVERT(date, addate)>=@startDate and convert(date,addate)<=@endDate and muserid=@userid group by a.goodsid --订单数量,和金额 select c.GoodsId,COUNT(distinct a.OrderId) OrderNum,SUM(a.TotalPrice) Totalprice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.CompanyId=1 and a.State>0 and a.State<3 and a.PlatId=2 and muserid=@userid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate group by c.GoodsId select GoodsId,SUM(Ad_Order_Quantity) AdOrdersNum,SUM(Ad_Order_Amount) AdOrderAmount into #ls_3 from AdOrdersProportion where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by GoodsId select d.GoodsCode,d.GoodsName, a.AdFee,b.OrderNum,b.TotalPrice,c.AdOrdersNum,c.AdOrderAmount from #ls_1 a left join #ls_2 b on a.goodsid=b.GoodsId left join #ls_3 c on a.goodsid=c.GoodsId left join HW_GoodsInfo d on a.goodsid=d.GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sDate); db.AddInParameter(cmd, "@endDate", DbType.Date, eDate); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); DataTable dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取所有人每人每天的销售额数据 public static List GetPeopleDaySalePriceList(DateTime sdt, DateTime edt) { var sql = @"select x.guserid as UserId,CONVERT(nvarchar(23), x.Date) as RDate,ISNULL(z.TotalPrice,0) TotalPrice from ( --找到所有运营人员,以及日期做笛卡尔积 select e.guserid,Date from ( select distinct muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e Cross join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) t where e.guserid in (-1,60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236) ) x left join ( --获取到没人每天的总销售额 select CONVERT(date, a.OrderDate) OrderDate,muserid guserid ,Sum(a.TotalPrice) TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate group by muserid,CONVERT(date, a.OrderDate) )z on x.Date=z.OrderDate and x.guserid=z.guserid order by x.guserid ,Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的销售额数据 public static List GetPeopleDaySalePriceList(int platid, DateTime sdt, DateTime edt) { var sql = @"select t2.guserid UserId, CONVERT(nvarchar(23), t2.Date) as RDate ,t1.TotalPrice from ( select z.OrderDate,z.guserid,SUM(ISNULL(z.TotalPrice,0)) TotalPrice from ( select CONVERT(date, a.OrderDate) OrderDate, a.TotalPrice, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) z group by z.guserid,z.OrderDate ) t1 full join ( select * from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b ) t2 on t1.OrderDate=t2.Date and ISNULL(t1.guserid,0)=ISNULL(t2.guserid,0) order by t2.guserid ,t2.Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取指定平台所有人每人每天的销售额数据 public static List GetPeopleDaySalePriceByPlatidList(int platid, DateTime sdt, DateTime edt) { var sql = @"select x.guserid UserId,CONVERT(nvarchar(23), x.Date) as RDate,ISNULL( z.TotalPrice,0) TotalPrice from ( select e.guserid,Date from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e Cross join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) t ) x left join ( select CONVERT(date,t.OrderDate) OrderDate,t.guserid,SUM(TotalPrice) TotalPrice from ( select CONVERT(date, a.OrderDate) OrderDate,Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid ,a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) t group by CONVERT(date, t.OrderDate),t.guserid )z on x.Date=z.OrderDate and ISNULL( x.guserid,0)=ISNULL( z.guserid,0) order by x.guserid ,Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取指定平台所有人每人每天的销售额数据 public static List GetPeopleDaySalePriceByPlatidListNew(string platids, DateTime sdt, DateTime edt) { var sql = @"select x.PlatId, x.guserid UserId,CONVERT(nvarchar(23), x.Date) as RDate,ISNULL( z.TotalPrice,0) TotalPrice from ( select e.PlatId, e.guserid,Date from ( select distinct a.platid, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId in (" + platids + ") and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e "; sql += @" Cross join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) t ) x left join ( select t.platid, CONVERT(date,t.OrderDate) OrderDate,t.guserid,SUM(TotalPrice) TotalPrice from ( select a.platid, CONVERT(date, a.OrderDate) OrderDate,Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid ,a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId in (" + platids + ") and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) t group by t.platid, CONVERT(date, t.OrderDate),t.guserid)z on x.Date=z.OrderDate and ISNULL( x.guserid,0)=ISNULL( z.guserid,0) and x.PlatId=z.PlatId order by x.PlatId, x.guserid ,Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt.Date); db.AddInParameter(cmd, "@endDate", DbType.Date, edt.Date); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人库存数量金额 public static List GetPeopleGoodsNum() { // var sql = @"select a.muserid,WNum=SUM(b.WestNum),WPrice=SUM(b.WestNumPrice),ENum=SUM(b.EastNum),EPrice=SUM(b.EastNumPrice),WNum2=SUM(b.GoodsHJNum14),WPrice2=SUM(b.GoodsHJNum14Price),ENum2=SUM(b.GoodsHJNum15),EPrice2=SUM(b.GoodsHJNum15Price),NBNum=SUM(b.NBHJNum),NBPrice=SUM(b.NBHJNumPrice) from HW_GoodsInfo a //inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId // group by a.muserid"; var sql = @" select 2 PlatId, IsNull( a.muserid,0) muserid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) ,DayTotalSolidFee=(Sum((WestNum+EastNum+GoodsHJNum14+GoodsHJNum15+NBHJNum)*a.Solid))*0.5 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId group by a.muserid union all select 3 PlatId, IsNull( a.guserid_ebay,0) muserid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) ,DayTotalSolidFee=(Sum((WestNum+EastNum+GoodsHJNum14+GoodsHJNum15+NBHJNum)*a.Solid))*0.5 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId group by a.guserid_ebay union all select 6 PlatId, IsNull( a.guserid_wlmart,0) muserid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) ,DayTotalSolidFee=(Sum((WestNum+EastNum+GoodsHJNum14+GoodsHJNum15+NBHJNum)*a.Solid))*0.5 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId group by a.guserid_wlmart union all select 15 PlatId, IsNull( a.guserid_shopify,0) muserid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) ,DayTotalSolidFee=(Sum((WestNum+EastNum+GoodsHJNum14+GoodsHJNum15+NBHJNum)*a.Solid))*0.5 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId group by a.guserid_shopify union all select 18 PlatId, IsNull( a.guserid_wayfair,0) muserid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) ,DayTotalSolidFee=(Sum((WestNum+EastNum+GoodsHJNum14+GoodsHJNum15+NBHJNum)*a.Solid))*0.5 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId group by a.guserid_wayfair union all select 21 PlatId, IsNull( a.guserid_sheIn,0) muserid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) ,DayTotalSolidFee=(Sum((WestNum+EastNum+GoodsHJNum14+GoodsHJNum15+NBHJNum)*a.Solid))*0.5 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId group by a.guserid_sheIn"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取每个人的库存数量金额 public static List GetPeopleEveryGoodsNum(string muids, string goodsCode) { string filt = "ISNULL( a.muserid,0) in (" + muids + ")"; if (!string.IsNullOrEmpty(goodsCode)) filt += " and a.GoodsCode like '%" + goodsCode + "%'"; // var sql = @" select COUNT(*) count from ( select a.GoodsCode from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where " + filt + " group by a.GoodsCode) z "; // sql += @" select GoodsCode, WStockNum,WStockPrice,WInRoadNum,WInRoadPrice,EStockNum,EStockPrice,EInRoadNum,EInRoadPrice,GNStockNum,GNStockPrice from ( //select ROW_NUMBER() over(order by a.GoodsCode desc) row, a.goodsCode GoodsCode,WStockNum=SUM(b.WestNum),WStockPrice=SUM(b.WestNumPrice),EStockNum=SUM(b.EastNum),EStockPrice=SUM(b.EastNumPrice),WInRoadNum=SUM(b.GoodsHJNum14),WInRoadPrice=SUM(b.GoodsHJNum14Price), //EInRoadNum=SUM(b.GoodsHJNum15),EInRoadPrice=SUM(b.GoodsHJNum15Price),GNStockNum=SUM(b.NBHJNum),GNStockPrice=SUM(b.NBHJNumPrice) from HW_GoodsInfo a //inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where " + filt + " group by a.GoodsCode) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; // Database db = DatabaseFactory.CreateDatabase(); // DbCommand cmd = db.GetSqlStringCommand(sql); // DataSet ds = db.ExecuteDataSet(cmd); // rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["count"]); // List ListModel = ds.Tables[1].ToList(); var sql = @"select a.goodsCode GoodsCode,WStockNum=SUM(b.WestNum),WStockPrice=SUM(b.WestNumPrice),EStockNum=SUM(b.EastNum),EStockPrice=SUM(b.EastNumPrice),WInRoadNum=SUM(b.GoodsHJNum14),WInRoadPrice=SUM(b.GoodsHJNum14Price), EInRoadNum=SUM(b.GoodsHJNum15),EInRoadPrice=SUM(b.GoodsHJNum15Price),GNStockNum=SUM(b.NBHJNum),GNStockPrice=SUM(b.NBHJNumPrice) from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where " + filt + " group by a.muserid, a.GoodsCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取每个人当天的库存花费 public static List GetPeopleDayStockFee(DateTime? sDate, DateTime? eDate) { var filter = " where 1=1 "; if (sDate.HasValue) filter += " and CONVERT(date,a.InDate)>='" + sDate.Value.Date + "' "; if (eDate.HasValue) filter += " and CONVERT(date,a.InDate)<='" + eDate.Value.Date + "'"; var sql = @"select ISNULL(muserid,0) UserId,Convert(decimal(12,2), SUM(StockSolidNum)*0.5) DayTotalSolidFee from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId " + filter + " group by ISNULL(muserid,0)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的广告花费数据 public static List GetPeopleDayAdFeeList(DateTime sdt, DateTime edt) { var sql = @"select ISNULL(guserid,UserId) UserId, CONVERT(nvarchar(23), ISNULL( t1.addate,t2.RequestDate)) as RDate, IsNull(adfee,0) TotalPrice from ( select t.addate,t.guserid,ABS(SUM(t.adfee)) adfee from ( select a.shopid,a.goodsid,CONVERT(date, addate) addate, adfee, b.PlatType,muserid guserid from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where b.PlatType=2 and CONVERT(date, a.addate)>=@startDate and CONVERT(date, a.addate)<=@endDate) t group by t.addate,t.guserid) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.addate=t2.RequestDate order by guserid ,addate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的订单数量数据 public static List GetPeopleDayOrderNumList(DateTime sdt, DateTime edt) { var sql = @"select ISNULL(UserId,guserid) UserId, CONVERT(nvarchar(23), ISNULL(RequestDate,OrderDate)) RDate ,ISNULL( OrderNum,0) OrderNum from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(date, a.OrderDate) OrderDate,a.OrderId,muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate group by CONVERT(date, a.OrderDate),a.OrderId,muserid) z group by OrderDate,guserid) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.OrderDate=t2.RequestDate order by UserId,RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取某平台每人每天的订单数量数据 public static List GetNoAmazonPeopleDayOrderNumList(int platid, int userid, DateTime sdt, DateTime edt) { var sql = @"select CONVERT(nvarchar(23), t1.Date) RDate,ISNULL( OrderNum,0) OrderNum,@userid as UserId from ( SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate) ) t1 left join ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(date, a.OrderDate) OrderDate,a.OrderId, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) t where guserid=187 group by t.OrderDate ,guserid ) t2 on t1.Date=t2.OrderDate order by t1.Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取某平台每人每天的订单数量数据 public static List GetNoAmazonAllPeopleDayOrderNumList(int platid, DateTime sdt, DateTime edt) { var sql = @"select CONVERT(nvarchar(23), t2.Date) RDate,ISNULL( OrderNum,0) OrderNum ,t2.guserid UserId from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(date, a.OrderDate) OrderDate,a.OrderId, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) t group by t.OrderDate ,guserid ) t1 full join ( select * from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b )t2 on t1.OrderDate=t2.Date and ISNULL( t1.guserid,0)=ISNULL( t2.guserid,0) order by t2.guserid ,Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的利润数据 public static List GetPeopleDayLRList(DateTime sdt, DateTime edt) { var sql = @"select ISNULL(t2.UserId,t1.guserid) UserId,Convert(nvarchar(23), ISNULL(t2.RequestDate,t1.OrderDate)) RDate,ISNULL(t1.LR,0) TotalPrice from ( select z1.guserid,z1.OrderDate, ISNULL(z1.LR,0)-ISNULL(z2.AdFee,0) LR from ( select CONVERT(date,a.orderdate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,muserid guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>= @startDate and CONVERT(date,z.OrderDate)<= @endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>= @startDate and CONVERT(date,a.OrderDate)<= @endDate group by f.guserid,CONVERT(date, a.OrderDate) ) z1 left join ( select orderdate, t1.muserid, sum(isnull(t2.adfee,0)) AdFee from ( select CONVERT(date,a1.OrderDate) OrderDate, d1.muserid, d1.GoodsId from DT_OrderInfo a1 inner join DT_OrderGoods b1 on a1.OrderId=b1.OrderId inner join HW_GoodsDetail c1 on b1.DetailId=c1.DetailId inner join HW_GoodsInfo d1 on c1.GoodsId=d1.GoodsId where CONVERT(date,a1.OrderDate)>= @startDate and CONVERT(date,a1.OrderDate)<=@endDate and PlatId=2 group by CONVERT(date,a1.OrderDate), d1.muserid,d1.GoodsId ) t1 left join (select CONVERT(date,DATEADD(day,1,addate)) AdDate, goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))>= @startDate and CONVERT(date, DATEADD(day,1,addate))<=@endDate group by CONVERT(date,DATEADD(day,1,addate)) , goodsid) t2 on t1.GoodsId=t2.goodsid and t1.OrderDate=t2.AdDate group by t1.muserid,OrderDate ) z2 on z1.OrderDate=z2.OrderDate and z1.guserid=z2.muserid ) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number,@startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.guserid=t2.UserId order by t2.UserId,t2.RequestDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的利润数据 public static List GetPeopleDayLRList(int platid, DateTime sdt, DateTime edt) { var sql = @" select t2.guserid UserId,Convert(nvarchar(23),t2.Date) RDate,ISNULL(t1.LR,0) TotalPrice from ( select CONVERT(date,a.orderdate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId, Case when z.PlatId=3 then guserid_ebay when z.PlatId=6 then guserid_wlmart when z.PlatId=15 then guserid_shopify when z.PlatId=18 then guserid_wayfair when z.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=@platid and CONVERT(date,z.OrderDate)>= @startDate and CONVERT(date,z.OrderDate)<= @endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date,a.OrderDate)>= @startDate and CONVERT(date,a.OrderDate)<= @endDate group by f.guserid,CONVERT(date, a.OrderDate) ) t1 full join ( select * from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b )t2 on t1.OrderDate=t2.Date and isnull(t1.guserid,0)=ISNULL(t2.guserid,0) order by t2.guserid,t2.Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的广告订单数据 public static List GetPeopleDayAdOrderNumList(DateTime sdt, DateTime edt) { var sql = @"select CONVERT(nvarchar(23), ISNULL( t2.RequestDate,t1.OrderDate)) RDate,ISNULL( t2.UserId,t1.UserId) UserId,ISNULL( t1.AdOrdersNum,0) OrderNum from ( select CONVERT(date,OrderDate) OrderDate, b.muserid UserId, SUM(Ad_Order_Quantity) AdOrdersNum from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by CONVERT(date,OrderDate), muserid ) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.UserId=t2.UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的广告销售金额数据 public static List GetPeopleDayAdOrderSalePriceList(DateTime sdt, DateTime edt) { var sql = @"select CONVERT(nvarchar(23), ISNULL( t2.RequestDate,t1.OrderDate)) RDate,ISNULL( t2.UserId,t1.UserId) UserId,ISNULL( t1.AdOrdersAmount,0) TotalPrice from ( select CONVERT(date,OrderDate) OrderDate, b.muserid UserId, SUM(Ad_Order_Amount) AdOrdersAmount from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by CONVERT(date,OrderDate), muserid ) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.UserId=t2.UserId order by UserId,RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每天的广告利润金额数据 public static List GetPeopleDayAdOrderLRPriceList(DateTime sdt, DateTime edt) { var sql = @" select ISNULL(UserId,guserid) UserId, CONVERT(nvarchar(23), ISNULL(RequestDate,OrderDate)) RDate ,ISNULL( OrderNum,0) OrderNum into #ls_1 from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(date, a.OrderDate) OrderDate,a.OrderId,muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate group by CONVERT(date, a.OrderDate),a.OrderId,muserid) z group by OrderDate,guserid) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.OrderDate=t2.RequestDate order by UserId,RDate select ISNULL(t2.UserId,t1.guserid) UserId,Convert(nvarchar(23), ISNULL(t2.RequestDate,t1.OrderDate)) RDate,ISNULL(t1.LR,0) TotalPrice into #ls_2 from ( select z1.guserid,z1.OrderDate, ISNULL(z1.LR,0)-ISNULL(z2.AdFee,0) LR from ( select CONVERT(date,a.orderdate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,muserid guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>= @startDate and CONVERT(date,z.OrderDate)<= @endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>= @startDate and CONVERT(date,a.OrderDate)<= @endDate group by f.guserid,CONVERT(date, a.OrderDate) ) z1 left join ( select orderdate, t1.muserid, sum(isnull(t2.adfee,0)) AdFee from ( select CONVERT(date,a1.OrderDate) OrderDate, d1.muserid, d1.GoodsId from DT_OrderInfo a1 inner join DT_OrderGoods b1 on a1.OrderId=b1.OrderId inner join HW_GoodsDetail c1 on b1.DetailId=c1.DetailId inner join HW_GoodsInfo d1 on c1.GoodsId=d1.GoodsId where CONVERT(date,a1.OrderDate)>= @startDate and CONVERT(date,a1.OrderDate)<=@endDate and PlatId=2 group by CONVERT(date,a1.OrderDate), d1.muserid,d1.GoodsId ) t1 left join (select CONVERT(date,DATEADD(day,1,addate)) AdDate, goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))>= @startDate and CONVERT(date, DATEADD(day,1,addate))<=@endDate group by CONVERT(date,DATEADD(day,1,addate)) , goodsid) t2 on t1.GoodsId=t2.goodsid and t1.OrderDate=t2.AdDate group by t1.muserid,OrderDate ) z2 on z1.OrderDate=z2.OrderDate and z1.guserid=z2.muserid ) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number,@startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.guserid=t2.UserId order by t2.UserId,t2.RequestDate select CONVERT(nvarchar(23), ISNULL( t2.RequestDate,t1.OrderDate)) RDate,ISNULL( t2.UserId,t1.UserId) UserId,ISNULL( t1.AdOrdersNum,0) OrderNum into #ls_3 from ( select CONVERT(date,OrderDate) OrderDate, b.muserid UserId, SUM(Ad_Order_Quantity) AdOrdersNum from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by CONVERT(date,OrderDate), muserid ) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @startDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.UserId=t2.UserId select a.UserId,a.RDate,a.OrderNum,case when ISNULL(a.OrderNum,0)=0 or ISNULL(c.OrderNum,0)=0 then 0 else CONVERT(decimal(12,2), (c.OrderNum*1.00/a.OrderNum)*b.TotalPrice) end TotalPrice from #ls_1 a left join #ls_2 b on a.UserId=b.UserId and a.RDate=b.RDate left join #ls_3 c on a.UserId=c.UserId and a.RDate=c.RDate order by a.UserId,a.RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取过去六个月每个人的销售额数据 public static List GetPeopleLast6MonthSalePriceList(DateTime sdt, DateTime edt) { var sql = @" select x.guserid as UserId,CONVERT(nvarchar(23), x.Date) as RDate,ISNULL(z.TotalPrice,0) TotalPrice from ( --找到所有运营人员,以及日期做笛卡尔积 select e.guserid,Date from ( select distinct muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e Cross join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) t where e.guserid in (-1,60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236) ) x left join ( --获取到没人每月的总销售额 select CONVERT(varchar(7), a.OrderDate, 120) OrderDate,muserid guserid ,Sum(a.TotalPrice) TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate group by muserid,CONVERT(varchar(7), a.OrderDate, 120) )z on x.Date=z.OrderDate and x.guserid=z.guserid order by x.guserid ,Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取平台过去六个月每个人的销售额数据 public static List GetPeopleLast6MonthSalePriceByPlatIdList(int platid, DateTime sdt, DateTime edt) { var sql = @"select x.guserid UserId,CONVERT(nvarchar(23), x.Date) as RDate, Isnull(z.TotalPrice,0) TotalPrice from ( select e.guserid,Date from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e Cross join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) t ) x left join ( select t.OrderDate,t.guserid,SUM(t.TotalPrice) TotalPrice from ( select CONVERT(varchar(7), a.OrderDate, 120) OrderDate,Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid , a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) t group by OrderDate,guserid )z on x.Date=z.OrderDate and ISNULL( x.guserid,0)=ISNULL(z.guserid,0) order by x.guserid ,Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取平台过去六个月每个人的销售额数据 public static List GetPeopleLast6MonthSalePriceByPlatIdListNew(string platids, DateTime sdt, DateTime edt) { var sql = @"select x.PlatId, x.guserid UserId,CONVERT(nvarchar(23), x.Date) as RDate, Isnull(z.TotalPrice,0) TotalPrice from ( select e.PlatId, e.guserid,Date from ( select distinct a.platid, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId in (" + platids + ") and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e"; sql += @" Cross join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) t )x left join ( select t.PlatId, t.OrderDate,t.guserid,SUM(t.TotalPrice) TotalPrice from ( select a.PlatId, CONVERT(varchar(7), dateadd(hour,12, a.OrderDate), 120) OrderDate,Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid , a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId in (" + platids + ") and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) t group by OrderDate,guserid,PlatId )z on x.Date=z.OrderDate and x.PlatId=z.PlatId and ISNULL( x.guserid,0)=ISNULL(z.guserid,0) order by x.PlatId, x.guserid ,Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的广告花费数据 public static List GetPeopleMonthAdFeeList(DateTime sdt, DateTime edt) { var sql = @"select ISNULL(guserid,UserId) UserId, CONVERT(nvarchar(23), ISNULL( t1.addate,t2.RequestDate)) as RDate, IsNull(adfee,0) TotalPrice from ( select CONVERT(varchar(7), t.addate, 120) addate,t.guserid,ABS(SUM(t.adfee)) adfee from ( select a.shopid,a.goodsid,CONVERT(date, addate) addate, adfee, b.PlatType,muserid guserid from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where b.PlatType=2 and CONVERT(date, a.addate)>=@startDate and CONVERT(date, a.addate)<=@endDate) t group by CONVERT(varchar(7), t.addate, 120),t.guserid) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.addate=t2.RequestDate order by guserid ,addate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的订单数量数据 public static List GetPeopleMonthOrderNumList(DateTime sdt, DateTime edt) { var sql = @"select ISNULL(UserId,guserid) UserId, CONVERT(nvarchar(23), ISNULL(RequestDate,OrderDate)) RDate ,ISNULL( OrderNum,0) OrderNum from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(varchar(7), a.OrderDate,120) OrderDate,a.OrderId,muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate group by CONVERT(varchar(7), a.OrderDate,120),a.OrderId,muserid) z group by OrderDate,guserid) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number,@startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.OrderDate=t2.RequestDate order by UserId,RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取每人每月的订单数量数据 public static List GetPeopleMonthOrderNumList(int userid, int platid, DateTime sdt, DateTime edt) { var sql = @" select t2.Date,t1.guserid,t1.OrderNum from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(varchar(7), a.OrderDate,120) OrderDate,a.OrderId, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate)t where ISNULL(t.guserid,0) =@userid group by t.OrderDate,t.guserid ) t1 full join ( SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate) ) t2 on t1.OrderDate=t2.Date order by Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的订单数量数据 public static List GetAllPeopleMonthOrderNumList(int platid, DateTime sdt, DateTime edt) { var sql = @" select CONVERT(nvarchar(23), t2.Date) RDate,t2.guserid UserId,t1.OrderNum from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(varchar(7), a.OrderDate,120) OrderDate,a.OrderId, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate)t group by t.OrderDate,t.guserid ) t1 full join ( select * from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b ) t2 on t1.OrderDate=t2.Date and ISNULL( t1.guserid,0)=ISNULL( t2.guserid,0) order by t2.guserid ,Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的销售额数据 public static List GetPeopleMonthSalePriceList(DateTime sdt, DateTime edt) { var sql = @"select x.guserid as UserId,CONVERT(nvarchar(23), x.Date) as RDate,ISNULL(z.TotalPrice,0) TotalPrice from ( --找到所有运营人员,以及日期做笛卡尔积 select e.guserid,Date from ( select distinct muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) e Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) t where e.guserid in (-1,60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236) ) x left join ( --获取到没人每月的总销售额 select CONVERT(varchar(7), a.OrderDate,120) OrderDate,muserid guserid ,Sum(a.TotalPrice) TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate group by muserid,CONVERT(varchar(7), a.OrderDate,120) )z on x.Date=z.OrderDate and x.guserid=z.guserid order by x.guserid ,Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的销售额数据 public static List GetPeopleMonthSalePriceList(int platid, DateTime sdt, DateTime edt) { var sql = @"select t2.Date RDate,t2.guserid UserId,t1.TotalPrice from ( select z.guserid,z.OrderDate,SUM(ISNULL(z.totalprice,0)) TotalPrice from ( select CONVERT(varchar(7), a.OrderDate,120) OrderDate, a.TotalPrice, Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate) z group by z.OrderDate,z.guserid ) t1 full join ( select * from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b )t2 on ISNULL(t1.guserid,0)=ISNULL(t2.guserid,0) and t1.OrderDate=t2.Date order by t2.guserid,t2.Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的利润数据 public static List GetPeopleMonthLRList(DateTime sdt, DateTime edt) { var sql = @" select ISNULL(t2.UserId,t1.guserid) UserId,Convert(nvarchar(23), ISNULL(t2.RequestDate,t1.OrderDate)) RDate,ISNULL(t1.LR,0) TotalPrice from ( select z1.guserid,z1.OrderDate, ISNULL(z1.LR,0)-ISNULL(z2.AdFee,0) LR from ( --查找到每人每个月没除去广告费的利润 select CONVERT(varchar(7),a.orderdate,120) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,muserid guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>= @startDate and CONVERT(date,z.OrderDate)<= @endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>= @startDate and CONVERT(date,a.OrderDate)<= @endDate group by f.guserid,CONVERT(varchar(7), a.OrderDate,120) ) z1 left join ( --查找到每人每个月的广告花费 select orderdate, t1.muserid, sum(isnull(t2.adfee,0)) AdFee from ( select CONVERT(varchar(7),a1.OrderDate,120) OrderDate, d1.muserid, d1.GoodsId from DT_OrderInfo a1 inner join DT_OrderGoods b1 on a1.OrderId=b1.OrderId inner join HW_GoodsDetail c1 on b1.DetailId=c1.DetailId inner join HW_GoodsInfo d1 on c1.GoodsId=d1.GoodsId where CONVERT(date,a1.OrderDate)>= @startDate and CONVERT(date,a1.OrderDate)<=@endDate and PlatId=2 group by CONVERT(varchar(7),a1.OrderDate,120), d1.muserid,d1.GoodsId ) t1 left join (select CONVERT(varchar(7),DATEADD(day,1,addate),120) AdDate, goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))>= @startDate and CONVERT(date, DATEADD(day,1,addate))<=@endDate group by CONVERT(varchar(7),DATEADD(day,1,addate),120) , goodsid) t2 on t1.GoodsId=t2.goodsid and t1.OrderDate=t2.AdDate group by t1.muserid,OrderDate ) z2 on z1.OrderDate=z2.OrderDate and z1.guserid=z2.muserid ) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.guserid=t2.UserId order by t2.UserId,t2.RequestDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的利润数据 public static List GetPeopleMonthLRList(int platid, DateTime sdt, DateTime edt) { var sql = @" select t2.guserid UserId, t2.Date RDate,ISNULL(t1.LR,0) TotalPrice from ( --查找到每人每个月没除去广告费的利润 select CONVERT(varchar(7),a.orderdate,120) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId, Case when z.PlatId=3 then guserid_ebay when z.PlatId=6 then guserid_wlmart when z.PlatId=15 then guserid_shopify when z.PlatId=18 then guserid_wayfair when z.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=@platid and CONVERT(date,z.OrderDate)>= @startDate and CONVERT(date,z.OrderDate)<= @endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date,a.OrderDate)>= @startDate and CONVERT(date,a.OrderDate)<= @endDate group by f.guserid,CONVERT(varchar(7), a.OrderDate,120) ) t1 full join ( select * from ( select distinct Case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=@platid and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate ) a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b )t2 on t1.OrderDate=t2.Date and ISNULL(t1.guserid,0)=ISNULL(t2.guserid,0) order by t2.guserid,t2.Date "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的广告订单数据 public static List GetPeopleMonthAdOrderNumList(DateTime sdt, DateTime edt) { var sql = @"select CONVERT(nvarchar(23), ISNULL( t2.RequestDate,t1.OrderDate)) RDate,ISNULL( t2.UserId,t1.UserId) UserId,ISNULL( t1.AdOrdersNum,0) OrderNum from ( select CONVERT(varchar(7),OrderDate,120) OrderDate, b.muserid UserId, SUM(Ad_Order_Quantity) AdOrdersNum from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by CONVERT(varchar(7),OrderDate,120), muserid ) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.UserId=t2.UserId order by UserId,RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的广告销售金额数据 public static List GetPeopleMonthAdOrderSalePriceList(DateTime sdt, DateTime edt) { var sql = @"select CONVERT(nvarchar(23), ISNULL( t2.RequestDate,t1.OrderDate)) RDate,ISNULL( t2.UserId,t1.UserId) UserId,ISNULL( t1.AdOrdersAmount,0) TotalPrice from ( select CONVERT(varchar(7),OrderDate,120) OrderDate, b.muserid UserId, SUM(Ad_Order_Amount) AdOrdersAmount from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by CONVERT(varchar(7),OrderDate,120), muserid ) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.UserId=t2.UserId order by UserId,RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取所有人每人每月的广告利润金额数据 public static List GetPeopleMonthAdOrderLRPriceList(DateTime sdt, DateTime edt) { var sql = @"select ISNULL(UserId,guserid) UserId, CONVERT(nvarchar(23), ISNULL(RequestDate,OrderDate)) RDate ,ISNULL( OrderNum,0) OrderNum into #ls_1 from ( select OrderDate,guserid,COUNT(distinct OrderId) OrderNum from ( select CONVERT(varchar(7), a.OrderDate,120) OrderDate,a.OrderId,muserid guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date, a.OrderDate)>= @startDate and CONVERT(date, a.OrderDate)<=@endDate group by CONVERT(varchar(7), a.OrderDate,120),a.OrderId,muserid) z group by OrderDate,guserid) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number,@startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.OrderDate=t2.RequestDate order by UserId,RDate select ISNULL(t2.UserId,t1.guserid) UserId,Convert(nvarchar(23), ISNULL(t2.RequestDate,t1.OrderDate)) RDate,ISNULL(t1.LR,0) TotalPrice into #ls_2 from ( select z1.guserid,z1.OrderDate, ISNULL(z1.LR,0)-ISNULL(z2.AdFee,0) LR from ( --查找到每人每个月没除去广告费的利润 select CONVERT(varchar(7),a.orderdate,120) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,muserid guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>= @startDate and CONVERT(date,z.OrderDate)<= @endDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>= @startDate and CONVERT(date,a.OrderDate)<= @endDate group by f.guserid,CONVERT(varchar(7), a.OrderDate,120) ) z1 left join ( --查找到每人每个月的广告花费 select orderdate, t1.muserid, sum(isnull(t2.adfee,0)) AdFee from ( select CONVERT(varchar(7),a1.OrderDate,120) OrderDate, d1.muserid, d1.GoodsId from DT_OrderInfo a1 inner join DT_OrderGoods b1 on a1.OrderId=b1.OrderId inner join HW_GoodsDetail c1 on b1.DetailId=c1.DetailId inner join HW_GoodsInfo d1 on c1.GoodsId=d1.GoodsId where CONVERT(date,a1.OrderDate)>= @startDate and CONVERT(date,a1.OrderDate)<=@endDate and PlatId=2 group by CONVERT(varchar(7),a1.OrderDate,120), d1.muserid,d1.GoodsId ) t1 left join (select CONVERT(varchar(7),DATEADD(day,1,addate),120) AdDate, goodsid,SUM(adfeenew) adfee from AD_FeeList where CONVERT(date, DATEADD(day,1,addate))>= @startDate and CONVERT(date, DATEADD(day,1,addate))<=@endDate group by CONVERT(varchar(7),DATEADD(day,1,addate),120) , goodsid) t2 on t1.GoodsId=t2.goodsid and t1.OrderDate=t2.AdDate group by t1.muserid,OrderDate ) z2 on z1.OrderDate=z2.OrderDate and z1.guserid=z2.muserid ) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.guserid=t2.UserId order by t2.UserId,t2.RequestDate select CONVERT(nvarchar(23), ISNULL( t2.RequestDate,t1.OrderDate)) RDate,ISNULL( t2.UserId,t1.UserId) UserId,ISNULL( t1.AdOrdersNum,0) OrderNum into #ls_3 from ( select CONVERT(varchar(7),OrderDate,120) OrderDate, b.muserid UserId, SUM(Ad_Order_Quantity) AdOrdersNum from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId =b.GoodsId where CONVERT(date,OrderDate)>=@startDate and CONVERT(date,OrderDate)<=@endDate group by CONVERT(varchar(7),OrderDate,120), muserid ) t1 full join ( select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @startDate ),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @startDate, @endDate)) b where a.UserId in (60, 69, 182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.OrderDate=t2.RequestDate and t1.UserId=t2.UserId order by UserId,RDate select a.UserId,a.RDate,case when ISNULL(a.OrderNum,0)=0 or ISNULL(c.OrderNum,0)=0 then 0 else CONVERT(decimal(12,2), (c.OrderNum*1.00/a.OrderNum)*b.TotalPrice) end TotalPrice from #ls_1 a left join #ls_2 b on a.UserId=b.UserId and a.RDate=b.RDate left join #ls_3 c on a.UserId=c.UserId and a.RDate=c.RDate order by a.UserId,a.RDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt); db.AddInParameter(cmd, "@endDate", DbType.Date, edt); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetGoodsUpFirstList(string mids) { string tsql = @" select ShopId,GoodsId,CONVERT(nvarchar(23),First_Day,120) FirstDay from AmazonShopProductUpFirstDay where goodsid in (" + mids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetGoodsDayImpressionsList(string mids) { string tsql = @" select ShopID,GoodsId,Impressions from AamzonGoodsDayImpressions with(nolock) where RequestDate=CONVERT(date,DATEADD(day,-1,getdate())) and goodsid in (" + mids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取所有shopify平台店铺 public static List GetShopSelectListByPlat(int platid) { string tsql = @" select ShopId,ShopName from JC_Shop where PlatType= " + platid; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取shopify平台店铺所有订单 public static List GetShopifyShopAllOrdersList(DateTime? sdate, DateTime? edate, int shopid, int pageIndex, int pageSize, out int rowCount) { var filt = ""; if (shopid != 0) filt += " and a.shopid=" + shopid; if (sdate.HasValue) filt += " and CONVERT(date,created_at)>='" + sdate.Value.ToString("yyyy-MM-dd") + "'"; if (edate.HasValue) filt += " and CONVERT(date,created_at)<='" + edate.Value.ToString("yyyy-MM-dd") + "'"; string tsql = @" select COUNT(1) count from ShopifyShopsOrders a inner join JC_Shop b on a.shopid=b.shopid left join ShopifyShopsOrders_shipping_lines c on a.shopifyorder_id=c.shopifyorder_id where 1=1 " + filt + "\r\n"; tsql += @"select ShopifyOrder_Id,ShopId,ShopName,CaptureState,CreateDate,OrderName,CustomerName,Currency, TotalPrice,PaymentStatus,FulfillmentStatus,Tags,DeliveryMethod,ItemCount from ( select ROW_NUMBER() over(order by created_at desc) row, a.shopifyorder_id ShopifyOrder_Id,a.shopid ShopId,b.ShopName, case when a.CaptureState=0 then '未抓取' when a.CaptureState=1 then '已抓取' when a.CaptureState=2 then '抓取失败' end CaptureState, CONVERT(nvarchar(120), a.created_at,120) CreateDate,a.name OrderName,a.customer_first_name+a.customer_last_name CustomerName,case when a.subtotal_price_set_shopmoney_currency_code='USD' then '$' end Currency, a.subtotal_price_set_shopmoney_amount TotalPrice,a.financial_status PaymentStatus,a.fulfillment_status FulfillmentStatus,a.tags Tags ,c.code DeliveryMethod ,ItemCount= (select SUM(quantity) from ShopifyShopsOrders_line_items where shopifyorder_id=a.shopifyorder_id) from ShopifyShopsOrders a inner join JC_Shop b on a.shopid=b.shopid left join ShopifyShopsOrders_shipping_lines c on a.shopifyorder_id=c.shopifyorder_id where 1=1 " + filt + ") t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["count"]); List ListModel = ds.Tables[1].ToList(); return ListModel; } #endregion #region 获取shopify平台店铺所有订单商品的图片 public static List GetShopifyShopAllOrdersImageList(string orderids) { //var sql = @"select a.shopifyorder_id, b.FirstImgUrl,a.SKU from ShopifyShopsOrders_line_items a inner join HW_GoodsDetail b on a.sku=b.SKU1 where ISNULL( b.FirstImgUrl,'')<>'' and a.shopifyorder_id in (" + orderids + ")"; var sql = @"select a.shopifyorder_id, b.FirstImgUrl,a.SKU,b.GoodsId, d.ShopName,e.LinkUrl from ShopifyShopsOrders_line_items a inner join HW_GoodsDetail b on a.sku=b.SKU1 inner join ShopifyShopsOrders c on a.shopifyorder_id=c.shopifyorder_id inner join JC_Shop d on c.shopid=d.ShopId left join (select ROW_NUMBER() over(partition by goodsid,linkdesc order by linkid) row ,LinkId,GoodsId,LinkUrl,LinkDesc from HW_BuyLink where ISNULL(LinkDesc,'')<>'' and ISNULL(LinkUrl,'')<>'') e on b.GoodsId=e.GoodsId and d.ShopName=e.LinkDesc and e.row=1 where ISNULL( b.FirstImgUrl,'')<>'' and a.shopifyorder_id in (" + orderids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable ds = db.ExecuteDataTable(cmd); List ListModel = ds.ToList(); return ListModel; } #endregion #region 更新shopify订单抓取状态 public static void UpdateShopifyOrderCaptureState(string shopifyOrderId, int status) { string sql = @" update ShopifyShopsOrders set CaptureState=" + status + " where shopifyorder_id='" + shopifyOrderId + "'"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion #region 获取Shopify订单数据 public static ShopifyShopOneOrderModel GetShopifyOrderModel(string shopifyOrderId) { string sql = @" select shopifyorder_id,shopid,CaptureState,name,created_at from ShopifyShopsOrders where shopifyorder_id='" + shopifyOrderId + "' "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); var model = new ShopifyShopOneOrderModel(); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回列表 public static List GetGoodsLast2DayAdFeeList(string mids) { string tsql = "select shopid,goodsid,SUM(ABS(isnull(adfee,0))) spend from AD_FeeList where CONVERT(date, addate) = CONVERT(date, DATEADD(day,-2,GETDATE())) and GoodsId in (" + mids + ") group by goodsid,shopid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetGoodsLast2DayAdFeeListByOrders(string oids) { string tsql = @"select distinct b.GoodsId into #ls_1 from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b with (nolock) on a.DetailId = b.DetailId where OrderId in (" + oids + ") "; tsql += @" select shopid, t1.goodsid,SUM(ABS(isnull(adfee, 0))) spend from AD_FeeList t1 inner join #ls_1 t2 on t1.goodsid=t2.GoodsId where CONVERT(date, addate) = CONVERT(date, DATEADD(day, -2, GETDATE())) group by t1.goodsid,shopid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetShopGoodDayImpressionsList(string mids) { //string tsql = "select CONVERT(date,RequestDate) RDate,ShopId,GoodsId,SUM(Impressions) Impressions from AamzonGoodsDayImpressions where CONVERT(date,RequestDate)>=CONVERT(date,DATEADD(day,-30,getdate())) and GoodsId in (" + mids + ") group by CONVERT(date,RequestDate),ShopId,GoodsId"; string tsql = @"select t1.Date RDate,t1.ShopId,t1.GoodsId,ISNULL(t2.Impressions,0) Impressions from ( select b.Date,a.ShopId,a.GoodsId from( select ShopId,GoodsId from AamzonGoodsDayImpressions where CONVERT(date,RequestDate)>=CONVERT(date,DATEADD(day,-30,getdate())) group by ShopId,GoodsId ) a Cross Join( SELECT CONVERT(date, DATEADD(DAY, number, DATEADD(day,-30,GETDATE()))) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, DATEADD(day,-30,GETDATE()), DATEADD(day,-1,GETDATE())) ) b )t1 left join ( select CONVERT(date,RequestDate) RDate,ShopId,GoodsId,SUM(Impressions) Impressions from AamzonGoodsDayImpressions where CONVERT(date,RequestDate)>=CONVERT(date,DATEADD(day,-30,getdate())) group by CONVERT(date,RequestDate),ShopId,GoodsId ) t2 on t1.Date=t2.RDate and t1.ShopId=t2.ShopId and t1.GoodsId=t2.GoodsId where t1.GoodsId in (" + mids + ") order by ShopId ,Date"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取SHopify店铺 public static List GetAllShopifyShops() { string tsql = "select ShopId,Appkey AppKey, DeveKey [Password],AccessToken,SendName ShopName from dbo.JC_Shop where PlatType=15 and ISNULL(appkey,'')<>'' and ISNULL(DeveKey,'')<>'' and ISNULL(AccessToken,'')<>''"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 更新SHopify店铺订单 public static void UpdateShopifyShopOrders(string sql) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion #region 获取需要Capture的shopify订单 public static List GetNeedCaptureShopifyOrders() { string tsql = "select a.shopifyorder_id,b.SendName ShopName,b.Appkey,b.DeveKey,b.AccessToken from dbo.ShopifyShopsOrders a left join dbo.JC_Shop b on a.shopid=b.ShopId where CONVERT(date,created_at)>=CONVERT(date,DATEADD(day,-1,getdate())) and CONVERT(date,created_at)<=CONVERT(date,DATEADD(day,-1,getdate())) order by a.created_at desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取个人销售数据页面留言数据 public static List GetPeopleSaleDatasRemarkList() { string tsql = " select PlatId, UserId,UserName,Remark,Categorys,IsGroup from PeopleSaleDatasRemark "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取个人销售数据页面留言数据 public static void UpdatePeopleSaleDataRemark(int userid, int platid, string username, string remark, int isgroup = 0) { string tsql = " if(exists(select 1 from PeopleSaleDatasRemark where UserId=" + userid + " and platid=" + platid + " and IsGroup=" + isgroup + "))\r\n begin\r\n Update PeopleSaleDatasRemark set Remark='" + remark + "' where UserId=" + userid + " and platid=" + platid + " and IsGroup=" + isgroup + " \r\n end\r\nelse\r\n begin\r\n insert into PeopleSaleDatasRemark (UserId,PlatId, UserName,Remark,IsGroup,CreateTime) values(" + userid + "," + platid + ", '" + username + "','" + remark + "'," + isgroup + ",GetDate())\r\n end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 获取个人销售数据页面产品类目数据 public static void UpdatePeopleSaleDataPCategorys(int userid, int platid, string username, string categorys, int isgroup = 0) { string tsql = " if(exists(select 1 from PeopleSaleDatasRemark where UserId=" + userid + " and platid=" + platid + " and IsGroup=" + isgroup + "))\r\n begin\r\n Update PeopleSaleDatasRemark set Categorys='" + categorys + "' where UserId=" + userid + " and platid=" + platid + " and IsGroup=" + isgroup + " \r\n end\r\nelse\r\n begin\r\n insert into PeopleSaleDatasRemark (UserId,PlatId, UserName,Categorys,IsGroup,CreateTime) values(" + userid + "," + platid + ", '" + username + "','" + categorys + "'," + isgroup + ",GetDate())\r\n end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 获取订单商品的大小类排名 public static List GetGoodsRankModelList(string shopids, DateTime? maxDate, DateTime? minDate) { string filt = ""; if (maxDate.HasValue) filt += " and CONVERT(date,OrderDate)>='" + minDate.Value.Date + "'"; if (minDate.HasValue) filt += " and CONVERT(date,OrderDate)<='" + maxDate.Value.Date + "'"; string tsql = " select ShopId,GoodsId,OrderDate,Int2 ,Int3 ,Int10,asin from DD_GoodsCodeData where ShopId in (" + shopids + ")" + filt; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取每个人商品排名区间的数量 public static List GetPeopleGoodsRankCountList(DateTime sdate) { var tsql = @" select t.muserid UserId,t.Name, COUNT(case when ISNULL(SmallRank,0)=1 then 1 end) as Rank1Count, COUNT(CASE WHEN ISNULL(SmallRank,0) BETWEEN 2 AND 10 THEN 1 END) AS Rank2To10Count, COUNT(CASE WHEN ISNULL(SmallRank,0) BETWEEN 11 AND 20 THEN 1 END) AS Rank11To20Count, COUNT(CASE WHEN ISNULL(SmallRank,0) BETWEEN 21 AND 30 THEN 1 END) AS Rank21To30Count, COUNT(CASE WHEN ISNULL(SmallRank,0) BETWEEN 31 AND 40 THEN 1 END) AS Rank31To40Count, COUNT(CASE WHEN ISNULL(SmallRank,0) BETWEEN 41 AND 50 THEN 1 END) AS Rank41To50Count, COUNT(CASE WHEN ISNULL(SmallRank,0) BETWEEN 51 AND 100 THEN 1 END) AS Rank51To100Count, COUNT(CASE WHEN ISNULL(SmallRank,0) >100 THEN 1 END) AS RankOver100Count, COUNT(CASE WHEN ISNULL(SmallRank,0) =0 THEN 1 END) AS NoRankCount from (select a.GoodsId,a.muserid ,c.Name, b.ShopId,b.ASIN,b.BigRank,b.SmallRank from HW_GoodsInfo a inner join AmazonShopGoodsRank b on a.GoodsId=b.GoodsId left join JC_UserInfo c on a.muserid=c.UserId where CONVERT(date,b.Indate)='" + sdate.ToString("yyyy-MM-dd") + "' and muserid is not null) t group by t.muserid,t.Name"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取每个人商品排名详情 public static List GetPeopleGoodsRankDetailList(DateTime sdate, int rangeType, int userid, int PageIndex, int PageSize, out int rowCount) { string filt = ""; switch (rangeType) { case 0: //排名全部 filt += ""; break; case 1: //排名1 filt += " and ISNULL(SmallRank,0)=1"; break; case 2: //排名2-10 filt += " and ISNULL(SmallRank,0)>=2 and ISNULL(SmallRank,0)<=10 "; break; case 3: //排名11-20 filt += " and ISNULL(SmallRank,0)>=11 and ISNULL(SmallRank,0)<=20"; break; case 4: //排名21-30 filt += " and ISNULL(SmallRank,0)>=21 and ISNULL(SmallRank,0)<=30 "; break; case 5: //排名31-40 filt += " and ISNULL(SmallRank,0)>=31 and ISNULL(SmallRank,0)<=40"; break; case 6: //排名41-50 filt += " and ISNULL(SmallRank,0)>=41 and ISNULL(SmallRank,0)<=50"; break; case 7: //排名51-100 filt += " and ISNULL(SmallRank,0)>=51 and ISNULL(SmallRank,0)<=100 "; break; case 8: //排名大于100 filt += " and ISNULL(SmallRank,0)>100"; break; case 9: //无排名 filt += " and ISNULL(SmallRank,0)=0"; break; } var tsql = @"select COUNT(1) Count from HW_GoodsInfo a inner join AmazonShopGoodsRank b on a.GoodsId=b.GoodsId left join HW_GoodsInfo c on a.GoodsId=c.GoodsId left join HW_GoodsDetail d on b.DetailId=d.DetailId left join JC_Shop f on b.ShopId=f.ShopId left join JC_UserInfo g on g.UserId=a.muserid where a.muserid is not null and CONVERT(date,b.InDate)='" + sdate.ToString("yyyy-MM-dd") + "' and a.muserid=" + userid + filt; tsql += @" select Name,ShopName,GoodsCode,SKU,ASIN,BigRank,SmallRank from ( select ROW_NUMBER() over(order by b.SmallRank) row , g.Name,f.ShopName,c.GoodsCode,d.SKU1 SKU,b.ASIN,b.BigRank,b.SmallRank from HW_GoodsInfo a inner join AmazonShopGoodsRank b on a.GoodsId=b.GoodsId left join HW_GoodsInfo c on a.GoodsId=c.GoodsId left join HW_GoodsDetail d on b.DetailId=d.DetailId left join JC_Shop f on b.ShopId=f.ShopId left join JC_UserInfo g on g.UserId=a.muserid where a.muserid is not null and CONVERT(date,b.InDate)='" + sdate.ToString("yyyy-MM-dd") + "' and a.muserid=" + userid + filt + ") t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); List ListModel = ds.Tables[1].ToList(); return ListModel; } #endregion #region 返回除亚马逊平台外其他平台个人每天的销售数据 public static List GetNoAmazonPeopleDaySaleDatasList(DateTime? sdt, DateTime? edt) { var sql = @" --select t.PlatId, t.guserid,COUNT(distinct t.OrderId) OrderNum ,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice Into #ls_1 from ( --select CONVERT(date, a.OrderDate) OrderDate,a.PlatId, a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice, --case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid --from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId --where a.State>0 and a.State<3 and a.PlatId!=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate ) t group by t.PlatId, t.guserid select t.PlatId, t.guserid,COUNT(distinct t.OrderId) OrderNum ,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice Into #ls_1 from ( select ROW_NUMBER() over(partition by z.orderid,z.guserid order by goodsnum) row,z.* from ( select CONVERT(date, a.OrderDate) OrderDate,a.PlatId, a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice, case when a.PlatId=3 then guserid_ebay when a.PlatId=6 then guserid_wlmart when a.PlatId=15 then guserid_shopify when a.PlatId=18 then guserid_wayfair when a.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId!=2 and CONVERT(date, a.OrderDate)>=@startDate and CONVERT(date, a.OrderDate)<=@endDate)z ) t group by t.PlatId, t.guserid select a.PlatId, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR , SUM(ISNULL(c.SubsidyFee,0)) SubsidyFee Into #ls_2 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.PlatId, g.guserid from ( select z.OrderId,x.GoodsId,z.platId, case when z.PlatId=3 then guserid_ebay when z.PlatId=6 then guserid_wlmart when z.PlatId=15 then guserid_shopify when z.PlatId=18 then guserid_wayfair when z.PlatId=21 then guserid_sheIn end guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId!=2 and CONVERT(date,z.OrderDate)>=@startDate and CONVERT(date,z.OrderDate)<=@endDate ) g group by g.OrderId,g.PlatId, g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId!=2 and CONVERT(date,a.OrderDate)>=@startDate and CONVERT(date,a.OrderDate)<= @endDate group by a.PlatId, f.guserid order by a.PlatId select UserId,CONVERT(decimal(12,2), SUM(ISNULL(AdFee, 0))) AdFee, SUM(ISNULL(AdOrderNum, 0)) AdOrdersNum,CONVERT(decimal(12,2), SUM(ISNULL(AdSaleAmount, 0))) AdOrderAmount into #ls_3 from PeopleDayFillSaleData where CONVERT(date,indate)>=@startDate and CONVERT(date,indate)<=@endDate group by UserId select a.PlatId,a.guserid UserId,0 IsGroup, c.Name, a.OrderNum OrdersNum,a.GoodsNum,a.TotalPrice SalePrice,Convert(decimal(12,2),Isnull( b.LR,0)) NetProfit,d.AdFee,d.AdOrdersNum,d.AdOrderAmount,b.SubsidyFee from #ls_1 a full join #ls_2 b on a.PlatId=b.PlatId and ISNULL( a.guserid,0)=ISNULL( b.guserid,0) left join JC_UserInfo c on a.guserid=UserId left join #ls_3 d on a.guserid=d.UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@startDate", DbType.Date, sdt.Value); db.AddInParameter(cmd, "@endDate", DbType.Date, edt.Value); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取每个人商品排名区间的数量和建议采购数量 public static List GetGoodsInNumList(string mids) { var tsql = @" select GoodsId,SUM(isnull( GoodsInNum,0)-ISNULL(BHNum3,0)) GoodsInNum ,SUM(ISNULL(BHNum3,0)) BHNum3, SUM( case when FHPlan=3 then isnull(CGNum,0) when FHPlan=1 then isnull(CGNum2,0) when FHPlan=2 then isnull(CGNum3,0) else isnull(CGNum,0) end) JYCGNum from HW_GoodsDetail where GoodsId in (" + mids + ") group by GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 更新商品方案数 public static void UpdateGoodsPlanCount(int goodsid, int? planCount) { string tsql = " update HW_GoodsInfo set PlanCount=" + (planCount.HasValue ? planCount.Value.ToString() : "null") + " where GoodsId=" + goodsid; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } public static void UpdateGoodsEditPlanCount(int goodsid, int? edplanCount) { string tsql = " update HW_GoodsInfo set EditPlanCount=" + (edplanCount.HasValue ? edplanCount.Value.ToString() : "null") + " where GoodsId=" + goodsid; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 获取产品分类 public static List GetGoodsSortList() { var tsql = @" select SortId, SortName from HW_GoodsSort "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 获取店铺广告花费详情 public static List GetShopAdFeeDetailList(int userid, DateTime? sDate, DateTime? eDate, string shopName, int PageIndex, int PageSize, out int rowCount) { //var tsql = @" select COUNT(1) as count from AD_FeeList a left join HW_GoodsInfo b on a.goodsid=b.GoodsId where isnull(a.goodscode,'')<>'' and addate=@sDate and shopname=@shopName // select GoodsCode,GoodsName,DetailId, AdFee,UserId,UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum from ( // select ROW_NUMBER() over(order by a.adfee desc) row, a.goodscode GoodsCode,b.GoodsName,a.DetailId,AdFee,b.muserid UserId,c.Name UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum from ( // select goodscode,detailid,goodsid, SUM(ABS(isnull(adfee,0))) AdFee,SUM(ISNULL(SaleAmount,0)) SaleAmount,SUM(ISNULL(OrderNum,0)) OrderNum,SUM(ISNULL(Ad_SaleAmount,0)) Ad_SaleAmount,SUM(ISNULL(Ad_OrderNum,0)) Ad_OrderNum from AD_FeeList // where ISNULL(goodscode,'')<>'' and addate>=@sDate and addate<=@eDate and shopname=@shopName group by goodscode,detailid,goodsid ) a // left join HW_GoodsInfo b on a.goodsid=b.GoodsId left join JC_UserInfo c on b.muserid=c.UserId ) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + (PageIndex * PageSize); var filt = ""; filt = userid == 0 ? "" : " and b.muserid=" + userid; var tsql = @" select COUNT(1) as count from (select b.GoodsId from AD_FeeList a inner join HW_GoodsInfo b on a.goodscode=b.GoodsCode where ISNULL(a.goodscode,'')<>'' and addate>=@sDate and addate<=@eDate and shopname=@shopName " + filt + " group by a.goodscode,b.goodsid)t"; tsql += @" select GoodsId, GoodsCode,GoodsName, AdFee,UserId,UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum from ( select ROW_NUMBER() over(order by a.adfee desc) row,b.GoodsId, a.goodscode GoodsCode,b.GoodsName,AdFee,b.muserid UserId,c.Name UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum from ( select a.goodscode,b.goodsid, SUM(ABS(isnull(adfee,0))) AdFee,SUM(ISNULL(SaleAmount,0)) SaleAmount,SUM(ISNULL(OrderNum,0)) OrderNum,SUM(ISNULL(Ad_SaleAmount,0)) Ad_SaleAmount,SUM(ISNULL(Ad_OrderNum,0)) Ad_OrderNum from AD_FeeList a inner join HW_GoodsInfo b on a.goodscode=b.GoodsCode where ISNULL(a.goodscode,'')<>'' and addate>=@sDate and addate<=@eDate and shopname=@shopName " + filt + " group by a.goodscode,b.goodsid ) a left join HW_GoodsInfo b on a.goodsid=b.GoodsId left join JC_UserInfo c on b.muserid=c.UserId ) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + (PageIndex * PageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate); db.AddInParameter(cmd, "@shopName", DbType.String, shopName); DataSet dst = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(dst.Tables[0].Rows[0]["count"]); List ListModel = dst.Tables[1].ToList(); return ListModel; } #endregion #region 获取店铺广告花费详情汇总 public static ShopAdFeeDetailModel GetShopAdFeeDetailTotal(int userid, DateTime? sDate, DateTime? eDate, string shopName) { var tsql = @" select SUM( ABS(ISNULL( a.adfee,0))) AdFee ,SUM( ISNULL(a.SaleAmount,0)) SaleAmount,SUM( ISNULL(a.OrderNum,0)) OrderNum,SUM(ISNULL(a.AD_SaleAmount,0)) Ad_SaleAmount,SUM(ISNULL(a.Ad_OrderNum,0)) Ad_OrderNum from AD_FeeList a Inner join HW_GoodsInfo b on a.goodsid=b.GoodsId where isnull(a.goodscode,'')<>'' and addate>=@sDate and addate<=@eDate and shopname=@shopName " + (userid == 0 ? "" : " and muserid=" + userid); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate); db.AddInParameter(cmd, "@shopName", DbType.String, shopName); DataTable dt = db.ExecuteDataTable(cmd); var rmodel = new ShopAdFeeDetailModel(); rmodel.GoodsCode = "汇总"; rmodel.AdFee = Convert.ToDecimal(dt.Rows[0]["AdFee"]); rmodel.OrderNum = Convert.ToInt32(dt.Rows[0]["OrderNum"]); rmodel.SaleAmount = Convert.ToDecimal(dt.Rows[0]["SaleAmount"]); rmodel.Ad_OrderNum = Convert.ToInt32(dt.Rows[0]["Ad_OrderNum"]); rmodel.Ad_SaleAmount = Convert.ToDecimal(dt.Rows[0]["Ad_SaleAmount"]); return rmodel; } #endregion #region 获取店铺商品订单利润数据 public static List GetShopGoodsLRDataList(int userid, DateTime? sDate, DateTime? eDate, string shopName) { // var sql = @" //select t.DetailId,SUM( Convert(decimal(12,2), //ISNULL(a.TotalPrice,0)-ISNULL(c.yj,0)-ISNULL(a.escrowFee,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- //(case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0))) LR //from ( //SELECT a.OrderId,b.DetailId FROM DT_OrderInfo A LEFT JOIN DT_OrderGoods B ON A.OrderId=B.OrderId WHERE CONVERT(date,DATEADD(hour,-15,a.OrderDate))>=@sDate and CONVERT(date,DATEADD(hour,-15,a.OrderDate))<=@eDate and ShopId=(select top 1 ShopId from JC_Shop where ShopName=@shopName) AND A.PlatId=2 group by a.OrderId,b.DetailId) t //inner join DT_OrderInfo a on t.OrderId=a.OrderId //left join DT_Fees c on a.OrderId=c.orderid //left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId group by DetailId"; var filt = ""; filt = userid == 0 ? "" : " and muserid=" + userid; var sql = @"select t.GoodsId,SUM( Convert(decimal(12,2), ISNULL(a.TotalPrice,0)-ISNULL(c.yj,0)-ISNULL(a.escrowFee,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0))) LR from ( SELECT a.OrderId,c.GoodsId FROM DT_OrderInfo A inner JOIN DT_OrderGoods B ON A.OrderId=B.OrderId inner join HW_GoodsDetail c on b.DetailId =c.DetailId inner join HW_GoodsInfo d on d.goodsid=c.goodsid WHERE CONVERT(date,DATEADD(hour,-15,a.OrderDate))>=@sDate and CONVERT(date,DATEADD(hour,-15,a.OrderDate))<=@eDate " + filt + " and ShopId=(select top 1 ShopId from JC_Shop where ShopName=@shopName) AND A.PlatId=2 group by a.OrderId,c.GoodsId) t "; sql += " inner join DT_OrderInfo a on t.OrderId=a.OrderId left join DT_Fees c on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId group by GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate); db.AddInParameter(cmd, "@shopName", DbType.String, shopName); DataTable dt = db.ExecuteDataTable(cmd); var datas = dt.ToList(); return datas; } #endregion #region 获取个人每天的H净利润 public static List GetPeopleDayHJLRList(DateTime sdate, DateTime edate) { var tsql = @" --广告费 select AdDate, guserid,SUM(adfee) adfee into #ls_1 from ( select ISNULL( addate,RequestDate) AdDate, ISNULL(guserid,UserId) guserid,adfee from ( select t.addate,t.guserid,ABS(SUM(t.adfee)) adfee from ( select a.shopid,a.goodsid,CONVERT(date, addate) addate, adfee, b.PlatType,muserid guserid from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where b.PlatType=2 and CONVERT(date, a.addate)>=@sDate and CONVERT(date, a.addate)<=@eDate) t group by t.addate,t.guserid) t1 full join (select a.UserId,b.Date as RequestDate from JC_UserInfo a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.UserId in (60, 69,182, 190, 200, 213, 216, 221,204, 205, 206, 207, 208, 209, 210, 212, 215, 222,229,230,231,232,233,234,235,236)) t2 on t1.guserid=t2.UserId and t1.addate=t2.RequestDate ) t group by AdDate, guserid --利润 select CONVERT(date,a.orderdate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR into #ls_2 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.guserid from ( select z.OrderId,x.GoodsId,muserid guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate) g group by g.OrderId,g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate group by CONVERT(date, a.OrderDate), f.guserid --仓储费 select CONVERT(date, a.InDate) InDate, muserid UserId,SUM(StockSolidNum)*0.5 TotalSolidFee into #ls_3 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date,a.InDate)>=@sDate and CONVERT(date,a.indate)<=@eDate group by CONVERT(date, a.InDate), muserid select convert(nvarchar(120) ,a.AdDate) RDate,isnull(a.guserid ,0) UserId,HJLR= ISNULL(b.LR,0)-ISNULL(a.adfee,0)-ISNULL(c.TotalSolidFee,0) from #ls_1 a left join #ls_2 b on a.AdDate=b.OrderDate and a.guserid=b.guserid left join #ls_3 c on a.AdDate=c.InDate and a.guserid=c.UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate); db.AddInParameter(cmd, "@eDate", DbType.Date, edate); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region /// /// 获取未确认数量 /// /// /// /// public static int GetCancelCGPlanNoQueRen(string detailids) { var sql = @"select COUNT(1) Count from HW_GoodsDetail where FHPlan !=1 and DetailId in (" + detailids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable tb = db.ExecuteDataTable(cmd); int count = Convert.ToInt32(tb.Rows[0][0]); return count; } public static void CancelCGPlan(string detailids, int year) { var sql = @" update HW_GoodsDetail set FHPlan=null where DetailId in (" + detailids + ") delete from HW_GoodsBFPlan where id in (select t.id from ( select ROW_NUMBER() over(order by weekno desc) row,id from HW_GoodsBFPlan where sjout=0 and year=" + year + " and detailid in (" + detailids + ") ) t where t.row=1) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion #region 获取店铺广告花费详情 public static List GetShopAdAnalysisDetailList(DateTime? sDate, DateTime? eDate, int shopid, int userid, int PageIndex, int PageSize, out int rowCount) { string fitStr = ""; if (shopid != 0) fitStr += " and shopid=" + shopid; if (userid != 0) fitStr += " and muserid=" + userid; var tsql = @"select ShopName,shopid, GoodsId, GoodsCode,GoodsName, AdFee,UserId,UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum into #ls1 from ( select ROW_NUMBER() over(order by a.adfee desc) row,a.shopid,d.ShopName, b.GoodsId, a.goodscode GoodsCode,b.GoodsName,AdFee,b.muserid UserId,c.Name UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum from ( select a.goodscode,b.goodsid,a.shopid, SUM(ABS(isnull(adfee,0))) AdFee,SUM(ISNULL(SaleAmount,0)) SaleAmount,SUM(ISNULL(OrderNum,0)) OrderNum,SUM(ISNULL(Ad_SaleAmount,0)) Ad_SaleAmount,SUM(ISNULL(Ad_OrderNum,0)) Ad_OrderNum from AD_FeeList a inner join HW_GoodsInfo b on a.goodscode=b.GoodsCode where ISNULL(a.goodscode,'')<>'' and addate>=@sDate and addate<=@eDate " + fitStr + " group by a.goodscode,b.goodsid,shopid)a left join HW_GoodsInfo b on a.goodsid=b.GoodsId left join JC_UserInfo c on b.muserid=c.UserId left join JC_Shop d on a.shopid=d.ShopId) t "; tsql += @" select t.ShopId, t.GoodsId,SUM( Convert(decimal(12,2), ISNULL(a.TotalPrice,0)-ISNULL(c.yj,0)-ISNULL(a.escrowFee,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0))) LR into #ls2 from ( SELECT a.ShopId, a.OrderId,c.GoodsId FROM DT_OrderInfo A inner JOIN DT_OrderGoods B ON A.OrderId=B.OrderId inner join HW_GoodsDetail c on b.DetailId =c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId WHERE CONVERT(date,DATEADD(hour,-15,a.OrderDate))>=@sDate and CONVERT(date,DATEADD(hour,-15,a.OrderDate))<=@eDate AND A.PlatId=2 " + fitStr + " group by a.OrderId,c.GoodsId,a.ShopId) t "; tsql += @" inner join DT_OrderInfo a on t.OrderId=a.OrderId left join DT_Fees c on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId group by t.ShopId, GoodsId select COUNT(1) count from #ls1 select ShopName,GoodsId,GoodsCode,GoodsName,AdFee,UserId,UserName,SaleAmount,OrderNum,Ad_SaleAmount,Ad_OrderNum,CPLR,TCB from ( select ROW_NUMBER() over(order by a.AdFee desc) row, a.ShopName,a.GoodsId,a.GoodsCode,a.GoodsName,a.AdFee,a.UserId,a.UserName,a.SaleAmount,a.OrderNum,a.Ad_SaleAmount,a.Ad_OrderNum, ISNULL(b.LR,0)-a.AdFee CPLR, convert(decimal(12,2) , (ISNULL(b.LR,0)-a.AdFee)*100/a.AdFee) TCB from #ls1 a left join #ls2 b on a.shopid=b.shopid and a.GoodsId=b.GoodsId where ISNULL(b.LR,0)-a.AdFee<0) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + (PageIndex * PageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate); DataSet dst = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(dst.Tables[0].Rows[0]["count"]); List ListModel = dst.Tables[1].ToList(); return ListModel; } #endregion #region 获取店铺索赔Case public static List GetShopClaimCaseList(DateTime? sDate, DateTime? eDate, int? shopid, int searchType, string searchTxt, int PageIndex, int PageSize, out int rowCount) { var filt = " 1=1 "; if (sDate.HasValue) filt += " and CONVERT(date, a.SPDate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "'"; if (eDate.HasValue) filt += " and CONVERT(date, a.SPDate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "'"; if (shopid.HasValue && shopid != 0) { filt += " and b.ShopId=" + shopid; } if (!string.IsNullOrEmpty(searchTxt)) { switch (searchType) { case 0: filt += " and a.OrderCode like '%" + searchTxt + "%'"; break; case 1: filt += " and a.GoodsCodes like '%" + searchTxt + "%'"; break; case 2: filt += " and a.SPDetail like '%" + searchTxt + "%'"; break; case 3: filt += " and a.ContactAmazon like '%" + searchTxt + "%'"; break; case 4: filt += " and a.ContactCustomer like '%" + searchTxt + "%'"; break; case 5: filt += " and a.Remark like '%" + searchTxt + "%'"; break; } } var sql = @"select COUNT(1) as count from ShopClaimCase a left join DT_OrderInfo b on a.OrderCode=b.OrderCode left join JC_Shop c on b.ShopId=c.ShopId where " + filt; sql += @" select ID,ShopId,ShopName,PlatType,OrderCode,SPDate,IsAffectODR,GoodsCodes,GoodPrice,SPDetail,ContactAmazon,RefundCustomerPrice,ContactCustomer,Remark from ( select ROW_NUMBER() over(order by a.CreateTime desc) row, a.ID, c.ShopId,c.ShopName,c.PlatType, a.OrderCode,CONVERT(nvarchar(20), SPDate,23) SPDate,case when IsAffectODR=1 then '是' else '否' end IsAffectODR,GoodsCodes,GoodPrice,SPDetail,ContactAmazon,RefundCustomerPrice,ContactCustomer,Remark from ShopClaimCase a left join DT_OrderInfo b on a.OrderCode=b.OrderCode left join JC_Shop c on b.ShopId=c.ShopId where " + filt + ") t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + (PageIndex * PageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet dst = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(dst.Tables[0].Rows[0]["count"]); List ListModel = dst.Tables[1].ToList(); return ListModel; } #endregion #region 获取店铺索赔Case public static ShopClaimCaseGoodsUserImg GetShopClaimCaseUserImg(int plat, string sku) { var sql = @"select top 1 t1.UserId,t2.Name UserName,t1.FirstImgUrl from ( select case when @plat=2 then muserid when @plat=3 then guserid_ebay when @plat=6 then guserid_wlmart when @plat=15 then guserid_shopify when @plat=18 then guserid_wayfair when @plat=21 then guserid_sheIn end UserId,a.FirstImgUrl from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where SKU1=@sku ) t1 left join JC_UserInfo t2 on t1.UserId=t2.UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@plat", DbType.Int32, plat); db.AddInParameter(cmd, "@sku", DbType.String, sku); DataTable dt = db.ExecuteDataTable(cmd); ShopClaimCaseGoodsUserImg ListModel = dt.Rows[0].ToModel(); return ListModel; } #endregion #region 保存店铺索赔Case数据 public static int SaveShopClaimCaseData(ShopClaimCaseData Model) { var tsql = ""; if (Model.ID == null || Model.ID == 0) { tsql += " insert into ShopClaimCase(OrderCode,SPDate,IsAffectODR,GoodsCodes,GoodPrice,SPDetail,ContactAmazon,RefundCustomerPrice,ContactCustomer,Remark,CreateTime) values(@OrderCode,@SPDate,@IsAffectODR,@GoodsCodes,@GoodPrice,@SPDetail,@ContactAmazon,@RefundCustomerPrice,@ContactCustomer,@Remark,GETDATE()) select SCOPE_IDENTITY()"; } else { tsql += " update ShopClaimCase set OrderCode=@OrderCode,SPDate=@SPDate,IsAffectODR=@IsAffectODR,GoodsCodes=@GoodsCodes,GoodPrice=@GoodPrice,SPDetail=@SPDetail,ContactAmazon=@ContactAmazon,RefundCustomerPrice=@RefundCustomerPrice,ContactCustomer=@ContactCustomer,Remark=@Remark where ID=" + Model.ID + " select " + Model.ID; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode.Trim()); db.AddInParameter(cmd, "@SPDate", DbType.DateTime, Model.SPDate); db.AddInParameter(cmd, "@IsAffectODR", DbType.Int32, Model.IsAffectODR); db.AddInParameter(cmd, "@GoodsCodes", DbType.String, Model.GoodsCodes); db.AddInParameter(cmd, "@GoodPrice", DbType.Decimal, Model.GoodPrice); db.AddInParameter(cmd, "@SPDetail", DbType.String, Model.SPDetail); db.AddInParameter(cmd, "@ContactAmazon", DbType.String, Model.ContactAmazon); db.AddInParameter(cmd, "@RefundCustomerPrice", DbType.Decimal, Model.RefundCustomerPrice); db.AddInParameter(cmd, "@ContactCustomer", DbType.String, Model.ContactCustomer); db.AddInParameter(cmd, "@Remark", DbType.String, Model.Remark); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除店铺索赔Case数据 public static void DeleteShopClaimCaseData(int id) { string tsql = @" delete from ShopClaimCase where ID=@id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion public static int GetDepartIdByUserid(int userid) { var sql = "select DeptId from JC_UserInfo where UserId=@UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@UserId", DbType.Int32, userid); DataTable dt = db.ExecuteDataTable(cmd); int deptid = Convert.ToInt32(dt.Rows[0][0]); return deptid; } #region 获取店铺的邮箱数据 public static List GetShopEmailsByShopId(int shopid) { var sql = "select ID,EmailAccount from ShopEmails where ShopId=@shopid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取店铺的邮件列表数据 public static List GetShopEmailsItemListDatas(int shopid, string emailCode, int pageSize, int pageIndex) { var sql = " select ID,ShopId,IsRead,case when DATEDIFF(day, EmailCNTime,getdate())>0 then CONVERT(varchar(5),EmailCNTime,101) else CONVERT(varchar(5),EmailCNTime,108) end EmailCNTime,FromAccount,Subject,EmailContent,OrderCode from (\r\nselect ROW_NUMBER() over( order by IsRead asc, EmailCNTime desc) row, ID,ShopId, IsRead,EmailCNTime,FromAccount,Subject,EmailContent,OrderCode from (\r\nselect ROW_NUMBER() over(partition by FromAccount order by IsRead asc, EmailCNTime desc) row,* from ShopEmailDatas where Shopid=" + shopid + " and ToAccount like '%" + emailCode + "%' and FromAccount like '%@marketplace.amazon.com%') t where t.row=1 ) t2 where t2.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取店铺的发件箱邮件列表数据 public static List GetShopSendEmailsItemListDatas(int shopid, string emailCode, int pageSize, int pageIndex) { var sql = " select ID,ShopId,IsRead,case when DATEDIFF(day, EmailCNTime,getdate())>0 then CONVERT(varchar(5),EmailCNTime,101) else CONVERT(varchar(5),EmailCNTime,108) end EmailCNTime,ToAccount as FromAccount ,Subject,EmailContent,OrderCode from (\r\nselect ROW_NUMBER() over(order by emailCNTime desc) row,ID,ShopId,IsRead,EmailCNTime,ToAccount ,Subject,EmailContent,OrderCode from ShopEmailDatas where Shopid=" + shopid + " and EmailType=1 and FromAccount like '%" + emailCode + "%') t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取店铺的收件箱邮件列表数据 public static List GetShopGetEmailsItemListDatas(int shopid, string emailCode, int pageSize, int pageIndex) { var sql = " select ID,ShopId,IsRead,case when DATEDIFF(day, EmailCNTime,getdate())>0 then CONVERT(varchar(5),EmailCNTime,101) else CONVERT(varchar(5),EmailCNTime,108) end EmailCNTime,FromAccount ,Subject,EmailContent,OrderCode from (\r\nselect ROW_NUMBER() over(order by emailCNTime desc) row,ID,ShopId,IsRead,EmailCNTime,FromAccount ,Subject,EmailContent,OrderCode from ShopEmailDatas where Shopid=" + shopid + " and EmailType=0 and ToAccount like '%" + emailCode + "%') t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取站内信数据 public static List GetShopZNXListDatas(int shopid, string emailCode, string customerEmail, int pageSize, int pageIndex) { var sql = " select ID,EmailCNTime, EmailContent ,EmailType from (\r\nselect ROW_NUMBER() over(order by EmailCNTime desc) row,ID,CONVERT(nvarchar(100),EmailCNTime,120) EmailCNTime,EmailContent EmailContent,EmailType from ShopEmailDatas where Shopid=" + shopid + " and (FromAccount like '%" + emailCode + "%' and ToAccount like '%" + customerEmail + "%') or (FromAccount like '%" + customerEmail + "%' and ToAccount like '%" + emailCode + "%') \r\n) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); List ListModel = dt.ToList(); return ListModel; } #endregion #region 获取店铺信息 public static JC_Shop GetShopInfoByShopid(int shopid) { var sql = " select top 1 * from JC_Shop where ShopId=@shopid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); DataTable dt = db.ExecuteDataTable(cmd); JC_Shop ListModel = dt.Rows[0].ToModel(); return ListModel; } #endregion #region public static void InsertShopEmailData(string sellerEmail, string customerEmail, int shopid, string orderid, string content) { var sql = @" insert into ShopEmailDatas (ShopId,IsRead,EmailCNTime,FromAccount,ToAccount,Importance,TextBody,CreateTime,EmailType,EmailContent,OrderCode) values(" + shopid + ",1,getdate(),'" + sellerEmail + "','" + customerEmail + "','Normal','" + content + "',getdate(),1,'" + content + "','" + orderid + "')"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion #region 获取人员每天填写的销售数据 public static List GetPeopleDayFillSaleDataList(int UserId, DateTime? SDate, DateTime? EDate, int PageIndex, int PageSize, out int rowCount) { string filt = " where 1=1 "; if (UserId != 0) filt += " and a.UserId=" + UserId; if (SDate.HasValue) filt += " and Convert(date, a.InDate)>='" + SDate.Value.Date + "'"; if (EDate.HasValue) filt += " and Convert(date,a.InDate)<='" + EDate.Value.Date + "'"; var sql = @" select COUNT(1) as count from PeopleDayFillSaleData a " + filt; sql += " select ID,UserId,UserName,InDate,AdFee,TCB,AdOrderNum,AdSaleAmount from (select Row_Number() over (order by a.ID desc) row,a.ID,a.UserId,b.Name UserName, a.InDate,AdFee,TCB,AdOrderNum,AdSaleAmount from PeopleDayFillSaleData a left join jc_UserInfo b on a.UserId=b.UserId " + filt + ") t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion #region 新增人员每天填写的销售数据 public static void InsertPeopleDayFillSaleDataList(int? ID, int UserId, DateTime? InDate, decimal? AdFee, decimal? TCB, int? AdOrderNum, decimal? AdSaleAmount) { var sql = ""; if (!ID.HasValue || ID == 0) { sql = " Insert into PeopleDayFillSaleData(UserId,InDate,AdFee,TCB,AdOrderNum,AdSaleAmount,CreateTime) Values(@UserId,@InDate,@AdFee,@TCB,@AdOrderNum,@AdSaleAmount,Getdate()) "; } else { sql = " Update PeopleDayFillSaleData set UserId=@UserId,InDate=@Indate,AdFee=@AdFee,TCB=@TCB,AdOrderNum=@AdOrderNum,AdSaleAmount=@AdSaleAmount where ID=@ID "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@Indate", DbType.DateTime, InDate); db.AddInParameter(cmd, "@AdFee", DbType.Decimal, AdFee); db.AddInParameter(cmd, "@TCB", DbType.Decimal, TCB); db.AddInParameter(cmd, "@AdOrderNum", DbType.Int32, AdOrderNum); db.AddInParameter(cmd, "@AdSaleAmount", DbType.Decimal, AdSaleAmount); db.ExecuteNonQuery(cmd); } #endregion #region 删除人员每天填写的销售数据 public static void DeletePeopleDayFillSaleDataList(int ID) { var sql = " Delete from PeopleDayFillSaleData where ID=@ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } #endregion #region 获取EBAY平台的每个人的仓储费 public static List GetEbayPeopleDayStockSolidFeeDatas(DateTime? sDate, DateTime? eDate) { var filt = " "; if (sDate.HasValue) filt += " and Convert(date,b.Indate)>='" + sDate.Value.Date + "'"; if (eDate.HasValue) filt += " and Convert(date,b.Indate)<='" + eDate.Value.Date + "'"; var sql = "select t.UserId,CONVERT(decimal(12,2), SUM(StockSolidNum)*0.5) as DayTotalSolidFee from (\r\nselect a.guserid_ebay UserId, case when Isnull(StockNum,0)=0 then 0 when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_ebay is not null " + filt + ") t group by userid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Walmart平台的每个人的仓储费 public static List GetWalmartPeopleDayStockSolidFeeDatas(DateTime? sDate, DateTime? eDate) { var filt = " "; if (sDate.HasValue) filt += " and Convert(date,b.Indate)>='" + sDate.Value.Date + "'"; if (eDate.HasValue) filt += " and Convert(date,b.Indate)<='" + eDate.Value.Date + "'"; var sql = " select a.guserid_wlmart UserId,CONVERT(decimal(12,2), SUM(ISNULL(b.StockSolidNum ,0))*0.5*0.05) DayTotalSolidFee from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wlmart is not null " + filt + " group by a.guserid_wlmart"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Wayfair平台的每个人的仓储费 public static List GetWayfairPeopleDayStockSolidFeeDatas(DateTime? sDate, DateTime? eDate) { var filt = " "; if (sDate.HasValue) filt += " and Convert(date,b.Indate)>='" + sDate.Value.Date + "'"; if (eDate.HasValue) filt += " and Convert(date,b.Indate)<='" + eDate.Value.Date + "'"; var sql = " select a.guserid_wayfair UserId,CONVERT(decimal(12,2), SUM(ISNULL(b.StockSolidNum ,0))*0.5*0.05) DayTotalSolidFee from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wayfair is not null " + filt + " group by a.guserid_wayfair"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取个人填写的销售数据 public static PeopleDayFillSaleDataModel GetPeopleDayFillSaleDataModel(int UserId, DateTime? sDate, DateTime? eDate) { var filt = " "; if (sDate.HasValue) filt += " and Convert(date,Indate)>='" + sDate.Value.Date + "'"; if (eDate.HasValue) filt += " and Convert(date,Indate)<='" + eDate.Value.Date + "'"; var sql = " select CONVERT(decimal(12,2),SUM(isnull(AdFee,0))) AdFee,CONVERT(decimal(12,2),SUM(isnull(AdSaleAmount,0))) AdSaleAmount,SUM(ISNULL(AdOrderNum,0)) AdOrderNum from PeopleDayFillSaleData where UserId=" + UserId + filt + " group by UserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataTable dt = db.ExecuteDataTable(cmd); if (dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region 获取ebay店铺总的广告费 public static decimal GetEbayPeopleDayTotalAdfee(string userids, DateTime? sDate, DateTime? eDate) { var sql = " select SUM(ISNULL(adfee,0)) Adfee from PeopleDayFillSaleData where UserId in (" + userids + ") and CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Value.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Value.Date); DataTable dt = db.ExecuteDataTable(cmd); return string.IsNullOrEmpty(dt.Rows[0]["Adfee"].ToString()) ? 0 : Convert.ToDecimal(dt.Rows[0]["Adfee"]); } #endregion #region 获取Ebay平台的净利润数据 public static List GetEbayPeopleHJLRDataList(DateTime sDate, DateTime eDate) { var sql = @" --订单利润 select CONVERT(date,a.OrderDate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR ,SUM(ISNULL(c.SubsidyFee,0)) SubsidyFee into #ls_1 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.PlatId, g.guserid from ( select z.OrderId,x.GoodsId,z.platId, guserid_ebay guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=3 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate ) g group by g.OrderId,g.PlatId, g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=3 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.PlatId, f.guserid ,CONVERT(date,a.OrderDate) order by a.PlatId --广告费 select Userid, CONVERT(date,InDate) InDate, SUM(ISNULL( adfee,0)) adfee into #ls_2 from PeopleDayFillSaleData where CONVERT(date,Indate)>=@sDate and CONVERT(date,Indate)<=@eDate group by CONVERT(date,Indate),UserId --仓储费 select t.InDate, t.UserId,CONVERT(decimal(12,2), SUM(StockSolidNum)*0.5) as DayTotalSolidFee into #ls_3 from (select CONVERT(date ,b.InDate) InDate, a.guserid_ebay UserId, case when ISNULL(StockNum,0)=0 then 0 when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_ebay is not null and Convert(date,b.Indate)>=@sDate and Convert(date,b.Indate)<=@eDate) t group by userid,InDate --李妍填写的广告费,需要平均分成三份加到下属三个员工 select CONVERT(date,InDate) InDate, CONVERT (decimal(12,2), SUM(ISNULL( adfee,0))/3) adfee into #ls_4 from PeopleDayFillSaleData where CONVERT(date,Indate)>=@sDate and CONVERT(date,Indate)<=@eDate and UserId=114 group by CONVERT(date,Indate),UserId select convert(nvarchar(100), a.OrderDate,23) RDate,isnull( a.guserid,0) UserId,ISNULL(a.LR,0)-ISNULL(b.adfee,0)-ISNULL(c.DayTotalSolidFee,0)-ISNULL(d.adfee,0) HJLR,a.LR ,isnull( b.adfee,0)+ISNULL( d.adfee,0) Adfee,c.DayTotalSolidFee,a.SubsidyFee from #ls_1 a left join #ls_2 b on a.OrderDate=b.InDate and a.guserid=b.userid left join #ls_3 c on a.OrderDate=c.Indate and a.guserid=c.UserId left join #ls_4 d on a.OrderDate=d.InDate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Walmart平台的净利润数据 public static List GetWalmartPeopleHJLRDataList(DateTime sDate, DateTime eDate) { var sql = @" --订单利润 select CONVERT(date,a.OrderDate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR into #ls_1 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.PlatId, g.guserid from ( select z.OrderId,x.GoodsId,z.platId, guserid_wlmart guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=6 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate ) g group by g.OrderId,g.PlatId, g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=6 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.PlatId, f.guserid ,CONVERT(date,a.OrderDate) order by a.PlatId --广告费 select Userid, CONVERT(date,InDate) InDate, SUM(ISNULL( adfee,0)) adfee into #ls_2 from PeopleDayFillSaleData where CONVERT(date,Indate)>=@sDate and CONVERT(date,Indate)<=@eDate group by CONVERT(date,Indate),UserId --仓储费 select a.guserid_wlmart UserId, CONVERT(date,b.indate) Indate, CONVERT(decimal(12,2), SUM(ISNULL(b.StockSolidNum ,0))*0.5*0.05) DayTotalSolidFee into #ls_3 from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wlmart is not null and CONVERT(date, b.InDate)>=@sDate and Convert(date,b.Indate)<=@eDate group by a.guserid_wlmart,CONVERT(date,b.InDate) select convert(nvarchar(100), a.OrderDate,23) RDate,isnull( a.guserid,0) UserId,ISNULL(a.LR,0)-ISNULL(b.adfee,0)-ISNULL(c.DayTotalSolidFee,0) HJLR from #ls_1 a left join #ls_2 b on a.OrderDate=b.InDate and a.guserid=b.userid left join #ls_3 c on a.OrderDate=c.Indate and a.guserid=c.UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Wayfair平台的净利润数据 public static List GetWayfairPeopleHJLRDataList(DateTime sDate, DateTime eDate) { var sql = @" --订单利润 select CONVERT(date,a.OrderDate) OrderDate, f.guserid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR into #ls_1 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join (select g.OrderId,g.PlatId, g.guserid from ( select z.OrderId,x.GoodsId,z.platId, guserid_wayfair guserid from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=18 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate ) g group by g.OrderId,g.PlatId, g.guserid) f on a.OrderId=f.OrderId where a.State>0 and a.State<3 and a.PlatId=18 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.PlatId, f.guserid ,CONVERT(date,a.OrderDate) order by a.PlatId --广告费 select Userid, CONVERT(date,InDate) InDate, SUM(ISNULL( adfee,0)) adfee into #ls_2 from PeopleDayFillSaleData where CONVERT(date,Indate)>=@sDate and CONVERT(date,Indate)<=@eDate group by CONVERT(date,Indate),UserId --仓储费 select a.guserid_wayfair UserId, CONVERT(date,b.indate) Indate, CONVERT(decimal(12,2), SUM(ISNULL(b.StockSolidNum ,0))*0.5*0.05) DayTotalSolidFee into #ls_3 from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wayfair is not null and CONVERT(date, b.InDate)>=@sDate and Convert(date,b.Indate)<=@eDate group by a.guserid_wayfair,CONVERT(date,b.InDate) select convert(nvarchar(100), a.OrderDate,23) RDate,isnull( a.guserid,0) UserId,ISNULL(a.LR,0)-ISNULL(b.adfee,0)-ISNULL(c.DayTotalSolidFee,0) HJLR from #ls_1 a left join #ls_2 b on a.OrderDate=b.InDate and a.guserid=b.userid left join #ls_3 c on a.OrderDate=c.Indate and a.guserid=c.UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shopify平台每个店铺的销售数据 public static List GetShopifyDaySaleDatas(DateTime sdate, DateTime edate) { var sql = @"--SHopify每个店铺的订单数量,及订单总金额 create table #ls_0(shopid int not null) insert #ls_0(shopid) select ShopId from JC_Shop where ShopId in (56,61,83,88) select t.ShopId,COUNT(distinct t.OrderId) OrderNum ,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice into #ls_1 from ( select ROW_NUMBER() over(partition by z.orderid,z.shopid order by goodsnum) row,z.* from ( select CONVERT(date, a.OrderDate) OrderDate,a.ShopId, a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=15 and a.ShopId in (56,61,83,88) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate)z ) t where t.row=1 group by t.ShopId --广告费 select ShopId,SUM(ISNULL(Rate3,0)) Adfee Into #ls_2 from JC_ShopData where ShopId in (56,61,83,88) and CONVERT(date,DATEADD(day,-1, InDate))>=@sDate and CONVERT(date,DATEADD(day,-1, InDate))<=@eDate group by ShopId --利润 select a.shopid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR , SUM(ISNULL(c.SubsidyFee,0)) SubsidyFee into #ls_3 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId where a.State>0 and a.State<3 and a.PlatId=15 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.ShopId --E-Match仓储费 declare @E_Mccfee decimal(12,2) select @E_Mccfee=ISNULL(CONVERT(decimal(12,2), SUM(ISNULL(b.StockSolidNum,0))*0.5*0.02),0) from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsID=b.GoodsId where a.SortId=749 and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate --所有商品的仓储费 Boson取2%,lucky取0.5%,karmasfar取0.1% declare @total_CCFee decimal(12,2) select @total_CCFee=SUM(isnull(stocksolidnum,0))*0.5 from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate select 15 PlatId, t1.ShopId UserId,t1.ShopName Name,t2.Adfee,t2.ordernum OrdersNum,t2.GoodsNum ,t2.TotalPrice SalePrice,t2.TCB,t2.LR NetProfit,T2.ccFee DayTotalSolidFee,HJLR=ISNULL( t2.LR,0)- ISNULL( t2.Adfee,0)- isnull(t2.ccfee,0),t2.SubsidyFee from JC_Shop t1 left join (select z.ShopId, b.Adfee,a.OrderNum,a.GoodsNum,a.TotalPrice,case when ISNULL( a.TotalPrice,0)=0 or ISNULL( b.Adfee,0)=0 then 0 else convert(decimal(12,2), (b.Adfee*100/a.TotalPrice)) end TCB,CONVERT(decimal(12,2), c.LR) LR,c.SubsidyFee, case when z.ShopId=56 then CONVERT(decimal(12,2), @total_CCFee*0.02) when z.ShopId=61 then CONVERT(decimal(12,2), @total_CCFee*0.005) when z.ShopId=83 then @E_Mccfee when z.ShopId=88 then CONVERT(decimal(12,2), @total_CCFee*0.001) end ccfee from #ls_0 z left join #ls_1 a on z.shopid=a.shopid left join #ls_2 b on z.shopid=b.ShopId left join #ls_3 c on z.shopid=c.ShopId ) t2 on t1.ShopId=t2.ShopId where t1.ShopId in (56,61,83,88)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shopify平台每个店铺的净利润数据 public static List GetShopifyHJLRDatas(DateTime sdate, DateTime edate) { var sql = @"--广告费 select CONVERT(date,DATEADD(day,-1, InDate)) InDate, ShopId,SUM(ISNULL(Rate3,0)) Adfee into #ls_1 from JC_ShopData where ShopId in (56,61,83,88) and CONVERT(date,DATEADD(day,-1, InDate))>=@sDate and CONVERT(date,DATEADD(day,-1, InDate))<=@eDate group by CONVERT(date,DATEADD(day,-1, InDate)), ShopId --利润 select convert(date,a.OrderDate) InDate, a.shopid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR Into #ls_2 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId where a.State>0 and a.State<3 and a.PlatId=15 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by CONVERT(date,a.OrderDate), a.ShopId Create table #ls_3 ( ShopId int , Indate date, ccfee decimal(12,2) ) insert into #ls_3 --E-Match仓储费 select 83 ShopId, CONVERT(date,b.indate) Indate, ISNULL(CONVERT(decimal(12,2), SUM(ISNULL(b.StockSolidNum,0))*0.5*0.02),0) ccfee from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsID=b.GoodsId where a.SortId=749 and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate group by CONVERT(date,b.InDate) --boson 2% union all select 56 Shopid, CONVERT(date,InDate) Indate,CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.02) ccfee from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate group by CONVERT(date,InDate) --lucky 0.5% union all select 61 Shopid, CONVERT(date,InDate) Indate,CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.005) ccfee from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate group by CONVERT(date,InDate) --kamarfar 0.1% union all select 88 Shopid, CONVERT(date,InDate) Indate ,CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.001) ccfee from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate group by CONVERT(date,InDate) select a.ShopId,b.Date InDate Into #ls_4 from JC_Shop a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.ShopId in (56,61,83,88) select t.ShopId UserId,CONVERT(nvarchar(100), t.InDate,23) RDate, HJLR=CONVERT(decimal(12,2), ISNULL(t.LR,0)-ISNULL(t.Adfee,0)-ISNULL(t.CCFee,0)) from ( select a.ShopId,a.InDate,b.Adfee,c.LR, d.ccfee CCFee from #ls_4 a left join #ls_1 b on a.ShopId=b.ShopId and a.InDate=b.InDate left join #ls_2 c on a.ShopId=c.ShopId and a.InDate=c.InDate left join #ls_3 d on a.ShopId=d.ShopId and a.InDate=d.Indate ) t "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取shopify平台的销售额折线图 public static List GetShopifyPeopleDaySalePriceDatas(DateTime sdate, DateTime edate) { var sql = @"select 15 PlatId, t1.ShopId UserId,convert(nvarchar(100), t1.InDate,23) RDate,t2.TotalPrice from ( select a.ShopId,b.Date InDate from JC_Shop a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.ShopId in (56,61,83,88) ) t1 left join ( select CONVERT(date, a.OrderDate) Indate,a.ShopId,SUM( isnull( a.TotalPrice,0)) TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=15 and a.ShopId in (56,61,83,88) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate group by CONVERT(date, a.OrderDate) ,a.ShopId ) t2 on t1.InDate =t2.Indate and t1.ShopId=t2.ShopId order by t1.ShopId,t1.Indate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取shopify平台的销售额月折线图 public static List GetShopifyPeopleMonthSalePriceDatas(DateTime sdate, DateTime edate) { var sql = @"select a.ShopId ,b.Date InDate into #ls_1 from JC_Shop a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @sDate),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @sDate, @eDate)) b where a.ShopId in (56,61,83,88) select CONVERT(nvarchar(7), a.OrderDate,120) Indate,a.ShopId,SUM( isnull( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=15 and a.ShopId in (56,61,83,88) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate group by CONVERT(nvarchar(7), a.OrderDate,120) ,a.ShopId select 15 PlatId, a.ShopId UserId,Convert(nvarchar(7) ,a.InDate,120) RDate,b.TotalPrice from #ls_1 a left join #ls_2 b on a.InDate=b.Indate and a.ShopId=b.ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取TikTok平台每个店铺的销售数据 public static List GetTikTokDaySaleDatas(DateTime sdate, DateTime edate) { var sql = @"--TikTok每个店铺的订单数量,及订单总金额 create table #ls_0(shopid int not null) insert #ls_0(shopid) select ShopId from JC_Shop where ShopId in (85) select t.ShopId,COUNT(distinct t.OrderId) OrderNum ,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice into #ls_1 from ( select ROW_NUMBER() over(partition by z.orderid,z.shopid order by goodsnum) row,z.* from ( select CONVERT(date, a.OrderDate) OrderDate,a.ShopId, a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=22 and a.ShopId in (85) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate)z ) t where t.row=1 group by t.ShopId --广告费 select ShopId,SUM(ISNULL(Rate3,0)) Adfee Into #ls_2 from JC_ShopData where ShopId in (85) and CONVERT(date,DATEADD(day,-1, InDate))>=@sDate and CONVERT(date,DATEADD(day,-1, InDate))<=@eDate group by ShopId --利润 select a.shopid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR , SUM(ISNULL(c.SubsidyFee,0)) SubsidyFee into #ls_3 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId where a.State>0 and a.State<3 and a.PlatId=22 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.ShopId --所有商品的仓储费 declare @total_CCFee decimal(12,2) select @total_CCFee=SUM(isnull(stocksolidnum,0))*0.5 from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate select 22 PlatId, t1.ShopId UserId,t1.ShopName Name,t2.Adfee,t2.ordernum OrdersNum,t2.GoodsNum ,t2.TotalPrice SalePrice,t2.TCB,t2.LR NetProfit,T2.ccFee DayTotalSolidFee,HJLR=ISNULL( t2.LR,0)- ISNULL( t2.Adfee,0)- isnull(t2.ccfee,0),t2.SubsidyFee from JC_Shop t1 left join (select z.ShopId, b.Adfee,a.OrderNum,a.GoodsNum,a.TotalPrice,case when ISNULL( a.TotalPrice,0)=0 or ISNULL( b.Adfee,0)=0 then 0 else convert(decimal(12,2), (b.Adfee*100/a.TotalPrice)) end TCB,CONVERT(decimal(12,2), c.LR) LR, case when z.ShopId=85 then CONVERT(decimal(12,2), @total_CCFee*0.02) else 0 end ccfee,c.SubsidyFee from #ls_0 z left join #ls_1 a on z.shopid=a.shopid left join #ls_2 b on z.shopid=b.ShopId left join #ls_3 c on z.shopid=c.ShopId ) t2 on t1.ShopId=t2.ShopId where t1.ShopId in (85)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取TikTok平台每个店铺的净利润数据 public static List GetTikTokHJLRDatas(DateTime sdate, DateTime edate) { var sql = @" --广告费 select CONVERT(date,DATEADD(day,-1, InDate)) InDate, ShopId,SUM(ISNULL(Rate3,0)) Adfee into #ls_1 from JC_ShopData where ShopId in (85) and CONVERT(date,DATEADD(day,-1, InDate))>=@sDate and CONVERT(date,DATEADD(day,-1, InDate))<=@eDate group by CONVERT(date,DATEADD(day,-1, InDate)), ShopId --利润 select convert(date,a.OrderDate) InDate, a.shopid, Sum(IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR Into #ls_2 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId where a.State>0 and a.State<3 and a.PlatId=22 and a.ShopId in (85) and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by CONVERT(date,a.OrderDate), a.ShopId Create table #ls_3 ( ShopId int , Indate date, ccfee decimal(12,2) ) insert into #ls_3 --TK_LK仓储费 select 85 ShopId, CONVERT(date,indate) Indate, ISNULL(CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.02),0) ccfee from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate group by CONVERT(date,InDate) select a.ShopId,b.Date InDate Into #ls_4 from JC_Shop a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.ShopId in (85) select t.ShopId UserId,CONVERT(nvarchar(100), t.InDate,23) RDate, HJLR=CONVERT(decimal(12,2), ISNULL(t.LR,0)-ISNULL(t.Adfee,0)-ISNULL(t.CCFee,0)) from ( select a.ShopId,a.InDate,b.Adfee,c.LR, d.ccfee CCFee from #ls_4 a left join #ls_1 b on a.ShopId=b.ShopId and a.InDate=b.InDate left join #ls_2 c on a.ShopId=c.ShopId and a.InDate=c.InDate left join #ls_3 d on a.ShopId=d.ShopId and a.InDate=d.Indate ) t"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取TikTok平台的销售额折线图 public static List GetTikTokPeopleDaySalePriceDatas(DateTime sdate, DateTime edate) { var sql = @"select 22 PlatId, t1.ShopId UserId,convert(nvarchar(100), t1.InDate,23) RDate,t2.TotalPrice from ( select a.ShopId,b.Date InDate from JC_Shop a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.ShopId in (85) ) t1 left join ( select CONVERT(date, a.OrderDate) Indate,a.ShopId,SUM( isnull( a.TotalPrice,0)) TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=22 and a.ShopId in (85) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate group by CONVERT(date, a.OrderDate) ,a.ShopId ) t2 on t1.InDate =t2.Indate and t1.ShopId=t2.ShopId order by t1.ShopId,t1.Indate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取TikTok平台的销售额月折线图 public static List GetTikTokPeopleMonthSalePriceDatas(DateTime sdate, DateTime edate) { var sql = @"select a.ShopId ,b.Date InDate into #ls_1 from JC_Shop a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @sDate),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @sDate, @eDate)) b where a.ShopId in (85) select CONVERT(nvarchar(7), a.OrderDate,120) Indate,a.ShopId,SUM( isnull( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=22 and a.ShopId in (85) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate group by CONVERT(nvarchar(7), a.OrderDate,120) ,a.ShopId select 22 PlatId, a.ShopId UserId,Convert(nvarchar(7) ,a.InDate,120) RDate,b.TotalPrice from #ls_1 a left join #ls_2 b on a.InDate=b.Indate and a.ShopId=b.ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region /// /// 更新订单的UPS运费 /// /// /// 运费 /// 仓库:241是RANCHO,242是E仓 public static void UpdateOrderUPSPostFee(int orderid, decimal postfee, int postid, string upslog) { var sql = ""; if (postid == 241) { sql = @" update DT_OrderInfo set UpsFeeR=@postfee,UpsFeelog=@upslog where OrderId=@orderid"; } else if (postid == 242) { sql = @" update DT_OrderInfo set UpsFeeE=@postfee,UpsFeelog=@upslog where OrderId=@orderid"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@postfee", DbType.Decimal, postfee); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.AddInParameter(cmd, "@upslog", DbType.String, upslog); db.ExecuteNonQuery(cmd); } #endregion #region /// /// 更新订单 /// public static void UpdateOrderUPSLog(int orderid, string upslog) { var sql = "update DT_OrderInfo set UpsFeelog=@upslog where OrderId=@orderid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.AddInParameter(cmd, "@upslog", DbType.String, upslog); db.ExecuteNonQuery(cmd); } #endregion #region 获取Shein平台每个店铺的销售数据 public static List GetSheinDaySaleDatas(DateTime sdate, DateTime edate) { var sql = @"--Shein每个店铺的订单数量,及订单总金额 create table #ls_0(shopid int not null) insert #ls_0(shopid) select ShopId from JC_Shop where ShopId in (84,89,90) select t.ShopId,COUNT(distinct t.OrderId) OrderNum ,SUM(t.GoodsNum) GoodsNum,SUM(t.TotalPrice) TotalPrice into #ls_1 from ( select ROW_NUMBER() over(partition by z.orderid,z.shopid order by goodsnum) row,z.* from ( select CONVERT(date, a.OrderDate) OrderDate,a.ShopId, a.OrderId,b.DetailId,b.GoodsNum,a.TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId in (84,89,90) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate)z ) t where t.row=1 group by t.ShopId --shein没有广告费,收销售额的10%佣金,导入的订单价格已经去除了佣金 --利润 select a.shopid, Sum(IsNull(a.TotalPrice,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR ,SUM(ISNULL(c.SubsidyFee,0)) SubsidyFee into #ls_3 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId where a.State>0 and a.State<3 and a.PlatId=21 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.ShopId --Shein库存费按照售卖订单商品的立方的12倍计算 declare @ccfee decimal(12,2) select a.ShopId, convert(decimal(12,2), SUM( b.GoodsNum*d.Solid*12)*0.5) ccfee into #ls_4 from DT_OrderInfo a inner join DT_OrderGoods b on a.orderid=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.ShopId in(84,89,90) and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.ShopId select 21 PlatId, t1.ShopId UserId,t1.ShopName+'('+t1.Master+')' Name,t2.ordernum OrdersNum,t2.GoodsNum ,t2.TotalPrice SalePrice,t2.LR NetProfit,T2.ccFee DayTotalSolidFee,HJLR=ISNULL( t2.LR,0)- isnull(t2.ccfee,0),t2.SubsidyFee from JC_Shop t1 left join (select z.ShopId,a.OrderNum,a.GoodsNum,a.TotalPrice,0 TCB,CONVERT(decimal(12,2), c.LR) LR,d.ccfee ccfee,SubsidyFee from #ls_0 z left join #ls_1 a on z.shopid=a.shopid left join #ls_3 c on z.shopid=c.ShopId left join #ls_4 d on a.ShopId=d.ShopId ) t2 on t1.ShopId=t2.ShopId where t1.ShopId in (84,89,90)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shein平台的销售额折线图 public static List GetSheinPeopleDaySalePriceDatas(DateTime sdate, DateTime edate) { var sql = @"select 21 PlatId, t1.ShopId UserId,convert(nvarchar(100), t1.InDate,23) RDate,t2.TotalPrice from ( select a.ShopId,b.Date InDate from JC_Shop a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.ShopId in (84,89,90) ) t1 left join ( select CONVERT(date, a.OrderDate) Indate,a.ShopId,SUM( isnull( a.TotalPrice,0)) TotalPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId in (84,89,90) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate group by CONVERT(date, a.OrderDate) ,a.ShopId ) t2 on t1.InDate =t2.Indate and t1.ShopId=t2.ShopId order by t1.ShopId,t1.Indate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shein平台的销售额月折线图 public static List GetSheinPeopleMonthSalePriceDatas(DateTime sdate, DateTime edate) { var sql = @"select a.ShopId ,b.Date InDate into #ls_1 from JC_Shop a Cross Join (SELECT CONVERT(nvarchar(7), DATEADD(MONTH, number, @sDate),120) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(MONTH, @sDate, @eDate)) b where a.ShopId in (84,89,90) select CONVERT(nvarchar(7), a.OrderDate,120) Indate,a.ShopId,SUM( isnull( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId in (84,89,90) and CONVERT(date, a.OrderDate)>=@sDate and CONVERT(date, a.OrderDate)<=@eDate group by CONVERT(nvarchar(7), a.OrderDate,120) ,a.ShopId select 21 PlatId, a.ShopId UserId,Convert(nvarchar(7) ,a.InDate,120) RDate,b.TotalPrice from #ls_1 a left join #ls_2 b on a.InDate=b.Indate and a.ShopId=b.ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shein平台每个店铺的净利润数据 public static List GetSheinHJLRDatas(DateTime sdate, DateTime edate) { var sql = @"select a.ShopId,b.Date InDate Into #ls_1 from JC_Shop a Cross Join (SELECT CONVERT(date, DATEADD(DAY, number, @sDate)) AS [Date] FROM master..spt_values WHERE type = 'P'AND number <= DATEDIFF(DAY, @sDate, @eDate)) b where a.ShopId in (84,89,90) --利润 select convert(date,a.OrderDate) InDate, a.shopid, Sum(IsNull(a.TotalPrice,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR into #ls_2 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId in (84,89,90) and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by CONVERT(date,a.OrderDate), a.ShopId --仓储费,订单商品的总立方的12倍 select CONVERT(date,a.OrderDate) InDate,ShopId, convert(decimal(12,2), SUM( b.GoodsNum*d.Solid*12)*0.5) CCFee into #ls_3 from DT_OrderInfo a inner join DT_OrderGoods b on a.orderid=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.ShopId in( 84,89,90) and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by a.ShopId, CONVERT(date,a.OrderDate) select a.ShopId UserId,CONVERT(nvarchar(100), a.InDate,23) RDate,HJLR=CONVERT(decimal(12,2), b.LR-c.CCFee) from #ls_1 a left join #ls_2 b on a.InDate=b.InDate and a.ShopId=b.ShopId left join #ls_3 c on a.InDate=c.InDate and a.ShopId=c.ShopId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, edate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取UPS运费 public static List GetUpsOrderList(DateTime? SDate) { string query = " select top 30 b.* from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where b.CountryCode='US' and a.OrderDate>=@SDate and ISNULL(UpsFeeR,0)=0 and a.UpsFeelog is null order by a.InDate"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@SDate", DbType.DateTime, SDate); return database.ExecuteDataTable(sqlStringCommand).ToList(); } #region 返回订单Model public static DT_OrderModelNew GetOrderModelNew(int OrderId) { DT_OrderModelNew model = null; string tsql = @"select a.*, b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,ShopName=[dbo].[GetShopName](a.ShopId),b.CountryCode,b.CountryName,b.PostError,b.SendAddr,b.PostOneCode,b.LogisticsId,b.RevProvinceCode,a.Fee6,a.Fee7,a.Fee8,BoxFee=a.Fee10,a.Fee11,a.Fee12,a.Fee13,a.Fee14,a.FactOrderFee,a.FactOrderCommison,a.FactOrderFax,b.Zone,a.UpsFeeR,a.UpsFeeE from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 返回订单Model public static DT_OrderModelNew GetOrderModelNew2(int OrderId) { DT_OrderModelNew model = null; string tsql = @"select a.*, b.TotalWeight,b.TotalSoild,b.MoneyType,b.CustomID,b.SKU,b.RevName,b.RevCountry,b.RevProvince,b.RevCity,b.RevArea,b.RevAddr,b.RevPhone,b.RevMoblie,b.RevMail,b.RevFax,b.RevPostCode,b.SendInfo,b.ErrorInfo,b.BuyRemark,b.LeaveWord,b.FeeType,b.IsRegister,b.Post,b.PostFee,b.GoodsFee,b.BankCode,b.BankNo,b.CustomBankCode,b.CustomType,b.ErrorImage,b.Channel,b.GoodsAddr,b.TrackCode,b.FontTrackCode,b.StoreId,b.PostInfo,b.OrderState,b.RevProvince,b.RevCity,b.RevArea,c.ShopName,b.CountryCode,b.CountryName,b.PostError,b.SendAddr,b.PostOneCode,b.LogisticsId,b.RevProvinceCode,a.Fee6,a.Fee7,a.Fee8,BoxFee=a.Fee10,a.Fee11,a.Fee12,a.Fee13,a.Fee14,a.FactOrderFee,a.FactOrderCommison,a.FactOrderFax,b.Zone,a.UpsFeeR,a.UpsFeeE from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId inner join jc_shop c on a.shopid=c.shopid where a.OrderId=@OrderId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询订单货物明细 // public static List GetOrderGoodsListNew(int OrderId) // { // List list = null; // string tsql = @" //select a.Id,a.OrderId,d.PlatId,a.DetailId,a.GoodsNum,a.GoodsPrice,a.RMBMoney,a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,SKUState=case when a.DetailId>0 then '已经分配' else '未分配' end,GoodsName=case when c.GoodsName is null then a.GoodsName else c.GoodsName end,productImgUrl=case when productImgUrl is not null and productImgUrl<>'' then productImgUrl else '../images/no.jpg' end,TypeDesc=a.GoodsDesc,GoodsDesc=case when a.detailid<=0 then '' when a.detailid>0 and c.GoodsCode is not null and c.GoodsCode<>'' then c.GoodsCode+' '+b.TypeCode+'['+b.TypeDesc+']' else c.GoodsOldCode+' '+b.TypeCode+'['+b.TypeDesc+']' end,a.OldNum,a.GoodsCode,GoodsId=isnull(c.GoodsId,0),OldTypeDesc=case when a.OldTypeDesc is not null and a.OldTypeDesc<>'' then '改为'+a.OldTypeDesc+'发' else '' end,a.OldTypeCode,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,InPrice=isnull(c.InPrice,0),c.Solid from DT_OrderGoods a //inner join DT_OrderInfo d on a.OrderId=d.OrderId //left join HW_GoodsDetail b on a.DetailId=b.DetailId //left join HW_GoodsInfo c on b.GoodsId=c.GoodsId //where a.OrderId=@OrderId //"; // Database db = DatabaseFactory.CreateDatabase(); // DbCommand cmd = db.GetSqlStringCommand(tsql); // db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); // DataSet ds = db.ExecuteDataSet(cmd); // list = ds.Tables[0].ToList(); // return list; // } #endregion public static void UpdateOrder(int OrderId, string log) { var sql = @" update DT_OrderInfo set UpsFeelog=@log where OrderId=@orderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@log", DbType.String, log); db.ExecuteNonQuery(cmd); } #region /// /// 更新订单的UPS运费 /// public static void UpdateOrderUPSPostFee(int orderid, decimal postfee, string upslog) { var sql = "update DT_OrderInfo set UpsFeeR=@postfee,UpsFeelog=@log where OrderId=@orderid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@postfee", DbType.Decimal, postfee); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.AddInParameter(cmd, "@log", DbType.String, upslog); db.ExecuteNonQuery(cmd); } #endregion #endregion #region 获取退货订单 public static List GetRefundOrderListDatas(int? shopId, int dateType, DateTime? sDate, DateTime? eDate, string orderId, int searchType, string search, int? isComp, int pageIndex, int pageSize, out int rowCount) { var filt = " where 1=1 "; if (shopId.HasValue && shopId.Value != 0) { filt += " and a.ShopId=" + shopId; } if (isComp.HasValue && isComp.Value == 1) { filt += " and (a.CompleteState=0 or a.CompleteState is null)"; } if (!string.IsNullOrEmpty(orderId)) { filt += " and a.OrderId like '%" + orderId + "%'"; } if (sDate.HasValue) { if (dateType == 0) //订单日期 { filt += " and Convert(Date,a.OrderDate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "'"; } else if (dateType == 1) //退货日期 { filt += " and Convert(Date,a.ReturnRequestDate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "'"; } } if (eDate.HasValue) { if (dateType == 0) //订单日期 { filt += " and Convert(Date,a.OrderDate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "'"; } else if (dateType == 1) //退货日期 { filt += " and Convert(Date,a.ReturnRequestDate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "'"; } } if (!string.IsNullOrEmpty(search)) { if (searchType == 0) //SKU { filt += " and b.MerchantSku like '%" + search + "%'"; } else if (searchType == 1) //ASIN { filt += " and b.ASIN like '%" + search + "%'"; } else if (searchType == 2) //TrackingId 跟踪码 { filt += " and c.TrackingId like '%" + search + "%'"; } } var sql = " select COUNT(1) count from (select ROW_NUMBER() over(partition by a.OrderId order by a.ReturnRequestDate desc) row , a.ID,a.OrderDate from ShopRefundOrderDatas a left join ShopRefundOrderDatas_ItemDetails b on a.ID=b.ShopRefundOrderDatasId left join ShopRefundOrderDatas_LabelDetails c on a.ID=c.ShopRefundOrderDatasId inner join JC_Shop d on a.ShopId=d.ShopId inner join DT_OrderInfo e on a.OrderId= e.PlatOrderCode " + filt + " ) t where t.row=1 \r\n"; sql += " select ID,OrderId,OrderCode,ShopId,ShopName,OrderDate,ReturnRequestDate,ReturnRequestStatus,ReturnType,OrderAmount,OrderQuantity,CompleteState,CompleteDate from (\r\nselect ROW_NUMBER() over(order by t.ReturnRequestDate desc) row ,ID,OrderId, OrderCode,ShopId,ShopName,OrderDate,ReturnRequestDate,ReturnRequestStatus,ReturnType,OrderAmount,OrderQuantity,CompleteState,CompleteDate from (\r\nselect ROW_NUMBER() over(partition by a.OrderId order by a.ReturnRequestDate desc) row , a.ID,e.OrderId, a.OrderId OrderCode, a.ShopId,d.ShopName, a.OrderDate,a.ReturnRequestDate,a.ReturnRequestStatus,a.ReturnType,a.OrderAmount,a.OrderQuantity ,Case when a.CompleteState is null or a.CompleteState =0 then '未结束' when a.CompleteState=1 then '结束' end CompleteState,CompleteDate from ShopRefundOrderDatas a left join ShopRefundOrderDatas_ItemDetails b on a.ID=b.ShopRefundOrderDatasId left join ShopRefundOrderDatas_LabelDetails c on a.ID=c.ShopRefundOrderDatasId inner join JC_Shop d on a.ShopId=d.ShopId inner join DT_OrderInfo e on a.OrderId= e.PlatOrderCode " + filt + ") t where t.row=1 ) t2 where t2.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } public static List GetRefundOrderList_ItemDatas(string ids) { var sql = @" select a.ShopRefundOrderDatasId,f.FirstImgUrl ImgUrl,f.GoodsName,a.ReturnReasonCode,a.Asin,a.MerchantSku SKU,a.ReturnQuantity,a.Resolution,a.RefundAmount,d.GoodsSKU,f.GoodsCode from ShopRefundOrderDatas_ItemDetails a inner join ShopRefundOrderDatas b on a.ShopRefundOrderDatasId=b.ID inner join DT_OrderInfo c on b.OrderId=c.PlatOrderCode inner join DT_OrderGoods d on c.OrderId=d.OrderId and a.Asin=d.productImgUrl inner join HW_GoodsDetail e on d.DetailId=e.DetailId inner join HW_GoodsInfo f on e.GoodsId=f.GoodsId where a.ShopRefundOrderDatasId in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetRefundOrderList_LabelDatas(string ids) { var sql = @" select ShopRefundOrderDatasId,case when len(a.TrackingId)>0 then a.TrackingId else c.tracking_id end TrackingId, case when LEN(a.ReturnCarrier)>0 then ReturnCarrier else c.return_carrier end ReturnCarrier,CurrencyCode,LabelCost,LabelType, c.ScanDate, case when c.InType=1 then 'Restock' when c.InType=2 then 'CTN change' when c.InType=3 then 'Scrap' when c.InType=4 then 'Sale' when c.InType= 5 then 'Claim' else '' end InType from ShopRefundOrderDatas_LabelDetails a inner join ShopRefundOrderDatas b on a.ShopRefundOrderDatasId=b.ID left join DT_OrderReturn c on b.OrderId=c.ordercode where ShopRefundOrderDatasId in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static void UpdateRefundOrderState(int id) { var sql = @" update ShopRefundOrderDatas set CompleteState=1 ,CompleteDate=GetDate() where ISNULL(CompleteState,0)!=1 and ID=" + id; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion #region 更新HW_GoodsInfo表数据的显示隐藏 public static void UpdateGoodsInfoXSYC(int goodsid, int isyc) { var sql = @" Update HW_GoodsInfo set isyc=" + isyc + " where GoodsId= " + goodsid; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion #region 商品类目关联店铺 public static List GetGoodsSortShopDatas(int? sortId, int? shopId, int PageIndex, int PageSize, out int rowCount) { var filt = " where 1=1 "; if (sortId.HasValue && sortId.Value != 0) filt += " and a.SortId=" + sortId; if (shopId.HasValue && shopId.Value != 0) filt += " and a.ShopId=" + shopId; var sql = @" select COUNT(1) count from GoodsSortShop a left join HW_GoodsSort b on a.SortId=b.SortId left join JC_Shop c on a.ShopId=c.ShopId " + filt; sql += " \r\n select ID,SortId,SortName,ShopId,ShopName from (\r\nselect ROW_NUMBER() over(order by CreateTime desc) row, a.ID,a.SortId,b.SortName,a.ShopId,c.ShopName from GoodsSortShop a left join HW_GoodsSort b on a.SortId=b.SortId left join JC_Shop c on a.ShopId=c.ShopId " + filt + " \r\n) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } public static int InsertGoodsSortShop(int sortId, int shopId) { var sql = @"if(exists(select 1 from GoodsSortShop where SortId=@sortId and ShopId=@shopId)) select 0 as ID else insert into GoodsSortShop(SortId,ShopId,CreateTime) values(@sortId,@shopId,GETDATE()) select SCOPE_IDENTITY() as ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sortId", DbType.Int32, sortId); db.AddInParameter(cmd, "@shopId", DbType.Int32, shopId); var dt = db.ExecuteDataTable(cmd); return Convert.ToInt32(dt.Rows[0]["ID"]); } public static int UpdateGoodsSortShop(int ID, int sortId, int shopId) { var sql = @"if(exists(select 1 from GoodsSortShop where SortId=@sortId and ShopId=@shopId)) select 0 as ID else update GoodsSortShop set SortId=@sortId ,ShopId=@shopId where ID=@ID select @ID as ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sortId", DbType.Int32, sortId); db.AddInParameter(cmd, "@shopId", DbType.Int32, shopId); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); var dt = db.ExecuteDataTable(cmd); return Convert.ToInt32(dt.Rows[0]["ID"]); } public static void DeleteGoodsSortShop(int ID) { var sql = @"delete from GoodsSortShop where ID=@ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } #endregion #region 根据商品获取商品类目的关联店铺 public static List GetGoodsSortShopModelForGoodIds(string ids) { var sql = @" select a.GoodsId,a.SortId,b.ShopId,c.ShopName from HW_GoodsInfo a inner join GoodsSortShop b on a.SortId=b.SortId inner join JC_Shop c on b.ShopId=c.ShopId where GoodsId in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 根据商品获取商品上架的链接 public static List GetHWBuyLinkModelForGoodIds(string ids) { var sql = @" select LinkId, GoodsId,LinkUrl,LinkDesc from HW_BuyLink where GoodsId in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 根据各个店铺各个类目上架商品的个数 public static List GetShopGoodsSortLinkCountDatas(int? isJSYC) { var filt = ""; if (isJSYC != 1) { filt += " and ISNULL(a.IsYC,0)=0 "; } var sql = @" select b.LinkDesc ShopName ,a.SortId,COUNT(1) Count from HW_GoodsInfo a inner join HW_BuyLink b on a.GoodsId=b.GoodsId where ISNULL(b.LinkUrl,'')<>'' " + filt + " group by a.SortId,b.LinkDesc order by SortId desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 更新Shop AccessToken public static void UpdateShopToken(JC_Shop shop) { var sql = " update JC_Shop set AccessToken='" + shop.AccessToken + "' ,RefreshToken='" + shop.RefreshToken + "' where ShopId=" + shop.ShopId; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } #endregion //public static List GetOrderModelList(string OrderIds) //{ // string query = "select a.OrderId,a.PlatOrderCode,a.JoinOrderCode,a.OrderCode,a.TotalPrice,a.MoneyCode,b.RevAddr,b.RevMail,b.RevCountry,b.RevPhone,b.RevMoblie,ISNULL(b.RevProvinceCode,b.RevProvince) RevProvince,b.RevPhone,b.CountryCode,b.RevCity,b.RevArea,b.Post,b.RevMail,b.LogisticsId,b.RevName,b.RevPostCode,b.CountryName,a.State,b.CustomID from DT_OrderInfo a\r\n inner join DT_OrderXXInfo b on a.OrderId=b.OrderId\r\n where a.OrderId in (" + OrderIds + ")"; // Database database = DatabaseFactory.CreateDatabase(); // DbCommand sqlStringCommand = database.GetSqlStringCommand(query); // DataSet dataSet = database.ExecuteDataSet(sqlStringCommand); // return dataSet.Tables[0].ToList(); //} public static string GetProvinceCode(string province) { string sql = @"select top 1 ISNULL( code,'') Code from DT_USMap where ename='" + province + "' or code='" + province + "'"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(sql); DataTable dt = database.ExecuteDataTable(sqlStringCommand); if (dt.Rows != null && dt.Rows.Count > 0) { return dt.Rows[0]["Code"].ToString(); } return ""; } #region 返回亚马逊平台个人管理商品的销售数据 public static List GetAmazonPeopleGoodsSaleDataList(DateTime sDate, DateTime eDate, string userids, int pageIndex, int pageSize, out int rowCount) { var sql = @"--管理的所有商品 select GoodsId,GoodsCode,GoodsName into #ls_1 from HW_GoodsInfo where muserid in (" + userids + ") "; sql += @" --各个商品的销售额 select c.GoodsId,SUM(ISNULL( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.muserid in (" + userids + ") group by c.GoodsId "; sql += @" --广告费 select a.GoodsId,SUM(isnull( a.adfeenew,0)) AdFee into #ls_3 from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where CONVERT(date,a.addate)>=@sDate and CONVERT(date,a.addate)<=@eDate and b.PlatType=2 and c.muserid in (" + userids + ") group by a.goodsid"; sql += @" --订单数量 select c.GoodsId,COUNT(distinct a.OrderId) OrderCount into #ls_4 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=2 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.muserid in (" + userids + ") group by c.GoodsId"; sql += @" select z.OrderId into #ls_9 from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.muserid in (" + userids + ") "; sql += @" --每个订单未除去广告费和仓储费的利润 select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_5 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join ( select distinct OrderId from #ls_9) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId"; sql += @" --广告订单数量,广告订单金额 select a.GoodsId,CONVERT(decimal(12,2), SUM(ISNULL(a.Ad_Order_Amount,0))) AdTotalPrice,SUM(ISNULL(a.ad_order_quantity,null)) AdOrderCount into #ls_6 from AdOrdersProportion a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and b.muserid in (" + userids + ") group by a.GoodsId"; sql += @" --广告订单利润=(广告订单数量/订单数量)*(订单利润-广告费) --广告花费占比=(广告花费/广告订单金额) --库存总金额 select a.goodsid,StockTotalPrice=SUM(b.WestNumPrice)+SUM(b.EastNumPrice)+SUM(b.GoodsHJNum14Price)+SUM(b.GoodsHJNum15Price)+SUM(b.NBHJNumPrice) into #ls_7 from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where a.muserid in (" + userids + ") group by a.GoodsId"; sql += @" --仓储费 select a.GoodsId,CONVERT(decimal(12,2),SUM(isnull(a.StockSolidNum,0)*0.5)) DayTotalSolidFee into #ls_8 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date,a.InDate)>=@sDate and CONVERT(date,a.InDate)<=@eDate and b.muserid in (" + userids + ") group by a.GoodsId select count(GoodsId) Count from #ls_1"; sql += @" select * from ( select row_number() over(order by a2.TotalPrice desc ,a3.AdFee desc) row, a1.GoodsId,a1.GoodsCode,a1.GoodsName, a3.AdFee,a4.OrderCount,a2.TotalPrice,case when ISNULL(a3.AdFee,0)=0 and isnull(a2.TotalPrice,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when isnull(a2.TotalPrice,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2),a3.AdFee*100/a2.TotalPrice)) end TCB, case when ISNULL(a3.AdFee,0)=0 and ISNULL(a6.AdTotalPrice,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when ISNULL(a6.AdTotalPrice,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2), a3.AdFee*100/a6.AdTotalPrice)) end AdSaleZB, a5.LR,a6.AdTotalPrice,a6.AdOrderCount,case when ISNULL(a4.OrderCount,0)=0 or ISNULL(a6.AdOrderCount,0)=0 then 0 else convert(decimal(12,2),(a6.AdOrderCount*1.00/a4.OrderCount)*(isnull(a5.LR,0)-Isnull(a3.AdFee,0))) end AdOrderLR, a7.StockTotalPrice,a8.DayTotalSolidFee, HJLR=ISNULL( a5.LR,0)-isnull(a3.AdFee,0)-isnull(a8.DayTotalSolidFee,0) from #ls_1 a1 left join #ls_2 a2 on a1.GoodsId=a2.GoodsId left join #ls_3 a3 on a1.GoodsId=a3.goodsid left join #ls_4 a4 on a1.GoodsId=a4.GoodsId left join #ls_5 a5 on a1.GoodsId=a5.GoodsId left join #ls_6 a6 on a1.GoodsId=a6.GoodsId left join #ls_7 a7 on a1.GoodsId=a7.GoodsId left join #ls_8 a8 on a1.GoodsId=a8.GoodsId ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); return ds.Tables[1].ToList(); } #endregion #region 获取亚马逊平台个人管理商品月净利润 public static List GetAmazonPeopleGoodsMonthHJLR(string userids, DateTime sDate, DateTime eDate) { var sql = @" select z.OrderId into #ls_4 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.muserid in (" + userids + ")"; sql += @" select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_1 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct OrderId from #ls_4 ) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId"; sql += @" --广告费 select a.GoodsId,SUM(isnull( a.adfeenew,0)) AdFee into #ls_2 from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where CONVERT(date,a.addate)>=@sDate and CONVERT(date,a.addate)<=@eDate and b.PlatType=2 and c.muserid in (" + userids + ") group by a.goodsid"; sql += @" --仓储费 select a.GoodsId,CONVERT(decimal(12,2),SUM(isnull(a.StockSolidNum,0)*0.5)) DayTotalSolidFee into #ls_3 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date,a.InDate)>=@sDate and CONVERT(date,a.InDate)<=@eDate and b.muserid in (" + userids + ") group by a.GoodsId"; sql += @" select a.GoodsId,ISNULL(a1.LR,0)-ISNULL(a2.AdFee,0)-ISNULL(a3.DayTotalSolidFee,0) MonthHJLR from HW_GoodsInfo a left join #ls_1 a1 on a.GoodsId=a1.GoodsId left join #ls_2 a2 on a.GoodsId=a2.goodsid left join #ls_3 a3 on a.GoodsId=a3.GoodsId where a.muserid in (" + userids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 返回Ebay平台个人管理商品的销售数据 public static List GetEBayPeopleGoodsSaleDataList(DateTime sDate, DateTime eDate, int userid, int pageIndex, int pageSize, out int rowCount) { var sql = @"--管理的所有商品 select GoodsId,GoodsCode,GoodsName into #ls_1 from HW_GoodsInfo where guserid_ebay=@muserid --各个商品的销售额 select c.GoodsId,SUM(ISNULL( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=3 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.guserid_ebay=@muserid group by c.GoodsId --广告费 ,广告订单数量,广告订单金额 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee,SUM(ISNULL(AdOrderCount,0)) AdOrderCount,SUM(ISNULL(AdSaleAmount,0)) AdSaleAmount into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=3 and c.guserid_ebay=@muserid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --订单数量 select c.GoodsId,COUNT(distinct a.OrderId) OrderCount into #ls_4 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=3 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.guserid_ebay=@muserid group by c.GoodsId --每个订单未除去广告费和仓储费的利润 select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_5 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=3 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.guserid_ebay=@muserid) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告订单利润=(广告订单数量/订单数量)*(订单利润-广告费) --仓储费 select t.GoodsId,CONVERT(decimal(12,2) ,SUM(t.StockSolidNum)*0.5) DayTotalSolidFee into #ls_6 from ( select a.GoodsId, case when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_ebay =@muserid and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate ) t group by t.GoodsId select count(GoodsId) Count from #ls_1 select * from ( select row_number() over(order by a2.TotalPrice desc,a3.AdFee desc) row, a1.GoodsId,a1.GoodsCode,a1.GoodsName,a3.AdFee,a4.OrderCount,a2.TotalPrice, case when ISNULL(a3.AdFee,0)=0 and isnull(a2.TotalPrice,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when isnull(a2.TotalPrice,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2),a3.AdFee*100/a2.TotalPrice)) end TCB, case when ISNULL(a3.AdFee,0)=0 and ISNULL(a3.AdSaleAmount,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when ISNULL(a3.AdSaleAmount,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2), a3.AdFee*100/a3.AdSaleAmount)) end AdSaleZB, a5.LR,a3.AdOrderCount,a3.AdSaleAmount AdTotalPrice, case when ISNULL(a4.OrderCount,0)=0 or ISNULL(a3.AdOrderCount,0)=0 then 0 else convert(decimal(12,2),(a3.AdOrderCount*1.00/a4.OrderCount)*(isnull(a5.LR,0)-Isnull(a3.AdFee,0))) end AdOrderLR, a6.DayTotalSolidFee,HJLR=ISNULL(a5.LR,0)-ISNULL(a3.AdFee,0)-ISNULL(a6.DayTotalSolidFee,0) from #ls_1 a1 left join #ls_2 a2 on a1.GoodsId=a2.GoodsId left join #ls_3 a3 on a1.GoodsId=a3.GoodsId left join #ls_4 a4 on a1.GoodsId=a4.GoodsId left join #ls_5 a5 on a1.GoodsId=a5.GoodsId left join #ls_6 a6 on a1.GoodsId=a6.GoodsId ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@muserid", DbType.Int32, userid); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); return ds.Tables[1].ToList(); } #endregion #region 获取EBay平台个人管理商品月净利润 public static List GetEBayPeopleGoodsMonthHJLR(int userid, DateTime sDate, DateTime eDate) { var sql = @"select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_1 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=3 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.guserid_ebay=@muserid) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee into #ls_2 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=3 and c.guserid_ebay=@muserid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select t.GoodsId,CONVERT(decimal(12,2) ,SUM(t.StockSolidNum)*0.5) DayTotalSolidFee into #ls_3 from ( select a.GoodsId, case when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_ebay =@muserid and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate ) t group by t.GoodsId select a.GoodsId,ISNULL(a1.LR,0)-ISNULL(a2.AdFee,0)-ISNULL(a3.DayTotalSolidFee,0) MonthHJLR from HW_GoodsInfo a left join #ls_1 a1 on a.GoodsId=a1.GoodsId left join #ls_2 a2 on a.GoodsId=a2.goodsid left join #ls_3 a3 on a.GoodsId=a3.GoodsId where a.guserid_ebay=@muserid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@muserid", DbType.Int32, userid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 返回沃尔玛平台个人管理商品的销售数据 public static List GetWlmartPeopleGoodsSaleDataList(DateTime sDate, DateTime eDate, int userid, int pageIndex, int pageSize, out int rowCount) { var sql = @"--管理的所有商品 select GoodsId,GoodsCode,GoodsName into #ls_1 from HW_GoodsInfo where guserid_wlmart=@muserid --各个商品的销售额 select c.GoodsId,SUM(ISNULL( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=6 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.guserid_wlmart=@muserid group by c.GoodsId --广告费 ,广告订单数量,广告订单金额 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee,SUM(ISNULL(AdOrderCount,0)) AdOrderCount,SUM(ISNULL(AdSaleAmount,0)) AdSaleAmount into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=6 and c.guserid_wlmart=@muserid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --订单数量 select c.GoodsId,COUNT(distinct a.OrderId) OrderCount into #ls_4 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=6 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.guserid_wlmart=@muserid group by c.GoodsId --每个订单未除去广告费和仓储费的利润 select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_5 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=6 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.guserid_wlmart=@muserid) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告订单利润=(广告订单数量/订单数量)*(订单利润-广告费) --仓储费 select a.GoodsId, CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.05) DayTotalSolidFee into #ls_6 from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wlmart =@muserid and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate group by a.GoodsId select count(GoodsId) Count from #ls_1 select * from ( select row_number() over(order by a2.TotalPrice desc,a3.AdFee desc) row, a1.GoodsId,a1.GoodsCode,a1.GoodsName,a3.AdFee,a4.OrderCount,a2.TotalPrice, case when ISNULL(a3.AdFee,0)=0 and isnull(a2.TotalPrice,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when isnull(a2.TotalPrice,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2),a3.AdFee*100/a2.TotalPrice)) end TCB, case when ISNULL(a3.AdFee,0)=0 and ISNULL(a3.AdSaleAmount,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when ISNULL(a3.AdSaleAmount,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2), a3.AdFee*100/a3.AdSaleAmount)) end AdSaleZB, a5.LR,a3.AdOrderCount,a3.AdSaleAmount AdTotalPrice, case when ISNULL(a4.OrderCount,0)=0 or ISNULL(a3.AdOrderCount,0)=0 then 0 else convert(decimal(12,2),(a3.AdOrderCount*1.00/a4.OrderCount)*(isnull(a5.LR,0)-Isnull(a3.AdFee,0))) end AdOrderLR, a6.DayTotalSolidFee,HJLR=ISNULL(a5.LR,0)-ISNULL(a3.AdFee,0)-ISNULL(a6.DayTotalSolidFee,0) from #ls_1 a1 left join #ls_2 a2 on a1.GoodsId=a2.GoodsId left join #ls_3 a3 on a1.GoodsId=a3.GoodsId left join #ls_4 a4 on a1.GoodsId=a4.GoodsId left join #ls_5 a5 on a1.GoodsId=a5.GoodsId left join #ls_6 a6 on a1.GoodsId=a6.GoodsId ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@muserid", DbType.Int32, userid); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); return ds.Tables[1].ToList(); } #endregion #region 获取沃尔玛平台个人管理商品月净利润 public static List GetWlmartPeopleGoodsMonthHJLR(int userid, DateTime sDate, DateTime eDate) { var sql = @"select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_1 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=6 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.guserid_wlmart=@muserid) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee into #ls_2 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=6 and c.guserid_wlmart=@muserid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select t.GoodsId,CONVERT(decimal(12,2) ,SUM(t.StockSolidNum)*0.5) DayTotalSolidFee into #ls_3 from ( select a.GoodsId, case when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wlmart =@muserid and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate ) t group by t.GoodsId select a.GoodsId,ISNULL(a1.LR,0)-ISNULL(a2.AdFee,0)-ISNULL(a3.DayTotalSolidFee,0) MonthHJLR from HW_GoodsInfo a left join #ls_1 a1 on a.GoodsId=a1.GoodsId left join #ls_2 a2 on a.GoodsId=a2.goodsid left join #ls_3 a3 on a.GoodsId=a3.GoodsId where a.guserid_wlmart=@muserid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@muserid", DbType.Int32, userid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 返回Wayfair平台个人管理商品的销售数据 public static List GetWayfairPeopleGoodsSaleDataList(DateTime sDate, DateTime eDate, int userid, int pageIndex, int pageSize, out int rowCount) { var sql = @"--管理的所有商品 select GoodsId,GoodsCode,GoodsName into #ls_1 from HW_GoodsInfo where guserid_wayfair=@muserid --各个商品的销售额 select c.GoodsId,SUM(ISNULL( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=18 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.guserid_wayfair=@muserid group by c.GoodsId --广告费 ,广告订单数量,广告订单金额 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee,SUM(ISNULL(AdOrderCount,0)) AdOrderCount,SUM(ISNULL(AdSaleAmount,0)) AdSaleAmount into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=18 and c.guserid_wayfair=@muserid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --订单数量 select c.GoodsId,COUNT(distinct a.OrderId) OrderCount into #ls_4 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=18 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate and d.guserid_wayfair=@muserid group by c.GoodsId --每个订单未除去广告费和仓储费的利润 select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_5 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=18 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.guserid_wayfair=@muserid) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告订单利润=(广告订单数量/订单数量)*(订单利润-广告费) --仓储费 select a.GoodsId, CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.05) DayTotalSolidFee into #ls_6 from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wayfair =@muserid and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate group by a.GoodsId select count(GoodsId) Count from #ls_1 select * from ( select row_number() over(order by a2.TotalPrice desc,a3.AdFee desc) row, a1.GoodsId,a1.GoodsCode,a1.GoodsName,a3.AdFee,a4.OrderCount,a2.TotalPrice, case when ISNULL(a3.AdFee,0)=0 and isnull(a2.TotalPrice,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when isnull(a2.TotalPrice,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2),a3.AdFee*100/a2.TotalPrice)) end TCB, case when ISNULL(a3.AdFee,0)=0 and ISNULL(a3.AdSaleAmount,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when ISNULL(a3.AdSaleAmount,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2), a3.AdFee*100/a3.AdSaleAmount)) end AdSaleZB, a5.LR,a3.AdOrderCount,a3.AdSaleAmount AdTotalPrice, case when ISNULL(a4.OrderCount,0)=0 or ISNULL(a3.AdOrderCount,0)=0 then 0 else convert(decimal(12,2),(a3.AdOrderCount*1.00/a4.OrderCount)*(isnull(a5.LR,0)-Isnull(a3.AdFee,0))) end AdOrderLR, a6.DayTotalSolidFee,HJLR=ISNULL(a5.LR,0)-ISNULL(a3.AdFee,0)-ISNULL(a6.DayTotalSolidFee,0) from #ls_1 a1 left join #ls_2 a2 on a1.GoodsId=a2.GoodsId left join #ls_3 a3 on a1.GoodsId=a3.GoodsId left join #ls_4 a4 on a1.GoodsId=a4.GoodsId left join #ls_5 a5 on a1.GoodsId=a5.GoodsId left join #ls_6 a6 on a1.GoodsId=a6.GoodsId ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@muserid", DbType.Int32, userid); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); return ds.Tables[1].ToList(); } #endregion #region 获取Wayfair平台个人管理商品月净利润 public static List GetWayfairPeopleGoodsMonthHJLR(int userid, DateTime sDate, DateTime eDate) { var sql = @"select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_1 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=18 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate and w.guserid_wayfair=@muserid) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee into #ls_2 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=18 and c.guserid_wayfair=@muserid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select t.GoodsId,CONVERT(decimal(12,2) ,SUM(t.StockSolidNum)*0.5) DayTotalSolidFee into #ls_3 from ( select a.GoodsId, case when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where guserid_wayfair =@muserid and CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate ) t group by t.GoodsId select a.GoodsId,ISNULL(a1.LR,0)-ISNULL(a2.AdFee,0)-ISNULL(a3.DayTotalSolidFee,0) MonthHJLR from HW_GoodsInfo a left join #ls_1 a1 on a.GoodsId=a1.GoodsId left join #ls_2 a2 on a.GoodsId=a2.goodsid left join #ls_3 a3 on a.GoodsId=a3.GoodsId where a.guserid_wayfair=@muserid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@muserid", DbType.Int32, userid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 返回Shopify平台个人管理商品的销售数据 public static List GetShopifyPeopleGoodsSaleDataList(DateTime sDate, DateTime eDate, int shopid, int pageIndex, int pageSize, out int rowCount) { var sql = @"--管理的所有商品 select GoodsId,GoodsCode,GoodsName into #ls_1 from HW_GoodsInfo --各个商品的销售额 select c.GoodsId,SUM(ISNULL( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=15 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate group by c.GoodsId --广告费 ,广告订单数量,广告订单金额 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee,SUM(ISNULL(AdOrderCount,0)) AdOrderCount,SUM(ISNULL(AdSaleAmount,0)) AdSaleAmount into #ls_3 from ShopGoodsAdFee a inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where a.ShopId=@shopid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --订单数量 select c.GoodsId,COUNT(distinct a.OrderId) OrderCount into #ls_4 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=15 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate group by c.GoodsId --每个订单未除去广告费和仓储费的利润 select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_5 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=15 and ShopId=@shopid and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告订单利润=(广告订单数量/订单数量)*(订单利润-广告费) --仓储费 E-Mact和Boson取2%,lucky取0.5%,karmasfar取0.1% select a.GoodsId,case when @shopid=83 or @shopid=@shopid then CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.02) when @shopid=61 then CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.005) when @shopid=88 then CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.001) end DayTotalSolidFee into #ls_6 from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate group by a.GoodsId select count(GoodsId) Count from #ls_1 select * from ( select row_number() over(order by a2.TotalPrice desc,a3.AdFee desc) row, a1.GoodsId,a1.GoodsCode,a1.GoodsName,a3.AdFee,a4.OrderCount,a2.TotalPrice, case when ISNULL(a3.AdFee,0)=0 and isnull(a2.TotalPrice,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when isnull(a2.TotalPrice,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2),a3.AdFee*100/a2.TotalPrice)) end TCB, case when ISNULL(a3.AdFee,0)=0 and ISNULL(a3.AdSaleAmount,0)=0 then '0' when ISNULL(a3.AdFee,0)=0 then '0' when ISNULL(a3.AdSaleAmount,0)=0 then '∞' else convert(nvarchar(10), convert(decimal(12,2), a3.AdFee*100/a3.AdSaleAmount)) end AdSaleZB, a5.LR,a3.AdOrderCount,a3.AdSaleAmount AdTotalPrice, case when ISNULL(a4.OrderCount,0)=0 or ISNULL(a3.AdOrderCount,0)=0 then 0 else convert(decimal(12,2),(a3.AdOrderCount*1.00/a4.OrderCount)*(isnull(a5.LR,0)-Isnull(a3.AdFee,0))) end AdOrderLR, a6.DayTotalSolidFee,HJLR=ISNULL(a5.LR,0)-ISNULL(a3.AdFee,0)-ISNULL(a6.DayTotalSolidFee,0) from #ls_1 a1 left join #ls_2 a2 on a1.GoodsId=a2.GoodsId left join #ls_3 a3 on a1.GoodsId=a3.GoodsId left join #ls_4 a4 on a1.GoodsId=a4.GoodsId left join #ls_5 a5 on a1.GoodsId=a5.GoodsId left join #ls_6 a6 on a1.GoodsId=a6.GoodsId ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); return ds.Tables[1].ToList(); } #endregion #region 获取Shopify平台个人管理商品月净利润 public static List GetShopifyPeopleGoodsMonthHJLR(int shopid, DateTime sDate, DateTime eDate) { var sql = @"select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_1 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0) + IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct z.OrderId from DT_OrderInfo z inner join DT_OrderGoods y on z.OrderId=y.OrderId inner join HW_GoodsDetail x on y.DetailId=x.DetailId inner join HW_GoodsInfo w on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=15 and ShopId=@shopid and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee into #ls_2 from ShopGoodsAdFee a inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where a.ShopId=@shopid and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select a.GoodsId,case when @shopid=83 or @shopid=56 then CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.02) when @shopid=61 then CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.005) when @shopid=88 then CONVERT(decimal(12,2), SUM(ISNULL(StockSolidNum,0))*0.5*0.001) end DayTotalSolidFee into #ls_3 from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate group by a.GoodsId select a.GoodsId,ISNULL(a1.LR,0)-ISNULL(a2.AdFee,0)-ISNULL(a3.DayTotalSolidFee,0) MonthHJLR from HW_GoodsInfo a left join #ls_1 a1 on a.GoodsId=a1.GoodsId left join #ls_2 a2 on a.GoodsId=a2.goodsid left join #ls_3 a3 on a.GoodsId=a3.GoodsId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 返回Shein平台个人管理商品的销售数据 public static List GetSheinPeopleGoodsSaleDataList(DateTime sDate, DateTime eDate, int shopid, int pageIndex, int pageSize, out int rowCount) { var sql = @"--管理的所有商品 select GoodsId,GoodsCode,GoodsName into #ls_1 from HW_GoodsInfo --各个商品的销售额 select c.GoodsId,SUM(ISNULL( a.TotalPrice,0)) TotalPrice into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate group by c.GoodsId --订单数量 select c.GoodsId,COUNT(distinct a.OrderId) OrderCount into #ls_3 from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<=@eDate group by c.GoodsId --每个订单未除去广告费和仓储费的利润 select g.GoodsId,convert(decimal(12,2), Sum(IsNull(a.TotalPrice,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0))) as LR into #ls_4 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join DT_OrderGoods f on a.OrderId=f.OrderId left join HW_GoodsDetail g on f.DetailId=g.DetailId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by g.GoodsId --Shein库存费按照售卖订单商品的立方的12倍计算 select d.GoodsId, convert(decimal(12,2), SUM( b.GoodsNum*d.Solid*12)*0.5) DayTotalSolidFee into #ls_5 from DT_OrderInfo a inner join DT_OrderGoods b on a.orderid=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by d.GoodsId select count(GoodsId) Count from #ls_1 select * from ( select row_number() over(order by a2.TotalPrice desc) row, a1.GoodsId,a1.GoodsCode,a1.GoodsName,a3.OrderCount,a2.TotalPrice, '' TCB,''AdSaleZB, a4.LR, a5.DayTotalSolidFee,HJLR=ISNULL(a4.LR,0)-ISNULL(a5.DayTotalSolidFee,0) from #ls_1 a1 left join #ls_2 a2 on a1.GoodsId=a2.GoodsId left join #ls_3 a3 on a1.GoodsId=a3.GoodsId left join #ls_4 a4 on a1.GoodsId=a4.GoodsId left join #ls_5 a5 on a1.GoodsId=a5.GoodsId ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["Count"]); return ds.Tables[1].ToList(); } #endregion #region 获取Shein平台个人管理商品月净利润 public static List GetSheinPeopleGoodsMonthHJLR(int shopid, DateTime sDate, DateTime eDate) { var sql = @"--每个订单未除去广告费和仓储费的利润 select g.GoodsId,convert(decimal(12,2), Sum(IsNull(a.TotalPrice,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0))) as LR into #ls_1 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join DT_OrderGoods f on a.OrderId=f.OrderId left join HW_GoodsDetail g on f.DetailId=g.DetailId where a.State>0 and a.State<3 and a.PlatId=21 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by g.GoodsId --仓储费 --Shein库存费按照售卖订单商品的立方的12倍计算 select d.GoodsId, convert(decimal(12,2), SUM( b.GoodsNum*d.Solid*12)*0.5) DayTotalSolidFee into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.orderid=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.ShopId=@shopid and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by d.GoodsId select a.GoodsId,ISNULL(a1.LR,0)-ISNULL(a2.DayTotalSolidFee,0) MonthHJLR from HW_GoodsInfo a left join #ls_1 a1 on a.GoodsId=a1.GoodsId left join #ls_2 a2 on a.GoodsId=a2.goodsid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 根据sku获取商品详情 public static HW_GoodsDetail GetGoodsDetailBySku(string sku) { var sql = "select top 1 DetailId,GoodsId from HW_GoodsDetail where SKU1=@sku or SKU2=@sku or SKU3=@sku or SKU4=@sku or SKU5=@sku or SKU6=@sku or SKU7=@sku or SKU8=@sku or SKU9=@sku or SKU10=@sku or SKU11=@sku or SKU12=@sku or SKU13=@sku"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sku", DbType.String, sku); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region 根据sku1获取商品详情 public static HW_GoodsDetail GetGoodsDetailBySku1(string sku1) { var sql = "select top 1 DetailId,GoodsId from HW_GoodsDetail where SKU1=@sku "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sku", DbType.String, sku1); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region 根据sku获取商品详情 public static GoodsInfoSizeModel GetGoodsInfoDetailBySku(string sku) { var sql = "select top 1 DetailId,a.GoodsId,a.SKU1,a.SKU14, b.Long2 Long,b.Width2 Width,b.Height2 Height,CAST( b.Weight2*0.0625 as decimal(12,2)) Weight from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where SKU1=@sku or SKU2=@sku or SKU3=@sku or SKU4=@sku or SKU5=@sku or SKU6=@sku or SKU7=@sku or SKU8=@sku or SKU9=@sku or SKU10=@sku or SKU11=@sku or SKU12=@sku or SKU13=@sku "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sku", DbType.String, sku); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region 更新或者新增店铺商品广告花费ShopGoodsAdFee public static bool UpdateOrInsertShopGoodsAdFee(ShopGoodsAdFeeModel md) { try { var sql = @"if (exists(select 1 from ShopGoodsAdFee where CONVERT(date,AdDate)=CONVERT(date,@AdDate) and ShopId=@ShopId and GoodSKU=@SKU and DetailId=@DetailId and GoodsId=@GoodsId)) begin update ShopGoodsAdFee set AdFee=@AdFee ,AdOrderCount=@AdOrderCount,AdSaleAmount=@AdSaleAmount where CONVERT(date,AdDate)=CONVERT(date,@AdDate) and ShopId=@ShopId and GoodSKU=@SKU and DetailId=@DetailId and GoodsId=@GoodsId end else begin insert into ShopGoodsAdFee(AdDate,ShopId,GoodSKU,DetailId, GoodsId,AdFee,AdOrderCount,AdSaleAmount,CreateTime) Values(@AdDate,@ShopId,@SKU,@DetailId,@GoodsId,@AdFee,@AdOrderCount,@AdSaleAmount,GetDate()) end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@AdDate", DbType.Date, md.AdDate); db.AddInParameter(cmd, "@ShopId", DbType.Int32, md.ShopId); db.AddInParameter(cmd, "@SKU", DbType.String, md.GoodSku); db.AddInParameter(cmd, "@DetailId", DbType.Int32, md.DetailId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, md.GoodsId); db.AddInParameter(cmd, "@AdFee", DbType.Decimal, md.AdFee); db.AddInParameter(cmd, "@AdOrderCount", DbType.Int32, md.AdOrderCount); db.AddInParameter(cmd, "@AdSaleAmount", DbType.Decimal, md.AdSaleAmount); db.ExecuteNonQuery(cmd); } catch (Exception ex) { return false; } return true; } #endregion #region 获取店铺商品每天的广告费 public static List GetShopGoodsAdFeeModel(int shopId, DateTime? sDate, DateTime? eDate, int pageIndex, int pageSize, out int rowCount) { var filt = " where 1=1 "; if (shopId != 0) { filt += " and a.ShopId=@shopId"; } if (sDate.HasValue) { filt += " and CONVERT(date,AdDate)>=@sDate"; } if (eDate.HasValue) { filt += " and CONVERT(date,AdDate)<=@eDate"; } var sql = " select count(1) count from ShopGoodsAdFee a " + filt; sql += " select * from (select ROW_NUMBER() over(order by AdDate desc) row, a.*,b.ShopName from ShopGoodsAdFee a left join JC_Shop b on a.ShopId=b.ShopId " + filt + " ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopId", DbType.Int32, shopId); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate); var ds = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(ds.Tables[0].Rows[0]["count"]); return ds.Tables[1].ToList(); } #endregion #region 根据组长id找到所有组员 public static List GetAllGroupPeopleDatas(int groupid) { var amaPeos = string.Join(",", AmazonGroupPeoples); var sql = "select * from JC_UserInfo where guserid=" + groupid + " and UserId!=" + groupid + " and UserId in (" + amaPeos + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取亚马逊平台人员管理商品净利润>0的数量所占的百分比 public static List GetAmazonPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--订单利润 select z.OrderId into #ls_4 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=2 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_1 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct OrderId from #ls_4 ) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(isnull( a.adfeenew,0)) AdFee into #ls_2 from AD_FeeList a inner join JC_Shop b on a.shopid=b.ShopId inner join HW_GoodsInfo c on a.goodsid=c.GoodsId where CONVERT(date,a.addate)>=@sDate and CONVERT(date,a.addate)<=@eDate and b.PlatType=2 and c.muserid in (69) group by a.goodsid --仓储费 select a.GoodsId,b.muserid, CONVERT(decimal(12,2),SUM(isnull(a.StockSolidNum,0)*0.5)) DayTotalSolidFee into #ls_3 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date,a.InDate)>=@sDate and CONVERT(date,a.InDate)<=@eDate and ISNULL(b.muserid,-1)!=-1 group by a.GoodsId,b.muserid select a.GoodsId,a.muserid UserId,ISNULL(b.LR,0)-ISNULL(c.AdFee,0)-ISNULL(a.DayTotalSolidFee,0) MonthHJLR from #ls_3 a left join #ls_1 b on a.GoodsId=b.GoodsId left join #ls_2 c on a.GoodsId=c.goodsid --SELECT -- muserid UserId, -- CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] --FROM -- (select a.GoodsId,a.muserid,ISNULL(b.LR,0)-ISNULL(c.AdFee,0)-ISNULL(a.DayTotalSolidFee,0) MonthHJLR from #ls_3 a left join #ls_1 b on a.GoodsId=b.GoodsId left join #ls_2 c on a.GoodsId=c.goodsid ) t --GROUP BY -- muserid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取EBay平台人员管理商品净利润>0的数量所占的百分比 public static List GetEBayPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--订单利润 select z.OrderId into #ls_1 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=3 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_2 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join (select distinct OrderId from #ls_1 ) f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId, SUM(ISNULL(a.AdFee,0)) AdFee into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=3 and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select t.GoodsId,t.UserId, CONVERT(decimal(12,2) ,SUM(t.StockSolidNum)*0.5) DayTotalSolidFee into #ls_4 from ( select a.GoodsId, a.guserid_ebay UserId, case when IsNull(StockNum,0)=0 then 0 when ISNULL(a.JYPrice,0)>200 then (StockSolidNum/StockNum)*2 else StockSolidNum*0.1 end StockSolidNum from HW_GoodsInfo a inner join PeopleDayStockSolid b on a.GoodsId=b.GoodsId where CONVERT(date,b.InDate)>=@sDate and CONVERT(date,b.InDate)<=@eDate and ISNULL(a.guserid_ebay,-1)!=-1 ) t group by t.GoodsId,UserId --select a.GoodsId,a.UserId,ISNULL(b.LR,0)-ISNULL(c.AdFee,0)-ISNULL(a.DayTotalSolidFee,0) MonthHJLR from #ls_4 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId SELECT UserId, CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] FROM (select a.GoodsId,a.UserId,ISNULL(b.LR,0)-ISNULL(c.AdFee,0)-ISNULL(a.DayTotalSolidFee,0) MonthHJLR from #ls_4 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId ) t GROUP BY UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shein平台人员管理商品净利润>0的数量所占的百分比 public static List GetSheinPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--每个订单未除去广告费和仓储费的利润 select g.GoodsId,a.ShopId, convert(decimal(12,2), Sum(IsNull(a.TotalPrice,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0))) as LR into #ls_1 from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId left join jc_shop e on d.ShopId=e.ShopId left join DT_OrderGoods f on a.OrderId=f.OrderId left join HW_GoodsDetail g on f.DetailId=g.DetailId where a.State>0 and a.State<3 and a.PlatId=21 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by g.GoodsId,a.ShopId --仓储费 --Shein库存费按照售卖订单商品的立方的12倍计算 select d.GoodsId,a.ShopId, convert(decimal(12,2), SUM( b.GoodsNum*d.Solid*12)*0.5) DayTotalSolidFee into #ls_2 from DT_OrderInfo a inner join DT_OrderGoods b on a.orderid=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.State>0 and a.State<3 and a.PlatId=21 and CONVERT(date,a.OrderDate)>=@sDate and CONVERT(date,a.OrderDate)<= @eDate group by d.GoodsId ,a.ShopId -- select a.GoodsId,a.ShopId UserId,ISNULL(b.LR,0)-ISNULL(a.DayTotalSolidFee,0) MonthHJLR from #ls_2 a left join #ls_1 b on a.GoodsId=b.GoodsId and a.ShopId=b.ShopId SELECT UserId, CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] FROM ( select a.GoodsId,a.ShopId UserId,ISNULL(b.LR,0)-ISNULL(a.DayTotalSolidFee,0) MonthHJLR from #ls_2 a left join #ls_1 b on a.GoodsId=b.GoodsId and a.ShopId=b.ShopId ) t GROUP BY UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Wlmart平台人员管理商品净利润>0的数量所占的百分比 public static List GetWlmartPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--订单利润 select z.OrderId into #ls_1 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=6 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_2 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join #ls_1 f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=6 and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select a.GoodsId,b.guserid_wlmart,SUM(ISNULL(a.StockSolidNum,0))*0.5*0.05 DayTotalSolidFee into #ls_4 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date, a.InDate)>=@sDate and CONVERT(date, a.InDate)<=@eDate and ISNULL(b.guserid_wlmart,-1)!=-1 group by a.GoodsId,b.guserid_wlmart --select a.GoodsId,a.guserid_wlmart UserId, ISNULL(b.LR,0)-ISNULL(a.DayTotalSolidFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_4 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId SELECT UserId, CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] FROM ( select a.GoodsId,a.guserid_wlmart UserId, ISNULL(b.LR,0)-ISNULL(a.DayTotalSolidFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_4 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId ) t GROUP BY UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Wayfair平台人员管理商品净利润>0的数量所占的百分比 public static List GetWayFairPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--订单利润 select z.OrderId into #ls_1 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=18 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_2 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join #ls_1 f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,SUM(ISNULL(a.AdFee,0)) AdFee into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=18 and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId --仓储费 select a.GoodsId,b.guserid_wayfair,SUM(ISNULL(a.StockSolidNum,0))*0.5*0.05 DayTotalSolidFee into #ls_4 from PeopleDayStockSolid a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where CONVERT(date, a.InDate)>=@sDate and CONVERT(date, a.InDate)<=@eDate and ISNULL(b.guserid_wayfair,-1)!=-1 group by a.GoodsId,b.guserid_wayfair --select a.GoodsId,a.guserid_wayfair UserId, ISNULL(b.LR,0)-ISNULL(a.DayTotalSolidFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_4 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId SELECT UserId,CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] FROM (select a.GoodsId,a.guserid_wayfair UserId, ISNULL(b.LR,0)-ISNULL(a.DayTotalSolidFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_4 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId ) t GROUP BY UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取Shopify平台人员管理商品净利润>0的数量所占的百分比 public static List GetShopifyPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--订单利润 select z.OrderId into #ls_1 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=15 and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_2 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join #ls_1 f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,b.ShopId, SUM(ISNULL(a.AdFee,0)) AdFee into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=15 and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId,b.ShopId ----仓储费 select GoodsId,SUM(ISNULL( StockSolidNum,0))*0.5 StockSolidNumFee into #ls_4 from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate group by GoodsId select * into #ls_5 from ( select GoodsId,83 ShopId,StockSolidNumFee*0.02 StockSolidNumFee from #ls_4 union all select GoodsId,56 ShopId,StockSolidNumFee*0.02 StockSolidNumFee from #ls_4 union all select GoodsId,61 ShopId,StockSolidNumFee*0.005 StockSolidNumFee from #ls_4 union all select GoodsId,88 ShopId,StockSolidNumFee*0.001 StockSolidNumFee from #ls_4 ) as t --select a.GoodsId,a.ShopId UserId, ISNULL(b.LR,0)-ISNULL(a.StockSolidNumFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_5 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId SELECT UserId, CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] FROM ( select a.GoodsId,a.ShopId UserId, ISNULL(b.LR,0)-ISNULL(a.StockSolidNumFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_5 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId ) t GROUP BY UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取TikTok平台人员管理商品净利润>0的数量所占的百分比 public static List GetTikTokPeopleGoodsHJLRPercentList(DateTime sdt, DateTime edt) { var sql = @"--订单利润 select z.OrderId into #ls_1 from DT_OrderInfo z with(nolock) inner join DT_OrderGoods y with(nolock) on z.OrderId=y.OrderId inner join HW_GoodsDetail x with(nolock) on y.DetailId=x.DetailId inner join HW_GoodsInfo w with(nolock) on x.GoodsId=w.GoodsId where z.State>0 and z.State<3 and PlatId=22 and z.ShopId in (85) and CONVERT(date,z.OrderDate)>=@sDate and CONVERT(date,z.OrderDate)<=@eDate select c.GoodsId ,CONVERT(decimal(12,2), SUM(a.LR)) LR into #ls_2 from ( select f.OrderId, (IsNull(a.TotalPrice,0)-IsNull(c.yj,0)-IsNull(a.escrowFee,0)-CONVERT(decimal(12,2),(IsNull(c.cb,0)/c.moneyrate))-CONVERT(decimal(12,2),(IsNull(c.hwsf,0)/c.moneyrate))-IsNull(c.yf,0)- (case when ISNULL(c.tc,0)<=0 then IsNull(c.tc,0) else c.tc end)-IsNull(d.FactPrice,0)-IsNull(d.PostFee,0)-IsNull(c.md,0)-IsNull(a.DR_BackFee,0)-IsNull(a.DR_PostFee,0)-IsNull(a.DR_SSFee,0)+ IsNull(c.SubsidyFee,0)) as LR from DT_OrderInfo a with(nolock) left join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId left join DT_Fees c with(nolock) on a.OrderId=c.orderid left join DT_OrderBackMoneyApply d on a.OrderId=d.OrderId inner join #ls_1 f on a.OrderId=f.OrderId ) a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId group by c.GoodsId --广告费 select a.GoodsId,b.ShopId, SUM(ISNULL(a.AdFee,0)) AdFee into #ls_3 from ShopGoodsAdFee a inner join JC_Shop b on a.ShopId=b.ShopId inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId where b.PlatType=22 and CONVERT(date,AdDate)>=@sDate and CONVERT(date,AdDate)<=@eDate group by a.GoodsId,b.ShopId ----仓储费 select GoodsId,SUM(ISNULL( StockSolidNum,0))*0.5 StockSolidNumFee into #ls_4 from PeopleDayStockSolid where CONVERT(date,InDate)>=@sDate and CONVERT(date,InDate)<=@eDate group by GoodsId select * into #ls_5 from ( select GoodsId,85 ShopId,StockSolidNumFee*0.02 StockSolidNumFee from #ls_4 ) as t SELECT UserId, CONVERT(decimal(12,2), COUNT(CASE WHEN monthHJLR > 0 THEN 1 END) * 100.0 / COUNT(goodsid)) AS [Percent] FROM ( select a.GoodsId,a.ShopId UserId, ISNULL(b.LR,0)-ISNULL(a.StockSolidNumFee,0)-ISNULL(c.AdFee,0) MonthHJLR from #ls_5 a left join #ls_2 b on a.GoodsId=b.GoodsId left join #ls_3 c on a.GoodsId=c.GoodsId ) t GROUP BY UserId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sDate", DbType.Date, sdt); db.AddInParameter(cmd, "@eDate", DbType.Date, edt); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 退货运单号临时记录表 public static OrderReturnTrackingId GetOrderReturnTrackingId(string code) { var sql = @"select top 1 * from OrderReturnTrackingId where TrackingId=@code"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@code", DbType.String, code); var dt = db.ExecuteDataTable(cmd); return dt.Rows[0].ToModel(); } #endregion #region 新增退货运单号临时记录表(PDA扫描人员使用) public static bool AddOrderReturnTrackingIdForScan(string code, int? userid, string wareHouse) { var sql = @"if(not exists(select 1 from OrderReturnTrackingId where TrackingId=@code)) begin insert into OrderReturnTrackingId(TrackingId,InType,CreateTime,UserId,WareHouse) values(@code,0,GETDATE(),@userid,@wareHouse); end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@code", DbType.String, code); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@wareHouse", DbType.String, wareHouse); return db.ExecuteNonQuery(cmd) >= 1; } public static int AddOrderReturnTrackingIdForScanReturnID(string code, string scanCode, int? userid, string wareHouse) { var sql = @"if(not exists(select 1 from OrderReturnTrackingId where TrackingId=@code and ScanTrackingId=@scanCode)) begin insert into OrderReturnTrackingId(TrackingId,InType,CreateTime,UserId,WareHouse,ScanTrackingId) values(@code,0,GETDATE(),@userid,@wareHouse,@scanCode); SELECT @@IDENTITY AS ID; end else select Top 1 ID from OrderReturnTrackingId where TrackingId=@code "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@code", DbType.String, code); db.AddInParameter(cmd, "@scanCode", DbType.String, scanCode); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@wareHouse", DbType.String, wareHouse); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return Convert.ToInt32(dt.Rows[0]["ID"]); } else return 0; } public static int UploadPhotoOrderReturnTrackingId(int id, string photo) { var sql = @"if(exists(select 1 from OrderReturnTrackingId where ID=@id)) begin update OrderReturnTrackingId set Photo=@Photo where ID=@id select 1 as ID end else begin select 0 as ID end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Photo", DbType.String, photo); db.AddInParameter(cmd, "@id", DbType.Int32, id); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return Convert.ToInt32(dt.Rows[0]["ID"]); } else return 0; } public static DT_OrderReturn GetDT_OrderReturnByTrackId(string code, string code2) { var sql = @" select top 1 * from DT_OrderReturn where tracking_id=@code or tracking_id=@code2 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@code", DbType.String, code); db.AddInParameter(cmd, "@code2", DbType.String, code2); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region 获取临时退货运单列表 public static List GetAllOrderReturnTrackingId(string code, int searchType, int inType, int pageIndex, int pageSize, out int rowCount) { var filt = " where 1=1 "; if (!string.IsNullOrEmpty(code)) { if (searchType == 0)//TrackingId { filt += " and TrackingId like '%" + code + "%'"; } else if (searchType == 1) //OrderCode { filt += " and OrderCode like '%" + code + "%'"; } else if (searchType == 2) //SKU { filt += " and SKU like '%" + code + "%'"; } } if (inType == 0) //未同步 { filt += " and InType=0 "; } else if (inType == 1) //已同步 { filt += " and InType=1 "; } var sql = @"select COUNT(1) count from OrderReturnTrackingId " + filt; sql += @" select * from ( select ROW_NUMBER() over( order by CreateTime desc) row,a.ID, TrackingId,OrderCode,SKU,ReturnNum,InType,a.CreateTime,a.UserId,b.Name,a.WareHouse,a.Photo,a.ScanTrackingId from OrderReturnTrackingId a left join JC_UserInfo b on a.UserId=b.UserId " + filt + " ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion #region 新增/修改退货运单号临时记录表 public static bool InsertOrderReturnTrackingId(OrderReturnTrackingId md) { var sql = ""; if (md.ID == 0) { sql = " insert into OrderReturnTrackingId(TrackingId,OrderCode,SKU,ReturnNum,InType,CreateTime,UserId,WareHouse) Values(@TrackingId,@OrderCode,@SKU,@ReturnNum,@InType,GetDate(),@UserId,@WareHouse)"; } else { sql = " Update OrderReturnTrackingId set TrackingId=@TrackingId , OrderCode=@OrderCode,SKU=@SKU,ReturnNum=@ReturnNum,InType=@InType ,WareHouse=@WareHouse where ID=@ID"; } // var sql = @"if(exists(select 1 from OrderReturnTrackingId where TrackingId=@TrackingId)) // begin // Update OrderReturnTrackingId set OrderCode=@OrderCode,SKU=@SKU,ReturnNum=@ReturnNum,InType=@InType ,WareHouse=@WareHouse where TrackingId=@TrackingId // end //else // begin // insert into OrderReturnTrackingId(TrackingId,OrderCode,SKU,ReturnNum,InType,CreateTime,UserId,WareHouse) Values(@TrackingId,@OrderCode,@SKU,@ReturnNum,@InType,GetDate(),@UserId,@WareHouse) // end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.AddInParameter(cmd, "@TrackingId", DbType.String, md.TrackingId); db.AddInParameter(cmd, "@OrderCode", DbType.String, md.OrderCode); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@ReturnNum", DbType.Int32, md.ReturnNum); db.AddInParameter(cmd, "@InType", DbType.Int32, md.InType); db.AddInParameter(cmd, "@UserId", DbType.Int32, md.InType); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); return db.ExecuteNonQuery(cmd) >= 1; } #endregion #region public static bool DeleteOrderReturnTrackingId(int id) { var sql = @" delete from OrderReturnTrackingId where ID=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); return db.ExecuteNonQuery(cmd) >= 1; } #endregion #region public static JC_UserInfoNew GetUserInfoByUserId(int userid) { var sql = @" select top 1 * from JC_UserInfo where UserId=@userid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) return dt.Rows[0].ToModel(); else return null; } #endregion #region 发货检验流程代码 public static List GetOrderPostInfoDatas(string searchCode, int searchType, string wareHouse, int postState, int printState, DateTime? sDate, DateTime? eDate, int PageSize, int PageIndex, out int rowCount) { var filt = " where 1=1"; if (!string.IsNullOrEmpty(searchCode)) { if (searchType == 1)//OrderCode { filt += " and OrderCode like '%" + searchCode + "%'"; } else if (searchType == 2)//SKU { filt += " and SKU Like '%" + searchCode + "%'"; } else if (searchType == 3)//LocationCode { filt += " and LocationCode like '%" + searchCode + "%'"; } else if (searchType == 4)//TrackCode { filt += " and TrackCode like '%" + searchCode + "%'"; } } if (!string.IsNullOrEmpty(wareHouse)) { filt += " and WareHouse='" + wareHouse + "'"; } if (postState >= 0) { filt += " and PostState=" + postState; } if (printState >= 0) { filt += " and PrintState=" + printState; } if (sDate.HasValue) { filt += " and Convert(date,PostDate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "'"; } if (eDate.HasValue) { filt += " and Convert(date,PostDate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "'"; } var sql = @" select COUNT(*) count from OrderPostInfo " + filt; sql += @" select * from ( select ROW_NUMBER() over(order by PostDate desc) row, * from OrderPostInfo " + filt + " ) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } public static void SaveOrderPostInfo(OrderPostInfo md) { var sql = @" if @ID>0 begin Update OrderPostInfo set WareHouse=@WareHouse,PostDate=@PostDate,OrderCode=@OrderCode,SKU=@SKU,NewSKU=@NewSKU,Qty=@Qty,LocationCode=@LocationCode,TrackCode=@TrackCode,PostState=@PostState,PostQty=@PostQty,PrintState=@PrintState,Remark=@Remark where ID=@ID end else begin Insert into OrderPostInfo(WareHouse,PostDate,OrderCode,SKU,NewSKU,Qty,LocationCode,TrackCode,PostState,PostQty,PrintState,Remark,CreateTime) values(@WareHouse,@PostDate,@OrderCode,@SKU,@NewSKU,@Qty,@LocationCode,@TrackCode,@PostState,@PostQty,@PrintState,@Remark,GETDATE()) end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@PostDate", DbType.DateTime, md.PostDate); db.AddInParameter(cmd, "@OrderCode", DbType.String, md.OrderCode); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@NewSKU", DbType.String, md.NewSKU); db.AddInParameter(cmd, "@Qty", DbType.Int32, md.Qty); db.AddInParameter(cmd, "@LocationCode", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, md.TrackCode); db.AddInParameter(cmd, "@PostState", DbType.Int32, md.PostState); db.AddInParameter(cmd, "@PostQty", DbType.Int32, md.PostQty); db.AddInParameter(cmd, "@PrintState", DbType.Int32, md.PrintState); db.AddInParameter(cmd, "@Remark", DbType.String, md.Remark); db.ExecuteNonQuery(cmd); } public static void DeleteOrderPostInfo(int id) { var sql = @" Delete from OrderPostInfo where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, id); db.ExecuteNonQuery(cmd); } public static void DeleteOrderPostInfoForIDs(string ids) { var sql = @" Delete from OrderPostInfo where ID in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } public static List GetOrderPostInfoListByIds(string ids, string warehouse) { var sql = @"select a.ID, a.OrderCode, a.NewSKU,a.SKU,a.Qty, LocationCode from OrderPostInfo a left join CK_StorePostion b on a.LocationCode=b.PostionCode where a.WareHouse='" + warehouse + "' and a.ID in (" + ids + ") order by b.PostionCode,b.SortNo"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 更新发货订单到打印中状态,已打印完成的状态不更改 /// /// public static void UpdateOrderPostInfoToPrinting(string ids) { var sql = @" update OrderPostInfo set PrintState=1 where PrintState=0 and ID in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } /// /// 删除仓库当天生成的拣货单 /// /// public static void DeleteAllPickGoodsList(string warehouse) { var sql = @"delete from PickGoodsInfo where WareHouse=@warehouse and CONVERT(date,InDate)=CONVERT(date,GETDATE())"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@warehouse", DbType.String, warehouse); db.ExecuteNonQuery(cmd); } /// /// 根据条件获取导出拣货单数据 /// /// /// /// /// /// /// /// /// public static List GetOrderPostInfoDatasBySearch(string searchCode, int searchType, string wareHouse, int postState, int printState, DateTime? sDate, DateTime? eDate) { var filt = " where 1=1"; if (!string.IsNullOrEmpty(searchCode)) { if (searchType == 1)//OrderCode { filt += " and a.OrderCode like '%" + searchCode + "%'"; } else if (searchType == 2)//SKU { filt += " and a.SKU Like '%" + searchCode + "%'"; } else if (searchType == 3)//LocationCode { filt += " and a.LocationCode like '%" + searchCode + "%'"; } else if (searchType == 4)//TrackCode { filt += " and a.TrackCode like '%" + searchCode + "%'"; } } if (!string.IsNullOrEmpty(wareHouse)) { filt += " and a.WareHouse='" + wareHouse + "'"; } if (postState >= 0) { filt += " and a.PostState=" + postState; } if (printState >= 0) { filt += " and a.PrintState=" + printState; } if (sDate.HasValue) { filt += " and Convert(date,a.PostDate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "'"; } if (eDate.HasValue) { filt += " and Convert(date,a.PostDate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "'"; } filt += " order by b.PostionCode,b.SortNo"; var sql = @" select a.ID, a.OrderCode, a.NewSKU,a.SKU,a.Qty, LocationCode from OrderPostInfo a left join CK_StorePostion b on a.LocationCode=b.PostionCode " + filt; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 根据条件获取导出Temu平台拣货单数据 /// /// /// /// /// public static List GetTemuOrderPostInfoDatasBySearch(string wareHouse, DateTime? sDate, DateTime? eDate) { var filt = " where b.PlatId=23"; if (!string.IsNullOrEmpty(wareHouse)) { filt += " and a.WareHouse='" + wareHouse + "'"; } if (sDate.HasValue) { filt += " and Convert(date,a.PostDate)>='" + sDate.Value.ToString("yyyy-MM-dd") + "'"; } if (eDate.HasValue) { filt += " and Convert(date,a.PostDate)<='" + eDate.Value.ToString("yyyy-MM-dd") + "'"; } filt += " order by a.LocationCode "; var sql = @" select a.ID, a.OrderCode, a.NewSKU,a.SKU,a.Qty, LocationCode from OrderPostInfo a inner join DT_OrderInfo b on a.OrderCode=b.OrderCode " + filt; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetDT_TrackCodeApplyNewsByOrderCode(string orderCode) { var sql = @" select * from DT_TrackCodeApply where OrderCode=@orderCode and State=1"; Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderCode", DbType.String, orderCode); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetDT_TrackCodeApplyNewsByOrderId(int orderid) { var sql = @" select * from DT_TrackCodeApply where orderid=@orderid and State=1"; Database db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 获取托盘数据 /// /// public static List GetTrayInfoDatas(DateTime? inDate, int userid, int logUserid, string code, string wareHouse, int state, int PageIndex, int PageSize, out int rowCount) { var filt = "where 1=1 "; if (inDate.HasValue) { filt += " and Convert(date,a.InDate)='" + inDate.Value.Date + "'"; } if (logUserid == 1 || logUserid == 103 || logUserid == 176) //admin ,Eddie,Nicolas可以看到全部的条形码 { if (userid != 0) { filt += " and TrayUserId=" + userid; } } else { filt += " and TrayUserId=" + logUserid; } if (!string.IsNullOrEmpty(code)) { filt += " and TrayCode like '%" + code + "%'"; } if (!string.IsNullOrEmpty(wareHouse)) { filt += " and WareHouse ='" + wareHouse + "'"; } if (state > -1) { filt += " and PrintState=" + state; } var sql = @" select COUNT(*) count from TrayInfo a " + filt; sql += @" select * from ( select ROW_NUMBER() over(order by a.InDate desc, Sort ) row,a.ID,Convert(date,a.InDate) InDate, TrayCode,WareHouse ,PrintState,a.Sort, b.Name from TrayInfo a left join JC_UserInfo b on a.TrayUserId=b.UserId " + filt + ") t where t.row Between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } public static void DeleteTrayInfo(int id) { var sql = @" Delete from TrayInfo where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, id); db.ExecuteNonQuery(cmd); } public static void SaveTrayInfo(TrayInfo md) { var sql = @" if @ID>0 begin update TrayInfo set TrayCode=@TrayCode,WareHouse=@WareHouse,State=@State where ID=@ID end else begin if(not exists(select 1 from TrayInfo where WareHouse=@WareHouse and TrayCode=@TrayCode )) begin insert into TrayInfo(TrayCode,WareHouse,State,CreateTime) values(@TrayCode,@WareHouse,@State,GETDATE()) end end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@TrayCode", DbType.String, md.TrayCode); //db.AddInParameter(cmd, "@State", DbType.Int32, md.State); db.ExecuteNonQuery(cmd); } public static List GetTrayInfo(DateTime indate, int userid, string warehouse, int printState) { var sql = @"select ID,InDate,TrayCode,WareHouse,PrintState,TrayUserId,Sort from TrayInfo where CONVERT(date,InDate)=@InDate and WareHouse=@WareHouse and TrayUserId=@UserId and PrintState=@PrintState order by Sort"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@InDate", DbType.Date, indate.Date); db.AddInParameter(cmd, "@WareHouse", DbType.String, warehouse); db.AddInParameter(cmd, "@UserId", DbType.Int32, userid); db.AddInParameter(cmd, "@PrintState", DbType.Int32, printState); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 保存托盘商品数据 /// /// public static void SaveTrayGoodsInfo(TrayPickGoodsInfo md) { //var sql = @"insert into TrayPickGoodsInfo (TrayCode,SKU,WareHouse,LocationCode,PickQty,PickUserId,PickGoodsInfo_Id,CreateTime,NewSKU,PackGoodCode,PackGoodCode2) Values(@TrayCode,@SKU,@WareHouse,@LocationCode,@PickQty,@PickUserId,@PickGoodsInfo_Id,GetDate(),@NewSKU,@PackGoodCode,@PackGoodCode2) // update PickGoodsInfo set ScanQty=ScanQty+@PickQty where ID=@PickGoodsInfo_Id"; var sql = @"if(exists(select 1 from TrayPickGoodsInfo where TrayCode=@TrayCode and PickGoodsInfo_Id=@PickGoodsInfo_Id)) begin update TrayPickGoodsInfo set PickQty=PickQty+@PickQty where TrayCode=@TrayCode and PickGoodsInfo_Id=@PickGoodsInfo_Id end else begin insert into TrayPickGoodsInfo (TrayCode,SKU,WareHouse,LocationCode,PickQty,PickUserId,PickGoodsInfo_Id,CreateTime,NewSKU,PackGoodCode,PackGoodCode2) Values(@TrayCode,@SKU,@WareHouse,@LocationCode,@PickQty,@PickUserId,@PickGoodsInfo_Id,GetDate(),@NewSKU,@PackGoodCode,@PackGoodCode2) end update PickGoodsInfo set ScanQty=ScanQty+@PickQty where ID=@PickGoodsInfo_Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@TrayCode", DbType.String, md.TrayCode); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@LocationCode", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@PickQty", DbType.Int32, md.PickQty); db.AddInParameter(cmd, "@PickUserId", DbType.Int32, md.PickUserId); db.AddInParameter(cmd, "@PickGoodsInfo_Id", DbType.Int32, md.PickGoodsInfo_Id); db.AddInParameter(cmd, "@NewSKU", DbType.String, md.NewSKU); db.AddInParameter(cmd, "@PackGoodCode", DbType.String, md.PackGoodCode); db.AddInParameter(cmd, "@PackGoodCode2", DbType.String, md.PackGoodCode2); db.ExecuteNonQuery(cmd); } /// /// 获取拣货工已生成的托盘列表 /// /// /// public static List GetUserPickTrayList(int userid, DateTime indate) { var sql = @" select a.ID, a.TrayCode,SUM(ISNULL( b.PickQty,0)) PickQty from TrayInfo a inner join TrayPickGoodsInfo b on a.TrayCode=b.TrayCode where CONVERT(date,InDate)=@indate and TrayUserId=@userid group by a.ID,a.TrayCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@indate", DbType.Date, indate); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 删除托盘中的商品信息 /// /// public static void DeleteTrayPickGoodsInfo(string ids) { var sql = @" update a set a.ScanQty=case when a.ScanQty<=b.PickQty then 0 else a.ScanQty-b.PickQty end from PickGoodsInfo a inner join TrayPickGoodsInfo b on a.ID=b.PickGoodsInfo_Id where b.ID in (" + ids + ") delete from TrayPickGoodsInfo where ID in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } /// /// 获取个人拣货商品信息 /// /// /// /// /// public static List GetPickGoodsInfo(int userid, DateTime InDate) { var sql = @"select ID,InDate,WareHouse,NewSKU,SKU,PickQty,ScanQty,LocationCode,PickUserId,PackGoodCode,PackGoodCode2 ,ISNULL( b.KCNum,0) KCNum from PickGoodsInfo a left join (select c.SKU1,b.PostionCode, SUM(ISNULL(a.KCNum,0)) KCNum from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where OrderGoodsId=0 and KCNum>= 0 group by c.SKU1, b.PostionCode) b on a.LocationCode=b.PostionCode and a.SKU=b.SKU1 where PickUserId=@userid and CONVERT(date,InDate)=@indate order by LocationCode"; //var sql = @"select ID,InDate,WareHouse,NewSKU,SKU,PickQty,ScanQty,LocationCode,PickUserId,PackGoodCode,PackGoodCode2 from PickGoodsInfo where PickUserId=@userid and CONVERT(date,InDate)=@indate order by LocationCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@indate", DbType.Date, InDate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetPickGoodsInfo2(int userid, DateTime InDate) { var sql = @"select ID,InDate,WareHouse,NewSKU,SKU,PickQty,ScanQty,LocationCode,PickUserId,PackGoodCode,PackGoodCode2 ,ISNULL( b.KCNum,0) KCNum from PickGoodsInfo a left join (select c.SKU1,b.PostionCode, SUM(ISNULL(a.KCNum,0)) KCNum from HW_GoodsInDetail a inner join CK_StorePostion b on a.PostionId=b.PostionId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where OrderGoodsId=0 and KCNum>= 0 group by c.SKU1, b.PostionCode) b on a.LocationCode=b.PostionCode and a.SKU=b.SKU1 where PickUserId=@userid and CONVERT(date,InDate)=@indate ORDER BY CASE WHEN LocationCode LIKE '%B%' THEN 1 WHEN LocationCode LIKE '%C%' THEN 2 WHEN LocationCode LIKE '%D%' THEN 3 ELSE 4 END, LocationCode; "; //var sql = @"select ID,InDate,WareHouse,NewSKU,SKU,PickQty,ScanQty,LocationCode,PickUserId,PackGoodCode,PackGoodCode2 from PickGoodsInfo where PickUserId=@userid and CONVERT(date,InDate)=@indate ORDER BY CASE WHEN LocationCode LIKE '%B%' THEN 1 WHEN LocationCode LIKE '%C%' THEN 2 WHEN LocationCode LIKE '%D%' THEN 3 ELSE 4 END, LocationCode; "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.AddInParameter(cmd, "@indate", DbType.Date, InDate.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 新增托盘码,同一个仓库的托盘码不允许重复 /// /// public static void AddTrayInfo(TrayInfo md) { var sql = @" declare @sort int select @sort=ISNULL(MAX(Sort),0)+1 from TrayInfo where CONVERT(date,InDate)=@InDate and WareHouse=@WareHouse select @sort declare @code nvarchar(20) set @code=@WareHouse+Convert(nvarchar(12),@InDate,112) if(@sort>0 and @sort<10) set @code=@code+'00'+CONVERT(nvarchar(10),@sort) else if(@sort>=10 and @sort<100) set @code=@code+'0'+CONVERT(nvarchar(10),@sort) else if(@sort>=100 and @sort<1000) set @code=@code+CONVERT(nvarchar(10),@sort) else set @code=@code+CONVERT(nvarchar(10),@sort) insert into TrayInfo (InDate,TrayCode,WareHouse,PrintState,TrayUserId,Sort,CreateTime) values(@InDate,@code,@WareHouse,@PrintState,@TrayUserId,@sort,GetDate()) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@InDate", DbType.Date, md.InDate.Date); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@PrintState", DbType.Int32, md.PrintState); db.AddInParameter(cmd, "@TrayUserId", DbType.Int32, md.TrayUserId); db.ExecuteNonQuery(cmd); } /// /// 更新托盘码为已打印状态 /// /// public static void UpdateTrayInfo(int id) { var sql = @" Update TrayInfo set PrintState=1 where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, id); db.ExecuteNonQuery(cmd); } /// /// 获取需要匹配SKU,和库位的拣货商品 /// /// /// /// /// /// /// public static PickGoodsInfo GetPickGoodsInfoById(int id) { var sql = @"select top 1 ID,InDate,WareHouse,NewSKU,SKU,ISNULL( PickQty,0) PickQty,ISNULL(ScanQty,0) ScanQty,LocationCode,PickUserId from PickGoodsInfo where ID=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } return null; } /// /// 获取需要匹配SKU,和库位的拣货商品 /// /// /// /// /// /// /// public static PickGoodsInfo GetPickGoodsInfoModelById(int id) { var sql = @"select * from PickGoodsInfo where ID=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } return null; } /// /// 获取托盘内的所有拣货商品信息 /// /// /// public static List GetTrayPickGoodsInfoList(string trayCode) { var sql = @"select ID,TrayCode,SKU,WareHouse,LocationCode,PickQty,PickUserId,PickGoodsInfo_Id,NewSKU,PackGoodCode,PackGoodCode2 from TrayPickGoodsInfo where TrayCode=@trayCode order by ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trayCode", DbType.String, trayCode); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 获取每天拣货列表数量 /// /// /// /// /// /// /// /// /// public static List GetPickGoodsInfosData(DateTime? inDate, string wareHouse, string SKU, int userid, int PageIndex, int PageSize, out int rowCount) { var filt = " where 1=1"; if (inDate.HasValue) { filt += " and CONVERT(date,a.InDate)='" + inDate.Value.Date + "'"; } if (!string.IsNullOrEmpty(wareHouse)) { filt += " and WareHouse='" + wareHouse + "'"; } if (!string.IsNullOrEmpty(SKU)) { filt += " and SKU like '%" + SKU + "%'"; } if (userid > 0) { filt += " and a.PickUserId=" + userid; } var sql = @" select COUNT(1) count from PickGoodsInfo a " + filt; sql += @" select * from ( select ROW_NUMBER() over(order by LocationCode) row, a.ID,CONVERT(date, a.InDate) InDate,WareHouse,NewSKU,SKU,ISNULL( PickQty,0) PickQty,ISNULL(ScanQty,0) ScanQty,LocationCode,PickUserId,b.Name from PickGoodsInfo a left join JC_UserInfo b on a.PickUserId=b.UserId " + filt + " ) t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } /// /// 删除拣货列表 /// /// public static void DeletePickGoodsInfoForIds(string ids) { var sql = @"delete from PickGoodsInfo where ID in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } /// /// 获取美国拣货工列表 /// /// public static List GetPickUserDatas() { var sql = @" select * from JC_UserInfo where DeptId=30 and State=1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); return db.ExecuteDataTable(cmd).ToList(); } /// /// 获取托盘拣货打印数据 /// /// /// public static List GetTrayGoodsDetailPrintDatas(string trayCode) { var sql = @"select a.ID,a.TrayCode,a.SKU,a.WareHouse,a.LocationCode,IsNull(a.PickQty,0) PickQty,IsNull( b.PrintQty,0) PrintQty,NewSKU,PackGoodCode,PackGoodCode2 from TrayPickGoodsInfo a left join (select TrayCode, SKU,WareHouse,LocationCode,SUM(IsNull(PrintQty,0)) PrintQty from TrayPrintGoodsInfo where TrayCode=@trayCode group by TrayCode, SKU,WareHouse,LocationCode) b on a.TrayCode=b.TrayCode and a.SKU=b.SKU and a.LocationCode=b.LocationCode where a.TrayCode=@trayCode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trayCode", DbType.String, trayCode); return db.ExecuteDataTable(cmd).ToList(); } /// /// 新增拣货列表数据 /// /// public static void SavePickGoodsInfoData(PickGoodsInfo md) { var sql = @" if(exists(select 1 from PickGoodsInfo where CONVERT(date,InDate)=CONVERT(date,@InDate) and WareHouse=@WareHouse and SKU=@SKU and LocationCode=@LocationCode and PickUserId=@PickUserId )) begin Update PickGoodsInfo set PickQty=ISNULL(PickQty,0)+@PickQty where CONVERT(date,InDate)=CONVERT(date,@InDate) and WareHouse=@WareHouse and SKU=@SKU and LocationCode=@LocationCode and PickUserId=@PickUserId end else begin insert into PickGoodsInfo (InDate,WareHouse,NewSKU,SKU,PickQty,ScanQty,LocationCode,PickUserId,CreateTime,PackGoodCode,PackGoodCode2) values(@InDate,@WareHouse,@NewSKU,@SKU,@PickQty,0,@LocationCode,@PickUserId,GETDATE(),@PackGoodCode,@PackGoodCode2) end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@InDate", DbType.Date, md.InDate.Date); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@NewSKU", DbType.String, md.NewSKU); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@PickQty", DbType.Int32, md.PickQty); db.AddInParameter(cmd, "@LocationCode", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@PickUserId", DbType.Int32, md.PickUserId); db.AddInParameter(cmd, "@PackGoodCode", DbType.String, md.PackGoodCode); db.AddInParameter(cmd, "@PackGoodCode2", DbType.String, md.PackGoodCode2); db.ExecuteNonQuery(cmd); } /// /// 根据sku获取货物的包装箱条码 /// /// /// public static SKUPackCodeModel GetGoodsPackCodeBySKU(string sku) { var sql = @"select top 1 a.GoodsId,GoodsCode,a.GoodsOldCode,a.BoxRate,b.TypeCode,IsNull( Barcode,'') Barcode from HW_GoodsInfo a inner join HW_GoodsDetail b on a.GoodsId=b.GoodsId where b.SKU1=@sku"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sku", DbType.String, sku); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } return null; } /// /// 获取用户当天拣货体积总立方 /// /// /// /// public static decimal GetUserPickGoodsTotalSolid(DateTime indate, int userid) { var sql = @" select Convert(decimal(12,2), ISNULL(SUM(ISNULL(PickQty,0)* ISNULL(c.Solid,0)),0)) TotalSolid from PickGoodsInfo a left join HW_GoodsDetail b on a.SKU=b.SKU1 or a.SKU=b.SKU2 or a.SKU=b.SKU3 or a.SKU=b.SKU4 left join HW_GoodsInfo c on b.GoodsId=c.GoodsId where CONVERT(date,a.InDate)=CONVERT(date,@InDate) and PickUserId=@userid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@InDate", DbType.Date, indate.Date); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); return Convert.ToDecimal(db.ExecuteScalar(cmd)); } /// /// 将拣货数据转给其他人 /// /// /// public static void TransferPickGoodsInfoDataToUser(string ids, int userid) { var sql = @" update PickGoodsInfo set PickUserId=" + userid + " where ID in (" + ids + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.ExecuteNonQuery(cmd); } /// /// 将拣货数据转给其他人 /// /// /// public static void TransferPickGoodsInfoDataToUserNew(PickGoodsInfo md, int userid) { var sql = @" declare @eid int set @eid=(select top 1 ID from PickGoodsInfo where CONVERT(date, InDate)=@InDate and WareHouse=@WareHouse and SKU=@SKU and LocationCode=@LocationCode and PickUserId=@PickUserId) if(ISNULL(@eid,0)!=0) begin Update PickGoodsInfo set PickQty=PickQty+@PickQty where ID=@eid end else begin insert into PickGoodsInfo (InDate,WareHouse,NewSKU,SKU,PickQty,ScanQty,LocationCode,PickUserId,CreateTime,PackGoodCode,PackGoodCode2) values(@InDate,@WareHouse,@NewSKU,@SKU,@PickQty,0,@LocationCode,@PickUserId,getdate(),@PackGoodCode,@PackGoodCode2) end delete from PickGoodsInfo where ID=@ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.AddInParameter(cmd, "@InDate", DbType.Date, md.InDate.Date); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@NewSKU", DbType.String, md.NewSKU); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@PickQty", DbType.Int32, md.PickQty); db.AddInParameter(cmd, "@ScanQty", DbType.Int32, md.ScanQty); db.AddInParameter(cmd, "@LocationCode", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@PickUserId", DbType.Int32, userid); db.AddInParameter(cmd, "@PackGoodCode", DbType.String, md.PackGoodCode); db.AddInParameter(cmd, "@PackGoodCode2", DbType.String, md.PackGoodCode2); db.ExecuteNonQuery(cmd); } /// /// 获取托盘码所属人员userid /// /// /// public static int GetTrayCodeBelongUserid(string trayCode) { var sql = @" select TrayUserId from TrayInfo where TrayCode=@trayCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trayCode", DbType.String, trayCode); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return (int)dt.Rows[0]["TrayUserId"]; } else return 0; } /// /// 获取托盘码数据 /// /// /// public static TrayInfo GetTrayCodeInfo(string trayCode) { var sql = @" select top 1 * from TrayInfo where TrayCode=@trayCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trayCode", DbType.String, trayCode); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } /// /// 根据商品匹配订单和未打印的跟踪码 /// /// public static MatchTrackingCodeModel MatchGoodsTrackingCode(string filt, string wareHouse, DateTime nowDate) { var sql = @" select top 1 a.ID OrderPostInfoID,a.OrderCode,a.Qty PickQty,a.PostQty ,b.Id TrackCodeApplyID,b.PostId,c.Name ExpressName, b.TrackCode,b.OrderId,b.LabelUrl,b.SKU as QtySKU from OrderPostInfo a inner join DT_TrackCodeApply b on a.OrderCode=b.OrderCode inner join JC_Express c on b.PostId=c.ExpressID where Convert(date,a.PostDate)='" + nowDate.Date + "' and a.PrintState=1 and b.State=1 and IsNull(b.LabelUrl,'')<>'' and IsNull(b.TrackPrintState,0)=0 and a.WareHouse='" + wareHouse + "' " + filt + " order by a.PostDate desc,b.[GetDate] desc"; //var sql = @" select top 1 a.ID OrderPostInfoID,a.OrderCode,a.Qty PickQty,a.PostQty ,b.Id TrackCodeApplyID,b.PostId,c.Name ExpressName, b.TrackCode,b.OrderId,b.LabelUrl,b.SKU as QtySKU from OrderPostInfo a inner join DT_TrackCodeApply b on a.OrderCode=b.OrderCode inner join JC_Express c on b.PostId=c.ExpressID where a.PrintState=1 and b.State=1 and IsNull(b.LabelUrl,'')<>'' and IsNull(b.TrackPrintState,0)=0 and a.WareHouse='" + wareHouse + "' " + filt + " order by a.PostDate desc,b.[GetDate] desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } /// /// 查询推荐可能想要匹配的跟踪码 /// /// public static List MatchGoodsTrackingCodeTJ(string filt, string wareHouse, DateTime nowDate) { var sql = @"select b.TrackCode,b.SKU as QtySKU from OrderPostInfo a inner join DT_TrackCodeApply b on a.OrderCode=b.OrderCode inner join JC_Express c on b.PostId=c.ExpressID where Convert(date,a.PostDate)='" + nowDate.Date + "' and a.PrintState=1 and b.State=1 and IsNull(b.TrackPrintState,0)=0 and a.WareHouse='" + wareHouse + "' " + filt + " group by b.TrackCode,b.SKU"; //var sql = @"select b.TrackCode,b.SKU as QtySKU from OrderPostInfo a inner join DT_TrackCodeApply b on a.OrderCode=b.OrderCode inner join JC_Express c on b.PostId=c.ExpressID where a.PrintState=1 and b.State=1 and IsNull(b.TrackPrintState,0)=0 and a.WareHouse='" + wareHouse + "' " + filt + " group by b.TrackCode,b.SKU"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 根据sku获取编码 /// /// /// public static string GetGoodsCodeBySKU(string sku) { var sql = @"select b.GoodsId,GoodsCode,GoodsOldCode, SKU1 from HW_GoodsDetail a inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId where SKU1=@sku"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sku", DbType.String, sku); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0]["GoodsCode"].ToString(); } else return ""; } /// /// 保存托盘已打印面单商品表 /// /// public static void SaveTrayPrintGoodsInfo(TrayPrintGoodsInfo md) { var sql = @" insert into TrayPrintGoodsInfo (TrayCode,SKU,WareHouse,LocationCode,PrintQty,PrintUserId,TrackingCode,CreateTime) values(@TrayCode,@SKU,@WareHouse,@LocationCode,@PrintQty,@PrintUserId,@TrackingCode,GetDate())"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@TrayCode", DbType.String, md.TrayCode); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@LocationCode", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@PrintQty", DbType.Int32, md.PrintQty); db.AddInParameter(cmd, "@PrintUserId", DbType.Int32, md.PrintUserId); db.AddInParameter(cmd, "@TrackingCode", DbType.String, md.TrackingCode); db.ExecuteNonQuery(cmd); } /// /// 根据订单号,sku,库位找寻还未发货完成的记录 /// /// /// /// /// public static List GetOrderPostInfoDatasForPrint(string orderCode, string sku) { var sql = @"select * from OrderPostInfo where OrderCode=@OrderCode and SKU=@SKU and Qty>ISNULL(PostQty,0) order by PostDate desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderCode", DbType.String, orderCode); db.AddInParameter(cmd, "@SKU", DbType.String, sku); return db.ExecuteDataTable(cmd).ToList(); } /// /// 更新订单的发货数量,发货状态,以及打印状态 /// /// public static void UpdateOrderPostInfo(OrderPostInfo md) { var sql = " update OrderPostInfo set PostQty=@PostQty,PostState=@PostState,PrintState=@PrintState where ID=@ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@PostQty", DbType.Int32, md.PostQty); db.AddInParameter(cmd, "@PostState", DbType.Int32, md.PostState); db.AddInParameter(cmd, "@PrintState", DbType.Int32, md.PrintState); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.ExecuteNonQuery(cmd); } /// /// 更新DT_TrackCodeApply表面单为已打印状态 /// /// public static void UpdateTrackCodeApplyPrintState(int id) { var sql = @" update DT_TrackCodeApply set TrackPrintState=1 where Id=@id update DT_TrackCodeApply set TrackPrintState=1 where TrackCode in ( select a.SonTrackCode from TrackCodeRelation a inner join DT_TrackCodeApply b on a.MainTrackCode =b.TrackCode where b.Id= @id )"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } /// /// 获取仓库库位拣货人数据 /// /// public static List GetPositionPickerDatas(string wareHouse, int PageIndex, int PageSize, out int rowCount) { var filt = "where 1=1 "; if (!string.IsNullOrEmpty(wareHouse)) { filt += " and a.WareHouse ='" + wareHouse + "'"; } var sql = @" select COUNT(*) count from StorePostionPicker a " + filt; sql += @" select * from ( select ROW_NUMBER() over(order by a.ID desc) row ,a.ID,a.WareHouse,a.PickType,a.TypeDesc,a.PickUserId,b.Name UserName from StorePostionPicker a left join JC_UserInfo b on a.PickUserId=b.UserId " + filt + ") t where t.row Between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } /// /// 保存仓库库位拣货人数据 /// /// public static int SavePositionPicker(StorePostionPicker md) { var sql = @" if(@id>0) begin if(exists(select 1 from StorePostionPicker where WareHouse=@WareHouse and PickType=@PickType and ID!=@id )) begin select 0; end else begin update StorePostionPicker set WareHouse=@WareHouse,PickType=@PickType,TypeDesc=@TypeDesc,PickUserId=@PickUserId where ID=@id select 1; end end else begin if(exists(select 1 from StorePostionPicker where WareHouse=@WareHouse and PickType=@PickType)) begin select 0; end else begin insert into StorePostionPicker(WareHouse,PickType,TypeDesc,PickUserId,CreateTime) values(@WareHouse,@PickType,@TypeDesc,@PickUserId,GetDate()) select 1; end end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, md.ID); db.AddInParameter(cmd, "@WareHouse", DbType.String, md.WareHouse); db.AddInParameter(cmd, "@PickType", DbType.Int32, md.PickType); db.AddInParameter(cmd, "@TypeDesc", DbType.String, md.TypeDesc); db.AddInParameter(cmd, "@PickUserId", DbType.Int32, md.PickUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } /// /// 删除仓库库位拣货人数据 /// /// public static void DeletePositionPicker(int id) { var sql = @" delete from StorePostionPicker where ID=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } /// /// /// /// /// public static List GetStorePostionPickers(string wareHouse) { var sql = @"select ID,WareHouse,PickType,TypeDesc,PickUserId from StorePostionPicker where WareHouse=@wareHouse"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@wareHouse", DbType.String, wareHouse); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// /// /// /// public static TrayMaxVolume GetTrayMaxVolumeDatas(string wareHouse) { var sql = @"select Top 1 ID,WareHouse,MaxVolume from TrayMaxVolume where WareHouse=@wareHouse"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@wareHouse", DbType.String, wareHouse); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } /// /// 获取快递跟踪码的快递名称 /// /// /// public static string GetTrackCodePostName(string trackCode) { var sql = @" select top 1 b.Name PostName from DT_TrackCodeApply a inner join JC_Express b on a.PostId =b.ExpressID where a.State=1 and (a.TrackCode=@trackCode or a.TrackCode2=@trackCode)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trackCode", DbType.String, trackCode); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0]["PostName"].ToString(); } else return ""; } /// /// 更新跟踪码图片名称 /// /// /// public static void UpdateTrackCodeImage(string trackCode, string labelUrl) { var sql = @" update DT_TrackCodeApply set LabelUrl=@LabelUrl where State=1 and (TrackCode=@trackCode or TrackCode2=@trackCode)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trackCode", DbType.String, trackCode); db.AddInParameter(cmd, "@LabelUrl", DbType.String, labelUrl); db.ExecuteNonQuery(cmd); } #region 导入跟踪码 public static int ImportTrackCode3(int PostId, string OrderCode, string TrackCode, string Name, string SKU) { string tsql = @" declare @OrderId int select @OrderId=OrderId from DT_OrderInfo where state<3 and state>0 and platOrderCode=@OrderCode if @OrderId>0 begin if(select count(0) from DT_TrackCodeApply where TrackCode=@TrackCode and state=1)=0 begin INSERT INTO [dbo].[DT_TrackCodeApply] ([PostId] ,[TrackType] ,[TrackCode] ,[TrackCode2] ,[GetDate] ,[InName] ,[OrderId] ,[State] ,[UpdateTime] ,[OrderCode] ,[OldPostFee] ,[ScanState] ,[ScanDate] ,[SKU]) values(@PostId,1,@TrackCode,null,getdate(),@Name,@OrderId,1,null,@OrderCode,null,0,null,@SKU) update DT_OrderXXInfo set PostError=null,TrackState=1,LogisticsId=10,Post=65 where OrderId=@OrderId update DT_OrderXXInfoNew set PostError=null,TrackState=1,LogisticsId=10,Post=65 where OrderId=@OrderId end select 1 end else begin select 0 end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PostId", DbType.Int32, PostId); db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode); db.AddInParameter(cmd, "@TrackCode", DbType.String, TrackCode); db.AddInParameter(cmd, "@Name", DbType.String, Name); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #endregion #region /// /// 获取退货单详情 /// /// /// /// public static List GetDT_OrderReturnDatas(string code1, string code2) { string sql = @"select * from DT_OrderReturn where tracking_id=@code1 or tracking_id=@code2"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@code1", DbType.String, code1); db.AddInParameter(cmd, "@code2", DbType.String, code2); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region /// /// 保存退货单详情 /// /// /// /// public static int SaveDT_OrderReturnDatas(OrderReturnBarcode md) { string sql = @" if( exists( select 1 from OrderReturnBarcode where TrackingCode=@trackingCode or TrackingCode2=@trackingCode2)) begin select 0; end else begin declare @sort int set @sort=(select Isnull(MAX(sort),0)+1 from OrderReturnBarcode) insert into OrderReturnBarcode (TrackingCode,TrackingCode2,SKUAndQty,LocationCode,Barcode,Sort,PrintState,DT_OrderReturn_id,ScanUserId, CreateTime) values(@trackingCode,@trackingCode2,@sku,@locationCode,'RP'+Convert(nvarchar(20),@sort),@sort,0,@orderReturn_id,@scanUserId, GetDate()) select 1; end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@trackingCode", DbType.String, md.TrackingCode); db.AddInParameter(cmd, "@trackingCode2", DbType.String, md.TrackingCode2); db.AddInParameter(cmd, "@sku", DbType.String, md.SKUAndQty); db.AddInParameter(cmd, "@locationCode", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@orderReturn_id", DbType.String, md.DT_OrderReturn_id); db.AddInParameter(cmd, "@scanUserId", DbType.Int32, md.ScanUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region /// /// 获取退货单详情 /// /// /// /// public static OrderReturnBarcode GetOrderReturnBarcodeDatas(string barcode) { string sql = @" select top 1 * from OrderReturnBarcode where Barcode=@barcode"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@barcode", DbType.String, barcode); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region /// /// 获取退货单详情 /// /// /// /// public static List GetOrderReturnBarcodeList(string search, int searchType, int printState, int PageIndex, int PageSize, out int rowCount) { string filt = " where 1=1 "; if (!string.IsNullOrEmpty(search)) { if (searchType == 1) { filt += " and a.TrackingCode like '%" + search + "%'"; } else if (searchType == 2) { filt += " and a.TrackingCode2 like '%" + search + "%'"; } else if (searchType == 3) { filt += " and a.SKUAndQty like '%" + search + "%'"; } else if (searchType == 4) { filt += " and a.LocationCode like '%" + search + "%'"; } else if (searchType == 5) { filt += " and a.Barcode like '%" + search + "%'"; } } if (printState > -1) { filt += " and a.PrintState=" + printState; } var sql = @" select COUNT(1) count from OrderReturnBarcode a " + filt; sql += @" select * from ( select ROW_NUMBER() over(order by CreateTime desc) row, a.ID,a.TrackingCode,a.TrackingCode2,a.SKUAndQty,a.LocationCode,a.Barcode,a.Sort,a.PrintState,a.DT_OrderReturn_id,a.ScanUserId,b.Name UserName ,a.CreateTime from OrderReturnBarcode a left join jc_UserInfo b on a.ScanUserId=b.UserId " + filt + ") t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion /// /// /// public static void SaveOrderReturnBarcodeDatas(OrderReturnBarcode md) { var sql = @" update OrderReturnBarcode set TrackingCode=@TrackingCode,TrackingCode2=@TrackingCode2, SKUAndQty=@sku,LocationCode=@location where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@TrackingCode", DbType.String, md.TrackingCode); db.AddInParameter(cmd, "@TrackingCode2", DbType.String, md.TrackingCode2); db.AddInParameter(cmd, "@sku", DbType.String, md.SKUAndQty); db.AddInParameter(cmd, "@location", DbType.String, md.LocationCode); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.ExecuteNonQuery(cmd); } public static void DeleteOrderReturnBarcodeDatas(int ID) { var sql = @" delete from OrderReturnBarcode where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } public static void UpdateOrderReturnBarcodePrintState(int ID) { var sql = @" Update OrderReturnBarcode set PrintState=1 where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } public static void UpdateTrackingCodeSKU(int id, string sku) { var sql = @" update DT_TrackCodeApply set SKU=@sku where Id=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, id); db.AddInParameter(cmd, "@sku", DbType.String, sku); db.ExecuteNonQuery(cmd); } /// /// 获取货物库存立方前一百名 /// /// /// public static List GetGoodsSolidTopDatas(int count) { var sql = @" select top " + count + " a.DetailId,a.SKU1 SKU,b.GoodsCode,b.GoodsName,'https://www.kferp.net/'+ REPLACE((case when ISNULL(a.FirstImgUrl,'')='' then b.FirstImgUrl else a.FirstImgUrl end),'../','') FirstImgUrl,ISNULL(b.Solid,0) SingleSolid, ISNULL(WestNum,0) WestNum, ISNULL(WestNum,0)*ISNULL(b.Solid,0) WestSolids, ISNULL(EastNum,0) EastNum, ISNULL(EastNum,0)*ISNULL(b.Solid,0) EastSolids,ISNULL(WestNum,0)+ISNULL(EastNum,0) TotalNum, (ISNULL(WestNum,0)+ISNULL(EastNum,0))*ISNULL(b.Solid,0) TotalSolid ,c.Name UserName from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId left join JC_UserInfo c on b.muserid=c.UserId order by (ISNULL(WestNum,0)+ISNULL(EastNum,0))*ISNULL(b.Solid,0) desc"; //var sql = @" select top " + count + " a.DetailId,a.SKU1 SKU,b.GoodsCode,b.GoodsName, case when ISNULL(a.FirstImgUrl,'')='' then b.FirstImgUrl else a.FirstImgUrl end FirstImgUrl,ISNULL(b.Solid,0) SingleSolid, ISNULL(WestNum,0) WestNum, ISNULL(WestNum,0)*ISNULL(b.Solid,0) WestSolids, ISNULL(EastNum,0) EastNum, ISNULL(EastNum,0)*ISNULL(b.Solid,0) EastSolids,ISNULL(WestNum,0)+ISNULL(EastNum,0) TotalNum, (ISNULL(WestNum,0)+ISNULL(EastNum,0))*ISNULL(b.Solid,0) TotalSolid from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId order by (ISNULL(WestNum,0)+ISNULL(EastNum,0))*ISNULL(b.Solid,0) desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); return db.ExecuteDataTable(cmd).ToList(); } /// /// 获取编号分配销量 /// /// /// public static List GetGoodsforPlan() { var sql = @" select a.GoodsCode,a.GoodsName,'https://www.kferp.net/'+ REPLACE((case when ISNULL(a.FirstImgUrl,'')='' then a.FirstImgUrl else a.FirstImgUrl end),'../','') FirstImgUrl,UserName=groupname_temu from HW_GoodsInfo a with(nolock) left join hw_goodsextra b with(nolock) on a.GoodsId=b.goodsid left join HW_GoodsUserPlanCount c with(nolock) on a.GoodsId = c.GoodsId where a.state=1 and a.companyid=1 and Isnull(a.IsYC,0)=0 and isnull(a.IsEnd,0)=0"; //var sql = @" select top " + count + " a.DetailId,a.SKU1 SKU,b.GoodsCode,b.GoodsName, case when ISNULL(a.FirstImgUrl,'')='' then b.FirstImgUrl else a.FirstImgUrl end FirstImgUrl,ISNULL(b.Solid,0) SingleSolid, ISNULL(WestNum,0) WestNum, ISNULL(WestNum,0)*ISNULL(b.Solid,0) WestSolids, ISNULL(EastNum,0) EastNum, ISNULL(EastNum,0)*ISNULL(b.Solid,0) EastSolids,ISNULL(WestNum,0)+ISNULL(EastNum,0) TotalNum, (ISNULL(WestNum,0)+ISNULL(EastNum,0))*ISNULL(b.Solid,0) TotalSolid from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b on a.GoodsId=b.GoodsId order by (ISNULL(WestNum,0)+ISNULL(EastNum,0))*ISNULL(b.Solid,0) desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); return db.ExecuteDataTable(cmd).ToList(); } #region 保存订单快递运费预估表 public static void SaveOrderPostFeeEstimate(OrderPostFeeEstimate md) { var sql = @"if(exists(select 1 from OrderPostFeeEstimate where OrderId=@OrderId and Warehouse=@Warehouse and ServiceType=@ServiceType)) begin update OrderPostFeeEstimate set FenQu=@FenQu,TotalFee=@TotalFee,BaseFee=@BaseFee,AHS=@AHS,OverSize=@OverSize,PYAreaFee=@PYAreaFee,CPYAreaFee=@CPYAreaFee,CJPYAreaFee=@CJPYAreaFee,FJDFee=@FJDFee,WangJiFee=@WangJiFee,RanYouFee=@RanYouFee,QianShouFee=@QianShouFee,ZZFDZFee=@ZZFDZFee,ChaoBiaoFee=@ChaoBiaoFee,YuJiSongDa=@YuJiSongDa,TotalDiscountFee=@TotalDiscountFee,TotalBillWeight=@TotalBillWeight where OrderId=@OrderId and Warehouse=@Warehouse and ServiceType=@ServiceType end else begin insert into OrderPostFeeEstimate(OrderId,Warehouse,ServiceType,FenQu,TotalFee,BaseFee,AHS,OverSize,PYAreaFee,CPYAreaFee,CJPYAreaFee,FJDFee,WangJiFee,RanYouFee,QianShouFee,ZZFDZFee,ChaoBiaoFee,YuJiSongDa,TotalDiscountFee,TotalBillWeight,IsBest,CreateTime) values(@OrderId,@Warehouse,@ServiceType,@FenQu,@TotalFee,@BaseFee,@AHS,@OverSize,@PYAreaFee,@CPYAreaFee,@CJPYAreaFee,@FJDFee,@WangJiFee,@RanYouFee,@QianShouFee,@ZZFDZFee,@ChaoBiaoFee,@YuJiSongDa,@TotalDiscountFee,@TotalBillWeight,@IsBest,GETDATE()) end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, md.OrderId); db.AddInParameter(cmd, "@Warehouse", DbType.String, md.Warehouse); db.AddInParameter(cmd, "@ServiceType", DbType.String, md.ServiceType); db.AddInParameter(cmd, "@FenQu", DbType.String, md.FenQu); db.AddInParameter(cmd, "@TotalFee", DbType.Decimal, md.TotalFee); db.AddInParameter(cmd, "@BaseFee", DbType.Decimal, md.BaseFee); db.AddInParameter(cmd, "@AHS", DbType.Decimal, md.AHS); db.AddInParameter(cmd, "@OverSize", DbType.Decimal, md.OverSize); db.AddInParameter(cmd, "@PYAreaFee", DbType.Decimal, md.PYAreaFee); db.AddInParameter(cmd, "@CPYAreaFee", DbType.Decimal, md.CPYAreaFee); db.AddInParameter(cmd, "@CJPYAreaFee", DbType.Decimal, md.CJPYAreaFee); db.AddInParameter(cmd, "@FJDFee", DbType.Decimal, md.FJDFee); db.AddInParameter(cmd, "@WangJiFee", DbType.Decimal, md.WangJiFee); db.AddInParameter(cmd, "@RanYouFee", DbType.Decimal, md.RanYouFee); db.AddInParameter(cmd, "@QianShouFee", DbType.Decimal, md.QianShouFee); db.AddInParameter(cmd, "@ZZFDZFee", DbType.Decimal, md.ZZFDZFee); db.AddInParameter(cmd, "@ChaoBiaoFee", DbType.Decimal, md.ChaoBiaoFee); db.AddInParameter(cmd, "@YuJiSongDa", DbType.DateTime, md.YuJiSongDa); db.AddInParameter(cmd, "@TotalDiscountFee", DbType.Decimal, md.TotalDiscountFee); db.AddInParameter(cmd, "@TotalBillWeight", DbType.String, md.TotalBillWeight); db.AddInParameter(cmd, "@IsBest", DbType.Int32, md.IsBest); db.ExecuteNonQuery(cmd); } /// /// 获取订单运费预估列表 /// /// /// public static List GetOrderPostFeeEstimatesDatas(int orderid) { var sql = @"select * from ( select *, case when TotalFee is null or TotalFee=0 then 0 else 1 end RowRank from OrderPostFeeEstimate where OrderId=@orderid ) t order by t.RowRank desc,IsBest desc ,TotalFee"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } /// /// 更改订单订单预估运费最优方案 /// /// /// public static void SetOrderPostFeeEstimatesBestByID(int id, int orderid) { var sql = "update OrderPostFeeEstimate set IsBest=0 where OrderId=@orderid\r\nupdate OrderPostFeeEstimate set IsBest=1 where ID=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } /// /// 更改订单订单预估运费最优方案 /// /// /// public static void SetOrderPostFeeEstimatesBest(int orderid) { //var sql = "update OrderPostFeeEstimate set IsBest=1 where ID in (select top 1 ID from OrderPostFeeEstimate where OrderId=@orderid and ISNULL(TotalFee,0)>0 order by TotalFee )"; var sql = @"declare @addressType nvarchar(100) declare @HYCJ decimal(12,6) --获取地址类型 set @addressType= (select top 1 RevFax from DT_OrderXXInfo where OrderId=@orderid) --获取东西部海运差价,计算最佳运费时需要加上海运差价 select @HYCJ=sum( isnull(c.Solid,0)*isnull(a.GoodsNum,0))*30 from DT_OrderGoods a left join HW_GoodsDetail b on a.DetailId=b.DetailId left join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId=@orderid update OrderPostFeeEstimate set IsBest=0 where OrderId=@orderid if(@addressType='Residential') --家庭地址只比较SMART_POST,GROUND_HOME_DELIVERY两种运费方式 begin update OrderPostFeeEstimate set IsBest=1 where ID in ( select top 1 ID from ( select *,case when Warehouse='E仓' then ISNULL(TotalFee,0)+@HYCJ else ISNULL(TotalFee,0) end as TotalFeeHYCJ from OrderPostFeeEstimate where OrderId=@orderid and ISNULL(TotalFee,0)>0 and ServiceType in ('SMART_POST','GROUND_HOME_DELIVERY') ) t order by t.TotalFeeHYCJ ) end else --商业地址只比较SMART_POST,FEDEX_GROUND begin update OrderPostFeeEstimate set IsBest=1 where ID in ( select top 1 ID from ( select *,case when Warehouse='E仓' then ISNULL(TotalFee,0)+@HYCJ else ISNULL(TotalFee,0) end as TotalFeeHYCJ from OrderPostFeeEstimate where OrderId=@orderid and ISNULL(TotalFee,0)>0 and ServiceType in ('SMART_POST','FEDEX_GROUND') ) t order by t.TotalFeeHYCJ ) end"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.ExecuteNonQuery(cmd); } /// /// 删除订单预估运费最优方案 /// /// /// public static void DeleteOrderPostFeeEstimates(int orderid) { var sql = " delete from OrderPostFeeEstimate where OrderId=@orderid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); db.ExecuteNonQuery(cmd); } #endregion #region 根据sku查询货物详情 public static HW_GoodsDetailNew GetHWGoodsDetailBySKU(string sku) { var sql = @"select * from HW_GoodsDetail where SKU1=@sku or SKU2=@sku or SKU3=@sku or SKU4=@sku or SKU5=@sku or SKU6=@sku or SKU7=@sku or SKU8=@sku or SKU9=@sku or SKU10=@sku or SKU11=@sku or SKU12=@sku or SKU13=@sku"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@sku", DbType.String, sku); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } else return null; } #endregion #region 返回订单Model public static List GetOrderModelList(string OrderIds) { List list = null; string tsql = @"select a.OrderId,a.PlatOrderCode,a.JoinOrderCode,a.OrderCode,a.TotalPrice,a.MoneyCode,b.RevAddr,b.RevMail,b.RevCountry,b.RevPhone,b.RevMoblie,ISNULL(b.RevProvinceCode,b.RevProvince) RevProvince,b.RevPhone,b.CountryCode,b.RevCity,b.RevArea,b.Post,b.RevMail,b.LogisticsId,b.RevName,b.RevPostCode,b.CountryName,a.State,b.CustomID,a.PlatId from DT_OrderInfo a inner join DT_OrderXXInfo b on a.OrderId=b.OrderId where a.OrderId in (" + OrderIds + ")"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion public static List GetDefaultCountListFromDay2(int PlatType, string Ids, DateTime? SDate, DateTime? EDate, int CompanyId) { string text = ""; switch (PlatType) { case 1: text = "select PlatId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo \r\nwhere State>0 and State<3 and CompanyId=@CompanyId and orderDate>=@SDate and CONVERT(date, orderDate)<=@EDate \r\ngroup by PlatId,convert(nvarchar(10),OrderDate,120)"; break; case 3: text = "select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(totalprice,moneycode,1)) from DT_OrderInfo \r\nwhere State>0 and State<3 and CONVERT(date, orderDate)>=@SDate and orderDate=<@EDate \r\ngroup by ShopId,convert(nvarchar(10),OrderDate,120)"; break; case 4: text = "select PlatId=0,OrderDate=convert(nvarchar(10),OrderDate,120),Price=SUM(dbo.MoneyUSDChange(totalprice,moneycode,1)) from DT_OrderInfo \r\nwhere State>0 and State<3 and orderDate>=@SDate and CONVERT(date, orderDate)<=@EDate \r\ngroup by convert(nvarchar(10),OrderDate,120)"; break; default: text = "select PlatId=ShopId,OrderDate=convert(nvarchar(10),OrderDate,120),Num=COUNT(0) from DT_OrderInfo \r\nwhere State>0 and State<3 and orderDate>=@SDate and CONVERT(date, orderDate)<=@EDate \r\ngroup by ShopId,convert(nvarchar(10),OrderDate,120)"; break; } Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(text); database.AddInParameter(sqlStringCommand, "@Ids", DbType.String, Ids); database.AddInParameter(sqlStringCommand, "@CompanyId", DbType.Int32, CompanyId); database.AddInParameter(sqlStringCommand, "@SDate", DbType.DateTime, SDate); database.AddInParameter(sqlStringCommand, "@EDate", DbType.DateTime, EDate); DataSet dataSet = database.ExecuteDataSet(sqlStringCommand); return dataSet.Tables[0].ToList(); } #region 保存 public static int Update_GoodsMoveCheck(CK_GoodsMoveCheck Model) { string tsql = @" if @id>0 begin Update [CK_GoodsMoveCheck] set [checkstate]=@checkstate,[checkcontent]=@checkcontent,[checkdate]=@checkdate where id=@id end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@oldpostionid", DbType.Int32, Model.oldpostionid); db.AddInParameter(cmd, "@oldpostiondesc", DbType.String, Model.oldpostiondesc); db.AddInParameter(cmd, "@kcnum", DbType.Int32, Model.kcnum); db.AddInParameter(cmd, "@movenum", DbType.Int32, Model.movenum); db.AddInParameter(cmd, "@outnum", DbType.Int32, Model.outnum); db.AddInParameter(cmd, "@newpostionid", DbType.Int32, Model.newpostionid); db.AddInParameter(cmd, "@newpostiondesc", DbType.String, Model.newpostiondesc); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@checkstate", DbType.Int32, Model.checkstate); db.AddInParameter(cmd, "@checkcontent", DbType.String, Model.checkcontent); db.AddInParameter(cmd, "@checkdate", DbType.DateTime, Model.checkdate); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 保存 public static int Save_GoodsMoveCheck(CK_GoodsMoveCheck Model) { string tsql = @" if @id>0 begin Update [CK_GoodsMoveCheck] set [detailid]=@detailid,[oldpostionid]=@oldpostionid,[oldpostiondesc]=@oldpostiondesc,[kcnum]=@kcnum,[movenum]=@movenum,[outnum]=@outnum,[newpostionid]=@newpostionid,[newpostiondesc]=@newpostiondesc,[indate]=@indate,[inname]=@inname,[checkstate]=@checkstate,[checkcontent]=@checkcontent,[checkdate]=@checkdate,[StoreId]=@StoreId where id=@id end else begin INSERT INTO [CK_GoodsMoveCheck]([detailid],[oldpostionid],[oldpostiondesc],[kcnum],[movenum],[outnum],[newpostionid],[newpostiondesc],[indate],[inname],[checkstate],[checkcontent],[checkdate],[StoreId])values(@detailid,@oldpostionid,@oldpostiondesc,@kcnum,@movenum,@outnum,@newpostionid,@newpostiondesc,@indate,@inname,@checkstate,@checkcontent,@checkdate,@StoreId) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@detailid", DbType.Int32, Model.detailid); db.AddInParameter(cmd, "@oldpostionid", DbType.Int32, Model.oldpostionid); db.AddInParameter(cmd, "@oldpostiondesc", DbType.String, Model.oldpostiondesc); db.AddInParameter(cmd, "@kcnum", DbType.Int32, Model.kcnum); db.AddInParameter(cmd, "@movenum", DbType.Int32, Model.movenum); db.AddInParameter(cmd, "@outnum", DbType.Int32, Model.outnum); db.AddInParameter(cmd, "@newpostionid", DbType.Int32, Model.newpostionid); db.AddInParameter(cmd, "@newpostiondesc", DbType.String, Model.newpostiondesc); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@checkstate", DbType.Int32, Model.checkstate); db.AddInParameter(cmd, "@checkcontent", DbType.String, Model.checkcontent); db.AddInParameter(cmd, "@checkdate", DbType.DateTime, Model.checkdate); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_GoodsMoveCheck(int id) { string tsql = @" delete from CK_GoodsMoveCheck where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static CK_GoodsMoveCheck GetModel_GoodsMoveCheck(int id) { CK_GoodsMoveCheck model = null; //string tsql = "select a.id,a.detailid,a.oldpostionid,a.oldpostiondesc,a.kcnum,a.movenum,a.outnum,a.newpostionid,a.newpostiondesc,a.indate,a.inname,a.checkstate,a.checkcontent,a.checkdate from CK_GoodsMoveCheck"; string tsql = @" select * from CK_GoodsMoveCheck where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 分页查询 public static List GetListGoodsMoveCheck(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"id=cast(a.id as int),a.detailid,a.oldpostionid,a.oldpostiondesc,a.kcnum,a.movenum,a.outnum,a.newpostionid,a.newpostiondesc,a.indate,a.inname,a.checkstate,a.checkcontent,a.checkdate,a.StoreId,b.SKU1,c.StoreName,checkstatename=case when a.checkstate=1 then '审批通过' when a.checkstate=2 then '驳回' when a.checkstate=3 then '取消' else '未审批' end"; ser.Tables = @"CK_GoodsMoveCheck a inner join HW_GoodsDetail b on a.detailid=b.detailid inner join CK_StoreHouse c on a.StoreId=c.StoreId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 多条件普通查询 public static List GetListGoodsMoveCheck(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); //ser.Fields = "a.id,a.detailid,a.oldpostionid,a.oldpostiondesc,a.kcnum,a.movenum,a.outnum,a.newpostionid,a.newpostiondesc,a.indate,a.inname,a.checkstate,a.checkcontent,a.checkdate"; ser.Fields = "a.*"; ser.Tables = @"CK_GoodsMoveCheck a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.KeyName = "id"; ser.Sort = Sort; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListGoodsMoveCheck() { //string tsql = "select a.id,a.detailid,a.oldpostionid,a.oldpostiondesc,a.kcnum,a.movenum,a.outnum,a.newpostionid,a.newpostiondesc,a.indate,a.inname,a.checkstate,a.checkcontent,a.checkdate from CK_GoodsMoveCheck"; string tsql = "select * from CK_GoodsMoveCheck"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListGoodsMoveCheck(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select id=cast(a.id as int),a.detailid,a.oldpostionid,a.oldpostiondesc,a.kcnum,a.movenum,a.outnum,a.newpostionid,a.newpostiondesc,a.indate,a.inname,a.checkstate,a.checkcontent,a.checkdate from CK_GoodsMoveCheck a"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 统计发货面单 public static List GetCountListLabels(string WareHouse, DateTime? SDate, DateTime? EDate, int TrackPrintState) { string tsql = ""; List list = null; tsql = @" select PostDate=CONVERT(varchar(10),PostDate, 120),num=COUNT(0) from DT_TrackCodeApply a inner join ( select OrderCode,PostDate=MAX(PostDate) from OrderPostInfo a where WareHouse=@WareHouse and a.PostDate>=@SDate and a.PostDate<@EDate group by OrderCode)b on a.OrderCode=b.OrderCode where isnull(a.TrackPrintState,0)=@TrackPrintState and a.State=1 group by CONVERT(varchar(10),PostDate, 120) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@WareHouse", DbType.String, WareHouse); db.AddInParameter(cmd, "@TrackPrintState", DbType.Int32, TrackPrintState); db.AddInParameter(cmd, "@SDate", DbType.DateTime, SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, EDate); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 快递跟踪码关联表 public static List GetTrackCodeRelations(string code, int pageIndex, int pageSize, out int rowCount) { var filt = " where 1=1"; if (!string.IsNullOrEmpty(code)) { filt += " and (MainTrackCode like '%" + code + "%' or SonTrackCode like '%" + code + "%')"; } var sql = @"select COUNT(*) count from TrackCodeRelation " + filt; sql += " select * from (\r\nselect ROW_NUMBER() over(order by id desc) row,ID,MainTrackCode,SonTrackCode,CreateTime from TrackCodeRelation " + filt + "\r\n) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize); var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataSet(cmd); rowCount = Convert.ToInt32(dt.Tables[0].Rows[0]["count"]); return dt.Tables[1].ToList(); } public static void SaveTrackCodeRelation(TrackCodeRelation md) { var sql = @"if(@ID>0) begin update TrackCodeRelation set MainTrackCode=@MainTrackCode,SonTrackCode=@SonTrackCode where ID=@ID end else begin insert into TrackCodeRelation(MainTrackCode,SonTrackCode,CreateTime) values(@MainTrackCode,@SonTrackCode,GETDATE()) end"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, md.ID); db.AddInParameter(cmd, "@MainTrackCode", DbType.String, md.MainTrackCode); db.AddInParameter(cmd, "@SonTrackCode", DbType.String, md.SonTrackCode); db.ExecuteNonQuery(cmd); } public static void DeleteTrackCodeRelation(int id) { var sql = @"delete from TrackCodeRelation where ID=@ID"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 获取东西部仓库货物当天的销售数量 public static List GetStoreGoodsSaleNumsNowDay() { var sql = @"select t.StoreId,t.DetailId,SUM(ISNULL(t.GoodsNum,0)) SaleNum from ( select case when c.StoreId=9 then 6 when c.StoreId=6 then 6 when c.StoreId=11 then 11 end StoreId, b.DetailId,b.GoodsNum from DT_OrderInfo a inner join DT_OrderXXInfo c on a.OrderId=c.OrderId inner join DT_OrderGoods b on a.OrderId=b.OrderId where a.State>0 and c.StoreId in (6,9,11) and a.State<3 and DATEDIFF(day,a.OrderDate,getdate())=0 ) t group by t.StoreId,t.DetailId "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); return db.ExecuteDataTable(cmd).ToList(); } #endregion #region 添加/编辑人员 public static void CreateUser(int? ID, string UserName, string Dep) { var sql = ""; if (!ID.HasValue || ID == 0) { sql = " Insert into UserInfoModel(UserName,Dep) Values(@UserName,@Dep) "; } else { sql = " Update UserInfoModel set UserName=@UserName,Dep=@Dep where ID=@ID "; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.AddInParameter(cmd, "@UserName", DbType.String, UserName); db.AddInParameter(cmd, "@Dep", DbType.String, Dep); db.ExecuteNonQuery(cmd); } #endregion #region 人员下拉列表 public static List GetUserList() { string query = "select * from UserInfoModel"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); DataTable tb = database.ExecuteDataTable(sqlStringCommand); return tb.ToList(); } #endregion #region 保存 public static int Save_UserInfo(UserInfoModel Model) { string tsql = @"Insert into UserInfoModel(UserName,Dep) Values(@UserName,@Dep)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, Model.UserName); db.AddInParameter(cmd, "@Dep", DbType.String, Model.Dep); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 列表 public static List GetUserInfoList(int ID, int PageIndex, int PageSize, out int rowCount) { string filt = " where 1=1 "; if (ID != 0) filt += " and ID=" + ID; var sql = @" select COUNT(1) as count from UserInfoModel a " + filt; sql += " select ID,UserName,Dep from (select Row_Number() over (order by ID desc) row,ID, UserName, Dep from UserInfoModel " + filt + ") t where t.row between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion #region 删除 public static void DelUserInfo(int ID) { var sql = " Delete from UserInfoModel where ID=@ID "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } #endregion #region 出勤数据 public static int Save_AttData(AttendanceModel Model) { string tsql = @"Insert Into AttendanceModel(UserName,AttDate,WorkTime,AfterWorkTime,StartLeaveDate,EndLeaveDate,TravelStartDate,TravelEndDate,OutStartDate,OutEndDate,Reason,Notes) Values(@UserName,@AttDate,@WorkTime,@AfterWorkTime,@StartLeaveDate,@EndLeaveDate,@TravelStartDate,@TravelEndDate,@OutStartDate,@OutEndDate,@Reason,@Notes)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, Model.UserName); db.AddInParameter(cmd, "@AttDate", DbType.DateTime, Model.AttDate); db.AddInParameter(cmd, "@WorkTime", DbType.DateTime, Model.WorkTime); db.AddInParameter(cmd, "@AfterWorkTime", DbType.DateTime, Model.AfterWorkTime); db.AddInParameter(cmd, "@StartLeaveDate", DbType.DateTime, Model.StartLeaveDate); db.AddInParameter(cmd, "@EndLeaveDate", DbType.DateTime, Model.EndLeaveDate); db.AddInParameter(cmd, "@TravelStartDate", DbType.DateTime, Model.TravelStartDate); db.AddInParameter(cmd, "@TravelEndDate", DbType.DateTime, Model.TravelEndDate); db.AddInParameter(cmd, "@OutStartDate", DbType.DateTime, Model.OutStartDate); db.AddInParameter(cmd, "@OutEndDate", DbType.DateTime, Model.OutEndDate); db.AddInParameter(cmd, "@Reason", DbType.Int32, Model.Reason); db.AddInParameter(cmd, "@Notes", DbType.String, Model.Notes); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 打卡时间 public static int Save_ClockData(ClockModel Model) { string tsql = @"Insert Into ClockModel(UserName,ClockDate) Values(@UserName,@ClockDate)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, Model.UserName); db.AddInParameter(cmd, "@ClockDate", DbType.DateTime, Model.ClockDate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 将打卡时间拆成两列赋值给出勤表中上班时间和下班时间 public static int ClockTime() { string sql = @"WITH ClockTimes AS ( SELECT UserName, CAST(ClockDate AS DATE) AS ClockDate, MIN(ClockDate) AS StartTime, MAX(ClockDate) AS EndTime FROM ClockModel GROUP BY UserName, CAST(ClockDate AS DATE) ) UPDATE AttendanceModel SET WorkTime = CASE WHEN ClockTimes.NumTimes = 1 THEN NULL ELSE ClockTimes.StartTime END, AfterWorkTime = CASE WHEN ClockTimes.NumTimes = 1 THEN NULL ELSE ClockTimes.EndTime END, Reason = CASE WHEN ClockTimes.NumTimes = 1 THEN 10 ELSE 1 END FROM AttendanceModel INNER JOIN ( SELECT UserName, CAST(ClockDate AS DATE) AS ClockDate, MIN(ClockDate) AS StartTime, MAX(ClockDate) AS EndTime, COUNT(*) AS NumTimes FROM ClockModel GROUP BY UserName, CAST(ClockDate AS DATE) ) AS ClockTimes ON AttendanceModel.UserName = ClockTimes.UserName AND CAST(AttendanceModel.AttDate AS DATE) = ClockTimes.ClockDate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); int rowsAffected = db.ExecuteNonQuery(cmd); return rowsAffected; } #endregion #region 出勤列表 public static List GetUserAttendanceList(int PageIndex, int PageSize, out int rowCount) { var sql = @" select COUNT(1) as count from UserInfoModel u join AttendanceModel a on u.ID = a.UserID; "; sql += "WITH NumberedAttendance AS (SELECT u.UserName,a.UserID,a.AttDate,a.WorkTime,a.AfterWorkTime,a.StartLeaveDate,a.EndLeaveDate,a.TravelStartDate,a.TravelEndDate,a.OutStartDate,a.OutEndDate,Sum(CASE WHEN DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, a.WorkTime)) >0 and DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, a.WorkTime)) <= 10 THEN 1 ELSE 0 END) AS WithinTenMin,Sum(CASE WHEN DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, a.WorkTime)) >0 and DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, a.WorkTime)) > 10 THEN 1 ELSE 0 END) AS OutsideTenMin,a.Reason,a.Notes,Row_Number() over (order by a.UserID) as RowNum FROM UserInfoModel u JOIN AttendanceModel a ON u.ID = a.UserID group by u.UserName,a.UserID,a.AttDate,a.WorkTime,a.AfterWorkTime,a.StartLeaveDate,a.EndLeaveDate,a.TravelStartDate,a.TravelEndDate,a.OutStartDate,a.OutEndDate,a.Reason,a.Notes) SELECT UserName,UserID,AttDate,WorkTime,AfterWorkTime,WithinTenMin,OutsideTenMin,Reason,Notes FROM NumberedAttendance where RowNum between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion #region 加班数据 public static int Save_SurData(SurplusWorkModel Model) { string tsql = @"Insert Into SurplusWorkModel(UserName,SurplusWorkStartDate,SurplusWorkEndDate,Notes) Values(@UserName,@SurplusWorkStartDate,@SurplusWorkEndDate,@Notes)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserName", DbType.String, Model.UserName); db.AddInParameter(cmd, "@SurplusWorkStartDate", DbType.DateTime, Model.SurplusWorkStartDate); db.AddInParameter(cmd, "@SurplusWorkEndDate", DbType.DateTime, Model.SurplusWorkEndDate); db.AddInParameter(cmd, "@Notes", DbType.String, Model.Notes); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 加班列表 public static List GetUserSurList(int PageIndex, int PageSize, out int rowCount) { var sql = @" select COUNT(1) as count from UserInfoModel u join SurplusWorkModel s on u.ID = s.UserID; "; sql += "WITH WorkOvertime AS(SELECT u.UserName, s.UserID, s.SurplusWorkStartDate, s.SurplusWorkEndDate, SUM(CASE WHEN DATEPART(WEEKDAY, s.SurplusWorkStartDate) BETWEEN 2 AND 6 THEN DATEDIFF(MINUTE, s.SurplusWorkStartDate, s.SurplusWorkEndDate) ELSE 0 END) / 60.0 AS DaySurplusWork, COUNT(CASE WHEN DATEDIFF(HOUR, s.SurplusWorkStartDate, s.SurplusWorkEndDate) > 2 AND DATEPART(WEEKDAY, s.SurplusWorkStartDate) BETWEEN 2 AND 6 THEN 1 END) AS WorkDayTwoHoursNum, COUNT(CASE WHEN DATEPART(WEEKDAY, s.SurplusWorkStartDate) IN(1, 7) AND DATEDIFF(MINUTE, s.SurplusWorkStartDate, s.SurplusWorkEndDate) <= 4 THEN 1 END) AS WeekendSurplusWorkHoursInFour, COUNT(CASE WHEN DATEPART(WEEKDAY, s.SurplusWorkStartDate) IN(1, 7) AND DATEDIFF(MINUTE, s.SurplusWorkStartDate, s.SurplusWorkEndDate) > 4 THEN 1 END) AS WeekendSurplusWorkHoursOutFour, s.Notes,Row_Number() over(order by s.UserID) as RowNum FROM UserInfoModel u JOIN SurplusWorkModel s ON u.ID = s.UserID group by u.UserName,s.UserID,s.SurplusWorkStartDate,s.SurplusWorkEndDate,s.Notes) SELECT UserName, UserID, SurplusWorkStartDate, SurplusWorkEndDate, DaySurplusWork, WorkDayTwoHoursNum, WeekendSurplusWorkHoursInFour, WeekendSurplusWorkHoursOutFour, Notes FROM WorkOvertime where RowNum between " + ((PageIndex - 1) * PageSize + 1) + " and " + PageIndex * PageSize; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); rowCount = (int)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion #region UserID赋值 public static int GiveUserIDformAtt(AttendanceModel model) { var uSql = "UPDATE AttendanceModel SET AttendanceModel.UserID = (SELECT UserInfoModel.ID FROM UserInfoModel WHERE UserInfoModel.UserName = AttendanceModel.UserName) WHERE EXISTS (SELECT 1 FROM UserInfoModel WHERE UserInfoModel.UserName = AttendanceModel.UserName)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(uSql); db.AddInParameter(cmd, "@UserID", DbType.String, model.UserID); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } public static int GiveUserIDformSur(SurplusWorkModel model) { var uSql = "UPDATE SurplusWorkModel SET SurplusWorkModel.UserID = (SELECT UserInfoModel.ID FROM UserInfoModel WHERE UserInfoModel.UserName = SurplusWorkModel.UserName) WHERE EXISTS (SELECT 1 FROM UserInfoModel WHERE UserInfoModel.UserName = SurplusWorkModel.UserName)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(uSql); db.AddInParameter(cmd, "@UserID", DbType.String, model.UserID); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } //public static int GiveUserIDformShift(ShiftRestModel model) //{ // var uSql = "UPDATE ShiftRestModel SET ShiftRestModel.UserID = (SELECT UserInfoModel.ID FROM UserInfoModel WHERE UserInfoModel.UserName = ShiftRestModel.UserName) WHERE EXISTS (SELECT 1 FROM UserInfoModel WHERE UserInfoModel.UserName = ShiftRestModel.UserName)"; // Database db = DatabaseFactory.CreateDatabase(); // DbCommand cmd = db.GetSqlStringCommand(uSql); // db.AddInParameter(cmd, "@UserID", DbType.String, model.UserID); // int a = Convert.ToInt32(db.ExecuteScalar(cmd)); // return a; //} #endregion #region 汇总列表 public static List GetSummaryDataList() { var sql = @" select COUNT(DISTINCT u.ID) as count from UserInfoModel u left join AttendanceModel a on u.ID = a.UserID left join SurplusWorkModel s on u.ID = s.UserID;"; sql += "SELECT u.ID,u.UserName,Sum(CASE WHEN DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, WorkTime)) >0 and DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, WorkTime)) <= 10 THEN 1 ELSE 0 END) AS WithinTenMin,Sum(CASE WHEN DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, a.WorkTime)) >0 and DATEDIFF(MINUTE, CONVERT(time, '08:30:00'), CONVERT(time, a.WorkTime)) > 10 THEN 1 ELSE 0 END) AS OutsideTenMin,SUM(CASE WHEN DATEDIFF(DAY, TravelStartDate, TravelEndDate) = 0 THEN 1 ELSE DATEDIFF(DAY, TravelStartDate, TravelEndDate) + 1 END - CASE WHEN DATEPART(HOUR, TravelStartDate) >= 12 THEN 1 ELSE 0 END - CASE WHEN DATEPART(HOUR, TravelEndDate) < 12 THEN 1 ELSE 0 END) AS TravelDays,SUM(CASE WHEN DATEDIFF(DAY, OutStartDate, OutEndDate) = 0 THEN 1 ELSE DATEDIFF(DAY, OutStartDate, OutEndDate) + 1 END - CASE WHEN DATEPART(HOUR, OutStartDate) >= 12 THEN 1 ELSE 0 END - CASE WHEN DATEPART(HOUR, OutEndDate) < 12 THEN 1 ELSE 0 END) AS OutDays,SUM(CASE WHEN Reason = 4 THEN CASE WHEN DATEDIFF(hour, StartLeaveDate, EndLeaveDate) > 8 THEN DATEDIFF(hour, StartLeaveDate, EndLeaveDate) - 1 ELSE CAST(DATEDIFF(minute, StartLeaveDate, EndLeaveDate) / 60.0 AS DECIMAL(10,2)) END ELSE 0 END) AS AffairLeaveHours,SUM(CASE WHEN Reason = 5 THEN CASE WHEN DATEDIFF(hour, StartLeaveDate, EndLeaveDate) > 8 THEN DATEDIFF(hour, StartLeaveDate, EndLeaveDate) - 1 ELSE CAST(DATEDIFF(minute, StartLeaveDate, EndLeaveDate) / 60.0 AS DECIMAL(10,2)) END ELSE 0 END) AS SickLeaveHours,(SELECT COUNT(*) AS ShouldAtt FROM (SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS Number FROM sys.columns) Numbers WHERE DATEADD(DAY, Number - 1, '2024-04-01') <= '2024-04-30' AND DATEPART(WEEKDAY, DATEADD(DAY, Number - 1, '2024-04-01')) BETWEEN 2 AND 6) AS ShouldAtt into #ls_1 FROM UserInfoModel u LEFT JOIN AttendanceModel a ON u.ID = a.UserID WHERE a.AttDate BETWEEN '2024-04-01' AND '2024-04-30' GROUP BY u.ID, u.UserName SELECT u.ID,CAST(SUM(CASE WHEN DATEPART(WEEKDAY, s.SurplusWorkStartDate) BETWEEN 2 AND 6 THEN CASE WHEN CONVERT(TIME, s.SurplusWorkStartDate) = '18:30:00' THEN DATEDIFF(MINUTE, SurplusWorkStartDate, s.SurplusWorkEndDate) / 60.0 ELSE DATEDIFF(MINUTE, s.SurplusWorkStartDate, s.SurplusWorkEndDate) / 60.0 END ELSE 0 END) AS DECIMAL(10, 2)) AS DaySurplusWork,COUNT(CASE WHEN DATEDIFF(HOUR, s.SurplusWorkStartDate, s.SurplusWorkEndDate) > 2 AND DATEPART(WEEKDAY, s.SurplusWorkStartDate) BETWEEN 2 AND 6 THEN 1 END) AS WorkDayTwoHoursNum,COUNT(CASE WHEN DATEPART(WEEKDAY, s.SurplusWorkStartDate) IN (1, 7) AND DATEDIFF(MINUTE, s.SurplusWorkStartDate, s.SurplusWorkEndDate) / 60.0 <= 4 THEN 1 END) AS WeekendSurplusWorkHoursInFour,COUNT(CASE WHEN DATEPART(WEEKDAY, s.SurplusWorkStartDate) IN (1, 7) AND DATEDIFF(MINUTE, s.SurplusWorkStartDate, s.SurplusWorkEndDate) / 60.0 > 4 THEN 1 END) AS WeekendSurplusWorkHoursOutFour into #ls_2 FROM UserInfoModel u LEFT JOIN SurplusWorkModel s on u.ID = s.UserID group by u.ID;select a.ID,UserName,ShouldAtt,WithinTenMin,OutsideTenMin,TravelDays,OutDays,AffairLeaveHours,SickLeaveHours,DaySurplusWork,WorkDayTwoHoursNum,WeekendSurplusWorkHoursInFour,WeekendSurplusWorkHoursOutFour from #ls_1 a left join #ls_2 b on a.ID=b.ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); return ds.Tables[1].ToList(); } #endregion #region 获取每天东西部未打印面单数据 public static List GetWareHouseNoPrintedDatas(string warehouse, DateTime date) { var filt = " b.State=1 and ISNULL(b.TrackPrintState,0)=0 and Convert(date, PostDate)=convert(date,'" + date.Date + "') "; if (!string.IsNullOrEmpty(warehouse)) { filt += " and WareHouse='" + warehouse + "'"; } var sql = @"select distinct a.WareHouse, b.TrackCode, b.SKU from OrderPostInfo a left join DT_TrackCodeApply b on a.OrderCode=b.OrderCode where " + filt; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); //db.AddInParameter(cmd, "wareHouse", DbType.String, warehouse); //db.AddInParameter(cmd, "date", DbType.Date, date.Date); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 删除订单 public static void DeleteOrderForTM2(string OrderIds) { string tsql = @" if(select count(1) from DT_OrderInfo where OrderId in (" + OrderIds + @") and MateState>0)=0 begin delete from DT_OrderXXInfo where OrderId in (" + OrderIds + @") delete from DT_OrderXXInfoNew where OrderId in (" + OrderIds + @") update b set b.GoodsPlanNum=ISNULL(b.GoodsPlanNum,0)-isnull(a.GoodsNum,0) from [DT_OrderGoods] a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where a.OrderId in (" + OrderIds + @") delete from API_OrderInfo where OrderCode in (select distinct PlatOrderCode from DT_OrderInfo where OrderId in (" + OrderIds + @")) delete from DT_OrderGoods where OrderId in (" + OrderIds + @") delete from DT_OrderInfo where OrderId in (" + OrderIds + @") delete from DT_OrderInfoNew where OrderId in (" + OrderIds + @") delete from DT_TrackCodeApply where OrderId in (" + OrderIds + @") end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.ExecuteNonQuery(cmd); } #endregion #region 保存产品补贴价格 public static void SaveGoodsBTPrice(int goodsid, decimal? price) { var sql = @"update HW_GoodsInfo set SubsidyFee=@price where GoodsId=@goodsid"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@goodsid", DbType.Int32, goodsid); db.AddInParameter(cmd, "@price", DbType.Decimal, price); db.ExecuteNonQuery(cmd); } #endregion #region 刷新产品的订单补贴价格 public static void UpdateOrderBTPrice(int goodsid, int platid) { var sql = @"update a set a.SubsidyFee=b.BTPrice from DT_Fees a inner join (select a.OrderId,SUM(b.GoodsNum*ISNULL(d.SubsidyFee,0)) BTPrice from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where a.OrderId in (select a.OrderId from DT_OrderInfo a inner join DT_OrderGoods b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on b.DetailId=c.DetailId inner join HW_GoodsInfo d on c.GoodsId=d.GoodsId where CONVERT(date,a.indate)>='2024-04-01' and CONVERT(date,a.indate)<='2024-07-31' and d.GoodsId=@goodsid and a.platid=@platid) group by a.OrderId ) b on a.orderid=b.OrderId"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@goodsid", DbType.Int32, goodsid); db.AddInParameter(cmd, "@platid", DbType.Int32, platid); db.ExecuteNonQuery(cmd); } #endregion #region 报价单 #region 保存 public static int Save_DT_Quote_NewTable(DT_Quote_NewTable Model) { int resultId = 0; try { string tsql = @" if @Id>0 begin UPDATE [dbo].[DT_Quote_New] SET [Foto] = @Foto, [Nombre] = @Nombre, [Caracteristicas] =@Caracteristicas, [Modelo] =@Modelo, [Recio] =@Recio, [QtyOrCtn] = @QtyOrCtn, [Cbm] = @Cbm, [AllCbm] = @AllCbm, [Gw] =@Gw, [Nw] = @Nw, [CompanyId] = @CompanyId, [UserId] = @UserId, [CreateDate] = @CreateDate, [IsAuthority] =@IsAuthority, [FactoryName] =@FactoryName, [FactoryImg] = @FactoryImg, [Cantidad] = @Cantidad, [Valor] = @Valor, [ClientId] = @ClientId, [CityName] = @CityName, [DTQuoteNo] = @DTQuoteNo, [IsCustomerUpdate] = @IsCustomerUpdate, [UpdateName] = @UpdateName WHERE [Id] = @Id; end else begin INSERT INTO [dbo].[DT_Quote_New] ([Foto], [Nombre], [Caracteristicas], [Modelo], [Recio], [QtyOrCtn], [Cbm],[AllCbm], [Gw], [Nw], [CompanyId], [UserId], [CreateDate], [IsAuthority], [FactoryName], [FactoryImg], [Cantidad], [Valor], [ClientId], [CityName], [DTQuoteNo],[IsCustomerUpdate],[UpdateName]) VALUES (@Foto,@Nombre,@Caracteristicas,@Modelo,@Recio, @QtyOrCtn,@Cbm,@AllCbm,@Gw, @Nw,@CompanyId, @UserId, @CreateDate,@IsAuthority, @FactoryName, @FactoryImg,@Cantidad,@Valor,@ClientId,@CityName,@DTQuoteNo,@IsCustomerUpdate,@UpdateName); set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@Foto", DbType.String, Model.Foto); db.AddInParameter(cmd, "@Nombre", DbType.String, Model.Nombre); db.AddInParameter(cmd, "@Caracteristicas", DbType.String, Model.Caracteristicas); db.AddInParameter(cmd, "@Modelo", DbType.String, Model.Modelo); db.AddInParameter(cmd, "@Recio", DbType.Decimal, Model.Recio); db.AddInParameter(cmd, "@QtyOrCtn", DbType.Int32, Model.QtyOrCtn); db.AddInParameter(cmd, "@Cbm", DbType.Decimal, Model.Cbm); db.AddInParameter(cmd, "@AllCbm", DbType.Decimal, Model.AllCbm); db.AddInParameter(cmd, "@Gw", DbType.Decimal, Model.Gw); db.AddInParameter(cmd, "@Nw", DbType.Decimal, Model.Nw); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@CreateDate", DbType.DateTime, Model.CreateDate); db.AddInParameter(cmd, "@IsAuthority", DbType.Boolean, Model.IsAuthority); db.AddInParameter(cmd, "@FactoryName", DbType.String, Model.FactoryName); db.AddInParameter(cmd, "@FactoryImg", DbType.String, Model.FactoryImg); db.AddInParameter(cmd, "@CityName", DbType.String, Model.CityName); db.AddInParameter(cmd, "@DTQuoteNo", DbType.String, Model.DTQuoteNo); db.AddInParameter(cmd, "@Cantidad", DbType.Int32, Model.Cantidad); db.AddInParameter(cmd, "@Valor", DbType.Decimal, Model.Valor); db.AddInParameter(cmd, "@ClientId", DbType.Int32, Model.ClientId); db.AddInParameter(cmd, "@IsCustomerUpdate", DbType.Boolean, Model.IsCustomerUpdate); db.AddInParameter(cmd, "@UpdateName", DbType.String, Model.UpdateName); resultId = Convert.ToInt32(db.ExecuteScalar(cmd)); } catch (Exception ex) { resultId = -1; } return resultId; } #region public static appShowMsg GetMsg_ClientToday(int ClientId, string newDate) { string sql = $"SELECT SUM(Valor) as AllValor,SUM(AllCbm) as AllCbm FROM [dbo].[DT_Quote_New] where ClientId = {ClientId} and CreateDate BETWEEN '{newDate}' AND dateadd(second,-1,dateadd(day,1,'{newDate}'));SELECT Id as ClientId,ClientName from JC_Client where Id = {ClientId};"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); var model1 = ds.Tables[0].Rows[0].ToModel(); var model2 = ds.Tables[1].Rows[0].ToModel(); appShowMsg model = new appShowMsg(); model.ClientName = model2.ClientName; model.ClientId = model2.ClientId; model.AllValor = model1.AllValor; model.AllCbm = model1.AllCbm; return model; } //不传时间 public static appShowMsg GetMsg_ClientToday_Nodate(int ClientId,string QuoteNo) { string sql = $"SELECT SUM(Valor) as AllValor,SUM(AllCbm) as AllCbm FROM [dbo].[DT_Quote_New] where ClientId = {ClientId} and DTQuoteNo = '{QuoteNo}';SELECT Id as ClientId,ClientName from JC_Client where Id = {ClientId};"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); DataSet ds = db.ExecuteDataSet(cmd); var model1 = ds.Tables[0].Rows[0].ToModel(); var model2 = ds.Tables[1].Rows[0].ToModel(); appShowMsg model = new appShowMsg(); model.ClientName = model2.ClientName; model.ClientId = model2.ClientId; model.AllValor = model1.AllValor; model.AllCbm = model1.AllCbm; return model; } public static DT_Quote_NewTable GetModel_DT_QuoteNewTable(int Id) { string tsql = $"SELECT * FROM [dbo].[DT_Quote_New] where Id = {Id} "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } public static List Delete_DT_Quote_NewTableByQuoteId(List Ids) { var sql = $"DELETE DT_Quote_New where Id in ({string.Join(",", Ids)})"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } #region 小程序的客户报价表查询 public static List GetPageList_DT_QuoteNewTable(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"CASE WHEN b.ClientName is null THEN '' ELSE b.ClientName END AS ClientName,c.UserName,a.*"; ser.Tables = @" [dbo].[DT_Quote_New] a LEFT JOIN JC_Client b on a.ClientId = b.Id LEFT JOIN JC_UserInfo c on a.UserId = c.UserId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } public static List GetList_DT_QuoteNewTable(string whereMsg, string Sort) { string FieldsMsg = @"CASE WHEN b.ClientName is null THEN '' ELSE b.ClientName END AS ClientName,c.UserName,a.*"; string TablesMsg = @" [dbo].[DT_Quote_New] a LEFT JOIN JC_Client b on a.ClientId = b.Id LEFT JOIN JC_UserInfo c on a.UserId = c.UserId "; //ser.Sort = Sort; //ser.KeyName = "Id"; //string tsql = ser.GetText(); string tsql = string.IsNullOrEmpty(whereMsg) ? $"select {FieldsMsg} from {TablesMsg} order by {Sort}".Replace("desc", "") : $"select {FieldsMsg} from {TablesMsg} where {whereMsg} order by {Sort}".Replace("desc", ""); List ListModel = new List(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); //db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } public static List GetList_DT_QuoteNewTable2(string where) { var sql = @"select CASE WHEN b.ClientName is null THEN '' ELSE b.ClientName END AS ClientName,a.* from [dbo].[DT_Quote_New] a LEFT JOIN JC_Client b on a.ClientId = b.Id "; if (!string.IsNullOrEmpty(where)) { sql += where; } var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #endregion public static int Save_DT_Quote_Old(DT_Quote Model) { int resultId = 0; //新增 if (Model.Id == null) { string tsql = $"INSERT INTO DT_Quote(Foto,Nombre,Caracteristicas,Modelo,Recio,QtyOrCtn,Cbm,Gw,Nw,CompanyId,UserId,CreateDate,IsAuthority,FactoryPrice) VALUES ('{Model.Foto}','{Model.Nombre}','{Model.Caracteristicas}','{Model.Modelo}','{Model.Recio}',{Model.QtyOrCtn},{Model.Cbm},{Model.Gw},{Model.Nw},{Model.CompanyId},{Model.UserId},'{Model.CreateDate}','{Model.IsAuthority}',{Model.FactoryPrice});SELECT SCOPE_IDENTITY();"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); resultId = Convert.ToInt32(result); } //保存 else { string tsql = $"UPDATE DT_Quote set Foto = '{Model.Foto}',Nombre = '{Model.Nombre}',Caracteristicas = '{Model.Caracteristicas}',Modelo = '{Model.Modelo}',Recio = '{Model.Recio}',QtyOrCtn = {Model.QtyOrCtn},Cbm = {Model.Cbm},Gw = {Model.Gw},Nw = {Model.Nw},IsAuthority = '{Model.IsAuthority}',FactoryPrice = {Model.FactoryPrice} where Id = {Model.Id}"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); resultId = (int)Model.Id; } return resultId; } public static int Save_DT_Quote(DT_Quote Model) { int resultId = 0; try { string tsql = @" if @Id>0 begin UPDATE [dbo].[DT_Quote] SET [Foto] = @Foto, [Nombre] = @Nombre, [Caracteristicas] =@Caracteristicas, [Modelo] =@Modelo, [Recio] =@Recio, [QtyOrCtn] = @QtyOrCtn, [Cbm] = @Cbm, [Gw] =@Gw, [Nw] = @Nw, [CompanyId] = @CompanyId, [UserId] = @UserId, [CreateDate] = @CreateDate, [IsAuthority] =@IsAuthority, [FactoryPrice] = @FactoryPrice, [FactoryName] =@FactoryName, [FactoryImg] = @FactoryImg WHERE [Id] = @Id; end else begin INSERT INTO [dbo].[DT_Quote] ([Foto], [Nombre], [Caracteristicas], [Modelo], [Recio], [QtyOrCtn], [Cbm], [Gw], [Nw], [CompanyId], [UserId], [CreateDate], [IsAuthority], [FactoryPrice], [FactoryName], [FactoryImg]) VALUES (@Foto,@Nombre,@Caracteristicas,@Modelo,@Recio, @QtyOrCtn,@Cbm,@Gw, @Nw,@CompanyId, @UserId, @CreateDate,@IsAuthority,@FactoryPrice, @FactoryName, @FactoryImg); set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@Foto", DbType.String, Model.Foto); db.AddInParameter(cmd, "@Nombre", DbType.String, Model.Nombre); db.AddInParameter(cmd, "@Caracteristicas", DbType.String, Model.Caracteristicas); db.AddInParameter(cmd, "@Modelo", DbType.String, Model.Modelo); db.AddInParameter(cmd, "@Recio", DbType.Decimal, Model.Recio); db.AddInParameter(cmd, "@QtyOrCtn", DbType.Int32, Model.QtyOrCtn); db.AddInParameter(cmd, "@Cbm", DbType.Decimal, Model.Cbm); db.AddInParameter(cmd, "@Gw", DbType.Decimal, Model.Gw); db.AddInParameter(cmd, "@Nw", DbType.Decimal, Model.Nw); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@CreateDate", DbType.DateTime, Model.CreateDate); db.AddInParameter(cmd, "@IsAuthority", DbType.Boolean, Model.IsAuthority); db.AddInParameter(cmd, "@FactoryPrice", DbType.Decimal, Model.FactoryPrice); db.AddInParameter(cmd, "@FactoryName", DbType.String, Model.FactoryName); db.AddInParameter(cmd, "@FactoryImg", DbType.String, Model.FactoryImg); resultId = Convert.ToInt32(db.ExecuteScalar(cmd)); } catch { resultId = -1; } return resultId; } public static int Save_DT_QuoteAuthority(int QuoteId, int ClientId) { string tsql = $"INSERT INTO DT_QuoteAuthority(QuoteId,ClientId) VALUES ('{QuoteId}','{ClientId}');SELECT SCOPE_IDENTITY();"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); int a = Convert.ToInt32(result); return a; } public static int Check_DT_QuoteAuthority(int QuoteId, int ClientId) { string tsql = $"SELECT count(1) from DT_QuoteAuthority where QuoteId = {QuoteId} and ClientId = {ClientId}"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); int resultId = Convert.ToInt32(result); return resultId; } #region 小程序的客户报价表查询 public static List GetList_DT_Quote_Detail(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"c.ClientName,b.ClientId,a.*"; ser.Tables = @"DT_Quote a INNER JOIN DT_QuoteAuthority b on a.Id = b.QuoteId INNER JOIN JC_Client c on c.Id = b.ClientId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #endregion #region 批量保存 public static int SaveList_DT_Quote(List ModelList) { int num = 0; foreach (var Model in ModelList) { string tsql = $"INSERT INTO DT_Quote(Foto,Nombre,Caracteristicas,Modelo,Recio,QtyOrCtn,Cbm,Gw,Nw) VALUES ('{Model.Foto}','{Model.Nombre}','{Model.Caracteristicas}','{Model.Modelo}','{Model.Recio}',{Model.QtyOrCtn},{Model.Cbm},{Model.Gw},{Model.Nw});"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); num += a; } return num; } #endregion #region 分页查询 public static List GetListDT_Quote(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); //ser.Fields = @"Id=cast(a.Id as int),a.Foto,a.Nombre,a.Caracteristicas,a.Modelo,a.Recio,a.QtyOrCtn,a.Cbm,a.Gw,a.Nw,a."; ser.Fields = @"a.*"; ser.Tables = @"DT_Quote a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 报价查询 public static List GetListDT_QuoteById(List Ids) { var sql = $"SELECT * from DT_Quote where Id in ('{string.Join("','", Ids)}')"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } #endregion #region 报价查询 public static List Select_DT_QuoteByQuoteId(List Ids) { var sql = $"SELECT DISTINCT QuoteId from DT_QuoteClientNum where QuoteId in ({string.Join(",", Ids)})"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); // 创建一个List来存储结果 List resultList = new List(); // 遍历DataTable中的指定列,假设列名是"ColumnName" foreach (DataRow row in tb.Rows) { // 确保列名存在,并且列中的数据可以转换为int类型 if (row.Table.Columns.Contains("QuoteId") && row["QuoteId"] != DBNull.Value) { // 将列中的值转换为int类型 int value = Convert.ToInt32(row["QuoteId"]); // 将转换后的值添加到列表中 resultList.Add(value); } } return resultList; } public static List Delete_DT_QuoteByQuoteId(List Ids) { var sql = $"DELETE DT_Quote where Id in ({string.Join(",", Ids)})"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } public static List Delete_DT_QuoteAuthorityByQuoteId(List Ids) { var sql = $"DELETE DT_QuoteAuthority where QuoteId in ({string.Join(",", Ids)})"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } #endregion #region 报价查询 public static List GetListDT_QuoteNewById(List ClientIds) { var sql = $"SELECT a.Cantidad,a.Valor,a.ClientId,c.ClientName,b.* FROM [dbo].[DT_QuoteClientNum] a INNER JOIN DT_Quote b on a.QuoteId = b.Id INNER JOIN JC_Client c on a.ClientId = c.Id "; if (ClientIds.Count() > 0) { sql += " where a.ClientId in ('{string.Join(\"','\", ClientIds)}')"; } var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } #endregion #region 客户查询 public static List GetClientList() { var sql = $"SELECT * from JC_Client where State = 1 "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } #endregion #region 客户分页报价单分页查询 public static List GetListDT_QuoteByClient(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"Id=cast(a.Id as int),a.Foto,a.Nombre,a.Caracteristicas,a.Modelo,a.Recio,a.QtyOrCtn,a.Cbm,a.Gw,a.Nw"; ser.Tables = @"DT_Quote a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 客户查询 public static List GetAllClientList() { var sql = $"SELECT * from JC_Client "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { return tb.ToList(); } return null; } public static List GetQuoteIdListByClientId(int ClientId) { var sql = $"SELECT QuoteId from DT_QuoteAuthority where ClientId = {ClientId}"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var tb = db.ExecuteDataTable(cmd); //if (tb != null && tb.Rows.Count > 0) //{ // return tb.ToList(); //} var quoteIds = new List(); // 创建一个字符串列表来存储结果 if (tb != null) { foreach (DataRow row in tb.Rows) { // 假设 QuoteId 是字符串类型 if (row["QuoteId"] != DBNull.Value) { quoteIds.Add(int.Parse(row["QuoteId"].ToString())); } } } return quoteIds; } #endregion #region 客户 #region 客户登录 public static JC_Client LoginNew_Client(string UserName, string PassWord) { string tsql = $"SELECT * from JC_Client where UserName = '{UserName}' and Password = '{PassWord}' and state = 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } #endregion #region 用户登录登录 public static JC_UserInfo LoginNew_User(string UserName, string PassWord) { string tsql = $"SELECT * from JC_UserInfo where UserName = '{UserName}' and Password = '{PassWord}' and state = 1"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var list = tb.Rows[0].ToModel(); return list; } #endregion /// /// 注册客户 /// /// /// public static int InsertClient(JC_Client Model) { string tsql = $"INSERT INTO JC_Client(ClientName,UserName,Password,State,Authority,CreateId,CreateDate ) VALUES ('{Model.ClientName}','{Model.UserName}','{Model.Password}',{Convert.ToInt32(Model.State)},{(int)Model.Authority},{Model.CreateId},'{Model.CreateDate}');"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } /// /// 检查重名 客户 /// /// /// public static int CheckClientUserName(string UserName) { string tsql = $"SELECT COUNT(1) from JC_Client where UserName = '{UserName}' and state = 1;"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } /// /// 检查重名 用户 /// /// /// public static int CheckUserName(string UserName) { string tsql = $"SELECT COUNT(1) from JC_UserInfo where UserName = '{UserName}' and state = 1;"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } /// /// 报价单数据 /// /// /// public static DT_QuoteClientNum CheckQuoteClientNum(int QuoteId, int ClientId) { string tsql = $"SELECT * from DT_QuoteClientNum where QuoteId = {QuoteId} and ClientId = {ClientId};"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var model = tb.Rows[0].ToModel(); return model; } #endregion #region /// /// 根据id获取报价单数据 /// /// /// public static DT_Quote Select_DT_QuoteByQuoteId(int QuoteId) { string tsql = $"SELECT * from DT_Quote where Id = {QuoteId};"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var model = tb.Rows[0].ToModel(); return model; } #endregion #region 保存意向报价单数据 public static int Save_DT_QuoteClientNum(DT_QuoteClientNum Model, bool isInsert) { string tsql = ""; if (isInsert) { tsql = $"INSERT INTO DT_QuoteClientNum(QuoteId,ClientId,Cantidad,Valor,CreateDate) VALUES ({Model.QuoteId},{Model.ClientId},{Model.Cantidad},{Model.Valor},'{Model.CreateDate}');"; } else { tsql = $"UPDATE DT_QuoteClientNum set Cantidad = {Model.Cantidad},OldCantidad = {Model.OldCantidad},Valor = {Model.Valor},OldValor = {Model.OldValor},ChangeDate = '{Model.ChangeDate}' where Id = {Model.Id};"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); int a = Convert.ToInt32(result); return a; } #endregion #region 客户修改密码 public static int UpdateClientPassword(int ClientId, string NewPassword) { string tsql = $"UPDATE JC_Client set Password = '{NewPassword}' where Id = {ClientId};"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); int a = Convert.ToInt32(result); return a; } #endregion #region 删除意向报价单数据 public static int Delete_DT_QuoteClientNum(List Ids) { if (Ids.Count > 0) { string tsql = $"DELETE DT_QuoteClientNum where id in ({string.Join(",", Ids)});"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); object result = db.ExecuteScalar(cmd); int a = Convert.ToInt32(result); return a; } return -1; } #endregion #region 平台展示意向报价单查询 public static List GetListDT_Quote_New(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @" a.Id,a.Cantidad,a.Valor,a.ClientId,c.ClientName,b.Foto,b.Nombre,b.Caracteristicas,b.Modelo,b.Recio,b.QtyOrCtn,b.Cbm,b.Gw,b.Nw"; ser.Tables = @"[dbo].[DT_QuoteClientNum] a INNER JOIN DT_Quote b on a.QuoteId = b.Id INNER JOIN JC_Client c on a.ClientId = c.Id"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 平台展示意向报价单查询 public static DT_Quote_New GetADT_Quote_New(int Id) { string tsql = $"SELECT a.Cantidad,a.Valor,a.ClientId,c.ClientName,b.* FROM [dbo].[DT_QuoteClientNum] a INNER JOIN DT_Quote b on a.QuoteId = b.Id INNER JOIN JC_Client c on a.ClientId = c.Id where a.id = {Id};"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb.Rows.Count == 0) return null; var model = tb.Rows[0].ToModel(); return model; } #endregion #endregion #region public static List GetTemuShopGoodPriceList(int shopid, string sku, int pageIndex, int pageSize, out int rowCount) { var filt = " where 1=1 "; if (shopid > 0) { filt += " and a.Shopid=@shopid"; } if (!string.IsNullOrEmpty(sku)) { filt += " and (a.sku like '%" + sku + "%' or a.SPUID like '%" + sku + "%')"; } var sql = @"select COUNT(1) count from TemuShopGoodPrice a inner join JC_Shop b on a.Shopid=b.ShopId " + filt; sql += @" select t.ID,t.Shopid,t.ShopName,t.SPUID,t.SKU,t.SalePrice,t.CreateUserId,t.PostPrice from ( select ROW_NUMBER() over(order by a.id desc) row, a.*,b.ShopName from TemuShopGoodPrice a inner join JC_Shop b on a.Shopid=b.ShopId" + filt + ") t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); var ds = db.ExecuteDataSet(cmd); rowCount = (Int32)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } #endregion #region 保存SaveTemuShopGoodPrice public static void SaveTemuShopGoodPrice(TemuShopGoodPrice md) { var sql = @" if(@id>0) begin update TemuShopGoodPrice set Shopid=@shopid,spuid=@spuid,SKU=@sku,SalePrice=@salePrice,PostPrice=@PostPrice where id=@id end else begin insert into TemuShopGoodPrice(Shopid,spuid,SKU,SalePrice,CreateUserId,CreateTime,PostPrice) values(@shopid,@spuid,@sku,@salePrice,@createUserId,GETDATE(),@PostPrice) end"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, md.ID); db.AddInParameter(cmd, "@shopid", DbType.Int32, md.Shopid); db.AddInParameter(cmd, "@spuid", DbType.String, md.SPUID); db.AddInParameter(cmd, "@sku", DbType.String, md.SKU); db.AddInParameter(cmd, "@salePrice", DbType.Decimal, md.SalePrice); db.AddInParameter(cmd, "@createUserId", DbType.Int32, md.CreateUserId); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, md.PostPrice); db.ExecuteNonQuery(cmd); } #endregion #region 删除emuShopGoodPrice public static void DeleteTemuShopGoodPrice(int id) { var sql = @" delete from TemuShopGoodPrice where id=@id"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion public static List GetTemuShopGoodPrice(int shopid, string sku, string spuid) { var sql = @" select * from TemuShopGoodPrice where Shopid=@shopid and sku=@sku and spuid=@spuid "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); db.AddInParameter(cmd, "@sku", DbType.String, sku); db.AddInParameter(cmd, "@spuid", DbType.String, spuid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetTemuShopGoodActive(int shopid, string sku, string SKUID) { var sql = @" select * from TemuShopGoodActive where Shopid=@shopid and SKU=@sku and SPUID=@SKUID "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); db.AddInParameter(cmd, "@SKU", DbType.String, sku); db.AddInParameter(cmd, "@SKUID", DbType.String, SKUID); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static TemuShopGoodPrice GetTemuShopGoodPriceOne(int shopid, string spuid) { var sql = @" select top 1 * from TemuShopGoodPrice where Shopid=@shopid and spuid=@spuid "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); db.AddInParameter(cmd, "@spuid", DbType.String, spuid); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0].ToModel(); } return null; } #region public static JC_Shop GetShopByShopName(string name) { var sql = @" select * from JC_Shop where Shopname=@name"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@name", DbType.String, name); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) return dt.Rows[0].ToModel(); return null; } #endregion #region TEMU商品价格审核 public static List GetTemuShopGoodPriceChecks(int shopid, string sku, int? state, int pageIndex, int pageSize, out int rowCount) { var filt = " where 1=1 "; if (shopid > 0) { filt += " and a.shopid= " + shopid; } if (!string.IsNullOrEmpty(sku)) { filt += " and (a.sku like '%" + sku + "%' or a.SPUID like '%" + sku + "%')"; } if (state.HasValue && state.Value >= 0) { filt += " and a.state= " + state.Value; } var sql = @"select COUNT(*) count from TemuShopGoodPriceCheck a inner join JC_Shop b on a.Shopid=b.ShopId " + filt; sql += @"select * from ( select ROW_NUMBER() over(order by a.id desc) row,a.*,b.ShopName,c.UserName CreateUserName,d.UserName CheckUserName,e.GoodsId,f.InPrice,f.FeeRate,f.Solid from TemuShopGoodPriceCheck a inner join JC_Shop b on a.Shopid=b.ShopId left join HW_GoodsDetail e on a.SKU=e.SKU1 left join HW_GoodsInfo f on e.GoodsId=f.GoodsId left join JC_UserInfo c on a.CreateUserId=c.UserId left join JC_UserInfo d on a.CheckUserId=d.UserId " + filt + " ) t where t.row between " + ((pageIndex - 1) * pageSize + 1) + " and " + pageIndex * pageSize; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var ds = db.ExecuteDataSet(cmd); rowCount = (Int32)ds.Tables[0].Rows[0]["count"]; return ds.Tables[1].ToList(); } public static void SaveTemuShopGoodPriceCheck(TemuShopGoodPriceCheck md) { var sql = @"if @id>0 begin update TemuShopGoodPriceCheck set State=@state,CheckUserId=@checkUserid,CheckTime=GETDATE(),PostPrice=@PostPrice where ID=@id end else begin insert into TemuShopGoodPriceCheck(TemuShopGoodPriceId,Shopid,SPUID,SKU,BeforePrice,AfterPrice,State,CreateUserId,CreateTime,PostPrice) values(@TemuShopGoodPriceId,@shopid,@spuid,@sku,@beforePrice,@afterPrice,@state,@createUserId,GETDATE(),@PostPrice) end"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, md.ID); db.AddInParameter(cmd, "@TemuShopGoodPriceId", DbType.Int32, md.TemuShopGoodPriceId); db.AddInParameter(cmd, "@shopid", DbType.Int32, md.Shopid); db.AddInParameter(cmd, "@sku", DbType.String, md.SKU); db.AddInParameter(cmd, "@spuid", DbType.String, md.SPUID); db.AddInParameter(cmd, "@beforePrice", DbType.Decimal, md.BeforePrice); db.AddInParameter(cmd, "@afterPrice", DbType.Decimal, md.AfterPrice); db.AddInParameter(cmd, "@state", DbType.Int32, md.State); db.AddInParameter(cmd, "@checkUserid", DbType.Int32, md.CheckUserId); db.AddInParameter(cmd, "@createUserId", DbType.Int32, md.CreateUserId); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, md.PostPrice); db.ExecuteNonQuery(cmd); } /// /// 查询是否存在正在审核中 /// /// /// /// /// public static TemuShopGoodPriceCheck GetTemuShopGoodPriceCheck(int TemuShopGoodPriceId) { var sql = @"select * from TemuShopGoodPriceCheck where TemuShopGoodPriceId=@TemuShopGoodPriceId and State=0"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@TemuShopGoodPriceId", DbType.Int32, TemuShopGoodPriceId); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) return dt.Rows[0].ToModel(); return null; } public static void DeleteTemuShopGoodPriceCheck(int id) { var sql = @" delete from TemuShopGoodPriceCheck where id=@id"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } public static TemuShopGoodPriceCheck GetTemuShopGoodPriceCheckById(int id) { var sql = @"select * from TemuShopGoodPriceCheck where id=@id"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) return dt.Rows[0].ToModel(); return null; } public static List GetTemuShopGoodsByShop(int shopid) { var sql = @"select * from TemuShopGoodPrice where Shopid=@shopid"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static void CheckTemuShopGoodPrice(int id, int userid, int state) { var sql = @" update TemuShopGoodPriceCheck set State=@state ,CheckUserId=@userid ,CheckTime=GETDATE() where State=0 and id=@id if(@state=1) begin Update a set a.SalePrice=b.AfterPrice from TemuShopGoodPrice a inner join TemuShopGoodPriceCheck b on a.ID=b.TemuShopGoodPriceId where b.ID=@id and b.state=1 end "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@state", DbType.Int32, state); db.AddInParameter(cmd, "@userid", DbType.Int32, userid); db.ExecuteNonQuery(cmd); } #endregion #region public static void SaveTemuShopWareHouse(TemuShopWareHouse md) { var sql = @"if(exists(select 1 from TemuShopWareHouse where Shopid=@shopid and warehouseId=@warehouseId)) begin update TemuShopWareHouse set warehouseName=@warehouseName,defaultWarehouse=@defaultWarehouse where Shopid=@shopid and warehouseId=@warehouseId end else begin insert into TemuShopWareHouse(Shopid,warehouseId,warehouseName,defaultWarehouse,CreateTime) values(@shopid,@warehouseId,@warehouseName,@defaultWarehouse,GETDATE()) end"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@shopid", DbType.Int32, md.Shopid); db.AddInParameter(cmd, "@warehouseId", DbType.String, md.warehouseId); db.AddInParameter(cmd, "@warehouseName", DbType.String, md.warehouseName); db.AddInParameter(cmd, "@defaultWarehouse", DbType.Int32, md.defaultWarehouse); db.ExecuteNonQuery(cmd); } #endregion #region TEMU订单申请 public static void SaveTemuOrderShipTrackCode(TemuOrderShipTrackCode md) { var sql = @" if(not exists(select 1 from TemuOrderShipTrackCode where ParentOrderSn=@ParentOrderSn and TrackCode=@TrackCode)) begin insert into TemuOrderShipTrackCode(ParentOrderSn,TrackCode,SKU,Weight,Long,Width,Height,CreateTime) values(@ParentOrderSn,@TrackCode,@SKU,@Weight,@Long,@Width,@Height,getdate()) end else begin update TemuOrderShipTrackCode set SKU=@SKU,Weight=@Weight,Long=@Long,Width=@Width,Height=@Height where ParentOrderSn=@ParentOrderSn and TrackCode=@TrackCode end "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ParentOrderSn", DbType.String, md.ParentOrderSn); db.AddInParameter(cmd, "@TrackCode", DbType.String, md.TrackCode); db.AddInParameter(cmd, "@SKU", DbType.String, md.SKU); db.AddInParameter(cmd, "@Weight", DbType.String, md.Weight); db.AddInParameter(cmd, "@Long", DbType.String, md.Long); db.AddInParameter(cmd, "@Width", DbType.String, md.Width); db.AddInParameter(cmd, "@Height", DbType.String, md.Height); db.ExecuteNonQuery(cmd); } public static void SaveTemuShopOrderGoodsDetail(TemuShopOrderGoodsDetail md) { var sql = @" insert into TemuShopOrderGoodsDetail(Shopid,ParentOrderSn,OrderSn,OrderStatus,GoodsId,SKUId,ThumbUrl,Quantity,GoodsName,ProductList,CreateTime) values(@Shopid,@ParentOrderSn,@OrderSn,@OrderStatus,@GoodsId,@SKUId,@ThumbUrl,@Quantity,@GoodsName,@ProductList,GETDATE()) "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Shopid", DbType.Int32, md.Shopid); db.AddInParameter(cmd, "@ParentOrderSn", DbType.String, md.ParentOrderSn); db.AddInParameter(cmd, "@OrderSn", DbType.String, md.OrderSn); db.AddInParameter(cmd, "@OrderStatus", DbType.Int32, md.OrderStatus); db.AddInParameter(cmd, "@GoodsId", DbType.String, md.GoodsId); db.AddInParameter(cmd, "@SKUId", DbType.String, md.SKUId); db.AddInParameter(cmd, "@ThumbUrl", DbType.String, md.ThumbUrl); db.AddInParameter(cmd, "@Quantity", DbType.Int32, md.Quantity); db.AddInParameter(cmd, "@GoodsName", DbType.String, md.GoodsName); db.AddInParameter(cmd, "@ProductList", DbType.String, md.ProductList); db.ExecuteNonQuery(cmd); } public static void DeleteTemuShopOrderGoodsDetailByParentOrderSn(string parentOrderSn) { var sql = @" delete from TemuShopOrderGoodsDetail where ParentOrderSn=@ParentOrderSn "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ParentOrderSn", DbType.String, parentOrderSn); db.ExecuteNonQuery(cmd); } public static List GetTemuShopOrderGoodsDetails(string parentOrderSn) { var sql = @"select * from TemuShopOrderGoodsDetail where ParentOrderSn=@ParentOrderSn"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@ParentOrderSn", DbType.String, parentOrderSn); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetTemuShopWareHouses(int shopid) { var sql = @"select * from TemuShopWareHouse where Shopid=" + shopid; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static HW_GoodsDetail GetHW_GoodsDetailByTemuSKUid(int orderid, string goodsid, string skuid) { var sql = @" select top 1 b.* from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where OrderId=@orderid and GoodsName like '%" + goodsid + "%' and GoodsName like '%" + skuid + "%'"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows != null && dt.Rows.Count > 0) return dt.Rows[0].ToModel(); return null; } public static void SaveTemuOrderShipPackageSn(TemuOrderShipPackageSn md) { var sql = @" if( not exists (select 1 from TemuOrderShipPackageSn where OrderId=@orderid and PackageSn=@packageSn)) begin insert into TemuOrderShipPackageSn(OrderId,OrderCode,PackageSn,CreateTime) values(@orderid,@orderCode,@packageSn,GETDATE()) end"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, md.OrderId); db.AddInParameter(cmd, "@orderCode", DbType.String, md.OrderCode); db.AddInParameter(cmd, "@packageSn", DbType.String, md.PackageSn); db.ExecuteNonQuery(cmd); } public static List GetTemuOrderShipPackageSn(int orderid) { var sql = @" select * from TemuOrderShipPackageSn where OrderId=@orderid "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region TEMU发货订单重命名跟踪码图片 public static List GetTemuTrackCodeFileDatas(string orderCode) { var sql = @"select a.OrderId,a.OrderCode,b.TrackCode, b.LabelUrl,b.SKU, b.PostId,c.Name ExpressName from DT_OrderInfo a inner join DT_TrackCodeApply b on a.OrderId=b.OrderId inner join JC_Express c on b.PostId=c.ExpressID where a.OrderCode='" + orderCode + "' and b.State=1"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 获取待审批价格的数量 public static int GetTemuGoodPriceCheckingQty() { var sql = @" select COUNT(1) count from TemuShopGoodPriceCheck where State=0 "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return (Int32)dt.Rows[0]["count"]; } #endregion #region 修改订单基本信息 public static void UpdateOrderBaseInfo23(DT_OrderModelSave Model) { string tsql = @" if @JoinOrderCode<>'' begin Update DT_OrderInfo set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState,IsSyncToWMS=@IsSyncToWMS where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfo a inner join DT_OrderInfo b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode Update DT_OrderInfoNew set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where JoinOrderCode=@JoinOrderCode Update a set a.[ErrorInfo]=@ErrorInfo from DT_OrderXXInfoNew a inner join DT_OrderInfoNew b on a.OrderId=b.OrderId where b.JoinOrderCode=@JoinOrderCode end else begin Update [DT_OrderInfo] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState,IsSyncToWMS=@IsSyncToWMS where OrderId=@OrderId Update [DT_OrderXXInfo] set [ErrorInfo]=@ErrorInfo,StoreId=@StoreId where OrderId=@OrderId Update [DT_OrderInfoNew] set PostState=@PostState,IsFba=@IsFba,MoneyState=@MoneyState where OrderId=@OrderId Update [DT_OrderXXInfoNew] set [ErrorInfo]=@ErrorInfo,StoreId=@StoreId where OrderId=@OrderId end update DT_OrderInfo set escrowFee=@escrowFee where OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId); db.AddInParameter(cmd, "@ErrorInfo", DbType.String, Model.ErrorInfo); db.AddInParameter(cmd, "@PostState", DbType.Int32, Model.PostState); db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba); db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, Model.escrowFee); db.AddInParameter(cmd, "@MoneyState", DbType.Int32, Model.MoneyState); db.AddInParameter(cmd, "@JoinOrderCode", DbType.String, Model.JoinOrderCode); db.AddInParameter(cmd, "@StoreId", DbType.Int32, Model.StoreId); db.AddInParameter(cmd, "@IsSyncToWMS", DbType.Int32, Model.IsSyncToWMS); db.ExecuteNonQuery(cmd); } #endregion #region 二手售卖相关代码 #region 查询订单货物明细 public static List GetOrderGoodsListNew5(int OrderId) { //Weight2 用于预估运费 List list = null; string tsql = @" select a.Id,a.OrderId,d.PlatId,a.DetailId,a.GoodsNum,GoodsPrice=isnull(c.FeeRate,0),a.MoneyCode,a.LockNum,a.ChaseId,a.GoodsSKU,a.PostInfo,SKUState=case when a.DetailId>0 then '已经分配' else '未分配' end,GoodsName=case when c.GoodsName is null then a.GoodsName else c.GoodsName end,productImgUrl=case when productImgUrl is not null and productImgUrl<>'' then productImgUrl else '../images/no.jpg' end,TypeDesc=a.GoodsDesc,GoodsDesc=case when a.detailid<=0 then '' when a.detailid>0 and c.GoodsCode is not null and c.GoodsCode<>'' then c.GoodsCode+' '+b.TypeCode+'['+b.TypeDesc+']' else c.GoodsOldCode+' '+b.TypeCode+'['+b.TypeDesc+']' end,a.OldNum,c.GoodsCode,GoodsId=isnull(c.GoodsId,0),OldTypeDesc=case when a.OldTypeDesc is not null and a.OldTypeDesc<>'' then '改为'+a.OldTypeDesc+'发' else '' end,a.OldTypeCode,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,c.GoodsEnglisgName,InPrice=isnull(c.InPrice,0),c.Solid,c.GoodsInfo, Weight2=case when a.Fee6>0 and (a.Fee60 and (a.Fee70 and (a.Fee80 and (d.Fee60 and (d.Fee70 and (d.Fee8(); return list; } #endregion #region 查询订单货物明细 public static List GetOrderGoodsPostionCodeSecond(int OrderId) { List list = null; string tsql = @" select d.PlatId,b.Id,c.PostionCode,Price=isnull(a.Price,0),PostPrice=isnull(a.PostPrice,0),HWCFee=isnull(a.HWCFee,0),InPrice=isnull(f.InPrice,0),GoodsPrice=isnull(a.GoodsRate,0) from HW_GoodsInDetail a inner join DT_OrderGoods b on a.OrderGoodsId=b.Id inner join CK_StorePostion c on a.PostionId=c.PostionId inner join DT_OrderInfo d on b.OrderId=d.OrderId left join HW_GoodsDetail e on b.DetailId=e.DetailId left join HW_GoodsInfo f on e.GoodsId=f.GoodsId where b.OrderId=@OrderId "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); DataSet ds = db.ExecuteDataSet(cmd); list = ds.Tables[0].ToList(); return list; } #endregion #region 保存提货信息 public static void UpdateSecondHandBuyer(int id, bool isSecondHandBuyer, string SecondHandBuyerName, string SecondHandBuyerPhone, string SecondHandBuyerTime) { string tsql = @" update [DT_OrderReturn] set isSecondHandBuyer=@isSecondHandBuyer,SecondHandBuyerName=@SecondHandBuyerName,SecondHandBuyerPhone=@SecondHandBuyerPhone,SecondHandBuyerTime=@SecondHandBuyerTime where [id]=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@isSecondHandBuyer", DbType.Boolean, isSecondHandBuyer); db.AddInParameter(cmd, "@SecondHandBuyerName", DbType.String, SecondHandBuyerName); db.AddInParameter(cmd, "@SecondHandBuyerPhone", DbType.String, SecondHandBuyerPhone); db.AddInParameter(cmd, "@SecondHandBuyerTime", DbType.String, SecondHandBuyerTime); db.ExecuteNonQuery(cmd); } #endregion #region 更新二手商品的状态 public static void UpdateSecondHandType(int id, int SecondHandType) { string tsql = @" update [DT_OrderReturn] set SecondHandType=@SecondHandType where [id]=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@SecondHandType", DbType.Int32, SecondHandType); db.ExecuteNonQuery(cmd); } #endregion #region 分页查询 public static List GetListOrderReturnSecond(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"id=cast(a.id as int),c.ShopName,c.ShopId,order_amount=b.TotalPrice,Img_Url=f.FirstImgUrl,d.Name,a.orderid,a.ordercode,a.asin,a.return_reason_code,a.merchant_sku,a.in_policy,a.return_quantity,a.resolution,a.refund_amount,a.tracking_id,a.return_carrier,a.label_cost,a.order_date,a.return_request_date,a.return_request_status,a.ScanDate,a.InType,a.ScanState,a.ScanUserId,a.remark,a.PostionCode,a.detailid,a.BarCode,a.ImgUrl,a.ImgUrl2,a.ImgUrl3,a.ImgUrl4,a.ImgUrl5,Case when WorkDesc='东仓' then 'E' when WorkDesc='西仓' then 'W' else '' end StoreName,IsNull(a.IsOfferUp,0) IsOfferUp, IsNull(a.IsMaketPlace,0) IsMaketPlace,a.isSecondHand,a.SecondHandCode,a.SecondHandType,a.SecondHandImgUrl,a.isSecondHandBuyer,a.SecondHandBuyerName,a.SecondHandBuyerPhone,a.SecondHandBuyerTime,a.SecondHandSalePrice "; ser.Tables = @"DT_OrderReturn a with(nolock) left join DT_OrderInfo b with(nolock) on a.orderid=b.OrderId left join JC_Shop c with(nolock) on b.ShopId=c.ShopId left Join JC_UserInfo d with(nolock) on a.ScanUserId=d.UserId left join HW_GoodsDetail e with(nolock) on a.detailid=e.DetailId left join HW_GoodsInfo f with(nolock) on e.GoodsId=f.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存拖货信息 public static void UpdatePutawayMsgSecond(int id, decimal SecondHandSalePrice, int isOfferUp, int isMaketPlace) { string tsql = @" update [DT_OrderReturn] set SecondHandSalePrice=@SecondHandSalePrice,isOfferUp=@isOfferUp,isMaketPlace=@isMaketPlace where [id]=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.AddInParameter(cmd, "@SecondHandSalePrice", DbType.Decimal, SecondHandSalePrice); db.AddInParameter(cmd, "@isOfferUp", DbType.Int32, isOfferUp); db.AddInParameter(cmd, "@isMaketPlace", DbType.Int32, isMaketPlace); db.ExecuteNonQuery(cmd); } #endregion #endregion #region public static JC_Shop GetShopModel(int ShopId) { JC_Shop result = null; string query = "select * from JC_Shop where ShopId=@ShopId"; Database database = DatabaseFactory.CreateDatabase(); DbCommand sqlStringCommand = database.GetSqlStringCommand(query); database.AddInParameter(sqlStringCommand, "@ShopId", DbType.Int32, ShopId); DataTable dataTable = database.ExecuteDataTable(sqlStringCommand); if (dataTable.Rows.Count > 0) { result = dataTable.Rows[0].ToModel(); } return result; } #endregion #region 执行存储过程,把ERP订单转到WMS public static void SyncERPOrderToWMS(DateTime sDate, DateTime eDate) { Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetStoredProcCommand("SyncOrdersToWMS"); db.AddInParameter(cmd, "@sdate", DbType.DateTime, sDate); db.AddInParameter(cmd, "@edate", DbType.DateTime, eDate); db.ExecuteNonQuery(cmd); } #endregion #region 根据订单号修改订单运费 public static int UpdateDT_FeeYFByOrderCode(string orderCode, decimal fee) { //var sql = @"update a set a.yf=@fee from DT_Fees a with (nolock) inner join DT_OrderInfo b with (nolock) on a.orderid=b.OrderId where b.OrderCode=@orderCode"; var sql = @" declare @orderid int set @orderid=0 select top 1 @orderid= OrderId from DT_OrderInfo with (nolock) where OrderCode=@orderCode if(ISNULL(@orderid,0)!=0) begin update DT_Fees set yf=@fee where orderid=@orderid select 1 end else select 0 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@fee", DbType.Decimal, fee); db.AddInParameter(cmd, "@orderCode", DbType.String, orderCode); int a = (Int32)db.ExecuteScalar(cmd); return a; } #endregion #region 运营申请sku数量相关 #region 获取店铺信息 /// /// 获取店铺信息 /// /// 查询时间 /// 查询人 /// public static Dictionary GetShopUserId() { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = new Dictionary(); shopMsg.Add(15, "guserid_shopify"); shopMsg.Add(18, "guserid_wayfair"); shopMsg.Add(21, "guserid_sheIn"); shopMsg.Add(3, "guserid_ebay"); shopMsg.Add(6, "guserid_wlmart"); shopMsg.Add(2, "muserid"); shopMsg.Add(22, "guserid_tiktok"); shopMsg.Add(23, "guserid_temu"); return shopMsg; } #endregion #region 查询某人分配的货物信息 /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static List GetGoodsListByUserId(int userid) { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = GetShopUserId(); //循环获取订单数据 foreach (var sMsg in shopMsg) { string tsql = @"select GoodsID,GoodsCode from HW_GoodsInfo where " + sMsg.Value + @" = @skuUserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@skuUserId", DbType.Int32, userid); DataTable tb = db.ExecuteDataTable(cmd); var list = tb.ToList(); if (list != null && list.Count() > 0) { var model = new UserSkuList() { goodsMsgModel = list, PlatId = sMsg.Key, UserId = userid }; ListModel.Add(model); } } return ListModel; } #endregion public static int GetGoodsIdByCode(string goodsCode) { int GoodsId = 0; try { var sql = @" select top 1 GoodsId from HW_GoodsInfo where GoodsCode=@GoodsCode "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@GoodsCode", DbType.String, goodsCode); var dt = db.ExecuteDataTable(cmd); GoodsId = Convert.ToInt32(dt.Rows[0]["GoodsId"]); } catch { GoodsId = 0; } return GoodsId; } public static decimal GetQuantityPrice(int YYUserId) { decimal GoodsId = 0; try { var sql = @" SELECT SUM(a.Quantity*b.ApplyPrice) as QuantityPrice FROM CK_GoodsApply a LEFT JOIN CK_GoodsApplyPrice b on a.GoodsId = b.GoodsId"; if (YYUserId != 1) sql += $" where a.UserId = {YYUserId}"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); GoodsId = Convert.ToDecimal(dt.Rows[0]["QuantityPrice"]); } catch { GoodsId = 0; } return GoodsId; } public static decimal GetQuantityPrice(List YYUserIdList) { decimal GoodsId = 0; try { var sql = @" SELECT SUM(a.Quantity*b.ApplyPrice) as QuantityPrice FROM CK_GoodsApply a LEFT JOIN CK_GoodsApplyPrice b on a.GoodsId = b.GoodsId"; if (YYUserIdList.Count() >= 0) sql += $" where a.UserId in ({string.Join(",", YYUserIdList)})"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); GoodsId = Convert.ToDecimal(dt.Rows[0]["QuantityPrice"]); } catch { GoodsId = 0; } return GoodsId; } public static decimal GetOnePrice(int GoodsId) { decimal ApplyPrice = 0; try { var sql = $" SELECT ApplyPrice from CK_GoodsApplyPrice where GoodsId ={GoodsId} "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); ApplyPrice = Convert.ToDecimal(dt.Rows[0]["ApplyPrice"]); } catch { ApplyPrice = 0; } return ApplyPrice; } public static int isYYGroupLeader(int UserId) { int ApplyPrice = 0; try { var sql = $"SELECT isGroupLeader from JC_YYUserInfo where UserId = {UserId}"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); if (dt.Rows[0]["isGroupLeader"] != null) { ApplyPrice = Convert.ToInt32(dt.Rows[0]["isGroupLeader"]); } } catch { ApplyPrice = 0; } return ApplyPrice; } #region 保存 public static int Save_CK_GoodsApply(CK_GoodsApply Model) { string tsql = @" if @Id>0 begin Update [CK_GoodsApply] set [GoodsId]=@GoodsId,[Quantity]=@Quantity,[InDate]=@InDate where Id=@Id end else begin INSERT INTO [CK_GoodsApply]([UserId],[GoodsId],[Quantity],[InDate])values(@UserId,@GoodsId,@Quantity,@InDate) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@Quantity", DbType.Int32, Model.Quantity); db.AddInParameter(cmd, "@InDate", DbType.DateTime2, Model.InDate); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } public static int Save_CK_GoodsApplyPrice(CK_GoodsApplyPrice Model) { string tsql = @" if @Id>0 begin Update [CK_GoodsApplyPrice] set [GoodsId]=@GoodsId,[ApplyPrice]=@ApplyPrice,[InPrice]=@InPrice,[FirstFreight]=@FirstFreight,[AllFreight]=@AllFreight,[FeeRate]=@FeeRate,[TaxesPrice]=@TaxesPrice where GoodsId=@GoodsId end else begin INSERT INTO [CK_GoodsApplyPrice]([GoodsId],[ApplyPrice],[InPrice],[FirstFreight],[AllFreight],[FeeRate],[TaxesPrice])values(@GoodsId,@ApplyPrice,@InPrice,@FirstFreight,@AllFreight,@FeeRate,@TaxesPrice) set @Id=SCOPE_IDENTITY() end select @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@ApplyPrice", DbType.Decimal, Model.ApplyPrice); db.AddInParameter(cmd, "@InPrice", DbType.Decimal, Model.InPrice); db.AddInParameter(cmd, "@FirstFreight", DbType.Decimal, Model.FirstFreight); db.AddInParameter(cmd, "@AllFreight", DbType.Decimal, Model.AllFreight); db.AddInParameter(cmd, "@FeeRate", DbType.Decimal, Model.FeeRate); db.AddInParameter(cmd, "@TaxesPrice", DbType.Decimal, Model.TaxesPrice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } public static CK_GoodsApplyPrice GetModel_CK_GoodsApplyPriceByGoodsId(int GoodsId) { CK_GoodsApplyPrice model = new CK_GoodsApplyPrice(); var sql = @" SELECT * from CK_GoodsApplyPrice where GoodsId=@GoodsId "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { model = dt.Rows[0].ToModel(); } return model; } #endregion #region 分页查询 public static List GetList_CK_GoodsApply(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.*,b.SKU1,c.UserName"; ser.Tables = @"CK_GoodsApply a LEFT JOIN HW_GoodsDetail b on a.DetailId = b.DetailId LEFT JOIN JC_UserInfo c on a.UserId = c.UserId "; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 删除 public static CK_GoodsApply Delete_CK_GoodsApply(int Id) { CK_GoodsApply model = null; string tsql = @" delete from CK_GoodsApply where Id=@Id "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataSet ds = db.ExecuteDataSet(cmd); return model; } #endregion #region 查找 public static CK_GoodsApply GetModel_CK_GoodsApply(int Id) { CK_GoodsApply model = new CK_GoodsApply(); var sql = @" SELECT a.*,b.GoodsCode,c.UserName from CK_GoodsApply a LEFT JOIN HW_GoodsInfo b on a.GoodsId = b.GoodsId LEFT JOIN JC_UserInfo c on a.UserId = c.UserId where Id=@Id "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { model = dt.Rows[0].ToModel(); } return model; } public static List GetGoodsApplyListByMsg(string str) { List model = new List(); var sql = @" SELECT * from CK_GoodsApply"; if (!string.IsNullOrEmpty(str)) { sql += $" where {str}"; } var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { model = dt.ToList(); } return model; } public static List GetList_CK_GoodsApplyByGoodsId(int GoodsId, int UserId) { List ListModel = new List(); var sql = @"SELECT a.*,b.GoodsCode,c.UserName,d.ApplyPrice*a.Quantity as OneAllPrice from CK_GoodsApply a LEFT JOIN HW_GoodsInfo b on a.GoodsId = b.GoodsId LEFT JOIN JC_UserInfo c on a.UserId = c.UserId LEFT JOIN CK_GoodsApplyPrice d on d.GoodsId = b.GoodsId where a.GoodsId=@GoodsId and a.UserId=@UserId"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); var dt = db.ExecuteDataTable(cmd); //if (dt != null && dt.Rows.Count > 0) //{ // model= dt.Rows[0].ToModel(); //} ListModel = dt.ToList(); return ListModel; } public static List GetQuantity_GoodsApplyByUserId(int UserId) { List ListModel = new List(); var sql = @"SELECT a.UserId,ISNULL(SUM(b.Quantity), 0) AS AllQuantity,ISNULL(SUM(b.Quantity*c.ApplyPrice),0) as QuantityPrice from ( SELECT DISTINCT UserId from JC_YYUserInfo) a LEFT JOIN CK_GoodsApply b on a.UserId = b.UserId LEFT JOIN CK_GoodsApplyPrice c on c.GoodsId = b.GoodsId GROUP BY a.UserId "; if (UserId != 1) { sql = @" SELECT a.UserId,ISNULL(SUM(b.Quantity), 0) AS AllQuantity,ISNULL(SUM(b.Quantity*c.ApplyPrice),0) as QuantityPrice from ( SELECT DISTINCT UserId from JC_YYUserInfo) a LEFT JOIN CK_GoodsApply b on a.UserId = b.UserId LEFT JOIN CK_GoodsApplyPrice c on c.GoodsId = b.GoodsId where a.UserId=@UserId GROUP BY a.UserId "; } var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); var dt = db.ExecuteDataTable(cmd); //if (dt != null && dt.Rows.Count > 0) //{ // model= dt.Rows[0].ToModel(); //} ListModel = dt.ToList(); return ListModel; } public static List GetQuantity_GoodsApplyByUserId(List UserIdList) { List ListModel = new List(); var sql = @"SELECT a.UserId,ISNULL(SUM(b.Quantity), 0) AS AllQuantity,ISNULL(SUM(b.Quantity*c.ApplyPrice),0) as QuantityPrice from JC_YYUserInfo a LEFT JOIN CK_GoodsApply b on a.UserId = b.UserId LEFT JOIN CK_GoodsApplyPrice c on c.GoodsId = b.GoodsId GROUP BY a.UserId "; if (UserIdList.Count() >= 0) { sql = $" SELECT a.UserId,ISNULL(SUM(b.Quantity), 0) AS AllQuantity,ISNULL(SUM(b.Quantity*c.ApplyPrice),0) as QuantityPrice from JC_YYUserInfo a LEFT JOIN CK_GoodsApply b on a.UserId = b.UserId LEFT JOIN CK_GoodsApplyPrice c on c.GoodsId = b.GoodsId where a.UserId in ({string.Join(",", UserIdList)}) GROUP BY a.UserId "; } var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); //db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); var dt = db.ExecuteDataTable(cmd); //if (dt != null && dt.Rows.Count > 0) //{ // model= dt.Rows[0].ToModel(); //} ListModel = dt.ToList(); return ListModel; } public static CK_GoodsApply GetModel_CK_GoodsApply(int UserId, int GoodsId) { CK_GoodsApply model = new CK_GoodsApply(); var sql = @" SELECT a.*,b.GoodsCode,c.UserName from CK_GoodsApply a LEFT JOIN HW_GoodsInfo b on a.GoodsId = b.GoodsId LEFT JOIN JC_UserInfo c on a.UserId = c.UserId where a.UserId=@UserId and a.GoodsId=@GoodsId"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@UserId", DbType.Int32, UserId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { model = dt.Rows[0].ToModel(); } return model; } public static CK_GoodsApply_GoodsPlat GetModel_GoodsPlat(int GoodsId) { CK_GoodsApply_GoodsPlat model = new CK_GoodsApply_GoodsPlat(); var sql = @" SELECT guserid_shopify,guserid_wayfair,guserid_sheIn,guserid_ebay,guserid_wlmart,muserid,guserid from HW_GoodsInfo where GoodsId = @GoodsId"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); var dt = db.ExecuteDataTable(cmd); if (dt != null && dt.Rows.Count > 0) { model = dt.Rows[0].ToModel(); } return model; } #endregion #region 汇总数据 public static DataTable GetAllList_CK_GoodsApply() { CK_GoodsApply model = new CK_GoodsApply(); var sql = @" DECLARE @cols AS NVARCHAR(MAX), @query AS NVARCHAR(MAX) -- 动态构建列名 SELECT @cols = COALESCE(@cols + ',','') + QUOTENAME(Month) FROM ( SELECT DISTINCT c.UserName as Month FROM CK_GoodsApply a LEFT JOIN JC_UserInfo c on a.UserId = c.UserId ) a -- 构建动态SQL语句 SET @query = 'WITH CTE AS ( SELECT hw.SKU1, hw.DetailId, c.UserName, ck.Quantity FROM CK_GoodsApply ck LEFT JOIN HW_GoodsDetail hw on ck.DetailId = hw.DetailId LEFT JOIN JC_UserInfo c on ck.UserId = c.UserId ) SELECT SKU1, DetailId, ' + @cols + ' FROM CTE PIVOT( SUM(Quantity) FOR UserName IN (' + @cols + ') ) pvt WHERE SKU1 IS NOT NULL ' -- 执行动态SQL EXEC sp_executesql @query "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); //if (dt != null && dt.Rows.Count > 0) //{ // model = dt.Rows[0].ToModel(); //} return dt; } #endregion #region 运营人员 public static List GetList_YYUser(string where) { string tsql = @"SELECT DISTINCT a.UserId as ID,a.Name from JC_UserInfo a INNER JOIN JC_YYUserInfo b on a.UserId = b.UserId "; if (!string.IsNullOrEmpty(where)) { tsql += where; } List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 汇总查询 public static List GetListHW_GoodsInfoNewForApplySku(string yySqlStr, int CompanyId, string SKU, int IsDH, int IsBH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (@SKU='' or a.SKU1 like '%'+@SKU+'%' or a.SKU2 like '%'+@SKU+'%' or a.SKU3 like '%'+@SKU+'%' or a.SKU4 like '%'+@SKU+'%' or a.SKU5 like '%'+@SKU+'%' or a.SKU6 like '%'+@SKU+'%' or a.TypeCode like '%'+@SKU+'%' or a.TypeDesc like '%'+@SKU+'%' or b.GoodsName like '%'+@SKU+'%' or b.GoodsCode like '%'+@SKU+'%') and (@IsDH=0 or a.NoGoods=1) and (@IsSafe=0 or a.SafeNum>0) "; if (!string.IsNullOrEmpty(yySqlStr)) { tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId where b.CompanyId=@CompanyId and (@SKU='' or a.SKU1 like '%'+@SKU+'%' or a.SKU2 like '%'+@SKU+'%' or a.SKU3 like '%'+@SKU+'%' or a.SKU4 like '%'+@SKU+'%' or a.SKU5 like '%'+@SKU+'%' or a.SKU6 like '%'+@SKU+'%' or a.TypeCode like '%'+@SKU+'%' or a.TypeDesc like '%'+@SKU+'%' or b.GoodsName like '%'+@SKU+'%' or b.GoodsCode like '%'+@SKU+'%') and (@IsDH=0 or a.NoGoods=1) and (@IsSafe=0 or a.SafeNum>0) and " + yySqlStr; } string[] templist = SKU.Split(' '); if (templist.Length > 1) { tsql1 = @" select distinct a.GoodsId from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId WHERE (a.TypeCode LIKE '%" + templist[0] + @"%' OR a.TypeDesc LIKE '%" + templist[0] + @"%' OR b.GoodsCode LIKE '%" + templist[0] + @"%' OR b.GoodsOldCode LIKE '%" + templist[0] + @"%' OR b.GoodsName LIKE '%" + templist[0] + @"%') and (a.TypeCode LIKE '%" + templist[1] + @"%' OR a.TypeDesc LIKE '%" + templist[1] + @"%' OR b.GoodsCode LIKE '%" + templist[1] + @"%' OR b.GoodsOldCode LIKE '%" + templist[1] + @"%' OR b.GoodsName LIKE '%" + templist[1] + @"%') "; } if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,b.GoodsNum,GoodsOutNum=isnull(b.GoodsNum,0)+isnull(b.GoodsInNum2,0),GoodsInNum2=isnull(b.GoodsInNum2,0),b.GoodsInNum,b.LeftNum,b.GoodsHJNum2,b.GoodsHJNum3,b.GoodsHJNum4,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,b.GoodsHJNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.State,NoGoodsState=case when a.NoGoods=1 then '是' else '否' end,a.Cert,a.UpOff,NoticeDays=case when b.GoodsHJNum2-isnull(b.GoodsNum,0)-isnull(b.GoodsInNum2,0)>0 then b.GoodsHJNum2/3 else 0 end,GoodsInNum3=isnull(b.GoodsInNum,0),IsNull(a.IsYC,0) IsYC,Case when IsNull(a.IsYC,0)=0 then '隐藏' else '显示' end YCXS "; if (SKU != "" || IsDH == 1 || IsBH == 1) { ser.Tables = @"(select * from HW_GoodsInfo a with(nolock) where GoodsId in (" + tsql1 + @"))a left join ( select GoodsId,GoodsNum=isnull(SUM(GoodsNum),0),GoodsHJNum=isnull(SUM(GoodsHJNum),0),GoodsHJNum2=isnull(SUM(GoodsHJNum2),0),GoodsHJNum3=isnull(SUM(GoodsHJNum3),0),GoodsHJNum4=isnull(SUM(GoodsHJNum4),0),GoodsInNum=isnull(SUM(GoodsInNum),0),GoodsInNum2=isnull(SUM(GoodsInNum2),0),LeftNum=isnull(SUM(GoodsNum),0)+isnull(SUM(GoodsInNum2),0)-isnull(SUM(GoodsPlanNum),0) from HW_GoodsDetail with(nolock) group by GoodsId)b on a.GoodsId=b.GoodsId"; } else ser.Tables = @"HW_GoodsInfo a with(nolock) left join ( select GoodsId,GoodsNum=isnull(SUM(GoodsNum),0),GoodsHJNum=isnull(SUM(GoodsHJNum),0),GoodsHJNum2=isnull(SUM(GoodsHJNum2),0),GoodsInNum=isnull(SUM(GoodsInNum),0),GoodsHJNum3=isnull(SUM(GoodsHJNum3),0),GoodsHJNum4=isnull(SUM(GoodsHJNum4),0),GoodsInNum2=isnull(SUM(GoodsInNum2),0),LeftNum=isnull(SUM(GoodsNum),0)+isnull(SUM(GoodsInNum2),0)-isnull(SUM(GoodsPlanNum),0) from HW_GoodsDetail with(nolock) group by GoodsId)b on a.GoodsId=b.GoodsId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "GoodsId"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); db.AddInParameter(cmd, "@IsDH", DbType.Int32, IsDH); db.AddInParameter(cmd, "@IsSafe", DbType.Int32, IsBH); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } public static List GetAllListCK_GoodsInfoNew(int CompanyId, List gooodsIdList) { string tsql = @"select GoodsId=cast(a.GoodsId as int),a.GoodsCode,a.GoodsEg,a.GoodsNo,a.GoodsOldCode,a.SortId,a.SortName,a.SupplierId,a.GoodsName,a.GoodsEnglisgName,b.GoodsNum,GoodsOutNum=isnull(b.GoodsNum,0)+isnull(b.GoodsInNum2,0),GoodsInNum2=isnull(b.GoodsInNum2,0),b.GoodsInNum,b.GoodsHJNum2,b.GoodsHJNum3,b.GoodsHJNum4,a.InPrice,a.NowPrice,a.Weight,a.WeightUnit,a.Solid,a.SolidUnit,a.Position,a.InDate,a.UpdateDate,a.FirstImgUrl,a.GoodsImageIds,a.CompanyId,a.GoodsPlanNum,b.GoodsHJNum,a.SafeNum,a.HGCode,a.HGCompanyCode,a.UpdateName,a.GoodsRemark,a.AutoPlan,a.NoGoods,a.AvgTime,a.State,NoGoodsState=case when a.NoGoods=1 then '是' else '否' end,a.Cert,a.UpOff,NoticeDays=case when b.GoodsHJNum2-isnull(b.GoodsNum,0)-isnull(b.GoodsInNum2,0)>0 then b.GoodsHJNum2/3 else 0 end,GoodsInNum3=isnull(b.GoodsInNum,0),IsNull(a.IsYC,0) IsYC,Case when IsNull(a.IsYC,0)=0 then '隐藏' else '显示' end YCXS,a.FeeRate "; tsql += @"from HW_GoodsDetail b with(nolock) inner join HW_GoodsInfo a with(nolock) on a.GoodsId=b.GoodsId "; if (gooodsIdList.Count() > 0) { tsql += @"where a.CompanyId=@CompanyId and a.State =1 and a.GoodsId in (" + string.Join(",", gooodsIdList) + ") ORDER BY a.GoodsId DESC "; } else { tsql += @"where a.CompanyId=@CompanyId and a.State =1 ORDER BY a.GoodsId DESC "; } List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetDetailIdList_CKGoodsApply(int UserId) { string tsql = @"SELECT DISTINCT DetailId from CK_GoodsApply"; if (UserId != 1) { tsql += $" where UserId in ({UserId})"; } List ListModel = new List(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); // 检查DataTable是否非空 if (tb != null && tb.Rows.Count > 0) { // 遍历DataTable的每一行 foreach (DataRow row in tb.Rows) { // 添加DetailId到ListModel中 ListModel.Add(row["DetailId"].ToString()); } // 现在ListModel包含了所有的DetailId } return ListModel; } public static List GetGoodsIdList_CKGoodsApply(int UserId) { string tsql = @"SELECT DISTINCT GoodsId from CK_GoodsApply"; if (UserId != 1) { tsql += $" where UserId in ({UserId})"; } List ListModel = new List(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); // 检查DataTable是否非空 if (tb != null && tb.Rows.Count > 0) { // 遍历DataTable的每一行 foreach (DataRow row in tb.Rows) { // 添加DetailId到ListModel中 ListModel.Add(row["GoodsId"].ToString()); } // 现在ListModel包含了所有的DetailId } return ListModel; } public static List GetGoodsIdList_CKGoodsApply(List UserIdList) { string tsql = @"SELECT DISTINCT GoodsId from CK_GoodsApply"; if (UserIdList.Count() >= 0) { tsql += $" where UserId in ({string.Join(",", UserIdList)})"; } List ListModel = new List(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); // 检查DataTable是否非空 if (tb != null && tb.Rows.Count > 0) { // 遍历DataTable的每一行 foreach (DataRow row in tb.Rows) { // 添加DetailId到ListModel中 ListModel.Add(row["GoodsId"].ToString()); } // 现在ListModel包含了所有的DetailId } return ListModel; } #endregion #endregion #region 保存TEMU平台订单返回的快递运费数据 public static void SaveTemuOrderPostFee(TemuOrderPostFee md) { var sql = @" if( exists(select 1 from TemuOrderPostFee where OrderId=@OrderId and WareHouseId=@WareHouseId and ChannelId=@ChannelId) ) begin update TemuOrderPostFee set WareHouseId=@WareHouseId,WareHouseName=@WareHouseName,PostFee=@PostFee,EstimatedText=@EstimatedText,ShipLogisticsType=@ShipLogisticsType,ShippingCompanyName=@ShippingCompanyName,ShipCompanyId=@ShipCompanyId,ChannelId=@ChannelId where OrderId=@OrderId and WareHouseId=@WareHouseId and ChannelId=@ChannelId end else begin insert into TemuOrderPostFee(OrderId,WareHouseId,WareHouseName,PostFee,EstimatedText,ShipLogisticsType,ShippingCompanyName,ShipCompanyId,ChannelId,CreateTime) values(@OrderId,@WareHouseId,@WareHouseName,@PostFee,@EstimatedText,@ShipLogisticsType,@ShippingCompanyName,@ShipCompanyId,@ChannelId,GETDATE()) end if(not exists(select 1 from GetTemuOrderPostFee where OrderId=@OrderId)) begin insert into GetTemuOrderPostFee(OrderId,CreateTime) values(@OrderId,GETDATE()) end "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, md.OrderId); db.AddInParameter(cmd, "@WareHouseId", DbType.String, md.WareHouseId); db.AddInParameter(cmd, "@WareHouseName", DbType.String, md.WareHouseName); db.AddInParameter(cmd, "@PostFee", DbType.Decimal, md.PostFee); db.AddInParameter(cmd, "@EstimatedText", DbType.String, md.EstimatedText); db.AddInParameter(cmd, "@ShipLogisticsType", DbType.String, md.ShipLogisticsType); db.AddInParameter(cmd, "@ShippingCompanyName", DbType.String, md.ShippingCompanyName); db.AddInParameter(cmd, "@ShipCompanyId", DbType.String, md.ShipCompanyId); db.AddInParameter(cmd, "@ChannelId", DbType.String, md.ChannelId); db.ExecuteNonQuery(cmd); } #endregion #region 查询还没有获取到渠道价格的TEMU订单 public static List GetTemuNoPostFeeOrders() { var sql = @" select top 1000 a.* from DT_OrderInfo a left join GetTemuOrderPostFee b on a.OrderId=b.OrderId where ShopId in (92,93) and State>0 and State<3 and ISNULL(b.Orderid,0)=0 order by OrderDate desc"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 保存TEMU平台订单返回的快递运费数据 public static void SaveGetTemuOrderPostFee(int orderid) { var sql = @" if(not exists(select 1 from GetTemuOrderPostFee where OrderId=@OrderId)) begin insert into GetTemuOrderPostFee(OrderId,CreateTime) values(@OrderId,GETDATE()) end "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, orderid); db.ExecuteNonQuery(cmd); } #endregion #region 查询某人某日分配sku的订单总和信息 /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static List MRJL_GetUserOderMsgByDay(DateTime sDate, DateTime eDate, int userid) { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = GetShopUserId(); //循环获取订单数据 foreach (var sMsg in shopMsg) { string tsql = @" select oi.ShopId, OrderNum = COUNT(0), RMBMoney = SUM(RMBPrice), escrowFee = sum(isnull(oi.escrowFee, 0)), USDMoney = SUM(oi.TotalPrice), InPrice = SUM(fee.cb), ckfee = SUM(fee.ck), mdfee = SUM(fee.md), adfee = SUM(oi.Ad_Fee), yf = SUM(fee.yf), LR=SUM(isnull(TotalPrice, 0) - isnull(escrowFee, 0) - isnull(yj, 0) - isnull(yf, 0) -((isnull(cb, 0) + isnull(hwsf, 0)) / moneyrate) - isnull(tc, 0) - isnull(ck, 0) - isnull(md, 0) - isnull(Ad_Fee, 0) + SubsidyFee) from DT_OrderInfo oi with(nolock) left join DT_Fees fee with(nolock) on oi.OrderId = fee.orderid left join DT_OrderGoods og with(nolock) on oi.OrderId=og.OrderId left join HW_GoodsDetail hgd with(nolock) on hgd.DetailId=og.DetailId where CONVERT(date, oi.OrderDate) <= @eDate and CONVERT(date, oi.OrderDate) >= @sDate and oi.ShopId in (select DISTINCT ShopId from JC_Shop where PlatType = @PlatType) and hgd.GoodsID in (select GoodsID from HW_GoodsInfo where " + sMsg.Value + @" = @skuUserId) group by oi.ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@PlatType", DbType.Int32, sMsg.Key); db.AddInParameter(cmd, "@skuUserId", DbType.Int32, userid); DataTable tb = db.ExecuteDataTable(cmd); var list = tb.ToList(); if (list != null && list.Count() > 0) { ListModel.AddRange(list); } } return ListModel; } #endregion #region 查询某人某日分配sku的订单总和信息 /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static List MRJL_GetUserOderDetailMsgByDay(DateTime sDate, DateTime eDate, int userid) { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = GetShopUserId(); //循环获取订单数据 foreach (var sMsg in shopMsg) { string tsql = @" select oi.ShopId, oi.OrderCode, oi.OrderId, oi.RMBPrice, escrowFee = isnull(oi.escrowFee, 0), USDMoney = oi.TotalPrice, InPrice = fee.cb, ckfee = fee.ck, mdfee = fee.md, adfee = oi.Ad_Fee, yf = fee.yf, LR=isnull(TotalPrice, 0) - isnull(escrowFee, 0) - isnull(yj, 0) - isnull(yf, 0) -((isnull(cb, 0) + isnull(hwsf, 0)) / moneyrate) - isnull(tc, 0) - isnull(ck, 0) - isnull(md, 0) - isnull(Ad_Fee, 0) + SubsidyFee, hgd.GoodsID, GoodsCode=hgd.SKU1, oi.InDate, PlatId=@PlatType from DT_OrderInfo oi with(nolock) left join DT_Fees fee with(nolock) on oi.OrderId = fee.orderid left join DT_OrderGoods og with(nolock) on oi.OrderId=og.OrderId left join HW_GoodsDetail hgd with(nolock) on hgd.DetailId=og.DetailId where CONVERT(date, oi.OrderDate) <= @eDate and CONVERT(date, oi.OrderDate) >= @sDate and oi.ShopId in (select DISTINCT ShopId from JC_Shop where PlatType = @PlatType) and hgd.GoodsID in (select GoodsID from HW_GoodsInfo where " + sMsg.Value + @" = @skuUserId) "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@PlatType", DbType.Int32, sMsg.Key); db.AddInParameter(cmd, "@skuUserId", DbType.Int32, userid); DataTable tb = db.ExecuteDataTable(cmd); var list = tb.ToList(); if (list != null && list.Count() > 0) { ListModel.AddRange(list); } } return ListModel; } #endregion #region 查询某人某日分配sku的订单的goodsid信息 /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static List MRJL_GetGoodsIdByDay(DateTime sDate, DateTime eDate, int userid) { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = GetShopUserId(); //循环获取订单数据 foreach (var sMsg in shopMsg) { string tsql = @"select DISTINCT oi.PlatId,oi.ShopId,hgd.GoodsID from DT_OrderInfo oi with(nolock) left join DT_OrderGoods og with(nolock) on oi.OrderId=og.OrderId left join HW_GoodsDetail hgd with(nolock) on hgd.DetailId=og.DetailId where CONVERT(date, oi.OrderDate) <= @eDate AND CONVERT(date, oi.OrderDate) >= @sDate and oi.ShopId in (select DISTINCT ShopId from JC_Shop where PlatType = @PlatType) and hgd.GoodsID in (select GoodsID from HW_GoodsInfo where " + sMsg.Value + @" = @skuUserId)"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@PlatType", DbType.Int32, sMsg.Key); db.AddInParameter(cmd, "@skuUserId", DbType.Int32, userid); DataTable tb = db.ExecuteDataTable(cmd); var list = tb.ToList(); if (list != null && list.Count() > 0) { ListModel.AddRange(list); } } return ListModel; } #endregion #region 获取月广告信息 /// /// 获取月广告信息 /// /// 查询时间 /// 查询人 /// public static BB_MRJL_Adfee MRJL_GetGKFeeByMouth(DateTime sDate, DateTime eDate, int plat, int shopid, List goodsIds) { //返回数据 BB_MRJL_Adfee model = new BB_MRJL_Adfee(); string tsql = ""; if (goodsIds.Count() > 0) { string goodsIdStr = string.Join(",", goodsIds); //亚马逊 if (plat == 2) { tsql = @" SELECT shopid,Adfee=SUM(isnull(adfeenew, 0)) from AD_FeeList where CONVERT(date, addate) <= @eDate and CONVERT(date, addate) >= @sDate and shopid = @shopid and goodsid in (" + goodsIdStr + @") GROUP BY shopid"; } else { tsql = @" SELECT shopid,Adfee=SUM(isnull(adfee, 0)) from ShopGoodsAdFee where CONVERT(date, addate) <= @eDate and CONVERT(date, addate) >= @sDate and shopid = @shopid and goodsid in (" + goodsIdStr + @") GROUP BY shopid"; } } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@shopid", DbType.Int32, shopid); DataTable tb = db.ExecuteDataTable(cmd); //ListModel = tb.ToList(); if (tb != null && tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #region 查询某人某日分配sku的订单 /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static List MRJL_GetUserListByDay(DateTime sDate, DateTime eDate, int platid) { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = new Dictionary(); string tsql = @"select oi.*,hgd.GoodsID,InPrice =fee.cb,ckfee = fee.ck,mdfee = fee.md,yf = fee.yf,LR=isnull(isnull(TotalPrice, 0) - isnull(escrowFee, 0) - isnull(yj, 0) - isnull(yf, 0) - ((isnull(cb, 0) + isnull(hwsf, 0)) / moneyrate) - isnull(tc, 0) - isnull(ck, 0) - isnull(md, 0) - isnull(Ad_Fee, 0) + SubsidyFee,0) from DT_OrderInfo oi with(nolock) left join DT_OrderGoods og with(nolock) on oi.OrderId=og.OrderId left join HW_GoodsDetail hgd with(nolock) on hgd.DetailId=og.DetailId left join DT_Fees fee with(nolock) on oi.OrderId = fee.orderid where CONVERT(date, oi.OrderDate) <= @eDate and CONVERT(date, oi.OrderDate) >=@sDate"; if (platid != 0) { tsql += " and oi.platid =@platid"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@sDate", DbType.Date, sDate.Date); db.AddInParameter(cmd, "@eDate", DbType.Date, eDate.Date); if (platid != 0) { db.AddInParameter(cmd, "@platid", DbType.Int32, platid); } DataTable tb = db.ExecuteDataTable(cmd); var list = tb.ToList(); if (list != null && list.Count() > 0) { ListModel.AddRange(list); } return ListModel; } #endregion #region 根据平台id和goodsid查询对应销售人员id /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static int MRJL_GetUsrIdByGoods(int goodsID, string SelectValue) { //返回数据 int userId = 0; string tsql = @"select " + SelectValue + " from HW_GoodsInfo where GoodsID = @GoodsID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsID", DbType.Int32, goodsID); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null) { userId = Convert.ToInt32(db.ExecuteScalar(cmd)); } return userId; } #endregion #region 根据平台id和goodsid查询对应销售人员id /// /// 查询某人某日分配sku的订单 /// /// 查询时间 /// 查询人 /// public static int MRJL_GetSkuNumByUserid(int Userid) { //返回数据 int userId = 0; string tsql = @"DECLARE @userid int --设置货号 SET @userid = @selectUserid select COUNT(DISTINCT a.GoodsId) from HW_GoodsDetail a with(nolock) inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId where guserid_shopify = @userid or guserid_wayfair = @userid or guserid_sheIn = @userid or guserid_ebay = @userid or guserid_wlmart = @userid or muserid = @userid or guserid_temu = @userid or guserid_tiktok = @userid"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@selectUserid", DbType.Int32, Userid); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null) { userId = Convert.ToInt32(db.ExecuteScalar(cmd)); } return userId; } #endregion #region 根据平台id查询对应平台名称id /// /// 根据平台id查询对应平台名称id /// /// 查询时间 /// 查询人 /// public static string MRJL_GetPlatNameByPlatId(int PlatId) { //返回数据 string platName = ""; string tsql = @"select top 1 Name from JC_BaseCodeDetail where KeyName = 'ptlx' and SortNo = @PlatId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null) { platName = Convert.ToString(db.ExecuteScalar(cmd)); } return platName; } public static string MRJL_GetShopNameByShopId(int ShopId) { //返回数据 string platName = ""; string tsql = @"SELECT top 1 ShopName from JC_Shop where ShopId = @ShopId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null) { platName = Convert.ToString(db.ExecuteScalar(cmd)); } return platName; } #endregion #region 库存申请 #region 查询某人分配sku的信息 /// /// 查询某人分配sku /// /// 查询时间 /// 查询人 /// public static List GetApplyGoodsListByUserId(int userid) { //返回数据 List ListModel = new List(); //店铺数据记录 Dictionary shopMsg = GetShopUserId(); //循环获取订单数据 foreach (var sMsg in shopMsg) { string tsql = @"select GoodsID,GoodsCode from HW_GoodsInfo where " + sMsg.Value + @" = @skuUserId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@skuUserId", DbType.Int32, userid); DataTable tb = db.ExecuteDataTable(cmd); // 检查DataTable是否非空 if (tb != null && tb.Rows.Count > 0) { var list = tb.ToList(); if (list != null && list.Count() > 0) { ListModel.AddRange(list); } } } return ListModel; } #endregion #region 根据货号查找销售价格 /// /// 根据货号查找销售价格 /// /// 查询时间 /// 查询人 /// public static decimal GetSalePriceByGoodsId(int goodsId) { decimal applyPrice = 0; try { string tsql = "SELECT top 1 ApplyPrice from CK_GoodsApplyPrice where GoodsId = @GoodsId"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, goodsId); applyPrice = Convert.ToDecimal(db.ExecuteScalar(cmd)); } catch { } return applyPrice; } #endregion #region 保存库存申请(新增或编辑) public static int Save_CKInventoryApply(CK_InventoryApply Model) { string tsql = @" if @id>0 begin Update [CK_InventoryApply] set UserId=@UserId,GoodsId=@GoodsId,ApplyPrice=@ApplyPrice,ApplyNum=@ApplyNum,ApplyDate=@ApplyDate,CheckDate=@CheckDate,Status=@Status,CheckMsg=@CheckMsg where Id=@id end else begin INSERT INTO [CK_InventoryApply](UserId,GoodsId,ApplyPrice,ApplyNum,ApplyDate,CheckDate,Status,CheckMsg)values(@UserId,@GoodsId,@ApplyPrice,@ApplyNum,@ApplyDate,@CheckDate,@Status,@CheckMsg) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, Model.GoodsId); db.AddInParameter(cmd, "@ApplyPrice", DbType.Decimal, Model.ApplyPrice); db.AddInParameter(cmd, "@ApplyNum", DbType.Int32, Model.ApplyNum); db.AddInParameter(cmd, "@ApplyDate", DbType.Date, Model.ApplyDate); db.AddInParameter(cmd, "@CheckDate", DbType.DateTime, Model.CheckDate); db.AddInParameter(cmd, "@Status", DbType.Int32, Model.Status); db.AddInParameter(cmd, "@CheckMsg", DbType.String, Model.CheckMsg); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 撤销库存申请(删除) public static void Delete_CKInventoryApply(int Id) { string tsql = @"Delete CK_InventoryApply where Id = @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteScalar(cmd); } #endregion #region 审核库存申请(通过或驳回) /// /// 审核库存申请(通过或驳回 /// /// /// 通过true 驳回false /// 驳回理由 非必填 public static void Check_CKInventoryApply(int Id, bool isSuccess, string checkMsg) { string tsql = @"Updare CK_InventoryApply where Id = @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteScalar(cmd); } #endregion #region 通过Id查询记录 #region 通过Id查询记录 /// /// 通过Id查询记录 /// /// 查询时间 /// 查询人 /// public static CK_InventoryApply GetModel_CKInventoryApply(int Id) { //返回数据 CK_InventoryApply model = new CK_InventoryApply(); string tsql = @"select top 1 * from CK_InventoryApply where Id = @Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); DataTable tb = db.ExecuteDataTable(cmd); //ListModel = tb.ToList(); if (tb != null && tb.Rows.Count > 0) model = tb.Rows[0].ToModel(); return model; } #endregion #endregion #region 分页查询库存申请(是否本人以及状态区分,关键词搜索) public static List GetPageList_CKInventoryApply(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"a.*,b.GoodsCode,UserName=c.Name"; ser.Tables = @"CK_InventoryApply a LEFT JOIN HW_GoodsInfo b on a.GoodsId = b.GoodsId LEFT JOIN JC_UserInfo c on a.UserId = c.UserId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "Id"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #endregion #region 更改采购单入库状态 public static void UpdateCG_Purchase(string buyCode, int state) { var sql = @" update CG_Purchase set PostState=@state where BuyCode=@buyCode update b set b.PState=@state from CG_Purchase a inner join CG_PurchaseGoods b on a.ChaseId=GJChaseId where PState<6 and a.BuyCode=@buyCode "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@state", DbType.Int32, state); db.AddInParameter(cmd, "@buyCode", DbType.String, buyCode); db.ExecuteNonQuery(cmd); } #endregion #region 管理人员相关 /// /// 添加 /// /// /// public static int Save_DDOrderAuth(DD_OrderAuth Model) { string tsql = @" if @id>0 begin Update [DD_OrderAuth] set UserId=@UserId,GroupLeaderId=@GroupLeaderId,isGroupLeader=@isGroupLeader where Id=@id end else begin INSERT INTO [DD_OrderAuth](UserId,GroupLeaderId,isGroupLeader)values(@UserId,@GroupLeaderId,@isGroupLeader) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.Id); db.AddInParameter(cmd, "@UserId", DbType.Int32, Model.UserId); db.AddInParameter(cmd, "@GroupLeaderId", DbType.Int32, Model.GroupLeaderId); db.AddInParameter(cmd, "@isGroupLeader", DbType.Boolean, Model.isGroupLeader); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } /// /// 删除 /// /// /// public static int Delete_DDOrderAuth(int id) { string tsql = @"delete [DD_OrderAuth] where Id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } public static List GetUserList(int selectUserId) { List ListModel = new List(); string tsql = @"SELECT ID=UserID,Name from JC_UserInfo"; if (selectUserId != -1) { tsql += $" where UserID!={selectUserId}"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { var list = tb.ToList(); ListModel = list; } return ListModel; } /// /// /// /// /// public static List GetList_DDOrderAuthShow(int groupLeaderId) { List ListModel = new List(); string tsql = @"SELECT GroupLeaderId,GroupLeaderName=c.Name,UserId=a.UserID,UserName=b.Name from DD_OrderAuth a LEFT JOIN JC_UserInfo b on a.UserID = b.UserID LEFT JOIN JC_UserInfo c on c.UserID = a.GroupLeaderId where GroupLeaderId in (SELECT UserID from DD_OrderAuth where isGroupLeader = 1) and isGroupLeader = 0"; if (groupLeaderId != -1) { tsql = @"SELECT GroupLeaderId,GroupLeaderName=c.Name,UserId=a.UserID,UserName=b.Name from DD_OrderAuth a LEFT JOIN JC_UserInfo b on a.UserID = b.UserID LEFT JOIN JC_UserInfo c on c.UserID = a.GroupLeaderId where GroupLeaderId = " + groupLeaderId + " and isGroupLeader = 0"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { var list = tb.ToList(); ListModel = list; } return ListModel; } public static List GetList_DDOrderAuth(int userID, int groupLeaderId, bool isGroupLeader) { List ListModel = new List(); string tsql = @"SELECT * from DD_OrderAuth where isGroupLeader = @isGroupLeader"; if (userID != -1) { tsql += @" and UserID = @UserID"; } if (groupLeaderId != -1) { tsql += @" and GroupLeaderId = @GroupLeaderId"; } Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@UserID", DbType.Int32, userID); db.AddInParameter(cmd, "@GroupLeaderId", DbType.Int32, groupLeaderId); db.AddInParameter(cmd, "@isGroupLeader", DbType.Boolean, isGroupLeader); DataTable tb = db.ExecuteDataTable(cmd); if (tb != null && tb.Rows.Count > 0) { var list = tb.ToList(); ListModel = list; } return ListModel; } #endregion #region 获取需要同步到WMS的订单 public static List GetSyncToWMSOrderDatas(DateTime sdate, DateTime edate) { var sql = @"select top 100 a.OrderId from DT_OrderInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId left join [50.196.110.198].[WMS].dbo.[DT_OrderInfo] c on a.OrderCode=c.OrderCode where a.State= 1 and a.PostState!=2 and ISNULL( a.PrintState,null)=0 and ISNULL(a.IsFba,0)=0 and ISNULL(c.OrderCode,'')='' and ISNULL(a.IsSyncToWMS,1)=1 and convert(date, a.orderdate)>=@sdate and convert(date, a.OrderDate)<=@edate order by a.OrderDate "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(@sql); db.AddInParameter(cmd, "@sdate", DbType.Date, sdate); db.AddInParameter(cmd, "@edate", DbType.Date, edate); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } public static List GetSyncToWMSOrderDatas_New(DateTime sdate, DateTime edate) { var sql = @"select top 1000 a.OrderId from DT_OrderInfo a with (nolock) inner join JC_Shop b with (nolock) on a.ShopId=b.ShopId left join [192.168.1.248].[WMS].dbo.[DT_OrderInfo] c on a.OrderCode=c.OrderCode where a.State= 1 and a.PostState!=2 and ISNULL( a.PrintState,null)=0 and ISNULL(a.IsFba,0)=0 and ISNULL(c.OrderCode,'')='' and ISNULL(a.IsSyncToWMS,1)=1 and convert(date, a.orderdate)>=@sdate and convert(date, a.OrderDate)<=@edate order by a.OrderDate "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(@sql); db.AddInParameter(cmd, "@sdate", DbType.Date, sdate); db.AddInParameter(cmd, "@edate", DbType.Date, edate); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region public static List GetSyncToWMSOrderGoodsDatas(int orderid) { var sql = @" select b.SKU1 GoodeCode,a.GoodsNum,a.PostInfo from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId where OrderId=@orderid "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(@sql); db.AddInParameter(cmd, "@orderid", DbType.Int32, orderid); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region public static List GetSyncToWMSTemuOrderGoodsDatas(string orderCode) { var sql = @" select ParentOrderSn,OrderSn,OrderStatus,GoodsId,SKUId,Quantity from [TemuShopOrderGoodsDetail] where ParentOrderSn=@OrderCode "; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(@sql); db.AddInParameter(cmd, "@OrderCode", DbType.String, orderCode); var dt = db.ExecuteDataTable(cmd); return dt.ToList(); } #endregion #region 保存ups运费计算 public static int UpdateOrderUpsFee(int OrderId, decimal? UpsFeeE1, decimal? UpsFeeE2, decimal? UpsFeeW1, decimal? UpsFeeW2) { string tsql = @" if @UpsFeeE1>0 begin update DT_OrderInfo set UpsFeeE1=@UpsFeeE1 where OrderId=@OrderId end else if @UpsFeeE2>0 begin update DT_OrderInfo set UpsFeeE2=@UpsFeeE2 where OrderId=@OrderId end else if @UpsFeeW1>0 begin update DT_OrderInfo set UpsFeeW1=@UpsFeeW1 where OrderId=@OrderId end else if @UpsFeeW2>0 begin update DT_OrderInfo set UpsFeeW2=@UpsFeeW2 where OrderId=@OrderId end select 1 "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId); db.AddInParameter(cmd, "@UpsFeeE1", DbType.Decimal, UpsFeeE1); db.AddInParameter(cmd, "@UpsFeeE2", DbType.Decimal, UpsFeeE2); db.AddInParameter(cmd, "@UpsFeeW1", DbType.Decimal, UpsFeeW1); db.AddInParameter(cmd, "@UpsFeeW2", DbType.Decimal, UpsFeeW2); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 分页查询 public static List GetListDT_OrderInfoForTM_LX(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; // if (IsSku == 0 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId=0"; // else // if (IsSku == 0 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId=0 and GoodsName like '%" + GoodsName + "%'"; // else // if (IsSku == 0 && SKU != "") // sql1 = sql1 + " a.DetailId=0"; // else if (IsSku == 1 && sql1 == "") // sql1 = @"select distinct a.OrderId from DT_OrderGoods a // inner join DT_OrderInfo b on a.OrderId=b.OrderId // where b.CompanyId=@CompanyId and a.DetailId>0"; // else // if (IsSku == 1 && GoodsName != "") // sql1 = "select distinct OrderId from DT_OrderGoods where DetailId>0 and GoodsSKU like '%" + GoodsName + "%'"; // else // if (IsSku == 1 && SKU != "") // sql1 = sql1 + " a.DetailId>0"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),PlatId=c.PlatType,a.ShopId,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Fee6,a.Fee7,a.Fee8,a.Post,a.PostFee,SimpErrorInfo=a.LxMess"; if (sql1 != "") ser.Tables = @"VW_Orders a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_Orders a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页查询 public static List GetListDT_OrderInfoForTM_LX1(int CompanyId, string GoodsName, string SKU, string TrackCode, int IsSku, int IsDH, RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { string sql1 = ""; string NoGoodsSql = ""; if (IsDH == 1) NoGoodsSql = " and isnull(b.NoGoods,0)=1"; if (IsDH == 0) NoGoodsSql = " and isnull(b.NoGoods,0)=0"; if (TrackCode != "") { sql1 = @"select OrderId into #OrderTemp from DT_TrackCodeApply with (nolock) where state=1 and TrackCode ='" + TrackCode + "' "; } else if (GoodsName != "") { if (GoodsName.Contains(" ")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split(' ')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split(' ')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split(' ')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split(' ')[1].Trim() + @"%')"; } else if (GoodsName.Contains("-")) { sql1 = @" select distinct OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsCode like '%" + GoodsName.Split('-')[0].Trim() + "%' or c.GoodsOldCode like '%" + GoodsName.Split('-')[0].Trim() + @"%') and (b.TypeCode like '%" + GoodsName.Split('-')[1].Trim() + @"%' or b.TypeDesc like '%" + GoodsName.Split('-')[1].Trim() + @"%')"; } else { sql1 = @" select distinct OrderId into #OrderTemp from (select a.OrderId from DT_OrderGoods a with (nolock) inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql + " and (c.GoodsName like '%" + GoodsName + "%' or c.GoodsCode like '%" + GoodsName + @"%'or c.GoodsOldCode like '%" + GoodsName + @"%') union select OrderId from DT_OrderGoods where DetailId=0 and GoodsSKU like '%" + GoodsName + "%')a"; } } else if (SKU != "") sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a with (nolock) inner join DT_OrderInfo b with (nolock) on a.OrderId=b.OrderId where b.CompanyId=@CompanyId and a.GoodsSku like '%" + SKU + "%'"; if (sql1 == "" && (IsDH > -1)) sql1 = @"select distinct a.OrderId into #OrderTemp from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where c.CompanyId=@CompanyId " + NoGoodsSql; if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,PlatId=c.PlatType,a.PlatOrderCode,a.JoinOrderCode,a.IsJoin,IsJoinState=case when a.IsJoin=1 then '[合并]' else '' end,a.GoodsNum,a.TotalPrice,a.MoneyCode,a.PostState,a.PostDate,a.FPDate,a.PrintState,a.MateState,a.State,a.OrderDate,a.InDate,a.CompanyId,a.IsBlank,a.CustomID,ErrorInfo='', a.OrderState,c.ShopName,c.Country,StateName=case when a.State=1 and PostState=0 then '未发货' when a.State=1 and PostState=1 then '已发货' when a.State=1 and PostState=3 then '部分发货' when a.State=2 then '已结束' when a.State=3 then '已取消' when a.State=1 and PostState=2 then '不允许发货' end,a.CountryCode,CountryName=case when a.CountryName is null then a.RevCountry else a.CountryName end,a.TrackState,a.IsSpare,a.IsSDan,a.BuyDate,a.RevName,a.RevProvince,a.escrowFee,a.Post,a.PostFee,SimpErrorInfo=a.LxMess"; if (sql1 != "") ser.Tables = @"VW_OrdersNew a with (nolock) inner join #OrderTemp b on a.OrderId=b.OrderId inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; else ser.Tables = @"VW_OrdersNew a with (nolock) inner join JC_Shop c with (nolock) on a.ShopId=c.ShopId"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "OrderId"; string tsql = ser.GetText(); if (sql1 != "") tsql = sql1 + " " + tsql; where.AddOutParameter("RowCount", System.Data.DbType.Int32); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 修改同步状态 public static int Save_OrderLXSate(string PlatOrderCode, int IsLX, string LxMess, string outboundOrderNo) { string tsql = @" update DT_OrderInfoNew set IsLX=@IsLX,LxMess=@LxMess,LxDate=getdate(),outboundOrderNo=@outboundOrderNo where PlatOrderCode=@PlatOrderCode update DT_OrderInfo set IsLX=@IsLX,LxMess=@LxMess,LxDate=getdate(),outboundOrderNo=@outboundOrderNo where PlatOrderCode=@PlatOrderCode "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, PlatOrderCode); db.AddInParameter(cmd, "@outboundOrderNo", DbType.String, outboundOrderNo); db.AddInParameter(cmd, "@IsLX", DbType.Int32, IsLX); db.AddInParameter(cmd, "@LxMess", DbType.String, LxMess); db.ExecuteScalar(cmd); return 1; } #endregion #region 读取待同步订单 public static List GetOrderList_LX(string orderids) { try { string tsql = @"select b.StoreId,b.RevAddr,b.RevProvinceCode,a.OrderId,a.PlatOrderCode,b.CountryCode,b.RevCountry,b.RevProvince,b.RevCity,b.RevPhone,b.RevMoblie,b.RevPostCode,b.RevName,b.RevFax,a.PlatId,b.BuyRemark,Upload_label=isnull(c.Upload_label,0),c.ShopName from DT_OrderInfo a with (nolock) inner join DT_OrderXXInfo b with (nolock) on a.OrderId=b.OrderId inner join jc_shop c on a.ShopId=c.ShopId where a.state=1 and isnull(IsLX,0)<>1 and isnull(a.IsFba,0)=0 and a.OrderId in (" + orderids + ") order by a.indate "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } catch (Exception ex) { ErrorFollow.TraceWrite("GetOrderList_LX", ex.Message, ex.Data.ToString()); return null; } } #endregion #region 读取待同步订单sku public static List GetOrderSKU_LX(string orderids) { try { string tsql = @" select SKU=case when b.SKU1 is not null and b.SKU1<>'' then b.SKU1 when b.SKU2 is not null and b.SKU2<>'' then b.SKU2 when b.SKU3 is not null and b.SKU3<>'' then b.SKU3 else b.SKU4 end,a.GoodsNum,a.OrderId,Weight=isnull(c.Weight,0)*0.0022,Weight2=isnull(c.Weight2,0)*0.0625,BoxRate=isnull(c.BoxRate,1) from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId in (" + orderids + ") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } catch (Exception ex) { ErrorFollow.TraceWrite("GetOrderSKU_LX", ex.Message, ex.Data.ToString()); return null; } } #endregion #region 读取待同步订单sku public static List GetOrderSKU(string orderids) { try { string tsql = @" select GoodsSKU=case when b.SKU1 is not null and b.SKU1<>'' then b.SKU1 when b.SKU2 is not null and b.SKU2<>'' then b.SKU2 when b.SKU3 is not null and b.SKU3<>'' then b.SKU3 else b.SKU4 end,a.GoodsNum,a.OrderId from DT_OrderGoods a inner join HW_GoodsDetail b on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where a.OrderId in (" + orderids + ") "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } catch (Exception ex) { ErrorFollow.TraceWrite("GetOrderSKU_LX", ex.Message, ex.Data.ToString()); return null; } } #endregion /// /// 更新sku temu 预计成本 /// /// public static int SaveTemuChengBen(TemuChengBen md) { var sql = @"if @id>0 begin update TemuChengBen set JinJia=@JinJia,YunFei=@YunFei,TouCheng=@TouCheng,HuoWuShuiFei=@HuoWuShuiFei,YuGuJiaGe=@YunFei,CreateTime=GETDATE(),CreateUserId=@CreateUserId,mUserId=@mUserId where ID=@id end else begin insert into TemuChengBen(GoodsId,JinJia,YunFei,TouCheng,HuoWuShuiFei,YuGuJiaGe,CreateUserId,CreateTime,mUserId) values(@GoodsId,@JinJia,@YunFei,@TouCheng,@HuoWuShuiFei,@YuGuJiaGe,@createUserId,GETDATE(),@mUserId) set @id=SCOPE_IDENTITY() end select @id"; var db = DatabaseFactory.CreateDatabase(); var cmd = db.GetSqlStringCommand(sql); db.AddInParameter(cmd, "@id", DbType.Int32, md.ID); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, md.GoodsId); db.AddInParameter(cmd, "@JinJia", DbType.Decimal, md.JinJia); db.AddInParameter(cmd, "@YunFei", DbType.Decimal, md.YunFei); db.AddInParameter(cmd, "@TouCheng", DbType.Decimal, md.TouCheng); db.AddInParameter(cmd, "@HuoWuShuiFei", DbType.Decimal, md.HuoWuShuiFei); db.AddInParameter(cmd, "@YuGuJiaGe", DbType.Decimal, md.YuGuJiaGe); db.AddInParameter(cmd, "@createUserId", DbType.Int32, md.CreateUserId); db.AddInParameter(cmd, "@mUserId", DbType.Int32, md.mUserId); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; //db.ExecuteNonQuery(cmd); } /// /// 查询 temu 预计成本 /// /// /// public static List GetTemuChengBen(int GoodsId) { try { string tsql = @" SELECT top 1 a.[ID],a.[GoodsId],c.GoodsCode,[JinJia],[YunFei],[TouCheng],[HuoWuShuiFei],[YuGuJiaGe],[CreateUserId],[CreateTime],a.mUserId,u.Name as UserName FROM [dbo].[TemuChengBen] a inner join HW_GoodsInfo c on a.GoodsId=c.GoodsId left join JC_UserInfo u on a.mUserId=u.UserId where a.GoodsId = @GoodsId order by a.CreateTime desc"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@GoodsId", DbType.Int32, GoodsId); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } catch (Exception ex) { ErrorFollow.TraceWrite("TemuChengBen", ex.Message, ex.Data.ToString()); return null; } } #region 修改售价 public static void Save_ManuaPrice(int DetailId, string ManuaPrice) { string tsql = @" if @DetailId>0 begin update HW_GoodsDetail set ManuaPrice=@ManuaPrice where DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@ManuaPrice", DbType.String, ManuaPrice); db.ExecuteNonQuery(cmd); } #endregion #region 修改售价 public static void Save_TemuPrice(int DetailId, string TemuPrice) { string tsql = @" if @DetailId>0 begin update HW_GoodsDetail set TemuPrice=@TemuPrice where DetailId=@DetailId end "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@DetailId", DbType.Int32, DetailId); db.AddInParameter(cmd, "@TemuPrice", DbType.String, TemuPrice); db.ExecuteNonQuery(cmd); } #endregion #region 保存TemuShopGoodActive public static int Save_TemuShopGoodActive(TemuShopGoodActive Model) { string tsql = @" if @ID>0 begin Update [TemuShopGoodActive] set [Shopid]=@Shopid,[SKU]=@SKU,[SPUID]=@SPUID,[BasePrice]=@BasePrice,[CreateUserId]=@CreateUserId,[CreateTime]=@CreateTime,[PostPrice]=@PostPrice,[State]=@State where ID=@ID delete from TemuShopGoodActiveDetail where ActiveId=@ID end else begin INSERT INTO [TemuShopGoodActive]([Shopid],[SKU],[SPUID],[BasePrice],[CreateUserId],[CreateTime],[PostPrice],[State])values(@Shopid,@SKU,@SPUID,@BasePrice,@CreateUserId,@CreateTime,@PostPrice,@State) set @ID=SCOPE_IDENTITY() end select @ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ID", DbType.Int32, Model.ID); db.AddInParameter(cmd, "@Shopid", DbType.Int32, Model.Shopid); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@SPUID", DbType.String, Model.SPUID); db.AddInParameter(cmd, "@BasePrice", DbType.Decimal, Model.BasePrice); db.AddInParameter(cmd, "@CreateUserId", DbType.Int32, Model.CreateUserId); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, Model.CreateTime); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); tsql = @"INSERT INTO [TemuShopGoodActiveDetail]([ActiveId],[OffNum],[SalePrice],[ActiveNum],[OutNum],[State],[SDate],[EDate],[SKUId],[SKU],[BasePrice],[ShareId],[TotalOutNum])values(@ActiveId,@OffNum,@SalePrice,@ActiveNum,@OutNum,@State,@SDate,@EDate,@SKUId,@SKU,@BasePrice,@ShareId,@TotalOutNum) set @ID=SCOPE_IDENTITY() select @ID "; cmd = db.GetSqlStringCommand(tsql); if (Model.ListModel!=null) { int shareid = 0; foreach (var item in Model.ListModel) { cmd.Parameters.Clear(); item.OutNum = 0; item.TotalOutNum = 0; item.State = 1; if (item.ActiveNum == 0) item.ShareId = shareid;//共享存入上一条数据的明细id db.AddInParameter(cmd, "@ID", DbType.Int32, item.Id); db.AddInParameter(cmd, "@ActiveId", DbType.Int32, a); db.AddInParameter(cmd, "@OffNum", DbType.Decimal, item.OffNum); db.AddInParameter(cmd, "@SalePrice", DbType.Decimal, item.SalePrice); db.AddInParameter(cmd, "@ActiveNum", DbType.Int32, item.ActiveNum); db.AddInParameter(cmd, "@OutNum", DbType.Int32, item.OutNum); db.AddInParameter(cmd, "@State", DbType.Int32, item.State); db.AddInParameter(cmd, "@SDate", DbType.DateTime, item.SDate); db.AddInParameter(cmd, "@EDate", DbType.DateTime, item.EDate); db.AddInParameter(cmd, "@SKUId", DbType.String, item.SKUId); db.AddInParameter(cmd, "@SKU", DbType.String, item.SKU); db.AddInParameter(cmd, "@BasePrice", DbType.Decimal, item.BasePrice); db.AddInParameter(cmd, "@ShareId", DbType.Int32, item.ShareId); db.AddInParameter(cmd, "@TotalOutNum", DbType.Int32, item.TotalOutNum); int b = Convert.ToInt32(db.ExecuteScalar(cmd)); if (item.ActiveNum > 0) shareid = b; } } return a; } #endregion #region 编辑TemuShopGoodActive public static int Update_TemuShopGoodActive_data(TemuShopGoodActive Model) { string tsql = @" if @ID>0 begin Update [TemuShopGoodActive] set [Shopid]=@Shopid,[SKU]=@SKU,[SPUID]=@SPUID,[BasePrice]=@BasePrice,[CreateUserId]=@CreateUserId,[CreateTime]=@CreateTime,[PostPrice]=@PostPrice,[State]=@State where ID=@ID end else select @ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ID", DbType.Int32, Model.ID); db.AddInParameter(cmd, "@Shopid", DbType.Int32, Model.Shopid); db.AddInParameter(cmd, "@SKU", DbType.String, Model.SKU); db.AddInParameter(cmd, "@SPUID", DbType.String, Model.SPUID); db.AddInParameter(cmd, "@BasePrice", DbType.Decimal, Model.BasePrice); db.AddInParameter(cmd, "@CreateUserId", DbType.Int32, Model.CreateUserId); db.AddInParameter(cmd, "@CreateTime", DbType.DateTime, Model.CreateTime); db.AddInParameter(cmd, "@PostPrice", DbType.Decimal, Model.PostPrice); db.AddInParameter(cmd, "@State", DbType.Int32, Model.State); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); tsql = @" if @Id>0 begin Update [TemuShopGoodActiveDetail] set [ActiveId]=@ActiveId,[OffNum]=@OffNum,[SalePrice]=@SalePrice,[ActiveNum]=@ActiveNum,[OutNum]=@OutNum where Id=@Id end else begin INSERT INTO [TemuShopGoodActiveDetail]([ActiveId],[OffNum],[SalePrice],[ActiveNum],[OutNum])values(@ActiveId,@OffNum,@SalePrice,@ActiveNum,@OutNum) end"; cmd = db.GetSqlStringCommand(tsql); if (Model.ListModel != null) { foreach (var item in Model.ListModel) { cmd.Parameters.Clear(); item.OutNum = 0; db.AddInParameter(cmd, "@ActiveId", DbType.Int32, a); db.AddInParameter(cmd, "@OffNum", DbType.Decimal, item.OffNum); db.AddInParameter(cmd, "@SalePrice", DbType.Decimal, item.SalePrice); db.AddInParameter(cmd, "@ActiveNum", DbType.Int32, item.ActiveNum); db.AddInParameter(cmd, "@OutNum", DbType.Int32, item.OutNum); db.AddInParameter(cmd, "@Id", DbType.Int32, item.Id); db.ExecuteNonQuery(cmd); } } return a; } #endregion #region 删除 public static void Delete_TemuShopGoodActive(int ID) { string tsql = @" delete from TemuShopGoodActive where ID=@ID delete from TemuShopGoodActiveDetail where ActiveId=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void End_TemuShopGoodActiveDetail(int ID) { string tsql = @" update TemuShopGoodActiveDetail set state=0 where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } #endregion #region 删除 public static void Update_TemuShopGoodActive(int ID) { string tsql = @" update TemuShopGoodActive set state=0 where ID=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); db.ExecuteNonQuery(cmd); } #endregion #region 删除明细 public static void DeleteDetail_TemuShopGoodActive(int Id) { string tsql = @" delete from TemuShopGoodActiveDetail where Id=@Id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@Id", DbType.Int32, Id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static TemuShopGoodActive GetModel_TemuShopGoodActive(int ID) { TemuShopGoodActive model = null; //string tsql = "select a.ID,a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State from TemuShopGoodActive"; string tsql = @" select * from TemuShopGoodActive where ID=@ID select * from TemuShopGoodActiveDetail where ActiveId=@ID"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@ID", DbType.Int32, ID); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); model.ListModel = ds.Tables[1].ToList(); foreach (var md in model.ListModel) { if (md.ShareId > 0) { md.IsShare ="共享库存"; md.IsDisabled="disabled"; } } } return model; } #endregion #region 分页查询 public static List GetListTemuShopGoodActive(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount) { if (where == null) where = new RefParameterCollection(); QueryService ser = new QueryService(); ser.Fields = @"ID=cast(a.ID as int),a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State"; ser.Tables = @"TemuShopGoodActive a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.PageIndex = PageIndex; ser.PageSize = PageSize; ser.Sort = Sort; ser.KeyName = "ID"; string tsql = ser.GetText(); where.AddOutParameter("RowCount", System.Data.DbType.Int32); ; List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 多条件普通查询 public static List GetListTemuShopGoodActive(RefParameterCollection where, string Sort) { if (where == null) where = new RefParameterCollection(); QueryOrdService ser = new QueryOrdService(); //ser.Fields = "a.ID,a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State"; ser.Fields = "a.*"; ser.Tables = @"TemuShopGoodActive a"; ser.Filter = where.GetWhere(System.Data.CommandType.Text); ser.KeyName = "ID"; ser.Sort = Sort; string tsql = ser.GetText(); Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, where); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListTemuShopGoodActive() { //string tsql = "select a.ID,a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State from TemuShopGoodActive"; string tsql = "select * from TemuShopGoodActive"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 返回列表 public static List GetListTemuShopGoodActiveDetail(string ids, string Sku, string SkuId) { string tsql = string.Empty; string where= string.Empty; string order = " order by id"; tsql = "select * from TemuShopGoodActiveDetail where ActiveId in (" + ids + ") "; if (!string.IsNullOrEmpty(Sku)) { where = " and sku like '%" + Sku + "%' "; } if (!string.IsNullOrEmpty(SkuId)) { where = " and SKUId = '" + SkuId + "' "; } tsql = tsql + where + order; //string tsql = "select a.ID,a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State from TemuShopGoodActive"; //string tsql = "select * from TemuShopGoodActiveDetail where ActiveId in (" + ids + ") and sku like '%"+ Sku + "%' order by id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListTemuShopGoodActive(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = @"select ID=cast(a.ID as int),a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State,b.ShopName,CreateUserName=c.Name from TemuShopGoodActive a left Join JC_Shop b on a.Shopid = b.Shopid left join jc_userinfo c on a.CreateUserId=c.UserId "; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.ID desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListTemuShopGoodActive_Test(string shopid, string Sku, string SkuId) { string Where = string.Empty; string order = " ) a order by a.ID desc"; string tsql = @"select ID,Shopid,SKU,SPUID,BasePrice,CreateUserId,CreateTime,PostPrice,State,ShopName,CreateUserName from ( select distinct ID=cast(a.ID as int),a.Shopid,a.SKU,a.SPUID,a.BasePrice,a.CreateUserId,a.CreateTime,a.PostPrice,a.State,b.ShopName,CreateUserName=c.Name from TemuShopGoodActive a left Join JC_Shop b on a.Shopid = b.Shopid left join jc_userinfo c on a.CreateUserId=c.UserId left join TemuShopGoodActiveDetail d on a.ID=d.ActiveId where 1=1 "; if (!string.IsNullOrEmpty(shopid)) { Where += shopid; } if (!string.IsNullOrEmpty(Sku)) { Where += " and d.sku like '%" + Sku + "%'"; } if (!string.IsNullOrEmpty(SkuId)) { Where += " and d.SKUId = '" + SkuId + "'"; } tsql = tsql + Where + order; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); ListModel = tb.ToList(); return ListModel; } #endregion #region 根据sku读temu订单 public static List GetTemuOrderFromSKU(string SKU) { string tsql = @" select c.SKU1,KcNum=c.WestNum+c.EastNum,c.WestNum,c.EastNum,b.*,lr=b.TotalPrice-b.yj-b.ck-b.cb-b.hwsf-b.sjyf-b.sjtc,a.GoodsNum from DT_OrderGoods a inner join ( select a.orderid,c.ShopName,a.PlatOrderCode,a.InDate,TotalPrice=isnull(a.TotalPrice,0),yj=isnull(b.yj,0),ck=isnull(b.ck,0),sjtc=isnull(b.sjtc,isnull(b.tc,0)),sjyf=isnull(b.sjyf,isnull(b.yf,0)),cb=isnull(b.sjcb,isnull(b.cb,0))/6.3,hwsf=isnull(b.hwsf,0)/6.3,b.sku from DT_OrderInfo a left join JC_Shop c on a.ShopId=c.ShopId left join DT_Fees b on a.OrderId=b.orderid where a.State>0 and a.State<3 and a.PlatId=23)b on a.OrderId=b.OrderId inner join HW_GoodsDetail c on a.DetailId=c.DetailId where c.SKU1=@SKU"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@SKU", DbType.String, SKU); DataTable tb = db.ExecuteDataTable(cmd); return tb.ToList(); } #endregion #region 保存 public static int Save_CustomFee(HT_CustomFee Model) { string tsql = @" if @id>0 begin Update [HT_CustomFee] set [customname]=@customname,[htdate]=@htdate,[htcode]=@htcode,[yjprice]=@yjprice,[rmbprice]=@rmbprice,[usdprice]=@usdprice,[njprice]=@njprice,[hyprice]=@hyprice,[hlrate]=@hlrate,[llrate]=@llrate,[totalrmbprice]=@totalrmbprice,[totalusdprice]=@totalusdprice,[yfprice]=@yfprice,[lxprice]=@lxprice,[inname]=@inname,[indate]=@indate,[state]=@state,jxdate=@jxdate,feetype=@feetype,hyrmbprice=@hyrmbprice,njrmbprice=@njrmbprice,yjrate=@yjrate,yjrmbprice=@yjrmbprice where id=@id end else begin INSERT INTO [HT_CustomFee]([customname],[htdate],[htcode],[yjprice],[rmbprice],[usdprice],[njprice],[hyprice],[hlrate],[llrate],[totalrmbprice],[totalusdprice],[yfprice],[lxprice],[inname],[indate],[state],jxdate,feetype,yjrate,njrmbprice,hyrmbprice,yjrmbprice)values(@customname,@htdate,@htcode,@yjprice,@rmbprice,@usdprice,@njprice,@hyprice,@hlrate,@llrate,@totalrmbprice,@totalusdprice,@yfprice,@lxprice,@inname,@indate,@state,@jxdate,@feetype,@yjrate,@njrmbprice,@hyrmbprice,@yjrmbprice) set @id=SCOPE_IDENTITY() end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@customname", DbType.String, Model.customname); db.AddInParameter(cmd, "@htdate", DbType.DateTime, Model.htdate); db.AddInParameter(cmd, "@htcode", DbType.String, Model.htcode); db.AddInParameter(cmd, "@yjprice", DbType.Decimal, Model.yjprice); db.AddInParameter(cmd, "@rmbprice", DbType.Decimal, Model.rmbprice); db.AddInParameter(cmd, "@usdprice", DbType.Decimal, Model.usdprice); db.AddInParameter(cmd, "@njprice", DbType.Decimal, Model.njprice); db.AddInParameter(cmd, "@hyprice", DbType.Decimal, Model.hyprice); db.AddInParameter(cmd, "@hlrate", DbType.Decimal, Model.hlrate); db.AddInParameter(cmd, "@llrate", DbType.Decimal, Model.llrate); db.AddInParameter(cmd, "@totalrmbprice", DbType.Decimal, Model.totalrmbprice); db.AddInParameter(cmd, "@totalusdprice", DbType.Decimal, Model.totalusdprice); db.AddInParameter(cmd, "@yfprice", DbType.Decimal, Model.yfprice); db.AddInParameter(cmd, "@lxprice", DbType.Decimal, Model.lxprice); db.AddInParameter(cmd, "@inname", DbType.String, Model.inname); db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate); db.AddInParameter(cmd, "@jxdate", DbType.DateTime, Model.jxdate); db.AddInParameter(cmd, "@feetype", DbType.Int32, Model.feetype); db.AddInParameter(cmd, "@yjrate", DbType.Decimal, Model.yjrate); db.AddInParameter(cmd, "@njrmbprice", DbType.Decimal, Model.njrmbprice); db.AddInParameter(cmd, "@hyrmbprice", DbType.Decimal, Model.hyrmbprice); db.AddInParameter(cmd, "@yjrmbprice", DbType.Decimal, Model.yjrmbprice); db.AddInParameter(cmd, "@state", DbType.Int32, Model.state); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_CustomFee(int id) { string tsql = @" delete from HT_CustomFee where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static HT_CustomFee GetModel_CustomFee(int id) { HT_CustomFee model = null; //string tsql = "select a.id,a.customname,a.htdate,a.htcode,a.yjprice,a.rmbprice,a.usdprice,a.njprice,a.hyprice,a.hlrate,a.llrate,a.totalrmbprice,a.totalusdprice,a.yfprice,a.lxprice,a.inname,a.indate,a.state from HT_CustomFee"; string tsql = @" select * from HT_CustomFee where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 返回列表 public static List GetListCustomFee() { //string tsql = "select a.id,a.customname,a.htdate,a.htcode,a.yjprice,a.rmbprice,a.usdprice,a.njprice,a.hyprice,a.hlrate,a.llrate,a.totalrmbprice,a.totalusdprice,a.yfprice,a.lxprice,a.inname,a.indate,a.state from HT_CustomFee"; string tsql = "select * from HT_CustomFee"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion #region 分页动态条件查询 public static List GetListCustomFee(string where, int PageIndex, int PageSize, string Sort, out int RowCount) { QueryService2 ser = new QueryService2(); ser.Tsql = "select id=cast(a.id as int),a.customname,a.htdate,a.htcode,a.yjprice,a.rmbprice,a.usdprice,a.njprice,a.hyprice,a.hlrate,a.llrate,a.totalrmbprice,a.totalusdprice,yfprice=isnull(a.yfprice,0),a.lxprice,a.inname,a.indate,a.state,a.jxdate,a.feetype,zfprice=case when a.feetype=1 then a.rmbprice else a.usdprice end,a.yjrate,a.njrmbprice,a.hyrmbprice,a.yjrmbprice,days=DATEDIFF(day,jxdate,getdate()),a.predate,days2=case when predate is not null then DATEDIFF(day,predate,getdate()) else -1 end from HT_CustomFee a"; ser.Tsql += " " + ser.Filter(where); ser.PageIndex = PageIndex; ser.PageSize = PageSize; if (string.IsNullOrEmpty(Sort) == true) { ser.Sort = "a.id desc"; } else { ser.Sort = Sort; } string tsql = ser.GetText(); List ListModel = null; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddOutParameter(cmd, "@RowCount", DbType.Int32, 4); DataTable tb = db.ExecuteDataTable(cmd); RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value); ListModel = tb.ToList(); return ListModel; } #endregion #region 保存 public static int Save_CustomFeeDetail(HT_CustomFeeDetail Model) { string tsql = @" if @id>0 begin Update [HT_CustomFeeDetail] set [feeid]=@feeid,[feedate]=@feedate,[feermbprice]=@feermbprice,[feeusdprice]=@feeusdprice,[hlrate]=@hlrate,[feetype]=@feetype,[jsbprice]=@jsbprice,[jslxprice]=@jslxprice where id=@id end else begin declare @prefeedate datetime,@prejsbprice decimal(18,2),@preyfprice decimal(18,2) select @prefeedate=predate,@prejsbprice=lxprice,@preyfprice=yfprice from HT_CustomFee where id=@feeid INSERT INTO [HT_CustomFeeDetail]([feeid],[feedate],[feermbprice],[feeusdprice],[hlrate],[feetype],[jsbprice],[jslxprice],prefeedate,prejsbprice,preyfprice)values(@feeid,@feedate,@feermbprice,@feeusdprice,@hlrate,@feetype,@jsbprice,@jslxprice,@prefeedate,@prejsbprice,@preyfprice) set @id=SCOPE_IDENTITY() update HT_CustomFee set yfprice=@hkprice,lxprice=@leftprice,predate=@feedate where id=@feeid update HT_CustomFee set state=1 where lxprice<=0 end select @id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, Model.id); db.AddInParameter(cmd, "@feeid", DbType.Int32, Model.feeid); db.AddInParameter(cmd, "@feedate", DbType.DateTime, Model.feedate); db.AddInParameter(cmd, "@feermbprice", DbType.Decimal, Model.feermbprice); db.AddInParameter(cmd, "@feeusdprice", DbType.Decimal, Model.feeusdprice); db.AddInParameter(cmd, "@hlrate", DbType.Decimal, Model.hlrate); db.AddInParameter(cmd, "@feetype", DbType.Int32, Model.feetype); db.AddInParameter(cmd, "@jsbprice", DbType.String, Model.jsbprice); db.AddInParameter(cmd, "@jslxprice", DbType.Decimal, Model.jslxprice); db.AddInParameter(cmd, "@hkprice", DbType.Decimal, Model.hkprice); db.AddInParameter(cmd, "@leftprice", DbType.Decimal, Model.leftprice); int a = Convert.ToInt32(db.ExecuteScalar(cmd)); return a; } #endregion #region 删除 public static void Delete_CustomFeeDetail(int id) { string tsql = @" declare @prefeedate datetime,@prejsbprice decimal(18,2),@preyfprice decimal(18,2),@feeid int select @prefeedate=prefeedate,@prejsbprice=prejsbprice,@preyfprice=preyfprice,@feeid=feeid from HT_CustomFeeDetail where id=@id delete from HT_CustomFeeDetail where id=@id update HT_CustomFee set yfprice=@preyfprice,lxprice=@prejsbprice,predate=@prefeedate,state=0 where id=@feeid "; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); db.ExecuteNonQuery(cmd); } #endregion #region 返回Model public static HT_CustomFeeDetail GetModel_CustomFeeDetail(int id) { HT_CustomFeeDetail model = null; //string tsql = "select a.id,a.feeid,a.feedate,a.feermbprice,a.feeusdprice,a.hlrate,a.feetype,a.jsbprice,a.jslxprice from HT_CustomFeeDetail"; string tsql = @" select * from HT_CustomFeeDetail where id=@id"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@id", DbType.Int32, id); DataSet ds = db.ExecuteDataSet(cmd); if (ds.Tables[0].Rows.Count > 0) { model = ds.Tables[0].Rows[0].ToModel(); } return model; } #endregion #region 返回列表 public static List GetListCustomFeeDetail(int feeid) { //string tsql = "select a.id,a.feeid,a.feedate,a.feermbprice,a.feeusdprice,a.hlrate,a.feetype,a.jsbprice,a.jslxprice from HT_CustomFeeDetail"; string tsql = "select * from HT_CustomFeeDetail where feeid=@feeid order by feedate"; Database db = DatabaseFactory.CreateDatabase(); DbCommand cmd = db.GetSqlStringCommand(tsql); db.AddInParameter(cmd, "@feeid", DbType.Int32, feeid); DataTable tb = db.ExecuteDataTable(cmd); List ListModel = tb.ToList(); return ListModel; } #endregion } }