base.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. package http
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "strings"
  6. "go-common/app/service/main/member/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/net/metadata"
  11. "go-common/library/time"
  12. )
  13. func base(ctx *bm.Context) {
  14. var (
  15. err error
  16. mid int64
  17. // baseInfo *model.BaseInfo
  18. params = ctx.Request.Form
  19. midStr = params.Get("mid")
  20. // res = c.Result()
  21. )
  22. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  23. // res["code"] = ecode.RequestErr
  24. ctx.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. // if baseInfo, err = memberSvc.BaseInfo(c, mid); err != nil {
  28. // log.Error("relationSvc.BaseInfo(%d) error(%v)", mid, err)
  29. // res["code"] = err
  30. // return
  31. // }
  32. // res["data"] = baseInfo
  33. ctx.JSON(memberSvc.BaseInfo(ctx, mid))
  34. }
  35. func member(ctx *bm.Context) {
  36. params := ctx.Request.Form
  37. // res := c.Result()
  38. midStr := params.Get("mid")
  39. mid, err := strconv.ParseInt(midStr, 10, 64)
  40. if err != nil || mid <= 0 {
  41. // res["code"] = ecode.RequestErr
  42. ctx.JSON(nil, ecode.RequestErr)
  43. return
  44. }
  45. // mb, err := memberSvc.Member(c, mid)
  46. // if err != nil {
  47. // log.Error("Failed to memberSvc.Member(%d): %+v", mid, err)
  48. // res["code"] = err
  49. // return
  50. // }
  51. // res["data"] = mb
  52. ctx.JSON(memberSvc.Member(ctx, mid))
  53. }
  54. func batchBase(ctx *bm.Context) {
  55. var (
  56. err error
  57. mid int64
  58. mids []int64
  59. // binfo map[int64]*model.BaseInfo
  60. params = ctx.Request.Form
  61. midsStr = params.Get("mids")
  62. // res = c.Result()
  63. )
  64. for _, str := range strings.Split(midsStr, ",") {
  65. if mid, err = strconv.ParseInt(str, 10, 64); err != nil {
  66. // res["code"] = ecode.RequestErr
  67. ctx.JSON(nil, ecode.RequestErr)
  68. return
  69. }
  70. mids = append(mids, mid)
  71. }
  72. // if binfo, err = memberSvc.BatchBaseInfo(c, mids); err != nil {
  73. // log.Error("memberSvc.BaseInfo(%d) error(%v)", mid, err)
  74. // res["code"] = err
  75. // return
  76. // }
  77. // res["data"] = binfo
  78. ctx.JSON(memberSvc.BatchBaseInfo(ctx, mids))
  79. }
  80. func setSign(ctx *bm.Context) {
  81. var (
  82. err error
  83. mid int64
  84. params = ctx.Request.Form
  85. midStr = params.Get("mid")
  86. usersign = params.Get("user_sign")
  87. // res = c.Result()
  88. )
  89. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  90. // res["code"] = ecode.RequestErr
  91. ctx.JSON(nil, ecode.RequestErr)
  92. return
  93. }
  94. // if usersign == "" {
  95. // res["code"] = ecode.RequestErr
  96. // return
  97. // }
  98. // 获取用户状态逻辑 status判断
  99. // if err := memberSvc.SetSign(c, mid, usersign); err != nil {
  100. // log.Error("memberSvc.SetSign(%d) error(%v)", mid, err)
  101. // res["code"] = ecode.ServerErr
  102. // return
  103. // }
  104. ctx.JSON(nil, memberSvc.SetSign(ctx, mid, usersign))
  105. }
  106. func setName(ctx *bm.Context) {
  107. var (
  108. err error
  109. mid int64
  110. params = ctx.Request.Form
  111. midStr = params.Get("mid")
  112. name = params.Get("name")
  113. // res = c.Result()
  114. )
  115. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  116. // res["code"] = ecode.RequestErr
  117. ctx.JSON(nil, ecode.RequestErr)
  118. return
  119. }
  120. if name == "" {
  121. // res["code"] = ecode.RequestErr
  122. ctx.JSON(nil, ecode.RequestErr)
  123. return
  124. }
  125. // if err := memberSvc.SetName(c, mid, name); err != nil {
  126. // log.Error("memberSvc.SetUname(%d) error(%v)", mid, err)
  127. // res["code"] = ecode.ServerErr
  128. // return
  129. // }
  130. ctx.JSON(nil, memberSvc.SetName(ctx, mid, name))
  131. }
  132. func setRank(ctx *bm.Context) {
  133. var (
  134. err error
  135. mid int64
  136. rank int64
  137. params = ctx.Request.Form
  138. midStr = params.Get("mid")
  139. rankStr = params.Get("rank")
  140. // res = c.Result()
  141. )
  142. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  143. // res["code"] = ecode.RequestErr
  144. ctx.JSON(nil, ecode.RequestErr)
  145. return
  146. }
  147. if rank, err = strconv.ParseInt(rankStr, 10, 64); err != nil {
  148. // res["code"] = ecode.RequestErr
  149. ctx.JSON(nil, ecode.RequestErr)
  150. return
  151. }
  152. // if err := memberSvc.SetRank(c, mid, rank); err != nil {
  153. // log.Error("relationSvc.SetRank(%d) error(%v)", mid, err)
  154. // res["code"] = ecode.ServerErr
  155. // return
  156. // }
  157. ctx.JSON(nil, memberSvc.SetRank(ctx, mid, rank))
  158. }
  159. // setSex set sex.
  160. func setSex(ctx *bm.Context) {
  161. var (
  162. err error
  163. mid int64
  164. sex int64
  165. params = ctx.Request.Form
  166. midStr = params.Get("mid")
  167. sexStr = params.Get("sex")
  168. // res = c.Result()
  169. )
  170. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  171. // res["code"] = ecode.RequestErr
  172. ctx.JSON(nil, ecode.RequestErr)
  173. return
  174. }
  175. if sex, err = strconv.ParseInt(sexStr, 10, 8); err != nil {
  176. // res["code"] = ecode.RequestErr
  177. ctx.JSON(nil, ecode.RequestErr)
  178. return
  179. }
  180. // if err = memberSvc.SetSex(c, mid, sex); err != nil {
  181. // log.Error("memberSvc.SetSex(%d, %d) error(%v)", mid, sex, err)
  182. // res["code"] = ecode.ServerErr
  183. // }
  184. ctx.JSON(nil, memberSvc.SetSex(ctx, mid, sex))
  185. }
  186. // setBirthday set Birthday.
  187. func setBirthday(ctx *bm.Context) {
  188. var (
  189. err error
  190. mid int64
  191. birthdayTs int64
  192. birthday time.Time
  193. params = ctx.Request.Form
  194. midStr = params.Get("mid")
  195. birthdayStr = params.Get("birthday")
  196. // res = c.Result()
  197. )
  198. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  199. // res["code"] = ecode.RequestErr
  200. ctx.JSON(nil, ecode.RequestErr)
  201. return
  202. }
  203. if birthdayTs, err = strconv.ParseInt(birthdayStr, 10, 32); err != nil {
  204. // res["code"] = ecode.RequestErr
  205. ctx.JSON(nil, ecode.RequestErr)
  206. return
  207. }
  208. birthday = time.Time(birthdayTs)
  209. // if err = memberSvc.SetBirthday(c, mid, birthday); err != nil {
  210. // log.Error("memberSvc.SetBirthday(%d, %d) error(%v)", mid, birthday, err)
  211. // res["code"] = ecode.ServerErr
  212. // }
  213. ctx.JSON(nil, memberSvc.SetBirthday(ctx, mid, birthday))
  214. }
  215. // setFace set face.
  216. func setFace(ctx *bm.Context) {
  217. var (
  218. err error
  219. mid int64
  220. params = ctx.Request.Form
  221. midStr = params.Get("mid")
  222. face = params.Get("face")
  223. // res = c.Result()
  224. )
  225. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  226. // res["code"] = ecode.RequestErr
  227. ctx.JSON(nil, ecode.RequestErr)
  228. return
  229. }
  230. // if err = memberSvc.SetFace(c, mid, face); err != nil {
  231. // log.Error("memberSvc.SetFace(%d, %d) error(%v)", mid, face, err)
  232. // res["code"] = ecode.ServerErr
  233. // }
  234. ctx.JSON(nil, memberSvc.SetFace(ctx, mid, face))
  235. }
  236. func setBase(ctx *bm.Context) {
  237. var (
  238. err error
  239. mid int64
  240. rank int64
  241. sex int64
  242. birthday int64
  243. params = ctx.Request.Form
  244. midStr = params.Get("mid")
  245. rankStr = params.Get("rank")
  246. face = params.Get("face")
  247. birthdayStr = params.Get("birthday")
  248. name = params.Get("name")
  249. sign = params.Get("user_sign")
  250. sexStr = params.Get("sex")
  251. // res = c.Result()
  252. )
  253. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  254. // res["code"] = ecode.RequestErr
  255. ctx.JSON(nil, ecode.RequestErr)
  256. return
  257. }
  258. if len(rankStr) != 0 {
  259. if rank, err = strconv.ParseInt(rankStr, 10, 64); err != nil {
  260. // res["code"] = ecode.RequestErr
  261. ctx.JSON(nil, ecode.RequestErr)
  262. return
  263. }
  264. }
  265. if len(sexStr) != 0 {
  266. if sex, err = strconv.ParseInt(sexStr, 10, 64); err != nil {
  267. // res["code"] = ecode.RequestErr
  268. ctx.JSON(nil, ecode.RequestErr)
  269. return
  270. }
  271. }
  272. if len(birthdayStr) != 0 {
  273. if birthday, err = strconv.ParseInt(birthdayStr, 10, 64); err != nil {
  274. // res["code"] = ecode.RequestErr
  275. ctx.JSON(nil, ecode.RequestErr)
  276. return
  277. }
  278. }
  279. b := &model.BaseInfo{Mid: mid, Face: face, Sex: sex, Birthday: time.Time(birthday), Name: name, Sign: sign, Rank: rank}
  280. // if err := memberSvc.SetBase(c, b); err != nil {
  281. // log.Error("memberSvc.SetBase(%d) error(%v)", mid, err)
  282. // res["code"] = ecode.ServerErr
  283. // return
  284. // }
  285. ctx.JSON(nil, memberSvc.SetBase(ctx, b))
  286. }
  287. func updateMorals(ctx *bm.Context) {
  288. var (
  289. err error
  290. // morals map[int64]int64
  291. )
  292. // res := c.Result()
  293. arg := &model.ArgUpdateMorals{}
  294. if err = ctx.Bind(arg); err != nil {
  295. return
  296. }
  297. arg.IP = metadata.String(ctx, metadata.RemoteIP)
  298. // morals, err = memberSvc.UpdateMorals(c, arg)
  299. // if err != nil {
  300. // res["code"] = err
  301. // return
  302. // }
  303. // res["data"] = morals
  304. ctx.JSON(memberSvc.UpdateMorals(ctx, arg))
  305. }
  306. func updateMoral(ctx *bm.Context) {
  307. arg := &model.ArgUpdateMoral{}
  308. if err := ctx.Bind(arg); err != nil {
  309. return
  310. }
  311. arg.IP = metadata.String(ctx, metadata.RemoteIP)
  312. ctx.JSON(nil, memberSvc.UpdateMoral(ctx, arg))
  313. }
  314. func undoMoral(ctx *bm.Context) {
  315. arg := &model.ArgUndo{}
  316. if err := ctx.Bind(arg); err != nil {
  317. return
  318. }
  319. ctx.JSON(nil, memberSvc.UndoMoral(ctx, arg.LogID, arg.Remark, arg.Operator))
  320. }
  321. // cacheDel delete user cache.
  322. func cacheDel(ctx *bm.Context) {
  323. var (
  324. mid int64
  325. action string
  326. ak string
  327. sd string
  328. err error
  329. )
  330. // res := c.Result()
  331. query := ctx.Request.Form
  332. midStr := query.Get("mid")
  333. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  334. // res["code"] = ecode.RequestErr
  335. ctx.JSON(nil, ecode.RequestErr)
  336. return
  337. }
  338. action = query.Get("modifiedAttr")
  339. ak = query.Get("access_token")
  340. sd = query.Get("session")
  341. memberSvc.DelCache(ctx, mid, action, ak, sd)
  342. // res["code"] = ecode.OK
  343. ctx.JSON(nil, nil)
  344. }
  345. // addPropertyReview add user property update review.
  346. func addPropertyReview(ctx *bm.Context) {
  347. arg := &model.ArgAddPropertyReview{}
  348. if err := ctx.Bind(arg); err != nil {
  349. return
  350. }
  351. form := ctx.Request.Form
  352. extra := form.Get("extra")
  353. if extra != "" {
  354. extraData := map[string]interface{}{}
  355. if err := json.Unmarshal([]byte(extra), &extraData); err != nil {
  356. log.Error("Failed to Unmarshal extra: %+v, error: %+v", extra, err)
  357. ctx.JSON(nil, ecode.RequestErr)
  358. return
  359. }
  360. arg.Extra = extraData
  361. }
  362. ctx.JSON(nil, memberSvc.AddPropertyReview(ctx, arg))
  363. }