email.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package english_report_email
  2. import (
  3. "hongze/hongze_yb_en_api/global"
  4. "hongze/hongze_yb_en_api/models/base"
  5. "time"
  6. )
  7. // 英文研报-邮箱
  8. type Email struct {
  9. Id uint `gorm:"primaryKey;column:id" json:"id"`
  10. CompanyId uint `gorm:"column:company_id" json:"company_id"` //客户ID
  11. Name string `gorm:"column:name" json:"name"` //客户名称
  12. CompanyName string `gorm:"column:company_name" json:"company_name"` //公司名称
  13. Email string `gorm:"column:email" json:"email"` //邮箱地址
  14. ViewTotal uint `gorm:"column:view_total" json:"view_total"` //累计点击量/阅读量
  15. LastViewTime time.Time `gorm:"column:last_view_time" json:"last_view_time"` //最后阅读时间
  16. RegisterTime time.Time `gorm:"column:register_time" json:"register_time"` //注册时间
  17. IsDeleted uint8 `gorm:"column:is_deleted" json:"is_deleted"` //删除状态:0-正常;1-已删除
  18. AdminId uint `gorm:"column:admin_id" json:"admin_id"` //创建人ID
  19. AdminName string `gorm:"column:admin_name" json:"admin_name"` //创建人名称
  20. Enable int `gorm:"column:enabled" json:"enabled"`
  21. Status int `description:"1:正式,2:临时,3:终止"`
  22. Password string `gorm:"column:password" json:"password"`
  23. Mobile string `gorm:"column:mobile" json:"mobile"`
  24. CountryCode string `gorm:"column:country_code" json:"country_code"` //国家代码
  25. base.TimeBase
  26. }
  27. // TableName get sql table name.获取数据库表名
  28. func (e *Email) TableName() string {
  29. return "english_report_email"
  30. }
  31. // Add 新增
  32. func (e *Email) Add() (err error) {
  33. err = global.MYSQL["rddp"].Create(e).Error
  34. return
  35. }
  36. // 修改
  37. func (e *Email) Update(updateCols []string) (err error) {
  38. err = global.MYSQL["rddp"].Model(e).Select(updateCols).Updates(e).Error
  39. return
  40. }
  41. func (e *Email) GetById(id int) (item *Email, err error) {
  42. err = global.MYSQL["rddp"].Model(e).Where("is_deleted = 0 AND id= ?", id).First(&item).Error
  43. return
  44. }
  45. func (e *Email) UpdateViewTotalById(Id uint) (err error) {
  46. sql := `UPDATE english_report_email SET view_total = view_total+1, last_view_time = NOW() WHERE id = ? `
  47. err = global.MYSQL["rddp"].Exec(sql, Id).Error
  48. return
  49. }
  50. func CheckUserPwd(loginType int, countryCode, account, password string) (item *Email, err error) {
  51. sql := ``
  52. if loginType == 1 {
  53. sql = `SELECT * FROM english_report_email WHERE email=? AND password=? AND is_deleted = 0 `
  54. err = global.MYSQL["rddp"].Raw(sql, account, password).Scan(&item).Error
  55. } else {
  56. sql = `SELECT * FROM english_report_email WHERE country_code = ? AND mobile=? AND password=? AND is_deleted = 0 `
  57. err = global.MYSQL["rddp"].Raw(sql, countryCode, account, password).Scan(&item).Error
  58. }
  59. return
  60. }
  61. func CheckUser(email string) (item *Email, err error) {
  62. sql := `SELECT * FROM english_report_email WHERE email=? AND is_deleted = 0 `
  63. err = global.MYSQL["rddp"].Raw(sql, email).First(&item).Error
  64. return
  65. }
  66. func (e *Email) GetByEmail(email string) (item *Email, err error) {
  67. err = global.MYSQL["rddp"].Model(e).Where("email = ? AND is_deleted = 0 ", email).First(&item).Error
  68. return
  69. }
  70. func (e *Email) GetByMobile(mobile, countryCode string) (item *Email, err error) {
  71. err = global.MYSQL["rddp"].Model(e).Where("mobile = ? AND country_code = ? AND is_deleted = 0 ", mobile, countryCode).First(&item).Error
  72. return
  73. }