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/TradeData/API_OrderInfoService.cs

1606 lines
81 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using NetLibrary;
using NetLibrary.Data;
using NetLibrary.ReportPrint;
using TradeModel;
using NetLibrary.OnlineTrade;
using NetLibrary.Log;
using MarketplaceWebServiceOrders.Model;
using System.Reflection;
namespace TradeData
{
public class API_OrderInfoService
{
#region 保存
public static int Save(int? CompanyId,API_OrderInfo Model)
{
if (Model.MoneyCode == "") Model.MoneyCode = null;
string tsql = @"
if @OrderId>0
begin
Update [API_OrderInfo] set [ShopId]=@ShopId,[ShopName]=@ShopName,[OrderCode]=@OrderCode,[PlatOrderCode]=@PlatOrderCode,[HBOrderCode]=@HBOrderCode,[TotalPrice]=@TotalPrice,[MoneyCode]=@MoneyCode,[OrderDate]=@OrderDate,[CustomID]=@CustomID,[RevName]=@RevName,[RevCountry]=@RevCountry,[RevAddr]=@RevAddr,[RevPhone]=@RevPhone,RevMobile=@RevMobile,[RevMail]=@RevMail,[RevFax]=@RevFax,RevZip=@RevZip,[BuyRemark]=@BuyRemark,[LeaveWord]=@LeaveWord,[PayDate]=@PayDate,[OutOrderDate]=@OutOrderDate,[PlatType]=@PlatType,IsFba=@IsFba,PostInfo=@PostInfo,RevProvince=@RevProvince,RevCity=@RevCity,RevArea=@RevArea,escrowFee=@escrowFee,logisticsAmount=@logisticsAmount,OrderState=@OrderState where OrderId=@OrderId
end
else
begin
--delete from API_OrderInfo where CompanyId=@CompanyId and OrderCode=@OrderCode
INSERT INTO [API_OrderInfo](CompanyId,[ShopId],[ShopName],[OrderCode],PlatOrderCode,HBOrderCode,[TotalPrice],[MoneyCode],[OrderDate],[CustomID],[RevName],[RevCountry],[RevAddr],[RevPhone],RevMobile,[RevMail],[RevFax],RevZip,[BuyRemark],[LeaveWord],[PayDate],[OutOrderDate],[PlatType],IsFba,PostInfo,State,RevProvince,RevCity,RevArea,OrderState,logisticsAmount,escrowFee,LogisticsId,ExpressId,OrderLevel,GoodsNum)values(@CompanyId,@ShopId,@ShopName,@OrderCode,@PlatOrderCode,@HBOrderCode,@TotalPrice,@MoneyCode,@OrderDate,@CustomID,@RevName,@RevCountry,@RevAddr,@RevPhone,@RevMobile,@RevMail,@RevFax,@RevZip,@BuyRemark,@LeaveWord,@PayDate,@OutOrderDate,@PlatType,@IsFba,@PostInfo,0,@RevProvince,@RevCity,@RevArea,@OrderState,@logisticsAmount,@escrowFee,@LogisticsId,@ExpressId,@OrderLevel,@GoodsNum)
set @OrderId=SCOPE_IDENTITY()
end
select @OrderId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId);
db.AddInParameter(cmd, "@CompanyId", DbType.Int32, CompanyId);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId);
db.AddInParameter(cmd, "@ShopName", DbType.String, Model.ShopName);
db.AddInParameter(cmd, "@OrderCode", DbType.String, Model.OrderCode);
db.AddInParameter(cmd, "@PlatOrderCode", DbType.String, Model.PlatOrderCode);
db.AddInParameter(cmd, "@HBOrderCode", DbType.String, Model.HBOrderCode);
db.AddInParameter(cmd, "@TotalPrice", DbType.Decimal, Model.TotalPrice);
db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode);
db.AddInParameter(cmd, "@OrderDate", DbType.DateTime2, Model.OrderDate);
db.AddInParameter(cmd, "@CustomID", DbType.String, Model.CustomID);
db.AddInParameter(cmd, "@RevName", DbType.String, Model.RevName);
db.AddInParameter(cmd, "@RevCountry", DbType.String, Model.RevCountry);
db.AddInParameter(cmd, "@RevAddr", DbType.String, Model.RevAddr);
db.AddInParameter(cmd, "@RevPhone", DbType.String, Model.RevPhone);
db.AddInParameter(cmd, "@RevMobile", DbType.String, Model.RevMobile);
db.AddInParameter(cmd, "@RevMail", DbType.String, Model.RevMail);
db.AddInParameter(cmd, "@RevFax", DbType.String, Model.RevFax);
db.AddInParameter(cmd, "@RevZip", DbType.String, Model.RevZip);
db.AddInParameter(cmd, "@RevProvince", DbType.String, Model.RevProvince);
db.AddInParameter(cmd, "@RevCity", DbType.String, Model.RevCity);
db.AddInParameter(cmd, "@RevArea", DbType.String, Model.RevArea);
db.AddInParameter(cmd, "@logisticsAmount", DbType.Decimal, Model.logisticsAmount);
db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, Model.escrowFee);
// if (Model.BuyRemark != null && Model.BuyRemark != "" && Model.BuyRemark.Length > 900)
// Model.BuyRemark = Model.BuyRemark.Substring(0, 900);
db.AddInParameter(cmd, "@BuyRemark", DbType.String, Model.BuyRemark);
db.AddInParameter(cmd, "@LeaveWord", DbType.String, Model.LeaveWord);
db.AddInParameter(cmd, "@PayDate", DbType.DateTime2, Model.PayDate);
db.AddInParameter(cmd, "@OutOrderDate", DbType.DateTime2, Model.OutOrderDate);
db.AddInParameter(cmd, "@PlatType", DbType.Int32, Model.PlatType);
db.AddInParameter(cmd, "@IsFba", DbType.Int32, Model.IsFba);
db.AddInParameter(cmd, "@PostInfo", DbType.String, Model.PostInfo);
db.AddInParameter(cmd, "@OrderState", DbType.Int32, Model.OrderState);
db.AddInParameter(cmd, "@LogisticsId", DbType.Int32, Model.LogisticsId);
db.AddInParameter(cmd, "@ExpressId", DbType.String, Model.ExpressId);
db.AddInParameter(cmd, "@OrderLevel", DbType.Int32, Model.OrderLevel);
db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, Model.GoodsNum);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
tsql = @"
if @Id>0
begin
Update [API_OrderGoods] set [GoodsNum]=@GoodsNum,[GoodsPrice]=@GoodsPrice,[GoodsSKU]=@GoodsSKU,[GoodsName]=@GoodsName,PostInfo=@PostInfo,MoneyCode=@MoneyCode,productImgUrl=@productImgUrl,GoodsCode=@GoodsCode,OldNum=@OldNum,GoodsDesc=@GoodsDesc where Id=@Id
end
else
begin
INSERT INTO [API_OrderGoods]([OrderId],[GoodsNum],[GoodsPrice],[GoodsSKU],[GoodsName],PostInfo,MoneyCode,productImgUrl,GoodsCode,OldNum,GoodsDesc,OrderItemId)values(@OrderId,@GoodsNum,@GoodsPrice,@GoodsSKU,@GoodsName,@PostInfo,@MoneyCode,@productImgUrl,@GoodsCode,@OldNum,@GoodsDesc,@OrderItemId)
end
";
cmd = db.GetSqlStringCommand(tsql);
string ids = "";
foreach (var item in Model.ListModel)
{
// ids += ", " + item.OrderId;
cmd.Parameters.Clear();
db.AddInParameter(cmd, "@OrderId", DbType.Int32, a);
db.AddInParameter(cmd, "@Id", DbType.Int32, item.Id);
db.AddInParameter(cmd, "@GoodsNum", DbType.Int32, item.GoodsNum);
db.AddInParameter(cmd, "@GoodsDesc", DbType.String, item.GoodsDesc);
db.AddInParameter(cmd, "@GoodsPrice", DbType.Decimal, item.GoodsPrice);
db.AddInParameter(cmd, "@GoodsSKU", DbType.String, item.GoodsSKU);
db.AddInParameter(cmd, "@GoodsName", DbType.String, item.GoodsName);
db.AddInParameter(cmd, "@MoneyCode", DbType.String, Model.MoneyCode);
db.AddInParameter(cmd, "@PostInfo", DbType.String, item.PostInfo);
db.AddInParameter(cmd, "@productImgUrl", DbType.String, item.productImgUrl);
db.AddInParameter(cmd, "@GoodsCode", DbType.String, item.GoodsCode);
db.AddInParameter(cmd, "@OldNum", DbType.Int32, item.OldNum);
db.AddInParameter(cmd, "@OrderItemId", DbType.String, item.OrderItemId);
db.ExecuteNonQuery(cmd);
}
//if (Model.OrderId > 0)
//{
// tsql = "delete from API_OrderGoods where OrderId=@OrderId and Id not in (" + ids + ")";
// cmd = db.GetSqlStringCommand(tsql);
// db.AddInParameter(cmd, "@OrderId", DbType.Int32, Model.OrderId);
// db.ExecuteNonQuery(cmd);
//}
return a;
}
#endregion
#region 删除
public static void Delete(int OrderId)
{
string tsql = @"
delete from API_OrderInfo where OrderId=@OrderId
delete from API_OrderGoods where OrderId=@OrderId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 返回Model
public static API_OrderInfo GetModel(int OrderId)
{
API_OrderInfo model = null;
string tsql = "select * from API_OrderInfo where OrderId=@OrderId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@OrderId", DbType.Int32, OrderId);
DataTable tb = db.ExecuteDataTable(cmd);
if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel<API_OrderInfo>();
return model;
}
#endregion
#region 分页查询
public static List<API_OrderInfo> GetListAPI_OrderInfo(RefParameterCollection where, int PageIndex, int PageSize, string Sort, out int RowCount)
{
if (where == null) where = new RefParameterCollection();
QueryService ser = new QueryService();
ser.Fields = @"OrderId=cast(a.OrderId as int),a.ShopId,a.ShopName,a.JoinOrderCode,a.TotalPrice,a.MoneyCode,a.OrderDate,a.CustomID,a.RevName,a.RevCountry,a.RevAddr,a.RevPhone,a.RevMobile,a.RevMail,a.RevFax,a.BuyRemark,a.LeaveWord,a.PayDate,a.OutOrderDate,a.PlatType";
ser.Tables = @"API_OrderInfo a";
ser.Filter = where.GetWhere(System.Data.CommandType.Text);
ser.PageIndex = PageIndex;
ser.PageSize = PageSize;
ser.Sort = Sort;
ser.KeyName = "OrderId";
string tsql = ser.GetText();
where.AddOutParameter("RowCount", System.Data.DbType.Int32); ;
List<API_OrderInfo> ListModel = null;
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, where);
DataTable tb = db.ExecuteDataTable(cmd);
RowCount = Convert.ToInt32(cmd.Parameters["@RowCount"].Value);
ListModel = tb.ToList<API_OrderInfo>();
return ListModel;
}
#endregion
#region 判断订单号是否重复
public static bool CheckJoinOrderCode1(int PlatType, string OrderCode, int OrderState,DateTime? OutOrderDate)
{
string tsql = @"
declare @OldOrderState int,@OrderId int
select top 1 @OldOrderState=isnull(OrderState,1),@OrderId=OrderId from API_OrderInfo where PlatType=@PlatType and OrderCode=@OrderCode
if @OldOrderState is not null
begin
if @OldOrderState<>@OrderState
begin
update API_OrderInfo set state=0,OrderState=@OrderState,OutOrderDate=@OutOrderDate where OrderId=@OrderId
end
select 1
end
else
begin
select 0
end
";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType);
db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode);
db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState);
db.AddInParameter(cmd, "@OutOrderDate", DbType.DateTime, OutOrderDate);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
if (a == 0) return true;
return false;
}
#endregion
#region 判断订单号是否重复
public static bool CheckJoinOrderCode(int PlatType, string OrderCode, int OrderState)
{
string tsql = @"
declare @OldOrderState int,@OrderId int
set @OrderId=0
select top 1 @OldOrderState=isnull(OrderState,1),@OrderId=OrderId from API_OrderInfo where PlatType=@PlatType and OrderCode=@OrderCode
if @OrderId>0
begin
if @OldOrderState<>@OrderState
begin
update API_OrderInfo set state=0,OrderState=@OrderState where OrderId=@OrderId
end
select 1
end
else
begin
select 0
end
";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType);
db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode);
db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
if (a == 0) return true;
return false;
}
#endregion
#region ebay判断订单号是否重复
public static bool CheckJoinOrderCode3(int PlatType, string OrderCode, int OrderState)
{
string tsql = @"
declare @OldOrderState int,@OrderId int
set @OrderId=0
select top 1 @OldOrderState=isnull(OrderState,1),@OrderId=OrderId from API_OrderInfo where PlatType=@PlatType and (OrderCode=@OrderCode or PlatOrderCode=@OrderCode)
if @OrderId>0
begin
if @OldOrderState<>@OrderState
begin
update API_OrderInfo set state=0,OrderState=@OrderState where OrderId=@OrderId
end
select 1
end
else
begin
select 0
end
";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@PlatType", DbType.Int32, PlatType);
db.AddInParameter(cmd, "@OrderCode", DbType.String, OrderCode);
db.AddInParameter(cmd, "@OrderState", DbType.Int32, OrderState);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
if (a == 0) return true;
return false;
}
#endregion
#region 读取所有未处理的订单
public static List<int> GetList(int CompanyID)
{
string tsql = "select OrderId from API_OrderInfo where CompanyID=@CompanyID and State=0";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID);
DataTable tb=db.ExecuteDataTable(cmd);
List<int> ListModel = new List<int>();
foreach (DataRow row in tb.Rows)
{
int OrderId = Convert.ToInt32(row["OrderId"]);
ListModel.Add(OrderId);
}
return ListModel;
}
#endregion
#region 读取所有未处理的订单
public static List<int> GetListForShop(int CompanyID,string ShopIds)
{
string tsql = "select OrderId from API_OrderInfo where CompanyID=@CompanyID and State=0 and ShopId in (" + ShopIds + ")";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@CompanyID", DbType.Int32, CompanyID);
DataTable tb = db.ExecuteDataTable(cmd);
List<int> ListModel = new List<int>();
foreach (DataRow row in tb.Rows)
{
int OrderId = Convert.ToInt32(row["OrderId"]);
ListModel.Add(OrderId);
}
return ListModel;
}
#endregion
#region 读取所有未处理的订单
public static List<API_OrderInfo> GetListForShop3(int ShopId)
{
string tsql = "select top 1000 * from API_OrderInfo where State<5 and ShopId=@ShopId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
DataTable tb = db.ExecuteDataTable(cmd);
return tb.ToList<API_OrderInfo>();
}
#endregion
#region 读取所有未处理的订单
public static List<API_OrderGoods> GetListOrderGoods(int ShopId)
{
string tsql = "select top 1500 b.* from API_OrderInfo a inner join API_OrderGoods b on a.orderid=b.orderid where a.State<5 and a.ShopId=@ShopId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
DataTable tb = db.ExecuteDataTable(cmd);
return tb.ToList<API_OrderGoods>();
}
#endregion
#region 读取所有未处理的订单
public static void UpdateOrderState(int ShopId)
{
string tsql = "update API_OrderInfo set state=5 where state<=1 and ShopId=@ShopId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 读取所有未处理的订单
public static List<int> GetListForShop2(int ShopId)
{
string tsql = "select OrderId from API_OrderInfo where State=0 and ShopId=@ShopId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
DataTable tb = db.ExecuteDataTable(cmd);
List<int> ListModel = new List<int>();
foreach (DataRow row in tb.Rows)
{
int OrderId = Convert.ToInt32(row["OrderId"]);
ListModel.Add(OrderId);
}
return ListModel;
}
#endregion
#region 读取所有未处理的订单
public static List<WL_ExpressSelect> GetExpressSelect(int PlatId)
{
List<WL_ExpressSelect> list = null;
string tsql = @"select a.*,b.EnglishName from WL_ExpressSelect a
left join JC_Country b on a.Country=b.Code where a.PlatId=@PlatId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@PlatId", DbType.Int32, PlatId);
DataTable tb = db.ExecuteDataTable(cmd);
list = tb.ToList<WL_ExpressSelect>();
return list;
}
#endregion
#region 查询上下架产品
public static List<JC_ProductOnOff> GetProductOnOffList()
{
List<JC_ProductOnOff> list = null;
string tsql = @"declare @nowmin int
select @nowmin=DATEPART(hour,GETDATE())*60+DATEPART(MINUTE,GETDATE())
select b.ShopId,b.Appkey,b.DeveKey,b.RefreshToken,b.AccessToken,b.RefreshTokenSaveTime,b.AccessTokenUpdateTime,IsOn=1,a.productIds from HW_OnOffList a
inner join JC_Shop b on a.ShopID=b.ShopId
inner join HW_OnOffDetail c on a.OnOffID=c.OnOffID
where a.onoffflag=1 and cast(SUBSTRING(OnTime,1,2) as int)*60+cast(SUBSTRING(OnTime,4,2) as int)=@nowmin
union
select b.ShopId,b.Appkey,b.DeveKey,b.RefreshToken,b.AccessToken,b.RefreshTokenSaveTime,b.AccessTokenUpdateTime,IsOn=0,a.productIds from HW_OnOffList a
inner join JC_Shop b on a.ShopID=b.ShopId
inner join HW_OnOffDetail c on a.OnOffID=c.OnOffID
where a.onoffflag=1 and cast(SUBSTRING(OffTime,1,2) as int)*60+cast(SUBSTRING(OffTime,4,2) as int)=@nowmin ";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
DataTable tb = db.ExecuteDataTable(cmd);
list = tb.ToList<JC_ProductOnOff>();
return list;
}
#endregion
#region 查询要导单店铺
public static JC_Shop GetImpotShop()
{
JC_Shop model = null;
string tsql = @"select top 1 b.*,a.DDSDate,a.DDEDate from JC_SyncState a
inner join Jc_shop b on a.CompanyId=b.ShopId
where SyncType=1 and IsDD=1";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
DataTable tb = db.ExecuteDataTable(cmd);
if (tb.Rows.Count > 0) model = tb.Rows[0].ToModel<JC_Shop>();
return model;
}
#endregion
#region 查询要导单店铺
public static List<JC_Shop> GetImpotShopList()
{
string tsql = @"
declare @InUserId int,@PlatType int
set @InUserId=-1
select top 1 @PlatType=b.PlatType from JC_SyncState a
inner join Jc_shop b on a.CompanyId=b.ShopId
where SyncType=1 and a.IsDD=1 and a.State=1 order by StartDate
select top 3 b.*,a.DDSDate,a.DDEDate from JC_SyncState a
inner join Jc_shop b on a.CompanyId=b.ShopId
where SyncType=1 and IsDD=1 and a.State=1 and b.PlatType=@PlatType";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
DataTable tb = db.ExecuteDataTable(cmd);
return tb.ToList<JC_Shop>();
}
#endregion
#region 修改采购时间
public static void UpdateBuyDate()
{
string tsql = @"
update b set b.BuyDate=GETDATE() from DT_OrderGoods a
inner join DT_OrderInfo b on a.OrderId=b.OrderId
inner join HW_GoodsDetail c on a.DetailId=c.DetailId
where b.BuyDate is null and b.FPDate is not null and b.State=1 and c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum>=0
update b set b.BuyDate=a.BuyDate from DT_OrderInfo a
inner join DT_OrderInfoNew b on a.OrderId=b.OrderId
where b.BuyDate is null and a.BuyDate is not null
--update DT_OrderInfo set BuyDate=null where OrderId in (
--select top 1 a.OrderId from DT_OrderGoods a
--inner join DT_OrderInfoNew b on a.OrderId=b.OrderId
--inner join HW_GoodsDetail c on a.DetailId=c.DetailId
--inner join (select a.DetailId,GoodsNum=SUM(a.GoodsNum) from DT_OrderGoods a
--inner join DT_OrderInfo b on a.OrderId=b.OrderId
--where b.State=1 and b.BuyDate is null group by a.DetailId)d on a.DetailId=d.DetailId
--where b.BuyDate is not null and b.FPDate is not null and b.State=1 and c.GoodsNum+c.GoodsInNum-c.GoodsPlanNum+d.GoodsNum<0 order by b.OrderLevel,b.InDate desc)";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 修改采购时间
public static List<HW_GoodsDetail> GetDetailList()
{
string tsql = @"
select distinct a.DetailId,LeftNum=b.GoodsPlanNum-b.GoodsNum-b.GoodsInNum from DT_OrderGoods a
inner join HW_GoodsDetail b on a.DetailId=b.DetailId
inner join DT_OrderInfo c on a.OrderId=c.OrderId
where b.GoodsNum+b.GoodsInNum-b.GoodsPlanNum<0 and c.State=1 order by a.DetailId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
DataTable tb = db.ExecuteDataTable(cmd);
return tb.ToList<HW_GoodsDetail>();
}
#endregion
#region 修改采购时间
public static List<HW_GoodsDetail> GetDetailOrderList(int DetailId)
{
string tsql = @"
select top 10 a.OrderId,c.BuyDate,c.InDate,c.OrderLevel from DT_OrderGoods a
inner join HW_GoodsDetail b on a.DetailId=b.DetailId
inner join DT_OrderInfo c on a.OrderId=c.OrderId
where a.DetailId=@DetailId and c.State=1 order by c.OrderLevel,c.InDate desc";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@DetailId", DbType.String, DetailId);
DataTable tb = db.ExecuteDataTable(cmd);
return tb.ToList<HW_GoodsDetail>();
}
#endregion
#region 查询要导单店铺
public static void SaveImpotShop(int ShopId,string info)
{
string tsql = @"update JC_SyncState set state=0,EndDate=getdate(),DDResult=@info where CompanyId=@ShopId and SyncType=1 ";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
db.AddInParameter(cmd, "@info", DbType.String, info);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 插入提示消息
public static void SaveImpotShopMess(int ShopId, string info)
{
string tsql = @"INSERT INTO [JC_OpenMess]([Content],[IsRead],[OpenDate],[Target],[Type],[UserType],[UserId])
select b.ShopName+':'+@info,0,getdate(),0,1,'P',a.UserId from JC_ShopUser a
inner join JC_Shop b on a.ShopId=b.ShopId where a.shopid=@ShopId and a.SType='S'";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
db.AddInParameter(cmd, "@info", DbType.String, info);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 插入提示消息
public static void SaveImpotShopMess2(int ShopId, string info)
{
string tsql = @"INSERT INTO [JC_OpenMess]([Content],[IsRead],[OpenDate],[Target],[Type],[UserType],[UserId])
select ShopName+':'+@info,0,getdate(),0,1,'P',1 from JC_Shop where shopid=@ShopId";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
db.AddInParameter(cmd, "@info", DbType.String, info);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 查询要导单店铺
public static void SaveImpotShopInfo(int ShopId, string info)
{
string tsql = @"update JC_SyncState set InName='系统自动采集',DDResult=@info where CompanyId=@ShopId and SyncType=1";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
db.AddInParameter(cmd, "@info", DbType.String, info);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 查询要导单店铺
public static void SaveImpotState(int ShopId)
{
string tsql = @"update JC_SyncState set IsDD=0 where CompanyId=@ShopId and SyncType=1";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 查询要导单店铺
public static void SaveImpotState2(string ShopIds)
{
string tsql = @"update JC_SyncState set IsDD=0 where CompanyId in (" + ShopIds + ") and SyncType=1";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 保存各平台数据
public static void SaveOrderModel(int? CompanyId,int ShopId, string ShopName, int PlatType, int IsFba, List<OrderModel> ListModel)
{
if (ListModel == null) return;
var wllist = GetExpressSelect(PlatType);
foreach (var item in ListModel)
{
if (item.PlatOrderCode == "112-6514054-6349010" || item.OrderCode == "108906731002378")
{
string asfsffs = "";
}
try
{
int OrderState = 1;
item.OrderState = 1;
//if (item.OrderState != null)
// OrderState = item.OrderState.Value;
if (PlatType == 1 && item.OutOrderDate != null)
{
if (API_OrderInfoService.CheckJoinOrderCode1(PlatType, item.OrderCode, OrderState, item.OutOrderDate.Value) == false)
continue;
}
else if (PlatType == 3)
{
string oid = item.OrderCode;
if (item.PlatOrderCode != null && item.PlatOrderCode != "" && item.PlatOrderCode.Length >5)
oid = item.PlatOrderCode;
item.OrderCode = oid;
item.PlatOrderCode = oid;
if (API_OrderInfoService.CheckJoinOrderCode3(PlatType, oid, OrderState) == false)
continue;
}
else
if (API_OrderInfoService.CheckJoinOrderCode(PlatType, item.OrderCode, OrderState) == false) continue;
if (item.MoneyCode == "") item.MoneyCode = null;
API_OrderInfo model = new API_OrderInfo();
model.ShopId = ShopId;
model.ShopName = ShopName;
model.OrderCode = item.OrderCode;
model.PlatOrderCode = item.PlatOrderCode;
model.HBOrderCode = item.HBOrderCode;
model.TotalPrice = item.TotalPrice;
model.MoneyCode = item.MoneyCode;
model.OrderDate = item.OrderDate;
model.CustomID = item.BuyerID;
model.RevName = item.BuyerName;
model.RevCountry = item.BuyerCountry;
model.RevAddr = item.BuyerAddr;
model.RevPhone = item.BuyerPhone;
model.RevMobile = item.BuyerMobile;
model.RevMail = item.BuyerMail;
model.RevFax = item.BuyerFax;
model.RevZip = item.BuyerZip;
model.RevProvince = item.BuyerProvince;
model.RevCity = item.BuyerCity;
model.RevArea = item.BuyerArea;
model.BuyRemark = item.OrderRemark;
model.LeaveWord = item.LeaveWord;
model.PayDate = item.PayDate;
model.OutOrderDate = item.OutOrderDate;
model.PlatType = PlatType;
model.IsFba = IsFba;
model.escrowFee = item.escrowFee;
// model.loanAmount = item.loanAmount;
model.logisticsAmount = item.logisticsAmount;
model.PostInfo = item.PostInfo;
if (wllist != null)
{
if (PlatType == 1)
{
//if(model.OrderCode=="72568607625211")
//{
// string ddfsf = "";
//}
var md = wllist.Find(n => n.ShopId == model.ShopId && n.PostInfo == model.PostInfo && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == model.PostInfo && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == model.PostInfo && n.Country == "0");
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == "0" && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
else
if (PlatType == 2)
{
var md = wllist.Find(n => n.PostInfo == model.PostInfo);
if (md == null)
md = wllist.Find(n => n.PostInfo == "0" && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.PostInfo == model.PostInfo && n.Country == "0");
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
else
if (PlatType >= 3 && PlatType <= 5)
{
var md = wllist.Find(n => n.ShopId == model.ShopId && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.Country == "0");
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
else
if (PlatType == 6)
{
var md = wllist.Find(n => n.PostInfo == model.PostInfo);
//var md = wllist.Find(n => n.ShopId == model.ShopId && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
//if (md == null)
//md = wllist.Find(n => n.ShopId == 0 && n.Country == "0");
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
if (model.ExpressId == 7 || model.ExpressId == 65 || model.ExpressId == 67) //修改分配级别
{
model.OrderLevel = 6;
}
}
if (item.OrderState == null)
model.OrderState = 1;
else
model.OrderState = item.OrderState;
model.ListModel = new List<API_OrderGoods>();
int HJNum = 0;
foreach (var item2 in item.ListModel)
{
API_OrderGoods check2 = null;
if (item2.MoneyCode == "") item2.MoneyCode = null;
API_OrderGoods model2 = new API_OrderGoods();
model2.productImgUrl = item2.productImgUrl;
model2.GoodsNum = item2.GoodsNum;
model2.GoodsPrice = item2.GoodsPrice;
model2.MoneyCode = item2.MoneyCode;
model2.GoodsName = item2.GoodsName;
model2.GoodsDesc = item2.TypeDesc;
model2.OrderItemId = item2.OrderItemId;
if (item2.GoodsSKU == null) item2.GoodsSKU = "";
model2.GoodsSKU = item2.GoodsSKU;
if (item2.GoodsSKU.Contains('{'))
{
// model2.GoodsSKU = item2.GoodsSKU.Substring(0, item2.GoodsSKU.IndexOf('{')).Trim();
string Num = item2.GoodsSKU.Substring(item2.GoodsSKU.IndexOf('{') + 1, item2.GoodsSKU.Length - item2.GoodsSKU.IndexOf('{') - 2);
model2.OldNum = item2.GoodsNum;
int GNum = 0;
if (int.TryParse(Num.Trim(), out GNum) == true)
model2.GoodsNum = GNum * model2.OldNum;
}
if (model.PlatType == 1)
{
string GoodsCode = item2.GoodsName.Trim().Replace(',', ' ');
if (model2.GoodsSKU.Contains('-'))
{
string[] skulist = model2.GoodsSKU.Split('-');
// model2.GoodsDesc += " " + model2.GoodsSKU;
// model2.GoodsSKU = skulist[1].Trim();
GoodsCode = skulist[0].Trim();
}
else
{
if (GoodsCode.Contains(' '))
{
GoodsCode = GoodsCode.Substring(GoodsCode.LastIndexOf(' ') + 1);
model2.GoodsCode = GoodsCode;
}
}
if (item2.TypeDesc != null && item2.TypeDesc != "")
model2.GoodsName += "[" + item2.TypeDesc + "]";
model2.GoodsCode = GoodsCode;
}
model2.PostInfo = item2.PostInfo;
if (model.PlatType == 1)
{
if (model2.GoodsCode != null && model2.GoodsCode != "")
check2 = model.ListModel.Find(o => o.GoodsSKU == model2.GoodsSKU && o.GoodsCode == model2.GoodsCode);
}
else
{
check2 = model.ListModel.Find(o => o.GoodsSKU == item2.GoodsSKU);
}
HJNum += item2.GoodsNum.Value;
if (check2 == null)
{
model.ListModel.Add(model2);
}
else
{
check2.GoodsNum = check2.GoodsNum + item2.GoodsNum;
}
}
try
{
model.GoodsNum = HJNum;
API_OrderInfoService.Save(CompanyId, model);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("保存各平台数据", "SaveOrderModel.Save", ex.Message + ";OrderCode:" + model.OrderCode);
return;
}
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("保存各平台数据", "SaveOrderModel.Save", ex.Message);
}
}
}
#endregion
#region 保存各平台数据
public static void SaveOrderModel2(int? CompanyId, int ShopId, string ShopName, int PlatType, int IsFba, List<OrderModel> ListModel)
{
if (ListModel == null) return;
var wllist = GetExpressSelect(PlatType);
foreach (var item in ListModel)
{
//if (item.PlatOrderCode == "72860947447064" || item.OrderCode == "72860947447064")
//{
// string asfsffs = "";
//}
try
{
int OrderState = 2;
//if (item.OrderState != null)
item.OrderState = 2;
if (PlatType == 1 && item.OutOrderDate != null)
{
if (API_OrderInfoService.CheckJoinOrderCode1(PlatType, item.OrderCode, OrderState, item.OutOrderDate.Value) == false)
continue;
}
else
if (API_OrderInfoService.CheckJoinOrderCode(PlatType, item.OrderCode, OrderState) == false) continue;
if (item.MoneyCode == "") item.MoneyCode = null;
API_OrderInfo model = new API_OrderInfo();
model.ShopId = ShopId;
model.ShopName = ShopName;
model.OrderCode = item.OrderCode;
model.PlatOrderCode = item.PlatOrderCode;
model.HBOrderCode = item.HBOrderCode;
model.TotalPrice = item.TotalPrice;
model.MoneyCode = item.MoneyCode;
model.OrderDate = item.OrderDate;
model.CustomID = item.BuyerID;
model.RevName = item.BuyerName;
model.RevCountry = item.BuyerCountry;
model.RevAddr = item.BuyerAddr;
model.RevPhone = item.BuyerPhone;
model.RevMobile = item.BuyerMobile;
model.RevMail = item.BuyerMail;
model.RevFax = item.BuyerFax;
model.RevZip = item.BuyerZip;
model.RevProvince = item.BuyerProvince;
model.RevCity = item.BuyerCity;
model.RevArea = item.BuyerArea;
model.BuyRemark = item.OrderRemark;
model.LeaveWord = item.LeaveWord;
model.PayDate = item.PayDate;
model.OutOrderDate = item.OutOrderDate;
model.PlatType = PlatType;
model.IsFba = IsFba;
model.escrowFee = item.escrowFee;
model.logisticsAmount = item.logisticsAmount;
model.PostInfo = item.PostInfo;
if (wllist != null)
{
if (PlatType == 1)
{
//if(model.OrderCode=="72568607625211")
//{
// string ddfsf = "";
//}
var md = wllist.Find(n => n.ShopId == model.ShopId && n.PostInfo == model.PostInfo && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == model.PostInfo && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == model.PostInfo && n.Country == "0");
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.PostInfo == "0" && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
else
if (PlatType == 2)
{
var md = wllist.Find(n => n.PostInfo == model.PostInfo);
if (md == null)
md = wllist.Find(n => n.PostInfo == "0" && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.PostInfo == model.PostInfo && n.Country == "0");
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
else
if (PlatType >= 3 && PlatType <= 5)
{
var md = wllist.Find(n => n.ShopId == model.ShopId && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && n.Country == "0");
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
else
if (PlatType == 6)
{
var md = wllist.Find(n => n.PostInfo == model.PostInfo);
//var md = wllist.Find(n => n.ShopId == model.ShopId && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
if (md == null)
md = wllist.Find(n => n.ShopId == 0 && (n.Country == model.RevCountry || n.EnglishName == model.RevCountry));
//if (md == null)
//md = wllist.Find(n => n.ShopId == 0 && n.Country == "0");
if (md != null)
{
model.LogisticsId = md.LogisticsId;
model.ExpressId = md.ExpressId;
}
}
if (model.ExpressId == 7 || model.ExpressId == 65 || model.ExpressId == 67) //修改分配级别
{
model.OrderLevel = 6;
}
}
if (item.OrderState == null)
model.OrderState = 1;
else
model.OrderState = item.OrderState;
model.ListModel = new List<API_OrderGoods>();
int HJNum = 0;
foreach (var item2 in item.ListModel)
{
API_OrderGoods check2 = null;
if (item2.MoneyCode == "") item2.MoneyCode = null;
API_OrderGoods model2 = new API_OrderGoods();
model2.productImgUrl = item2.productImgUrl;
model2.GoodsNum = item2.GoodsNum;
model2.GoodsPrice = item2.GoodsPrice;
model2.MoneyCode = item2.MoneyCode;
model2.GoodsName = item2.GoodsName;
model2.GoodsDesc = item2.TypeDesc;
model2.OrderItemId = item2.OrderItemId;
if (item2.GoodsSKU == null) item2.GoodsSKU = "";
model2.GoodsSKU = item2.GoodsSKU;
if (item2.GoodsSKU.Contains('{'))
{
//model2.GoodsSKU = item2.GoodsSKU.Substring(0, item2.GoodsSKU.IndexOf('{')).Trim();
string Num = item2.GoodsSKU.Substring(item2.GoodsSKU.IndexOf('{') + 1, item2.GoodsSKU.Length - item2.GoodsSKU.IndexOf('{') - 2);
model2.OldNum = item2.GoodsNum;
int GNum = 0;
if (int.TryParse(Num.Trim(), out GNum) == true)
model2.GoodsNum = GNum * model2.OldNum;
}
if (model.PlatType == 1)
{
string GoodsCode = item2.GoodsName.Trim().Replace(',', ' ');
if (model2.GoodsSKU.Contains('-'))
{
string[] skulist = model2.GoodsSKU.Split('-');
// model2.GoodsDesc += " " + model2.GoodsSKU;
//model2.GoodsSKU = skulist[1].Trim();
GoodsCode = skulist[0].Trim();
}
else
{
if (GoodsCode.Contains(' '))
{
GoodsCode = GoodsCode.Substring(GoodsCode.LastIndexOf(' ') + 1);
model2.GoodsCode = GoodsCode;
}
}
if (item2.TypeDesc != null && item2.TypeDesc != "")
model2.GoodsName += "[" + item2.TypeDesc + "]";
model2.GoodsCode = GoodsCode;
}
model2.PostInfo = item2.PostInfo;
if (model.PlatType == 1)
{
if (model2.GoodsCode != null && model2.GoodsCode != "")
check2 = model.ListModel.Find(o => o.GoodsSKU == model2.GoodsSKU && o.GoodsCode == model2.GoodsCode);
}
else
{
check2 = model.ListModel.Find(o => o.GoodsSKU == item2.GoodsSKU);
}
HJNum += item2.GoodsNum.Value;
if (check2 == null)
{
model.ListModel.Add(model2);
}
else
{
check2.GoodsNum = check2.GoodsNum + item2.GoodsNum;
}
}
try
{
model.GoodsNum = HJNum;
API_OrderInfoService.Save(CompanyId, model);
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("保存各平台数据", "SaveOrderModel.Save", ex.Message + ";OrderCode:" + model.OrderCode);
return;
}
}
catch (Exception ex)
{
ErrorFollow.TraceWrite("保存各平台数据", "SaveOrderModel.Save", ex.Message);
}
}
}
#endregion
//#region 速卖通数据导入
//public static string ImportAlibab(DateTime? StartDate, DateTime? StopDate, List<int> ListModel)
//{
// AlibabaApi obj = new AlibabaApi();
// string error = "";
// string mess = "";
// foreach (int ShopId in ListModel)
// {
// JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
// obj.ShopId = ShopId;
// obj.Appkey = ShopModel.Appkey;
// obj.DeveKey = ShopModel.DeveKey;
// obj.RefreshToken = ShopModel.RefreshToken;
// obj.AccessToken = ShopModel.AccessToken;
// obj.GroupName = ShopModel.ShopName;
// obj.RefreshTokenSaveTime = ShopModel.RefreshTokenSaveTime;
// obj.AccessTokenUpdateTime = ShopModel.AccessTokenUpdateTime;
// var olist = GetOrderCodeList(2000, ShopId);
// List<OrderModel> ListOrderModel = obj.GetWaitGoods(StartDate, StopDate, true,olist, out error);
// //List<OrderModel> ListOrderModel = obj.GetPayMoneyGoods(true, out error);
// if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
// if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
// mess += "导入待发货订单:" + ListOrderModel.Count.ToString() + "条;";
// SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 1, 0, ListOrderModel);
// List<OrderModel> ListOrderModel1 = obj.GetPayMoneyGoods(true, out error);
// //List<OrderModel> ListOrderModel = obj.GetPayMoneyGoods(true, out error);
// if (ListOrderModel1 == null) ListOrderModel1 = new List<OrderModel>();
// if (string.IsNullOrEmpty(error) == false) return mess + "导入已支付未到账订单订单失败:" + error;
// mess += "导入已支付未到账订单:" + ListOrderModel1.Count.ToString() + "条";
// SaveOrderModel2(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 1, 0, ListOrderModel1);
// }
// return mess;
//}
//#endregion
public static string ImportAlibab(DateTime? StartDate, DateTime? StopDate, List<int> ListModel)
{
string errorMessage = "";
string str2 = "";
foreach (int num in ListModel)
{
List<Alibaba_OrderCode> orderCodeList;
List<OrderModel> list2;
JC_Shop model = JC_ShopService.GetModel(num);
if ((model.Code != null) && (model.Code != ""))
{
AlibabaApiQM iqm = new AlibabaApiQM
{
ShopId = new int?(num)
};
if ((model.Code != null) && (model.Code != ""))
{
iqm.sessionKey = model.Code;
orderCodeList = GetOrderCodeList(0x1f40, num);
list2 = iqm.GetWaitGoods("WAIT_SELLER_SEND_GOODS", 1, StartDate, StopDate, true, orderCodeList, out errorMessage);
if (!string.IsNullOrEmpty(errorMessage))
{
return ("导入订单失败:" + errorMessage);
}
if (list2 == null)
{
str2 = str2 + "导入待发货订单0条;";
}
else
{
str2 = str2 + "导入待发货订单:" + list2.Count.ToString() + "条;";
SaveOrderModel(model.CompanyId, num, model.ShopName, 1, 0, list2);
}
}
}
else
{
AlibabaApi api = new AlibabaApi
{
ShopId = num,
Appkey = model.Appkey,
DeveKey = model.DeveKey,
RefreshToken = model.RefreshToken,
AccessToken = model.AccessToken,
GroupName = model.ShopName,
RefreshTokenSaveTime = model.RefreshTokenSaveTime,
AccessTokenUpdateTime = model.AccessTokenUpdateTime
};
orderCodeList = GetOrderCodeList(0x7d0, num);
list2 = api.GetWaitGoods(StartDate, StopDate, true, orderCodeList, out errorMessage);
if (list2 == null)
{
list2 = new List<OrderModel>();
}
if (!string.IsNullOrEmpty(errorMessage))
{
return ("导入订单失败:" + errorMessage);
}
str2 = str2 + "导入待发货订单:" + list2.Count.ToString() + "条;";
SaveOrderModel(model.CompanyId, num, model.ShopName, 1, 0, list2);
}
}
return str2;
}
#region 亚马逊数据导入
public static string ImportAmazon(DateTime? StartDate, DateTime? StopDate, List<int> ListModel)
{
AmazonApi obj = new AmazonApi();
ApiNew.Amazonapinew obj2 = new ApiNew.Amazonapinew();
string error = "";
string mess = "";
foreach (int ShopId in ListModel)
{
JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
if (ShopModel.Code != null && ShopModel.Code != "")
{
obj2.accessKeyId = ShopModel.RefreshToken;
obj2.secretAccessKey = ShopModel.AccessToken;
obj2.merchantId = ShopModel.Appkey;
obj2.marketplaceId = ShopModel.DeveKey;
obj2.country = ShopModel.Country;
obj2.MWSAuthToken = ShopModel.Code;
List<OrderModel> ListOrderModel = obj2.GetOrders(StartDate, StopDate, ShopModel.ShopName,null,out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 2, 0, ListOrderModel);
mess = "导入普通订单:" + ListOrderModel.Count.ToString() + "条;";
if (ShopModel.IsFba == true)
{
System.Threading.Thread.Sleep(60000);//暂停60秒
List<OrderModel> ListOrderModel2 = obj2.GetFBAOrders(StartDate, StopDate, ShopModel.ShopName, out error);
if (ListOrderModel2 == null) ListOrderModel2 = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return mess + "导入海外仓订单订单失败:" + error;
mess += "导入海外仓订单:" + ListOrderModel2.Count.ToString() + "条;";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 2, 1, ListOrderModel2);
}
}
else
{
obj.accessKeyId = ShopModel.RefreshToken;
obj.secretAccessKey = ShopModel.AccessToken;
obj.merchantId = ShopModel.Appkey;
obj.marketplaceId = ShopModel.DeveKey;
obj.country = ShopModel.Country;
List<OrderModel> ListOrderModel = obj.GetOrders(StartDate, StopDate, ShopModel.ShopName, out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 2, 0, ListOrderModel);
mess = "导入普通订单:" + ListOrderModel.Count.ToString() + "条;";
if (ShopModel.IsFba == true)
{
System.Threading.Thread.Sleep(60000);//暂停60秒
List<OrderModel> ListOrderModel2 = obj.GetFBAOrders(StartDate, StopDate, ShopModel.ShopName, DateTime.Today, out error);
if (ListOrderModel2 == null) ListOrderModel2 = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return mess + "导入海外仓订单订单失败:" + error;
mess += "导入海外仓订单:" + ListOrderModel2.Count.ToString() + "条;";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 2, 1, ListOrderModel2);
}
}
}
return mess;
}
#endregion
#region Ebay数据导入
public static string ImportEbay(DateTime? StartDate, DateTime? StopDate, List<int> ListModel)
{
EbayApi obj = new EbayApi();
string error = "";
foreach (int ShopId in ListModel)
{
JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
obj.Appkey = ShopModel.Appkey;
obj.DeveKey = ShopModel.DeveKey;
obj.CertKey = ShopModel.RefreshToken;
List<OrderModel> ListOrderModel = obj.GetOrders(StartDate, StopDate, ShopModel.AccessToken, out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
error = "导入订单:" + ListOrderModel.Count.ToString() + "条";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 3, 0, ListOrderModel);
}
return error;
}
#endregion
#region Ebay数据导入
public static string ImportEbayForTM(DateTime? StartDate, DateTime? StopDate, List<int> ListModel)
{
EbayApi obj = new EbayApi();
string error = "";
foreach (int ShopId in ListModel)
{
JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
obj.Appkey = ShopModel.Appkey;
obj.DeveKey = ShopModel.DeveKey;
obj.CertKey = ShopModel.RefreshToken;
obj.ShopNo = ShopModel.ShopNo;
List<OrderModel> ListOrderModel = obj.GetOrdersForTM(StartDate, StopDate, ShopModel.AccessToken, out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
error += "导入订单:" + ListOrderModel.Count.ToString() + "条";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 3, 0, ListOrderModel);
}
return error;
}
#endregion
#region Wish数据导入
public static string ImportWish(List<int> ListModel)
{
WishApi obj = new WishApi();
string error = "";
foreach (int ShopId in ListModel)
{
JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
List<OrderModel> ListOrderModel = obj.GetOrders(ShopModel.AccessToken, out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:"+error;
error += "导入订单:" + ListOrderModel.Count.ToString() + "条";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 4, 0, ListOrderModel);
}
return error;
}
public static string ImportWish2(List<int> ListModel)
{
WishApi obj = new WishApi();
string error = "";
foreach (int ShopId in ListModel)
{
JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
obj.ShopId = ShopModel.ShopId.Value;
obj.client_id = ShopModel.Appkey;
obj.client_secret = ShopModel.DeveKey;
obj.AccessToken = ShopModel.AccessToken;
obj.RefreshToken = ShopModel.RefreshToken;
obj.AccessTokenUpdateTime = ShopModel.AccessTokenUpdateTime;
obj.RefreshTokenSaveTime = ShopModel.RefreshTokenSaveTime;
obj.code = ShopModel.Code;
List<OrderModel> ListOrderModel = obj.GetOrdersNew(out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
error += "导入订单:" + ListOrderModel.Count.ToString() + "条";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 4, 0, ListOrderModel);
}
return error;
}
#endregion
#region Lazada数据导入
public static string ImportLazada(List<int> ListModel)
{
LazadaApi obj = new LazadaApi();
string error = "";
foreach (int ShopId in ListModel)
{
JC_Shop ShopModel = JC_ShopService.GetModel(ShopId);
List<OrderModel> ListOrderModel = obj.GetOrders(ShopModel.Country, ShopModel.Appkey, ShopModel.AccessToken, DateTime.Now.AddDays(-10), out error);
if (ListOrderModel == null) ListOrderModel = new List<OrderModel>();
if (string.IsNullOrEmpty(error) == false) return "导入订单失败:" + error;
error += "导入订单:" + ListOrderModel.Count.ToString() + "条";
SaveOrderModel(ShopModel.CompanyId, ShopId, ShopModel.ShopName, 5, 0, ListOrderModel);
}
return error;
}
#endregion
#region CD数据导入
public void ImportCD(List<OrderModel> ListModel, string ShopName, int ShopId)
{
SaveOrderModel(1, ShopId, ShopName, 6, 0, ListModel);
}
#endregion
#region 保存留言
public int SaveLeaveword(DT_Leaveword Model)
{
string tsql = @"
select @Id=Id from DT_Leaveword where wId=@wId
if @Id>0
begin
if @isRead=1
begin
Update [DT_Leaveword] set [isRead]=@isRead where Id=@Id
end
end
else
begin
INSERT INTO [DT_Leaveword]([wordContent],[orderId],[isRead],[senderName],[senderLoginId],[receiverLoginId],[fileUrl],[wordCreate],[wordCreateCN],[wId],[typeId],[indate])values(@wordContent,@orderId,@isRead,@senderName,@senderLoginId,@receiverLoginId,@fileUrl,@wordCreate,@wordCreateCN,@wId,@typeId,@indate)
set @Id=SCOPE_IDENTITY()
end
select @Id";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id);
db.AddInParameter(cmd, "@wordContent", DbType.String, Model.wordContent);
db.AddInParameter(cmd, "@orderId", DbType.String, Model.orderId);
db.AddInParameter(cmd, "@isRead", DbType.Boolean, Model.isRead);
db.AddInParameter(cmd, "@senderName", DbType.String, Model.senderName);
db.AddInParameter(cmd, "@senderLoginId", DbType.String, Model.senderLoginId);
db.AddInParameter(cmd, "@receiverLoginId", DbType.String, Model.receiverLoginId);
db.AddInParameter(cmd, "@fileUrl", DbType.String, Model.fileUrl);
db.AddInParameter(cmd, "@wordCreate", DbType.DateTime, Model.wordCreate);
db.AddInParameter(cmd, "@wordCreateCN", DbType.DateTime, Model.wordCreateCN);
db.AddInParameter(cmd, "@wId", DbType.Int64, Model.wId);
db.AddInParameter(cmd, "@typeId", DbType.String, Model.typeId);
db.AddInParameter(cmd, "@indate", DbType.DateTime, Model.indate);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
return a;
}
#endregion
#region 保存站内信
public int SaveInnerMail(DT_InnerMail Model)
{
string tsql = @"
select @Id=Id from DT_InnerMail where wId=@wId
if @Id>0
begin
if @isRead=1
begin
Update [DT_InnerMail] set [isRead]=@isRead where Id=@Id
end
end
else
begin
INSERT INTO [DT_InnerMail]([wordContent],[orderId],[isRead],[senderName],[senderLoginId],[receiverLoginId],[fileUrl],[wordCreate],[wId],[typeId])values(@wordContent,@orderId,@isRead,@senderName,@senderLoginId,@receiverLoginId,@fileUrl,@wordCreate,@wId,@typeId)
set @Id=SCOPE_IDENTITY()
end
select @Id";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id);
db.AddInParameter(cmd, "@wordContent", DbType.String, Model.wordContent);
db.AddInParameter(cmd, "@orderId", DbType.String, Model.orderId);
db.AddInParameter(cmd, "@isRead", DbType.Boolean, Model.isRead);
db.AddInParameter(cmd, "@senderName", DbType.String, Model.senderName);
db.AddInParameter(cmd, "@senderLoginId", DbType.String, Model.senderLoginId);
db.AddInParameter(cmd, "@receiverLoginId", DbType.String, Model.receiverLoginId);
db.AddInParameter(cmd, "@fileUrl", DbType.String, Model.fileUrl);
db.AddInParameter(cmd, "@wordCreate", DbType.DateTime, Model.wordCreate);
db.AddInParameter(cmd, "@wId", DbType.Int32, Model.wId);
db.AddInParameter(cmd, "@typeId", DbType.String, Model.typeId);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
return a;
}
#endregion
#region 保存订单放款
public int SaveOrderLoan(DT_OrderLoan Model)
{
string tsql = @"
--select top 1 @Id=Id from DT_OrderLoan where orderId=@orderId
if @Id>0
begin
Update [DT_OrderLoan] set [amountTotal]=@amountTotal,affiliateCommission=@affiliateCommission,[currencyCode]=@currencyCode,[loanStatus]=@loanStatus,[realLoanAmount]=@realLoanAmount,[escrowFee]=@escrowFee where Id=@Id
end
else
begin
INSERT INTO [DT_OrderLoan]([amountTotal],[orderId],[currencyCode],[loanStatus],[realLoanAmount],[escrowFee],[waitLoanReson],[affiliateCommission],[realLoanMoneyCode],[escrowFeeMoneyCode],[affiliateMoneyCode],[CompanyId],[ShopId])values(@amountTotal,@orderId,@currencyCode,@loanStatus,@realLoanAmount,@escrowFee,@waitLoanReson,@affiliateCommission,@realLoanMoneyCode,@escrowFeeMoneyCode,@affiliateMoneyCode,@CompanyId,@ShopId)
set @Id=SCOPE_IDENTITY()
end
select @Id";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id);
db.AddInParameter(cmd, "@amountTotal", DbType.Decimal, Model.amountTotal);
db.AddInParameter(cmd, "@orderId", DbType.String, Model.orderId);
db.AddInParameter(cmd, "@currencyCode", DbType.String, Model.currencyCode);
db.AddInParameter(cmd, "@loanStatus", DbType.String, Model.loanStatus);
db.AddInParameter(cmd, "@realLoanAmount", DbType.Decimal, Model.realLoanAmount);
db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, Model.escrowFee);
db.AddInParameter(cmd, "@waitLoanReson", DbType.String, Model.waitLoanReson);
db.AddInParameter(cmd, "@affiliateCommission", DbType.Decimal, Model.affiliateCommission);
db.AddInParameter(cmd, "@realLoanMoneyCode", DbType.String, Model.realLoanMoneyCode);
db.AddInParameter(cmd, "@escrowFeeMoneyCode", DbType.String, Model.escrowFeeMoneyCode);
db.AddInParameter(cmd, "@affiliateMoneyCode", DbType.String, Model.affiliateMoneyCode);
db.AddInParameter(cmd, "@CompanyId", DbType.Int32, Model.CompanyId);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, Model.ShopId);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
return a;
}
#endregion
#region 保存订单放款明细
public int SaveOrderLoanDetail(DT_OrderLoanDetail Model)
{
string tsql = @"
if @Id>0
begin
Update [DT_OrderLoanDetail] set [LoanId]=@LoanId,[loanStatus]=@loanStatus,[realLoanAmount]=@realLoanAmount,[escrowFee]=@escrowFee,[waitLoanReson]=@waitLoanReson,[affiliateCommission]=@affiliateCommission,[childOrderId]=@childOrderId where Id=@Id
end
else
begin
INSERT INTO [DT_OrderLoanDetail]([LoanId],[loanStatus],[realLoanAmount],[escrowFee],[waitLoanReson],[affiliateCommission],[childOrderId])values(@LoanId,@loanStatus,@realLoanAmount,@escrowFee,@waitLoanReson,@affiliateCommission,@childOrderId)
set @Id=SCOPE_IDENTITY()
end
select @Id";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@Id", DbType.Int32, Model.Id);
db.AddInParameter(cmd, "@LoanId", DbType.Int32, Model.LoanId);
db.AddInParameter(cmd, "@loanStatus", DbType.String, Model.loanStatus);
db.AddInParameter(cmd, "@realLoanAmount", DbType.Decimal, Model.realLoanAmount);
db.AddInParameter(cmd, "@escrowFee", DbType.Decimal, Model.escrowFee);
db.AddInParameter(cmd, "@waitLoanReson", DbType.String, Model.waitLoanReson);
db.AddInParameter(cmd, "@affiliateCommission", DbType.Decimal, Model.affiliateCommission);
db.AddInParameter(cmd, "@childOrderId", DbType.String, Model.childOrderId);
int a = Convert.ToInt32(db.ExecuteScalar(cmd));
return a;
}
#endregion
#region 保存
public void SaveOneWord(ShippingMethods Model)
{
string tsql = @"
INSERT INTO [OneWord](Code,[Name],[IsTracking],[MaxWeightInKg],[Region])values(@Code,@Name,@IsTracking,@MaxWeightInKg,@Region)
";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@Code", DbType.String, Model.Code);
db.AddInParameter(cmd, "@Name", DbType.String, Model.Name);
db.AddInParameter(cmd, "@IsTracking", DbType.Boolean, Model.IsTracking);
db.AddInParameter(cmd, "@MaxWeightInKg", DbType.Decimal, Model.MaxWeightInKg);
db.AddInParameter(cmd, "@Region", DbType.String, Model.Region);
db.ExecuteNonQuery(cmd);
}
#endregion
#region 保存纠纷
public void SaveIssue(IssueList Model)
{
string tsql = @"DECLARE @IssueID INT
select @IssueID=IssueID from API_OrderIssue where id=@id
if @IssueID>0
begin
Update [API_OrderIssue] set [gmtModified]=@gmtModified,[issueStatus]=@issueStatus where id=@id
end
else
begin
INSERT INTO [API_OrderIssue]([id],[gmtCreate],[gmtModified],[orderId],[issueStatus],[reasonChinese],[reasonEnglish])values(@id,@gmtCreate,@gmtModified,@orderId,@issueStatus,@reasonChinese,@reasonEnglish)
end
select @IssueID";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@id", DbType.String, Model.id.ToString());
db.AddInParameter(cmd, "@gmtCreate", DbType.DateTime, Model.gmtCreate);
db.AddInParameter(cmd, "@gmtModified", DbType.DateTime, Model.gmtModified);
db.AddInParameter(cmd, "@orderId", DbType.String, Model.orderId.ToString());
db.AddInParameter(cmd, "@issueStatus", DbType.String, Model.issueStatus);
db.AddInParameter(cmd, "@reasonChinese", DbType.String, Model.reasonChinese);
db.AddInParameter(cmd, "@reasonEnglish", DbType.String, Model.reasonEnglish);
db.ExecuteScalar(cmd);
//string a = Convert.ToInt32(db.ExecuteScalar(cmd)).ToString();
//return a;
}
#endregion
#region 查询已导入订单
public static List<Alibaba_OrderCode> GetOrderCodeList(int TopNum,int ShopId)
{
List<Alibaba_OrderCode> list = null;
string tsql = @"
select top " + TopNum + @" OrderCode from API_OrderInfo where ShopId=@ShopId order by OrderDate desc
";
Database db = DatabaseFactory.CreateDatabase();
DbCommand cmd = db.GetSqlStringCommand(tsql);
db.AddInParameter(cmd, "@ShopId", DbType.Int32, ShopId);
DataSet ds = db.ExecuteDataSet(cmd);
list = ds.Tables[0].ToList<Alibaba_OrderCode>();
return list;
}
#endregion
public static List<DT_OrderModel> GetFedexOrderList(DateTime? SDate)
{
string query = " select top 30 b.* from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where b.CountryCode='US' and a.InDate>=@SDate and a.FeeLog is null order by a.InDate";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
database.AddInParameter(sqlStringCommand, "@SDate", DbType.DateTime, SDate);
return database.ExecuteDataTable(sqlStringCommand).ToList<DT_OrderModel>();
}
public static List<DT_OrderModel> GetFedexOrderListBak(DateTime? SDate)
{
string query = " select b.* from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where b.CountryCode='US' and a.InDate>=@SDate and b.RevProvinceCode in ('MI','OH','PA','NY','KY','VA') and a.FeeLog is null order by a.InDate";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
database.AddInParameter(sqlStringCommand, "@SDate", DbType.DateTime, SDate);
return database.ExecuteDataTable(sqlStringCommand).ToList<DT_OrderModel>();
}
public static List<DT_OrderModel> GetFedexOrderList2(string OrderIds)
{
string query = " select b.* from DT_OrderInfo a with(nolock) inner join DT_OrderXXInfo b with(nolock) on a.OrderId=b.OrderId where a.OrderId in (" + OrderIds + ")";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
return database.ExecuteDataTable(sqlStringCommand).ToList<DT_OrderModel>();
}
public static List<DT_OrderMateGoods> GetFedexOrderGoodsList(string OrderIds)
{
string query = " select a.Id,a.OrderId,a.GoodsNum,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,InPrice=isnull(c.InPrice,0) from DT_OrderGoods a with(nolock) inner join HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join HW_GoodsInfo c on b.GoodsId=c.GoodsId where OrderId in (" + OrderIds + ")";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList<DT_OrderMateGoods>();
}
public static List<DT_OrderMateGoods> GetFedexOrderGoodsListbak(string OrderIds)
{
string query = " select a.Id,a.OrderId,a.GoodsNum,Weight=case when c.Weight2 is not null and c.Weight2>0 then c.Weight2 when c.Weight is not null and c.Weight>0 then c.Weight*0.035274 else null end,c.Width2,Length2=c.Long2,c.Height2,InPrice=isnull(c.InPrice,0) from newerp.dbo.DT_OrderGoods a with(nolock) inner join newerp.dbo.HW_GoodsDetail b with(nolock) on a.DetailId=b.DetailId inner join newerp.dbo.HW_GoodsInfo c on b.GoodsId=c.GoodsId where OrderId in (" + OrderIds + ")";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList<DT_OrderMateGoods>();
}
public static void UpdateFee(int OrderId, string FeeHtml)
{
try
{
string query = " Update [DT_OrderInfo] set FeeLog=@FeeHtml where OrderId=@OrderId ";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
database.AddInParameter(sqlStringCommand, "@OrderId", DbType.Int32, OrderId);
database.AddInParameter(sqlStringCommand, "@FeeHtml", DbType.String, FeeHtml);
database.ExecuteNonQuery(sqlStringCommand);
}
catch (Exception exception)
{
ErrorFollow.TraceWrite("UpdateFee", "", exception.Message);
}
}
public static List<DT_OrderSyncPMModel> GetApiOrderSyncGoodList(string orderids)
{
string query = " select a.OrderId,b.productImgUrl ASIN,b.GoodsSKU GoodSKU, a.ShopId,c.Appkey,c.DeveKey,c.RefreshToken ,c.Country from API_OrderInfo a inner join API_OrderGoods b on a.OrderId=b.OrderId inner join JC_Shop c on a.ShopId = c.ShopId where c.PlatType = 2 and a.State = 0 and a.OrderId in (" + orderids + ") ";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
return database.ExecuteDataSet(sqlStringCommand).Tables[0].ToList<DT_OrderSyncPMModel>();
}
public static int GetGoodsIdByApiOrderGoodSKU(string sku)
{
string query = " select top 1 GoodsId from HW_GoodsDetail where SKU1=@sku or SKU2=@sku or SKU3=@sku or SKU4=@sku or SKU5=@sku or SKU6=@sku or SKU7=@sku or SKU8=@sku or SKU9=@sku or SKU10=@sku or SKU11=@sku or SKU12=@sku or SKU13=@sku or SKU14=@sku or SKU15=@sku ";
Database database = DatabaseFactory.CreateDatabase();
DbCommand sqlStringCommand = database.GetSqlStringCommand(query);
database.AddInParameter(sqlStringCommand, "@sku", DbType.String, sku);
var obj = database.ExecuteScalar(sqlStringCommand);
if(obj!=null)
return Convert.ToInt32(obj);
else
return 0;
}
}
}