netease_log_def.go 16 KB

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