xzs_choose_send.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxXzsChooseSend struct {
  7. Id int `orm:"column(id);pk"`
  8. UserId int `description:"用户ID"`
  9. Mobile string `description:"手机号"`
  10. Email string `description:"邮箱"`
  11. CompanyId int `description:"公司id"`
  12. CompanyName string `description:"公司名称"`
  13. RealName string `description:"用户实际名称"`
  14. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  15. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  16. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  17. CreateTime time.Time `description:"创建时间"`
  18. ModifyTime time.Time `description:"更新时间"`
  19. }
  20. type CygxXzsChooseSendResp struct {
  21. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  22. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  23. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  24. List []*ChartPermissionResp
  25. }
  26. type SubmitChooseSendResp struct {
  27. IsRefuse int `description:"是否拒绝推送,0否、1是 如果为1 则不做任何推送"`
  28. IsSubjective int `description:"是否选择主观推送, 1 是 、 0否"`
  29. IsObjective int `description:"是否选择客观推送, 1 是 、 0否"`
  30. IndustrialManagementIds string `description:"产业ID,多个用, 隔开"`
  31. }
  32. //添加
  33. func AddCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow) (err error) {
  34. o, err := orm.NewOrm().Begin()
  35. if err != nil {
  36. return
  37. }
  38. defer func() {
  39. if err == nil {
  40. o.Commit()
  41. } else {
  42. o.Rollback()
  43. }
  44. }()
  45. //删除原有的关注记录
  46. sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
  47. _, err = o.Raw(sql, item.Mobile).Exec()
  48. //批量添加新的关注记录
  49. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  50. if err != nil {
  51. return err
  52. }
  53. //添加所勾选的消息类型
  54. _, err = o.Insert(item)
  55. return
  56. }
  57. //获取数量
  58. func GetXzsChooseSendCountByMobile(mobile string) (count int, err error) {
  59. sql := ` SELECT COUNT(1) AS count FROM cygx_xzs_choose_send WHERE mobile = ? `
  60. o := orm.NewOrm()
  61. err = o.Raw(sql, mobile).QueryRow(&count)
  62. return
  63. }
  64. //添加
  65. func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustryFllow) (err error) {
  66. o, err := orm.NewOrm().Begin()
  67. if err != nil {
  68. return
  69. }
  70. defer func() {
  71. if err == nil {
  72. o.Commit()
  73. } else {
  74. o.Rollback()
  75. }
  76. }()
  77. //删除原有的关注记录
  78. sql := `DELETE FROM cygx_industry_fllow WHERE mobile = ?`
  79. _, err = o.Raw(sql, item.Mobile).Exec()
  80. //批量添加新的关注记录
  81. _, err = o.InsertMulti(len(itemsFllow), itemsFllow)
  82. if err != nil {
  83. return err
  84. }
  85. //修改现有的类型
  86. updateParams := make(map[string]interface{})
  87. updateParams["UserId"] = item.UserId
  88. updateParams["Mobile"] = item.Mobile
  89. updateParams["Email"] = item.Email
  90. updateParams["CompanyId"] = item.CompanyId
  91. updateParams["CompanyName"] = item.CompanyName
  92. updateParams["RealName"] = item.RealName
  93. updateParams["ModifyTime"] = time.Now()
  94. updateParams["IsRefuse"] = item.IsRefuse
  95. updateParams["IsSubjective"] = item.IsSubjective
  96. updateParams["IsObjective"] = item.IsObjective
  97. whereParam := map[string]interface{}{"mobile": item.Mobile}
  98. err = UpdateByExpr(CygxXzsChooseSend{}, whereParam, updateParams)
  99. return
  100. }
  101. //根据用户openid获取token
  102. func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) {
  103. sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=? LIMIT 1 `
  104. o := orm.NewOrm()
  105. err = o.Raw(sql, mobile).QueryRow(&item)
  106. return
  107. }