netease_log_def.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. package model
  2. import (
  3. "encoding/json"
  4. "rocommon/util"
  5. model2 "roserver/baseserver/model"
  6. "roserver/serverproto"
  7. "strconv"
  8. )
  9. //网易P1日志
  10. const (
  11. SDKPlatform_Quick = "SDKQuick"
  12. SDKPlatform_NBSDK = "SDKNB"
  13. SDKPlatform_UniSDK = "SDKUni" //SDKUni
  14. )
  15. func neteaseWriteLog(prefix string, logInfo interface{}) {
  16. return
  17. retStr, err := json.Marshal(logInfo)
  18. if err == nil {
  19. timeStr := util.GetCurrentTimeNow().Format("2006-01-02 15:04:05 Z0700")
  20. util.SpecialF("[%v][%v],%v", timeStr, prefix, string(retStr))
  21. }
  22. }
  23. //OnlineRoleNum
  24. type NeteaseLogOnlineRoleNum struct {
  25. Server int `json:"server"`
  26. Online int `json:"online"`
  27. OnLineTime uint64 `json:"on_line_time"`
  28. }
  29. func (this *NeteaseLogOnlineRoleNum) Log(role *Role) {
  30. neteaseWriteLog("OnlineRoleNum", this)
  31. }
  32. //LogoutRole
  33. type NeteaseLogCommonInfo struct {
  34. IPv4 string `json:"ip"`
  35. Server int `json:"server"`
  36. Ipv6 string `json:"ipv6"`
  37. DeviceModel string `json:"device_model"`
  38. DeviceHeight int `json:"device_height"`
  39. DeviceWidth int `json:"device_width"`
  40. OsName string `json:"os_name"`
  41. OsVer string `json:"os_ver"`
  42. MacAddr string `json:"mac_addr"`
  43. Udid string `json:"udid"`
  44. Isp string `json:"isp"`
  45. Network string `json:"network"`
  46. AppChannel string `json:"app_channel"`
  47. AppVer string `json:"app_ver"`
  48. TransId string `json:"transid"`
  49. UnisdkDeviceId string `json:"unisdk_deviceid"`
  50. IsEmulator int `json:"is_emulator"`
  51. IsRoot int `json:"is_root"`
  52. AccountId string `json:"account_id"`
  53. OldAccountId string `json:"old_accountid"`
  54. IMEI string `json:"imei"`
  55. CountryCode string `json:"country_code"`
  56. EnterSN string `json:"enter_sn"`
  57. OAid string `json:"oaid"`
  58. EngineVer string `json:"engine_ver"`
  59. }
  60. type NeteaseLogCreateRole struct {
  61. NeteaseLogCommonInfo
  62. Aid uint64 `json:"aid"`
  63. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  64. CreateTime uint64 `json:"create_time"` //s timestamp
  65. RoleName string `json:"role_name"`
  66. RoleLevel int `json:"role_level"`
  67. VipLevel int `json:"vip_level"`
  68. Exp int64 `json:"exp"`
  69. LogoutTime uint64 `json:"logout_time"` //s timestamp
  70. OnlineTime int `json:"online_time"` //s
  71. }
  72. type ItemData struct {
  73. ItemId int `json:"item_id"` //s
  74. ItemNum int `json:"item_num"` //s
  75. }
  76. type PayDetail struct {
  77. Name string `json:"prepaid_name"` //s
  78. GoodsId int `json:"prepaid_id"` //s
  79. GoodsType int `json:"prepaid_type"` //s
  80. }
  81. //充值日志
  82. type NeteaseLogRoleCharge struct {
  83. NeteaseLogCommonInfo
  84. //重置获得的道具
  85. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  86. RoleName string `json:"role_name"`
  87. RoleLevel int `json:"role_level"`
  88. VipLevel int `json:"vip_level"`
  89. PayChannel string `json:"pay_channel"`
  90. Gold int `json:"yuanbao"`
  91. FreeGold int `json:"free_yuanbao"`
  92. ChargeRMB float32 `json:"cash"`
  93. Currency string `json:"currency"`
  94. CurGold int `json:"left_yuanbao"`
  95. CurFreeGold int `json:"left_free_yuanbao"`
  96. PayTime uint64 `json:"pay_time"`
  97. PayMethod string `json:"pay_method"`
  98. ItemList []*ItemData `json:"get_item"` //s
  99. SN string `json:"sn"` //sSN string `json:"sn"` //s
  100. Consumesn string `json:"consumesn"`
  101. Detail PayDetail `json:"prepaid_detail"`
  102. Aid uint64 `json:"aid"`
  103. }
  104. //金币购买道具日志
  105. type NeteaseLogGoldBuyItem struct {
  106. NeteaseLogCommonInfo
  107. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  108. RoleName string `json:"role_name"`
  109. RoleLevel int `json:"role_level"`
  110. VipLevel int `json:"vip_level"`
  111. ItemId int `json:"item_id"` //获得的物品ID。
  112. ItemName string `json:"item_name"`
  113. BuyTime uint64 `json:"buy_time"`
  114. ExpireTime uint64 `json:"expire_time"`
  115. ItemCount int `json:"count"`
  116. Price int `json:"price"`
  117. Gold int `json:"yuanbao"` //购买花费的金币
  118. CurGold int `json:"left_yuanbao"` //当前的金币
  119. FreeGold int `json:"free_yuanbao"`
  120. CurFreeGold int `json:"left_free_yuanbao"`
  121. CostMoney int `json:"cost_money"`
  122. Aid uint64 `json:"aid"`
  123. }
  124. //金币购买其他物品
  125. type NeteaseLogGoldBuyOther struct {
  126. NeteaseLogCommonInfo
  127. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  128. RoleLevel int `json:"role_level"`
  129. VipLevel int `json:"vip_level"`
  130. Reason string `json:"reason"`
  131. Gold int `json:"yuanbao"` //购买花费的金币
  132. CurGold int `json:"left_yuanbao"` //当前的金币
  133. FreeGold int `json:"free_yuanbao"`
  134. CurFreeGold int `json:"left_free_yuanbao"`
  135. UseTime uint64 `json:"use_time"`
  136. Aid uint64 `json:"aid"`
  137. }
  138. //获得元宝日志
  139. type NeteaseLogRoleGetGold struct {
  140. NeteaseLogCommonInfo
  141. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  142. RoleName string `json:"role_name"`
  143. RoleLevel int `json:"role_level"`
  144. VipLevel int `json:"vip_level"`
  145. Reason string `json:"reason"`
  146. Gold int `json:"yuanbao"` //购买获得的金币
  147. FreeGold int `json:"free_yuanbao"`
  148. CurGold int `json:"left_yuanbao"` //当前的金币
  149. CurFreeGold int `json:"left_free_yuanbao"`
  150. GainTime uint64 `json:"gain_time"`
  151. Aid uint64 `json:"aid"`
  152. }
  153. //获得元宝日志 计费监控
  154. type NeteaseLogRoleGetGoldJF struct {
  155. NeteaseLogCommonInfo
  156. Aid uint64 `json:"aid"`
  157. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  158. RoleName string `json:"role_name"`
  159. RoleLevel int `json:"role_level"`
  160. VipLevel int `json:"vip_level"`
  161. GainType int `json:"gain_type"`
  162. SN string `json:"sn"`
  163. Consumesn string `json:"consumesn"`
  164. PayChannel string `json:"pay_channel"`
  165. Reason PayDetail `json:"reason"`
  166. TotalGold int `json:"yuanbao"` //购买需要的金币
  167. CurTotalGold int `json:"left_yuanbao"` //当前的金币
  168. PayGold int `json:"pay_yuanbao"` //当前的金币
  169. CurPayGold int `json:"left_pay_yuanbao"` //当前的金币
  170. FreeGold int `json:"free_yuanbao"`
  171. CurFreeGold int `json:"left_free_yuanbao"`
  172. GainTime uint64 `json:"gain_time"`
  173. }
  174. type UseReason struct {
  175. ItemId int `json:"item_id"`
  176. ItemName string `json:"item_name"`
  177. Count int `json:"count"`
  178. Info int `json:"info"`
  179. }
  180. //使用元宝日志 计费监控
  181. type NeteaseLogRoleUseGoldJF struct {
  182. NeteaseLogCommonInfo
  183. Aid uint64 `json:"aid"`
  184. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  185. RoleName string `json:"role_name"`
  186. RoleLevel int `json:"role_level"`
  187. VipLevel int `json:"vip_level"`
  188. UseType int `json:"use_type"`
  189. Reason UseReason `json:"reason"`
  190. TotalGold int `json:"yuanbao"` //消耗金币总量
  191. CurTotalGold int `json:"left_yuanbao"` //当前的金币总量
  192. PayGold int `json:"pay_yuanbao"` //消耗付费金币
  193. CurPayGold int `json:"left_pay_yuanbao"` //付费金币总量
  194. FreeGold int `json:"free_yuanbao"`
  195. CurFreeGold int `json:"left_free_yuanbao"`
  196. UseTime uint64 `json:"use_time"`
  197. }
  198. //聊天监控
  199. type NeteaseLogRoleChat struct {
  200. NeteaseLogCommonInfo
  201. RoleId string `json:"role_id"` //角色唯一标识,在所有服唯一
  202. RoleName string `json:"role_name"`
  203. RoleLevel int `json:"role_level"`
  204. Content string `json:"content"`
  205. Channel string `json:"channel"`
  206. Scene string `json:"scene"`
  207. Axis string `json:"axis"`
  208. ChatTime uint64 `json:"chat_time"`
  209. YAccount string `json:"y_account_id"`
  210. YRoleId string `json:"y_obj"`
  211. YLevel int `json:"y_level"`
  212. YName string `json:"y_name"`
  213. }
  214. func (this *NeteaseLogCreateRole) Log(role *Role) {
  215. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  216. return
  217. }
  218. if role.GetClientParam() != nil {
  219. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  220. //this.commonInfo = *(role.GetClientParam())
  221. }
  222. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  223. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  224. this.CreateTime = role.RegisterTime / 1000 //s
  225. this.RoleName = role.GetNickName()
  226. this.RoleLevel = int(role.GetRoleLevel())
  227. this.VipLevel = int(role.GetRoleVipLevel())
  228. this.Exp = int64(role.GetRoleBase().GetRoleBaseExp())
  229. this.LogoutTime = role.GetRoleBase().RoleData().LastLoginTime / 1000 //s
  230. neteaseWriteLog("LogoutRole", this)
  231. }
  232. func (this *NeteaseLogRoleCharge) LogRoleCharge(role *Role) {
  233. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  234. return
  235. }
  236. if role.GetClientParam() != nil {
  237. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  238. }
  239. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  240. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  241. this.RoleName = role.GetNickName()
  242. this.RoleLevel = int(role.GetRoleLevel())
  243. this.VipLevel = int(role.GetRoleVipLevel())
  244. this.FreeGold = 0
  245. this.CurFreeGold = 0
  246. neteaseWriteLog("Prepaid", this)
  247. }
  248. func (this *NeteaseLogGoldBuyItem) LogRoleGoldBuyItem(role *Role) {
  249. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  250. return
  251. }
  252. if role.GetClientParam() != nil {
  253. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  254. }
  255. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  256. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  257. this.RoleName = role.GetNickName()
  258. this.RoleLevel = int(role.GetRoleLevel())
  259. this.VipLevel = int(role.GetRoleVipLevel())
  260. this.FreeGold = 0
  261. this.CurFreeGold = 0
  262. this.CurGold = int(role.GetRmb())
  263. neteaseWriteLog("ItemBuy", this)
  264. }
  265. func (this *NeteaseLogGoldBuyOther) LogRoleGoldBuyOther(role *Role) {
  266. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  267. return
  268. }
  269. if role.GetClientParam() != nil {
  270. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  271. }
  272. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  273. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  274. this.RoleLevel = int(role.GetRoleLevel())
  275. this.VipLevel = int(role.GetRoleVipLevel())
  276. this.FreeGold = 0
  277. this.CurFreeGold = 0
  278. this.CurGold = int(role.GetRmb())
  279. neteaseWriteLog("YuanbaoUse", this)
  280. }
  281. func (this *NeteaseLogRoleGetGold) LogRoleGetGold(role *Role) {
  282. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  283. return
  284. }
  285. if role.GetClientParam() != nil {
  286. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  287. }
  288. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  289. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  290. this.RoleName = role.GetNickName()
  291. this.RoleLevel = int(role.GetRoleLevel())
  292. this.VipLevel = int(role.GetRoleVipLevel())
  293. this.FreeGold = 0
  294. this.CurFreeGold = 0
  295. this.CurGold = int(role.GetRmb())
  296. neteaseWriteLog("YuanbaoGain", this)
  297. }
  298. func (this *NeteaseLogRoleGetGoldJF) LogRoleGetGoldJF(role *Role) {
  299. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  300. return
  301. }
  302. if role.GetClientParam() != nil {
  303. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  304. }
  305. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  306. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  307. this.RoleName = role.GetNickName()
  308. this.RoleLevel = int(role.GetRoleLevel())
  309. this.VipLevel = int(role.GetRoleVipLevel())
  310. this.FreeGold = 0
  311. this.CurFreeGold = 0
  312. neteaseWriteLog("JFYuanbaoGain", this)
  313. }
  314. func (this *NeteaseLogRoleUseGoldJF) LogRoleUseGoldJF(role *Role) {
  315. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  316. return
  317. }
  318. if role.GetClientParam() != nil {
  319. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  320. }
  321. this.Aid, _ = model2.Str2NumU64(role.GetOpenId())
  322. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  323. this.RoleName = role.GetNickName()
  324. this.RoleLevel = int(role.GetRoleLevel())
  325. this.VipLevel = int(role.GetRoleVipLevel())
  326. this.FreeGold = 0
  327. this.CurFreeGold = 0
  328. neteaseWriteLog("JFYuanbaoUse", this)
  329. }
  330. func (this *NeteaseLogRoleChat) LogRoleChat(role *Role, targetRole *Role) {
  331. if role == nil || role.GetPlatform() != SDKPlatform_UniSDK {
  332. return
  333. }
  334. if role.GetClientParam() != nil {
  335. this.NeteaseLogCommonInfo = *(role.GetClientParam())
  336. }
  337. this.RoleId = strconv.FormatUint(role.GetUUid(), 10)
  338. this.RoleName = role.GetNickName()
  339. this.RoleLevel = int(role.GetRoleLevel())
  340. if targetRole != nil {
  341. this.YRoleId = strconv.FormatUint(targetRole.GetUUid(), 10)
  342. this.YLevel = int(targetRole.GetRoleLevel())
  343. this.YName = targetRole.GetNickName()
  344. if targetRole.GetClientParam() != nil {
  345. this.YAccount = targetRole.GetClientParam().AccountId
  346. }
  347. }
  348. neteaseWriteLog("Chat", this)
  349. }
  350. //uni sdk log
  351. func (this *Role) WriteChargeLog(payRewardInfo *serverproto.PayOrderSaveInfo) int {
  352. if payRewardInfo == nil {
  353. return 0
  354. }
  355. nLog := &NeteaseLogRoleCharge{
  356. PayChannel: payRewardInfo.PayChannel,
  357. ChargeRMB: payRewardInfo.Amount,
  358. CurGold: int(this.GetRmb()),
  359. SN: strconv.FormatUint(payRewardInfo.CpOrderId, 10),
  360. Consumesn: payRewardInfo.SdkOrderId,
  361. Currency: payRewardInfo.PayCurrency,
  362. PayMethod: payRewardInfo.PayMethod,
  363. PayTime: payRewardInfo.PayTime,
  364. }
  365. nLog.Detail.GoodsId = int(payRewardInfo.GoodsId)
  366. nLog.Detail.Name = payRewardInfo.GoodsName
  367. nLog.Detail.GoodsType = int(payRewardInfo.GoodsType)
  368. for _, data := range payRewardInfo.RewardList {
  369. if data.Key == int32(serverproto.ResType_Res_Rmb) {
  370. nLog.Gold = int(data.Value)
  371. }
  372. nLog.ItemList = append(nLog.ItemList, &ItemData{
  373. ItemId: int(data.Key),
  374. ItemNum: int(data.Value),
  375. })
  376. }
  377. nLog.LogRoleCharge(this)
  378. return nLog.Gold
  379. }
  380. //计费:充值获取金币
  381. func (this *Role) WriteChargeAddGoldLogJF(payRewardInfo *serverproto.PayOrderSaveInfo, gold int32) {
  382. if payRewardInfo == nil {
  383. return
  384. }
  385. nLog := &NeteaseLogRoleGetGoldJF{
  386. SN: strconv.FormatUint(payRewardInfo.CpOrderId, 10),
  387. Consumesn: payRewardInfo.SdkOrderId,
  388. TotalGold: int(gold),
  389. CurTotalGold: int(this.GetRmb()),
  390. PayGold: int(gold),
  391. CurPayGold: int(this.GetRmb()),
  392. GainTime: uint64(util.GetTimeSeconds()),
  393. GainType: 0,
  394. PayChannel: payRewardInfo.PayChannel,
  395. }
  396. nLog.Reason.Name = payRewardInfo.GoodsName
  397. nLog.Reason.GoodsId = int(payRewardInfo.GoodsId)
  398. nLog.Reason.GoodsType = int(payRewardInfo.GoodsType)
  399. nLog.LogRoleGetGoldJF(this)
  400. }
  401. //计费:非充值获取金币
  402. func (this *Role) WriteAddGoldLogJF(gold int32, addFrom int32) {
  403. nLog := &NeteaseLogRoleGetGoldJF{
  404. TotalGold: int(gold),
  405. CurTotalGold: int(this.GetRmb()),
  406. PayGold: int(gold),
  407. CurPayGold: int(this.GetRmb()),
  408. GainTime: uint64(util.GetTimeSeconds()),
  409. GainType: 0,
  410. }
  411. nLog.Reason.Name = strconv.FormatUint(uint64(addFrom), 10)
  412. nLog.LogRoleGetGoldJF(this)
  413. }
  414. //非计费:获取金币
  415. func (this *Role) WriteAddGoldLog(gold int32, addFrom int32, reason int32) {
  416. //nLog := &NeteaseLogRoleGetGold{
  417. // Gold: int(gold),
  418. // GainTime: uint64(util.GetTimeSeconds()),
  419. //}
  420. //
  421. //cfg, ok := serverproto.UseGoldPointLoader[int32(addFrom)]
  422. //if ok {
  423. // nLog.Reason = cfg.Explain
  424. //} else {
  425. // nLog.Reason = strconv.FormatUint(uint64(addFrom), 10)
  426. //}
  427. //nLog.LogRoleGetGold(this)
  428. }
  429. //计费:消耗金币
  430. func (this *Role) WriteUseGoldLogJF(st AddItemST) {
  431. nLog := &NeteaseLogRoleUseGoldJF{
  432. UseTime: uint64(util.GetTimeSeconds()),
  433. }
  434. if st.AddFrom == AddFrom_Shop_Buy ||
  435. st.AddFrom == AddFrom_Shop_Arane ||
  436. st.AddFrom == AddFrom_Shop_Dark ||
  437. st.AddFrom == AddFrom_Shop_Guild ||
  438. st.AddFrom == AddFrom_Shop_Pet {
  439. nLog.UseType = 0
  440. nLog.Reason.ItemId = int(st.ReasonParam)
  441. nLog.Reason.Count = int(st.ReasonParam2)
  442. shopCfg, ok := serverproto.ShopCfgLoader[st.ReasonParam]
  443. if ok {
  444. nLog.Reason.ItemName = shopCfg.GoodsName
  445. }
  446. } else {
  447. nLog.UseType = 1
  448. nLog.Reason.Info = int(st.AddFrom)
  449. }
  450. nLog.TotalGold = int(st.ItemCount)
  451. nLog.CurTotalGold = int(this.GetRmb())
  452. nLog.PayGold = int(st.ItemCount)
  453. nLog.CurPayGold = int(this.GetRmb())
  454. nLog.LogRoleUseGoldJF(this)
  455. }
  456. func (this *Role) WriteUseGoldOtherLog(st AddItemST) {
  457. //nLog := &NeteaseLogGoldBuyOther{
  458. // UseTime: uint64(util.GetTimeSeconds()),
  459. //}
  460. //
  461. //cfg, ok := serverproto.UseGoldPointLoader[int32(st.AddFrom)]
  462. //if ok {
  463. // nLog.Reason = cfg.Explain
  464. //} else {
  465. // nLog.Reason = strconv.FormatUint(uint64(st.AddFrom), 10)
  466. //}
  467. //nLog.Gold = int(st.ItemCount)
  468. //nLog.LogRoleGoldBuyOther(this)
  469. }