test.go 747 B

1234567891011121314151617181920212223242526272829303132
  1. package controller
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "gorm.io/gorm"
  5. "hongze/hongze_yb/controller/response"
  6. "hongze/hongze_yb/models/tables/wx_user"
  7. )
  8. func Test(c *gin.Context) {
  9. wxUserInfo, err := wx_user.GetByMobile("18170239278")
  10. if err != nil {
  11. response.Fail("获取失败", c)
  12. return
  13. }
  14. response.OkData("获取成功", wxUserInfo, c)
  15. }
  16. func Test2(c *gin.Context) {
  17. where := make(map[string]interface{})
  18. where["mobile like"] = "11817023927%"
  19. wxUserInfo, err := wx_user.GetByWhereMap(where)
  20. if err != nil {
  21. if err == gorm.ErrRecordNotFound {
  22. response.Fail("获取失败,找不到该用户", c)
  23. } else {
  24. response.Fail("获取失败,"+err.Error(), c)
  25. }
  26. return
  27. }
  28. response.OkData("获取成功", wxUserInfo, c)
  29. }