예제 #1
0
        /// <summary>
        /// 取分页数据,返回 JSON
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public ActionResult List(int pageindex, int pagesize, string key, string start, string end, string cabh)
        {
            List <Model.Xiazhuinfo> list = dal.GetListArray("*", "id desc", pagesize, pageindex, GetCond(key, start, end, cabh));
            ArrayList arr = new ArrayList();

            foreach (var item in list)
            {
                arr.Add(new
                {
                    id         = item.id,
                    createtime = item.createtime.ToString("yyyy-MM-dd HH:mm:ss"),
                    userid     = item.userid,
                    username   = item.username,
                    czid       = item.czid,
                    czname     = item.czname,
                    wfid       = item.wfid,
                    wfname     = item.wfname,
                    buycode    = item.buycode,
                    beishu     = item.beishu,
                    buymoney   = item.buymoney,
                    remark     = item.remark,
                    qihao      = item.qihao,
                    iszj       = item.iszj,
                    zjmoney    = item.zjmoney,
                    kjcode     = item.kjcode + "",
                    shouxufee  = item.shouxufee,
                    czr        = item.czr,
                    kjtime     = string.IsNullOrEmpty(item.kjcode) ? "" : item.kjtime.ToString("yyyy-MM-dd HH:mm:ss"),
                });
            }
            return(Json(arr));
        }
