api.go 5.76 KB
package config

import (
	"apigame/util/util-lx/lxalilog"
	"apigame/util/util-lx/lxconv"
	"apigame/util/util-lx/lxmysql"
	"encoding/json"
	"errors"
	"fmt"
)

type MApiGameConfig struct {
	AppID  string `json:"appid"`
	Secret string `json:"secret"`
	Appkey string `json:"appkey"`
	Name   string `json:"name"`
}

// GetApiGameConfig 获取游戏配置文件
func GetApiGameConfig(gameid string) (data MApiGameConfig, err error) {

	config := lxmysql.QueryCacheConfig{
		SQL:      fmt.Sprintf("select appid,secret,appkey,name from s_game_config where isdel=0 and status=1 and gameid='%s' order by id desc limit 1", gameid),
		DBIndex:  CONST_APIDBINDEX,
		Exexpire: CONST_CACHETIME,
	}

	var datas []MApiGameConfig

	err = lxmysql.QueryWithCache(config, &datas)
	if err != nil {
		lxalilog.Errors(err, lxconv.JsonEncode(config))
		return
	}

	if len(datas) < 1 {
		err = errors.New("no rows")
		lxalilog.Errors(err)
		return
	}

	data = datas[0]

	return
}

type MApiServerConfig struct {
	Egift        MApiServerEgift    `json:"egift"`        //无尽轮换
	Membership   []Membership       `json:"membership"`   //周卡 月卡
	Novicegift   Novicegift         `json:"novicegift"`   // 新手礼包
	PassCheck    []PassCheck        `json:"pass_check"`   //通行证
	Qixi         QixiConfig         `json:"qixi"`         //七夕活动
	Thinkingdata ThinkingdataConfig `json:"thinkingdata"` //数数配置
}

// --------------------------- 无尽轮换礼包配置表 ---------------------------

// MApiServerEgift 无尽轮换礼包配置表
type MApiServerEgift struct {
	Config     []MApiServerEgiftConfig `json:"config"`
	ListLength string                  `json:"list_length"`
	Days       string                  `json:"days"`
	Date       string                  `json:"date"`
}

type MApiServerEgiftConfig struct {
	ID      string `json:"id"`
	Award   string `json:"award"`
	Type    string `json:"type"`
	ShopID  string `json:"shop_id"`
	GroupID string `json:"group_id,omitempty"`
}

// --------------------------- 无尽轮换礼包配置表 ---------------------------

// --------------------------- 周卡 月卡 配置 ---------------------------

type Membership struct {
	Name       string `json:"name"`       //  模式名称
	Days       string `json:"days"`       // 第几天
	Goodid     string `json:"goodid"`     // 商品ID
	Award      string `json:"award"`      // 奖励
	Naturalday string `json:"naturalday"` // 是否自然日
}

// --------------------------- 周卡 月卡 配置 ---------------------------

// --------------------------- 新手 配置 ---------------------------

type Novicegift struct {
	Goodid string `json:"goodid"` // 商品ID
	List   []struct {
		Days  string `json:"days"`  // 第几天
		Award string `json:"award"` // 奖励
	} `json:"list"`
}

// --------------------------- 新手礼包 配置 ---------------------------

type PassCheck struct {
	ID         string `json:"ID"`
	Level      string `json:"Level"`
	GroupId    string `json:"GroupId"`
	GoodId     string `json:"GoodId"`
	Experience string `json:"Experience"`
	AwardFree  string `json:"AwardFree"`
	AwardPay   string `json:"AwardPay"`
	DrawTime   int64  `json:"DrawTime"`
}

// --------------------------- 七夕活动 ---------------------------

type QixiConfig struct {
	ActivityId    string                    `json:"activity_id"`
	StartTime     int64                     `json:"start_time"`
	EndTime       int64                     `json:"end_time"`
	Awards        []QixiConfigAwards        `json:"awards"`
	FalseProgress []QixiConfigFalseProgress `json:"false_progress"`
	Mail          QixiConfigMail            `json:"mail"`
	RankConfig    QixiConfigRankConfig      `json:"rank_config"`
	AlilogName    string                    `json:"alilog_name"`
	AddMax        int64                     `json:"add_max"`
}

type QixiConfigFalseProgress struct {
	Day           string `json:"day"`
	Time          string `json:"time"`
	ChangeLowest  string `json:"change_lowest"`
	ChangeHighest string `json:"change_highest"`
	Must          string `json:"must"`
}

type QixiConfigAwards struct {
	Point       string `json:"point"`
	AwardType   string `json:"award_type"`
	AwardNumber string `json:"award_number"`
	LowLimit    string `json:"low_limit"`
	HighLimit   string `json:"high_limit"`
}

type QixiConfigMail struct {
	Title   string `json:"title"`
	Sender  string `json:"sender"`
	Content string `json:"content"`
	Ex      int64  `json:"ex"`
}

type QixiConfigRankConfig struct {
	MinPoint int64 `json:"min_point"`
}

// --------------------------- 七夕活动 ---------------------------

// --------------------------- 数数配置 ---------------------------

type ThinkingdataConfig struct {
	Appid string `json:"appid"`
	Id    int    `json:"id"`
	Swich struct {
		Engine   int `json:"engine"`
		Order    int `json:"order"`
		Pass     int `json:"pass"`
		Recharge int `json:"recharge"` // 累计充值 开启
	} `json:"switch"`
}

// --------------------------- 数数配置 ---------------------------

// GetApiServerConfig 获取游服务端置文件
func GetApiServerConfig(gameid string, dbindex ...string) (data MApiServerConfig, content string, err error) {

	var dindex = CONST_APIDBINDEX
	if len(dbindex) > 0 {
		dindex = dbindex[0]
	}

	config := lxmysql.QueryCacheConfig{
		SQL:      fmt.Sprintf("select * from s_server_config where gameid='%s' limit 1", gameid),
		DBIndex:  dindex,
		Exexpire: CONST_CACHETIME,
	}

	var datas []struct {
		Content string `json:"content"`
	}

	err = lxmysql.QueryWithCache(config, &datas)
	if err != nil {
		lxalilog.Errors(err, lxconv.JsonEncode(config))
		return
	}

	if len(datas) < 1 {
		err = errors.New("no rows")
		lxalilog.Errors(err)
		return
	}

	if datas[0].Content == "" {
		err = errors.New("content nil")
		lxalilog.Errors(err)
	}

	content = datas[0].Content

	_ = json.Unmarshal([]byte(content), &data)

	return
}