eta_trial.go 4.5 KB

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