questionnaire.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. package eta_trial
  2. import (
  3. "encoding/json"
  4. "eta/eta_api/models"
  5. "eta/eta_api/models/eta_trial"
  6. etaTrialService "eta/eta_api/services/eta_trial"
  7. "eta/eta_api/utils"
  8. "time"
  9. )
  10. // QuestionnairePopUp
  11. // @Title 获取问卷调查弹窗信息
  12. // @Description 获取问卷调查弹窗信息
  13. // @Success 200 {object} response.TryOutCompanyListResp
  14. // @router /questionnaire/popup [get]
  15. func (this *EtaTrialController) QuestionnairePopUp() {
  16. br := new(models.BaseResponse).Init()
  17. defer func() {
  18. if br.ErrMsg == "" {
  19. br.IsSendEmail = false
  20. }
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. sysUser := this.SysUser
  25. if sysUser == nil {
  26. br.Msg = "请登录"
  27. br.ErrMsg = "请登录,SysUser Is Empty"
  28. br.Ret = 408
  29. return
  30. }
  31. // 仅试用平台用
  32. if utils.BusinessCode != utils.BusinessCodeSandbox {
  33. br.Ret = 200
  34. br.Success = true
  35. br.Msg = "获取成功"
  36. return
  37. }
  38. var resp eta_trial.QuestionnairePopupResp
  39. var userReq etaTrialService.GetEtaTrialUserReq
  40. userReq.Mobile = sysUser.Mobile
  41. item, e := etaTrialService.GetEtaTrialUser(userReq)
  42. if e != nil {
  43. br.Msg = "获取失败"
  44. br.ErrMsg = "获取ETA试用客户失败, GetEtaTrialUser Err:" + e.Error()
  45. return
  46. }
  47. if item.EtaTrialId <= 0 {
  48. br.Ret = 200
  49. br.Success = true
  50. br.Msg = "获取成功"
  51. return
  52. }
  53. fillItem, e := eta_trial.GetQuestionnaireFillRecordCountByMobile(sysUser.Mobile)
  54. if e != nil && e.Error() != utils.ErrNoRow() {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取数据失败失败,GetQuestionnaireFillRecordCountByMobile Err:" + e.Error()
  57. return
  58. }
  59. if fillItem == nil {
  60. //没填过
  61. if item.ModifyTime.AddDate(0, 0, 6).Before(time.Now()) {
  62. //弹窗
  63. resp.IsPopup = 1
  64. }
  65. } else {
  66. //填过,判断是否超过了14天
  67. if fillItem.IsFill == 2 && fillItem.CreateTime.AddDate(0, 0, 13).Before(time.Now()) {
  68. //弹窗
  69. resp.IsPopup = 1
  70. } else if fillItem.IsFill == 1 {
  71. //显示图标但不弹窗
  72. resp.IsShow = 1
  73. }
  74. }
  75. questionnaireList, e := etaTrialService.GetEtaTrialQuestionnaireList()
  76. if e != nil {
  77. br.Msg = "获取失败"
  78. br.ErrMsg = "获取问卷调查列表失败, GetEtaTrialQuestionnaireList Err: " + e.Error()
  79. return
  80. }
  81. resp.Question = questionnaireList
  82. br.Data = resp
  83. br.Ret = 200
  84. br.Success = true
  85. br.Msg = "获取成功"
  86. }
  87. // QuestionnaireCommit
  88. // @Title 提交问卷
  89. // @Description 提交问卷
  90. // @Success 200 {object} response.TryOutCompanyListResp
  91. // @router /questionnaire/commit [post]
  92. func (this *EtaTrialController) QuestionnaireCommit() {
  93. br := new(models.BaseResponse).Init()
  94. defer func() {
  95. this.Data["json"] = br
  96. this.ServeJSON()
  97. }()
  98. sysUser := this.SysUser
  99. if sysUser == nil {
  100. br.Msg = "请登录"
  101. br.ErrMsg = "请登录,SysUser Is Empty"
  102. br.Ret = 408
  103. return
  104. }
  105. var req eta_trial.EtaTrialQuestionnaireReq
  106. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  107. if err != nil {
  108. br.Msg = "参数解析异常!"
  109. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  110. return
  111. }
  112. var userReq etaTrialService.GetEtaTrialUserReq
  113. userReq.Mobile = sysUser.Mobile
  114. admin, e := etaTrialService.GetEtaTrialUser(userReq)
  115. if e != nil {
  116. br.Msg = "操作失败"
  117. br.ErrMsg = "获取ETA试用客户失败, GetEtaTrialUser Err:" + e.Error()
  118. return
  119. }
  120. if admin.EtaTrialId <= 0 {
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "操作成功"
  124. return
  125. }
  126. if req.IsFill == 0 {
  127. // 稍后再填
  128. fillItem := &eta_trial.QuestionnaireFillRecord{
  129. Mobile: admin.Mobile,
  130. IsFill: 1,
  131. CreateTime: time.Now(),
  132. ModifyTime: time.Now(),
  133. }
  134. err := eta_trial.AddQuestionnaireFillRecord(fillItem)
  135. if err != nil {
  136. br.Msg = "新增填写记录失败"
  137. br.ErrMsg = "新增填写记录失败, Err:" + err.Error()
  138. return
  139. }
  140. } else {
  141. // 已填写
  142. list := make([]eta_trial.EtaTrialQuestionnaireRecord, 0)
  143. for _, q := range req.List {
  144. v := eta_trial.EtaTrialQuestionnaireRecord{
  145. UserName: admin.UserName,
  146. CompanyName: admin.CompanyName,
  147. Position: admin.Position,
  148. Options: q.Options,
  149. Mobile: admin.Mobile,
  150. Type: q.Type,
  151. QuestionnaireId: q.QuestionnaireId,
  152. CreateTime: time.Now(),
  153. }
  154. list = append(list, v)
  155. }
  156. var commitReq etaTrialService.EtaTrialQuestionnaireCommitReq
  157. commitReq.List = list
  158. commitRes, e := etaTrialService.EtaTrialQuestionnaireCommit(commitReq)
  159. if e != nil {
  160. br.Msg = "操作失败"
  161. br.ErrMsg = "新增问卷记录失败, EtaTrialQuestionnaireCommit Err: " + e.Error()
  162. return
  163. }
  164. if !commitRes {
  165. br.Msg = "操作失败"
  166. br.ErrMsg = "新增问卷记录失败" + e.Error()
  167. return
  168. }
  169. fillItem := &eta_trial.QuestionnaireFillRecord{
  170. Mobile: admin.Mobile,
  171. IsFill: 2,
  172. CreateTime: time.Now(),
  173. ModifyTime: time.Now(),
  174. }
  175. err := eta_trial.AddQuestionnaireFillRecord(fillItem)
  176. if err != nil {
  177. br.Msg = "新增填写记录失败"
  178. br.ErrMsg = "新增填写记录失败, Err:" + err.Error()
  179. return
  180. }
  181. }
  182. br.Ret = 200
  183. br.Success = true
  184. br.Msg = "提交成功"
  185. }