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.

388 lines
15 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.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
{
/// <summary>
/// OrderAPI 的摘要说明
/// </summary>
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<OrderInfo_Model>(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<Order_GoodsInfoModel_HWC> dlist = new List<Order_GoodsInfoModel_HWC>();
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<OrderInfo_Cancel> olist = jsonconvert.Deserialize<List<OrderInfo_Cancel>>(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
{
/// <summary>
/// 订单号 必传
/// </summary>
public string OrderCode { get; set; }
}
public class OrderInfo_Model
{
/// <summary>
/// 订单号 必传
/// </summary>
public string OrderCode { get; set; }
/// <summary>
/// 物流方式
/// </summary>
public string PostInfo { get; set; }
/// <summary>
/// 收件地址 必传
/// </summary>
public string RevAddr { get; set; }
/// <summary>
/// 收件人 必传
/// </summary>
public string RevName { get; set; }
/// <summary>
/// 城市 必传
/// </summary>
public string RevCity { get; set; }
/// <summary>
/// 区域
/// </summary>
public string RevArea { get; set; }
/// <summary>
/// 省 必传
/// </summary>
public string RevProvince { get; set; }
/// <summary>
/// 手机 或者电话 一个 必传
/// </summary>
public string RevPhone { get; set; }
/// <summary>
/// 电话
/// </summary>
public string RevMoblie { get; set; }
/// <summary>
/// 邮编 必传
/// </summary>
public string RevPostCode { get; set; }
/// <summary>
/// 国家编号 二字码 必传
/// </summary>
public string RevCountry { get; set; }
/// <summary>
/// 是否允许直接发货 0 允许发货 1 需要确认后 再发货 必传
/// </summary>
public Int32? verify { get; set; }
/// <summary>
/// 仓库 编号 西部CA仓 传 CA 东部FL仓 传 FL 必传
/// </summary>
public string warehouse_code { get; set; }
/// <summary>
/// 订单金额 美金
/// </summary>
public decimal? TotalPrice { get; set; }
public List<Order_GoodsInfoModel> GoodsList { get; set; }
}
public class Order_GoodsInfoModel
{
/// <summary>
/// 货物名称 报关 名
/// </summary>
public string GoodsName { get; set; }
/// <summary>
/// 货物英文报关 名 必传
/// </summary>
public string GoodsENName { get; set; }
/// <summary>
/// 货物数量 必传
/// </summary>
public int GoodsNum { get; set; }
/// <summary>
/// sku 必传
/// </summary>
public string SKU { get; set; }
/// <summary>
/// 单个重量 单位 克 g 必传
/// </summary>
public decimal? Weight { get; set; }
/// <summary>
/// 单个产品尺寸 长度 单位 英寸 in 必传
/// </summary>
public decimal? Long { get; set; }
/// <summary>
/// 单个产品尺寸 宽度 单位 英寸 in 必传
/// </summary>
public decimal? Width { get; set; }
/// <summary>
/// 单个产品尺寸 高度 单位 英寸 in 必传
/// </summary>
public decimal? Height { get; set; }
}
}
}