eta_trial.go 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package eta_trial
  2. import (
  3. "eta/eta_forum_admin/utils"
  4. "github.com/beego/beego/v2/client/orm"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. type EtaTrial struct {
  9. EtaTrialId int `orm:"column(eta_trial_id);pk" description:"eta试用客户id"`
  10. UserName string `description:"客户名称"`
  11. CompanyName string `description:"客户公司姓名"`
  12. Position string `description:"职位"`
  13. Password string `json:"-"`
  14. Account string `json:"-"`
  15. Mobile string `description:"手机号"`
  16. Enabled int `description:"1:有效,0:禁用"`
  17. ActiveTime int `description:"累计活跃时长"`
  18. LastLoginTime time.Time `description:"最后一次登陆时间"`
  19. SellerId int `description:"销售id"`
  20. Seller string `description:"销售员名称"`
  21. CreateTime time.Time
  22. ModifyTime time.Time
  23. LastLoginDuration int `description:"最后一次登录时长"`
  24. }
  25. type TrialAccountTransferReq struct {
  26. EtaTrialIdList []int `description:"转移使用用户id列表"`
  27. CurrentSellerId int `description:"转移后员工id"`
  28. CurrentSellerName string `description:"转移后员工名称"`
  29. IsCheckAll bool `description:"是否全选"`
  30. }
  31. // Update 更新用户基础信息
  32. func (item *EtaTrial) Update(cols []string) (err error) {
  33. o := orm.NewOrm()
  34. _, err = o.Update(item, cols...)
  35. return
  36. }
  37. func GetETATrialList(condition, sortStr string, pars []interface{}, startSize, pageSize int) (items []*ETATrialListRespItem, err error) {
  38. sql := `SELECT * FROM eta_trial WHERE 1=1 `
  39. if sortStr == "" {
  40. sortStr = "ORDER BY create_time DESC "
  41. }
  42. if condition != "" {
  43. sql += condition
  44. }
  45. sql += sortStr + ` LIMIT ?,? `
  46. o := orm.NewOrm()
  47. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  48. return
  49. }
  50. func GetETATrialListCount(condition string, pars []interface{}) (count int, err error) {
  51. sql := `SELECT COUNT(1) AS count FROM eta_trial WHERE 1 = 1 `
  52. o := orm.NewOrm()
  53. if condition != "" {
  54. sql += condition
  55. }
  56. err = o.Raw(sql, pars).QueryRow(&count)
  57. return
  58. }
  59. type ETATrialListRespItem struct {
  60. EtaTrialId int `orm:"column(eta_trial_id);pk" description:"eta试用客户id"`
  61. UserName string `description:"客户名称"`
  62. CompanyName string `description:"客户公司姓名"`
  63. Position string `description:"职位"`
  64. Mobile string `description:"手机号"`
  65. ActiveTime string `description:"累计活跃时长"`
  66. LastLoginTime string `description:"最后一次登陆时间"`
  67. SellerId int `description:"销售id"`
  68. Seller string `description:"销售员名称"`
  69. InterestModule string `description:"感兴趣模块"`
  70. Expiration int `description:"账号到期时长"`
  71. Enabled int `description:"1:有效,0:禁用"`
  72. IndexNum int `description:"累计添加指标"`
  73. ChartNum int `description:"累计添加图表"`
  74. LoginNum int `description:"累计登录次数"`
  75. Password string
  76. Account string
  77. CreateTime string
  78. ModifyTime string
  79. LastLoginDuration string `description:"最后一次登录时长"`
  80. }
  81. type ETATrialListRespList struct {
  82. List []*ETATrialListRespItem
  83. Paging *paging.PagingItem
  84. ApprovalNum int
  85. }
  86. type ETATrialAddItem struct {
  87. UserName string `description:"客户名称"`
  88. CompanyName string `description:"客户公司姓名"`
  89. Position string `description:"职位"`
  90. Mobile string `description:"手机号"`
  91. }
  92. type ETATrialAddReq struct {
  93. List []ETATrialAddItem
  94. }
  95. func GetETATrialByMobile(mobile string) (item *EtaTrial, err error) {
  96. sql := `SELECT * FROM eta_trial WHERE mobile = ? `
  97. o := orm.NewOrm()
  98. err = o.Raw(sql, mobile).QueryRow(&item)
  99. return
  100. }
  101. // 新增客户
  102. func AddETATrial(item *EtaTrial) (lastId int64, err error) {
  103. o := orm.NewOrm()
  104. lastId, err = o.Insert(item)
  105. return
  106. }
  107. func GetETATrialByAccount(account string) (items []*EtaTrial, err error) {
  108. sql := `SELECT * FROM eta_trial WHERE account LIKE '%` + account + `%' `
  109. o := orm.NewOrm()
  110. _, err = o.Raw(sql).QueryRows(&items)
  111. return
  112. }
  113. func UpdateETATrialEnable(mobile string) (err error) {
  114. o := orm.NewOrm()
  115. sql := `UPDATE eta_trial SET enabled=1,modify_time=NOW()
  116. WHERE mobile=? `
  117. _, err = o.Raw(sql, mobile).Exec()
  118. return
  119. }
  120. // TransferETATrial 转移试用用户跟进销售人员
  121. func TransferETATrial(item *TrialAccountTransferReq) (err error) {
  122. o := orm.NewOrm()
  123. sql := `UPDATE eta_trial SET seller=?,seller_id=?,modify_time=NOW() WHERE 1 = 1 `
  124. var condition string
  125. var params []interface{}
  126. if item.IsCheckAll {
  127. if len(item.EtaTrialIdList) > 0 {
  128. condition = ` AND eta_trial_id not IN (` + utils.GetOrmInReplace(len(item.EtaTrialIdList)) + `)`
  129. for _, id := range item.EtaTrialIdList {
  130. params = append(params, id)
  131. }
  132. }
  133. } else {
  134. condition = ` AND eta_trial_id IN (` + utils.GetOrmInReplace(len(item.EtaTrialIdList)) + `)`
  135. for _, id := range item.EtaTrialIdList {
  136. params = append(params, id)
  137. }
  138. }
  139. sql += condition
  140. params = append([]interface{}{item.CurrentSellerName, item.CurrentSellerId}, params...)
  141. _, err = o.Raw(sql, params...).Exec()
  142. return
  143. }
  144. func GetETATrialByCondition(condition string, pars []interface{}) (item []*EtaTrial, err error) {
  145. o := orm.NewOrm()
  146. sql := `SELECT * FROM eta_trial WHERE 1=1 `
  147. sql += condition
  148. _, err = o.Raw(sql, pars...).QueryRows(&item)
  149. if err != nil {
  150. return nil, err
  151. }
  152. return item, nil
  153. }