config.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/services"
  6. "strings"
  7. "time"
  8. )
  9. type ConfigController struct {
  10. BaseAuthController
  11. }
  12. type BaseConfigController struct {
  13. BaseCommonController
  14. }
  15. // @Title 获取搜索推荐词
  16. // @Description 获取搜索推荐词
  17. // @Success 200 {object} models.ConfigResp
  18. // @router /detail [get]
  19. func (this *ConfigController) BrowseHistoryList() {
  20. br := new(models.BaseResponse).Init()
  21. defer func() {
  22. this.Data["json"] = br
  23. this.ServeJSON()
  24. }()
  25. resp := new(models.ConfigResp)
  26. detail := new(models.CygxConfig)
  27. //configCode := "hot_search"
  28. //detail, err := models.GetConfigByCode(configCode)
  29. hotSearch, err := models.GetHotSearch()
  30. if err != nil {
  31. br.Msg = "获取数据失败"
  32. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  33. return
  34. }
  35. chartList, err := models.GetChartListConfig()
  36. if err != nil {
  37. br.Msg = "获取信息失败"
  38. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  39. return
  40. }
  41. for _, v := range chartList {
  42. item := new(models.KeyWord)
  43. item.KeyWord = v.Title
  44. resp.List = append(resp.List, item)
  45. }
  46. var condition string
  47. var pars []interface{}
  48. currentTime := time.Now()
  49. starTime := currentTime.AddDate(0, 0, -8).Format("2006-01-02") + " 00:00:00"
  50. endTime := currentTime.AddDate(0, 0, -1).Format("2006-01-02") + " 23:59:59"
  51. condition += ` AND create_time < ` + "'" + endTime + "'" + `AND create_time > ` + "'" + starTime + "'"
  52. hotList, err := models.GetSearchKeyWordTop(condition, pars)
  53. if err != nil {
  54. br.Msg = "获取信息失败"
  55. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  56. return
  57. }
  58. for _, v := range hotList {
  59. item := new(models.KeyWord)
  60. item.KeyWord = v.KeyWord
  61. resp.ListHot = append(resp.ListHot, item)
  62. }
  63. detail.ConfigValue = hotSearch
  64. resp.Item = detail
  65. br.Msg = "获取成功!"
  66. br.Ret = 200
  67. br.Success = true
  68. br.Data = resp
  69. }
  70. // @Title 页面访问统计
  71. // @Description 上传页面访问统计
  72. // @Param request body models.CygxPageHistoryRecordRep true "type json string"
  73. // @Success Ret=200 新增成功
  74. // @router /pageHistory [post]
  75. func (this *ConfigController) PageHistory() {
  76. br := new(models.BaseResponse).Init()
  77. defer func() {
  78. this.Data["json"] = br
  79. this.ServeJSON()
  80. }()
  81. user := this.User
  82. if user == nil {
  83. br.Msg = "请登录"
  84. br.ErrMsg = "请登录,SysUser Is Empty"
  85. br.Ret = 408
  86. return
  87. }
  88. var req models.CygxPageHistoryRecordRep
  89. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  90. if err != nil {
  91. br.Msg = "参数解析异常!"
  92. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  93. return
  94. }
  95. pageType := req.PageType
  96. var havePageType bool
  97. PageType := []string{"Summary", "SummarySearch", "Report", "ReportSearch", "IndustryList", "Activit", "ActivitSearch", "ActivitParticulars", "ReportParticulars", "MySchedule", "LabelMore", "ArticleCopy"}
  98. for _, v := range PageType {
  99. if pageType == v {
  100. havePageType = true
  101. }
  102. }
  103. if !havePageType {
  104. br.Msg = "新增失败"
  105. br.ErrMsg = "PageType参数类型错误:" + pageType
  106. return
  107. }
  108. item := new(models.CygxPageHistoryRecord)
  109. item.UserId = user.UserId
  110. item.CreateTime = time.Now()
  111. item.Mobile = user.Mobile
  112. item.Email = user.Email
  113. item.CompanyId = user.CompanyId
  114. item.CompanyName = user.CompanyName
  115. item.DetailId = req.DetailId
  116. item.ChartPermissionId = req.ChartPermissionId
  117. item.IndustrialManagementId = req.IndustrialManagementId
  118. item.PageType = req.PageType
  119. _, err = models.AddCygxPageHistoryRecord(item)
  120. if err != nil {
  121. br.Msg = "新增访问记录失败"
  122. br.ErrMsg = "新增访问记录失败,Err:" + err.Error()
  123. return
  124. }
  125. br.Ret = 200
  126. br.Success = true
  127. br.Msg = "新增成功"
  128. }
  129. // @Title 获取研选说明
  130. // @Description 获取研选说明接口
  131. // @Success 200 {object} models.ConfigResp
  132. // @router /descriptionOfResearch [get]
  133. func (this *ConfigController) DescriptionOfResearch() {
  134. br := new(models.BaseResponse).Init()
  135. defer func() {
  136. this.Data["json"] = br
  137. this.ServeJSON()
  138. }()
  139. configCode := "description_of_research"
  140. detail, err := models.GetConfigByCode(configCode)
  141. if err != nil {
  142. br.Msg = "获取数据失败"
  143. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  144. return
  145. }
  146. resp := new(models.ConfigResp)
  147. resp.Item = detail
  148. br.Msg = "获取成功!"
  149. br.Ret = 200
  150. br.Success = true
  151. br.Data = resp
  152. }
  153. // @Title 获取搜索推荐词(无需token)
  154. // @Description 获取搜索推荐词(无需token)
  155. // @Success 200 {object} models.ConfigResp
  156. // @router /detailPublic [get]
  157. func (this *BaseConfigController) HotDetail() {
  158. br := new(models.BaseResponse).Init()
  159. defer func() {
  160. this.Data["json"] = br
  161. this.ServeJSON()
  162. }()
  163. detail := new(models.CygxConfig)
  164. hotSearch, err := models.GetHotSearch()
  165. if err != nil {
  166. br.Msg = "获取数据失败"
  167. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  168. return
  169. }
  170. detail.ConfigValue = hotSearch
  171. resp := new(models.ConfigResp)
  172. resp.Item = detail
  173. br.Msg = "获取成功!"
  174. br.Ret = 200
  175. br.Success = true
  176. br.Data = resp
  177. }
  178. // @Title 用户搜索记录统计
  179. // @Description 用户搜索记录统计
  180. // @Param KeyWord query string false "搜索关键词"
  181. // @Success Ret=200 新增成功
  182. // @router /user/search/keyWordLog [post]
  183. func (this *ConfigController) KeyWordLog() {
  184. br := new(models.BaseResponse).Init()
  185. defer func() {
  186. this.Data["json"] = br
  187. this.ServeJSON()
  188. }()
  189. var req models.CygxSearchKeyWordLogRep
  190. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  191. if err != nil {
  192. br.Msg = "参数解析异常!"
  193. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  194. return
  195. }
  196. keyWord := req.KeyWord
  197. if keyWord == "" {
  198. br.Msg = "搜索内容不能为空"
  199. return
  200. }
  201. user := this.User
  202. if user == nil {
  203. br.Msg = "请登录"
  204. br.ErrMsg = "请登录,SysUser Is Empty"
  205. br.Ret = 408
  206. return
  207. }
  208. if keyWord != "" {
  209. go services.AddUserSearchLog(user, keyWord, 1)
  210. }
  211. br.Ret = 200
  212. br.Success = true
  213. br.Msg = "新增成功"
  214. }
  215. // @Title 关于我们浏览记录
  216. // @Description 关于我们浏览记录接口
  217. // @Success 200
  218. // @router /aboutUs/addHistory [post]
  219. func (this *ConfigController) AboutUsAdd() {
  220. br := new(models.BaseResponse).Init()
  221. defer func() {
  222. this.Data["json"] = br
  223. this.ServeJSON()
  224. }()
  225. user := this.User
  226. if user == nil {
  227. br.Msg = "请重新登录"
  228. br.Ret = 408
  229. return
  230. }
  231. go services.AddCygxAboutUsVideoHistory(user)
  232. br.Ret = 200
  233. br.Success = true
  234. br.Msg = "操作成功!"
  235. }
  236. // @Title 买方研选产品介绍(无需token)
  237. // @Description 买方研选产品介绍接口(无需token)
  238. // @Success 200 {object} models.ConfigImgListResp
  239. // @router /research/introduce [get]
  240. func (this *BaseConfigController) ResearchIntroduce() {
  241. br := new(models.BaseResponse).Init()
  242. defer func() {
  243. this.Data["json"] = br
  244. this.ServeJSON()
  245. }()
  246. conf, err := models.GetConfigByCode("research_introduce_img_url")
  247. if err != nil {
  248. br.Msg = "获取数据失败"
  249. br.ErrMsg = "买方研选产品介绍信息失败,Err:" + err.Error()
  250. return
  251. }
  252. if conf.ConfigValue == "" {
  253. br.Msg = "获取失败"
  254. br.ErrMsg = "买方研选产品介绍信息失败"
  255. return
  256. }
  257. list := new(*models.ConfigImgListResp)
  258. if err = json.Unmarshal([]byte(conf.ConfigValue), &list); err != nil {
  259. br.Msg = "获取失败"
  260. br.ErrMsg = "买方研选产品介绍信配置值解析失败, Err: " + err.Error()
  261. return
  262. }
  263. br.Msg = "获取成功!"
  264. br.Ret = 200
  265. br.Success = true
  266. br.Data = list
  267. }
  268. // @Title 买方研选报价单(无需token)
  269. // @Description 买方研选报价单(无需token)
  270. // @Success 200 {object} models.ConfigImgListResp
  271. // @router /research/quotation [get]
  272. func (this *BaseConfigController) ResearchQuotation() {
  273. br := new(models.BaseResponse).Init()
  274. defer func() {
  275. this.Data["json"] = br
  276. this.ServeJSON()
  277. }()
  278. conf, err := models.GetConfigByCode("research_quotation_img_url")
  279. if err != nil {
  280. br.Msg = "获取数据失败"
  281. br.ErrMsg = "买方研选产品介绍信息失败,Err:" + err.Error()
  282. return
  283. }
  284. if conf.ConfigValue == "" {
  285. br.Msg = "获取失败"
  286. br.ErrMsg = "买方研选产品介绍信息失败"
  287. return
  288. }
  289. list := new(*models.ConfigImgListResp)
  290. if err = json.Unmarshal([]byte(conf.ConfigValue), &list); err != nil {
  291. br.Msg = "获取失败"
  292. br.ErrMsg = "买方研选产品介绍信配置值解析失败, Err: " + err.Error()
  293. return
  294. }
  295. br.Msg = "获取成功!"
  296. br.Ret = 200
  297. br.Success = true
  298. br.Data = list
  299. }
  300. // @Title 买方研选升级新资源海报(无需token)
  301. // @Description 买方研选升级新资源海报(无需token)
  302. // @Success 200 {object} models.ConfigImgListResp
  303. // @router /research/hb [get]
  304. func (this *BaseConfigController) ResearchHb() {
  305. br := new(models.BaseResponse).Init()
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. detail, err := models.GetConfigByCode("research_hb_img_url")
  311. if err != nil {
  312. br.Msg = "获取数据失败"
  313. br.ErrMsg = "买方研选升级新资源海报信息失败,Err:" + err.Error()
  314. return
  315. }
  316. resp := new(models.ConfigImgHbResp)
  317. list := strings.Split(detail.ConfigValue, "{|}")
  318. if len(list) == 0 {
  319. list = make([]string, 0)
  320. }
  321. resp.HbImg = list[0]
  322. resp.ButtonImg = list[len(list)-1]
  323. br.Msg = "获取成功!"
  324. br.Ret = 200
  325. br.Success = true
  326. br.Data = resp
  327. }