public.go 21 KB

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