poster.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package v1
  2. import (
  3. "context"
  4. "designs/app/common/request"
  5. "designs/config"
  6. "designs/global"
  7. "designs/response"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func AddUserOption(c *gin.Context) {
  11. //验证
  12. form := request.Check(c, &struct {
  13. OpenId string `json:"openid" binding:"required"`
  14. Gid string `json:"gid" binding:"required"`
  15. Pf string `json:"pf" binding:"required"`
  16. Option string `json:"option" binding:"required"`
  17. }{})
  18. optionKey := config.Get("app.option_key") + form.Gid + ":" + form.OpenId
  19. data := map[string]interface{}{
  20. "option": form.Option,
  21. }
  22. err := global.App.Redis.HMSet(context.Background(), optionKey, data).Err()
  23. if err != nil {
  24. response.Fail(c, 1003, err.Error())
  25. return
  26. }
  27. response.Success(c, gin.H{})
  28. }
  29. func GetUserOption(c *gin.Context) {
  30. form := request.Check(c, &struct {
  31. OpenId string `json:"openid" binding:"required"`
  32. Gid string `json:"gid" binding:"required"`
  33. }{})
  34. optionKey := config.Get("app.option_key") + form.Gid + ":" + form.OpenId
  35. data, err := global.App.Redis.HGetAll(context.Background(), optionKey).Result()
  36. if err != nil {
  37. response.Fail(c, 1003, err.Error())
  38. return
  39. }
  40. response.Success(c, gin.H{
  41. "option": data["option"],
  42. })
  43. }