互动
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.

95 lines
4.0 KiB

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