예제 #2
0
        public async Task <string> InsertKJCodeAsync(bool onlyfirst = false, string url = "http://bwlc.net/bulletin/prevkeno.html")
        {
            var           config  = Configuration.Default.WithDefaultLoader();
            var           address = url;
            StringBuilder sb      = new StringBuilder();

            DAL.XiazhuinfoDAL xzdal = new DAL.XiazhuinfoDAL()
            {
                ConnStr = ConnStr
            };
            DAL.QihaoinfoDAL qhdal = new DAL.QihaoinfoDAL()
            {
                ConnStr = ConnStr
            };
            int    czid   = 1;
            string czname = "北京28";

            #region 北京福彩网的抓取规则
            using (var document = await BrowsingContext.New(config).OpenAsync(address))
            {
                string allhtml = document.QuerySelector("body").InnerHtml;

                //   Util.Log.Info($"开始抓取开奖号,远程返回的HTML:{allhtml} <br /> \r\n");

                var cellSelector = "table.tb tr";
                var cells        = document.QuerySelectorAll(cellSelector);



                foreach (var item in cells)
                {
                    string qihao  = "";
                    string kjcode = "";
                    string kjtime = "";

                    if (item.InnerHtml.Contains("td"))
                    {
                        qihao  = item.QuerySelector("td:nth-child(1)").TextContent;
                        kjcode = item.QuerySelector("td:nth-child(2)").TextContent;
                        kjtime = item.QuerySelector("td:nth-child(4)").TextContent;

                        Model.Qihaoinfo qihaoinfo = qhdal.GetModelByCond($"qihao='{qihao}' and czid={czid}");


                        if (qihaoinfo != null && !string.IsNullOrEmpty(qihaoinfo.kjcode))
                        {
                            sb.Append($"期号:{qihao}<span style='color:red;'>已存在</span><br /> \r\n");
                            if (onlyfirst)
                            {
                                break;
                            }
                            continue;
                        }

                        DateTime d = DateTime.Parse(kjtime);



                        string[]   ss  = kjcode.Split(',');
                        List <int> arr = new List <int>();
                        foreach (var s in ss)
                        {
                            arr.Add(int.Parse(s));
                        }
                        arr.Sort();
                        int    shu1        = arr[0] + arr[1] + arr[2] + arr[3] + arr[4] + arr[5];
                        int    shu2        = arr[6] + arr[7] + arr[8] + arr[9] + arr[10] + arr[11];
                        int    shu3        = arr[12] + arr[13] + arr[14] + arr[15] + arr[16] + arr[17];
                        string real_kjcode = (shu1 % 10 + shu2 % 10 + shu3 % 10).ToString();
                        string remark      = $"{shu1 % 10} + {shu2 % 10} + {shu3 % 10}";

                        if (qihaoinfo == null)
                        {
                            qhdal.Add(new Qihaoinfo()
                            {
                                czid       = czid,
                                czname     = czname,
                                createtime = DateTime.Now,
                                kjtime     = d,
                                starttime  = d.AddMinutes(-5),
                                endtime    = d.AddMinutes(-2),
                                qihao      = qihao,
                                kjcode2    = kjcode,
                                kjcode     = real_kjcode,
                                remark     = remark,
                                code1      = shu1 % 10,
                                code2      = shu2 % 10,
                                code3      = shu3 % 10
                            });
                        }
                        else
                        {
                            //期号存在,开奖号为空,修改
                            qihaoinfo.kjcode  = real_kjcode;
                            qihaoinfo.kjcode2 = kjcode;
                            qihaoinfo.remark  = remark;
                            qihaoinfo.code1   = shu1 % 10;
                            qihaoinfo.code2   = shu2 % 10;
                            qihaoinfo.code3   = shu3 % 10;
                            qhdal.Update(qihaoinfo);
                        }



                        sb.Append($"期号:{qihao},开奖号:{kjcode},开奖时间 :{kjtime} <span style='color:green'>已插入</span><br /> \r\n");

                        #region 兑奖
                        sb.Append($"兑奖结果:<br />\r\n");
                        List <Model.Xiazhuinfo> list_xiazhu = xzdal.GetListArray($"czid=1 and qihao='{qihao}'", "id");
                        foreach (var xz in list_xiazhu)
                        {
                            try
                            {
                                string str = this.DuiJiang(xz.id);
                                //   sb.Append(str + "<br />\r\n");  前台用户也能采集,不显示每张跟单的兑奖结果
                            }
                            catch (Exception ex)
                            {
                                //   sb.Append($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n");
                                //  Util.Log.Error($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n");
                            }
                        }
                        #endregion

                        if (onlyfirst)
                        {
                            break;
                        }
                    }
                }

                //document.Close();
                //document.Dispose();
            }
            #endregion

            #region PC2820.com的抓取规则
            //address = "https://pc2820.com/";
            //using (var document = await BrowsingContext.New(config).OpenAsync(address))
            //{
            //    string allhtml = document.QuerySelector("body").InnerHtml;

            //    //  Util.Log.Info($"开始抓取开奖号,远程返回的HTML:{allhtml} <br /> \r\n");

            //    var firsttable = document.QuerySelector("table"); //第一个表格就是存期号,开奖时间,开奖号的
            //    var trs = firsttable.QuerySelectorAll("tr");
            //    foreach (var onetr in trs)
            //    {
            //        if (onetr.InnerHtml.Contains("td"))
            //        {
            //            string qihao = onetr.QuerySelector("td:nth-child(1)").TextContent;
            //            string kjtime = onetr.QuerySelector("td:nth-child(2)").TextContent;
            //            string remark = onetr.QuerySelector("td:nth-child(3)").TextContent;
            //            string code1 = "";
            //            string code2 = "";
            //            string code3 = "";
            //            string kjcode = "";

            //            Regex reg = new Regex(@"(\d+)\+(\d+)\+(\d+)=(\d+)");
            //            Match m = reg.Match(remark);
            //            if (m.Success)
            //            {
            //                code1 = m.Groups[1].Value;
            //                code2 = m.Groups[2].Value;
            //                code3 = m.Groups[3].Value;
            //                kjcode = m.Groups[4].Value;


            //                //  sb.Append("\r\n期号:" + qihao + ", 开奖时间:" + kjtime + ", 开奖号:" + code1 + " + " + code2 + " + " + code3 + " = " + kjcode);

            //                Model.Qihaoinfo qihaoinfo = qhdal.GetModelByCond($"qihao='{qihao}' and czid={czid}");


            //                if (qihaoinfo != null && !string.IsNullOrEmpty(qihaoinfo.kjcode))
            //                {
            //                    sb.Append($"期号:{qihao} <span style='color:red;'>已存在</span><br /> \r\n");
            //                    if (onlyfirst)
            //                    {
            //                        break;
            //                    }
            //                    continue;
            //                }
            //                DateTime d = DateTime.Parse(kjtime);

            //                if (qihaoinfo == null)
            //                {
            //                    qhdal.Add(new Qihaoinfo()
            //                    {
            //                        czid = czid,
            //                        czname = czname,
            //                        createtime = DateTime.Now,
            //                        kjtime = d,
            //                        starttime = d.AddMinutes(-5),
            //                        endtime = d.AddMinutes(-2),
            //                        qihao = qihao,
            //                        kjcode2 = "",
            //                        kjcode = kjcode,
            //                        remark = remark,
            //                        code1 = int.Parse(code1),
            //                        code2 = int.Parse(code2),
            //                        code3 = int.Parse(code3)
            //                    });
            //                }
            //                else
            //                {
            //                    //期号存在,开奖号为空,修改
            //                    qihaoinfo.kjcode = kjcode;
            //                    qihaoinfo.kjcode2 = "";
            //                    qihaoinfo.remark = remark;
            //                    qihaoinfo.code1 = int.Parse(code1);
            //                    qihaoinfo.code2 = int.Parse(code2);
            //                    qihaoinfo.code3 = int.Parse(code3);
            //                    qhdal.Update(qihaoinfo);

            //                }



            //                sb.Append($"期号:{qihao},开奖号:{kjcode},开奖时间 :{kjtime} <span style='color:green'>已插入</span><br /> \r\n");

            //                #region 兑奖
            //                sb.Append($"兑奖结果:<br />\r\n");
            //                List<Model.Xiazhuinfo> list_xiazhu = xzdal.GetListArray($"czid=1 and qihao='{qihao}'", "id");
            //                foreach (var xz in list_xiazhu)
            //                {
            //                    try
            //                    {
            //                        string str = this.DuiJiang(xz.id);
            //                        //   sb.Append(str + "<br />\r\n");  前台用户也能采集,不显示每张跟单的兑奖结果
            //                    }
            //                    catch (Exception ex)
            //                    {
            //                        //   sb.Append($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n");
            //                        Util.Log.Error($"跟单【{xz.id}】兑奖出错【{ex.Message}】<br />\r\n");
            //                    }
            //                }
            //                #endregion

            //                if (onlyfirst)
            //                {
            //                    break;
            //                }
            //            }


            //        }
            //    }
            //}
            #endregion


            return(sb.ToString());
        }