关于目前千团大战与我的一些事情

美国空前成功的团购网站Groupon 获得巨大成功后,2010年新春以来 国内团购网站雨后春笋般的出现了,中国互联网领域突然掀起一股“团购网”创业热潮,上演了目前的千团大战。

美团网、拉手、爱赴团、聚划算、米团网、窝窝团、赶团网、团宝网、可可网、七七团、KK团。。。。其中 拉手还获得了风投的亲睐,迅速将团购城市从北京伸向全国各大城市。

本人是在今年4月知道团购这个模式的,起初也想弄一个团购站,但由于要上班,精力有限,还有秒杀网要弄,所以就没有弄团购站了。后来也不知道正在哪看到一个团购导航站点,该站点将其收录的所有团购站的团购信息集中到一块,方便用户查找浏览,我觉得这样挺好,接下来就开始了我的团购网站的开发,为了起个好听的名字,我就叫它"嗨团",是从淘宝网的嗨淘网联想的。

各大有资源、有平台的门户站点也相继建立起团购站点,都来瓜分这个大蛋糕,腾讯QQ团、搜狐爱家团、新浪团、千橡集团的糯米团 等等。最后孰赢孰输,我想很快就能见分晓了。我们拭目以待。

 

如果有兴趣的可以看看我的 嗨团网 域名 http://www.hituan.net/ 只可惜 .com的域名已经被注册了。

从选择前台,到后台简单开发,用了一个晚上的时间,一直弄到凌晨3点半(杯具 第二天上班迟到,被扣了一百多)。

本站的所用到的简单技术:

1、数据缓存 网站自动定时更新

      从数据库读取数据放入cache 记录 并设置过期时间为5分钟后

 

