user.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package models
  2. import (
  3. "errors"
  4. "github.com/jinzhu/gorm"
  5. )
  6. // User user
  7. type User struct {
  8. gorm.Model
  9. UserKey string
  10. UserRoleID int
  11. UserName string `sql:"type:varchar(20);not null;"`
  12. UserPass string `sql:"type:varchar(50);not null;"`
  13. Phone string `sql:"type:varchar(20);not null;"`
  14. Email string `sql:"type:varchar(200);not null;"`
  15. UserType int `sql:"default:1;not null;"`
  16. VendorID uint
  17. Status int `sql:"default:1;not null;"`
  18. Vendor Vendor `gorm:"foreignkey:VendorID"`
  19. }
  20. // Validate 验证
  21. func (a *User) Validate() error {
  22. if a.UserName == "" || a.UserPass == "" || a.Vendor.VendorName == "" {
  23. return errors.New("参数不能为空")
  24. }
  25. return nil
  26. }
  27. // LoginRequest 登录请求
  28. type LoginRequest struct {
  29. UserName string `json:"login_name" `
  30. Password string `json:"login_pass" `
  31. }
  32. // Validate 验证
  33. func (a *LoginRequest) Validate() error {
  34. if a.UserName == "" || a.Password == "" {
  35. return errors.New("参数不能为空")
  36. }
  37. return nil
  38. }
  39. // Reqrequest 注册请求
  40. type Reqrequest struct {
  41. UserName string `json:"username"`
  42. PassWord string `json:"password" `
  43. Phone string `json:"phone" `
  44. Email string `json:"email" `
  45. VendorName string `json:"company"`
  46. }
  47. // Validate 验证
  48. func (a *Reqrequest) Validate() error {
  49. if a.UserName == "" || a.PassWord == "" || a.Phone == "" || a.Email == "" || a.VendorName == "" {
  50. return errors.New("参数不能为空")
  51. }
  52. return nil
  53. }