web.go 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. package http
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/interface/main/creative/conf"
  7. accmdl "go-common/app/interface/main/creative/model/account"
  8. arcMdl "go-common/app/interface/main/creative/model/archive"
  9. "go-common/app/interface/main/creative/model/danmu"
  10. elecMdl "go-common/app/interface/main/creative/model/elec"
  11. "go-common/app/interface/main/creative/model/order"
  12. porderM "go-common/app/interface/main/creative/model/porder"
  13. "go-common/app/interface/main/creative/model/tag"
  14. "go-common/app/interface/main/creative/model/watermark"
  15. accSvcModel "go-common/app/service/main/account/model"
  16. "go-common/library/ecode"
  17. "go-common/library/log"
  18. bm "go-common/library/net/http/blademaster"
  19. "go-common/library/net/metadata"
  20. "go-common/library/sync/errgroup"
  21. )
  22. func webViewArc(c *bm.Context) {
  23. params := c.Request.Form
  24. aidStr := params.Get("aid")
  25. hidStr := params.Get("history")
  26. ip := metadata.String(c, metadata.RemoteIP)
  27. midI, ok := c.Get("mid")
  28. if !ok {
  29. c.JSON(nil, ecode.NoLogin)
  30. return
  31. }
  32. mid, _ := midI.(int64)
  33. aid, err := strconv.ParseInt(aidStr, 10, 64)
  34. if err != nil {
  35. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. var (
  40. elecArc *elecMdl.ArcState
  41. archive *arcMdl.Archive
  42. videos []*arcMdl.Video
  43. staffs []*arcMdl.StaffView
  44. sMids []int64
  45. sMap map[int64]*accSvcModel.Info
  46. wm *watermark.Watermark
  47. g = &errgroup.Group{}
  48. ctx = context.TODO()
  49. subtitle *danmu.SubtitleSubjectReply
  50. )
  51. g.Go(func() error {
  52. elecArc, _ = elecSvc.ArchiveState(ctx, aid, mid, ip)
  53. return nil
  54. })
  55. g.Go(func() error {
  56. var (
  57. av *arcMdl.ArcVideo
  58. )
  59. if av, err = arcSvc.View(ctx, mid, aid, ip, arcMdl.PlatformWeb); err == nil && av != nil {
  60. archive = av.Archive
  61. videos = av.Videos
  62. staffs = av.Archive.Staffs
  63. } else {
  64. archive = &arcMdl.Archive{}
  65. videos = []*arcMdl.Video{}
  66. staffs = []*arcMdl.StaffView{}
  67. }
  68. return err
  69. })
  70. g.Go(func() error {
  71. wm, _ = wmSvc.WaterMark(c, mid)
  72. return nil
  73. })
  74. g.Go(func() error {
  75. subtitle, _ = danmuSvc.SubView(c, aid, ip)
  76. return nil
  77. })
  78. if err = g.Wait(); err != nil {
  79. c.JSON(nil, err)
  80. return
  81. }
  82. for _, v := range staffs {
  83. sMids = append(sMids, v.ApMID)
  84. }
  85. if sMap, err = accSvc.Infos(c, sMids, ip); err != nil {
  86. log.Error("accSvc.Infos(%v) error(%v)", sMids, err)
  87. err = nil
  88. }
  89. for k, v := range staffs {
  90. if m, ok := sMap[v.ApMID]; ok {
  91. staffs[k].ApName = m.Name
  92. }
  93. }
  94. hid, err := strconv.ParseInt(hidStr, 10, 64)
  95. if err == nil && hid > 0 {
  96. history, err := arcSvc.HistoryView(c, mid, hid, ip)
  97. if err == nil && history.Mid > 0 {
  98. archive.Title = history.Title
  99. archive.Desc = history.Content
  100. archive.Cover = history.Cover
  101. videos = history.Video
  102. }
  103. }
  104. c.JSON(map[string]interface{}{
  105. "archive": archive,
  106. "videos": videos,
  107. "staffs": staffs,
  108. "arc_elec": elecArc,
  109. "watermark": wm,
  110. "tip": vsSvc.WebManagerTip,
  111. "subtitle": subtitle,
  112. }, nil)
  113. }
  114. func webArchives(c *bm.Context) {
  115. params := c.Request.Form
  116. pageStr := params.Get("pn")
  117. psStr := params.Get("ps")
  118. order := params.Get("order")
  119. tidStr := params.Get("tid")
  120. keyword := params.Get("keyword")
  121. class := params.Get("status")
  122. tmidStr := params.Get("tmid")
  123. ip := metadata.String(c, metadata.RemoteIP)
  124. var tmid int64
  125. midI, ok := c.Get("mid")
  126. if !ok {
  127. c.JSON(nil, ecode.CreativeNotLogin)
  128. return
  129. }
  130. mid, ok := midI.(int64)
  131. if !ok {
  132. c.JSON(nil, ecode.CreativeNotLogin)
  133. return
  134. }
  135. if tmidStr != "" {
  136. tmid, _ = strconv.ParseInt(tmidStr, 10, 64)
  137. }
  138. if tmid > 0 && dataSvc.IsWhite(mid) {
  139. mid = tmid
  140. }
  141. // check params
  142. pn, _ := strconv.Atoi(pageStr)
  143. if pn <= 0 {
  144. pn = 1
  145. }
  146. ps, _ := strconv.Atoi(psStr)
  147. if ps <= 0 || ps > 20 {
  148. ps = 10
  149. }
  150. coop, _ := strconv.Atoi(params.Get("coop"))
  151. if coop > 0 {
  152. coop = 1
  153. }
  154. tid, _ := strconv.ParseInt(tidStr, 10, 16)
  155. if tid <= 0 {
  156. tid = 0
  157. }
  158. arc, err := arcSvc.WebArchives(c, mid, int16(tid), keyword, order, class, ip, pn, ps, coop)
  159. if err != nil {
  160. c.JSON(nil, err)
  161. return
  162. }
  163. c.JSON(arc, nil)
  164. }
  165. func webStaffApplies(c *bm.Context) {
  166. params := c.Request.Form
  167. pageStr := params.Get("pn")
  168. psStr := params.Get("ps")
  169. tidStr := params.Get("tid")
  170. keyword := params.Get("keyword")
  171. state := params.Get("state")
  172. tmidStr := params.Get("tmid")
  173. //check user
  174. var tmid int64
  175. midI, ok := c.Get("mid")
  176. if !ok {
  177. c.JSON(nil, ecode.CreativeNotLogin)
  178. return
  179. }
  180. mid, _ := midI.(int64)
  181. if tmidStr != "" {
  182. tmid, _ = strconv.ParseInt(tmidStr, 10, 64)
  183. }
  184. if tmid > 0 && dataSvc.IsWhite(mid) {
  185. mid = tmid
  186. }
  187. // check params
  188. pn, _ := strconv.Atoi(pageStr)
  189. if pn <= 0 {
  190. pn = 1
  191. }
  192. ps, _ := strconv.Atoi(psStr)
  193. if ps <= 0 || ps > 20 {
  194. ps = 10
  195. }
  196. tid, _ := strconv.ParseInt(tidStr, 10, 16)
  197. if tid <= 0 {
  198. tid = 0
  199. }
  200. arc, err := arcSvc.ApplySearch(c, mid, int16(tid), keyword, state, pn, ps)
  201. if err != nil {
  202. c.JSON(nil, err)
  203. return
  204. }
  205. c.JSON(arc, nil)
  206. }
  207. func webViewPre(c *bm.Context) {
  208. ip := metadata.String(c, metadata.RemoteIP)
  209. params := c.Request.Form
  210. lang := params.Get("lang")
  211. midI, ok := c.Get("mid")
  212. if !ok {
  213. c.JSON(nil, ecode.NoLogin)
  214. return
  215. }
  216. mid, _ := midI.(int64)
  217. var (
  218. err error
  219. mf *accmdl.MyInfo
  220. g = &errgroup.Group{}
  221. ctx = context.TODO()
  222. industryList, showtypeList []*porderM.Config
  223. orders = make([]*order.Order, 0)
  224. videoJam *arcMdl.VideoJam
  225. dymcLottery bool
  226. wm *watermark.Watermark
  227. prePay map[string]interface{}
  228. staffConf struct {
  229. TypeList []*conf.StaffTypeConf `json:"typelist"`
  230. Titles []*tag.StaffTitle `json:"titles"`
  231. }
  232. )
  233. g.Go(func() error {
  234. mf, err = accSvc.MyInfo(ctx, mid, ip, time.Now())
  235. if err != nil {
  236. log.Info("accSvc.MyInfo (%d) err(%v)", mid, err)
  237. }
  238. if mf != nil {
  239. mf.Commercial = arcSvc.AllowCommercial(ctx, mid)
  240. }
  241. return nil
  242. })
  243. g.Go(func() error {
  244. industryList, _ = adSvc.IndustryList(ctx)
  245. showtypeList, _ = adSvc.ShowList(ctx)
  246. return nil
  247. })
  248. g.Go(func() error {
  249. if arcSvc.AllowOrderUps(mid) {
  250. orders, _ = arcSvc.ExecuteOrders(ctx, mid, ip)
  251. }
  252. return nil
  253. })
  254. g.Go(func() error {
  255. videoJam, _ = arcSvc.VideoJam(ctx, ip)
  256. return nil
  257. })
  258. g.Go(func() error {
  259. dymcLottery, _ = dymcSvc.LotteryUserCheck(ctx, mid)
  260. return nil
  261. })
  262. g.Go(func() error {
  263. wm, err = wmSvc.WaterMark(ctx, mid)
  264. if err != nil {
  265. log.Info("wmSvc.WaterMark (%d) err(%+v) WaterMark(%+v)", mid, err, wm)
  266. }
  267. if len(wm.URL) == 0 {
  268. wm.State = 1
  269. }
  270. return nil
  271. })
  272. g.Go(func() error {
  273. prePay, err = paySvc.Pre(ctx, mid)
  274. return nil
  275. })
  276. g.Wait()
  277. if mf != nil {
  278. mf.DymcLottery = dymcLottery
  279. }
  280. staffConf.Titles = arcSvc.StaffTitles(ctx)
  281. staffConf.TypeList = staffSvc.TypeConfig()
  282. c.JSON(map[string]interface{}{
  283. "prepay": prePay,
  284. "video_jam": videoJam,
  285. "typelist": arcSvc.Types(c, lang),
  286. "activities": arcSvc.Activities(c),
  287. "myinfo": mf,
  288. "orders": orders,
  289. "industry_list": industryList,
  290. "showtype_list": showtypeList,
  291. "watermark": wm,
  292. "fav": arcSvc.Fav(c, mid),
  293. "tip": vsSvc.WebManagerTip,
  294. "staff_conf": staffConf,
  295. }, nil)
  296. }
  297. func webDelArc(c *bm.Context) {
  298. req := c.Request
  299. ip := metadata.String(c, metadata.RemoteIP)
  300. parmes := req.Form
  301. challenge := parmes.Get("geetest_challenge")
  302. validate := parmes.Get("geetest_validate")
  303. seccode := parmes.Get("geetest_seccode")
  304. success := req.Form.Get("geetest_success")
  305. // check user
  306. midI, ok := c.Get("mid")
  307. if !ok {
  308. c.JSON(nil, ecode.NoLogin)
  309. return
  310. }
  311. mid, _ := midI.(int64)
  312. aid, err := strconv.ParseInt(parmes.Get("aid"), 10, 64)
  313. if err != nil {
  314. log.Error("strconv.ParseInt(%d) error(%v)", aid, err)
  315. c.JSON(nil, ecode.RequestErr)
  316. return
  317. }
  318. successi, err := strconv.Atoi(success)
  319. if err != nil {
  320. successi = 1
  321. }
  322. if gtSvc.Validate(c, challenge, validate, seccode, "web", ip, successi, mid) {
  323. c.JSON(nil, arcSvc.Del(c, mid, aid, ip))
  324. } else {
  325. c.JSON(nil, ecode.CreativeGeetestErr)
  326. }
  327. }
  328. func webVideos(c *bm.Context) {
  329. ip := metadata.String(c, metadata.RemoteIP)
  330. params := c.Request.Form
  331. // check user
  332. midI, ok := c.Get("mid")
  333. if !ok {
  334. c.JSON(nil, ecode.NoLogin)
  335. return
  336. }
  337. mid, _ := midI.(int64)
  338. aidStr := params.Get("aid")
  339. aid, err := strconv.ParseInt(aidStr, 10, 64)
  340. if err != nil {
  341. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  342. c.JSON(nil, ecode.RequestErr)
  343. return
  344. }
  345. archive, videos, err := arcSvc.Videos(c, mid, aid, ip)
  346. if err != nil {
  347. c.JSON(nil, err)
  348. return
  349. }
  350. c.JSON(map[string]interface{}{
  351. "archive": archive,
  352. "videos": videos,
  353. }, nil)
  354. }
  355. func webDescFormat(c *bm.Context) {
  356. ip := metadata.String(c, metadata.RemoteIP)
  357. params := c.Request.Form
  358. typeidStr := params.Get("typeid")
  359. cpStr := params.Get("copyright")
  360. lang := params.Get("lang")
  361. _, ok := c.Get("mid")
  362. if !ok {
  363. c.JSON(nil, ecode.NoLogin)
  364. return
  365. }
  366. typeid, err := strconv.ParseInt(typeidStr, 10, 64)
  367. if err != nil {
  368. log.Error("strconv.ParseInt(%s) error(%v)", typeidStr, err)
  369. c.JSON(nil, ecode.RequestErr)
  370. return
  371. }
  372. copyright, err := strconv.ParseInt(cpStr, 10, 64)
  373. if err != nil {
  374. log.Error("strconv.ParseInt(%s) error(%v)", typeidStr, err)
  375. c.JSON(nil, ecode.RequestErr)
  376. return
  377. }
  378. if copyright != 1 && copyright != 2 {
  379. log.Error("strconv.ParseInt(%s) error(%v)", typeidStr, err)
  380. c.JSON(nil, ecode.RequestErr)
  381. return
  382. }
  383. format, err := arcSvc.DescFormat(c, typeid, copyright, lang, ip)
  384. if err != nil {
  385. c.JSON(nil, err)
  386. return
  387. }
  388. c.JSON(format, nil)
  389. }
  390. func webViewPoints(c *bm.Context) {
  391. ip := metadata.String(c, metadata.RemoteIP)
  392. params := c.Request.Form
  393. aidStr := params.Get("aid")
  394. cidStr := params.Get("cid")
  395. midStr, ok := c.Get("mid")
  396. if !ok {
  397. c.JSON(nil, ecode.NoLogin)
  398. return
  399. }
  400. mid, ok := midStr.(int64)
  401. if !ok {
  402. log.Error("mid(%s) to int64 not ok", midStr)
  403. c.JSON(nil, ecode.RequestErr)
  404. return
  405. }
  406. aid, err := strconv.ParseInt(aidStr, 10, 64)
  407. if err != nil {
  408. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  409. c.JSON(nil, ecode.RequestErr)
  410. return
  411. }
  412. cid, err := strconv.ParseInt(cidStr, 10, 64)
  413. if err != nil {
  414. log.Error("strconv.ParseInt(%s) error(%v)", cidStr, err)
  415. c.JSON(nil, ecode.RequestErr)
  416. return
  417. }
  418. vps, err := arcSvc.WebViewPoints(c, aid, cid, mid, ip)
  419. if err != nil {
  420. c.JSON(nil, err)
  421. return
  422. }
  423. c.JSON(vps, nil)
  424. }
  425. /*func webViewPointsEdit(c *bm.Context) {
  426. ip := metadata.String(c, metadata.RemoteIP)
  427. params := c.Request.Form
  428. aidStr := params.Get("aid")
  429. cidStr := params.Get("cid")
  430. midStr, ok := c.Get("mid")
  431. pointStr := params.Get("points")
  432. if !ok {
  433. c.JSON(nil, ecode.NoLogin)
  434. return
  435. }
  436. mid, ok := midStr.(int64)
  437. if !ok {
  438. log.Error("mid(%s) to int64 not ok", midStr)
  439. c.JSON(nil, ecode.RequestErr)
  440. return
  441. }
  442. aid, err := strconv.ParseInt(aidStr, 10, 64)
  443. if err != nil {
  444. log.Error("strconv.ParseInt(%s) error(%v)", aidStr, err)
  445. c.JSON(nil, ecode.RequestErr)
  446. return
  447. }
  448. cid, err := strconv.ParseInt(cidStr, 10, 64)
  449. if err != nil {
  450. log.Error("strconv.ParseInt(%s) error(%v)", cidStr, err)
  451. c.JSON(nil, ecode.RequestErr)
  452. return
  453. }
  454. err := arcSvc.WebViewPointsEdit(c, aid, cid, mid, vp, ip)
  455. if err != nil {
  456. c.JSON(nil, err)
  457. return
  458. }
  459. c.JSON(nil, nil)
  460. }
  461. */
  462. func webUserSearch(c *bm.Context) {
  463. var (
  464. err error
  465. searchUp []*accmdl.SearchUp
  466. accCards map[int64]*accSvcModel.Card
  467. relas map[int64]int
  468. mids []int64
  469. g = &errgroup.Group{}
  470. )
  471. searchUp = make([]*accmdl.SearchUp, 0)
  472. accCards = make(map[int64]*accSvcModel.Card)
  473. relas = make(map[int64]int)
  474. params := c.Request.Form
  475. midI, ok := c.Get("mid")
  476. if !ok {
  477. c.JSON(nil, ecode.NoLogin)
  478. return
  479. }
  480. mid, _ := midI.(int64)
  481. kw := params.Get("kw")
  482. ip := metadata.String(c, metadata.RemoteIP)
  483. inMid, _ := strconv.ParseInt(kw, 10, 64)
  484. nickMid, err := danmuSvc.UserMid(c, kw, ip)
  485. if err != nil {
  486. c.JSON(nil, err)
  487. return
  488. }
  489. if nickMid != 0 && nickMid != mid {
  490. mids = append(mids, nickMid)
  491. }
  492. if inMid != 0 && inMid != nickMid && inMid != mid {
  493. mids = append(mids, inMid)
  494. }
  495. if len(mids) == 0 {
  496. c.JSON(map[string]interface{}{
  497. "users": []*accmdl.SearchUp{},
  498. }, nil)
  499. return
  500. }
  501. g.Go(func() error {
  502. if accCards, err = accSvc.Cards(c, mids, ip); err != nil {
  503. log.Error("accSvc.Infos(%v) error(%v)", mids, err)
  504. return err
  505. }
  506. return nil
  507. })
  508. g.Go(func() error {
  509. if relas, err = accSvc.FRelations(c, mid, mids, ip); err != nil {
  510. log.Error("accSvc.Relations(%d,%v) error(%v)", mid, mids, err)
  511. return err
  512. }
  513. return nil
  514. })
  515. if err = g.Wait(); err != nil {
  516. c.JSON(nil, err)
  517. return
  518. }
  519. for _, v := range accCards {
  520. up := &accmdl.SearchUp{
  521. Mid: v.Mid,
  522. Name: v.Name,
  523. Face: v.Face,
  524. Silence: v.Silence,
  525. }
  526. if rela, ok := relas[v.Mid]; ok {
  527. up.Relation = rela
  528. if rela >= 128 {
  529. up.IsBlock = true
  530. }
  531. }
  532. searchUp = append(searchUp, up)
  533. }
  534. c.JSON(map[string]interface{}{
  535. "users": searchUp,
  536. }, nil)
  537. }