private async void ItemHub_ItemStockChanged(Top.Tmc.Message msg) { //AppendText(msg.Topic); //AppendText(msg.Content); //页面新增商品后会触发此消息 var def = new { increment = 999999, num = 999999, num_iid = 523021091186 }; var d = JsonConvert.DeserializeAnonymousType(msg.Content, def); var product = await FindProductById(d.num_iid); if (product != null && product.StockQty != d.num) { //更新库存 product.StockQty = d.num; AppDatabase.db.ProductItems.Update(product); BindDGViewProduct(); //await SetItemQty(product); } }
private async void ItemHub_ItemUpshelf(Top.Tmc.Message msg) { //AppendText(msg.Topic); //AppendText(msg.Content); var def = new { num_iid = 522569629924 }; var d = JsonConvert.DeserializeAnonymousType(msg.Content, def); var product = await FindProductById(d.num_iid).ConfigureAwait(false); if (product != null) { AppendText("上架了商品【{0}】", product.ItemName); product.OnUpshelf(AppDatabase.db.ProductItems); } BindDGViewProduct(); }
private async void TradeHub_TradeClose(Top.Tmc.Message msg) { //AppendText(msg.Topic); //AppendText(msg.Content); var definition = new { buyer_nick = "", payment = "", oid = 0L, tid = 0L, type = "guarantee_trade", seller_nick = "" }; //var content = @"{'buyer_nick':'包花呗','payment':'9.56','oid':1316790655492656,'tid':1316790655492656,'type':'guarantee_trade','seller_nick':'红指甲与高跟鞋'}"; var d = JsonConvert.DeserializeAnonymousType(msg.Content, definition); var result = await this.InvokeTask(client.TradeHub.GetTradeStatus, d.tid); if (result.Success) { var trade = AppDatabase.db.TopTrades.FindById(d.tid); if (trade != null) { trade.Status = result.Data; AppDatabase.db.TopTrades.Update(trade); CloseTradeQueue.Enqueue(trade.Tid, CloseTradeIfPossible, OnCloseTradeExecuted); } } }
private async void TradeHub_TradeBuyerPay(Top.Tmc.Message msg) { //AppendText(msg.Topic); //AppendText(msg.Content); //解析内容 var definition = new { buyer_nick = "", payment = "", oid = 0L, tid = 0L, type = "guarantee_trade", seller_nick = "" }; //var content = @"{'buyer_nick':'包花呗','payment':'9.56','oid':1316790655492656,'tid':1316790655492656,'type':'guarantee_trade','seller_nick':'红指甲与高跟鞋'}"; var d = JsonConvert.DeserializeAnonymousType(msg.Content, definition); var trade = (await this.InvokeTask(client.TradeHub.GetTrade, d.tid)).Data; AppDatabase.UpsertTopTrade(trade); var product = AppDatabase.db.ProductItems.FindById(trade.NumIid); if (product == null) { AppendText("忽略非平台商品订单{0}", trade.Tid); return; } var statistic = AppDatabase.db.Statistics.FindById(d.seller_nick) ?? new Statistic { Id = d.seller_nick }; statistic.PayCount++; AppDatabase.db.Statistics.Upsert(statistic, statistic.Id); OnStatisticUpdate(statistic); AppendText("[{0}]交易付款,买家:{1} 创建于{2},付款时间{3}", trade.Tid, trade.BuyerNick, trade.Created.ToString("M月d日 H时m分s秒"), trade.PayTime.Value.ToString("M月d日 H时m分s秒")); CloseTradeQueue.Enqueue(trade.Tid, CloseTradeIfPossible, OnCloseTradeExecuted); }
private async void TradeHub_TradeCreate(Top.Tmc.Message msg) { //AppendText(msg.Topic); //AppendText(msg.Content); //解析内容 var definition = new { buyer_nick = "", payment = "", oid = 0L, tid = 0L, type = "guarantee_trade", seller_nick = "" }; //var content = @"{'buyer_nick':'包花呗','payment':'9.56','oid':1316790655492656,'tid':1316790655492656,'type':'guarantee_trade','seller_nick':'红指甲与高跟鞋'}"; var d = JsonConvert.DeserializeAnonymousType(msg.Content, definition); var trade = (await this.InvokeTask(client.TradeHub.GetTrade, d.tid)).Data; var product = AppDatabase.db.ProductItems.FindById(trade.NumIid); if (product == null) { AppendText("忽略非平台商品订单{0}", trade.Tid); return; } //更新订单列表 AppDatabase.db.TopTrades.Upsert(trade, trade.Tid); AppendText("[{0}]交易创建:买家:{1}", d.tid, d.buyer_nick); //更新统计信息 var statistic = AppDatabase.db.Statistics.FindById(d.seller_nick) ?? new Statistic { Id = d.seller_nick }; statistic.BuyCount++; AppDatabase.db.Statistics.Upsert(statistic, statistic.Id); OnStatisticUpdate(statistic); SuplierInfo supplier = null; if (!string.IsNullOrEmpty(product.SupplierId)) { supplier = product.GetSuplierInfo(); } else { await CheckIfLoginRequired(); using (var wbHelper = new WBHelper(true)) { try { //查找供应商 supplier = await this.InvokeTask(supplierInfo, wbHelper, product.SpuId); if (supplier.profitData != null && supplier.profitData.Any()) { product.OnSupplierInfoUpdate(AppDatabase.db.ProductItems, supplier); } } catch (Exception ex) { AppendException(ex); } } } if (supplier != null && supplier.profitData != null && supplier.profitData.Any()) { //5分钟之前的消息即过期的下单信息不处理 if ((ServerDateTime - trade.Created).TotalMinutes > 5) { AppendText("[{0}/{1}]不拦截过期交易。", trade.Tid, trade.NumIid); return; } var interceptType = AppSetting.UserSetting.Get<string>("拦截模式"); if (interceptType == InterceptMode.无条件拦截模式) { InteceptQueue.Enqueue(new InterceptInfo(supplier, product.SpuId, trade, statistic), InterceptTrade, OnInterceptExecuted); return; } else if (interceptType == InterceptMode.仅拦截亏本交易) { if (supplier.profitMin < 0) { InteceptQueue.Enqueue(new InterceptInfo(supplier, product.SpuId, trade, statistic), InterceptTrade, OnInterceptExecuted); } else AppendText("[{0}/{1}]不拦截-{2}。", trade.Tid, trade.NumIid, interceptType); return; } else if (interceptType == InterceptMode.智能拦截模式) { //若14天内同充值号码 var number = new Regex(@"(?<=号码:|用户名:)(\d{5,12})\b").Match(trade.ReceiverAddress ?? "").Value; if (!string.IsNullOrEmpty(number)) { var countNumUsed = AppDatabase.db.TopTrades.Count(x => x.ReceiverAddress.Contains(number) && x.NumIid == trade.NumIid); if (countNumUsed > 1) { //AppendText("14天内同充值号码拦截,订单ID={0}", trade.Tid); InteceptQueue.Enqueue(new InterceptInfo(supplier, product.SpuId, trade, statistic), InterceptTrade, OnInterceptExecuted); return; } } //14天内同宝贝付款订单大于1 var orderCount = AppDatabase.db.TopTrades.Count(x => x.BuyerNick == trade.BuyerNick && x.NumIid == trade.NumIid); if (orderCount > 1) { //AppendText("14天内同宝贝付款订单大于1拦截,订单ID={0}", trade.Tid); InteceptQueue.Enqueue(new InterceptInfo(supplier, product.SpuId, trade, statistic), InterceptTrade, OnInterceptExecuted); return; } //买家是白名单内买家,不拦截 if (AppSetting.UserSetting.Get("买家白名单", new string[0]).Any(x => x == trade.BuyerNick)) { AppendText("[{0}/{1}]不拦截-{2}。", trade.Tid, trade.NumIid, interceptType); return; } //黑名单买家一律拦截 if (AppSetting.UserSetting.Get<string[]>("买家黑名单", new string[0]).Any(x => x == trade.BuyerNick)) { //AppendText("黑名单买家拦截,订单ID={0}", trade.Tid); InteceptQueue.Enqueue(new InterceptInfo(supplier, product.SpuId, trade, statistic), InterceptTrade, OnInterceptExecuted); return; } //购买数量超过1件的拦截 if (trade.Num > 1) { //AppendText("购买数量超过1件拦截,订单ID={0}", trade.Tid); InteceptQueue.Enqueue(new InterceptInfo(supplier, product.SpuId, trade, statistic), InterceptTrade, OnInterceptExecuted); return; } AppendText("[{0}/{1}]不拦截-{2}。", trade.Tid, trade.NumIid, interceptType); } } else { AppendText("[{0}/{1}]交易商品供应商信息未查询到,不拦截。", trade.Tid, trade.NumIid); } }