web_index.go 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. package http
  2. import (
  3. "context"
  4. "strconv"
  5. "go-common/app/interface/main/creative/model/order"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/net/metadata"
  10. "go-common/library/sync/errgroup"
  11. )
  12. func webIndexStat(c *bm.Context) {
  13. ip := metadata.String(c, metadata.RemoteIP)
  14. params := c.Request.Form
  15. // check user
  16. midI, ok := c.Get("mid")
  17. tmidStr := params.Get("tmid")
  18. if !ok {
  19. c.JSON(nil, ecode.NoLogin)
  20. return
  21. }
  22. mid, _ := midI.(int64)
  23. tmid, _ := strconv.ParseInt(tmidStr, 10, 64)
  24. if tmid > 0 && dataSvc.IsWhite(mid) {
  25. mid = tmid
  26. }
  27. stat, err := dataSvc.NewStat(c, mid, ip)
  28. if err != nil {
  29. c.JSON(nil, err)
  30. return
  31. }
  32. rfd, _ := dataSvc.RelationFansDay(c, mid)
  33. log.Info("dataSvc.NewStat(%+v) mid(%d)", stat, mid)
  34. c.JSON(map[string]interface{}{
  35. "total_click": stat.Play,
  36. "total_dm": stat.Dm,
  37. "total_reply": stat.Comment,
  38. "total_fans": stat.Fan,
  39. "total_fav": stat.Fav,
  40. "total_like": stat.Like,
  41. "total_share": stat.Share,
  42. "incr_click": stat.Play - stat.PlayLast,
  43. "incr_dm": stat.Dm - stat.DmLast,
  44. "incr_reply": stat.Comment - stat.CommentLast,
  45. "incr_fans": stat.Fan - stat.FanLast,
  46. "inc_fav": stat.Fav - stat.FavLast,
  47. "inc_like": stat.Like - stat.LikeLast,
  48. "inc_share": stat.Share - stat.ShareLast,
  49. "fan_recent_thirty": rfd,
  50. }, nil)
  51. }
  52. func webIndexTool(c *bm.Context) {
  53. params := c.Request.Form
  54. tyStr := params.Get("type")
  55. // check user
  56. _, ok := c.Get("mid")
  57. if !ok {
  58. c.JSON(nil, ecode.NoLogin)
  59. return
  60. }
  61. // check params
  62. ty, err := strconv.ParseInt(tyStr, 10, 8)
  63. if err != nil || ty < 0 || ty > 2 {
  64. ty = 0
  65. }
  66. tool, err := operSvc.Tool(c, int8(ty))
  67. if err != nil {
  68. c.JSON(nil, err)
  69. return
  70. }
  71. c.JSON(tool, nil)
  72. }
  73. func webIndexFull(c *bm.Context) {
  74. // check user
  75. _, ok := c.Get("mid")
  76. if !ok {
  77. c.JSON(nil, ecode.NoLogin)
  78. return
  79. }
  80. opers, err := operSvc.WebOperations(c)
  81. if err != nil {
  82. c.JSON(nil, err)
  83. return
  84. }
  85. c.JSON(opers, nil)
  86. }
  87. func webIndexNotify(c *bm.Context) {
  88. // check user
  89. _, ok := c.Get("mid")
  90. if !ok {
  91. c.JSON(nil, ecode.NoLogin)
  92. return
  93. }
  94. opers, err := operSvc.WebOperations(c)
  95. if err != nil {
  96. c.JSON(nil, err)
  97. return
  98. }
  99. if length := len(opers["creative"]); length > 0 {
  100. c.JSON(opers["creative"][length-1], nil)
  101. } else {
  102. c.JSON(nil, nil)
  103. }
  104. }
  105. func webIndexOper(c *bm.Context) {
  106. _, ok := c.Get("mid")
  107. if !ok {
  108. c.JSON(nil, ecode.NoLogin)
  109. return
  110. }
  111. c.JSON(operSvc.WebRelOperCache, nil)
  112. }
  113. func webIndexVersion(c *bm.Context) {
  114. _, ok := c.Get("mid")
  115. if !ok {
  116. c.JSON(nil, ecode.NoLogin)
  117. return
  118. }
  119. c.JSON(vsSvc.VersionMapCache, nil)
  120. }
  121. func webWhite(c *bm.Context) {
  122. ip := metadata.String(c, metadata.RemoteIP)
  123. params := c.Request.Form
  124. midI, ok := c.Get("mid")
  125. if !ok {
  126. c.JSON(nil, ecode.NoLogin)
  127. return
  128. }
  129. tmidStr := params.Get("tmid")
  130. var (
  131. err error
  132. tmid int64
  133. orderAllow, orderUp int
  134. cmAd *order.UpValidate
  135. g = &errgroup.Group{}
  136. ctx = context.TODO()
  137. task int8
  138. ugcpay, staff bool
  139. staffCount int
  140. )
  141. mid, _ := midI.(int64)
  142. if tmidStr != "" {
  143. if tmid, err = strconv.ParseInt(tmidStr, 10, 64); err != nil {
  144. log.Error("strconv.ParseInt(%s) error(%v)", tmidStr, err)
  145. c.JSON(nil, ecode.RequestErr)
  146. return
  147. }
  148. if tmid > 0 && dataSvc.IsWhite(mid) {
  149. mid = tmid
  150. }
  151. }
  152. g.Go(func() error { //商单
  153. if ok = arcSvc.AllowOrderUps(mid); ok {
  154. orderAllow = 1
  155. }
  156. return nil
  157. })
  158. g.Go(func() error { //商单广告
  159. cmAd, _ = arcSvc.UpValidate(ctx, mid, ip)
  160. return nil
  161. })
  162. g.Go(func() error { //任务系统 0-关闭 1-开启
  163. task = whiteSvc.TaskWhiteList(mid)
  164. return nil
  165. })
  166. g.Go(func() error { //ugc付费白名单校验
  167. ugcpay, _ = paySvc.White(ctx, mid)
  168. return nil
  169. })
  170. g.Go(func() error { //联合投稿白名单
  171. staff, _ = upSvc.ShowStaff(ctx, mid)
  172. return nil
  173. })
  174. g.Go(func() error { //联合投稿staff合作按钮
  175. staffCount, _ = arcSvc.StaffValidate(ctx, mid)
  176. return nil
  177. })
  178. g.Wait()
  179. c.JSON(map[string]interface{}{
  180. "order": map[string]interface{}{
  181. "allow": orderAllow,
  182. "up": orderUp,
  183. },
  184. "growup": nil,
  185. "cm_ad": cmAd,
  186. "task": task,
  187. "ugcpay": ugcpay,
  188. "staff": staff,
  189. "staff_count": staffCount,
  190. }, nil)
  191. }
  192. func webIndexNewcomer(c *bm.Context) {
  193. // check user
  194. midI, ok := c.Get("mid")
  195. if !ok {
  196. c.JSON(nil, ecode.CreativeNotLogin)
  197. return
  198. }
  199. mid, _ := midI.(int64)
  200. res, err := newcomerSvc.IndexNewcomer(c, mid)
  201. if err != nil {
  202. c.JSON(nil, err)
  203. return
  204. }
  205. c.JSON(res, nil)
  206. }