app_h5.go 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/creative/model/academy"
  5. "go-common/app/interface/main/creative/model/archive"
  6. whmdl "go-common/app/interface/main/creative/model/weeklyhonor"
  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/sync/errgroup"
  12. "go-common/library/xstr"
  13. )
  14. func appH5ArcTags(c *bm.Context) {
  15. params := c.Request.Form
  16. tidStr := params.Get("typeid")
  17. title := params.Get("title")
  18. filename := params.Get("filename")
  19. desc := params.Get("desc")
  20. cover := params.Get("cover")
  21. midStr, ok := c.Get("mid")
  22. mid := midStr.(int64)
  23. if !ok {
  24. c.JSON(nil, ecode.CreativeNotLogin)
  25. return
  26. }
  27. tid, _ := strconv.ParseInt(tidStr, 10, 16)
  28. if tid <= 0 {
  29. tid = 0
  30. }
  31. tags, _ := dataSvc.TagsWithChecked(c, mid, uint16(tid), title, filename, desc, cover, archive.TagPredictFromAPP)
  32. c.JSON(tags, nil)
  33. }
  34. func appH5ArcTagInfo(c *bm.Context) {
  35. params := c.Request.Form
  36. tagNameStr := params.Get("tag_name")
  37. midStr, ok := c.Get("mid")
  38. mid := midStr.(int64)
  39. if !ok {
  40. c.JSON(nil, ecode.CreativeNotLogin)
  41. return
  42. }
  43. if len(tagNameStr) == 0 {
  44. log.Error("tagNameStr len zero (%s)", tagNameStr)
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. code, msg := arcSvc.TagCheck(c, mid, tagNameStr)
  49. c.JSON(map[string]interface{}{
  50. "code": code,
  51. "msg": msg,
  52. }, nil)
  53. }
  54. func appH5Pre(c *bm.Context) {
  55. midStr, ok := c.Get("mid")
  56. if !ok {
  57. c.JSON(nil, ecode.CreativeNotLogin)
  58. return
  59. }
  60. mid := midStr.(int64)
  61. c.JSON(map[string]interface{}{
  62. "activities": arcSvc.Activities(c),
  63. "fav": arcSvc.Fav(c, mid),
  64. }, nil)
  65. }
  66. func appH5MissionByType(c *bm.Context) {
  67. params := c.Request.Form
  68. tidStr := params.Get("tid")
  69. _, ok := c.Get("mid")
  70. if !ok {
  71. c.JSON(nil, ecode.CreativeNotLogin)
  72. return
  73. }
  74. tid, _ := strconv.Atoi(tidStr)
  75. actWithTP, _ := arcSvc.MissionOnlineByTid(c, int16(tid), 1)
  76. c.JSON(actWithTP, nil)
  77. }
  78. func toInt(s string) (i int, err error) {
  79. if s == "" {
  80. return 0, nil
  81. }
  82. i, err = strconv.Atoi(s)
  83. if err != nil {
  84. log.Error("strconv.Atoi s(%s) error(%v)", s, err)
  85. err = ecode.RequestErr
  86. }
  87. return
  88. }
  89. func toInt64(s string) (i int64, err error) {
  90. if s == "" {
  91. return 0, nil
  92. }
  93. i, err = strconv.ParseInt(s, 10, 64)
  94. if err != nil {
  95. log.Error("strconv.Atoi s(%s) error(%v)", s, err)
  96. err = ecode.RequestErr
  97. }
  98. return
  99. }
  100. func h5ViewPlay(c *bm.Context) {
  101. params := c.Request.Form
  102. aidStr := params.Get("aid")
  103. busStr := params.Get("business")
  104. // check user
  105. midI, ok := c.Get("mid")
  106. if !ok {
  107. c.JSON(nil, ecode.CreativeNotLogin)
  108. return
  109. }
  110. mid, ok := midI.(int64)
  111. if !ok || mid == 0 {
  112. c.JSON(nil, ecode.CreativeNotLogin)
  113. return
  114. }
  115. aid, err := toInt64(aidStr)
  116. if err != nil || aid <= 0 {
  117. c.JSON(nil, err)
  118. return
  119. }
  120. bus, err := toInt(busStr)
  121. if err != nil {
  122. c.JSON(nil, err)
  123. return
  124. }
  125. if aid == 0 || bus == 0 {
  126. c.JSON(nil, ecode.RequestErr)
  127. return
  128. }
  129. pl, err := acaSvc.ViewPlay(c, mid, aid, int8(bus))
  130. if err != nil {
  131. c.JSON(nil, err)
  132. return
  133. }
  134. c.JSON(pl, nil)
  135. }
  136. func h5AddPlay(c *bm.Context) {
  137. params := c.Request.Form
  138. aidStr := params.Get("aid")
  139. busStr := params.Get("business")
  140. watchStr := params.Get("watch")
  141. // check user
  142. midI, ok := c.Get("mid")
  143. if !ok {
  144. c.JSON(nil, ecode.CreativeNotLogin)
  145. return
  146. }
  147. mid, ok := midI.(int64)
  148. if !ok || mid == 0 {
  149. c.JSON(nil, ecode.CreativeNotLogin)
  150. return
  151. }
  152. aid, err := toInt64(aidStr)
  153. if err != nil || aid <= 0 {
  154. c.JSON(nil, err)
  155. return
  156. }
  157. bus, err := toInt(busStr)
  158. if err != nil {
  159. c.JSON(nil, err)
  160. return
  161. }
  162. watch, err := toInt(watchStr)
  163. if err != nil {
  164. c.JSON(nil, err)
  165. return
  166. }
  167. if aid == 0 || bus == 0 || watch == 0 {
  168. c.JSON(nil, ecode.RequestErr)
  169. return
  170. }
  171. id, err := acaSvc.PlayAdd(c, mid, aid, int8(bus), int8(watch))
  172. if err != nil {
  173. c.JSON(nil, err)
  174. return
  175. }
  176. c.JSON(map[string]interface{}{
  177. "id": id,
  178. }, nil)
  179. }
  180. func h5DelPlay(c *bm.Context) {
  181. params := c.Request.Form
  182. aidStr := params.Get("aid")
  183. busStr := params.Get("business")
  184. // check user
  185. midI, ok := c.Get("mid")
  186. if !ok {
  187. c.JSON(nil, ecode.CreativeNotLogin)
  188. return
  189. }
  190. mid, ok := midI.(int64)
  191. if !ok || mid == 0 {
  192. c.JSON(nil, ecode.CreativeNotLogin)
  193. return
  194. }
  195. aid, err := toInt64(aidStr)
  196. if err != nil || aid <= 0 {
  197. c.JSON(nil, err)
  198. return
  199. }
  200. bus, err := toInt(busStr)
  201. if err != nil {
  202. c.JSON(nil, err)
  203. return
  204. }
  205. if aid == 0 || bus == 0 {
  206. c.JSON(nil, ecode.RequestErr)
  207. return
  208. }
  209. id, err := acaSvc.PlayDel(c, mid, aid, int8(bus))
  210. if err != nil {
  211. c.JSON(nil, err)
  212. return
  213. }
  214. c.JSON(map[string]interface{}{
  215. "id": id,
  216. }, nil)
  217. }
  218. func h5PlayList(c *bm.Context) {
  219. params := c.Request.Form
  220. pnStr := params.Get("pn")
  221. psStr := params.Get("ps")
  222. // check user
  223. midStr, ok := c.Get("mid")
  224. if !ok {
  225. c.JSON(nil, ecode.CreativeNotLogin)
  226. return
  227. }
  228. mid, ok := midStr.(int64)
  229. if !ok || mid == 0 {
  230. c.JSON(nil, ecode.CreativeNotLogin)
  231. return
  232. }
  233. pn, err := toInt(pnStr)
  234. if err != nil {
  235. c.JSON(nil, err)
  236. return
  237. }
  238. ps, err := toInt(psStr)
  239. if err != nil {
  240. c.JSON(nil, err)
  241. return
  242. }
  243. if pn <= 0 {
  244. pn = 1
  245. }
  246. if ps > 20 || ps <= 0 {
  247. ps = 20
  248. }
  249. arcs, err := acaSvc.PlayList(c, mid, pn, ps)
  250. if err != nil {
  251. c.JSON(nil, err)
  252. return
  253. }
  254. c.JSON(arcs, nil)
  255. }
  256. func h5ThemeDir(c *bm.Context) {
  257. occs, err := acaSvc.Occupations(c)
  258. if err != nil {
  259. c.JSON(nil, err)
  260. return
  261. }
  262. c.JSON(occs, nil)
  263. }
  264. func h5NewbCourse(c *bm.Context) {
  265. nc, err := acaSvc.NewbCourse(c)
  266. if err != nil {
  267. c.JSON(nil, err)
  268. return
  269. }
  270. c.JSON(nc, nil)
  271. }
  272. func h5Tags(c *bm.Context) {
  273. c.JSON(acaSvc.Tags(c), nil)
  274. }
  275. func h5Archive(c *bm.Context) {
  276. params := c.Request.Form
  277. tidsStr := params.Get("tids")
  278. bsStr := params.Get("business")
  279. pageStr := params.Get("pn")
  280. psStr := params.Get("ps")
  281. keyword := params.Get("keyword")
  282. order := params.Get("order")
  283. drStr := params.Get("duration")
  284. ip := metadata.String(c, metadata.RemoteIP)
  285. var (
  286. tids []int64
  287. err error
  288. )
  289. // check params
  290. if tidsStr != "" {
  291. if tids, err = xstr.SplitInts(tidsStr); err != nil {
  292. log.Error("strconv.ParseInt(%s) error(%v)", tidsStr, err)
  293. c.JSON(nil, ecode.RequestErr)
  294. return
  295. }
  296. }
  297. bs, err := toInt(bsStr)
  298. if err != nil {
  299. c.JSON(nil, err)
  300. return
  301. }
  302. dr, err := toInt(drStr)
  303. if err != nil {
  304. c.JSON(nil, err)
  305. return
  306. }
  307. pn, err := toInt(pageStr)
  308. if err != nil {
  309. c.JSON(nil, err)
  310. return
  311. }
  312. ps, err := toInt(psStr)
  313. if err != nil {
  314. c.JSON(nil, err)
  315. return
  316. }
  317. if pn <= 0 {
  318. pn = 1
  319. }
  320. if ps > 20 || ps <= 0 {
  321. ps = 20
  322. }
  323. aca := &academy.EsParam{
  324. Tid: tids,
  325. Business: bs,
  326. Pn: pn,
  327. Ps: ps,
  328. Keyword: keyword,
  329. Order: order,
  330. IP: ip,
  331. Duration: dr,
  332. }
  333. var arcs *academy.ArchiveList
  334. arcs, err = acaSvc.Archives(c, aca)
  335. if err != nil {
  336. c.JSON(nil, err)
  337. return
  338. }
  339. c.JSON(arcs, nil)
  340. }
  341. func h5Feature(c *bm.Context) {
  342. ip := metadata.String(c, metadata.RemoteIP)
  343. // check params
  344. aca := &academy.EsParam{
  345. Pn: 1,
  346. Ps: 50,
  347. Keyword: "",
  348. Order: "",
  349. IP: ip,
  350. }
  351. aca2 := &academy.EsParam{
  352. Pn: 1,
  353. Ps: 50,
  354. Keyword: "",
  355. Order: "",
  356. IP: ip,
  357. }
  358. var (
  359. g = &errgroup.Group{}
  360. offArcs, chArcs *academy.ArchiveList
  361. )
  362. g.Go(func() error {
  363. aca.Tid = []int64{acaSvc.OfficialID} //官方课程
  364. offArcs, _ = acaSvc.ArchivesWithES(c, aca)
  365. return nil
  366. })
  367. g.Go(func() error {
  368. aca2.Tid = []int64{acaSvc.EditorChoiceID} //编辑精选
  369. chArcs, _ = acaSvc.ArchivesWithES(c, aca2)
  370. return nil
  371. })
  372. g.Wait()
  373. c.JSON(map[string]interface{}{
  374. "official_course": offArcs,
  375. "editor_choice": chArcs,
  376. }, nil)
  377. }
  378. func weeklyHonor(c *bm.Context) {
  379. midStr, _ := c.Get("mid")
  380. var mid int64
  381. uid, ok := midStr.(int64)
  382. if ok {
  383. mid = uid
  384. }
  385. arg := new(struct {
  386. UID int64 `form:"uid"`
  387. Token string `form:"token"`
  388. })
  389. if err := c.Bind(arg); err != nil {
  390. return
  391. }
  392. if mid == 0 && arg.UID == 0 {
  393. c.JSON(nil, ecode.CreativeNotLogin)
  394. return
  395. }
  396. rec, err := honorSvc.WeeklyHonor(c, mid, arg.UID, arg.Token)
  397. if err != nil {
  398. c.JSON(nil, err)
  399. return
  400. }
  401. c.JSON(rec, nil)
  402. }
  403. func weeklyHonorSubSwitch(c *bm.Context) {
  404. midStr, _ := c.Get("mid")
  405. mid := midStr.(int64)
  406. if mid <= 0 {
  407. c.JSON(nil, ecode.CreativeNotLogin)
  408. return
  409. }
  410. params := c.Request.Form
  411. stateStr := params.Get("state")
  412. st, err := strconv.Atoi(stateStr)
  413. state := uint8(st)
  414. if err != nil || (state != whmdl.HonorSub && state != whmdl.HonorUnSub) {
  415. c.JSON(nil, ecode.ReqParamErr)
  416. }
  417. err = honorSvc.ChangeSubState(c, mid, state)
  418. c.JSON(nil, err)
  419. }
  420. func h5RecommendV2(c *bm.Context) {
  421. midStr, _ := c.Get("mid")
  422. var mid int64
  423. uid, ok := midStr.(int64)
  424. if ok {
  425. mid = uid
  426. }
  427. rec, err := acaSvc.RecommendV2(c, mid)
  428. if err != nil {
  429. c.JSON(nil, err)
  430. return
  431. }
  432. c.JSON(rec, nil)
  433. }
  434. func h5ThemeCousreV2(c *bm.Context) {
  435. params := c.Request.Form
  436. pnStr := params.Get("pn")
  437. psStr := params.Get("ps")
  438. pidStr := params.Get("pid")
  439. skidStr := params.Get("skid")
  440. sidStr := params.Get("sid")
  441. pn, err := toInt(pnStr)
  442. if err != nil {
  443. c.JSON(nil, err)
  444. return
  445. }
  446. ps, err := toInt(psStr)
  447. if err != nil {
  448. c.JSON(nil, err)
  449. return
  450. }
  451. if pn <= 0 {
  452. pn = 1
  453. }
  454. if ps > 20 || ps <= 0 {
  455. ps = 20
  456. }
  457. var pids, skids, sids []int64
  458. if pidStr != "" {
  459. if pids, err = xstr.SplitInts(pidStr); err != nil {
  460. log.Error("strconv.ParseInt pidStr(%s) error(%v)", pidStr, err)
  461. c.JSON(nil, ecode.RequestErr)
  462. return
  463. }
  464. }
  465. if skidStr != "" {
  466. if skids, err = xstr.SplitInts(skidStr); err != nil {
  467. log.Error("strconv.ParseInt skidStr(%s) error(%v)", skidStr, err)
  468. c.JSON(nil, ecode.RequestErr)
  469. return
  470. }
  471. }
  472. if sidStr != "" {
  473. if sids, err = xstr.SplitInts(sidStr); err != nil {
  474. log.Error("strconv.ParseInt sidStr(%s) error(%v)", sidStr, err)
  475. c.JSON(nil, ecode.RequestErr)
  476. return
  477. }
  478. }
  479. arcs, err := acaSvc.ProfessionSkill(c, pids, skids, sids, pn, ps, false)
  480. if err != nil {
  481. c.JSON(nil, err)
  482. return
  483. }
  484. c.JSON(arcs, nil)
  485. }
  486. func h5Keywords(c *bm.Context) {
  487. c.JSON(acaSvc.Keywords(c), nil)
  488. }