activity_ask_email.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/models/system"
  5. )
  6. type AskEmailRep struct {
  7. Name string `description:"姓名"`
  8. Email string `description:"邮箱"`
  9. Mobile string `description:"手机号"`
  10. ChartPermissionName string `description:"权限名称"`
  11. AdminId int
  12. }
  13. func GetAskEmail() (item []*AskEmailRep, err error) {
  14. o := orm.NewOrmUsingDB("hz_cygx")
  15. sql := `SELECT * FROM cygx_activity_ask_email`
  16. _, err = o.Raw(sql).QueryRows(&item)
  17. return
  18. }
  19. // 判断研究员是不是策略行业的
  20. func GetAskEmailCountByCelue(adminId string) (count int, err error) {
  21. o := orm.NewOrmUsingDB("hz_cygx")
  22. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_ask_email WHERE chart_permission_name = '策略' AND admin_id IN (` + adminId + `) `
  23. err = o.Raw(sqlCount).QueryRow(&count)
  24. return
  25. }
  26. func GetAskEmailListByAdminIds(adminId string) (item []*AskEmailRep, err error) {
  27. o := orm.NewOrmUsingDB("hz_cygx")
  28. sql := `SELECT * FROM cygx_activity_ask_email WHERE chart_permission_name != '' AND admin_id IN (` + adminId + `) `
  29. _, err = o.Raw(sql).QueryRows(&item)
  30. return
  31. }
  32. func GetAskEmailList() (item []*AskEmailRep, err error) {
  33. o := orm.NewOrmUsingDB("hz_cygx")
  34. sql := `SELECT * FROM cygx_activity_ask_email WHERE chart_permission_name != '' ORDER BY sort DESC`
  35. _, err = o.Raw(sql).QueryRows(&item)
  36. return
  37. }
  38. // 权益自定义派点信息
  39. func GetAskEmailListPoint() (item []*AskEmailRep, err error) {
  40. o := orm.NewOrmUsingDB("hz_cygx")
  41. sql := `SELECT * FROM cygx_activity_ask_email WHERE chart_permission_name != '' AND enabled_point = 1 AND admin_id > 0 ORDER BY sort DESC , id ASC `
  42. _, err = o.Raw(sql).QueryRows(&item)
  43. return
  44. }
  45. // 权益自定义研究员信息
  46. func GetAskEmailListResearcher() (item []*AskEmailRep, err error) {
  47. o := orm.NewOrmUsingDB("hz_cygx")
  48. sql := `SELECT * FROM cygx_activity_ask_email WHERE chart_permission_name != '' AND enabled_researcher = 1 AND admin_id > 0 ORDER BY sort DESC , id ASC `
  49. _, err = o.Raw(sql).QueryRows(&item)
  50. return
  51. }
  52. func UpdateAskEmail(item *AskEmailRep) (err error) {
  53. o := orm.NewOrmUsingDB("hz_cygx")
  54. sql := `UPDATE cygx_activity_ask_email SET admin_id=? where mobile=?`
  55. _, err = o.Raw(sql, item.AdminId, item.Mobile).Exec()
  56. return
  57. }
  58. func InitSyncActivityAskEmailAdminId() {
  59. list, err := GetAskEmailList()
  60. if err != nil {
  61. return
  62. }
  63. sysUserList, err := system.GetAdminList()
  64. if err != nil {
  65. return
  66. }
  67. adminMap := make(map[string]*system.Admin, 0)
  68. for _, v := range sysUserList {
  69. adminMap[v.Mobile] = v
  70. }
  71. for _, v := range list {
  72. if admin, ok := adminMap[v.Mobile]; ok {
  73. v.AdminId = admin.AdminId
  74. err = UpdateAskEmail(v)
  75. if err != nil {
  76. return
  77. }
  78. }
  79. }
  80. }