eta_trial.go 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. package crm
  2. import (
  3. "hongze/hz_crm_eta/global"
  4. "time"
  5. )
  6. // EtaTrial ETA试用
  7. type EtaTrial struct {
  8. EtaTrialId int `gorm:"primaryKey;column:eta_trial_id;type:int(11);not null" json:"eta_trial_id"`
  9. UserName string `gorm:"column:user_name;type:varchar(100);default:''" json:"user_name"`
  10. CompanyName string `gorm:"column:company_name;type:varchar(100);default:''" json:"company_name"`
  11. Position string `gorm:"column:position;type:varchar(100);default:''" json:"position"` // 职务
  12. Account string `gorm:"column:account;type:varchar(100);default:''" json:"account"` // 账号
  13. Password string `gorm:"column:password;type:varchar(100);default:''" json:"password"` // 账号
  14. Mobile string `gorm:"column:mobile;type:varchar(20)" json:"mobile"` // 手机号
  15. ActiveTime int `gorm:"column:active_time;type:int(11) unsigned;default:0" json:"active_time"` // 累计活跃时长
  16. IndexNum int `gorm:"column:index_num;type:int(11) unsigned;default:0" json:"index_num"` // 累计添加指标
  17. ChartNum int `gorm:"column:chart_num;type:int(11) unsigned;default:0" json:"chart_num"` // 累计添加图表
  18. LoginNum int `gorm:"column:login_num;type:int(11) unsigned;default:0" json:"login_num"` // 累计登录次数
  19. Enabled int `gorm:"column:enabled;type:tinyint(1);not null;default:1" json:"enabled"` // 1:有效,0:禁用
  20. LastLoginTime time.Time `gorm:"column:last_login_time;type:datetime" json:"last_login_time"` // 最后一次登陆时间
  21. CreateTime time.Time `gorm:"column:create_time;type:datetime" json:"create_time"` // 申请时间
  22. ModifyTime time.Time `gorm:"column:modify_time;type:datetime" json:"modify_time"` // 账号更新时间
  23. Seller string `gorm:"column:seller;type:varchar(200);default:''" json:"seller"` // 销售员
  24. SellerId int `gorm:"column:seller_id;type:bigint(20);default:0" json:"seller_id"` // 销售员id
  25. }
  26. type EtaTrialItem struct {
  27. EtaTrialId int `gorm:"primaryKey;column:eta_trial_id;type:int(11);not null"`
  28. UserName string `gorm:"column:user_name;type:varchar(100);default:''"`
  29. CompanyName string `gorm:"column:company_name;type:varchar(100);default:''"`
  30. Position string `gorm:"column:position;type:varchar(100);default:''"` // 职务
  31. Account string `gorm:"column:account;type:varchar(100);default:''"` // 账号
  32. Password string `gorm:"column:password;type:varchar(100);default:''"` // 账号
  33. Mobile string `gorm:"column:mobile;type:varchar(20)"` // 手机号
  34. ActiveTime int `gorm:"column:active_time;type:int(11) unsigned;default:0"` // 累计活跃时长
  35. IndexNum int `gorm:"column:index_num;type:int(11) unsigned;default:0"` // 累计添加指标
  36. ChartNum int `gorm:"column:chart_num;type:int(11) unsigned;default:0"` // 累计添加图表
  37. LoginNum int `gorm:"column:login_num;type:int(11) unsigned;default:0"` // 累计登录次数
  38. Enabled int `gorm:"column:enabled;type:tinyint(1);not null;default:1"` // 1:有效,0:禁用
  39. LastLoginTime time.Time `gorm:"column:last_login_time;type:datetime"` // 最后一次登陆时间
  40. CreateTime time.Time `gorm:"column:create_time;type:datetime"` // 申请时间
  41. ModifyTime time.Time `gorm:"column:modify_time;type:datetime"` // 账号更新时间
  42. Seller string `gorm:"column:seller;type:varchar(200);default:''"` // 销售员
  43. SellerId int `gorm:"column:seller_id;type:bigint(20);default:0"` // 销售员id
  44. }
  45. func (m *EtaTrial) TableName() string {
  46. return "eta_trial"
  47. }
  48. // Create 新增
  49. func (m *EtaTrial) Create() (err error) {
  50. err = global.MYSQL["hz_crm"].Create(m).Error
  51. return
  52. }
  53. // Update 更新
  54. func (m *EtaTrial) Update(cols []string) (err error) {
  55. err = global.MYSQL["hz_crm"].Model(m).Select(cols).Updates(m).Error
  56. return
  57. }
  58. // GetEtaTrialByMobile 手机号获取试用客户
  59. func GetEtaTrialByMobile(mobile string) (item *EtaTrialItem, err error) {
  60. err = global.MYSQL["hz_crm"].Model(EtaTrial{}).Where("mobile = ?", mobile).First(&item).Error
  61. return
  62. }
  63. // DisableEtaTrailByMobile 禁用客户
  64. func DisableEtaTrailByMobile(mobile string) (err error) {
  65. expTime := time.Now().AddDate(0, 0, -14)
  66. sql := `UPDATE eta_trial SET enabled = 0, modify_time = ? WHERE mobile = ?`
  67. err = global.MYSQL["hz_crm"].Exec(sql, expTime, mobile).Error
  68. return
  69. }
  70. // DeleteEtaTrialByMobile 删除客户
  71. func DeleteEtaTrialByMobile(mobile string) (err error) {
  72. sql := `DELETE FROM eta_trial WHERE mobile = ?`
  73. err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
  74. return
  75. }
  76. // UpdateEtaTrailActiveTime 更新用户累计活跃时间
  77. func UpdateEtaTrailActiveTime(activeTime int, mobile string) (err error) {
  78. sql := `UPDATE eta_trial SET active_time = active_time + ? WHERE mobile = ?`
  79. err = global.MYSQL["hz_crm"].Exec(sql, activeTime, mobile).Error
  80. return
  81. }
  82. // UpdateEtaTrialLoginByMobile 更新用户最后登录时间和次数
  83. func UpdateEtaTrialLoginByMobile(mobile string) (err error) {
  84. sql := `UPDATE eta_trial SET last_login_time = NOW(), login_num = login_num + 1 WHERE mobile = ?`
  85. err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
  86. return
  87. }
  88. // UpdateEtaTrialIndexNumByMobile 更新累计添加指标数
  89. func UpdateEtaTrialIndexNumByMobile(mobile string) (err error) {
  90. sql := `UPDATE eta_trial SET index_num = index_num + 1 WHERE mobile = ?`
  91. err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
  92. return
  93. }
  94. // UpdateEtaTrialChartNumByMobile 更新累计添加图表数
  95. func UpdateEtaTrialChartNumByMobile(mobile string) (err error) {
  96. sql := `UPDATE eta_trial SET chart_num = chart_num + 1 WHERE mobile = ?`
  97. err = global.MYSQL["hz_crm"].Exec(sql, mobile).Error
  98. return
  99. }
  100. // UpdateEtaTrialPositionByMobile 更新用户相关信息
  101. func UpdateEtaTrialPositionByMobile(realName, position, mobile string, enable int) (err error) {
  102. sql := ``
  103. // 禁用
  104. if enable == 0 {
  105. expTime := time.Now().AddDate(0, 0, -14)
  106. sql = `UPDATE eta_trial SET user_name = ?, position = ?, enabled = ?, modify_time = ? WHERE mobile = ?`
  107. err = global.MYSQL["hz_crm"].Exec(sql, realName, position, enable, expTime, mobile).Error
  108. return
  109. }
  110. // 启用
  111. sql = `UPDATE eta_trial SET user_name = ?, position = ?, enabled = ? WHERE mobile = ?`
  112. err = global.MYSQL["hz_crm"].Exec(sql, realName, position, enable, mobile).Error
  113. return
  114. }
  115. // UpdateEtaTrailLastLoginDuration 更新用户最后一次登录时长
  116. func UpdateEtaTrailLastLoginDuration(activeTime int, mobile string) (err error) {
  117. sql := `UPDATE eta_trial SET last_login_duration = ? WHERE mobile = ?`
  118. err = global.MYSQL["hz_crm"].Exec(sql, activeTime, mobile).Error
  119. return
  120. }