mine.go 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. package space
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "sync"
  7. "go-common/app/interface/main/app-interface/model/space"
  8. accmdl "go-common/app/service/main/account/model"
  9. relmdl "go-common/app/service/main/relation/model"
  10. "go-common/library/log"
  11. "go-common/library/sync/errgroup.v2"
  12. )
  13. const (
  14. _initSidebarKey = "sidebar_%d_%d"
  15. _selfCenter = 6
  16. _mySerive = 7
  17. _creative = 11
  18. _ipadSelfCenter = 12
  19. _ipadCreative = 13
  20. )
  21. var (
  22. iphoneMenu = map[int]string{
  23. _creative: "创作中心",
  24. _selfCenter: "个人中心",
  25. _mySerive: "我的服务",
  26. }
  27. iphoneNormalMenu = []int{_creative, _selfCenter, _mySerive}
  28. iphoneFilterMenu = []int{_selfCenter, _mySerive}
  29. ipadNormalMenu = []int{_ipadCreative, _ipadSelfCenter}
  30. ipadFilterMenu = []int{_ipadSelfCenter}
  31. )
  32. // Mine mine center for iphone/android
  33. func (s *Service) Mine(c context.Context, mid int64, platform, filtered string, build int, plat int8) (mine *space.Mine, err error) {
  34. var whiteMap, rdMap map[int64]bool
  35. mine = new(space.Mine)
  36. mine.Official.Type = -1
  37. if mid > 0 {
  38. if mine, whiteMap, rdMap, err = s.userInfo(c, mid, platform, plat); err != nil {
  39. return
  40. }
  41. }
  42. if platform == "ios" {
  43. mine.Sections = s.sections(c, whiteMap, rdMap, mid, build, filtered == "1", plat)
  44. }
  45. return
  46. }
  47. // MineIpad mine center for ipad
  48. func (s *Service) MineIpad(c context.Context, mid int64, platform, filtered string, build int, plat int8) (mine *space.Mine, err error) {
  49. var whiteMap, rdMap map[int64]bool
  50. mine = new(space.Mine)
  51. mine.Official.Type = -1
  52. if mid > 0 {
  53. if mine, whiteMap, rdMap, err = s.userInfo(c, mid, platform, plat); err != nil {
  54. return
  55. }
  56. }
  57. mine.IpadSections, mine.IpadUpperSections = s.ipadSections(c, whiteMap, rdMap, mid, build, filtered == "1", plat)
  58. return
  59. }
  60. func (s *Service) userInfo(c context.Context, mid int64, platform string, plat int8) (mine *space.Mine, whiteMap, rdMap map[int64]bool, err error) {
  61. mine = new(space.Mine)
  62. whiteMap = make(map[int64]bool)
  63. rdMap = make(map[int64]bool)
  64. eg := errgroup.WithContext(c)
  65. // account userinfo
  66. eg.Go(func(ctx context.Context) (err error) {
  67. var ps *accmdl.ProfileStat
  68. if ps, err = s.accDao.Profile3(ctx, mid); err != nil {
  69. log.Error("s.accDao.UserInfo(%d) error(%v)", mid, err)
  70. return
  71. }
  72. if ps.Silence == 1 {
  73. if mine.EndTime, err = s.accDao.BlockTime(ctx, mid); err != nil {
  74. log.Error("%+v", err)
  75. err = nil
  76. }
  77. }
  78. mine.Silence = ps.Silence
  79. mine.Mid = ps.Mid
  80. mine.Name = ps.Name
  81. mine.Face = ps.Face
  82. mine.Coin = ps.Coins
  83. if ps.Pendant.Image != "" {
  84. mine.Pendant = &space.Pendant{Image: ps.Pendant.Image}
  85. }
  86. switch ps.Sex {
  87. case "男":
  88. mine.Sex = 1
  89. case "女":
  90. mine.Sex = 2
  91. default:
  92. mine.Sex = 0
  93. }
  94. mine.Rank = ps.Rank
  95. mine.Level = ps.Level
  96. if ps.Vip.Status == 1 {
  97. mine.VipType = ps.Vip.Type
  98. }
  99. if ps.Official.Role == 0 {
  100. mine.Official.Type = -1
  101. } else {
  102. if ps.Official.Role <= 2 {
  103. mine.Official.Type = 0
  104. } else {
  105. mine.Official.Type = 1
  106. }
  107. mine.Official.Desc = ps.Official.Title
  108. }
  109. return
  110. })
  111. // music card
  112. eg.Go(func(ctx context.Context) (err error) {
  113. cardm, err := s.audioDao.Card(ctx, mid)
  114. if err != nil {
  115. log.Error("%+v", err)
  116. err = nil
  117. return
  118. }
  119. if card, ok := cardm[mid]; ok && card.Type == 1 && card.Status == 1 {
  120. mine.AudioType = card.Type
  121. }
  122. return
  123. })
  124. // following and follower
  125. eg.Go(func(ctx context.Context) (err error) {
  126. var stat *relmdl.Stat
  127. if stat, err = s.relDao.Stat(ctx, mid); err != nil {
  128. log.Error("%+v", err)
  129. err = nil
  130. return
  131. }
  132. mine.Following = stat.Following
  133. mine.Follower = stat.Follower
  134. return
  135. })
  136. // new followers
  137. eg.Go(func(ctx context.Context) (err error) {
  138. if mine.NewFollowers, err = s.relDao.FollowersUnreadCount(ctx, mid); err != nil {
  139. log.Error("%+v", err)
  140. err = nil
  141. return
  142. }
  143. return
  144. })
  145. // dynamic count
  146. eg.Go(func(ctx context.Context) (err error) {
  147. var count int64
  148. if count, err = s.bplusDao.DynamicCount(ctx, mid); err != nil {
  149. log.Error("%+v", err)
  150. err = nil
  151. return
  152. }
  153. mine.Dynamic = count
  154. return
  155. })
  156. // bcoin
  157. eg.Go(func(ctx context.Context) (err error) {
  158. var bp float64
  159. if bp, err = s.payDao.UserWalletInfo(ctx, mid, platform); err != nil {
  160. log.Error("%+v", err)
  161. err = nil
  162. return
  163. }
  164. mine.BCoin = bp
  165. return
  166. })
  167. // creative
  168. eg.Go(func(ctx context.Context) (err error) {
  169. var (
  170. isUp int
  171. show int
  172. )
  173. if isUp, show, err = s.memberDao.Creative(ctx, mid); err != nil {
  174. log.Error("%+v", err)
  175. err = nil
  176. return
  177. }
  178. mine.ShowVideoup = show
  179. mine.ShowCreative = isUp
  180. return
  181. })
  182. if platform == "ios" {
  183. var mutex sync.Mutex
  184. //white
  185. for _, v := range s.white[plat] {
  186. tmpID := v.ID
  187. tmpURL := v.URL
  188. eg.Go(func(ctx context.Context) (err error) {
  189. ok, err := s.accDao.UserCheck(ctx, mid, tmpURL)
  190. if err != nil {
  191. log.Error("s.accDao.UserCheck error(%+v)", err)
  192. err = nil
  193. return
  194. }
  195. if ok {
  196. mutex.Lock()
  197. whiteMap[tmpID] = true
  198. mutex.Unlock()
  199. }
  200. return
  201. })
  202. }
  203. //redDot
  204. for _, v := range s.redDot[plat] {
  205. tmpID := v.ID
  206. tmpURL := v.URL
  207. eg.Go(func(ctx context.Context) (err error) {
  208. ok, err := s.accDao.RedDot(ctx, mid, tmpURL)
  209. if err != nil {
  210. log.Error("s.accDao.RedDot error(%+v)", err)
  211. err = nil
  212. return
  213. }
  214. if ok {
  215. mutex.Lock()
  216. rdMap[tmpID] = true
  217. mutex.Unlock()
  218. }
  219. return
  220. })
  221. }
  222. }
  223. // when account info error,return,ingore else error
  224. err = eg.Wait()
  225. return
  226. }
  227. func (s *Service) sections(c context.Context, whiteMap, rdMap map[int64]bool, mid int64, build int, filtered bool, plat int8) (sections []*space.Section) {
  228. menus := iphoneNormalMenu
  229. if filtered {
  230. menus = iphoneFilterMenu
  231. }
  232. for _, module := range menus {
  233. key := fmt.Sprintf(_initSidebarKey, plat, module)
  234. ss, ok := s.sectionCache[key]
  235. if !ok {
  236. continue
  237. }
  238. var items []*space.SectionItem
  239. for _, si := range ss {
  240. if !si.CheckLimit(build) {
  241. continue
  242. }
  243. if si.Item.Name == "离线缓存" && filtered {
  244. continue
  245. }
  246. if si.Item.WhiteURL != "" && !whiteMap[si.Item.ID] {
  247. continue
  248. }
  249. tmpItem := &space.SectionItem{
  250. Title: si.Item.Name,
  251. Icon: si.Item.Logo,
  252. NeedLogin: si.Item.NeedLogin,
  253. URI: si.Item.Param,
  254. }
  255. if si.Item.Red != "" && rdMap[si.Item.ID] {
  256. tmpItem.RedDot = 1
  257. }
  258. items = append(items, tmpItem)
  259. }
  260. if len(items) == 0 {
  261. continue
  262. }
  263. sections = append(sections, &space.Section{
  264. Title: iphoneMenu[module],
  265. Items: items,
  266. })
  267. }
  268. return
  269. }
  270. func (s *Service) ipadSections(c context.Context, whiteMap, rdMap map[int64]bool, mid int64, build int, filtered bool, plat int8) (ipadSections, ipadUpperSections []*space.SectionItem) {
  271. menus := ipadNormalMenu
  272. if filtered {
  273. menus = ipadFilterMenu
  274. }
  275. for _, module := range menus {
  276. key := fmt.Sprintf(_initSidebarKey, plat, module)
  277. ss, ok := s.sectionCache[key]
  278. if !ok {
  279. continue
  280. }
  281. for _, si := range ss {
  282. if !si.CheckLimit(build) {
  283. continue
  284. }
  285. if si.Item.Name == "离线缓存" && filtered {
  286. continue
  287. }
  288. if si.Item.WhiteURL != "" && !whiteMap[si.Item.ID] {
  289. continue
  290. }
  291. tmpItem := &space.SectionItem{
  292. Title: si.Item.Name,
  293. Icon: si.Item.Logo,
  294. NeedLogin: si.Item.NeedLogin,
  295. URI: si.Item.Param,
  296. }
  297. if si.Item.Red != "" && rdMap[si.Item.ID] {
  298. tmpItem.RedDot = 1
  299. }
  300. if module == _ipadCreative {
  301. ipadUpperSections = append(ipadUpperSections, tmpItem)
  302. } else {
  303. ipadSections = append(ipadSections, tmpItem)
  304. }
  305. }
  306. }
  307. return
  308. }
  309. // Myinfo simple myinfo
  310. func (s *Service) Myinfo(c context.Context, mid int64) (myinfo *space.Myinfo, err error) {
  311. var pf *accmdl.ProfileStat
  312. if pf, err = s.accDao.Profile3(c, mid); err != nil {
  313. log.Error("%+v", err)
  314. return
  315. }
  316. p, _ := json.Marshal(pf)
  317. log.Warn("myinfo mid(%d) pf(%s)", mid, p)
  318. myinfo = new(space.Myinfo)
  319. if pf.Silence == 1 {
  320. if myinfo.EndTime, err = s.accDao.BlockTime(c, mid); err != nil {
  321. log.Error("%+v", err)
  322. err = nil
  323. }
  324. }
  325. myinfo.Coins = pf.Coins
  326. myinfo.Sign = pf.Sign
  327. switch pf.Sex {
  328. case "男":
  329. myinfo.Sex = 1
  330. case "女":
  331. myinfo.Sex = 2
  332. default:
  333. myinfo.Sex = 0
  334. }
  335. myinfo.Mid = mid
  336. myinfo.Birthday = pf.Birthday.Time().Format("2006-01-02")
  337. myinfo.Name = pf.Name
  338. myinfo.Face = pf.Face
  339. myinfo.Rank = pf.Rank
  340. myinfo.Level = pf.Level
  341. myinfo.Vip = pf.Vip
  342. myinfo.Silence = pf.Silence
  343. myinfo.EmailStatus = pf.EmailStatus
  344. myinfo.TelStatus = pf.TelStatus
  345. myinfo.Official = pf.Official
  346. myinfo.Identification = pf.Identification
  347. if pf.Pendant.Image != "" {
  348. myinfo.Pendant = &space.Pendant{Image: pf.Pendant.Image}
  349. }
  350. return
  351. }