model.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. package model
  2. import (
  3. "crypto/hmac"
  4. "crypto/sha1"
  5. "encoding/base64"
  6. "encoding/json"
  7. "fmt"
  8. "math/rand"
  9. "net/url"
  10. "strings"
  11. gotime "time"
  12. "go-common/app/service/main/account-recovery/conf"
  13. "go-common/library/log"
  14. "go-common/library/time"
  15. )
  16. // QueryInfoReq query mid info req
  17. type QueryInfoReq struct {
  18. QType string `form:"q_type" validate:"required"`
  19. QValue string `form:"q_value" validate:"required"`
  20. CToken string `form:"token" validate:"required"`
  21. Code string `form:"code" validate:"required"`
  22. }
  23. // QueryInfoResp query info response
  24. type QueryInfoResp struct {
  25. Status int64 `json:"status"`
  26. UID int64 `json:"uid"`
  27. }
  28. // MIDInfo mid info data
  29. type MIDInfo struct {
  30. Mids string `json:"mids"`
  31. Count int64 `json:"count"`
  32. }
  33. // User user info data
  34. type User struct {
  35. UserID string `json:"userid"`
  36. Pwd string `json:"pwd"`
  37. }
  38. // Check check safe: Flag , reg: CheckInfo
  39. type Check struct {
  40. CheckInfo string `json:"checkInfo"`
  41. }
  42. // UserInfoReq 用户申诉提交信息
  43. type UserInfoReq struct {
  44. LoginAddrs string `json:"login_addrs" form:"login_addrs" validate:"required,min=1"`
  45. RegTime time.Time `json:"reg_time" form:"reg_time" validate:"required"`
  46. RegType int8 `json:"reg_type" form:"reg_type" validate:"required"`
  47. RegAddr string `json:"reg_addr" form:"reg_addr" validate:"required"`
  48. Unames string `json:"unames" form:"unames"`
  49. Pwds string `json:"pwds" form:"pwds" validate:"required"`
  50. Phones string `json:"phones" form:"phones"`
  51. Emails string `json:"emails" form:"emails"`
  52. SafeQuestion int8 `json:"safe_question" form:"safe_question" default:"99"`
  53. SafeAnswer string `json:"safe_answer" form:"safe_answer"`
  54. CardID string `json:"card_id" form:"card_id"`
  55. CardType int8 `json:"card_type" form:"card_type" default:"99"`
  56. Captcha string `json:"captcha" form:"captcha" validate:"required"`
  57. LinkMail string `json:"link_mail" form:"link_mail" validate:"required,email"`
  58. Mid int64 `json:"mid" form:"mid" validate:"required,min=1"`
  59. Business string `json:"business" form:"business" default:"account"`
  60. BusinessMap map[string]string
  61. Files []string `json:"files" form:"files,split"`
  62. LastSucCount int64 //成功找回的总次数
  63. LastSucCTime time.Time //上次成功找回的提交时间
  64. }
  65. // DBAccountRecoveryAddit is
  66. type DBAccountRecoveryAddit struct {
  67. Rid int64 `json:"rid"`
  68. Files string `json:"files"`
  69. Extra string `json:"extra"`
  70. Ctime time.Time `json:"ctime"`
  71. Mtime time.Time `json:"mtime"`
  72. }
  73. // AsRecoveryAddit parse DBAccountRecoveryAddit to RecoveryAddit
  74. func (dbAddit *DBAccountRecoveryAddit) AsRecoveryAddit() *RecoveryAddit {
  75. addit := &RecoveryAddit{
  76. Files: []string{},
  77. Extra: map[string]interface{}{},
  78. }
  79. if err := json.Unmarshal([]byte(dbAddit.Extra), &addit.Extra); err != nil {
  80. log.Error("QueryRecoveryAddit: json.Unmarshal(%s) error(%v)", addit.Extra, err)
  81. }
  82. addit.Files = strings.Split(dbAddit.Files, ",")
  83. for i, v := range addit.Files {
  84. addit.Files[i] = BuildFileURL(v)
  85. }
  86. return addit
  87. }
  88. // BuildFileURL build bfs download url
  89. func BuildFileURL(raw string) string {
  90. if raw == "" {
  91. return ""
  92. }
  93. ori, err := url.Parse(raw)
  94. if err != nil {
  95. return raw
  96. }
  97. if strings.HasPrefix(ori.Path, "/bfs/account") {
  98. //println("filename=====",bfsFilename(ori.Path, "account"))
  99. token := authorize(conf.Conf.Bfs.Key, conf.Conf.Bfs.Secret, "GET", "account", bfsFilename(ori.Path, "account"), gotime.Now().Unix())
  100. p := url.Values{}
  101. p.Set("token", token)
  102. ori.RawQuery = p.Encode()
  103. }
  104. if ori.Hostname() == "" {
  105. ori.Host = fmt.Sprintf("i%d.hdslb.com", rand.Int63n(3))
  106. ori.Scheme = "http"
  107. }
  108. return ori.String()
  109. }
  110. // authorize returns authorization for upload file to bfs
  111. func authorize(key, secret, method, bucket, filename string, expire int64) string {
  112. content := fmt.Sprintf("%s\n%s\n%s\n%d\n", method, bucket, filename, expire)
  113. mac := hmac.New(sha1.New, []byte(secret))
  114. mac.Write([]byte(content))
  115. signature := base64.StdEncoding.EncodeToString(mac.Sum(nil))
  116. return fmt.Sprintf("%s:%s:%d", key, signature, expire)
  117. }
  118. func bfsFilename(path string, bucket string) string {
  119. return strings.TrimLeft(path, fmt.Sprintf("/bfs/%s", bucket))
  120. }
  121. // QueryRecoveryInfoReq 信息查询请求
  122. type QueryRecoveryInfoReq struct {
  123. // FirstRid int64 `json:"first_rid" form:"first_rid"`
  124. // LastRid int64 `json:"last_rid" form:"last_rid"`
  125. // RID account recovery info id
  126. RID int64 `json:"rid" form:"rid"`
  127. // UID user id
  128. UID int64 `json:"uid" form:"uid"`
  129. // Status account recovery status
  130. // status value, example: default "0", thought "1", reject "2"
  131. Status *int64 `json:"status" form:"-"`
  132. // Game is game user
  133. // game value, example: "1"/"0"
  134. Game *int64 `json:"game" form:"-"`
  135. // Size default size 10
  136. Size int64 `json:"size" form:"size"`
  137. StartTime time.Time `json:"start_time" form:"start_time"`
  138. EndTime time.Time `json:"end_time" form:"end_time"`
  139. IsAdvanced bool `json:"-"`
  140. // CurrPage int64 `form:"curr_page"`
  141. Page int64 `form:"page"`
  142. Bussiness string `json:"-"`
  143. }
  144. // DBRecoveryInfoParams DBRecoveryInfoParams
  145. type DBRecoveryInfoParams struct {
  146. ExistGame bool
  147. ExistStatus bool
  148. ExistMid bool
  149. Mid int64
  150. Game int64
  151. Status int64
  152. FirstRid int64
  153. LastRid int64
  154. Size int64
  155. StartTime time.Time
  156. EndTime time.Time
  157. SubNum int64
  158. CurrPage int64
  159. }
  160. // AccountRecoveryInfo account recovery db info
  161. type AccountRecoveryInfo struct {
  162. Rid int64
  163. Mid int64
  164. UserType int64
  165. Status int64
  166. LoginAddr string
  167. UNames string
  168. RegTime time.Time `json:"-"`
  169. RegTimeStr string `json:"RegTime"`
  170. RegType int64 `json:"-"`
  171. RegTypeStr string `json:"RegType"`
  172. RegAddr string
  173. Pwd string
  174. Phones string
  175. Emails string
  176. SafeQuestion int64 `json:"-"`
  177. SafeQuestionStr string `json:"SafeQuestion"`
  178. SafeAnswer string
  179. CardType int64 `json:"-"`
  180. CardTypeStr string `json:"CardType"`
  181. CardID string
  182. SysLoginAddr string
  183. SysReg string
  184. SysUNames string
  185. SysPwds string
  186. SysPhones string
  187. SysEmails string
  188. SysSafe string
  189. SysCard string
  190. LinkEmail string
  191. Operator string
  192. OptTime time.Time
  193. Remark string
  194. CTime time.Time
  195. MTime time.Time
  196. Bussiness string
  197. LastSucCount int64
  198. LastSucCTime time.Time
  199. }
  200. // RecoveryResInfo RecoveryResInfo
  201. type RecoveryResInfo struct {
  202. AccountRecoveryInfo
  203. RecoverySuccess
  204. RecoveryAddit
  205. LastSuccessData
  206. }
  207. // RecoverySuccess recovery success info
  208. type RecoverySuccess struct {
  209. SuccessMID int64 `json:"-"`
  210. SuccessCount int64
  211. FirstSuccessTime time.Time
  212. LastSuccessTime time.Time
  213. }
  214. // LastSuccessData last recovery success info
  215. type LastSuccessData struct {
  216. LastApplyMID int64 `json:"-"`
  217. LastApplyTime time.Time
  218. }
  219. // RecoveryAddit common business field
  220. type RecoveryAddit struct {
  221. Files []string
  222. Extra map[string]interface{}
  223. }
  224. // MultiQueryRes MultiQueryRes
  225. type MultiQueryRes struct {
  226. Info []*RecoveryResInfo
  227. Page *Page
  228. }
  229. // UserInfoRes response of userInfo
  230. type UserInfoRes struct {
  231. LoginAddrs string `json:"login_addrs"`
  232. Unames string `json:"unames"`
  233. Pwds string `json:"pwds"`
  234. Phones string `json:"phones"`
  235. Emails string `json:"emails"`
  236. RegInfo *RegInfo `json:"reg_info"`
  237. SafeInfo *SafeInfo `json:"safe_info"`
  238. CardInfo *CardInfo `json:"card_info"`
  239. }
  240. // RegInfo reg info
  241. type RegInfo struct {
  242. RegTime time.Time `json:"reg_time"`
  243. RegType int64 `json:"reg_type"`
  244. RegAddr string `json:"reg_addr"`
  245. }
  246. // SafeInfo safe info
  247. type SafeInfo struct {
  248. SafeQuestion int8 `json:"safe_question"`
  249. SafeAnswer string `json:"safe_answer"`
  250. }
  251. // CardInfo card info
  252. type CardInfo struct {
  253. CardID string `json:"card_id"`
  254. CardType int8 `json:"card_type"`
  255. }
  256. // SysInfo sys check info
  257. type SysInfo struct {
  258. SysLoginAddrs string `json:"sys_login_addrs"`
  259. SysReg string `json:"sys_reg"`
  260. SysUNames string `json:"sys_nick"`
  261. SysPwds string `json:"sys_pwds"`
  262. SysPhones string `json:"sys_phones"`
  263. SysEmails string `json:"sys_emails"`
  264. SysSafe string `json:"sys_safe"`
  265. SysCard string `json:"sys_card"`
  266. }
  267. // OperInfo operate info
  268. type OperInfo struct {
  269. Operator string `json:"operator"`
  270. OperTime time.Time `json:"oper_time"`
  271. }
  272. // AppealRes 信息查询返回结果
  273. type AppealRes struct {
  274. Rid int64 `json:"rid"`
  275. Mid int64 `json:"uid"`
  276. Ctime time.Time `json:"ctime"`
  277. Count int64 `json:"count"`
  278. LinkEmail string `json:"link_email"`
  279. Remark string `json:"remark"`
  280. Status int64 `json:"status"`
  281. UserInfoRes *UserInfoRes `json:"user_info"`
  282. SysInfo *SysInfo `json:"sys_info"`
  283. OperInfo *OperInfo `json:"oper_info"`
  284. }
  285. // Page page
  286. type Page struct {
  287. //Num int64 `json:"num"`
  288. Size int64 `json:"size"`
  289. Total int64 `json:"total"`
  290. }
  291. //JudgeReq appeal judge
  292. type JudgeReq struct {
  293. Status int64 `form:"status" validate:"required"`
  294. Rid int64 `form:"rid" validate:"required"`
  295. Operator string `form:"operator" validate:"required"`
  296. OptTime time.Time `form:"opt_time" validate:"required"`
  297. Remark string `form:"remark"`
  298. }
  299. //BatchJudgeReq appeal judge
  300. type BatchJudgeReq struct {
  301. Status int64 `form:"status" validate:"required"`
  302. Rids string `form:"rids" validate:"required"`
  303. Operator string `form:"operator" validate:"required"`
  304. OptTime time.Time `form:"opt_time" validate:"required"`
  305. Remark string `form:"remark"`
  306. RidsAry []int64
  307. }
  308. // CommonResq common response
  309. type CommonResq struct {
  310. Code int64 `json:"code"`
  311. TS int64 `json:"ts"`
  312. Message string `json:"message"`
  313. }
  314. // Token captcha token
  315. type Token struct {
  316. Token string `json:"token"`
  317. URL string `json:"url"`
  318. }
  319. // TokenResq response of capthca
  320. type TokenResq struct {
  321. CommonResq
  322. Data *Token `json:"data"`
  323. }
  324. // Game data of game
  325. type Game struct {
  326. GameBaseID int `json:"id"`
  327. GameName string `json:"name"`
  328. LastLogin string `json:"lastLogin"`
  329. }
  330. // GameListRes game list res
  331. type GameListRes struct {
  332. Mid int64 `json:"mid"`
  333. Items []*Game `json:"items"`
  334. }
  335. // UserBindLogRes UserBindLogRes
  336. type UserBindLogRes struct {
  337. Page Page `json:"page"`
  338. Result []*UserBindLog `json:"result"`
  339. }
  340. // UserBindLog UserBindLog
  341. type UserBindLog struct {
  342. Mid int64 `json:"mid"`
  343. Phone string `json:"phone"`
  344. Email string `json:"email"`
  345. Time string `json:"time"`
  346. }
  347. // BatchAppeal some of appeal info
  348. type BatchAppeal struct {
  349. Rid string
  350. Mid string
  351. LinkMail string
  352. Ctime time.Time
  353. }
  354. // NickNameReq request es params
  355. type NickNameReq struct {
  356. Mid int64 `form:"mid"`
  357. Page int `form:"page"`
  358. Size int `form:"size"`
  359. From int64 `form:"from"`
  360. To int64 `form:"to"`
  361. }
  362. // NickNameLogEs query field form es
  363. type NickNameLogEs struct {
  364. OldName string `json:"str_0"`
  365. NewName string `json:"str_1"`
  366. }
  367. // NickESRes the result of es query
  368. type NickESRes struct {
  369. Page Page `json:"page"`
  370. Result []*NickNameLogEs `json:"result"`
  371. }
  372. // NickNameLogRes make NickESRes result become we need
  373. type NickNameLogRes struct {
  374. Page Page `json:"page"`
  375. Result []*NickNameInfo `json:"result"`
  376. }
  377. // NickNameInfo nickName
  378. type NickNameInfo struct {
  379. OldName string `json:"old_name"`
  380. NewName string `json:"new_name"`
  381. }
  382. // CheckEmailPhone check email and phone
  383. type CheckEmailPhone struct {
  384. PhonesCheck string
  385. EmailCheck string
  386. }
  387. //CaptchaMailReq get mail captcha
  388. type CaptchaMailReq struct {
  389. Mid int64 `form:"mid" validate:"required"`
  390. LinkMail string `form:"link_mail" validate:"required"`
  391. }
  392. // AddrInfo AddrInfo
  393. type AddrInfo struct {
  394. OftenAddrs string `json:"oftenAddrs"`
  395. }
  396. // SendMailReq send mail according to status and rid
  397. type SendMailReq struct {
  398. RID int64 `form:"rid" validate:"required"`
  399. Status int64 `form:"status" validate:"required"`
  400. }
  401. // LoginIPInfo login ip info
  402. type LoginIPInfo struct {
  403. LoginIP string `json:"loginip"`
  404. }
  405. // UserInfo user detail info
  406. type UserInfo struct {
  407. Mid int64 `json:"mid"`
  408. Phone string `json:"telphone"`
  409. Email string `json:"email"`
  410. JoinTime time.Time `json:"join_time"`
  411. }
  412. // UserBindLogReq UserBindLogReq
  413. type UserBindLogReq struct {
  414. // Action value : telBindLog or emailBindLog
  415. Action string `form:"action"`
  416. Mid int64 `form:"mid"`
  417. //Query search tel or email
  418. Query string `form:"query"`
  419. Page int `form:"page"`
  420. Size int `form:"size"`
  421. From int64 `form:"from"`
  422. To int64 `form:"to"`
  423. }
  424. // EsRes EsRes
  425. type EsRes struct {
  426. Page Page `json:"page"`
  427. Result []*UserActLogEs `json:"result"`
  428. }
  429. // UserActLogEs UserActLogEs
  430. type UserActLogEs struct {
  431. Mid int64 `json:"mid"`
  432. Str0 string `json:"str_0"`
  433. ExtraData string `json:"extra_data"`
  434. CTime string `json:"ctime"`
  435. }
  436. const (
  437. // VerifyMail verify mail
  438. VerifyMail = 1 //验证码邮件
  439. // CommitMail commit mail
  440. CommitMail = 2 //申诉信息提交邮件
  441. // RejectMail reject mail
  442. RejectMail = 3 //账号申诉驳回邮件
  443. // AgreeMail agree mail
  444. AgreeMail = 4 //账号审核通过邮件
  445. // DOAgree agree this appeal
  446. DOAgree = 1 //申诉通过
  447. // DOReject reject this appeal
  448. DOReject = 2 //申诉驳回
  449. // HIDEALL hide all
  450. HIDEALL = "*********"
  451. // BizGame game
  452. BizGame = "game"
  453. )
  454. // BusinessExtraArgs business args
  455. func BusinessExtraArgs(business string) []string {
  456. switch business {
  457. case BizGame:
  458. return []string{"GamePlay", "GameArea", "GameRoleCTime", "GameRoleCreatePhoneType", "GameUsedPhoneType", "GameNames"}
  459. }
  460. return []string{}
  461. }