gmAction.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128
  1. package gm
  2. import (
  3. "context"
  4. "encoding/csv"
  5. "fmt"
  6. "github.com/gogf/gf/container/glist"
  7. "github.com/gogf/gf/container/gmap"
  8. "github.com/gogf/gf/frame/g"
  9. "github.com/gogf/gf/net/ghttp"
  10. "github.com/gogf/gf/os/gfile"
  11. "github.com/gogf/gf/util/gconv"
  12. "gmanager/library/base"
  13. "gmanager/library/mongo/gameinfo"
  14. "gmanager/library/mongo/gm"
  15. "gmanager/library/mongo/util"
  16. "gmanager/library/netutil"
  17. "go.mongodb.org/mongo-driver/bson"
  18. "go.mongodb.org/mongo-driver/bson/primitive"
  19. "log"
  20. "os"
  21. "strings"
  22. "time"
  23. )
  24. type Action struct {
  25. base.BaseRouter
  26. }
  27. //发送邮件日志列表
  28. func (action *Action) GetSendMailList(r *ghttp.Request) {
  29. var timeLayoutStr = "2006-01-02 15:04:05"
  30. form := base.NewForm(r.GetMap())
  31. bs := bson.D{bson.E{"cmd", "sendmail"}}
  32. data := g.ListAnyAny{}
  33. count := gm.ModelSendMailLog.GetListCount(bs)
  34. page := util.Page{
  35. PageSize: gconv.Int64(form.Rows),
  36. CurrentPage: gconv.Int64(form.Page),
  37. Total: gconv.Int64(count),
  38. }
  39. sendMailLogList := gm.ModelSendMailLog.GetPageList(bs, page)
  40. dayMap := gmap.New()
  41. for sendMailLogList.Next(context.TODO()) {
  42. var sendMailLog gm.SendMailLog
  43. err := sendMailLogList.Decode(&sendMailLog)
  44. if err != nil {
  45. //log.Fatal(err)
  46. log.Println(err)
  47. continue
  48. }
  49. dayMap.Set("id", sendMailLog.Id)
  50. dayMap.Set("userid", sendMailLog.UserId)
  51. dayMap.Set("servername", sendMailLog.ServerName)
  52. dayMap.Set("param", sendMailLog.Param)
  53. dayMap.Set("title", sendMailLog.Title)
  54. dayMap.Set("content", sendMailLog.Content)
  55. dayMap.Set("cmd", sendMailLog.Cmd)
  56. dayMap.Set("updateuser", sendMailLog.UpdateUser)
  57. st := time.Unix(sendMailLog.UpdateTime, 0).Format(timeLayoutStr)
  58. dayMap.Set("updatetime", st)
  59. dayMap.Set("state", sendMailLog.State)
  60. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  61. }
  62. fmt.Println(data)
  63. base.Succ(r,
  64. g.Map{
  65. "rows": data,
  66. "total": page.Total,
  67. "current": page.CurrentPage,
  68. })
  69. }
  70. //全服发送邮件日志列表
  71. func (action *Action) GetSendMailAllList(r *ghttp.Request) {
  72. var timeLayoutStr = "2006-01-02 15:04:05"
  73. form := base.NewForm(r.GetMap())
  74. bs := bson.D{bson.E{"cmd", "sendmailall"}}
  75. data := g.ListAnyAny{}
  76. count := gm.ModelSendMailLog.GetListCount(bs)
  77. page := util.Page{
  78. PageSize: gconv.Int64(form.Rows),
  79. CurrentPage: gconv.Int64(form.Page),
  80. Total: gconv.Int64(count),
  81. }
  82. sendMailLogList := gm.ModelSendMailLog.GetPageList(bs, page)
  83. dayMap := gmap.New()
  84. for sendMailLogList.Next(context.TODO()) {
  85. var sendMailLog gm.SendMailLog
  86. err := sendMailLogList.Decode(&sendMailLog)
  87. if err != nil {
  88. //log.Fatal(err)
  89. log.Println(err)
  90. continue
  91. }
  92. dayMap.Set("id", sendMailLog.Id)
  93. dayMap.Set("servername", sendMailLog.ServerName)
  94. dayMap.Set("param", sendMailLog.Param)
  95. dayMap.Set("title", sendMailLog.Title)
  96. dayMap.Set("content", sendMailLog.Content)
  97. dayMap.Set("cmd", sendMailLog.Cmd)
  98. dayMap.Set("updateuser", sendMailLog.UpdateUser)
  99. st := time.Unix(sendMailLog.UpdateTime, 0).Format(timeLayoutStr)
  100. dayMap.Set("updatetime", st)
  101. dayMap.Set("state", sendMailLog.State)
  102. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  103. }
  104. fmt.Println(data)
  105. base.Succ(r,
  106. g.Map{
  107. "rows": data,
  108. "total": page.Total,
  109. "current": page.CurrentPage,
  110. })
  111. }
  112. //保存邮件日志
  113. func (action *Action) SaveMailLog(r *ghttp.Request) {
  114. form := base.NewForm(r.GetMap())
  115. cmdStr := form.Params["cmdStr"]
  116. serverid := form.Params["serverid"]
  117. if serverid == "" {
  118. base.Fail(r, "请选择服务器")
  119. }
  120. userid := form.Params["userid"]
  121. if cmdStr == "sendmail" && userid == "" {
  122. base.Fail(r, "请输入用户uid")
  123. }
  124. useridArray := strings.Split(userid,"#")
  125. param := form.Params["param"]
  126. if param == "" {
  127. base.Fail(r, "请输入参数")
  128. }
  129. title := form.Params["title"]
  130. if title == "" {
  131. base.Fail(r, "请输入标题")
  132. }
  133. content := form.Params["content"]
  134. if content == "" {
  135. base.Fail(r, "请输入内容")
  136. }
  137. //根据服务器id查询gmip,gmport,服务器名称
  138. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  139. var serverInfo gameinfo.ServerInfo
  140. err := singleResult.Decode(&serverInfo)
  141. if err != nil {
  142. base.Fail(r, "查询服务器信息出现异常,"+serverid)
  143. }
  144. gmip := serverInfo.GMIp
  145. gmport := serverInfo.GMPort
  146. servername := serverInfo.Name
  147. data := g.ListAnyAny{}
  148. dayMap := gmap.New()
  149. for _,uid := range useridArray {
  150. //保存日志
  151. sendmail := new(gm.SendMailLog)
  152. sendmail.Id = primitive.NewObjectID()
  153. if cmdStr == "sendmail" {
  154. sendmail.UserId = gconv.String(uid)
  155. }
  156. sendmail.ServerId = gconv.String(serverid)
  157. sendmail.ServerName = gconv.String(servername)
  158. sendmail.GMIp = gconv.String(gmip)
  159. sendmail.GMPort = gconv.String(gmport)
  160. sendmail.Param = gconv.String(param)
  161. sendmail.Title = gconv.String(title)
  162. sendmail.Content = gconv.String(content)
  163. sendmail.Cmd = gconv.String(cmdStr)
  164. username := base.GetUser(r).Username
  165. sendmail.UpdateUser = username
  166. sendmail.UpdateTime = time.Now().Unix()
  167. sendmail.State = 2 //刚保存为发送中 30s后执行发送;邮件状态:0:未发送 1:已发送 2:发送中 3:发送失败
  168. gm.ModelSendMailLog.InsertOne(sendmail)
  169. dayMap.Set("id",sendmail.Id)
  170. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  171. }
  172. base.Resp(r, 0, "保存成功", data)
  173. }
  174. //修改邮件
  175. func (action *Action) UpdateMail(r *ghttp.Request) {
  176. form := base.NewForm(r.GetMap())
  177. data := gconv.Map(form.Params["data"])
  178. gm.ModelSendMailLog.InsUpdate(gconv.String(data["id"]), gconv.Int(data["state"]))
  179. base.Resp(r, 0, "操作成功", nil)
  180. }
  181. //发送邮件
  182. func (action *Action) SendMail(r *ghttp.Request) {
  183. form := base.NewForm(r.GetMap())
  184. _dataId := gconv.Map(form.Params["dataId"])
  185. for _ , id := range _dataId {
  186. _data := gconv.Map(id)
  187. dataId := gconv.String(_data["id"])
  188. obj_id, _ := primitive.ObjectIDFromHex(dataId)
  189. data := gm.ModelSendMailLog.FindOne("_id", obj_id)
  190. var sendMailLog gm.SendMailLog
  191. err := data.Decode(&sendMailLog)
  192. if err != nil {
  193. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
  194. base.Resp(r, -1, "当前数据有误", nil)
  195. }
  196. cmdStr := sendMailLog.Cmd
  197. serverid := sendMailLog.ServerId
  198. userid := ""
  199. if cmdStr == "sendmail" {
  200. userid = sendMailLog.UserId
  201. }
  202. param := sendMailLog.Param
  203. title := sendMailLog.Title
  204. content := sendMailLog.Content
  205. //根据服务器id查询gmip,gmport,服务器名称
  206. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  207. var serverInfo gameinfo.ServerInfo
  208. err = singleResult.Decode(&serverInfo)
  209. if err != nil {
  210. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
  211. base.Resp(r, -1, "查询服务器信息出现异常", nil)
  212. }
  213. gmip := serverInfo.GMIp
  214. gmport := serverInfo.GMPort
  215. ages := param + "@#" + title + "@#" + content
  216. cmd := netutil.Gmcmd{
  217. ServerIp: gmip,
  218. ServerPort: gmport,
  219. Cmd: cmdStr,
  220. UserId: userid,
  221. Args: ages,
  222. }
  223. res := int32(-1)
  224. if (cmdStr == "sendmail") {
  225. res = cmd.SendGM() //0 成功
  226. } else if (cmdStr == "sendmailall") {
  227. res = cmd.SendGMAll() //0 成功
  228. } else {
  229. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
  230. base.Resp(r, -1, "当前数据有误", nil)
  231. }
  232. if res == -100 {
  233. // 修改日志状态为发送失败
  234. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
  235. base.Resp(r, -1, "thrift解析地址时出错", nil)
  236. } else if res == -101 {
  237. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
  238. base.Resp(r, -1, "thrift打开服务器socket出错", nil)
  239. } else if res == 0 {
  240. // 修改日志状态为已发送
  241. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 1)
  242. } else {
  243. gm.ModelSendMailLog.InsUpdate(gconv.String(dataId), 3)
  244. base.Resp(r, -1, "发送失败", nil)
  245. }
  246. }
  247. base.Resp(r, 0, "发送成功", nil)
  248. }
  249. //全服发送邮件
  250. func (action *Action) SendMailAll(r *ghttp.Request) {
  251. const cmdStr = "sendmailall"
  252. form := base.NewForm(r.GetMap())
  253. serverid := form.Params["serverid"]
  254. if serverid == "" {
  255. base.Fail(r, "请选择服务器")
  256. }
  257. param := form.Params["param"]
  258. if param == "" {
  259. base.Fail(r, "请输入参数")
  260. }
  261. title := form.Params["title"]
  262. if title == "" {
  263. base.Fail(r, "请输入标题")
  264. }
  265. content := form.Params["content"]
  266. if content == "" {
  267. base.Fail(r, "请输入内容")
  268. }
  269. ages := param + "@#" + title + "@#" + content
  270. //根据服务器id查询gmip,gmport,服务器名称
  271. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  272. var serverInfo gameinfo.ServerInfo
  273. err := singleResult.Decode(&serverInfo)
  274. gmip := serverInfo.GMIp
  275. gmport := serverInfo.GMPort
  276. servername := serverInfo.Name
  277. if err != nil {
  278. base.Fail(r, "查询服务器信息出现异常,"+serverid)
  279. }
  280. cmd := netutil.Gmcmd{
  281. ServerIp: gmip,
  282. ServerPort: gmport,
  283. Cmd: cmdStr,
  284. Args: ages,
  285. }
  286. res := cmd.SendGMAll() //0 成功
  287. if res == -100 {
  288. base.Resp(r, 1, "thrift解析地址时出错", nil)
  289. } else if res == -101 {
  290. base.Resp(r, 1, "thrift打开服务器socket出错", nil)
  291. }
  292. //保存日志
  293. sendmail := new(gm.SendMailLog)
  294. sendmail.Id = primitive.NewObjectID()
  295. sendmail.ServerId = gconv.String(serverid)
  296. sendmail.ServerName = gconv.String(servername)
  297. sendmail.GMIp = gconv.String(gmip)
  298. sendmail.GMPort = gconv.String(gmport)
  299. sendmail.Param = gconv.String(param)
  300. sendmail.Title = gconv.String(title)
  301. sendmail.Content = gconv.String(content)
  302. sendmail.Cmd = gconv.String(cmdStr)
  303. username := base.GetUser(r).Username
  304. sendmail.UpdateUser = username
  305. sendmail.UpdateTime = time.Now().Unix()
  306. insertOne := gm.ModelSendMailLog.InsertOne(sendmail)
  307. fmt.Println(serverid, servername, gmip, gmport, param, title, content, cmdStr, username, time.Now().Unix())
  308. fmt.Println("insertOne.InsertedID==============", insertOne.InsertedID)
  309. if res == 0 {
  310. base.Resp(r, 0, "发送成功", nil)
  311. } else {
  312. base.Resp(r, 1, "发送失败", nil)
  313. }
  314. }
  315. //查询用户充值记录
  316. func (action *Action) GetRechargeInfoList(r *ghttp.Request) {
  317. form := base.NewForm(r.GetMap())
  318. serverid := form.Params["serverid"]
  319. if serverid == "" {
  320. base.Fail(r, "请选择服务器")
  321. }
  322. userid := form.Params["userid"]
  323. if userid == "" {
  324. base.Fail(r, "请输入用户id")
  325. }
  326. page := g.ListAnyAny{}
  327. bs := bson.D{bson.E{"_id", gconv.Int32(userid)}}
  328. rechargeInfoRes := gm.ModelRechargeInfo.FindRechargeInfo(bs, serverid)
  329. var showsWithInfo []bson.M
  330. if err := rechargeInfoRes.All(context.TODO(), &showsWithInfo); err != nil {
  331. fmt.Println(err)
  332. }
  333. if showsWithInfo == nil {
  334. base.Fail(r, "该用户不存在")
  335. return
  336. }
  337. playerManager := showsWithInfo[0]["playerManager"]
  338. playerManagerMap := gconv.Map(playerManager)
  339. res := gconv.Map(playerManagerMap["rechargeInfo"])
  340. dayMap := gmap.New()
  341. dayMap.Set("userid", userid)
  342. dayMap.Set("servername", serverid)
  343. dayMap.Set("saveAmt", res["saveAmt"])
  344. dayMap.Set("soulCrystalAmt", res["soulCrystalAmt"])
  345. dayMap.Set("monthSaveAmt", res["monthSaveAmt"])
  346. dayMap.Set("smonthSaveAmt", res["smonthSaveAmt"])
  347. dayMap.Set("isFirst", res["isFirst"])
  348. var timeLayoutStr = "2006-01-02 15:04:05"
  349. st := time.Unix(gconv.Int64(res["createTime"])/1000, 0).Format(timeLayoutStr)
  350. dayMap.Set("createTime", st)
  351. dayMap.Set("isDayFirst", res["isDayFirst"])
  352. page = append(g.ListAnyAny{gconv.Map(dayMap)}, page...)
  353. base.Succ(r,
  354. g.Map{
  355. "page": form.Page,
  356. "rows": page,
  357. "total": form.TotalPage,
  358. "records": form.TotalSize,
  359. })
  360. }
  361. func (action *Action) Pay(r *ghttp.Request) {
  362. const cmdStr = "pay"
  363. form := base.NewForm(r.GetMap())
  364. serverid := form.Params["serverid"]
  365. if serverid == "" {
  366. base.Fail(r, "请选择服务器")
  367. }
  368. userid := form.Params["userid"]
  369. if userid == "" {
  370. base.Fail(r, "请输入userid")
  371. }
  372. payid := form.Params["payid"]
  373. if payid == "" {
  374. base.Fail(r, "请输入payid")
  375. }
  376. ages := payid
  377. //根据服务器id查询gmip,gmport,服务器名称
  378. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  379. var serverInfo gameinfo.ServerInfo
  380. err := singleResult.Decode(&serverInfo)
  381. gmip := serverInfo.GMIp
  382. gmport := serverInfo.GMPort
  383. servername := serverInfo.Name
  384. if err != nil {
  385. base.Fail(r, "查询服务器信息出现异常,"+serverid)
  386. }
  387. cmd := netutil.Gmcmd{
  388. ServerIp: gmip,
  389. ServerPort: gmport,
  390. Cmd: cmdStr,
  391. UserId: userid,
  392. Args: ages,
  393. }
  394. res := cmd.SendGM() //0 成功
  395. if res == -100 {
  396. base.Resp(r, 1, "thrift解析地址时出错", nil)
  397. } else if res == -101 {
  398. base.Resp(r, 1, "thrift打开服务器socket出错", nil)
  399. }
  400. //保存日志
  401. payLog := new(gm.PayLog)
  402. payLog.Id = primitive.NewObjectID()
  403. payLog.UserId = gconv.String(userid)
  404. payLog.PayId = gconv.String(payid)
  405. payLog.ServerId = gconv.String(serverid)
  406. payLog.ServerName = gconv.String(servername)
  407. payLog.GMIp = gconv.String(gmip)
  408. payLog.GMPort = gconv.String(gmport)
  409. payLog.Cmd = gconv.String(cmdStr)
  410. username := base.GetUser(r).Username
  411. payLog.UpdateUser = username
  412. payLog.UpdateTime = time.Now().Unix()
  413. gm.ModelPayLog.InsertOne(payLog)
  414. fmt.Println(userid, serverid, servername, gmip, gmport, payid, cmdStr, username, time.Now().Unix())
  415. if res == 0 {
  416. base.Resp(r, 0, "充值成功", nil)
  417. } else {
  418. base.Resp(r, 1, "充值失败", nil)
  419. }
  420. }
  421. //充值日志列表
  422. func (action *Action) GetPayLogList(r *ghttp.Request) {
  423. var timeLayoutStr = "2006-01-02 15:04:05"
  424. form := base.NewForm(r.GetMap())
  425. //bs := bson.D{bson.E{"cmd", "pay"}}
  426. bs := bson.D{{}}
  427. data := g.ListAnyAny{}
  428. count := gm.ModelPayLog.GetListCount(bs)
  429. page := util.Page{
  430. PageSize: gconv.Int64(form.Rows),
  431. CurrentPage: gconv.Int64(form.Page),
  432. Total: gconv.Int64(count),
  433. }
  434. payLogList := gm.ModelPayLog.GetPageList(bs, page)
  435. dayMap := gmap.New()
  436. for payLogList.Next(context.TODO()) {
  437. var payLog gm.PayLog
  438. err := payLogList.Decode(&payLog)
  439. if err != nil {
  440. //log.Fatal(err)
  441. log.Println(err)
  442. continue
  443. }
  444. dayMap.Set("servername", payLog.ServerName)
  445. dayMap.Set("userid", payLog.UserId)
  446. dayMap.Set("payid", payLog.PayId)
  447. dayMap.Set("cmd", payLog.Cmd)
  448. dayMap.Set("updateuser", payLog.UpdateUser)
  449. st := time.Unix(payLog.UpdateTime, 0).Format(timeLayoutStr)
  450. dayMap.Set("updatetime", st)
  451. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  452. }
  453. fmt.Println(data)
  454. base.Succ(r,
  455. g.Map{
  456. "rows": data,
  457. "total": page.Total,
  458. "current": page.CurrentPage,
  459. })
  460. }
  461. //查询CreatCdk列表
  462. func (action *Action) GetCreatCdkList(r *ghttp.Request) {
  463. var timeLayoutStr = "2006-01-02 15:04:05"
  464. form := base.NewForm(r.GetMap())
  465. bs := bson.D{{}}
  466. data := g.ListAnyAny{}
  467. count := gm.ModelCreatcdkLog.GetListCount(bs)
  468. page := util.Page{
  469. PageSize: gconv.Int64(form.Rows),
  470. CurrentPage: gconv.Int64(form.Page),
  471. Total: gconv.Int64(count),
  472. }
  473. creatcdkLogList := gm.ModelCreatcdkLog.GetPageList(bs, page)
  474. dayMap := gmap.New()
  475. for creatcdkLogList.Next(context.TODO()) {
  476. var creatcdkLog gm.CreatcdkLog
  477. err := creatcdkLogList.Decode(&creatcdkLog)
  478. if err != nil {
  479. //log.Fatal(err)
  480. log.Println(err)
  481. continue
  482. }
  483. dayMap.Set("infoid", creatcdkLog.InfoId)
  484. dayMap.Set("ctype", creatcdkLog.Ctype)
  485. dayMap.Set("reward", creatcdkLog.Reward)
  486. dayMap.Set("title", creatcdkLog.Title)
  487. dayMap.Set("contetnt", creatcdkLog.Contetnt)
  488. dayMap.Set("channelname", creatcdkLog.ChannelName)
  489. dayMap.Set("cmd", creatcdkLog.Cmd)
  490. dayMap.Set("updateuser", creatcdkLog.UpdateUser)
  491. st := time.Unix(creatcdkLog.UpdateTime, 0).Format(timeLayoutStr)
  492. dayMap.Set("updatetime", st)
  493. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  494. }
  495. fmt.Println(data)
  496. base.Succ(r,
  497. g.Map{
  498. "rows": data,
  499. "total": page.Total,
  500. "current": page.CurrentPage,
  501. })
  502. }
  503. func (action *Action) CreatCdk(r *ghttp.Request) {
  504. const cmdStr = "creatcdk"
  505. form := base.NewForm(r.GetMap())
  506. ctype := form.Params["ctype"]
  507. if ctype == "" {
  508. base.Fail(r, "请选择类型")
  509. }
  510. reward := form.Params["reward"]
  511. if reward == "" {
  512. base.Fail(r, "请输入奖励")
  513. }
  514. title := form.Params["title"]
  515. if title == "" {
  516. base.Fail(r, "请输入邮件标题")
  517. }
  518. contetnt := form.Params["contetnt"]
  519. if contetnt == "" {
  520. base.Fail(r, "请输入邮件内容")
  521. }
  522. channelname := form.Params["channelname"]
  523. if channelname == "" {
  524. base.Fail(r, "请输入CDK标识")
  525. } else if len(channelname) != 3 {
  526. base.Fail(r, "长度只允许为3个字符")
  527. }
  528. ages := ctype + " " + reward + " " + title + " " + contetnt + " " + channelname
  529. singleResult := gameinfo.ModelServer.FindOne("_id", 1) //取1服
  530. var serverInfo gameinfo.ServerInfo
  531. err := singleResult.Decode(&serverInfo)
  532. gmip := serverInfo.GMIp
  533. gmport := serverInfo.GMPort
  534. servername := serverInfo.Name
  535. if err != nil {
  536. base.Fail(r, "查询服务器信息出现异常")
  537. }
  538. cmd := netutil.Gmcmd{
  539. ServerIp: gmip,
  540. ServerPort: gmport,
  541. Cmd: cmdStr,
  542. Args: ages,
  543. }
  544. res := cmd.Creatcdk()
  545. if res == -100 {
  546. base.Resp(r, 1, "thrift解析地址时出错", nil)
  547. } else if res == -101 {
  548. base.Resp(r, 1, "thrift打开服务器socket出错", nil)
  549. }
  550. //保存日志
  551. creatcdkLog := new(gm.CreatcdkLog)
  552. singleResult1 := gm.ModelCdkAddInfo.FindOne("goods_channel", channelname)
  553. var cdkAddInfo gm.CdkAddInfo
  554. err1 := singleResult1.Decode(&cdkAddInfo)
  555. if err1 != nil {
  556. base.Fail(r, "查询出现异常")
  557. }
  558. creatcdkLog.Id = primitive.NewObjectID()
  559. creatcdkLog.InfoId = cdkAddInfo.Id
  560. creatcdkLog.ServerId = gconv.String(1)
  561. creatcdkLog.ServerName = servername
  562. creatcdkLog.Ctype = ctype
  563. creatcdkLog.Reward = reward
  564. creatcdkLog.Title = title
  565. creatcdkLog.Contetnt = contetnt
  566. creatcdkLog.ChannelName = channelname
  567. creatcdkLog.Cmd = gconv.String(cmdStr)
  568. username := base.GetUser(r).Username
  569. creatcdkLog.UpdateUser = username
  570. creatcdkLog.UpdateTime = time.Now().Unix()
  571. gm.ModelCreatcdkLog.InsertOne(creatcdkLog)
  572. base.Resp(r, 0, "执行完成", nil)
  573. }
  574. //获取Cdkinfo列表
  575. func (action *Action) GetCdkIdList(r *ghttp.Request) {
  576. list := glist.New()
  577. bs := bson.D{}
  578. creatcdkLogList := gm.ModelCdkAddInfo.FindServerInfoList(bs)
  579. for creatcdkLogList.Next(context.TODO()) {
  580. dayMap := gmap.New()
  581. var cdkAddInfo gm.CdkAddInfo
  582. err := creatcdkLogList.Decode(&cdkAddInfo)
  583. if err != nil {
  584. //log.Fatal(err)
  585. log.Println(err)
  586. continue
  587. }
  588. dayMap.Set("id", cdkAddInfo.Id)
  589. dayMap.Set("channelName", cdkAddInfo.GoodsChannel)
  590. list.PushFront(dayMap)
  591. }
  592. base.Succ(r, list)
  593. }
  594. //查询CreatCdk列表
  595. func (action *Action) GetCreatCdkCodeList(r *ghttp.Request) {
  596. var timeLayoutStr = "2006-01-02 15:04:05"
  597. form := base.NewForm(r.GetMap())
  598. bs := bson.D{{}}
  599. data := g.ListAnyAny{}
  600. count := gm.ModelCreatcdkCodeLog.GetListCount(bs)
  601. page := util.Page{
  602. PageSize: gconv.Int64(form.Rows),
  603. CurrentPage: gconv.Int64(form.Page),
  604. Total: gconv.Int64(count),
  605. }
  606. creatcdkCodeLogList := gm.ModelCreatcdkCodeLog.GetPageList(bs, page)
  607. dayMap := gmap.New()
  608. for creatcdkCodeLogList.Next(context.TODO()) {
  609. var creatcdkCodeLog gm.CreatcdkCodeLog
  610. err := creatcdkCodeLogList.Decode(&creatcdkCodeLog)
  611. if err != nil {
  612. //log.Fatal(err)
  613. log.Println(err)
  614. continue
  615. }
  616. dayMap.Set("cdkid", creatcdkCodeLog.CdkId)
  617. dayMap.Set("cdknum", creatcdkCodeLog.CdkNum)
  618. dayMap.Set("tick", creatcdkCodeLog.Tick)
  619. dayMap.Set("cmd", creatcdkCodeLog.Cmd)
  620. dayMap.Set("updateuser", creatcdkCodeLog.UpdateUser)
  621. st := time.Unix(creatcdkCodeLog.UpdateTime, 0).Format(timeLayoutStr)
  622. dayMap.Set("updatetime", st)
  623. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  624. }
  625. fmt.Println(data)
  626. base.Succ(r,
  627. g.Map{
  628. "rows": data,
  629. "total": page.Total,
  630. "current": page.CurrentPage,
  631. })
  632. }
  633. func (action *Action) CreatCdkCode(r *ghttp.Request) {
  634. const cmdStr = "creatcdkcode"
  635. form := base.NewForm(r.GetMap())
  636. cdkid := form.Params["cdkid"]
  637. if cdkid == "" {
  638. base.Fail(r, "请选择CDKID")
  639. }
  640. cdknum := form.Params["cdknum"]
  641. if cdknum == "" {
  642. base.Fail(r, "请输入数量")
  643. }
  644. nowtime := time.Now().Unix()
  645. ages := cdkid + " " + cdknum + " " + gconv.String(nowtime)
  646. singleResult := gameinfo.ModelServer.FindOne("_id", 1) //取1服
  647. var serverInfo gameinfo.ServerInfo
  648. err := singleResult.Decode(&serverInfo)
  649. gmip := serverInfo.GMIp
  650. gmport := serverInfo.GMPort
  651. if err != nil {
  652. base.Fail(r, "查询服务器信息出现异常")
  653. }
  654. cmd := netutil.Gmcmd{
  655. ServerIp: gmip,
  656. ServerPort: gmport,
  657. Cmd: cmdStr,
  658. Args: ages,
  659. }
  660. res := cmd.Creatcdk()
  661. if res == -100 {
  662. base.Resp(r, 1, "thrift解析地址时出错", nil)
  663. } else if res == -101 {
  664. base.Resp(r, 1, "thrift打开服务器socket出错", nil)
  665. }
  666. //保存日志
  667. var creatcdkCodeLog gm.CreatcdkCodeLog
  668. creatcdkCodeLog.Id = primitive.NewObjectID()
  669. creatcdkCodeLog.CdkId = gconv.Int(cdkid)
  670. creatcdkCodeLog.CdkNum = gconv.Int(cdknum)
  671. creatcdkCodeLog.Tick = nowtime
  672. creatcdkCodeLog.Cmd = gconv.String(cmdStr)
  673. username := base.GetUser(r).Username
  674. creatcdkCodeLog.UpdateUser = username
  675. creatcdkCodeLog.UpdateTime = time.Now().Unix()
  676. gm.ModelCreatcdkCodeLog.InsertOne(creatcdkCodeLog)
  677. base.Resp(r, 0, "执行完成", nil)
  678. }
  679. func (action *Action) DownloadCdk(r *ghttp.Request) {
  680. ticke := r.GetString("ticke")
  681. singleResult := gm.ModelCdkInfo.FindAll("ticke", gconv.String(ticke))
  682. fileName := "CDK_" + gconv.String(time.Now().Unix()) + ".txt"
  683. file, err := gfile.Create(fileName)
  684. if err != nil {
  685. fmt.Println("open file is failed, err: ", err.Error())
  686. }
  687. // 写入UTF-8 BOM,防止中文乱码
  688. file.WriteString("\xEF\xBB\xBF")
  689. w := csv.NewWriter(file)
  690. for singleResult.Next(context.TODO()) {
  691. var cdkInfo gm.CdkInfo
  692. err := singleResult.Decode(&cdkInfo)
  693. if err != nil {
  694. //log.Fatal(err)
  695. log.Println(err)
  696. continue
  697. }
  698. w.Write([]string{cdkInfo.Id})
  699. // 刷新缓冲
  700. w.Flush()
  701. }
  702. r.Response.ServeFileDownload(fileName)
  703. file.Close()
  704. //删除生成的文件
  705. os.Remove("./" + fileName)
  706. }
  707. //查询禁言列表
  708. func (action *Action) GetSilenceList(r *ghttp.Request) {
  709. var timeLayoutStr = "2006-01-02 15:04:05"
  710. form := base.NewForm(r.GetMap())
  711. bs := bson.D{{}}
  712. data := g.ListAnyAny{}
  713. count := gm.ModelSilence.GetListCount(bs)
  714. page := util.Page{
  715. PageSize: gconv.Int64(form.Rows),
  716. CurrentPage: gconv.Int64(form.Page),
  717. Total: gconv.Int64(count),
  718. }
  719. silenceLogList := gm.ModelSilence.GetPageList(bs, page)
  720. dayMap := gmap.New()
  721. for silenceLogList.Next(context.TODO()) {
  722. var silenceLog gm.SilenceLog
  723. err := silenceLogList.Decode(&silenceLog)
  724. if err != nil {
  725. //log.Fatal(err)
  726. log.Println(err)
  727. continue
  728. }
  729. dayMap.Set("uid", silenceLog.Uid)
  730. dayMap.Set("serverName", silenceLog.ServerName)
  731. dayMap.Set("stype", silenceLog.Stype)
  732. dayMap.Set("cmd", silenceLog.Cmd)
  733. dayMap.Set("updateuser", silenceLog.UpdateUser)
  734. st := time.Unix(silenceLog.UpdateTime, 0).Format(timeLayoutStr)
  735. dayMap.Set("updatetime", st)
  736. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  737. }
  738. fmt.Println(data)
  739. base.Succ(r,
  740. g.Map{
  741. "rows": data,
  742. "total": page.Total,
  743. "current": page.CurrentPage,
  744. })
  745. }
  746. //禁言
  747. func (action *Action) SetSilence(r *ghttp.Request) {
  748. const cmdStr = "silence"
  749. form := base.NewForm(r.GetMap())
  750. serverid := form.Params["serverid"]
  751. if serverid == "" {
  752. base.Fail(r, "请选择服务器")
  753. }
  754. userid := form.Params["userid"]
  755. if userid == "" {
  756. base.Fail(r, "请输入用户id")
  757. }
  758. stype := form.Params["stype"]
  759. if stype == "" {
  760. base.Fail(r, "请选择禁言类型")
  761. }
  762. ages := userid + " " + stype
  763. //根据服务器id查询gmip,gmport,服务器名称
  764. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  765. var serverInfo gameinfo.ServerInfo
  766. err := singleResult.Decode(&serverInfo)
  767. gmip := serverInfo.GMIp
  768. gmport := serverInfo.GMPort
  769. servername := serverInfo.Name
  770. if err != nil {
  771. base.Fail(r, "查询服务器信息出现异常,"+serverid)
  772. }
  773. cmd := netutil.Gmcmd{
  774. ServerIp: gmip,
  775. ServerPort: gmport,
  776. Cmd: cmdStr,
  777. Args: ages,
  778. }
  779. fmt.Println(cmd)
  780. res := cmd.Creatcdk() //0 成功
  781. if res == -100 {
  782. base.Resp(r, 1, "thrift解析地址时出错", nil)
  783. } else if res == -101 {
  784. base.Resp(r, 1, "thrift打开服务器socket出错", nil)
  785. }
  786. //保存日志
  787. var silenceLog gm.SilenceLog
  788. silenceLog.Id = primitive.NewObjectID()
  789. silenceLog.ServerId = serverid
  790. silenceLog.ServerName = servername
  791. silenceLog.Uid = gconv.Int(userid)
  792. silenceLog.Stype = gconv.Int(stype)
  793. silenceLog.Cmd = gconv.String(cmdStr)
  794. silenceLog.UpdateUser = base.GetUser(r).Username
  795. silenceLog.UpdateTime = time.Now().Unix()
  796. gm.ModelSilence.InsertOne(silenceLog)
  797. if res == 0 {
  798. base.Resp(r, 0, "发送成功", nil)
  799. } else {
  800. base.Resp(r, 1, "发送失败", nil)
  801. }
  802. }
  803. // 坦克评论列表
  804. func (action *Action) HeroCommentList(r *ghttp.Request) {
  805. var timeLayoutStr = "2006-01-02 15:04:05"
  806. form := base.NewForm(r.GetMap())
  807. bs := bson.D{{}}
  808. if form.Params != nil {
  809. if form.Params["uid"] != "" {
  810. bs1 := bson.E{"uid", form.Params["uid"]}
  811. bs = append(bs, bs1)
  812. }
  813. if form.Params["heroId"] != "" {
  814. bs1 := bson.E{"heroId", gconv.Int32(form.Params["heroId"])}
  815. bs = append(bs, bs1)
  816. }
  817. }
  818. data := g.ListAnyAny{}
  819. count := gm.ModelHeroComment.GetListCount(bs)
  820. page := util.Page{
  821. PageSize: gconv.Int64(form.Rows),
  822. CurrentPage: gconv.Int64(form.Page),
  823. Total: gconv.Int64(count),
  824. }
  825. heroCommentList := gm.ModelHeroComment.GetPageList(bs, page)
  826. dayMap := gmap.New()
  827. for heroCommentList.Next(context.TODO()) {
  828. var heroComment gm.HeroComment
  829. err := heroCommentList.Decode(&heroComment)
  830. if err != nil {
  831. //log.Fatal(err)
  832. log.Println(err)
  833. continue
  834. }
  835. dayMap.Set("serverId", heroComment.ServerId)
  836. dayMap.Set("heroId", heroComment.HeroId)
  837. dayMap.Set("uid", heroComment.Uid)
  838. dayMap.Set("uName", heroComment.UName)
  839. dayMap.Set("content", heroComment.Content)
  840. dayMap.Set("likes", heroComment.Likes)
  841. st := time.Unix(heroComment.Time, 0).Format(timeLayoutStr)
  842. dayMap.Set("time", st)
  843. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  844. }
  845. base.Succ(r,
  846. g.Map{
  847. "rows": data,
  848. "total": page.Total,
  849. "current": page.CurrentPage,
  850. })
  851. }
  852. //禁言英雄评论
  853. func (action *Action) SetSilenceHeroComment(r *ghttp.Request) {
  854. const cmdStr = "silence_herocomment"
  855. serverId := r.GetString("serverId")
  856. uid := r.GetString("uid")
  857. stype := r.GetString("stype") // 0解除禁言 1删除记录并设置禁言
  858. ages := uid + " " + stype
  859. //根据服务器id查询gmip,gmport,服务器名称
  860. singleResult := gameinfo.ModelServer.FindOne("server_id", serverId)
  861. var serverInfo gameinfo.ServerInfo
  862. err := singleResult.Decode(&serverInfo)
  863. gmip := serverInfo.GMIp
  864. gmport := serverInfo.GMPort
  865. if err != nil {
  866. base.Fail(r, "查询服务器信息出现异常," + serverId)
  867. }
  868. cmd := netutil.Gmcmd{
  869. ServerIp: gmip,
  870. ServerPort: gmport,
  871. Cmd: cmdStr,
  872. Args: ages,
  873. }
  874. fmt.Println(cmd)
  875. res := cmd.Creatcdk() //0 成功
  876. if res == -100 {
  877. base.Resp(r, 1, "thrift解析地址时出错", nil)
  878. } else if res == -101 {
  879. base.Resp(r, 1, "thrift打开服务器socket出错", nil)
  880. }
  881. if (stype == "1") {
  882. // 删除英雄评论
  883. gm.ModelHeroComment.DeleteMany("uid", uid)
  884. }
  885. // 保存日志
  886. var heroCommentLog gm.HeroCommentLog
  887. heroCommentLog.Id = primitive.NewObjectID()
  888. heroCommentLog.ServerId = serverInfo.ServerId
  889. heroCommentLog.ServerName = serverInfo.Name
  890. heroCommentLog.Uid = uid
  891. heroCommentLog.Stype = gconv.Int(stype)
  892. heroCommentLog.Cmd = cmdStr
  893. heroCommentLog.UpdateUser = base.GetUser(r).Username
  894. heroCommentLog.UpdateTime = time.Now().Unix()
  895. gm.ModelHeroCommentLog.InsertOne(heroCommentLog)
  896. if res == 0 {
  897. base.Resp(r, 0, "操作成功", nil)
  898. } else {
  899. base.Resp(r, 1, "操作失败", nil)
  900. }
  901. }
  902. // 坦克评论日志列表
  903. func (action *Action) HeroCommentLogList(r *ghttp.Request) {
  904. var timeLayoutStr = "2006-01-02 15:04:05"
  905. form := base.NewForm(r.GetMap())
  906. bs := bson.D{{}}
  907. data := g.ListAnyAny{}
  908. count := gm.ModelHeroCommentLog.GetListCount(bs)
  909. page := util.Page{
  910. PageSize: gconv.Int64(form.Rows),
  911. CurrentPage: gconv.Int64(form.Page),
  912. Total: gconv.Int64(count),
  913. }
  914. heroCommentLogList := gm.ModelHeroCommentLog.GetPageList(bs, page)
  915. dayMap := gmap.New()
  916. for heroCommentLogList.Next(context.TODO()) {
  917. var heroCommentLog gm.HeroCommentLog
  918. err := heroCommentLogList.Decode(&heroCommentLog)
  919. if err != nil {
  920. //log.Fatal(err)
  921. log.Println(err)
  922. continue
  923. }
  924. dayMap.Set("uid", heroCommentLog.Uid)
  925. dayMap.Set("serverId", heroCommentLog.ServerId)
  926. dayMap.Set("serverName", heroCommentLog.ServerName)
  927. dayMap.Set("type", heroCommentLog.Stype)
  928. dayMap.Set("cmd", heroCommentLog.Cmd)
  929. dayMap.Set("updateuser", heroCommentLog.UpdateUser)
  930. st := time.Unix(heroCommentLog.UpdateTime, 0).Format(timeLayoutStr)
  931. dayMap.Set("updatetime", st)
  932. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  933. }
  934. base.Succ(r,
  935. g.Map{
  936. "rows": data,
  937. "total": page.Total,
  938. "current": page.CurrentPage,
  939. })
  940. }
  941. //发送道具日志列表
  942. func (action *Action) GetSendModifyItemList(r *ghttp.Request) {
  943. var timeLayoutStr = "2006-01-02 15:04:05"
  944. form := base.NewForm(r.GetMap())
  945. bs := bson.D{bson.E{"cmd", "modifyitem"}}
  946. data := g.ListAnyAny{}
  947. count := gm.ModelModifyItemLog.GetListCount(bs)
  948. page := util.Page{
  949. PageSize: gconv.Int64(form.Rows),
  950. CurrentPage: gconv.Int64(form.Page),
  951. Total: gconv.Int64(count),
  952. }
  953. sendModifyItemLogList := gm.ModelModifyItemLog.GetPageList(bs, page)
  954. dayMap := gmap.New()
  955. for sendModifyItemLogList.Next(context.TODO()) {
  956. var modifyItemLog gm.ModifyItemLog
  957. err := sendModifyItemLogList.Decode(&modifyItemLog)
  958. if err != nil {
  959. //log.Fatal(err)
  960. log.Println(err)
  961. continue
  962. }
  963. dayMap.Set("id", modifyItemLog.Id)
  964. dayMap.Set("userid", modifyItemLog.UserId)
  965. dayMap.Set("servername", modifyItemLog.ServerName)
  966. dayMap.Set("param", modifyItemLog.Param)
  967. dayMap.Set("modifyMode", modifyItemLog.ModifyMode)
  968. dayMap.Set("cmd", modifyItemLog.Cmd)
  969. dayMap.Set("updateuser", modifyItemLog.UpdateUser)
  970. st := time.Unix(modifyItemLog.UpdateTime, 0).Format(timeLayoutStr)
  971. dayMap.Set("updatetime", st)
  972. dayMap.Set("state", modifyItemLog.State)
  973. data = append(g.ListAnyAny{gconv.Map(dayMap)}, data...)
  974. }
  975. fmt.Println(data)
  976. base.Succ(r,
  977. g.Map{
  978. "rows": data,
  979. "total": page.Total,
  980. "current": page.CurrentPage,
  981. })
  982. }
  983. //保存发送道具日志
  984. func (action *Action) SaveModifyItemLog(r *ghttp.Request) {
  985. form := base.NewForm(r.GetMap())
  986. cmdStr := form.Params["cmdStr"]
  987. serverid := form.Params["serverid"]
  988. if serverid == "" {
  989. base.Fail(r, "请选择服务器")
  990. }
  991. userid := form.Params["userid"]
  992. if cmdStr == "sendmail" && userid == "" {
  993. base.Fail(r, "请输入用户uid")
  994. }
  995. modifyMode := form.Params["modifyMode"]
  996. if modifyMode == "" {
  997. base.Fail(r, "请输入修改模式")
  998. }
  999. param := form.Params["param"]
  1000. if param == "" {
  1001. base.Fail(r, "请输入道具参数")
  1002. }
  1003. //根据服务器id查询gmip,gmport,服务器名称
  1004. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  1005. var serverInfo gameinfo.ServerInfo
  1006. err := singleResult.Decode(&serverInfo)
  1007. if err != nil {
  1008. base.Fail(r, "查询服务器信息出现异常,"+serverid)
  1009. }
  1010. gmip := serverInfo.GMIp
  1011. gmport := serverInfo.GMPort
  1012. servername := serverInfo.Name
  1013. //保存日志
  1014. modifyItemLog := new(gm.ModifyItemLog)
  1015. modifyItemLog.Id = primitive.NewObjectID()
  1016. if cmdStr == "modifyitem" {
  1017. modifyItemLog.UserId = gconv.String(userid)
  1018. }
  1019. modifyItemLog.ServerId = gconv.String(serverid)
  1020. modifyItemLog.ServerName = gconv.String(servername)
  1021. modifyItemLog.GMIp = gconv.String(gmip)
  1022. modifyItemLog.GMPort = gconv.String(gmport)
  1023. modifyItemLog.ModifyMode = gconv.Int(modifyMode)
  1024. modifyItemLog.Param = gconv.String(param)
  1025. modifyItemLog.Cmd = gconv.String(cmdStr)
  1026. username := base.GetUser(r).Username
  1027. modifyItemLog.UpdateUser = username
  1028. modifyItemLog.UpdateTime = time.Now().Unix()
  1029. modifyItemLog.State = 2 //刚保存为发送中 30s后执行发送;邮件状态:0:未发送 1:已发送 2:发送中 3:发送失败
  1030. gm.ModelModifyItemLog.InsertOne(modifyItemLog)
  1031. base.Resp(r, 0, "保存成功", modifyItemLog.Id)
  1032. }
  1033. //修改发送道具
  1034. func (action *Action) UpdateModifyItem(r *ghttp.Request) {
  1035. form := base.NewForm(r.GetMap())
  1036. data := gconv.Map(form.Params["data"])
  1037. gm.ModelModifyItemLog.InsUpdate(gconv.String(data["id"]), gconv.Int(data["state"]))
  1038. base.Resp(r, 0, "操作成功", nil)
  1039. }
  1040. //发送道具
  1041. func (action *Action) SendModifyItem(r *ghttp.Request) {
  1042. form := base.NewForm(r.GetMap())
  1043. dataId := form.Params["dataId"]
  1044. obj_id, _ := primitive.ObjectIDFromHex(gconv.String(dataId))
  1045. data := gm.ModelModifyItemLog.FindOne("_id", obj_id)
  1046. var modifyItemLog gm.ModifyItemLog
  1047. err := data.Decode(&modifyItemLog)
  1048. if err != nil {
  1049. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
  1050. base.Resp(r, -1, "当前数据有误", nil)
  1051. }
  1052. cmdStr := modifyItemLog.Cmd
  1053. serverid := modifyItemLog.ServerId
  1054. userid := ""
  1055. if cmdStr == "modifyitem" {
  1056. userid = modifyItemLog.UserId
  1057. }
  1058. modifyMode := gconv.String(modifyItemLog.ModifyMode)
  1059. param := modifyItemLog.Param
  1060. //根据服务器id查询gmip,gmport,服务器名称
  1061. singleResult := gameinfo.ModelServer.FindOne("_id", gconv.Int32(serverid))
  1062. var serverInfo gameinfo.ServerInfo
  1063. err = singleResult.Decode(&serverInfo)
  1064. if err != nil {
  1065. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
  1066. base.Resp(r, -1, "查询服务器信息出现异常", nil)
  1067. }
  1068. gmip := serverInfo.GMIp
  1069. gmport := serverInfo.GMPort
  1070. ages := modifyMode + " " + param
  1071. cmd := netutil.Gmcmd{
  1072. ServerIp: gmip,
  1073. ServerPort: gmport,
  1074. Cmd: cmdStr,
  1075. UserId: userid,
  1076. Args: ages,
  1077. }
  1078. res := int32(-1)
  1079. if (cmdStr == "modifyitem") {
  1080. res = cmd.SendGM() //0 成功
  1081. } else {
  1082. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
  1083. base.Resp(r, -1, "当前数据有误", nil)
  1084. }
  1085. if res == -100 {
  1086. // 修改日志状态为发送失败
  1087. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
  1088. base.Resp(r, -1, "thrift解析地址时出错", nil)
  1089. } else if res == -101 {
  1090. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
  1091. base.Resp(r, -1, "thrift打开服务器socket出错", nil)
  1092. } else if res == 0 {
  1093. // 修改日志状态为已发送
  1094. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 1)
  1095. base.Resp(r, 0, "发送成功", nil)
  1096. } else {
  1097. gm.ModelModifyItemLog.InsUpdate(gconv.String(dataId), 3)
  1098. base.Resp(r, -1, "发送失败", nil)
  1099. }
  1100. }