public.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. package controller
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/gin-gonic/gin"
  7. "hongze/hongze_yb/controller/response"
  8. "hongze/hongze_yb/global"
  9. "hongze/hongze_yb/logic"
  10. "hongze/hongze_yb/models/request"
  11. respond "hongze/hongze_yb/models/response"
  12. "hongze/hongze_yb/models/tables/banner"
  13. "hongze/hongze_yb/models/tables/banner_view_history"
  14. "hongze/hongze_yb/models/tables/company"
  15. "hongze/hongze_yb/models/tables/wx_user"
  16. "hongze/hongze_yb/models/tables/yb_config"
  17. "hongze/hongze_yb/models/tables/yb_research_banner"
  18. "hongze/hongze_yb/models/tables/yb_research_signup_statistics"
  19. "hongze/hongze_yb/models/tables/yb_resource"
  20. "hongze/hongze_yb/models/tables/yb_suncode_pars"
  21. "hongze/hongze_yb/services"
  22. "hongze/hongze_yb/services/alarm_msg"
  23. "hongze/hongze_yb/services/user"
  24. "hongze/hongze_yb/services/wx_app"
  25. "hongze/hongze_yb/utils"
  26. "io/ioutil"
  27. "net/url"
  28. "os"
  29. "path"
  30. "strconv"
  31. "time"
  32. )
  33. // GetApplyVarietyList
  34. // @Tags 公共模块
  35. // @Summary 获取所有可以申请的品种权限列表
  36. // @Description 获取所有可以申请的品种权限列表
  37. // @Security ApiKeyAuth
  38. // @securityDefinitions.basic BasicAuth
  39. // @Param Authorization header string true "微信登录后获取到的token"
  40. // @Accept json
  41. // @Product json
  42. // @Success 200 {object} []logic.ApplyVariety "获取成功"
  43. // @failure 400 {string} string "获取失败"
  44. // @Router /public/get_apply_variety_list [get]
  45. func GetApplyVarietyList(c *gin.Context) {
  46. list, err := logic.GetApplyVarietyList()
  47. if err != nil {
  48. response.FailData("获取品种失败", "获取品种失败,Err:"+err.Error(), c)
  49. return
  50. }
  51. response.OkData("获取成功", list, c)
  52. }
  53. // Upload
  54. // @Tags 公共模块
  55. // @Summary 文件上传
  56. // @Description 文件上传
  57. // @Security ApiKeyAuth
  58. // @securityDefinitions.basic BasicAuth
  59. // @Param Authorization header string true "微信登录后获取到的token"
  60. // @Param file formData file false "操作描述"
  61. // @Accept multipart/form-data
  62. // @Product json
  63. // @Success 200 {object} string "上传成功"
  64. // @failure 400 {string} string "上传失败,存储目录创建失败"
  65. // @Router /public/upload [post]
  66. func Upload(c *gin.Context) {
  67. // 单文件
  68. file, err := c.FormFile("file")
  69. fmt.Println("file", file)
  70. if err != nil {
  71. response.FailData("获取资源失败", "获取资源失败,Err:"+err.Error(), c)
  72. return
  73. }
  74. ext := path.Ext(file.Filename)
  75. dateDir := time.Now().Format("20060102")
  76. uploadDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
  77. err = os.MkdirAll(uploadDir, 0766)
  78. if err != nil {
  79. response.FailData("存储目录创建失败", "存储目录创建失败,Err:"+err.Error(), c)
  80. return
  81. }
  82. randStr := utils.GetRandStringNoSpecialChar(28)
  83. fileName := randStr + ext
  84. fpath := uploadDir + "/" + fileName
  85. // 上传文件至指定目录
  86. err = c.SaveUploadedFile(file, fpath)
  87. if err != nil {
  88. response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
  89. return
  90. }
  91. defer func() {
  92. os.Remove(fpath)
  93. }()
  94. //上传到阿里云
  95. resourceUrl, err := services.UploadAliyun(fileName, fpath)
  96. if err != nil {
  97. response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
  98. return
  99. }
  100. response.OkData("文件上传成功", resourceUrl, c)
  101. }
  102. // GetSharePoster
  103. // @Tags 公共模块
  104. // @Summary 获取分享海报
  105. // @Description 获取分享海报
  106. // @Security ApiKeyAuth
  107. // @securityDefinitions.basic BasicAuth
  108. // @Param request body services.SharePosterReq true "type json string"
  109. // @Accept application/json
  110. // @Success 200 {object} string "获取成功"
  111. // @failure 400 {string} string "获取失败"
  112. // @Router /public/get_share_poster [post]
  113. func GetSharePoster(c *gin.Context) {
  114. var req services.SharePosterReq
  115. if c.ShouldBind(&req) != nil {
  116. response.Fail("参数异常", c)
  117. return
  118. }
  119. if req.Source == "" {
  120. response.Fail("来源有误", c)
  121. return
  122. }
  123. imgUrl, err := services.CreatePosterFromSourceV2(req.CodePage, req.CodeScene, req.Source, req.Version, req.Pars)
  124. if err != nil {
  125. response.FailData("获取分享海报失败", "获取分享海报失败, Err: "+err.Error(), c)
  126. return
  127. }
  128. response.OkData("获取成功", imgUrl, c)
  129. }
  130. // GetSuncodeScene 获取小程序太阳码scene值
  131. // @Tags 公共模块
  132. // @Summary 获取小程序太阳码scene值
  133. // @Description 获取小程序太阳码scene值
  134. // @Security ApiKeyAuth
  135. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  136. // @Param scene_key query string true "scene_key值"
  137. // @Success 200 {string} string "获取成功"
  138. // @failure 400 {string} string "获取失败"
  139. // @Router /public/get_suncode_scene [get]
  140. func GetSuncodeScene(c *gin.Context) {
  141. reqKey := c.DefaultQuery("scene_key", "")
  142. if reqKey == "" {
  143. response.Fail("参数有误", c)
  144. }
  145. pars, err := yb_suncode_pars.GetSceneByKey(reqKey)
  146. if err != nil && err != utils.ErrNoRow {
  147. response.FailMsg("获取失败", "GetSuncodeScene获取失败, Err: "+err.Error(), c)
  148. return
  149. }
  150. scene := ""
  151. if pars != nil {
  152. scene = pars.Scene
  153. }
  154. response.OkData("获取成功", scene, c)
  155. }
  156. // GetVarietyTagTree 标签树
  157. // @Tags 公共模块
  158. // @Summary 标签树
  159. // @Description 标签树
  160. // @Security ApiKeyAuth
  161. // @Param Authorization header string true "Bearer 31a165baebe6dec616b1f8f3207b4273"
  162. // @Param scene_key query string true "scene_key值"
  163. // @Success 200 {string} string "获取成功"
  164. // @failure 400 {string} string "获取失败"
  165. // @Router /public/get_variety_tag_tree [get]
  166. func GetVarietyTagTree(c *gin.Context) {
  167. questionId, _ := strconv.Atoi(c.Query("community_question_id"))
  168. list, err := services.GetTagTree(questionId)
  169. if err != nil {
  170. response.FailMsg("获取标签树失败", "获取标签树失败, Err: "+err.Error(), c)
  171. return
  172. }
  173. response.OkData("获取成功", list, c)
  174. }
  175. // WechatWarning 小程序前端预警提示
  176. // @Tags 公共模块
  177. // @Description 小程序前端预警提示
  178. // @Param content query string true "预警信息"
  179. // @Success 200 {string} string "操作成功"
  180. // @failure 400 {string} string "操作失败"
  181. // @Router /public/wechat_warning [post]
  182. func WechatWarning(c *gin.Context) {
  183. var req request.WechatWarningReq
  184. if err := c.Bind(&req); err != nil {
  185. response.Fail("参数有误", c)
  186. return
  187. }
  188. if req.Content != "" {
  189. tips := fmt.Sprintf("研报小程序前端报错预警-ErrMsg: %s", req.Content)
  190. global.LOG.Warning(tips)
  191. go alarm_msg.SendAlarmMsg(tips, 2)
  192. }
  193. response.Ok("操作成功", c)
  194. }
  195. // UploadAudio 上传音频文件
  196. // @Tags 公共模块
  197. // @Description 上传音频文件
  198. // @Param file query string true "音频文件"
  199. // @Success 200 {string} string "上传成功"
  200. // @failure 400 {string} string "上传失败"
  201. // @Router /public/upload_audio [post]
  202. func UploadAudio(c *gin.Context) {
  203. file, err := c.FormFile("file")
  204. if err != nil {
  205. response.FailMsg("获取资源失败", "获取资源失败, Err:"+err.Error(), c)
  206. return
  207. }
  208. ext := path.Ext(file.Filename)
  209. if ext != ".mp3" {
  210. response.Fail("暂仅支持mp3格式", c)
  211. return
  212. }
  213. dateDir := time.Now().Format("20060102")
  214. localDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
  215. if err := os.MkdirAll(localDir, 0766); err != nil {
  216. response.FailMsg("存储目录创建失败", "UploadAudio 存储目录创建失败, Err:"+err.Error(), c)
  217. return
  218. }
  219. randStr := utils.GetRandStringNoSpecialChar(28)
  220. filtName := randStr + ext
  221. fpath := localDir + "/" + filtName
  222. defer func() {
  223. _ = os.Remove(fpath)
  224. }()
  225. // 生成文件至指定目录
  226. if err := c.SaveUploadedFile(file, fpath); err != nil {
  227. response.FailMsg("文件生成失败", "UploadAudio 文件生成失败, Err:"+err.Error(), c)
  228. return
  229. }
  230. // 获取音频文件时长
  231. fByte, err := ioutil.ReadFile(fpath)
  232. if err != nil {
  233. response.FailMsg("读取本地文件失败", "UploadAudio 读取本地文件失败", c)
  234. return
  235. }
  236. if len(fByte) <= 0 {
  237. response.FailMsg("文件大小有误", "UploadAudio 文件大小有误", c)
  238. return
  239. }
  240. seconds, err := services.GetMP3PlayDuration(fByte)
  241. if err != nil {
  242. response.FailMsg("读取文件时长失败", "UploadAudio 读取文件时长失败", c)
  243. return
  244. }
  245. // 音频大小MB
  246. fi, err := os.Stat(fpath)
  247. if err != nil {
  248. response.FailMsg("读取文件大小失败", "UploadAudio 读取文件大小失败", c)
  249. return
  250. }
  251. mb := utils.Bit2MB(fi.Size(), 2)
  252. // 上传文件至阿里云
  253. ossDir := "yb_wx/audio/"
  254. resourceUrl, err := services.UploadAliyunToDir(filtName, fpath, ossDir)
  255. if err != nil {
  256. response.FailMsg("文件上传失败", "UploadAudio 文件上传失败, Err:"+err.Error(), c)
  257. return
  258. }
  259. resp := &respond.CommunityQuestionAudioUpload{
  260. AudioURL: resourceUrl,
  261. AudioPlaySeconds: fmt.Sprint(seconds),
  262. AudioSize: fmt.Sprint(mb),
  263. }
  264. // 记录文件
  265. go func() {
  266. extendData := struct {
  267. FileName string
  268. AudioURL string
  269. AudioPlaySeconds string
  270. AudioSize string
  271. }{
  272. file.Filename,
  273. resourceUrl,
  274. fmt.Sprint(seconds),
  275. fmt.Sprint(mb),
  276. }
  277. dataByte, e := json.Marshal(extendData)
  278. if e != nil {
  279. return
  280. }
  281. re := new(yb_resource.YbResource)
  282. re.ResourceUrl = resourceUrl
  283. re.ResourceType = yb_resource.ResourceTypeAudio
  284. re.ExtendData = string(dataByte)
  285. re.CreateTime = time.Now().Local()
  286. if e = re.Create(); e != nil {
  287. return
  288. }
  289. }()
  290. response.OkData("上传成功", resp, c)
  291. }
  292. // UpdateViewLog
  293. // @Description 更新各模块访问/点击日志(有时间的话统一改版做一个入口,统一访问日志)
  294. // @Success 200 {string} string "更新成功"
  295. // @Router /public/view_log/update [post]
  296. func UpdateViewLog(c *gin.Context) {
  297. var req request.ViewLogUpdateReq
  298. if err := c.Bind(&req); err != nil {
  299. response.Fail("参数有误:"+err.Error(), c)
  300. return
  301. }
  302. if req.Id <= 0 {
  303. response.Fail("参数有误", c)
  304. return
  305. }
  306. if req.Source <= 0 {
  307. response.Fail("来源有误", c)
  308. return
  309. }
  310. userInfo := user.GetInfoByClaims(c)
  311. err := services.UpdateViewLogBySource(int(userInfo.UserID), req.Id, req.StopSeconds, req.Source)
  312. if err != nil {
  313. fmt.Println(err.Error())
  314. response.FailMsg("更新日志失败", err.Error(), c)
  315. return
  316. }
  317. response.Ok("更新成功", c)
  318. }
  319. // GetTelAreaList 获取手机号区号列表
  320. func GetTelAreaList(c *gin.Context) {
  321. type TelAreaList struct {
  322. Name string `json:"name"`
  323. Value string `json:"value"`
  324. }
  325. // 读取配置
  326. var cond string
  327. var pars []interface{}
  328. cond += `config_code = ?`
  329. pars = append(pars, yb_config.TelAreaList)
  330. confDao := new(yb_config.YbConfig)
  331. conf, e := confDao.Fetch(cond, pars)
  332. if e != nil {
  333. response.FailMsg("获取失败", "获取手机号区号配置失败, Err: "+e.Error(), c)
  334. return
  335. }
  336. if conf.ConfigID <= 0 || conf.ConfigValue == "" {
  337. response.FailMsg("获取失败", "获取手机号区号配置失败", c)
  338. return
  339. }
  340. respList := make([]*TelAreaList, 0)
  341. if e = json.Unmarshal([]byte(conf.ConfigValue), &respList); e != nil {
  342. response.FailMsg("获取失败", "手机号区号配置解析失败, Err: "+e.Error(), c)
  343. return
  344. }
  345. response.OkData("获取成功", respList, c)
  346. }
  347. // BannerMark banner图埋点
  348. // @Tags 公共模块
  349. // @Summary banner图埋点
  350. // @Description banner图埋点
  351. // @Security ApiKeyAuth
  352. // @securityDefinitions.basic BasicAuth
  353. // @Param email query string true "电子邮箱账号"
  354. // @Accept json
  355. // @Product json
  356. // @Success 200 {string} string 获取验证码成功
  357. // @Failure 400 {string} string 请输入邮箱地址
  358. // @Router /banner/mark [post]
  359. func BannerMark(c *gin.Context) {
  360. userInfo := user.GetInfoByClaims(c)
  361. var req request.BannerMarkReq
  362. if err := c.Bind(&req); err != nil {
  363. response.Fail("参数有误:"+err.Error(), c)
  364. return
  365. }
  366. //if req.BannerUrl == "" {
  367. // response.FailMsg("参数有误", "BannerUrl不能为空", c)
  368. // return
  369. //}
  370. if req.FirstSource <= 0 {
  371. response.FailMsg("参数有误", "FirstSource不能为空", c)
  372. return
  373. }
  374. if req.SecondSource <= 0 {
  375. response.FailMsg("参数有误", "SecondSource", c)
  376. }
  377. if req.Id <= 0 {
  378. response.FailMsg("参数有误", "Id错误", c)
  379. }
  380. item, err := banner.GetBannerById(req.Id)
  381. if err != nil {
  382. fmt.Println("GetByUserId:", err.Error())
  383. return
  384. }
  385. // 联系人信息
  386. strInt64 := strconv.FormatUint(userInfo.UserID, 10)
  387. id, _ := strconv.Atoi(strInt64)
  388. wxUserInfo, err := wx_user.GetByUserId(id)
  389. if err != nil {
  390. fmt.Println("GetByUserId:", err.Error())
  391. return
  392. }
  393. companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
  394. if tmpErr != nil {
  395. err = tmpErr
  396. if tmpErr == utils.ErrNoRow {
  397. err = errors.New("找不到该客户")
  398. return
  399. }
  400. return
  401. }
  402. //新增userViewHistory记录
  403. banner_view_history := &banner_view_history.BannerViewHistory{
  404. UserID: userInfo.UserID,
  405. Mobile: wxUserInfo.Mobile,
  406. Email: wxUserInfo.Email,
  407. RealName: wxUserInfo.RealName,
  408. CompanyName: companyInfo.CompanyName,
  409. CreatedTime: time.Now(),
  410. LastUpdatedTime: time.Now(),
  411. FirstSource: req.FirstSource,
  412. SecondSource: req.SecondSource,
  413. BannerUrl: item.ImageUrlMobile,
  414. StartDate: item.StartDate,
  415. EndDate: item.EndDate,
  416. Remark: item.Remark,
  417. }
  418. err = banner_view_history.AddBannerViewHistory()
  419. if err != nil {
  420. fmt.Println("AddUserViewHistory err", err.Error())
  421. }
  422. response.Ok("成功", c)
  423. }
  424. // BannerList banner图列表
  425. // @Tags 公共模块
  426. // @Summary banner图列表
  427. // @Description banner图列表
  428. // @Security ApiKeyAuth
  429. // @securityDefinitions.basic BasicAuth
  430. // @Accept json
  431. // @Product json
  432. // @Success 200 {string} string 获取验证码成功
  433. // @Failure 400 {string} string 请输入邮箱地址
  434. // @Router /banner/list [get]
  435. func BannerList(c *gin.Context) {
  436. isHomepage, _ := strconv.Atoi(c.Query("is_homepage"))
  437. page, _ := strconv.Atoi(c.Query("page"))
  438. limit, _ := strconv.Atoi(c.Query("limit"))
  439. cond := " enable = 1 "
  440. if isHomepage != 1 {
  441. cond += " AND id <> 9999"
  442. }
  443. list, err := banner.GetBannerList(cond, page, limit)
  444. if err != nil {
  445. response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
  446. return
  447. }
  448. response.OkData("获取成功", list, c)
  449. }
  450. // BannerHistoryList banner历史图列表
  451. // @Tags 公共模块
  452. // @Summary banner图列表
  453. // @Description banner图列表
  454. // @Security ApiKeyAuth
  455. // @securityDefinitions.basic BasicAuth
  456. // @Accept json
  457. // @Product json
  458. // @Success 200 {string} string 获取验证码成功
  459. // @Failure 400 {string} string 请输入邮箱地址
  460. // @Router /banner_history/list [get]
  461. func BannerHistoryList(c *gin.Context) {
  462. page, _ := strconv.Atoi(c.Query("page"))
  463. limit, _ := strconv.Atoi(c.Query("limit"))
  464. cond := ""
  465. cond += " enable = 0 "
  466. total, err := banner.GetBannerListCount(cond)
  467. if err != nil {
  468. response.FailMsg("获取失败", "获取banner总数失败, Err: "+err.Error(), c)
  469. return
  470. }
  471. list, err := banner.GetBannerList(cond, page, limit)
  472. if err != nil {
  473. response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
  474. return
  475. }
  476. var resp respond.BannerRespItem
  477. resp.Paging = respond.GetPaging(page, limit, int(total))
  478. resp.List = list
  479. response.OkData("获取成功", resp, c)
  480. }
  481. // BannerList banner图详情
  482. // @Tags 公共模块
  483. // @Summary banner图详情
  484. // @Description banner图详情
  485. // @Security ApiKeyAuth
  486. // @securityDefinitions.basic BasicAuth
  487. // @Accept json
  488. // @Product json
  489. // @Success 200 {string} string 获取验证码成功
  490. // @Failure 400 {string} string 请输入邮箱地址
  491. // @Router /banner/detail [get]
  492. func BannerDetail(c *gin.Context) {
  493. bannerId, _ := strconv.Atoi(c.Query("banner_id"))
  494. item, err := banner.GetBannerById(bannerId)
  495. if err != nil {
  496. response.FailMsg("获取失败", "获取banner失败, Err: "+err.Error(), c)
  497. return
  498. }
  499. response.OkData("获取成功", item, c)
  500. }
  501. // BannerGetQRCode banner历史图列表
  502. // @Tags 公共模块
  503. // @Summary banner图列表
  504. // @Description banner图列表
  505. // @Security ApiKeyAuth
  506. // @securityDefinitions.basic BasicAuth
  507. // @Accept json
  508. // @Product json
  509. // @Success 200 {string} string 获取验证码成功
  510. // @Failure 400 {string} string 请输入邮箱地址
  511. // @Router /banner/get_qrcode [get]
  512. func BannerGetQRCode(c *gin.Context) {
  513. userId, _ := strconv.Atoi(c.Query("UserId"))
  514. bannerId, _ := strconv.Atoi(c.Query("BannerId"))
  515. remark := c.Query("Remark")
  516. wxUserInfo, err := wx_user.GetByUserId(userId)
  517. if err != nil {
  518. response.Ok(err.Error(), c)
  519. return
  520. }
  521. companyInfo, tmpErr := company.GetByCompanyId(wxUserInfo.CompanyID)
  522. if tmpErr != nil {
  523. err = tmpErr
  524. if tmpErr == utils.ErrNoRow {
  525. response.Fail(err.Error(), c)
  526. err = errors.New("找不到该客户")
  527. return
  528. }
  529. response.Fail(err.Error(), c)
  530. return
  531. }
  532. companyName := companyInfo.CompanyName
  533. companyNameCode := url.QueryEscape(companyName) // 进行URL编码
  534. remarkCode := url.QueryEscape(remark) // 进行URL编码
  535. url := "pages-report/signUpPage/signUpPage?RealName=%s&CompanyName=%s&Mobile=%s&BannerId=%d&Title=%s"
  536. url = fmt.Sprintf(url, wxUserInfo.RealName, companyNameCode, wxUserInfo.Mobile, bannerId, remarkCode)
  537. picByte, err := wx_app.GetSunCodeV2(url)
  538. if err != nil {
  539. return
  540. }
  541. // 生成图片
  542. localPath := "./static/img"
  543. fileName := utils.GetRandStringNoSpecialChar(28) + ".png"
  544. fpath := fmt.Sprint(localPath, "/", fileName)
  545. f, err := os.Create(fpath)
  546. if err != nil {
  547. return
  548. }
  549. if _, err = f.Write(picByte); err != nil {
  550. return
  551. }
  552. defer func() {
  553. f.Close()
  554. os.Remove(fpath)
  555. }()
  556. //上传到阿里云
  557. resourceUrl, err := services.UploadAliyun(fileName, fpath)
  558. if err != nil {
  559. response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
  560. return
  561. }
  562. response.OkData("获取成功", resourceUrl, c)
  563. }
  564. // ResearchSignUp 报名
  565. // @Tags 公共模块
  566. // @Summary banner图列表
  567. // @Description banner图列表
  568. // @Security ApiKeyAuth
  569. // @securityDefinitions.basic BasicAuth
  570. // @Accept json
  571. // @Product json
  572. // @Success 200 {string} string 获取验证码成功
  573. // @Failure 400 {string} string 请输入邮箱地址
  574. // @Router /banner/signup [get]
  575. func ResearchSignUp(c *gin.Context) {
  576. //inviteCode := c.Query("InviteCode")
  577. realName := c.Query("RealName")
  578. companyName := c.Query("CompanyName")
  579. mobile := c.Query("Mobile")
  580. bannerId, _ := strconv.Atoi(c.Query("BannerId"))
  581. customName := c.Query("CustomName")
  582. customMobile := c.Query("CustomMobile")
  583. customCompanyName := c.Query("CustomCompanyName")
  584. //userInfo := user.GetInfoByClaims(c)
  585. //userDetail, err, errMsg := userLogic.GetUserInfo(userInfo)
  586. //if err != nil {
  587. // if errMsg != "" {
  588. // errMsg = "获取失败"
  589. // }
  590. // response.Fail(errMsg, c)
  591. // return
  592. //}
  593. count, err := yb_research_signup_statistics.GetSignUpCountByMobileAndBannerId(customMobile, bannerId)
  594. if err != nil {
  595. response.FailData("查询失败", "查询失败,Err:"+err.Error(), c)
  596. return
  597. }
  598. if count > 0 {
  599. response.FailData("该手机号已报名!", "该手机号已报名", c)
  600. return
  601. }
  602. ob := &yb_research_signup_statistics.YbResearchSignupStatistics{
  603. Mobile: mobile,
  604. CustomCompanyName: customCompanyName,
  605. CompanyName: companyName,
  606. BannerId: bannerId,
  607. CustomName: customName,
  608. RealName: realName,
  609. CustomMobile: customMobile,
  610. CreateTime: time.Now(),
  611. }
  612. err = ob.Create()
  613. if err != nil {
  614. response.FailData("报名失败", "报名失败,Err:"+err.Error(), c)
  615. return
  616. }
  617. response.Ok("报名成功", c)
  618. }
  619. // BannerGetQRCode banner调研图下载
  620. // @Tags 公共模块
  621. // @Summary banner调研图下载
  622. // @Description banner调研图下载
  623. // @Security ApiKeyAuth
  624. // @securityDefinitions.basic BasicAuth
  625. // @Accept json
  626. // @Product json
  627. // @Success 200 {string} string 获取验证码成功
  628. // @Failure 400 {string} string 请输入邮箱地址
  629. // @Router /banner/download [get]
  630. func BannerDowload(c *gin.Context) {
  631. var req request.BannerDownloadReq
  632. if err := c.Bind(&req); err != nil {
  633. response.Fail("参数有误:"+err.Error(), c)
  634. return
  635. }
  636. obj := yb_research_banner.YbResearchBanner{}
  637. item, err := obj.Fetch(req.UserId, req.BannerId)
  638. if err != nil && err != utils.ErrNoRow {
  639. response.Fail(err.Error(), c)
  640. return
  641. }
  642. resourceUrl := ""
  643. if item.ImgURL == "" {
  644. randStr := utils.GetRandStringNoSpecialChar(28)
  645. jpegPath := `./static/` + randStr + ".jpeg"
  646. err := services.ReportToJpeg(req.BannerUrl, jpegPath)
  647. if err != nil {
  648. response.FailData("图片转jpeg失败", "图片转jpeg失败,Err:"+err.Error(), c)
  649. return
  650. }
  651. dateDir := time.Now().Format("20060102")
  652. uploadDir := global.CONFIG.Serve.StaticDir + "hongze/" + dateDir
  653. err = os.MkdirAll(uploadDir, 0766)
  654. if err != nil {
  655. response.FailData("存储目录创建失败", "存储目录创建失败,Err:"+err.Error(), c)
  656. return
  657. }
  658. defer func() {
  659. os.Remove(jpegPath)
  660. }()
  661. //上传到阿里云
  662. resourceUrl, err = services.UploadAliyun(randStr+".jpeg", jpegPath)
  663. if err != nil {
  664. response.FailData("文件上传失败", "文件上传失败,Err:"+err.Error(), c)
  665. return
  666. }
  667. obj.BannerID = req.BannerId
  668. obj.UserID = req.UserId
  669. obj.ImgURL = resourceUrl
  670. err = obj.Create()
  671. if err != nil {
  672. response.FailData("创建banner长图记录失败", "创建banner长图记录失败,Err:"+err.Error(), c)
  673. return
  674. }
  675. } else {
  676. resourceUrl = item.ImgURL
  677. }
  678. response.OkData("获取成功", resourceUrl, c)
  679. }