using BizCom;
using Microsoft.SqlServer.Server;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NHibernate.Mapping;
using SiteCore;
using SiteCore.Handler;
using SiteCore.taobao;
using SiteCore.taoObj;
using SQLData;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using static SiteCore.taoObj.Api_tmc_trade_info_Obj;
using static SiteCore.taoObj.Api_trade_fullinfo_get_response_Obj;
using static SiteCore.taoObj.Api_trade_info;
using static SiteCore.taoObj.dataShopResponseVo;
using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
using static SiteCore.taoObj.Trade_fullinfo_get_response_Obj;
using static SiteCore.taoObj.work_core_vo;
//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 SiteCore
{
///
/// 同步推送处理
///
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();
//查询是否有退款记录
CeErpSpecialRefund ceErpSpecialRefund = new CeErpSpecialRefund();
ceErpSpecialRefund = CeErpSpecialRefund.GetByTid(trade.tid);
if (ceErpSpecialRefund != null)
{
refundTmcHelper.Api_TmcRefundMsg(ceErpSpecialRefund.refxml);
ceErpSpecialRefund.whethernotify = 1;
ceErpSpecialRefund.Update();
}
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)
{
value = value.Replace("\n", " ");
value = value.Replace("\r", " ");
value = value.Replace("*", "x");
if (value == null)
{
return "";
}
return value;
}
public static string GetNull_tostring(object value)
{
if (value == null)
{
return "";
}
return value.ToString();
}
//接收到--卖家修改备注消息
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 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.交易关闭);
//}
}
static List postcodes = new List()
{
"yujia","taolai","zhufan","dingyi","lingtao","yangguangmao","xinkeli","yuejia","maiyu","xiyinshuo"
};
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");
XLog.SaveLog(0, "Api_tmc_trade_info_Obj isNull");
return;
}
Content tObj = fullObj.content;
List orderList = tObj.lines;
//未付款,未成功的单不需要 榆家不收
if (tObj.status == "DELETED" || (tObj.status == "CANCEL" && tObj.refType != "JD") || tObj.status == "UNKNOWN" || tObj.status == "UNPAID" || postcodes.IndexOf(tObj.posCode) > -1)
{
return;
}
bool isCreate = false;
CeErpTrade trade = null;
trade = CeErpTrade.Get(tObj.refOid);
tObj.sellerMemo = tObj.sellerMemo.Replace("默拍-发小礼物", "").Replace("电子稿-发小礼物", "").Replace("客户联系不上-发小礼物", "");
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);
}
if (tObj.posCode != null) trade.posCode = tObj.posCode;
trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
if (trade.seller_nick == "")
{
trade.seller_nick = getShopNameByECode(trade.posCode);
tObj.openSellerNick = trade.seller_nick;
}
//trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
trade.payment = Convert.ToDouble(tObj.payment);
//trade.receiver_name = tObj.receiver_name;
}
if (trade.buyer_nick == null || trade.buyer_nick.Length == 0)
{
trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
}
trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
trade.receiver_state = tObj.receiverState;
trade.receiver_city = tObj.receiverCity;
trade.receiverId = tObj.receiverId;
trade.receiver_town = GetNoNullValue_string(tObj.receiverTown);
trade.receiver_district = GetNoNullValue_string(tObj.receiverDistrict);
if (trade.type == "JD" && tObj.status == "CANCEL")
trade.status = "CLOSE";
else
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;
//备注修改
tObj.sellerMemo = GetNoNullValue_string(tObj.sellerMemo);
if (trade.seller_memo != tObj.sellerMemo)
{
isSellerMemoChange = true;
}
if (trade.seller_memo.Length != tObj.sellerMemo.Length)
{
isSellerMemoChange = true;
}
trade.seller_memo = tObj.sellerMemo;
if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
{
if (tObj.refType == "TMALL" || tObj.refType == "TB")
{
string[] acclist = tObj.sellerMemo.Split('-');
List list = new List(acclist);
string buyer_nick = "";
if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
{
if (list.Count > 3)
{
buyer_nick = list[3];
}
}
else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else if (trade.seller_memo.IndexOf("寄样") != -1)
{
if (list.Count > 3)
{
buyer_nick = list[3];
}
}
else if (trade.seller_memo.IndexOf("拿样订单") != -1)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else
{
if (list.Count > 5)
{
buyer_nick = list[5];
}
}
tObj.sellerMemo = string.Join("-", list);
tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
}
}
if (isCreate)
{
trade.create_time = DateTime.Now;
trade.Create();
}
else
{
if (tObj.status == "CLOSE")
{
trade.consign_time = DateTime.Now;
}
trade.Update();
}
//dataHelper.sendErpTradeInfo(new dataSendTradeBean(tObj));
try
{
if (tObj.status == "CLOSE" || tObj.status == "CANCEL")
{
StringBuilder sql = new StringBuilder();
sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, tObj.refOid);
CeErpTradeCell.ExecuteNonQuery(sql.ToString());
ApiVo apiVo = new ApiVo();
apiVo.actionName = "closeDesign";
apiVo.orderNumber = tObj.refOid;
//designHelper.API_WorkCore(apiVo);//closeDesign
LogHelper.addLog(tObj.refOid, 0, "交易关闭", (int)OrderState.交易关闭);
// commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
// removeOldCustomerInfo(trade);
}
else if (tObj.status == "COMPLETE")
{
StringBuilder sql = new StringBuilder();
sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, tObj.refOid);
CeErpTradeCell.ExecuteNonQuery(sql.ToString());
//commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
}
else if (tObj.status == "SHIPPED")//已发货
{
StringBuilder sql = new StringBuilder();
sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, tObj.refOid);
CeErpTradeCell.ExecuteNonQuery(sql.ToString());
//commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
}
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "shipped:" + ex.Message);
throw ex;
}
int xianhuoProductCount = 0;
bool isXianhuo = false;
string xianhuoMemo = "(" + trade.tid + ")现货-";
bool isNew = true;
CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
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.oid = item.refOlId;
order.tid = trade.tid;
order.buyer_nick = trade.buyer_nick;
}
if (item.refundStatus == "PART_REFUNDED" || item.refundStatus == "REFUNDED" || item.refundStatus == "WAIT_BUYER_RETURN_GOODS")
{
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 = DateTime.Now;
if (tObj.modifyTime != null && tObj.modifyTime.Length > 0)
{
refund.modified = StampToDateTime(tObj.modifyTime);
}
refund.status = item.refundStatus;
refund.order_status = tObj.status;
refund.payment = tObj.payment;
refund.refund_fee = tObj.payment;
refund.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
refund.buyer_id = GetNull_tostring(tObj.openBuyerId);
refund.seller_nick = trade.seller_nick;
refund.total_fee = tObj.payment;
refund.RefundState = 1;//1待审核2待确认
refund.Create();
//cell订单 添加退款标记
int rstate = commonHelper.getRefundTagByState(item.refundStatus);
commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
designHelper.API_refundOrder(tObj.refOid, "refundEd", "");
LogHelper.addLog(tObj.refOid, 0, "已退款", (int)OrderState.交易关闭);
}
else
{
if (refund.status != item.refundStatus)
{
refund.modified = DateTime.Now;
refund.status = item.refundStatus;
refund.order_status = tObj.status;
refund.Update();
int rstate = commonHelper.getRefundTagByState(item.refundStatus);
commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
LogHelper.addLog(tObj.refOid, 0, "更新退款状态", (int)OrderState.交易关闭);
}
}
}
else if (item.refundStatus == "REFUNDING" && order.refund_status != "REFUNDING")
{
commonHelper.UpdateRefundOrderState(tObj.refOid, 1);
designHelper.API_refundOrder(tObj.refOid, "refundIng", "");
LogHelper.addLog(tObj.refOid, 0, "申请退款中");
}
else if (item.refundStatus == "NO_REFUND" && order.refund_status != "NO_REFUND" && isCreateOrder == false)
{
//CeErpTradeRefund.Del(tObj.refOid);
commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
designHelper.API_refundOrder(tObj.refOid, "refundCancel", "");
LogHelper.addLog(tObj.refOid, 0, "关闭申请退款");
}
else if (item.refundStatus == "REJECT_REFUNDED" && order.refund_status != "REJECT_REFUNDED" && isCreateOrder == false)
{
//CeErpTradeRefund.Del(tObj.refOid);
commonHelper.UpdateRefundOrderState(tObj.refOid, 0);
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.picUrl != null)
order.pic_path = item.picUrl;
order.num = Convert.ToDouble(item.num.ToString());
order.payment = Convert.ToDouble(item.price);
order.total_fee = Convert.ToDouble(item.totalFee);
//order.adjust_fee = Convert.ToDouble(item.price);
if (item.refSkuId != null && item.refSkuId != "")
{
order.sku_id = item.refSkuId;
}
if (item.standards != null && item.standards != "")
{
order.sku_properties_name = item.standards;
}
if (item.refSpuId != null && item.refSpuId != "")
{
order.spu_id = item.refSpuId;
}
if (item.refSkuId != null && item.standards != null && (item.standards.IndexOf("现货") != -1 || item.standards.IndexOf("封酒贴") != -1 || item.standards.IndexOf("兔团团") != -1 || item.standards.IndexOf("帆布") != -1 || item.standards.IndexOf("手拉旗") != -1 || item.standards.IndexOf("kt") != -1 || item.standards.IndexOf("条幅") != -1 || item.standards.IndexOf("#") != -1) && item.standards.IndexOf("定制") == -1)
{
isXianhuo = true;
xianhuoMemo += order.sku_properties_name;
xianhuoMemo += ("-数量:" + order.num + ";");
xianhuoProductCount += (int)order.num;
if (isCreateOrder)
{
string goodsSql = "select * from CE_ErpBagShopGoods";
DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
if (goodsDt.Rows.Count > 0)
{
foreach (DataRow gdr in goodsDt.Rows)
{
string bname = gdr["bname"].ToString();
string bsize = gdr["bsize"].ToString();
string bcount = gdr["bcount"].ToString();
if (bname.Length > 0 && order.sku_properties_name.IndexOf(bname) != -1)
{
order.bagName = bname;
order.isBagOrder = 1;
}
if (bsize.Length > 0 && order.sku_properties_name.IndexOf(bsize) != -1)
{
order.bagSize = bsize;
}
if (bcount.Length > 0 && order.sku_properties_name.IndexOf(bcount) != -1)
{
order.bagCount = bcount;
int bbcount = commonHelper.getIntCountFromString(bcount);
order.bagRealCount = bbcount * (int)order.num;
}
}
}
}
}
if (isCreateOrder)
{
order.Create();
CeErpTradeSpu ceErpTradeSpu = CeErpTradeSpu.GetBySpuId(order.spu_id);
//dataHelper.sendErpTradeOrderInfo(new dataSendTradeOrderBean(item, tObj));
if (ceErpTradeSpu == null)
{
ceErpTradeSpu = new CeErpTradeSpu();
ceErpTradeSpu.spuId = order.spu_id;
ceErpTradeSpu.tid = order.tid;
ceErpTradeSpu.createTime = DateTime.Now;
dataSendSpuBean bean = new dataSendSpuBean();
bean.ShortText1728890680485 = order.title;
bean.ShortText1728890649488 = order.spu_id;
bean.shopId = shopId.ToString();
bean.Date1728891156995 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
dataResponseVo response = dataHelper.sendSpuInfo(bean);
if (response != null)
{
if ("0".Equals(response.errcode))
{
ceErpTradeSpu.isSync = true;
}
else
{
ceErpTradeSpu.message = response.errmsg;
}
}
ceErpTradeSpu.Create();
}
DateTime orderTime = ceErpTradeSpu.createTime ?? DateTime.MinValue;
if (DateTime.Compare(orderTime.AddDays(30), DateTime.Now) < 0)
{
isNew = false;
}
}
else
{
order.Update();
}
}
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "|order表:" + ex.Message);
throw ex;
}
//if (isXianhuo)
//{
// xianhuoMemo += "-";
// xianhuoMemo += trade.seller_nick;
//}
if (!trade.IsNew)
{
trade.IsNew = isNew;
}
CeErpTradeCell entity = null;
entity = CeErpTradeCell.GetByCtid_M(tObj.refOid);
if (entity == null)
{
try
{
entity = new CeErpTradeCell();
entity.ctid = tObj.refOid;
//唯一标识
entity.OrderSn = tObj.refOid;
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
entity.tid = tObj.refOid;
entity.seller_memo = "";
entity.payment = Convert.ToDouble(tObj.payment);
entity.AfterSalePayment = Convert.ToDouble(tObj.payment);
if (tObj.payTime != null)
{
entity.pay_time = StampToDateTime(tObj.payTime);
}
entity.UpdateTime = DateTime.Now;
entity.ShopId = shopId;
if (isXianhuo)
{
entity.OrderState = 6;
entity.seller_memo = xianhuoMemo;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
entity.IsXianHuo = 1;
entity.FinishPlaceTime = entity.pay_time;
entity.ProductCount = xianhuoProductCount.ToString();
if (xianhuoMemo.IndexOf("封酒贴") != -1)
{
entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
if (trade.buyer_memo != "")
{
entity.OrderState = 2;
entity.ProductId = 1;
entity.IsXianHuo = 0;
xianhuoMemo = xianhuoMemo.Replace("现货", "");
xianhuoMemo = xianhuoMemo.Replace(" ", "");
entity.seller_memo = xianhuoMemo;
if (entity.ShopId != 0)
{
entity.OrderState = orderAudit(entity.ShopId);
}
}
}
else if (xianhuoMemo.IndexOf("#") != -1)
{
entity.SupplierId = 87;
}
else if (xianhuoMemo.IndexOf("喜字贴") != -1)
{
entity.SupplierId = 70;
}
else if (xianhuoMemo.IndexOf("兔团团") != -1)
{
entity.SupplierId = 101;
}
else if (xianhuoMemo.IndexOf("手拉旗") != -1)
{
entity.SupplierId = 108;
}
try
{
string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
List> material_list = new List>();
List> name_list = new List>();
foreach (DataRow dr in goodsDt.Rows)
{
string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
List xianhuo = sqlMemo.Split(',').ToList();
foreach (var item in xianhuo)
{
if (string.IsNullOrEmpty(item)) continue;
Dictionary material_map = new Dictionary();//材质
Dictionary name_map = new Dictionary();//特殊名称
if (item.IndexOf('-') > -1)
{
List list = item.Split('-').ToList();
material_map.Add(dr["id"].ToString(), list[0]);
name_map.Add(dr["id"].ToString(), list[1]);
}
else
{
material_map.Add(dr["id"].ToString(), item);
}
material_list.Add(material_map);
name_list.Add(name_map);
}
}
List materials = new List();
List names = new List();
List result = new List();
for (int i = 0; i < material_list.Count; i++)
{
Dictionary map = material_list[i];
foreach (var item in map)
{
if (xianhuoMemo.IndexOf(item.Value) > -1)
{
Dictionary map2 = name_list[i];
if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
{
foreach (var item1 in map2)
{
if (xianhuoMemo.IndexOf(item1.Value) > -1)
{
names.Add(item1.Key);
materials.Add(item.Key);
}
}
}
else
{
materials.Add(item.Key);
}
}
}
}
if (names.Count > 0)//特殊名称有只先在特殊名称里选择
{
result = names.Distinct().ToList();
}
else
{
result = materials.Distinct().ToList();
}
if (result.Count > 0)
{
Random rnd = new Random();
int index = rnd.Next(result.Count);
entity.SupplierId = int.Parse(result[index]);
}
}
catch (Exception e)
{
XLog.SaveLog(0, res + "|现货匹配|" + e.Message);
}
if (isCreate)
{
int oldRes = isOldAndInsertCustomerInfo(trade, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2) entity.IsOldCustomerMore = 1;
}
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
//if (trade != null)
//{
// trade.seller_memo = xianhuoMemo;
// trade.Update();
//}
}
//if (xianhuoMemo.IndexOf("修改文字下单备注") != -1)
//{
// entity.OrderState = Convert.ToInt32(OrderState.待设计); // Convert.ToInt32(OrderState.待设计);
// entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
// entity.WaitDesignTime = DateTime.Now;
// entity.FinishPlaceTime = null;
// entity.SupplierId = 0;
// LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
//}
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid);
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "|cell创建" + ex.Message);
}
}
if (tObj.sellerMemo == "物料")
{
entity.seller_memo = "(" + trade.tid + ")-物料";
entity.OrderState = 6; //下单完成
entity.WaitDesignTime = DateTime.Now;
entity.FinishDesignTime = DateTime.Now;
entity.StartDesignTime = DateTime.Now;
entity.FinishPlaceTime = DateTime.Now;
entity.IsSample = 1;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
entity.Update();
}
//else if (isXianhuo && trade.status== "NOT_SHIPPED")
//{
// entity.seller_memo = xianhuoMemo;
// entity.IsXianHuo = 1;
// entity.FinishPlaceTime = entity.pay_time;
// entity.ProductCount = xianhuoProductCount.ToString();
// if (xianhuoMemo.IndexOf("封酒贴") != -1)
// {
// if (trade.buyer_memo != "") //没设计之前
// {
// if(entity.OrderState <= 2)
// {
// entity.OrderState = 2; //买家有备注的要设计
// }
// entity.ProductId = 1;
// entity.IsXianHuo = 0;
// xianhuoMemo = xianhuoMemo.Replace("现货", "");
// xianhuoMemo = xianhuoMemo.Replace(" ", "");
// entity.seller_memo = xianhuoMemo;
// }
// }
// else if (xianhuoMemo.IndexOf("喜字贴") != -1)
// {
// entity.SupplierId = 70; //智涛
// LogHelper.addLog(entity.ctid,0,"喜字贴纸现货到智涛待发货",0);
// }
// entity.Update();
//}
if (isSellerMemoChange)
{
try
{
createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "|2|" + ex.Message);
}
}
}
public static void Api_TmcTradeMsg_Create(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 create|" + ex.Message);
throw ex;
}
if (fullObj == null)
{
XLog.SaveLog(0, "create 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);
}
if (tObj.posCode != null) trade.posCode = tObj.posCode;
trade.buyer_nick = GetNull_tostring(tObj.openBuyerNick);
trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
//trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
if (trade.seller_nick == "")
{
trade.seller_nick = getShopNameByECode(trade.posCode);
}
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.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();
}
int xianhuoProductCount = 0;
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;
order.refund_status = item.refundStatus;
order.status = trade.status;
order.title = item.title;
order.price = Convert.ToDouble(item.price);
if (item.picUrl != null)
order.pic_path = item.picUrl;
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) && item.standards.IndexOf("定制") == -1)
{
order.sku_properties_name = item.standards;
order.sku_id = item.refSkuId;
isXianhuo = true;
xianhuoMemo += order.sku_properties_name;
xianhuoMemo += ("-数量:" + order.num + "; ");
xianhuoProductCount += (int)order.num;
}
if (isCreateOrder)
{
order.Create();
}
else
{
order.Update();
}
}
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "|create order表:" + ex.Message);
throw ex;
}
//if (isXianhuo)
//{
// xianhuoMemo += "-";
// xianhuoMemo += trade.seller_nick;
//}
CeErpTradeCell entity = null;
entity = CeErpTradeCell.GetByCtid_M(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 (tObj.payTime != null)
{
entity.pay_time = StampToDateTime(tObj.payTime);
}
CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
if (isXianhuo)
{
entity.FinishPlaceTime = DateTime.Now;
entity.OrderState = 6;
entity.seller_memo = xianhuoMemo;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
entity.IsXianHuo = 1;
if (xianhuoMemo.IndexOf("封酒贴") != -1)
{
entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);
if (trade.buyer_memo != "")
{
entity.OrderState = 2;
entity.ProductId = 1;
entity.IsXianHuo = 0;
xianhuoMemo = xianhuoMemo.Replace("现货", "");
xianhuoMemo = xianhuoMemo.Replace(" ", "");
entity.seller_memo = xianhuoMemo;
if (entity.ShopId != 0)
{
entity.OrderState = orderAudit(entity.ShopId);
}
}
}
else if (xianhuoMemo.IndexOf("喜字贴") != -1)
{
entity.SupplierId = 70;
}
entity.FinishPlaceTime = entity.pay_time;
entity.ProductCount = xianhuoProductCount.ToString();
if (isCreate)
{
int oldRes = isOldAndInsertCustomerInfo(trade, entity);
if (oldRes == 2)
{
entity.IsOldCustomer = 1;
entity.IsOldCustomerMore = 1;
}
else if (oldRes == 1)
{
entity.IsOldCustomer = 1;
}
}
//if (trade != null)
//{
// trade.seller_memo = xianhuoMemo;
// trade.Update();
//}
}
entity.Create();
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "|create cell创建" + ex.Message);
throw ex;
}
}
if (isSellerMemoChange && trade.seller_memo.Length > 0)
{
try
{
createCellOrder(trade, tObj.refOid, tObj.sellerMemo, tObj.openBuyerNick);
}
catch (Exception ex)
{
XLog.SaveLog(0, res + "|2_create|" + ex.Message);
}
}
}
public static void createCellOrder(CeErpTrade father, string tid, string smemo, string buyer, bool isJump = false)
{
smemo = smemo.Replace("\r", " ");
smemo = smemo.Replace("\n", " ");
bool isNeedCellOrder = true;
//try
//{
string issql = "select * from ce_erptradecell where tid='" + tid + "';";
DataTable ishavedt = CeErpTradeCell.ExecuteDataset(issql).Tables[0];
if (ishavedt.Rows.Count > 0)
{
foreach (DataRow hdr in ishavedt.Rows)
{
if (smemo.IndexOf("封酒贴") != -1)
{
if (Convert.ToInt32(hdr["IsXianHuo"]) == 1 && Convert.ToInt32(hdr["OrderState"]) >= 4)
{
isNeedCellOrder = false;
break;
}
else if (Convert.ToInt32(hdr["IsXianHuo"]) == 0 && Convert.ToInt32(hdr["OrderState"]) > 2)
{
isNeedCellOrder = false;
break;
}
}
else if ((Convert.ToInt32(hdr["OrderState"]) > 2 && smemo.IndexOf("礼物") == -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("礼物") != -1) || (Convert.ToInt32(hdr["OrderState"]) >= 4 && smemo.IndexOf("寄样") != -1))
{
isNeedCellOrder = false;
break;
}
}
if (isNeedCellOrder)
{
foreach (DataRow hdr in ishavedt.Rows)
{
if (hdr["ctid"].ToString().IndexOf("C") != -1)
{
string sql_del = "delete from CE_ErpTradeCell where tid='" + tid + "'";
CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
break;
}
}
}
}
//}
//catch(Exception ex)
//{
// isNeedCellOrder = false;
// XLog.SaveLog(0, "推送是否需要重新生成判断出错"+ tid + ex.Message);
//}
if (isJump)
{
isNeedCellOrder = true;
LogHelper.addLog(tid, 0, "原单强制重新生成", 0);
}
//if (smemo.IndexOf("g") != -1)
//{
// smemo = smemo.Replace("g", "克");
//}
if (smemo.IndexOf("补差价") != -1)
{
CeErpTradeCell entity = null;
entity = CeErpTradeCell.GetByCtid(tid);
bool ishaveBu = true;
if (entity == null)
{
entity = new CeErpTradeCell();
entity.ctid = tid;
//唯一标识
entity.OrderSn = tid;
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
entity.tid = tid;
ishaveBu = false;
}
entity.UpdateTime = DateTime.Now;
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (father.type != "PDD")
{
if (entity.OrderState >= 5) return;
}
entity.seller_memo = smemo;
entity.payment = Convert.ToDouble(father.payment);
entity.AfterSalePayment = Convert.ToDouble(father.payment);
entity.pay_time = father.pay_time;
smemo = smemo.Replace(":", ":");
string[] listmemo = smemo.Split(':');
if (listmemo.Length > 1)
{
string maintid = listmemo[1];//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();
if (father.type != "PDD")
{
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"]);
entity.SupplierId = Convert.ToInt32(dt_bu.Rows[0]["SupplierId"]);
entity.seller_memo = "补差价:" + entity.ptid;
entity.payment = father.payment;
entity.IsSample = 2;
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
{
father.create_time = DateTime.Now;
father.orderType = 20;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 20, 10);
}
ApiVo apiVo = new ApiVo();
apiVo.orderNumber = entity.ptid;
apiVo.payment = entity.payment;
apiVo.actionName = "repairDesign";
designHelper.API_WorkCore(apiVo);//repairDesign
LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
CeErpSukuraData.createInfo(entity.ctid, 1);
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
isNeedCellOrder = false;
}
else if (smemo.IndexOf("拿样订单") != -1)
{
CeErpTradeCell entity = null;
entity = CeErpTradeCell.GetByCtid(tid);
if (entity == null)
{
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
entity = new CeErpTradeCell();
entity.ctid = tid;
//唯一标识
entity.OrderSn = tid;
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
entity.UpdateTime = DateTime.Now;
entity.tid = tid;
entity.seller_memo = smemo;
entity.payment = Convert.ToDouble(father.payment);
entity.pay_time = father.pay_time;
entity.AfterSalePayment = Convert.ToDouble(father.payment);
entity.OrderState = 6; //下单完成
entity.FinishPlaceTime = DateTime.Now;
entity.IsSample = 1;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
entity.IsOldCustomer = 0;
father.create_time = DateTime.Now;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
else
{
entity.IsSample = 1;
entity.UpdateTime = DateTime.Now;
entity.seller_memo = smemo;
entity.OrderState = 6;
entity.FinishPlaceTime = DateTime.Now;
entity.IsOldCustomer = 0;
entity.Update();
}
LogHelper.addLog(entity.ctid, entity.CustomerUserId, entity.seller_memo, entity.OrderState);
CeErpSukuraData.createInfo(entity.ctid, 1);
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
isNeedCellOrder = false;
}
if (isNeedCellOrder == false)
{
return;
}
if (smemo.IndexOf("*") != -1)
{
return;
}
if (smemo.IndexOf("{") != -1 && smemo.IndexOf("+") != -1)
{
createNewSplitFn(smemo, father);
return;
}
string[] memoList = null;
if (smemo.IndexOf(",") != -1)
{
smemo = smemo.Replace(',', ',');
}
if (smemo.IndexOf(",,") != -1)
{
return;
}
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
{
decimal hePrice = Convert.ToDecimal(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, memoList.Length);
//}
//else
if (item.IndexOf("logo") != -1 || item.IndexOf("LOGO") != -1)
{
createLogoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
}
else if (item.IndexOf("寄样") != -1)
{
createDemoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
}
else if (item.IndexOf("礼物") != -1)
{
createSmallGiftCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
}
else
createNotHeBaoCell(isMulity, orderIdx, item, father, ref hePrice, memoList.Length);
orderIdx = orderIdx + 1;
}
}
bool isHaveHebaoOrder = false;
if (needHebaoItem.Length > 0)
{
isHaveHebaoOrder = true;
needHebaoItem = needHebaoItem.Substring(0, needHebaoItem.Length - 1);
createHebaoCell(isMulity, orderIdx, needHebaoItem, father, hePrice);
orderIdx = orderIdx + 1;
}
if (orderIdx > 2)
{
try
{
string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
LogHelper.addLog(tid, 0, "delete ctid=tid orderidx=" + orderIdx, 0);
if (System.Math.Abs(hePrice) > Convert.ToDecimal(0.01) && hePrice != Convert.ToDecimal(father.payment) && isHaveHebaoOrder == false)
{
string sql_pay = "update CE_ErpTradeCell with(rowlock) set orderstate=0 where tid='" + tid + "';";
CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString());
LogHelper.addLog(tid, 0, "拆分金额相加与总金额不等", 0);
}
}
catch (Exception ex)
{
XLog.SaveLog(0, tid + "|删除首单错误|" + ex.Message);
string sql_del = "delete from CE_ErpTradeCell where ctid='" + tid + "';";
CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
}
}
string orderSql = string.Format("SELECT * FROM [dbo].[CE_ErpTradeOrder] WHERE tid = '{0}' and total_fee > 0", father.tid);
DataTable table = SqlHelper.ExecuteDataSet(orderSql).Tables[0];
string spu_id = "";
if (table != null && table.Rows.Count == 1)
{
spu_id = table.Rows[0]["spu_id"].ToString();
}
string cellSql = string.Format("SELECT ctid FROM [dbo].[CE_ErpTradeCell] WHERE tid = '{0}'", father.tid);
DataTable data = SqlHelper.ExecuteDataSet(cellSql).Tables[0];
if (data != null && data.Rows.Count > 0)
{
foreach (DataRow row in data.Rows)
{
CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(row["ctid"].ToString());
if (ceErpTradeCellExtend == null)
{
ceErpTradeCellExtend = new CeErpTradeCellExtend();
ceErpTradeCellExtend.ctid = row["ctid"].ToString();
}
ceErpTradeCellExtend.spu_id = spu_id;
if (ceErpTradeCellExtend.ID == 0)
{
ceErpTradeCellExtend.Create();
}
else
{
ceErpTradeCellExtend.Update();
}
}
}
//autoCell(tid);
}
}
public static void createNewSplitFn(string smemo, CeErpTrade father)
{
if (smemo.IndexOf("合包") != -1)
{
createHebaoCell(false, 0, smemo, father);
}
else
{
int firstDaKuoHaoCount = 0;
string firstoneContent = commonHelper.MidStrEx(smemo, "{", "}");
string[] oneElementList = firstoneContent.Split('+');
firstDaKuoHaoCount = oneElementList.Length;
string[] memoList = smemo.Split('-');
for (int idx = 0; idx < firstDaKuoHaoCount; idx++)
{
string newMemoStr = "";
foreach (string oneStr in memoList)
{
string oneContent = "";
if (oneStr.IndexOf("{") != -1)
{
oneContent = commonHelper.MidStrEx(oneStr, "{", "}");
string[] oneList = oneContent.Split('+');
if (oneList.Length != firstDaKuoHaoCount)
{
XLog.SaveLog(0, father.tid + ",备注大括号内的元素个数不相等");
return;
}
newMemoStr += oneList[idx];
}
else
newMemoStr += oneStr;
newMemoStr += "-";
}
newMemoStr = newMemoStr.Substring(0, newMemoStr.Length - 1);
if (idx == 0)
createNewSplitCell(true, idx + 1, newMemoStr, father, father.payment - firstDaKuoHaoCount * 0.1, firstDaKuoHaoCount);
else
createNewSplitCell(true, idx + 1, newMemoStr, father, 0.1, firstDaKuoHaoCount);
}
try
{
string sql_del = "delete from CE_ErpTradeCell where ctid='" + father.tid + "'";
CeErpTradeCell.ExecuteNonQuery(sql_del.ToString());
LogHelper.addLog(father.tid, 0, "新拆分方法 delete ctid=tid ", 0);
}
catch (Exception ex)
{
XLog.SaveLog(0, "|新拆分删除首单错误|" + ex.Message);
}
}
}
public static void createLogoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
{
if (itemMemo.Length <= 0) return;
string ctid = "";
string splitTag = "";
if (isMulty && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + orderIndex;
}
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.OrderSn = ctid;
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
}
entity.UpdateTime = DateTime.Now;
entity.tid = father.tid;
entity.SplitTag = splitTag;
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (entity.IsSample == 1 || entity.IsSample == 2)
{
entity.IsSample = 0;
entity.ptid = "";
}
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
string[] acclist = itemMemo.Split('-');
if (acclist.Length < 4) return;
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 = 2;
if (entity.ShopId != 0)
{
entity.OrderState = orderAudit(entity.ShopId);
}
}
}
entity.ProductId = getProductIdByName("logo");
if (entity.ProductId == 0)
{
return;
}
entity.ProductCount = count;// commonHelper.changeCountFromChiness(count); ;
if (isMulty)
{
try
{
string strPrice = acclist[4];
if (strPrice.IndexOf("元") != -1)
{
strPrice = strPrice.Replace("元", "");
}
entity.payment = Convert.ToDouble(strPrice);
hePrice = hePrice - Convert.ToDecimal(acclist[4]);
}
catch (Exception ex)
{
}
}
else
{
entity.payment = Convert.ToDouble(father.payment);
entity.AfterSalePayment = Convert.ToDouble(father.payment);
}
string newmemo = "(" + entity.OrderSn + ")-";
string newOtherMemo = "";
for (int i = 0; i < acclist.Length; i++)
{
if (i == 3) continue;
if (i >= 4)
{
newOtherMemo += acclist[i];
}
else
newmemo += acclist[i];
if (i < acclist.Length - 2)
{
newmemo += "-";
}
}
string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
newmemo += ("-" + sName);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (isMulty)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
if (itemMemo.IndexOf("顺丰到付") != -1)
{
if (newmemo.IndexOf("顺丰到付") == -1)
newmemo += ("-顺丰到付");
entity.IsSF = 2;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
}
else if (itemMemo.IndexOf("顺丰寄付") != -1)
{
if (newmemo.IndexOf("顺丰寄付") == -1)
newmemo += ("-顺丰寄付");
entity.IsSF = 1;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
}
if (itemMemo.IndexOf("加急") != -1)
{
if (newmemo.IndexOf("加急") == -1)
newmemo += ("-加急");
entity.IsUrgency = true;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
}
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
entity.pay_time = father.pay_time;
//int oldRes = isOldAndInsertCustomerInfo(father, entity);
//if (oldRes>0)
//{
// entity.IsOldCustomer = 1;
// if (oldRes == 2)
// {
// entity.IsOldCustomer = 1;
// entity.IsOldCustomerMore = 1;
// }
//}
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
{
entity.IsOldCustomer = 0;
}
int oldRes = isOldAndInsertCustomerInfo(father, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2) entity.IsOldCustomerMore = 1;
int curHour = DateTime.Now.Hour;
int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
}
else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
}
else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
}
else
{
CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
{
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
}
}
}
}
if (isNull)
{
father.create_time = DateTime.Now;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
else
{
entity.Update();
}
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
CeErpSukuraData.createInfo(entity.ctid, 1);
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "logo推送生成" + entity.seller_memo, entity.OrderState);
}
public static void createDianziCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
{
if (itemMemo.Length <= 0) return;
string ctid = "";
string splitTag = "";
if (isMulity && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + orderIndex;
}
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;
entity.SplitTag = splitTag;
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (entity.IsSample == 1 || entity.IsSample == 2)
{
entity.IsSample = 0;
entity.ptid = "";
}
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
string[] acclist = itemMemo.Split('-');
if (acclist.Length < 4) return;
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.OrderState = Convert.ToInt32(OrderState.待设计);
//entity.DesignUserId = 255; //电子稿给亿佳设计
//entity.WaitDesignTime = DateTime.Now;
}
entity.ProductId = getProductIdByName(product);
if (entity.ProductId == 0)
{
return;
}
entity.ProductCount = count;// commonHelper.changeCountFromChiness(count); ;
entity.isDianziOrder = 1;//电子稿
entity.pay_time = father.pay_time;
if (isMulity)
{
try
{
string strPrice = acclist[4];
if (strPrice.IndexOf("元") != -1)
{
strPrice = strPrice.Replace("元", "");
}
entity.payment = Convert.ToDouble(strPrice);
hePrice = hePrice - Convert.ToDecimal(acclist[4]);
}
catch (Exception ex)
{
//XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
}
}
else
{
entity.payment = Convert.ToDouble(father.payment);
entity.AfterSalePayment = Convert.ToDouble(father.payment);
}
string newmemo = "(" + entity.tid + ")-";
string newOtherMemo = "";
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);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (isMulity)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
//int oldRes = isOldAndInsertCustomerInfo(father, entity);
//if (oldRes > 0)
//{
// entity.IsOldCustomer = 1;
// if (oldRes == 2)
// {
// entity.IsOldCustomer = 1;
// entity.IsOldCustomerMore = 1;
// }
//}
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
entity.IsOldCustomer = 0;
int oldRes = isOldAndInsertCustomerInfo(father, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2) entity.IsOldCustomerMore = 1;
dealOldCustomerEntityAuto(ref entity);
}
}
if (isNull)
{
father.create_time = DateTime.Now;
father.Update();
entity.Create();
}
else
{
entity.Update();
}
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
CeErpSukuraData.createInfo(entity.ctid, 1);
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "电子稿推送生成" + entity.seller_memo, entity.OrderState);
}
public static void createDemoCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
{
if (itemMemo.Length <= 0) return;
string ctid = "";
string splitTag = "";
if (isMulty && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + orderIndex;
}
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.OrderSn = ctid;
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
}
entity.UpdateTime = DateTime.Now;
entity.tid = father.tid;
entity.SplitTag = splitTag;
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
entity.IsSample = 3;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
string[] acclist = itemMemo.Split('-');
if (acclist.Length <= 3) return;
//string count = acclist[0];
string product = acclist[1];
string account = acclist[3];
DataRow cusInfo = getUserInfoByAccount(account);
if (cusInfo != null)
{
entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
if (entity.OrderState > 6)
{
}
else
{
entity.OrderState = Convert.ToInt32(OrderState.下单完成);
}
}
entity.ProductId = getProductIdByName(product);
if (entity.ProductId == 0)
{
return;
}
if (isMulty)
{
try
{
string strPrice = acclist[4];
if (strPrice.IndexOf("元") != -1)
{
strPrice = strPrice.Replace("元", "");
}
entity.payment = Convert.ToDouble(strPrice);
hePrice = hePrice - Convert.ToDecimal(strPrice);
}
catch (Exception ex)
{
//XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
}
}
else
{
entity.payment = Convert.ToDouble(father.payment);
entity.AfterSalePayment = Convert.ToDouble(father.payment);
}
string newmemo = "(" + entity.OrderSn + ")-";
string newOtherMemo = "";
List list = new List();
for (int i = 0; i < acclist.Length; i++)
{
if (i == 3) continue;
if (isMulty)
{
if (i == 4) continue;
}
list.Add(acclist[i]);
}
newmemo += string.Join("-", list);
string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
newmemo += ("-" + sName);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (isMulty)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
if (itemMemo.IndexOf("顺丰到付") != -1)
{
if (newmemo.IndexOf("顺丰到付") == -1)
newmemo += ("-顺丰到付");
entity.IsSF = 2;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
}
else if (itemMemo.IndexOf("顺丰寄付") != -1)
{
if (newmemo.IndexOf("顺丰寄付") == -1)
newmemo += ("-顺丰寄付");
entity.IsSF = 1;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
}
if (itemMemo.IndexOf("加急") != -1)
{
if (newmemo.IndexOf("加急") == -1)
newmemo += ("-加急");
entity.IsUrgency = true;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
}
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
entity.pay_time = father.pay_time;
entity.FinishDesignTime = DateTime.Now;
entity.StartDesignTime = DateTime.Now;
entity.WaitDesignTime = DateTime.Now;
entity.FinishPlaceTime = DateTime.Now;
entity.IsOldCustomer = 0;
int oldRes = isOldAndInsertCustomerInfo(father, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2)
{
entity.IsOldCustomer = 1;
entity.IsOldCustomerMore = 1;
}
}
if (isNull)
{
father.create_time = DateTime.Now;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
else
{
entity.Update();
}
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
CeErpSukuraData.createInfo(entity.ctid, 1);
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "寄样推送生成" + entity.seller_memo, entity.OrderState);
}
public static void createSmallGiftCell(bool isMulty, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
{
if (itemMemo.Length <= 0) return;
string ctid = "";
string splitTag = "";
if (isMulty && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + orderIndex;
}
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;
}
if (entity.OrderState > 6) return;
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (entity.IsSample == 1 || entity.IsSample == 2)
{
entity.IsSample = 0;
entity.ptid = "";
}
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
entity.ctid = ctid;
if (string.IsNullOrEmpty(entity.OrderSn))
{
//唯一标识
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
}
entity.UpdateTime = DateTime.Now;
entity.tid = father.tid;
entity.SplitTag = splitTag;
string[] acclist = itemMemo.Split('-');
if (acclist.Length < 2) return;
if (itemMemo.Contains("插牌") || itemMemo.Contains("插排"))
{
return;
}
string product = acclist[0];
string account = acclist[1];
DataRow cusInfo = getUserInfoByAccount(account); //客服id
if (cusInfo != null)
{
entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
}
entity.IsOldCustomer = 0;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
entity.IsXianHuo = 1;
entity.IsGift = 1;
entity.FinishPlaceTime = father.pay_time;
if (entity.OrderState < 6)
{
entity.OrderState = Convert.ToInt32(OrderState.下单完成);
}
if (isMulty)
{
try
{
string strPrice = acclist[2];
if (strPrice.IndexOf("元") != -1)
{
strPrice = strPrice.Replace("元", "");
}
entity.payment = Convert.ToDouble(strPrice);
hePrice = hePrice - Convert.ToDecimal(acclist[2]);
}
catch (Exception ex)
{
//XLog.SaveLog(0, "createDianziCell,payment=acclist[4]" + "|" + ex.Message);
}
}
else
{
entity.payment = Convert.ToDouble(father.payment);
entity.AfterSalePayment = Convert.ToDouble(father.payment);
}
string newmemo = "(" + entity.OrderSn + ")-";
string newOtherMemo = "";
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" + totalCount + "+" + orderIndex + "]";
}
if (newmemo.IndexOf("现货") != -1)
{
newmemo = newmemo.Replace("礼物", "");
}
if (itemMemo.IndexOf("顺丰到付") != -1)
{
newmemo += ("-顺丰到付");
entity.IsSF = 2;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
}
else if (itemMemo.IndexOf("顺丰寄付") != -1)
{
newmemo += ("-顺丰寄付");
entity.IsSF = 1;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
}
if (itemMemo.IndexOf("加急") != -1)
{
newmemo += ("-加急");
entity.IsUrgency = true;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
}
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
entity.pay_time = father.pay_time;
if (isNull)
{
father.create_time = DateTime.Now;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
else
{
entity.Update();
}
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
CeErpSukuraData.createInfo(entity.ctid, 1);
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "礼物推送生成" + entity.seller_memo, entity.OrderState);
}
public static void createHebaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, decimal hePrice = 0)
{
if (itemMemo.Length <= 0) return;
string[] hebaoMemoList = itemMemo.Split(',');
string memo_index1 = hebaoMemoList[0];
string ctid = "";
string splitTag = "";
if (isMulity && orderIndex > 1 && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + orderIndex + "+" + orderIndex;
}
else if (itemMemo.Length > 2)
{
ctid = father.tid;
}
CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
bool ishave = true;
if (entity == null)
{
entity = new CeErpTradeCell();
ishave = false;
}
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (entity.IsSample == 1 || entity.IsSample == 2)
{
entity.IsSample = 0;
entity.ptid = "";
}
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
entity.ctid = ctid;
if (string.IsNullOrEmpty(entity.OrderSn))
{
//唯一标识
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
}
entity.UpdateTime = DateTime.Now;
entity.tid = father.tid;
entity.SplitTag = splitTag;
string[] acclist = memo_index1.Split('-');
bool isXianhuo = false;
if (acclist[0] == "现货")
{
System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
System.Array.Resize(ref acclist, acclist.Length - 1);
isXianhuo = true;
}
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 ((acclist[3] == "不干胶" || 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);
if (entity.ProductId == 0)
{
return;
}
if (isMulity && hePrice != 0)
{
entity.payment = Convert.ToDouble(hePrice);
}
else
{
entity.payment = father.payment;
}
DataRow cusInfo = getUserInfoByAccount(account);
if (cusInfo != null)
{
entity.CustomerUserId = Convert.ToInt32(cusInfo["ID"]);
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
entity.OrderState = 2;
if (entity.ShopId != 0)
{
entity.OrderState = orderAudit(entity.ShopId);
}
if (entity.DesignUserId > 0)
{
entity.OrderState = 3;
}
}
}
if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
{
entity.IsOldCustomer = 1;
if (itemMemo.IndexOf("改稿") != -1)
{
if (entity.payment > 0)
{
//designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
dealOldCustomerEntityTag(ref entity, father);
}
}
}
else
{
entity.OrderState = 3;
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;//commonHelper.changeCountFromChiness(count); ;
entity.Craft = ct;
entity.pay_time = father.pay_time;
string newmemo = "(" + entity.OrderSn + ")-";
if (isXianhuo)
{
newmemo += "现货-";
entity.IsXianHuo = 1;
}
string newOtherMemo = "";
for (int idx = 0; idx < hebaoMemoList.Length; idx++)
{
string smallitem = hebaoMemoList[idx];
if (idx == 0 && smallitem.IndexOf("海报") != -1)
{
newmemo = "";
}
string[] smallList = smallitem.Split('-');
if (smallList.Length > 5 && idx > 0)
{
string itemsize = smallList[0];
string itemcount = smallList[1];
string itemmt = "", itemct = "";
if ((smallList[3] == "不干胶" || smallitem.IndexOf("PVC卡片") != -1 || smallitem.IndexOf("pvc卡片") != -1 || smallitem.IndexOf("海报") != -1) && smallitem.IndexOf("礼物") == -1)
{
itemmt = acclist[2];
}
else
{
itemmt = acclist[3];
}
itemct = acclist[4];
entity.ProductSize = entity.ProductSize + "," + itemsize;
entity.ProductCount = entity.ProductCount + "," + itemcount;
entity.Material = entity.Material + "," + itemmt;
entity.Craft = entity.Craft + "," + itemct;
}
if (smallList.Length >= 7)
{
smallList[6] = smallList[6].Replace("(", "");
smallList[6] = smallList[6].Replace(")", "");
smallList[6] = smallList[6].Replace("(", "");
smallList[6] = smallList[6].Replace(")", "");
entity.MakeSupplier = smallList[6];
smallList[6] = "(" + smallList[6] + ")";
newmemo += smallList[6];
newmemo += "-";
}
if (smallitem.IndexOf("海报") != -1)
{
newmemo += smallList[2];
newmemo += smallList[0];
newmemo += "-";
newmemo += smallList[1];
newmemo += "(";
newmemo += father.tid;
newmemo += ")";
newmemo += "-";
newmemo += smallList[4];
if (smallList.Length > 7)
{
for (int i = 7; i < smallList.Length; i++)
{
newOtherMemo += smallList[i];
newOtherMemo += "-";
}
}
if (smallitem.IndexOf("5mmpvc") != -1)
{
entity.ProductId = 8; //pvc卡片
}
}
else
{
for (int i = 0; i < smallList.Length; i++)
{
if (isMulity && i == 5)
{
continue;
}
if (i >= 7)
{
newOtherMemo += smallList[i];
if (i < smallList.Length - 2 && i != 2 && i != 3)
{
newOtherMemo += "-";
}
}
else
{
if (i == 6)
{
continue;
}
else
newmemo += smallList[i];
if (i != 2 && i != 3)
{
newmemo += "-";
}
}
}
}
if (hebaoMemoList.Length > idx + 1)
{
newmemo += ",";
newOtherMemo += ",";
}
}
string sName = getShopSNameByName(father.seller_nick);
newmemo += (sName);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (orderIndex > 1 && isMulity)
{
newmemo += "-[C" + orderIndex + "+" + orderIndex + "]";
}
//newmemo += "-合包";
if (itemMemo.IndexOf("顺丰到付") != -1)
{
//if(newmemo.IndexOf("顺丰到付")==-1)
// newmemo += ("-顺丰到付");
entity.IsSF = 2;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
}
else if (itemMemo.IndexOf("顺丰寄付") != -1)
{
//if (newmemo.IndexOf("顺丰寄付") == -1)
// newmemo += ("-顺丰寄付");
entity.IsSF = 1;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
}
if (itemMemo.IndexOf("加急") != -1)
{
//if (newmemo.IndexOf("加急") == -1)
// newmemo += ("-加急");
entity.IsUrgency = true;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
}
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
{
string odt = commonHelper.getDateFromString(newOtherMemo);
if (odt.Length > 0)
{
entity.OldCustomerTime = Convert.ToDateTime(odt);
}
}
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
{
entity.IsOldCustomer = 0;
}
int oldRes = isOldAndInsertCustomerInfo(father, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2) entity.IsOldCustomerMore = 1;
dealOldCustomerEntityAuto(ref entity);
}
}
if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
{
entity.OrderState = 6;
entity.FinishPlaceTime = DateTime.Now;
entity.SupplierId = 98;//-领鸿
}
if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
{
entity.OrderState = 6;
entity.FinishPlaceTime = DateTime.Now;
entity.SupplierId = 5;//-福广
}
if (ishave)
{
entity.Update();
}
else
{
father.create_time = DateTime.Now;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
CeErpSukuraData.createInfo(entity.ctid, 1);
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "合包推送生成" + entity.seller_memo, entity.OrderState);
}
public static void createNotHeBaoCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, ref decimal hePrice, int totalCount)
{
if (itemMemo.Length <= 0) return;
//itemMemo = "现货-240x50cm-100张-条幅-旗帜布-上打2个孔-辞暮尔尔";
string ctid = "";
string splitTag = "";
if (isMulity && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + totalCount + "+" + orderIndex;
}
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;
if (string.IsNullOrEmpty(entity.OrderSn))
{
//唯一标识
string orderSn = dataHelper.getSaleOrderSn();
if (orderSn != "")
{
entity.OrderSn = orderSn;
}
}
entity.UpdateTime = DateTime.Now;
entity.tid = father.tid;
entity.SplitTag = splitTag;
string[] acclist = itemMemo.Split('-');
bool isXianhuo = false;
if (acclist[0] == "现货")
{
isXianhuo = true;
System.Array.Copy(acclist, 1, acclist, 0, acclist.Length - 1);
System.Array.Resize(ref acclist, acclist.Length - 1);
}
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (entity.IsSample == 1 || entity.IsSample == 2)
{
entity.IsSample = 0;
entity.ptid = "";
}
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
if (entity.IsXianHuo == 1)
{
entity.IsXianHuo = 0;
}
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 ((acclist[3] == "不干胶" || itemMemo.IndexOf("电子稿") != -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.ToDecimal(strPrice);
}
catch (Exception ex)
{
entity.payment = 0;
return;
}
if (acclist.Length >= 8)
{
acclist[7] = acclist[7].Replace("(", "");
acclist[7] = acclist[7].Replace(")", "");
acclist[7] = acclist[7].Replace("(", "");
acclist[7] = acclist[7].Replace(")", "");
entity.MakeSupplier = acclist[7];
acclist[7] = "(" + acclist[7] + ")";
}
}
else
{
entity.payment = father.payment;
if (acclist.Length >= 7)
{
acclist[6] = acclist[6].Replace("(", "");
acclist[6] = acclist[6].Replace(")", "");
acclist[6] = acclist[6].Replace("(", "");
acclist[6] = acclist[6].Replace(")", "");
entity.MakeSupplier = acclist[6];
acclist[6] = "(" + acclist[6] + ")";
}
}
entity.ProductId = getProductIdByName(product);
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)
{
}
else
{
entity.OrderState = 2;
if (entity.ShopId != 0)
{
entity.OrderState = orderAudit(entity.ShopId);
}
if (entity.DesignUserId > 0)
{
entity.OrderState = 3;
}
}
}
if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
{
entity.IsOldCustomer = 1;
if (itemMemo.IndexOf("改稿") != -1)
{
if (entity.payment > 0)
{
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
dealOldCustomerEntityTag(ref entity, father);
}
}
}
else
{
if (entity.payment != 0)
{
entity.OrderState = -1; // Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
entity.WaitDesignTime = DateTime.Now;
entity.FinishPlaceTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
}
}
}
if (mt.IndexOf("铜板纸") != -1)
{
mt = mt.Replace("铜板纸", "铜版纸");
}
entity.Material = mt;
entity.ProductSize = size;
entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
entity.Craft = ct;
entity.pay_time = father.pay_time;
if (itemMemo.IndexOf("电子稿") != -1)
{
entity.isDianziOrder = 1;
}
if (product == "现货手提袋")
{
entity.OrderState = 6;//下单完成
entity.FinishPlaceTime = DateTime.Now;
}
string newmemo = "(" + entity.OrderSn + ")-";
if (isXianhuo)
{
newmemo += "现货-";
entity.IsXianHuo = 1;
}
string newOtherMemo = "";
if (false)
{
newmemo = acclist[2];
newmemo += acclist[0];
newmemo += "-";
newmemo += acclist[1];
newmemo += "(";
newmemo += father.tid;
newmemo += ")";
newmemo += "-";
newmemo += acclist[4];
string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
newmemo += ("-" + sName);
newmemo += ("-" + father.buyer_nick);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (isMulity)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
if (acclist.Length > 7)
{
for (int i = 7; i < acclist.Length; i++)
{
newOtherMemo += acclist[i];
newOtherMemo += "-";
}
}
}
else
{
if (acclist.Length >= 7 && !isMulity)
{
newmemo += acclist[6];
newmemo += "-";
}
if (isMulity && acclist.Length >= 8)
{
newmemo += acclist[7];
newmemo += "-";
}
for (int i = 0; i < acclist.Length; i++)
{
if ((isMulity && i == 6) || i == 5)
{
continue;
}
if ((i >= 7 && !isMulity) || (isMulity && i >= 8))
{
newOtherMemo += acclist[i];
newOtherMemo += "-";
}
else
{
if ((i == 6 && !isMulity) || (isMulity && i == 7))
{
continue;
}
else
newmemo += acclist[i];
if (i != 2 && i != 3)
{
newmemo += "-";
}
}
}
string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
newmemo += (sName);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (itemMemo.IndexOf("顺丰到付") != -1)
{
//if (newmemo.IndexOf("顺丰到付") == -1)
// newmemo += ("-顺丰到付");
entity.IsSF = 2;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
}
else if (itemMemo.IndexOf("顺丰寄付") != -1)
{
//if (newmemo.IndexOf("顺丰寄付") == -1)
// newmemo += ("-顺丰寄付");
entity.IsSF = 1;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
}
if (itemMemo.IndexOf("加急") != -1)
{
//if (newmemo.IndexOf("加急") == -1)
// newmemo += ("-加急");
entity.IsUrgency = true;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
}
}
if (isMulity)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
newmemo = newmemo.Replace("\n", " ");
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
{
string odt = commonHelper.getDateFromString(newOtherMemo);
if (odt.Length > 0)
{
entity.OldCustomerTime = Convert.ToDateTime(odt);
}
}
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
//到了设计那边,就更新memo,状态不设置
}
else
{
if (!(itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1))
{
entity.IsOldCustomer = 0;
}
int oldRes = isOldAndInsertCustomerInfo(father, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2) entity.IsOldCustomerMore = 1;
dealOldCustomerEntityAuto(ref entity);
}
}
if ((entity.ProductId == 27 || entity.ProductId == 52) && entity.IsXianHuo == 1)
{
entity.OrderState = 6;
entity.FinishPlaceTime = DateTime.Now;
entity.SupplierId = 98;//-领鸿
}
if (entity.ProductId == 1971 && entity.IsXianHuo == 1)
{
entity.OrderState = 6;
entity.FinishPlaceTime = DateTime.Now;
entity.SupplierId = 5;//-福广
}
if (ishave)
{
entity.Update();
}
else
{
father.create_time = DateTime.Now;
father.Update();
entity.Create();
CeErpTradeCellExtend.createInfo(entity.ctid, 10, 10);
}
//dataHelper.sendErpTradeCellInfo(new dataSendTradeCellBean(entity, father));
CeErpSukuraData.createInfo(entity.ctid, 1);
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "普通推送生成:" + entity.seller_memo, entity.OrderState);
}
public static void dealOldCustomerEntityTag(ref CeErpTradeCell entity, CeErpTrade father)
{
//UV跟指定店铺
int[] shopList = { 49, 67, 26, 45, 13, 68, 20, 17, 52, 21, 66, 63, 64 };
if (entity.ProductId == 43 || shopList.Contains(entity.ShopId))
{
/**int curHour = DateTime.Now.Hour;
int initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
}
else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
}
else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户改稿单指派特定设计师" + entity.DesignUserId, entity.OrderState);
}
else
{**/
int designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
if (designId != 0)
{
entity.DesignUserId = designId;
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给之前设计师", entity.OrderState);
}
}
}
public static void dealOldCustomerEntityAuto(ref CeErpTradeCell entity)
{
int curHour = DateTime.Now.Hour;
int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
/**if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
}
else if (webConfig.OldCusPart1ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner1);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
}
else if (webConfig.OldCusPart2ShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner2);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户单指派特定设计师" + entity.DesignUserId, entity.OrderState);
}
else
{**/
CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
//这个设计师有上班,有关联此店铺
if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
{
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户单指派" + entity.DesignUserId, entity.OrderState);
}
//}
}
public static void createNewSplitCell(bool isMulity, int orderIndex, string itemMemo, CeErpTrade father, double orderPrice, int totalCount)
{
if (itemMemo.Length <= 0) return;
string ctid = "";
string splitTag = "";
if (isMulity && itemMemo.Length > 2)
{
string preStr = "C" + orderIndex + "_";
ctid = preStr + father.tid;
splitTag = "C" + orderIndex;
}
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;
entity.SplitTag = splitTag;
string[] acclist = itemMemo.Split('-');
if (entity.ShopId == 0)
{
CeErpShop nShop = CeErpShop.GetShopIdByName(father.seller_nick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
}
if (entity.IsSample == 1 || entity.IsSample == 2)
{
entity.IsSample = 0;
}
if (entity.isDianziOrder == 1)
{
entity.isDianziOrder = 0;
}
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 ((acclist[3] == "不干胶" || 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)
{
entity.payment = orderPrice;
if (acclist.Length >= 7)
{
acclist[6] = acclist[6].Replace("(", "");
acclist[6] = acclist[6].Replace(")", "");
acclist[6] = acclist[6].Replace("(", "");
acclist[6] = acclist[6].Replace(")", "");
entity.MakeSupplier = acclist[6];
acclist[6] = "(" + acclist[6] + ")";
}
}
entity.ProductId = getProductIdByName(product);
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)
{
}
else
{
entity.OrderState = 2;
if (entity.ShopId != 0)
{
entity.OrderState = orderAudit(entity.ShopId);
}
if (entity.DesignUserId > 0)
{
entity.OrderState = 3;
}
}
}
if (itemMemo.IndexOf("老客户") != -1 || itemMemo.IndexOf("老顾客") != -1)
{
entity.IsOldCustomer = 1;
if (itemMemo.IndexOf("改稿") != -1)
{
if (entity.payment > 0)
{
//designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId);
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
}
else
{
int designId = Convert.ToInt32(webConfig.PlaceChangeId);
CeErpUser oldGaiPlace = CeErpUser.Get(designId);
if (oldGaiPlace != null && ("," + oldGaiPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldGaiPlace.Person.OnDuty == 1)
{
}
else
{
designId = getOldCusByBuyer(father.buyer_nick, entity.ShopId, entity.ProductId);
}
if (designId != 0)
{
entity.DesignUserId = designId;
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户改稿指派给" + (designId == Convert.ToInt32(webConfig.PlaceChangeId) ? "下单部" : "原设计师"), entity.OrderState);
}
}
}
}
else
{
if (entity.payment != 0)
{
entity.OrderState = 3; // Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id); //下单员
entity.WaitDesignTime = DateTime.Now;
LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部" + entity.DesignUserId, entity.OrderState);
}
}
}
if (mt.IndexOf("铜板纸") != -1)
{
mt = mt.Replace("铜板纸", "铜版纸");
}
entity.Material = mt;
entity.ProductSize = size;
entity.ProductCount = count;//commonHelper.changeCountFromChiness(count);
entity.Craft = ct;
entity.pay_time = father.pay_time;
if (product == "现货手提袋")
{
entity.OrderState = 6;//下单完成
entity.FinishPlaceTime = DateTime.Now;
}
string newmemo = "(" + father.tid + ")-";
string newOtherMemo = "";
if (itemMemo.IndexOf("海报") != -1)
{
newmemo = acclist[2];
newmemo += acclist[0];
newmemo += "-";
newmemo += acclist[1];
newmemo += "(";
newmemo += father.tid;
newmemo += ")";
newmemo += "-";
newmemo += acclist[4];
string sName = getShopSNameByName(father.seller_nick);//获取店铺简称
newmemo += ("-" + sName);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (isMulity)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
if (acclist.Length > 7)
{
for (int i = 7; i < acclist.Length; i++)
{
newOtherMemo += acclist[i];
newOtherMemo += "-";
}
}
}
else
{
if (acclist.Length >= 7)
{
newmemo += acclist[6];
newmemo += "-";
}
for (int i = 0; i < acclist.Length; i++)
{
if (i == 5)
{
continue;
}
if (i >= 7)
{
newOtherMemo += acclist[i];
newOtherMemo += "-";
}
else
{
if (i == 6)
{
continue;
}
else
newmemo += acclist[i];
if (i != 2 && i != 3)
{
newmemo += "-";
}
}
}
string sName = getShopSNameByName(father.seller_nick);
newmemo += (sName);
if (father.buyer_nick.IndexOf("*") < 0)
{
newmemo += ("-" + father.buyer_nick);
}
newmemo += ("-" + father.receiver_state);
if (cusInfo != null)
{
newmemo += ("-" + Convert.ToString(cusInfo["Tb"]));
}
if (itemMemo.IndexOf("顺丰到付") != -1)
{
entity.IsSF = 2;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰到付", entity.OrderState);
}
else if (itemMemo.IndexOf("顺丰寄付") != -1)
{
//if (newmemo.IndexOf("顺丰寄付") == -1)
// newmemo += ("-顺丰寄付");
entity.IsSF = 1;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "顺丰寄付", entity.OrderState);
}
if (itemMemo.IndexOf("加急") != -1)
{
//if (newmemo.IndexOf("加急") == -1)
// newmemo += ("-加急");
entity.IsUrgency = true;
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "加急", entity.OrderState);
}
}
if (isMulity)
{
newmemo += "-[C" + totalCount + "+" + orderIndex + "]";
}
newmemo = newmemo.Replace("\n", " ");
entity.seller_memo = newmemo;
entity.OtherMemo = newOtherMemo;
if (entity.IsOldCustomer == 1 && newOtherMemo.IndexOf("改稿") == -1)
{
string odt = commonHelper.getDateFromString(newOtherMemo);
if (odt.Length > 0)
{
entity.OldCustomerTime = Convert.ToDateTime(odt);
}
}
if (entity.IsOldCustomer == 0)
{
if (entity.OrderState > 2 && entity.DesignUserId > 0)
{
//到了设计那边,就更新memo,状态不设置
}
else
{
int oldRes = isOldAndInsertCustomerInfo(father, entity);
if (oldRes > 0)
{
entity.IsOldCustomer = 1;
if (oldRes == 2) entity.IsOldCustomerMore = 1;
int curHour = DateTime.Now.Hour;
int initSysDesignerId = Convert.ToInt32(webConfig.PlaceOldCusId);
if (webConfig.OldCusPartShopId.IndexOf("," + entity.ShopId + ",") >= 0 && curHour >= 8 && curHour < 17)
{
initSysDesignerId = Convert.ToInt32(webConfig.OldCusPartShopDesigner);
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
}
else
{
CeErpUser oldPlace = CeErpUser.Get(initSysDesignerId);
if (oldPlace != null && ("," + oldPlace.pemShop + ",").IndexOf("," + entity.ShopId + ",") > -1 && oldPlace.Person.OnDuty == 1)
{
entity.OrderState = Convert.ToInt32(OrderState.待设计);
entity.DesignUserId = initSysDesignerId;
entity.WaitDesignTime = DateTime.Now;
}
}
}
}
}
if (ishave)
{
entity.Update();
}
else
{
entity.Create();
}
LogHelper.addLog(entity.ctid, entity.CustomerUserId, "新备注推送生成:" + entity.seller_memo, entity.OrderState);
}
public static int getOldCusByBuyer(string buyer, int shopId, int prodcutId)
{
DateTime nowTime = DateTime.Now;
if (nowTime.Hour >= 17)
{
return 0;
}
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林春鸿下单部设计
{
int designId = Convert.ToInt32(dr["DesignUserId"]);
string sql_user = "select * from view_erpuser where ','+pemShop+',' like '%," + shopId + ",%' and (PostCode='Designer' or PostCode='DesignerMr') and ','+pemDesign+',' like '%," + prodcutId + ",%' and OnDuty=1 and id=" + designId;
DataTable dt_user = CeErpTradeRefund.ExecuteDataset(sql_user).Tables[0];
if (dt_user.Rows.Count > 0)
{
return designId;
}
else
return 0;
}
}
return 0;
}
public static int getProductIdByName(string proName)
{
string dname = proName;
if (dname == "暧心贴")
{
dname = "暖心贴";
}
string sql = "select top 1 * from ce_erpproduct where uuid='" + 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 isOpen=1 and Account='" + account + "'";
DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0];
}
return null;
}
public static string getShopNameByECode(string code)
{
string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
return dt.Rows[0]["ShopName"].ToString();
}
return "";
}
// 时间戳转为C#格式时间
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 trade = CeErpTrade.Get(tObj.refOid);
bool isCreate = false;
if (trade == null)
{
trade = new CeErpTrade();
isCreate = true;
}
//原始单创建
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 = GetNull_tostring(tObj.openBuyerNick);
trade.buyer_id = GetNull_tostring(tObj.openBuyerId);
//trade.adjust_fee = Convert.ToDouble(tObj.adjust_fee);
trade.seller_nick = GetNull_tostring(tObj.openSellerNick);
if (trade.seller_nick == "")
{
trade.seller_nick = getShopNameByECode(trade.posCode);
}
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);
if (trade.seller_nick != "" && trade.pay_time > StampToDateTime("1725120000000"))
{
if (tObj.refType == "TMALL" || tObj.refType == "TB")
{
string[] acclist = tObj.sellerMemo.Split('-');
List list = new List(acclist);
string buyer_nick = "";
if ((trade.seller_memo.IndexOf("logo") != -1 || trade.seller_memo.IndexOf("LOGO") != -1))
{
if (list.Count > 3)
{
buyer_nick = list[3];
}
}
else if (trade.seller_memo.IndexOf("补差") != -1 && list.Count < 6)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else if (trade.seller_memo.IndexOf("默拍单") != -1 && list.Count < 6)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else if (trade.seller_memo.IndexOf("寄样") != -1)
{
if (list.Count > 3)
{
buyer_nick = list[3];
}
}
else if (trade.seller_memo.IndexOf("拿样订单") != -1)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else if (trade.seller_memo.IndexOf("礼物") != -1 && list.Count < 6)
{
if (list.Count > 1)
{
buyer_nick = list[1];
}
}
else
{
if (list.Count > 5)
{
buyer_nick = list[5];
}
}
tObj.sellerMemo = string.Join("-", list);
tObj.sellerMemo = tObj.sellerMemo.Replace("-" + buyer_nick, string.Empty);
trade.buyer_nick = buyer_nick.Replace("+", "-").Replace("#", "logo").Replace("@", "LOGO");
}
}
if (isCreate)
{
trade.Create();
}
else
{
trade.Update();
}
bool isXianhuo = false;
string xianhuoMemo = "(" + trade.tid + ")现货-";
//order表创建
foreach (Api_trade_fullinfo_get_response_Obj.LinesItem item in orderList)
{
bool orderCreate = false;
CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.refOlId);
if (order == null)
{
order = new CeErpTradeOrder();
orderCreate = true;
}
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.picUrl != null)
order.pic_path = item.picUrl;
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) && item.standards.IndexOf("定制") == -1)
{
order.sku_properties_name = item.standards;
order.sku_id = item.refSkuId;
isXianhuo = true;
xianhuoMemo += order.sku_properties_name;
xianhuoMemo += ("-数量:" + order.num + "; ");
}
if (orderCreate)
{
order.Create();
}
else
{
order.Update();
}
}
//if (isXianhuo)
//{
// xianhuoMemo += "-";
// xianhuoMemo += trade.seller_nick;
//}
//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.payment = Convert.ToDouble(tObj.payment);
if (tObj.payTime != null)
{
entity.pay_time = StampToDateTime(tObj.payTime);
}
CeErpShop nShop = CeErpShop.GetShopIdByName(tObj.openSellerNick);
int shopId = 0;
if (nShop != null)
{
shopId = nShop.ID;
}
entity.ShopId = shopId;
if (isXianhuo)
{
entity.OrderState = 6;//现货直接下单完成
entity.seller_memo = xianhuoMemo;
entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
entity.IsXianHuo = 1;
entity.FinishPlaceTime = entity.pay_time;
if (xianhuoMemo.IndexOf("封酒贴") != -1)
{
entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
if (trade.buyer_memo != "")
{
entity.OrderState = 2; //买家有备注的要设计
entity.ProductId = 1;
entity.IsXianHuo = 0;
xianhuoMemo = xianhuoMemo.Replace("现货", "");
xianhuoMemo = xianhuoMemo.Replace(" ", "");
entity.seller_memo = xianhuoMemo;
}
}
else if (xianhuoMemo.IndexOf("喜字贴") != -1)
{
entity.SupplierId = 70; //智涛
}
//if (trade != null)
//{
// trade.seller_memo = xianhuoMemo;
// trade.Update();
//}
}
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 int isOldCustomerOrder(CeErpTrade father)
{
if (father.seller_nick == "") return 0;
CeErpCustomer cusone = null;
cusone = CeErpCustomer.GetByNick(father.buyer_nick);
if (cusone != null)
{
return 1;
}
return 0;
}
public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
{
if (father.seller_nick == "") return 0;
CeErpCustomer cus = null;
cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
if (cus == null)
{
cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
}
int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
//CeErpCustomer cusone = null;
//cusone = CeErpCustomer.GetByNick(father.buyer_nick);
if (cus != null)
{
if (cus.lastbuy_time.ToString() == "") return 0;
if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
//cus.address = Obj.receiver_state + Obj.receiver_city + Obj.receiver_address;
//cus.phone = Obj.receiver_mobile;
cus.buyer_id = father.buyer_id;
int returnNum = 0;
int lastpCount = cus.product_count;
if (cus.lastTid == father.tid)
{
if (pcount != cus.product_count)
{
cus.product_count = pcount;
cus.Update();
}
}
else
{
TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
cus.buyer_nick = father.buyer_nick;
cus.buy_day = Convert.ToInt32(tsday.TotalDays);
cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
cus.buy_count = cus.buy_count + 1;
cus.lastbuy_time2 = cus.lastbuy_time;
cus.lastbuy_time = father.pay_time;
cus.product_count = pcount;
cus.lastTid2 = cus.lastTid;
cus.lastTid = father.tid;
cus.Update();
}
if (cus.buy_day > 1)
{
if (pcount > lastpCount && cus.product_count != 0)
{
cus.isMore = 1;
returnNum = 2;
}
else
returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
}
else
{
returnNum = 0;
}
return returnNum;
}
//else if (cusone != null)
//{
// cusone.seller_nick = father.seller_nick;
// TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cusone.lastbuy_time);
// cusone.buy_day = Convert.ToInt32(tsday.TotalDays);
// cusone.total_fee = cusone.total_fee + Convert.ToDouble(father.payment);
// cusone.buy_count = cusone.buy_count + 1;
// cusone.lastbuy_time2 = cusone.lastbuy_time;
// cusone.lastbuy_time = father.pay_time;
// cusone.product_count = pcount;
// cusone.lastTid2 = cusone.lastTid;
// cusone.lastTid = father.tid;
// cusone.Update();
// return 1;
//}
else
{
try
{
cus = new CeErpCustomer();
cus.buyer_nick = father.buyer_nick;
cus.seller_nick = father.seller_nick;
cus.buyer_id = father.buyer_id;
//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 = father.pay_time;
cus.lastTid = father.tid;
cus.total_fee = Convert.ToDouble(father.payment);
cus.product_count = pcount;
cus.Create();
//StringBuilder sql = new StringBuilder();
//sql.AppendFormat("select * from Sheet2$ where customer_name='{0}' and CHARINDEX(company_name,'{1}')>0 ", father.buyer_nick,father.seller_nick);
//DataTable dt = CeErpTradeCell.ExecuteDataset(sql.ToString()).Tables[0];
//if (dt.Rows.Count > 0)
//{
// return true;
//}
return 0;
}
catch (Exception ex)
{
XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
}
}
return 0;
}
public static void removeOldCustomerInfo(CeErpTrade trade)
{
CeErpCustomer cus = null;
cus = CeErpCustomer.GetByNickAndShop(trade.buyer_nick, trade.seller_nick);
if (cus != null)
{
if (cus.lastTid == trade.tid)
{
if (cus.buy_count > 1)
{
cus.lastTid = cus.lastTid2;
cus.lastbuy_time = cus.lastbuy_time2;
cus.buy_count = cus.buy_count - 1;
cus.Update();
}
else
{
CeErpCustomer.Del(cus.ID);
}
}
}
}
//接收到--新订单生成消息
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);
}
public static int orderAudit(int shopId)
{
try
{
CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
if (ceErpShop == null) return 2;
if (!ceErpShop.orderAudit) return 2;
return -1;
}
catch (Exception ex)
{
return 2;
}
}
public static void autoCell(string tid)
{
if (tid.Length == 0)
{
return;
}
DateTime nowTime = DateTime.Now;
if (nowTime.Hour < 9 || nowTime.Hour > 18)//超出时间
{
return;
}
try
{
string sql = string.Format("select ctid,IsOldCustomer,shopid from view_ErpTradeCell where tid='{0}' and orderstate=2 and productid<>0 and designuserid=0 and payment>0 and isrefund=0 order by IsUrgency desc,pay_time asc;", tid);
DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
if (dt != null && dt.Rows.Count > 0)
{
bool changeBl = false;
//int c = Convert.ToInt32(result);// / 20 + 1;
foreach (DataRow dr in dt.Rows)
{
if (nowTime.Hour > 12 && nowTime.Hour < 17)
{
//这段时间白班晚班平均分配
if (changeBl)
{
changeBl = false;
}
else
{
changeBl = true;
}
}
else
changeBl = false;
string IsOldCustomer = dr["IsOldCustomer"].ToString();
string res = "";
CeErpShop ceErpShop = CeErpShop.Get(dr["shopid"]);
int userId = 0;
if (ceErpShop != null)
{
userId = ceErpShop.UserID;
}
SqlParameter[] sqlParameter = {
new SqlParameter("@inctid", SqlDbType.VarChar,200),
new SqlParameter("@intype", SqlDbType.Int,5),
new SqlParameter("@res", SqlDbType.VarChar, 50) };
sqlParameter[0].Value = dr["ctid"].ToString();
sqlParameter[1].Value = changeBl ? 1 : 0;
sqlParameter[2].Direction = ParameterDirection.Output;
if (IsOldCustomer == "1" && userId == 241)//老客户分给指定部门
{
DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch_day", sqlParameter);
}
else
{
DbHelper.DbConn.ExecuteNonQuery(CommandType.StoredProcedure, "sp_autodispatch", sqlParameter);
}
res = sqlParameter[2].Value.ToString();
}
}
}
catch (Exception ex)
{
XLog.SaveLog(0, tid + "|实时派单错误|" + ex.Message);
}
}
}
}