You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ERP/TradeManageNew/SysManageServiceNew.asmx.cs

17854 lines
812 KiB
C#

2 months ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using NetLibrary.Data;
using System.Data;
using NetLibrary.ReportPrint;
using TradeData;
using NetLibrary;
using System.Text;
using TradeModel;
using NetLibrary.Log;
using System.Web.Script.Serialization;
using System.Collections;
using System.Reflection;
using Org.BouncyCastle.Crypto.Parameters;
using Aspose.Pdf.Operators;
using NPOI.HSSF.Record.Formula.Functions;
using System.Diagnostics.Eventing.Reader;
using System.Web.Configuration;
using TradeManage.SysManage;
using Newtonsoft.Json;
using System.Net;
using System.IO;
using Aspose.Pdf.Facades;
using TradeManage;
using System.Web.Script.Services;
using Ghostscript.NET.Rasterizer;
using System.Web.UI.WebControls;
using Spire.Pdf.Graphics;
using Spire.Pdf;
using Aspose.Pdf.Drawing;
using System.Drawing;
using System.Drawing.Imaging;
using iTextSharp.text.pdf;
using PdfDocument = Spire.Pdf.PdfDocument;
using NPOI.HSSF.Model;
using System.Drawing.Drawing2D;
using System.ComponentModel.Design;
using System.Data.Common;
using Lazop.Api;
using System.Web.Services.Description;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using Aspose.Pdf;
using NPOI.POIFS.FileSystem;
using NPOI.HSSF.Util;
using Newtonsoft.Json.Linq;
using DataTable = System.Data.DataTable;
using Pages = TradeManage.Pages;
using Aspose.Pdf.Annotations;
namespace TradeManageNew
{
/// <summary>
/// SysManageServiceNew 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
[System.Web.Script.Services.ScriptService]
public class SysManageServiceNew : System.Web.Services.WebService
{
public readonly List<int> Group1Peoples = new List<int>() { 69, 181, 200, 216, 221 };//一组人员
public readonly List<int> Group2Peoples = new List<int>() { 204, 205, 206, 222 };//二组人员
public readonly List<int> Group3Peoples = new List<int>() { 60, 182, 190, 213 };//三组人员
public readonly List<int> Group4Peoples = new List<int>() { 207, 208, 209, 210, 212 };//四组人员
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod(EnableSession = true)]
public void SetFedex()
{
// ErrorFollow.TraceWrite("GetTrackCode", "", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
string error = "";
//var md = DataNew.GetAutoCode(1);//smart
var obj11 = new BaseService();
int ExpressId = 228;
//if (md != null && md.StoreId == 11)
// ExpressId = 237;
//// if(md!=null)
//// ErrorFollow.TraceWrite("GetTrackCode", "md1", md.PlatOrderCode);
var companymd = obj11.GetAddressModel2(ExpressId);
var pmd = DataNew.GetExpressModel(1, ExpressId);
//if (md != null && pmd != null && companymd != null)
// error = DD_OrderServiceNew.GetOrderPostCodeAuto(md, pmd, companymd, ExpressId);
//if (error != "")
// ErrorFollow.TraceWrite("GetTrackCodesmart", "", error);
//md = DataNew.GetAutoCode(2);//smart
//ExpressId = 228;
//if (md != null && md.StoreId == 11)
// ExpressId = 237;
//if (md != null)
// error = DD_OrderServiceNew.GetOrderPostCodeAuto(md, pmd, companymd, ExpressId);
//if (error != "")
// ErrorFollow.TraceWrite("GetTrackCodesmart", "", error);
error = "";
var md3 = DataNew.GetAutoCode(5);//home
ExpressId = 234;
if (md3 != null && md3.StoreId == 11)
ExpressId = 239;
companymd = obj11.GetAddressModel2(ExpressId);
var pmd3 = DataNew.GetExpressModel(1, ExpressId);
if (md3 != null)
error = DD_OrderServiceNew.GetOrderPostCodeAuto(md3, pmd3, companymd, ExpressId);
if (error != "")
ErrorFollow.TraceWrite("GetTrackCodehome", "", error);
error = "";
var md2 = DataNew.GetAutoCode(3);//groud
ExpressId = 233;
if (md2 != null && md2.StoreId == 11)
ExpressId = 238;
companymd = obj11.GetAddressModel2(ExpressId);
var pmd2 = DataNew.GetExpressModel(1, ExpressId);
if (md2 != null)
error = DD_OrderServiceNew.GetOrderPostCodeAuto(md2, pmd2, companymd, ExpressId);
if (error != "")
ErrorFollow.TraceWrite("GetTrackCodegroud", "", error);
error = "";
md2 = DataNew.GetAutoCode(4);//groud
ExpressId = 228;
if (md2 != null && md2.StoreId == 11)
ExpressId = 237;
if (md2 != null)
error = DD_OrderServiceNew.GetOrderPostCodeAuto(md2, pmd2, companymd, 233);
if (error != "")
ErrorFollow.TraceWrite("GetTrackCodegroud", "", error);
}
#region 保存店铺数据
[WebMethod(EnableSession = true)]
public int SaveShopData2(JC_ShopDataNew Model)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
// if (Model.Id == null || Model.Id.Value == 0)
// Model.InDate = DateTime.Now;
Model.InName = Session["Name"].ToString();
Model.InUserId = Convert.ToInt32(Session["UserId"]);
int Id = DataNew.SaveShopData(Model);
return Id;
}
#endregion
#region 查询店铺数据
[WebMethod(EnableSession = true)]
public JsonModel<List<JC_ShopDataNew>> GetListJC_ShopData2(int ShopId, string ShopIds, DateTime? SDate, DateTime? EDate, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
RefParameterCollection Param = new RefParameterCollection();
if (ShopId > 0)
Param.Add("a.ShopId", "=", ShopId, DbType.Int32);
else if (ShopIds != "")
{
Param.Add("a.ShopId", "in", ShopIds.Trim(','), DbType.String);
}
if (SDate != null)
Param.Add("a.InDate", ">=", SDate, DbType.DateTime);
if (EDate != null)
Param.Add("a.InDate", "<", EDate.Value.AddDays(1), DbType.DateTime);
JsonModel<List<JC_ShopDataNew>> resultModel = new JsonModel<List<JC_ShopDataNew>>();
int RowCount = 0;
string Sort = "Id desc";
resultModel.DataSource = DataNew.GetListJC_ShopData2(Param, PageIndex, PageSize, Sort, out RowCount);
resultModel.RowCount = RowCount;
return resultModel;
}
#endregion
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_UserInfo> GetKFUserInfo()
{
PagesNew.Login(this.Session);
var ListModel = DataNew.GetKFUserInfo();
return ListModel;
}
#endregion
#region 报表401
[WebMethod(EnableSession = true)]
public string GetReportTable401(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode, decimal? moneyrate, int isyc)
{
try
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
string tj3 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
//TimeSpan ts = EDate.Value - SDate.Value;
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (moneyrate == null)
moneyrate = 6.8M;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=" + moneyrate + @"
--MRate from JC_Money where MCode='USD' and PlatId=2
--sjyf thf 退 thyf 退 wlssf qtfy ggf 广
--yj ,escrowFee ,yf ,b.cb ,b.sjcb ,b.hwsf ,b.sjhwsf ,b.ck ,b.md tc
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.State>0 and a.State<3 " + tj + @"
select a.UserId,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 from HW_GoodsUser 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 and a.ShopId=d.ShopId
where d.State>0 and d.State<3 " + tj3 + @"
group by a.UserId
select a.UserId,a.ShopId,d.OrderId into #ls_fee2 from HW_GoodsUser 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 and a.ShopId=d.ShopId
where d.State>0 and d.State<3 " + tj3 + @"
group by a.UserId,a.ShopId,d.OrderId
select 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.UserId
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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.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.UserId)a
select a.UserName,GoodsNum=a.Num,OutGoods=g.codenum,NoGoods=a.Num-g.codenum,Rate=g.codenum*1.00/a.Num,a.Name,sjzje=f.zje,OrderNum=g.ordernum,Num=g.GoodsNum,e.*,rylx=case when kh=0 then '' else '' end,ymxkh=kh,ymxjj=case when kh=0 then 0 when kh>=80000 and isnull(e.ymxml,0)>=kh then floor((isnull(e.ymxml,0)-kh)/10000)*300 when kh>=80000 and isnull(e.ymxml,0)<kh and (kh-isnull(e.ymxml,0))%10000>0 then floor((kh-isnull(e.ymxml,0))/10000)*-300-300 when kh>=80000 and isnull(e.ymxml,0)<kh then floor((kh-isnull(e.ymxml,0))/10000)*-300 when kh<80000 and isnull(e.ymxml,0)>=kh then floor((isnull(e.ymxml,0)-kh)/10000)*300 else 0 end from (
select a.UserId,a.UserName,a.Name,kh=isnull(a.AnnualDay,80000),b.Num from JC_UserInfo a
inner join (
select UserId,Num=COUNT(distinct GoodsId) from HW_GoodsUser with(nolock)
group by UserId)b on a.UserId=b.UserId
where a.state=1)a
inner join #ls_fee4 e on a.UserId=e.UserId
left join #ls_fee3 f on a.UserId=f.UserId
left join #ls_fee5 g on a.UserId=g.UserId
" + tj2 + @"";
DataTable dt = obj.GetReportData(sql);
if (isyc == 1)
return GetReport2(dt, 501);
else
return GetReport2(dt, 50);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetReportTable401", "", ex.Message);
return null;
}
}
#endregion
#region 报表410
[WebMethod(EnableSession = true)]
public string GetReportTable410(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode, decimal? moneyrate, int isyc)
{
try
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
string tj3 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
//TimeSpan ts = EDate.Value - SDate.Value;
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (moneyrate == null)
moneyrate = 6.8M;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=" + moneyrate + @"
--MRate from JC_Money where MCode='USD' and PlatId=2
--sjyf thf 退 thyf 退 wlssf qtfy ggf 广
--yj ,escrowFee ,yf ,b.cb ,b.sjcb ,b.hwsf ,b.sjhwsf ,b.ck ,b.md tc
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 " + tj + @"
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 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 " + tj3 + @"
group by a.muserid
select UserId=a.muserid,d.OrderId 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 " + tj3 + @"
group by a.muserid,d.OrderId
select 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.UserId
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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.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.UserId)a
select a.UserName,GoodsNum=a.Num,OutGoods=g.codenum,NoGoods=a.Num-g.codenum,Rate=g.codenum*1.00/a.Num,a.Name,sjzje=f.zje,OrderNum=g.ordernum,Num=g.GoodsNum,e.*,rylx=case when kh=0 then '' else '' end,ymxkh=kh,ymxjj=case when kh=0 then 0 when kh>=80000 and isnull(e.ymxml,0)>=kh then floor((isnull(e.ymxml,0)-kh)/10000)*300 when kh>=80000 and isnull(e.ymxml,0)<kh and (kh-isnull(e.ymxml,0))%10000>0 then floor((kh-isnull(e.ymxml,0))/10000)*-300-300 when kh>=80000 and isnull(e.ymxml,0)<kh then floor((kh-isnull(e.ymxml,0))/10000)*-300 when kh<80000 and isnull(e.ymxml,0)>=kh then floor((isnull(e.ymxml,0)-kh)/10000)*300 else 0 end from (
select a.UserId,a.UserName,a.Name,kh=isnull(a.AnnualDay,80000),b.Num from JC_UserInfo a
inner join (
select UserId=muserid,Num=COUNT(distinct GoodsId) from HW_GoodsInfo with(nolock)
where muserid>0
group by muserid)b on a.UserId=b.UserId
where a.state=1)a
left join #ls_fee4 e on a.UserId=e.UserId
left join #ls_fee3 f on a.UserId=f.UserId
left join #ls_fee5 g on a.UserId=g.UserId
" + tj2 + @" order by g.codenum desc";
DataTable dt = obj.GetReportData(sql);
if (isyc == 1)
return GetReport2(dt, 501);
else
return GetReport2(dt, 50);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetReportTable410", "", ex.Message);
return null;
}
}
#endregion
#region 报表405
[WebMethod(EnableSession = true)]
public string GetReportTable405(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode, decimal? moneyrate, int isyc)
{
try
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
string tj3 = "";
string tj4 = "";
string tj5 = "";
string tj6 = "";
string tj7 = "";
string tj8 = "";
string tj9 = "";
string tj10 = "";
string tj11 = "";
string tj12 = "";
string tj13 = "";
string tj14 = "";
string tj15 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and a.OrderDate>='" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj5 += " and d.OrderDate>='" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj6 += " and a.OrderDate>='" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj7 += " and d.OrderDate>='" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj11 = " and DHDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj12 = " and DHDate>='" + SDate.Value.AddYears(-1).AddMonths(1).AddMonths(-1).ToString("yyyy-MM-dd") + "' and DHDate<'" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj14 = " and a.DHDate<'" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj15 = " and a.DHDate<'" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and a.OrderDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj5 += " and d.OrderDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj6 += " and a.OrderDate<'" + EDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj7 += " and d.OrderDate<'" + EDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj13 = " and DHDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
//TimeSpan ts = EDate.Value - SDate.Value;
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (moneyrate == null)
moneyrate = 6.8M;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=" + moneyrate + @"
--MRate from JC_Money where MCode='USD' and PlatId=2
--sjyf thf 退 thyf 退 wlssf qtfy ggf 广
--yj ,escrowFee ,yf ,b.cb ,b.sjcb ,b.hwsf ,b.sjhwsf ,b.ck ,b.md tc
--
select muserid,GoodsId into #ls_bysl from HW_GoodsInfo where muserid>0 " + tj11 + @"
select muserid,dynum=COUNT(0) into #ls_bysl_num from #ls_bysl group by muserid
--
select muserid,GoodsId into #ls_sysl from HW_GoodsInfo where muserid>0 " + tj12 + @"
select muserid,synum=COUNT(0) into #ls_sysl_num from #ls_sysl group by muserid
--
select muserid,GoodsId into #ls_qnsl from HW_GoodsInfo where muserid>0 " + tj13 + @"
select muserid,qnnum=COUNT(0) into #ls_qnsl_num from #ls_qnsl group by muserid
--
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_byorder 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 " + tj + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_byordernum from #ls_bysl 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_syordernum from #ls_sysl 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_qnordernum from #ls_qnsl 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid
--
select UserId=a.muserid,d.OrderId into #ls_byuserorder from #ls_bysl 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid,d.OrderId
--
select UserId=a.muserid,d.OrderId into #ls_syuserorder from #ls_sysl 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid,d.OrderId
--
select UserId=a.muserid,d.OrderId into #ls_qnuserorder from #ls_qnsl 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid,d.OrderId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_bylr from (
select 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_byuserorder a
inner join #ls_byorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_sylr from (
select 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_syuserorder a
inner join #ls_byorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_qnlr from (
select 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_qnuserorder a
inner join #ls_byorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
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_syorder 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 " + tj6 + @"
--
select UserId=a.muserid,d.OrderId into #ls_syuserorderinfo 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 #ls_syorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid,d.OrderId
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_syordergoods 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 #ls_syorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_sy from (
select 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_syuserorderinfo a
inner join #ls_syorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
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_qnorder 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 " + tj4 + @"
--
select UserId=a.muserid,d.OrderId into #ls_qnuserorderinfo 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 #ls_qnorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid,d.OrderId
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_qnordergoods 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 #ls_qnorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0
group by a.muserid
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_qn from (
select 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_qnuserorderinfo a
inner join #ls_qnorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
--
select UserId=a.muserid,d.OrderId into #ls_byuserorderinfo_bz 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj14 + @"
group by a.muserid,d.OrderId
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_byordergoods_bz 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj14 + @"
group by a.muserid
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_by_bz from (
select 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_byuserorderinfo_bz a
inner join #ls_byorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
select UserId=a.muserid,d.OrderId into #ls_syuserorderinfo_bz 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 #ls_syorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj14 + @"
group by a.muserid,d.OrderId
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_syordergoods_bz 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 #ls_syorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj14 + @"
group by a.muserid
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_sy_bz from (
select 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_syuserorderinfo_bz a
inner join #ls_syorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
select UserId=a.muserid,d.OrderId into #ls_byuserorderinfo_qnbz 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj15 + @"
group by a.muserid,d.OrderId
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_byordergoods_qnbz 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 #ls_byorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj15 + @"
group by a.muserid
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_by_qnbz from (
select 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_byuserorderinfo_qnbz a
inner join #ls_byorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
select UserId=a.muserid,d.OrderId into #ls_qnuserorderinfo_bz 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 #ls_syorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj15 + @"
group by a.muserid,d.OrderId
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_qnordergoods_bz 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 #ls_syorder d with(nolock) on c.OrderId=d.OrderId
where d.PlatId=2 and a.muserid>0 " + tj15 + @"
group by a.muserid
--/
select a.UserId,qnxlbz=(a.GoodsNum+1)/(isnull(b.GoodsNum,0)+1) into #ls_qnxlbz from #ls_byordergoods_qnbz a
left join #ls_qnordergoods_bz b on a.UserId=b.UserId
--/
select a.UserId,syxlbz=(a.GoodsNum+1)/(isnull(b.GoodsNum,0)+1) into #ls_syxlbz from #ls_byordergoods_bz a
left join #ls_syordergoods_bz b on a.UserId=b.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_qn_bz from (
select 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_qnuserorderinfo_bz a
inner join #ls_qnorder b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--/
select a.UserId,qnlrbz=(isnull(a.ml,0)+1)/(isnull(b.ml,0)+1) into #ls_qnlrbz from #ls_fee4_by_qnbz a
left join #ls_fee4_qn_bz b on a.UserId=b.UserId
--/
select a.UserId,sylrbz=(isnull(a.ml,0)+1)/(isnull(b.ml,0)+1) into #ls_sylrbz from #ls_fee4_by_bz a
left join #ls_fee4_sy_bz b on a.UserId=b.UserId
--
select distinct UserId=muserid into #ls_user from HW_GoodsInfo with(nolock)
where muserid>0
select a.UserId,b.Name,dynum=isnull(c.dynum,0),synum=isnull(d.synum,0),qnnum=isnull(e.qnnum,0),dygoodsnum=isnull(f.GoodsNum,0),sygoodsnum=isnull(g.GoodsNum,0),qngoodsnum=isnull(h.GoodsNum,0),sygoodsnum2=isnull(i.GoodsNum,0),qngoodsnum2=isnull(j.GoodsNum,0),dyml=isnull(k.ml,0),syml=isnull(l.ml,0),qnml=isnull(m.ml,0),syml2=isnull(n.ml,0),qnml2=isnull(o.ml,0),xpnum=isnull(f.GoodsNum,0),qnxlbz=p.qnxlbz,syxlbz=q.syxlbz,xpml=isnull(k.ml,0),qnlrbz=r.qnlrbz,sylrbz=s.sylrbz,df=ISNULL(p.qnxlbz,0)*ISNULL(q.syxlbz,0)*ISNULL(r.qnlrbz,0)*ISNULL(s.sylrbz,0),df2=isnull(c.dynum,0)*0.05+isnull(k.ml,0)*0.1 from #ls_user a
inner join JC_UserInfo b on a.UserId=b.UserId
left join #ls_bysl_num c on a.UserId=c.muserid
left join #ls_sysl_num d on a.UserId=d.muserid
left join #ls_qnsl_num e on a.UserId=e.muserid
left join #ls_byordernum f on a.UserId=f.UserId
left join #ls_syordernum g on a.UserId=g.UserId
left join #ls_qnordernum h on a.UserId=h.UserId
left join #ls_syordergoods i on a.UserId=i.UserId
left join #ls_qnordergoods j on a.UserId=j.UserId
left join #ls_bylr k on a.UserId=k.UserId
left join #ls_sylr l on a.UserId=l.UserId
left join #ls_qnlr m on a.UserId=m.UserId
left join #ls_fee4_sy n on a.UserId=n.UserId
left join #ls_fee4_qn o on a.UserId=o.UserId
left join #ls_qnxlbz p on a.UserId=p.UserId
left join #ls_syxlbz q on a.UserId=q.UserId
left join #ls_qnlrbz r on a.UserId=r.UserId
left join #ls_sylrbz s on a.UserId=s.UserId
" + tj2 + @"
order by e.qnnum desc
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 502);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetReportTable410", "", ex.Message);
return null;
}
}
#endregion
#region 报表405
[WebMethod(EnableSession = true)]
public string GetReportTable405_bak(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode, decimal? moneyrate, int isyc)
{
try
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
string tj3 = "";
string tj4 = "";
string tj5 = "";
string tj6 = "";
string tj7 = "";
string tj8 = "";
string tj9 = "";
string tj10 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and a.OrderDate>='" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj5 += " and d.OrderDate>='" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj6 += " and a.OrderDate>='" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj7 += " and d.OrderDate>='" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj9 = " and InDate<'" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and a.OrderDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj5 += " and d.OrderDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj6 += " and a.OrderDate<'" + EDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj7 += " and d.OrderDate<'" + EDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj8 = " and InDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj10 = " and InDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
//TimeSpan ts = EDate.Value - SDate.Value;
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (moneyrate == null)
moneyrate = 6.8M;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=" + moneyrate + @"
--MRate from JC_Money where MCode='USD' and PlatId=2
--sjyf thf 退 thyf 退 wlssf qtfy ggf 广
--yj ,escrowFee ,yf ,b.cb ,b.sjcb ,b.hwsf ,b.sjhwsf ,b.ck ,b.md tc
--
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 " + tj + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 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 " + tj3 + @"
group by a.muserid
--
select UserId=a.muserid,d.OrderId 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 " + tj3 + @"
group by a.muserid,d.OrderId
--
select 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.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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.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.UserId)a
--
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_qn 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 " + tj4 + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5_qn 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 " + tj5 + @"
group by a.muserid
--
select UserId=a.muserid,d.OrderId into #ls_fee2_qn 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 " + tj5 + @"
group by a.muserid,d.OrderId
--
select a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_qn from #ls_fee2_qn a
inner join #ls_fee_qn b on a.OrderId=b.OrderId
group by a.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_qn from (
select 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_qn a
inner join #ls_fee_qn b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
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_sy 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 " + tj6 + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5_sy 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 " + tj7 + @"
group by a.muserid
--
select UserId=a.muserid,d.OrderId into #ls_fee2_sy 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 " + tj7 + @"
group by a.muserid,d.OrderId
--
select a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_sy from #ls_fee2_sy a
inner join #ls_fee_sy b on a.OrderId=b.OrderId
group by a.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_sy from (
select 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_sy a
inner join #ls_fee_sy b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
select muserid,num=COUNT(0) into #ls_bysl from HW_GoodsInfo where muserid>0 " + tj8 + @" group by muserid
select muserid,num=COUNT(0) into #ls_sysl from HW_GoodsInfo where muserid>0 " + tj9 + @" group by muserid
select muserid,num=COUNT(0) into #ls_qnsl from HW_GoodsInfo where muserid>0 " + tj10 + @" group by muserid
select a.UserId,h.Name,bynum=isnull(b.num,0),synum=isnull(c.num,0),qynum=isnull(d.num,0),byzje=f.zje,byml=e.ml,bymll=e.mll,byGoodsNum=g.GoodsNum,byordernum=g.ordernum,bycodenum=g.codenum,syzje=ff.zje,syml=ee.ml,symll=ee.mll,syGoodsNum=gg.GoodsNum,syordernum=gg.ordernum,sycodenum=gg.codenum,qnzje=fff.zje,qnml=eee.ml,qnmll=eee.mll,qnGoodsNum=ggg.GoodsNum,qnordernum=ggg.ordernum,qncodenum=ggg.codenum from (
select UserId=muserid,Num=COUNT(distinct GoodsId) from HW_GoodsInfo with(nolock)
where muserid>0
group by muserid)a
inner join JC_UserInfo h on a.UserId=h.UserId
left join #ls_bysl b on a.UserId=b.muserid
left join #ls_sysl c on a.UserId=c.muserid
left join #ls_qnsl d on a.UserId=d.muserid
left join #ls_fee4 e on a.UserId=e.UserId
left join #ls_fee3 f on a.UserId=f.UserId
left join #ls_fee5 g on a.UserId=g.UserId
left join #ls_fee4_sy ee on a.UserId=ee.UserId
left join #ls_fee3_sy ff on a.UserId=ff.UserId
left join #ls_fee5_sy gg on a.UserId=gg.UserId
left join #ls_fee4_qn eee on a.UserId=eee.UserId
left join #ls_fee3_qn fff on a.UserId=fff.UserId
left join #ls_fee5_qn ggg on a.UserId=ggg.UserId
" + tj2 + @"
order by a.Num desc
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 502);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetReportTable410", "", ex.Message);
return null;
}
}
#endregion
#region 报表405
[WebMethod(EnableSession = true)]
public string GetReportExcel405(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode, decimal? moneyrate, int isyc)
{
try
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
string tj3 = "";
string tj4 = "";
string tj5 = "";
string tj6 = "";
string tj7 = "";
string tj8 = "";
string tj9 = "";
string tj10 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and a.OrderDate>='" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj5 += " and d.OrderDate>='" + SDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj6 += " and a.OrderDate>='" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj7 += " and d.OrderDate>='" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj9 = " and InDate<'" + SDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and a.OrderDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj5 += " and d.OrderDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
tj6 += " and a.OrderDate<'" + EDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj7 += " and d.OrderDate<'" + EDate.Value.AddMonths(-1).ToString("yyyy-MM-dd") + "' ";
tj8 = " and InDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj10 = " and InDate<'" + EDate.Value.AddYears(-1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
//TimeSpan ts = EDate.Value - SDate.Value;
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (moneyrate == null)
moneyrate = 6.8M;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=" + moneyrate + @"
--MRate from JC_Money where MCode='USD' and PlatId=2
--sjyf thf 退 thyf 退 wlssf qtfy ggf 广
--yj ,escrowFee ,yf ,b.cb ,b.sjcb ,b.hwsf ,b.sjhwsf ,b.ck ,b.md tc
--
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 " + tj + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 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 " + tj3 + @"
group by a.muserid
--
select UserId=a.muserid,d.OrderId 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 " + tj3 + @"
group by a.muserid,d.OrderId
--
select 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.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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.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.UserId)a
--
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_qn 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 " + tj4 + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5_qn 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 " + tj5 + @"
group by a.muserid
--
select UserId=a.muserid,d.OrderId into #ls_fee2_qn 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 " + tj5 + @"
group by a.muserid,d.OrderId
--
select a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_qn from #ls_fee2_qn a
inner join #ls_fee_qn b on a.OrderId=b.OrderId
group by a.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_qn from (
select 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_qn a
inner join #ls_fee_qn b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
--
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_sy 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 " + tj6 + @"
--
select UserId=a.muserid,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5_sy 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 " + tj7 + @"
group by a.muserid
--
select UserId=a.muserid,d.OrderId into #ls_fee2_sy 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 " + tj7 + @"
group by a.muserid,d.OrderId
--
select a.UserId,zje=SUM(b.TotalPrice) into #ls_fee3_sy from #ls_fee2_sy a
inner join #ls_fee_sy b on a.OrderId=b.OrderId
group by a.UserId
--
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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_sy from (
select 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_sy a
inner join #ls_fee_sy b on a.OrderId=b.OrderId
where b.yf>0 and b.cb>0
group by a.UserId)a
select muserid,num=COUNT(0) into #ls_bysl from HW_GoodsInfo where muserid>0 " + tj8 + @" group by muserid
select muserid,num=COUNT(0) into #ls_sysl from HW_GoodsInfo where muserid>0 " + tj9 + @" group by muserid
select muserid,num=COUNT(0) into #ls_qnsl from HW_GoodsInfo where muserid>0 " + tj10 + @" group by muserid
select a.UserId,h.Name,bynum=isnull(b.num,0),synum=isnull(c.num,0),qynum=isnull(d.num,0),byzje=f.zje,byml=e.ml,bymll=e.mll,byGoodsNum=g.GoodsNum,byordernum=g.ordernum,bycodenum=g.codenum,syzje=ff.zje,syml=ee.ml,symll=ee.mll,syGoodsNum=gg.GoodsNum,syordernum=gg.ordernum,sycodenum=gg.codenum,qnzje=fff.zje,qnml=eee.ml,qnmll=eee.mll,qnGoodsNum=ggg.GoodsNum,qnordernum=ggg.ordernum,qncodenum=ggg.codenum from (
select UserId=muserid,Num=COUNT(distinct GoodsId) from HW_GoodsInfo with(nolock)
where muserid>0
group by muserid)a
inner join JC_UserInfo h on a.UserId=h.UserId
left join #ls_bysl b on a.UserId=b.muserid
left join #ls_sysl c on a.UserId=c.muserid
left join #ls_qnsl d on a.UserId=d.muserid
left join #ls_fee4 e on a.UserId=e.UserId
left join #ls_fee3 f on a.UserId=f.UserId
left join #ls_fee5 g on a.UserId=g.UserId
left join #ls_fee4_sy ee on a.UserId=ee.UserId
left join #ls_fee3_sy ff on a.UserId=ff.UserId
left join #ls_fee5_sy gg on a.UserId=gg.UserId
left join #ls_fee4_qn eee on a.UserId=eee.UserId
left join #ls_fee3_qn fff on a.UserId=fff.UserId
left join #ls_fee5_qn ggg on a.UserId=ggg.UserId
" + tj2 + @"
order by a.Num desc
";
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 502);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetReportTable405", "", ex.Message);
return null;
}
}
#endregion
#region 报表403
[WebMethod(EnableSession = true)]
public string GetReportTable403(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode, decimal? moneyrate)
{
try
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
string tj3 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (moneyrate == null)
moneyrate = 6.8M;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=" + moneyrate + @"
--MRate from JC_Money where MCode='USD' and PlatId=2
--sjyf thf 退 thyf 退 wlssf qtfy ggf 广
--yj ,escrowFee ,yf ,b.cb ,b.sjcb ,b.hwsf ,b.sjhwsf ,b.ck ,b.md tc
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.State>0 and a.State<3 " + tj + @"
select a.UserId,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 from HW_GoodsUser 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 and a.ShopId=d.ShopId
where d.State>0 and d.State<3 " + tj3 + @"
group by a.UserId
select a.UserId,a.ShopId,d.OrderId into #ls_fee2 from HW_GoodsUser 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 and a.ShopId=d.ShopId
where d.State>0 and d.State<3 " + tj3 + @"
group by a.UserId,a.ShopId,d.OrderId
select 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.UserId
select a.UserId,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,thf,thyf,ggf,qtfy,wlssf,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,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.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.UserId)a
select a.UserName,GoodsNum=a.Num,OutGoods=g.codenum,NoGoods=a.Num-g.codenum,Rate=g.codenum*1.00/a.Num,a.Name,sjzje=f.zje,OrderNum=g.ordernum,Num=g.GoodsNum,e.*,rylx=case when kh=0 then '' else '' end,ymxkh=kh,ymxjj=isnull(e.ymxml,0)-kh from (
select a.UserId,a.UserName,a.Name,kh=550*" + days + @",b.Num from JC_UserInfo a
inner join (
select UserId,Num=COUNT(distinct GoodsId) from HW_GoodsUser with(nolock)
group by UserId)b on a.UserId=b.UserId
where a.state=1)a
inner join #ls_fee4 e on a.UserId=e.UserId
left join #ls_fee3 f on a.UserId=f.UserId
left join #ls_fee5 g on a.UserId=g.UserId
" + tj2 + @"";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 53);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetReportTable401", "", ex.Message);
return null;
}
}
#endregion
#region 报表401
[WebMethod(EnableSession = true)]
public string GetReportTable4012(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " b.LastOrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " and b.LastOrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
string tj3 = "";
string tj4 = "";
if (SDate != null)
{
tj3 += " OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " addate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj3 += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and addate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
//TimeSpan ts = EDate.Value - SDate.Value;
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
//if (GoodsCode != "")
// tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
declare @MRate decimal(18,4)
select top 1 @MRate=MRate from JC_Money where MCode='USD' and PlatId=2
--
select *,zje=dbo.MoneyUSDChange(TotalPrice,MoneyCode,1),yj=dbo.getYJRate2(PlatId,dbo.MoneyUSDChange(TotalPrice,MoneyCode,2)) into #DT_OrderInfoUser from DT_OrderInfo with(nolock) where CompanyId=1 and State>0 and State<3 " + tj + @" and dbo.[GetOrderPostFee](OrderId)>0
--退
select DR_BackFee,orderid into #BackFee_ls from DT_OrderInfo where " + tj3 + @"
--退
select DR_PostFee,orderid into #PostFee_ls from DT_OrderInfo where " + tj3 + @"
--退
select DR_SSFee,orderid into #SSFee_ls from DT_OrderInfo where " + tj3 + @"
--广
select shopid,goodsid,addfee=SUM(dec3) into #ADFee_ls from DT_AdFee where " + tj4 + @" group by shopid,goodsid
--select * from #ADFee_ls where addfee>10000
--
/* select e.OrderId,ckfee=isnull(sum((DATEDIFF(day,a.InDate,a.UpDateTime)+1)*0.5*d.GoodsNum*ISNULL(c.Solid,0)),0) into #CKFee_ls from HW_GoodsInDetail 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_OrderGoods d with(nolock) on a.OrderGoodsId=d.Id
inner join #DT_OrderInfoUser e on d.OrderId=e.OrderId
where a.UpDateTime is not null group by e.OrderId */
update #DT_OrderInfoUser set GoodsNum=1 where ISNULL(GoodsNum,0)=0
select a.ShopId,PlatId=case when a.PlatId=2 then 2 else 1 end,c.GoodsId,zje=SUM(a.zje*b.GoodsNum/a.GoodsNum),yj=SUM(a.yj*b.GoodsNum/a.GoodsNum),OrderNum=COUNT(distinct a.PlatOrderCode),Num=sum(b.GoodsNum),OutGoods=count(distinct d.GoodsId),cb=sum(b.GoodsNum*isnull(d.InPrice,0))/6.6,tc=sum(170*isnull(d.Solid,0)*isnull(b.GoodsNum,0)),md=sum(b.GoodsNum)*0.6,yf=SUM(L.yf),sf=sum(b.GoodsNum*isnull(d.InPrice,0)*isnull(d.FeeRate,0)*0.01)/6.6,ck=isnull(sum(L.ck),0),tkf=isnull(sum(e.DR_BackFee),0),thyf=isnull(sum(f.DR_PostFee),0),ssf=isnull(sum(g.DR_SSFee),0) into #DT_Fee_LS from #DT_OrderInfoUser 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
left join [DT_Fees] L on a.OrderId=L.OrderId
left join #BackFee_ls e on a.OrderId=e.OrderId
left join #PostFee_ls f on a.OrderId=f.OrderId
left join #SSFee_ls g on a.OrderId=g.OrderId
group by a.PlatId,a.ShopId,c.GoodsId
--drop table #DT_Fee_LS
select a.*,ggf=isnull(b.addfee,0),ml=zje-yj-cb-tc-md-yf-sf-ck-tkf-thyf-isnull(b.addfee,0)+ssf,ml2=zje-yj-cb-tc-yf-sf-tkf-thyf-isnull(b.addfee,0)+ssf into #DT_Fee_LS2 from #DT_Fee_LS a
left join #ADFee_ls b on a.GoodsId=b.goodsid and a.ShopId=b.shopid
select b.UserId,ml=SUM(c.ml2)*@MRate into #DT_Fee_LS3 from HW_GoodsUser a with(nolock)
inner join JC_UserInfo b on a.UserId=b.UserId
inner join #DT_Fee_LS2 c on a.GoodsId=c.GoodsId and a.ShopId=c.ShopId
where b.State=1
group by b.UserId
--select SUM(zje),sum(cb),SUM(tc),SUM(yf) from #DT_Fee_LS2
select a.*,GoodsNum=d.Num,NoGoods=d.Num-OutGoods,Rate=OutGoods*1.00/d.Num,ymxml=isnull(e.ml,0),rylx=case when kh=0 then '' else '' end,ymxkh=kh,ymxjj=case when kh=0 then 0 when kh>=80000 and isnull(e.ml,0)>=kh then floor((isnull(e.ml,0)-kh)/10000)*300 when kh>=80000 and isnull(e.ml,0)<kh and (kh-isnull(e.ml,0))%10000>0 then floor((kh-isnull(e.ml,0))/10000)*-300-300 when kh>=80000 and isnull(e.ml,0)<kh then floor((kh-isnull(e.ml,0))/10000)*-300 when kh<80000 and isnull(e.ml,0)>=kh then floor((isnull(e.ml,0)-kh)/10000)*300 else 0 end from (
select b.UserId,b.UserName,b.Name,Num=SUM(Num),OutGoods=SUM(OutGoods),OrderNum=SUM(OrderNum),zje=SUM(c.zje),yj=SUM(c.yj),cb=SUM(c.cb),tc=SUM(c.tc),md=SUM(c.md),yf=SUM(c.yf),sf=SUM(c.sf),ck=SUM(c.ck),tkf=SUM(c.tkf),thyf=SUM(c.thyf),ggf=SUM(c.ggf),ssf=SUM(c.ssf),ml=SUM(c.ml),mll=SUM(c.ml)/SUM(c.zje),kh=MAX(isnull(AnnualDay,0)) from HW_GoodsUser a with(nolock)
inner join JC_UserInfo b on a.UserId=b.UserId
inner join #DT_Fee_LS2 c on a.GoodsId=c.GoodsId and a.ShopId=c.ShopId
where b.State=1
group by b.UserId,b.UserName,b.Name)a
inner join (select UserId,Num=COUNT(distinct GoodsId) from HW_GoodsUser with(nolock)
group by UserId)d on a.UserId=d.UserId
left join #DT_Fee_LS3 e on a.UserId=e.UserId
" + tj2 + @"
--select * from HW_GoodsUser
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 50);
}
#endregion
#region 报表401
[WebMethod(EnableSession = true)]
public string GetReportTable4011(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " b.LastOrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " and b.LastOrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " and a.UserId=" + UserId + " ";
}
decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days;
decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
decimal fje = 0;
if (hj > 0)
fje = thj * 1.00M / hj;
if (GoodsCode != "")
tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
select * into #DT_OrderInfoUser from DT_OrderInfo with(nolock) where CompanyId=1 and State>0 and State<3 " + tj + @" and dbo.[GetOrderPostFee](OrderId)>0
select a.UserId,Num=COUNT(distinct a.GoodsId) into #DT_OrderInfoUser3 from HW_GoodsUser a with(nolock)
inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId
inner join HW_GoodsDetail e with(nolock) on b.GoodsId=e.GoodsId
inner join DT_OrderGoods c with(nolock) on e.DetailId=c.DetailId
inner join #DT_OrderInfoUser d with(nolock) on c.OrderId=d.OrderId and a.ShopId=d.ShopId
where d.CompanyId=1 " + tj2 + @" group by a.UserId
select a.OrderId,a.TotalPrice,a.MoneyCode,a.ShopId,a.PlatId,a.PlatOrderCode,a.InDate,b.DetailId,b.GoodsNum,b.id into #DT_OrderInfo_Ls from DT_OrderInfo a with(nolock)
inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId
where a.CompanyId=1 and a.State>0 and a.State<3 " + tj + @" and dbo.[GetOrderPostFee](a.OrderId)>0
select f.UserId,zje=sum(a.TotalPrice),cb=sum(a.GoodsNum*d.InPrice)/6.6,tc=sum(170*isnull(d.Solid,0)),md=count(distinct a.PlatOrderCode)*0.6,yf=SUM(dbo.[GetOrderPostFee](a.OrderId)),sf=sum(a.GoodsNum*d.InPrice*isnull(d.FeeRate,0)*0.01)/6.6 into #DT_OrderInfo_Ls3 from #DT_OrderInfo_Ls a
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 f with(nolock) on d.GoodsId=f.GoodsId and a.ShopId=f.ShopId
--left join HW_GoodsInDetail e with(nolock) on a.Id=e.OrderGoodsId
where dbo.[GetOrderPostFee](a.OrderId)>0
group by f.UserId
select b.UserId,b.Num,Price=dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId),yjPrice=dbo.getYJRate2(a.PlatId,dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId)) into #DT_OrderInfoUser2 from #DT_OrderInfoUser a inner join (
select a.UserId,d.OrderId,Num=SUM(c.GoodsNum) from HW_GoodsUser a with(nolock)
inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId
inner join HW_GoodsDetail e with(nolock) on b.GoodsId=e.GoodsId
inner join DT_OrderGoods c with(nolock) on e.DetailId=c.DetailId
inner join #DT_OrderInfoUser d on c.OrderId=d.OrderId and a.ShopId=d.ShopId
where d.CompanyId=1 " + tj2 + @"
group by a.UserId,d.OrderId)b on a.OrderId=b.OrderId
select a.UserId,zje=b.Price,je=b.Price-b.yjPrice,a.cb,a.tc,a.yf,a.md,ckf=b.Price*" + fje + @",sf,ml=b.Price-b.yjPrice-cb-sf-md-tc-yf-zje*" + fje + @",mll=case when b.Price>0 then (b.Price-b.yjPrice-cb-sf-tc-md-yf-b.Price*" + fje + @")*100/b.Price else 0 end into #DT_OrderInfo_Ls2 from #DT_OrderInfo_Ls3 a
inner join (
select UserId,OrderNum=COUNT(0),Price=SUM(Price),yjPrice=SUM(yjPrice) from #DT_OrderInfoUser2
group by UserId)b on a.userid=b.UserId
select c.Name,c.UserName,a.*,GoodsNum=d.Num,OutGoods=isnull(e.Num,0),Rate=case when d.Num>0 then isnull(e.Num,0)*1.0/d.Num else 0 end,NoGoods=d.Num-isnull(e.Num,0),f.* from (
select UserId,Num=sum(Num),OrderNum=COUNT(0),Price=SUM(Price) from #DT_OrderInfoUser2
group by UserId)a
inner join JC_UserInfo c on a.UserId=c.UserId
inner join (select UserId,Num=COUNT(distinct GoodsId) from HW_GoodsUser with(nolock)
group by UserId)d on c.UserId=d.UserId
left join #DT_OrderInfoUser3 e on c.UserId=e.UserId
left join #DT_OrderInfo_Ls2 f on c.userid=f.userid
drop table #DT_OrderInfoUser, #DT_OrderInfoUser2, #DT_OrderInfoUser3,#DT_OrderInfo_Ls,#DT_OrderInfo_Ls2
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 50);
}
#endregion
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_UserInfo> GetAllListJC_UserInfo()
{
PagesNew.Login(this.Session);
var ListModel = JC_ShopService.GetListUserInfo();
return ListModel;
}
#endregion
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_UserInfo> GetListUserInfoFromDept(int deptid)
{
PagesNew.Login(this.Session);
var ListModel = DataNew.GetListUserInfoFromDept(deptid);
return ListModel;
}
#endregion
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_UserInfo> GetListUserInfoFromGroup3(int groupid)
{
PagesNew.Login(this.Session);
int UserId = Convert.ToInt32(Session["UserId"]);
var ListModel = DataNew.GetListUserInfoFromGroup3(UserId, groupid);
return ListModel;
}
#endregion
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_UserInfo> GetListUserInfoFromGroup()
{
PagesNew.Login(this.Session);
int UserId = Convert.ToInt32(Session["UserId"]);
var ListModel = DataNew.GetListUserInfoFromGroup(UserId);
return ListModel;
}
#endregion
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_UserInfo> GetListUserInfoFromGroup2(int iscp)
{
PagesNew.Login(this.Session);
int UserId = Convert.ToInt32(Session["UserId"]);
var ListModel = DataNew.GetListUserInfoFromGroup2(UserId, iscp);
return ListModel;
}
#endregion
#region 报表402
[WebMethod(EnableSession = true)]
public string GetReportTable402(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj3 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
}
string tj2 = "";
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
// TimeSpan ts = EDate.Value - SDate.Value;
// DateTime dt1 = Convert.ToDateTime("2008-8-8");
//DateTime dt2 = System.DateTime.Now;
DateTime dt1 = SDate.Value;
DateTime dt2 = EDate.Value;
// int Year = dt2.Year - dt1.Year;
int Month = (dt2.Year - dt1.Year) * 12 + (dt2.Month - dt1.Month);
if (Month == 0)
Month = 1;
decimal jcje = Convert.ToDecimal(14000 * 0.03 * Month);
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (GoodsCode != "")
tj2 += " d.GoodsCode='" + GoodsCode + "' ";
string sql = @"
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.State>0 and a.State<3 " + tj + @"
select KFName=a.KFName2,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 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.State>0 and d.State<3 and ISNULL(a.kfname2,'')<>'' " + tj3 + @"
group by a.KFName2
select KFName=a.KFName2,d.OrderId,tcrate=max(a.tcrate) 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.State>0 and d.State<3 and ISNULL(a.kfname2,'')<>'' " + tj3 + @"
group by a.KFName2,d.OrderId
select a.KFName,zje=SUM(b.TotalPrice) into #ls_fee3 from #ls_fee2 a
inner join #ls_fee b on a.OrderId=b.OrderId
group by a.KFName
select a.KFName,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,tkf=thf,thyf,ggf,qtfy,ssf=wlssf,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-ck-md-thf-thyf-ggf-qtfy+wlssf,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,a.tcrate into #ls_fee4 from (
select a.KFName,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)),tcrate=max(a.tcrate) 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.KFName)a
select a.UserId,a.name,GoodsNum=a.Num,OutGoods=g.codenum,NoGoods=a.Num-g.codenum,Rate=g.codenum*1.00/a.Num,a.Name,sjzje=f.zje,OrderNum=g.ordernum,Num=g.GoodsNum,e.*,mltc=case when e.ml<0 then 0 else e.ml*e.tcrate end-" + jcje + ",jcje=" + jcje + @" from (
select a.UserId,a.UserName,a.Name,b.Num from JC_UserInfo a
inner join (
select KFName=KFName2,Num=COUNT(distinct GoodsId) from HW_GoodsInfo with(nolock)
group by KFName2)b on a.Name=b.KFName
where a.state=1)a
inner join #ls_fee4 e on a.Name=e.KFName
left join #ls_fee3 f on a.Name=f.KFName
left join #ls_fee5 g on a.Name=g.KFName
" + tj2 + @"";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 52);
}
#endregion
#region 报表402 排除2020年7月
[WebMethod(EnableSession = true)]
public string GetReportTable402_PC(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj3 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj3 += " and d.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
}
string tj2 = "";
if (UserId > 0)
{
tj2 += " where a.UserId=" + UserId + " ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
// TimeSpan ts = EDate.Value - SDate.Value;
// DateTime dt1 = Convert.ToDateTime("2008-8-8");
//DateTime dt2 = System.DateTime.Now;
DateTime dt1 = SDate.Value;
DateTime dt2 = EDate.Value;
// int Year = dt2.Year - dt1.Year;
int Month = (dt2.Year - dt1.Year) * 12 + (dt2.Month - dt1.Month);
if (Month == 0)
Month = 1;
decimal jcje = Convert.ToDecimal(14000 * 0.03 * Month);
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (GoodsCode != "")
tj2 += " d.GoodsCode='" + GoodsCode + "' ";
string sql = @"
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.State>0 and a.State<3 and isnull(a.ck_date,getdate())>='2020-07-01' " + tj + @"
select KFName=a.KFName2,ordernum=COUNT(distinct d.OrderId),codenum=COUNT(distinct a.GoodsId),GoodsNum=sum(c.GoodsNum) into #ls_fee5 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.State>0 and d.State<3 and isnull(d.ck_date,getdate())>='2020-07-01' and ISNULL(a.kfname2,'')<>'' " + tj3 + @"
group by a.KFName2
select KFName=a.KFName2,d.OrderId,tcrate=max(a.tcrate) 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.State>0 and d.State<3 and isnull(d.ck_date,getdate())>='2020-07-01' and ISNULL(a.kfname2,'')<>'' " + tj3 + @"
group by a.KFName2,d.OrderId
select a.KFName,zje=SUM(b.TotalPrice) into #ls_fee3 from #ls_fee2 a
inner join #ls_fee b on a.OrderId=b.OrderId
group by a.KFName
select a.KFName,zje,escrowFee,yj,yf,cb,hwsf,tc,ck,md,tkf=thf,thyf,ggf,qtfy,ssf=wlssf,ml=zje-escrowFee-yj-yf-cb-hwsf-tc-ck-md-thf-thyf-ggf-qtfy+wlssf,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,a.tcrate into #ls_fee4 from (
select a.KFName,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)),tcrate=max(a.tcrate) 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.KFName)a
select a.UserId,a.name,GoodsNum=a.Num,OutGoods=g.codenum,NoGoods=a.Num-g.codenum,Rate=g.codenum*1.00/a.Num,a.Name,sjzje=f.zje,OrderNum=g.ordernum,Num=g.GoodsNum,e.*,mltc=case when e.ml<0 then 0 else e.ml*e.tcrate end-" + jcje + ",jcje=" + jcje + @" from (
select a.UserId,a.UserName,a.Name,b.Num from JC_UserInfo a
inner join (
select KFName=KFName2,Num=COUNT(distinct GoodsId) from HW_GoodsInfo with(nolock)
group by KFName2)b on a.Name=b.KFName
where a.state=1)a
inner join #ls_fee4 e on a.Name=e.KFName
left join #ls_fee3 f on a.Name=f.KFName
left join #ls_fee5 g on a.Name=g.KFName
" + tj2 + @"";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 52);
}
#endregion
#region 报表402备份
[WebMethod(EnableSession = true)]
public string GetReportTable40211(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " b.LastOrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " and b.LastOrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " where b.UserId=" + UserId + " ";
}
string tj3 = "";
string tj4 = "";
if (SDate != null)
{
tj3 += " OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " addate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj3 += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and addate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
//decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
// TimeSpan ts = EDate.Value - SDate.Value;
// DateTime dt1 = Convert.ToDateTime("2008-8-8");
//DateTime dt2 = System.DateTime.Now;
DateTime dt1 = SDate.Value;
DateTime dt2 = EDate.Value;
// int Year = dt2.Year - dt1.Year;
int Month = (dt2.Year - dt1.Year) * 12 + (dt2.Month - dt1.Month);
decimal jcje = Convert.ToDecimal(14000 * 0.03 * Month);
//int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
if (GoodsCode != "")
tj2 += " d.GoodsCode='" + GoodsCode + "' ";
string sql = @"
--
select *,zje=dbo.MoneyUSDChange(TotalPrice,MoneyCode,1),yj=dbo.getYJRate2(PlatId,dbo.MoneyUSDChange(TotalPrice,MoneyCode,2)) into #DT_OrderInfoUser from DT_OrderInfo with(nolock) where CompanyId=1 and State>0 and State<3 " + tj + @" and dbo.[GetOrderPostFee](OrderId)>0
--退
select DR_BackFee,orderid into #BackFee_ls from DT_OrderInfo where " + tj3 + @"
--退
select DR_PostFee,orderid into #PostFee_ls from DT_OrderInfo where " + tj3 + @"
--退
select DR_SSFee,orderid into #SSFee_ls from DT_OrderInfo where " + tj3 + @"
--广
select goodsid,addfee=SUM(dec3) into #ADFee_ls from DT_AdFee where " + tj4 + @" group by goodsid
--
select e.OrderId,ckfee=isnull(sum((DATEDIFF(day,a.InDate,a.UpDateTime)+1)*0.5*d.GoodsNum*ISNULL(c.Solid,0)),0) into #CKFee_ls from HW_GoodsInDetail 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_OrderGoods d with(nolock) on a.OrderGoodsId=d.Id
inner join #DT_OrderInfoUser e on d.OrderId=e.OrderId
where a.UpDateTime is not null group by e.OrderId
select c.GoodsId,zje=SUM(a.zje*b.GoodsNum/a.GoodsNum),yj=SUM(a.yj*b.GoodsNum/a.GoodsNum),OrderNum=COUNT(distinct a.PlatOrderCode),Num=sum(b.GoodsNum),OutGoods=count(distinct d.GoodsId),cb=sum(b.GoodsNum*isnull(d.InPrice,0))/6.6,tc=sum(170*isnull(d.Solid,0)),md=sum(b.GoodsNum)*0.6,yf=SUM(dbo.[GetOrderPostFee](a.OrderId)),sf=sum(b.GoodsNum*isnull(d.InPrice,0)*isnull(d.FeeRate,0)*0.01)/6.6,ck=isnull(sum(L.ckfee),0),tkf=isnull(sum(e.DR_BackFee),0),thyf=isnull(sum(f.DR_PostFee),0),ssf=isnull(sum(g.DR_SSFee),0),tcrate=max(isnull(d.tcrate,0)) into #DT_Fee_LS from #DT_OrderInfoUser 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
left join #CKFee_ls L on a.OrderId=L.OrderId
left join #BackFee_ls e on a.OrderId=e.OrderId
left join #PostFee_ls f on a.OrderId=f.OrderId
left join #SSFee_ls g on a.OrderId=g.OrderId
group by c.GoodsId
select a.*,ggf=isnull(b.addfee,0),ml=zje-yj-cb-tc-md-yf-sf-ck-tkf-thyf-isnull(b.addfee,0)+ssf,mltc=(zje-yj-cb-tc-md-yf-sf-ck-tkf-thyf-isnull(b.addfee,0)+ssf)*a.tcrate into #DT_Fee_LS2 from #DT_Fee_LS a
left join #ADFee_ls b on a.GoodsId=b.goodsid
select b.UserId,b.Name,Num=sum(Num),GoodsNum=COUNT(0),OutGoods=SUM(OutGoods),NoGoods=COUNT(0)-SUM(OutGoods),Rate=SUM(OutGoods)*1.00/COUNT(0),OrderNum=SUM(OrderNum),zje=SUM(c.zje),yj=SUM(c.yj),cb=SUM(c.cb),tc=SUM(c.tc),md=SUM(c.md),yf=SUM(c.yf),sf=SUM(c.sf),ck=SUM(c.ck),tkf=SUM(c.tkf),thyf=SUM(c.thyf),ggf=SUM(c.ggf),ssf=SUM(c.ssf),ml=SUM(c.ml),mltc=SUM(case when c.mltc<0 then 0 else c.mltc end)-" + jcje + @",jcje=" + jcje + @",mll=SUM(c.ml)/SUM(c.zje) from HW_GoodsInfo a with(nolock)
inner join JC_UserInfo b with(nolock) on a.KFName=b.Name and b.State=1
left join #DT_Fee_LS2 c on a.GoodsId=c.GoodsId
" + tj2 + @"
group by b.UserId,b.Name
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 52);
}
#endregion
#region 报表402
[WebMethod(EnableSession = true)]
public string GetReportTable4021(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
EDate = EDate.Value.AddDays(1);
if (SDate != null)
{
tj += " and OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " b.LastOrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " and b.LastOrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " and a.UserId=" + UserId + " ";
}
string tj3 = "";
string tj4 = "";
if (SDate != null)
{
tj3 += " OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " addate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj3 += " and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + "' ";
tj4 += " and addate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
decimal hj = DataNew.GetListTotalPrice2(SDate.Value, EDate.Value);
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days;
decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
decimal fje = 0;
if (hj > 0)
fje = thj * 1.00M / hj;
if (GoodsCode != "")
tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
select * into #DT_OrderInfoUser from DT_OrderInfo with(nolock) where CompanyId=1 and State>0 and State<3 " + tj + @" and dbo.[GetOrderPostFee](OrderId)>0
select a.UserId,Num=COUNT(distinct b.GoodsId) into #DT_OrderInfoUser3 from JC_UserInfo a with(nolock)
inner join HW_GoodsInfo b with(nolock) on a.name=b.kfname and a.State=1
inner join HW_GoodsDetail e with(nolock) on b.GoodsId=e.GoodsId
inner join DT_OrderGoods c with(nolock) on e.DetailId=c.DetailId
inner join #DT_OrderInfoUser d with(nolock) on c.OrderId=d.OrderId
where d.CompanyId=1 " + tj2 + @" group by a.UserId
select DR_BackFee,orderid into #BackFee_ls from DT_OrderInfo where OrderDate>='2020-08-01' and OrderDate<'2020-10-01'
select DR_PostFee,orderid into #PostFee_ls from DT_OrderInfo where OrderDate>='2020-08-01' and OrderDate<'2020-10-01'
select DR_SSFee,orderid into #SSFee_ls from DT_OrderInfo where OrderDate>='2020-08-01' and OrderDate<'2020-10-01'
select goodsid,addfee=SUM(dec3) into #ADFee_ls from DT_AdFee where addate>='2020-11-01' group by goodsid
select a.OrderId,a.TotalPrice,goodsprice=a.TotalPrice*b.goodsnum/a.goodsnum,a.MoneyCode,a.ShopId,a.PlatId,a.PlatOrderCode,a.InDate,b.DetailId,b.GoodsNum,b.id,DR_BackFee=isnull(c.DR_BackFee,0),DR_PostFee=isnull(d.DR_PostFee,0),DR_SSFee=isnull(e.DR_SSFee,0) into #DT_OrderInfo_Ls from DT_OrderInfo a with(nolock)
inner join DT_OrderGoods b with(nolock) on a.OrderId=b.OrderId
left join #BackFee_ls c on a.orderid=c.orderid
left join #BackFee_ls d on a.orderid=d.orderid
left join #SSFee_ls e on a.orderid=e.orderid
where a.CompanyId=1 and a.State>0 and a.State<3 " + tj + @" and dbo.[GetOrderPostFee](a.OrderId)>0
select f.UserId,zje=sum(a.goodsprice),cb=sum(a.GoodsNum*d.InPrice)/6.6,tc=sum(170*isnull(d.Solid,0)),md=count(distinct a.PlatOrderCode)*0.6,yf=SUM(dbo.[GetOrderPostFee](a.OrderId)),sf=sum(a.GoodsNum*d.InPrice*isnull(d.FeeRate,0)*0.01)/6.6,tkf=sum(a.DR_BackFee),thyf=sum(a.DR_BackFee) into #DT_OrderInfo_Ls3 from #DT_OrderInfo_Ls a
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 JC_UserInfo f with(nolock) on d.KFName=f.Name and f.State=1
--left join HW_GoodsInDetail e with(nolock) on a.Id=e.OrderGoodsId
where dbo.[GetOrderPostFee](a.OrderId)>0
group by f.UserId
select b.UserId,b.Num,Price=dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId),yjPrice=dbo.getYJRate2(a.PlatId,dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId)) into #DT_OrderInfoUser2 from #DT_OrderInfoUser a inner join (
select a.UserId,d.OrderId,Num=SUM(c.GoodsNum) from JC_UserInfo a with(nolock)
inner join HW_GoodsInfo b with(nolock) on a.Name=b.KFName and a.State=1
inner join HW_GoodsDetail e with(nolock) on b.GoodsId=e.GoodsId
inner join DT_OrderGoods c with(nolock) on e.DetailId=c.DetailId
inner join #DT_OrderInfoUser d on c.OrderId=d.OrderId
where d.CompanyId=1 " + tj2 + @"
group by a.UserId,d.OrderId)b on a.OrderId=b.OrderId
select a.UserId,zje=b.Price,je=b.Price-b.yjPrice,a.cb,a.tc,a.yf,a.md,ckf=b.Price*" + fje + @",sf,ml=b.Price-b.yjPrice-cb-sf-md-tc-yf-zje*" + fje + @",mll=case when b.Price>0 then (b.Price-b.yjPrice-cb-sf-tc-md-yf-b.Price*" + fje + @")*100/b.Price else 0 end into #DT_OrderInfo_Ls2 from #DT_OrderInfo_Ls3 a
inner join (
select UserId,OrderNum=COUNT(0),Price=SUM(Price),yjPrice=SUM(yjPrice) from #DT_OrderInfoUser2
group by UserId)b on a.userid=b.UserId
select c.Name,c.UserName,a.*,GoodsNum=d.Num,OutGoods=isnull(e.Num,0),Rate=case when d.Num>0 then isnull(e.Num,0)*1.0/d.Num else 0 end,NoGoods=d.Num-isnull(e.Num,0),f.* from (
select UserId,Num=sum(Num),OrderNum=COUNT(0),Price=SUM(Price) from #DT_OrderInfoUser2
group by UserId)a
inner join JC_UserInfo c on a.UserId=c.UserId
inner join (select kfname,Num=COUNT(distinct GoodsId) from HW_GoodsInfo with(nolock) where kfname is not null
group by kfname)d on c.name=d.KFName
left join #DT_OrderInfoUser3 e on c.UserId=e.UserId
left join #DT_OrderInfo_Ls2 f on c.userid=f.userid
drop table #DT_OrderInfoUser, #DT_OrderInfoUser2, #DT_OrderInfoUser3,#DT_OrderInfo_Ls,#DT_OrderInfo_Ls2
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 52);
}
#endregion
#region 报表182
[WebMethod(EnableSession = true)]
public string GetReportTable182(DateTime? InDate, DateTime? EDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
string dd = "";
try
{
var obj = new BaseService();
EDate = EDate.Value.AddDays(1);
string tj = "";
string tj1 = "";
if (DeptId > 0)
{
tj += " and b.DeptId=" + DeptId + " ";
tj1 += " and a.DeptId=" + DeptId + " ";
}
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
if (MoneyCode != "0")
tj += " and a.MoneyCode='" + MoneyCode + "' ";
decimal hj = DataNew.GetListTotalPrice2(InDate.Value, EDate.Value);
TimeSpan ts = EDate.Value - InDate.Value;
int days = ts.Days;
decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
decimal fje = 0;
if (hj > 0)
fje = thj * 1.00M / hj;
string sql = @"
select a.ShopId,a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,InPrice=d.InPrice,InPrice=d.InPrice,BZ=case when d.InPrice>0 then RMBMoney/d.InPrice else 0 end,LR=0,MLL='',ShopCDGoods=0,ShopTJGoods=0,ckfee=0.00,mdfee=isnull(c.OrderNum,0)*0.6,ftckfee=isnull(c.USDMoney,0)*" + fje + @",LR2=0,MLL2='',b.Rate3 from JC_Shop a
inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a with(nolock)
inner join JC_Shop b with(nolock) on a.ShopId=b.ShopId
where a.State>0 " + tj + " and a.State<3 and a.OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by b.ShopId)c on a.ShopId=c.ShopId
left join (select ShopId,Rate3=sum(isnull(Rate3,0)) from JC_ShopData with(nolock) where InDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and InDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"'
group by ShopId) b on a.ShopId=b.ShopId
inner join (select a.ShopId,InPrice=sum(isnull(d.InPrice,0)*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.State>0 and a.State<3 and a.OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by a.ShopId)d on a.ShopId=d.ShopId
where a.CompanyId=1 " + tj1 + " order by " + Sort;
DataTable dt = obj.GetReportData(sql);
string sql2 = @"
select a.*,Num2=isnull(b.Num2,0) from (
select b.ShopId,Num=COUNT(0) from HW_GoodsInfo a with(nolock)
inner join HW_Shop b with(nolock) on a.GoodsId=b.GoodsId
group by b.ShopId)a
left join (
select a.ShopId,Num2=COUNT(distinct c.GoodsId) 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 a.OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by a.ShopId)b on a.ShopId=b.ShopId";
DataTable dt2 = obj.GetReportData(sql2);
var dlist = DataNew.GetListGoodsDays(InDate.Value);
DD_OrderData data = new DD_OrderData();
if (dt != null)
{
decimal f1 = 0;
decimal f2 = 0;
decimal f3 = 0;
decimal f4 = 0;
decimal f5 = 0;
decimal f6 = 0;
// int ds = 0;
// decimal f9 = 0;
decimal cyxs = 0;
decimal cyyj = 0;
decimal hwcb = 0;
decimal hwtc = 0;
decimal hwyf = 0;
decimal hwyf1 = 0;
decimal hwyf2 = 0;
int yf1 = 0;
int yf2 = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
decimal ckfee = 0;//存储费
decimal mdfee = 0;//面单费
decimal adfee = 0;//广告费
decimal MRate = Convert.ToDecimal((double)6.5);
List<JC_Money> list7 = new BaseService().GetMoneyList2();
var olist = DataNew.GetListShopList2(Convert.ToInt32(dt.Rows[i]["ShopId"]), InDate);
string ids = "";
if (olist != null)
{
foreach (var order in olist)
{
ids += order.OrderId.ToString() + ",";
}
}
if (ids != "")
{
// List<DT_OrderGoods> orderGoodsListPP = DataNew.GetOrderGoodsListPP(ids.Trim(','));
List<DT_OrderGoods> orderGoodsList = DataNew.GetOrderGoodsList(ids.Trim(','));
if (orderGoodsList != null)
{
//ds += orderGoodsList.Count;
//foreach (var md in orderGoodsList)
//{
// f9 += md.GoodsPrice.Value * md.GoodsNum.Value;
//}
foreach (var md in olist)
{
List<DT_OrderGoods> gmd = null;
if (gmd == null)
gmd = orderGoodsList.FindAll(n => n.OrderId == md.OrderId);
md.GoodsList = gmd;
}
}
}
decimal lr = 0;
decimal lr2 = 0;
string AddrType = "";
decimal tweight = 0;
if (olist != null)
{
foreach (var md in olist)
{
//if (md.PlatOrderCode == "2793358899439")
//{
// string cc = "";
//}
JC_Money money = list7.Find(n => n.MCode == "USD" && n.PlatId == md.PlatId);
if (money != null)
{
MRate = money.MRate.Value;
}
else
{
money = list7.Find(n => n.MCode == "USD");
MRate = money.MRate.Value;
}
decimal TotalPrice = md.TotalPrice.Value;
decimal yj = 0M;
yj = TotalPrice * Convert.ToDecimal((double)0.15);
int PlatType = md.PlatId.Value;
if (PlatType == 1)
{
yj = TotalPrice * Convert.ToDecimal((double)0.05);
}
else if (PlatType == 4)
{
yj = 0;
}
else if (PlatType == 5)
{
yj = TotalPrice * Convert.ToDecimal((double)0.1);
}
else if (PlatType == 15)
{
yj = TotalPrice * Convert.ToDecimal((double)0.029) + 0.3M;
}
f1 += TotalPrice;
f2 += yj;
decimal GoodsPrice = 0M;
decimal TCFee = 0M;
decimal TCFee2 = 0M;
decimal SolidFee = 0M;
decimal GoodsPrice2 = 0M;
decimal ckfee2 = 0M;
tweight = 0;
if (md.GoodsList != null)
{
if (md.GoodsList.Count > 0)
{
AddrType = md.GoodsList[0].JoinOrderCode;
}
if (md.GoodsList != null)
{
foreach (DT_OrderGoods goods in md.GoodsList)
{
if (dlist != null)
{
var dmd = dlist.Find(n => n.OrderId == md.OrderId && n.DetailId == goods.DetailId);
if (dmd != null && dmd.days > 0)
{
ckfee2 += dmd.days.Value * 1.00M * goods.Solid2.Value * goods.GoodsNum.Value * 0.3M;
ckfee += dmd.days.Value * 1.00M * goods.Solid2.Value * goods.GoodsNum.Value * 0.3M;
}
}
//if (goods.GoodsFee.HasValue && (goods.GoodsFee.Value > 0M))
//{
// GoodsPrice += goods.GoodsFee.Value;
//}
//else
if (goods.Weight != null)
{
tweight += goods.Weight.Value * goods.GoodsNum.Value;
}
if (goods.GoodsPrice.HasValue)
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
//f9 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
}
// ds++;
if (goods.TCFee != null && goods.TCFee > 0 && goods.GoodsPrice != null)//税费
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value * goods.TCFee.Value * Convert.ToDecimal(0.01);
}
//if (goods.Solid != null && goods.Solid > 0)//匹配的头程费
//{
// TCFee2 += goods.Solid.Value * goods.GoodsNum.Value;
//}
//else
if (goods.Solid2.HasValue)
{
SolidFee += goods.Solid2.Value * goods.GoodsNum.Value;
}
}
}
}
if (GoodsPrice2 > 0M)
{
GoodsPrice = GoodsPrice2 / MRate;
}
f4 += GoodsPrice;
decimal escrowFee = 0M;
if ((TCFee == 0M) && (SolidFee > 0M))
{
TCFee = Convert.ToDecimal(170) * SolidFee;
}
// TCFee += TCFee2;
f5 += TCFee;// +TCFee2;
if (md.escrowFee.HasValue)
{
escrowFee = md.escrowFee.Value;
}
decimal num10 = 0M;
if (md.PostFee.HasValue)
{
num10 = md.PostFee.Value;
}
// decimal num11 = 0M;
// decimal num12 = 0M;
// decimal num13 = 0M;
//if (md.Post == 222 || md.Post == 226 || md.Post == 227)
//{
// num13 = num10 * Convert.ToDecimal((double)0.1);
//}
decimal feestore11 = 0M;//e仓运费
decimal feestore6 = 0M;//w仓运费
decimal feestore = 0M;
if (md.Fee11 != null && md.Fee11 > 0)
{
feestore11 = md.Fee11.Value;
}
if (feestore11 == 0 && md.Fee12 != null && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < feestore11)
{
feestore11 = md.Fee12.Value;
}
if (feestore11 == 0 && md.Fee13 != null && md.Fee13 > 0)
feestore11 = md.Fee13.Value;
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < feestore11)
{
feestore11 = md.Fee13.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee11 != null && md.Fee13 != null && md.Fee11 > 0 && md.Fee11 < md.Fee13)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee13 != null && md.Fee13 > 0 && md.Fee11 > md.Fee13)
{
feestore11 = md.Fee13.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee11 != null && md.Fee12 != null && md.Fee11 > 0 && md.Fee11 < md.Fee12)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee12 != null && md.Fee12 > 0 && md.Fee11 > md.Fee12)
{
feestore11 = md.Fee12.Value;
}
}
if (md.Fee12 != null && tweight >= 1120 && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (feestore11 > 0)
{
hwyf1 += feestore11;
yf1++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
if (md.Fee6 != null && md.Fee6 > 0)
{
feestore6 = md.Fee6.Value;
}
if (feestore6 == 0 && md.Fee7 != null && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < feestore6)
{
feestore6 = md.Fee7.Value;
}
if (feestore6 == 0 && md.Fee8 != null && md.Fee8 > 0)
feestore6 = md.Fee8.Value;
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < feestore6)
{
feestore6 = md.Fee8.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee6 != null && md.Fee8 != null && md.Fee6 > 0 && md.Fee6 < md.Fee8)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee8 != null && md.Fee8 > 0 && md.Fee6 > md.Fee8)
{
feestore6 = md.Fee8.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee6 != null && md.Fee7 != null && md.Fee6 > 0 && md.Fee6 < md.Fee7)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee7 != null && md.Fee7 > 0 && md.Fee6 > md.Fee7)
{
feestore6 = md.Fee7.Value;
}
}
if (md.Fee7 != null && tweight >= 1120 && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (feestore6 > 0)
{
hwyf2 += feestore6;
yf2++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
feestore = feestore11;
if (feestore11 == 0)
feestore = feestore6;
if (feestore6 > 0 && feestore6 < feestore11)
feestore = feestore6;
f6 += feestore;
md.PostFee = new decimal?(num10);
md.BoxFee = new decimal?(feestore);//运费
//decimal num15 = 0M;
decimal num16 = 0M;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, TCFee);
num16 = TotalPrice - yj - GoodsPrice - escrowFee - feestore - TCFee - ckfee2 - 0.6M;
// ErrorFollow.TraceWrite("Fee18", md.PlatOrderCode, "TotalPrice:" + TotalPrice + "|yj:" + yj + "|GoodsPrice:" + GoodsPrice + "|feestore:" + feestore + "|escrowFee:" + escrowFee + "|TCFee:" + TCFee + "|lr:" + num16);
decimal lrje2 = TotalPrice - yj - GoodsPrice - escrowFee - feestore - TCFee - TotalPrice * fje - 0.6M;
if (feestore > 0 && GoodsPrice > 0)
{
//cyxs += TotalPrice;
//cyyj += yj;
//hwcb += GoodsPrice;
//hwtc += TCFee;
//hwyf += num14;
lr += num16;
lr2 += lrje2;
}
}
}
dt.Rows[i]["ckfee"] = Convert.ToDecimal(ckfee.ToString("0.00"));
decimal ptckfee2 = 0;
if (dt.Rows[i]["ftckfee"].ToString() != "")
ptckfee2 = Convert.ToDecimal(dt.Rows[i]["ftckfee"].ToString());
dt.Rows[i]["ftckfee"] = Convert.ToDecimal(ptckfee2.ToString("0.00"));
decimal ggfee = 0;
if (dt.Rows[i]["Rate3"].ToString() != "")
ggfee = Convert.ToDecimal(dt.Rows[i]["Rate3"].ToString());
lr = lr - ggfee;
lr2 = lr2 - ggfee;
dt.Rows[i]["LR"] = lr;
dt.Rows[i]["LR2"] = lr2;
if (dt.Rows[i]["USDMoney"].ToString() != "" && Convert.ToDecimal(dt.Rows[i]["USDMoney"]) > 0)
dt.Rows[i]["MLL"] = (lr * 100 / Convert.ToDecimal(dt.Rows[i]["USDMoney"])).ToString("0.00") + "%";
if (dt.Rows[i]["USDMoney"].ToString() != "" && Convert.ToDecimal(dt.Rows[i]["USDMoney"]) > 0)
dt.Rows[i]["MLL2"] = (lr2 * 100 / Convert.ToDecimal(dt.Rows[i]["USDMoney"])).ToString("0.00") + "%";
if (dt2 != null)
{
var row = dt2.Select("shopId=" + Convert.ToInt32(dt.Rows[i]["ShopId"]));
if (row != null && row.Length > 0)
{
dt.Rows[i]["ShopCDGoods"] = Convert.ToInt32(row[0]["Num2"]);
dt.Rows[i]["ShopTJGoods"] = Convert.ToInt32(row[0]["Num"]);
}
}
}
//decimal f0 = f1 - f2 - f4 - f5 - f6;
//decimal zlr = cyxs - cyyj - hwcb - hwtc - hwyf - hwyf1 - hwyf2-yf1-yf2;
}
return GetReport3(dt, 46);
}
catch (Exception ex)
{
string a = dd;
return "";
}
}
#endregion
#region 报表183
[WebMethod(EnableSession = true)]
public string GetReportTable183(DateTime? InDate, DateTime? EDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
string dd = "";
//try
// {
var obj = new BaseService();
EDate = EDate.Value.AddDays(1);
string tj = "";
string tj1 = "";
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
// if (MoneyCode != "0")
// tj += " and a.MoneyCode='" + MoneyCode + "' ";
// decimal hj = DataNew.GetListTotalPrice2(InDate.Value, EDate.Value);
// TimeSpan ts = EDate.Value - InDate.Value;
// int days = ts.Days;
//decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
//decimal fje = 0;
//if (hj > 0)
// fje = thj * 1.00M / hj;
// string sql = @"
//select a.ShopId,a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,InPrice=d.InPrice,InPrice=d.InPrice,BZ=case when d.InPrice>0 then RMBMoney/d.InPrice else 0 end,LR=0,MLL='',ShopCDGoods=0,ShopTJGoods=0,ckfee=0.00,mdfee=0,LR2=0,MLL2='',b.Rate3 from JC_Shop a
//inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a with(nolock)
//inner join JC_Shop b with(nolock) on a.ShopId=b.ShopId
//where a.State>0 " + tj + " and a.State<3 and a.OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by b.ShopId)c on a.ShopId=c.ShopId
//left join (select ShopId,Rate3=sum(isnull(Rate3,0)) from JC_ShopData with(nolock) where InDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and InDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"'
//group by ShopId) b on a.ShopId=b.ShopId
//inner join (select a.ShopId,InPrice=sum(isnull(d.InPrice,0)*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.State>0 and a.State<3 and a.OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by a.ShopId)d on a.ShopId=d.ShopId
//where a.CompanyId=1 " + tj1 + " order by " + Sort;
string sql = @"
select c.*,b.shopname from (
select ShopId,TotalPrice=sum(dbo.MoneyChange(TotalPrice,MoneyCode,1)),escrowFee=0.00,fee7=0.00,ordernum=COUNT(0),TotalPrice2=0.00,cb=0.00,ml=0.00,mlr='' from DT_OrderInfo a with(nolock)
where state>0 and state<3 and OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by ShopId)c
inner join jc_shop b on c.shopid=b.shopid
where b.CompanyId=1 " + tj + @"
order by " + Sort;
DataTable dt = obj.GetReportData(sql);
string sql2 = @"
select ShopId,TotalPrice=sum(isnull(dbo.MoneyChange(TotalPrice,MoneyCode,1),0)),escrowFee=sum(isnull(dbo.MoneyChange(escrowFee,MoneyCode,1),0)),fee7=sum(isnull(dbo.MoneyChange(fee7,MoneyCode,1),0)),ordernum=COUNT(0) from DT_OrderInfo a with(nolock)
where fee7>0 and state>0 and state<3 and OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' group by ShopId";
DataTable dt2 = obj.GetReportData(sql2);
string sql3 = @"
select a.ShopId,InPrice=sum(isnull(d.InPrice,0)*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.fee7>0 and a.state>0 and a.OrderDate>='" + InDate.Value.ToString("yyyy-MM-dd") + "' and a.OrderDate<'" + EDate.Value.ToString("yyyy-MM-dd") + @"' and a.state<3 group by a.ShopId";
DataTable dt3 = obj.GetReportData(sql3);
DD_OrderData data = new DD_OrderData();
if (dt != null)
{
decimal zje = 0;
decimal zje2 = 0;
decimal zcb = 0;
decimal zyf = 0;
decimal zyj = 0;
decimal zlr = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
int shopid = Convert.ToInt32(dt.Rows[i]["ShopId"]);
DataRow[] rows2 = dt2.Select("ShopId=" + shopid);
DataRow[] rows3 = dt3.Select("ShopId=" + shopid);
if (rows2 != null && rows2.Length > 0)
{
if (rows2[0]["TotalPrice"] != null)
dt.Rows[i]["TotalPrice2"] = Convert.ToDecimal(rows2[0]["TotalPrice"]);
if (rows2[0]["escrowFee"] != null)
dt.Rows[i]["escrowFee"] = Convert.ToDecimal(rows2[0]["escrowFee"]);
if (rows2[0]["fee7"].ToString() != "")
dt.Rows[i]["fee7"] = Convert.ToDecimal(rows2[0]["fee7"]);
if (rows2[0]["TotalPrice"] != null)
zje2 += Convert.ToDecimal(rows2[0]["TotalPrice"]);
if (rows2[0]["fee7"] != null)
zyf += Convert.ToDecimal(rows2[0]["fee7"]);
if (rows2[0]["escrowFee"] != null)
zyj += Convert.ToDecimal(rows2[0]["escrowFee"]);
}
if (rows3 != null && rows3.Length > 0)
{
if (rows3[0]["InPrice"] != null)
{
dt.Rows[i]["cb"] = Convert.ToDecimal(rows3[0]["InPrice"]);
zcb += Convert.ToDecimal(rows3[0]["InPrice"]);
}
}
if (dt.Rows[i]["TotalPrice"] != null)
zje += Convert.ToDecimal(dt.Rows[i]["TotalPrice"]);
decimal ml = 0;
if (dt.Rows[i]["TotalPrice2"].ToString() != "" && dt.Rows[i]["escrowFee"].ToString() != "" && dt.Rows[i]["fee7"].ToString() != "" && dt.Rows[i]["cb"].ToString() != "")
ml = Convert.ToDecimal(dt.Rows[i]["TotalPrice2"]) - Convert.ToDecimal(dt.Rows[i]["escrowFee"]) - Convert.ToDecimal(dt.Rows[i]["fee7"]) - Convert.ToDecimal(dt.Rows[i]["cb"]);
zlr += ml;
dt.Rows[i]["ml"] = ml;
string mlr = "";
if (dt.Rows[i]["TotalPrice2"] != null && Convert.ToDecimal(dt.Rows[i]["TotalPrice2"]) > 0)
mlr = (ml * 100 / Convert.ToDecimal(dt.Rows[i]["TotalPrice2"])).ToString("0.00");
dt.Rows[i]["mlr"] = mlr;
}
var row = dt.NewRow();
row["shopname"] = "合计:";
row["TotalPrice"] = zje;
row["TotalPrice2"] = zje2;
row["cb"] = zcb;
row["escrowFee"] = zyj;
row["fee7"] = zyf;
row["ml"] = zlr;
row["mlr"] = "";
if (zje2 > 0)
row["mlr"] = (zlr * 100 / zje2).ToString("0.00");
dt.Rows.Add(row);
}
return GetReport3(dt, 45);
//}
//catch (Exception ex)
//{
// string a = dd;
// return "";
//}
}
#endregion
#region 报表180
[WebMethod(EnableSession = true)]
public string GetReportTable180(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
string dd = "";
try
{
var obj = new BaseService();
string tj = "";
string tj1 = "";
if (DeptId > 0)
{
tj += " and b.DeptId=" + DeptId + " ";
tj1 += " and a.DeptId=" + DeptId + " ";
}
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
if (MoneyCode != "0")
tj += " and a.MoneyCode='" + MoneyCode + "' ";
string sql = @"
select a.ShopId,a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.USDUseMoney,b.USDUseMoney,b.USDNoMoney,b.RMBUseMoney,b.RMBNoMoney,b.InforViolate,b.PropertyViolate,b.OtherViolate,b.Rate1,b.Rate2,b.Rate3,b.Rate4,b.Rate5,b.Rate6,FeeDate=isnull(b.FeeDate,a.FeeDate),TXFee=isnull(b.TXFee,a.TXFee),InPrice=d.InPrice,InPrice=d.InPrice,BZ=case when d.InPrice>0 then RMBMoney/d.InPrice else 0 end,LR=0,MLL='' from JC_Shop a
inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a
inner join JC_Shop b on a.ShopId=b.ShopId
where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId
left join JC_ShopData b on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0
inner join (select a.ShopId,InPrice=sum(isnull(d.InPrice,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.State>0 and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)d on a.ShopId=d.ShopId
where a.CompanyId=1 " + tj1 + " order by " + Sort;
DataTable dt = obj.GetReportData(sql);
DD_OrderData data = new DD_OrderData();
if (dt != null)
{
decimal f1 = 0;
decimal f2 = 0;
decimal f3 = 0;
decimal f4 = 0;
decimal f5 = 0;
decimal f6 = 0;
// int ds = 0;
// decimal f9 = 0;
decimal cyxs = 0;
decimal cyyj = 0;
decimal hwcb = 0;
decimal hwtc = 0;
decimal hwyf = 0;
decimal hwyf1 = 0;
decimal hwyf2 = 0;
int yf1 = 0;
int yf2 = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
decimal MRate = Convert.ToDecimal((double)6.5);
List<JC_Money> list7 = new BaseService().GetMoneyList2();
var olist = DataNew.GetListShopList2(Convert.ToInt32(dt.Rows[i]["ShopId"]), InDate);
string ids = "";
if (olist != null)
{
foreach (var order in olist)
{
ids += order.OrderId.ToString() + ",";
}
}
if (ids != "")
{
// List<DT_OrderGoods> orderGoodsListPP = DataNew.GetOrderGoodsListPP(ids.Trim(','));
List<DT_OrderGoods> orderGoodsList = DataNew.GetOrderGoodsList(ids.Trim(','));
if (orderGoodsList != null)
{
//ds += orderGoodsList.Count;
//foreach (var md in orderGoodsList)
//{
// f9 += md.GoodsPrice.Value * md.GoodsNum.Value;
//}
foreach (var md in olist)
{
List<DT_OrderGoods> gmd = null;
if (gmd == null)
gmd = orderGoodsList.FindAll(n => n.OrderId == md.OrderId);
md.GoodsList = gmd;
}
}
}
decimal lr = 0;
string AddrType = "";
decimal tweight = 0;
if (olist != null)
{
foreach (var md in olist)
{
dd = md.PlatOrderCode;
//if (md.PlatOrderCode == "2793358899439")
//{
// string cc = "";
//}
JC_Money money = list7.Find(n => n.MCode == "USD" && n.PlatId == md.PlatId);
if (money != null)
{
MRate = money.MRate.Value;
}
else
{
money = list7.Find(n => n.MCode == "USD");
MRate = money.MRate.Value;
}
decimal TotalPrice = md.TotalPrice.Value;
decimal yj = 0M;
yj = TotalPrice * Convert.ToDecimal((double)0.15);
int PlatType = md.PlatId.Value;
if (PlatType == 1)
{
yj = TotalPrice * Convert.ToDecimal((double)0.05);
}
else if (PlatType == 4)
{
yj = 0;
}
else if (PlatType == 5)
{
yj = TotalPrice * Convert.ToDecimal((double)0.1);
}
else if (PlatType == 15)
{
yj = TotalPrice * Convert.ToDecimal((double)0.029) + 0.3M;
}
f1 += TotalPrice;
f2 += yj;
decimal GoodsPrice = 0M;
decimal TCFee = 0M;
decimal TCFee2 = 0M;
decimal SolidFee = 0M;
decimal GoodsPrice2 = 0M;
tweight = 0;
if (md.GoodsList != null)
{
if (md.GoodsList.Count > 0)
{
AddrType = md.GoodsList[0].JoinOrderCode;
}
if (md.GoodsList != null)
{
foreach (DT_OrderGoods goods in md.GoodsList)
{
//if (goods.GoodsFee.HasValue && (goods.GoodsFee.Value > 0M))
//{
// GoodsPrice += goods.GoodsFee.Value;
//}
//else
if (goods.Weight != null)
{
tweight += goods.Weight.Value * goods.GoodsNum.Value;
}
if (goods.GoodsPrice.HasValue)
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
//f9 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
}
// ds++;
if (goods.TCFee != null && goods.TCFee > 0 && goods.GoodsPrice != null)//税费
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value * goods.TCFee.Value * Convert.ToDecimal(0.01);
}
//if (goods.Solid != null && goods.Solid > 0)//匹配的头程费
//{
// TCFee2 += goods.Solid.Value * goods.GoodsNum.Value;
//}
//else
if (goods.Solid2.HasValue)
{
SolidFee += goods.Solid2.Value * goods.GoodsNum.Value;
}
}
}
}
if (GoodsPrice2 > 0M)
{
GoodsPrice = GoodsPrice2 / MRate;
}
f4 += GoodsPrice;
decimal escrowFee = 0M;
if ((TCFee == 0M) && (SolidFee > 0M))
{
TCFee = Convert.ToDecimal(170) * SolidFee;
}
// TCFee += TCFee2;
f5 += TCFee;// +TCFee2;
if (md.escrowFee.HasValue)
{
escrowFee = md.escrowFee.Value;
}
decimal num10 = 0M;
if (md.PostFee.HasValue)
{
num10 = md.PostFee.Value;
}
decimal num11 = 0M;
decimal num12 = 0M;
decimal num13 = 0M;
//if (md.Post == 222 || md.Post == 226 || md.Post == 227)
//{
// num13 = num10 * Convert.ToDecimal((double)0.1);
//}
decimal feestore11 = 0M;//e仓运费
decimal feestore6 = 0M;//w仓运费
decimal feestore = 0M;
if (md.Fee11 != null && md.Fee11 > 0)
{
feestore11 = md.Fee11.Value;
}
if (feestore11 == 0 && md.Fee12 != null && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < feestore11)
{
feestore11 = md.Fee12.Value;
}
if (feestore11 == 0 && md.Fee13 != null && md.Fee13 > 0)
feestore11 = md.Fee13.Value;
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < feestore11)
{
feestore11 = md.Fee13.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee11 != null && md.Fee13 != null && md.Fee11 > 0 && md.Fee11 < md.Fee13)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee13 != null && md.Fee13 > 0 && md.Fee11 > md.Fee13)
{
feestore11 = md.Fee13.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee11 != null && md.Fee12 != null && md.Fee11 > 0 && md.Fee11 < md.Fee12)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee12 != null && md.Fee12 > 0 && md.Fee11 > md.Fee12)
{
feestore11 = md.Fee12.Value;
}
}
if (md.Fee12 != null && tweight >= 1120 && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (feestore11 > 0)
{
hwyf1 += feestore11;
yf1++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
if (md.Fee6 != null && md.Fee6 > 0)
{
feestore6 = md.Fee6.Value;
}
if (feestore6 == 0 && md.Fee7 != null && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < feestore6)
{
feestore6 = md.Fee7.Value;
}
if (feestore6 == 0 && md.Fee8 != null && md.Fee8 > 0)
feestore6 = md.Fee8.Value;
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < feestore6)
{
feestore6 = md.Fee8.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee6 != null && md.Fee8 != null && md.Fee6 > 0 && md.Fee6 < md.Fee8)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee8 != null && md.Fee8 > 0 && md.Fee6 > md.Fee8)
{
feestore6 = md.Fee8.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee6 != null && md.Fee7 != null && md.Fee6 > 0 && md.Fee6 < md.Fee7)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee7 != null && md.Fee7 > 0 && md.Fee6 > md.Fee7)
{
feestore6 = md.Fee7.Value;
}
}
if (md.Fee7 != null && tweight >= 1120 && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (feestore6 > 0)
{
hwyf2 += feestore6;
yf2++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
feestore = feestore11;
if (feestore11 == 0)
feestore = feestore6;
if (feestore6 > 0 && feestore6 < feestore11)
feestore = feestore6;
f6 += feestore;
md.PostFee = new decimal?(num10);
md.BoxFee = new decimal?(feestore);//运费
//decimal num15 = 0M;
decimal num16 = 0M;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, TCFee);
num16 = ((((((TotalPrice - yj) - GoodsPrice) - escrowFee) - feestore) - TCFee) - num11) - num12;
if (feestore > 0 && GoodsPrice > 0)
{
//cyxs += TotalPrice;
//cyyj += yj;
//hwcb += GoodsPrice;
//hwtc += TCFee;
//hwyf += num14;
lr += num16;
}
}
}
dt.Rows[i]["LR"] = lr;
if (dt.Rows[i]["USDMoney"].ToString() != "" && Convert.ToDecimal(dt.Rows[i]["USDMoney"]) > 0)
dt.Rows[i]["MLL"] = (lr * 100 / Convert.ToDecimal(dt.Rows[i]["USDMoney"])).ToString("0.00") + "%";
}
//decimal f0 = f1 - f2 - f4 - f5 - f6;
//decimal zlr = cyxs - cyyj - hwcb - hwtc - hwyf - hwyf1 - hwyf2-yf1-yf2;
}
return GetReport3(dt, 18);
}
catch (Exception ex)
{
string a = dd;
ErrorFollow.TraceWrite("GetReportTable18", ex.Message, dd);
return "";
}
}
#endregion
#region 报表18
[WebMethod(EnableSession = true)]
public string GetReportTable18(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort, bool isyc)
{
string dd = "";
try
{
var obj = new BaseService();
string tj = "";
string tj1 = "";
//if (DeptId > 0)
//{
// tj += " and b.DeptId=" + DeptId + " ";
// tj1 += " and a.DeptId=" + DeptId + " ";
//}
if (PlatId > 0)
{
tj += " and a.PlatId=" + PlatId + " ";
tj1 += " and a.PlatId=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and a.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
//if (MoneyCode != "0")
// tj += " and a.MoneyCode='" + MoneyCode + "' ";
// string sql = @"
//declare @moneyrate decimal(18,4)
//select @moneyrate=MRate from JC_Money where MCode='USD' and PlatId=2
//select a.ShopId,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.RMBPrice,c.yj,yf=c.yf,cb=c.cb,hwsf=c.hwsf,c.tc,c.ck,c.md,a.Ad_Fee,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee,a.Other_Fee,moneyrate=isnull(c.moneyrate,@moneyrate) into #ls from DT_OrderInfo a with(nolock)
//inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId
//left join DT_Fees c with(nolock) on a.OrderId=c.orderid
//where DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 " + tj + @" and a.State>0 and a.State<3
//select a.*,Num2=isnull(b.Num2,0) into #ls2 from (
//select b.ShopId,Num=COUNT(0) from HW_GoodsInfo a with(nolock)
//inner join HW_Shop b with(nolock) on a.GoodsId=b.GoodsId
//group by b.ShopId)a
//left join (
//select a.ShopId,Num2=COUNT(distinct c.GoodsId) 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 DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)b on a.ShopId=b.ShopId
//select d.ShopName,Master=case when d.Master=d.buyer then d.Master when d.buyer is not null and d.buyer<>'' then d.Master+'-'+d.buyer else d.Master end,a.OrderNum,a.RMBMoney,a.USDMoney,AvgPrice=case when a.OrderNum>0 then cast(a.USDMoney/a.OrderNum as decimal(18,2)) else 0 end,a.InPrice,LR=cast(b.ml as decimal(18,2)),MLL=case when b.TotalPrice>0 then cast(b.ml*100/b.TotalPrice as decimal(18,2)) else 0 end,ShopTJGoods=e.Num,ShopCDGoods=e.Num2,ckfee,a.mdfee,a.adfee,bz=case when a.InPrice>0 then CAST(a.RMBMoney/a.InPrice as decimal(18,2)) else 0 end,c.GoodRate,c.ODR,c.DSRService,c.DSRGoods,h.DSRPost,c.USDUseMoney,c.USDNoMoney,c.RMBUseMoney,c.RMBNoMoney,c.Rate1,c.Rate2,f.Rate3,c.Rate4,c.PropertyViolate,c.Rate5,g.Rate6,Rate7=isnull(c.Rate7,d.dayfee),JL=cast(b.ml as decimal(18,2))+isnull(ckfee,0)+isnull(mdfee,0)-isnull(c.Rate3,0)-isnull(c.Rate7,d.dayfee),FeeDate=isnull(c.FeeDate,d.FeeDate),TXFee=isnull(c.TXFee,d.TXFee) from
//JC_Shop d left join (
//select ShopId,OrderNum=COUNT(0),RMBMoney=SUM(RMBPrice),escrowFee=sum(escrowFee),USDMoney=SUM(TotalPrice),InPrice=SUM(cb),ckfee=SUM(ck),mdfee=SUM(md),adfee=SUM(Ad_Fee) from #ls
//group by ShopId)a on d.ShopId=a.ShopId
//left join (select ShopId,TotalPrice=sum(TotalPrice),ml=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)) from #ls where yf>0
//group by ShopId)b on a.ShopId=b.ShopId
//left join (
//select GoodRate,ODR,DSRService,DSRGoods,DSRPost,USDUseMoney,USDNoMoney,RMBUseMoney, RMBNoMoney,Rate1,Rate2,Rate3,Rate4,PropertyViolate,Rate5,Rate6,Rate7,FeeDate,TXFee
//TXFee,ShopId from JC_ShopData
//where DATEDIFF(day,indate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 )c on a.ShopId=c.ShopId
//left Join #ls2 e on a.ShopId=e.ShopId
// left join (select shopid,SUM(ABS(adfee)) Rate3 from AD_FeeList where DATEDIFF(day,addate,'" + InDate.Value.AddDays(-2).ToString("yyyy-MM-dd") + "')=0 group by shopid) f on d.ShopId=f.shopid "+
// " left join ( select shopid,SUM(ABS(adfee)) Rate6 from AD_FeeList where CONVERT(varchar(7), addate, 120)='"+ InDate.Value.ToString("yyyy-MM") + "' group by shopid) g on d.ShopId=g.shopid "+
// " left join(select b.name shopName,case when a.Spend=0 or a.ad_sale_amount=0 then 0 else cast((Spend/ad_sale_amount)*100 as decimal(12,2)) end DSRPost from ( select sid,SUM(ISNULL(ABS(spend),0)) Spend, SUM(ISNULL(ad_sales_amount,0)) ad_sale_amount from [192.168.1.187].[UpGoods].dbo.LxERP_ProductPerformance where summary_field='Asin' and RequestDate='" + InDate.Value.AddDays(-2).ToString("yyyy-MM-dd") + "' group by sid) a left join [192.168.1.187].[UpGoods].dbo.LxERP_Amazon_Shop b on a.sid=b.sid) h on d.ShopName=h.shopName "
// + " order by " + Sort;
string sql = @"
declare @moneyrate decimal(18,4)
select @moneyrate=MRate from JC_Money where MCode='USD' and PlatId=2
select a.ShopId,a.TotalPrice,escrowFee=isnull(a.escrowFee,0),a.RMBPrice,c.yj,yf=c.yf,cb=c.cb,hwsf=c.hwsf,c.tc,c.ck,c.md,a.Ad_Fee,a.DR_BackFee,a.DR_PostFee,a.DR_SSFee,a.Other_Fee,moneyrate=isnull(c.moneyrate,@moneyrate),ISnull( c.SubsidyFee,0) SubsidyFee into #ls from DT_OrderInfo a with(nolock)
inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId
left join DT_Fees c with(nolock) on a.OrderId=c.orderid
where DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 " + tj + @" and a.State>0 and a.State<3
select a.*,Num2=isnull(b.Num2,0) into #ls2 from (
select b.ShopId,Num=COUNT(0) from HW_GoodsInfo a with(nolock)
inner join HW_Shop b with(nolock) on a.GoodsId=b.GoodsId
group by b.ShopId)a
left join (
select a.ShopId,Num2=COUNT(distinct c.GoodsId) 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 DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)b on a.ShopId=b.ShopId
select * from (
select d.ShopName,Master=case when d.Master=d.buyer then d.Master when d.buyer is not null and d.buyer<>'' then d.Master+'-'+d.buyer else d.Master end,a.OrderNum,a.RMBMoney,a.USDMoney,AvgPrice=case when a.OrderNum>0 then cast(a.USDMoney/a.OrderNum as decimal(18,2)) else 0 end,a.InPrice,LR=cast(b.ml as decimal(18,2)),MLL=case when b.TotalPrice>0 then cast(b.ml*100/b.TotalPrice as decimal(18,2)) else 0 end,ShopTJGoods=e.Num,ShopCDGoods=e.Num2,ckfee,a.mdfee,a.adfee,bz=case when a.InPrice>0 then CAST(a.RMBMoney/a.InPrice as decimal(18,2)) else 0 end,a.yf,c.GoodRate,c.ODR,t3.CVR DSRService,t3.user_sessions DSRGoods,f.DSRPost,c.USDUseMoney, n1.originalTotalCurrencyAmount as USDNoMoney,c.RMBUseMoney,c.RMBNoMoney,t2.orderDefectRate Rate1,t2.validTrackingRate Rate2,Case when d.PlatType=2 then f.Rate3 else c.Rate3 end Rate3,t4.RefundRate as Rate4, ABS( ISNULL( t4.RefundAmount,0) ) as PropertyViolate,t2.cancelRate Rate5,Case when d.PlatType=2 then g.Rate6 else (select SUM(ISNULL(Rate3,0)) from JC_ShopData where ShopId=d.ShopId and DATEDIFF(MONTH,InDate,'2023-10-18')=0) end Rate6,Rate7=isnull(c.Rate7,d.dayfee),JL=cast(b.ml as decimal(18,2))+isnull(ckfee,0)-isnull(c.Rate3,0)-isnull(c.Rate7,d.dayfee),t1.financialEventGroupEndLocale as FeeDate,t1.originalTotalCurrencyAmount as TXFee from
JC_Shop d left join (
select ShopId,OrderNum=COUNT(0),RMBMoney=SUM(RMBPrice),escrowFee=sum(escrowFee),USDMoney=SUM(TotalPrice),InPrice=SUM(cb),ckfee=SUM(ck),mdfee=SUM(md),adfee=SUM(Ad_Fee),yf=SUM(yf) from #ls
group by ShopId)a on d.ShopId=a.ShopId
left join (select ShopId,TotalPrice=sum(TotalPrice),ml=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 #ls where yf>0
group by ShopId)b on a.ShopId=b.ShopId
left join (
select GoodRate,ODR,DSRService,DSRGoods,DSRPost,USDUseMoney,USDNoMoney,RMBUseMoney, RMBNoMoney,Rate1,Rate2,Rate3,Rate4,PropertyViolate,Rate5,Rate6,Rate7,FeeDate,TXFee
TXFee,ShopId from JC_ShopData
where DATEDIFF(day,indate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 )c on a.ShopId=c.ShopId
left Join #ls2 e on a.ShopId=e.ShopId
left join [192.168.1.187].[UpGoods].dbo.LxERP_Amazon_Shop o on d.ShopName=o.name
left join ( select sid, CONVERT(decimal(12,2), SUM(t.cost)) as Rate3,CONVERT(decimal(12,2), SUM(t.sales)) as ad_sales , case when CONVERT(decimal(12,2), SUM(t.sales))<=0 then '∞' else CONVERT(nvarchar(20), convert(decimal(12,2), (CONVERT(decimal(12,2), SUM(t.cost))/CONVERT(decimal(12,2), SUM(t.sales)))*100)) end DSRPost from( select sid, SUM( ISNULL(cost,0)) as cost,SUM(ISNULL(sales,0))sales from [192.168.1.187].[UpGoods].dbo.LxERP_SPAdGroupReports where CONVERT(date,report_date)='" + InDate.Value.AddDays(-2).Date.ToString("yyyy-MM-dd") + "' group by sid union all select sid, SUM( ISNULL(cost,0)) as cost,SUM(ISNULL(sales,0))sales from [192.168.1.187].[UpGoods].dbo.LxERP_SBCampaignReports where CONVERT(date,report_date)='" + InDate.Value.AddDays(-2).Date.ToString("yyyy-MM-dd") + "' group by sid union all select sid, SUM( ISNULL(cost,0)) as cost,SUM(ISNULL(sales,0))sales from [192.168.1.187].[UpGoods].dbo.LxERP_SDAdGroupReports where CONVERT(date,report_date)='" + InDate.Value.AddDays(-2).Date.ToString("yyyy-MM-dd") + "' group by sid) t group by sid ) f on f.sid=o.sid" +
" \r\n left join (select sid, CONVERT(decimal(12,2), SUM(t.cost)) as Rate6 from( select sid, SUM( ISNULL(cost,0)) as cost from [192.168.1.187].[UpGoods].dbo.LxERP_SPAdGroupReports where CONVERT(date,report_date)<='" + InDate.Value.AddDays(-2).ToString("yyyy-MM-dd") + "' and CONVERT(date,report_date)>='" + InDate.Value.AddDays(-31).ToString("yyyy-MM-dd") + "' group by sid union all select sid, SUM( ISNULL(cost,0)) as cost from [192.168.1.187].[UpGoods].dbo.LxERP_SBCampaignReports where CONVERT(date,report_date)<='" + InDate.Value.AddDays(-2).ToString("yyyy-MM-dd") + "' and CONVERT(date,report_date)>='" + InDate.Value.AddDays(-31).ToString("yyyy-MM-dd") + "' group by sid union all select sid, SUM( ISNULL(cost,0)) as cost from [192.168.1.187].[UpGoods].dbo.LxERP_SDAdGroupReports where CONVERT(date,report_date)<='" + InDate.Value.AddDays(-2).ToString("yyyy-MM-dd") + "' and CONVERT(date,report_date)>='" + InDate.Value.AddDays(-31).ToString("yyyy-MM-dd") + "' group by sid) t group by sid) g on o.sid=g.sid " +
" \r\n left join(select t.row, t.storename,t.financialEventGroupEndLocale,t.originCurrencyIcon,CAST(ISNULL( t.originalTotalCurrencyAmount,0) as decimal(12,2)) as originalTotalCurrencyAmount from ( select ROW_NUMBER() over(PARTITION BY storename ORDER BY requestDate DESC) row,storename, financialEventGroupEndLocale,originCurrencyIcon,originalTotalCurrencyAmount from [192.168.1.187].[UpGoods].dbo.LxERP_SettlementSummaryData where accountType='Standard' and processingStatus='Closed ') t where t.row=1) t1 on d.ShopName=t1.storeName left join (select storename,CONVERT(decimal(12,2), SUM(ISNULL(originalTotalCurrencyAmount,0))) originalTotalCurrencyAmount from [192.168.1.187].[UpGoods].dbo.LxERP_SettlementSummaryData where processingStatus='Open' and accountType='Standard' group by storename) n1 on d.ShopName=n1.storeName " +
"\r\n" +
" left join (select sid, CAST( orderDefectRate *100 as decimal(12,2)) orderDefectRate,CAST( validTrackingRate *100 as decimal(12,2)) validTrackingRate,cast(CancelRate *100 as decimal(12,2)) cancelRate from (\r\nselect ROW_NUMBER() over(PARTITION BY sid ORDER BY requestDate DESC) row,sid, orderDefectRate,validTrackingRate,CancelRate from [192.168.1.187].[UpGoods].dbo.Amazon_V2_SELLER_PERFORMANCE_REPORT where CONVERT(date, RequestDate)='" + InDate.Value.AddDays(-1).Date.ToString("yyyy-MM-dd") + "') t where t.row=1)t2 on t2.sid=o.sid \r\nleft join (select sid, user_sessions,totalOrderItems, case when user_sessions=0 or totalOrderItems=0 then 0 else convert(decimal(12,2),(totalOrderItems*1.00/user_sessions)*100 ) end as CVR from [192.168.1.187].[UpGoods].dbo.Amazon_SALES_AND_TRAFFIC_REPORT where CONVERT(date, ReportDate)='" + InDate.Value.AddDays(-2).Date.ToString("yyyy-MM-dd") + "') t3 on t3.sid=o.sid\r\nleft join [192.168.1.187].[UpGoods].dbo.AmazonStoreRefundAmountAndRate t4 on t4.sid=o.sid and Convert(date, t4.ReportDate)='" + InDate.Value.AddDays(-2).Date.ToString("yyyy-MM-dd") + "'\r\n"
+ " where d.PlatType=2 union all\r\n select d.ShopName,Master=case when d.Master=d.buyer then d.Master when d.buyer is not null and d.buyer<>'' then d.Master+'-'+d.buyer else d.Master end,a.OrderNum,a.RMBMoney,a.USDMoney,AvgPrice=case when a.OrderNum>0 then cast(a.USDMoney/a.OrderNum as decimal(18,2)) else 0 end,a.InPrice,LR=cast(b.ml as decimal(18,2)),MLL=case when b.TotalPrice>0 then cast(b.ml*100/b.TotalPrice as decimal(18,2)) else 0 end,ShopTJGoods=e.Num,ShopCDGoods=e.Num2,ckfee,a.mdfee,a.adfee,bz=case when a.InPrice>0 then CAST(a.RMBMoney/a.InPrice as decimal(18,2)) else 0 end,a.yf,c.GoodRate,c.ODR,c.DSRService,c.DSRGoods,case when ISNULL(c.DSRPost,0)=0 then '' else CONVERT(nvarchar(20),c.DSRPost) end DSRPost,c.USDUseMoney,c.USDNoMoney,c.RMBUseMoney,c.RMBNoMoney,c.Rate1,c.Rate2,c.Rate3,c.Rate4,c.PropertyViolate,c.Rate5,c.Rate6,Rate7=isnull(c.Rate7,d.dayfee),JL=cast(b.ml as decimal(18,2))+isnull(ckfee,0)-isnull(c.Rate3,0)-isnull(c.Rate7,d.dayfee),FeeDate=isnull(c.FeeDate,d.FeeDate),TXFee=isnull(c.TXFee,d.TXFee) from \r\nJC_Shop d left join (\r\nselect ShopId,OrderNum=COUNT(0),RMBMoney=SUM(RMBPrice),escrowFee=sum(escrowFee),USDMoney=SUM(TotalPrice),InPrice=SUM(cb),ckfee=SUM(ck),mdfee=SUM(md),adfee=SUM(Ad_Fee),yf=SUM(yf) from #ls\r\ngroup by ShopId)a on d.ShopId=a.ShopId\r\nleft join (select ShopId,TotalPrice=sum(TotalPrice),ml=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 #ls where yf>0\r\ngroup by ShopId)b on a.ShopId=b.ShopId\r\nleft join (\r\nselect GoodRate,ODR,DSRService,DSRGoods,DSRPost,USDUseMoney,USDNoMoney,RMBUseMoney, RMBNoMoney,Rate1,Rate2,Rate3,Rate4,PropertyViolate,Rate5,Rate6,Rate7,FeeDate,TXFee\r\nTXFee,ShopId from JC_ShopData\r\nwhere DATEDIFF(day,indate,'" + InDate.Value.ToString("yyyy-MM-dd") + "')=0 )c on a.ShopId=c.ShopId\r\nleft Join #ls2 e on a.ShopId=e.ShopId where d.PlatType!=2 " + (isyc ? " and d.Master!='东南亚专用'" : "") + "\r\n) a order by " + Sort;
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 18);
}
catch (Exception ex)
{
string a = dd;
return "";
}
}
#endregion
#region 报表18(备份0518)
[WebMethod(EnableSession = true)]
public string GetReportTable1822(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
string dd = "";
try
{
var obj = new BaseService();
string tj = "";
string tj1 = "";
if (DeptId > 0)
{
tj += " and b.DeptId=" + DeptId + " ";
tj1 += " and a.DeptId=" + DeptId + " ";
}
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
if (MoneyCode != "0")
tj += " and a.MoneyCode='" + MoneyCode + "' ";
string sql = @"
select a.ShopId,a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.USDUseMoney,b.USDUseMoney,b.USDNoMoney,b.RMBUseMoney,b.RMBNoMoney,b.InforViolate,b.PropertyViolate,b.OtherViolate,b.Rate1,b.Rate2,b.Rate3,b.Rate4,b.Rate5,b.Rate6,FeeDate=isnull(b.FeeDate,a.FeeDate),TXFee=isnull(b.TXFee,a.TXFee),InPrice=d.InPrice,InPrice=d.InPrice,BZ=case when d.InPrice>0 then RMBMoney/d.InPrice else 0 end,LR=0,MLL='',ShopCDGoods=0,ShopTJGoods=0,ckfee=0.00,mdfee=0.00,adfee=0.00 from JC_Shop a
inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a with(nolock)
inner join JC_Shop b with(nolock) on a.ShopId=b.ShopId
where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId
left join JC_ShopData b with(nolock) on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0
inner join (select a.ShopId,InPrice=sum(isnull(d.InPrice,0)*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.State>0 and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)d on a.ShopId=d.ShopId
where a.CompanyId=1 " + tj1 + " order by " + Sort;
DataTable dt = obj.GetReportData(sql);
string sql2 = @"
select a.*,Num2=isnull(b.Num2,0) from (
select b.ShopId,Num=COUNT(0) from HW_GoodsInfo a with(nolock)
inner join HW_Shop b with(nolock) on a.GoodsId=b.GoodsId
group by b.ShopId)a
left join (
select a.ShopId,Num2=COUNT(distinct c.GoodsId) 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 DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)b on a.ShopId=b.ShopId";
DataTable dt2 = obj.GetReportData(sql2);
DataNew.updatestorefee(InDate.Value, InDate.Value.AddDays(1));
DD_OrderData data = new DD_OrderData();
if (dt != null)
{
decimal f1 = 0;
decimal f2 = 0;
decimal f3 = 0;
decimal f4 = 0;
decimal f5 = 0;
decimal f6 = 0;
// int ds = 0;
// decimal f9 = 0;
decimal cyxs = 0;
decimal cyyj = 0;
decimal hwcb = 0;
decimal hwtc = 0;
decimal hwyf = 0;
decimal hwyf1 = 0;
decimal hwyf2 = 0;
int yf1 = 0;
int yf2 = 0;
decimal zlr = 0;//总利润
decimal hjyj = 0;
decimal hjyf = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
decimal MRate = Convert.ToDecimal((double)6.5);
List<JC_Money> list7 = new BaseService().GetMoneyList2();
var olist = DataNew.GetListShopList2(Convert.ToInt32(dt.Rows[i]["ShopId"]), InDate);
string ids = "";
if (olist != null)
{
foreach (var order in olist)
{
ids += order.OrderId.ToString() + ",";
}
}
if (ids != "")
{
// List<DT_OrderGoods> orderGoodsListPP = DataNew.GetOrderGoodsListPP(ids.Trim(','));
List<DT_OrderGoods_tj> orderGoodsList = DataNew.GetOrderGoodsListtj(ids.Trim(','));
if (orderGoodsList != null)
{
//ds += orderGoodsList.Count;
//foreach (var md in orderGoodsList)
//{
// f9 += md.GoodsPrice.Value * md.GoodsNum.Value;
//}
foreach (var md in olist)
{
List<DT_OrderGoods_tj> gmd = null;
if (gmd == null)
gmd = orderGoodsList.FindAll(n => n.OrderId == md.OrderId);
md.GoodsListtj = gmd;
}
}
}
decimal lr = 0;
string AddrType = "";
decimal tweight = 0;
decimal hjckfee = 0;//仓储费
decimal hjmdfee = 0;//面单费
decimal hjadfee = 0;//广告费
if (olist != null)
{
foreach (var md in olist)
{
//if (md.PlatOrderCode == "2793358899439")
//{
// string cc = "";
//}
JC_Money money = list7.Find(n => n.MCode == "USD" && n.PlatId == md.PlatId);
if (money != null)
{
MRate = money.MRate.Value;
}
else
{
money = list7.Find(n => n.MCode == "USD");
MRate = money.MRate.Value;
}
decimal TotalPrice = md.TotalPrice.Value;
decimal yj = 0M;
yj = TotalPrice * Convert.ToDecimal((double)0.15);
int PlatType = md.PlatId.Value;
if (PlatType == 1)
{
yj = TotalPrice * Convert.ToDecimal((double)0.05);
}
else if (PlatType == 4)
{
yj = 0;
}
else if (PlatType == 5)
{
yj = TotalPrice * Convert.ToDecimal((double)0.1);
}
else if (PlatType == 18)
{
yj = TotalPrice * Convert.ToDecimal((double)0.06);
}
else if (PlatType == 15)
{
yj = TotalPrice * Convert.ToDecimal((double)0.029) + 0.3M;
}
f1 += TotalPrice;
f2 += yj;
decimal GoodsPrice = 0M;
decimal TCFee = 0M;
decimal TCFee2 = 0M;
decimal SolidFee = 0M;
decimal GoodsPrice2 = 0M;
decimal ckfee = 0;//仓储费
decimal mdfee = 0;//面单费
decimal adfee = 0;//广告费
tweight = 0;
if (md.GoodsListtj != null)
{
if (md.GoodsListtj.Count > 0)
{
AddrType = md.GoodsListtj[0].JoinOrderCode;
}
if (md.GoodsListtj != null)
{
foreach (DT_OrderGoods_tj goods in md.GoodsListtj)
{
//if (goods.GoodsFee.HasValue && (goods.GoodsFee.Value > 0M))
//{
// GoodsPrice += goods.GoodsFee.Value;
//}
//else
if (goods.Weight != null)
{
tweight += goods.Weight.Value * goods.GoodsNum.Value;
}
if (goods.GoodsPrice.HasValue)
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
//f9 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
}
// ds++;
if (goods.TCFee != null && goods.TCFee > 0 && goods.GoodsPrice != null)//税费
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value * goods.TCFee.Value * Convert.ToDecimal(0.01);
}
//if (goods.Solid != null && goods.Solid > 0)//匹配的头程费
//{
// TCFee2 += goods.Solid.Value * goods.GoodsNum.Value;
//}
//else
if (goods.Solid2.HasValue)
{
SolidFee += goods.Solid2.Value * goods.GoodsNum.Value;
}
if (goods.ckfee != null)
ckfee += goods.ckfee.Value;
if (goods.mdfee != null)
mdfee += goods.mdfee.Value;
if (goods.adfee != null)
adfee += goods.adfee.Value;
if (goods.ckfee != null)
hjckfee += ckfee;
if (goods.mdfee != null)
hjmdfee += mdfee;
if (goods.adfee != null)
hjadfee += adfee;
}
}
}
if (GoodsPrice2 > 0M)
{
GoodsPrice = GoodsPrice2 / MRate;
}
f4 += GoodsPrice;
decimal escrowFee = 0M;
if ((TCFee == 0M) && (SolidFee > 0M))
{
TCFee = Convert.ToDecimal(170) * SolidFee;
}
// TCFee += TCFee2;
f5 += TCFee;// +TCFee2;
if (md.escrowFee.HasValue)
{
escrowFee = md.escrowFee.Value;
}
decimal num10 = 0M;
if (md.PostFee.HasValue)
{
num10 = md.PostFee.Value;
}
// decimal num11 = 0M;
// decimal num12 = 0M;
// decimal num13 = 0M;
//if (md.Post == 222 || md.Post == 226 || md.Post == 227)
//{
// num13 = num10 * Convert.ToDecimal((double)0.1);
//}
decimal feestore11 = 0M;//e仓运费
decimal feestore6 = 0M;//w仓运费
decimal feestore = 0M;
if (md.Fee11 != null && md.Fee11 > 0)
{
feestore11 = md.Fee11.Value;
}
if (feestore11 == 0 && md.Fee12 != null && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < feestore11)
{
feestore11 = md.Fee12.Value;
}
if (feestore11 == 0 && md.Fee13 != null && md.Fee13 > 0)
feestore11 = md.Fee13.Value;
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < feestore11)
{
feestore11 = md.Fee13.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee11 != null && md.Fee13 != null && md.Fee11 > 0 && md.Fee11 < md.Fee13)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee13 != null && md.Fee13 > 0 && md.Fee11 > md.Fee13)
{
feestore11 = md.Fee13.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee11 != null && md.Fee12 != null && md.Fee11 > 0 && md.Fee11 < md.Fee12)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee12 != null && md.Fee12 > 0 && md.Fee11 > md.Fee12)
{
feestore11 = md.Fee12.Value;
}
}
if (md.Fee12 != null && tweight >= 1120 && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (feestore11 > 0)
{
hwyf1 += feestore11;
yf1++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
if (md.Fee6 != null && md.Fee6 > 0)
{
feestore6 = md.Fee6.Value;
}
if (feestore6 == 0 && md.Fee7 != null && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < feestore6)
{
feestore6 = md.Fee7.Value;
}
if (feestore6 == 0 && md.Fee8 != null && md.Fee8 > 0)
feestore6 = md.Fee8.Value;
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < feestore6)
{
feestore6 = md.Fee8.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee6 != null && md.Fee8 != null && md.Fee6 > 0 && md.Fee6 < md.Fee8)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee8 != null && md.Fee8 > 0 && md.Fee6 > md.Fee8)
{
feestore6 = md.Fee8.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee6 != null && md.Fee7 != null && md.Fee6 > 0 && md.Fee6 < md.Fee7)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee7 != null && md.Fee7 > 0 && md.Fee6 > md.Fee7)
{
feestore6 = md.Fee7.Value;
}
}
if (md.Fee7 != null && tweight >= 1120 && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (feestore6 > 0)
{
hwyf2 += feestore6;
yf2++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
feestore = feestore11;
if (feestore11 == 0)
feestore = feestore6;
if (feestore6 > 0 && feestore6 < feestore11)
feestore = feestore6;
f6 += feestore;
md.PostFee = new decimal?(num10);
md.BoxFee = new decimal?(feestore);//运费
//var admd = DataNew.GetModel_OrderFee(md.OrderId.Value);///仓储 面单 广告费
//if (admd != null)
//{
// ckfee = admd.ckfee.Value;
// mdfee = admd.mdfee.Value;
// adfee = admd.adfee.Value;
// hjckfee += ckfee;
// hjmdfee += mdfee;
// hjadfee += adfee;
//}
//decimal num15 = 0M;
decimal num16 = 0M;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, TCFee);
hjyj += yj;
hjyf += feestore;
num16 = TotalPrice - yj - GoodsPrice - escrowFee - feestore - TCFee - ckfee - adfee;
// ErrorFollow.TraceWrite("Fee18", md.PlatOrderCode, "TotalPrice:" + TotalPrice + "|yj:" + yj + "|GoodsPrice:" + GoodsPrice + "|feestore:" + feestore + "|escrowFee:" + escrowFee + "|TCFee:" + TCFee + "|lr:" + num16);
if (feestore > 0 && GoodsPrice > 0)
{
//cyxs += TotalPrice;
//cyyj += yj;
//hwcb += GoodsPrice;
//hwtc += TCFee;
//hwyf += num14;
lr += num16;
}
}
}
ErrorFollow.TraceWrite("利润", hjyj.ToString(), hjyf.ToString());
dt.Rows[i]["ckfee"] = hjckfee;
dt.Rows[i]["mdfee"] = hjmdfee;
dt.Rows[i]["adfee"] = hjadfee;
dt.Rows[i]["LR"] = lr;
if (dt.Rows[i]["USDMoney"].ToString() != "" && Convert.ToDecimal(dt.Rows[i]["USDMoney"]) > 0)
dt.Rows[i]["MLL"] = (lr * 100 / Convert.ToDecimal(dt.Rows[i]["USDMoney"])).ToString("0.00") + "%";
if (dt2 != null)
{
var row = dt2.Select("shopId=" + Convert.ToInt32(dt.Rows[i]["ShopId"]));
if (row != null && row.Length > 0)
{
dt.Rows[i]["ShopCDGoods"] = Convert.ToInt32(row[0]["Num2"]);
dt.Rows[i]["ShopTJGoods"] = Convert.ToInt32(row[0]["Num"]);
}
}
}
//decimal f0 = f1 - f2 - f4 - f5 - f6;
//decimal zlr = cyxs - cyyj - hwcb - hwtc - hwyf - hwyf1 - hwyf2-yf1-yf2;
}
return GetReport3(dt, 18);
}
catch (Exception ex)
{
string a = dd;
return "";
}
}
#endregion
#region 报表18
[WebMethod(EnableSession = true)]
public string GetReportExcel18(DateTime? InDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
string dd = "";
try
{
var obj = new BaseService();
string tj = "";
string tj1 = "";
if (DeptId > 0)
{
tj += " and b.DeptId=" + DeptId + " ";
tj1 += " and a.DeptId=" + DeptId + " ";
}
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
if (MoneyCode != "0")
tj += " and a.MoneyCode='" + MoneyCode + "' ";
string sql = @"
select a.ShopId,a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end,b.GoodRate,b.ODR,b.DSRGoods,b.DSRService,b.DSRPost,b.USDUseMoney,b.USDUseMoney,b.USDNoMoney,b.RMBUseMoney,b.RMBNoMoney,b.InforViolate,b.PropertyViolate,b.OtherViolate,b.Rate1,b.Rate2,b.Rate3,b.Rate4,b.Rate5,b.Rate6,FeeDate=isnull(b.FeeDate,a.FeeDate),TXFee=isnull(b.TXFee,a.TXFee),InPrice=d.InPrice,InPrice=d.InPrice,BZ=case when d.InPrice>0 then RMBMoney/d.InPrice else 0 end,LR=0,MLL='' from JC_Shop a
inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a
inner join JC_Shop b on a.ShopId=b.ShopId
where a.State>0 " + tj + " and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by b.ShopId)c on a.ShopId=c.ShopId
left join JC_ShopData b on a.ShopId=b.ShopId and DATEDIFF(day,b.InDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0
inner join (select a.ShopId,InPrice=sum(isnull(d.InPrice,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.State>0 and a.State<3 and DATEDIFF(day,a.OrderDate,'" + InDate.Value.ToString("yyyy-MM-dd") + @"')=0 group by a.ShopId)d on a.ShopId=d.ShopId
where a.CompanyId=1 " + tj1 + " order by " + Sort;
DataTable dt = obj.GetReportData(sql);
DD_OrderData data = new DD_OrderData();
if (dt != null)
{
decimal f1 = 0;
decimal f2 = 0;
decimal f3 = 0;
decimal f4 = 0;
decimal f5 = 0;
decimal f6 = 0;
// int ds = 0;
// decimal f9 = 0;
decimal cyxs = 0;
decimal cyyj = 0;
decimal hwcb = 0;
decimal hwtc = 0;
decimal hwyf = 0;
decimal hwyf1 = 0;
decimal hwyf2 = 0;
int yf1 = 0;
int yf2 = 0;
for (int i = 0; i < dt.Rows.Count; i++)
{
decimal MRate = Convert.ToDecimal((double)6.5);
List<JC_Money> list7 = new BaseService().GetMoneyList2();
var olist = DataNew.GetListShopList2(Convert.ToInt32(dt.Rows[i]["ShopId"]), InDate);
string ids = "";
if (olist != null)
{
foreach (var order in olist)
{
ids += order.OrderId.ToString() + ",";
}
}
if (ids != "")
{
// List<DT_OrderGoods> orderGoodsListPP = DataNew.GetOrderGoodsListPP(ids.Trim(','));
List<DT_OrderGoods> orderGoodsList = DataNew.GetOrderGoodsList(ids.Trim(','));
if (orderGoodsList != null)
{
//ds += orderGoodsList.Count;
//foreach (var md in orderGoodsList)
//{
// f9 += md.GoodsPrice.Value * md.GoodsNum.Value;
//}
foreach (var md in olist)
{
List<DT_OrderGoods> gmd = null;
if (gmd == null)
gmd = orderGoodsList.FindAll(n => n.OrderId == md.OrderId);
md.GoodsList = gmd;
}
}
}
decimal lr = 0;
string AddrType = "";
decimal tweight = 0;
if (olist != null)
{
foreach (var md in olist)
{
//if (md.PlatOrderCode == "2793358899439")
//{
// string cc = "";
//}
JC_Money money = list7.Find(n => n.MCode == "USD" && n.PlatId == md.PlatId);
if (money != null)
{
MRate = money.MRate.Value;
}
else
{
money = list7.Find(n => n.MCode == "USD");
MRate = money.MRate.Value;
}
decimal TotalPrice = md.TotalPrice.Value;
decimal yj = 0M;
yj = TotalPrice * Convert.ToDecimal((double)0.15);
int PlatType = md.PlatId.Value;
if (PlatType == 1)
{
yj = TotalPrice * Convert.ToDecimal((double)0.05);
}
else if (PlatType == 4)
{
yj = 0;
}
else if (PlatType == 5)
{
yj = TotalPrice * Convert.ToDecimal((double)0.1);
}
f1 += TotalPrice;
f2 += yj;
decimal GoodsPrice = 0M;
decimal TCFee = 0M;
decimal TCFee2 = 0M;
decimal SolidFee = 0M;
decimal GoodsPrice2 = 0M;
tweight = 0;
if (md.GoodsList != null)
{
if (md.GoodsList.Count > 0)
{
AddrType = md.GoodsList[0].JoinOrderCode;
}
if (md.GoodsList != null)
{
foreach (DT_OrderGoods goods in md.GoodsList)
{
//if (goods.GoodsFee.HasValue && (goods.GoodsFee.Value > 0M))
//{
// GoodsPrice += goods.GoodsFee.Value;
//}
//else
if (goods.Weight != null)
{
tweight += goods.Weight.Value * goods.GoodsNum.Value;
}
if (goods.GoodsPrice.HasValue)
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
//f9 += goods.GoodsPrice.Value * goods.GoodsNum.Value;
}
// ds++;
if (goods.TCFee != null && goods.TCFee > 0 && goods.GoodsPrice != null)//税费
{
GoodsPrice2 += goods.GoodsPrice.Value * goods.GoodsNum.Value * goods.TCFee.Value * Convert.ToDecimal(0.01);
}
//if (goods.Solid != null && goods.Solid > 0)//匹配的头程费
//{
// TCFee2 += goods.Solid.Value * goods.GoodsNum.Value;
//}
//else
if (goods.Solid2.HasValue)
{
SolidFee += goods.Solid2.Value * goods.GoodsNum.Value;
}
}
}
}
if (GoodsPrice2 > 0M)
{
GoodsPrice = GoodsPrice2 / MRate;
}
f4 += GoodsPrice;
decimal escrowFee = 0M;
if ((TCFee == 0M) && (SolidFee > 0M))
{
TCFee = Convert.ToDecimal(170) * SolidFee;
}
// TCFee += TCFee2;
f5 += TCFee;// +TCFee2;
if (md.escrowFee.HasValue)
{
escrowFee = md.escrowFee.Value;
}
decimal num10 = 0M;
if (md.PostFee.HasValue)
{
num10 = md.PostFee.Value;
}
decimal num11 = 0M;
decimal num12 = 0M;
decimal num13 = 0M;
//if (md.Post == 222 || md.Post == 226 || md.Post == 227)
//{
// num13 = num10 * Convert.ToDecimal((double)0.1);
//}
decimal feestore11 = 0M;//e仓运费
decimal feestore6 = 0M;//w仓运费
decimal feestore = 0M;
if (md.Fee11 != null && md.Fee11 > 0)
{
feestore11 = md.Fee11.Value;
}
if (feestore11 == 0 && md.Fee12 != null && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < feestore11)
{
feestore11 = md.Fee12.Value;
}
if (feestore11 == 0 && md.Fee13 != null && md.Fee13 > 0)
feestore11 = md.Fee13.Value;
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < feestore11)
{
feestore11 = md.Fee13.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee11 != null && md.Fee13 != null && md.Fee11 > 0 && md.Fee11 < md.Fee13)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee13 != null && md.Fee13 > 0 && md.Fee11 > md.Fee13)
{
feestore11 = md.Fee13.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee11 != null && md.Fee12 != null && md.Fee11 > 0 && md.Fee11 < md.Fee12)
{
feestore11 = md.Fee11.Value;
}
else if (md.Fee11 != null && md.Fee12 != null && md.Fee12 > 0 && md.Fee11 > md.Fee12)
{
feestore11 = md.Fee12.Value;
}
}
if (md.Fee12 != null && tweight >= 1120 && md.Fee12 > 0)
feestore11 = md.Fee12.Value;
if (feestore11 > 0)
{
hwyf1 += feestore11;
yf1++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
if (md.Fee6 != null && md.Fee6 > 0)
{
feestore6 = md.Fee6.Value;
}
if (feestore6 == 0 && md.Fee7 != null && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < feestore6)
{
feestore6 = md.Fee7.Value;
}
if (feestore6 == 0 && md.Fee8 != null && md.Fee8 > 0)
feestore6 = md.Fee8.Value;
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < feestore6)
{
feestore6 = md.Fee8.Value;
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL")
{
if (md.Fee6 != null && md.Fee8 != null && md.Fee6 > 0 && md.Fee6 < md.Fee8)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee8 != null && md.Fee8 > 0 && md.Fee6 > md.Fee8)
{
feestore6 = md.Fee8.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (md.Fee6 != null && md.Fee7 != null && md.Fee6 > 0 && md.Fee6 < md.Fee7)
{
feestore6 = md.Fee6.Value;
}
else if (md.Fee6 != null && md.Fee7 != null && md.Fee7 > 0 && md.Fee6 > md.Fee7)
{
feestore6 = md.Fee7.Value;
}
}
if (md.Fee7 != null && tweight >= 1120 && md.Fee7 > 0)
feestore6 = md.Fee7.Value;
if (feestore6 > 0)
{
hwyf2 += feestore6;
yf2++;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, num14);
}
feestore = feestore11;
if (feestore11 == 0)
feestore = feestore6;
if (feestore6 > 0 && feestore6 < feestore11)
feestore = feestore6;
f6 += feestore;
md.PostFee = new decimal?(num10);
md.BoxFee = new decimal?(feestore);//运费
//decimal num15 = 0M;
decimal num16 = 0M;
// DD_OrderData.GetGoodsFee2(md.OrderId.Value, TCFee);
num16 = ((((((TotalPrice - yj) - GoodsPrice) - escrowFee) - feestore) - TCFee) - num11) - num12;
if (feestore > 0 && GoodsPrice > 0)
{
//cyxs += TotalPrice;
//cyyj += yj;
//hwcb += GoodsPrice;
//hwtc += TCFee;
//hwyf += num14;
lr += num16;
}
}
}
dt.Rows[i]["LR"] = lr;
if (dt.Rows[i]["USDMoney"].ToString() != "")
dt.Rows[i]["MLL"] = (lr * 100 / Convert.ToDecimal(dt.Rows[i]["USDMoney"])).ToString("0.00") + "%";
}
//decimal f0 = f1 - f2 - f4 - f5 - f6;
//decimal zlr = cyxs - cyyj - hwcb - hwtc - hwyf - hwyf1 - hwyf2-yf1-yf2;
}
return GetExcelReport(dt, 18);
}
catch (Exception ex)
{
string a = dd;
return "";
}
}
#endregion
#region 报表41
[WebMethod(EnableSession = true)]
public List<HW_GoodsUserNew> GetReportTable41(DateTime? InDate, DateTime? EDate, int ShopId, int PlatId, string Name, string Sort)
{
var obj = new BaseService();
var slist = DataNew.GetListGoodsUserFee(PlatId, ShopId, Name);
if (slist == null)
return null;
var glist = DataNew.GetListGoodsUserOrder(PlatId, ShopId, InDate, EDate.Value.AddDays(1));
var olist = DataNew.GetListGoodsUserOrder2(PlatId, ShopId, InDate, EDate.Value.AddDays(1));
if (olist == null)
olist = new List<DT_OrderGoodsUser>();
decimal MRate = Convert.ToDecimal((double)6.5);
List<JC_Money> mlist = new BaseService().GetMoneyList2();
if (mlist != null)
{
var umd = mlist.Find(n => n.MCode == "USD");
if (umd != null)
MRate = umd.MRate.Value;
}
decimal hj = DataNew.GetListTotalPrice2(InDate.Value, EDate.Value.AddDays(1));
TimeSpan ts = EDate.Value.AddDays(1) - InDate.Value;
int days = ts.Days;
decimal thj = 100000 * 12 * days / 365;//每月10w 每天平摊仓储费
decimal fje = 0;
if (hj > 0)
fje = thj * 1.00M / hj;
decimal TotalPrice0 = 0;
decimal TotalRMBPrice0 = 0;
decimal YJFee0 = 0;
decimal GoodsFee0 = 0;
decimal TCFee0 = 0;
decimal PostFee0 = 0;
decimal RateFee0 = 0;
decimal TLR0 = 0;
decimal TLR02 = 0;
decimal hjft = 0;
int GNum0 = 0;
foreach (var md in slist)
{
if (glist != null)
{
var olistmd = olist.Find(n => n.ShopId == md.ShopId && n.UserId == md.UserId);
var gmd = glist.FindAll(n => n.ShopId == md.ShopId && n.UserId == md.UserId);
if (gmd != null)
{
decimal TotalPrice = 0;
decimal TotalRMBPrice = 0;
decimal YJFee = 0;
decimal GoodsFee = 0;
decimal TCFee = 0;
decimal PostFee = 0;
decimal RateFee = 0;
decimal TLR = 0;
int GNum = 0;
foreach (var ggmd in gmd)
{
decimal TotalPrice2 = 0;
decimal TotalRMBPrice2 = 0;
decimal YJFee2 = 0;
decimal GoodsFee2 = 0;
decimal TCFee2 = 0;
decimal PostFee2 = 0;
decimal PostFee3 = 0;
decimal RateFee2 = 0;
decimal TLR2 = 0;
int GNum2 = 0;
int DNum2 = 0;
if (ggmd.GoodsNum2 <= 1 && ggmd.TotalPrice != null)
TotalPrice2 = ggmd.TotalPrice.Value;
else if (ggmd.GoodsNum2 > 1 && ggmd.TotalPrice != null && ggmd.GoodsOrderFee > 0)
{
TotalPrice2 = ggmd.GoodsOrderFee.Value;
}
else if (ggmd.GoodsNum2 > 1 && ggmd.TotalPrice != null && ggmd.GoodsOrderFee == 0)
{
TotalPrice2 = (ggmd.TotalPrice.Value / ggmd.GoodsNum2.Value) * ggmd.GoodsNum.Value;
}
if (ggmd.PlatId == 1)
YJFee2 = TotalPrice2 * Convert.ToDecimal((double)0.05);
else
YJFee2 = TotalPrice2 * Convert.ToDecimal((double)0.15);
if (ggmd.InPrice != null)
GoodsFee2 = ggmd.InPrice.Value * ggmd.GoodsNum.Value / MRate;
if (ggmd.Solid != null)
TCFee2 = ggmd.Solid.Value * ggmd.GoodsNum.Value * Convert.ToDecimal(170);
string AddrType = ggmd.RevFax;//签收类型
if (AddrType == "Residential" || AddrType == "RESIDENTIAL" || AddrType == "")
{
if (ggmd.Fee6 != null && ggmd.Fee8 != null && ggmd.Fee6 > 0 && ggmd.Fee6 < ggmd.Fee8)
{
PostFee2 = ggmd.Fee6.Value;
}
else if (ggmd.Fee6 != null && ggmd.Fee8 != null && ggmd.Fee8 > 0 && ggmd.Fee6 > ggmd.Fee8)
{
PostFee2 = ggmd.Fee8.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (ggmd.Fee6 != null && ggmd.Fee7 != null && ggmd.Fee6 > 0 && ggmd.Fee6 < ggmd.Fee7)
{
PostFee2 = ggmd.Fee6.Value;
}
else if (ggmd.Fee6 != null && ggmd.Fee7 != null && ggmd.Fee7 > 0 && ggmd.Fee6 > ggmd.Fee7)
{
PostFee2 = ggmd.Fee7.Value;
}
}
if (AddrType == "Residential" || AddrType == "RESIDENTIAL" || AddrType == "")
{
if (ggmd.Fee11 != null && ggmd.Fee13 != null && ggmd.Fee11 > 0 && ggmd.Fee11 < ggmd.Fee13)
{
PostFee3 = ggmd.Fee11.Value;
}
else if (ggmd.Fee11 != null && ggmd.Fee13 != null && ggmd.Fee13 > 0 && ggmd.Fee11 > ggmd.Fee13)
{
PostFee3 = ggmd.Fee13.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (ggmd.Fee11 != null && ggmd.Fee12 != null && ggmd.Fee11 > 0 && ggmd.Fee11 < ggmd.Fee12)
{
PostFee3 = ggmd.Fee11.Value;
}
else if (ggmd.Fee11 != null && ggmd.Fee12 != null && ggmd.Fee12 > 0 && ggmd.Fee11 > ggmd.Fee12)
{
PostFee3 = ggmd.Fee12.Value;
}
}
decimal tweight = 0;
if (ggmd.Weight != null)
tweight = ggmd.Weight.Value * ggmd.GoodsNum.Value;
if (ggmd.Fee7 != null && tweight >= 1120 && ggmd.Fee7 > 0)
PostFee2 = ggmd.Fee7.Value;
if (ggmd.Fee12 != null && tweight >= 1120 && ggmd.Fee12 > 0)
PostFee3 = ggmd.Fee12.Value;
if (PostFee2 == 0)
PostFee2 = PostFee3;
if (PostFee3 > 0 && PostFee2 > PostFee3)
PostFee2 = PostFee3;
if (ggmd.GoodsNum2 > 1 && PostFee2 > 0)
{
PostFee2 = (PostFee2 / ggmd.GoodsNum2.Value) * ggmd.GoodsNum.Value;
}
if (ggmd.FeeRate > 0 && GoodsFee2 > 0)
RateFee2 = ggmd.FeeRate.Value * 0.01M * GoodsFee2;
if (TotalPrice2 > 0)
TotalRMBPrice2 = TotalPrice2 * MRate;
if (GoodsFee2 > 0 && PostFee2 > 0)
{
TLR2 = TotalPrice2 - YJFee2 - GoodsFee2 - PostFee2 - TCFee2 - RateFee2;
}
GNum2 = ggmd.GoodsNum.Value;
GNum += GNum2;
TotalPrice += TotalPrice2;
TotalRMBPrice += TotalRMBPrice2;
YJFee += YJFee2;
GoodsFee += GoodsFee2;
TCFee += TCFee2;
PostFee += PostFee2;
RateFee += RateFee2;
TLR += TLR2;
}
GNum0 += GNum;
TotalPrice0 += TotalPrice;
TotalRMBPrice0 += TotalRMBPrice;
YJFee0 += YJFee;
GoodsFee0 += GoodsFee;
TCFee0 += TCFee;
PostFee0 += PostFee;
RateFee0 += RateFee;
TLR0 += TLR;
md.TotalPrice = TotalPrice.ToString("0.00");
decimal ftfee = TotalPrice * fje;
hjft += ftfee;
md.ftkcfee = Convert.ToDecimal(ftfee.ToString("0.00"));
if (olistmd != null)
md.mdfee = 0.6M * olistmd.GoodsNum;
else
md.mdfee = 0;
md.TotalRMBPrice = TotalRMBPrice.ToString("0.00");
md.GoodsFee = GoodsFee.ToString("0.00");
md.GoodsNum = GNum;
md.LR = TLR.ToString("0.00");
decimal lr2 = TLR - md.ftkcfee.Value - md.mdfee.Value;
md.LR2 = lr2.ToString("0.00");
TLR02 += lr2;
if (GoodsFee > 0)
md.PGRate = (TotalPrice / GoodsFee).ToString("0.00");
}
}
}
var tmd = new HW_GoodsUserNew();
tmd.Name = "合计:";
tmd.TotalPrice = TotalPrice0.ToString("0.00");
tmd.TotalRMBPrice = TotalRMBPrice0.ToString("0.00");
tmd.GoodsFee = GoodsFee0.ToString("0.00");
tmd.GoodsNum = GNum0;
tmd.ftkcfee = Convert.ToDecimal(hjft.ToString("0.00"));
tmd.LR = TLR0.ToString("0.00");
tmd.LR2 = TLR02.ToString("0.00");
slist.Add(tmd);
return slist;
}
#endregion
#region 报表41
[WebMethod(EnableSession = true)]
public string GetReportExcel41(DateTime? InDate, DateTime? EDate, int ShopId, int PlatId, string Name, string Sort)
{
var obj = new BaseService();
var slist = DataNew.GetListGoodsUserFee(PlatId, ShopId, Name);
if (slist == null)
return null;
var glist = DataNew.GetListGoodsUserOrder(PlatId, ShopId, InDate, EDate.Value.AddDays(1));
decimal MRate = Convert.ToDecimal((double)6.5);
List<JC_Money> mlist = new BaseService().GetMoneyList2();
if (mlist != null)
{
var umd = mlist.Find(n => n.MCode == "USD");
if (umd != null)
MRate = umd.MRate.Value;
}
decimal TotalPrice0 = 0;
decimal TotalRMBPrice0 = 0;
decimal YJFee0 = 0;
decimal GoodsFee0 = 0;
decimal TCFee0 = 0;
decimal PostFee0 = 0;
decimal RateFee0 = 0;
decimal TLR0 = 0;
int GNum0 = 0;
int DNum0 = 0;
foreach (var md in slist)
{
if (glist != null)
{
var gmd = glist.FindAll(n => n.ShopId == md.ShopId && n.UserId == md.UserId);
if (gmd != null)
{
decimal TotalPrice = 0;
decimal TotalRMBPrice = 0;
decimal YJFee = 0;
decimal GoodsFee = 0;
decimal TCFee = 0;
decimal PostFee = 0;
decimal RateFee = 0;
decimal TLR = 0;
int GNum = 0;
int DNum = 0;
foreach (var ggmd in gmd)
{
decimal TotalPrice2 = 0;
decimal TotalRMBPrice2 = 0;
decimal YJFee2 = 0;
decimal GoodsFee2 = 0;
decimal TCFee2 = 0;
decimal PostFee2 = 0;
decimal RateFee2 = 0;
decimal TLR2 = 0;
int GNum2 = 0;
int DNum2 = 0;
if (ggmd.GoodsNum2 <= 1 && ggmd.TotalPrice != null)
TotalPrice2 = ggmd.TotalPrice.Value;
else if (ggmd.GoodsNum2 > 1 && ggmd.TotalPrice != null && ggmd.GoodsOrderFee > 0)
{
TotalPrice2 = ggmd.GoodsOrderFee.Value;
}
else if (ggmd.GoodsNum2 > 1 && ggmd.TotalPrice != null && ggmd.GoodsOrderFee == 0)
{
TotalPrice2 = (ggmd.TotalPrice.Value / ggmd.GoodsNum2.Value) * ggmd.GoodsNum.Value;
}
if (ggmd.PlatId == 1)
YJFee2 = TotalPrice2 * Convert.ToDecimal((double)0.05);
else
YJFee2 = TotalPrice2 * Convert.ToDecimal((double)0.15);
if (ggmd.InPrice != null)
GoodsFee2 = ggmd.InPrice.Value * ggmd.GoodsNum.Value / MRate;
if (ggmd.Solid != null)
TCFee2 = ggmd.Solid.Value * ggmd.GoodsNum.Value * Convert.ToDecimal(170);
string AddrType = ggmd.RevFax;//签收类型
if (AddrType == "Residential" || AddrType == "RESIDENTIAL" || AddrType == "")
{
if (ggmd.Fee6 != null && ggmd.Fee8 != null && ggmd.Fee6 > 0 && ggmd.Fee6 < ggmd.Fee8)
{
PostFee2 = ggmd.Fee6.Value;
}
else if (ggmd.Fee6 != null && ggmd.Fee8 != null && ggmd.Fee8 > 0 && ggmd.Fee6 > ggmd.Fee8)
{
PostFee2 = ggmd.Fee8.Value;
}
}
if (AddrType == "Commercial" || AddrType == "OFFICE")
{
if (ggmd.Fee6 != null && ggmd.Fee7 != null && ggmd.Fee6 > 0 && ggmd.Fee6 < ggmd.Fee7)
{
PostFee2 = ggmd.Fee6.Value;
}
else if (ggmd.Fee6 != null && ggmd.Fee7 != null && ggmd.Fee7 > 0 && ggmd.Fee6 > ggmd.Fee7)
{
PostFee2 = ggmd.Fee7.Value;
}
}
decimal tweight = 0;
if (ggmd.Weight != null)
tweight = ggmd.Weight.Value * ggmd.GoodsNum.Value;
if (ggmd.Fee7 != null && tweight >= 1120 && ggmd.Fee7 > 0)
PostFee2 = ggmd.Fee7.Value;
if (ggmd.GoodsNum2 > 1 && PostFee2 > 0)
{
PostFee2 = (PostFee2 / ggmd.GoodsNum2.Value) * ggmd.GoodsNum.Value;
}
if (ggmd.FeeRate > 0 && GoodsFee2 > 0)
RateFee2 = ggmd.FeeRate.Value * 0.01M * GoodsFee2;
if (TotalPrice2 > 0)
TotalRMBPrice2 = TotalPrice2 * MRate;
if (GoodsFee2 > 0 && PostFee2 > 0)
TLR2 = TotalPrice2 - YJFee2 - GoodsFee2 - PostFee2 - TCFee2 - RateFee2;
GNum2 = ggmd.GoodsNum.Value;
GNum += GNum2;
TotalPrice += TotalPrice2;
TotalRMBPrice += TotalRMBPrice2;
YJFee += YJFee2;
GoodsFee += GoodsFee2;
TCFee += TCFee2;
PostFee += PostFee2;
RateFee += RateFee2;
TLR += TLR2;
}
GNum0 += GNum;
TotalPrice0 += TotalPrice;
TotalRMBPrice0 += TotalRMBPrice;
YJFee0 += YJFee;
GoodsFee0 += GoodsFee;
TCFee0 += TCFee;
PostFee0 += PostFee;
RateFee0 += RateFee;
TLR0 += TLR;
md.TotalPrice = TotalPrice.ToString("0.00");
md.TotalRMBPrice = TotalRMBPrice.ToString("0.00");
md.GoodsFee = GoodsFee.ToString("0.00");
md.GoodsNum = GNum;
md.LR = TLR.ToString("0.00");
if (GoodsFee > 0)
md.PGRate = (TotalPrice / GoodsFee).ToString("0.00");
}
}
}
var tmd = new HW_GoodsUserNew();
tmd.Name = "合计:";
tmd.TotalPrice = TotalPrice0.ToString("0.00");
tmd.TotalRMBPrice = TotalRMBPrice0.ToString("0.00");
tmd.GoodsFee = GoodsFee0.ToString("0.00");
tmd.GoodsNum = GNum0;
tmd.LR = TLR0.ToString("0.00");
slist.Add(tmd);
TableColumnCollection columns = new TableColumnCollection();
columns.Add("ShopName", "店铺", DbType.String, "");
columns.Add("Name", "人员", DbType.String, "");
columns.Add("GNum", "分配货号数", DbType.String, "");
columns.Add("TotalRMBPrice", "销售额RMB", DbType.String, "");
columns.Add("TotalPrice", "销售额USD", DbType.String, "");
columns.Add("GoodsNum", "销售数量", DbType.String, "");
columns.Add("GoodsFee", "货物成本", DbType.String, "");
columns.Add("PGRate", "营业额/货物成本", DbType.String, "");
columns.Add("LR", "预估利润", DbType.String, "");
MicrosoftExcel excel = new MicrosoftExcel();
return excel.Export(slist, columns);
}
#endregion
#region 报表
public string GetReport3(DataTable dt, int ReportId)
{
PagesNew.Login(this.Session);
var obj = new BaseService();
var rmd = BaseService.GetReportModel(ReportId);
var rlist = obj.GetRepoartColsList(ReportId);
if (rmd == null || rlist == null)
return "";
StringBuilder html = new StringBuilder();
html.Append("<tr class='HeaderStyle'><th>序号</th>");
foreach (var md in rlist)
{
html.Append("<th>" + md.ColName + "</th>");
}
html.Append("</tr>");
if (dt != null)
{
DataRow row = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
html.Append("<tr class='DataGridRowStyle'><td>" + (i + 1).ToString() + "</td>");
int rowindex = 1;
foreach (var md in rlist)
{
if (dt.Columns.Contains(md.ColValue) == false)
{
html.Append("<td rowindex='" + rowindex + "' rowtr='" + i + "' rname='" + md.ColName + "'></td>");
rowindex++;
continue;
}
if (md.IsSum == 1 && i == 0)
{
if (row == null)
row = dt.NewRow();
if (md.ColType == "int")
{
try
{
row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + " is not null"));
}
catch
{
row[md.ColValue] = 0;
}
}
else if (md.ColType == "dec")
{
try
{
row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + "<>0"));
}
catch
{
row[md.ColValue] = 0;
}
}
}
if (dt.Rows[i][md.ColValue] != null && dt.Rows[i][md.ColValue].ToString() != "")
{
string csscolor = "";
if (md.ContionType == "=" && dt.Rows[i][md.ColValue].ToString() == md.SValue)
{
csscolor = md.ColColor;
}
else
if (md.ContionType == ">" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) > Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) < Convert.ToDecimal(md.EValue))
{
csscolor = md.ColColor;
}
else
if (md.ContionType == ">=" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) >= Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) <= Convert.ToDecimal(md.EValue))
{
csscolor = md.ColColor;
}
if (csscolor != "")
csscolor = "style='color:" + csscolor + "'";
string datav = "";
if (md.ColType == "date1")
datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd");
else
if (md.ColType == "date2")
datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd HH:mm");
else if (md.ColType == "dec")
datav = Convert.ToDecimal(dt.Rows[i][md.ColValue]).ToString("0.00");
else
datav = dt.Rows[i][md.ColValue].ToString();
html.Append("<td " + csscolor + " rowindex='" + rowindex + "' rowtr='" + i + "' rname='" + md.ColName + "'>" + datav + "</td>");
}
else
html.Append("<td rowindex='" + rowindex + "' rowtr='" + i + "' rname='" + md.ColName + "'></td>");
rowindex++;
}
html.Append("</tr>");
}
int hj = 0;
if (row != null)
{
html.Append("<tr class='DataGridRowStyle'><td>合计:</td>");
foreach (var md in rlist)
{
if (dt.Columns.Contains(md.ColValue) == false)
{
html.Append("<td></td>");
continue;
}
if (md.IsSum == 1 && row[md.ColValue] != null)
{
if (hj == 0)
{
hj = 1;
string hjje = "";
if (row[md.ColValue] != null && row[md.ColValue].ToString() != "")
hjje = Convert.ToDecimal(row[md.ColValue]).ToString("0.00");
html.Append("<td rtype='hj' rname='" + md.ColName + "'>" + hjje + "</td>");
}
else
{
string hjje = "";
if (row[md.ColValue] != null && row[md.ColValue].ToString() != "")
hjje = Convert.ToDecimal(row[md.ColValue]).ToString("0.00");
html.Append("<td rtype='hj' rname='" + md.ColName + "'>" + hjje + "</td>");
}
}
else
html.Append("<td></td>");
}
html.Append("</tr>");
}
}
return html.ToString();
}
#endregion
#region 导出报表
public string GetExcelReport(DataTable dt, int ReportId)
{
PagesNew.Login(this.Session);
var obj = new BaseService();
TableColumnCollection listColumns = new TableColumnCollection();
var rmd = BaseService.GetReportModel(ReportId);
var rlist = obj.GetRepoartColsList(ReportId);
if (rmd == null || rlist == null || dt == null)
return "";
DataRow row = null;
int hj = 0;
foreach (var md in rlist)
{
if (md.IsExcel == 1)
listColumns.Add(md.ColValue, md.ColName, DbType.String, "");
if (md.IsSum == 1)
{
if (row == null)
row = dt.NewRow();
if (md.ColType == "int" && dt != null && dt.Rows.Count > 0)
row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", ""));
else if (md.ColType == "dec" && dt != null && dt.Rows.Count > 0)
row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", ""));
}
else if (hj == 0 && md.ColType == "str")
{
if (row == null)
row = dt.NewRow();
row[md.ColValue] = "合计:";
}
}
if (row != null)
dt.Rows.Add(row);
MicrosoftExcel obj2 = new MicrosoftExcel();
return obj2.Export(dt, listColumns);
}
#endregion
#region 订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountReport1(int Type, int ShopId, int PlatId, DateTime? SDate, DateTime? EDate, Int32? TJ1, Int32? TJ2, Int32? TJ3, Int32? TJ4, Int32? TJ5, Int32? TJ6, Int32? TJ7, Int32? TJ8, Int32? TJ9, Int32? TJ10)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days + 1;
List<DT_CountListFromDay> countlist = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist2 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist3 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist4 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist5 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist6 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist7 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist8 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist9 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist10 = new List<DT_CountListFromDay>();
if (TJ1 == 1)
countlist = DataNew.GetCountListReport(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ2 == 1)
countlist2 = DataNew.GetCountListReport2(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ3 == 1)
countlist3 = DataNew.GetCountListReport3(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ4 == 1)
countlist4 = DataNew.GetCountListReport4(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ5 == 1)
countlist5 = DataNew.GetCountListReport5(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ6 == 1)
countlist6 = DataNew.GetCountListReport6(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ7 == 1)
countlist7 = DataNew.GetCountListReport7(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ8 == 1)
countlist8 = DataNew.GetCountListReport8(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ9 == 1)
countlist9 = DataNew.GetCountListReport9(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ10 == 1)
countlist10 = DataNew.GetCountListReport10(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
categories = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.Value.AddDays(i)).ToString("MM月dd日");
}
}
if (TJ10 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist10 != null)
{
var countmd = countlist10.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "总销售额";
datamd.data = data;
list.Add(datamd);
}
if (TJ1 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "总销售额扣除佣金";
datamd.data = data;
list.Add(datamd);
}
if (TJ2 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist2 != null)
{
var countmd = countlist2.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "参与预估销售额";
datamd.data = data;
list.Add(datamd);
}
if (TJ3 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist3 != null)
{
var countmd = countlist3.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "参与实际销售额";
datamd.data = data;
list.Add(datamd);
}
if (TJ4 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist4 != null)
{
var countmd = countlist4.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "预估货物成本";
datamd.data = data;
list.Add(datamd);
}
if (TJ5 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist5 != null)
{
var countmd = countlist5.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际货物成本";
datamd.data = data;
list.Add(datamd);
}
if (TJ6 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist6 != null)
{
var countmd = countlist6.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "预估运费";
datamd.data = data;
list.Add(datamd);
}
if (TJ7 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist7 != null)
{
var countmd = countlist7.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际运费";
datamd.data = data;
list.Add(datamd);
}
if (TJ8 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist8 != null)
{
var countmd = countlist8.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "预估利润";
datamd.data = data;
list.Add(datamd);
}
if (TJ9 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist9 != null)
{
var countmd = countlist9.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际利润";
datamd.data = data;
list.Add(datamd);
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountReportNew1(int Type, string ShopIds, int PlatId, DateTime? SDate, DateTime? EDate, Int32? TJ1, Int32? TJ2, Int32? TJ3, Int32? TJ4, Int32? TJ5, Int32? TJ6, Int32? TJ7, Int32? TJ8, Int32? TJ9, Int32? TJ10)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days + 1;
int ShopId = 0;
if (ShopIds.StartsWith("-1") == false)
ShopId = 1;
ShopIds = ShopIds.TrimEnd(',');
List<DT_CountListFromDay> countlist = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist2 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist3 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist4 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist5 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist6 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist7 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist8 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist9 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist10 = new List<DT_CountListFromDay>();
if (TJ1 == 1)
countlist = DataNew.GetCountListReportNew(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ2 == 1)
countlist2 = DataNew.GetCountListReportNew2(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ3 == 1)
countlist3 = DataNew.GetCountListReportNew3(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ4 == 1)
countlist4 = DataNew.GetCountListReportNew4(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ5 == 1)
countlist5 = DataNew.GetCountListReportNew5(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ6 == 1)
countlist6 = DataNew.GetCountListReportNew6(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ7 == 1)
countlist7 = DataNew.GetCountListReportNew7(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ8 == 1)
countlist8 = DataNew.GetCountListReportNew8(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ9 == 1)
countlist9 = DataNew.GetCountListReportNew9(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ10 == 1)
countlist10 = DataNew.GetCountListReportNew10(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
categories = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.Value.AddDays(i)).ToString("MM月dd日");
}
}
var shoplist = DataNew.GetShopAllList(1, PlatId);
if (ShopIds.StartsWith("-1") == true)
{
ShopIds = "";
foreach (var smd in shoplist)
{
ShopIds += smd.ShopId + ",";
}
ShopIds = ShopIds.TrimEnd(',');
}
string[] shops = ShopIds.Split(',');
if (TJ10 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist10 != null)
{
var countmd = countlist10.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "总销售额";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist10 != null)
{
var countmdall = countlist10.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ1 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "总销售额扣除佣金";
datamd.data = data;
list.Add(datamd);
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var countmdall = countlist.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
}
if (TJ2 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist2 != null)
{
var countmd = countlist2.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "参与预估销售额";
datamd.data = data;
list.Add(datamd);
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist2 != null)
{
var countmdall = countlist2.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
}
if (TJ3 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist3 != null)
{
var countmd = countlist3.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "参与实际销售额";
datamd.data = data;
list.Add(datamd);
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist3 != null)
{
var countmdall = countlist3.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
}
if (TJ4 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist4 != null)
{
var countmd = countlist4.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "预估货物成本";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist4 != null)
{
var countmdall = countlist4.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ5 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist5 != null)
{
var countmd = countlist5.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "实际货物成本";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist5 != null)
{
var countmdall = countlist5.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ6 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist6 != null)
{
var countmd = countlist6.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "预估运费";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist6 != null)
{
var countmdall = countlist6.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ7 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist7 != null)
{
var countmd = countlist7.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "实际运费";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist7 != null)
{
var countmdall = countlist7.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ8 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist8 != null)
{
var countmd = countlist8.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "预估利润";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist8 != null)
{
var countmdall = countlist8.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ9 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist9 != null)
{
var countmd = countlist9.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "实际利润";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist9 != null)
{
var countmdall = countlist9.FindAll(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountReportNew2(int Type, int PlatId, string ShopIds, int SYear, int SMonth, int EYear, int EMonth, Int32? TJ1, Int32? TJ2, Int32? TJ3, Int32? TJ4, Int32? TJ5, Int32? TJ6, Int32? TJ7, Int32? TJ8, Int32? TJ9, Int32? TJ10)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
int ShopId = 0;
if (ShopIds.StartsWith("-1") == false)
ShopId = 1;
ShopIds = ShopIds.TrimEnd(',');
string sm = SMonth.ToString();
if (SMonth < 10)
sm = "0" + SMonth.ToString();
string em = (EMonth + 1).ToString();
if (EMonth < 9)
em = "0" + (EMonth + 1).ToString();
DateTime? SDate = Convert.ToDateTime(SYear.ToString() + "-" + sm + "-01");
DateTime? EDate = Convert.ToDateTime(EYear.ToString() + "-" + em + "-01");
List<DT_CountListFromDay> countlist = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist2 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist3 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist4 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist5 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist6 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist7 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist8 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist9 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist10 = new List<DT_CountListFromDay>();
if (TJ1 == 1)
countlist = DataNew.GetCountListReportNew(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ2 == 1)
countlist2 = DataNew.GetCountListReportNew2(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ3 == 1)
countlist3 = DataNew.GetCountListReportNew3(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ4 == 1)
countlist4 = DataNew.GetCountListReportNew4(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ5 == 1)
countlist5 = DataNew.GetCountListReportNew5(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ6 == 1)
countlist6 = DataNew.GetCountListReportNew6(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ7 == 1)
countlist7 = DataNew.GetCountListReportNew7(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ8 == 1)
countlist8 = DataNew.GetCountListReportNew8(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ9 == 1)
countlist9 = DataNew.GetCountListReportNew9(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ10 == 1)
countlist10 = DataNew.GetCountListReportNew10(Type, PlatId, ShopId, ShopIds, SDate.Value, EDate.Value.AddDays(1), CompanyId);
int days = 0;
if (SYear == EYear)
days = EMonth - SMonth + 1;
else
days = 12 - SMonth + EMonth + 1;
var shoplist = DataNew.GetShopAllList(1, PlatId);
if (ShopIds.StartsWith("-1") == true)
{
ShopIds = "";
foreach (var smd in shoplist)
{
ShopIds += smd.ShopId + ",";
}
ShopIds = ShopIds.TrimEnd(',');
}
string[] shops = ShopIds.Split(',');
categories = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.Value.AddMonths(i)).ToString("yyyy年MM月");
}
}
if (TJ10 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist10 != null)
{
var countmd = countlist10.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "总销售额";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist10 != null)
{
var countmdall = countlist10.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ1 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "总销售额扣除佣金";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var countmdall = countlist.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ2 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist2 != null)
{
var countmd = countlist2.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "参与预估销售额";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist2 != null)
{
var countmdall = countlist2.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ3 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist3 != null)
{
var countmd = countlist3.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "参与实际销售额";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist3 != null)
{
var countmdall = countlist3.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ4 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist4 != null)
{
var countmd = countlist4.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "预估货物成本";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist4 != null)
{
var countmdall = countlist4.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ5 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist5 != null)
{
var countmd = countlist5.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "实际货物成本";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist5 != null)
{
var countmdall = countlist5.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ6 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist6 != null)
{
var countmd = countlist6.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "预估运费";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist6 != null)
{
var countmdall = countlist6.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ7 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist7 != null)
{
var countmd = countlist7.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "实际运费";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist7 != null)
{
var countmdall = countlist7.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ8 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist8 != null)
{
var countmd = countlist8.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = shopmd.ShopName;// "预估利润";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist8 != null)
{
var countmdall = countlist8.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
if (TJ9 == 1)
{
for (int m = 0; m < shops.Length; m++)
{
var shopmd = shoplist.Find(n => n.ShopId == Convert.ToInt32(shops[m]));
if (shopmd == null)
continue;
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist9 != null)
{
var countmd = countlist9.Find(n => n.PlatId == shopmd.ShopId && n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际利润";
datamd.data = data;
list.Add(datamd);
}
var datamdz = new DT_OrderCountData();
decimal[] dataz = new decimal[days];
datamdz.name = "合计";
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist9 != null)
{
var countmdall = countlist9.FindAll(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
decimal tzj = 0;
if (countmdall != null)
{
foreach (var cmd in countmdall)
{
if (cmd.Price != null)
tzj += cmd.Price.Value;
}
}
dataz[j] = tzj;
}
}
}
datamdz.data = dataz;
list.Add(datamdz);
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountReport2(int Type, int PlatId, int ShopId, int SYear, int SMonth, int EYear, int EMonth, Int32? TJ1, Int32? TJ2, Int32? TJ3, Int32? TJ4, Int32? TJ5, Int32? TJ6, Int32? TJ7, Int32? TJ8, Int32? TJ9, Int32? TJ10)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
string sm = SMonth.ToString();
if (SMonth < 10)
sm = "0" + SMonth.ToString();
string em = (EMonth + 1).ToString();
if (EMonth < 9)
em = "0" + (EMonth + 1).ToString();
DateTime? SDate = Convert.ToDateTime(SYear.ToString() + "-" + sm + "-01");
DateTime? EDate = Convert.ToDateTime(EYear.ToString() + "-" + em + "-01");
List<DT_CountListFromDay> countlist = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist2 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist3 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist4 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist5 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist6 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist7 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist8 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist9 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist10 = new List<DT_CountListFromDay>();
if (TJ1 == 1)
countlist = DataNew.GetCountListReport(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ2 == 1)
countlist2 = DataNew.GetCountListReport2(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ3 == 1)
countlist3 = DataNew.GetCountListReport3(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ4 == 1)
countlist4 = DataNew.GetCountListReport4(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ5 == 1)
countlist5 = DataNew.GetCountListReport5(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ6 == 1)
countlist6 = DataNew.GetCountListReport6(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ7 == 1)
countlist7 = DataNew.GetCountListReport7(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ8 == 1)
countlist8 = DataNew.GetCountListReport8(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ9 == 1)
countlist9 = DataNew.GetCountListReport9(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
if (TJ10 == 1)
countlist10 = DataNew.GetCountListReport10(Type, PlatId, ShopId, SDate.Value, EDate.Value.AddDays(1), CompanyId);
int days = 0;
if (SYear == EYear)
days = EMonth - SMonth + 1;
else
days = 12 - SMonth + EMonth + 1;
categories = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.Value.AddMonths(i)).ToString("yyyy年MM月");
}
}
if (TJ10 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist10 != null)
{
var countmd = countlist10.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "总销售额";
datamd.data = data;
list.Add(datamd);
}
if (TJ1 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "总销售额扣除佣金";
datamd.data = data;
list.Add(datamd);
}
if (TJ2 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist2 != null)
{
var countmd = countlist2.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "参与预估销售额";
datamd.data = data;
list.Add(datamd);
}
if (TJ3 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist3 != null)
{
var countmd = countlist3.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "参与实际销售额";
datamd.data = data;
list.Add(datamd);
}
if (TJ4 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist4 != null)
{
var countmd = countlist4.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "预估货物成本";
datamd.data = data;
list.Add(datamd);
}
if (TJ5 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist5 != null)
{
var countmd = countlist5.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际货物成本";
datamd.data = data;
list.Add(datamd);
}
if (TJ6 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist6 != null)
{
var countmd = countlist6.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "预估运费";
datamd.data = data;
list.Add(datamd);
}
if (TJ7 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist7 != null)
{
var countmd = countlist7.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际运费";
datamd.data = data;
list.Add(datamd);
}
if (TJ8 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist8 != null)
{
var countmd = countlist8.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "预估利润";
datamd.data = data;
list.Add(datamd);
}
if (TJ9 == 1)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (countlist9 != null)
{
var countmd = countlist9.Find(n => n.OrderDate == SDate.Value.AddMonths(j).ToString("yyyy-MM"));
if (countmd != null)
data[j] = countmd.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
var datamd = new DT_OrderCountData();
datamd.name = "实际利润";
datamd.data = data;
list.Add(datamd);
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 计算当天
[WebMethod(EnableSession = true)]
public void GetCountSum()
{
PagesNew.Login(this.Session);
DataNew.GetCountSum(DateTime.Today);
}
#endregion
#region 个人订单列表
[WebMethod(EnableSession = true)]
public JsonModel<List<DT_OrderUserListNew>> GetUserOrderList2(int BJState, int UserId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, decimal? GDFee, decimal YJRate, string OrderCode, string Name, string TrackCode, int OffType, decimal? Offfee, int PageSize, int PageIndex)
{
PagesNew.Login(this.Session);
try
{
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
List<DT_OrderUserNew> dlist = null;
var slist = obj.Get_ShopList(CompanyId);
if (UserId > 0)
dlist = DataNew.Get_OrderUser(BJState, CompanyId, OrderState, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name, OffType, Offfee);
else
dlist = DataNew.Get_OrderUser2(BJState, CompanyId, OrderState, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name, OffType, Offfee);
List<DT_OrderUserNew> glist = null;
if (UserId > 0)
glist = DataNew.Get_OrderGoods(CompanyId, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode);
else
glist = DataNew.Get_OrderGoods2(CompanyId, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode);
// ErrorFollow.TraceWrite("GetUserOrderList2", "", dlist.Count().ToString() + " " + glist.Count().ToString());
if (dlist == null || glist == null)
return null;
decimal USDRate = Convert.ToDecimal(6.5);
var obj2 = new BaseService();
var mlist = obj2.GetMoneyList2();
List<DT_OrderUserListNew> olist = new List<DT_OrderUserListNew>();
int rowindex = 1;
string Ids = "";
string Ids2 = "";
if (dlist != null)
{
foreach (var md in dlist)
{
Ids2 += md.OrderId.Value + ",";
if (md.OrderState2 == 1)
Ids += md.OrderId.Value + ",";
}
}
var backorderlist = new List<DT_OrderBackMoneyApply>();
if (Ids != "")
{
backorderlist = DataNew.GetListOrderBackMoneyApply(Ids.Trim(','));
}
var trackorderlist = new List<DT_TrackCodeApply>();
if (Ids2 != "")
{
trackorderlist = DataNew.GetListOrderTrackCodeApply(Ids2.Trim(','));
}
if (dlist != null)
{
decimal hj1 = 0;
decimal hj11 = 0;
decimal hj21 = 0;
decimal hj2 = 0;
decimal hj3 = 0;
decimal hj4 = 0;
decimal hj5 = 0;
decimal hj51 = 0;
decimal hj6 = 0;
decimal hj7 = 0;
decimal hj8 = 0;
decimal hj9 = 0;//赔款
decimal hj10 = 0;//我们承担运费
decimal Tckfee = 0;//
decimal Tmdfee = 0;//
decimal Tadfee = 0;//
decimal TDR_BackFee = 0;//
decimal TDR_PostFee = 0;//
decimal TDR_SSFee = 0;//
int hjsl = 0;
foreach (var md in dlist)
{
var mmd = mlist.Find(n => n.PlatId == md.PlatId && n.MCode == "USD");
if (mmd != null)
USDRate = mmd.MRate.Value;
decimal? Lr = 0;
DT_OrderUserListNew model = new DT_OrderUserListNew();
model.BJState = md.BJState;
model.OrderId = md.OrderId;
model.StateName = "正常订单";
int BackType = 0;//退款类型
int BackOrderState = 0;//订单类型
int? GoodsBackType = 0;//退款类型
int IsBackOrder = 0;//是否退货订单
int GoodsState = 0;//是否退货订单
decimal PKPrice = 0;//赔款金额
decimal OurPostFee = 0;//退货运费
string TrackCode2 = "";
if (trackorderlist != null && trackorderlist.Count > 0)
{
var tlist = trackorderlist.FindAll(n => n.OrderId == md.OrderId);
if (tlist != null)
{
foreach (var tmd in tlist)
{
TrackCode2 += tmd.TrackCode + "<br/>";
}
}
}
if (md.OrderState2 == 1 && backorderlist != null)
{
var bmd = backorderlist.Find(n => n.OrderId == md.OrderId);
if (bmd != null)
{
IsBackOrder = 1;
model.StateName = "退货赔款订单";
// <option value="0">退款退货</option>
//<option value="1">退款不退货</option>
//<option value="2">赔款不退货</option>
//<option value="3">赔款退货</option>
// <option value="0">取消订单收取佣金20%</option>
//<option value="1">订单和佣金正常</option>
if (bmd.FactPrice != null)
PKPrice = bmd.FactPrice.Value;
if (bmd.GoodState != null)
GoodsState = bmd.GoodState.Value;
if (bmd.PostFee != null && bmd.PostFee > 0)
OurPostFee = bmd.PostFee.Value;
GoodsBackType = bmd.BackState;
if (bmd.BackType != null)
{
BackType = bmd.BackType.Value;
if (bmd.BackType == 0)
{
model.Remark = "退款/退货";
}
else if (bmd.BackType == 1)
{
model.Remark = "退款/不退货";
}
else if (bmd.BackType == 2)
{
model.Remark = "部分赔款/不退货";
}
else if (bmd.BackType == 3)
{
model.Remark = "部分赔款/退货";
}
else if (bmd.BackType == 6)
{
model.Remark = "补发配件";
}
}
if (bmd.OrderState != null)
{
BackOrderState = bmd.OrderState.Value;
if (bmd.OrderState == 0)
{
model.Remark += "取消订单收取佣金20%";
}
else if (bmd.OrderState == 1)
{
model.Remark += "订单和佣金正常";
}
}
}
}
var shopmd = slist.Find(n => n.ShopId == md.ShopId);
if (shopmd != null)
{
model.PlatName = shopmd.PlatName + "|" + shopmd.ShopName;
}
else
model.PlatName = "";
model.RevName = md.RevName;
model.RevProvince = md.RevProvince;
model.TrackCode = TrackCode2;// md.TrackCode2;
model.PlatOrderCode = md.PlatOrderCode;
model.JoinOrderCode = md.JoinOrderCode;
model.CountryName = md.CountryName;
model.OrderDate = md.OrderDate.Value.ToString("yyyy-MM-dd");
if (md.PostDate != null)
model.PostDate = md.PostDate.Value.ToString("yyyy-MM-dd");
else
model.PostDate = "";
model.PostInfo = md.PostInfo;
model.GoodsNum = md.GoodsNum;
hjsl += md.GoodsNum.Value;
var gglist = glist.FindAll(n => n.OrderId == md.OrderId);
decimal hwcb = 0;
decimal tc = 0;
decimal sf = 0;
decimal ckfee = 0;//
decimal mdfee = 0;//
decimal adfee = 0;//
decimal DR_BackFee = 0;//
decimal DR_PostFee = 0;//
decimal DR_SSFee = 0;//
//var admd = DataNew.GetModel_OrderFee(md.OrderId.Value);///仓储 面单 广告费
//if (admd != null)
//{
// ckfee = admd.ckfee.Value;
// mdfee = admd.mdfee.Value;
// adfee = admd.adfee.Value;
// DR_BackFee = admd.DR_BackFee.Value;
// DR_PostFee = admd.DR_PostFee.Value;
// DR_SSFee = admd.DR_SSFee.Value;
// Lr -= ckfee;
// Lr -= mdfee;
// Lr -= adfee;
// Lr -= DR_BackFee;
// Lr -= DR_PostFee;
// Lr += DR_SSFee;
//}
string ghtml = "";
if (gglist != null)
{
foreach (var ggmd in gglist)
{
if (ggmd.GoodsFee != null)
{
hwcb += ggmd.GoodsFee.Value;
if (ggmd.FeeRate != null)
sf += ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100;
}
if (ggmd.TCFee != null)
{
tc += ggmd.TCFee.Value;
}
decimal hwcb2 = 0;
if (ggmd.GoodsFee != null && ggmd.GoodsNum != null && ggmd.GoodsNum.Value > 0)
hwcb2 = ggmd.GoodsFee.Value / ggmd.GoodsNum.Value;
ghtml += "<a gid='" + ggmd.Id + "' gcb='" + hwcb2 + "'>" + ggmd.GoodsCode + "</a>" + ggmd.TypeDesc + "数量:" + ggmd.GoodsNum + "";
if (ggmd.GoodsFee != null)
{
ghtml += "成本:" + (ggmd.GoodsFee.Value / USDRate).ToString("0.00") + "";
}
else
ghtml += "成本0";
if (ggmd.FeeRate != null)
{
ghtml += "税率:" + ggmd.FeeRate.Value + "%";
// if (ggmd.GoodsFee != null)
// ghtml += "税费:" + (ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100 / USDRate).ToString("0.00") +"";
// else
// ghtml += "税费0";
}
else
{
ghtml += "税率0";
// ghtml += "税费0";
}
//if (ggmd.TCFee != null)
//{
// ghtml += "头程:" + ggmd.TCFee.Value.ToString("0.00") + "<br/>";
//}
//else
// ghtml += "头程0<br/>";
if (ggmd.ckfee != null)
ckfee += ggmd.ckfee.Value;
if (ggmd.mdfee != null)
mdfee += ggmd.mdfee.Value;
if (ggmd.adfee != null)
adfee += ggmd.adfee.Value;
Lr -= ckfee;
Lr -= mdfee;
Lr -= adfee;
}
}
model.GoodsCode = ghtml;
Tckfee += ckfee;//
Tmdfee += mdfee;//
Tadfee += adfee;//
if (md.DR_BackFee != null)
DR_BackFee = md.DR_BackFee.Value;
if (md.DR_PostFee != null)
DR_PostFee = md.DR_PostFee.Value;
if (md.DR_SSFee != null)
DR_SSFee = md.DR_SSFee.Value;
Lr -= DR_BackFee;
Lr -= DR_PostFee;
Lr += DR_SSFee;
TDR_BackFee += DR_BackFee;//
TDR_PostFee += DR_PostFee;//
TDR_SSFee += DR_SSFee;//
//if @PlatId=1 set @escrowFee=0.95else if @PlatId=2 or @PlatId=3set @escrowFee=0.85else if @PlatId=5 set @escrowFee=0.9
decimal ptyjrate = 0;
if (md.PlatId == 1)
ptyjrate = Convert.ToDecimal(0.05);
else if (md.PlatId == 2 || md.PlatId == 3 || md.PlatId == 6)
ptyjrate = Convert.ToDecimal(0.15);
else if (md.PlatId == 5)
ptyjrate = Convert.ToDecimal((double)0.1);
else if (md.PlatId == 18)
ptyjrate = Convert.ToDecimal((double)0.06);
if (md.TotalPrice != null)
{
if (md.MoneyCode != "USD")
{
var opmd = mlist.Find(n => n.MCode == md.MoneyCode);
var opmd2 = mlist.Find(n => n.MCode == "USD");
if (opmd != null)
md.TotalPrice = opmd.MRate * md.TotalPrice / opmd2.MRate;
}
if (IsBackOrder == 1 && BackOrderState == 0)//取消订单
{
model.TotalPrice = "0";
model.YJPrice = (md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2)).ToString("0.00");
model.escrowFee = md.escrowFee.Value.ToString("0.00");
decimal yj = md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2);
if (md.PlatId == 15)
yj = (md.TotalPrice.Value * Convert.ToDecimal((double)0.029) + 0.3M) * Convert.ToDecimal(0.2);
Lr -= yj;
Lr -= md.escrowFee.Value;
hj11 += yj;
hj21 += md.escrowFee.Value;
}
else
{
model.TotalPrice = md.TotalPrice.Value.ToString("0.00");
decimal yj = md.TotalPrice.Value * ptyjrate;
if (md.PlatId == 15)
yj = (md.TotalPrice.Value * Convert.ToDecimal((double)0.029) + 0.3M);
model.YJPrice = yj.ToString("0.00");
if (md.PlatId == 15)
model.YJPrice = (md.TotalPrice.Value * Convert.ToDecimal((double)0.029) + 0.3M).ToString("0.00");
model.escrowFee = md.escrowFee.Value.ToString("0.00");
Lr += md.TotalPrice.Value;
Lr -= md.TotalPrice.Value * ptyjrate;
Lr -= md.escrowFee.Value;
hj1 += md.TotalPrice.Value;
hj11 += yj;
hj21 += md.escrowFee.Value;
}
}
else
{
model.TotalPrice = "";
model.YJPrice = "";
model.escrowFee = "";
}
if (IsBackOrder == 1 && (GoodsBackType == 1 || GoodsBackType == 2))//退货已经入库 不计成本
{
model.GoodsFee = "0";
model.Fee1 = "0";
model.Fee3 = "0";
}
else
{
if (md.Fee4 != null) //货物成本
{
model.GoodsFee = md.Fee4.Value.ToString("0.00");
hj2 += md.Fee4.Value;
Lr -= md.Fee4.Value;
}
else
if (hwcb > 0)
{
model.GoodsFee = (hwcb / USDRate).ToString("0.00");
hj2 += hwcb / USDRate;
Lr -= hwcb / USDRate;
}
else
model.GoodsFee = "0";
// html.Append("<td></td>");
if (sf > 0)
{
model.Fee1 = (sf / USDRate).ToString("0.00");
hj3 += sf / USDRate;
Lr -= sf / USDRate;
}
else
model.Fee1 = "";
if (md.Fee3 != null) //头程
{
tc = md.Fee3.Value;
}
if (tc > 0)
{
model.Fee3 = tc.ToString("0.00");
Lr -= tc;
hj4 += tc;
}
else
model.Fee3 = "0";
}
decimal yjyf = 0;
if (md.StoreId == 6 || md.StoreId == 9)
{
if (md.Fee6 != null && md.Fee6 > 0)
yjyf = md.Fee6.Value;
else if (md.Fee7 != null && md.Fee7 > 0)
yjyf = md.Fee7.Value;
else if (md.Fee8 != null && md.Fee8 > 0)
yjyf = md.Fee8.Value;
if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < yjyf)
yjyf = md.Fee6.Value;
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < yjyf)
yjyf = md.Fee7.Value;
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < yjyf)
yjyf = md.Fee8.Value;
if (md.RevFax == "Commercial" || md.RevFax == "OFFICE")
{
if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < md.Fee7)
{
yjyf = md.Fee6.Value;
}
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < md.Fee6)
{
yjyf = md.Fee7.Value;
}
}
else if (md.RevFax == "Residential" || md.RevFax == "RESIDENTIAL")
{
if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < md.Fee8)
{
yjyf = md.Fee8.Value;
}
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < md.Fee6)
{
yjyf = md.Fee8.Value;
}
}
}
else
{
if (md.Fee11 != null && md.Fee11 > 0)
yjyf = md.Fee11.Value;
else if (md.Fee12 != null && md.Fee12 > 0)
yjyf = md.Fee12.Value;
else if (md.Fee13 != null && md.Fee13 > 0)
yjyf = md.Fee13.Value;
if (md.Fee11 != null && md.Fee11 > 0 && md.Fee11 < yjyf)
yjyf = md.Fee6.Value;
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < yjyf)
yjyf = md.Fee12.Value;
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < yjyf)
yjyf = md.Fee13.Value;
if (md.RevFax == "Commercial" || md.RevFax == "OFFICE")
{
if (md.Fee11 != null && md.Fee11 > 0 && md.Fee11 < md.Fee12)
{
yjyf = md.Fee11.Value;
}
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < md.Fee11)
{
yjyf = md.Fee12.Value;
}
}
else if (md.RevFax == "Residential" || md.RevFax == "RESIDENTIAL")
{
if (md.Fee11 != null && md.Fee11 > 0 && md.Fee11 < md.Fee13)
{
yjyf = md.Fee11.Value;
}
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < md.Fee11)
{
yjyf = md.Fee13.Value;
}
}
}
md.Fee2 = yjyf;
if (md.Fee2 != null)
{
model.Fee2 = (md.Fee2.Value).ToString("0.00");
hj51 += md.Fee2.Value;
}
else
model.Fee2 = "0";
if (md.PostFee != null)
{
model.PostFee = (md.PostFee.Value).ToString("0.00");
Lr -= md.PostFee.Value;
hj5 += md.PostFee.Value;
}
else
model.PostFee = "0";
if (md.PostInfo != null && md.PostInfo.Contains("Fedex") && md.PostFee != null)
{
model.Fee4 = (md.PostFee.Value * YJRate / 100).ToString("0.00");
Lr -= md.PostFee.Value * YJRate / 100;
hj6 += md.PostFee.Value * YJRate / 100;
}
else
model.Fee4 = "0";
if (md.GDFee != null)
{
model.GDFee = md.GDFee.Value.ToString("0.00");
Lr -= md.GDFee.Value;
hj7 += md.GDFee.Value;
}
else
model.GDFee = "";
model.BackPostFee = OurPostFee.ToString("0.00");
Lr -= OurPostFee;
hj10 += OurPostFee;
if (IsBackOrder == 1 && PKPrice > 0)
{
model.BackMoney = PKPrice.ToString("0.00");
Lr -= PKPrice;
hj9 += PKPrice;
}
model.CCFee = ckfee.ToString("0.00");
model.MDFee = mdfee.ToString("0.00");
model.GGFee = adfee.ToString("0.00");
model.DR_BackFee = DR_BackFee.ToString("0.00");
model.DR_PostFee = DR_PostFee.ToString("0.00");
model.DR_SSFee = DR_SSFee.ToString("0.00");
model.LRFee = Lr.Value.ToString("0.00");
hj8 += Lr.Value;
if (Lr.Value > 0 && md.TotalPrice != null && md.TotalPrice > 0)
model.LRRate = ((Lr.Value / md.TotalPrice.Value) * 100).ToString("0.00") + "%";
else if (Lr.Value == 0)
model.LRRate = "0%";
if (Lr.Value < 0 && md.TotalPrice != null && md.TotalPrice > 0)
model.LRRate = "-" + ((Lr.Value * -1 / md.TotalPrice.Value) * 100).ToString("0.00") + "%";
if (rowindex > PageSize * (PageIndex - 1) && rowindex <= PageSize * PageIndex)
olist.Add(model);
rowindex++;
}
DT_OrderUserListNew model2 = new DT_OrderUserListNew();
model2.GoodsCode = "合计:";
model2.GoodsNum = hjsl;
model2.TotalPrice = hj1.ToString("0.00");
model2.YJPrice = hj11.ToString("0.00");
model2.GoodsFee = hj2.ToString("0.00");
model2.escrowFee = hj21.ToString("0.00");
model2.Fee1 = hj3.ToString("0.00");
model2.Fee3 = hj4.ToString("0.00");
model2.PostFee = hj5.ToString("0.00");
model2.Fee4 = hj6.ToString("0.00");
model2.BackPostFee = hj10.ToString("0.00");
model2.BackMoney = hj9.ToString("0.00");
model2.LRFee = hj8.ToString("0.00");
model2.CCFee = Tckfee.ToString("0.00");
model2.MDFee = Tmdfee.ToString("0.00");
model2.GGFee = Tadfee.ToString("0.00");
model2.DR_BackFee = TDR_BackFee.ToString("0.00");
model2.DR_PostFee = TDR_PostFee.ToString("0.00");
model2.DR_SSFee = TDR_SSFee.ToString("0.00");
if (hj8 > 0 && hj1 > 0)
model2.LRRate = (hj8 / hj1 * 100).ToString("0.00") + "%";
else if (hj8 == 0)
model2.LRRate = "0%";
else if (hj1 > 0)
model2.LRRate = "<font color='red'>-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%<font>";
olist.Add(model2);
// html.Append("<tr class='DataGridRowStyle'><td></td>");
// html.Append("<td></td>");
// html.Append("<td></td>");
// html.Append("<td></td>");
// html.Append("<td></td>");
// html.Append("<td></td>");
// html.Append("<td></td>");
// html.Append("<td></td>");
//model2. 合计:</td>");
// html.Append("<td>" + hj1.ToString("0.00") + "</td>");
// html.Append("<td>" + hj2.ToString("0.00") + "</td>");
// // html.Append("<td></td>");
// html.Append("<td>" + hj3.ToString("0.00") + "</td>");
// html.Append("<td>" + hj4.ToString("0.00") + "</td>");
// html.Append("<td>" + hj51.ToString("0.00") + "</td>");
// html.Append("<td>" + hj5.ToString("0.00") + "</td>");
// html.Append("<td>" + hj6.ToString("0.00") + "</td>");
// html.Append("<td>" + hj7.ToString("0.00") + "</td>");
// html.Append("<td>" + hj8.ToString("0.00") + "</td>");
// if (hj8 > 0)
// html.Append("<td>" + (hj8 / hj1 * 100).ToString("0.00") + "%</td>");
// else if (hj8 == 0)
// html.Append("<td>0%</td>");
// else
// html.Append("<td>-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%</td>");
// html.Append("</tr>");
}
JsonModel<List<DT_OrderUserListNew>> resultModel = new JsonModel<List<DT_OrderUserListNew>>();
int RowCount = 0;
resultModel.DataSource = olist;
resultModel.RowCount = rowindex;
return resultModel;
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetUserOrderList2", "", ex.Message);
}
return null;
}
#endregion
#region 个人订单列表
[WebMethod(EnableSession = true)]
public string GetUserOrderExcel2(int BJState, int UserId, int OrderState, int PlatId, int ShopId, DateTime? SDate, DateTime? EDate, string GoodsCode, decimal? GDFee, decimal YJRate, string OrderCode, string Name, string TrackCode, int OffType, decimal? Offfee)
{
PagesNew.Login(this.Session);
try
{
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
List<DT_OrderUserNew> dlist = null;
var slist = obj.Get_ShopList(CompanyId);
if (UserId > 0)
dlist = DataNew.Get_OrderUser(BJState, CompanyId, OrderState, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name, OffType, Offfee);
else
dlist = DataNew.Get_OrderUser2(BJState, CompanyId, OrderState, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode, OrderCode, TrackCode, Name, OffType, Offfee);
List<DT_OrderUserNew> glist = null;
if (UserId > 0)
glist = DataNew.Get_OrderGoods(CompanyId, PlatId, ShopId, UserId, SDate, EDate.Value.AddDays(1), GoodsCode);
else
glist = DataNew.Get_OrderGoods2(CompanyId, PlatId, ShopId, SDate, EDate.Value.AddDays(1), GoodsCode);
// ErrorFollow.TraceWrite("GetUserOrderList2", "", dlist.Count().ToString() + " " + glist.Count().ToString());
if (dlist == null || glist == null)
return null;
decimal USDRate = Convert.ToDecimal(6.5);
var obj2 = new BaseService();
var mlist = obj2.GetMoneyList2();
List<DT_OrderUserListNew> olist = new List<DT_OrderUserListNew>();
int rowindex = 1;
string Ids = "";
string Ids2 = "";
if (dlist != null)
{
foreach (var md in dlist)
{
Ids2 += md.OrderId.Value + ",";
if (md.OrderState2 == 1)
Ids += md.OrderId.Value + ",";
}
}
var backorderlist = new List<DT_OrderBackMoneyApply>();
if (Ids != "")
{
backorderlist = DataNew.GetListOrderBackMoneyApply(Ids.Trim(','));
}
var trackorderlist = new List<DT_TrackCodeApply>();
if (Ids2 != "")
{
trackorderlist = DataNew.GetListOrderTrackCodeApply(Ids2.Trim(','));
}
if (dlist != null)
{
decimal hj1 = 0;
decimal hj11 = 0;
decimal hj21 = 0;
decimal hj2 = 0;
decimal hj3 = 0;
decimal hj4 = 0;
decimal hj5 = 0;
decimal hj51 = 0;
decimal hj6 = 0;
decimal hj7 = 0;
decimal hj8 = 0;
decimal hj9 = 0;//赔款
decimal hj10 = 0;//我们承担运费
decimal Tckfee = 0;//
decimal Tmdfee = 0;//
decimal Tadfee = 0;//
decimal TDR_BackFee = 0;//
decimal TDR_PostFee = 0;//
decimal TDR_SSFee = 0;//
int hjsl = 0;
foreach (var md in dlist)
{
var mmd = mlist.Find(n => n.PlatId == md.PlatId && n.MCode == "USD");
if (mmd != null)
USDRate = mmd.MRate.Value;
decimal? Lr = 0;
DT_OrderUserListNew model = new DT_OrderUserListNew();
model.BJState = md.BJState;
model.OrderId = md.OrderId;
model.StateName = "正常订单";
int BackType = 0;//退款类型
int BackOrderState = 0;//订单类型
int? GoodsBackType = 0;//退款类型
int IsBackOrder = 0;//是否退货订单
int GoodsState = 0;//是否退货订单
decimal PKPrice = 0;//赔款金额
decimal OurPostFee = 0;//退货运费
string TrackCode2 = "";
if (trackorderlist != null && trackorderlist.Count > 0)
{
var tlist = trackorderlist.FindAll(n => n.OrderId == md.OrderId);
if (tlist != null)
{
foreach (var tmd in tlist)
{
TrackCode2 += tmd.TrackCode + ",";
}
}
}
if (md.OrderState2 == 1 && backorderlist != null)
{
var bmd = backorderlist.Find(n => n.OrderId == md.OrderId);
if (bmd != null)
{
IsBackOrder = 1;
model.StateName = "退货赔款订单";
// <option value="0">退款退货</option>
//<option value="1">退款不退货</option>
//<option value="2">赔款不退货</option>
//<option value="3">赔款退货</option>
// <option value="0">取消订单收取佣金20%</option>
//<option value="1">订单和佣金正常</option>
if (bmd.FactPrice != null)
PKPrice = bmd.FactPrice.Value;
if (bmd.GoodState != null)
GoodsState = bmd.GoodState.Value;
if (bmd.PostFee != null && bmd.PostFee > 0)
OurPostFee = bmd.PostFee.Value;
GoodsBackType = bmd.BackState;
if (bmd.BackType != null)
{
BackType = bmd.BackType.Value;
if (bmd.BackType == 0)
{
model.Remark = "退款/退货";
}
else if (bmd.BackType == 1)
{
model.Remark = "退款/不退货";
}
else if (bmd.BackType == 2)
{
model.Remark = "部分赔款/不退货";
}
else if (bmd.BackType == 3)
{
model.Remark = "部分赔款/退货";
}
else if (bmd.BackType == 6)
{
model.Remark = "补发配件";
}
}
if (bmd.OrderState != null)
{
BackOrderState = bmd.OrderState.Value;
if (bmd.OrderState == 0)
{
model.Remark += "取消订单收取佣金20%";
}
else if (bmd.OrderState == 1)
{
model.Remark += "订单和佣金正常";
}
}
}
}
var shopmd = slist.Find(n => n.ShopId == md.ShopId);
if (shopmd != null)
{
model.PlatName = shopmd.PlatName + "|" + shopmd.ShopName;
}
else
model.PlatName = "";
model.RevName = md.RevName;
model.RevProvince = md.RevProvince;
model.TrackCode = TrackCode2;// md.TrackCode2;
model.PlatOrderCode = md.PlatOrderCode;
model.JoinOrderCode = md.JoinOrderCode;
model.CountryName = md.CountryName;
model.OrderDate = md.OrderDate.Value.ToString("yyyy-MM-dd");
if (md.PostDate != null)
model.PostDate = md.PostDate.Value.ToString("yyyy-MM-dd");
else
model.PostDate = "";
model.PostInfo = md.PostInfo;
model.GoodsNum = md.GoodsNum;
hjsl += md.GoodsNum.Value;
var gglist = glist.FindAll(n => n.OrderId == md.OrderId);
decimal hwcb = 0;
decimal tc = 0;
decimal sf = 0;
decimal ckfee = 0;//
decimal mdfee = 0;//
decimal adfee = 0;//
decimal DR_BackFee = 0;//
decimal DR_PostFee = 0;//
decimal DR_SSFee = 0;//
//var admd = DataNew.GetModel_OrderFee(md.OrderId.Value);///仓储 面单 广告费
//if (admd != null)
//{
// ckfee = admd.ckfee.Value;
// mdfee = admd.mdfee.Value;
// adfee = admd.adfee.Value;
// DR_BackFee = admd.DR_BackFee.Value;
// DR_PostFee = admd.DR_PostFee.Value;
// DR_SSFee = admd.DR_SSFee.Value;
// Lr -= ckfee;
// Lr -= mdfee;
// Lr -= adfee;
// Lr -= DR_BackFee;
// Lr -= DR_PostFee;
// Lr += DR_SSFee;
//}
string ghtml = "";
if (gglist != null)
{
foreach (var ggmd in gglist)
{
if (ggmd.GoodsFee != null)
{
hwcb += ggmd.GoodsFee.Value;
if (ggmd.FeeRate != null)
sf += ggmd.GoodsFee.Value * ggmd.FeeRate.Value / 100;
}
if (ggmd.TCFee != null)
{
tc += ggmd.TCFee.Value;
}
decimal hwcb2 = 0;
if (ggmd.GoodsFee != null && ggmd.GoodsNum != null && ggmd.GoodsNum.Value > 0)
hwcb2 = ggmd.GoodsFee.Value / ggmd.GoodsNum.Value;
ghtml += ggmd.GoodsCode + " " + ggmd.TypeDesc + " 数量:" + ggmd.GoodsNum;
//if (ggmd.TCFee != null)
//{
// ghtml += "头程:" + ggmd.TCFee.Value.ToString("0.00") + "<br/>";
//}
//else
// ghtml += "头程0<br/>";
if (ggmd.ckfee != null)
ckfee += ggmd.ckfee.Value;
if (ggmd.mdfee != null)
mdfee += ggmd.mdfee.Value;
if (ggmd.adfee != null)
adfee += ggmd.adfee.Value;
Lr -= ckfee;
Lr -= mdfee;
Lr -= adfee;
model.SortName = ggmd.SortName;
}
}
model.GoodsCode = ghtml;
Tckfee += ckfee;//
Tmdfee += mdfee;//
Tadfee += adfee;//
if (md.DR_BackFee != null)
DR_BackFee = md.DR_BackFee.Value;
if (md.DR_PostFee != null)
DR_PostFee = md.DR_PostFee.Value;
if (md.DR_SSFee != null)
DR_SSFee = md.DR_SSFee.Value;
Lr -= DR_BackFee;
Lr -= DR_PostFee;
Lr += DR_SSFee;
TDR_BackFee += DR_BackFee;//
TDR_PostFee += DR_PostFee;//
TDR_SSFee += DR_SSFee;//
//if @PlatId=1 set @escrowFee=0.95else if @PlatId=2 or @PlatId=3set @escrowFee=0.85else if @PlatId=5 set @escrowFee=0.9
decimal ptyjrate = 0;
if (md.PlatId == 1)
ptyjrate = Convert.ToDecimal(0.05);
else if (md.PlatId == 2 || md.PlatId == 3 || md.PlatId == 6)
ptyjrate = Convert.ToDecimal(0.15);
else if (md.PlatId == 5)
ptyjrate = Convert.ToDecimal((double)0.1);
else if (md.PlatId == 18)
ptyjrate = Convert.ToDecimal((double)0.06);
if (md.TotalPrice != null)
{
if (md.MoneyCode != "USD")
{
var opmd = mlist.Find(n => n.MCode == md.MoneyCode);
var opmd2 = mlist.Find(n => n.MCode == "USD");
if (opmd != null)
md.TotalPrice = opmd.MRate * md.TotalPrice / opmd2.MRate;
}
if (IsBackOrder == 1 && BackOrderState == 0)//取消订单
{
model.TotalPrice = "0";
model.YJPrice = (md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2)).ToString("0.00");
model.escrowFee = md.escrowFee.Value.ToString("0.00");
decimal yj = md.TotalPrice.Value * ptyjrate * Convert.ToDecimal(0.2);
if (md.PlatId == 15)
yj = (md.TotalPrice.Value * Convert.ToDecimal((double)0.029) + 0.3M) * Convert.ToDecimal(0.2);
Lr -= yj;
Lr -= md.escrowFee.Value;
hj11 += yj;
hj21 += md.escrowFee.Value;
}
else
{
model.TotalPrice = md.TotalPrice.Value.ToString("0.00");
decimal yj = md.TotalPrice.Value * ptyjrate;
if (md.PlatId == 15)
yj = (md.TotalPrice.Value * Convert.ToDecimal((double)0.029) + 0.3M);
model.YJPrice = yj.ToString("0.00");
if (md.PlatId == 15)
model.YJPrice = (md.TotalPrice.Value * Convert.ToDecimal((double)0.029) + 0.3M).ToString("0.00");
model.escrowFee = md.escrowFee.Value.ToString("0.00");
Lr += md.TotalPrice.Value;
Lr -= md.TotalPrice.Value * ptyjrate;
Lr -= md.escrowFee.Value;
hj1 += md.TotalPrice.Value;
hj11 += yj;
hj21 += md.escrowFee.Value;
}
}
else
{
model.TotalPrice = "";
model.YJPrice = "";
model.escrowFee = "";
}
if (IsBackOrder == 1 && (GoodsBackType == 1 || GoodsBackType == 2))//退货已经入库 不计成本
{
model.GoodsFee = "0";
model.Fee1 = "0";
model.Fee3 = "0";
}
else
{
if (md.Fee4 != null) //货物成本
{
model.GoodsFee = md.Fee4.Value.ToString("0.00");
hj2 += md.Fee4.Value;
Lr -= md.Fee4.Value;
}
else
if (hwcb > 0)
{
model.GoodsFee = (hwcb / USDRate).ToString("0.00");
hj2 += hwcb / USDRate;
Lr -= hwcb / USDRate;
}
else
model.GoodsFee = "0";
// html.Append("<td></td>");
if (sf > 0)
{
model.Fee1 = (sf / USDRate).ToString("0.00");
hj3 += sf / USDRate;
Lr -= sf / USDRate;
}
else
model.Fee1 = "";
if (md.Fee3 != null) //头程
{
tc = md.Fee3.Value;
}
if (tc > 0)
{
model.Fee3 = tc.ToString("0.00");
Lr -= tc;
hj4 += tc;
}
else
model.Fee3 = "0";
}
decimal yjyf = 0;
if (md.StoreId == 6 || md.StoreId == 9)
{
if (md.Fee6 != null && md.Fee6 > 0)
yjyf = md.Fee6.Value;
else if (md.Fee7 != null && md.Fee7 > 0)
yjyf = md.Fee7.Value;
else if (md.Fee8 != null && md.Fee8 > 0)
yjyf = md.Fee8.Value;
if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < yjyf)
yjyf = md.Fee6.Value;
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < yjyf)
yjyf = md.Fee7.Value;
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < yjyf)
yjyf = md.Fee8.Value;
if (md.RevFax == "Commercial" || md.RevFax == "OFFICE")
{
if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < md.Fee7)
{
yjyf = md.Fee6.Value;
}
if (md.Fee7 != null && md.Fee7 > 0 && md.Fee7 < md.Fee6)
{
yjyf = md.Fee7.Value;
}
}
else if (md.RevFax == "Residential" || md.RevFax == "RESIDENTIAL")
{
if (md.Fee6 != null && md.Fee6 > 0 && md.Fee6 < md.Fee8)
{
yjyf = md.Fee8.Value;
}
if (md.Fee8 != null && md.Fee8 > 0 && md.Fee8 < md.Fee6)
{
yjyf = md.Fee8.Value;
}
}
}
else
{
if (md.Fee11 != null && md.Fee11 > 0)
yjyf = md.Fee11.Value;
else if (md.Fee12 != null && md.Fee12 > 0)
yjyf = md.Fee12.Value;
else if (md.Fee13 != null && md.Fee13 > 0)
yjyf = md.Fee13.Value;
if (md.Fee11 != null && md.Fee11 > 0 && md.Fee11 < yjyf)
yjyf = md.Fee6.Value;
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < yjyf)
yjyf = md.Fee12.Value;
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < yjyf)
yjyf = md.Fee13.Value;
if (md.RevFax == "Commercial" || md.RevFax == "OFFICE")
{
if (md.Fee11 != null && md.Fee11 > 0 && md.Fee11 < md.Fee12)
{
yjyf = md.Fee11.Value;
}
if (md.Fee12 != null && md.Fee12 > 0 && md.Fee12 < md.Fee11)
{
yjyf = md.Fee12.Value;
}
}
else if (md.RevFax == "Residential" || md.RevFax == "RESIDENTIAL")
{
if (md.Fee11 != null && md.Fee11 > 0 && md.Fee11 < md.Fee13)
{
yjyf = md.Fee11.Value;
}
if (md.Fee13 != null && md.Fee13 > 0 && md.Fee13 < md.Fee11)
{
yjyf = md.Fee13.Value;
}
}
}
md.Fee2 = yjyf;
if (md.Fee2 != null)
{
model.Fee2 = (md.Fee2.Value).ToString("0.00");
hj51 += md.Fee2.Value;
}
else
model.Fee2 = "0";
if (md.PostFee != null)
{
model.PostFee = (md.PostFee.Value).ToString("0.00");
Lr -= md.PostFee.Value;
hj5 += md.PostFee.Value;
}
else
model.PostFee = "0";
if (md.PostInfo != null && md.PostInfo.Contains("Fedex") && md.PostFee != null)
{
model.Fee4 = (md.PostFee.Value * YJRate / 100).ToString("0.00");
Lr -= md.PostFee.Value * YJRate / 100;
hj6 += md.PostFee.Value * YJRate / 100;
}
else
model.Fee4 = "0";
if (md.GDFee != null)
{
model.GDFee = md.GDFee.Value.ToString("0.00");
Lr -= md.GDFee.Value;
hj7 += md.GDFee.Value;
}
else
model.GDFee = "";
model.BackPostFee = OurPostFee.ToString("0.00");
Lr -= OurPostFee;
hj10 += OurPostFee;
if (IsBackOrder == 1 && PKPrice > 0)
{
model.BackMoney = PKPrice.ToString("0.00");
Lr -= PKPrice;
hj9 += PKPrice;
}
model.CCFee = ckfee.ToString("0.00");
model.MDFee = mdfee.ToString("0.00");
model.GGFee = adfee.ToString("0.00");
model.DR_BackFee = DR_BackFee.ToString("0.00");
model.DR_PostFee = DR_PostFee.ToString("0.00");
model.DR_SSFee = DR_SSFee.ToString("0.00");
model.LRFee = Lr.Value.ToString("0.00");
hj8 += Lr.Value;
if (Lr.Value > 0 && md.TotalPrice != null && md.TotalPrice > 0)
model.LRRate = ((Lr.Value / md.TotalPrice.Value) * 100).ToString("0.00") + "%";
else if (Lr.Value == 0)
model.LRRate = "0%";
if (Lr.Value < 0 && md.TotalPrice != null && md.TotalPrice > 0)
model.LRRate = "-" + ((Lr.Value * -1 / md.TotalPrice.Value) * 100).ToString("0.00") + "%";
olist.Add(model);
rowindex++;
}
DT_OrderUserListNew model2 = new DT_OrderUserListNew();
model2.GoodsCode = "合计:";
model2.GoodsNum = hjsl;
model2.TotalPrice = hj1.ToString("0.00");
model2.YJPrice = hj11.ToString("0.00");
model2.GoodsFee = hj2.ToString("0.00");
model2.escrowFee = hj21.ToString("0.00");
model2.Fee1 = hj3.ToString("0.00");
model2.Fee3 = hj4.ToString("0.00");
model2.PostFee = hj5.ToString("0.00");
model2.Fee4 = hj6.ToString("0.00");
model2.BackPostFee = hj10.ToString("0.00");
model2.BackMoney = hj9.ToString("0.00");
model2.LRFee = hj8.ToString("0.00");
model2.CCFee = Tckfee.ToString("0.00");
model2.MDFee = Tmdfee.ToString("0.00");
model2.GGFee = Tadfee.ToString("0.00");
model2.DR_BackFee = TDR_BackFee.ToString("0.00");
model2.DR_PostFee = TDR_PostFee.ToString("0.00");
model2.DR_SSFee = TDR_SSFee.ToString("0.00");
if (hj8 > 0 && hj1 > 0)
model2.LRRate = (hj8 / hj1 * 100).ToString("0.00") + "%";
else if (hj8 == 0)
model2.LRRate = "0%";
else if (hj1 > 0)
model2.LRRate = "<font color='red'>-" + (hj8 * -1 / hj1 * 100).ToString("0.00") + "%<font>";
olist.Add(model2);
}
if (olist == null)
return "";
DataTable tb = olist.ToDataTable<DT_OrderUserListNew>();
TableColumnCollection listColumns = new TableColumnCollection();
listColumns.Add("PlatName", "平台|店铺", DbType.String, "");
listColumns.Add("PlatOrderCode", "订单号", DbType.String, "");
listColumns.Add("CountryName", "国家", DbType.String, "");
listColumns.Add("RevProvince", "州省", DbType.String, "");
listColumns.Add("OrderDate", "订单日期", DbType.String, "");
listColumns.Add("PostDate", "发货日期", DbType.String, "");
listColumns.Add("RevName", "收件人", DbType.String, "");
listColumns.Add("PostInfo", "物流方式", DbType.String, "");
listColumns.Add("TrackCode", "跟踪码", DbType.String, "");
listColumns.Add("SortName", "产品分类", DbType.String, "");
listColumns.Add("GoodsCode", "货物编号", DbType.String, "");
listColumns.Add("GoodsNum", "货物数量", DbType.String, "");
listColumns.Add("TotalPrice", "订单金额$", DbType.String, "");
listColumns.Add("YJPrice", "佣金$", DbType.String, "");
listColumns.Add("escrowFee", "税费$", DbType.String, "");
listColumns.Add("GoodsFee", "货物成本", DbType.String, "");
listColumns.Add("Fee1", "关税", DbType.String, "");
listColumns.Add("Fee3", "头程费用", DbType.String, "");
listColumns.Add("Fee2", "预估运费", DbType.String, "");
listColumns.Add("PostFee", "运费", DbType.String, "");
listColumns.Add("Fee4", "运费佣金", DbType.String, "");
listColumns.Add("BackPostFee", "我们承担的运费", DbType.String, "");
listColumns.Add("GDFee", "固定成本", DbType.String, "");
listColumns.Add("CCFee", "仓储费", DbType.String, "");
listColumns.Add("MDFee", "面单费", DbType.String, "");
listColumns.Add("GGFee", "广告费", DbType.String, "");
listColumns.Add("DR_BackFee", "退款费", DbType.String, "");
listColumns.Add("DR_PostFee", "退货运费", DbType.String, "");
listColumns.Add("DR_SSFee", "物流申诉费", DbType.String, "");
listColumns.Add("LRRate", "利润率", DbType.String, "");
MicrosoftExcel obj3 = new MicrosoftExcel();
return obj3.Export(tb, listColumns);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetUserOrderList2", "", ex.Message);
}
return null;
}
#endregion
#region 报表27
[WebMethod(EnableSession = true)]
public string GetReportTable27(int Type, DateTime? SDate, DateTime? EDate, int StoreId)
{
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
//if (StoreId > 0)
//{
// tj = " and b.StoreId=" + StoreId;
//}
if (Type == 1)
{
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
else
{
if (SDate != null)
tj += " and a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
string sql = @"select OrderDate=CONVERT(varchar(10),a.OrderDate, 120),Solid=sum(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.CompanyId=" + CompanyId + " and a.state>0 and a.State<3 " + tj + " group by CONVERT(varchar(10),a.OrderDate, 120)";
if (Type == 2)
sql = @"select OrderDate=CONVERT(varchar(10),a.PostDate, 120),Solid=sum(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.CompanyId=" + CompanyId + " and a.PostState=1 " + tj + " group by CONVERT(varchar(10),a.PostDate, 120)";
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 38);
}
#endregion
#region 报表47
[WebMethod(EnableSession = true)]
public string GetReportTable47(DateTime? SDate, DateTime? EDate)
{
var obj = new BaseService();
string tj = "";
if (SDate != null)
tj += " a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"
select b.name,num=COUNT(0) from DT_TrackCodeScan a with(nolock)
inner join JC_UserInfo b with(nolock) on a.SureUserId=b.UserId
where " + tj + " group by b.name ";
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 47);
}
#endregion
#region 报表47
[WebMethod(EnableSession = true)]
public string GetReportTable51(DateTime? SDate, DateTime? EDate)
{
var obj = new BaseService();
string tj = "";
if (SDate != null)
tj += " a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"
select a.PlatOrderCode,a.InDate,a.PostDate,b.TrackCode,c.Name,a.JHRemark from DT_OrderInfo a with(nolock)
left join DT_TrackCodeScan b with(nolock) on a.OrderId=b.OrderId
left join JC_UserInfo c with(nolock) on b.SureUserId=c.UserId
where JHError=1 and " + tj + " order by a.PostDate ";
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 51);
}
#endregion
#region 报表27
[WebMethod(EnableSession = true)]
public string GetExcelTable51(DateTime? SDate, DateTime? EDate)
{
var obj = new BaseService();
string tj = "";
if (SDate != null)
tj += " a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"
select a.PlatOrderCode,a.InDate,a.PostDate,b.TrackCode,c.Name,a.JHRemark from DT_OrderInfo a with(nolock)
left join DT_TrackCodeScan b with(nolock) on a.OrderId=b.OrderId
left join JC_UserInfo c with(nolock) on b.SureUserId=c.UserId
where JHError=1 and " + tj + " order by a.PostDate ";
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 51);
}
#endregion
#region 发货立方
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountGoodsSoild(DateTime? SDate, DateTime? EDate, int Type)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
string tj = "";
if (Type == 1)
{
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
else
{
if (SDate != null)
tj += " and a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
string sql = @"select OrderDate=CONVERT(varchar(10),a.OrderDate, 120),Solid=sum(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.state>0 and a.State<3 " + tj + " group by CONVERT(varchar(10),a.OrderDate, 120)";
if (Type == 2)
sql = @"select OrderDate=CONVERT(varchar(10),a.PostDate, 120),Solid=sum(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.PostState=1 " + tj + " group by CONVERT(varchar(10),a.PostDate, 120)";
var obj2 = new BaseService();
DataTable dt = obj2.GetReportData(sql);
List<OrderSoild> countlist = new List<OrderSoild>();
if (dt != null)
countlist = dt.ToList<OrderSoild>();
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days + 1;
categories = new string[days];
for (int i = 0; i < days; i++)
{
categories[i] = SDate.Value.AddDays(i).ToString("MM月dd日");
}
decimal[] data = new decimal[days];
for (int j = 0; j < days; j++)
{
var glist = countlist.Find(n => n.OrderDate == SDate.Value.AddDays(j).ToString("yyyy-MM-dd"));
if (glist == null)
{
data[j] = 0;
}
else
data[j] = glist.Solid.Value;
}
var datamd = new DT_OrderCountData();
datamd.name = "货物立方";
datamd.data = data;
list.Add(datamd);
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 发货立方
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountGoodsSoildDay()
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
string tj = "";
DateTime SDate = DateTime.Today.AddDays(-30);
DateTime EDate = DateTime.Today.AddDays(1);
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select OrderDate=CONVERT(varchar(10),a.OrderDate, 120),Solid=sum(isnull(d.Solid,0)*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.state>0 and a.State<3 " + tj + " group by CONVERT(varchar(10),a.OrderDate, 120)";
var obj2 = new BaseService();
DataTable dt = obj2.GetReportData(sql);
List<OrderSoild> countlist = new List<OrderSoild>();
if (dt != null)
countlist = dt.ToList<OrderSoild>();
TimeSpan ts = EDate - SDate;
int days = ts.Days + 1;
categories = new string[days];
for (int i = 0; i < days; i++)
{
categories[i] = SDate.AddDays(i).ToString("MM月dd日");
}
decimal[] data = new decimal[days];
for (int j = 0; j < days; j++)
{
var glist = countlist.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist == null)
{
data[j] = 0;
}
else
data[j] = glist.Solid.Value;
}
var datamd = new DT_OrderCountData();
datamd.name = "货物立方";
datamd.data = data;
list.Add(datamd);
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 发货立方
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountGoodsSoildDay_New()
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
string tj = "";
DateTime SDate = DateTime.Today.AddDays(-30);
DateTime EDate = DateTime.Today.AddDays(1);
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select OrderDate=CONVERT(varchar(10),a.OrderDate, 120),Solid=sum(isnull(d.Solid,0)*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.state>0 and a.State<3 " + tj + @" group by CONVERT(varchar(10),a.OrderDate, 120)
select OrderDate=CONVERT(varchar(10),a.OrderDate, 120),Solid=sum(isnull(d.Solid,0)*b.GoodsNum) from DT_OrderInfo a with(nolock)
inner join DT_OrderXXInfo e 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.state>0 and a.State<3 and e.StoreId = 6 " + tj + @" group by CONVERT(varchar(10),a.OrderDate, 120)
select OrderDate = CONVERT(varchar(10), a.OrderDate, 120), Solid = sum(isnull(d.Solid, 0) * b.GoodsNum) from DT_OrderInfo a with(nolock)
inner join DT_OrderXXInfo e 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.state > 0 and a.State < 3 and e.StoreId = 11 " + tj + @" group by CONVERT(varchar(10), a.OrderDate, 120)
";
var obj2 = new BaseService();
DataSet ds = obj2.GetReportData2(sql);
List<OrderSoild> countlist = new List<OrderSoild>();
List<OrderSoild> countlist2 = new List<OrderSoild>();
List<OrderSoild> countlist3 = new List<OrderSoild>();
if (ds != null)
countlist = ds.Tables[0].ToList<OrderSoild>();
if (ds != null && ds.Tables.Count > 1)
countlist2 = ds.Tables[1].ToList<OrderSoild>();
if (ds != null && ds.Tables.Count > 2)
countlist3 = ds.Tables[2].ToList<OrderSoild>();
TimeSpan ts = EDate - SDate;
int days = ts.Days + 1;
categories = new string[days];
for (int i = 0; i < days; i++)
{
categories[i] = SDate.AddDays(i).ToString("MM月dd日");
}
decimal[] data = new decimal[days];
decimal[] data2 = new decimal[days];
decimal[] data3 = new decimal[days];
for (int j = 0; j < days; j++)
{
if (countlist != null)
{
var glist = countlist.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist == null)
{
data[j] = 0;
}
else
data[j] = glist.Solid.Value;
}
else
data[j] = 0;
if (countlist2 != null)
{
var glist2 = countlist2.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist2 == null)
{
data2[j] = 0;
}
else
data2[j] = glist2.Solid.Value;
}
else
data2[j] = 0;
if (countlist3 != null)
{
var glist3 = countlist3.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist3 == null)
{
data3[j] = 0;
}
else
data3[j] = glist3.Solid.Value;
}
else
data3[j] = 0;
}
var datamd = new DT_OrderCountData();
datamd.name = "货物立方--合计";
datamd.data = data;
list.Add(datamd);
datamd = new DT_OrderCountData();
datamd.name = "货物立方--W仓";
datamd.data = data2;
list.Add(datamd);
datamd = new DT_OrderCountData();
datamd.name = "货物立方--E仓";
datamd.data = data3;
list.Add(datamd);
md.categories = categories;
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 发货立方
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountGoodsSoildMonth()
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
string tj = "";
DateTime SDate = Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-01")).AddMonths(-11);
DateTime EDate = DateTime.Today.AddDays(1);
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select OrderDate=cast(DATEPART(month,OrderDate) as nvarchar(10)),Solid=sum(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.state>0 and a.State<3 " + tj + " group by DATEPART(month,OrderDate)";
var obj2 = new BaseService();
DataTable dt = obj2.GetReportData(sql);
List<OrderSoild> countlist = new List<OrderSoild>();
if (dt != null)
countlist = dt.ToList<OrderSoild>();
int days = 12;
categories = new string[days];
for (int i = 0; i < days; i++)
{
categories[i] = SDate.AddMonths(i).ToString("MM月");
}
decimal[] data = new decimal[days];
for (int j = 0; j < days; j++)
{
var glist = countlist.Find(n => n.OrderDate == SDate.AddMonths(j).Month.ToString());
if (glist == null)
{
data[j] = 0;
}
else
data[j] = glist.Solid.Value;
}
var datamd = new DT_OrderCountData();
datamd.name = "货物立方";
datamd.data = data;
list.Add(datamd);
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 发货立方
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountGoodsSoildMonth_New()
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
string tj = "";
DateTime SDate = Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-01")).AddMonths(-11);
DateTime EDate = DateTime.Today.AddDays(1);
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select OrderDate=cast(DATEPART(month,OrderDate) as nvarchar(10)),Solid=sum(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.state>0 and a.State<3 " + tj + @" group by DATEPART(month,OrderDate)
--W
select OrderDate = cast(DATEPART(month, OrderDate) as nvarchar(10)),Solid = sum(isnull(d.Solid, 0) * b.GoodsNum) from DT_OrderInfo a
inner join DT_OrderXXInfo e on a.OrderId = e.OrderId
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 e.StoreId = 6 " + tj + @" group by DATEPART(month, OrderDate)
--E
select OrderDate = cast(DATEPART(month, OrderDate) as nvarchar(10)),Solid = sum(isnull(d.Solid, 0) * b.GoodsNum) from DT_OrderInfo a
inner join DT_OrderXXInfo e on a.OrderId = e.OrderId
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 e.StoreId = 11 " + tj + @" group by DATEPART(month, OrderDate)
";
var obj2 = new BaseService();
DataSet ds = obj2.GetReportData2(sql);
List<OrderSoild> countlist = new List<OrderSoild>();
List<OrderSoild> countlist2 = new List<OrderSoild>();
List<OrderSoild> countlist3 = new List<OrderSoild>();
if (ds != null)
countlist = ds.Tables[0].ToList<OrderSoild>();
if (ds != null && ds.Tables.Count > 1)
countlist2 = ds.Tables[1].ToList<OrderSoild>();
if (ds != null && ds.Tables.Count > 2)
countlist3 = ds.Tables[2].ToList<OrderSoild>();
int days = 12;
categories = new string[days];
for (int i = 0; i < days; i++)
{
categories[i] = SDate.AddMonths(i).ToString("MM月");
}
decimal[] data = new decimal[days];
decimal[] data2 = new decimal[days];
decimal[] data3 = new decimal[days];
for (int j = 0; j < days; j++)
{
var glist = countlist.Find(n => n.OrderDate == SDate.AddMonths(j).Month.ToString());
if (glist == null)
{
data[j] = 0;
}
else
data[j] = glist.Solid.Value;
if (countlist2 != null)
{
var glist2 = countlist2.Find(n => n.OrderDate == SDate.AddMonths(j).Month.ToString());
if (glist2 == null)
{
data2[j] = 0;
}
else
data2[j] = glist2.Solid.Value;
}
else
data2[j] = 0;
if (countlist3 != null)
{
var glist3 = countlist3.Find(n => n.OrderDate == SDate.AddMonths(j).Month.ToString());
if (glist3 == null)
{
data3[j] = 0;
}
else
data3[j] = glist3.Solid.Value;
}
else
data3[j] = 0;
}
var datamd = new DT_OrderCountData();
datamd.name = "货物立方--合计";
datamd.data = data;
list.Add(datamd);
datamd = new DT_OrderCountData();
datamd.name = "货物立方--W仓";
datamd.data = data2;
list.Add(datamd);
datamd = new DT_OrderCountData();
datamd.name = "货物立方--E仓";
datamd.data = data3;
list.Add(datamd);
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 报表27
[WebMethod(EnableSession = true)]
public string GetExcelTable27(int Type, DateTime? SDate, DateTime? EDate, int StoreId)
{
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
//if (StoreId > 0)
//{
// tj = " and b.StoreId=" + StoreId;
//}
if (Type == 1)
{
if (SDate != null)
tj += " and a.OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
else
{
if (SDate != null)
tj += " and a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.PostDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
string sql = @"select OrderDate=CONVERT(varchar(10),a.OrderDate, 120),Solid=sum(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.state>0 and a.State<3 " + tj + " group by CONVERT(varchar(10),a.OrderDate, 120)";
if (Type == 2)
sql = @"select OrderDate=CONVERT(varchar(10),a.PostDate, 120),Solid=sum(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.PostState=1 " + tj + " group by CONVERT(varchar(10),a.PostDate, 120)";
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 38);
}
#endregion
#region 首页订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetDefaultOrderCountMonth(List<DT_OrderCountContent> listshop, int Type)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
DateTime SDate = Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-01")).AddMonths(-11);
DateTime EDate = DateTime.Today;
List<DT_CountForMonth> countlist = new List<DT_CountForMonth>();
if (Type == 1)
countlist = DataNew.GetDefaultCountListFromMonth(SDate, EDate.AddDays(1), CompanyId);
else
countlist = DataNew.GetDefaultCountListFromMonthPrice(SDate, EDate.AddDays(1), CompanyId);
List<DT_CountForMonth> countlist2 = new List<DT_CountForMonth>();
if (Type == 1)
countlist2 = DataNew.GetDefaultCountListFromMonth2(SDate, EDate.AddDays(1), CompanyId);
else
countlist2 = DataNew.GetDefaultCountListFromMonthPrice2(SDate, EDate.AddDays(1), CompanyId);
categories = new string[12];
int m = 11;
for (int i = 0; i < 12; i++)
{
categories[i] = (DateTime.Today.AddMonths(-1 * m).Month).ToString() + "月";
m--;
}
if (Type == 1)
{
var smd = new DT_OrderCountContent();
smd.Id = 0;
smd.Name = "总单量";
listshop.Insert(0, smd);
}
else
if (Type == 2)
{
var smd = new DT_OrderCountContent();
smd.Id = 0;
smd.Name = "总销售额";
listshop.Insert(0, smd);
}
if (listshop != null && listshop.Count > 0)
{
for (int i = 0; i < listshop.Count; i++)
{
decimal[] data = new decimal[12];
int m2 = 11;
for (int j = 0; j < 12; j++)
{
if (listshop[i].Id == 0)
{
if (countlist2 != null)
{
var countmd2 = countlist2.Find(n => n.Month == DateTime.Today.AddMonths(-1 * m2).Month);
if (countmd2 != null)
{
if (Type == 1)
data[j] = countmd2.Num.Value;
else
data[j] = countmd2.Price.Value;
}
else
data[j] = 0;
}
else
data[j] = 0;
}
else
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.ShopId == listshop[i].Id && n.Month == DateTime.Today.AddMonths(-1 * m2).Month);
if (countmd != null)
{
if (Type == 1)
data[j] = countmd.Num.Value;
else
data[j] = countmd.Price.Value;
}
else
data[j] = 0;
}
else
data[j] = 0;
}
m2--;
}
var datamd = new DT_OrderCountData();
datamd.name = listshop[i].Name;
datamd.data = data;
list.Add(datamd);
}
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 首页订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetDefaultOrderCount1(List<DT_OrderCountContent> listshop, int Type, int Days)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
DateTime SDate = DateTime.Today.AddDays(-1 * Days);
DateTime EDate = DateTime.Today;
TimeSpan ts = EDate - SDate;
int days = ts.Days + 1;
List<DT_CountListFromDay> countlist = new List<DT_CountListFromDay>();
countlist = obj.GetDefaultCountListFromDay2(Type, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId);
List<DT_CountListFromDay> countlist2 = new List<DT_CountListFromDay>();
List<DT_CountListFromDay> countlist3 = new List<DT_CountListFromDay>();
if (Type == 3)
{
countlist2 = obj.GetDefaultCountListFromDay2(4, Ids.Trim(','), SDate, EDate.AddDays(1), CompanyId);
//countlist3 = obj.GetDefaultCountListFromDay2(4, Ids.Trim(','), SDate.AddYears(-1), EDate.AddDays(1).AddYears(-1), CompanyId);
countlist3 = DataNew.GetDefaultCountListFromDay2(4, Ids.Trim(','), SDate.AddYears(-1), EDate.AddDays(1).AddYears(-1), CompanyId);
}
categories = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.AddDays(i)).ToString("MM月dd日");
}
}
if (Type == 3)
{
var smd = new DT_OrderCountContent();
smd.Id = 0;
smd.Name = "总销售额";
listshop.Insert(0, smd);
var _smd = new DT_OrderCountContent();
_smd.Id = -1;
_smd.Name = "去年总销售额";
listshop.Insert(0, _smd);
}
if (listshop != null && listshop.Count > 0)
{
for (int i = 0; i < listshop.Count; i++)
{
decimal[] data = new decimal[days];
if (days > 0)
{
for (int j = 0; j < days; j++)
{
if (listshop[i].Id == 0 && Type == 3)
{
if (countlist2 != null)
{
var countmd2 = countlist2.Find(n => n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd2 != null)
data[j] = countmd2.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
else if (listshop[i].Id == -1 && Type == 3)
{
if (countlist3 != null)
{
var countmd2 = countlist3.Find(n => n.OrderDate == SDate.AddYears(-1).AddDays(j).ToString("yyyy-MM-dd"));
if (countmd2 != null)
data[j] = countmd2.Price.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
else
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.OrderDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (countmd != null && Type == 3)
data[j] = countmd.Price.Value;
else if (countmd != null)
data[j] = countmd.Num.Value;
else
data[j] = 0;
}
else
data[j] = 0;
}
}
}
var datamd = new DT_OrderCountData();
datamd.name = listshop[i].Name;
datamd.data = data;
list.Add(datamd);
}
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 首页订单统计
[WebMethod(EnableSession = true)]
public DT_OrderNum GetDefaultOrderCountMonth2(List<DT_OrderCountContent> listshop, int Type)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
DateTime SDate = Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-01")).AddMonths(-11);
DateTime EDate = DateTime.Today;
List<DT_CountForMonth> countlist = new List<DT_CountForMonth>();
if (Type == 1)
countlist = DataNew.GetDefaultCountListFromMonthPT(SDate, EDate.AddDays(1), CompanyId);
else
countlist = DataNew.GetDefaultCountListFromMonthPTPrice(SDate, EDate.AddDays(1), CompanyId);
List<DT_CountForMonth> countlist2 = new List<DT_CountForMonth>();
if (Type == 1)
countlist2 = DataNew.GetDefaultCountListFromMonth2(SDate, EDate.AddDays(1), CompanyId);
else
countlist2 = DataNew.GetDefaultCountListFromMonthPrice2(SDate, EDate.AddDays(1), CompanyId);
categories = new string[12];
int m = 11;
for (int i = 0; i < 12; i++)
{
categories[i] = (DateTime.Today.AddMonths(-1 * m).Month).ToString() + "月";
m--;
}
if (Type == 1)
{
var smd = new DT_OrderCountContent();
smd.Id = 0;
smd.Name = "总单量";
listshop.Insert(0, smd);
}
else
if (Type == 2)
{
var smd = new DT_OrderCountContent();
smd.Id = 0;
smd.Name = "总销售额";
listshop.Insert(0, smd);
}
if (listshop != null && listshop.Count > 0)
{
for (int i = 0; i < listshop.Count; i++)
{
decimal[] data = new decimal[12];
int m2 = 11;
for (int j = 0; j < 12; j++)
{
if (listshop[i].Id == 0)
{
if (countlist2 != null)
{
var countmd2 = countlist2.Find(n => n.Month == DateTime.Today.AddMonths(-1 * m2).Month);
if (countmd2 != null)
{
if (Type == 1)
data[j] = countmd2.Num.Value;
else
data[j] = countmd2.Price.Value;
}
else
data[j] = 0;
}
else
data[j] = 0;
}
else
{
if (countlist != null)
{
var countmd = countlist.Find(n => n.PlatId == listshop[i].Id && n.Month == DateTime.Today.AddMonths(-1 * m2).Month);
if (countmd != null)
{
if (Type == 1)
data[j] = countmd.Num.Value;
else
data[j] = countmd.Price.Value;
}
else
data[j] = 0;
}
else
data[j] = 0;
}
m2--;
}
var datamd = new DT_OrderCountData();
datamd.name = listshop[i].Name;
datamd.data = data;
list.Add(datamd);
}
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 首页货物销量
[WebMethod(EnableSession = true)]
public DT_OrderNum GetOrderCountGoods(string GoodsCode, DateTime? SDate, DateTime? EDate, int Type)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
EDate = EDate.Value.AddDays(1);
List<DT_Order> countlist = DataNew.Get_OrderGoodsNum(CompanyId, SDate, EDate, GoodsCode);
if (countlist == null)
countlist = new List<DT_Order>();
TimeSpan ts = EDate.Value - SDate.Value;
int days = ts.Days + 1;
if (Type == 2)//10天
days = ts.Days / 10 + 1;
if (Type == 3)//月
{
int year = EDate.Value.Year - SDate.Value.Year;
int month = EDate.Value.Month - SDate.Value.Month;
int total = year * 12 + month;
days = total + 1;
}
categories = new string[days];
for (int i = 0; i < days; i++)
{
if (Type == 1)
categories[i] = SDate.Value.AddDays(i).ToString("MM月dd日");
else if (Type == 2)
categories[i] = SDate.Value.AddDays(i * 10).ToString("MM月dd日") + "-" + SDate.Value.AddDays((i + 1) * 10 - 1).ToString("MM月dd日");
else if (Type == 3)
categories[i] = SDate.Value.AddMonths(i).ToString("MM月");
}
decimal[] data = new decimal[days];
for (int j = 0; j < days; j++)
{
List<DT_Order> glist = new List<DT_Order>();
if (Type == 1)
glist = countlist.FindAll(n => n.OrderDate >= SDate.Value.AddDays(j) && n.OrderDate < SDate.Value.AddDays(j + 1));
else
if (Type == 2)
glist = countlist.FindAll(n => n.OrderDate >= SDate.Value.AddDays(j * 10) && n.OrderDate < SDate.Value.AddDays((j + 1) * 10));
if (Type == 3)
glist = countlist.FindAll(n => n.OrderDate >= Convert.ToDateTime(SDate.Value.AddMonths(j).ToString("yyyy-MM-01")) && n.OrderDate < Convert.ToDateTime(SDate.Value.AddMonths(j + 1).ToString("yyyy-MM-01")));
int GNum = 0;
if (glist != null)
{
foreach (var gmd in glist)
{
GNum += gmd.GoodsNum.Value;
}
}
data[j] = GNum;
}
var datamd = new DT_OrderCountData();
datamd.name = GoodsCode;
datamd.data = data;
list.Add(datamd);
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 首页货物销量
[WebMethod(EnableSession = true)]
public DT_OrderNum GetCountGoodsData(int GoodsId, DateTime SDate, DateTime EDate, int IsGG, int IsDJL, int XL, int XSJE, int DLPM, int XLPM)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
DataNew.SumGoodsCodeData();
string[] categories = null;
DT_OrderNum md = new DT_OrderNum();
var list = new List<DT_OrderCountData>();
EDate = EDate.AddDays(1);
List<DD_GoodsCodeData> countlist = DataNew.GetListGoodsCodeData(SDate, EDate, GoodsId);
if (countlist == null)
countlist = new List<DD_GoodsCodeData>();
TimeSpan ts = EDate - SDate;
int days = ts.Days + 1;
categories = new string[days];
for (int i = 0; i < days; i++)
{
categories[i] = SDate.AddDays(i).ToString("MM月dd日");
}
var datamd = new DT_OrderCountData();
if (IsGG == 1)
{
decimal[] data = new decimal[days];
for (int j = 0; j < days; j++)
{
var dmd = countlist.Find(n => n.OrderDate >= SDate.AddDays(j) && n.OrderDate < SDate.AddDays(j + 1));
if (dmd != null && dmd.Dec1 != null)
data[j] = dmd.Dec1.Value;
else
data[j] = 0;
}
datamd.name = "广告费";
datamd.data = data;
list.Add(datamd);
}
if (IsDJL == 1)
{
decimal[] data2 = new decimal[days];
for (int j = 0; j < days; j++)
{
var dmd = countlist.Find(n => n.OrderDate >= SDate.AddDays(j) && n.OrderDate < SDate.AddDays(j + 1));
if (dmd != null && dmd.Int1 != null)
data2[j] = dmd.Int1.Value;
else
data2[j] = 0;
}
datamd = new DT_OrderCountData();
datamd.name = "点击量";
datamd.data = data2;
list.Add(datamd);
}
if (DLPM == 1)
{
decimal[] data5 = new decimal[days];
for (int j = 0; j < days; j++)
{
var dmd = countlist.Find(n => n.OrderDate >= SDate.AddDays(j) && n.OrderDate < SDate.AddDays(j + 1));
if (dmd != null && dmd.Int2 != null)
data5[j] = dmd.Int2.Value;
else
data5[j] = 0;
}
datamd = new DT_OrderCountData();
datamd.name = "大类排名";
datamd.data = data5;
list.Add(datamd);
}
if (XLPM == 1)
{
decimal[] data6 = new decimal[days];
for (int j = 0; j < days; j++)
{
var dmd = countlist.Find(n => n.OrderDate >= SDate.AddDays(j) && n.OrderDate < SDate.AddDays(j + 1));
if (dmd != null && dmd.Int3 != null)
data6[j] = dmd.Int3.Value;
else
data6[j] = 0;
}
datamd = new DT_OrderCountData();
datamd.name = "小类排名";
datamd.data = data6;
list.Add(datamd);
}
if (XL == 1)
{
decimal[] data3 = new decimal[days];
for (int j = 0; j < days; j++)
{
var dmd = countlist.Find(n => n.OrderDate >= SDate.AddDays(j) && n.OrderDate < SDate.AddDays(j + 1));
if (dmd != null && dmd.Int4 != null)
data3[j] = dmd.Int4.Value;
else
data3[j] = 0;
}
datamd = new DT_OrderCountData();
datamd.name = "成交量";
datamd.data = data3;
list.Add(datamd);
}
if (XSJE == 1)
{
decimal[] data4 = new decimal[days];
for (int j = 0; j < days; j++)
{
var dmd = countlist.Find(n => n.OrderDate >= SDate.AddDays(j) && n.OrderDate < SDate.AddDays(j + 1));
if (dmd != null && dmd.Dec2 != null)
data4[j] = dmd.Dec2.Value;
else
data4[j] = 0;
}
datamd = new DT_OrderCountData();
datamd.name = "成交金额";
datamd.data = data4;
list.Add(datamd);
}
md.categories = categories;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 首页货物销量
[WebMethod(EnableSession = true)]
public List<DD_GoodsCodeData> GetCountGoodsDataList(int GoodsId, DateTime SDate, DateTime EDate, int IsGG, int IsDJL, int XL, int XSJE)
{
PagesNew.Login(this.Session);
var obj = new DD_OrderData();
var list = new List<DT_OrderCountData>();
EDate = EDate.AddDays(1);
var countlist = DataNew.GetListGoodsCodeData2(SDate, EDate, GoodsId);
return countlist;
}
#endregion
#region 保存-用户信息
[WebMethod(EnableSession = true)]
public int Save_JC_UserInfoHWC(JC_UserInfo Model)
{
PagesNew.Login(this.Session);
// int CompanyID = Convert.ToInt32(Session["CompanyId"]);
// Model.CompanyId = CompanyID;
return DataNew.SaveUserInfo(Model);
}
#endregion
#region 分页查询-用户信息
[WebMethod(EnableSession = true)]
public JsonModel<List<JC_UserInfo>> GetListJC_UserInfo(int CompanyID, string Name, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
JsonModel<List<JC_UserInfo>> resultModel = new JsonModel<List<JC_UserInfo>>();
int RowCount = 0;
string Sort = "";
// CompanyID = Convert.ToInt32(Session["CompanyId"]);
RefParameterCollection param = new RefParameterCollection();
if (CompanyID > 0) param.Add("a.CompanyID", "=", CompanyID, DbType.Int32);
param.Add("a.State", ">", 0, DbType.Int32);
param.Add("(UserType", "=", "H", DbType.String);
param.Add("UserType", "=", "M", "or", ")", DbType.String);
if (string.IsNullOrEmpty(Name) == false)
{
param.Add("(Name", "like", Name, DbType.String);
param.Add("UserName", "like", Name, "or", ")", DbType.String);
}
resultModel.DataSource = DataNew.GetListJC_UserInfo(param, PageIndex, PageSize, Sort, out RowCount);
resultModel.RowCount = RowCount;
return resultModel;
}
#endregion
#region 分页查询-用户信息
[WebMethod(EnableSession = true)]
public JsonModel<List<JC_UserInfoNew>> GetListJC_UserInfoForTM(int CompanyID, int DeptID, string Name, int State, int IsRoom, string HuKou, string EmployeeType, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
JsonModel<List<JC_UserInfoNew>> resultModel = new JsonModel<List<JC_UserInfoNew>>();
int RowCount = 0;
string Sort = "UserId";
CompanyID = Convert.ToInt32(Session["CompanyId"]);
RefParameterCollection param = new RefParameterCollection();
param.Add("a.CompanyID", "=", CompanyID, DbType.Int32);
if (DeptID > 0)
param.Add("a.DeptId", "=", DeptID, DbType.Int32);
param.Add("a.State", "=", State, DbType.Int32);
if (IsRoom > -1)
param.Add("a.IsRoom", "=", IsRoom, DbType.Int32);
if (HuKou != "-1")
param.Add("a.HuKou", "=", HuKou, DbType.String);
if (EmployeeType != "-1")
param.Add("a.EmployeeType", "=", EmployeeType, DbType.String);
if (string.IsNullOrEmpty(Name) == false)
{
param.Add("(Name", "like", Name, DbType.String);
param.Add("UserName", "like", Name, "or", ")", DbType.String);
}
param.Add("(UserType", "=", "P", DbType.String);
param.Add("UserType", "=", "M", "or", ")", DbType.String);
resultModel.DataSource = DataNew.GetListJC_UserInfoForTM(param, PageIndex, PageSize, Sort, out RowCount);
resultModel.RowCount = RowCount;
if (resultModel.DataSource != null)
{
foreach (var md in resultModel.DataSource)
{
var rlist = JC_RoleInfoService.GetUserRoleList(md.UserId.Value);
if (rlist != null && rlist.Count > 0)
md.RoleId = rlist[0].RoleId;
}
}
return resultModel;
}
#endregion
#region 保存
[WebMethod(EnableSession = true)]
public int Save_CompanyNew(JC_CompanyNew Model)
{
PagesNew.Login(this.Session);
int Id = DataNew.Save_Company(Model);
JC_UserInfo2 umd = new JC_UserInfo2();
umd.CompanyId = Id;
umd.UserName = Model.UserName;
umd.Password = Model.Password;
umd.UserType = "H";
umd.State = 1;
umd.InDate = DateTime.Now;
umd.IsLogin = 1;
umd.Name = Model.CompanyName;
DataNew.SaveUserInfo2(umd);
return Id;
}
#endregion
#region 保存
[WebMethod(EnableSession = true)]
public int SetGroupName(int guserid, int userid, string groupname)
{
PagesNew.Login(this.Session);
DataNew.SetGroupName(guserid, userid, groupname);
return 1;
}
#endregion
#region 登陆
[WebMethod(EnableSession = true)]
public bool LoginNew2(string UserName, string PassWord)
{
var list = DataNew.LoginNew2(UserName, PassWord);
if (list == null)
{
string Content = "登陆用户名:" + UserName + "密码:" + PassWord + "登陆时间:" + DateTime.Now.ToString() + "登陆ip";
PagesNew.SaveLog(0, "登陆日志", Content, 0);
return false;
}
UserModel model = new UserModel();
if (list.CompanyId > 0) model.CompanyID = list.CompanyId.Value;
model.Name = list.Name;
model.UserID = list.UserId.Value;
model.UserType = list.UserType;
model.UserName = UserName;
model.PassWord = PassWord;
model.CompanyName = list.CompanyName;
if (list.DeptId != null)
model.DeptId = list.DeptId.Value;
else
model.DeptId = 0;
model.Duty = list.Duty;
Session["IsPdf"] = "0";
Session["PT"] = "hwc";
Session["CompanyId"] = model.CompanyID;
Session["DeptId"] = model.DeptId;
Session["Name"] = model.Name;
Session["UserId"] = model.UserID;
Session["UserName"] = model.UserName;
Session["UserType"] = model.UserType;
Session["CompanyName"] = model.CompanyName;
Session["Duty"] = model.Duty;
Session["Login_UserModel"] = model;
//string Content1="登陆用户名:"+UserName+"姓名:"+model.Name+"登陆时间:"+DateTime.Now.ToString()+"登陆ip"+ LoginIp+"";
//Pages.SaveLog(model.UserID,"登陆日志",Content1,0);
//JC_ExpressService.InitExpress(model.CompanyID);
return true;
}
#endregion
#region 登陆
[WebMethod(EnableSession = true)]
public bool LoginNew(string UserName, string PassWord, string ul, string LoginIp)
{
//HttpContext.Current.Request.UserHostAddress
//HttpContext.Current.Request.ServerVariables.GetValues("REMOTE_ADDR")[0]
//string LoginIp = HttpContext.Current.Request.ServerVariables.GetValues("REMOTE_ADDR")[0];
int IsNb = 0;
if (ul.Contains("192.168."))
IsNb = 1;
if (ul.Contains("http://localhost:"))
IsNb = 1;
var list = DataNew.LoginNew(UserName, PassWord, LoginIp, IsNb);
if (list == null)
{
string Content = "登陆用户名:" + UserName + "密码:" + PassWord + "登陆时间:" + DateTime.Now.ToString() + "登陆ip" + LoginIp + "";
PagesNew.SaveLog(0, "登陆日志", Content, 0);
return false;
}
UserModel model = new UserModel();
if (list.CompanyId > 0) model.CompanyID = list.CompanyId.Value;
model.Name = list.Name;
model.UserID = list.UserId.Value;
model.UserType = list.UserType;
model.UserName = UserName;
model.PassWord = PassWord;
model.CompanyName = list.CompanyName;
if (list.DeptId != null)
model.DeptId = list.DeptId.Value;
else
model.DeptId = 0;
model.Duty = list.Duty;
if (list.Mobile3 != null && list.Mobile3 != "")
{
Session["KTSKU"] = list.Mobile3;
}
else
Session["KTSKU"] = "";
Session["IsPdf"] = "0";
Session["CompanyId"] = model.CompanyID;
Session["DeptId"] = model.DeptId;
Session["Name"] = model.Name;
Session["UserId"] = model.UserID;
Session["UserName"] = model.UserName;
Session["UserType"] = model.UserType;
Session["CompanyName"] = model.CompanyName;
Session["Duty"] = model.Duty;
Session["AllShop"] = list.UserCard;//是否查询所有店铺
Session["Login_UserModel"] = model;
//string Content1="登陆用户名:"+UserName+"姓名:"+model.Name+"登陆时间:"+DateTime.Now.ToString()+"登陆ip"+ LoginIp+"";
//Pages.SaveLog(model.UserID,"登陆日志",Content1,0);
//JC_ExpressService.InitExpress(model.CompanyID);
return true;
}
#endregion
#region 读取全部或单个客户经理
[WebMethod(EnableSession = true)]
public List<BaseModel> GetListCustom()
{
PagesNew.Login(this.Session);
int UserId = Convert.ToInt32(Session["UserId"]);
return DataNew.GetListCustom(UserId);
}
#endregion
#region 分页查询
[WebMethod(EnableSession = true)]
public JsonModel<List<JC_CompanyNew>> GetListCompanyList(string cs, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
string where = CustomIO.Base64StringToString(cs);
if (where != "") where = "where " + where.Substring(4);
var resultModel = new JsonModel<List<JC_CompanyNew>>();
int RowCount = 0;
resultModel.DataSource = DataNew.GetListCompany(where, PageIndex, PageSize, "", out RowCount);
resultModel.RowCount = RowCount;
if (resultModel.DataSource != null)
{
foreach (var md in resultModel.DataSource)
{
var umd = DataNew.GetUserInfoMd(md.CompanyID.Value);
if (umd != null)
{
md.UserName = umd.UserName;
md.Password = umd.Password;
}
}
}
return resultModel;
}
#endregion
#region 读取全部或单个机构
[WebMethod(EnableSession = true)]
public List<BaseModel> GetListCompany()
{
PagesNew.Login(this.Session);
int CompanyID = Convert.ToInt32(Session["CompanyId"]);
int UserId = Convert.ToInt32(Session["UserId"]);
return DataNew.GetListCompany1(CompanyID, UserId);
}
#endregion
#region 读取全部或单个机构
[WebMethod(EnableSession = true)]
public List<BaseModel> GetListCompany3()
{
PagesNew.Login(this.Session);
int CompanyID = Convert.ToInt32(Session["CompanyId"]);
int UserId = Convert.ToInt32(Session["UserId"]);
return DataNew.GetListCompany3(CompanyID, UserId);
}
#endregion
#region 读取全部或单个机构
[WebMethod(EnableSession = true)]
public List<BaseModel> GetListCompany2()
{
PagesNew.Login(this.Session);
int CompanyID = Convert.ToInt32(Session["CompanyId"]);
int UserId = Convert.ToInt32(Session["UserId"]);
return DataNew.GetListCompany2(CompanyID, UserId);
}
#endregion
#region 读取菜单
[WebMethod(EnableSession = true)]
public List<JC_MenuList2> GetListMenu2()
{
PagesNew.Login(this.Session);
int UserID = Convert.ToInt32(Session["UserId"]);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
return DataNew.GetListMenu2(UserID, CompanyId);
}
#endregion
#region 读取菜单
[WebMethod(EnableSession = true)]
public void DeleteJC_Company(int CompanyId)
{
PagesNew.Login(this.Session);
DataNew.DeleteJC_Company(CompanyId);
}
#endregion
#region 报表40
[WebMethod(EnableSession = true)]
public string GetReportTable40(DateTime? SDate, DateTime? EDate, int UserId, string GoodsCode)
{
var obj = new BaseService();
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
string tj = "";
string tj2 = "";
if (SDate != null)
{
tj += " and OrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
// tj2 += " b.LastOrderDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
}
if (EDate != null)
{
tj += " and OrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
// tj2 += " and b.LastOrderDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
}
if (UserId > 0)
{
tj2 += " and a.UserId=" + UserId + " ";
}
if (GoodsCode != "")
tj2 += " and e.GoodsCode='" + GoodsCode + "' ";
string sql = @"
select * into #DT_OrderInfoUser from DT_OrderInfo with(nolock) where CompanyId=1 and State>0 and State<3 " + tj + @"
select a.UserId,Num=COUNT(distinct a.GoodsId) into #DT_OrderInfoUser3 from HW_GoodsUser a with(nolock)
inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId
inner join HW_GoodsDetail e with(nolock) on b.GoodsId=e.GoodsId
inner join DT_OrderGoods c with(nolock) on e.DetailId=c.DetailId
inner join #DT_OrderInfoUser d with(nolock) on c.OrderId=d.OrderId and a.ShopId=d.ShopId
where d.CompanyId=1 " + tj2 + @" group by a.UserId
select b.UserId,b.Num,Price=dbo.MoneyUSDChange(a.TotalPrice,a.MoneyCode,a.CompanyId) into #DT_OrderInfoUser2 from #DT_OrderInfoUser a inner join (
select a.UserId,d.OrderId,Num=SUM(c.GoodsNum) from HW_GoodsUser a with(nolock)
inner join HW_GoodsInfo b with(nolock) on a.GoodsId=b.GoodsId
inner join HW_GoodsDetail e with(nolock) on b.GoodsId=e.GoodsId
inner join DT_OrderGoods c with(nolock) on e.DetailId=c.DetailId
inner join #DT_OrderInfoUser d on c.OrderId=d.OrderId and a.ShopId=d.ShopId
where d.CompanyId=1 " + tj2 + @"
group by a.UserId,d.OrderId)b on a.OrderId=b.OrderId
select c.Name,c.UserName,a.*,GoodsNum=d.Num,OutGoods=isnull(e.Num,0),Rate=case when d.Num>0 then isnull(e.Num,0)*1.0/d.Num else 0 end,NoGoods=d.Num-isnull(e.Num,0) from (
select UserId,Num=sum(Num),OrderNum=COUNT(0),Price=SUM(Price) from #DT_OrderInfoUser2
group by UserId)a
inner join JC_UserInfo c on a.UserId=c.UserId
inner join (select UserId,Num=COUNT(distinct GoodsId) from HW_GoodsUser with(nolock)
group by UserId)d on c.UserId=d.UserId
left join #DT_OrderInfoUser3 e on c.UserId=e.UserId
drop table #DT_OrderInfoUser, #DT_OrderInfoUser2, #DT_OrderInfoUser3
";
DataTable dt = obj.GetReportData(sql);
return GetReport2(dt, 40);
}
#endregion
#region 报表
public string GetReport2(DataTable dt, int ReportId)
{
PagesNew.Login(this.Session);
var obj = new BaseService();
var rmd = BaseService.GetReportModel(ReportId);
var rlist = obj.GetRepoartColsList(ReportId);
if (rmd == null || rlist == null)
return "";
StringBuilder html = new StringBuilder();
html.Append("<tr class='HeaderStyle'><th>序号</th>");
foreach (var md in rlist)
{
html.Append("<th>" + md.ColName + "</th>");
}
html.Append("</tr>");
if (dt != null)
{
DataRow row = null;
for (int i = 0; i < dt.Rows.Count; i++)
{
html.Append("<tr class='DataGridRowStyle'><td>" + (i + 1).ToString() + "</td>");
int rowindex = 1;
foreach (var md in rlist)
{
if (dt.Columns.Contains(md.ColValue) == false)
{
html.Append("<td rowindex='" + rowindex + "' rowtr='" + i + "'></td>");
rowindex++;
continue;
}
if (md.IsSum == 1 && i == 0)
{
if (row == null)
row = dt.NewRow();
if (md.ColType == "int")
{
try
{
row[md.ColValue] = Convert.ToInt32(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + " is not null"));
}
catch
{
row[md.ColValue] = 0;
}
}
else if (md.ColType == "dec")
{
try
{
row[md.ColValue] = Convert.ToDecimal(dt.Compute("sum(" + md.ColValue + ")", "" + md.ColValue + " is not null"));
}
catch
{
row[md.ColValue] = 0;
}
}
}
if (dt.Rows[i][md.ColValue] != null && dt.Rows[i][md.ColValue].ToString() != "")
{
string csscolor = "";
if (md.ContionType == "=" && dt.Rows[i][md.ColValue].ToString() == md.SValue)
{
csscolor = md.ColColor;
}
else
if (md.ContionType == ">" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) > Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) < Convert.ToDecimal(md.EValue))
{
csscolor = md.ColColor;
}
else
if (md.ContionType == ">=" && Convert.ToDecimal(dt.Rows[i][md.ColValue]) >= Convert.ToDecimal(md.SValue) && Convert.ToDecimal(dt.Rows[i][md.ColValue]) <= Convert.ToDecimal(md.EValue))
{
csscolor = md.ColColor;
}
if (csscolor != "")
csscolor = "style='color:" + csscolor + "'";
string datav = "";
if (md.ColType == "date1")
datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd");
else
if (md.ColType == "date2")
datav = Convert.ToDateTime(dt.Rows[i][md.ColValue]).ToString("yyyy-MM-dd HH:mm");
else if (md.ColType == "dec")
{
datav = Convert.ToDecimal(dt.Rows[i][md.ColValue]).ToString("0.00");
}
else
datav = dt.Rows[i][md.ColValue].ToString();
html.Append("<td " + csscolor + " rowindex='" + rowindex + "' rowtr='" + i + "'><a uid='" + dt.Rows[i]["UserId"].ToString() + "'>" + datav + "<a></td>");
}
else
html.Append("<td rowindex='" + rowindex + "' rowtr='" + i + "'></td>");
rowindex++;
}
html.Append("</tr>");
}
int hj = 0;
if (row != null)
{
html.Append("<tr class='DataGridRowStyle'><td>合计:</td>");
foreach (var md in rlist)
{
if (dt.Columns.Contains(md.ColValue) == false)
{
html.Append("<td></td>");
continue;
}
if (md.IsSum == 1 && row[md.ColValue] != null)
{
if (hj == 0)
{
hj = 1;
if (row[md.ColValue].ToString().Contains("."))
html.Append("<td>" + Convert.ToDecimal(row[md.ColValue]).ToString("0.00") + "</td>");
else
html.Append("<td>" + row[md.ColValue] + "</td>");
}
else
{
if (row[md.ColValue].ToString().Contains("."))
html.Append("<td>" + Convert.ToDecimal(row[md.ColValue]).ToString("0.00") + "</td>");
else
html.Append("<td>" + row[md.ColValue] + "</td>");
}
}
else
html.Append("<td></td>");
}
html.Append("</tr>");
}
}
return html.ToString();
}
#endregion
#region 分页查询店铺
[WebMethod(EnableSession = true)]
public JsonModel<List<JC_Shop>> GetListJC_ShopForHWC(int CompanyID, int PlatType, string ShopName, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
if (CompanyID == 0) CompanyID = Convert.ToInt32(Session["CompanyId"]);
JsonModel<List<JC_Shop>> resultModel = new JsonModel<List<JC_Shop>>();
int RowCount = 0;
string Sort = "a.DeptId";
RefParameterCollection param = new RefParameterCollection();
param.Add("a.CompanyID", "=", CompanyID, DbType.Int32);
if (PlatType > 0)
param.Add("PlatType", "=", PlatType, DbType.Int32);
if (string.IsNullOrEmpty(ShopName) == false)
param.Add("ShopName", "like", ShopName, DbType.String);
resultModel.DataSource = DataNew.GetListJC_ShopForHWC(param, PageIndex, PageSize, Sort, out RowCount);
resultModel.RowCount = RowCount;
return resultModel;
}
#endregion
#region 保存店铺
[WebMethod(EnableSession = true)]
public string Save_ShopHWC(JC_Shop Model)
{
PagesNew.Login(this.Session);
Model.InDate = DateTime.Now;
int ShopId = JC_ShopService.SaveShop(Model);
return "成功";
}
#endregion
#region 平台店铺
[WebMethod(EnableSession = true)]
public List<JC_Shop> GetShopList(int PlatType, int CompanyId)
{
PagesNew.Login(this.Session);
var list = DataNew.GetShopList(CompanyId, PlatType);
return list;
}
#endregion
#region 报表16
[WebMethod(EnableSession = true)]
public string GetReportTable16(DateTime? SDate, DateTime? EDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
var obj = new BaseService();
if (EDate == null)
EDate = DateTime.Now;
string tj = "";
string tj1 = "";
if (DeptId > 0)
{
tj += " and b.DeptId=" + DeptId + " ";
tj1 += " and a.DeptId=" + DeptId + " ";
}
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
string endtime = Convert.ToDateTime(EDate.ToString()).AddDays(1).ToString();
if (MoneyCode != "0")
tj += " and a.MoneyCode='" + MoneyCode + "' ";
string sql = @"
select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end from JC_Shop a
inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a
inner join JC_Shop b on a.ShopId=b.ShopId
where a.State>0 " + tj + " and a.State<3 and a.OrderDate>='" + SDate + "' and a.OrderDate<'" + endtime + @"' group by b.ShopId)c on a.ShopId=c.ShopId
where a.CompanyId=1 " + tj1 + " order by " + Sort;
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 16);
}
#endregion
#region 报表16
[WebMethod(EnableSession = true)]
public string GetReportExcel16(DateTime? SDate, DateTime? EDate, int DeptId, int ShopId, int PlatId, string MoneyCode, string Sort)
{
var obj = new BaseService();
string tj = "";
string tj1 = "";
if (DeptId > 0)
{
tj += " and b.DeptId=" + DeptId + " ";
tj1 += " and a.DeptId=" + DeptId + " ";
}
if (PlatId > 0)
{
tj += " and b.PlatType=" + PlatId + " ";
tj1 += " and a.PlatType=" + PlatId + " ";
}
if (ShopId > 0)
{
tj += " and b.ShopId=" + ShopId + " ";
tj1 += " and a.ShopId=" + ShopId + " ";
}
string endtime = Convert.ToDateTime(EDate.ToString()).AddDays(1).ToString();
if (MoneyCode != "0")
tj += " and a.MoneyCode='" + MoneyCode + "' ";
string sql = @"
select a.ShopName,OrderNum=isnull(c.OrderNum,0),USDMoney=isnull(c.USDMoney,0),RMBMoney=isnull(c.RMBMoney,0),AvgPrice=case when c.OrderNum is null or c.USDMoney is null or c.OrderNum=0 then 0 else c.USDMoney/c.OrderNum end from JC_Shop a
inner join (select b.ShopId,OrderNum=COUNT(0),USDMoney=SUM(dbo.MoneyUSDChange(TotalPrice,a.MoneyCode,a.CompanyId)),RMBMoney=SUM(dbo.MoneyChange(TotalPrice,a.MoneyCode,a.CompanyId)) from DT_OrderInfo a
inner join JC_Shop b on a.ShopId=b.ShopId
where a.State>0 " + tj + " and a.State<3 and a.OrderDate>='" + SDate + "' and a.OrderDate<='" + endtime + @"' group by b.ShopId)c on a.ShopId=c.ShopId
where a.CompanyId=1 " + tj1 + " order by " + Sort;
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 16);
}
#endregion
#region 报表45
[WebMethod(EnableSession = true)]
public string GetReportTable45(DateTime? SDate, DateTime? EDate, string GoodsCode)
{
var obj = new BaseService();
if (EDate == null)
EDate = DateTime.Now;
string tj = "";
string tj1 = "";
if (GoodsCode != "")
tj += " and e.GoodsCode='" + GoodsCode + "'";
string sql = @"
select a.PlatOrderCode,e.GoodsCode,d.TrackCode,b.PostFee,feew=dbo.GetPostFeeNew(a.OrderId,6,a.Fee6,a.Fee7,a.Fee8,a.Fee11,a.Fee12,a.Fee13,b.RevFax),feee=dbo.GetPostFeeNew(a.OrderId,11,a.Fee6,a.Fee7,a.Fee8,a.Fee11,a.Fee12,a.Fee13,b.RevFax),h.PostionCode from DT_OrderInfo a with(nolock)
inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId
inner join DT_OrderGoods c with(nolock) on a.OrderId=c.OrderId
inner join HW_GoodsDetail f with(nolock) on c.DetailId=f.DetailId
inner join HW_GoodsInfo e with(nolock) on f.GoodsId=e.GoodsId
inner join DT_TrackCodeApply d with(nolock) on a.OrderId=d.OrderId and d.State=1
inner join HW_GoodsInDetail g with(nolock) on c.Id=g.OrderGoodsId
inner join CK_StorePostion h with(nolock) on g.PostionId=h.PostionId
where a.State>0 and a.State<3 " + tj + " and a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 45);
}
#endregion
#region 报表16
[WebMethod(EnableSession = true)]
public string GetReportExcel45(DateTime? SDate, DateTime? EDate, string GoodsCode)
{
var obj = new BaseService();
string tj = "";
if (GoodsCode != "")
tj += " and e.GoodsCode='" + GoodsCode + "'";
string sql = @"
select a.PlatOrderCode,e.GoodsCode,d.TrackCode,b.PostFee,feew=dbo.GetPostFeeNew(a.OrderId,6,a.Fee6,a.Fee7,a.Fee8,a.Fee11,a.Fee12,a.Fee13,b.RevFax),feee=dbo.GetPostFeeNew(a.OrderId,11,a.Fee6,a.Fee7,a.Fee8,a.Fee11,a.Fee12,a.Fee13,b.RevFax),h.PostionCode from DT_OrderInfo a with(nolock)
inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId
inner join DT_OrderGoods c with(nolock) on a.OrderId=c.OrderId
inner join HW_GoodsDetail f with(nolock) on c.DetailId=f.DetailId
inner join HW_GoodsInfo e with(nolock) on f.GoodsId=e.GoodsId
inner join DT_TrackCodeApply d with(nolock) on a.OrderId=d.OrderId and d.State=1
inner join HW_GoodsInDetail g with(nolock) on c.Id=g.OrderGoodsId
inner join CK_StorePostion h with(nolock) on g.PostionId=h.PostionId
where a.State>0 and a.State<3 " + tj + " and a.PostDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "'";
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 45);
}
#endregion
[WebMethod(EnableSession = true)]
public JsonModel<List<DT_OrderBackMoneyApply>> GetListJC_OrderBack2(int ShopId, string Reason1, string Name, int CheckState1, int CheckState2, DateTime? SDate, DateTime? EDate, int PageIndex, int PageSize)
{
PagesNew.Login(base.Session);
DD_OrderData data = new DD_OrderData();
int num = Convert.ToInt32(base.Session["UserId"]);
int num2 = Convert.ToInt32(base.Session["DeptId"]);
string str = Convert.ToString(base.Session["Name"]);
string str2 = Convert.ToString(base.Session["Duty"]);
RefParameterCollection where = new RefParameterCollection();
if (((str2 != "副总经理") && (str2 != "总经理")) && (str2 != "经理"))
{
where.Add("a.InUserId", "=", num, DbType.Int32);
}
if (ShopId > 0)
{
where.Add("a.ShopId", "=", ShopId, DbType.String);
}
if (CheckState1 != -1)
{
where.Add("a.State", "=", CheckState1, DbType.Int32);
}
if (CheckState2 == 1)
{
where.Add("a.CompanyAgree2", "=", "同意赔款", DbType.String);
}
else if (CheckState2 == 2)
{
where.Add("a.CompanyAgree2", "=", "不同意赔款", DbType.String);
}
else if (CheckState2 == 0)
{
where.Add("isnull(a.CompanyAgree2,'')", "=", "", DbType.String);
}
if (Name != "")
{
where.Add("(a.InName", "like", Name, DbType.String);
where.Add("a.OrderCode", "like", Name, "or", DbType.String);
where.Add("a.GoodsCode", "like", Name, "or", ")", DbType.String);
}
if (SDate.HasValue)
{
where.Add("a.InDate", ">=", SDate, DbType.DateTime);
}
if (EDate.HasValue)
{
where.Add("a.InDate", "<", EDate.Value.AddDays(1.0), DbType.DateTime);
}
if (Reason1 != "0")
{
where.Add("a.BackReason1", "=", Reason1, DbType.String);
}
JsonModel<List<DT_OrderBackMoneyApply>> model = new JsonModel<List<DT_OrderBackMoneyApply>>();
int rowCount = 0;
string sort = "c.OrderDate desc";
model.DataSource = data.GetListDT_OrderBackMoneyApply2(where, PageIndex, PageSize, sort, out rowCount);
model.RowCount = rowCount;
if (model.DataSource != null)
{
string str4 = "";
List<DT_OrderUser> list = new List<DT_OrderUser>();
List<DT_OrderUser> list2 = new List<DT_OrderUser>();
foreach (DT_OrderBackMoneyApply apply in model.DataSource)
{
str4 = str4 + apply.OrderId.Value.ToString() + ",";
}
if (str4 != "")
{
list = DataNew.Get_OrderGoodsForBack(str4.TrimEnd(new char[] { ',' }));
list2 = data.Get_OrderGoodsForBack2(str4.TrimEnd(new char[] { ',' }));
}
if (list == null)
{
list = new List<DT_OrderUser>();
}
if (list2 == null)
{
list2 = new List<DT_OrderUser>();
}
decimal num4 = Convert.ToDecimal((double)6.5);
List<JC_Money> list3 = new BaseService().GetMoneyList2();
using (List<DT_OrderBackMoneyApply>.Enumerator enumerator = model.DataSource.GetEnumerator())
{
Predicate<JC_Money> match = null;
Predicate<DT_OrderUser> predicate2 = null;
Predicate<DT_OrderUser> predicate3 = null;
DT_OrderBackMoneyApply md;
while (enumerator.MoveNext())
{
decimal? nullable2;
decimal num12;
md = enumerator.Current;
decimal num5 = 0M;
if (match == null)
{
match = n => (n.PlatId == md.PlatId) && (n.MCode == "USD");
}
JC_Money money = list3.Find(match);
if (money != null)
{
num4 = money.MRate.Value;
}
decimal num6 = 0M;
int? platId = md.PlatId;
if ((platId.GetValueOrDefault() == 1) && platId.HasValue)
{
num6 = Convert.ToDecimal((double)0.05);
}
else
{
platId = md.PlatId;
if (((platId.GetValueOrDefault() == 2) && platId.HasValue) || (((platId = md.PlatId).GetValueOrDefault() == 3) && platId.HasValue))
{
num6 = Convert.ToDecimal((double)0.15);
}
else
{
platId = md.PlatId;
if ((platId.GetValueOrDefault() == 5) && platId.HasValue)
{
num6 = Convert.ToDecimal((double)0.1);
}
}
}
if (md.OrderPrice.HasValue)
{
num12 = md.OrderPrice.Value * num6;
md.YJPrice = new decimal?(Convert.ToDecimal(num12.ToString("0.00")));
}
else
{
md.YJPrice = 0;
}
decimal num7 = md.OrderPrice.Value;
platId = md.OrderState;
if ((platId.GetValueOrDefault() == 0) && platId.HasValue)
{
num12 = md.YJPrice.Value * Convert.ToDecimal((double)0.2);
md.YJPrice = new decimal?(Convert.ToDecimal(num12.ToString("0.00")));
num7 = 0M;
}
if (predicate2 == null)
{
predicate2 = n => n.OrderId == md.OrderId;
}
List<DT_OrderUser> list4 = list.FindAll(predicate2);
if (predicate3 == null)
{
predicate3 = n => n.OrderId == md.OrderId;
}
List<DT_OrderUser> list5 = list2.FindAll(predicate3);
decimal num8 = 0M;
if (list4 != null)
{
foreach (DT_OrderUser user in list4)
{
num12 = (user.GDFee.Value + user.Fee1.Value) / num4;
num8 += Convert.ToDecimal(num12.ToString("0.00")) + user.Fee2.Value;
}
}
md.GoodsFee = new decimal?(num8);
platId = md.BackState;
if (((platId.GetValueOrDefault() == 1) && platId.HasValue) || (((platId = md.BackState).GetValueOrDefault() == 3) && platId.HasValue))
{
md.GoodsFee = 0;
}
md.OnePostFee = 0;
md.PostRate = 0;
if ((list5 != null) && (list5.Count > 0))
{
md.OnePostFee = list5[0].Fee1;
if (list5[0].PostId == 0x41)
{
md.PostRate = new decimal?(list5[0].Fee1.Value * Convert.ToDecimal((double)0.1));
}
}
decimal num9 = 0M;
if (md.PostFee.HasValue && (((nullable2 = md.PostFee).GetValueOrDefault() > 0M) && nullable2.HasValue))
{
num9 = md.PostFee.Value;
}
decimal num10 = 0M;
if (md.FactPrice.HasValue && (((nullable2 = md.FactPrice).GetValueOrDefault() > 0M) && nullable2.HasValue))
{
num10 = md.FactPrice.Value;
}
num5 = ((((((num7 - md.YJPrice.Value) - md.escrowFee.Value) - md.GoodsFee.Value) - md.OnePostFee.Value) - md.PostRate.Value) - num10) - num9;
md.LRFee = new decimal?(num5);
}
}
}
return model;
}
[WebMethod(EnableSession = true)]
public string GetListJC_OrderBackExcel(int ShopId, string Reason1, string Name, int CheckState1, int CheckState2, DateTime? SDate, DateTime? EDate, int PageIndex, int PageSize)
{
PagesNew.Login(base.Session);
DD_OrderData data = new DD_OrderData();
int num = Convert.ToInt32(base.Session["UserId"]);
int num2 = Convert.ToInt32(base.Session["DeptId"]);
string str = Convert.ToString(base.Session["Name"]);
string str2 = Convert.ToString(base.Session["Duty"]);
RefParameterCollection where = new RefParameterCollection();
if (((str2 != "副总经理") && (str2 != "总经理")) && (str2 != "经理"))
{
where.Add("a.InUserId", "=", num, DbType.Int32);
}
if (ShopId > 0)
{
where.Add("a.ShopId", "=", ShopId, DbType.String);
}
if (CheckState1 != -1)
{
where.Add("a.State", "=", CheckState1, DbType.Int32);
}
if (CheckState2 == 1)
{
where.Add("a.CompanyAgree2", "=", "同意赔款", DbType.String);
}
else if (CheckState2 == 2)
{
where.Add("a.CompanyAgree2", "=", "不同意赔款", DbType.String);
}
else if (CheckState2 == 0)
{
where.Add("isnull(a.CompanyAgree2,'')", "=", "", DbType.String);
}
if (Name != "")
{
where.Add("(a.InName", "like", Name, DbType.String);
where.Add("a.OrderCode", "like", Name, "or", DbType.String);
where.Add("a.GoodsCode", "like", Name, "or", ")", DbType.String);
}
if (SDate.HasValue)
{
where.Add("a.InDate", ">=", SDate, DbType.DateTime);
}
if (EDate.HasValue)
{
where.Add("a.InDate", "<", EDate.Value.AddDays(1.0), DbType.DateTime);
}
if (Reason1 != "0")
{
where.Add("a.BackReason1", "=", Reason1, DbType.String);
}
int rowCount = 0;
string sort = "c.OrderDate desc";
List<DT_OrderBackMoneyApply> listModel = data.GetListDT_OrderBackMoneyApply2(where, PageIndex, PageSize, sort, out rowCount);
if (listModel != null)
{
string str4 = "";
List<DT_OrderUser> list2 = new List<DT_OrderUser>();
List<DT_OrderUser> list3 = new List<DT_OrderUser>();
foreach (DT_OrderBackMoneyApply apply in listModel)
{
str4 = str4 + apply.OrderId.Value.ToString() + ",";
}
if (str4 != "")
{
list2 = DataNew.Get_OrderGoodsForBack(str4.TrimEnd(new char[] { ',' }));
list3 = data.Get_OrderGoodsForBack2(str4.TrimEnd(new char[] { ',' }));
}
if (list2 == null)
{
list2 = new List<DT_OrderUser>();
}
if (list3 == null)
{
list3 = new List<DT_OrderUser>();
}
decimal num4 = Convert.ToDecimal((double)6.5);
List<JC_Money> list4 = new BaseService().GetMoneyList2();
using (List<DT_OrderBackMoneyApply>.Enumerator enumerator = listModel.GetEnumerator())
{
Predicate<JC_Money> match = null;
Predicate<DT_OrderUser> predicate2 = null;
Predicate<DT_OrderUser> predicate3 = null;
DT_OrderBackMoneyApply md;
while (enumerator.MoveNext())
{
decimal? nullable2;
decimal num12;
md = enumerator.Current;
decimal num5 = 0M;
if (match == null)
{
match = n => (n.PlatId == md.PlatId) && (n.MCode == "USD");
}
JC_Money money = list4.Find(match);
if (money != null)
{
num4 = money.MRate.Value;
}
decimal num6 = 0M;
int? platId = md.PlatId;
if ((platId.GetValueOrDefault() == 1) && platId.HasValue)
{
num6 = Convert.ToDecimal((double)0.05);
}
else
{
platId = md.PlatId;
if (((platId.GetValueOrDefault() == 2) && platId.HasValue) || (((platId = md.PlatId).GetValueOrDefault() == 3) && platId.HasValue))
{
num6 = Convert.ToDecimal((double)0.15);
}
else
{
platId = md.PlatId;
if ((platId.GetValueOrDefault() == 5) && platId.HasValue)
{
num6 = Convert.ToDecimal((double)0.1);
}
}
}
if (md.OrderPrice.HasValue)
{
num12 = md.OrderPrice.Value * num6;
md.YJPrice = new decimal?(Convert.ToDecimal(num12.ToString("0.00")));
}
else
{
md.YJPrice = 0;
}
decimal num7 = md.OrderPrice.Value;
platId = md.OrderState;
if ((platId.GetValueOrDefault() == 0) && platId.HasValue)
{
num12 = md.YJPrice.Value * Convert.ToDecimal((double)0.2);
md.YJPrice = new decimal?(Convert.ToDecimal(num12.ToString("0.00")));
num7 = 0M;
}
if (predicate2 == null)
{
predicate2 = n => n.OrderId == md.OrderId;
}
List<DT_OrderUser> list5 = list2.FindAll(predicate2);
if (predicate3 == null)
{
predicate3 = n => n.OrderId == md.OrderId;
}
List<DT_OrderUser> list6 = list3.FindAll(predicate3);
decimal num8 = 0M;
if (list5 != null)
{
foreach (DT_OrderUser user in list5)
{
num12 = (user.GDFee.Value + user.Fee1.Value) / num4;
num8 += Convert.ToDecimal(num12.ToString("0.00")) + user.Fee2.Value;
}
}
md.GoodsFee = new decimal?(num8);
platId = md.BackState;
if (((platId.GetValueOrDefault() == 1) && platId.HasValue) || (((platId = md.BackState).GetValueOrDefault() == 3) && platId.HasValue))
{
md.GoodsFee = 0;
}
md.OnePostFee = 0;
md.PostRate = 0;
if ((list6 != null) && (list6.Count > 0))
{
md.OnePostFee = list6[0].Fee1;
if (list6[0].PostId == 0x41)
{
md.PostRate = new decimal?(list6[0].Fee1.Value * Convert.ToDecimal((double)0.1));
}
}
decimal num9 = 0M;
if (md.PostFee.HasValue && (((nullable2 = md.PostFee).GetValueOrDefault() > 0M) && nullable2.HasValue))
{
num9 = md.PostFee.Value;
}
decimal num10 = 0M;
if (md.FactPrice.HasValue && (((nullable2 = md.FactPrice).GetValueOrDefault() > 0M) && nullable2.HasValue))
{
num10 = md.FactPrice.Value;
}
num5 = ((((((num7 - md.YJPrice.Value) - md.escrowFee.Value) - md.GoodsFee.Value) - md.OnePostFee.Value) - md.PostRate.Value) - num10) - num9;
md.LRFee = new decimal?(num5);
}
}
}
DataTable tb = listModel.ToDataTable<DT_OrderBackMoneyApply>();
TableColumnCollection columns = new TableColumnCollection();
columns.Add("ShopName", "店铺", DbType.String, "");
columns.Add("OrderCode", "订单号", DbType.String, "");
columns.Add("GoodsCode", "货物编号", DbType.String, "");
columns.Add("BackReason1", "订单日期", DbType.String, "");
columns.Add("OrderDate", "赔款原因", DbType.String, "yyyy-MM-dd");
columns.Add("BackAdvise", "赔款初步方案", DbType.String, "");
columns.Add("BackAdvise2", "赔款最终方案", DbType.String, "");
columns.Add("OrderStateName", "订单状态", DbType.String, "");
columns.Add("OrderPrice", "订单原金额", DbType.String, "");
columns.Add("YJPrice", "佣金$", DbType.String, "");
columns.Add("escrowFee", "税费", DbType.String, "");
columns.Add("GoodsFee", "货物成本", DbType.String, "");
columns.Add("OnePostFee", "首次运费", DbType.String, "");
columns.Add("PostRate", "运费佣金", DbType.String, "");
columns.Add("FactPrice", "实际赔款", DbType.String, "");
columns.Add("PostFee", "我们承担退货运费", DbType.String, "");
columns.Add("LRFee", "利润", DbType.String, "");
columns.Add("BackStateName", "退货仓库验货", DbType.String, "");
columns.Add("StateName", "处理状态", DbType.String, "");
columns.Add("InName", "提交人", DbType.String, "");
columns.Add("CompanyRemark", "领导意见1", DbType.String, "");
columns.Add("CompanyRemark2", "领导意见2", DbType.String, "");
MicrosoftExcel excel = new MicrosoftExcel();
return excel.Export(tb, columns);
}
#region 普通查询列表
[WebMethod(EnableSession = true)]
public List<JC_Shop> GetListShop22()
{
PagesNew.Login(this.Session);
var ListModel = DataNew.GetMyShop22();
return ListModel;
}
#endregion
#region wish店铺授权
[WebMethod(EnableSession = true)]
public string WishGetAccessToken(int ShopId, string client_id, string client_secret, string code, string redirect_uri)
{
PagesNew.Login(this.Session);
WishNew obj = new WishNew();
obj.ShopId = ShopId;
obj.client_id = client_id;
obj.client_secret = client_secret;
obj.code = code;
obj.grant_type = "authorization_code";
obj.redirect_uri = redirect_uri;
string errormess = "";
string mess = obj.GetTokenV3(out errormess);
if (errormess != "")
return "错误:" + errormess;
return mess;
}
#endregion
#region 首页订单数
[WebMethod(EnableSession = true)]
public DT_DefaultDataNew GetDefaultDataForTM2(DateTime? st, Decimal MRate)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
BaseService obj = new BaseService();
// DateTime st=new DateTime();
// st =Convert.ToDateTime("2014-04-10");
DateTime sdate = Convert.ToDateTime(DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"));
DateTime edate = Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-dd"));
var model = DataNew.GetDefaultDataForTM2(CompanyId, st, st.Value.AddDays(-1), sdate, edate);
//if (model != null)
//{
// model.AddPrice = model.TotalPrice * MRate;
//}
return model;
}
#endregion
#region 首页订单数
[WebMethod(EnableSession = true)]
public DT_DefaultDataNew GetDefaultDataForTM3()
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
BaseService obj = new BaseService();
// DateTime st=new DateTime();
// st =Convert.ToDateTime("2014-04-10");
DateTime sdate = DateTime.Today.AddDays(-1);
DateTime sdate2 = Convert.ToDateTime(DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd") + " 08:00");
DateTime edate2 = Convert.ToDateTime(DateTime.Today.ToString("yyyy-MM-dd") + " 08:00");
var model = DataNew.GetDefaultDataForTM3(CompanyId, sdate, sdate2, edate2);
//if (model != null)
//{
// model.AddPrice = model.TotalPrice * MRate;
//}
return model;
}
#endregion
#region 读取菜单
[WebMethod(EnableSession = true)]
public List<JC_MenuListNew> GetListMenuNew()
{
PagesNew.Login(this.Session);
int UserID = Convert.ToInt32(Session["UserId"]);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
return DataNew.GetListMenuNew(UserID, CompanyId);
}
#endregion
#region 报表25
[WebMethod(EnableSession = true)]
public string GetReportTable25(DateTime? SDate, DateTime? EDate)
{
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
if (SDate != null)
tj += " a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select InDate=CONVERT(varchar(10), a.indate, 23),b.Name,Num=count(distinct TrackCode) from DT_TrackCodeScan a
inner join JC_UserInfo b on a.BagUserId=b.UserId
where " + tj + " group by CONVERT(varchar(10), a.indate, 23),b.Name";
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 28);
}
#endregion
#region 报表25
[WebMethod(EnableSession = true)]
public string GetExcelTable25(DateTime? SDate, DateTime? EDate)
{
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
if (SDate != null)
tj += " a.InDate>='" + SDate.Value.ToString("yyyy-MM-dd") + "' ";
if (EDate != null)
tj += " and a.InDate<'" + EDate.Value.AddDays(1).ToString("yyyy-MM-dd") + "' ";
string sql = @"select InDate=CONVERT(varchar(10), a.indate, 23),b.Name,Num=count(distinct TrackCode) from DT_TrackCodeScan a
inner join JC_UserInfo b on a.BagUserId=b.UserId
where " + tj + " group by CONVERT(varchar(10), a.indate, 23),b.Name";
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 28);
}
#endregion
#region 计算费用
[WebMethod(EnableSession = true)]
public int GetModel_OrderFee2()
{
PagesNew.Login(this.Session);
int a = DataNew.GetModel_OrderFee2();
return a;
}
#endregion
[WebMethod(EnableSession = true)]
public string GetListUSMap(string GoodsCode, DateTime? Sdate, DateTime? edate)
{
if (!Sdate.HasValue)
{
Sdate = new DateTime?(DateTime.Today.AddDays(-100.0));
}
if (!edate.HasValue)
{
edate = new DateTime?(DateTime.Today);
}
BaseService.SetData();
List<DT_USMap> list = BaseService.GetListUSOrder(GoodsCode, Sdate, new DateTime?(edate.Value.AddDays(1.0)));
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(list);
}
[WebMethod(EnableSession = true)]
public string GetListUSMap2()
{
DateTime Sdate = DateTime.Today.AddDays(-1);
// BaseService.SetData();
List<DT_USMap> list = DataNew.GetListUSOrder("", Sdate, Sdate.AddDays(1));
JavaScriptSerializer serializer = new JavaScriptSerializer();
return serializer.Serialize(list);
}
[WebMethod(EnableSession = true)]
public JC_ShopDataNew GetStoreFeeCount()
{
PagesNew.Login(this.Session);
var md = DataNew.GetStoreFeeCount();
return md;
}
#region 货物SKU
[WebMethod(EnableSession = true)]
public string GetGoodSKUKC(string GoodsCode)
{
PagesNew.Login(this.Session);
try
{
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
if (GoodsCode != "")
{
tj += " and (b.SKU1='" + GoodsCode + "' or b.SKU2='" + GoodsCode + "' or b.SKU3='" + GoodsCode + "' or b.SKU4='" + GoodsCode + "' ) ";
}
string sql = @"
select SKU1,KCNum=SUM(a.KCNum) from HW_GoodsInDetail a with(nolock)
inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId
where a.storeid in (6,9,11) and a.OrderGoodsId=0 and a.KCNum>0 " + tj + " group by b.sku1 ";
// ErrorFollow.TraceWrite("GetFedex", "", sql);
DataTable dt = obj.GetReportData(sql);
return GetReport3(dt, 22);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("GetFedex", "", ex.Message);
return "";
}
}
#endregion
#region 货物SKU
[WebMethod(EnableSession = true)]
public string GetExcelGoodSKUKC(string GoodsCode)
{
PagesNew.Login(this.Session);
var obj = new BaseService();
string CompanyId = Session["CompanyId"].ToString();
string tj = "";
if (GoodsCode != "")
{
tj += " and (b.SKU1='" + GoodsCode + "' or b.SKU2='" + GoodsCode + "' or b.SKU3='" + GoodsCode + "' or b.SKU4='" + GoodsCode + "' ) ";
}
string sql = @"
select SKU1,KCNum=SUM(a.KCNum) from HW_GoodsInDetail a with(nolock)
inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId
where a.storeid in (6,9,11) and a.OrderGoodsId=0 and a.KCNum>0 " + tj + " group by b.sku1 ";
DataTable dt = obj.GetReportData(sql);
return GetExcelReport(dt, 22);
}
#endregion
#region 保存财务每天必填资金流数据
[WebMethod(EnableSession = true)]
public int SaveFinanceFundData(FinanceFundData Model)
{
PagesNew.Login(this.Session);
if (Model.ID == null || Model.ID.Value == 0)
Model.CreateTime = DateTime.Now;
Model.CreateUserId = Convert.ToInt32(Session["UserId"]);
int companyId = Convert.ToInt32(Session["CompanyId"]);
var moneyObj = DataNew.GetFinanceFundMoneyData(companyId);
if (moneyObj != null)
{
Model.WI = moneyObj.RCRate;
Model.EI = moneyObj.ECRate;
Model.OI = moneyObj.ZTPrice;
Model.KI = moneyObj.YYCRate;
Model.FAM = moneyObj.DJMoney;
Model.TOTAL = ((Model.WI.HasValue ? Model.WI.Value : 0) + (Model.EI.HasValue ? Model.EI.Value : 0) + Model.BA) * Model.Rate + (Model.OI.HasValue ? Model.OI.Value : 0) + (Model.KI.HasValue ? Model.KI.Value : 0) + Model.CA - Model.FN + Model.FD;
}
int Id = DataNew.SaveFinanceFundData(Model);
return Id;
}
#endregion
#region 获取财务每天必填资金流数据
[WebMethod(EnableSession = true)]
public JsonModel<List<FinanceFundData>> GetFinanceFundDataList(DateTime? SDate, DateTime? EDate, int PageSize, int PageIndex)
{
PagesNew.Login(this.Session);
var jsonModel = new JsonModel<List<FinanceFundData>>();
int rowCount = 0;
jsonModel.DataSource = DataNew.GetFinanceFundDataList(SDate, EDate, PageSize, PageIndex, out rowCount);
jsonModel.RowCount = rowCount;
return jsonModel;
}
#endregion
#region 删除财务每天必填资金流数据
[WebMethod(EnableSession = true)]
public void DeleteFinanceFundData(int id)
{
PagesNew.Login(this.Session);
DataNew.DeleteFinanceFundData(id);
}
#endregion
#region 获取昨天的财务每天必填资金流数据汇率
[WebMethod(EnableSession = true)]
public decimal GetLastDayFinanceFundRateData()
{
PagesNew.Login(this.Session);
return DataNew.GetLastDayFinanceFundRateData();
}
#endregion
#region 获取昨天财务每天必填资金流汇总数据
[WebMethod(EnableSession = true)]
public decimal GetLastDayFinanceFundTotalData()
{
PagesNew.Login(this.Session);
return DataNew.GetLastDayFinanceFundTotalData();
}
#endregion
#region 获取个人每天的广告花费、销售数据
[WebMethod(EnableSession = true)]
public JsonModel<List<PeopleDaySaleDataModel>> GetPeopleDaySaleDatas(int userid, DateTime? SDate, DateTime? EDate, int PageSize, int PageIndex)
{
PagesNew.Login(this.Session);
var jsonModel = new JsonModel<List<PeopleDaySaleDataModel>>();
var rdatas = new List<PeopleDaySaleDataModel>();
//所有平台的总数居
var tdatas = new List<PeopleDaySaleDataModel>();
var kclist = new List<PeopleGoodsNum>();
var kcFeelist = new List<PeopleDayStockFeeModel>();
var zxtAllDatas = new List<PeopleDaySalePriceModel>();
var zxtMonthAllDatas = new List<PeopleDaySalePriceModel>();
var HJLRDaysDatas = new List<PeoPleHJLRModel>();
var amaZonHJLRDaysDatas = new List<PeoPleHJLRModel>();
var datas = new List<PeopleDaySaleDataModel>();
//总的每天折线图汇总数据
var totalzxtDatas = new List<PeopleDaySalePriceModel>();
//总的每月折线图汇总数据
var totalzxtMonthDatas = new List<PeopleDaySalePriceModel>();
DateTime sdt = DateTime.Now.Date, edt = DateTime.Now.Date;
if (DateTime.Now.Day == 1)//如果当天是一号,则取上个月的三十天数据
{
sdt = DateTime.Now.AddMonths(-1).Date;
edt = DateTime.Now.AddDays(-1).Date;
}
else //否则日期区间从1号开始到当前日期前一天
{
sdt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).Date;//当前月份第一天的日期
edt = DateTime.Now.AddDays(-1).Date;//当前日期前一天
}
var firstDay = new DateTime(DateTime.Now.AddMonths(-6).Year, DateTime.Now.AddMonths(-6).Month, 1).Date;//当前月份六个月前的第一天
//var lastDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1);//当前月份上个月的最后一天
var lastDay = DateTime.Now.AddDays(-1).Date;//当前日期前一天
var deptid = userid == 0 ? 0 : DataNew.GetDepartIdByUserid(userid);
#region 亚马逊平台数据
if (deptid == 0 || deptid == 1) //亚马逊平台
{
//一组,二组,三组人员分开,并且每组加一条组汇总数据
var group1ps = Group1Peoples;//一组人员
var group2ps = Group2Peoples;//二组人员
var group3ps = Group3Peoples;//三组人员
var group4ps = Group4Peoples;//四组人员
//亚马逊平台数据 运营1-10管理可以看到所有亚马逊
datas = DataNew.GetPeopleDaySaleDatasList(userid == 223 ? 0 : userid, SDate, EDate);
if (userid == 190)
{
datas.AddRange(DataNew.GetPeopleDaySaleDatasList(60, SDate, EDate));
}
if (datas != null && datas.Count > 0)
tdatas.AddRange(datas);
//库存总金额
kclist = DataNew.GetPeopleGoodsNum().Where(r => r.PlatId == 2).ToList();
//亚马逊平台库存花费总金额
kcFeelist = DataNew.GetPeopleDayStockFee(SDate, EDate);
//获取到每人每天的销售金额
zxtAllDatas = DataNew.GetPeopleDaySalePriceList(sdt, edt);
//一组每天的销售金额汇总
var group1SaleDatas = zxtAllDatas.Where(r => group1ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -2 }).OrderBy(t => t.RDate).ToList();
//二组每天的销售金额汇总
var group2SaleDatas = zxtAllDatas.Where(r => group2ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -3 }).OrderBy(t => t.RDate).ToList();
//三组每天的销售金额汇总
var group4SaleDatas = zxtAllDatas.Where(r => group3ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -5 }).OrderBy(t => t.RDate).ToList();
//四组每天的销售金额汇总
var group5SaleDatas = zxtAllDatas.Where(r => group4ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -6 }).OrderBy(t => t.RDate).ToList();
//所有人汇总
//var group3SaleDatas = zxtAllDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -4 }).OrderBy(t => t.RDate).ToList();
//所有人六个月内每个月的销售额
zxtMonthAllDatas = DataNew.GetPeopleLast6MonthSalePriceList(firstDay, lastDay);
//一组每个月的销售金额汇总
var group1MonthSaleDatas = zxtMonthAllDatas.Where(r => group1ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -2 }).OrderBy(t => t.RDate).ToList();
//二组每个月的销售金额汇总
var group2MonthSaleDatas = zxtMonthAllDatas.Where(r => group2ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -3 }).OrderBy(t => t.RDate).ToList();
//三组每个月的销售金额汇总
var group4MonthSaleDatas = zxtMonthAllDatas.Where(r => group3ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -5 }).OrderBy(t => t.RDate).ToList();
//四组每个月的销售金额汇总
var group5MonthSaleDatas = zxtMonthAllDatas.Where(r => group4ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -6 }).OrderBy(t => t.RDate).ToList();
//所有人每个月的销售金额汇总
//var group3MonthSaleDatas =zxtMonthAllDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -4 }).OrderBy(t => t.RDate).ToList();
//H净利润每天的数据
amaZonHJLRDaysDatas = DataNew.GetPeopleDayHJLRList(sdt, edt);
HJLRDaysDatas.AddRange(amaZonHJLRDaysDatas);
//一组每天的H净利润汇总
var group1HJLRDatas = amaZonHJLRDaysDatas.Where(r => group1ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -2 }).OrderBy(t => t.RDate).ToList();
//二组每天的H净利润汇总
var group2HJLRDatas = amaZonHJLRDaysDatas.Where(r => group2ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -3 }).OrderBy(t => t.RDate).ToList();
//三组每天的H净利润汇总
var group4HJLRDatas = amaZonHJLRDaysDatas.Where(r => group3ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -5 }).OrderBy(t => t.RDate).ToList();
//四组每天的H净利润汇总
var group5HJLRDatas = amaZonHJLRDaysDatas.Where(r => group4ps.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -6 }).OrderBy(t => t.RDate).ToList();
var rDatasGroup1 = new List<PeopleDaySaleDataModel>();//一组数据
var rDatasGroup2 = new List<PeopleDaySaleDataModel>();//二组数据
var rDatasGroup3 = new List<PeopleDaySaleDataModel>();//汇总数据
var rDatasGroup4 = new List<PeopleDaySaleDataModel>();//三组数据
var rDatasGroup5 = new List<PeopleDaySaleDataModel>();//四组数据
//var rDatasGroup6 = new List<PeopleDaySaleDataModel>();//其它固定人员
//获取一组数据
rDatasGroup1 = datas.Where(r => group1ps.Contains(r.UserId)).OrderByDescending(r => r.InDate).ToList();
//获取二组数据
rDatasGroup2 = datas.Where(r => group2ps.Contains(r.UserId)).OrderBy(r => r.UserId).ToList();
//获取三组数据
rDatasGroup4 = datas.Where(r => group3ps.Contains(r.UserId)).OrderBy(r => r.UserId).ToList();
//获取四组数据
rDatasGroup5 = datas.Where(r => group4ps.Contains(r.UserId)).OrderBy(r => r.UserId).ToList();
if (userid == 0 || userid == 223)
{
//获取一组数据汇总
var group1Total = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -2,
Name = "一组汇总",
PlatId = 2,
AdFee = rDatasGroup1.Sum(r => r.AdFee),
GoodsNum = rDatasGroup1.Sum(r => r.GoodsNum),
OrdersNum = rDatasGroup1.Sum(r => r.OrdersNum),
SalePrice = rDatasGroup1.Sum(r => r.SalePrice),
NetProfit = rDatasGroup1.Sum(r => r.NetProfit),
AdOrdersNum = rDatasGroup1.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasGroup1.Sum(r => r.AdOrderAmount),
AdOrderLR = rDatasGroup1.Sum(r => r.AdOrderLR),
HJLR = rDatasGroup1.Sum(r => r.HJLR),
HJLRForMonth = group1HJLRDatas.Sum(r => r.TotalPrice),
datas = group1SaleDatas,
mdatas = group1MonthSaleDatas,
hdatas = group1HJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && group1ps.Contains(r.muserid.Value)).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => group1ps.Contains(r.UserId)).Sum(r => r.DayTotalSolidFee) : 0,
};
rDatasGroup1.Add(group1Total);
//获取二组数据汇总
var group2Total = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -3,
PlatId = 2,
Name = "二组汇总",
AdFee = rDatasGroup2.Sum(r => r.AdFee),
GoodsNum = rDatasGroup2.Sum(r => r.GoodsNum),
OrdersNum = rDatasGroup2.Sum(r => r.OrdersNum),
SalePrice = rDatasGroup2.Sum(r => r.SalePrice),
NetProfit = rDatasGroup2.Sum(r => r.NetProfit),
AdOrdersNum = rDatasGroup2.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasGroup2.Sum(r => r.AdOrderAmount),
AdOrderLR = rDatasGroup2.Sum(r => r.AdOrderLR),
HJLR = rDatasGroup2.Sum(r => r.HJLR),
HJLRForMonth = group2HJLRDatas.Sum(r => r.TotalPrice),
datas = group2SaleDatas,
mdatas = group2MonthSaleDatas,
hdatas = group2HJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && group2ps.Contains(r.muserid.Value)).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => group2ps.Contains(r.UserId)).Sum(r => r.DayTotalSolidFee) : 0,
};
rDatasGroup2.Add(group2Total);
//获取三组数据汇总
var group3Total = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -5,
PlatId = 2,
Name = "三组汇总",
AdFee = rDatasGroup4.Sum(r => r.AdFee),
GoodsNum = rDatasGroup4.Sum(r => r.GoodsNum),
OrdersNum = rDatasGroup4.Sum(r => r.OrdersNum),
SalePrice = rDatasGroup4.Sum(r => r.SalePrice),
NetProfit = rDatasGroup4.Sum(r => r.NetProfit),
AdOrdersNum = rDatasGroup4.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasGroup4.Sum(r => r.AdOrderAmount),
AdOrderLR = rDatasGroup4.Sum(r => r.AdOrderLR),
HJLR = rDatasGroup4.Sum(r => r.HJLR),
HJLRForMonth = group4HJLRDatas.Sum(r => r.TotalPrice),
datas = group4SaleDatas,
mdatas = group4MonthSaleDatas,
hdatas = group4HJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && group3ps.Contains(r.muserid.Value)).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => group3ps.Contains(r.UserId)).Sum(r => r.DayTotalSolidFee) : 0,
};
rDatasGroup4.Add(group3Total);
//获取四组数据汇总
var group5Total = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -6,
PlatId = 2,
Name = "四组汇总",
AdFee = rDatasGroup5.Sum(r => r.AdFee),
GoodsNum = rDatasGroup5.Sum(r => r.GoodsNum),
OrdersNum = rDatasGroup5.Sum(r => r.OrdersNum),
SalePrice = rDatasGroup5.Sum(r => r.SalePrice),
NetProfit = rDatasGroup5.Sum(r => r.NetProfit),
AdOrdersNum = rDatasGroup5.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasGroup5.Sum(r => r.AdOrderAmount),
AdOrderLR = rDatasGroup5.Sum(r => r.AdOrderLR),
HJLR = rDatasGroup5.Sum(r => r.HJLR),
HJLRForMonth = group5HJLRDatas.Sum(r => r.TotalPrice),
datas = group5SaleDatas,
mdatas = group5MonthSaleDatas,
hdatas = group5HJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && group4ps.Contains(r.muserid.Value)).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => group4ps.Contains(r.UserId)).Sum(r => r.DayTotalSolidFee) : 0,
};
rDatasGroup5.Add(group5Total);
//组1组2组3,组4都不包含的人员,暂时排除运营9
rDatasGroup3 = datas.Where(r => !group1ps.Contains(r.UserId) && !group2ps.Contains(r.UserId) && !group3ps.Contains(r.UserId) && !group4ps.Contains(r.UserId) && r.UserId != 215).OrderByDescending(r => r.UserId).ToList();
}
rdatas.AddRange(rDatasGroup1);
rdatas.AddRange(rDatasGroup2);
rdatas.AddRange(rDatasGroup4);
rdatas.AddRange(rDatasGroup5);
rdatas.AddRange(rDatasGroup3);
totalzxtDatas.AddRange(zxtAllDatas);
totalzxtMonthDatas.AddRange(zxtMonthAllDatas);
}
#endregion
//获取除亚马逊之外,其它平台的数据
var odatas = DataNew.GetNoAmazonPeopleDaySaleDatasList(SDate, EDate);
var zxtDayTotalDatas = DataNew.GetPeopleDaySalePriceByPlatidListNew("3,6,18", sdt, edt);
var zxtMonthTotalDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdListNew("3,6,18", firstDay, lastDay);
#region Ebay组数据
var ebayZXTDatas = new List<PeopleDaySalePriceModel>();
var ebayZXTMonthDatas = new List<PeopleDaySalePriceModel>();
var ebayHJLRMonthDatas = new List<PeoPleHJLRModel>();
if (deptid == 0 || deptid == 27)
{
var rDatasEbay = new List<PeopleDaySaleDataModel>();
if (userid == 114 || userid == 0) //Ebay组长
{
rDatasEbay = odatas.Where(r => r.PlatId == 3).ToList();
}
else
{
rDatasEbay = odatas.Where(r => r.PlatId == 3 && r.UserId == userid).ToList();
}
//获取ebay平台每个人每天的净利润
ebayHJLRMonthDatas = DataNew.GetEbayPeopleHJLRDataList(sdt, edt);
HJLRDaysDatas.AddRange(ebayHJLRMonthDatas);
//获取李妍每天填写的数据,李妍填写的数据要平均分配给其它人
var fillData = DataNew.GetPeopleDayFillSaleDataModel(114, SDate, EDate);
//获取ebay所有的广告费按照每个人的销售额进行比例分配
var totalAdfee = DataNew.GetEbayPeopleDayTotalAdfee("122,187,201,114", SDate, EDate);
//获取到三个人的销售额之和
var totalSaleAmount = rDatasEbay.Where(r => r.UserId == 122 || r.UserId == 187 || r.UserId == 201).ToList().Sum(r => r.SalePrice);
//获取组员人数,进行平均
var pCount = rDatasEbay.Where(r => r.UserId > 0).Count();
//获取Ebay的仓储费
var ccFeesEbay = DataNew.GetEbayPeopleDayStockSolidFeeDatas(SDate, EDate);
//循环数据计算每一条数据的仓储费以及H净利
foreach (var item in rDatasEbay)
{
if (item.UserId > 0)
{
if (!item.SalePrice.HasValue || item.SalePrice == 0 || !totalSaleAmount.HasValue)
{
item.AdFee = 0;
}
else
{
item.AdFee = Math.Round(totalAdfee * (item.SalePrice.Value / totalSaleAmount.Value), 2);
}
}
if (fillData != null && pCount > 0)
{
//item.AdFee = (item.AdFee == null ? 0 : item.AdFee) + (Math.Round(Convert.ToDecimal(fillData.AdFee / pCount), 2));
item.AdOrdersNum = (item.AdOrdersNum == null ? 0 : item.AdOrdersNum) + (fillData.AdOrderNum.Value / pCount);
item.AdOrderAmount = (item.AdOrderAmount == null ? 0 : item.AdOrderAmount) + (Math.Round(Convert.ToDecimal(fillData.AdSaleAmount / pCount), 2));
}
var ccfee = ccFeesEbay == null ? null : ccFeesEbay.Where(r => r.UserId == item.UserId).FirstOrDefault();
item.DayTotalSolidFee = ccfee == null ? null : ccfee.DayTotalSolidFee;
item.HJLR = (item.NetProfit ?? 0) - (item.AdFee ?? 0) - (item.DayTotalSolidFee ?? 0);
item.HJLRForMonth = ebayHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
}
tdatas.AddRange(rDatasEbay);
//ebayZXTDatas = DataNew.GetPeopleDaySalePriceByPlatidList(3, sdt, edt);
ebayZXTDatas = zxtDayTotalDatas.Where(r => r.PlatId == 3).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//ebayZXTMonthDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdList(3, firstDay, lastDay);
ebayZXTMonthDatas = zxtMonthTotalDatas.Where(r => r.PlatId == 3).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
if (userid == 114 || userid == 0)
{
//ebay汇总行数据
var ebayTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -7,
PlatId = 3,
Name = "Ebay汇总",
AdFee = rDatasEbay.Sum(r => r.AdFee),
GoodsNum = rDatasEbay.Sum(r => r.GoodsNum),
OrdersNum = rDatasEbay.Sum(r => r.OrdersNum),
SalePrice = rDatasEbay.Sum(r => r.SalePrice),
NetProfit = rDatasEbay.Sum(r => r.NetProfit),
AdOrdersNum = rDatasEbay.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasEbay.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
datas = ebayZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -7 }).OrderBy(t => t.RDate).ToList(),
mdatas = ebayZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -7 }).OrderBy(t => t.RDate).ToList(),
//StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 3).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = rDatasEbay.Sum(r => r.DayTotalSolidFee),
HJLRForMonth = ebayHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = ebayHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -8 }).OrderBy(t => t.RDate).ToList()
};
ebayTotal.HJLR = (ebayTotal.NetProfit ?? 0) - (ebayTotal.AdFee ?? 0) - (ebayTotal.DayTotalSolidFee ?? 0);
rDatasEbay.Add(ebayTotal);
}
rdatas.AddRange(rDatasEbay);
totalzxtDatas.AddRange(ebayZXTDatas);
totalzxtMonthDatas.AddRange(ebayZXTMonthDatas);
}
#endregion
#region Shein组数据
var sheinZXTDatas = new List<PeopleDaySalePriceModel>();
var sheinZXTMonthDatas = new List<PeopleDaySalePriceModel>();
if (userid == 0 || userid == 1 || userid == 114 || userid == 122 || userid == 187 || userid == 201)
{
var rDatasShein = DataNew.GetSheinDaySaleDatas(SDate.Value, EDate.Value);
var sheinHJLRMonthDatas = DataNew.GetSheinHJLRDatas(sdt, edt);
HJLRDaysDatas.AddRange(sheinHJLRMonthDatas);
foreach (var item in rDatasShein)
{
item.HJLRForMonth = sheinHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
item.hdatas = sheinHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
}
tdatas.AddRange(rDatasShein);
var sheinZxtDayTotalDatas = DataNew.GetSheinPeopleDaySalePriceDatas(sdt, edt);
var sheinZxtMonthTotalDatas = DataNew.GetSheinPeopleMonthSalePriceDatas(firstDay, lastDay);
sheinZXTDatas = sheinZxtDayTotalDatas.Where(r => r.PlatId == 21).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
sheinZXTMonthDatas = sheinZxtMonthTotalDatas.Where(r => r.PlatId == 21).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
var sheinTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -11,
PlatId = 21,
Name = "Shein汇总",
AdFee = rDatasShein.Sum(r => r.AdFee),
GoodsNum = rDatasShein.Sum(r => r.GoodsNum),
OrdersNum = rDatasShein.Sum(r => r.OrdersNum),
SalePrice = rDatasShein.Sum(r => r.SalePrice),
NetProfit = rDatasShein.Sum(r => r.NetProfit),
AdOrdersNum = rDatasShein.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasShein.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
datas = sheinZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -11 }).OrderBy(t => t.RDate).ToList(),
mdatas = sheinZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -11 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasShein.Sum(r => r.DayTotalSolidFee),
HJLR = rDatasShein.Sum(r => r.HJLR),
HJLRForMonth = sheinHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = sheinHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -11 }).OrderBy(t => t.RDate).ToList()
};
rdatas.AddRange(rDatasShein);
rdatas.Add(sheinTotal);
totalzxtDatas.AddRange(sheinZXTDatas);
totalzxtMonthDatas.AddRange(sheinZXTMonthDatas);
}
#endregion
#region Walmart组数据
var walmartZXTDatas = new List<PeopleDaySalePriceModel>();
var walmartZXTMonthDatas = new List<PeopleDaySalePriceModel>();
var walmartHJLRMonthDatas = new List<PeoPleHJLRModel>();
if (deptid == 0 || deptid == 32 || userid == 114)
{
var rDatasWalmart = odatas.Where(r => r.PlatId == 6).ToList();
//获取Walmart的仓储费
var ccFeesWalmart = DataNew.GetWalmartPeopleDayStockSolidFeeDatas(SDate, EDate);
//获取walmart平台每个人每天的净利润
walmartHJLRMonthDatas = DataNew.GetWalmartPeopleHJLRDataList(sdt, edt);
HJLRDaysDatas.AddRange(walmartHJLRMonthDatas);
//循环数据计算每一条数据的仓储费以及H净利
foreach (var item in rDatasWalmart)
{
var ccfee = ccFeesWalmart == null ? null : ccFeesWalmart.Where(r => r.UserId == item.UserId).FirstOrDefault();
item.DayTotalSolidFee = ccfee == null ? null : ccfee.DayTotalSolidFee;
item.HJLR = (item.NetProfit ?? 0) - (item.AdFee ?? 0) - (item.DayTotalSolidFee ?? 0);
item.HJLRForMonth = walmartHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
}
tdatas.AddRange(rDatasWalmart);
//walmartZXTDatas = DataNew.GetPeopleDaySalePriceByPlatidList(6, sdt, edt);
walmartZXTDatas = zxtDayTotalDatas.Where(r => r.PlatId == 6).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//walmartZXTMonthDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdList(6, firstDay, lastDay);
walmartZXTMonthDatas = zxtMonthTotalDatas.Where(r => r.PlatId == 6).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//Walmart汇总行数据
var walmartTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -8,
PlatId = 6,
Name = "Walmart汇总",
AdFee = rDatasWalmart.Sum(r => r.AdFee),
GoodsNum = rDatasWalmart.Sum(r => r.GoodsNum),
OrdersNum = rDatasWalmart.Sum(r => r.OrdersNum),
SalePrice = rDatasWalmart.Sum(r => r.SalePrice),
NetProfit = rDatasWalmart.Sum(r => r.NetProfit),
AdOrdersNum = rDatasWalmart.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasWalmart.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
datas = walmartZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -8 }).OrderBy(t => t.RDate).ToList(),
mdatas = walmartZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -8 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasWalmart.Sum(r => r.DayTotalSolidFee),
HJLRForMonth = walmartHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = walmartHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -8 }).OrderBy(t => t.RDate).ToList()
};
walmartTotal.HJLR = (walmartTotal.NetProfit ?? 0) - (walmartTotal.AdFee ?? 0) - (walmartTotal.DayTotalSolidFee ?? 0);
rDatasWalmart.Add(walmartTotal);
rdatas.AddRange(rDatasWalmart);
totalzxtDatas.AddRange(walmartZXTDatas);
totalzxtMonthDatas.AddRange(walmartZXTMonthDatas);
}
#endregion
#region Wayfair组数据
var wayfairZXTDatas = new List<PeopleDaySalePriceModel>();
var wayfairZXTMonthDatas = new List<PeopleDaySalePriceModel>();
var wayfairHJLRMonthDatas = new List<PeoPleHJLRModel>();
if (deptid == 0 || deptid == 33 || userid == 114)
{
var rDatasWayfair = odatas.Where(r => r.PlatId == 18).ToList();
//获取Wayfair的仓储费
var ccFeesWayfair = DataNew.GetWayfairPeopleDayStockSolidFeeDatas(SDate, EDate);
wayfairHJLRMonthDatas = DataNew.GetWayfairPeopleHJLRDataList(sdt, edt);
HJLRDaysDatas.AddRange(wayfairHJLRMonthDatas);
//循环数据计算每一条数据的仓储费以及H净利
foreach (var item in rDatasWayfair)
{
var ccfee = ccFeesWayfair == null ? null : ccFeesWayfair.Where(r => r.UserId == item.UserId).FirstOrDefault();
item.DayTotalSolidFee = ccfee == null ? null : ccfee.DayTotalSolidFee;
item.HJLR = (item.NetProfit ?? 0) - (item.AdFee ?? 0) - (item.DayTotalSolidFee ?? 0);
item.HJLRForMonth = wayfairHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
}
tdatas.AddRange(odatas.Where(r => r.PlatId == 18));
//wayfairZXTDatas = DataNew.GetPeopleDaySalePriceByPlatidList(18, sdt, edt);
wayfairZXTDatas = zxtDayTotalDatas.Where(r => r.PlatId == 18).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//wayfairZXTMonthDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdList(18, firstDay, lastDay);
wayfairZXTMonthDatas = zxtMonthTotalDatas.Where(r => r.PlatId == 18).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//wayfair汇总行数据
var wayfairTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -9,
PlatId = 18,
Name = "Wayfair汇总",
AdFee = rDatasWayfair.Sum(r => r.AdFee),
GoodsNum = rDatasWayfair.Sum(r => r.GoodsNum),
OrdersNum = rDatasWayfair.Sum(r => r.OrdersNum),
SalePrice = rDatasWayfair.Sum(r => r.SalePrice),
NetProfit = rDatasWayfair.Sum(r => r.NetProfit),
AdOrdersNum = rDatasWayfair.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasWayfair.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
datas = wayfairZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -9 }).OrderBy(t => t.RDate).ToList(),
mdatas = wayfairZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -9 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasWayfair.Sum(r => r.DayTotalSolidFee),
HJLRForMonth = wayfairHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = wayfairHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -9 }).OrderBy(t => t.RDate).ToList()
};
wayfairTotal.HJLR = (wayfairTotal.NetProfit ?? 0) - (wayfairTotal.AdFee ?? 0) - (wayfairTotal.DayTotalSolidFee ?? 0);
rDatasWayfair.Add(wayfairTotal);
rdatas.AddRange(rDatasWayfair);
totalzxtDatas.AddRange(wayfairZXTDatas);
totalzxtMonthDatas.AddRange(wayfairZXTMonthDatas);
}
#endregion
#region Shopify组数据
var shopifyZXTDatas = new List<PeopleDaySalePriceModel>();
var shopifyZXTMonthDatas = new List<PeopleDaySalePriceModel>();
//admin/tinco/周梦良/羊莉芸
if (userid == 0 || userid == 1 || userid == 225 || userid == 226 || userid == 227)
{
var rDatasShopify = DataNew.GetShopifyDaySaleDatas(SDate.Value, EDate.Value);
var shopifyHJLRMonthDatas = DataNew.GetShopifyHJLRDatas(sdt, edt);
HJLRDaysDatas.AddRange(shopifyHJLRMonthDatas);
foreach (var item in rDatasShopify)
{
item.HJLRForMonth = shopifyHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
item.hdatas = shopifyHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
}
tdatas.AddRange(rDatasShopify);
var shopifyZxtDayTotalDatas = DataNew.GetShopifyPeopleDaySalePriceDatas(sdt, edt);
var shopifyZxtMonthTotalDatas = DataNew.GetShopifyPeopleMonthSalePriceDatas(firstDay, lastDay);
shopifyZXTDatas = shopifyZxtDayTotalDatas.Where(r => r.PlatId == 15).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
shopifyZXTMonthDatas = shopifyZxtMonthTotalDatas.Where(r => r.PlatId == 15).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
var shopifyTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -10,
PlatId = 15,
Name = "Shopify汇总",
AdFee = rDatasShopify.Sum(r => r.AdFee),
GoodsNum = rDatasShopify.Sum(r => r.GoodsNum),
OrdersNum = rDatasShopify.Sum(r => r.OrdersNum),
SalePrice = rDatasShopify.Sum(r => r.SalePrice),
NetProfit = rDatasShopify.Sum(r => r.NetProfit),
AdOrdersNum = rDatasShopify.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasShopify.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
datas = shopifyZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -10 }).OrderBy(t => t.RDate).ToList(),
mdatas = shopifyZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -10 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasShopify.Sum(r => r.DayTotalSolidFee),
HJLR = rDatasShopify.Sum(r => r.HJLR),
HJLRForMonth = shopifyHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = shopifyHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -10 }).OrderBy(t => t.RDate).ToList()
};
rdatas.AddRange(rDatasShopify);
rdatas.Add(shopifyTotal);
totalzxtDatas.AddRange(shopifyZXTDatas);
totalzxtMonthDatas.AddRange(shopifyZXTMonthDatas);
}
#endregion
//汇总行数据
var allTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -4,
PlatId = 0,
Name = "汇总",
AdFee = tdatas.Sum(r => r.AdFee),
GoodsNum = tdatas.Sum(r => r.GoodsNum),
OrdersNum = tdatas.Sum(r => r.OrdersNum),
SalePrice = tdatas.Sum(r => r.SalePrice),
NetProfit = tdatas.Sum(r => r.NetProfit),
AdOrdersNum = tdatas.Sum(r => r.AdOrdersNum),
AdOrderAmount = tdatas.Sum(r => r.AdOrderAmount),
AdOrderLR = tdatas.Sum(r => r.AdOrderLR),
HJLR = tdatas.Sum(r => r.HJLR),
HJLRForMonth = HJLRDaysDatas.Sum(r => r.HJLR),
datas = totalzxtDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -4 }).OrderBy(t => t.RDate).ToList(),
mdatas = totalzxtMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -4 }).OrderBy(t => t.RDate).ToList(),
hdatas = HJLRDaysDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -4 }).OrderBy(t => t.RDate).ToList(),
StockTotalPrice = kclist != null ? kclist.Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Sum(r => r.DayTotalSolidFee) : 0,
};
if (kclist != null && rdatas != null)
{
foreach (var umd in rdatas)
{
var kmd = kclist.Find(n => n.muserid == umd.UserId && n.PlatId == umd.PlatId);
if (kmd != null)
{
umd.StockTotalPrice = kmd.StockTotalPrice;
}
}
}
if (kcFeelist != null && rdatas != null)
{
foreach (var item in rdatas)
{
if (item.PlatId == 2 || item.PlatId == 0)
{
var kcfee = kcFeelist.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (kcfee != null)
{
item.DayTotalSolidFee = kcfee.DayTotalSolidFee;
}
}
}
}
var remakes = DataNew.GetPeopleSaleDatasRemarkList();
if (remakes != null && rdatas != null)
{
foreach (var item in rdatas)
{
var remake = remakes.Where(r => r.UserId == item.UserId && r.PlatId == item.PlatId).FirstOrDefault();
if (remake != null)
{
item.Remakes = remake.Remark;
item.Categorys = remake.Categorys;
}
}
}
var lastDatas = rdatas.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
if (userid == 0)
{
lastDatas.Add(allTotal);
}
//循环所有数据,获取每条对应的折线图数据
foreach (var item in lastDatas)
{
if (item.PlatId == 2) //亚马逊
{
if (item.UserId == -2 || item.UserId == -3 || item.UserId == -4 || item.UserId == -5 || item.UserId == -6)
continue;
var zxdatas = zxtAllDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = zxtMonthAllDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var hjrDatas = amaZonHJLRDaysDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = hjrDatas.ToList();
item.HJLRForMonth = hjrDatas.Sum(r => r.TotalPrice);
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 3) //ebay
{
if (item.UserId == -7)
continue;
var zxdatas = ebayZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = ebayZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var zxHdatas = ebayHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = zxHdatas.ToList();
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 6) //walmart
{
if (item.UserId == -8)
continue;
var zxdatas = walmartZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = walmartZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var zxHdatas = walmartHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = zxHdatas.ToList();
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 18) //wayfair
{
if (item.UserId == -9)
continue;
var zxdatas = wayfairZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = wayfairZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var zxHdatas = wayfairHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = zxHdatas.ToList();
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 15) //shopify
{
if (item.UserId == -10)
continue;
var zxdatas = shopifyZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = shopifyZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
else if (item.PlatId == 21)
{
if (item.UserId == -11)
continue;
var zxdatas = sheinZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = sheinZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
}
if (!item.AdFee.HasValue || item.AdFee.Value == 0 || !item.AdOrderAmount.HasValue || item.AdOrderAmount.Value == 0)
item.AdProductZB = null;
else
item.AdProductZB = Math.Round(item.AdFee.Value * 100 / item.AdOrderAmount.Value, 2);
}
jsonModel.DataSource = lastDatas;
jsonModel.RowCount = datas.Count;
return jsonModel;
}
#endregion
#region 获取个人每天的广告花费、销售数据
[WebMethod(EnableSession = true)]
public JsonModel<List<PeopleDaySaleDataModel>> GetPeopleDaySaleDatasNew(int userid, DateTime? SDate, DateTime? EDate, int PageSize, int PageIndex)
{
PagesNew.Login(this.Session);
var jsonModel = new JsonModel<List<PeopleDaySaleDataModel>>();
var rdatas = new List<PeopleDaySaleDataModel>();
//所有平台的总数居
var tdatas = new List<PeopleDaySaleDataModel>();
var kclist = new List<PeopleGoodsNum>();
var kcFeelist = new List<PeopleDayStockFeeModel>();
var zxtAllDatas = new List<PeopleDaySalePriceModel>();
var zxtMonthAllDatas = new List<PeopleDaySalePriceModel>();
var HJLRDaysDatas = new List<PeoPleHJLRModel>();
var amaZonHJLRDaysDatas = new List<PeoPleHJLRModel>();
var datas = new List<PeopleDaySaleDataModel>();
//总的每天折线图汇总数据
var totalzxtDatas = new List<PeopleDaySalePriceModel>();
//总的每月折线图汇总数据
var totalzxtMonthDatas = new List<PeopleDaySalePriceModel>();
DateTime sdt = DateTime.Now.Date, edt = DateTime.Now.Date;
if (DateTime.Now.Day == 1)//如果当天是一号,则取上个月的三十天数据
{
sdt = DateTime.Now.AddMonths(-1).Date;
edt = DateTime.Now.AddDays(-1).Date;
}
else //否则日期区间从1号开始到当前日期前一天
{
sdt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).Date;//当前月份第一天的日期
edt = DateTime.Now.AddDays(-1).Date;//当前日期前一天
}
var firstDay = new DateTime(DateTime.Now.AddMonths(-6).Year, DateTime.Now.AddMonths(-6).Month, 1).Date;//当前月份六个月前的第一天
//var lastDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).AddDays(-1);//当前月份上个月的最后一天
var lastDay = DateTime.Now.AddDays(-1).Date;//当前日期前一天
var deptid = userid == 0 ? 0 : DataNew.GetDepartIdByUserid(userid);
//获取每个人的产品类目和备注数据
var remakes = DataNew.GetPeopleSaleDatasRemarkList();
var rpDays1 = GetTwoDateRepeatDays(SDate.Value, EDate.Value);//当前选中时间区间的重复天数
var rpDays2= GetTwoDateRepeatDays(sdt, edt);//月h净利当前月的时间区间的重复天数
#region 亚马逊平台数据
if (deptid == 0 || deptid == 1) //亚马逊平台
{
//亚马逊平台数据 运营1-10管理可以看到所有亚马逊
datas = DataNew.GetPeopleDaySaleDatasList(0, SDate, EDate);
//库存总金额
kclist = DataNew.GetPeopleGoodsNum().Where(r => r.PlatId == 2).ToList();
//亚马逊平台库存花费总金额
kcFeelist = DataNew.GetPeopleDayStockFee(SDate, EDate);
//获取到每人每天的销售金额
zxtAllDatas = DataNew.GetPeopleDaySalePriceList(sdt, edt);
//所有人六个月内每个月的销售额
zxtMonthAllDatas = DataNew.GetPeopleLast6MonthSalePriceList(firstDay, lastDay);
//amazon个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetAmazonPeopleGoodsHJLRPercentList(sdt, edt);
//H净利润每天的数据
amaZonHJLRDaysDatas = DataNew.GetPeopleDayHJLRList(sdt, edt);
if (amaZonHJLRDaysDatas != null)
{
foreach(var ahj in amaZonHJLRDaysDatas)
{
//运营组-1在2024-04-01 至2024-07-31之间仓储费每天补贴300所以净利润要每天相对增加300
if (ahj.UserId==60 && Convert.ToDateTime( ahj.RDate)>=Convert.ToDateTime("2024-04-01") && Convert.ToDateTime(ahj.RDate) <= Convert.ToDateTime("2024-07-30"))
{
ahj.HJLR = ahj.HJLR + 300;
}
}
}
if (datas != null && datas.Count > 0)
{
foreach(var dt in datas)
{
if (dt.UserId == 60) //运营组-1在2024-04-01 至2024-07-31之间仓储费每天补贴300
{
dt.DayTotalSolidFee = (dt.DayTotalSolidFee.HasValue ? dt.DayTotalSolidFee.Value : 0) - 300 * rpDays1;
dt.HJLR = (dt.HJLR.HasValue ? dt.HJLR.Value : 0) + 300 * rpDays1;
dt.SubsidyFee = (dt.SubsidyFee.HasValue ? dt.SubsidyFee.Value : 0) + 300 * rpDays1;
}
}
var amazonGroupDatas = new List<PeopleDaySaleDataModel>();
//这两个账号数据全部显示
if (userid == 0 || userid == 223)
{
//组员只显示在组长下面,如果是组长,需要汇总自己本身的数据以及组员的数据
foreach (var data in datas)
{
//如果是组长,获取到组员以及本身的数据汇总,并且添加组员数据到组内;如果是组员直接跳过
if (!data.GroupUserId.HasValue || data.GroupUserId == data.UserId)
{
//获取到该组的组员以及组长自身的数据
var groupDatas = datas.Where(r => r.GroupUserId == data.UserId || r.UserId == data.UserId).ToList();
//组成员
var groupUserIds = groupDatas.Select(r => r.UserId).ToList();
//组销售额日折线图数据
var groupSaleDatas = zxtAllDatas.Where(r => groupUserIds.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = data.UserId }).OrderBy(t => t.RDate).ToList();
//组销售额月折线图数据
var groupMonthSaleDatas = zxtMonthAllDatas.Where(r => groupUserIds.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = data.UserId }).OrderBy(t => t.RDate).ToList();
//组净利润日折线图数据
var groupHJLRDatas = amaZonHJLRDaysDatas.Where(r => groupUserIds.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = userid }).OrderBy(t => t.RDate).ToList();
var groupModel = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = data.UserId,
IsGroup = groupDatas.Count() > 1 ? 1 : 0, //当组员个数>1时此时是组长否则只有自己一个人
Name = data.Name,
PlatId = 2,
AdFee = groupDatas.Sum(r => r.AdFee),
GoodsNum = groupDatas.Sum(r => r.GoodsNum),
OrdersNum = groupDatas.Sum(r => r.OrdersNum),
SalePrice = groupDatas.Sum(r => r.SalePrice),
NetProfit = groupDatas.Sum(r => r.NetProfit),
AdOrdersNum = groupDatas.Sum(r => r.AdOrdersNum),
AdOrderAmount = groupDatas.Sum(r => r.AdOrderAmount),
AdOrderLR = groupDatas.Sum(r => r.AdOrderLR),
HJLR = groupDatas.Sum(r => r.HJLR),
HJLRForMonth = amaZonHJLRDaysDatas.Where(r => groupUserIds.Contains(r.UserId)).Sum(r => r.HJLR),
SubsidyFee=groupDatas.Sum(r=>r.SubsidyFee),
datas = groupSaleDatas,
mdatas = groupMonthSaleDatas,
hdatas = groupHJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && groupUserIds.Contains(r.muserid.Value)).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => groupUserIds.Contains(r.UserId)).Sum(r => r.DayTotalSolidFee) : 0,
};
var rm = remakes.Where(r => r.PlatId == 2 && r.UserId == groupModel.UserId && r.IsGroup == groupModel.IsGroup).FirstOrDefault();
if (rm != null)
{
groupModel.Remakes = rm.Remark;
groupModel.Categorys = rm.Categorys;
}
//计算百分比
var goodsCount = peoPleHJLRs.Where(r => groupUserIds.Contains(r.UserId)).Count();
var zhengCount = peoPleHJLRs.Where(r => groupUserIds.Contains(r.UserId) && r.MonthHJLR > 0).Count();
groupModel.HJLRPercent = (goodsCount == 0 || zhengCount == 0) ? 0 : Convert.ToDecimal(Math.Round(zhengCount * 100.00 / goodsCount, 2));
if (groupDatas.Count > 1)
{
//组内成员数据
foreach (var gd in groupDatas)
{
gd.IsGroup = 0;
gd.GroupUserId = groupModel.UserId;
gd.GroupName = groupModel.Name;
gd.HJLRForMonth = amaZonHJLRDaysDatas.Where(r => r.UserId == gd.UserId).Sum(r => r.HJLR);
gd.datas = zxtAllDatas.Where(r => r.UserId == gd.UserId).OrderBy(r => r.RDate).ToList();
gd.mdatas = zxtMonthAllDatas.Where(r => r.UserId == gd.UserId).OrderBy(r => r.RDate).ToList();
var hdatas = amaZonHJLRDaysDatas.Where(r => r.UserId == gd.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
gd.hdatas = hdatas;
gd.HJLRForMonth = hdatas.Sum(r => r.TotalPrice);
var stockTotalPrice = kclist == null ? null : kclist.Where(r => r.PlatId == 2 && r.muserid == gd.UserId).FirstOrDefault();
gd.StockTotalPrice = stockTotalPrice == null ? 0 : stockTotalPrice.StockTotalPrice;
var dayTotalSolidPrice = kcFeelist == null ? null : kcFeelist.Where(r => r.UserId == gd.UserId).FirstOrDefault();
gd.DayTotalSolidFee = dayTotalSolidPrice == null ? 0 : dayTotalSolidPrice.DayTotalSolidFee;
//if(gd.UserId==60&& DateTime.Now.Date >= Convert.ToDateTime("2024-04-01") && DateTime.Now.Date<=Convert.ToDateTime("2024-07-30"))
//计算投产比
if (!gd.SalePrice.HasValue || gd.SalePrice.Value == 0 || !gd.AdFee.HasValue)
{
gd.TCB = null;
gd.TCBColor = "color:black";
}
else
{
gd.TCB = decimal.Round((gd.AdFee.Value * 100 / gd.SalePrice.Value), 2);
if (gd.TCB <= 5)
gd.TCBColor = "color:black";
else if (gd.TCB > 5 && gd.TCB <= 10)
gd.TCBColor = "color:#ffca00";
else if (gd.TCB > 10)
gd.TCBColor = "color:red";
}
if (!gd.AdFee.HasValue || gd.AdFee.Value == 0 || !gd.AdOrderAmount.HasValue || gd.AdOrderAmount.Value == 0)
gd.AdProductZB = null;
else
gd.AdProductZB = Math.Round(gd.AdFee.Value * 100 / gd.AdOrderAmount.Value, 2);
var grm = remakes.Where(r => r.PlatId == 2 && r.UserId == gd.UserId && r.IsGroup == 0).FirstOrDefault();
if (grm != null)
{
gd.Remakes = grm.Remark;
gd.Categorys = grm.Categorys;
}
//计算百分比
var _goodsCount = peoPleHJLRs.Where(r => r.UserId == gd.UserId).Count();
var _zhengCount = peoPleHJLRs.Where(r => r.UserId == gd.UserId && r.MonthHJLR > 0).Count();
gd.HJLRPercent = (_goodsCount == 0 || _zhengCount == 0) ? 0 : Convert.ToDecimal(Math.Round(_zhengCount * 100.00 / _goodsCount, 2));
}
groupModel.GroupPeopleDatas = groupDatas;
}
amazonGroupDatas.Add(groupModel);
}
}
}
else
{
var pData = datas.Where(r => r.UserId == userid).FirstOrDefault();
if (pData != null && (pData.GroupUserId == null || pData.GroupUserId == userid)) //单个用户登录并且是组长
{
//获取到该组的组员以及组长自身的数据
var groupDatas = datas.Where(r => r.GroupUserId == userid || r.UserId == userid).ToList();
//组成员
var groupUserIds = groupDatas.Select(r => r.UserId).ToList();
//组销售额日折线图数据
var groupSaleDatas = zxtAllDatas.Where(r => groupUserIds.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = userid }).OrderBy(t => t.RDate).ToList();
//组销售额月折线图数据
var groupMonthSaleDatas = zxtMonthAllDatas.Where(r => groupUserIds.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = userid }).OrderBy(t => t.RDate).ToList();
//组净利润日折线图数据
var groupHJLRDatas = amaZonHJLRDaysDatas.Where(r => groupUserIds.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = userid }).OrderBy(t => t.RDate).ToList();
var groupModel = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = userid,
IsGroup = groupDatas.Count() > 1 ? 1 : 0, //当组员个数>1时此时是组长否则只有自己一个人
Name = pData.Name,
PlatId = 2,
AdFee = groupDatas.Sum(r => r.AdFee),
GoodsNum = groupDatas.Sum(r => r.GoodsNum),
OrdersNum = groupDatas.Sum(r => r.OrdersNum),
SalePrice = groupDatas.Sum(r => r.SalePrice),
NetProfit = groupDatas.Sum(r => r.NetProfit),
AdOrdersNum = groupDatas.Sum(r => r.AdOrdersNum),
AdOrderAmount = groupDatas.Sum(r => r.AdOrderAmount),
AdOrderLR = groupDatas.Sum(r => r.AdOrderLR),
HJLR = groupDatas.Sum(r => r.HJLR),
HJLRForMonth = amaZonHJLRDaysDatas.Where(r => groupUserIds.Contains(r.UserId)).Sum(r => r.HJLR),
SubsidyFee=groupDatas.Sum(r=>r.SubsidyFee),
datas = groupSaleDatas,
mdatas = groupMonthSaleDatas,
hdatas = groupHJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && groupUserIds.Contains(r.muserid.Value)).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => groupUserIds.Contains(r.UserId)).Sum(r => r.DayTotalSolidFee) : 0,
};
var rm = remakes.Where(r => r.PlatId == 2 && r.UserId == groupModel.UserId && r.IsGroup == groupModel.IsGroup).FirstOrDefault();
if (rm != null)
{
groupModel.Remakes = rm.Remark;
groupModel.Categorys = rm.Categorys;
}
//计算百分比
var goodsCount = peoPleHJLRs.Where(r => groupUserIds.Contains(r.UserId)).Count();
var zhengCount = peoPleHJLRs.Where(r => groupUserIds.Contains(r.UserId) && r.MonthHJLR > 0).Count();
groupModel.HJLRPercent = (goodsCount == 0 || zhengCount == 0) ? 0 : Convert.ToDecimal(Math.Round(zhengCount * 100.00 / goodsCount, 2));
if (groupDatas.Count > 1)
{
//组内成员数据
foreach (var gd in groupDatas)
{
gd.IsGroup = 0;
gd.GroupUserId = groupModel.UserId;
gd.GroupName = groupModel.Name;
gd.HJLRForMonth = amaZonHJLRDaysDatas.Where(r => r.UserId == gd.UserId).Sum(r => r.HJLR);
gd.datas = zxtAllDatas.Where(r => r.UserId == gd.UserId).OrderBy(r => r.RDate).ToList();
gd.mdatas = zxtMonthAllDatas.Where(r => r.UserId == gd.UserId).OrderBy(r => r.RDate).ToList();
var hdatas = amaZonHJLRDaysDatas.Where(r => r.UserId == gd.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
gd.hdatas = hdatas;
gd.HJLRForMonth = hdatas.Sum(r => r.TotalPrice);
var stockTotalPrice = kclist == null ? null : kclist.Where(r => r.PlatId == 2 && r.muserid == gd.UserId).FirstOrDefault();
gd.StockTotalPrice = stockTotalPrice == null ? 0 : stockTotalPrice.StockTotalPrice;
var dayTotalSolidPrice = kcFeelist == null ? null : kcFeelist.Where(r => r.UserId == gd.UserId).FirstOrDefault();
gd.DayTotalSolidFee = dayTotalSolidPrice == null ? 0 : dayTotalSolidPrice.DayTotalSolidFee;
//计算投产比
if (!gd.SalePrice.HasValue || gd.SalePrice.Value == 0 || !gd.AdFee.HasValue)
{
gd.TCB = null;
gd.TCBColor = "color:black";
}
else
{
gd.TCB = decimal.Round((gd.AdFee.Value * 100 / gd.SalePrice.Value), 2);
if (gd.TCB <= 5)
gd.TCBColor = "color:black";
else if (gd.TCB > 5 && gd.TCB <= 10)
gd.TCBColor = "color:#ffca00";
else if (gd.TCB > 10)
gd.TCBColor = "color:red";
}
if (!gd.AdFee.HasValue || gd.AdFee.Value == 0 || !gd.AdOrderAmount.HasValue || gd.AdOrderAmount.Value == 0)
gd.AdProductZB = null;
else
gd.AdProductZB = Math.Round(gd.AdFee.Value * 100 / gd.AdOrderAmount.Value, 2);
var grm = remakes.Where(r => r.PlatId == 2 && r.UserId == gd.UserId && r.IsGroup == 0).FirstOrDefault();
if (grm != null)
{
gd.Remakes = grm.Remark;
gd.Categorys = grm.Categorys;
}
//计算百分比
var _goodsCount = peoPleHJLRs.Where(r => r.UserId == gd.UserId).Count();
var _zhengCount = peoPleHJLRs.Where(r => r.UserId == gd.UserId && r.MonthHJLR > 0).Count();
gd.HJLRPercent = (_goodsCount == 0 || _zhengCount == 0) ? 0 : Convert.ToDecimal(Math.Round(_zhengCount * 100.00 / _goodsCount, 2));
}
groupModel.GroupPeopleDatas = groupDatas;
}
amazonGroupDatas.Add(groupModel);
}
else if (pData != null && pData.GroupUserId != null)//单个用户登录不是组长
{
//组销售额日折线图数据
var groupSaleDatas = zxtAllDatas.Where(r => r.UserId == userid).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = userid }).OrderBy(t => t.RDate).ToList();
//组销售额月折线图数据
var groupMonthSaleDatas = zxtMonthAllDatas.Where(r => r.UserId == userid).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = userid }).OrderBy(t => t.RDate).ToList();
//组净利润日折线图数据
var groupHJLRDatas = amaZonHJLRDaysDatas.Where(r => r.UserId == userid).GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = userid }).OrderBy(t => t.RDate).ToList();
var groupModel = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = userid,
IsGroup = 0,
Name = pData.Name,
PlatId = 2,
AdFee = pData.AdFee,
GoodsNum = pData.GoodsNum,
OrdersNum = pData.OrdersNum,
SalePrice = pData.SalePrice,
NetProfit = pData.NetProfit,
AdOrdersNum = pData.AdOrdersNum,
AdOrderAmount = pData.AdOrderAmount,
AdOrderLR = pData.AdOrderLR,
HJLR = pData.HJLR,
HJLRForMonth = amaZonHJLRDaysDatas.Where(r => r.UserId == userid).Sum(r => r.HJLR),
SubsidyFee=pData.SubsidyFee,
datas = groupSaleDatas,
mdatas = groupMonthSaleDatas,
hdatas = groupHJLRDatas,
StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 2 && r.muserid.Value == userid).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Where(r => r.UserId == userid).Sum(r => r.DayTotalSolidFee) : 0,
};
var rm = remakes.Where(r => r.PlatId == 2 && r.UserId == groupModel.UserId && r.IsGroup == groupModel.IsGroup).FirstOrDefault();
if (rm != null)
{
groupModel.Remakes = rm.Remark;
groupModel.Categorys = rm.Categorys;
}
//计算百分比
var goodsCount = peoPleHJLRs.Where(r => r.UserId == userid).Count();
var zhengCount = peoPleHJLRs.Where(r => r.UserId == userid && r.MonthHJLR > 0).Count();
groupModel.HJLRPercent = (goodsCount == 0 || zhengCount == 0) ? 0 : Convert.ToDecimal(Math.Round(zhengCount * 100.00 / goodsCount, 2));
amazonGroupDatas.Add(groupModel);
}
}
if (amazonGroupDatas != null && amazonGroupDatas.Count > 0)
{
tdatas.AddRange(amazonGroupDatas.OrderByDescending(r => r.OrdersNum));
rdatas.AddRange(amazonGroupDatas.OrderByDescending(r => r.OrdersNum));
}
}
HJLRDaysDatas.AddRange(amaZonHJLRDaysDatas);
totalzxtDatas.AddRange(zxtAllDatas);
totalzxtMonthDatas.AddRange(zxtMonthAllDatas);
}
#endregion
//获取除亚马逊之外,其它平台的数据
var odatas = DataNew.GetNoAmazonPeopleDaySaleDatasList(SDate, EDate);
var zxtDayTotalDatas = DataNew.GetPeopleDaySalePriceByPlatidListNew("3,6,18", sdt, edt);
var zxtMonthTotalDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdListNew("3,6,18", firstDay, lastDay);
#region Ebay组数据
var ebayZXTDatas = new List<PeopleDaySalePriceModel>();
var ebayZXTMonthDatas = new List<PeopleDaySalePriceModel>();
var ebayHJLRMonthDatas = new List<PeoPleHJLRModel>();
if (deptid == 0 || deptid == 27)
{
var rDatasEbay = new List<PeopleDaySaleDataModel>();
if (userid == 114 || userid == 0) //Ebay组长
{
rDatasEbay = odatas.Where(r => r.PlatId == 3).ToList();
}
else
{
rDatasEbay = odatas.Where(r => r.PlatId == 3 && r.UserId == userid).ToList();
}
//获取ebay平台每个人每天的净利润
ebayHJLRMonthDatas = DataNew.GetEbayPeopleHJLRDataList(sdt, edt);
HJLRDaysDatas.AddRange(ebayHJLRMonthDatas);
//获取李妍每天填写的数据,李妍填写的数据要平均分配给其它人
var fillData = DataNew.GetPeopleDayFillSaleDataModel(114, SDate, EDate);
//获取ebay所有的广告费按照每个人的销售额进行比例分配
//var totalAdfee = DataNew.GetEbayPeopleDayTotalAdfee("122,187,201,114", SDate, EDate);
//获取李妍总的广告费
var totalAdfee = DataNew.GetEbayPeopleDayTotalAdfee("114", SDate, EDate);
//获取到三个人的销售额之和
var totalSaleAmount = rDatasEbay.Where(r => r.UserId == 122 || r.UserId == 187 || r.UserId == 201).ToList().Sum(r => r.SalePrice);
//获取组员人数,进行平均
var pCount = rDatasEbay.Where(r => r.UserId > 0).Count();
//获取Ebay的仓储费
var ccFeesEbay = DataNew.GetEbayPeopleDayStockSolidFeeDatas(SDate, EDate);
//ebay个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetEBayPeopleGoodsHJLRPercentList(sdt, edt);
//循环数据计算每一条数据的仓储费以及H净利
foreach (var item in rDatasEbay)
{
if (item.UserId > 0)
{
//李妍的广告费由按照三个人销售额比例分配改成三人平均分配2024-05-13
//if (!item.SalePrice.HasValue || item.SalePrice == 0 || !totalSaleAmount.HasValue)
//{
// item.AdFee = 0;
//}
//else
//{
// item.AdFee = Math.Round(totalAdfee * (item.SalePrice.Value / totalSaleAmount.Value), 2);
//}
item.AdFee = (item.AdFee.HasValue ? item.AdFee : 0) + Math.Round(totalAdfee / 3, 2);
}
if (fillData != null && pCount > 0)
{
//item.AdFee = (item.AdFee == null ? 0 : item.AdFee) + (Math.Round(Convert.ToDecimal(fillData.AdFee / pCount), 2));
item.AdOrdersNum = (item.AdOrdersNum == null ? 0 : item.AdOrdersNum) + (fillData.AdOrderNum.Value / pCount);
item.AdOrderAmount = (item.AdOrderAmount == null ? 0 : item.AdOrderAmount) + (Math.Round(Convert.ToDecimal(fillData.AdSaleAmount / pCount), 2));
}
var ccfee = ccFeesEbay == null ? null : ccFeesEbay.Where(r => r.UserId == item.UserId).FirstOrDefault();
item.DayTotalSolidFee = ccfee == null ? null : ccfee.DayTotalSolidFee;
item.HJLR = (item.NetProfit ?? 0) - (item.AdFee ?? 0) - (item.DayTotalSolidFee ?? 0);
item.HJLRForMonth = ebayHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
//计算百分比
var u_percent = peoPleHJLRs.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (u_percent != null)
item.HJLRPercent = u_percent.Percent;
}
tdatas.AddRange(rDatasEbay);
//ebayZXTDatas = DataNew.GetPeopleDaySalePriceByPlatidList(3, sdt, edt);
ebayZXTDatas = zxtDayTotalDatas.Where(r => r.PlatId == 3).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//ebayZXTMonthDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdList(3, firstDay, lastDay);
ebayZXTMonthDatas = zxtMonthTotalDatas.Where(r => r.PlatId == 3).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
if (userid == 114 || userid == 0)
{
//ebay汇总行数据
var ebayTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -7,
PlatId = 3,
IsGroup = 0,
Name = "Ebay汇总",
AdFee = rDatasEbay.Sum(r => r.AdFee),
GoodsNum = rDatasEbay.Sum(r => r.GoodsNum),
OrdersNum = rDatasEbay.Sum(r => r.OrdersNum),
SalePrice = rDatasEbay.Sum(r => r.SalePrice),
NetProfit = rDatasEbay.Sum(r => r.NetProfit),
AdOrdersNum = rDatasEbay.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasEbay.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
SubsidyFee=rDatasEbay.Sum(r=>r.SubsidyFee),
datas = ebayZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -7 }).OrderBy(t => t.RDate).ToList(),
mdatas = ebayZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -7 }).OrderBy(t => t.RDate).ToList(),
//StockTotalPrice = kclist != null ? kclist.Where(r => r.PlatId == 3).Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = rDatasEbay.Sum(r => r.DayTotalSolidFee),
HJLRForMonth = ebayHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = ebayHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -8 }).OrderBy(t => t.RDate).ToList()
};
ebayTotal.HJLR = (ebayTotal.NetProfit ?? 0) - (ebayTotal.AdFee ?? 0) - (ebayTotal.DayTotalSolidFee ?? 0);
rDatasEbay.Add(ebayTotal);
}
rdatas.AddRange(rDatasEbay);
totalzxtDatas.AddRange(ebayZXTDatas);
totalzxtMonthDatas.AddRange(ebayZXTMonthDatas);
}
#endregion
#region Shein组数据
var sheinZXTDatas = new List<PeopleDaySalePriceModel>();
var sheinZXTMonthDatas = new List<PeopleDaySalePriceModel>();
if (userid == 0 || userid == 1 || userid == 114 || userid == 122 || userid == 187 || userid == 201)
{
var rDatasShein = DataNew.GetSheinDaySaleDatas(SDate.Value, EDate.Value);
var sheinHJLRMonthDatas = DataNew.GetSheinHJLRDatas(sdt, edt);
HJLRDaysDatas.AddRange(sheinHJLRMonthDatas);
//shein个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetSheinPeopleGoodsHJLRPercentList(sdt, edt);
foreach (var item in rDatasShein)
{
item.IsGroup = 0;
item.HJLRForMonth = sheinHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
item.hdatas = sheinHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
//计算百分比
var u_percent = peoPleHJLRs.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (u_percent != null)
item.HJLRPercent = u_percent.Percent;
}
tdatas.AddRange(rDatasShein);
var sheinZxtDayTotalDatas = DataNew.GetSheinPeopleDaySalePriceDatas(sdt, edt);
var sheinZxtMonthTotalDatas = DataNew.GetSheinPeopleMonthSalePriceDatas(firstDay, lastDay);
sheinZXTDatas = sheinZxtDayTotalDatas.Where(r => r.PlatId == 21).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
sheinZXTMonthDatas = sheinZxtMonthTotalDatas.Where(r => r.PlatId == 21).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
var sheinTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -11,
PlatId = 21,
IsGroup = 0,
Name = "Shein汇总",
AdFee = rDatasShein.Sum(r => r.AdFee),
GoodsNum = rDatasShein.Sum(r => r.GoodsNum),
OrdersNum = rDatasShein.Sum(r => r.OrdersNum),
SalePrice = rDatasShein.Sum(r => r.SalePrice),
NetProfit = rDatasShein.Sum(r => r.NetProfit),
AdOrdersNum = rDatasShein.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasShein.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
datas = sheinZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -11 }).OrderBy(t => t.RDate).ToList(),
mdatas = sheinZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -11 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasShein.Sum(r => r.DayTotalSolidFee),
HJLR = rDatasShein.Sum(r => r.HJLR),
HJLRForMonth = sheinHJLRMonthDatas.Sum(r => r.HJLR),
SubsidyFee=rDatasShein.Sum(r=>r.SubsidyFee),
hdatas = sheinHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -11 }).OrderBy(t => t.RDate).ToList()
};
rdatas.AddRange(rDatasShein);
rdatas.Add(sheinTotal);
totalzxtDatas.AddRange(sheinZXTDatas);
totalzxtMonthDatas.AddRange(sheinZXTMonthDatas);
}
#endregion
#region Walmart组数据
var walmartZXTDatas = new List<PeopleDaySalePriceModel>();
var walmartZXTMonthDatas = new List<PeopleDaySalePriceModel>();
var walmartHJLRMonthDatas = new List<PeoPleHJLRModel>();
if (deptid == 0 || deptid == 32 || userid == 114)
{
var rDatasWalmart = odatas.Where(r => r.PlatId == 6).ToList();
//获取Walmart的仓储费
var ccFeesWalmart = DataNew.GetWalmartPeopleDayStockSolidFeeDatas(SDate, EDate);
//获取walmart平台每个人每天的净利润
walmartHJLRMonthDatas = DataNew.GetWalmartPeopleHJLRDataList(sdt, edt);
HJLRDaysDatas.AddRange(walmartHJLRMonthDatas);
//Wlmart个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetWlmartPeopleGoodsHJLRPercentList(sdt, edt);
//循环数据计算每一条数据的仓储费以及H净利
foreach (var item in rDatasWalmart)
{
var ccfee = ccFeesWalmart == null ? null : ccFeesWalmart.Where(r => r.UserId == item.UserId).FirstOrDefault();
item.DayTotalSolidFee = ccfee == null ? null : ccfee.DayTotalSolidFee;
item.HJLR = (item.NetProfit ?? 0) - (item.AdFee ?? 0) - (item.DayTotalSolidFee ?? 0);
item.HJLRForMonth = walmartHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
//计算百分比
var u_percent = peoPleHJLRs.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (u_percent != null)
item.HJLRPercent = u_percent.Percent;
}
tdatas.AddRange(rDatasWalmart);
//walmartZXTDatas = DataNew.GetPeopleDaySalePriceByPlatidList(6, sdt, edt);
walmartZXTDatas = zxtDayTotalDatas.Where(r => r.PlatId == 6).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//walmartZXTMonthDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdList(6, firstDay, lastDay);
walmartZXTMonthDatas = zxtMonthTotalDatas.Where(r => r.PlatId == 6).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//Walmart汇总行数据
var walmartTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -8,
PlatId = 6,
IsGroup = 0,
Name = "Walmart汇总",
AdFee = rDatasWalmart.Sum(r => r.AdFee),
GoodsNum = rDatasWalmart.Sum(r => r.GoodsNum),
OrdersNum = rDatasWalmart.Sum(r => r.OrdersNum),
SalePrice = rDatasWalmart.Sum(r => r.SalePrice),
NetProfit = rDatasWalmart.Sum(r => r.NetProfit),
AdOrdersNum = rDatasWalmart.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasWalmart.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
SubsidyFee=rDatasWalmart.Sum(r=>r.SubsidyFee),
datas = walmartZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -8 }).OrderBy(t => t.RDate).ToList(),
mdatas = walmartZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -8 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasWalmart.Sum(r => r.DayTotalSolidFee),
HJLRForMonth = walmartHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = walmartHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -8 }).OrderBy(t => t.RDate).ToList()
};
walmartTotal.HJLR = (walmartTotal.NetProfit ?? 0) - (walmartTotal.AdFee ?? 0) - (walmartTotal.DayTotalSolidFee ?? 0);
rDatasWalmart.Add(walmartTotal);
rdatas.AddRange(rDatasWalmart);
totalzxtDatas.AddRange(walmartZXTDatas);
totalzxtMonthDatas.AddRange(walmartZXTMonthDatas);
}
#endregion
#region Wayfair组数据
var wayfairZXTDatas = new List<PeopleDaySalePriceModel>();
var wayfairZXTMonthDatas = new List<PeopleDaySalePriceModel>();
var wayfairHJLRMonthDatas = new List<PeoPleHJLRModel>();
if (deptid == 0 || deptid == 33 || userid == 114)
{
var rDatasWayfair = odatas.Where(r => r.PlatId == 18).ToList();
//获取Wayfair的仓储费
var ccFeesWayfair = DataNew.GetWayfairPeopleDayStockSolidFeeDatas(SDate, EDate);
wayfairHJLRMonthDatas = DataNew.GetWayfairPeopleHJLRDataList(sdt, edt);
HJLRDaysDatas.AddRange(wayfairHJLRMonthDatas);
//wayfair个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetWayFairPeopleGoodsHJLRPercentList(sdt, edt);
//循环数据计算每一条数据的仓储费以及H净利
foreach (var item in rDatasWayfair)
{
var ccfee = ccFeesWayfair == null ? null : ccFeesWayfair.Where(r => r.UserId == item.UserId).FirstOrDefault();
item.DayTotalSolidFee = ccfee == null ? null : ccfee.DayTotalSolidFee;
item.HJLR = (item.NetProfit ?? 0) - (item.AdFee ?? 0) - (item.DayTotalSolidFee ?? 0);
item.HJLRForMonth = wayfairHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
//计算百分比
var u_percent = peoPleHJLRs.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (u_percent != null)
item.HJLRPercent = u_percent.Percent;
}
tdatas.AddRange(odatas.Where(r => r.PlatId == 18));
//wayfairZXTDatas = DataNew.GetPeopleDaySalePriceByPlatidList(18, sdt, edt);
wayfairZXTDatas = zxtDayTotalDatas.Where(r => r.PlatId == 18).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//wayfairZXTMonthDatas = DataNew.GetPeopleLast6MonthSalePriceByPlatIdList(18, firstDay, lastDay);
wayfairZXTMonthDatas = zxtMonthTotalDatas.Where(r => r.PlatId == 18).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
//wayfair汇总行数据
var wayfairTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -9,
PlatId = 18,
IsGroup = 0,
Name = "Wayfair汇总",
AdFee = rDatasWayfair.Sum(r => r.AdFee),
GoodsNum = rDatasWayfair.Sum(r => r.GoodsNum),
OrdersNum = rDatasWayfair.Sum(r => r.OrdersNum),
SalePrice = rDatasWayfair.Sum(r => r.SalePrice),
NetProfit = rDatasWayfair.Sum(r => r.NetProfit),
AdOrdersNum = rDatasWayfair.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasWayfair.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
SubsidyFee=rDatasWayfair.Sum(r=>r.SubsidyFee),
datas = wayfairZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -9 }).OrderBy(t => t.RDate).ToList(),
mdatas = wayfairZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -9 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasWayfair.Sum(r => r.DayTotalSolidFee),
HJLRForMonth = wayfairHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = wayfairHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -9 }).OrderBy(t => t.RDate).ToList()
};
wayfairTotal.HJLR = (wayfairTotal.NetProfit ?? 0) - (wayfairTotal.AdFee ?? 0) - (wayfairTotal.DayTotalSolidFee ?? 0);
rDatasWayfair.Add(wayfairTotal);
rdatas.AddRange(rDatasWayfair);
totalzxtDatas.AddRange(wayfairZXTDatas);
totalzxtMonthDatas.AddRange(wayfairZXTMonthDatas);
}
#endregion
#region Shopify组数据
var shopifyZXTDatas = new List<PeopleDaySalePriceModel>();
var shopifyZXTMonthDatas = new List<PeopleDaySalePriceModel>();
//admin/tinco/周梦良/羊莉芸
if (userid == 0 || userid == 1 || userid == 225 || userid == 226 || userid == 227)
{
var rDatasShopify = DataNew.GetShopifyDaySaleDatas(SDate.Value, EDate.Value);
var shopifyHJLRMonthDatas = DataNew.GetShopifyHJLRDatas(sdt, edt);
HJLRDaysDatas.AddRange(shopifyHJLRMonthDatas);
//shopify个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetShopifyPeopleGoodsHJLRPercentList(sdt, edt);
foreach (var item in rDatasShopify)
{
item.IsGroup = 0;
item.HJLRForMonth = shopifyHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
item.hdatas = shopifyHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
//计算百分比
var u_percent = peoPleHJLRs.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (u_percent != null)
item.HJLRPercent = u_percent.Percent;
}
tdatas.AddRange(rDatasShopify);
var shopifyZxtDayTotalDatas = DataNew.GetShopifyPeopleDaySalePriceDatas(sdt, edt);
var shopifyZxtMonthTotalDatas = DataNew.GetShopifyPeopleMonthSalePriceDatas(firstDay, lastDay);
shopifyZXTDatas = shopifyZxtDayTotalDatas.Where(r => r.PlatId == 15).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
shopifyZXTMonthDatas = shopifyZxtMonthTotalDatas.Where(r => r.PlatId == 15).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
var shopifyTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -10,
PlatId = 15,
IsGroup = 0,
Name = "Shopify汇总",
AdFee = rDatasShopify.Sum(r => r.AdFee),
GoodsNum = rDatasShopify.Sum(r => r.GoodsNum),
OrdersNum = rDatasShopify.Sum(r => r.OrdersNum),
SalePrice = rDatasShopify.Sum(r => r.SalePrice),
NetProfit = rDatasShopify.Sum(r => r.NetProfit),
AdOrdersNum = rDatasShopify.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasShopify.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
SubsidyFee=rDatasShopify.Sum(r=>r.SubsidyFee),
datas = shopifyZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -10 }).OrderBy(t => t.RDate).ToList(),
mdatas = shopifyZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -10 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasShopify.Sum(r => r.DayTotalSolidFee),
HJLR = rDatasShopify.Sum(r => r.HJLR),
HJLRForMonth = shopifyHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = shopifyHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -10 }).OrderBy(t => t.RDate).ToList()
};
rdatas.AddRange(rDatasShopify);
rdatas.Add(shopifyTotal);
totalzxtDatas.AddRange(shopifyZXTDatas);
totalzxtMonthDatas.AddRange(shopifyZXTMonthDatas);
}
#endregion
#region TikTok组数据
var tiktokZXTDatas = new List<PeopleDaySalePriceModel>();
var tiktokZXTMonthDatas = new List<PeopleDaySalePriceModel>();
//admin/tinco
if (userid == 0 || userid == 1 || userid == 225)
{
var rDatasTikTok = DataNew.GetTikTokDaySaleDatas(SDate.Value, EDate.Value);
var tiktokHJLRMonthDatas = DataNew.GetTikTokHJLRDatas(sdt, edt);
HJLRDaysDatas.AddRange(tiktokHJLRMonthDatas);
//tiktok个人管理商品H净利润数据
var peoPleHJLRs = DataNew.GetTikTokPeopleGoodsHJLRPercentList(sdt, edt);
foreach (var item in rDatasTikTok)
{
item.IsGroup = 0;
item.HJLRForMonth = tiktokHJLRMonthDatas.Where(r => r.UserId == item.UserId).Sum(r => r.HJLR);
item.hdatas = tiktokHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR }).ToList();
//计算百分比
var u_percent = peoPleHJLRs.Where(r => r.UserId == item.UserId).FirstOrDefault();
if (u_percent != null)
item.HJLRPercent = u_percent.Percent;
}
tdatas.AddRange(rDatasTikTok);
var tiktokZxtDayTotalDatas = DataNew.GetTikTokPeopleDaySalePriceDatas(sdt, edt);
var tiktokZxtMonthTotalDatas = DataNew.GetTikTokPeopleMonthSalePriceDatas(firstDay, lastDay);
tiktokZXTDatas = tiktokZxtDayTotalDatas.Where(r => r.PlatId == 22).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
tiktokZXTMonthDatas = tiktokZxtMonthTotalDatas.Where(r => r.PlatId == 22).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, TotalPrice = r.TotalPrice, UserId = r.UserId }).ToList();
var tiktokTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -12,
PlatId = 22,
IsGroup = 0,
Name = "TikTok汇总",
AdFee = rDatasTikTok.Sum(r => r.AdFee),
GoodsNum = rDatasTikTok.Sum(r => r.GoodsNum),
OrdersNum = rDatasTikTok.Sum(r => r.OrdersNum),
SalePrice = rDatasTikTok.Sum(r => r.SalePrice),
NetProfit = rDatasTikTok.Sum(r => r.NetProfit),
AdOrdersNum = rDatasTikTok.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatasTikTok.Sum(r => r.AdOrderAmount),
AdOrderLR = null,
SubsidyFee=rDatasTikTok.Sum(r=>r.SubsidyFee),
datas = tiktokZXTDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -10 }).OrderBy(t => t.RDate).ToList(),
mdatas = tiktokZXTMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -10 }).OrderBy(t => t.RDate).ToList(),
DayTotalSolidFee = rDatasTikTok.Sum(r => r.DayTotalSolidFee),
HJLR = rDatasTikTok.Sum(r => r.HJLR),
HJLRForMonth = tiktokHJLRMonthDatas.Sum(r => r.HJLR),
hdatas = tiktokHJLRMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -10 }).OrderBy(t => t.RDate).ToList()
};
rdatas.AddRange(rDatasTikTok);
rdatas.Add(tiktokTotal);
totalzxtDatas.AddRange(tiktokZXTDatas);
totalzxtMonthDatas.AddRange(tiktokZXTMonthDatas);
}
#endregion
//汇总行数据
var allTotal = new PeopleDaySaleDataModel()
{
InDate = "",
UserId = -4,
PlatId = 0,
IsGroup = 0,
Name = "汇总",
AdFee = tdatas.Sum(r => r.AdFee),
GoodsNum = tdatas.Sum(r => r.GoodsNum),
OrdersNum = tdatas.Sum(r => r.OrdersNum),
SalePrice = tdatas.Sum(r => r.SalePrice),
NetProfit = tdatas.Sum(r => r.NetProfit),
AdOrdersNum = tdatas.Sum(r => r.AdOrdersNum),
AdOrderAmount = tdatas.Sum(r => r.AdOrderAmount),
AdOrderLR = tdatas.Sum(r => r.AdOrderLR),
SubsidyFee=tdatas.Sum(r=>r.SubsidyFee),
HJLR = tdatas.Sum(r => r.HJLR),
HJLRForMonth = HJLRDaysDatas.Sum(r => r.HJLR),
datas = totalzxtDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -4 }).OrderBy(t => t.RDate).ToList(),
mdatas = totalzxtMonthDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.TotalPrice), UserId = -4 }).OrderBy(t => t.RDate).ToList(),
hdatas = HJLRDaysDatas.GroupBy(r => r.RDate).Select(g => new PeopleDaySalePriceModel { RDate = g.Key, TotalPrice = g.Sum(r => r.HJLR), UserId = -4 }).OrderBy(t => t.RDate).ToList(),
StockTotalPrice = kclist != null ? kclist.Sum(r => r.StockTotalPrice) : 0,
DayTotalSolidFee = kcFeelist != null ? kcFeelist.Sum(r => r.DayTotalSolidFee) : 0,
};
//if (kclist != null && rdatas != null)
//{
// foreach (var umd in rdatas)
// {
// var kmd = kclist.Find(n => n.muserid == umd.UserId && n.PlatId == umd.PlatId);
// if (kmd != null)
// {
// umd.StockTotalPrice = kmd.StockTotalPrice;
// }
// }
//}
//if (kcFeelist != null && rdatas != null)
//{
// foreach (var item in rdatas)
// {
// if (item.PlatId == 2 || item.PlatId == 0)
// {
// var kcfee = kcFeelist.Where(r => r.UserId == item.UserId).FirstOrDefault();
// if (kcfee != null)
// {
// item.DayTotalSolidFee = kcfee.DayTotalSolidFee;
// }
// }
// }
//}
if (remakes != null && rdatas != null)
{
foreach (var item in rdatas)
{
if (item.PlatId == 2)
continue;
var remake = remakes.Where(r => r.UserId == item.UserId && r.PlatId == item.PlatId).FirstOrDefault();
if (remake != null)
{
item.Remakes = remake.Remark;
item.Categorys = remake.Categorys;
}
}
}
var lastDatas = rdatas.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
if (userid == 0)
{
lastDatas.Add(allTotal);
}
//循环所有数据,获取每条对应的折线图数据
foreach (var item in lastDatas)
{
if (item.PlatId == 2) //亚马逊
{
//if (item.UserId == -2 || item.UserId == -3 || item.UserId == -4 || item.UserId == -5 || item.UserId == -6)
// continue;
//var zxdatas = zxtAllDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
//item.datas = zxdatas;
//var zxMdatas = zxtMonthAllDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
//item.mdatas = zxMdatas;
//var hjrDatas = amaZonHJLRDaysDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
//item.hdatas = hjrDatas.ToList();
//item.HJLRForMonth = hjrDatas.Sum(r => r.TotalPrice);
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 3) //ebay
{
if (item.UserId == -7)
continue;
var zxdatas = ebayZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = ebayZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var zxHdatas = ebayHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = zxHdatas.ToList();
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 6) //walmart
{
if (item.UserId == -8)
continue;
var zxdatas = walmartZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = walmartZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var zxHdatas = walmartHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = zxHdatas.ToList();
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 18) //wayfair
{
if (item.UserId == -9)
continue;
var zxdatas = wayfairZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = wayfairZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
var zxHdatas = wayfairHJLRMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).Select(r => new PeopleDaySalePriceModel { RDate = r.RDate, UserId = r.UserId, TotalPrice = r.HJLR });
item.hdatas = zxHdatas.ToList();
//计算投产比
if (!item.SalePrice.HasValue || item.SalePrice.Value == 0 || !item.AdFee.HasValue)
{
item.TCB = null;
item.TCBColor = "color:black";
}
else
{
item.TCB = decimal.Round((item.AdFee.Value * 100 / item.SalePrice.Value), 2);
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
}
else if (item.PlatId == 15) //shopify
{
if (item.UserId == -10)
continue;
var zxdatas = shopifyZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = shopifyZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
if (item.TCB <= 5)
item.TCBColor = "color:black";
else if (item.TCB > 5 && item.TCB <= 10)
item.TCBColor = "color:#ffca00";
else if (item.TCB > 10)
item.TCBColor = "color:red";
}
else if (item.PlatId == 21)
{
if (item.UserId == -11)
continue;
var zxdatas = sheinZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = sheinZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
}
else if (item.PlatId == 22)
{
if (item.UserId == -12)
continue;
var zxdatas = tiktokZXTDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.datas = zxdatas;
var zxMdatas = tiktokZXTMonthDatas.Where(r => r.UserId == item.UserId).OrderBy(r => r.RDate).ToList();
item.mdatas = zxMdatas;
}
if (!item.AdFee.HasValue || item.AdFee.Value == 0 || !item.AdOrderAmount.HasValue || item.AdOrderAmount.Value == 0)
item.AdProductZB = null;
else
item.AdProductZB = Math.Round(item.AdFee.Value * 100 / item.AdOrderAmount.Value, 2);
}
jsonModel.DataSource = lastDatas;
jsonModel.RowCount = rdatas.Count;
return jsonModel;
}
#endregion
#region 计算两个时间区间的重叠天数
public int GetTwoDateRepeatDays(DateTime sdt,DateTime edt)
{
DateTime overlapStartDate = new DateTime(2024, 4, 1); // 重叠时间区间的开始日期
DateTime overlapEndDate = new DateTime(2024, 7, 31); // 重叠时间区间的结束日期
// 确定重叠部分的开始日期和结束日期
DateTime latestStartDate = sdt.Date > overlapStartDate ? sdt.Date : overlapStartDate;
DateTime earliestEndDate = edt.Date < overlapEndDate ? edt.Date : overlapEndDate;
// 计算重叠部分的天数
int overlapDays = (earliestEndDate - latestStartDate).Days + 1;
if (overlapDays < 0)
{
overlapDays = 0; // 如果没有重叠部分,重叠天数为 0
}
return overlapDays;
}
#endregion
#region 获取个人每天的广告花费详情
[WebMethod(EnableSession = true)]
public List<PeopleAdFeeDetailModel> GetPeopleAdFeeDetailDatas(int userid, DateTime? sDate, DateTime? eDate)
{
PagesNew.Login(this.Session);
var rDatas = DataNew.GetPeopleAdFeeDetailList(userid, sDate, eDate);
if (rDatas != null && rDatas.Count > 0)
{
var tmodel = new PeopleAdFeeDetailModel()
{
GoodsCode = "汇总",
AdFee = rDatas.Sum(r => r.AdFee),
OrderNum = rDatas.Sum(r => r.OrderNum),
TotalPrice = rDatas.Sum(r => r.TotalPrice),
AdOrdersNum = rDatas.Sum(r => r.AdOrdersNum),
AdOrderAmount = rDatas.Sum(r => r.AdOrderAmount)
};
rDatas.Add(tmodel);
}
return rDatas;
}
#endregion
#region 根据数据类型获取某人每天的折线图数据
[WebMethod(EnableSession = true)]
public List<ZXTDataModel> GetPeopleDayZXTDatas(int userid, int platid, int dataType, int dateType, DateTime sDate, DateTime eDate)
{
//dateType:1按天2按月
var rdatas = new List<ZXTDataModel>();
//按月时用到的开始结束日期
var startDate = new DateTime(sDate.Year, sDate.Month, 1);//开始日期所在月的第一天
var endDate = new DateTime(eDate.AddMonths(1).Year, eDate.AddMonths(1).Month, 1).AddDays(-1);//结束日期所在月的最后一台
if (dataType == 1)//广告花费
{
var adAllDatas = new List<PeopleDaySalePriceModel>();
if (dateType == 1) //按天
adAllDatas = DataNew.GetPeopleDayAdFeeList(sDate, eDate);
else if (dateType == 2) //按月
adAllDatas = DataNew.GetPeopleMonthAdFeeList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = adAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = adAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4)//所有汇总
{
rdatas = adAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5)//三组汇总
{
rdatas = adAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6)//四组汇总
{
rdatas = adAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = adAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
}
else if (dataType == 2)//订单数量
{
var orderNumAllDatas = new List<PeopleDayOrderNumModel>();
if (platid == 2)
{
if (dateType == 1)//按天
orderNumAllDatas = DataNew.GetPeopleDayOrderNumList(sDate, eDate);
else if (dateType == 2)//按月
orderNumAllDatas = DataNew.GetPeopleMonthOrderNumList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = orderNumAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = orderNumAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4) //所有汇总
{
rdatas = orderNumAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5) //三组汇总
{
rdatas = orderNumAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6) //四组汇总
{
rdatas = orderNumAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = orderNumAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.OrderNum }).ToList();
}
}
else if (platid == 3 || platid == 6 || platid == 18)
{
if (dateType == 1)//按天
orderNumAllDatas = DataNew.GetNoAmazonAllPeopleDayOrderNumList(platid, sDate, eDate);
else if (dateType == 2)//按月
orderNumAllDatas = DataNew.GetAllPeopleMonthOrderNumList(platid, startDate, endDate);
if (userid > -2) //userid<=-2说明是汇总
{
rdatas = orderNumAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.OrderNum }).ToList();
}
else//ebay/walmart/wayfair汇总
{
rdatas = orderNumAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
}
else if (platid == 0)//总汇总
{
if (dateType == 1)//按天
{
var amaOrderNumAllDatas = DataNew.GetPeopleDayOrderNumList(sDate, eDate);
if (amaOrderNumAllDatas != null && amaOrderNumAllDatas.Count > 0)
orderNumAllDatas.AddRange(amaOrderNumAllDatas);
var ebayOrderNumAllDatas = DataNew.GetNoAmazonAllPeopleDayOrderNumList(3, sDate, eDate);
if (ebayOrderNumAllDatas != null && ebayOrderNumAllDatas.Count > 0)
orderNumAllDatas.AddRange(ebayOrderNumAllDatas);
}
else if (dateType == 2)//按月
{
var amaOrderNumAllDatas = DataNew.GetPeopleMonthOrderNumList(startDate, endDate);
if (amaOrderNumAllDatas != null && amaOrderNumAllDatas.Count > 0)
orderNumAllDatas.AddRange(amaOrderNumAllDatas);
var ebayOrderNumAllDatas = DataNew.GetAllPeopleMonthOrderNumList(3, startDate, endDate);
if (ebayOrderNumAllDatas != null && ebayOrderNumAllDatas.Count > 0)
orderNumAllDatas.AddRange(ebayOrderNumAllDatas);
}
rdatas = orderNumAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
}
else if (dataType == 3) //销售额
{
var saleAllDatas = new List<PeopleDaySalePriceModel>();
if (platid == 2)
{
if (dateType == 1) //按天
saleAllDatas = DataNew.GetPeopleDaySalePriceList(sDate, eDate);
else if (dateType == 2) //按月
saleAllDatas = DataNew.GetPeopleMonthSalePriceList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = saleAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = saleAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4) //所有汇总
{
rdatas = saleAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5)//三组汇总
{
rdatas = saleAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6)//四组汇总
{
rdatas = saleAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = saleAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
}
else if (platid == 3 || platid == 6 || platid == 18) //ebay/walmart/wayfair
{
if (dateType == 1)//按天
saleAllDatas = DataNew.GetPeopleDaySalePriceList(platid, sDate, eDate);
else if (dateType == 2)//按月
saleAllDatas = DataNew.GetPeopleMonthSalePriceList(platid, startDate, endDate);
if (userid > -2) //userid<=-2说明是汇总
{
rdatas = saleAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
else//ebay/walmart/wayfair汇总
{
rdatas = saleAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
}
else if (platid == 0)//总汇总
{
if (dateType == 1)//按天
{
var amasaleAllDatas = DataNew.GetPeopleDaySalePriceList(sDate, eDate);
if (amasaleAllDatas != null && amasaleAllDatas.Count > 0)
saleAllDatas.AddRange(amasaleAllDatas);
var ebaysaleAllDatas = DataNew.GetPeopleDaySalePriceList(3, sDate, eDate);
if (ebaysaleAllDatas != null && ebaysaleAllDatas.Count > 0)
saleAllDatas.AddRange(ebaysaleAllDatas);
}
else if (dateType == 2)//按月
{
var amasaleAllDatas = DataNew.GetPeopleMonthSalePriceList(sDate, eDate);
if (amasaleAllDatas != null && amasaleAllDatas.Count > 0)
saleAllDatas.AddRange(amasaleAllDatas);
var ebaysaleAllDatas = DataNew.GetPeopleMonthSalePriceList(3, sDate, eDate);
if (ebaysaleAllDatas != null && ebaysaleAllDatas.Count > 0)
saleAllDatas.AddRange(ebaysaleAllDatas);
}
rdatas = saleAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
}
else if (dataType == 4) //利润
{
var saleAllDatas = new List<PeopleDaySalePriceModel>();
if (platid == 2)
{
if (dateType == 1) //按天
saleAllDatas = DataNew.GetPeopleDayLRList(sDate, eDate);
else if (dateType == 2) //按月
saleAllDatas = DataNew.GetPeopleMonthLRList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = saleAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = saleAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4) //所有汇总
{
rdatas = saleAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5) //三组汇总
{
rdatas = saleAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6) //四组汇总
{
rdatas = saleAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = saleAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
}
else if (platid == 3 || platid == 6 || platid == 18) //ebay/walmart/wayfair
{
if (dateType == 1) //按天
saleAllDatas = DataNew.GetPeopleDayLRList(platid, sDate, eDate);
else if (dateType == 2) //按月
saleAllDatas = DataNew.GetPeopleMonthLRList(platid, startDate, endDate);
if (userid > -2) //userid<=-2说明是汇总
{
rdatas = saleAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
else//ebay/walmart/wayfair汇总
{
rdatas = saleAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
}
else if (platid == 0) //总汇总
{
if (dateType == 1)//按天
{
var amasaleAllDatas = DataNew.GetPeopleDayLRList(sDate, eDate);
if (amasaleAllDatas != null && amasaleAllDatas.Count > 0)
saleAllDatas.AddRange(amasaleAllDatas);
var ebaysaleAllDatas = DataNew.GetPeopleDayLRList(3, sDate, eDate);
if (ebaysaleAllDatas != null && ebaysaleAllDatas.Count > 0)
saleAllDatas.AddRange(ebaysaleAllDatas);
}
else if (dateType == 2)//按月
{
var amasaleAllDatas = DataNew.GetPeopleMonthLRList(sDate, eDate);
if (amasaleAllDatas != null && amasaleAllDatas.Count > 0)
saleAllDatas.AddRange(amasaleAllDatas);
var ebaysaleAllDatas = DataNew.GetPeopleMonthLRList(3, sDate, eDate);
if (ebaysaleAllDatas != null && ebaysaleAllDatas.Count > 0)
saleAllDatas.AddRange(ebaysaleAllDatas);
}
rdatas = saleAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
}
else if (dataType == 5) //广告订单数量
{
var adAllDatas = new List<PeopleDayOrderNumModel>();
if (dateType == 1) //按天
adAllDatas = DataNew.GetPeopleDayAdOrderNumList(sDate, eDate);
else if (dateType == 2) //按月
adAllDatas = DataNew.GetPeopleMonthAdOrderNumList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = adAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = adAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4)//所有汇总
{
rdatas = adAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5)//三组汇总
{
rdatas = adAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6)//四组汇总
{
rdatas = adAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.OrderNum) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = adAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.OrderNum }).ToList();
}
}
else if (dataType == 6) //广告订单金额
{
var adAllDatas = new List<PeopleDaySalePriceModel>();
if (dateType == 1) //按天
adAllDatas = DataNew.GetPeopleDayAdOrderSalePriceList(sDate, eDate);
else if (dateType == 2) //按月
adAllDatas = DataNew.GetPeopleMonthAdOrderSalePriceList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = adAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = adAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4)//所有汇总
{
rdatas = adAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5)//三组汇总
{
rdatas = adAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6)//四组汇总
{
rdatas = adAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = adAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
}
else if (dataType == 7) //广告订单利润
{
var adAllDatas = new List<PeopleDaySalePriceModel>();
if (dateType == 1) //按天
adAllDatas = DataNew.GetPeopleDayAdOrderLRPriceList(sDate, eDate);
else if (dateType == 2) //按月
adAllDatas = DataNew.GetPeopleMonthAdOrderLRPriceList(startDate, endDate);
if (userid == -2)//一组汇总
{
rdatas = adAllDatas.Where(r => Group1Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -3)//二组汇总
{
rdatas = adAllDatas.Where(r => Group2Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -4)//所有汇总
{
rdatas = adAllDatas.GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -5)//三组汇总
{
rdatas = adAllDatas.Where(r => Group3Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else if (userid == -6)//四组汇总
{
rdatas = adAllDatas.Where(r => Group4Peoples.Contains(r.UserId)).GroupBy(r => r.RDate).Select(g => new ZXTDataModel { Name = g.Key, Value = g.Sum(r => r.TotalPrice) }).OrderBy(t => t.Name).ToList();
}
else
{
rdatas = adAllDatas.Where(r => r.UserId == userid).OrderBy(r => r.RDate).Select(r => new ZXTDataModel { Name = r.RDate, Value = r.TotalPrice }).ToList();
}
}
return rdatas;
}
#endregion
#region 获取个人每个商品的库存数量以及金额数据
[WebMethod(EnableSession = true)]
public JsonModel<List<PeopleEveryGoodsNum>> GetPeopleEveryGoodsNumPriceDatas(int userid, string goodsCode, int PageSize, int PageIndex)
{
PagesNew.Login(this.Session);
var jsonModel = new JsonModel<List<PeopleEveryGoodsNum>>();
var muids = "";
if (userid == -2)//第一组
muids = string.Join(",", Group1Peoples);
else if (userid == -3)//第二组
muids = string.Join(",", Group2Peoples);
else if (userid == -4)//所有人汇总
{
var allPeoples = new List<int>();
allPeoples.AddRange(Group1Peoples);
allPeoples.AddRange(Group2Peoples);
allPeoples.AddRange(Group3Peoples);
allPeoples.AddRange(Group4Peoples);
allPeoples.Add(-1);
allPeoples.Add(0);
muids = string.Join(",", allPeoples);
}
else if (userid == -5)
muids = string.Join(",", Group3Peoples);
else if (userid == -6)
muids = string.Join(",", Group4Peoples);
else
{
muids = "'" + userid.ToString() + "'";
}
var datas = new List<PeopleEveryGoodsNum>();
datas = DataNew.GetPeopleEveryGoodsNum(muids, goodsCode);
var rdatas = datas.Skip((PageIndex - 1) * PageSize).Take(PageSize).ToList();
var tmodel = new PeopleEveryGoodsNum()
{
GoodsCode = "汇总",
WStockNum = datas.Sum(r => r.WStockNum),
WStockPrice = datas.Sum(r => r.WStockPrice),
WInRoadNum = datas.Sum(r => r.WInRoadNum),
WInRoadPrice = datas.Sum(r => r.WInRoadPrice),
EStockNum = datas.Sum(r => r.EStockNum),
EStockPrice = datas.Sum(r => r.EStockPrice),
EInRoadNum = datas.Sum(r => r.EInRoadNum),
EInRoadPrice = datas.Sum(r => r.EInRoadPrice),
GNStockNum = datas.Sum(r => r.GNStockNum),
GNStockPrice = datas.Sum(r => r.GNStockPrice)
};
rdatas.Add(tmodel);
jsonModel.DataSource = rdatas;
jsonModel.RowCount = datas.Count;
return jsonModel;
}
#endregion
#region 保存个人销售数据页面备注
[WebMethod(EnableSession = true)]
public ApiResponseModel UpdatePeopleSaleDataRemark(int userid, int platid, string username, string remark, int isgroup)
{
PagesNew.Login(this.Session);
var robj = new ApiResponseModel();
try
{
DataNew.UpdatePeopleSaleDataRemark(userid, platid, username, remark, isgroup);
robj.Code = 1;
robj.Message = "更新成功";
}
catch
{
robj.Code = 0;
robj.Message = "更新失败";
}
return robj;
}
#endregion
//#region 保存个人销售数据产品类目
//[WebMethod(EnableSession = true)]
//public ApiResponseModel UpdatePeopleSaleDataPCategory(int userid, int platid, string username, string categorys)
//{
// PagesNew.Login(this.Session);
// var robj = new ApiResponseModel();
// try
// {
// DataNew.UpdatePeopleSaleDataPCategorys(userid, platid, username, categorys);
// robj.Code = 1;
// robj.Message = "更新成功";
// }
// catch
// {
// robj.Code = 0;
// robj.Message = "更新失败";
// }
// return robj;
//}
//#endregion
#region 获取每个人商品的排名区间数量
[WebMethod(EnableSession = true)]
public JsonModel<List<PeopleGoodsRankCountModel>> GetPeopleGoodsRankCountDatas(DateTime SDate)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<PeopleGoodsRankCountModel>>();
var datas = DataNew.GetPeopleGoodsRankCountList(SDate);
rmodel.DataSource = datas;
rmodel.RowCount = datas != null ? datas.Count : 0;
return rmodel;
}
#endregion
#region 获取每个人商品的排名区间详情
[WebMethod(EnableSession = true)]
public JsonModel<List<PeopleGoodsRankDetailModel>> GetPeopleGoodsRankDetailDatas(DateTime SDate, int userid, int rangeType, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<PeopleGoodsRankDetailModel>>();
int rowCount = 0;
var datas = DataNew.GetPeopleGoodsRankDetailList(SDate, rangeType, userid, PageIndex, PageSize, out rowCount);
rmodel.DataSource = datas;
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 获取每个人商品的排名区间详情
[WebMethod(EnableSession = true)]
public List<HW_GoodsSortDataModel> GetHWGoodsSortDatas()
{
PagesNew.Login(this.Session);
var datas = DataNew.GetGoodsSortList();
return datas;
}
#endregion
#region 保存个人销售数据产品类目
[WebMethod(EnableSession = true)]
public ApiResponseModel UpdatePeopleSaleDataPCategory(int userid, int platid, string userName, string categorys, int isgroup)
{
PagesNew.Login(this.Session);
var robj = new ApiResponseModel();
try
{
DataNew.UpdatePeopleSaleDataPCategorys(userid, platid, userName, categorys, isgroup);
robj.Code = 1;
robj.Message = "更新成功";
}
catch
{
robj.Code = 0;
robj.Message = "更新失败";
}
return robj;
}
#endregion
#region 获取店铺广告花费详情
[WebMethod(EnableSession = true)]
public JsonModel<List<ShopAdFeeDetailModel>> GetShopAdFeeDetailDatas(int UserId, DateTime sDate, DateTime eDate, string shopName, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<ShopAdFeeDetailModel>>();
int rowCount = 0;
var datas = DataNew.GetShopAdFeeDetailList(UserId, sDate, eDate, shopName, PageIndex, PageSize, out rowCount);
if (datas != null && datas.Count > 0)
{
var lrDatas = DataNew.GetShopGoodsLRDataList(UserId, sDate, eDate, shopName);
foreach (var data in datas)
{
if (lrDatas == null)
{
data.CPLR = 0 - data.AdFee;
}
else
{
var lrdata = lrDatas.Where(r => r.GoodsId == data.GoodsId).FirstOrDefault();
if (lrdata != null)
{
data.CPLR = lrdata.LR - data.AdFee;
}
else
{
data.CPLR = 0 - data.AdFee;
}
}
data.TCB = (data.AdFee == 0 || data.CPLR == 0 || !data.CPLR.HasValue || !data.AdFee.HasValue) ? 0 : Math.Round((data.CPLR.Value * 100 / data.AdFee.Value), 2);
}
var totalModel = DataNew.GetShopAdFeeDetailTotal(UserId, sDate, eDate, shopName);
totalModel.CPLR = lrDatas == null ? (0 - totalModel.AdFee) : (lrDatas.Sum(r => r.LR) - totalModel.AdFee);
totalModel.TCB = Math.Round(totalModel.CPLR.Value * 100 / totalModel.AdFee.Value, 2);
datas.Add(totalModel);
}
rmodel.DataSource = datas;
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 获取店铺投产比<0的商品广告花费详情
[WebMethod(EnableSession = true)]
public JsonModel<List<ShopAdAnalysisDetailModel>> GetShopAdAnalysisDetailDatas(DateTime sDate, DateTime eDate, int shopid, int userid, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<ShopAdAnalysisDetailModel>>();
int rowCount = 0;
var datas = DataNew.GetShopAdAnalysisDetailList(sDate, eDate, shopid, userid, PageIndex, PageSize, out rowCount);
rmodel.DataSource = datas;
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 获取店铺投诉case数据
[WebMethod(EnableSession = true)]
public JsonModel<List<ShopClaimCaseModel>> GetShopClaimCaseDatas(DateTime? sDate, DateTime? eDate, int? shopid, int searchType, string searchTxt, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<ShopClaimCaseModel>>();
int rowCount = 0;
var datas = DataNew.GetShopClaimCaseList(sDate, eDate, shopid, searchType, searchTxt, PageIndex, PageSize, out rowCount);
if (datas != null && datas.Count > 0)
{
foreach (var dt in datas)
{
if (!string.IsNullOrEmpty(dt.GoodsCodes))
{
var userNames = "";
var images = "";
foreach (var code in dt.GoodsCodes.Split(','))
{
if (dt.PlatType.HasValue)
{
var userIMG = DataNew.GetShopClaimCaseUserImg(dt.PlatType.Value, code);
if (userIMG != null)
{
userNames += userIMG.UserName + ",";
images += "<img src='" + userIMG.FirstImgUrl + "' width='50px' height='50px'/>";
}
}
}
dt.UserName = string.IsNullOrEmpty(userNames) ? "" : userNames.TrimEnd(',');
dt.Image = images;
}
}
}
rmodel.DataSource = datas;
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 保存店铺索赔Case数据
[WebMethod(EnableSession = true)]
public int SaveShopClaimCaseData(ShopClaimCaseData Model)
{
PagesNew.Login(this.Session);
if (Model.ID == null || Model.ID.Value == 0)
Model.CreateTime = DateTime.Now;
int Id = DataNew.SaveShopClaimCaseData(Model);
return Id;
}
#endregion
#region 删除店铺索赔Case数据
[WebMethod(EnableSession = true)]
public void DeleteShopClaimCaseData(int id)
{
PagesNew.Login(this.Session);
DataNew.DeleteShopClaimCaseData(id);
}
#endregion
#region 获取店铺邮箱数据
[WebMethod(EnableSession = true)]
public List<ShopEmailsSelectModel> GetShopEmailsDatas(int shopid)
{
PagesNew.Login(this.Session);
var rmodel = new List<ShopEmailsSelectModel>();
rmodel = DataNew.GetShopEmailsByShopId(shopid);
return rmodel;
}
#endregion
#region 获取店铺邮箱邮件数据
[WebMethod(EnableSession = true)]
public List<ShopEmailItemListModel> GetShopEmailItemListDatas(int emailType, int shopid, string emailCode, int pageIndex, int pageSize)
{
PagesNew.Login(this.Session);
var rmodel = new List<ShopEmailItemListModel>();
if (emailType == 0) //站内信
{
rmodel = DataNew.GetShopEmailsItemListDatas(shopid, emailCode, pageSize, pageIndex);
}
else if (emailType == 1) //发件箱
{
rmodel = DataNew.GetShopSendEmailsItemListDatas(shopid, emailCode, pageSize, pageIndex);
}
else if (emailType == 2) //收件箱
{
rmodel = DataNew.GetShopGetEmailsItemListDatas(shopid, emailCode, pageSize, pageIndex);
}
if (rmodel != null && rmodel.Count > 0)
{
foreach (var item in rmodel)
{
if (item.FromAccount.IndexOf('"') == 0)
{
var nsIndex = item.FromAccount.IndexOf("\"");
var neIndex = item.FromAccount.LastIndexOf("\"");
item.CustomerName = item.FromAccount.Substring(nsIndex + 1, neIndex - nsIndex - 1);
var esIndex = item.FromAccount.IndexOf("<");
var eeIndex = item.FromAccount.IndexOf(">");
item.CustomerEmail = item.FromAccount.Substring(esIndex + 1, eeIndex - esIndex - 1);
}
else
{
item.CustomerName = "";
item.CustomerEmail = item.FromAccount;
}
}
}
return rmodel;
}
#endregion
#region 获取店铺邮箱站内信数据
[WebMethod(EnableSession = true)]
public List<ShopEmailZNXListModel> GetShopZNXListDatas(int emailType, int shopid, string emailCode, string customerEmail, int pageIndex, int pageSize)
{
PagesNew.Login(this.Session);
var rmodel = new List<ShopEmailZNXListModel>();
if (emailType == 0)
{
rmodel = DataNew.GetShopZNXListDatas(shopid, emailCode, customerEmail, pageSize, pageIndex);
if (pageIndex == 1)
{
rmodel = rmodel.OrderBy(r => r.EmailCNTime).ToList();
}
}
else if (emailType == 1)
{
}
else if (emailType == 2)
{
}
return rmodel;
}
#endregion
#region 发送站内信到亚马逊顾客
[WebMethod(EnableSession = true)]
public APIReturnModel SendZNXToAmazonCustomer(int shopid, string orderid, string content, string attachments, string sellerEmail, string customerEmail)
{
PagesNew.Login(this.Session);
var rmodel = new APIReturnModel();
if (string.IsNullOrEmpty(orderid))
{
rmodel.Code = 0;
rmodel.Message = "订单号不能为空";
return rmodel;
}
if (string.IsNullOrEmpty(content) && string.IsNullOrEmpty(attachments))
{
rmodel.Code = 0;
rmodel.Message = "回复信息或者邮件不能都为空";
return rmodel;
}
var shop = DataNew.GetShopInfoByShopid(shopid);
if (shop == null)
{
rmodel.Code = 0;
rmodel.Message = "店铺不存在";
return rmodel;
}
try
{
var ServiceURL = "https://sellingpartnerapi-na.amazon.com";
string url = "http://api.sumool.com/AmazonProxy/NewSendRequest";
#region 设置市场所在地借口地址
switch (shop.Country.ToString())
{
case "美国":
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
break;
case "加拿大":
ServiceURL = "https://sellingpartnerapi-na.amazon.com";
break;
case "欧洲":
ServiceURL = "https://sellingpartnerapi-eu.amazon.com";
break;
case "日本":
ServiceURL = "https://sellingpartnerapi-fe.amazon.com";
break;
case "中国":
ServiceURL = "https://mws.amazonservices.com.cn";
break;
}
#endregion
string str = "EndPoint=" + ServiceURL;
str += "&SumoolToKen=" + shop.RefreshToken;
str += "&SellerId=" + shop.Appkey;
var bodyObj = new AmazonZNXContentModel();
bodyObj.text = content;
//附件添加逻辑将附件文件的服务器地址上传到亚马逊指定的api接口接口会返回uploadDestinationId
if (!string.IsNullOrEmpty(attachments))
{
}
else
bodyObj.attachments = null;
string body = JsonConvert.SerializeObject(bodyObj);
byte[] bytes = Encoding.Default.GetBytes(body);
string bb = Convert.ToBase64String(bytes);
str += "&BodyContent=" + bb;
str += "&Command=/messaging/v1/orders/" + orderid + "/messages/confirmCustomizationDetails?marketplaceIds=" + shop.DeveKey;
str += "&HttpMethod=POST";
var data = Encoding.UTF8.GetBytes(str);
var ErrorMessage = "";
string XmlContent = CustomIO.HttpRequest2(url, "Post", "application/x-www-form-urlencoded; charset=UTF-8", null, HttpVersion.Version10, data, out ErrorMessage);
if (!string.IsNullOrEmpty(ErrorMessage))
throw new Exception(ErrorMessage);
AmazonOrderItemResult model = JsonConvert.DeserializeObject<AmazonOrderItemResult>(XmlContent);
if (model.HasError == true)
{
rmodel.Code = 0;
rmodel.Message = model.Message;
return rmodel;
}
var apiResponse = JsonConvert.DeserializeObject<CreateConfirmCustomizationDetailsResponse>(model.ResultObject);
if (apiResponse != null && apiResponse.errors != null && apiResponse.errors.Count > 0)
{
rmodel.Code = 0;
rmodel.Message = apiResponse.errors.FirstOrDefault().message;
return rmodel;
}
DataNew.InsertShopEmailData(sellerEmail, customerEmail, shopid, orderid, content);
rmodel.Code = 1;
rmodel.Message = "Success";
return rmodel;
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "发生异常:" + ex.Message;
return rmodel;
}
}
#endregion
#region 亚马逊站内信上传附件
[WebMethod]
public APIReturnModel AmazonZNXUpFJ(List<HttpPostedFileBase> files)
{
PagesNew.Login(this.Session);
var rmodel = new APIReturnModel();
if (HttpContext.Current.Request.Files.Count > 0)
{
var renamedFiles = new System.Collections.Generic.List<string>();
for (int i = 0; i < HttpContext.Current.Request.Files.Count; i++)
{
var file = HttpContext.Current.Request.Files[i];
if (file.ContentLength > 0)
{
var newFileName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
var filePath = System.IO.Path.Combine("指定文件夹路径", newFileName); // 指定文件夹路径
file.SaveAs(filePath);
renamedFiles.Add(newFileName);
}
}
//return new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(renamedFiles);
}
return rmodel;
}
#endregion
#region 人员每天填写销售数据
[WebMethod]
public JsonModel<List<PeopleDayFillSaleData>> GetPeopleDayFillSaleDataList(int UserId, DateTime? SDate, DateTime? EDate, int PageIndex, int PageSize)
{
var rmodel = new JsonModel<List<PeopleDayFillSaleData>>();
int rowCount = 0;
rmodel.DataSource = DataNew.GetPeopleDayFillSaleDataList(UserId, SDate, EDate, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 新增或更新人员每天填写销售数据
[WebMethod]
public APIReturnModel SavePeopleDayFillSaleData(SavePeopleDayFillSaleData Model)
{
var rmodel = new APIReturnModel();
try
{
DataNew.InsertPeopleDayFillSaleDataList(Model.ID, Model.UserId, Model.InDate, Model.AdFee, Model.TCB, Model.AdOrderNum, Model.AdSaleAmount);
rmodel.Code = 1;
rmodel.Message = "Success";
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "失败";
}
return rmodel;
}
#endregion
#region 删除人员每天填写销售数据
[WebMethod]
public APIReturnModel DeletePeopleDayFillSaleData(int ID)
{
var rmodel = new APIReturnModel();
try
{
DataNew.DeletePeopleDayFillSaleDataList(ID);
rmodel.Code = 1;
rmodel.Message = "Success";
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "失败";
}
return rmodel;
}
#endregion
#region 商品分类关联的店铺
[WebMethod(EnableSession = true)]
public JsonModel<List<GoodsSortShop>> GetGoodsSortShopList(int? sortId, int? shopId, int PageIndex, int PageSize)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<GoodsSortShop>>();
int rowCount = 0;
rmodel.DataSource = DataNew.GetGoodsSortShopDatas(sortId, shopId, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
return rmodel;
}
[WebMethod(EnableSession = true)]
public APIReturnModel InsertOrUpdateGoodsSortShop(int ID, int sortId, int shopId)
{
PagesNew.Login(this.Session);
var rmodel = new APIReturnModel();
try
{
int code = 0;
if (ID <= 0)
{
code = DataNew.InsertGoodsSortShop(sortId, shopId);
}
else
code = DataNew.UpdateGoodsSortShop(ID, sortId, shopId);
if (code > 0)
{
rmodel.Code = 1;
rmodel.Message = "成功";
}
else
{
rmodel.Code = 0;
rmodel.Message = "数据已存在";
}
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "失败:" + ex.Message;
}
return rmodel;
}
[WebMethod(EnableSession = true)]
public APIReturnModel DeleteGoodsSortShop(int ID)
{
PagesNew.Login(this.Session);
var rmodel = new APIReturnModel();
try
{
DataNew.DeleteGoodsSortShop(ID);
rmodel.Code = 1;
rmodel.Message = "成功";
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "失败:" + ex.Message;
}
return rmodel;
}
#endregion
#region 店铺上架各个类目的商品链接个数
[WebMethod(EnableSession = true)]
public JsonModel<List<ShopGoodsSortLinkCount>> GetShopGoodsSortLinkCountList(int isJSYC)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<ShopGoodsSortLinkCount>>();
var datas = new List<ShopGoodsSortLinkCount>();
var shopLinkList = DataNew.GetShopGoodsSortLinkCountDatas(isJSYC);
//var sorts = DataNew.GetGoodsSortList().Where(r => r.SortId != 758).ToList();//排除畅想导入
var shops = DataNew.GetShopList(1, 2).Where(r => r.ShopId != 62 && r.ShopId != 79).OrderBy(r => r.ShopId).ToList();
foreach (var shop in shops)
{
var item = new ShopGoodsSortLinkCount();
item.ShopId = shop.ShopId.Value;
item.ShopName = shop.ShopName;
item.RYPQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 746).FirstOrDefault()?.Count;
item.JDQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 747).FirstOrDefault()?.Count;
item.CWQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 748).FirstOrDefault()?.Count;
item.DQQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 749).FirstOrDefault()?.Count;
item.ZYLQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 750).FirstOrDefault()?.Count;
item.ETWJQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 751).FirstOrDefault()?.Count;
item.GJQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 752).FirstOrDefault()?.Count;
item.HWTYQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 753).FirstOrDefault()?.Count;
item.JKHLQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 754).FirstOrDefault()?.Count;
item.QPQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 755).FirstOrDefault()?.Count;
item.JRYPQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 756).FirstOrDefault()?.Count;
item.YZQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 757).FirstOrDefault()?.Count;
item.JSQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 759).FirstOrDefault()?.Count;
item.DJQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 760).FirstOrDefault()?.Count;
item.JJQty = shopLinkList.Where(r => r.ShopName.Trim().ToUpper() == shop.ShopName.Trim().ToUpper() && r.SortId == 761).FirstOrDefault()?.Count;
datas.Add(item);
}
var tItem = new ShopGoodsSortLinkCount()
{
ShopId = 0,
ShopName = "汇总",
RYPQty = datas.Sum(r => r.RYPQty),
JDQty = datas.Sum(r => r.JDQty),
CWQty = datas.Sum(r => r.CWQty),
DQQty = datas.Sum(r => r.DQQty),
ZYLQty = datas.Sum(r => r.ZYLQty),
ETWJQty = datas.Sum(r => r.ETWJQty),
GJQty = datas.Sum(r => r.GJQty),
HWTYQty = datas.Sum(r => r.HWTYQty),
JKHLQty = datas.Sum(r => r.JKHLQty),
QPQty = datas.Sum(r => r.QPQty),
JRYPQty = datas.Sum(r => r.JRYPQty),
YZQty = datas.Sum(r => r.YZQty),
JSQty = datas.Sum(r => r.JSQty),
DJQty = datas.Sum(r => r.DJQty),
JJQty = datas.Sum(r => r.JJQty)
};
var allCount = tItem.RYPQty + tItem.JDQty + tItem.CWQty + tItem.DQQty + tItem.ZYLQty + tItem.ETWJQty + tItem.GJQty + tItem.HWTYQty + tItem.JKHLQty + tItem.QPQty + tItem.JRYPQty + tItem.YZQty + tItem.JSQty + tItem.DJQty + tItem.JJQty;
tItem.ShopName = "汇总(" + allCount.ToString() + ")";
datas.Add(tItem);
rmodel.DataSource = datas;
rmodel.RowCount = shops.Count;
return rmodel;
}
#endregion
#region 个人管理商品的销售数据
[WebMethod(EnableSession = true)]
public JsonModel<List<PeoPleGoodsSaleDataModel>> GetPeopleGoodsSaleDatas(int userid, int platId, DateTime sDate, DateTime eDate, int PageIndex, int PageSize, int isGroup = 0)
{
PagesNew.Login(this.Session);
var rmodel = new JsonModel<List<PeoPleGoodsSaleDataModel>>();
int rowCount = 0;
DateTime sdt = DateTime.Now.Date, edt = DateTime.Now.Date;
if (DateTime.Now.Day == 1)//如果当天是一号,则取上个月的三十天数据
{
sdt = DateTime.Now.AddMonths(-1).Date;
edt = DateTime.Now.AddDays(-1).Date;
}
else //否则日期区间从1号开始到当前日期前一天
{
sdt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).Date;//当前月份第一天的日期
edt = DateTime.Now.AddDays(-1).Date;//当前日期前一天
}
if (platId == 2)//亚马逊
{
var userids = new List<int>();
userids.Add(userid);
if (isGroup == 1)
{
var groups = DataNew.GetAllGroupPeopleDatas(userid);
if (groups != null)
userids.AddRange(groups.Select(r => r.UserId.Value).ToList());
}
rmodel.DataSource = DataNew.GetAmazonPeopleGoodsSaleDataList(sDate, eDate, string.Join(",", userids), PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
var monthHs = DataNew.GetAmazonPeopleGoodsMonthHJLR(string.Join(",", userids), sdt, edt);
if (rmodel.DataSource != null)
{
foreach (var item in rmodel.DataSource)
{
var monthHj = monthHs == null ? null : monthHs.Where(r => r.GoodsId == item.GoodsId).FirstOrDefault();
item.MonthHJLR = monthHj == null ? null : monthHj.MonthHJLR;
}
}
}
else if (platId == 3)//EBay
{
rmodel.DataSource = DataNew.GetEBayPeopleGoodsSaleDataList(sDate, eDate, userid, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
var monthHs = DataNew.GetEBayPeopleGoodsMonthHJLR(userid, sdt, edt);
if (rmodel.DataSource != null)
{
foreach (var item in rmodel.DataSource)
{
var monthHj = monthHs == null ? null : monthHs.Where(r => r.GoodsId == item.GoodsId).FirstOrDefault();
item.MonthHJLR = monthHj == null ? null : monthHj.MonthHJLR;
}
}
}
else if (platId == 6)//Wlmart
{
rmodel.DataSource = DataNew.GetWlmartPeopleGoodsSaleDataList(sDate, eDate, userid, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
var monthHs = DataNew.GetWlmartPeopleGoodsMonthHJLR(userid, sdt, edt);
if (rmodel.DataSource != null)
{
foreach (var item in rmodel.DataSource)
{
var monthHj = monthHs == null ? null : monthHs.Where(r => r.GoodsId == item.GoodsId).FirstOrDefault();
item.MonthHJLR = monthHj == null ? null : monthHj.MonthHJLR;
}
}
}
else if (platId == 15) //Shopify
{
rmodel.DataSource = DataNew.GetShopifyPeopleGoodsSaleDataList(sDate, eDate, userid, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
var monthHs = DataNew.GetShopifyPeopleGoodsMonthHJLR(userid, sdt, edt);
if (rmodel.DataSource != null)
{
foreach (var item in rmodel.DataSource)
{
var monthHj = monthHs == null ? null : monthHs.Where(r => r.GoodsId == item.GoodsId).FirstOrDefault();
item.MonthHJLR = monthHj == null ? null : monthHj.MonthHJLR;
}
}
}
else if (platId == 18)//Wayfair
{
rmodel.DataSource = DataNew.GetWayfairPeopleGoodsSaleDataList(sDate, eDate, userid, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
var monthHs = DataNew.GetWayfairPeopleGoodsMonthHJLR(userid, sdt, edt);
if (rmodel.DataSource != null)
{
foreach (var item in rmodel.DataSource)
{
var monthHj = monthHs == null ? null : monthHs.Where(r => r.GoodsId == item.GoodsId).FirstOrDefault();
item.MonthHJLR = monthHj == null ? null : monthHj.MonthHJLR;
}
}
}
else if (platId == 21)//Shein
{
rmodel.DataSource = DataNew.GetSheinPeopleGoodsSaleDataList(sDate, eDate, userid, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
var monthHs = DataNew.GetSheinPeopleGoodsMonthHJLR(userid, sdt, edt);
if (rmodel.DataSource != null)
{
foreach (var item in rmodel.DataSource)
{
var monthHj = monthHs == null ? null : monthHs.Where(r => r.GoodsId == item.GoodsId).FirstOrDefault();
item.MonthHJLR = monthHj == null ? null : monthHj.MonthHJLR;
}
}
}
return rmodel;
}
#endregion
#region 导入店铺商品每天的广告花费
[WebMethod(EnableSession = true)]
public string ImportShopGoodsAdFee(string FileName, int ShopId)
{
Pages.Login(this.Session);
if (string.IsNullOrEmpty(FileName) == true) return "要导入的文件路径不能为空";
string ServerFileName = AppDomain.CurrentDomain.BaseDirectory + FileName;
if (System.IO.File.Exists(ServerFileName) == false) return "要导入的文件路径不存在";
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
try
{
MicrosoftExcel excel = new MicrosoftExcel();
DataTable tb = excel.ImportExcel(ServerFileName);
string error = "";
int drCount = 0;
var goodsList = new List<ShopGoodsAdFeeModel>();
for (int i = 0; i < tb.Rows.Count; i++)
{
var rmodel = new ShopGoodsAdFeeModel();
if (string.IsNullOrEmpty(tb.Rows[i][0].ToString()))
{
error += "第" + (i + 1) + "行日期为空; ";
continue;
}
rmodel.AdDate = Convert.ToDateTime(tb.Rows[i][0].ToString());
if (string.IsNullOrEmpty(tb.Rows[i][1].ToString()))
{
error += "第" + (i + 1) + "行商品SKU为空; ";
continue;
}
var hwDetail = DataNew.GetGoodsDetailBySku(tb.Rows[i][1].ToString());
if (hwDetail == null)
{
error += "第" + (i + 1) + "行商品SKU未匹配到商品; ";
continue;
}
rmodel.GoodSku = tb.Rows[i][1].ToString();
rmodel.DetailId = hwDetail.DetailId;
rmodel.GoodsId = hwDetail.GoodsId;
rmodel.AdFee = string.IsNullOrEmpty(tb.Rows[i][2].ToString()) ? 0 : Convert.ToDecimal(tb.Rows[i][2]);
rmodel.AdOrderCount = string.IsNullOrEmpty(tb.Rows[i][3].ToString()) ? 0 : Convert.ToInt32(tb.Rows[i][3]);
rmodel.AdSaleAmount = string.IsNullOrEmpty(tb.Rows[i][4].ToString()) ? 0 : Convert.ToDecimal(tb.Rows[i][4]);
rmodel.ShopId = ShopId;
if (DataNew.UpdateOrInsertShopGoodsAdFee(rmodel))
{
drCount++;
}
else
{
error += "第" + (i + 1) + "行导入失败; ";
}
}
if (string.IsNullOrEmpty(error))
return "导入成功";
else
return error;
}
catch (Exception ex)
{
return "文件导入失败:" + ex.Message;
}
}
#endregion
#region 获取店铺商品每天的广告花费
[WebMethod(EnableSession = true)]
public JsonModel<List<ShopGoodsAdFeeModel>> GetShopGoodsAdFeeList(int shopId, DateTime? sDate, DateTime? eDate, int PageIndex, int PageSize)
{
Pages.Login(this.Session);
var rmodel = new JsonModel<List<ShopGoodsAdFeeModel>>();
int rowCount = 0;
rmodel.DataSource = DataNew.GetShopGoodsAdFeeModel(shopId, sDate, eDate, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
/// <summary>
/// 上传快递面单图片
/// </summary>
/// <returns></returns>
[WebMethod(EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void UploadTrackCodeImages()
{
PagesNew.Login(base.Session);
var rmodel = new APIReturnModel();
var httpRequest = System.Web.HttpContext.Current.Request;
var context = System.Web.HttpContext.Current;
try
{
int errorCount = 0;
string errorMsg = "";
if (httpRequest.Files.Count > 0)
{
for (int i = 0; i < httpRequest.Files.Count; i++)
{
var imgPath = System.AppDomain.CurrentDomain.BaseDirectory + "attached/";
var file = httpRequest.Files[i];
var fileName = file.FileName;
var trackCode = fileName.Split('.')[0];
var endName = fileName.Split('.')[1];//结尾
if (string.IsNullOrEmpty(trackCode))
{
errorCount++;
errorMsg += fileName + "; ";
continue;
}
var trackName = DataNew.GetTrackCodePostName(trackCode);
if (trackName != null)
{
if (trackName.ToUpper().Contains("FEDEX"))
{
imgPath += "fedex/" + trackCode;
}
else if (trackName.ToUpper().Contains("UPS"))
{
imgPath += "ups/" + trackCode;
}
else if (trackName.ToUpper().Contains("USPS"))
{
imgPath += "usps/" + trackCode;
}
else if (trackName.Contains("客户自提"))
{
imgPath += "khzt/" + trackCode;
}
else
{
errorCount++;
errorMsg += fileName + "; ";
continue;
}
if (File.Exists(imgPath + "." + endName))
{
// 文件存在,删除文件
File.Delete(imgPath + "." + endName);
}
file.SaveAs(imgPath + "." + endName);
//如果上传的面单是pdf的则需要转换成PNG格式
if (endName.ToLower() == "pdf")
{
// 打开 PDF 文档
PdfReader pdfReader = new PdfReader(imgPath + "." + endName);
// 获取 PDF 文档的页数
int pageCount = pdfReader.NumberOfPages;
pdfReader.Close();
if (pageCount == 1)
{
PdfDocument pdf = new PdfDocument();
//加载需要转换的PDF文档
pdf.LoadFromFile(imgPath + "." + endName);
//超过多页的pdf文件直接保存打印的时候直接打印多张pdf
//循环遍历每个页面
for (int j = 0; j < pdf.Pages.Count; j++)
{
//将所有页面转换为图像并设置图像Dpi
System.Drawing.Image image = pdf.SaveAsImage(j, PdfImageType.Bitmap, 500, 500);
//设置图像格式
String pngfile = String.Format(imgPath + ".png", j);
//如果上传的是Fedex的面单把pdf转换成PNG之后统一图片分辨率为2000*3000否则仓库会打印尺寸异常
if (trackName.ToUpper().Contains("FEDEX"))
{
// 调整图像大小为2000*3000px
System.Drawing.Bitmap resizedImage = new System.Drawing.Bitmap(image, 2000, 3000);
resizedImage.Save(pngfile, System.Drawing.Imaging.ImageFormat.Png);
}
else if (trackName.ToUpper().Contains("USPS")) //USPS的面单横向打印出来有问题顺时针旋转90°变成竖向
{
//图片旋转90°
image.RotateFlip(RotateFlipType.Rotate90FlipNone);
//重新改变图片尺寸
System.Drawing.Bitmap resizedImage = new System.Drawing.Bitmap(image, 2000, 3000);
//保存改变后的图片
resizedImage.Save(pngfile, System.Drawing.Imaging.ImageFormat.Png);
}
else
{
image.Save(pngfile, System.Drawing.Imaging.ImageFormat.Png);
}
}
fileName = trackCode + ".png";
}
//PdfDocument pdf = new PdfDocument();
////加载需要转换的PDF文档
//pdf.LoadFromFile(imgPath + "." + endName);
////超过多页的pdf文件直接保存打印的时候直接打印多张pdf
//if (pdf.Pages.Count >= 2)
//{
// //errorCount++;
// //errorMsg += fileName + "; ";
// //continue;
//}
//else
//{
// //循环遍历每个页面
// for (int j = 0; j < pdf.Pages.Count; j++)
// {
// //将所有页面转换为图像并设置图像Dpi
// System.Drawing.Image image = pdf.SaveAsImage(j, PdfImageType.Bitmap, 500, 500);
// //设置图像格式
// String pngfile = String.Format(imgPath + ".png", j);
// image.Save(pngfile, System.Drawing.Imaging.ImageFormat.Png);
// }
// fileName = trackCode + ".png";
//}
}
DataNew.UpdateTrackCodeImage(trackCode, fileName);
}
else
{
errorCount++;
errorMsg += fileName + "; ";
}
//imgPath += "test/" + fileName;
//if (File.Exists(imgPath))
//{
// // 文件存在,删除文件
// File.Delete(imgPath);
//}
//file.SaveAs(imgPath);
//PdfDocument pdf = new PdfDocument();
////加载需要转换的PDF文档
//pdf.LoadFromFile(imgPath);
////循环遍历每个页面
//for (int j = 0; j < pdf.Pages.Count; j++)
//{
// //将所有页面转换为图像并设置图像Dpi
// System.Drawing.Image image = pdf.SaveAsImage(j, PdfImageType.Bitmap, 500, 500);
// //设置图像格式
// String pngfile = String.Format(imgPath2 + "test/" + trackCode + ".png", j);
// image.Save(pngfile, System.Drawing.Imaging.ImageFormat.Png);
//}
//if (File.Exists(imgPath))
//{
// // 文件存在,删除文件
// File.Delete(imgPath);
//}
//file.SaveAs(imgPath);
//if (string.IsNullOrEmpty(trackCode))
//{
// errorCount++;
// errorMsg += fileName + "; ";
// continue;
//}
//var trackName = DataNew.GetTrackCodePostName(trackCode);
//if (trackName != null)
//{
// var imgPath = System.AppDomain.CurrentDomain.BaseDirectory + "attached/";
// if (trackName.ToUpper().Contains("FEDEX"))
// {
// imgPath += "fedex/" + fileName;
// }
// else if (trackName.ToUpper().Contains("UPS"))
// {
// imgPath += "ups/" + fileName;
// }
// else if (trackName.ToUpper().Contains("USPS"))
// {
// imgPath += "usps/" + fileName;
// }
// else if (trackName.Contains("客户自提"))
// {
// imgPath += "khzt/" + fileName;
// }
// else
// {
// errorCount++;
// errorMsg += fileName + "; ";
// continue;
// }
// if (File.Exists(imgPath))
// {
// // 文件存在,删除文件
// File.Delete(imgPath);
// }
// file.SaveAs(imgPath);
// DataNew.UpdateTrackCodeImage(trackCode, fileName);
//}
//else
//{
// errorCount++;
// errorMsg += fileName + "; ";
//}
}
}
if (errorCount > 0)
{
rmodel.Code = 0;
rmodel.Message = errorCount + " failed uploads:" + errorMsg;
}
else
{
rmodel.Code = 1;
rmodel.Message = "success";
}
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = ex.Message;
}
var serializer = new JavaScriptSerializer();
// 设置响应的内容类型为 JSON
context.Response.ContentType = "application/json";
context.Response.Write(serializer.Serialize(rmodel));
context.Response.End();
}
#region 首页发货面单统计
[WebMethod(EnableSession = true)]
public DT_LabelNum GetLablesCount(int Days)
{
PagesNew.Login(this.Session);
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
var obj = new DD_OrderData();
string Ids = "";
string[] categories = null;
DT_LabelNum md = new DT_LabelNum();
var list = new List<DT_LabelCountData>();
DateTime SDate = DateTime.Today.AddDays(-1 * Days);
DateTime EDate = DateTime.Today;
TimeSpan ts = EDate - SDate;
int days = ts.Days + 1;
List<DT_CountLabelsFromDay> countlist = new List<DT_CountLabelsFromDay>();
countlist = DataNew.GetCountListLabels("w", SDate, EDate.AddDays(1), 0);
if (countlist == null)
countlist = new List<DT_CountLabelsFromDay>();
List<DT_CountLabelsFromDay> countlist2 = new List<DT_CountLabelsFromDay>();
countlist2 = DataNew.GetCountListLabels("w", SDate, EDate.AddDays(1), 1);
if (countlist2 == null)
countlist2 = new List<DT_CountLabelsFromDay>();
List<DT_CountLabelsFromDay> countlist3 = new List<DT_CountLabelsFromDay>();
countlist3 = DataNew.GetCountListLabels("e", SDate, EDate.AddDays(1), 0);
if (countlist3 == null)
countlist3 = new List<DT_CountLabelsFromDay>();
List<DT_CountLabelsFromDay> countlist4 = new List<DT_CountLabelsFromDay>();
countlist4 = DataNew.GetCountListLabels("e", SDate, EDate.AddDays(1), 1);
if (countlist4 == null)
countlist4 = new List<DT_CountLabelsFromDay>();
categories = new string[days];
var categories2 = new string[days];
if (days > 0)
{
for (int i = 0; i < days; i++)
{
categories[i] = (SDate.AddDays(i)).ToString("MM月dd日");
categories2[i] = (SDate.AddDays(i)).ToString("yyyy-MM-dd");
}
}
#region
//decimal[] data = new decimal[days];
//decimal[] data2 = new decimal[days];
//decimal[] data3 = new decimal[days];
//decimal[] data4 = new decimal[days];
//for (int j = 0; j < days; j++)
//{
// var glist = countlist.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
// if (glist == null)
// {
// data[j] = 0;
// }
// else
// data[j] = glist.num.Value;
// if (countlist2 != null)
// {
// var glist2 = countlist2.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
// if (glist2 == null)
// {
// data2[j] = 0;
// }
// else
// data2[j] = glist2.num.Value;
// }
// else
// data2[j] = 0;
// if (countlist3 != null)
// {
// var glist3 = countlist3.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
// if (glist3 == null)
// {
// data3[j] = 0;
// }
// else
// data3[j] = glist3.num.Value;
// }
// else
// data3[j] = 0;
// if (countlist4 != null)
// {
// var glist4 = countlist4.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
// if (glist4 == null)
// {
// data4[j] = 0;
// }
// else
// data4[j] = glist4.num.Value;
// }
// else
// data4[j] = 0;
//}
#endregion
List<DT_LabelNumAndColor> data = new List<DT_LabelNumAndColor>();
List<DT_LabelNumAndColor> data2 = new List<DT_LabelNumAndColor>();
List<DT_LabelNumAndColor> data3 = new List<DT_LabelNumAndColor>();
List<DT_LabelNumAndColor> data4 = new List<DT_LabelNumAndColor>();
for (int j = 0; j < days; j++)
{
var d1 = new DT_LabelNumAndColor();
var glist = countlist.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist == null)
{
d1.y = 0;
}
else
{
d1.y = glist.num.Value;
}
d1.color = "lightblue";
data.Add(d1);
var d2 = new DT_LabelNumAndColor();
if (countlist2 != null)
{
var glist2 = countlist2.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist2 == null)
{
d2.y = 0;
}
else
d2.y= glist2.num.Value;
}
else
d2.y = 0;
if (d1.y > 0)
d2.color = "lightblue";
else
d2.color = "lightgreen";
data2.Add(d2);
var d3 = new DT_LabelNumAndColor();
if (countlist3 != null)
{
var glist3 = countlist3.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist3 == null)
{
d3.y = 0;
}
else
d3.y= glist3.num.Value;
}
else
d3.y = 0;
d3.color = "lightblue";
data3.Add(d3);
var d4 = new DT_LabelNumAndColor();
if (countlist4 != null)
{
var glist4 = countlist4.Find(n => n.PostDate == SDate.AddDays(j).ToString("yyyy-MM-dd"));
if (glist4 == null)
{
d4.y = 0;
}
else
d4.y = glist4.num.Value;
}
else
d4.y = 0;
if (d3.y > 0)
d4.color = "lightblue";
else
d4.color = "lightgreen";
data4.Add(d4);
}
var datamd = new DT_LabelCountData();
datamd.name = "W仓未发货";
datamd.data = data;
datamd.stack = "W";
datamd.color = "lightblue";
list.Add(datamd);
datamd = new DT_LabelCountData();
datamd.name = "W仓已发货";
datamd.data = data2;
datamd.stack = "W";
datamd.color = "lightgreen";
list.Add(datamd);
datamd = new DT_LabelCountData();
datamd.name = "E仓未发货";
datamd.stack = "E";
datamd.data = data3;
datamd.color = "lightblue";
list.Add(datamd);
datamd = new DT_LabelCountData();
datamd.name = "E仓已发货";
datamd.stack = "E";
datamd.data = data4;
datamd.color = "lightgreen";
list.Add(datamd);
md.categories = categories;
md.categories2 = categories2;
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
string postmessage = JsonConvert.Serialize(list);
md.Data = postmessage;
return md;
}
#endregion
#region 添加/编辑人员
[WebMethod(EnableSession = true)]
public APIReturnModel CreateUser(UserInfoModel model)
{
var rmodel = new APIReturnModel();
try
{
DataNew.CreateUser(model.ID, model.UserName, model.Dep);
rmodel.Code = 1;
rmodel.Message = "Success";
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "失败";
}
return rmodel;
}
#endregion
#region 人员下拉列表
[WebMethod(EnableSession = true)]
public List<UserInfoModel> GetUserList()
{
PagesNew.Login(this.Session);
var ListModel = DataNew.GetUserList();
return ListModel;
}
#endregion
#region 导入人员列表
[WebMethod(EnableSession = true)]
public string ImportUserList(string FileName)
{
PagesNew.Login(this.Session);
if (string.IsNullOrEmpty(FileName) == true) return "要导入的文件路径不能为空";
string ServerFileName = AppDomain.CurrentDomain.BaseDirectory + FileName;
if (System.IO.File.Exists(ServerFileName) == false) return "要导入的文件路径不存在";
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
try
{
MicrosoftExcel excel = new MicrosoftExcel();
DataTable tb = excel.ImportExcel(ServerFileName);
string error = "";
if (tb.Columns.Contains("UserName") == false) { error = error + "导入模板的 UserName 列不存在"; }
if (tb.Columns.Contains("Dep") == false) { error = error + "导入模板的 Dep 列不存在"; }
if (string.IsNullOrEmpty(error) == false) return error + "导入格式不正确";
List<UserInfoModel> UserList = new List<UserInfoModel>();
int count = 0;
for (int i = 0; i < tb.Rows.Count; i++)
{
UserInfoModel md = new UserInfoModel();
if (tb.Rows[i]["UserName"].ToString().Trim() != "")
{
md.UserName = tb.Rows[i]["UserName"].ToString().Trim();
md.Dep = tb.Rows[i]["Dep"].ToString().Trim();
int a = DataNew.Save_UserInfo(md);
if (a == -1)
{
error += md.UserName + "姓名对应不上";
}
else if (a == -2)
{
error += md.Dep + "部门对应不上";
}
else
{
count++;
}
}
}
error = "数据导入成功【" + count + "条】;" + error;
return error;
}
catch (Exception e)
{
return "文件导入失败!请确定模板格式是否正确,或者重新下载模板,填写数据,重新导入!!!" + e.Message;
}
}
#endregion
#region 人员列表
[WebMethod(EnableSession = true)]
public JsonModel<List<UserInfoModel>> GetUserInfoList(int ID, int PageIndex, int PageSize)
{
var rmodel = new JsonModel<List<UserInfoModel>>();
int rowCount = 0;
rmodel.DataSource = DataNew.GetUserInfoList(ID, PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 删除
[WebMethod]
public APIReturnModel DelUserInfo(int ID)
{
var rmodel = new APIReturnModel();
try
{
DataNew.DelUserInfo(ID);
rmodel.Code = 1;
rmodel.Message = "Success";
}
catch (Exception ex)
{
rmodel.Code = 0;
rmodel.Message = "失败";
}
return rmodel;
}
#endregion
#region 导入出勤数据
[WebMethod(EnableSession = true)]
public string ImportAttData(string FileName)
{
PagesNew.Login(this.Session);
if (string.IsNullOrEmpty(FileName) == true) return "要导入的文件路径不能为空";
string ServerFileName = AppDomain.CurrentDomain.BaseDirectory + FileName;
if (System.IO.File.Exists(ServerFileName) == false) return "要导入的文件路径不存在";
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
try
{
MicrosoftExcel excel = new MicrosoftExcel();
DataTable tb = excel.ImportExcel(ServerFileName);
string error = "";
if (tb.Columns.Contains("姓名") == false) { error = error + "导入模板的 姓名 列不存在"; }
if (tb.Columns.Contains("出勤日期") == false) { error = error + "导入模板的 出勤日期 列不存在"; }
if (tb.Columns.Contains("上班时间(实际打卡时间)") == false) { error = error + "导入模板的 上班时间(实际打卡时间) 列不存在"; }
if (tb.Columns.Contains("下班时间(实际打卡时间)") == false) { error = error + "导入模板的 下班时间(实际打卡时间) 列不存在"; }
if (tb.Columns.Contains("请假起始时间") == false) { error = error + "导入模板的 请假起始时间 列不存在"; }
if (tb.Columns.Contains("请假结束时间") == false) { error = error + "导入模板的 请假结束时间 列不存在"; }
if (tb.Columns.Contains("出差起始时间") == false) { error = error + "导入模板的 出差起始时间 列不存在"; }
if (tb.Columns.Contains("出差结束时间") == false) { error = error + "导入模板的 出差结束时间 列不存在"; }
if (tb.Columns.Contains("外出起始时间") == false) { error = error + "导入模板的 外出起始时间 列不存在"; }
if (tb.Columns.Contains("外出结束时间") == false) { error = error + "导入模板的 外出结束时间 列不存在"; }
if (tb.Columns.Contains("原因") == false) { error = error + "导入模板的 原因 列不存在"; }
if (tb.Columns.Contains("备注") == false) { error = error + "导入模板的 备注 列不存在"; }
if (string.IsNullOrEmpty(error) == false) return error + "导入格式不正确";
List<AttendanceModel> AttList = new List<AttendanceModel>();
int count = 0;
for (int i = 0; i < tb.Rows.Count; i++)
{
AttendanceModel md = new AttendanceModel();
if (tb.Rows[i]["姓名"].ToString().Trim() != "")
{
md.UserName = tb.Rows[i]["姓名"].ToString().Trim();
if (tb.Rows[i]["出勤日期"].ToString().Trim() != "")
{
md.AttDate = Convert.ToDateTime(tb.Rows[i]["出勤日期"].ToString().Trim());
}
if (tb.Rows[i]["上班时间(实际打卡时间)"].ToString().Trim() != "")
{
md.WorkTime = Convert.ToDateTime(tb.Rows[i]["上班时间(实际打卡时间)"].ToString().Trim());
}
else
{
md.WorkTime = null;
}
if (tb.Rows[i]["下班时间(实际打卡时间)"].ToString().Trim() != "")
{
md.AfterWorkTime = Convert.ToDateTime(tb.Rows[i]["下班时间(实际打卡时间)"].ToString().Trim());
}
else
{
md.AfterWorkTime = null;
}
if (tb.Rows[i]["请假起始日期"].ToString().Trim() != "" || tb.Rows[i]["请假起始时间"].ToString().Trim() != "")
{
DateTime LeaveStrDate = Convert.ToDateTime(tb.Rows[i]["请假起始日期"].ToString().Trim());
DateTime LeaveStrTime = Convert.ToDateTime(tb.Rows[i]["请假起始时间"].ToString().Trim());
md.StartLeaveDate = new DateTime(LeaveStrDate.Year, LeaveStrDate.Month, LeaveStrDate.Day, LeaveStrTime.Hour, LeaveStrTime.Minute, LeaveStrTime.Second);
}
else
{
md.StartLeaveDate = null;
}
if (tb.Rows[i]["请假结束日期"].ToString().Trim() != "" || tb.Rows[i]["请假结束时间"].ToString().Trim() != "")
{
DateTime LeaveEndDate = Convert.ToDateTime(tb.Rows[i]["请假结束日期"].ToString().Trim());
DateTime LeaveEndTime = Convert.ToDateTime(tb.Rows[i]["请假结束时间"].ToString().Trim());
md.EndLeaveDate = new DateTime(LeaveEndDate.Year, LeaveEndDate.Month, LeaveEndDate.Day, LeaveEndTime.Hour, LeaveEndTime.Minute, LeaveEndTime.Second);
}
else
{
md.EndLeaveDate = null;
}
if (tb.Rows[i]["出差起始日期"].ToString().Trim() != "" || tb.Rows[i]["出差起始时间"].ToString().Trim() != "")
{
DateTime TravelStrDate = Convert.ToDateTime(tb.Rows[i]["出差起始日期"].ToString().Trim());
DateTime TravelStrTime = Convert.ToDateTime(tb.Rows[i]["出差起始时间"].ToString().Trim());
md.TravelStartDate = new DateTime(TravelStrDate.Year, TravelStrDate.Month, TravelStrDate.Day, TravelStrTime.Hour, TravelStrTime.Minute, TravelStrTime.Second);
}
else
{
md.TravelStartDate = null;
}
if (tb.Rows[i]["出差结束日期"].ToString().Trim() != "" || tb.Rows[i]["出差结束时间"].ToString().Trim() != "")
{
DateTime TravelEndDate = Convert.ToDateTime(tb.Rows[i]["出差结束日期"].ToString().Trim());
DateTime TravelEndTime = Convert.ToDateTime(tb.Rows[i]["出差结束时间"].ToString().Trim());
md.TravelEndDate = new DateTime(TravelEndDate.Year, TravelEndDate.Month, TravelEndDate.Day, TravelEndTime.Hour, TravelEndTime.Minute, TravelEndTime.Second);
}
else
{
md.TravelEndDate = null;
}
if (tb.Rows[i]["外出起始日期"].ToString().Trim() != "" || tb.Rows[i]["外出起始时间"].ToString().Trim() != "")
{
DateTime OutStrDate = Convert.ToDateTime(tb.Rows[i]["外出起始日期"].ToString().Trim());
DateTime OutStrTime = Convert.ToDateTime(tb.Rows[i]["外出起始时间"].ToString().Trim());
md.OutStartDate = new DateTime(OutStrDate.Year, OutStrDate.Month, OutStrDate.Day, OutStrTime.Hour, OutStrTime.Minute, OutStrTime.Second);
}
else
{
md.OutStartDate = null;
}
if (tb.Rows[i]["外出结束日期"].ToString().Trim() != "" || tb.Rows[i]["外出结束时间"].ToString().Trim() != "")
{
DateTime OutEndDate = Convert.ToDateTime(tb.Rows[i]["外出结束日期"].ToString().Trim());
DateTime OutEndTime = Convert.ToDateTime(tb.Rows[i]["外出结束时间"].ToString().Trim());
md.OutEndDate = new DateTime(OutEndDate.Year, OutEndDate.Month, OutEndDate.Day, OutEndTime.Hour, OutEndTime.Minute, OutEndTime.Second);
}
else
{
md.OutEndDate = null;
}
string reasonString = tb.Rows[i]["原因"].ToString().Trim();
if (Enum.TryParse<Reason>(reasonString, out Reason reason))
{
md.Reason = reason; // 假设md.Reason是ReasonEnum类型
}
md.Notes = tb.Rows[i]["备注"].ToString().Trim();
int a = DataNew.Save_AttData(md);
if (a == -1)
{
error += md.UserName + "姓名对应不上";
}
else if (a == -2)
{
error += md.AttDate + "日期对应不上";
}
else if (a == -3)
{
error += md.WorkTime + "上班时间(实际打卡时间)对应不上";
}
else if (a == -4)
{
error += md.AfterWorkTime + "下班时间(实际打卡时间)对应不上";
}
else if (a == -5)
{
error += md.StartLeaveDate + "请假起始时间对应不上";
}
else if (a == -6)
{
error += md.EndLeaveDate + "请假结束时间对应不上";
}
else if (a == -7)
{
error += md.TravelStartDate + "出差起始时间对应不上";
}
else if (a == -8)
{
error += md.TravelEndDate + "出差结束时间对应不上";
}
else if (a == -9)
{
error += md.OutStartDate + "外出起始时间对应不上";
}
else if (a == -10)
{
error += md.OutEndDate + "外出结束时间对应不上";
}
else if (a == -11)
{
error += md.Reason + "原因对应不上";
}
else if (a == -12)
{
error += md.Notes + "备注对应不上";
}
else
{
count++;
}
DataNew.GiveUserIDformAtt(md);
}
}
error = "数据导入成功【" + count + "条】;" + error;
return error;
}
catch (Exception e)
{
return "文件导入失败!请确定模板格式是否正确,或者重新下载模板,填写数据,重新导入!!!" + e.Message;
}
}
#endregion
#region 导入打卡时间
[WebMethod(EnableSession = true)]
public string ImportClockData(string FileName)
{
PagesNew.Login(this.Session);
if (string.IsNullOrEmpty(FileName) == true) return "要导入的文件路径不能为空";
string ServerFileName = AppDomain.CurrentDomain.BaseDirectory + FileName;
if (System.IO.File.Exists(ServerFileName) == false) return "要导入的文件路径不存在";
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
try
{
MicrosoftExcel excel = new MicrosoftExcel();
DataTable tb = excel.ImportExcel(ServerFileName);
string error = "";
if (tb.Columns.Contains("姓名") == false) { error = error + "导入模板的 姓名 列不存在"; }
if (tb.Columns.Contains("打卡时间") == false) { error = error + "导入模板的 出勤日期 列不存在"; }
if (string.IsNullOrEmpty(error) == false) return error + "导入格式不正确";
List<ClockModel> ClockList = new List<ClockModel>();
int count = 0;
for (int i = 0; i < tb.Rows.Count; i++)
{
ClockModel md = new ClockModel();
if (tb.Rows[i]["姓名"].ToString().Trim() != "")
{
md.UserName = tb.Rows[i]["姓名"].ToString().Trim();
if (tb.Rows[i]["打卡时间"].ToString().Trim() != "")
{
md.ClockDate = Convert.ToDateTime(tb.Rows[i]["打卡时间"].ToString().Trim());
}
else
{
md.ClockDate = null;
}
int a = DataNew.Save_ClockData(md);
if (a == -1)
{
error += md.UserName + "姓名对应不上";
}
else if (a == -2)
{
error += md.ClockDate + "打卡时间对应不上";
}
else
{
count++;
}
DataNew.ClockTime();
}
}
error = "数据导入成功【" + count + "条】;" + error;
return error;
}
catch (Exception e)
{
return "文件导入失败!请确定模板格式是否正确,或者重新下载模板,填写数据,重新导入!!!" + e.Message;
}
}
#endregion
#region 出勤列表
[WebMethod(EnableSession = true)]
public JsonModel<List<UserAttendanceDto>> GetUserAttendanceList(int PageIndex, int PageSize)
{
var rmodel = new JsonModel<List<UserAttendanceDto>>();
int rowCount = 0;
rmodel.DataSource = DataNew.GetUserAttendanceList(PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 导入加班数据
[WebMethod(EnableSession = true)]
public string ImportSurData(string FileName)
{
PagesNew.Login(this.Session);
if (string.IsNullOrEmpty(FileName) == true) return "要导入的文件路径不能为空";
string ServerFileName = AppDomain.CurrentDomain.BaseDirectory + FileName;
if (System.IO.File.Exists(ServerFileName) == false) return "要导入的文件路径不存在";
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
try
{
MicrosoftExcel excel = new MicrosoftExcel();
DataTable tb = excel.ImportExcel(ServerFileName);
string error = "";
if (tb.Columns.Contains("姓名") == false) { error = error + "导入模板的 姓名 列不存在"; }
if (tb.Columns.Contains("加班起始时间") == false) { error = error + "导入模板的 加班起始时间 列不存在"; }
if (tb.Columns.Contains("加班结束时间") == false) { error = error + "导入模板的 加班结束时间 列不存在"; }
if (tb.Columns.Contains("备注") == false) { error = error + "导入模板的 备注 列不存在"; }
if (string.IsNullOrEmpty(error) == false) return error + "导入格式不正确";
List<SurplusWorkModel> SurList = new List<SurplusWorkModel>();
int count = 0;
for (int i = 0; i < tb.Rows.Count; i++)
{
SurplusWorkModel md = new SurplusWorkModel();
if (tb.Rows[i]["姓名"].ToString().Trim() != "")
{
md.UserName = tb.Rows[i]["姓名"].ToString().Trim();
if (tb.Rows[i]["加班起始日期"].ToString().Trim() != "" || tb.Rows[i]["加班起始时间"].ToString().Trim() != "")
{
DateTime SurStrDate = Convert.ToDateTime(tb.Rows[i]["加班起始日期"].ToString().Trim());
DateTime SurStrTime = Convert.ToDateTime(tb.Rows[i]["加班起始日期"].ToString().Trim());
md.SurplusWorkStartDate = new DateTime(SurStrDate.Year, SurStrDate.Month, SurStrDate.Day, SurStrTime.Hour, SurStrTime.Minute, SurStrTime.Second);
}
else
{
md.SurplusWorkStartDate = null;
}
if (tb.Rows[i]["加班结束日期"].ToString().Trim() != "" || tb.Rows[i]["加班结束时间"].ToString().Trim() != "")
{
DateTime SurEndDate = Convert.ToDateTime(tb.Rows[i]["加班结束日期"].ToString().Trim());
DateTime SurEndTime = Convert.ToDateTime(tb.Rows[i]["加班结束时间"].ToString().Trim());
md.SurplusWorkEndDate = new DateTime(SurEndDate.Year, SurEndDate.Month, SurEndDate.Day, SurEndTime.Hour, SurEndTime.Minute, SurEndTime.Second);
}
else
{
md.SurplusWorkEndDate = null;
}
md.Notes = tb.Rows[i]["备注"].ToString().Trim();
int a = DataNew.Save_SurData(md);
if (a == -1)
{
error += md.UserName + "姓名对应不上";
}
else if (a == -2)
{
error += md.SurplusWorkStartDate + "加班起始时间对应不上";
}
else if (a == -3)
{
error += md.SurplusWorkEndDate + "加班结束时间对应不上";
}
else if (a == -4)
{
error += md.Notes + "备注对应不上";
}
else
{
count++;
}
DataNew.GiveUserIDformSur(md);
}
}
error = "数据导入成功【" + count + "条】;" + error;
return error;
}
catch (Exception e)
{
return "文件导入失败!请确定模板格式是否正确,或者重新下载模板,填写数据,重新导入!!!" + e.Message;
}
}
#endregion
#region 加班列表
[WebMethod(EnableSession = true)]
public JsonModel<List<UserSurDto>> GetUserSurList(int PageIndex, int PageSize)
{
var rmodel = new JsonModel<List<UserSurDto>>();
int rowCount = 0;
rmodel.DataSource = DataNew.GetUserSurList(PageIndex, PageSize, out rowCount);
rmodel.RowCount = rowCount;
return rmodel;
}
#endregion
#region 汇总列表
[WebMethod(EnableSession = true)]
public JsonModel<List<SummaryDataDto>> GetSummaryDataList()
{
var rmodel = new JsonModel<List<SummaryDataDto>>();
rmodel.DataSource = DataNew.GetSummaryDataList();
return rmodel;
}
#endregion
#region 导出汇总数据
[WebMethod(EnableSession = true)]
public string Get_SummaryDataExcel()
{
// 这里确保您的登录逻辑正确
PagesNew.Login(this.Session);
var slist = DataNew.GetSummaryDataList();
var hlist = new List<SummaryDataDto>();
TableColumnCollection listColumns = new TableColumnCollection();
// 添加列信息
listColumns.Add("ID", "序号", DbType.String, "");
listColumns.Add("UserName", "姓名", DbType.String, "");
listColumns.Add("ShouldAtt", "应出勤", DbType.String, "");
listColumns.Add("WithinTenMin", "10分钟内迟到次数", DbType.String, "");
listColumns.Add("OutsideTenMin", "10分钟外迟到次数", DbType.String, "");
listColumns.Add("TravelDays", "出差天数", DbType.String, "");
listColumns.Add("OutDays", "外出天数", DbType.String, "");
listColumns.Add("AffairLeaveHours", "请假时长(事假)", DbType.String, "");
listColumns.Add("SickLeaveHours", "请假时长(病假)", DbType.String, "");
listColumns.Add("DaySurplusWork", "日加班时长", DbType.String, "");
listColumns.Add("WorkDayTwoHoursNum", "工作日2小时以上次数", DbType.String, "");
listColumns.Add("WeekendSurplusWorkHoursInFour", "周末加班时(<=4H)", DbType.String, "");
listColumns.Add("WeekendSurplusWorkHoursOutFour", "周末加班时(>4H)", DbType.String, "");
// 调用 Excel 导出方法并返回结果
MicrosoftExcel obj2 = new MicrosoftExcel();
return obj2.Export(slist, listColumns);
}
#endregion
#region 报价单正式应用
#region 客户登陆 ok
[WebMethod(EnableSession = true)]
public AppResultModel<string> LoginNew_PhoneApp(string UserName, string PassWord)
{
//客户登录尝试
var model_client = DataNew.LoginNew_Client(UserName, PassWord);
var resultModel = new AppResultModel<string>();
try
{
if (model_client == null)
{
//客户登录失败
//尝试用户登录
var model_user = DataNew.LoginNew_User(UserName, PassWord);
if (model_user == null)
{
resultModel.result = false;
resultModel.msg = $"用户名或密码错误,请重试!";
return resultModel;
}
else
{
//用户登录成功
Session["IsClient"] = false;
Session["IsPdf"] = "0";
Session["Name"] = model_user.Name;
Session["UserId"] = model_user.UserId;
//Session["Login_UserModel"] = model_user;
//Session["Login_ClientModel"] = model_user;
//resultModel.result = true;
//resultModel.data = "登录成功";
//resultModel.msg = "登录成功";
}
}
else
{
//客户登录成功
Session["IsClient"] = true;
Session["ClientId"] = model_client.Id;
Session["UserId"] = model_client.Id;
Session["Name"] = model_client.ClientName;
//Session["Login_ClientModel"] = model_client;
//resultModel.result = true;
//resultModel.data = "登录成功";
//resultModel.msg = "登录成功";
}
resultModel.result = true;
resultModel.data = "登录成功";
resultModel.msg = "登录成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.StackTrace}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 保存报价单 ok
[WebMethod(EnableSession = true)]
public AppResultModel<int> Save_DT_Quote_NewTable(DT_Quote_NewTable Model)
{
var resultModel = new AppResultModel<int>();
try
{
//Pages.Login(this.Session);
if (string.IsNullOrEmpty(Model.Foto) || Model.Recio == null)
{
resultModel.result = false;
resultModel.msg = $"报价商品图片和单价不能为空!";
resultModel.data = -1;
return resultModel;
}
Model.CompanyId = Convert.ToInt32(Session["CompanyId"]);
Model.UserId = Convert.ToInt32(Session["UserId"]); ;
Model.CreateDate = DateTime.Now;
Model.IsAuthority = true;
int Id = DataNew.Save_DT_Quote_NewTable(Model);
if (Id == -1)
{
resultModel.result = false;
resultModel.msg = $"添加或保存失败";
resultModel.data = 0;
}
else
{
resultModel.result = true;
resultModel.msg = $"保存成功";
resultModel.data = Id;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 返回单个客户今天的报价总金额和总体积 ok
[WebMethod(EnableSession = true)]
public AppResultModel<appShowMsg> GetMsg_ClientToday(int ClientId,string newDate)
{
var resultModel = new AppResultModel<appShowMsg>();
try
{
//var newDate = DateTime.Now.ToShortDateString();
var newappShowMsg = DataNew.GetMsg_ClientToday(ClientId, newDate);
if (newappShowMsg == null)
{
resultModel.result = false;
resultModel.msg = $"查询失败";
resultModel.data = new appShowMsg();
}
else
{
resultModel.result = true;
resultModel.msg = $"查询成功";
resultModel.data = newappShowMsg;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 批量删除报价单 目前不判断客户
[WebMethod(EnableSession = true)]
public AppResultModel<List<int>> Delete_DT_QuoteNewTableList(List<int> QuoteIdList)
{
var resultModel = new AppResultModel<List<int>>();
try
{
//Pages.Login(this.Session);
if (QuoteIdList.Count > 0 )
{
DataNew.Delete_DT_Quote_NewTableByQuoteId(QuoteIdList);
}
resultModel.result = true;
resultModel.msg = "操作成功";
resultModel.data = QuoteIdList;
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
resultModel.data = new List<int>() ;
}
return resultModel;
}
#endregion
#region 获取报价单信息列表信息
[WebMethod(EnableSession = true)]
public PageAppResultModel<DT_Quote_NewTable> GetList_DT_QuoteNewTable(string search,int ClientId,string newDate,string Sort, int PageIndex, int PageSize)
{
var resultModel = new PageAppResultModel<DT_Quote_NewTable>();
try
{
//Pages.Login(this.Session);
int RowCount = 0;
RefParameterCollection param = new RefParameterCollection();
//客户身份
if (Convert.ToBoolean(Session["IsClient"]))
{
var newclientId = Convert.ToInt32(Session["ClientId"]);
param.Add("a.ClientId", "=", newclientId, DbType.Int32);
}
else
{
if (ClientId != -1)
{
param.Add("a.ClientId", "=", ClientId, DbType.Int32);
}
}
if (!string.IsNullOrEmpty(newDate))
{
param.Add("(a.CreateDate", ">=", $"{newDate} 00:00:00", DbType.String);
param.Add("a.CreateDate", "<=", $"{newDate} 23:59:59", "and",")", DbType.String);
}
if (string.IsNullOrEmpty(search) == false) param.Add("(a.Nombre", "like", search, "and", DbType.String);
if (string.IsNullOrEmpty(search) == false) param.Add("a.Modelo", "like", search, "or", DbType.String);
if (string.IsNullOrEmpty(search) == false) param.Add("a.DTQuoteNo", "like", search, "or", ")", DbType.String);
resultModel.data = new PageAppResultList<List<DT_Quote_NewTable>>();
var newModel = DataNew.GetPageList_DT_QuoteNewTable(param, PageIndex, PageSize, Sort, out RowCount);
var newList = new List<DT_Quote_NewTable>();
resultModel.data.datas = newModel == null ? newList : newModel;
resultModel.data.total = RowCount;
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 获取报价单信息列表信息 平台获取
[WebMethod(EnableSession = true)]
public NewPageAppResultModel<DT_Quote_NewTable> GetList_DT_QuoteTable(string search, int ClientId, string FactoryName, string UserName,string StartDate, string EndDate, string Sort, int PageIndex, int PageSize)
{
var resultModel = new NewPageAppResultModel<DT_Quote_NewTable>();
try
{
//Pages.Login(this.Session);
int RowCount = 0;
RefParameterCollection param = new RefParameterCollection();
//客户身份
if (Convert.ToBoolean(Session["IsClient"]))
{
var newclientId = Convert.ToInt32(Session["ClientId"]);
param.Add("a.ClientId", "=", newclientId, DbType.Int32);
}
else
{
if (ClientId != -1)
{
param.Add("a.ClientId", "=", ClientId, DbType.Int32);
}
}
if (!string.IsNullOrEmpty(StartDate) && !string.IsNullOrEmpty(EndDate))
{
param.Add("(a.CreateDate", ">=", $"{StartDate} 00:00:00", DbType.String);
param.Add("a.CreateDate", "<=", $"{EndDate} 23:59:59", "and", ")", DbType.String);
}
if (!string.IsNullOrEmpty(FactoryName))
{
param.Add("a.FactoryName", "like", FactoryName, DbType.String);
}
if (!string.IsNullOrEmpty(UserName))
{
param.Add("c.UserName", "like", UserName, DbType.String);
}
if (string.IsNullOrEmpty(search) == false) {
param.Add("(a.Nombre", "like", search, DbType.String);
param.Add("a.Modelo", "like", search, "or", DbType.String);
param.Add("a.DTQuoteNo", "like", search, "or", ")", DbType.String);
}
//if (string.IsNullOrEmpty(search) == false) param.Add("a.Modelo", "like", search, "or", DbType.String);
//if (string.IsNullOrEmpty(search) == false) param.Add("a.FactoryName", "like", search, "or", DbType.String);
//if (string.IsNullOrEmpty(search) == false) param.Add("c.UserName", "like", search, "or", DbType.String);
resultModel.data = new NewPageAppResultList<List<DT_Quote_NewTable>>();
var newModel = DataNew.GetPageList_DT_QuoteNewTable(param, PageIndex, PageSize, Sort, out RowCount);
var newList = new List<DT_Quote_NewTable>();
resultModel.data.datas = newModel == null ? newList : newModel;
//resultModel.RowCount = RowCount;
resultModel.data.total = RowCount;
resultModel.data.newAllCbm = newModel == null ? 0 : resultModel.data.datas.Sum(t => t.AllCbm);
resultModel.data.newAllValor = newModel == null ? 0 : resultModel.data.datas.Sum(t => t.Valor);
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 获取报价单信息列表信息
[WebMethod(EnableSession = true)]
public AppResultModel<DT_Quote_NewTable> GetModel_DT_QuoteNewTable(int Id)
{
var resultModel = new AppResultModel<DT_Quote_NewTable>();
try
{
//Pages.Login(this.Session);
if (Id > 0)
{
var newModel = DataNew.GetModel_DT_QuoteNewTable(Id);
if (newModel == null)
{
resultModel.data = new DT_Quote_NewTable();
resultModel.result = false;
resultModel.msg = $"你选择的报价单不存在";
}
else
{
resultModel.data = newModel;
resultModel.result = true;
resultModel.msg = $"查询成功";
}
}
else
{
resultModel.data = new DT_Quote_NewTable();
resultModel.result = false;
resultModel.msg = $"你选择的报价单不存在";
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 导出报价单 未完善
[WebMethod(EnableSession = true)]
public AppResultModel<string> Get_DT_QuoteNewExcel(string search, int ClientId, string FactoryName, string UserName, string StartDate, string EndDate, string Sort)
{
// 这里确保您的登录逻辑正确
//PagesNew.Login(this.Session);
var resultModel = new AppResultModel<string>();
string errorMsg = "";
try
{
//Pages.Login(this.Session);
#region 信息查询
RefParameterCollection param = new RefParameterCollection();
string where = string.Empty;
//客户身份
if (Convert.ToBoolean(Session["IsClient"]))
{
var newclientId = Convert.ToInt32(Session["ClientId"]);
where += $"a.ClientId = {newclientId}";
param.Add("a.ClientId", "=", newclientId, DbType.Int32);
}
else
{
if (ClientId != -1)
{
where += $"a.ClientId = {ClientId}";
where += $"";
param.Add("a.ClientId", "=", ClientId, DbType.Int32);
}
}
if (!string.IsNullOrEmpty(StartDate) && !string.IsNullOrEmpty(EndDate))
{
string newWhere = $"(a.CreateDate >= '{StartDate} 00:00:00' and a.CreateDate <= '{EndDate} 23:59:59')";
where += string.IsNullOrEmpty(where) ? newWhere : $" and {newWhere}";
}
if (!string.IsNullOrEmpty(FactoryName))
{
string newWhere = $"(a.FactoryName like '%{FactoryName}%')";
where += string.IsNullOrEmpty(where) ? newWhere : $" and {newWhere}";
}
if (!string.IsNullOrEmpty(UserName))
{
string newWhere = $"(c.UserName like '%{UserName}%')";
where += string.IsNullOrEmpty(where) ? newWhere : $" and {newWhere}";
}
if (string.IsNullOrEmpty(search) == false)
{
string newWhere = $"(a.Nombre like '%{search}%' or a.Modelo like '%{search}%')";
where += string.IsNullOrEmpty(where) ? newWhere : $" and {newWhere}";
}
var list = DataNew.GetList_DT_QuoteNewTable(where, Sort);
#endregion
resultModel.data = GetQuoteExcel(list,out errorMsg);
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}|{errorMsg}";
resultModel.result = false;
resultModel.data = "";
}
return resultModel;
}
[WebMethod(EnableSession = true)]
public AppResultModel<string> Get_DT_QuoteNewExcel2(List<int> Ids)
{
// 这里确保您的登录逻辑正确
//PagesNew.Login(this.Session);
var resultModel = new AppResultModel<string>();
string errorMsg = "";
try
{
//Pages.Login(this.Session);
#region 信息查询
int RowCount = 0;
RefParameterCollection param = new RefParameterCollection();
string whereStr = "";
//客户身份
if (Ids.Count() > 0 )
{
whereStr = $" where a.Id in ({string.Join(",", Ids)})";
}
var list = DataNew.GetList_DT_QuoteNewTable2(whereStr);
#endregion
resultModel.data = GetQuoteExcel(list,out errorMsg);
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}|{errorMsg}";
resultModel.result = false;
resultModel.data = "";
}
return resultModel;
}
public string GetQuoteExcel(List<DT_Quote_NewTable> list,out string errorMsg)
{
string allFilename = "";
errorMsg = "";
#region 生成excel
//var hjObj = new GoodsSolidTopModel();
//hjObj.SKU = "合计";
//hjObj.WestNum = list.Sum(r => r.WestNum);
//hjObj.WestSolids = list.Sum(r => r.WestSolids);
//hjObj.EastNum = list.Sum(r => r.EastNum);
//hjObj.EastSolids = list.Sum(r => r.EastSolids);
//hjObj.TotalNum = list.Sum(r => r.TotalNum);
//hjObj.TotalSolid = list.Sum(r => r.TotalSolid);
//list.Add(hjObj);
//创建工作薄
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("Sheet1");
sheet.SetColumnWidth(0, 18 * 256);
var drawing = sheet.CreateDrawingPatriarch();
//填充列标题以及样式
int rowsNum = 0; //行号
HSSFRow headerRow = (HSSFRow)sheet.CreateRow(rowsNum);
headerRow.CreateCell(0, CellType.STRING).SetCellValue("产品图片");
headerRow.CreateCell(1, CellType.STRING).SetCellValue("意向箱数");
headerRow.CreateCell(2, CellType.STRING).SetCellValue("中文品名");
headerRow.CreateCell(3, CellType.STRING).SetCellValue("采购单价");
headerRow.CreateCell(4, CellType.STRING).SetCellValue("货币代码");
headerRow.CreateCell(5, CellType.STRING).SetCellValue("计量单位");
headerRow.CreateCell(6, CellType.STRING).SetCellValue("包装容量");
headerRow.CreateCell(7, CellType.STRING).SetCellValue("厂商编号");
headerRow.CreateCell(8, CellType.STRING).SetCellValue("报价日期");
headerRow.CreateCell(9, CellType.STRING).SetCellValue("工厂货号");
headerRow.CreateCell(10, CellType.STRING).SetCellValue("价格");
headerRow.CreateCell(11, CellType.STRING).SetCellValue("报价单位");
headerRow.CreateCell(12, CellType.STRING).SetCellValue("起 订 量");
headerRow.CreateCell(13, CellType.STRING).SetCellValue("是否开票");
headerRow.CreateCell(14, CellType.STRING).SetCellValue("包装长度");
headerRow.CreateCell(15, CellType.STRING).SetCellValue("包装宽度");
headerRow.CreateCell(16, CellType.STRING).SetCellValue("包装高度");
headerRow.CreateCell(17, CellType.STRING).SetCellValue("产品编号");
headerRow.CreateCell(18, CellType.STRING).SetCellValue("英文品名");
headerRow.CreateCell(19, CellType.STRING).SetCellValue("产品描述");
headerRow.CreateCell(20, CellType.STRING).SetCellValue("包装体积");
headerRow.CreateCell(21, CellType.STRING).SetCellValue("20# 装量");
headerRow.CreateCell(22, CellType.STRING).SetCellValue("40# 装量");
headerRow.CreateCell(23, CellType.STRING).SetCellValue("40HQ装量");
headerRow.CreateCell(24, CellType.STRING).SetCellValue("条形码号");
//headerRow.CreateCell(25, CellType.STRING).SetCellValue("操作员工");
//headerRow.CreateCell(26, CellType.STRING).SetCellValue("工厂名称");
rowsNum = 1; //行号
if (list != null && list.Count() > 0)
{
foreach (var link in list)
{
try
{
////https://www.kferp.net/ServerCookies/a24928bb-4f25-417b-b784-f1b3cced7221.jpg
////图片压缩
// 读取原始图片
try
{
string sourceImagePath = AppDomain.CurrentDomain.BaseDirectory + link.Foto;
//string sourceImagePath1 = AppDomain.CurrentDomain.BaseDirectory + "ServerCookies/newQuate/";
//string destinationImagePath = ImageCompress.CompressionImage(sourceImagePath, sourceImagePath1, 1);
//var pictureData = GetImageFromUrl(destinationImagePath);
//string sourceImagePath = "C:\\Users\\Administrator\\Desktop\\图片1.png";
var pictureData = ImageCompress.CompressImage(sourceImagePath);
if (pictureData != null)
{
var pictureIndex = workbook.AddPicture(pictureData, PictureType.PNG);
// 在每一行的第一列插入图片
var pictureCell = sheet.CreateRow(rowsNum).CreateCell(0);
sheet.GetRow(rowsNum).Height = 80 * 20;
pictureCell.CellStyle = workbook.CreateCellStyle();
var anchor = new HSSFClientAnchor(0, 0, 0, 0, 0, rowsNum, 1, rowsNum + 1);
anchor.AnchorType = 2;
var picture = drawing.CreatePicture(anchor, pictureIndex);
}
else
{
var _dataCell = sheet.CreateRow(rowsNum).CreateCell(0);
sheet.GetRow(rowsNum).Height = 80 * 20;
_dataCell.SetCellValue("");
}
}
catch
{
var _dataCell = sheet.CreateRow(rowsNum).CreateCell(0);
sheet.GetRow(rowsNum).Height = 80 * 20;
_dataCell.SetCellValue("");
}
// var pictureData = GetImageFromUrl(AppDomain.CurrentDomain.BaseDirectory + link.Foto);
//var pictureData = GetImageFromUrl("https://www.kferp.net/" + link.Foto);
//if (pictureData != null)
//{
// var pictureIndex = workbook.AddPicture(pictureData, PictureType.PNG);
// // 在每一行的第一列插入图片
// var pictureCell = sheet.CreateRow(rowsNum).CreateCell(0);
// sheet.GetRow(rowsNum).Height = 80 * 20;
// pictureCell.CellStyle = workbook.CreateCellStyle();
// var anchor = new HSSFClientAnchor(0, 0, 0, 0, 0, rowsNum, 1, rowsNum + 1);
// anchor.AnchorType = 2;
// var picture = drawing.CreatePicture(anchor, pictureIndex);
//}
//else
//{
// var _dataCell = sheet.CreateRow(rowsNum).CreateCell(0);
// sheet.GetRow(rowsNum).Height = 80 * 20;
// _dataCell.SetCellValue("");
//}
// 在每一行的第二列插入数据
sheet.GetRow(rowsNum).CreateCell(1).SetCellValue(link.Cantidad.ToString());
sheet.GetRow(rowsNum).CreateCell(2).SetCellValue(link.Nombre.ToString());
sheet.GetRow(rowsNum).CreateCell(3).SetCellValue((double)link.Recio);
sheet.GetRow(rowsNum).CreateCell(4).SetCellValue("RMB");
sheet.GetRow(rowsNum).CreateCell(5).SetCellValue("PCS");
sheet.GetRow(rowsNum).CreateCell(6).SetCellValue(link.QtyOrCtn);
sheet.GetRow(rowsNum).CreateCell(7).SetCellValue("");
sheet.GetRow(rowsNum).CreateCell(8).SetCellValue(link.CreateDate.ToString());
sheet.GetRow(rowsNum).CreateCell(9).SetCellValue(link.Modelo.ToString());
sheet.GetRow(rowsNum).CreateCell(10).SetCellValue(link.Recio.ToString());
sheet.GetRow(rowsNum).CreateCell(11).SetCellValue("PCS");
sheet.GetRow(rowsNum).CreateCell(12).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(13).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(14).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(15).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(16).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(17).SetCellValue(link.Modelo.ToString());
sheet.GetRow(rowsNum).CreateCell(18).SetCellValue("");
sheet.GetRow(rowsNum).CreateCell(19).SetCellValue(link.Caracteristicas);
sheet.GetRow(rowsNum).CreateCell(20).SetCellValue((double)link.Cbm);
sheet.GetRow(rowsNum).CreateCell(21).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(22).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(23).SetCellValue(0);
sheet.GetRow(rowsNum).CreateCell(24).SetCellValue("");
//sheet.GetRow(rowsNum).CreateCell(25).SetCellValue(link.UserName);
//sheet.GetRow(rowsNum).CreateCell(26).SetCellValue(link.FactoryName);
rowsNum++;
}
catch(Exception ex)
{
errorMsg += $"{rowsNum}行出错ex{ex.Message}\r\n";
}
}
}
string filename = Guid.NewGuid().ToString() + ".xls";
string DirectoryName = AppDomain.CurrentDomain.BaseDirectory + "ServerCookies";
if (System.IO.Directory.Exists(DirectoryName) == false) System.IO.Directory.CreateDirectory(DirectoryName);
string ServerFileName = DirectoryName + "/" + filename;
//保存
using (FileStream fs = new FileStream(ServerFileName, FileMode.Create, FileAccess.Write))
{
workbook.Write(fs);
}
workbook.Dispose();
allFilename = "ServerCookies/" + filename;
//return "ServerCookies/" + filename;
#endregion
return allFilename;
}
// 从URL获取图片数据
public byte[] GetImageFromUrl(string url)
{
try
{
using (WebClient webClient = new WebClient())
{
return webClient.DownloadData(new Uri(url));
}
}
catch (Exception ex)
{
return null;
}
}
#endregion
#region 报价城市
/// <summary>
/// /
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="MaxQty">最大数量</param>
/// <param name="MinQty">最小数量</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public PageAppResultModel<string> GetQuoteCityList()
{
var resultModel = new PageAppResultModel<string>();
try
{
//Pages.Login(this.Session);
var list = new List<String>() { "Ningbo", "shantou", "tianjin", "yiwu", "guangzhou", "hongkong", "Yangzhou", "Shenzhen" };
resultModel.data = new PageAppResultList<List<string>>();
resultModel.data.datas = list;
resultModel.data.total = list.Count();
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#endregion
#region 报价单
#region 保存报价单 ok
[WebMethod(EnableSession = true)]
public AppResultModel<int> Save_DT_Quote(DT_Quote Model)
{
var resultModel = new AppResultModel<int>();
try
{
Pages.Login(this.Session);
if (string.IsNullOrEmpty(Model.Nombre) || Model.Recio == null)
{
resultModel.result = false;
resultModel.msg = $"报价货号和单价不能为空!";
resultModel.data = -1;
return resultModel;
}
Model.CompanyId = Convert.ToInt32(Session["CompanyId"]);
Model.UserId = Convert.ToInt32(Session["UserId"]); ;
Model.CreateDate = DateTime.Now;
if (Model.ClientId.Count > 0)
{
Model.IsAuthority = true;
}
else
{
Model.IsAuthority = false;
}
int Id = DataNew.Save_DT_Quote(Model);
if (Id == -1)
{
resultModel.result = false;
resultModel.msg = $"添加或保存失败";
resultModel.data = 0;
}
else
{
//添加权限表
if (Model.ClientId.Count > 0)
{
foreach (var ClientId in Model.ClientId)
{
//检查
if (DataNew.Check_DT_QuoteAuthority(Id, ClientId) == 0)
{
DataNew.Save_DT_QuoteAuthority(Id, ClientId);
}
DT_QuoteClientNum numModel = new DT_QuoteClientNum();
numModel.Cantidad = Model.Cantidad;
numModel.Valor = Model.Valor;
numModel.ClientId = ClientId;
numModel.QuoteId = Id;
DataNew.Save_DT_QuoteClientNum(numModel, true);
//Model.Cantidad =
}
}
resultModel.result = true;
resultModel.msg = $"保存成功";
resultModel.data = Id;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
[WebMethod(EnableSession = true)]
public AppResultModel<int> Edit_DT_Quote_NewTable(DT_Quote_NewTable Model)
{
var resultModel = new AppResultModel<int>();
try
{
//Pages.Login(this.Session);
if (string.IsNullOrEmpty(Model.Nombre))
{
resultModel.result = false;
resultModel.msg = $"报价货号和单价不能为空!";
resultModel.data = -1;
return resultModel;
}
Model.CompanyId = Convert.ToInt32(Session["CompanyId"]);
Model.UserId = Convert.ToInt32(Session["UserId"]); ;
Model.CreateDate = DateTime.Now;
Model.AllCbm = Model.Cbm * Model.Cantidad;
Model.Valor = (decimal)(Model.Recio * Model.QtyOrCtn * Model.Cantidad);
int Id = DataNew.Save_DT_Quote_NewTable(Model);
if (Id == -1)
{
resultModel.result = false;
resultModel.msg = $"添加或保存失败";
resultModel.data = 0;
}
else
{
resultModel.result = true;
resultModel.msg = $"保存成功";
resultModel.data = Id;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 批量保存 ok
[WebMethod(EnableSession = true)]
public AppResultModel<string> Save_DT_QuoteList(List<DT_Quote> ModelList)
{
var resultModel = new AppResultModel<string>();
try
{
Pages.Login(this.Session);
//string treturnIds = "";
int CompanyId = Convert.ToInt32(Session["CompanyId"]);
int UserId = Convert.ToInt32(Session["UserId"]);
int num = ModelList.Count();
int num_fail = 0;
int num_success = 0;
foreach (DT_Quote Model in ModelList)
{
Model.CompanyId = Convert.ToInt32(Session["CompanyId"]);
Model.UserId = Convert.ToInt32(Session["UserId"]); ;
Model.CreateDate = DateTime.Now;
if (Model.ClientId.Count > 0)
{
Model.IsAuthority = true;
}
else
{
Model.IsAuthority = false;
}
int Id = DataNew.Save_DT_Quote(Model);
if (Id == 0)
{
num_fail++;
}
else
{
//添加权限表
if (Model.ClientId.Count > 0)
{
foreach (var ClientId in Model.ClientId)
{
//检查
DataNew.Check_DT_QuoteAuthority(Id, ClientId);
DataNew.Save_DT_QuoteAuthority(Id, ClientId);
}
}
num_success++;
}
}
resultModel.result = true;
resultModel.msg = "操作成功";
resultModel.data = $"总操作数量{num}条,成功{num_success}条,失败{num_fail}条";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 批量删除 ok
[WebMethod(EnableSession = true)]
public AppResultModel<List<int>> Delete_DT_QuotePageList(List<int> QuoteIdList)
{
var resultModel = new AppResultModel<List<int>>();
try
{
Pages.Login(this.Session);
int num = QuoteIdList.Count();
///无法删除的List
var deletefailList = DataNew.Select_DT_QuoteByQuoteId(QuoteIdList);
var newQuoteIdList = QuoteIdList.Except(deletefailList).ToList();
///无法删除的List
if (newQuoteIdList.Count() > 0)
{
var deleteList = DataNew.Delete_DT_QuoteByQuoteId(newQuoteIdList);
}
resultModel.result = true;
resultModel.msg = "操作成功";
resultModel.data = newQuoteIdList;
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
/// <summary>
/// 客户的小程序查看报价 分页查询
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
#region id查询 平台查询基础报价表
/// <summary>
/// /
/// </summary>
/// <param name="QuoteId">QuoteId</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public AppResultModel<DT_Quote> Select_DT_QuoteByQuoteId(int QuoteId)
{
var resultModel = new AppResultModel<DT_Quote>();
try
{
Pages.Login(this.Session);
resultModel.data = DataNew.Select_DT_QuoteByQuoteId(QuoteId);
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region id查询 平台查询基础报价表
/// <summary>
/// /
/// </summary>
/// <param name="QuoteId">QuoteId</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public AppResultModel<DT_Quote_New> Select_DT_CilentQuoteByQuoteId(int Id)
{
var resultModel = new AppResultModel<DT_Quote_New>();
try
{
Pages.Login(this.Session);
resultModel.data = DataNew.GetADT_Quote_New(Id);
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 分页查询 平台查询基础报价表
/// <summary>
/// /
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="MaxQty">最大数量</param>
/// <param name="MinQty">最小数量</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public PageAppResultModel<DT_Quote> Select_DT_QuotePageList(string Nombre, string Modelo, int MaxQty, int MinQty, int PageIndex, int PageSize)
{
var resultModel = new PageAppResultModel<DT_Quote>();
try
{
Pages.Login(this.Session);
int RowCount = 0;
string Sort = "";
RefParameterCollection param = new RefParameterCollection();
//param.Add("state", "=", 1, DbType.Int32);
if (string.IsNullOrEmpty(Nombre) == false) param.Add("a.Nombre", "like", Nombre, DbType.String);
if (string.IsNullOrEmpty(Modelo) == false) param.Add("a.Modelo", "like", Modelo, DbType.String);
if (MaxQty != -1) param.Add("a.QtyOrCtn", "<=", MaxQty, DbType.Int32);
if (MinQty != -1) param.Add("a.QtyOrCtn", ">=", MinQty, DbType.Int32);
resultModel.data = new PageAppResultList<List<DT_Quote>>();
resultModel.data.datas = DataNew.GetListDT_Quote(param, PageIndex, PageSize, Sort, out RowCount);
resultModel.data.total = resultModel.data.datas == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 客户的小程序查看报价 分页查询
/// <summary>
/// /
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public PageAppResultModel<DT_Quote> Select_DT_QuotePageListByClient(string Nombre, string Modelo,int PageIndex, int PageSize)
{
var resultModel = new PageAppResultModel<DT_Quote>();
try
{
Pages.Login(this.Session);
int RowCount = 0;
string Sort = "";
RefParameterCollection param = new RefParameterCollection();
var clientId = Convert.ToInt32(Session["ClientId"]);
var QuoteIdList = DataNew.GetQuoteIdListByClientId(clientId);
param.Add("(a.IsAuthority", "=", 0, DbType.Int32);
param.Add("a.Id", "in", string.Join(",", QuoteIdList).TrimEnd(','), "or", ")", DbType.String);
if (string.IsNullOrEmpty(Nombre) == false) param.Add("a.Nombre", "like", Nombre, DbType.String);
if (string.IsNullOrEmpty(Modelo) == false) param.Add("a.Modelo", "like", Modelo, DbType.String);
resultModel.data = new PageAppResultList<List<DT_Quote>>();
resultModel.data.datas = DataNew.GetListDT_QuoteByClient(param, PageIndex, PageSize, Sort, out RowCount);
resultModel.data.total = resultModel.data.datas == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
/// <summary>
/// 客户的小程序查看报价 分页查询
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public PageAppResultModel<DT_Quote> Select_DT_QuotePageListByClient_Old(string search, int PageIndex, int PageSize)
{
var resultModel = new PageAppResultModel<DT_Quote>();
try
{
Pages.Login(this.Session);
int RowCount = 0;
string Sort = "";
RefParameterCollection param = new RefParameterCollection();
var clientId = Convert.ToInt32(Session["ClientId"]);
var QuoteIdList = DataNew.GetQuoteIdListByClientId(clientId);
param.Add("(a.IsAuthority", "=", 0, DbType.Int32);
param.Add("a.Id", "in", string.Join(",", QuoteIdList).TrimEnd(','), "or", ")", DbType.String);
if (string.IsNullOrEmpty(search) == false) param.Add("a.Nombre", "like", search, "or", DbType.String);
if (string.IsNullOrEmpty(search) == false) param.Add("a.Modelo", "like", search, "or" ,DbType.String);
resultModel.data = new PageAppResultList<List<DT_Quote>>();
var newDate = DataNew.GetListDT_QuoteByClient(param, PageIndex, PageSize, Sort, out RowCount);
var newList = new List<DT_Quote>();
resultModel.data.datas = newDate == null ? newList : newDate;
resultModel.data.total = newDate == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 导出报价单 未完善
[WebMethod(EnableSession = true)]
public string Get_DT_QuoteExcel(List<int> Ids)
{
// 这里确保您的登录逻辑正确
//PagesNew.Login(this.Session);
var slist = DataNew.GetListDT_QuoteById(Ids);
var hlist = new List<DT_Quote>();
TableColumnCollection listColumns = new TableColumnCollection();
// 添加列信息
listColumns.Add("Foto", "摄影图像", DbType.String, "");
listColumns.Add("Nombre", "名称", DbType.String, "");
listColumns.Add("Caracteristicas", "特点", DbType.String, "");
listColumns.Add("Modelo", "样本", DbType.String, "");
listColumns.Add("Recio", "价格", DbType.String, "");
listColumns.Add("QtyOrCtn", "箱数", DbType.String, "");
listColumns.Add("Cbm", "立方米", DbType.String, "");
listColumns.Add("Gw", "毛重", DbType.String, "");
listColumns.Add("Nw", "净值", DbType.String, "");
listColumns.Add("Recio", "客户价格", DbType.Decimal, "");
listColumns.Add("FactoryPrice", "工厂价格", DbType.Decimal, "");
//listColumns.Add("Cantidad", "投入", DbType.String, "");
//listColumns.Add("Valor", "价格", DbType.String, "");
// 调用 Excel 导出方法并返回结果
MicrosoftExcel obj2 = new MicrosoftExcel();
return obj2.Export(slist, listColumns);
}
#endregion
#region 读取正常状态客户 ok
[WebMethod(EnableSession = true)]
public PageAppResultModel<JC_Client> GetClientList()
{
var resultModel = new PageAppResultModel<JC_Client>();
try
{
PagesNew.Login(this.Session);
resultModel.data = new PageAppResultList<List<JC_Client>>();
resultModel.data.datas = DataNew.GetClientList();
resultModel.data.total = resultModel.data.datas == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"返回成功";
}
catch(Exception ex)
{
resultModel.result = false;
resultModel.msg = $"{ex.StackTrace}";
}
return resultModel;
}
#endregion
#region 读取全部状态客户 ok
[WebMethod(EnableSession = true)]
public PageAppResultModel<JC_Client> GetAllClientList()
{
var resultModel = new PageAppResultModel<JC_Client>();
try
{
PagesNew.Login(this.Session);
resultModel.data = new PageAppResultList<List<JC_Client>>();
resultModel.data.datas = DataNew.GetAllClientList();
resultModel.data.total = resultModel.data.datas == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"返回成功";
}
catch (Exception ex)
{
resultModel.result = false;
resultModel.msg = $"{ex.StackTrace}";
}
return resultModel;
}
#endregion
#region 创建一个客户 简单创建 暂时不用
[WebMethod(EnableSession = true)]
public CreateClientMsg CreateClient()
{
PagesNew.Login(this.Session);
JC_Client client = new JC_Client();
client.ClientName = "测试";
client.UserName = "ceshi";
client.Password = "ceshi";
client.State = true;
client.Authority = AuthorityType.;
client.CreateId = Convert.ToInt32(Session["UserId"]);
client.CreateDate = DateTime.Now;
DataNew.InsertClient(client);
CreateClientMsg msg = new CreateClientMsg()
{
ClientName = client.UserName,
UserName = client.UserName,
Password = client.Password,
Authority = client.Authority,
CreateDate = client.CreateDate,
};
return msg;
}
#endregion
#region 创建一个客户
[WebMethod(EnableSession = true)]
public AppResultModel<CreateClientMsg> CreateClientByMsg(JC_Client client)
{
var resultModel = new AppResultModel<CreateClientMsg>();
try
{
PagesNew.Login(this.Session);
//判断 不能与用户表和客户表信息重复
int num_client = DataNew.CheckClientUserName(client.UserName);
int num_user = DataNew.CheckUserName(client.UserName);
if (num_client > 0 || num_user > 0)
{
resultModel.msg = "注册失败原因UserName重复";
resultModel.result = false;
}
else
{
client.State = true;
client.Authority = (AuthorityType)0;
client.CreateId = Convert.ToInt32(Session["UserId"]);
client.CreateDate = DateTime.Now;
DataNew.InsertClient(client);
CreateClientMsg dataModel = new CreateClientMsg()
{
ClientName = client.UserName,
UserName = client.UserName,
Password = client.Password,
Authority = client.Authority,
CreateDate = client.CreateDate,
};
resultModel.result = true;
resultModel.msg = "创建成功";
resultModel.data = dataModel;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 获取身份信息 ok
[WebMethod(EnableSession = true)]
public AppResultModel<AppIdentityModel> GetIdentityBySession()
{
var resultModel = new AppResultModel<AppIdentityModel>();
try
{
AppIdentityModel model = new AppIdentityModel()
{
Id = int.Parse(Session["UserId"].ToString()),
Name = Session["Name"].ToString(),
IsClient = bool.Parse(Session["IsClient"].ToString())
};
resultModel.result = true;
resultModel.data = model;
resultModel.msg = $"返回成功";
}
catch(Exception ex)
{
resultModel.result = false;
resultModel.msg = $"错误提示:{ex.StackTrace}";
}
return resultModel;
}
#endregion
#region 创建客户的意向报价单
[WebMethod(EnableSession = true)]
public AppResultModel<string> CreateAQuoteByMsg(DT_QuoteClientNum Model)
{
var resultModel = new AppResultModel<string>();
try
{
PagesNew.Login(this.Session);
//检查参数值
if (Model.ClientId == null || Model.ClientId == 0)
{
Model.ClientId = int.Parse(Session["ClientId"].ToString());
}
if (Model.QuoteId == null || Model.ClientId == null || Model.Cantidad == null || Model.Valor == null)
{
resultModel.msg = "请检查QuoteId|ClientId|Cantidad|Valor这四个参数值必须有值!";
resultModel.result = false;
}
else
{
if (Model.ClientId == null || Model.ClientId == 0)
{
Model.ClientId = int.Parse(Session["ClientId"].ToString());
}
DT_QuoteClientNum oldModel = DataNew.CheckQuoteClientNum((int)Model.QuoteId, (int)Model.ClientId);
//新增
if (Model.Id == null && oldModel == null)
{
Model.CreateDate = DateTime.Now;
DataNew.Save_DT_QuoteClientNum(Model, true);
resultModel.msg = "新增成功!";
}
//修改
else
{
Model.ChangeDate = DateTime.Now;
Model.OldCantidad = oldModel.Cantidad;
Model.OldValor = oldModel.Valor;
DataNew.Save_DT_QuoteClientNum(Model, false);
resultModel.msg = "保存成功!";
}
resultModel.result = true;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 创建客户的意向报价单 批量
[WebMethod(EnableSession = true)]
public AppResultModel<string> CreateQuoteListByMsg(List<DT_QuoteClientNum> List)
{
var resultModel = new AppResultModel<string>();
try
{
PagesNew.Login(this.Session);
foreach (var Model in List)
{
if (Model.ClientId == null || Model.ClientId == 0)
{
Model.ClientId = int.Parse(Session["ClientId"].ToString());
}
DT_QuoteClientNum oldModel = DataNew.CheckQuoteClientNum((int)Model.QuoteId, (int)Model.ClientId);
//新增
if (Model.Id == null && oldModel == null)
{
Model.CreateDate = DateTime.Now;
DataNew.Save_DT_QuoteClientNum(Model, true);
}
//修改
else
{
Model.ChangeDate = DateTime.Now;
Model.OldCantidad = oldModel.Cantidad;
DataNew.Save_DT_QuoteClientNum(Model, false);
}
}
resultModel.result = true;
resultModel.msg = $"操作成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 删除客户的意向报价单 批量
[WebMethod(EnableSession = true)]
public AppResultModel<string> DeleteQuoteListByMsgList(List<int> Ids)
{
var resultModel = new AppResultModel<string>();
try
{
PagesNew.Login(this.Session);
if (Ids.Count > 0)
{
DataNew.Delete_DT_QuoteClientNum(Ids);
}
resultModel.result = true;
resultModel.msg = $"操作成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 分页查询 平台查询客户意向 报价表
/// <summary>
/// /
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="MaxQty">最大数量</param>
/// <param name="MinQty">最小数量</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public PageAppResultModel<DT_Quote_New> Select_DT_QuotePageListByClientId(string Nombre, string Modelo, int MaxQty, int MinQty,List<int> ClientIds, int PageIndex, int PageSize)
{
var resultModel = new PageAppResultModel<DT_Quote_New>();
try
{
Pages.Login(this.Session);
int RowCount = 0;
string Sort = "";
RefParameterCollection param = new RefParameterCollection();
//param.Add("state", "=", 1, DbType.Int32);
if (string.IsNullOrEmpty(Nombre) == false) param.Add("b.Nombre", "like", Nombre, DbType.String);
if (string.IsNullOrEmpty(Modelo) == false) param.Add("b.Modelo", "like", Modelo, DbType.String);
if (MaxQty != -1) param.Add("b.QtyOrCtn", "<=", MaxQty, DbType.Int32);
if (MinQty != -1) param.Add("b.QtyOrCtn", ">=", MinQty, DbType.Int32);
if (ClientIds.Count > 0 ) param.Add("a.ClientId", "in", string.Join(",", ClientIds).TrimEnd(','), DbType.String);
resultModel.data = new PageAppResultList<List<DT_Quote_New>>();
resultModel.data.datas = DataNew.GetListDT_Quote_New(param, PageIndex, PageSize, Sort, out RowCount);
resultModel.data.total = resultModel.data.datas == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
/// <summary>
/// /
/// </summary>
/// <param name="Nombre">名称</param>
/// <param name="Modelo">特点</param>
/// <param name="MaxQty">最大数量</param>
/// <param name="MinQty">最小数量</param>
/// <param name="PageIndex">页</param>
/// <param name="PageSize">页数量</param>
/// <returns></returns>
[WebMethod(EnableSession = true)]
public PageAppResultModel<DT_Quote_New> Select_DT_QuotePageListByClientId_New(string search, List<int> ClientIds, int PageIndex, int PageSize)
{
var resultModel = new PageAppResultModel<DT_Quote_New>();
try
{
Pages.Login(this.Session);
int RowCount = 0;
string Sort = "";
RefParameterCollection param = new RefParameterCollection();
//param.Add("state", "=", 1, DbType.Int32);
if (string.IsNullOrEmpty(search) == false) param.Add("b.Nombre", "like", search, "or", DbType.String);
if (string.IsNullOrEmpty(search) == false) param.Add("b.Modelo", "like", search, "or", DbType.String);
if (ClientIds.Count > 0 ) param.Add("a.ClientId", "in", string.Join(",", ClientIds).TrimEnd(','), DbType.String);
resultModel.data = new PageAppResultList<List<DT_Quote_New>>();
var newData = DataNew.GetListDT_Quote_New(param, PageIndex, PageSize, Sort, out RowCount);
List<DT_Quote_New> newList = new List<DT_Quote_New>();
resultModel.data.datas = newData == null ? newList : newData; ;
resultModel.data.total = newData == null ? 0 : resultModel.data.datas.Count();
resultModel.result = true;
resultModel.msg = $"查询成功";
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 客户修改密码
[WebMethod(EnableSession = true)]
public AppResultModel<string> UpdateClientPassword(string NewPassword)
{
var resultModel = new AppResultModel<string>();
try
{
// 这里确保您的登录逻辑正确
PagesNew.Login(this.Session);
var ClientId = int.Parse(Session["ClientId"].ToString());
if (ClientId <= 0)
{
resultModel.msg = "未找到登录客户信息";
resultModel.result = false;
}
else
{
DataNew.UpdateClientPassword(ClientId, NewPassword);
resultModel.msg = "修改成功";
resultModel.result = true;
}
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#region 导出意向报价单 未完善
[WebMethod(EnableSession = true)]
public AppResultModel<string> Get_DT_QuoteExcel_New(List<int> ClientIds)
{
var resultModel = new AppResultModel<string>();
try
{
// 这里确保您的登录逻辑正确
PagesNew.Login(this.Session);
var slist = DataNew.GetListDT_QuoteNewById(ClientIds);
//var hlist = new List<DT_Quote>();
TableColumnCollection listColumns = new TableColumnCollection();
// 添加列信息
listColumns.Add("ClientName", "客户", DbType.String, "");
listColumns.Add("Cantidad", "客户意向数量", DbType.Int32, "");
listColumns.Add("Foto", "摄影图像", DbType.String, "");
listColumns.Add("Nombre", "名称", DbType.String, "");
listColumns.Add("Caracteristicas", "特点", DbType.String, "");
listColumns.Add("Modelo", "样本", DbType.String, "");
//listColumns.Add("QtyOrCtn", "箱数", DbType.String, "");
listColumns.Add("Cbm", "立方米", DbType.String, "");
listColumns.Add("Gw", "毛重", DbType.String, "");
listColumns.Add("Nw", "净值", DbType.String, "");
listColumns.Add("Recio", "单件价格", DbType.String, "");
//listColumns.Add("Cantidad", "买入数量", DbType.String, "");
listColumns.Add("Valor", "总价格", DbType.String, "");
// 调用 Excel 导出方法并返回结果
MicrosoftExcel obj2 = new MicrosoftExcel();
resultModel.msg = obj2.Export(slist, listColumns);
resultModel.result = true;
}
catch (Exception ex)
{
resultModel.msg = $"{ex.Message}";
resultModel.result = false;
}
return resultModel;
}
#endregion
#endregion
#region 二手相关
#endregion
#region 报表相关
#region 登录人员的某段时期的销售数据
[WebMethod(EnableSession = true)]
public JsonModel<List<BB_MRJL_User>> GetUserOrderSaleList(int UserId,int PlatId, DateTime sDate, DateTime eDate)
{
//Pages.Login(this.Session);
var rmodel = new JsonModel<List<BB_MRJL_User>>();
var resultList = new List<BB_MRJL_User>();
resultList = GetUserOrderSaleList_TongYong(UserId, PlatId, sDate, eDate );
rmodel.DataSource = resultList;
rmodel.RowCount = resultList.Count();
return rmodel;
}
public List<BB_MRJL_User> GetUserOrderSaleList_TongYong(int UserId,int PlatId, DateTime sDate, DateTime eDate)
{
var resultList = new List<BB_MRJL_User>();
try
{
var ff = DataNew.GetList_YYUser("");
if (UserId == 1)
{
var list = DataNew.MRJL_GetUserListByDay(sDate, eDate, PlatId);
var skuList = DataNew.GetShopUserId();
foreach (var l in list)
{
int orderUserId = 0;
try
{
orderUserId = DataNew.MRJL_GetUsrIdByGoods((int)l.GoodsID, skuList[(int)l.PlatId]);
l.OrderUserId = orderUserId;
}
catch
{
}
}
var OrderUserIdList = list.Select(t => t.OrderUserId).Distinct().ToList();
foreach (var orderuderid in OrderUserIdList)
{
if (orderuderid != null && orderuderid != 0 && orderuderid != 1 && orderuderid != -1 && ff.Select(t => t.ID).ToList().Contains((int)orderuderid))
{
var newOrderList = list.Where(t => t.OrderUserId == orderuderid).ToList();
var resultModel = new BB_MRJL_User();
decimal Rate6 = 0;
foreach (var oShopId in newOrderList.Select(t => t.ShopId).Distinct().ToList())
{
//获取广告
var plstId = newOrderList.Where(t => t.ShopId == oShopId).Select(t => t.PlatId).FirstOrDefault();
var goods = newOrderList.Where(t => t.ShopId == oShopId).Select(t => t.GoodsID.ToString()).Distinct().ToList();
var adfeeModel2 = DataNew.MRJL_GetGKFeeByMouth(sDate, eDate, (int)plstId, (int)oShopId, goods);
decimal newRate6 = adfeeModel2 != null ? adfeeModel2.Adfee : 0;
Rate6 += Math.Round(newRate6, 2);
}
resultModel.LR = newOrderList.Sum(t => Math.Round((decimal)t.LR, 2));
resultModel.JL = Math.Round(newOrderList.Sum(t => Math.Round((decimal)t.LR, 2)) + newOrderList.Sum(t => (decimal)t.ckfee) - Rate6,2);
resultModel.Rate6 = Rate6;
resultModel.RMBMoney = newOrderList.Sum(t => Math.Round((decimal)t.RMBPrice, 2));
resultModel.USDMoney = newOrderList.Sum(t => Math.Round((decimal)t.TotalPrice, 2));
//20240909 美元达标计算
TimeSpan difference = eDate - sDate;
decimal realRMBMoney = 1600 * (difference.Days+1);
resultModel.USDMoneyColer = resultModel.USDMoney >= realRMBMoney? "black" : "red";
resultModel.yf = newOrderList.Sum(t => t.yf);
resultModel.mdfee = newOrderList.Sum(t => t.mdfee);
resultModel.userid = (int)orderuderid;
resultModel.username = ff.Where(t => t.ID == orderuderid).Select(t => t.Name).FirstOrDefault();
resultModel.OrderNum = newOrderList.Count();
resultModel.PlatId = (int)newOrderList.FirstOrDefault().PlatId;
resultModel.PlatName = DataNew.MRJL_GetPlatNameByPlatId((int)newOrderList.FirstOrDefault().PlatId);
//20240909 新增sku数量记录
resultModel.SkuNum = DataNew.MRJL_GetSkuNumByUserid((int)orderuderid);
resultList.Add(resultModel);
}
}
//int rowCount = resultList.Count();
//rmodel.DataSource = resultList.OrderByDescending(t => t.OrderNum).ToList();
//rmodel.RowCount = rowCount;
//return resultList;
}
else
{
var resultModel = new BB_MRJL_User();
var list = DataNew.MRJL_GetUserOderMsgByDay(sDate, eDate, UserId);
var goodsList = DataNew.MRJL_GetGoodsIdByDay(sDate, eDate, UserId);
int platId = 0;
if (list != null && list.Count() > 0)
{
foreach (var l in list)
{
if (goodsList != null && goodsList.Count() > 0)
{
//获取广告
var plstId = goodsList.Where(t => t.ShopId == l.ShopId).Select(t => t.PlatId).FirstOrDefault();
platId = plstId;
var goods = goodsList.Where(t => t.ShopId == l.ShopId).Select(t => t.GoodsID.ToString()).ToList();
var adfeeModel2 = DataNew.MRJL_GetGKFeeByMouth(sDate, eDate, plstId, l.ShopId, goods);
//l.Rate3 = adfeeModel1 != null ? adfeeModel1.Adfee : 0;
l.Rate6 = adfeeModel2 != null ? adfeeModel2.Adfee : 0;
//
}
//净利润
l.LR = Math.Round(l.LR, 2);
l.JL = Math.Round(l.LR + l.ckfee - l.Rate6, 2) ;
}
resultModel.LR = list.Sum(t => t.LR);
resultModel.JL = Math.Round(list.Sum(t => t.JL)) ;
resultModel.Rate6 = list.Sum(t => t.Rate6);
resultModel.RMBMoney = list.Sum(t => t.RMBMoney);
resultModel.USDMoney = list.Sum(t => t.USDMoney);
resultModel.yf = list.Sum(t => t.yf);
resultModel.mdfee = list.Sum(t => t.mdfee);
resultModel.userid = UserId;
resultModel.username = ff.Where(t => t.ID == UserId).Select(t => t.Name).FirstOrDefault();
resultModel.OrderNum = list.Sum(t => t.OrderNum); //OrderNum
resultModel.PlatId = platId;
resultModel.PlatName = DataNew.MRJL_GetPlatNameByPlatId(platId);
resultList.Add(resultModel);
}
//int rowCount = resultList.Count();
//rmodel.DataSource = resultList;
//rmodel.RowCount = rowCount;
//return resultList;
}
}
catch
{
}
return resultList.OrderByDescending(t => t.OrderNum).ToList();
}
#endregion
[WebMethod(EnableSession = true)]
public string GetExcelFile_UserOrderSaleList(int UserId,int PlatId, DateTime sDate, DateTime eDate)
{
// 这里确保您的登录逻辑正确
//PagesNew.Login(this.Session);
string failMsg = "";
try
{
//Pages.Login(this.Session);
#region 信息查询
var slist = new List<BB_MRJL_User>();
slist = GetUserOrderSaleList_TongYong(UserId, PlatId, sDate, eDate );
#endregion
var hlist = new List<BB_MRJL_User>();
TableColumnCollection listColumns = new TableColumnCollection();
// 添加列信息
listColumns.Add("username", "销售人员", DbType.String, "");
listColumns.Add("PlatName", "销售平台", DbType.String, "");
listColumns.Add("OrderNum", "销售订单量", DbType.String, "");
listColumns.Add("RMBMoney", "销售金额/RMB", DbType.String, "");
listColumns.Add("USDMoney", "销售金额/$", DbType.String, "");
listColumns.Add("yf", "运费", DbType.String, "");
listColumns.Add("Rate6", "广告花费($)", DbType.String, "");
listColumns.Add("mdfee", "面单费用", DbType.String, "");
listColumns.Add("LR", "预估利润", DbType.String, "");
listColumns.Add("JL", "净利润", DbType.String, "");
// 调用 Excel 导出方法并返回结果
MicrosoftExcel obj2 = new MicrosoftExcel();
failMsg = obj2.Export(slist, listColumns);
}
catch (Exception ex)
{
}
return failMsg;
}
[WebMethod(EnableSession = true)]
public List<BB_MRJL_OrderDeatil> GetUserOrderDetailSaleList(int UserId, DateTime sDate, DateTime eDate)
{
// 这里确保您的登录逻辑正确
//PagesNew.Login(this.Session);
var resultList = new List<BB_MRJL_OrderDeatil>();
try
{
var ff = DataNew.GetList_YYUser("");
//Pages.Login(this.Session);
var resultModel = new BB_MRJL_OrderDeatil();
var list = DataNew.MRJL_GetUserOderDetailMsgByDay(sDate, eDate, UserId);
if (list != null && list.Count() > 0)
{
foreach (var l in list)
{
var goods = new List<string>();
goods.Add(l.GoodsID.ToString());
var adfeeModel2 = DataNew.MRJL_GetGKFeeByMouth(sDate, eDate, l.PlatId, l.ShopId, goods);
//l.Rate3 = adfeeModel1 != null ? adfeeModel1.Adfee : 0;
l.Rate6 = adfeeModel2 != null ? adfeeModel2.Adfee : 0;
//净利润
l.LR = Math.Round(l.LR, 2);
l.JL = Math.Round(l.LR + l.ckfee - l.Rate6, 2);
l.userid = UserId;
l.username = ff.Where(t => t.ID == UserId).Select(t => t.Name).FirstOrDefault();
l.PlatId = l.PlatId;
l.PlatName = DataNew.MRJL_GetPlatNameByPlatId(l.PlatId);
l.ShopName = DataNew.MRJL_GetShopNameByShopId(l.ShopId);
resultList.Add(l);
}
}
}
catch (Exception ex)
{
}
return resultList.OrderBy(t => t.InDate).ToList();
}
#endregion
#region 库存申请
#region 查找用户的分配货号
[WebMethod(EnableSession = true)]
public List<GoodsBaseModel> GetGoodsListByUserId()
{
PagesNew.Login(this.Session);
int userid = Convert.ToInt32(Session["UserId"]);
return TradeManageNew.DataNew.GetApplyGoodsListByUserId(userid);
}
#endregion
#region 根据货号查找销售价格
[WebMethod(EnableSession = true)]
public decimal GetSalePriceByGoodsId(int GoodsId)
{
PagesNew.Login(this.Session);
return TradeManageNew.DataNew.GetSalePriceByGoodsId(GoodsId);
}
#endregion
#region 保存出库申请
[WebMethod(EnableSession = true)]
public string Save_CKInventoryApply(CK_InventoryApply Model)
{
//PagesNew.Login(this.Session);
string result = "";
try
{
//新增
if (Model.Id == 0)
{
Model.ApplyDate = DateTime.Now;
Model.CheckDate = DateTime.Now;
Model.Status = 0;
}
//编辑
else
{
Model.ApplyDate = DateTime.Now;
Model.CheckDate = DateTime.Now;
}
TradeManageNew.DataNew.Save_CKInventoryApply(Model);
}
catch (Exception ex)
{
result = ex.Message;
}
return result;
}
#endregion
#region 分页查询
[WebMethod(EnableSession = true)]
public JsonModel<List<CK_InventoryApply>> GetPageList_CKInventoryApply(int UserId, int Status, string GoodsCode, DateTime? sDate, DateTime? eDate, int PageIndex, int PageSize)
{
//PagesNew.Login(this.Session);
var resultModel = new JsonModel<List<CK_InventoryApply>>();
try
{
RefParameterCollection Param = new RefParameterCollection();
#region 查询条件添加
//员工单人
if (UserId != 1)
{
Param.Add("a.UserId", "=", UserId, DbType.Int32);
}
//状态查询
if (Status != -1)
{
Param.Add("a.Status", "=", Status, DbType.Int32);
}
//货号查询
if (!string.IsNullOrEmpty(GoodsCode))
{
Param.Add("b.GoodsCode", "like", GoodsCode, DbType.String);
}
//时间
if (sDate != null)
{
Param.Add("a.ApplyDate", ">=", sDate, DbType.Date);
}
//状态查询
if (eDate != null)
{
Param.Add("a.ApplyDate", "<=", eDate, DbType.Date);
}
#endregion
int RowCount = 0;
string Sort = "Id";
resultModel.DataSource = TradeManageNew.DataNew.GetPageList_CKInventoryApply(Param, PageIndex, PageSize, Sort, out RowCount);
resultModel.RowCount = RowCount;
}
catch (Exception ex)
{
resultModel.ErrorMsg = ex.Message;
}
return resultModel;
}
#endregion
#region 更新出库申请状态
[WebMethod(EnableSession = true)]
public string UpdateStatus_CKInventoryApply(int Id, int Status, string CheckMsg)
{
//PagesNew.Login(this.Session);
string result = "";
try
{
var model = TradeManageNew.DataNew.GetModel_CKInventoryApply(Id);
if (model != null)
{
if (model.Status != 1)
{
model.Status = Status;
if (Status == 1)
{
model.CheckDate = DateTime.Now;
//同时新增库存表信息
}
else if (Status == 2)
{
model.CheckMsg = CheckMsg;
}
TradeManageNew.DataNew.Save_CKInventoryApply(model);
}
else
{
result = "本条记录已审核通过,请勿操作!";
}
}
else
{
result = "没有查询到对应记录,更新失败";
}
}
catch (Exception ex)
{
result = ex.Message;
}
return result;
}
#endregion
#region 撤销出库申请
[WebMethod(EnableSession = true)]
public string Cancel_CKInventoryApply(int Id)
{
//PagesNew.Login(this.Session);
string result = "";
try
{
var model = TradeManageNew.DataNew.GetModel_CKInventoryApply(Id);
if (model != null)
{
if (model.Status != 1)
{
TradeManageNew.DataNew.Delete_CKInventoryApply((int)model.Id);
}
else
{
result = "本条记录已审核通过,请勿操作!";
}
}
else
{
result = "没有查询到对应记录,更新失败";
}
}
catch (Exception ex)
{
result = ex.Message;
}
return result;
}
#endregion
#endregion
#region 管理人员
#region 获取管理人员
[WebMethod(EnableSession = true)]
public List<BaseModel> GetUserList(int selectUserId)
{
//PagesNew.Login(this.Session);
return DataNew.GetUserList(selectUserId);
}
#endregion
#region 获取管理人员及下属
[WebMethod(EnableSession = true)]
public List<DD_OrderAuth_Show> GetList_DDOrderAuthShow(int selectUserId)
{
//PagesNew.Login(this.Session);
List<DD_OrderAuth_Show> resultList = new List<DD_OrderAuth_Show>();
var oldList = DataNew.GetList_DDOrderAuthShow(selectUserId);
if (oldList.Count() > 0)
{
foreach (var newGroupLeaderId in oldList.Select(t => t.GroupLeaderId).Distinct().ToList())
{
try
{
var newList = oldList.Where(t => t.GroupLeaderId == newGroupLeaderId).ToList();
DD_OrderAuth_Show model = new DD_OrderAuth_Show();
model.GroupLeaderId = newList.First().GroupLeaderId;
model.GroupLeaderName = newList.First().GroupLeaderName;
model.UserNameList = string.Join(",", newList.Select(t => t.UserName));
model.UserName = newList.Select(t => t.UserName).ToList();
model.UserId = newList.Select(t => t.UserId).ToList();
resultList.Add(model);
}
catch
{
}
}
}
return resultList;
}
#endregion
#region 开始保存
[WebMethod(EnableSession = true)]
public string Save_DDOrderAuth(int GroupLeaderId,List<int> UserIdList)
{
//PagesNew.Login(this.Session);
string resultMsg = "";
try
{
//判断本管理人员是否存在
var groupLeaderList = DataNew.GetList_DDOrderAuth(GroupLeaderId, -1, true);
//已存在本管理人员
if (groupLeaderList.Count() > 0)
{
//先检索已存在被管理者人员名单
var oldPersonList = DataNew.GetList_DDOrderAuth(-1, GroupLeaderId, false);
var oldUserIdList = oldPersonList.Select(t => t.UserId).ToList();
var deleteUserIdList = oldPersonList.Where(t => !UserIdList.Contains(t.UserId)).ToList();
if (deleteUserIdList != null && deleteUserIdList.Count() > 0)
{
foreach (var deleteModel in deleteUserIdList)
{
DataNew.Delete_DDOrderAuth((int)deleteModel.Id);
}
}
var insertUserIdList = UserIdList.Where(t => !oldUserIdList.Contains(t)).ToList();
if (insertUserIdList != null && insertUserIdList.Count() >0)
{
foreach (var userid in insertUserIdList)
{
DD_OrderAuth insertPersonModel = new DD_OrderAuth()
{
UserId = userid,
isGroupLeader = false,
GroupLeaderId = GroupLeaderId
};
DataNew.Save_DDOrderAuth(insertPersonModel);
}
}
}
//未存在 添加
else
{
//添加管理人员信息
DD_OrderAuth insertGroupLeaderModel = new DD_OrderAuth()
{
UserId = GroupLeaderId,
isGroupLeader = true,
GroupLeaderId = -1
};
DataNew.Save_DDOrderAuth(insertGroupLeaderModel);
//循环添加被管理者信息
foreach (var userid in UserIdList)
{
DD_OrderAuth insertPersonModel = new DD_OrderAuth()
{
UserId = userid,
isGroupLeader = false,
GroupLeaderId = GroupLeaderId
};
DataNew.Save_DDOrderAuth(insertPersonModel);
}
}
}
catch(Exception ex)
{
resultMsg = ex.Message;
}
return resultMsg;
}
#endregion
#region 开始保存
[WebMethod(EnableSession = true)]
public List<DD_OrderAuth> GetList_DDOrderAuth(int userID, int groupLeaderId, bool isGroupLeader)
{
//PagesNew.Login(this.Session);
List<DD_OrderAuth> groupLeaderList = new List<DD_OrderAuth>();
try
{
//判断本管理人员是否存在
groupLeaderList = DataNew.GetList_DDOrderAuth(userID, groupLeaderId, isGroupLeader);
}
catch (Exception ex)
{
}
return groupLeaderList;
}
#endregion
#region 删除
[WebMethod(EnableSession = true)]
public string Delete_DDOrderAuthByGroupLeaderId(int GroupLeaderId)
{
//PagesNew.Login(this.Session);
string resultMsg = "";
try
{
//判断本管理人员是否存在
var groupLeaderList = DataNew.GetList_DDOrderAuth(GroupLeaderId, -1, true);
//已存在本管理人员
if (groupLeaderList.Count() > 0)
{
//先检索已存在被管理者人员名单
var oldPersonList = DataNew.GetList_DDOrderAuth(-1, GroupLeaderId, false);
if (oldPersonList != null && oldPersonList.Count() > 0)
{
foreach (var deleteModel in oldPersonList)
{
DataNew.Delete_DDOrderAuth((int)deleteModel.Id);
}
}
//删除管理者
DataNew.Delete_DDOrderAuth((int)groupLeaderList.FirstOrDefault().Id);
}
}
catch (Exception ex)
{
resultMsg = ex.Message;
}
return resultMsg;
}
#endregion
#endregion
}
}