using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Serialization;
using NetLibrary.Log;
using System.IO;
using TradeModel;
using NetLibrary;
using static TradeManageNew.OuterService.ShageService;
namespace TradeManageNew
{
///
/// OrderAPI 的摘要说明
///
public class OrderAPI : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string UserCode = context.Request.QueryString["UserCode"];
string Method = context.Request.QueryString["Method"];
string Ver = context.Request.QueryString["Ver"];
JavaScriptSerializer jsonconvert = new JavaScriptSerializer();
SyncDataModel md = new SyncDataModel();
md.Result = "";
string content2 = "";
try
{
StreamReader sr = new StreamReader(context.Request.InputStream);
string ResponseContent = sr.ReadToEnd();
ErrorFollow.TraceWrite("协议", "", ResponseContent);
if (string.IsNullOrEmpty(UserCode) == true || string.IsNullOrEmpty(Method) == true || string.IsNullOrEmpty(Ver) == true)
{
md.Code = "101";
md.Result = "缺少参数或者参数不正确,请确保有如下UserCode,Method,Ver参数";
content2 = jsonconvert.Serialize(md);
context.Response.Write(content2);
return;
}
int CompanyId = DataNew.IsCompany(UserCode);
if (CompanyId == 0)
{
md.Code = "101";
md.Result = "UserCode授权码不正确";
content2 = jsonconvert.Serialize(md);
context.Response.Write(content2);
return;
}
if (Ver == "1.0")
{
if (string.IsNullOrEmpty(ResponseContent) == true)
{
md.Code = "104";
md.Result = "提交数据不能为空";
content2 = jsonconvert.Serialize(md);
context.Response.Write(content2);
return;
}
if (Method == "OrderAdd")
{
OrderInfo_Model model = jsonconvert.Deserialize(ResponseContent);
if (model == null)
{
md.Code = "400";
md.Result = "提交json数据格式不正确";
content2 = jsonconvert.Serialize(md);
context.Response.Write(content2);
return;
}
string error = "";
if (model.OrderCode == null||model.OrderCode == "")
{
error += "订单号没有";
}
if (model.RevAddr == null || model.RevAddr == "")
{
error += "收件地址没有";
}
if (model.RevCountry == null || model.RevCountry == "")
{
error += "国家没有";
}
if (model.RevCity == null || model.RevCity == "")
{
error += "城市没有";
}
if (model.RevProvince == null || model.RevProvince == "")
{
error += "州、省没有";
}
if (model.RevPostCode == null || model.RevPostCode == "")
{
error += "邮编没有";
}
if (model.warehouse_code == null || model.warehouse_code == "")
{
error += "仓库编号没有";
}
if ((model.RevMoblie == null || model.RevMoblie == "")&& (model.RevPhone == null || model.RevPhone == ""))
{
error += "手机和电话必须有一个";
}
if (model.GoodsList==null|| model.GoodsList.Count==0)
{
error += "订单商品信息没有";
}
if (model.GoodsList != null)
{
foreach (var gmd in model.GoodsList)
{
if(gmd.SKU==null||gmd.SKU=="")
error += "订单商品信息sku没有";
if (gmd.GoodsENName == null || gmd.GoodsENName == "")
error += "订单商品信息英文名称没有";
if (gmd.Weight == null)
error += "订单商品信息重量(g)没有";
if (gmd.Long == null)
error += "订单商品信息长(in)没有";
if (gmd.Width == null)
error += "订单商品信息宽(in)没有";
if (gmd.Height == null)
error += "订单商品信息高(in)没有";
}
}
if (error !="")
{
md.Code = "400";
md.Result = error;
content2 = jsonconvert.Serialize(md);
context.Response.Write(content2);
return;
}
DT_OrderInfo_HWC OrderModel = new DT_OrderInfo_HWC();
OrderModel.OrderCode = model.OrderCode;
OrderModel.PlatOrderCode = model.OrderCode;
OrderModel.OrderDate = DateTime.Now;
OrderModel.PlatId = 0;
OrderModel.ShopId = 0;
OrderModel.RevName = model.RevName;
OrderModel.RevAddr = model.RevAddr;
OrderModel.RevArea = model.RevArea;
OrderModel.RevCity = model.RevCity;
OrderModel.RevCountry = model.RevCountry;
OrderModel.RevProvince = model.RevProvince;
OrderModel.RevMoblie = model.RevMoblie;
OrderModel.RevPhone = model.RevPhone;
OrderModel.RevPostCode = model.RevPostCode;
if (model.TotalPrice != null)
OrderModel.TotalPrice = model.TotalPrice;
else
OrderModel.TotalPrice = 0;
OrderModel.MoneyCode = "USD";
if(model.verify!=null)
OrderModel.PostState = model.verify;
else
OrderModel.PostState =0;
OrderModel.StoreCode= model.warehouse_code;
OrderModel.CompanyId = CompanyId;
List dlist = new List();
int gnum = 0;
foreach (var gmd in model.GoodsList)
{
Order_GoodsInfoModel_HWC dmd = new Order_GoodsInfoModel_HWC();
dmd.SKU = gmd.SKU;
dmd.GoodsName = gmd.GoodsName;
dmd.GoodsENName = gmd.GoodsENName;
dmd.Weight = gmd.Weight;
dmd.Long = gmd.Long;
dmd.Width = gmd.Width;
dmd.Height = gmd.Height;
dmd.GoodsNum = gmd.GoodsNum;
dmd.CompanyId = CompanyId;
gnum += gmd.GoodsNum;
dlist.Add(dmd);
}
OrderModel.GoodsNum = gnum;
OrderModel.GoodsList = dlist;
DataNew.OrderAdd_HWC(OrderModel);
md.Code = "100";
md.Result = "Success";
md.Data ="";
}
if (Method == "OrderCancel")
{
List olist = jsonconvert.Deserialize>(ResponseContent);
if (olist == null)
{
md.Code = "400";
md.Result = "提交json数据格式不正确";
content2 = jsonconvert.Serialize(md);
context.Response.Write(content2);
return;
}
string error = "";
foreach (var omd in olist)
{
int a=DataNew.CancelOrder(omd.OrderCode, CompanyId);
if (a == -1)
error += omd.OrderCode+"订单号不存在";
else if (a == 0)
error += omd.OrderCode+"订单已经打印面单不能取消,请联系仓库";
}
if (error != "")
{
md.Code = "100";
md.Result = error;
md.Data = "";
return;
}
md.Code = "100";
md.Result = "Success";
md.Data = "";
}
else
{
//获取用户数据
// var ListUserInfo = BaseService.GetListSyncUserInfo(model.CompanyID);
md.Code = "400";
md.Result = "方法不存在";
md.Data = null;
}
}
}
catch (Exception ex)
{
md.Code = "104";
md.Result = ex.Message;
}
content2 = jsonconvert.Serialize(md);
ErrorFollow.TraceWrite("返回值", "", content2);
context.Response.Write(content2);
}
public bool IsReusable
{
get
{
return false;
}
}
public class OrderInfo_Cancel
{
///
/// 订单号 必传
///
public string OrderCode { get; set; }
}
public class OrderInfo_Model
{
///
/// 订单号 必传
///
public string OrderCode { get; set; }
///
/// 物流方式
///
public string PostInfo { get; set; }
///
/// 收件地址 必传
///
public string RevAddr { get; set; }
///
/// 收件人 必传
///
public string RevName { get; set; }
///
/// 城市 必传
///
public string RevCity { get; set; }
///
/// 区域
///
public string RevArea { get; set; }
///
/// 省 必传
///
public string RevProvince { get; set; }
///
/// 手机 或者电话 一个 必传
///
public string RevPhone { get; set; }
///
/// 电话
///
public string RevMoblie { get; set; }
///
/// 邮编 必传
///
public string RevPostCode { get; set; }
///
/// 国家编号 二字码 必传
///
public string RevCountry { get; set; }
///
/// 是否允许直接发货 0 允许发货 1 需要确认后 再发货 必传
///
public Int32? verify { get; set; }
///
/// 仓库 编号 西部CA仓 传 CA 东部FL仓 传 FL 必传
///
public string warehouse_code { get; set; }
///
/// 订单金额 美金
///
public decimal? TotalPrice { get; set; }
public List GoodsList { get; set; }
}
public class Order_GoodsInfoModel
{
///
/// 货物名称 报关 名
///
public string GoodsName { get; set; }
///
/// 货物英文报关 名 必传
///
public string GoodsENName { get; set; }
///
/// 货物数量 必传
///
public int GoodsNum { get; set; }
///
/// sku 必传
///
public string SKU { get; set; }
///
/// 单个重量 单位 克 g 必传
///
public decimal? Weight { get; set; }
///
/// 单个产品尺寸 长度 单位 英寸 in 必传
///
public decimal? Long { get; set; }
///
/// 单个产品尺寸 宽度 单位 英寸 in 必传
///
public decimal? Width { get; set; }
///
/// 单个产品尺寸 高度 单位 英寸 in 必传
///
public decimal? Height { get; set; }
}
}
}