action.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package http
  2. import (
  3. "go-common/app/admin/main/reply/model"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. func actionCount(c *bm.Context) {
  9. var (
  10. err error
  11. v = new(struct {
  12. RpID int64 `form:"rpid" validate:"required"`
  13. Oid int64 `form:"oid" validate:"required"`
  14. Type int32 `form:"type" validate:"required"`
  15. AdminID int64 `form:"admin_id"`
  16. })
  17. )
  18. if err = c.Bind(v); err != nil {
  19. return
  20. }
  21. like, hate, err := rpSvc.ActionCount(c, v.RpID, v.Oid, v.AdminID, v.Type)
  22. if err != nil {
  23. log.Warn("svc.ActionInfo(%+v) error(%v)", v, err)
  24. c.JSON(nil, err)
  25. return
  26. }
  27. data := map[string]interface{}{
  28. "like": like,
  29. "hate": hate,
  30. }
  31. c.JSONMap(data, nil)
  32. }
  33. func actionUpdate(c *bm.Context) {
  34. var (
  35. err error
  36. v = new(struct {
  37. RpID int64 `form:"rpid" validate:"required"`
  38. Oid int64 `form:"oid" validate:"required"`
  39. Type int32 `form:"type" validate:"required"`
  40. Action int32 `form:"action" validate:"required,min=1,max=2"`
  41. Count int32 `form:"count"`
  42. AdminID int64 `form:"admin_id"`
  43. Remark string `form:"remark"`
  44. })
  45. )
  46. if err = c.Bind(v); err != nil {
  47. return
  48. }
  49. adid := v.AdminID
  50. if uid, ok := c.Get("uid"); ok {
  51. adid = uid.(int64)
  52. }
  53. switch v.Action {
  54. case model.ActionLike:
  55. if v.Count < 0 {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. err = rpSvc.UpActionLike(c, v.RpID, v.Oid, adid, v.Type, v.Count, v.Remark)
  60. case model.ActionHate:
  61. err = rpSvc.UpActionHate(c, v.RpID, v.Oid, adid, v.Type, v.Count, v.Remark)
  62. default:
  63. err = ecode.RequestErr
  64. }
  65. if err != nil {
  66. log.Warn("rpSvc.ActionUpdate(%v) error(%v)", v, err)
  67. c.JSON(nil, err)
  68. return
  69. }
  70. c.JSON(nil, nil)
  71. }