Exemplo n.º 1
0
func (self *oprPrevSeasonRankCom) Start(peer netfw.IPeer) {

	m := peer.(martinihttp.IMartiniAcceptor).GetInterface()

	m.Get("/seasonrank", sessionauth.LoginRequired, binding.Bind(queryZone{}), func(r render.Render, msg queryZone) {

		var zones []zoneInfo

		dbopr.IterateShowDB(func(name, showname string) {
			zones = append(zones, zoneInfo{
				Name:     name,
				ShowName: showname,
			})
		})

		r.HTML(200, "index", nil)
		r.HTML(200, "seasonrank", zones)

	})

	m.Post("/rankdata", sessionauth.LoginRequired, binding.Bind(queryZone{}), func(r render.Render, msg queryZone) {

		res, err := dbopr.ExecuteSQL(msg.Zone, &dbLastSeason{}, "select $FIELD_NAME$ from tb_last_season")
		if err != nil {
			r.Data(200, []byte(err.Error()))
			return
		}

		r.JSON(200, res)

	})

}
Exemplo n.º 2
0
func (self *oprUserDataCom) Start(peer netfw.IPeer) {

	m := peer.(martinihttp.IMartiniAcceptor).GetInterface()

	m.Get("/userdata", func(r render.Render) {

		var zonesInfo []zoneInfo

		dbopr.IterateShowDB(func(name, showName string) {

			zone := zoneInfo{
				Name:     name,
				ShowName: showName,
			}

			res, err := dbopr.ExecuteSQL(name, &dbZone{}, "select $FIELD_NAME$ from tb_area")
			if err != nil {
				log.Println(err)
			}

			for _, b := range res {
				area := b.(dbZone)
				zone.AreaID = append(zone.AreaID, area.Area_id)
			}

			if len(zone.AreaID) > 0 {
				zonesInfo = append(zonesInfo, zone)
			}

		})

		r.HTML(200, "index", nil)
		r.HTML(200, "userdata", zonesInfo)
	})

	m.Post("/queryuserdata", binding.Bind(queryByZone{}), func(msg queryByZone, r render.Render) {

		table := fmt.Sprintf("tb_rank_%d", msg.Service)

		if !dbopr.IsTableExist(msg.Zone, table) {
			r.Data(200, []byte(fmt.Sprintf("zone(%s) is not exist!", table)))
			return
		}

		maxpage := dbopr.GetRecordPageCount(msg.Zone, table)

		var err error
		var res []interface{}

		if msg.Zone == "db_td2ios" {
			if msg.ID != 0 {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select %s.t_sid, %s.t_imei, %s.t_nickname, %s.t_victory, %s.t_yuxi_value, tb_user.t_password from %s, tb_user where %s.t_sid=tb_user.t_sid and %s.t_sid=%d", table, table, table, table, table, table, table, table, msg.ID)
			} else if msg.IMEI != "" {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select %s.t_sid, %s.t_imei, %s.t_nickname, %s.t_victory, %s.t_yuxi_value, tb_user.t_password from %s, tb_user where %s.t_sid=tb_user.t_sid and %s.t_imei='%s'", table, table, table, table, table, table, table, table, msg.IMEI)
			} else {
				if msg.Page <= 0 {
					msg.Page = 1
				} else if msg.Page > maxpage {
					msg.Page = maxpage
				}
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select %s.t_sid, %s.t_imei, %s.t_nickname, %s.t_victory, %s.t_yuxi_value, tb_user.t_password from %s, tb_user where %s.t_sid=tb_user.t_sid limit %d,%d", table, table, table, table, table, table, table, (msg.Page-1)*100, 100)
			}
		} else {
			if msg.ID != 0 {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select $FIELD_NAME$ from %s where t_sid=%d", table, msg.ID)
			} else if msg.IMEI != "" {
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select $FIELD_NAME$ from where t_imei='%s'", table, msg.IMEI)
			} else {
				if msg.Page <= 0 {
					msg.Page = 1
				} else if msg.Page > maxpage {
					msg.Page = maxpage
				}
				res, err = dbopr.ExecuteSQL(msg.Zone, &dbUserData{}, "select $FIELD_NAME$ from %s limit %d,%d", table, (msg.Page-1)*100, 100)
			}
		}

		if err != nil {
			r.Data(200, []byte(err.Error()))
			return
		}

		info := dataInfo{
			Zone:    msg.Zone,
			Service: msg.Service,
			Page:    msg.Page,
			MaxPage: maxpage,
		}

		for _, v := range res {
			user := v.(dbUserData)
			info.Data = append(info.Data, user)
		}

		r.JSON(200, info)

	})

	m.Post("/userdata", binding.Bind(dbUserData{}), func(msg dbUserData, r render.Render) {

		table := fmt.Sprintf("tb_rank_%d", msg.Service)

		if !dbopr.IsTableExist(msg.Zone, table) {
			r.Data(200, []byte(fmt.Sprintf("zone(%s) is not exist!", table)))
			return
		}

		_, err := dbopr.ExecuteSQL(msg.Zone, &msg, "update %s set $FIELD_EQUN$ where t_sid=%d", table, msg.T_sid)
		if err != nil {
			log.Println(err)
			r.Data(200, []byte(err.Error()))
			return
		}

		if msg.T_password != "" {

			hash := md5.New()
			_, err = hash.Write([]byte(msg.T_password))
			if err != nil {
				r.JSON(200, []byte(err.Error()))
				return
			}

			msg.T_password = hex.EncodeToString(hash.Sum(nil))

			log.Println("update user password:"******"update tb_user set t_password='******' where t_sid=%d", msg.T_password, msg.T_sid)
			if err != nil {
				log.Println(err)
				r.JSON(200, []byte(err.Error()))
				return
			} else {
				r.JSON(200, msg)
				return
			}

		}

		r.JSON(200, "execute success")

	})

	m.Post("/deleteuser", binding.Bind(dbUserData{}), func(msg dbUserData, r render.Render) {

		table := fmt.Sprintf("tb_rank_%d", msg.Service)

		if !dbopr.IsTableExist(msg.Zone, table) {
			r.Data(200, []byte(fmt.Sprintf("zone(%s) is not exist!", table)))
			return
		}

		_, err := dbopr.ExecuteSQL(msg.Zone, nil, "delete from %s where t_sid=%d", table, msg.T_sid)
		if err != nil {
			log.Println(err)
			r.Data(200, []byte(err.Error()))
			return
		}

		_, err = dbopr.ExecuteSQL(msg.Zone, nil, "delete from tb_user where t_sid=%d", msg.T_sid)
		if err != nil {
			log.Println(err)
			r.Data(200, []byte(err.Error()))
			return
		}

		r.JSON(200, "execute success")

	})

}