using BizCom; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Data; //status可选值: //* TRADE_NO_CREATE_PAY(没有创建支付宝交易) //* WAIT_BUYER_PAY(等待买家付款) //* SELLER_CONSIGNED_PART(卖家部分发货) //* WAIT_SELLER_SEND_GOODS(等待卖家发货, 即:买家已付款) //* WAIT_BUYER_CONFIRM_GOODS(等待买家确认收货, 即:卖家已发货) //* TRADE_BUYER_SIGNED(买家已签收, 货到付款专用) //* TRADE_FINISHED(交易成功) //* TRADE_CLOSED(付款以后用户退款成功,交易自动关闭) //* TRADE_CLOSED_BY_TAOBAO(付款以前,卖家或买家主动关闭交易) //* PAY_PENDING(国际信用卡支付付款确认中) //* WAIT_PRE_AUTH_CONFIRM(0元购合约中) namespace ErpServer { /// /// 同步推送处理 /// public class tmcHelper { public static int RemoveEmptyEntries { get; private set; } // case "taobao_trade_TradeCreate"://创建淘宝交易消息 // { // break; // } // case "taobao_trade_TradeLogisticsAddressChanged"://卖家修改交易收货地址消息 // case "taobao_trade_TradeMemoModified"://交易备注修改消息 // case "taobao_trade_TradeRated"://交易评价变更消息 // case "taobao_trade_TradeBuyerPay"://买家付完款,或万人团买家付完尾款 // case "taobao_trade_TradeSuccess"://交易成功消息(确认收货) // case "taobao_trade_TradePartlyConfirmPay"://子订单打款成功消息 // case "taobao_trade_TradePartlyRefund"://子订单退款成功消息 // case "taobao_trade_TradeDelayConfirmPay"://延长收货时间消息 // case "taobao_trade_TradeSellerShip"://卖家发货消息 // case "taobao_trade_TradeClose"://关闭交易消息 // case "taobao_trade_TradeCloseAndModifyDetailOrder"://关闭或修改子订单消息 // case "taobao_trade_TradeModifyFee"://修改交易费用消息 public static string GetUTF8String(byte[] buffer) { if (buffer == null) return null; if (buffer.Length <= 3) { return Encoding.UTF8.GetString(buffer); } byte[] bomBuffer = new byte[] { 0xef, 0xbb, 0xbf }; if (buffer[0] == bomBuffer[0] && buffer[1] == bomBuffer[1] && buffer[2] == bomBuffer[2]) { return new UTF8Encoding(false).GetString(buffer, 3, buffer.Length - 3); } return Encoding.UTF8.GetString(buffer); } /// /// 交易订单关闭 /// /// public static void erp_CloseTrade(string content) { Dictionary dics = Utils.Serialization.JSON.ToDictionary(content); string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO if (status == "TRADE_CLOSED_BY_TAOBAO") { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTradeCell set status='{0}' where tid='{1}';", status, dics["tid"]); sql.AppendFormat("update CE_ErpTradeCell set OrderState={1} where tid='{0}' ;", dics["tid"], OrderState.交易关闭); sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", status, dics["tid"], dics["oid"]); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); //消息通知 } } //接收到--新订单生成消息 public static void erp_TradeBuyerPay(string content) { Dictionary dics = Utils.Serialization.JSON.ToDictionary(content); string tid = dics["tid"].ToString(); string sellerNick = dics["seller_nick"].ToString(); string sessionkey = taobaoHelper.ShopKeyDics[sellerNick]; string res = taobaoHelper.TradeFullinfoGet(sessionkey, tid); //taobaoHelper.test(); createNewOrder(res); } //创建新订单 public static void createNewOrder(string res) { Trade_fullinfo_get_response_Obj fullObj = null; if (res == "") return; try { res = GetUTF8String(Encoding.UTF8.GetBytes(res)); //res = res.Replace(" ", ""); fullObj = JsonConvert.DeserializeObject(res); } catch (Exception ex) { } if (fullObj == null) { Console.WriteLine("Trade_fullinfo_get_response_Obj isNull"); return; } Trade tObj = fullObj.trade_fullinfo_get_response.trade; Orders orderList = tObj.orders; StringBuilder sql = new StringBuilder(); CeErpTrade td = CeErpTrade.Get(tObj.tid); if (td!=null) { //已经存在了,就不要再继续创建了; return; } //原始单创建 CeErpTrade trade = new CeErpTrade(); trade.tid = tObj.tid; trade.num = tObj.num; trade.status = tObj.status; trade.type = tObj.type; trade.price = Convert.ToDouble(tObj.price); trade.discount_fee = Convert.ToDouble(tObj.discount_fee); trade.total_fee = Convert.ToDouble(tObj.total_fee); trade.created = tObj.created; if (tObj.pay_time.ToString() != "0001/1/1 0:00:00" && tObj.pay_time != null) { trade.pay_time = tObj.pay_time; } if (tObj.modified.ToString() != "0001/1/1 0:00:00" && tObj.modified != null) { trade.modified = tObj.modified; } if (tObj.end_time.ToString() != "0001/1/1 0:00:00" && tObj.end_time != null) { trade.end_time = tObj.end_time; } trade.buyer_nick = tObj.buyer_nick; trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee); trade.seller_nick = tObj.seller_nick; trade.payment = Convert.ToDouble(tObj.payment); trade.receiver_name = tObj.receiver_name; trade.receiver_state = tObj.receiver_state; trade.receiver_city = tObj.receiver_city; trade.receiver_town = GetNoNullValue_string(tObj.receiver_town); trade.receiver_district = GetNoNullValue_string(tObj.receiver_district); trade.receiver_address = tObj.receiver_address; trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile); trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone); if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null) { trade.consign_time = tObj.consign_time; } if (tObj.delivery_time.ToString() != "0001/1/1 0:00:00" && tObj.delivery_time != null) { trade.delivery_time = tObj.delivery_time; } trade.buyer_message = GetNoNullValue_string(tObj.buyer_message); trade.buyer_memo = GetNoNullValue_string(tObj.buyer_memo); trade.seller_memo = GetNoNullValue_string(tObj.seller_memo); trade.Create(); bool isXianhuo = false;//是否为现货单,现货单直接根据客户选的 选项生成Cell备注 string xianhuoMemo = "(" + trade.tid + ")现货-" ; //order表创建 foreach (Order item in orderList.order) { CeErpTradeOrder order = new CeErpTradeOrder(); order.tid = trade.tid; order.oid = item.oid; order.buyer_nick = trade.buyer_nick; order.refund_status = item.refund_status; order.status = item.status; order.title = item.title; order.price = Convert.ToDouble(item.price); order.pic_path = item.pic_path; order.num = Convert.ToDouble(item.num.ToString()); order.payment = Convert.ToDouble(item.payment); order.adjust_fee = Convert.ToDouble(item.adjust_fee); if(item.sku_id != null && item.sku_properties_name != null && item.sku_properties_name.IndexOf("现货")!=-1) { order.sku_properties_name = item.sku_properties_name; order.sku_id = item.sku_id; isXianhuo = true; xianhuoMemo += order.sku_properties_name; } order.Create(); } if (isXianhuo) { xianhuoMemo += "-"; xianhuoMemo += trade.seller_nick; } //cell表创建 CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(tObj.tid); if (entity == null) { try { entity = new CeErpTradeCell(); entity.ctid = tObj.tid; entity.tid = tObj.tid; entity.payment = Convert.ToDouble(tObj.payment); if (isXianhuo) { entity.OrderState = 5; entity.seller_memo = xianhuoMemo; } entity.Create(); } catch(Exception ex) { XLog.SaveLog(0, ex.Message); } } operateCustomer(tObj); } public static void operateCustomer(Trade Obj) { CeErpCustomer cus = null; cus = CeErpCustomer.GetByNick(Obj.buyer_nick); if (cus != null) { cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address; cus.phone = Obj.receiver_mobile; TimeSpan tsday = Obj.pay_time.Subtract((DateTime)cus.lastbuy_time); cus.buy_day = tsday.Days ; cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment); cus.buy_count = cus.buy_count + 1 ; cus.lastbuy_time = Obj.pay_time; cus.Update(); } else { try { cus = new CeErpCustomer(); cus.buyer_nick = Obj.buyer_nick; cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address; cus.phone = Obj.receiver_mobile; cus.buy_day = 0; cus.buy_count = 1; cus.lastbuy_time = Obj.pay_time; cus.total_fee = Convert.ToDouble(Obj.payment); cus.Create(); } catch(Exception ex) { XLog.SaveLog(0, ex.Message); } } } public static string GetNoNullValue_string(string value) { if (value == null) { return ""; } return value; } public static void erp_TradeMemoModified(string content) { Dictionary dics = Utils.Serialization.JSON.ToDictionary(content); if (!dics.ContainsKey("seller_memo")) { return; } string tid = dics["tid"].ToString(); string smemo = dics["seller_memo"].ToString();//TRADE_CLOSED_BY_TAOBAO string buyer = dics["buyer_nick"].ToString(); CeErpTrade mainEn = CeErpTrade.Get(tid); if (mainEn == null) return; createCellOrder(mainEn,tid,smemo,buyer); } public static void createCellOrder(CeErpTrade father,string tid,string smemo,string buyer,bool isJump=false) { bool isNeedCellOrder = true; //是否需要生成cell string issql = "select * from ce_erptradecell where tid='" + tid + "';"; DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0]; if (ishavedt.Rows.Count > 0) { if(Convert.ToInt32(ishavedt.Rows[0]["OrderState"])>0 && Convert.ToInt32(ishavedt.Rows[0]["DesignUserId"]) > 0) { isNeedCellOrder = false; } else if (ishavedt.Rows[0]["ctid"].ToString().IndexOf("C") != -1 && Convert.ToInt32(ishavedt.Rows[0]["OrderState"]) == 0 && Convert.ToInt32(ishavedt.Rows[0]["DesignUserId"]) == 0) { string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'"; CeErpTradeCell.ExecuteNonQuery(sql_del.ToString()); } } if (isJump) { isNeedCellOrder = true; } //补差价单 if (smemo.IndexOf("补差价") != -1) { CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(tid); bool ishaveBu = true; if (entity == null) { entity = new CeErpTradeCell(); entity.ctid = tid; entity.tid = tid; ishaveBu = false; } if (entity.OrderState >= 5) return; entity.seller_memo = smemo; entity.IsSample = 2;//补差价单 smemo = smemo.Replace(":", ":"); string[] listmemo = smemo.Split(':'); if (listmemo.Length > 1) { string maintid = System.Text.RegularExpressions.Regex.Replace(listmemo[1], @"[^0-9]+", ""); string sql = "select top 1 * from ce_erptradecell where tid='" + maintid + "'"; DataTable dt_bu = CeErpTradeCell.ExecuteDataset(sql).Tables[0]; if (dt_bu.Rows.Count > 0) { entity.ptid = dt_bu.Rows[0]["tid"].ToString(); entity.OrderState = Convert.ToInt32(dt_bu.Rows[0]["OrderState"]); entity.CustomerUserId = Convert.ToInt32(dt_bu.Rows[0]["CustomerUserId"]); entity.DesignUserId = Convert.ToInt32(dt_bu.Rows[0]["DesignUserId"]); if(dt_bu.Rows[0]["WaitDesignTime"] != DBNull.Value) { entity.WaitDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["WaitDesignTime"]); } if (dt_bu.Rows[0]["StartDesignTime"] != DBNull.Value) { entity.StartDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["StartDesignTime"]); } if (dt_bu.Rows[0]["FinishDesignTime"] != DBNull.Value) { entity.FinishDesignTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishDesignTime"]); } if (dt_bu.Rows[0]["FinishPlaceTime"] != DBNull.Value) { entity.FinishPlaceTime = Convert.ToDateTime(dt_bu.Rows[0]["FinishPlaceTime"]); } } } if (ishaveBu) { entity.Update(); } else { entity.Create(); } LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState); isNeedCellOrder = false; } else if(smemo.IndexOf("拿样订单") != -1) { CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(tid); if (entity == null) { entity = new CeErpTradeCell(); entity.ctid = tid; entity.tid = tid; entity.seller_memo = smemo; entity.OrderState = 6; //下单完成 entity.IsSample = 1; entity.Create(); } else { entity.IsSample = 1; entity.seller_memo = smemo; entity.OrderState = 6; entity.Update(); } LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState); isNeedCellOrder = false; } if (isNeedCellOrder == false) { return; } if (smemo.IndexOf("*") != -1) { return; } string[] memoList = null; if (smemo.IndexOf(",") != -1) { smemo = smemo.Replace(',',','); } memoList = smemo.Split(','); int orderIdx = 1; int hebaoCount = 0; bool isMulity = false; if (memoList.Length > 1) { isMulity = true; foreach(string mstr in memoList) { if (mstr.IndexOf("合包") != -1) { hebaoCount += 1; } } } if (hebaoCount == 1) { createHebaoCell(isMulity, 0, smemo, father); } else { double hePrice = father.payment; string needHebaoItem = ""; foreach (string item in memoList) { if (item.IndexOf("合包") != -1) { needHebaoItem += item; needHebaoItem += ","; } else { if (item.IndexOf("电子稿") != -1) { createDianziCell(isMulity,orderIdx,item,father,ref hePrice); } else if(item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1) { createLogoCell(isMulity, orderIdx, item, father, ref hePrice); } else if (item.IndexOf("现货") != -1) { createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice); } else createNotHeBaoCell(isMulity, orderIdx, item, father,ref hePrice); orderIdx++; } } if (needHebaoItem.Length > 0) { createHebaoCell(isMulity, orderIdx, needHebaoItem, father,hePrice); orderIdx++; } if (orderIdx>2) { string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "'"; CeErpTradeRefund.ExecuteNonQuery(sql_del.ToString()); } } } public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father,ref double hePrice) { if (itemMemo.Length <= 0) return; string ctid = ""; if (isMulty && itemMemo.Length > 2) { string preStr = "C" + orderIndex + "_"; ctid = preStr + father.tid; } else if (itemMemo.Length > 2) { ctid = father.tid; } CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(ctid); bool isNull = false; if (entity == null) { entity = new CeErpTradeCell(); isNull = true; } entity.ctid = ctid; entity.tid = father.tid; string[] acclist = itemMemo.Split('-'); string count = acclist[0]; string product = acclist[1]; string account = acclist[3]; DataRow cusInfo = getUserInfoByAccount(account); //客服id if (cusInfo != null) { entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]); if (entity.OrderState > 2 && entity.DesignUserId > 0) { } else entity.OrderState = Convert.ToInt32(OrderState.待抢单); } entity.ProductId = getProductIdByName("logo"); entity.ProductCount = count; if (isMulty) { try { entity.payment = Convert.ToDouble(acclist[4]); hePrice = hePrice - Convert.ToDouble(acclist[4]); } catch (Exception ex) { XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message); } } string newmemo = "(" + entity.tid + ")-"; for (int i = 0; i < acclist.Length; i++) { if (i == 3) continue; newmemo += acclist[i]; if (i < acclist.Length - 2) { newmemo += "-"; } } string sName = getShopSNameByName(father.seller_nick); newmemo += ("-" + sName); newmemo += ("-" + father.buyer_nick); newmemo += ("-" + father.receiver_state); if (cusInfo != null) { newmemo += ("-" + Convert.ToString(cusInfo["Tb"])); } if (isMulty) { newmemo += "-[C" + orderIndex + "]"; } entity.seller_memo = newmemo; if (isNull) { entity.Create(); } else { entity.Update(); } LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState); } public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref double hePrice) { if (itemMemo.Length <= 0) return; string ctid = ""; if (isMulity && itemMemo.Length > 2) { string preStr = "C" + orderIndex + "_"; ctid = preStr + father.tid; } else if (itemMemo.Length > 2) { ctid = father.tid; } CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(ctid); bool isNull = false; if (entity == null) { entity = new CeErpTradeCell(); isNull = true; } entity.ctid = ctid; entity.tid = father.tid; string[] acclist = itemMemo.Split('-'); string count = acclist[0]; string product = acclist[1]; string account = acclist[3]; DataRow cusInfo = getUserInfoByAccount(account); //客服id if (cusInfo != null) { entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]); } if (entity.OrderState < 3 && entity.DesignUserId == 0) { entity.OrderState = Convert.ToInt32(OrderState.待设计); entity.DesignUserId = 255; entity.WaitDesignTime = DateTime.Now; } entity.ProductId = getProductIdByName(product); entity.ProductCount = count; if (isMulity) { try { entity.payment = Convert.ToDouble(acclist[4]); hePrice = hePrice - Convert.ToDouble(acclist[4]); } catch (Exception ex) { XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message); } } string newmemo = "(" + entity.tid + ")-"; for (int i = 0; i < acclist.Length; i++) { if (i == 3) continue; newmemo += acclist[i]; if (i < acclist.Length - 2) { newmemo += "-"; } } string sName = getShopSNameByName(father.seller_nick);//获取店铺简称 newmemo += ("-" + sName); newmemo += ("-" + father.buyer_nick); newmemo += ("-" + father.receiver_state); if (cusInfo != null) { newmemo += ("-" + Convert.ToString(cusInfo["Tb"])); } if (isMulity) { newmemo += "-[C" + orderIndex + "]"; } entity.seller_memo = newmemo; if (isNull) { entity.Create(); } else { entity.Update(); } LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState); } public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father,ref double hePrice) { if (itemMemo.Length <= 0) return; string ctid = ""; if (isMulty && itemMemo.Length > 2) { string preStr = "C" + orderIndex + "_"; ctid = preStr + father.tid; } else if (itemMemo.Length > 2) { ctid = father.tid; } CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(ctid); bool isNull = false; if (entity == null) { entity = new CeErpTradeCell(); isNull = true; } entity.ctid = ctid; entity.tid = father.tid; string[] acclist = itemMemo.Split('-'); string product = acclist[0]; string account = acclist[1]; DataRow cusInfo = getUserInfoByAccount(account); //客服id if (cusInfo != null) { entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]); } entity.OrderState = Convert.ToInt32(OrderState.下单完成); if (isMulty) { try { entity.payment = Convert.ToDouble(acclist[2]); hePrice = hePrice - Convert.ToDouble(acclist[2]); } catch (Exception ex) { XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message); } } string newmemo = "(" + entity.tid + ")-"; for (int i = 0; i < acclist.Length; i++) { if (i == 1) continue; newmemo += acclist[i]; if (i < acclist.Length - 1) { newmemo += "-"; } } string sName = getShopSNameByName(father.seller_nick); newmemo += ("-" + sName); newmemo += ("-" + father.buyer_nick); newmemo += ("-" + father.receiver_state); if (cusInfo != null) { newmemo += ("-" + Convert.ToString(cusInfo["Tb"])); } if (isMulty) { newmemo += "-[C" + orderIndex + "]"; } entity.seller_memo = newmemo; if (isNull) { entity.Create(); } else { entity.Update(); } LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState); } public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father,double hePrice=0) { if (itemMemo.Length <= 0) return; string[] hebaoMemoList = itemMemo.Split(','); string memo_index1 = hebaoMemoList[0]; string ctid = ""; if (isMulity && orderIndex>1 && itemMemo.Length > 2) { string preStr = "C" + orderIndex + "_"; ctid = preStr + father.tid; } else if (itemMemo.Length > 2) { ctid = father.tid; } CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid); bool ishave = true; if (entity == null) { entity = new CeErpTradeCell(); ishave = false; } entity.ctid = ctid; entity.tid = father.tid; string[] acclist = memo_index1.Split('-'); if (acclist.Length < 6) { return; } string size = acclist[0]; string count = acclist[1]; bool isBuGanJiao = false; string product = ""; string mt = "", ct = ""; string account = ""; //不干胶材质和产品名对换 memo_index1 = memo_index1.Replace("PVC", "pvc"); if ((memo_index1.IndexOf("不干胶") != -1 || memo_index1.IndexOf("PVC卡片") != -1 || memo_index1.IndexOf("pvc卡片") != -1 || memo_index1.IndexOf("海报") != -1) && memo_index1.IndexOf("现货")==-1) { isBuGanJiao = true; product = acclist[3]; mt = acclist[2]; } else { product = acclist[2]; mt = acclist[3]; } account = acclist[5]; ct = acclist[4]; entity.ProductId = getProductIdByName(product); //找不到对应产品id的不生成 if (entity.ProductId == 0) { return; } if (isMulity && hePrice != 0) { entity.payment = hePrice; } else { entity.payment = father.payment; } DataRow cusInfo = getUserInfoByAccount(account); //客服id if (cusInfo != null) { entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]); if (entity.OrderState > 2 && entity.DesignUserId > 0) { } else { entity.OrderState = 2; if (entity.DesignUserId > 0) { entity.OrderState = 3; } } } if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1) { if (itemMemo.IndexOf("改稿") != -1) { int designId = getOldCusByBuyer(father.buyer_nick); entity.DesignUserId = designId; if (designId != 0) { if (entity.OrderState > 2 && entity.DesignUserId > 0) { } else entity.OrderState = Convert.ToInt32(OrderState.待设计); entity.WaitDesignTime = DateTime.Now; LogHelper.addLog(entity.ctid, 0, "老客户改稿", entity.OrderState); } } else { entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计); entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿 entity.WaitDesignTime = DateTime.Now; LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState); } } entity.Material = mt; entity.ProductSize = size; entity.ProductCount = count; entity.Craft = ct; string newmemo = "(" + father.tid + ")-"; for(int idx = 0; idx < hebaoMemoList.Length; idx++) { string smallitem = hebaoMemoList[idx]; if (idx == 0 && smallitem.IndexOf("海报") != -1) { newmemo = ""; } smallitem = smallitem.Replace("-合包", ""); smallitem = smallitem.Replace("-(合包)", ""); string[] smallList = smallitem.Split('-'); if (smallitem.IndexOf("海报") != -1) { newmemo += smallList[2]; newmemo += smallList[0]; newmemo += "-"; newmemo += smallList[1]; newmemo += "("; newmemo += father.tid; newmemo += ")"; newmemo += "-"; newmemo += smallList[4]; } else { for (int i = 0; i < smallList.Length; i++) { if (isMulity && i == 5) { continue; } newmemo += smallList[i]; if (i < smallList.Length - 2 && i != 2 && i != 3) { newmemo += "-"; } } } if (hebaoMemoList.Length > idx + 1) { newmemo += ","; } } //string nohebaomemo = itemMemo.Replace("-合包",""); //string newmemo = "(" + entity.tid + ")-" + nohebaomemo; string sName = getShopSNameByName(father.seller_nick);//获取店铺简称 newmemo += ("-" + sName); newmemo += ("-" + father.buyer_nick); newmemo += ("-" + father.receiver_state); if (cusInfo != null) { newmemo += ("-" + Convert.ToString(cusInfo["Tb"])); } if (orderIndex > 1 && isMulity) { newmemo += "-[C" + orderIndex + "]"; } newmemo += "-合包"; entity.seller_memo = newmemo; if (ishave) { entity.Update(); } else entity.Create(); LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState); } public static void createNotHeBaoCell(bool isMulity, int orderIndex,string itemMemo,CeErpTrade father,ref double hePrice) { if (itemMemo.Length <= 0) return; string ctid = ""; if (isMulity && itemMemo.Length > 2) //item.length>2 避免备注加了分隔符,,且后面的是空的或者回车或者空格 { string preStr = "C" + orderIndex + "_"; ctid = preStr + father.tid; } else if (itemMemo.Length > 2) { ctid = father.tid; } CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid); bool ishave = true; if (entity == null) { entity = new CeErpTradeCell(); ishave = false; } entity.ctid = ctid; entity.tid = father.tid; string[] acclist = itemMemo.Split('-'); if (isMulity && acclist.Length < 7) { return; } if (acclist.Length < 6) { return; } string size = acclist[0]; string count = acclist[1]; bool isBuGanJiao = false; string product = ""; string mt = "", ct = ""; string account = ""; //不干胶材质和产品名对换 itemMemo = itemMemo.Replace("PVC", "pvc"); if ((itemMemo.IndexOf("不干胶") != -1 || itemMemo.IndexOf("PVC卡片") != -1 || itemMemo.IndexOf("pvc卡片") != -1 || itemMemo.IndexOf("海报") != -1) && itemMemo.IndexOf("现货") == -1) { isBuGanJiao = true; product = acclist[3]; mt = acclist[2]; } else { product = acclist[2]; mt = acclist[3]; } account = acclist[5]; ct = acclist[4]; //如果是拆分单的话要多一个价格的拆分 if (isMulity) { try { string strPrice = acclist[6]; if (strPrice.IndexOf("元") != -1) { strPrice = strPrice.Replace("元", ""); } entity.payment = Convert.ToDouble(strPrice); hePrice = hePrice - Convert.ToDouble(strPrice); //总价格-拆分后其他的价格=剩下需要拿去合包的价格 } catch (Exception ex) { //XLog.SaveLog(0, "createNotHeBaoCell,payment=acclist[6]" + "|" + ex.Message); } } else { entity.payment = father.payment; } entity.ProductId = getProductIdByName(product); //找不到对应产品id的不生成 if (entity.ProductId == 0) { return; } DataRow cusInfo = getUserInfoByAccount(account); //客服id if (cusInfo != null) { entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]); if(entity.OrderState>2 && entity.DesignUserId > 0) { //到了设计那边,就更新memo,状态不设置 } else { entity.OrderState = 2; if (entity.DesignUserId > 0) //推送过来更新的时候,如果已经指派给设计师了就待设计 { entity.OrderState = 3; } } } if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1) { if (itemMemo.IndexOf("改稿") != -1) { int designId = getOldCusByBuyer(father.buyer_nick); entity.DesignUserId = designId; if (designId != 0) { if (entity.OrderState > 2 && entity.DesignUserId > 0) { //到了设计那边,就更新memo,状态不设置 } else entity.OrderState = Convert.ToInt32(OrderState.待设计); entity.WaitDesignTime = DateTime.Now; LogHelper.addLog(entity.ctid, 0, "老客户改稿", entity.OrderState); } } else { entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计); entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单不林春鸿;//下单不林春鸿 entity.WaitDesignTime = DateTime.Now; LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState); } } entity.Material = mt; entity.ProductSize = size; entity.ProductCount = count; entity.Craft = ct; string newmemo = "(" + father.tid + ")-"; if (itemMemo.IndexOf("海报") != -1) { newmemo = acclist[2]; newmemo += acclist[0]; newmemo += "-"; newmemo += acclist[1]; newmemo += "("; newmemo += father.tid; newmemo += ")"; newmemo += "-"; newmemo += acclist[4]; } else { for (int i = 0; i < acclist.Length; i++) { if (isMulity && i == 6) { continue; } else if (i == 5) { continue; } newmemo += acclist[i]; if (i < acclist.Length - 2 && i != 2 && i != 3) { newmemo += "-"; } } } string sName = getShopSNameByName(father.seller_nick);//获取店铺简称 newmemo += ("-" + sName); newmemo += ("-" + father.buyer_nick); newmemo += ("-" + father.receiver_state); if (cusInfo != null) { newmemo += ("-" + Convert.ToString(cusInfo["Tb"])); } if (isMulity) { newmemo += "-[C" + orderIndex + "]"; } entity.seller_memo = newmemo; if (ishave) { entity.Update(); } else entity.Create(); LogHelper.addLog(entity.ctid, entity.CustomerUserId, "推送生成:" + entity.seller_memo, entity.OrderState); } public static int getOldCusByBuyer(string buyer) { string sql = "select top 5 * from view_erptradecell where buyer_nick='" + buyer + "';"; DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0]; foreach (DataRow dr in dt.Rows) { if (Convert.ToInt32(dr["DesignUserId"]) != 0 && Convert.ToInt32(dr["DesignUserId"])!= Convert.ToInt32(webConfig.PlaceDesigner_id)) //188林春鸿下单部设计 { return Convert.ToInt32(dr["DesignUserId"]); } } return 0; } public static int getProductIdByName(string proName) { string dname = proName; if(dname == "暧心贴") { dname = "暖心贴"; } string sql = "select top 1 * from ce_erpproduct where PType='" + dname + "';"; DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0]; if (dt.Rows.Count > 0) { return Convert.ToInt32(dt.Rows[0]["ID"]); } return 0; } public static string getShopSNameByName(string seller_nick) { string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';"; DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0]; if (dt.Rows.Count > 0) { return Convert.ToString(dt.Rows[0]["SName"]); } return ""; } //public static string getShopRealName(string seller_nick) //{ // string sql = "select * from CE_ErpShop where ShopName='" + seller_nick + "';"; // DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0]; // if (dt.Rows.Count > 0) // { // if(dt.Rows[0]["ShopName"].ToString()!= dt.Rows[0]["Summary"].ToString()) // return Convert.ToString(dt.Rows[0]["ShopName"]); // } // return seller_nick; //} //补差价单 关联 public static DataRow getRelationOrder(string buyer,string sampTid) { string sql = "select top 3 * from view_erptradecell where buyer_nick='" + buyer+"' and seller_memo not like '%补差价%' and tid<>'"+sampTid+"' order by id desc"; DataTable dt = CeErpTradeRefund.ExecuteDataset(sql).Tables[0]; if (dt.Rows.Count > 0) { DataRow need = dt.Rows[0]; if (dt.Rows.Count == 1) { return need; } int idx = 0; foreach(DataRow dr in dt.Rows) { if (idx != 0) { int day = Convert.ToDateTime(need["pay_time"]).Day; int nday = Convert.ToDateTime(dr["pay_time"]).Day; if (day==nday) { need = dr; } } idx++; } return need; } return null; } public static DataRow getUserInfoByAccount(string account) { string sql = "select * from view_erpuser where Account='"+account+"'"; DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0]; if (dt != null && dt.Rows.Count > 0) { return dt.Rows[0]; } return null; } public static void erp_TradeSuccess(string content) { Dictionary dics = Utils.Serialization.JSON.ToDictionary(content); string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO //if (status == "TRADE_FINISHED") //{ StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}';", "TRADE_FINISHED", dics["tid"]); sql.AppendFormat("update view_ErpTradeCell set OrderState={1} where tid='{0}';", dics["tid"], (int)OrderState.交易完成); sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}' ;", "TRADE_FINISHED", dics["tid"], dics["oid"]); CeErpTradeCell.ExecuteNonQuery(sql.ToString()); //} } public static void erp_TradeSellerShip(string content) { Dictionary dics = Utils.Serialization.JSON.ToDictionary(content); string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO //if (status == "WAIT_BUYER_CONFIRM_GOODS") //{ StringBuilder sql = new StringBuilder(); //sql.AppendFormat("update view_ErpTradeCell set OrderState={2} where tid='{0}' and IsPreDelivery=0 ;", dics["tid"], (int)OrderState.已发货);//发货接口已经改变OrderState sql.AppendFormat("update CE_ErpTrade set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]); sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' ;", "WAIT_BUYER_CONFIRM_GOODS", dics["tid"]); CeErpTradeCell.ExecuteNonQuery(sql.ToString()); //} } public static void erp_TradePartlyRefund(string content) { Dictionary dics = Utils.Serialization.JSON.ToDictionary(content); string status = dics["status"].ToString();//TRADE_CLOSED_BY_TAOBAO //if (status == "TRADE_CLOSED") //{ StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTrade set status='{0}'where tid='{1}' ;", "TRADE_CLOSED", dics["tid"]); sql.AppendFormat("update CE_ErpTradeOrder set status='{0}' where tid='{1}' and oid='{2}';", "TRADE_CLOSED", dics["tid"], dics["oid"]); sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund={1} where tid='{2}';", (int)OrderState.交易关闭,1, dics["tid"]); CeErpTradeCell.ExecuteNonQuery(sql.ToString()); LogHelper.addLog(dics["tid"].ToString(),0,"客户申请退款,已确认", (int)OrderState.交易关闭) ; //} } public static void Api_TmcTradeMsg(string res) { Api_tmc_trade_info_Obj fullObj = null; if (res == "") return; try { res = GetUTF8String(Encoding.UTF8.GetBytes(res)); //res = res.Replace(" ", ""); fullObj = JsonConvert.DeserializeObject(res); } catch (Exception ex) { XLog.SaveLog(0, res + "|1|"+ex.Message); } if (fullObj == null) { Console.WriteLine("Api_tmc_trade_info_Obj isNull"); return; } Content tObj = fullObj.content; List orderList = tObj.lines; if(tObj.status== "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID") { return; } bool isCreate = false; CeErpTrade trade = null; trade = CeErpTrade.Get(tObj.refOid); if (trade == null) { isCreate = true; trade = new CeErpTrade(); trade.tid = tObj.refOid; trade.type = tObj.refType; trade.price = Convert.ToDouble(tObj.totalPrice); trade.discount_fee = Convert.ToDouble(tObj.discountFee); trade.total_fee = Convert.ToDouble(tObj.totalFee); trade.created = StampToDateTime(tObj.orderTime); if (tObj.payTime != null && tObj.payTime.Length > 0) { trade.pay_time = StampToDateTime(tObj.payTime); } trade.buyer_nick = tObj.openBuyerNick; //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee); trade.seller_nick = tObj.openSellerNick; trade.payment = Convert.ToDouble(tObj.payment); //trade.receiver_name = tObj.receiver_name; trade.receiver_state = tObj.receiverState; trade.receiver_city = tObj.receiverCity; trade.receiver_town = GetNoNullValue_string(tObj.receiverTown); trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict); } if (tObj.posCode != null)trade.posCode = tObj.posCode; trade.status = tObj.status; //if (tObj.refundStatus == "PART_REFUNDED" || tObj.refundStatus == "ALL_REFUNDED") //{ //} trade.seller_flag = tObj.flag; if (tObj.modifyTime != null && tObj.modifyTime.Length>0) { trade.modified = StampToDateTime(tObj.modifyTime); } if ( tObj.finishTime!=null && tObj.finishTime.Length>0) { trade.end_time = StampToDateTime(tObj.finishTime); } if (tObj.shippingTime != null && tObj.shippingTime.Length>0) { trade.delivery_time = StampToDateTime(tObj.shippingTime); } //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo); trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo); bool isSellerMemoChange = false; if (trade.seller_memo != tObj.sellerMemo) { isSellerMemoChange = true; } trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo); if (isCreate) { trade.Create(); } else { trade.Update(); } if (tObj.status == "CLOSE") { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}' where tid='{1}' and ctid not like '%S_%';", (int)OrderState.交易关闭, tObj.refOid); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭); return; } else if (tObj.status == "COMPLETE") { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update ce_ErpTradeCell set OrderState={1},IsUrgency=0 where IsPreDelivery=0 and tid='{0}' and ctid not like '%C_%' and ctid not like '%S_%';", tObj.refOid, (int)OrderState.交易完成); sql.AppendFormat("update ce_ErpTradeCell set OrderState={1},IsUrgency=0 where IsPreDelivery=0 and tid='{0}' and ctid like '%C_%' and OrderState>5 and ctid not like '%S_%';", tObj.refOid, (int)OrderState.交易完成); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); return; } else if (tObj.status == "SHIPPED")//已发货 { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update ce_ErpTradeCell set OrderState={1} where IsPreDelivery=0 and tid='{0}' and ctid not like '%C_%' and ctid not like '%S_%';", tObj.refOid, (int)OrderState.已发货); sql.AppendFormat("update ce_ErpTradeCell set OrderState={1} where IsPreDelivery=0 and tid='{0}' and ctid like '%C_%' and OrderState>5 and ctid not like '%S_%';", tObj.refOid, (int)OrderState.已发货); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); return; } bool isXianhuo = false; string xianhuoMemo = "(" + trade.tid + ")现货-"; try { foreach (Api_tmc_trade_info_Obj.LinesItem item in orderList) { CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId); bool isCreateOrder = false; if (order == null) { order = new CeErpTradeOrder(); isCreateOrder = true; } order.tid = trade.tid; order.oid = item.refOlId; order.buyer_nick = trade.buyer_nick; if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS" || item.refundStatus == "REJECT_REFUNDED") { CeErpTradeRefund refund = CeErpTradeRefund.GetByTid(tObj.refOid); if (refund == null) { refund = new CeErpTradeRefund(); refund.refund_id = tObj.refOid; refund.tid = tObj.refOid; //refund.oid = item.oid; refund.created = StampToDateTime(tObj.orderTime); if (tObj.modifyTime != null && tObj.modifyTime.Length > 0) { refund.modified = StampToDateTime(tObj.modifyTime); } refund.status = tObj.refundStatus; refund.order_status = tObj.status; //refund.good_status = item.good_status; refund.payment = tObj.payment; refund.refund_fee = tObj.payment; //refund.refund_phase = item.refund_phase; //refund.reason = item.reason; //refund.describe = item.desc; refund.buyer_nick = tObj.openBuyerNick; refund.seller_nick = tObj.openSellerNick; refund.total_fee = tObj.payment; //refund.has_good_return = item.has_good_return; refund.RefundState = 1; refund.Create(); StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTradeCell set OrderState='{0}',IsRefund=1 where tid='{1}' and ctid not like '%S_%';", (int)OrderState.交易关闭, tObj.refOid); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); LogHelper.addLog(tObj.refOid, 0, "已退款,交易关闭", (int)OrderState.交易关闭); } } else if(item.refundStatus == "REFUNDING") { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTradeCell set IsRefund=2 where tid='{0}' and ctid not like '%S_%';", tObj.refOid); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); LogHelper.addLog(tObj.refOid, 0, "申请退款中"); } else if(item.refundStatus == "NO_REFUND" && order.refund_status!= "NO_REFUND" && isCreateOrder==false) { StringBuilder sql = new StringBuilder(); sql.AppendFormat("update CE_ErpTradeCell set IsRefund=0 where tid='{0}' and ctid not like '%S_%';", tObj.refOid); CeErpTradeRefund.ExecuteNonQuery(sql.ToString()); LogHelper.addLog(tObj.refOid, 0, "关闭申请退款"); } order.refund_status = item.refundStatus; order.status = trade.status; order.title = item.title; order.price = Convert.ToDouble(item.price); if (item.picPath != null) order.pic_path = item.picPath; order.num = Convert.ToDouble(item.num.ToString()); order.payment = Convert.ToDouble(item.price); //order.adjust_fee = Convert.ToDouble(item.price); if (item.refSkuId != null && item.standards != null && item.standards.IndexOf("现货") != -1 && item.standards.IndexOf("定制") == -1) { order.sku_properties_name = item.standards; order.sku_id = item.refSkuId; isXianhuo = true; xianhuoMemo += order.sku_properties_name; } if (isCreateOrder) { order.Create(); } else { order.Update(); } } } catch(Exception ex) { XLog.SaveLog(0, res + "|order表" + ex.Message); } if (isXianhuo) { xianhuoMemo += "-"; xianhuoMemo += trade.seller_nick; } if (isCreate == false) { if (isSellerMemoChange) { try { createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick); } catch (Exception ex) { XLog.SaveLog(0, res + "|2|" + ex.Message); } } return; } //cell表创建 CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(tObj.refOid); if (entity == null) { try { entity = new CeErpTradeCell(); entity.ctid = tObj.refOid; entity.tid = tObj.refOid; entity.seller_memo = ""; entity.payment = Convert.ToDouble(tObj.payment); entity.AfterSalePayment = Convert.ToDouble(tObj.payment); if (isXianhuo) { entity.OrderState = 6; //下单完成 entity.seller_memo = xianhuoMemo; entity.SupplierId = 2; //领淘本部 } entity.Create(); } catch (Exception ex) { XLog.SaveLog(0, res + "|cell创建" + ex.Message); } } if (tObj.sellerMemo.Length > 0) { try { createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick); } catch (Exception ex) { XLog.SaveLog(0, res + "|3|" + ex.Message); } } //生成档案客户信息 insertCustomerInfo(tObj); } public static DateTime StampToDateTime(string timeStamp) { DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(timeStamp + "0000"); TimeSpan toNow = new TimeSpan(lTime); return dateTimeStart.Add(toNow); } public static void Api_Tmc_CreateNewOrder(string res) { Api_trade_fullinfo_get_response_Obj fullObj = null; if (res == "") return; try { res = GetUTF8String(Encoding.UTF8.GetBytes(res)); //res = res.Replace(" ", ""); fullObj = JsonConvert.DeserializeObject(res); } catch (Exception ex) { XLog.SaveLog(0, ex.Message); } if (fullObj == null) { Console.WriteLine("Api_trade_fullinfo_get_response_Obj isNull"); return; } ContentItem tObj = null; if (fullObj.response.data.content.Count > 0) { tObj = fullObj.response.data.content[0]; } if (tObj == null) { return; } if (tObj.status == "DELETED" || tObj.status == "CANCEL" || tObj.status == "UNKNOWN" || tObj.status == "UNPAID") { return; } List orderList = tObj.lines; StringBuilder sql = new StringBuilder(); CeErpTrade td = CeErpTrade.Get(tObj.refOid); if (td != null) { return; } CeErpTrade trade = new CeErpTrade(); trade.tid = tObj.refOid; if (tObj.posCode != null) trade.posCode = tObj.posCode; //trade.num = tObj.num; trade.status = tObj.status; trade.seller_flag = tObj.flag; trade.type = tObj.refType; trade.price = Convert.ToDouble(tObj.totalPrice); trade.discount_fee = Convert.ToDouble(tObj.discountFee); trade.total_fee = Convert.ToDouble(tObj.totalFee); trade.created = StampToDateTime(tObj.orderTime); if (tObj.payTime!=null) { trade.pay_time = StampToDateTime(tObj.payTime); } if ( tObj.modifyTime != null) { trade.modified = StampToDateTime(tObj.modifyTime); } if (tObj.finishTime != null) { trade.end_time = StampToDateTime(tObj.finishTime); } trade.buyer_nick = tObj.openBuyerNick; //trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee); trade.seller_nick = tObj.openSellerNick; trade.payment = Convert.ToDouble(tObj.payment); //trade.receiver_name = tObj.receiver_name; trade.receiver_state = tObj.receiverState; trade.receiver_city = tObj.receiverCity; trade.receiver_town = GetNoNullValue_string(tObj.receiverTown); trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict); //trade.receiver_address = tObj.receiver_address; //trade.receiver_mobile = GetNoNullValue_string(tObj.receiver_mobile); //trade.receiver_phone = GetNoNullValue_string(tObj.receiver_phone); //if (tObj.consign_time.ToString() != "0001/1/1 0:00:00" && tObj.consign_time != null) //{ // trade.consign_time = tObj.consign_time; //} if ( tObj.shippingTime != null) { trade.delivery_time = StampToDateTime(tObj.shippingTime); } //trade.buyer_message = GetNoNullValue_string(tObj.buyerMemo); trade.buyer_memo = GetNoNullValue_string(tObj.buyerMemo); trade.seller_memo = GetNoNullValue_string(tObj.sellerMemo); trade.Create(); bool isXianhuo = false; string xianhuoMemo = "(" + trade.tid + ")现货-"; foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList) { CeErpTradeOrder order = new CeErpTradeOrder(); order.tid = trade.tid; order.oid = item.refOlId; order.buyer_nick = trade.buyer_nick; order.refund_status = item.refundStatus; order.status = trade.status; order.title = item.title; order.price = Convert.ToDouble(item.price); if(item.picPath!=null) order.pic_path = item.picPath; order.num = Convert.ToDouble(item.num.ToString()); order.payment = Convert.ToDouble(item.price); //order.adjust_fee = Convert.ToDouble(item.price); if (item.refSkuId != null && item.standards != null && item.standards.IndexOf("现货") != -1 && item.standards.IndexOf("定制")==-1) { order.sku_properties_name = item.standards; order.sku_id = item.refSkuId; isXianhuo = true; xianhuoMemo += order.sku_properties_name; } order.Create(); } if (isXianhuo) { xianhuoMemo += "-"; xianhuoMemo += trade.seller_nick; } CeErpTradeCell entity = null; entity = CeErpTradeCell.GetByCtid(tObj.refOid); if (entity == null) { try { entity = new CeErpTradeCell(); entity.ctid = tObj.refOid; entity.tid = tObj.refOid; entity.payment = Convert.ToDouble(tObj.payment); if (isXianhuo) { entity.OrderState = 6;//现货直接下单完成 entity.seller_memo = xianhuoMemo; entity.SupplierId = 2; //领淘本部 } entity.Create(); } catch (Exception ex) { XLog.SaveLog(0, ex.Message); } } if (tObj.sellerMemo.Length > 0) { try { createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick); } catch (Exception ex) { XLog.SaveLog(0, res + "|" + ex.Message); } } ////生成档案客户信息 //insertCustomerInfo(tObj); } public static void insertCustomerInfo(Content Obj) { CeErpCustomer cus = null; cus = CeErpCustomer.GetByNick(Obj.openBuyerNick); if (cus != null) { //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address; //cus.phone = Obj.receiver_mobile; TimeSpan tsday = StampToDateTime(Obj.payTime).Subtract((DateTime)cus.lastbuy_time); cus.buy_day = tsday.Days; cus.total_fee = cus.total_fee + Convert.ToDouble(Obj.payment); cus.buy_count = cus.buy_count + 1; cus.lastbuy_time = StampToDateTime(Obj.payTime); cus.Update(); } else { try { cus = new CeErpCustomer(); cus.buyer_nick = Obj.openBuyerNick; //cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address; //cus.phone = Obj.receiver_mobile; cus.buy_day = 0; cus.buy_count = 1; cus.lastbuy_time = StampToDateTime(Obj.payTime); cus.total_fee = Convert.ToDouble(Obj.payment); cus.Create(); } catch (Exception ex) { XLog.SaveLog(0, ex.Message); } } } //接收到--新订单生成消息 public static void API_Tmc_TradeBuyerPay(string content) { Api_tmc_trade_info_Obj fullObj = null; if (content == "") return; try { content = GetUTF8String(Encoding.UTF8.GetBytes(content)); //res = res.Replace(" ", ""); fullObj = JsonConvert.DeserializeObject(content); } catch (Exception ex) { } if (fullObj == null) { Console.WriteLine("Api_tmc_trade_info_Obj isNull"); return; } Content tObj = fullObj.content; string res = apiHelper.API_TradeFullinfoGet(tObj.refOid); //taobaoHelper.test(); Api_Tmc_CreateNewOrder(res); } //推送接收到卖家备注修改 public static void API_Tmc_TradeMemoModified(string content) { Api_tmc_trade_info_Obj fullObj = null; if (content == "") return; try { content = GetUTF8String(Encoding.UTF8.GetBytes(content)); //res = res.Replace(" ", ""); fullObj = JsonConvert.DeserializeObject(content); } catch (Exception ex) { } if (fullObj == null) { Console.WriteLine("Api_tmc_trade_info_Obj isNull"); return; } Content tObj = fullObj.content; //原始表--没有这个单,不能拆分 CeErpTrade mainEn = CeErpTrade.Get(tObj.refOid); if (mainEn == null) return; createCellOrder(mainEn, tObj.refOid, tObj.sellerMemo, tObj.sellerMemo); } } }