Exemple #1
0
 /// <summary>
 /// 检测看有没有多点登录
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void timer_Tick(object sender, EventArgs e)
 {
     if (EnableRun)
     {
         var api    = new Api.BuyApi("CheckClientCode", "Account", new { ID = userinfo.ID, Code = userinfo.Code });
         var result = api.CreateRequestReturnBuyResult <object>();
         if (result.State != "Success")
         {
             EnableRun = false;
             frmLogin.Show();
             MessageBox.Show("检测到在有你的帐号在别的地方登陆");
         }
     }
 }
        public void UploadTaobao(string path)
        {
            var    fileInfo = new FileInfo(path);
            var    fileName = fileInfo.Name;
            string fileUrl  = null;

            try
            {
                OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponUploadStart, $"代理{dlProxy.PhoneNumber}的{fileName}开始上传");
                Dictionary <string, string> files = new Dictionary <string, string>();
                files.Add("file", path);
                var uploadFileApi = new Api.BuyUploadApi(files);
                fileUrl = uploadFileApi.CreateRequestReturnUrls()[0];
                OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponUploadComplated, $"代理{dlProxy.PhoneNumber}的{fileName}上传完成");
                try
                {
                    OnStateChange(Enums.StateLogType.TaoBaoCouponAddDbStart, $"代理{dlProxy.PhoneNumber}的{fileName}开始处理");
                    var api = new Api.BuyApi("Import", "Taobao", new
                    {
                        UserID = dlProxy.ID,
                        Url    = fileUrl
                    });

                    var result = api.CreateRequestReturnBuyResult <object>();
                    if (result.State == "Success")
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponAddDbComplated, $"代理{dlProxy.PhoneNumber}的{fileName}处理完成");
                    }
                    else
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponAddDbFail, $"代理{dlProxy.PhoneNumber}的{fileName}处理失败");
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        Bll.Buy.LoopCheckCouponUserTemps(dlProxy.ID, Enums.Platform.TaoBao);
                        OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponAddDbComplated, $"代理{dlProxy.PhoneNumber}的{fileName}处理完成");
                    }
                    catch (Exception)
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponDownloadFail, $"{fileName}处理失败");
                        SystemBase.WriteLog($"提交失败 {ex.Message}", "UploadTaobao");
                    }
                }
            }
            catch (Exception ex)
            {
                OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponUploadFail, $"代理{dlProxy.PhoneNumber}的{fileName}上传失败");
                SystemBase.WriteLog($"上传失败 {ex.Message}", "UploadTaobao");
            }
            finally
            {
                try
                {
                    fileInfo.Delete();
                }
                catch (Exception ex)
                {
                    OnStateChange?.Invoke(Enums.StateLogType.TaoBaoCouponDeleteTemp, $"代理{dlProxy.PhoneNumber}的{fileName}缓存文件删除失败");
                }
            }
            Task task = new Task(() =>
            {
                chrome.Load(COUPON_DOWNLOAD_URL);
            });

            task.Start();
        }
Exemple #3
0
        public void LoadCoupon()
        {
            OnStateChange?.Invoke(Enums.StateLogType.MoGuJieGetCouponStart, "开始加载蘑菇街优惠券");
            var cids     = MoGuJie.Method.AllCategory;
            var pageSize = 100;
            var models   = new List <Coupon>();

            foreach (var cid in cids)
            {
                if (!EnableRun)
                {
                    return;
                }

                try
                {
                    //获取第一页
                    var result = mgj.GetItemList(channels, cid, pageNo: 1, pageSize: pageSize);
                    //已经初始化过了,就不往下加载了
                    if (result.Total > 0)
                    {
                        models.AddRange(result.Items);
                        //获取
                        if (!onlyFirstPage)
                        {
                            for (int i = 2; i <= result.TotalPage; i++)
                            {
                                var result2 = mgj.GetItemList(channels, cid, pageNo: i, pageSize: pageSize);
                                models.AddRange(result2.Items);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    SystemBase.WriteLog(ex.Message, "MoGuJie");
                }
            }


            OnStateChange?.Invoke(Enums.StateLogType.MoGuJieGetCouponComplated, "加载蘑菇街优惠券加载完成");
            var dirInfo = new System.IO.DirectoryInfo($"{Config.RuningPath}\\temp");

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
            foreach (var item in channels)
            {
                var pModel   = models.Where(s => s.UserID == item.UserID).ToList();
                var path     = $"{Config.RuningPath}\\temp\\蘑菇街_{item.Name}_{DateTime.Now:yyyyMMddHHmm}.json";
                var fileInfo = new System.IO.FileInfo(path);
                System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(pModel));


                try
                {
                    OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbStart, $"蘑菇街 代理{item.Name} 提交开始");
                    var files = new Dictionary <string, string>();
                    files.Add("file", path);

                    var upload = new Api.BuyUploadApi(files).CreateRequestReturnUrls();
                    var update = new Api.BuyApi("ImportItems", "MoGuJie", new { Url = upload[0] }).CreateRequestReturnBuyResult <object>();

                    if (update.State == "Success")
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbComplated, $"蘑菇街 代理{item.Name} 提交完成");
                        try
                        {
                            System.IO.File.Delete(path);
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbError, update.Message);
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        Bll.Buy.LoopCheckCouponUserTemps(item.UserID, Enums.Platform.MGJ);
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbComplated, $"蘑菇街 代理{item.Name} 提交完成");
                    }
                    catch (Exception)
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponAddDbError, $"蘑菇街 代理{item.Name} 提交超时");
                    }
                }
                finally
                {
                    try
                    {
                        System.IO.File.Delete(path);
                    }
                    catch (Exception ex)
                    {
                        OnStateChange?.Invoke(Enums.StateLogType.MoGuJieCouponDeleteTemp, $"蘑菇街 代理{item.Name} 提交有误");
                    }
                }
            }

            onlyFirstPage = true;

            var task = new Task(() =>
            {
                Thread.Sleep(5 * 60 * 1000);
                mgj.RefeashToken();
                LoadCoupon();
            });

            task.Start();
        }