互动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
3.7 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/pkg/errors"
  5. "go.uber.org/zap"
  6. "hudongzhuanjia/logger"
  7. "time"
  8. "github.com/ouxuanserver/osmanthuswine/src/core"
  9. "github.com/ouxuanserver/osmanthuswine/src/helper"
  10. )
  11. const CustomerTN = TableNamePrefix + "customer"
  12. //客户表
  13. type Customer struct {
  14. Id int64 `json:"id" xorm:"not null pk autoincr comment('主键') INT(11)"`
  15. Activities []*Activity `json:"activities" xorm:"-" description:"用户创建的主活动"`
  16. Nickname string `json:"nickname" xorm:"not null default('') comment('昵称') VARCHAR(255)"`
  17. Username string `json:"username" xorm:"not null default('') comment('用户名') VARCHAR(255)"`
  18. Password string `json:"-" xorm:"not null default('') comment('密码') VARCHAR(255)"`
  19. Openid string `json:"open_id" xorm:"not null default('') comment('openid') VARCHAR(128)"`
  20. Token string `json:"token" xorm:"not null default('') comment('登陆凭证token') VARCHAR(255)"`
  21. Balance float64 `json:"balance" xorm:"not null default(0.00) comment('余额') DECIMAL(18)"`
  22. SmsCode string `json:"sms_code" xorm:"not null default('') comment('短信验证码') VARCHAR(128)"`
  23. AreaId int64 `json:"area_id" xorm:"not null default(0) comment('地区id') INT(11)"` // 子账号的地区
  24. ActivityId int64 `json:"activity_id" xrom:"not null default(0) comment('主活动id') INT(11)"`
  25. HeadImg string `json:"head_img" xorm:"not null default('') comment('头像') VARCHAR(255)"`
  26. Email string `json:"email" xorm:"not null default('') comment('邮箱') VARCHAR(128)"`
  27. Phone string `json:"phone" xorm:"not null default('') comment('电话号码') VARCHAR(128)"`
  28. QqOpenid string `json:"qq_openid" xorm:"not null default('') comment('qq openid') VARCHAR(255)"`
  29. Tag string `json:"tag" xorm:"-" description:"tag ws过滤信息"`
  30. Pid int64 `json:"pid" xorm:"not null default(0) comment('上级账号,该值为空时不允许登陆web客户端') INT(11)"` // 可能判断是否为子账号h
  31. RoleId int64 `json:"role_id" xorm:"not null default(4) comment('1超级管理员|2平台管理员|3普通管理员|4代理会员|5渠道会员|6普通会员') INT(11)"`
  32. TopId int64 `json:"top_id" xorm:"not null default(0) comment('角色的上级id') INT(11)"`
  33. IsDelete bool `json:"-" xorm:"not null default(0) comment('软删除') TINYINT(1)"`
  34. CreatedAt time.Time `json:"-" xorm:"not null created comment('创建时间') DATETIME"`
  35. UpdatedAt time.Time `json:"-" xorm:"not null updated comment('更新时间') DATETIME"`
  36. }
  37. func (t *Customer) TableName() string {
  38. return CustomerTN
  39. }
  40. //根据账号和密码验证用户
  41. func (t *Customer) Author(name, pwd string) error {
  42. exist, err := core.GetXormAuto().Where("(phone=? or email=?) and role_id=? and is_delete=0",
  43. name, name, 6).Get(t)
  44. if err != nil {
  45. logger.Error("验证用户失败",
  46. zap.Error(err),
  47. zap.String("name", name),
  48. zap.String("pwd", pwd))
  49. return errors.WithStack(err)
  50. }
  51. if !exist {
  52. return errors.New("用户名错误,请重新输入")
  53. }
  54. if t.Pid == 0 {
  55. pwd = helper.Md5(fmt.Sprintf("hdzj==%s", pwd))
  56. }
  57. if t.Password != pwd {
  58. return errors.New("密码错误,请重新输入")
  59. }
  60. return nil
  61. }
  62. func (t *Customer) GetByOpenid(openid string) (bool, error) {
  63. return core.GetXormAuto().Where("is_delete=0 and openid=?", openid).Get(t)
  64. }
  65. func (t *Customer) GetByQQOpenid(openid string) (bool, error) {
  66. return core.GetXormAuto().Where("is_delete=0 and qq_openid=?", openid).Get(t)
  67. }
  68. func (t *Customer) GetByActivityIdAndAreaId(activityId, areaId interface{}) (bool, error) {
  69. return core.GetXormAuto().Where("is_delete=0 and activity_id=? and area_id=?", activityId, areaId).Get(t)
  70. }