test.go 779 B

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