| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128 |
- package gm
- import (
- "context"
- "encoding/csv"
- "fmt"
- "github.com/gogf/gf/container/glist"
- "github.com/gogf/gf/container/gmap"
- "github.com/gogf/gf/frame/g"
- "github.com/gogf/gf/net/ghttp"
- "github.com/gogf/gf/os/gfile"
- "github.com/gogf/gf/util/gconv"
- "gmanager/library/base"
- "gmanager/library/mongo/gameinfo"
- "gmanager/library/mongo/gm"
- "gmanager/library/mongo/util"
- "gmanager/library/netutil"
- "go.mongodb.org/mongo-driver/bson"
- "go.mongodb.org/mongo-driver/bson/primitive"
- "log"
- "os"
- "strings"
- "time"
- )
- type Action struct {
- base.BaseRouter
- }
- //发送邮件日志列表
- func (action *Action) GetSendMailList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{bson.E{"cmd", "sendmail"}}
- data := g.ListAnyAny{}
- count := gm.ModelSendMailLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- sendMailLogList := gm.ModelSendMailLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for sendMailLogList.Next(context.TODO()) {
- var sendMailLog gm.SendMailLog
- err := sendMailLogList.Decode(&sendMailLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("id", sendMailLog.Id)
- dayMap.Set("userid", sendMailLog.UserId)
- dayMap.Set("servername", sendMailLog.ServerName)
- dayMap.Set("param", sendMailLog.Param)
- dayMap.Set("title", sendMailLog.Title)
- dayMap.Set("content", sendMailLog.Content)
- dayMap.Set("cmd", sendMailLog.Cmd)
- dayMap.Set("updateuser", sendMailLog.UpdateUser)
- st := time.Unix(sendMailLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- dayMap.Set("state", sendMailLog.State)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //全服发送邮件日志列表
- func (action *Action) GetSendMailAllList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{bson.E{"cmd", "sendmailall"}}
- data := g.ListAnyAny{}
- count := gm.ModelSendMailLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- sendMailLogList := gm.ModelSendMailLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for sendMailLogList.Next(context.TODO()) {
- var sendMailLog gm.SendMailLog
- err := sendMailLogList.Decode(&sendMailLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("id", sendMailLog.Id)
- dayMap.Set("servername", sendMailLog.ServerName)
- dayMap.Set("param", sendMailLog.Param)
- dayMap.Set("title", sendMailLog.Title)
- dayMap.Set("content", sendMailLog.Content)
- dayMap.Set("cmd", sendMailLog.Cmd)
- dayMap.Set("updateuser", sendMailLog.UpdateUser)
- st := time.Unix(sendMailLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- dayMap.Set("state", sendMailLog.State)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //保存邮件日志
- func (action *Action) SaveMailLog(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- cmdStr := form.Params["cmdStr"]
- serverid := form.Params["serverid"]
- if serverid == "" {
- base.Fail(r, "请选择服务器")
- }
- userid := form.Params["userid"]
- if cmdStr == "sendmail" && userid == "" {
- base.Fail(r, "请输入用户uid")
- }
- useridArray := strings.Split(userid,"#")
- param := form.Params["param"]
- if param == "" {
- base.Fail(r, "请输入参数")
- }
- title := form.Params["title"]
- if title == "" {
- base.Fail(r, "请输入标题")
- }
- content := form.Params["content"]
- if content == "" {
- base.Fail(r, "请输入内容")
- }
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常,"+serverid)
- }
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- servername := serverInfo.Name
- data := g.ListAnyAny{}
- dayMap := gmap.New()
- for _,uid := range useridArray {
- //保存日志
- sendmail := new(gm.SendMailLog)
- sendmail.Id = primitive.NewObjectID()
- if cmdStr == "sendmail" {
- sendmail.UserId = gconv.String(uid)
- }
- sendmail.ServerId = gconv.String(serverid)
- sendmail.ServerName = gconv.String(servername)
- sendmail.GMIp = gconv.String(gmip)
- sendmail.GMPort = gconv.String(gmport)
- sendmail.Param = gconv.String(param)
- sendmail.Title = gconv.String(title)
- sendmail.Content = gconv.String(content)
- sendmail.Cmd = gconv.String(cmdStr)
- username := base.GetUser(r).Username
- sendmail.UpdateUser = username
- sendmail.UpdateTime = time.Now().Unix()
- sendmail.State = 2 //刚保存为发送中 30s后执行发送;邮件状态:0:未发送 1:已发送 2:发送中 3:发送失败
- gm.ModelSendMailLog.InsertOne(sendmail)
- dayMap.Set("id",sendmail.Id)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- base.Resp(r, 0, "保存成功", data)
- }
- //修改邮件
- func (action *Action) UpdateMail(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- data := gconv.Map(form.Params["data"])
- gm.ModelSendMailLog.InsUpdate(gconv.String(data["id"]), gconv.Int(data["state"]))
- base.Resp(r, 0, "操作成功", nil)
- }
- //发送邮件
- func (action *Action) SendMail(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- _dataId := gconv.Map(form.Params["dataId"])
- for _ , id := range _dataId {
- _data := gconv.Map(id)
- dataId := gconv.String(_data["id"])
- obj_id, _ := primitive.ObjectIDFromHex(dataId)
- data := gm.ModelSendMailLog.FindOne("_id", obj_id)
- var sendMailLog gm.SendMailLog
- err := data.Decode(&sendMailLog)
- if err != nil {
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "当前数据有误", nil)
- }
- cmdStr := sendMailLog.Cmd
- serverid := sendMailLog.ServerId
- userid := ""
- if cmdStr == "sendmail" {
- userid = sendMailLog.UserId
- }
- param := sendMailLog.Param
- title := sendMailLog.Title
- content := sendMailLog.Content
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err = singleResult.Decode(&serverInfo)
- if err != nil {
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "查询服务器信息出现异常", nil)
- }
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- ages := param + "@#" + title + "@#" + content
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- UserId: userid,
- Args: ages,
- }
- res := int32(-1)
- if (cmdStr == "sendmail") {
- res = cmd.SendGM() //0 成功
- } else if (cmdStr == "sendmailall") {
- res = cmd.SendGMAll() //0 成功
- } else {
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "当前数据有误", nil)
- }
- if res == -100 {
- // 修改日志状态为发送失败
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "thrift打开服务器socket出错", nil)
- } else if res == 0 {
- // 修改日志状态为已发送
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 1)
- } else {
- gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "发送失败", nil)
- }
- }
- base.Resp(r, 0, "发送成功", nil)
- }
- //全服发送邮件
- func (action *Action) SendMailAll(r *ghttp.Request) {
- const cmdStr = "sendmailall"
- form := base.NewForm(r.GetMap())
- serverid := form.Params["serverid"]
- if serverid == "" {
- base.Fail(r, "请选择服务器")
- }
- param := form.Params["param"]
- if param == "" {
- base.Fail(r, "请输入参数")
- }
- title := form.Params["title"]
- if title == "" {
- base.Fail(r, "请输入标题")
- }
- content := form.Params["content"]
- if content == "" {
- base.Fail(r, "请输入内容")
- }
- ages := param + "@#" + title + "@#" + content
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- servername := serverInfo.Name
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常,"+serverid)
- }
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- Args: ages,
- }
- res := cmd.SendGMAll() //0 成功
- if res == -100 {
- base.Resp(r, 1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- base.Resp(r, 1, "thrift打开服务器socket出错", nil)
- }
- //保存日志
- sendmail := new(gm.SendMailLog)
- sendmail.Id = primitive.NewObjectID()
- sendmail.ServerId = gconv.String(serverid)
- sendmail.ServerName = gconv.String(servername)
- sendmail.GMIp = gconv.String(gmip)
- sendmail.GMPort = gconv.String(gmport)
- sendmail.Param = gconv.String(param)
- sendmail.Title = gconv.String(title)
- sendmail.Content = gconv.String(content)
- sendmail.Cmd = gconv.String(cmdStr)
- username := base.GetUser(r).Username
- sendmail.UpdateUser = username
- sendmail.UpdateTime = time.Now().Unix()
- insertOne := gm.ModelSendMailLog.InsertOne(sendmail)
- fmt.Println(serverid, servername, gmip, gmport, param, title, content, cmdStr, username, time.Now().Unix())
- fmt.Println("insertOne.InsertedID==============", insertOne.InsertedID)
- if res == 0 {
- base.Resp(r, 0, "发送成功", nil)
- } else {
- base.Resp(r, 1, "发送失败", nil)
- }
- }
- //查询用户充值记录
- func (action *Action) GetRechargeInfoList(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- serverid := form.Params["serverid"]
- if serverid == "" {
- base.Fail(r, "请选择服务器")
- }
- userid := form.Params["userid"]
- if userid == "" {
- base.Fail(r, "请输入用户id")
- }
- page := g.ListAnyAny{}
- bs := bson.D{bson.E{"_id", gconv.Int32(userid)}}
- rechargeInfoRes := gm.ModelRechargeInfo.FindRechargeInfo(bs, serverid)
- var showsWithInfo []bson.M
- if err := rechargeInfoRes.All(context.TODO(), &showsWithInfo); err != nil {
- fmt.Println(err)
- }
- if showsWithInfo == nil {
- base.Fail(r, "该用户不存在")
- return
- }
- playerManager := showsWithInfo[0]["playerManager"]
- playerManagerMap := gconv.Map(playerManager)
- res := gconv.Map(playerManagerMap["rechargeInfo"])
- dayMap := gmap.New()
- dayMap.Set("userid", userid)
- dayMap.Set("servername", serverid)
- dayMap.Set("saveAmt", res["saveAmt"])
- dayMap.Set("soulCrystalAmt", res["soulCrystalAmt"])
- dayMap.Set("monthSaveAmt", res["monthSaveAmt"])
- dayMap.Set("smonthSaveAmt", res["smonthSaveAmt"])
- dayMap.Set("isFirst", res["isFirst"])
- var timeLayoutStr = "2006-01-02 15:04:05"
- st := time.Unix(gconv.Int64(res["createTime"])/1000, 0).Format(timeLayoutStr)
- dayMap.Set("createTime", st)
- dayMap.Set("isDayFirst", res["isDayFirst"])
- page = append(g.ListAnyAny{gconv.Map(dayMap)}, page...)
- base.Succ(r,
- g.Map{
- "page": form.Page,
- "rows": page,
- "total": form.TotalPage,
- "records": form.TotalSize,
- })
- }
- func (action *Action) Pay(r *ghttp.Request) {
- const cmdStr = "pay"
- form := base.NewForm(r.GetMap())
- serverid := form.Params["serverid"]
- if serverid == "" {
- base.Fail(r, "请选择服务器")
- }
- userid := form.Params["userid"]
- if userid == "" {
- base.Fail(r, "请输入userid")
- }
- payid := form.Params["payid"]
- if payid == "" {
- base.Fail(r, "请输入payid")
- }
- ages := payid
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- servername := serverInfo.Name
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常,"+serverid)
- }
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- UserId: userid,
- Args: ages,
- }
- res := cmd.SendGM() //0 成功
- if res == -100 {
- base.Resp(r, 1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- base.Resp(r, 1, "thrift打开服务器socket出错", nil)
- }
- //保存日志
- payLog := new(gm.PayLog)
- payLog.Id = primitive.NewObjectID()
- payLog.UserId = gconv.String(userid)
- payLog.PayId = gconv.String(payid)
- payLog.ServerId = gconv.String(serverid)
- payLog.ServerName = gconv.String(servername)
- payLog.GMIp = gconv.String(gmip)
- payLog.GMPort = gconv.String(gmport)
- payLog.Cmd = gconv.String(cmdStr)
- username := base.GetUser(r).Username
- payLog.UpdateUser = username
- payLog.UpdateTime = time.Now().Unix()
- gm.ModelPayLog.InsertOne(payLog)
- fmt.Println(userid, serverid, servername, gmip, gmport, payid, cmdStr, username, time.Now().Unix())
- if res == 0 {
- base.Resp(r, 0, "充值成功", nil)
- } else {
- base.Resp(r, 1, "充值失败", nil)
- }
- }
- //充值日志列表
- func (action *Action) GetPayLogList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- //bs := bson.D{bson.E{"cmd", "pay"}}
- bs := bson.D{{}}
- data := g.ListAnyAny{}
- count := gm.ModelPayLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- payLogList := gm.ModelPayLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for payLogList.Next(context.TODO()) {
- var payLog gm.PayLog
- err := payLogList.Decode(&payLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("servername", payLog.ServerName)
- dayMap.Set("userid", payLog.UserId)
- dayMap.Set("payid", payLog.PayId)
- dayMap.Set("cmd", payLog.Cmd)
- dayMap.Set("updateuser", payLog.UpdateUser)
- st := time.Unix(payLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //查询CreatCdk列表
- func (action *Action) GetCreatCdkList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{{}}
- data := g.ListAnyAny{}
- count := gm.ModelCreatcdkLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- creatcdkLogList := gm.ModelCreatcdkLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for creatcdkLogList.Next(context.TODO()) {
- var creatcdkLog gm.CreatcdkLog
- err := creatcdkLogList.Decode(&creatcdkLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("infoid", creatcdkLog.InfoId)
- dayMap.Set("ctype", creatcdkLog.Ctype)
- dayMap.Set("reward", creatcdkLog.Reward)
- dayMap.Set("title", creatcdkLog.Title)
- dayMap.Set("contetnt", creatcdkLog.Contetnt)
- dayMap.Set("channelname", creatcdkLog.ChannelName)
- dayMap.Set("cmd", creatcdkLog.Cmd)
- dayMap.Set("updateuser", creatcdkLog.UpdateUser)
- st := time.Unix(creatcdkLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- func (action *Action) CreatCdk(r *ghttp.Request) {
- const cmdStr = "creatcdk"
- form := base.NewForm(r.GetMap())
- ctype := form.Params["ctype"]
- if ctype == "" {
- base.Fail(r, "请选择类型")
- }
- reward := form.Params["reward"]
- if reward == "" {
- base.Fail(r, "请输入奖励")
- }
- title := form.Params["title"]
- if title == "" {
- base.Fail(r, "请输入邮件标题")
- }
- contetnt := form.Params["contetnt"]
- if contetnt == "" {
- base.Fail(r, "请输入邮件内容")
- }
- channelname := form.Params["channelname"]
- if channelname == "" {
- base.Fail(r, "请输入CDK标识")
- } else if len(channelname) != 3 {
- base.Fail(r, "长度只允许为3个字符")
- }
- ages := ctype + " " + reward + " " + title + " " + contetnt + " " + channelname
- singleResult := gameinfo.ModelServer.FindOne("_id", 1) //取1服
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- servername := serverInfo.Name
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常")
- }
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- Args: ages,
- }
- res := cmd.Creatcdk()
- if res == -100 {
- base.Resp(r, 1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- base.Resp(r, 1, "thrift打开服务器socket出错", nil)
- }
- //保存日志
- creatcdkLog := new(gm.CreatcdkLog)
- singleResult1 := gm.ModelCdkAddInfo.FindOne("goods_channel", channelname)
- var cdkAddInfo gm.CdkAddInfo
- err1 := singleResult1.Decode(&cdkAddInfo)
- if err1 != nil {
- base.Fail(r, "查询出现异常")
- }
- creatcdkLog.Id = primitive.NewObjectID()
- creatcdkLog.InfoId = cdkAddInfo.Id
- creatcdkLog.ServerId = gconv.String(1)
- creatcdkLog.ServerName = servername
- creatcdkLog.Ctype = ctype
- creatcdkLog.Reward = reward
- creatcdkLog.Title = title
- creatcdkLog.Contetnt = contetnt
- creatcdkLog.ChannelName = channelname
- creatcdkLog.Cmd = gconv.String(cmdStr)
- username := base.GetUser(r).Username
- creatcdkLog.UpdateUser = username
- creatcdkLog.UpdateTime = time.Now().Unix()
- gm.ModelCreatcdkLog.InsertOne(creatcdkLog)
- base.Resp(r, 0, "执行完成", nil)
- }
- //获取Cdkinfo列表
- func (action *Action) GetCdkIdList(r *ghttp.Request) {
- list := glist.New()
- bs := bson.D{}
- creatcdkLogList := gm.ModelCdkAddInfo.FindServerInfoList(bs)
- for creatcdkLogList.Next(context.TODO()) {
- dayMap := gmap.New()
- var cdkAddInfo gm.CdkAddInfo
- err := creatcdkLogList.Decode(&cdkAddInfo)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("id", cdkAddInfo.Id)
- dayMap.Set("channelName", cdkAddInfo.GoodsChannel)
- list.PushFront(dayMap)
- }
- base.Succ(r, list)
- }
- //查询CreatCdk列表
- func (action *Action) GetCreatCdkCodeList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{{}}
- data := g.ListAnyAny{}
- count := gm.ModelCreatcdkCodeLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- creatcdkCodeLogList := gm.ModelCreatcdkCodeLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for creatcdkCodeLogList.Next(context.TODO()) {
- var creatcdkCodeLog gm.CreatcdkCodeLog
- err := creatcdkCodeLogList.Decode(&creatcdkCodeLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("cdkid", creatcdkCodeLog.CdkId)
- dayMap.Set("cdknum", creatcdkCodeLog.CdkNum)
- dayMap.Set("tick", creatcdkCodeLog.Tick)
- dayMap.Set("cmd", creatcdkCodeLog.Cmd)
- dayMap.Set("updateuser", creatcdkCodeLog.UpdateUser)
- st := time.Unix(creatcdkCodeLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- func (action *Action) CreatCdkCode(r *ghttp.Request) {
- const cmdStr = "creatcdkcode"
- form := base.NewForm(r.GetMap())
- cdkid := form.Params["cdkid"]
- if cdkid == "" {
- base.Fail(r, "请选择CDKID")
- }
- cdknum := form.Params["cdknum"]
- if cdknum == "" {
- base.Fail(r, "请输入数量")
- }
- nowtime := time.Now().Unix()
- ages := cdkid + " " + cdknum + " " + gconv.String(nowtime)
- singleResult := gameinfo.ModelServer.FindOne("_id", 1) //取1服
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常")
- }
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- Args: ages,
- }
- res := cmd.Creatcdk()
- if res == -100 {
- base.Resp(r, 1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- base.Resp(r, 1, "thrift打开服务器socket出错", nil)
- }
- //保存日志
- var creatcdkCodeLog gm.CreatcdkCodeLog
- creatcdkCodeLog.Id = primitive.NewObjectID()
- creatcdkCodeLog.CdkId = gconv.Int(cdkid)
- creatcdkCodeLog.CdkNum = gconv.Int(cdknum)
- creatcdkCodeLog.Tick = nowtime
- creatcdkCodeLog.Cmd = gconv.String(cmdStr)
- username := base.GetUser(r).Username
- creatcdkCodeLog.UpdateUser = username
- creatcdkCodeLog.UpdateTime = time.Now().Unix()
- gm.ModelCreatcdkCodeLog.InsertOne(creatcdkCodeLog)
- base.Resp(r, 0, "执行完成", nil)
- }
- func (action *Action) DownloadCdk(r *ghttp.Request) {
- ticke := r.GetString("ticke")
- singleResult := gm.ModelCdkInfo.FindAll("ticke", gconv.String(ticke))
- fileName := "CDK_" + gconv.String(time.Now().Unix()) + ".txt"
- file, err := gfile.Create(fileName)
- if err != nil {
- fmt.Println("open file is failed, err: ", err.Error())
- }
- // 写入UTF-8 BOM,防止中文乱码
- file.WriteString("\xEF\xBB\xBF")
- w := csv.NewWriter(file)
- for singleResult.Next(context.TODO()) {
- var cdkInfo gm.CdkInfo
- err := singleResult.Decode(&cdkInfo)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- w.Write([]string{cdkInfo.Id})
- // 刷新缓冲
- w.Flush()
- }
- r.Response.ServeFileDownload(fileName)
- file.Close()
- //删除生成的文件
- os.Remove("./" + fileName)
- }
- //查询禁言列表
- func (action *Action) GetSilenceList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{{}}
- data := g.ListAnyAny{}
- count := gm.ModelSilence.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- silenceLogList := gm.ModelSilence.GetPageList(bs, page)
- dayMap := gmap.New()
- for silenceLogList.Next(context.TODO()) {
- var silenceLog gm.SilenceLog
- err := silenceLogList.Decode(&silenceLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("uid", silenceLog.Uid)
- dayMap.Set("serverName", silenceLog.ServerName)
- dayMap.Set("stype", silenceLog.Stype)
- dayMap.Set("cmd", silenceLog.Cmd)
- dayMap.Set("updateuser", silenceLog.UpdateUser)
- st := time.Unix(silenceLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //禁言
- func (action *Action) SetSilence(r *ghttp.Request) {
- const cmdStr = "silence"
- form := base.NewForm(r.GetMap())
- serverid := form.Params["serverid"]
- if serverid == "" {
- base.Fail(r, "请选择服务器")
- }
- userid := form.Params["userid"]
- if userid == "" {
- base.Fail(r, "请输入用户id")
- }
- stype := form.Params["stype"]
- if stype == "" {
- base.Fail(r, "请选择禁言类型")
- }
- ages := userid + " " + stype
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- servername := serverInfo.Name
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常,"+serverid)
- }
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- Args: ages,
- }
- fmt.Println(cmd)
- res := cmd.Creatcdk() //0 成功
- if res == -100 {
- base.Resp(r, 1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- base.Resp(r, 1, "thrift打开服务器socket出错", nil)
- }
- //保存日志
- var silenceLog gm.SilenceLog
- silenceLog.Id = primitive.NewObjectID()
- silenceLog.ServerId = serverid
- silenceLog.ServerName = servername
- silenceLog.Uid = gconv.Int(userid)
- silenceLog.Stype = gconv.Int(stype)
- silenceLog.Cmd = gconv.String(cmdStr)
- silenceLog.UpdateUser = base.GetUser(r).Username
- silenceLog.UpdateTime = time.Now().Unix()
- gm.ModelSilence.InsertOne(silenceLog)
- if res == 0 {
- base.Resp(r, 0, "发送成功", nil)
- } else {
- base.Resp(r, 1, "发送失败", nil)
- }
- }
- // 坦克评论列表
- func (action *Action) HeroCommentList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{{}}
- if form.Params != nil {
- if form.Params["uid"] != "" {
- bs1 := bson.E{"uid", form.Params["uid"]}
- bs = append(bs, bs1)
- }
- if form.Params["heroId"] != "" {
- bs1 := bson.E{"heroId", gconv.Int32(form.Params["heroId"])}
- bs = append(bs, bs1)
- }
- }
- data := g.ListAnyAny{}
- count := gm.ModelHeroComment.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- heroCommentList := gm.ModelHeroComment.GetPageList(bs, page)
- dayMap := gmap.New()
- for heroCommentList.Next(context.TODO()) {
- var heroComment gm.HeroComment
- err := heroCommentList.Decode(&heroComment)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("serverId", heroComment.ServerId)
- dayMap.Set("heroId", heroComment.HeroId)
- dayMap.Set("uid", heroComment.Uid)
- dayMap.Set("uName", heroComment.UName)
- dayMap.Set("content", heroComment.Content)
- dayMap.Set("likes", heroComment.Likes)
- st := time.Unix(heroComment.Time, 0).Format(timeLayoutStr)
- dayMap.Set("time", st)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //禁言英雄评论
- func (action *Action) SetSilenceHeroComment(r *ghttp.Request) {
- const cmdStr = "silence_herocomment"
- serverId := r.GetString("serverId")
- uid := r.GetString("uid")
- stype := r.GetString("stype") // 0解除禁言 1删除记录并设置禁言
- ages := uid + " " + stype
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("server_id", serverId)
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常," + serverId)
- }
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- Args: ages,
- }
- fmt.Println(cmd)
- res := cmd.Creatcdk() //0 成功
- if res == -100 {
- base.Resp(r, 1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- base.Resp(r, 1, "thrift打开服务器socket出错", nil)
- }
- if (stype == "1") {
- // 删除英雄评论
- gm.ModelHeroComment.DeleteMany("uid", uid)
- }
- // 保存日志
- var heroCommentLog gm.HeroCommentLog
- heroCommentLog.Id = primitive.NewObjectID()
- heroCommentLog.ServerId = serverInfo.ServerId
- heroCommentLog.ServerName = serverInfo.Name
- heroCommentLog.Uid = uid
- heroCommentLog.Stype = gconv.Int(stype)
- heroCommentLog.Cmd = cmdStr
- heroCommentLog.UpdateUser = base.GetUser(r).Username
- heroCommentLog.UpdateTime = time.Now().Unix()
- gm.ModelHeroCommentLog.InsertOne(heroCommentLog)
- if res == 0 {
- base.Resp(r, 0, "操作成功", nil)
- } else {
- base.Resp(r, 1, "操作失败", nil)
- }
- }
- // 坦克评论日志列表
- func (action *Action) HeroCommentLogList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{{}}
- data := g.ListAnyAny{}
- count := gm.ModelHeroCommentLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- heroCommentLogList := gm.ModelHeroCommentLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for heroCommentLogList.Next(context.TODO()) {
- var heroCommentLog gm.HeroCommentLog
- err := heroCommentLogList.Decode(&heroCommentLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("uid", heroCommentLog.Uid)
- dayMap.Set("serverId", heroCommentLog.ServerId)
- dayMap.Set("serverName", heroCommentLog.ServerName)
- dayMap.Set("type", heroCommentLog.Stype)
- dayMap.Set("cmd", heroCommentLog.Cmd)
- dayMap.Set("updateuser", heroCommentLog.UpdateUser)
- st := time.Unix(heroCommentLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //发送道具日志列表
- func (action *Action) GetSendModifyItemList(r *ghttp.Request) {
- var timeLayoutStr = "2006-01-02 15:04:05"
- form := base.NewForm(r.GetMap())
- bs := bson.D{bson.E{"cmd", "modifyitem"}}
- data := g.ListAnyAny{}
- count := gm.ModelModifyItemLog.GetListCount(bs)
- page := util.Page{
- PageSize: gconv.Int64(form.Rows),
- CurrentPage: gconv.Int64(form.Page),
- Total: gconv.Int64(count),
- }
- sendModifyItemLogList := gm.ModelModifyItemLog.GetPageList(bs, page)
- dayMap := gmap.New()
- for sendModifyItemLogList.Next(context.TODO()) {
- var modifyItemLog gm.ModifyItemLog
- err := sendModifyItemLogList.Decode(&modifyItemLog)
- if err != nil {
- //log.Fatal(err)
- log.Println(err)
- continue
- }
- dayMap.Set("id", modifyItemLog.Id)
- dayMap.Set("userid", modifyItemLog.UserId)
- dayMap.Set("servername", modifyItemLog.ServerName)
- dayMap.Set("param", modifyItemLog.Param)
- dayMap.Set("modifyMode", modifyItemLog.ModifyMode)
- dayMap.Set("cmd", modifyItemLog.Cmd)
- dayMap.Set("updateuser", modifyItemLog.UpdateUser)
- st := time.Unix(modifyItemLog.UpdateTime, 0).Format(timeLayoutStr)
- dayMap.Set("updatetime", st)
- dayMap.Set("state", modifyItemLog.State)
- data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
- }
- fmt.Println(data)
- base.Succ(r,
- g.Map{
- "rows": data,
- "total": page.Total,
- "current": page.CurrentPage,
- })
- }
- //保存发送道具日志
- func (action *Action) SaveModifyItemLog(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- cmdStr := form.Params["cmdStr"]
- serverid := form.Params["serverid"]
- if serverid == "" {
- base.Fail(r, "请选择服务器")
- }
- userid := form.Params["userid"]
- if cmdStr == "sendmail" && userid == "" {
- base.Fail(r, "请输入用户uid")
- }
- modifyMode := form.Params["modifyMode"]
- if modifyMode == "" {
- base.Fail(r, "请输入修改模式")
- }
- param := form.Params["param"]
- if param == "" {
- base.Fail(r, "请输入道具参数")
- }
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err := singleResult.Decode(&serverInfo)
- if err != nil {
- base.Fail(r, "查询服务器信息出现异常,"+serverid)
- }
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- servername := serverInfo.Name
- //保存日志
- modifyItemLog := new(gm.ModifyItemLog)
- modifyItemLog.Id = primitive.NewObjectID()
- if cmdStr == "modifyitem" {
- modifyItemLog.UserId = gconv.String(userid)
- }
- modifyItemLog.ServerId = gconv.String(serverid)
- modifyItemLog.ServerName = gconv.String(servername)
- modifyItemLog.GMIp = gconv.String(gmip)
- modifyItemLog.GMPort = gconv.String(gmport)
- modifyItemLog.ModifyMode = gconv.Int(modifyMode)
- modifyItemLog.Param = gconv.String(param)
- modifyItemLog.Cmd = gconv.String(cmdStr)
- username := base.GetUser(r).Username
- modifyItemLog.UpdateUser = username
- modifyItemLog.UpdateTime = time.Now().Unix()
- modifyItemLog.State = 2 //刚保存为发送中 30s后执行发送;邮件状态:0:未发送 1:已发送 2:发送中 3:发送失败
- gm.ModelModifyItemLog.InsertOne(modifyItemLog)
- base.Resp(r, 0, "保存成功", modifyItemLog.Id)
- }
- //修改发送道具
- func (action *Action) UpdateModifyItem(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- data := gconv.Map(form.Params["data"])
- gm.ModelModifyItemLog.InsUpdate(gconv.String(data["id"]), gconv.Int(data["state"]))
- base.Resp(r, 0, "操作成功", nil)
- }
- //发送道具
- func (action *Action) SendModifyItem(r *ghttp.Request) {
- form := base.NewForm(r.GetMap())
- dataId := form.Params["dataId"]
- obj_id, _ := primitive.ObjectIDFromHex(gconv.String(dataId))
- data := gm.ModelModifyItemLog.FindOne("_id", obj_id)
- var modifyItemLog gm.ModifyItemLog
- err := data.Decode(&modifyItemLog)
- if err != nil {
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "当前数据有误", nil)
- }
- cmdStr := modifyItemLog.Cmd
- serverid := modifyItemLog.ServerId
- userid := ""
- if cmdStr == "modifyitem" {
- userid = modifyItemLog.UserId
- }
- modifyMode := gconv.String(modifyItemLog.ModifyMode)
- param := modifyItemLog.Param
- //根据服务器id查询gmip,gmport,服务器名称
- singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
- var serverInfo gameinfo.ServerInfo
- err = singleResult.Decode(&serverInfo)
- if err != nil {
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "查询服务器信息出现异常", nil)
- }
- gmip := serverInfo.GMIp
- gmport := serverInfo.GMPort
- ages := modifyMode + " " + param
- cmd := netutil.Gmcmd{
- ServerIp: gmip,
- ServerPort: gmport,
- Cmd: cmdStr,
- UserId: userid,
- Args: ages,
- }
- res := int32(-1)
- if (cmdStr == "modifyitem") {
- res = cmd.SendGM() //0 成功
- } else {
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "当前数据有误", nil)
- }
- if res == -100 {
- // 修改日志状态为发送失败
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "thrift解析地址时出错", nil)
- } else if res == -101 {
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "thrift打开服务器socket出错", nil)
- } else if res == 0 {
- // 修改日志状态为已发送
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 1)
- base.Resp(r, 0, "发送成功", nil)
- } else {
- gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
- base.Resp(r, -1, "发送失败", nil)
- }
- }
|