/*
         * 推荐商家 后台用
         * */
        public JsonResult RecShopListGet(string shopId)
        {
            OleDbConnection mycn = buildConn();
            mycn.Open();
            string condition = "";
            if (!string.IsNullOrEmpty(shopId))
            {
                condition += " and s.shopid= " + shopId + "";
            }

            string sql = "select s.* from shop s,recommend_shop r where 1=1 and r.shopid = s.shopid " + condition;
            OleDbCommand mycm = new OleDbCommand(sql, mycn);
            OleDbDataReader msdr = mycm.ExecuteReader();
            List<RecShop> list = new List<RecShop>();
            while (msdr.Read())
            {
                if (msdr.HasRows)
                {
                    string[] readstring = new string[msdr.FieldCount];
                    for (int i = 0; i < msdr.FieldCount; i++)
                    {
                        if (msdr.IsDBNull(i))
                        {
                            continue;
                        }
                    }
                    RecShop u = new RecShop();
                    u.shopId = (int)msdr["shopid"];
                    u.shopName = msdr.GetString(1);
                    u.introduction = msdr.GetString(2);
                    u.picurl = msdr.GetString(3);
                    u.attention = (int)msdr["attention"];

                    list.Add(u);
                }
            }
            msdr.Close();
            mycn.Close();
            return Json(new { data = list, success = true }, JsonRequestBehavior.AllowGet);
        }
        /*
         * 天天美食、玩乐生活等
         * type为必录项
         */
        public JsonResult ShopNorTypeListGet(string type, string start, string limit)
        {
            OleDbConnection mycn = buildConn();
            mycn.Open();

            if (string.IsNullOrEmpty(type))
            {
                return Json(new { success = false, msg = "传入的type值为空!" }, JsonRequestBehavior.AllowGet);
            }

            string sql = "select s.shopid,s.shopname,s.introduction,s.piclist,s.attention  from shop s where  s.shopid in (select shop_id from shop_type where type_id = " + type + ")";// ) m  left join type f on f.type_id = " + type + "" +" LIMIT " + start + ", " + limit + "";
            OleDbCommand mycm = new OleDbCommand(sql, mycn);
            OleDbDataReader msdr = mycm.ExecuteReader();
            List<RecShop> list = new List<RecShop>();
            while (msdr.Read())
            {
                if (msdr.HasRows)
                {
                    string[] readstring = new string[msdr.FieldCount];
                    for (int i = 0; i < msdr.FieldCount; i++)
                    {
                        if (msdr.IsDBNull(i))
                        {
                            continue;
                        }
                    }
                    RecShop u = new RecShop();
                    u.shopId = Convert.ToInt32(msdr["shopid"]);
                    u.shopName = Convert.ToString(msdr["shopname"]);
                    u.introduction = Convert.ToString(msdr["introduction"]);
                    u.picurl = Convert.ToString(msdr["piclist"]);
                    u.attention = Convert.ToInt32(msdr["attention"]);

                    //u.type = Convert.ToString(msdr["type_name"]);

                    list.Add(u);
                }
            }
            msdr.Close();
            mycn.Close();
            return Json(new { data = list, success = true }, JsonRequestBehavior.AllowGet);
        }
        /*
         * 1会员商家 2新店推荐 3品牌推荐 4胜利特价
         * 店铺列表
         * */
        public JsonResult ShopMidListGet(string type, string start, string limit)
        {
            OleDbConnection mycn = buildConn();
            mycn.Open();
            string condition = "";
            if (!string.IsNullOrEmpty(type))
            {
                condition += " and r.type= '" + type + "'";
            }

            int curPage = (Convert.ToInt16(start) / 10);
            int pag = curPage * Convert.ToInt16(limit);
            string sql = "";
            if (start == "0")
            {
                sql = "select top " + Convert.ToInt16(limit) + " s.*,r.type from shop s,recommend_shop r where 1=1 and r.shopid = s.shopid " + condition + " order by s.shopid desc ";
            }
            else
            {
                sql = "select top " + Convert.ToInt16(limit) + " s.*,r.type from shop s,recommend_shop r where 1=1 and r.shopid = s.shopid " + condition + " and s.shopid not in (select top " + pag + " shopid from shop s,type r where 1=1 and r.shopid= s.shopid " + condition + " ) order by s.shopid desc ";
            }

            OleDbCommand mycm = new OleDbCommand(sql, mycn);
            OleDbDataReader msdr = mycm.ExecuteReader();
            List<RecShop> list = new List<RecShop>();
            while (msdr.Read())
            {
                if (msdr.HasRows)
                {
                    string[] readstring = new string[msdr.FieldCount];
                    for (int i = 0; i < msdr.FieldCount; i++)
                    {
                        if (msdr.IsDBNull(i))
                        {
                            continue;
                        }
                    }
                    RecShop u = new RecShop();
                    u.shopId = Convert.ToInt32(msdr["shopid"]);
                    u.shopName = Convert.ToString(msdr["shopname"]);
                    u.introduction = Convert.ToString(msdr["introduction"]);
                    u.picurl = Convert.ToString(msdr["piclist"]);
                    u.attention = Convert.ToInt32(msdr["attention"]);
                    if (System.DBNull.Value != msdr["type"])
                    {
                        u.type = Convert.ToString(msdr["type"]);
                    }
                    list.Add(u);
                }
            }
            msdr.Close();
            mycn.Close();
            return Json(new { data = list, success = true }, JsonRequestBehavior.AllowGet);
        }
        /*
         * 我的收藏
         * */
        public JsonResult ShopFavorListGet(string userName, string start, string limit)
        {
            OleDbConnection mycn = buildConn();
            mycn.Open();
            string condition = "";
            if (!string.IsNullOrEmpty(userName))
            {
                condition += " and u.username= '******'";
            }

            string sql = "select s.*,r.*,t.type_id from shop s,favorite r,shop_type t,sys_user u where 1=1 and u.id = r.user_id and t.shop_id = s.shopid and r.shop_id = s.shopid " + condition + " order by s.shopid";
            OleDbCommand mycm = new OleDbCommand(sql, mycn);
            OleDbDataReader msdr = mycm.ExecuteReader();
            List<RecShop> list = new List<RecShop>();
            List<RecShop> listResult = new List<RecShop>();
            while (msdr.Read())
            {
                if (msdr.HasRows)
                {
                    string[] readstring = new string[msdr.FieldCount];
                    for (int i = 0; i < msdr.FieldCount; i++)
                    {
                        if (msdr.IsDBNull(i))
                        {
                            continue;
                        }
                    }
                    RecShop u = new RecShop();
                    u.shopId = Convert.ToInt16(msdr["shopid"]);
                    u.shopName = Convert.ToString(msdr["shopname"]);
                    u.introduction = Convert.ToString(msdr["introduction"]);
                    u.picurl = Convert.ToString(msdr["piclist"]);
                    u.attention = Convert.ToInt16(msdr["attention"]);
                    u.type = Convert.ToString((int)msdr["type_id"]);
                    list.Add(u);
                }
            }
            int s = Convert.ToInt16(start);
            int p = Convert.ToInt16(limit);
            if (p > list.Count - s - (p * (s / p)))
            {
                p = list.Count;
            }
            for (int i = s; i < p; i++)
            {
                listResult.Add(list[i]);
            }
            msdr.Close();
            mycn.Close();
            return Json(new { data = listResult, success = true }, JsonRequestBehavior.AllowGet);
        }