pc.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. package pc
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "hongze/hongze_yb/controller/response"
  7. userLogic "hongze/hongze_yb/logic/user"
  8. pcModels "hongze/hongze_yb/models/response/pc"
  9. "hongze/hongze_yb/models/tables/customer_comment"
  10. "hongze/hongze_yb/models/tables/rddp/classify"
  11. "hongze/hongze_yb/models/tables/rddp/msg_code"
  12. "hongze/hongze_yb/models/tables/rddp/report"
  13. "hongze/hongze_yb/models/tables/rddp/report_chapter"
  14. "hongze/hongze_yb/models/tables/rddp/session"
  15. "hongze/hongze_yb/models/tables/wx_user"
  16. "hongze/hongze_yb/models/tables/wx_user_log"
  17. "hongze/hongze_yb/models/tables/yb_activity"
  18. "hongze/hongze_yb/models/tables/yb_pc_suncode"
  19. "hongze/hongze_yb/services"
  20. "hongze/hongze_yb/services/pc"
  21. report2 "hongze/hongze_yb/services/report"
  22. userService "hongze/hongze_yb/services/user"
  23. "hongze/hongze_yb/services/wechat"
  24. "hongze/hongze_yb/utils"
  25. "strconv"
  26. "time"
  27. )
  28. // LatestNews 研报首页最新资讯
  29. func LatestNews(c *gin.Context) {
  30. reqChartPermissionId := c.DefaultQuery("chart_permission_id", "")
  31. if reqChartPermissionId == "" {
  32. response.Fail("请输入权限ID", c)
  33. return
  34. }
  35. chartPermissionId, err := strconv.Atoi(reqChartPermissionId)
  36. if err != nil {
  37. response.Fail("权限ID格式错误", c)
  38. return
  39. }
  40. userinfo := userService.GetInfoByClaims(c)
  41. list, err := pc.GetLatestReportList(userinfo, chartPermissionId)
  42. if err != nil {
  43. response.Fail("获取报告失败", c)
  44. return
  45. }
  46. //recommendList, err := pcModels.GetLatestReportList()
  47. //if err != nil {
  48. // response.Fail("获取报告详情失败"+err.Error(), c)
  49. // return
  50. //}
  51. response.OkData("查询成功", list, c)
  52. return
  53. }
  54. // Banner 上新公告banner图
  55. func Banner(c *gin.Context) {
  56. var resp pcModels.LatestReleaseResp
  57. activityItem, err := yb_activity.GetLatestActivity()
  58. if err != nil {
  59. response.Fail(err.Error(), c)
  60. return
  61. }
  62. reportItem, err := report.GetLatestReport()
  63. if err != nil {
  64. response.Fail(err.Error(), c)
  65. return
  66. }
  67. imgMap := map[string]string{
  68. "晨报": utils.ALIYUN_YBIMG_HOST + "day.png",
  69. "周报": utils.ALIYUN_YBIMG_HOST + "week.png",
  70. "双周报": utils.ALIYUN_YBIMG_HOST + "two_week.png",
  71. "月报": utils.ALIYUN_YBIMG_HOST + "month.png",
  72. "草根调研": utils.ALIYUN_YBIMG_HOST + "cgdy.png",
  73. "需求报告": utils.ALIYUN_YBIMG_HOST + "xqbg.png",
  74. "宏观报告": utils.ALIYUN_YBIMG_HOST + "hgbg.png",
  75. "日度点评": utils.ALIYUN_YBIMG_HOST + "rddp.png",
  76. "数据点评": utils.ALIYUN_YBIMG_HOST + "sjdp.png",
  77. "碳市场价格周报": utils.ALIYUN_YBIMG_HOST + "coal.png",
  78. "行业调研": utils.ALIYUN_YBIMG_HOST + "hydy.png",
  79. "百家谈": utils.ALIYUN_YBIMG_HOST + "bjt.png",
  80. "会议纪要": utils.ALIYUN_YBIMG_HOST + "hyjy.png",
  81. "大事点评": utils.ALIYUN_YBIMG_HOST + "dsdp.png",
  82. "年报合集": utils.ALIYUN_YBIMG_HOST + "nbhj.png",
  83. }
  84. if activityItem.CreateTime.Before(reportItem.PublishTime) {
  85. resp.ActivityOrReport = 1
  86. resp.ReportId = reportItem.ReportId
  87. resp.ClassifyIdSecond = reportItem.ClassifyIdSecond
  88. resp.ImgUrl = imgMap[reportItem.ClassifyNameFirst]
  89. } else {
  90. resp.ActivityOrReport = 0
  91. resp.Activity = activityItem
  92. resp.ImgUrl = utils.ALIYUN_YBIMG_HOST + "activity.png"
  93. }
  94. response.OkData("查询成功", resp, c)
  95. return
  96. }
  97. // LatestRelease 上新公告
  98. func LatestRelease(c *gin.Context) {
  99. classifyIdString := c.DefaultQuery("ClassifyId", "")
  100. if classifyIdString == "" {
  101. response.Fail("请输入classifyId", c)
  102. return
  103. }
  104. classifyId, err := strconv.Atoi(classifyIdString)
  105. if err != nil {
  106. response.Fail("请输入正确classifyId", c)
  107. return
  108. }
  109. classifyInfo, err := classify.GetByClassifyId(classifyId)
  110. if err != nil {
  111. response.Fail("分类查询出错", c)
  112. return
  113. }
  114. response.OkData("查询成功", classifyInfo, c)
  115. return
  116. }
  117. // ClassifyDetail 专栏详情
  118. func ClassifyDetail(c *gin.Context) {
  119. reqClassifyIdSecond := c.DefaultQuery("classify_id_second", "")
  120. if reqClassifyIdSecond == "" {
  121. response.Fail("请输入二级分类标识", c)
  122. return
  123. }
  124. classifyIdSecond, err := strconv.Atoi(reqClassifyIdSecond)
  125. if err != nil {
  126. response.Fail("请输入正确的二级分类标识", c)
  127. return
  128. }
  129. userinfo := userService.GetInfoByClaims(c)
  130. detail, err := pc.GetClassifyDetail(userinfo, classifyIdSecond)
  131. if err != nil {
  132. response.Fail(err.Error(), c)
  133. return
  134. }
  135. response.OkData("查询成功", detail, c)
  136. return
  137. }
  138. // ClassifyDetailBanner 专栏详情banner图
  139. func ClassifyDetailBanner(c *gin.Context) {
  140. reqReportId := c.DefaultQuery("reportId", "")
  141. //classifyName := c.DefaultQuery("classify_name_first", "")
  142. //if reqReportId == "" {
  143. // response.Fail("请输入二级分类标识", c)
  144. // return
  145. //}
  146. reportId, err := strconv.Atoi(reqReportId)
  147. if err != nil {
  148. response.Fail("报告ID格式有误", c)
  149. return
  150. }
  151. reportInfo, err := report.GetByReportId(reportId)
  152. if err != nil {
  153. response.Fail("报告查询出错", c)
  154. return
  155. }
  156. //查询分类类别,根据分类配置显示专栏还是报告合集
  157. parentClassify, err := classify.GetByClassifyIdFirst(reportInfo.ClassifyIdFirst)
  158. if err != nil {
  159. response.Fail("获取分类信息失败"+err.Error(), c)
  160. return
  161. }
  162. minClassifyId, _, err := report2.GetMinClassify(reportInfo)
  163. if err != nil {
  164. response.FailMsg("查询最新一期报告合集失败", "查询最新一期报告合集失败1:"+err.Error(), c)
  165. return
  166. }
  167. var bannerResp *pcModels.DetailBannerResp
  168. if reportInfo.HasChapter == 1 {
  169. chapterItem, err := report_chapter.GetLatestChapterByMinClassifyId(minClassifyId)
  170. if err != nil {
  171. response.FailMsg("查询最新一期报告合集失败2", "查询最新一期报告合集失败2:"+err.Error(), c)
  172. return
  173. }
  174. resp := &pcModels.DetailBannerResp{
  175. ReportId: chapterItem.ReportId,
  176. ClassifyNameFirst: chapterItem.ClassifyNameFirst,
  177. ClassifyIdFirst: chapterItem.ClassifyIdFirst,
  178. Stage: chapterItem.Stage,
  179. ImgUrl: "",
  180. Type: "报告合集",
  181. ShowType: 1,
  182. }
  183. bannerResp = resp
  184. } else {
  185. if reportInfo.Id == 0 {
  186. response.Fail("报告不存在", c)
  187. return
  188. }
  189. if reportInfo.State != 2 && reportInfo.State != 6 {
  190. response.Fail("报告未发布", c)
  191. return
  192. }
  193. reportItem, err := report.GetLatestReportByClassifyId(reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
  194. if err != nil {
  195. response.Fail("获取报告详情失败"+err.Error(), c)
  196. return
  197. }
  198. //查询分类类别,根据分类配置显示专栏还是报告合集
  199. minClassify, err := classify.GetByClassifyId(minClassifyId)
  200. if err != nil {
  201. response.FailMsg("获取分类信息失败", "获取分类信息失败"+err.Error(), c)
  202. return
  203. }
  204. resp := &pcModels.DetailBannerResp{
  205. ReportId: reportItem.ReportId,
  206. Stage: reportItem.Stage,
  207. VipTitle: minClassify.VipTitle,
  208. Author: reportItem.Author,
  209. ReportAuthor: minClassify.ReportAuthor,
  210. ImgUrl: "",
  211. ClassifyNameFirst: reportItem.ClassifyNameFirst,
  212. ClassifyIdFirst: reportItem.ClassifyIdFirst,
  213. ClassifyNameSecond: reportItem.ClassifyNameSecond,
  214. ClassifyIdSecond: reportItem.ClassifyIdSecond,
  215. ShowType: minClassify.ShowType,
  216. }
  217. if parentClassify.ShowType == 1 || parentClassify.ShowType == 3 {
  218. resp.Type = "报告合集"
  219. } else {
  220. resp.Type = "专栏详情"
  221. }
  222. bannerResp = resp
  223. }
  224. //有人的用人的底图,和上新公告图片不完全一样
  225. /*firstNameMap := map[string]string{
  226. "晨报": utils.ALIYUN_YBIMG_HOST + "day.png",
  227. "周报": utils.ALIYUN_YBIMG_HOST + "week.png",
  228. "双周报": utils.ALIYUN_YBIMG_HOST + "two_week.png",
  229. "月报": utils.ALIYUN_YBIMG_HOST + "month.png",
  230. "会议纪要": utils.ALIYUN_YBIMG_HOST + "hyjy.png",
  231. "大事点评": utils.ALIYUN_YBIMG_HOST + "dsdp.png",
  232. "年报合集": utils.ALIYUN_YBIMG_HOST + "nbhj.png",
  233. //"草根调研": utils.ALIYUN_YBIMG_HOST + "hy.png",
  234. //"需求报告": utils.ALIYUN_YBIMG_HOST + "lxt.png",
  235. //"碳市场价格周报": utils.ALIYUN_YBIMG_HOST + "sjx.png",
  236. //"行业调研": utils.ALIYUN_YBIMG_HOST + "qp.png",
  237. }*/
  238. //secondNameMap := map[string]string{
  239. // //宏观报告
  240. // "宏观周期观察": utils.ALIYUN_YBIMG_HOST + "gx.png",
  241. // "房地产市场跟踪": utils.ALIYUN_YBIMG_HOST + "gx.png",
  242. // "货币政策跟踪": utils.ALIYUN_YBIMG_HOST + "gx.png",
  243. // "全球宏观经济周度回顾": utils.ALIYUN_YBIMG_HOST + "ldb.png",
  244. // "宏观点评": utils.ALIYUN_YBIMG_HOST + "zzh.png",
  245. // //日度点评
  246. // "知白守黑日评": utils.ALIYUN_YBIMG_HOST + "wxy.png",
  247. // "有声有色日度闲": utils.ALIYUN_YBIMG_HOST + "qp.png",
  248. // "化里化外日评": utils.ALIYUN_YBIMG_HOST + "qmz.png",
  249. // "每日经济数据备忘录": utils.ALIYUN_YBIMG_HOST + "ldb.png",
  250. // "股债日评": utils.ALIYUN_YBIMG_HOST + "zzh.png",
  251. // "贵金属复盘": utils.ALIYUN_YBIMG_HOST + "hx.png",
  252. // //数据点评
  253. // "钢材周度数据点评": utils.ALIYUN_YBIMG_HOST + "wxy.png",
  254. // "甲醇开工数据点评": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  255. // "短纤数据点评": utils.ALIYUN_YBIMG_HOST + "zyy.png",
  256. // "玻璃数据点评": utils.ALIYUN_YBIMG_HOST + "gwy.png",
  257. // "聚烯烃数据点评": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  258. // "铜行业数据点评": utils.ALIYUN_YBIMG_HOST + "yf.png",
  259. // "国际钢材市场数据点评": utils.ALIYUN_YBIMG_HOST + "bx.png",
  260. // "废钢周度数据点评": utils.ALIYUN_YBIMG_HOST + "bx.png",
  261. // "PP数据点评": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  262. // "PVC数据点评": utils.ALIYUN_YBIMG_HOST + "lyx.png",
  263. // "BOPP数据点评": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  264. // "塑编数据点评": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  265. // "铁矿库存数据点评": utils.ALIYUN_YBIMG_HOST + "hk.png",
  266. // "宏观数据点评": utils.ALIYUN_YBIMG_HOST + "zzh.png",
  267. // "铝数据点评": utils.ALIYUN_YBIMG_HOST + "yf.png",
  268. // "甲醇库存数据点评": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  269. // "玻璃纯碱数据点评": utils.ALIYUN_YBIMG_HOST + "gwy.png",
  270. // "乙二醇数据点评": utils.ALIYUN_YBIMG_HOST + "zyy.png",
  271. // "纯碱数据点评": utils.ALIYUN_YBIMG_HOST + "gwy.png",
  272. // "COVID-19跟踪": utils.ALIYUN_YBIMG_HOST + "lxt.png",
  273. // "双焦数据点评": utils.ALIYUN_YBIMG_HOST + "zs.png",
  274. // "苯乙烯库存数据点评": utils.ALIYUN_YBIMG_HOST + "cy.png",
  275. // "苯乙烯数据点评": utils.ALIYUN_YBIMG_HOST + "cy.png",
  276. // "苯乙烯简评": utils.ALIYUN_YBIMG_HOST + "cy.png",
  277. // "EIA天然气库存点评": utils.ALIYUN_YBIMG_HOST + "wyy.png",
  278. // "美国油气钻机数据点评": utils.ALIYUN_YBIMG_HOST + "wyy.png",
  279. // "OPEC+产量点评": utils.ALIYUN_YBIMG_HOST + "hyy.png",
  280. // "原油船期数数据跟踪": utils.ALIYUN_YBIMG_HOST + "wyy.png",
  281. // "EIA原油库存点评": utils.ALIYUN_YBIMG_HOST + "hyy.png",
  282. // "苯乙烯开工数据点评": utils.ALIYUN_YBIMG_HOST + "cy.png",
  283. // "聚酯数据点评": utils.ALIYUN_YBIMG_HOST + "qc.png",
  284. // "铁矿航运数据点评": utils.ALIYUN_YBIMG_HOST + "hk.png",
  285. // //百家谈
  286. // "能化百家谈": utils.ALIYUN_YBIMG_HOST + "qmz.png",
  287. // "有色百家谈": utils.ALIYUN_YBIMG_HOST + "qp.png",
  288. // "黑色百家谈": utils.ALIYUN_YBIMG_HOST + "wxy.png",
  289. //}
  290. authorMap := map[string]string{
  291. "白昕": utils.ALIYUN_YBIMG_HOST + "bx.png",
  292. "曹阳": utils.ALIYUN_YBIMG_HOST + "cy.png",
  293. "曾硕": utils.ALIYUN_YBIMG_HOST + "zs.png",
  294. "曾滢月": utils.ALIYUN_YBIMG_HOST + "zyy.png",
  295. "程品": utils.ALIYUN_YBIMG_HOST + "cp.png",
  296. "高雯宇": utils.ALIYUN_YBIMG_HOST + "gwy.png",
  297. "高昕": utils.ALIYUN_YBIMG_HOST + "gx.png",
  298. "高吟": utils.ALIYUN_YBIMG_HOST + "gy.png",
  299. "陈聪聪": utils.ALIYUN_YBIMG_HOST + "ccc.png",
  300. "何凯": utils.ALIYUN_YBIMG_HOST + "hk.png",
  301. "黄鑫": utils.ALIYUN_YBIMG_HOST + "hx.png",
  302. "黄逸赟": utils.ALIYUN_YBIMG_HOST + "hyy.png",
  303. "黄溢": utils.ALIYUN_YBIMG_HOST + "hy.png",
  304. "李灵": utils.ALIYUN_YBIMG_HOST + "ll.png",
  305. "林秋馨": utils.ALIYUN_YBIMG_HOST + "lqx.png",
  306. "刘鼎邦": utils.ALIYUN_YBIMG_HOST + "ldb.png",
  307. "钱鹏": utils.ALIYUN_YBIMG_HOST + "qp.png",
  308. "刘艺羡": utils.ALIYUN_YBIMG_HOST + "lyx.png",
  309. "戚明之": utils.ALIYUN_YBIMG_HOST + "qmz.png",
  310. "秦钏": utils.ALIYUN_YBIMG_HOST + "qc.png",
  311. "施琪": utils.ALIYUN_YBIMG_HOST + "sq.png",
  312. "王存响": utils.ALIYUN_YBIMG_HOST + "wcx.png",
  313. "王沛": utils.ALIYUN_YBIMG_HOST + "wp.png",
  314. "苏畅": utils.ALIYUN_YBIMG_HOST + "sc.png",
  315. "史瑾璇": utils.ALIYUN_YBIMG_HOST + "sjx.png",
  316. "王亚丹": utils.ALIYUN_YBIMG_HOST + "wyd.png",
  317. "虞风": utils.ALIYUN_YBIMG_HOST + "yf.png",
  318. "魏忻悦": utils.ALIYUN_YBIMG_HOST + "wxy.png",
  319. "王艺滢": utils.ALIYUN_YBIMG_HOST + "wyy.png",
  320. "姚昕泽": utils.ALIYUN_YBIMG_HOST + "yxz.png",
  321. "章左昊": utils.ALIYUN_YBIMG_HOST + "zzh.png",
  322. "李晓瞳": utils.ALIYUN_YBIMG_HOST + "lxt.png",
  323. "弘则FICC无锡调研团队": utils.ALIYUN_YBIMG_HOST + "qp.png",
  324. "弘则能化组": utils.ALIYUN_YBIMG_HOST + "qmz.png",
  325. "弘则有色团队": utils.ALIYUN_YBIMG_HOST + "qp.png",
  326. "弘则黑色团队": utils.ALIYUN_YBIMG_HOST + "wp.png",
  327. "弘则宏观团队": utils.ALIYUN_YBIMG_HOST + "zzh.png",
  328. "张立舟": utils.ALIYUN_YBIMG_HOST + "zlz.png",
  329. "郑露": utils.ALIYUN_YBIMG_HOST + "zl.png",
  330. "酒子怡": utils.ALIYUN_YBIMG_HOST + "jzy.png",
  331. }
  332. if parentClassify.ShowType == 1 || parentClassify.ShowType == 3 {
  333. bannerResp.ImgUrl = parentClassify.YbRightBanner
  334. } else if url, ok := authorMap[bannerResp.ReportAuthor]; ok {
  335. bannerResp.ImgUrl = url
  336. }
  337. response.OkData("查询成功", bannerResp, c)
  338. return
  339. }
  340. // Recommend 报告详情页更多推荐
  341. func Recommend(c *gin.Context) {
  342. reqReportId := c.DefaultQuery("reportId", "")
  343. if reqReportId == "" {
  344. response.Fail("请输入二级分类标识", c)
  345. return
  346. }
  347. reportId, err := strconv.Atoi(reqReportId)
  348. if err != nil {
  349. response.Fail("报告ID格式有误", c)
  350. return
  351. }
  352. reportInfo, err := report.GetByReportId(reportId)
  353. if err != nil {
  354. response.Fail("报告查询出错", c)
  355. return
  356. }
  357. if reportInfo.Id == 0 {
  358. response.Fail("报告不存在", c)
  359. return
  360. }
  361. minClassifyId, _, err := report2.GetMinClassify(reportInfo)
  362. if err != nil {
  363. response.FailMsg("查询最新一期报告合集失败", "查询最新一期报告合集失败1:"+err.Error(), c)
  364. return
  365. }
  366. var recommendResp []*pcModels.RecommendResp
  367. if reportInfo.HasChapter == 1 {
  368. recommendList, err := report_chapter.GetWeekRecommendListV2(reportId, minClassifyId)
  369. if err != nil {
  370. response.FailMsg("获取推荐报告列表失败", "获取推荐报告列表失败:"+err.Error(), c)
  371. return
  372. }
  373. for _, chapter := range recommendList {
  374. resp := &pcModels.RecommendResp{
  375. ReportId: chapter.ReportId,
  376. ReportChapterID: chapter.ReportChapterId,
  377. Title: chapter.Title,
  378. Stage: chapter.Stage,
  379. ClassifyNameFirst: chapter.ClassifyNameFirst,
  380. ClassifySecondFirst: "",
  381. }
  382. recommendResp = append(recommendResp, resp)
  383. }
  384. } else {
  385. if reportInfo.State != 2 && reportInfo.State != 6 {
  386. response.Fail("报告未发布", c)
  387. return
  388. }
  389. reportType := 0
  390. if reportInfo.ClassifyNameFirst == "权益研报" {
  391. reportType = 1
  392. } else {
  393. reportType = 2
  394. }
  395. recommendList := make([]*pcModels.Report, 0)
  396. if reportInfo.RaiReportId > 0 {
  397. recommendList, err = pcModels.GetRaiRecommendList(reportId, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird, reportInfo.PublishTime)
  398. if err != nil {
  399. response.Fail("获取报告详情失败"+err.Error(), c)
  400. return
  401. }
  402. } else {
  403. recommendList, err = pcModels.GetRecommendListV2(reportId, reportType, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
  404. if err != nil {
  405. response.Fail("获取报告详情失败"+err.Error(), c)
  406. return
  407. }
  408. }
  409. for _, chapter := range recommendList {
  410. resp := &pcModels.RecommendResp{
  411. ReportId: chapter.Id,
  412. ReportChapterID: 0,
  413. Title: chapter.Title,
  414. Stage: chapter.Stage,
  415. ClassifyNameFirst: chapter.ClassifyNameFirst,
  416. ClassifySecondFirst: chapter.ClassifyNameSecond,
  417. RaiReportId: chapter.RaiReportId,
  418. }
  419. recommendResp = append(recommendResp, resp)
  420. }
  421. }
  422. response.OkData("查询成功", recommendResp, c)
  423. return
  424. }
  425. // ClassifyFirstList Ficc 菜单
  426. func ClassifyFirstList(c *gin.Context) {
  427. userinfo := userService.GetInfoByClaims(c)
  428. classList, err := pc.GetClassifyFirstList(userinfo)
  429. if err != nil {
  430. response.Fail(err.Error(), c)
  431. return
  432. }
  433. response.OkData("查询成功", classList, c)
  434. return
  435. }
  436. // CustomerComment 客户评价
  437. func CustomerComment(c *gin.Context) {
  438. lists, err := customer_comment.GetCustomerComment()
  439. if err != nil {
  440. response.Fail(err.Error(), c)
  441. return
  442. }
  443. response.OkData("查询成功", lists, c)
  444. return
  445. }
  446. // GetSunCode 获取太阳码
  447. // @Tags 公共模块
  448. // @Summary 获取分享海报
  449. // @Description 获取分享海报
  450. // @Param request body services.SunCodeReq true "type json string"
  451. // @Success 200 {object} string "获取成功"
  452. // @failure 400 {string} string "获取失败"
  453. // @Router /pc/getSunCode [post]
  454. func GetSunCode(c *gin.Context) {
  455. var req services.SunCodeReq
  456. if c.ShouldBind(&req) != nil {
  457. response.Fail("参数异常", c)
  458. return
  459. }
  460. var sunCodeUrl string
  461. //先查,查不到再去生成上传
  462. item, err := yb_pc_suncode.GetYbPcSunCode(req.CodeScene, req.CodePage)
  463. if err != nil && err != utils.ErrNoRow {
  464. response.FailMsg("获取太阳码失败", err.Error(), c)
  465. return
  466. }
  467. if item != nil && item.SuncodeURL != "" {
  468. sunCodeUrl = item.SuncodeURL
  469. }
  470. if sunCodeUrl == "" {
  471. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  472. if err != nil {
  473. response.FailMsg("生成太阳码失败:err:"+err.Error(), err.Error(), c)
  474. return
  475. }
  476. }
  477. response.OkData("查询成功", sunCodeUrl, c)
  478. return
  479. }
  480. // @Title pc端微信登录接口
  481. // @Description pc端微信登录接口
  482. // @Param Code query string true "微信唯一编码code"
  483. // @Success 200 {object} models.WxLoginResp
  484. // @router /pc/login [get]
  485. func WechatLogin(c *gin.Context) {
  486. var resp pcModels.LoginResp
  487. var token string
  488. var userId int
  489. var isBind bool
  490. code := c.DefaultQuery("Code", "")
  491. if code == "" {
  492. response.Fail("code参数错误", c)
  493. return
  494. }
  495. item, err := wechat.PcWxGetUserOpenIdByCode(code)
  496. if err != nil {
  497. response.Fail(err.Error(), c)
  498. return
  499. }
  500. fmt.Println("token:", item.AccessToken)
  501. fmt.Println("token:", item.Errmsg)
  502. fmt.Println("token:", item.Errcode)
  503. if item.Errcode != 0 {
  504. response.Fail(item.Errmsg, c)
  505. return
  506. }
  507. openId := item.Openid
  508. //wxUserInfo, err := wx_app.GetSession(code)
  509. //if err != nil {
  510. // response.Fail("获取失败,Err:"+err.Error(), c)
  511. // return
  512. //}
  513. //获取用户信息
  514. wxPcUserInfo, err := wechat.PcWxGetUserInfo(openId, item.AccessToken)
  515. if err != nil {
  516. response.Fail(err.Error(), c)
  517. return
  518. }
  519. if wxPcUserInfo.Errcode != 0 {
  520. response.Fail(err.Error(), c)
  521. return
  522. }
  523. unionId := item.Unionid
  524. //sessionKey := wxUserInfo.SessionKey
  525. //needUpdateSessionKey := true //是否更新sessionKey
  526. QUERY_WX_USER:
  527. wxUser, wxUserErr := userService.GetWxUserItemByOpenId(openId)
  528. if wxUserErr == userService.ERR_NO_USER_RECORD { //没有用户openid记录
  529. _, recordErr := userService.AddUserRecord(openId, unionId, "", "", "", "", "", "", "", 3, 0, 0)
  530. //如果插入失败,那么直接将错误信息返回
  531. if recordErr != nil {
  532. err = recordErr
  533. return
  534. }
  535. //needUpdateSessionKey = false //因为是新增用户微信信息,所以不需要更新sessionKey的数据了
  536. //插入成功后,需要重新查询该用户,并进入下面的逻辑
  537. goto QUERY_WX_USER
  538. } else if wxUserErr == userService.ERR_USER_NOT_BIND {
  539. // 未绑定则去查询unionId是否已经绑定了用户(其他平台,不区分平台),有相应的手机号邮箱信息则自动绑定
  540. //platformUser, platformErr := userService.GetFirstWxUserItemByUnionId(unionId)
  541. //if platformErr == nil {
  542. // // 当公众号用户存在时
  543. // if platformUser.Mobile != "" || platformUser.Email != "" {
  544. // // 有手机号或邮箱则绑定信息则自动绑定并新增wx_user
  545. // countryCode := 0
  546. // if platformUser.CountryCode != "" {
  547. // countryCode, _ = strconv.Atoi(platformUser.CountryCode)
  548. // }
  549. // tempToken, tempUser, tempErr, errMsg := userService.BindWxUser(openId, platformUser.Mobile, platformUser.Email, "", 3, countryCode, 1)
  550. // if tempErr != nil {
  551. // err = errors.New("自动绑定公众号用户失败,Err:" + tempErr.Error() + ", errMsg:" + errMsg)
  552. // return
  553. // }
  554. // token = tempToken
  555. // userId = int(tempUser.UserID)
  556. // isBind = true
  557. // }
  558. //}
  559. } else if wxUserErr != nil {
  560. err = wxUserErr
  561. return
  562. }
  563. //更新微信用户的sessionKey
  564. //if needUpdateSessionKey {
  565. // _ = user_record.ModifySessionKeyByOpenid(openId, sessionKey)
  566. //}
  567. // 如果已经登录注册绑定的情况下/或者首次登录且为弘则研究公众号用户
  568. if wxUserErr == nil {
  569. userId = int(wxUser.UserID)
  570. // 如果账户有绑定了手机号或者邮箱,那么标记为已绑定
  571. if wxUser.Mobile != "" || wxUser.Email != "" {
  572. isBind = true
  573. }
  574. }
  575. //获取登录token
  576. tokenItem, tokenErr := session.GetTokenByOpenId(openId)
  577. if tokenErr != nil && tokenErr != utils.ErrNoRow {
  578. err = errors.New("登录失败,获取token失败:" + tokenErr.Error())
  579. return
  580. }
  581. fmt.Println("AccessToken:", item.AccessToken)
  582. fmt.Println("tokenItem:", tokenItem.AccessToken)
  583. if tokenErr != nil && tokenErr == utils.ErrNoRow {
  584. timeUnix := time.Now().Unix()
  585. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  586. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  587. fmt.Println("token:", tokenItem.AccessToken)
  588. //新增session
  589. {
  590. sessionItem := &session.Session{
  591. OpenID: openId,
  592. UserID: int64(userId),
  593. CreatedTime: time.Now(),
  594. LastUpdatedTime: time.Now(),
  595. ExpireTime: time.Now().AddDate(0, 3, 0),
  596. AccessToken: token,
  597. }
  598. sessionErr := sessionItem.Create()
  599. if err != nil {
  600. err = errors.New("登录失败,新增用户session信息失败:" + sessionErr.Error())
  601. return
  602. }
  603. }
  604. } else {
  605. token = tokenItem.AccessToken
  606. //如果联系人编号不为空,且联系人编号与session里面的联系人编号不一致的时候,需要做session变更
  607. //if userId > 0 && tokenItem.UserID != int64(userId) {
  608. // _ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
  609. //}
  610. //if userId > 0 {
  611. //}
  612. _ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
  613. }
  614. //新增登录日志
  615. {
  616. loginLog := &wx_user_log.WxUserLog{
  617. UserID: userId,
  618. OpenID: openId,
  619. UnionID: unionId,
  620. CreateTime: time.Now(),
  621. Handle: "yb_login",
  622. Remark: token,
  623. }
  624. go loginLog.Create()
  625. }
  626. resp.IsBind = isBind
  627. resp.Token = token
  628. response.OkData("查询成功", resp, c)
  629. return
  630. }
  631. // @Title 登录
  632. // @Description 登录接口
  633. // @Param request body models.LoginReq true "type json string"
  634. // @Success 200 {object} models.LoginResp
  635. // @router /pc/pcLogin [post]
  636. func PcLogin(c *gin.Context) {
  637. var req pcModels.PcLoginReq
  638. if c.ShouldBind(&req) != nil {
  639. response.Fail("参数异常", c)
  640. return
  641. }
  642. userId := 0
  643. var isAdd bool
  644. if req.LoginType == 1 {
  645. if req.Mobile == "" {
  646. response.Fail("请输入手机号", c)
  647. return
  648. }
  649. if req.SmsCode == "" {
  650. response.Fail("请输入有效手机验证码", c)
  651. return
  652. }
  653. item, err := msg_code.GetMsgCode(req.Mobile, req.SmsCode)
  654. if err != nil {
  655. if err == utils.ErrNoRow {
  656. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  657. return
  658. } else {
  659. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  660. return
  661. }
  662. }
  663. if item == nil {
  664. response.Fail("手机验证码错误,请重新输入", c)
  665. return
  666. }
  667. if item.Code != req.SmsCode {
  668. response.Fail("验证码失效,请重新最新验证码", c)
  669. return
  670. }
  671. wxUser, err := wx_user.GetByMobile(req.Mobile)
  672. if err != nil {
  673. if err == utils.ErrNoRow {
  674. isAdd = true
  675. } else {
  676. response.Fail("根据手机号获取用户信息失败,Err:"+err.Error(), c)
  677. return
  678. }
  679. }
  680. if wxUser == nil {
  681. isAdd = true
  682. } else {
  683. userId = int(wxUser.UserID)
  684. }
  685. //BindMobile(openId, mobile string, userId, loginType int) (err error) {
  686. //newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
  687. } else if req.LoginType == 2 {
  688. if req.Email == "" {
  689. response.Fail("邮箱不能为空,请输入邮箱", c)
  690. return
  691. }
  692. if !utils.ValidateEmailFormatat(req.Email) {
  693. response.Fail("邮箱格式错误,请重新输入", c)
  694. return
  695. }
  696. if req.SmsCode == "" {
  697. response.Fail("请输入有效验证码", c)
  698. return
  699. }
  700. item, err := msg_code.GetMsgCode(req.Email, req.SmsCode)
  701. if err != nil {
  702. if err == utils.ErrNoRow {
  703. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  704. return
  705. } else {
  706. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  707. return
  708. }
  709. }
  710. if item == nil {
  711. response.Fail("邮箱证码错误,请重新输入:", c)
  712. return
  713. }
  714. wxUser, err := wx_user.GetByEmail(req.Email)
  715. if err != nil {
  716. if err == utils.ErrNoRow {
  717. isAdd = true
  718. } else {
  719. response.Fail("根据邮箱获取用户信息失败,Err:"+err.Error(), c)
  720. return
  721. }
  722. }
  723. if wxUser == nil {
  724. isAdd = true
  725. } else {
  726. userId = int(wxUser.UserID)
  727. }
  728. } else {
  729. response.Fail("无效的登录方式,loginType:"+strconv.Itoa(req.LoginType), c)
  730. }
  731. if isAdd {
  732. user := new(wx_user.WxUser)
  733. user.CompanyID = 1
  734. user.CreatedTime = time.Now()
  735. user.FirstLogin = 1
  736. user.Enabled = 1
  737. user.Email = req.Email
  738. user.Mobile = req.Mobile
  739. if req.LoginType == 1 {
  740. user.BindAccount = user.Mobile
  741. } else {
  742. user.BindAccount = user.Email
  743. }
  744. user.RegisterTime = time.Now()
  745. user.LoginTime = time.Now()
  746. user.RegisterPlatform = 2
  747. if req.IsFreeLogin {
  748. user.IsFreeLogin = 1
  749. } else {
  750. user.IsFreeLogin = 0
  751. }
  752. lastId, err := user.Add()
  753. if err != nil {
  754. response.Fail("登录失败,新增客户信息失败,Err:"+err.Error(), c)
  755. return
  756. }
  757. fmt.Println("lastId:", lastId)
  758. userId = int(lastId)
  759. timeUnix := time.Now().Unix()
  760. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  761. token := utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
  762. //新增session
  763. {
  764. session := new(session.Session)
  765. session.UserID = int64(userId)
  766. session.CreatedTime = time.Now()
  767. session.LastUpdatedTime = time.Now()
  768. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  769. session.AccessToken = token
  770. err = session.Create()
  771. if err != nil {
  772. response.Fail("登录失败,新增用户session信息失败:"+err.Error(), c)
  773. return
  774. }
  775. }
  776. } else {
  777. user := new(wx_user.WxUser)
  778. user.UserID = uint64(userId)
  779. if req.IsFreeLogin {
  780. user.IsFreeLogin = 1
  781. } else {
  782. user.IsFreeLogin = 0
  783. }
  784. err := user.Update([]string{"is_free_login"})
  785. if err != nil {
  786. response.Fail("登录失败,修改登录信息失败,Err:"+err.Error(), c)
  787. return
  788. }
  789. }
  790. if userId == 0 {
  791. response.Fail("登录失败,id为 0", c)
  792. return
  793. }
  794. err := wx_user.ModifyFirstLogin(uint64(userId))
  795. if err != nil {
  796. response.Fail("登录失败,判断权限失败:"+err.Error(), c)
  797. return
  798. }
  799. var token string
  800. tokenItem, err := session.GetTokenByUid(userId)
  801. if err != nil && err != utils.ErrNoRow {
  802. response.Fail("登录失败,获取token失败:"+err.Error(), c)
  803. return
  804. }
  805. if tokenItem == nil || (err != nil && err == utils.ErrNoRow) {
  806. timeUnix := time.Now().Unix()
  807. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  808. token = utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
  809. //新增session
  810. {
  811. session := new(session.Session)
  812. session.UserID = int64(userId)
  813. session.CreatedTime = time.Now()
  814. session.LastUpdatedTime = time.Now()
  815. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  816. session.AccessToken = token
  817. err = session.Create()
  818. if err != nil {
  819. response.Fail("登录失败,新增用户session信息失败:"+err.Error(), c)
  820. return
  821. }
  822. }
  823. } else {
  824. token = tokenItem.AccessToken
  825. }
  826. //新增登录日志
  827. {
  828. loginLog := new(wx_user_log.WxUserLog)
  829. loginLog.UserID = userId
  830. loginLog.Mobile = req.Mobile
  831. loginLog.Email = req.Email
  832. loginLog.Handle = "pc_login"
  833. loginLog.CreateTime = time.Now()
  834. go loginLog.Create()
  835. }
  836. response.OkData("登录成功", token, c)
  837. }
  838. // GetSmsCode 获取短信验证码接口
  839. // @Tags 用户模块
  840. // @Summary 获取短信验证码
  841. // @Description 获取短信验证码接口
  842. // @Security ApiKeyAuth
  843. // @securityDefinitions.basic BasicAuth
  844. // @Param mobile query string true "手机号"
  845. // @Param area_num query string true "手机国际区号(中国大陆:86)"
  846. // @Accept json
  847. // @Product json
  848. // @Success 200 {string} string 获取验证码成功
  849. // @Failure 400 {string} string 手机号不能为空,请输入手机号
  850. // @Router /pc_code/get_sms_code [get]
  851. func GetSmsCode(c *gin.Context) {
  852. mobile := c.DefaultQuery("mobile", "")
  853. areaNum := c.DefaultQuery("area_num", "")
  854. err, errMsg := userLogic.PcSendSmsCode(mobile, areaNum)
  855. if err != nil {
  856. if errMsg != "" {
  857. errMsg = "获取验证码失败"
  858. } else {
  859. errMsg = err.Error()
  860. }
  861. response.Fail(errMsg, c)
  862. return
  863. }
  864. response.Ok("获取验证码成功", c)
  865. }
  866. // GetEmailCode 获取邮箱验证码接口
  867. // @Tags 用户模块
  868. // @Summary 获取邮箱验证码
  869. // @Description 获取邮箱验证码
  870. // @Security ApiKeyAuth
  871. // @securityDefinitions.basic BasicAuth
  872. // @Param email query string true "电子邮箱账号"
  873. // @Accept json
  874. // @Product json
  875. // @Success 200 {string} string 获取验证码成功
  876. // @Failure 400 {string} string 请输入邮箱地址
  877. // @Router /pc_code/get_email_code [get]
  878. func GetEmailCode(c *gin.Context) {
  879. email := c.DefaultQuery("email", "")
  880. if email == "" {
  881. response.Fail("请输入邮箱地址", c)
  882. return
  883. }
  884. if !utils.ValidateEmailFormatat(email) {
  885. response.Fail("邮箱格式错误,请重新输入", c)
  886. return
  887. }
  888. err, errMsg := userLogic.PcSendEmailCode(email)
  889. if err != nil {
  890. if errMsg != "" {
  891. errMsg = "获取验证码失败"
  892. } else {
  893. errMsg = err.Error()
  894. }
  895. response.Fail(errMsg, c)
  896. return
  897. }
  898. response.Ok("获取验证码成功", c)
  899. }