public.go 21 KB

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