questionnaire_vote.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type CygxQuestionnaireVote struct {
  7. QuestionnaireVoteId int `orm:"column(questionnaire_vote_id);pk"`
  8. QuestionnaireId int `description:"问卷ID"`
  9. QuestionnaireThemeId int `description:"问卷主题ID"`
  10. UserId int `description:"用户ID"`
  11. CreateTime time.Time
  12. Mobile string `description:"手机号"`
  13. Email string `description:"邮箱"`
  14. CompanyId int `description:"公司id"`
  15. CompanyName string `description:"公司名称"`
  16. ModifyTime time.Time `description:"修改时间"`
  17. RealName string `description:"用户实际名称"`
  18. SellerName string `description:"所属销售"`
  19. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  20. }
  21. type CygxQuestionnaireVoteOtherTheme struct {
  22. QuestionnaireVoteOtherThemeId int `orm:"column(questionnaire_vote_other_theme_id);pk"`
  23. QuestionnaireId int `description:"问卷ID"`
  24. UserId int `description:"用户ID"`
  25. CreateTime time.Time
  26. Mobile string `description:"手机号"`
  27. Email string `description:"邮箱"`
  28. CompanyId int `description:"公司id"`
  29. CompanyName string `description:"公司名称"`
  30. ModifyTime time.Time `description:"修改时间"`
  31. RealName string `description:"用户实际名称"`
  32. SellerName string `description:"所属销售"`
  33. Content string `description:"内容"`
  34. RegisterPlatform int `description:"来源 1小程序,2:网页"`
  35. }
  36. // 获取数量
  37. func GetCygxQuestionnaireVoteCount(condition string, pars []interface{}) (count int, err error) {
  38. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_questionnaire_vote as art WHERE 1= 1 `
  39. if condition != "" {
  40. sqlCount += condition
  41. }
  42. o := orm.NewOrm()
  43. err = o.Raw(sqlCount, pars).QueryRow(&count)
  44. return
  45. }
  46. type CygxQuestionnaireVoteReq struct {
  47. QuestionnaireId int `description:"问卷ID"`
  48. QuestionnaireThemeIds []int `description:"问卷主题ID"`
  49. Content string `description:"内容"`
  50. }
  51. // 添加
  52. func AddCygxQuestionnaireVote(voteItems []*CygxQuestionnaireVote, otherItem *CygxQuestionnaireVoteOtherTheme) (err error) {
  53. o := orm.NewOrm()
  54. to, err := o.Begin()
  55. if err != nil {
  56. return
  57. }
  58. defer func() {
  59. if err != nil {
  60. _ = to.Rollback()
  61. } else {
  62. _ = to.Commit()
  63. }
  64. }()
  65. //其它主题类型提交需要写入的信息
  66. if otherItem.Content != "" {
  67. _, err = to.Insert(otherItem)
  68. if err != nil {
  69. return
  70. }
  71. //更新其他主题投票数量
  72. sql := ` UPDATE cygx_questionnaire SET other_theme_total = other_theme_total +1 WHERE questionnaire_id = ? `
  73. _, err = o.Raw(sql, otherItem.QuestionnaireId).Exec()
  74. }
  75. //主题ID提交问卷需要写入的信息
  76. for _, v := range voteItems {
  77. _, err = to.Insert(v)
  78. if err != nil {
  79. return
  80. }
  81. }
  82. return
  83. }