蛋蛋星球-客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

648 lines
19 KiB

  1. package friend_circle
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/im/model"
  5. "applet/app/e"
  6. "applet/app/md/friend_circles"
  7. "applet/app/svc"
  8. svc2 "applet/app/svc/friend_circle"
  9. "applet/app/utils"
  10. "code.fnuoos.com/EggPlanet/egg_system_rules.git/md"
  11. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  12. svc3 "code.fnuoos.com/EggPlanet/egg_system_rules.git/svc"
  13. "code.fnuoos.com/go_rely_warehouse/zyos_go_es.git/es"
  14. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  15. "context"
  16. "encoding/json"
  17. "errors"
  18. "fmt"
  19. "github.com/gin-gonic/gin"
  20. "github.com/olivere/elastic/v7"
  21. "strconv"
  22. "strings"
  23. "time"
  24. )
  25. // PersonalSendingList
  26. // @Summary 朋友圈-个人发送朋友圈列表
  27. // @Tags 朋友圈
  28. // @Description 个人发送朋友圈列表
  29. // @Accept json
  30. // @Produce json
  31. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  32. // @Param req body friend_circles.PersonalSendingListReq true "签名上传url"
  33. // @Success 200 {object} friend_circles.PersonalSendingListResp "返回数据"
  34. // @Failure 400 {object} md.Response "具体错误"
  35. // @Router /api/v1/circleFriends/personalSending [POST]
  36. func PersonalSendingList(c *gin.Context) {
  37. var req friend_circles.PersonalSendingListReq
  38. err := c.ShouldBindJSON(&req)
  39. if err != nil {
  40. err = svc.HandleValidateErr(err)
  41. err1 := err.(e.E)
  42. e.OutErr(c, err1.Code, err1.Error())
  43. return
  44. }
  45. resp, err := svc2.GetPersonalSendingList(c, req)
  46. if err != nil {
  47. e.OutErr(c, e.ERR, err.Error())
  48. }
  49. resp.Page = req.Page
  50. resp.PageSize = req.PageSize
  51. e.OutSuc(c, resp, nil)
  52. }
  53. // MySelfList
  54. // @Summary 朋友圈-我的朋友圈列表
  55. // @Tags 朋友圈
  56. // @Description 我的朋友圈列表
  57. // @Accept json
  58. // @Produce json
  59. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  60. // @Param req body friend_circles.MySelfListReq true "签名上传url"
  61. // @Success 200 {object} friend_circles.MySelfListResp "返回数据"
  62. // @Failure 400 {object} md.Response "具体错误"
  63. // @Router /api/v1/circleFriends/mySelfList [POST]
  64. func MySelfList(c *gin.Context) {
  65. var args friend_circles.MySelfListReq
  66. err := c.ShouldBindJSON(&args)
  67. if err != nil {
  68. err = svc.HandleValidateErr(err)
  69. err1 := err.(e.E)
  70. e.OutErr(c, err1.Code, err1.Error())
  71. return
  72. }
  73. resp, err := svc2.MySelfList(c, args)
  74. if err != nil {
  75. e.OutErr(c, e.ERR, err.Error())
  76. return
  77. }
  78. imUserIds := make([]int64, len(resp.List))
  79. for i, friendCircle := range resp.List {
  80. imUserIds[i] = friendCircle.ImUid
  81. }
  82. nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
  83. if err != nil {
  84. e.OutErr(c, e.ERR, err.Error())
  85. return
  86. }
  87. for _, friendCircle := range resp.List {
  88. val, ok := nicknameAndAvatarMap[friendCircle.ImUid]
  89. if ok {
  90. friendCircle.ImNickname = val.NickName
  91. friendCircle.ImAvatar = val.Avatar
  92. }
  93. }
  94. resp.Page = args.Page
  95. resp.PageSize = args.PageSize
  96. e.OutSuc(c, resp, nil)
  97. }
  98. // IsCanPublish
  99. // @Summary 朋友圈-是否可以发布朋友圈
  100. // @Tags 朋友圈
  101. // @Description 是否可以发布朋友圈
  102. // @Accept json
  103. // @Produce json
  104. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  105. // @Success 200 {string} "success"
  106. // @Failure 400 {object} md.Response "具体错误"
  107. // @Router /api/v1/circleFriends/isCanPublish [GET]
  108. func IsCanPublish(c *gin.Context) {
  109. isCan, err := svc2.IsCanPublish(c)
  110. if err != nil {
  111. fmt.Println("IsPublish:::::", err.Error())
  112. }
  113. resp := friend_circles.IsCanCommentResp{IsCan: isCan}
  114. e.OutSuc(c, resp, nil)
  115. }
  116. // FriendCircleLikeList
  117. // @Summary 朋友圈-朋友圈点赞列表
  118. // @Tags 朋友圈
  119. // @Description 朋友圈点赞列表
  120. // @Accept json
  121. // @Produce json
  122. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  123. // @Param req body friend_circles.FriendCircleLikeListReq true "签名上传url"
  124. // @Success 200 {object} friend_circles.FriendCircleLikeListResp "返回数据"
  125. // @Failure 400 {object} md.Response "具体错误"
  126. // @Router /api/v1/circleFriends/likeList [POST]
  127. func FriendCircleLikeList(c *gin.Context) {
  128. var req friend_circles.FriendCircleLikeListReq
  129. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  130. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  131. return
  132. }
  133. //查找朋友圈记录
  134. doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, req.CircleIndexId)
  135. if err != nil {
  136. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  137. return
  138. }
  139. if !doc.Found { // 表示没找到数据
  140. e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在")
  141. return
  142. }
  143. from := (req.Page - 1) * req.PageSize
  144. // 查找点赞列表
  145. query := elastic.NewBoolQuery()
  146. query.Must(elastic.NewTermQuery("circle_id", req.CircleIndexId))
  147. searchResult, err := es.EsClient.Search().
  148. Index(md.EggFriendCircleLikeEsAlias). // 替换为你的索引名称
  149. Query(query).
  150. From(from).
  151. Size(req.PageSize).
  152. Sort("created_at", false). // 按时间倒排
  153. Pretty(true).
  154. Do(context.Background())
  155. if err != nil {
  156. return
  157. }
  158. var docs []*md.EggFriendCircleLikeEs
  159. var docUserIds []int64
  160. var total int64
  161. // 检查是否有结果
  162. if searchResult.Hits.TotalHits.Value != 0 {
  163. // 解析结果
  164. total = searchResult.Hits.TotalHits.Value
  165. for _, hit := range searchResult.Hits.Hits {
  166. var like md.EggFriendCircleLikeEs
  167. err = json.Unmarshal(hit.Source, &like)
  168. if err != nil {
  169. return
  170. }
  171. docUserIds = append(docUserIds, like.ImUid)
  172. docs = append(docs, &like)
  173. }
  174. }
  175. nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(docUserIds)
  176. if err != nil {
  177. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  178. return
  179. }
  180. var list []*friend_circles.FriendCircleLikeEsStruct
  181. for _, like := range docs {
  182. temp := friend_circles.FriendCircleLikeEsStruct{
  183. Uid: like.Uid,
  184. ImUid: like.ImUid,
  185. CircleId: like.CircleId,
  186. }
  187. val, ok := nicknameAndAvatarMap[like.ImUid]
  188. if ok {
  189. temp.ImNickname = val.NickName
  190. temp.ImAvatar = val.Avatar
  191. }
  192. list = append(list, &temp)
  193. }
  194. resp := friend_circles.FriendCircleLikeListResp{
  195. List: list,
  196. Page: req.Page,
  197. PageSize: req.PageSize,
  198. Total: total,
  199. }
  200. e.OutSuc(c, resp, nil)
  201. }
  202. // Publish
  203. // @Summary 朋友圈-发布朋友圈
  204. // @Tags 朋友圈
  205. // @Description 发布朋友圈
  206. // @Accept json
  207. // @Produce json
  208. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  209. // @Param req body friend_circles.PublishReq true "请求参数"
  210. // @Success 200 {string} "success"
  211. // @Failure 400 {object} md.Response "具体错误"
  212. // @Router /api/v1/circleFriends/publish [POST]
  213. func Publish(c *gin.Context) {
  214. var req friend_circles.PublishReq
  215. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  216. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  217. return
  218. }
  219. isCan, err := svc2.IsCanPublish(c)
  220. if err != nil {
  221. e.OutErr(c, e.ERR, err.Error())
  222. return
  223. }
  224. if !isCan {
  225. e.OutErr(c, e.ERR, "当前不允许发朋友圈")
  226. return
  227. }
  228. user := svc.GetUser(c)
  229. var imUser model.User
  230. _, err = db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser)
  231. if err != nil {
  232. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  233. return
  234. }
  235. scheme, domain := svc.ImageBucket(db.Db)
  236. var imageStr string
  237. if len(req.ImageList) > 0 {
  238. imageStr = utils.SerializeStr(req.ImageList)
  239. imageStr = strings.ReplaceAll(imageStr, fmt.Sprintf("%s://%s/", scheme, domain), "{{tempHost}}")
  240. }
  241. //插入es记录
  242. now := time.Now()
  243. nowStr := now.Format("2006-01-02 15:04:05")
  244. createDocRet, err := es.CreateDoc(md.EggFriendCircleEsIndex, strconv.FormatInt(user.Id, 10)+"_"+utils.Int64ToStr(now.Unix()), md.EggFriendCircleEs{
  245. Uid: user.Id,
  246. ImUid: imUser.Id,
  247. Kind: 1,
  248. Content: req.Content,
  249. Image: imageStr,
  250. Video: req.Video,
  251. LikesNums: 0,
  252. ShareNums: 0,
  253. CommentNums: 0,
  254. State: 1,
  255. IsTopUp: 2,
  256. IsPraise: 2,
  257. CreatedAt: nowStr,
  258. UpdatedAt: nowStr,
  259. })
  260. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  261. // 推到 es 更新发朋友圈次数
  262. ch, err := rabbit.Cfg.Pool.GetChannel()
  263. if err != nil {
  264. return
  265. }
  266. defer ch.Release()
  267. ch.Publish(md2.EggAppExchange, md2.EggSendFriendCircleData{Uid: user.Id}, md2.EggRoutKeyForSendFriendCircle)
  268. e.OutSuc(c, "success", nil)
  269. }
  270. // RecommendList
  271. // @Summary 朋友圈-推荐列表
  272. // @Tags 朋友圈
  273. // @Description 推荐列表
  274. // @Accept json
  275. // @Produce json
  276. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  277. // @Param req body friend_circles.RecommendListReq true "签名上传url"
  278. // @Success 200 {object} friend_circles.RecommendListResp "返回数据"
  279. // @Failure 400 {object} md.Response "具体错误"
  280. // @Router /api/v1/circleFriends/recommendList [POST]
  281. func RecommendList(c *gin.Context) {
  282. var req friend_circles.RecommendListReq
  283. err := c.ShouldBindJSON(&req)
  284. if err != nil {
  285. err = svc.HandleValidateErr(err)
  286. err1 := err.(e.E)
  287. e.OutErr(c, err1.Code, err1.Error())
  288. return
  289. }
  290. resp, err := svc2.GetRecommendList(req)
  291. if err != nil {
  292. e.OutErr(c, e.ERR, err.Error())
  293. return
  294. }
  295. imUserIds := make([]int64, len(resp.List))
  296. for i, friendCircle := range resp.List {
  297. imUserIds[i] = friendCircle.ImUid
  298. }
  299. nicknameAndAvatarMap, err := svc2.GetImUserNicknameAndAvatar(imUserIds)
  300. if err != nil {
  301. e.OutErr(c, e.ERR, err.Error())
  302. return
  303. }
  304. for _, friendCircle := range resp.List {
  305. val, ok := nicknameAndAvatarMap[friendCircle.ImUid]
  306. if ok {
  307. friendCircle.ImNickname = val.NickName
  308. friendCircle.ImAvatar = val.Avatar
  309. }
  310. }
  311. e.OutSuc(c, resp, nil)
  312. }
  313. // CommentList
  314. // @Summary 朋友圈-评论列表
  315. // @Tags 朋友圈
  316. // @Description 评论列表
  317. // @Accept json
  318. // @Produce json
  319. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  320. // @Param circle_index_id query string true "朋友圈文档记录"
  321. // @Param req body friend_circles.CommentListReq true "请求参数"
  322. // @Success 200 {string} "success"
  323. // @Failure 400 {object} md.Response "具体错误"
  324. // @Router /api/v1/circleFriends/commentList [POST]
  325. func CommentList(c *gin.Context) {
  326. var req friend_circles.CommentListReq
  327. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  328. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  329. return
  330. }
  331. //查找朋友圈记录
  332. doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, req.CircleIndexId)
  333. if err != nil {
  334. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  335. return
  336. }
  337. if !doc.Found { // 表示没找到数据
  338. e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在")
  339. return
  340. }
  341. resp, err := svc2.CommentList(req)
  342. if err != nil {
  343. e.OutErr(c, e.ERR, err.Error())
  344. return
  345. }
  346. e.OutSuc(c, resp, nil)
  347. }
  348. // CommentDetail
  349. // @Summary 朋友圈-评论详情
  350. // @Tags 朋友圈
  351. // @Description 评论详情
  352. // @Accept json
  353. // @Produce json
  354. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  355. // @Param comment_index_id query string true "评论文档记录"
  356. // @Success 200 {string} "success"
  357. // @Failure 400 {object} md.Response "具体错误"
  358. // @Router /api/v1/circleFriends/commentDetail [GET]
  359. func CommentDetail(c *gin.Context) {
  360. var req friend_circles.CommentDetailReq
  361. if err1 := c.ShouldBindJSON(&req); err1 != nil {
  362. e.OutErr(c, e.ERR_INVALID_ARGS, err1.Error())
  363. return
  364. }
  365. //查找评论记录
  366. boolQuery := elastic.NewBoolQuery()
  367. boolQuery.Must(elastic.NewTermQuery("_id", req.CommentIndexId))
  368. searchResult, err := es.EsClient.Search().
  369. Index(md.EggFriendCircleCommentEsAlias).
  370. Query(boolQuery).
  371. Pretty(true).
  372. Do(context.Background())
  373. if err != nil {
  374. e.OutErr(c, e.ERR, err.Error())
  375. return
  376. }
  377. var doc md.EggFriendCircleCommentEs
  378. // 检查是否有结果
  379. if searchResult.Hits.TotalHits.Value != 0 {
  380. err = json.Unmarshal(searchResult.Hits.Hits[0].Source, &doc)
  381. if err != nil {
  382. e.OutErr(c, e.ERR, err.Error())
  383. return
  384. }
  385. } else {
  386. e.OutErr(c, e.ERR_NOT_FAN, "评论文档记录不存在")
  387. return
  388. }
  389. resp, err := svc2.CommentDetail(req)
  390. if err != nil {
  391. e.OutErr(c, e.ERR, err.Error())
  392. return
  393. }
  394. resp.CircleIndexId = doc.CircleId
  395. e.OutSuc(c, resp, nil)
  396. }
  397. // Delete
  398. // @Summary 朋友圈-删除朋友圈
  399. // @Tags 朋友圈
  400. // @Description 删除朋友圈
  401. // @Accept json
  402. // @Produce json
  403. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  404. // @Param req body friend_circles.EggFriendCircleDelReq true "请求参数"
  405. // @Success 200 {string} "success"
  406. // @Failure 400 {object} md.Response "具体错误"
  407. // @Router /api/v1/circleFriends/delete [DELETE]
  408. func Delete(c *gin.Context) {
  409. var req friend_circles.EggFriendCircleDelReq
  410. err := c.ShouldBindJSON(&req)
  411. if err != nil {
  412. err = svc.HandleValidateErr(err)
  413. err1 := err.(e.E)
  414. e.OutErr(c, err1.Code, err1.Error())
  415. return
  416. }
  417. user := svc.GetUser(c)
  418. aliasName := md.EggFriendCircleEsAlias
  419. // 1.判断是否是自己文章
  420. doc, err := es.FirstDoc(md.EggFriendCircleEsIndex, req.CircleIndexId)
  421. if err != nil {
  422. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  423. return
  424. }
  425. if !doc.Found { // 表示没找到数据
  426. e.OutErr(c, e.ERR_NOT_FAN, "朋友圈文档记录不存在")
  427. return
  428. }
  429. var docInfo md.EggFriendCircleEs
  430. utils.Unserialize(doc.Source, &docInfo)
  431. if docInfo.Uid != user.Id {
  432. e.OutErr(c, e.ERR, errors.New("不允许删除别人的朋友圈"))
  433. return
  434. }
  435. // 2.删除文章
  436. deleteDocRet, err := es.DeleteDoc(aliasName, req.CircleIndexId)
  437. if err != nil {
  438. e.OutErr(c, e.ERR, err.Error())
  439. return
  440. }
  441. fmt.Printf("CreateDoc ==> %+v \n\n", deleteDocRet)
  442. // 3.将评论id推入mq
  443. err = svc2.DelFriendCircleComment(req.CircleIndexId)
  444. if err != nil {
  445. e.OutErr(c, e.ERR, err.Error())
  446. return
  447. }
  448. e.OutSuc(c, "success", nil)
  449. }
  450. // Share
  451. // @Summary 朋友圈-分享后朋友圈分享数(增加)
  452. // @Tags 朋友圈
  453. // @Description 分享后朋友圈分享数(增加)
  454. // @Accept json
  455. // @Produce json
  456. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  457. // @Param req body friend_circles.EggFriendCircleShareReq true "请求参数"
  458. // @Success 200 {string} "success"
  459. // @Failure 400 {object} md.Response "具体错误"
  460. // @Router /api/v1/circleFriends/share [POST]
  461. func Share(c *gin.Context) {
  462. var req friend_circles.EggFriendCircleShareReq
  463. err := c.ShouldBindJSON(&req)
  464. if err != nil {
  465. err = svc.HandleValidateErr(err)
  466. err1 := err.(e.E)
  467. e.OutErr(c, err1.Code, err1.Error())
  468. return
  469. }
  470. script := elastic.NewScript("ctx._source.share_nums += params.inc").Param("inc", 1)
  471. aliasName := md.EggFriendCircleEsAlias
  472. _, err = es.EsClient.Update().
  473. Index(aliasName).
  474. Id(req.CircleIndexId).
  475. Script(script).
  476. Do(context.Background())
  477. if err != nil {
  478. e.OutErr(c, e.ERR, err.Error())
  479. return
  480. }
  481. e.OutSuc(c, "success", nil)
  482. }
  483. // Like
  484. // @Summary 朋友圈-点赞朋友圈
  485. // @Tags 朋友圈
  486. // @Description 点赞朋友圈
  487. // @Accept json
  488. // @Produce json
  489. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  490. // @Param req body friend_circles.EggFriendCircleLikeReq true "请求参数"
  491. // @Success 200 {string} "success"
  492. // @Failure 400 {object} md.Response "具体错误"
  493. // @Router /api/v1/circleFriends/like [POST]
  494. func Like(c *gin.Context) {
  495. var req friend_circles.EggFriendCircleLikeReq
  496. err := c.ShouldBindJSON(&req)
  497. if err != nil {
  498. err = svc.HandleValidateErr(err)
  499. err1 := err.(e.E)
  500. e.OutErr(c, err1.Code, err1.Error())
  501. return
  502. }
  503. user := svc.GetUser(c)
  504. likeEsIndex := svc3.GetEggFriendCircleLikeEsIndex(user.Id)
  505. likeId := svc3.GetEggFriendCircleLikeEsIndexId(user.Id, req.CircleIndexId)
  506. // 判断是否已经点赞过
  507. query := elastic.NewBoolQuery().
  508. Must(
  509. elastic.NewTermQuery("_id", likeId),
  510. )
  511. searchResult, err := es.EsClient.Search().Index(likeEsIndex).
  512. Query(query).
  513. Size(0). // 只关心总数,不实际返回文档
  514. Do(context.Background())
  515. if err != nil {
  516. return
  517. }
  518. total := searchResult.TotalHits()
  519. if int(total) > 0 {
  520. e.OutSuc(c, "success", nil)
  521. return
  522. }
  523. var imUser model.User
  524. _, err = db.DbIm.Where("phone_number = ?", user.Phone).Get(&imUser)
  525. if err != nil {
  526. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  527. return
  528. }
  529. // 新增点赞信息
  530. now := time.Now()
  531. m := md.EggFriendCircleLikeEs{
  532. Uid: user.Id,
  533. ImUid: imUser.Id,
  534. CircleId: req.CircleIndexId,
  535. CreatedAt: now.Format("2006-01-02 15:04:05"),
  536. UpdatedAt: now.Format("2006-01-02 15:04:05"),
  537. }
  538. createDocRet, err := es.CreateDoc(likeEsIndex, likeId, &m)
  539. if err != nil {
  540. e.OutErr(c, e.ERR, err.Error())
  541. return
  542. }
  543. fmt.Printf("CreateDoc ==> %+v \n\n", createDocRet)
  544. // 增加文章点赞数
  545. script := elastic.NewScript("ctx._source.likes_nums += params.inc").Param("inc", 1)
  546. aliasName := md.EggFriendCircleEsAlias
  547. _, err = es.EsClient.Update().
  548. Index(aliasName).
  549. Id(req.CircleIndexId).
  550. Script(script).
  551. Do(context.Background())
  552. if err != nil {
  553. e.OutErr(c, e.ERR, err.Error())
  554. return
  555. }
  556. e.OutSuc(c, "success", nil)
  557. }
  558. // CancelLike
  559. // @Summary 朋友圈-取消点赞朋友圈
  560. // @Tags 朋友圈
  561. // @Description 取消点赞朋友圈
  562. // @Accept json
  563. // @Produce json
  564. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  565. // @Param req body friend_circles.EggFriendCircleCancelLikeReq true "请求参数"
  566. // @Success 200 {string} "success"
  567. // @Failure 400 {object} md.Response "具体错误"
  568. // @Router /api/v1/circleFriends/cancelLike [POST]
  569. func CancelLike(c *gin.Context) {
  570. // 减少文章点赞数
  571. var req friend_circles.EggFriendCircleCancelLikeReq
  572. err := c.ShouldBindJSON(&req)
  573. if err != nil {
  574. err = svc.HandleValidateErr(err)
  575. err1 := err.(e.E)
  576. e.OutErr(c, err1.Code, err1.Error())
  577. return
  578. }
  579. user := svc.GetUser(c)
  580. // 删除点赞信息
  581. likeEsIndex := svc3.GetEggFriendCircleLikeEsIndex(user.Id)
  582. likeId := svc3.GetEggFriendCircleLikeEsIndexId(user.Id, req.CircleIndexId)
  583. deleteDocRet, err := es.DeleteDoc(likeEsIndex, likeId)
  584. if err != nil {
  585. if err.Error() == "elastic: Error 404 (Not Found)" {
  586. e.OutErr(c, e.ERR_BAD_REQUEST, errors.New("点赞已取消,请勿重复请求").Error())
  587. return
  588. }
  589. e.OutErr(c, e.ERR, err.Error())
  590. return
  591. }
  592. fmt.Printf("DeleteDoc ==> %+v \n\n", deleteDocRet)
  593. // 减少文章点赞数
  594. script := elastic.NewScript("ctx._source.likes_nums -= params.inc").Param("inc", 1)
  595. aliasName := md.EggFriendCircleEsAlias
  596. _, err = es.EsClient.Update().
  597. Index(aliasName).
  598. Id(req.CircleIndexId).
  599. Script(script).
  600. Do(context.Background())
  601. if err != nil {
  602. e.OutErr(c, e.ERR, err.Error())
  603. return
  604. }
  605. e.OutSuc(c, "success", nil)
  606. }