示例#1
0
        public static bool AddNoteTradeToDB(NotifyTrade trade)
        {
            try
            {
                string query = @"INSERT INTO NotifyTrade(tid,buyer_nick,nick,status,oid,payment,seller_nick,createDate)
                                        VALUES(@tid,@buyer_nick,@nick,@status,@oid,@payment,@seller_nick,getdate())";

                SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@tid", trade.Tid),
                    new SqlParameter("@buyer_nick", trade.BuyerNick),
                    new SqlParameter("@nick", trade.SellerNick),
                    new SqlParameter("@status", trade.Status),
                    new SqlParameter("@oid", trade.Oid),
                    new SqlParameter("@payment", trade.Payment),
                    new SqlParameter("@seller_nick", trade.SellerNick)
                };

                DataBaseTool.ExecuteSql(query, param);
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionReporter.WriteLog(ex, ExceptionPostion.TBApply_Data);
                return(false);
            }
        }
示例#2
0
        public static bool UpdateNoteTradeToDB(NotifyTrade trade)
        {
            try
            {
                string query = @"update NotifyTrade set status = @status,modified = getdate() where tid = @tid";

                SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@tid", trade.Tid),
                    new SqlParameter("@status", trade.Status)
                };

                DataBaseTool.ExecuteSql(query, param);
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionReporter.WriteLog(ex, ExceptionPostion.TBApply_Data);
                return(false);
            }
        }
示例#3
0
        public static bool AddTradeOrderDenfense(NotifyTrade trade)
        {
            try
            {
                string query = @"INSERT INTO NotifyTradeForOrderDefense(tid,buyer_nick,oid,seller_nick)
                                 VALUES(@tid,@buyer_nick,@oid,@seller_nick)";

                SqlParameter[] param = new SqlParameter[]
                {
                    new SqlParameter("@tid", trade.Tid),
                    new SqlParameter("@buyer_nick", trade.BuyerNick),
                    new SqlParameter("@oid", trade.Oid),
                    new SqlParameter("@seller_nick", trade.SellerNick)
                };
                DataBaseTool.ExecuteSql(query, param);
                return(true);
            }
            catch (Exception ex)
            {
                ExceptionReporter.WriteLog(ex, ExceptionPostion.TBApply_Data);
                return(false);
            }
        }
示例#4
0
        public static void Main(string[] args)
        {
            TmcClient client = new TmcClient(appKey, appSecret, "default");

            client.OnMessage += (s, e) =>
            {
                try
                {
                    string status = e.Message.Topic;
                    //将消息进行转换
                    IDictionary obj = TopUtils.ParseJson(e.Message.Content);

                    if (obj != null)
                    {
                        #region //物流信息的处理20160916 yao
                        try
                        {
                            if (obj.Contains("action"))
                            {
                                Console.WriteLine(DateTime.Now.ToString() + ":物流提醒:" + e.Message.Content);
                                LogsticDetailTrace logstic = new LogsticDetailTrace();

                                logstic.Tid  = obj["tid"].ToString();
                                logstic.Desc = obj["desc"].ToString();
                                if (obj.Contains("out_sid"))
                                {
                                    logstic.Out_side = obj["out_sid"].ToString();
                                }
                                logstic.Time = obj["time"].ToString();
                                if (obj.Contains("company_name"))
                                {
                                    logstic.Company_name = obj["company_name"].ToString();
                                }
                                logstic.Action = obj["action"].ToString();
                                if (LogisticsBLL.TidIsExist(logstic.Tid))
                                {
                                    LogisticsBLL.updateLogistics(logstic);
                                }
                                else
                                {
                                    LogisticsBLL.AddLogistics(logstic);
                                }
                            }
                            else
                            {
                                NotifyTrade trade = null;
                                Console.WriteLine(DateTime.Now.ToString() + ":店铺管家订单:" + e.Message.Content);
                                trade            = new NotifyTrade();
                                trade.Tid        = obj["tid"].ToString();
                                trade.BuyerNick  = obj["buyer_nick"].ToString();
                                trade.Status     = status;
                                trade.SellerNick = obj["seller_nick"].ToString();
                                trade.Oid        = obj["oid"].ToString();
                                trade.Payment    = obj["payment"].ToString();
                                if (!DBUtil.CheckNoteTradeIsExit(trade.Tid.ToString()))
                                {
                                    DBUtil.AddNoteTradeToDB(trade);                //物流提醒之用
                                    if (status.Equals("taobao_trade_TradeCreate")) //订单拦截之用
                                    {
                                        DBUtil.AddTradeOrderDenfense(trade);
                                    }
                                }
                                else
                                {
                                    DBUtil.UpdateNoteTradeToDB(trade);
                                }
                            }
                        }
                        catch (Exception e1)
                        {
                            Console.WriteLine(e1.ToString());
                        }
                        #endregion
                    }
                    // 默认不抛出异常则认为消息处理成功
                }
                catch (Exception exp)
                {
                    ExceptionReporter.WriteLog(exp, ExceptionPostion.TBApply_Data);
                    e.Fail(); // 消息处理失败回滚,服务端需要重发
                }
            };
            client.Connect("ws://mc.api.taobao.com/");
            Console.ReadLine();
        }