代码
   private   double  createTimeSpan  =   300000 ; // 默认为5分钟
         public   void  ProcessRequest(HttpContext context)
        {
            
if  (System.Web.HttpContext.Current.Cache.Get( " createTime " !=   null )
            {
                DateTime createTime 
=  (DateTime)System.Web.HttpContext.Current.Cache.Get( " createTime " );
                
double .TryParse(System.Configuration.ConfigurationManager.AppSettings[ " createTimeSpan " ].ToString(),  out  createTimeSpan);
                TimeSpan sp 
=  DateTime.Now  -  createTime;
                
if  (sp.TotalMilliseconds  >  createTimeSpan)
                {
                    getItemList();
                }
            }
            
else
            {
                getItemList();
                context.Response.Write(
" refresh " );
            }
        }

 

 

 

  网站前台用Ajax去请求后台文件 每5分钟请求一次(即从API中抓取数据,入库以及更新团购成交量等信息)

      代码:

 

代码
 1      function update() {
 2          $. get ( " UpdateItemList.ashx?rnd= "   +  Math.random()  +   "" ""
 3          function(r) {
 4               if  (r  ==   " refresh " ) {;
 5                  location.href  =  window.location.href
 6              }
 7          })
 8      }
 9      update();
10      setInterval(update,  300000 );          
 

 

 

 

2、图片延时加载

  所有团购图片默认不显示,等网页加载完毕后用jQuery遍历去填充图片

13     if(arrImg!=""){ //arrImg 在后台生成好,已经放到前台了。
14         var arrImg=imgStr.split("|");
15         var imgsrc=new Array();
16         for(var i=0;i<arrImg.length;i++){
17             imgsrc[i]=arrImg[i];
18         }
19         var img=new Image(267,160);
20         $(function(){
21             $('.bigImg').each(function(i){
22                 $(this).get(0).style.display="none";
23                 img.src="uploadfile/"+imgsrc[i];
24                 $(this).attr("src",img.src);
25                 $(this).get(0).style.display="block";
26             });
27         });
28     }

 

3、动态采集所有团购站的API数据

  分析API数据 并入库

    

 

 

 

具体的API格式 可以看这个地方:http://www.hituan.net/API/api.xml

 

从API采集数据入库
         ///   <summary>
        
///  从已知的API获取数据
        
///   </summary>
        
///   <returns></returns>
         protected   void  getItemList()
        {
            DataTable dt 
=   null ;
            
using  (DataSet ds  =  DataAccess.DbHelperSQL.Query( " select distinct API,siteID from tbl_API where ispublic ='1' " ))
            {
                
if  (ds  !=   null   &&  ds.Tables[ 0 ].Rows.Count  >   0 )
                {
                    dt 
=   new  DataTable();
                    dt.Columns.Add(
" siteID " , Type.GetType( " System.Int32 " ));
                    dt.Columns.Add(
" itemURL " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" webSiteName " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" siteUrl " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" city " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" title " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" image " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" startTime " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" endTime " , Type.GetType( " System.String " ));
                    dt.Columns.Add(
" value " typeof ( float ));
                    dt.Columns.Add(
" price " typeof ( float ));
                    dt.Columns.Add(
" rebate " typeof ( float ));
                    dt.Columns.Add(
" bought " , Type.GetType( " System.Int32 " ));
                    
foreach  (DataRow dr  in  ds.Tables[ 0 ].Rows)
                    {
                        
string  api  =  dr[ 0 ].ToString();
                        
string  siteID  =  dr[ 1 ].ToString();
                        
if  ( string .IsNullOrEmpty(api)) {  continue ; }
                        
string  xmlInfo  =  getXmlFileString(api).ToLower();
                        
if  ( string .IsNullOrEmpty(xmlInfo)) {  continue ; }
                        
if  ( ! string .IsNullOrEmpty(xmlInfo))
                        {
                            XmlDocument doc 
=   new  XmlDocument();
                            
try
                            {
                                doc.LoadXml(xmlInfo);
                            }
                            
catch
                            {
                                
continue ;
                            }

                            XmlNodeList nodes 
=  doc.SelectNodes( " /urlset/url " );
                            
if  (nodes  !=   null )
                            {
                                
foreach  (XmlNode node  in  nodes)
                                {
                                    XmlNode NodeItemURL 
=  node.SelectSingleNode( " loc " );
                                    XmlNode NodeWebsite 
=  node.SelectSingleNode( " data/display/website " );
                                    XmlNode NodeSiteUrl 
=  node.SelectSingleNode( " data/display/siteurl " );
                                    XmlNode NodeCity 
=  node.SelectSingleNode( " data/display/city " );
                                    XmlNode NodeTitle 
=  node.SelectSingleNode( " data/display/title " );
                                    XmlNode NodeImage 
=  node.SelectSingleNode( " data/display/image " );
                                    XmlNode NodeStartTime 
=  node.SelectSingleNode( " data/display/starttime " );
                                    XmlNode NodeEndTime 
=  node.SelectSingleNode( " data/display/endtime " );
                                    XmlNode NodeValue 
=  node.SelectSingleNode( " data/display/value " );
                                    XmlNode NodePrice 
=  node.SelectSingleNode( " data/display/price " );
                                    XmlNode NodeRebate 
=  node.SelectSingleNode( " data/display/rebate " );
                                    XmlNode NodeBought 
=  node.SelectSingleNode( " data/display/bought " );

                                    
string  itemURL  =  NodeItemURL.InnerText; // 具体的团购地址 
                                     string  webSiteName  =  NodeWebsite.InnerText;  // 网站名称
                                     string  siteUrl  =  NodeSiteUrl.InnerText; // 具体城市的站点地址
                                     string  city  =  NodeCity.InnerText;  // 城市
                                     string  title  =  NodeTitle.InnerText; // 团购标题
                                     string  image  =  NodeImage.InnerText; // 图片
                                     string  startTime  =  NodeStartTime.InnerText; // 开始时间
                                     string  endTime  =  NodeEndTime.InnerText; // 结束时间
                                     string  value  =  NodeValue.InnerText; /// /原价
                                     decimal  price  =  Decimal.Parse(NodePrice.InnerText.Trim()); // 购买价格
                                     decimal  rebate  =   0 ;
                                    
decimal .TryParse(NodeRebate.InnerText.Trim(),  out  rebate); // 折扣
                                     int  bought  =  Convert.ToInt32(NodeBought.InnerText.Trim()); // 已经购买人数
                                    DataRow drr  =  dt.NewRow();
                                    drr[
" siteID " =  siteID;
                                    drr[
" itemURL " =  itemURL;
                                    drr[
" webSiteName " =  webSiteName;
                                    drr[
" siteUrl " =  siteUrl;
                                    drr[
" city " =  city;
                                    drr[
" title " =  title;
                                    drr[
" image " =  image;
                                    drr[
" startTime " =  startTime;
                                    drr[
" endTime " =  endTime;
                                    drr[
" value " =  value;
                                    drr[
" price " =  price;
                                    drr[
" rebate " =  rebate;
                                    drr[
" bought " =  bought;
                                    dt.Rows.Add(drr);
                                }
                            }
                        }

                    }
                    
double .TryParse(System.Configuration.ConfigurationManager.AppSettings[ " createTimeSpan " ].ToString(),  out  createTimeSpan);
                    System.Web.HttpContext.Current.Cache.Add(
" createTime " , DateTime.Now,  null , DateTime.Now.AddMilliseconds(createTimeSpan), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal,  null );
                    UpdateDataBase(dt);
                }
                
if  (dt  !=   null )
                {
                    dt.Dispose();
                }

            }
          
        }

 

5、首页团片展示 随即动态提取

    随即的从数据库中提取正在团购的信息。

前台展示的方法:

 

代码
 1           private   void  getItemList()
 2          {
 3              DataTable dt  =   null ;
 4               if  (System.Web.HttpContext.Current.Cache.Get( " ItemList " !=   null )
 5              {
 6                  dt  =  (DataTable)System.Web.HttpContext.Current.Cache.Get( " ItemList " );
 7              }
 8               else
 9              {
10                   int  dataGridNum  =   33 ; // 团片展示显示的个数默认为33个
11                   if  (System.Web.HttpContext.Current.Cache.Get( " datagridNum " !=   null )
12                  {
13                      dataGridNum  =  ( int )System.Web.HttpContext.Current.Cache.Get( " datagridNum " );
14                  }
15                   else
16                  {
17                       int .TryParse(System.Configuration.ConfigurationManager.AppSettings[ " datagridNum " ].ToString(),  out  dataGridNum);
18                      System.Web.HttpContext.Current.Cache.Add( " dataGridNum " , dataGridNum.ToString(),  null , DateTime.Now.AddHours( 1 ), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal,  null );
19 
20                  }
21                   string  SQL  =   @" select top  "   +  dataGridNum.ToString()  +   "  list.*,site.sitename  from tbl_itemlist list left join tbl_siteList site on list.siteid=site.id where closeDate>getdate() and picpath<>'' Order By NewID() asc,price asc " ;
22                   using  (DataSet ds  =  DataAccess.DbHelperSQL.Query(SQL))
23                  {
24                       if  (ds  !=   null   &&  ds.Tables[ 0 ].Rows.Count  >   0 )
25                      {
26                          
27                           int  createTimeSpan  =   300000 ; // 5分钟
28                           if  (System.Web.HttpContext.Current.Cache.Get( " createTimeSpan " !=   null )
29                          {
30                              createTimeSpan  =  Convert.ToInt32(System.Web.HttpContext.Current.Cache.Get( " createTimeSpan " ).ToString());
31                          }
32                           else
33                          {
34                               int .TryParse(System.Configuration.ConfigurationManager.AppSettings[ " createTimeSpan " ].ToString(),  out  createTimeSpan);
35                              System.Web.HttpContext.Current.Cache.Add( " createTimeSpan " , createTimeSpan.ToString(),  null , DateTime.Now.AddHours( 1 ), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal,  null );
36                          }
37                          dt  =  ds.Tables[ 0 ];
38                          System.Web.HttpContext.Current.Cache.Add( " ItemList " , ds.Tables[ 0 ],  null , DateTime.Now.AddMilliseconds(createTimeSpan), TimeSpan.Zero, System.Web.Caching.CacheItemPriority.Normal,  null );
39                      }
40                  }
41              }
42               if  (dt  !=   null )
43              {
44                   this .rptItemList.DataSource  =  dt;
45                   this .rptItemList.DataBind();
46                   foreach  (DataRow dr  in  dt.Rows) {
47                      sb.Append(dr[ " PicPath " ].ToString()  +   " | " );
48                  }
49                   if  (sb.Length  <   1 ) {
50                      sb.Append( "   " );
51                  }
52              }
53          }

 

 

 

6、将Unix timestamp 时间戳与目前的时间格式如(2010-10-59 10:59:59)之间的相互转化

    我从有的团购站说 Unix timestamp 与具体的时间之间无法转化

 

代码
        ///   <summary>
        
///  根据时间戳返回团购具体的结束时间
        
///   </summary>
        
///   <param name="timeStamp"></param>
        
///   <returns></returns>
         private   string  getRealTime( string  timeStamp)
        {
            DateTime dtStart 
=  TimeZone.CurrentTimeZone.ToLocalTime( new  DateTime( 1970 1 1 ));
            
long  lTime  =   long .Parse(timeStamp  +   " 0000000 " );
            TimeSpan toNow 
=   new  TimeSpan(lTime);
            
return  dtStart.Add(toNow).ToString( " yyyy-MM-dd hh:mm:ss " );

        }

 

 

代码
         private   string  DateString2TimeSpan( string  DateString)
        {
            
string  querySQL  =   " select datediff(second,'1970/1/1 00:00:00',' "   +  DateString  +   " ')-8*60*60 " ;
            
return  DataAccess.DbHelperSQL.GetSingle(querySQL).ToString();

        }

 

 

 

 

 

 

 

你可能感兴趣的:(关于目前千团大战与我的一些事情)