pc.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950
  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, err := pcModels.GetRecommendListV2(reportId, reportType, reportInfo.ClassifyIdFirst, reportInfo.ClassifyIdSecond, reportInfo.ClassifyIdThird)
  396. if err != nil {
  397. response.Fail("获取报告详情失败"+err.Error(), c)
  398. return
  399. }
  400. for _, chapter := range recommendList {
  401. resp := &pcModels.RecommendResp{
  402. ReportId: chapter.Id,
  403. ReportChapterID: 0,
  404. Title: chapter.Title,
  405. Stage: chapter.Stage,
  406. ClassifyNameFirst: chapter.ClassifyNameFirst,
  407. ClassifySecondFirst: chapter.ClassifyNameSecond,
  408. }
  409. recommendResp = append(recommendResp, resp)
  410. }
  411. }
  412. response.OkData("查询成功", recommendResp, c)
  413. return
  414. }
  415. // ClassifyFirstList Ficc 菜单
  416. func ClassifyFirstList(c *gin.Context) {
  417. userinfo := userService.GetInfoByClaims(c)
  418. classList, err := pc.GetClassifyFirstList(userinfo)
  419. if err != nil {
  420. response.Fail(err.Error(), c)
  421. return
  422. }
  423. response.OkData("查询成功", classList, c)
  424. return
  425. }
  426. // CustomerComment 客户评价
  427. func CustomerComment(c *gin.Context) {
  428. lists, err := customer_comment.GetCustomerComment()
  429. if err != nil {
  430. response.Fail(err.Error(), c)
  431. return
  432. }
  433. response.OkData("查询成功", lists, c)
  434. return
  435. }
  436. // GetSunCode 获取太阳码
  437. // @Tags 公共模块
  438. // @Summary 获取分享海报
  439. // @Description 获取分享海报
  440. // @Param request body services.SunCodeReq true "type json string"
  441. // @Success 200 {object} string "获取成功"
  442. // @failure 400 {string} string "获取失败"
  443. // @Router /pc/getSunCode [post]
  444. func GetSunCode(c *gin.Context) {
  445. var req services.SunCodeReq
  446. if c.ShouldBind(&req) != nil {
  447. response.Fail("参数异常", c)
  448. return
  449. }
  450. var sunCodeUrl string
  451. //先查,查不到再去生成上传
  452. item, err := yb_pc_suncode.GetYbPcSunCode(req.CodeScene, req.CodePage)
  453. if err != nil && err != utils.ErrNoRow {
  454. response.FailMsg("获取太阳码失败", err.Error(), c)
  455. return
  456. }
  457. if item != nil && item.SuncodeURL != "" {
  458. sunCodeUrl = item.SuncodeURL
  459. }
  460. if sunCodeUrl == "" {
  461. sunCodeUrl, err = services.PcCreateAndUploadSunCode(req.CodeScene, req.CodePage)
  462. if err != nil {
  463. response.FailMsg("生成太阳码失败", err.Error(), c)
  464. return
  465. }
  466. }
  467. response.OkData("查询成功", sunCodeUrl, c)
  468. return
  469. }
  470. // @Title pc端微信登录接口
  471. // @Description pc端微信登录接口
  472. // @Param Code query string true "微信唯一编码code"
  473. // @Success 200 {object} models.WxLoginResp
  474. // @router /pc/login [get]
  475. func WechatLogin(c *gin.Context) {
  476. var resp pcModels.LoginResp
  477. var token string
  478. var userId int
  479. var isBind bool
  480. code := c.DefaultQuery("Code", "")
  481. if code == "" {
  482. response.Fail("code参数错误", c)
  483. return
  484. }
  485. item, err := wechat.PcWxGetUserOpenIdByCode(code)
  486. if err != nil {
  487. response.Fail(err.Error(), c)
  488. return
  489. }
  490. fmt.Println("token:", item.AccessToken)
  491. fmt.Println("token:", item.Errmsg)
  492. fmt.Println("token:", item.Errcode)
  493. if item.Errcode != 0 {
  494. response.Fail(item.Errmsg, c)
  495. return
  496. }
  497. openId := item.Openid
  498. //wxUserInfo, err := wx_app.GetSession(code)
  499. //if err != nil {
  500. // response.Fail("获取失败,Err:"+err.Error(), c)
  501. // return
  502. //}
  503. //获取用户信息
  504. wxPcUserInfo, err := wechat.PcWxGetUserInfo(openId, item.AccessToken)
  505. if err != nil {
  506. response.Fail(err.Error(), c)
  507. return
  508. }
  509. if wxPcUserInfo.Errcode != 0 {
  510. response.Fail(err.Error(), c)
  511. return
  512. }
  513. unionId := item.Unionid
  514. //sessionKey := wxUserInfo.SessionKey
  515. //needUpdateSessionKey := true //是否更新sessionKey
  516. QUERY_WX_USER:
  517. wxUser, wxUserErr := userService.GetWxUserItemByOpenId(openId)
  518. if wxUserErr == userService.ERR_NO_USER_RECORD { //没有用户openid记录
  519. _, recordErr := userService.AddUserRecord(openId, unionId, "", "", "", "", "", "", "", 3, 0, 0)
  520. //如果插入失败,那么直接将错误信息返回
  521. if recordErr != nil {
  522. err = recordErr
  523. return
  524. }
  525. //needUpdateSessionKey = false //因为是新增用户微信信息,所以不需要更新sessionKey的数据了
  526. //插入成功后,需要重新查询该用户,并进入下面的逻辑
  527. goto QUERY_WX_USER
  528. } else if wxUserErr == userService.ERR_USER_NOT_BIND {
  529. // 未绑定则去查询unionId是否已经绑定了用户(其他平台,不区分平台),有相应的手机号邮箱信息则自动绑定
  530. //platformUser, platformErr := userService.GetFirstWxUserItemByUnionId(unionId)
  531. //if platformErr == nil {
  532. // // 当公众号用户存在时
  533. // if platformUser.Mobile != "" || platformUser.Email != "" {
  534. // // 有手机号或邮箱则绑定信息则自动绑定并新增wx_user
  535. // countryCode := 0
  536. // if platformUser.CountryCode != "" {
  537. // countryCode, _ = strconv.Atoi(platformUser.CountryCode)
  538. // }
  539. // tempToken, tempUser, tempErr, errMsg := userService.BindWxUser(openId, platformUser.Mobile, platformUser.Email, "", 3, countryCode, 1)
  540. // if tempErr != nil {
  541. // err = errors.New("自动绑定公众号用户失败,Err:" + tempErr.Error() + ", errMsg:" + errMsg)
  542. // return
  543. // }
  544. // token = tempToken
  545. // userId = int(tempUser.UserID)
  546. // isBind = true
  547. // }
  548. //}
  549. } else if wxUserErr != nil {
  550. err = wxUserErr
  551. return
  552. }
  553. //更新微信用户的sessionKey
  554. //if needUpdateSessionKey {
  555. // _ = user_record.ModifySessionKeyByOpenid(openId, sessionKey)
  556. //}
  557. // 如果已经登录注册绑定的情况下/或者首次登录且为弘则研究公众号用户
  558. if wxUserErr == nil {
  559. userId = int(wxUser.UserID)
  560. // 如果账户有绑定了手机号或者邮箱,那么标记为已绑定
  561. if wxUser.Mobile != "" || wxUser.Email != "" {
  562. isBind = true
  563. }
  564. }
  565. //获取登录token
  566. tokenItem, tokenErr := session.GetTokenByOpenId(openId)
  567. if tokenErr != nil && tokenErr != utils.ErrNoRow {
  568. err = errors.New("登录失败,获取token失败:" + tokenErr.Error())
  569. return
  570. }
  571. fmt.Println("AccessToken:", item.AccessToken)
  572. fmt.Println("tokenItem:", tokenItem.AccessToken)
  573. if tokenErr != nil && tokenErr == utils.ErrNoRow {
  574. timeUnix := time.Now().Unix()
  575. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  576. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  577. fmt.Println("token:", tokenItem.AccessToken)
  578. //新增session
  579. {
  580. sessionItem := &session.Session{
  581. OpenID: openId,
  582. UserID: int64(userId),
  583. CreatedTime: time.Now(),
  584. LastUpdatedTime: time.Now(),
  585. ExpireTime: time.Now().AddDate(0, 3, 0),
  586. AccessToken: token,
  587. }
  588. sessionErr := sessionItem.Create()
  589. if err != nil {
  590. err = errors.New("登录失败,新增用户session信息失败:" + sessionErr.Error())
  591. return
  592. }
  593. }
  594. } else {
  595. token = tokenItem.AccessToken
  596. //如果联系人编号不为空,且联系人编号与session里面的联系人编号不一致的时候,需要做session变更
  597. //if userId > 0 && tokenItem.UserID != int64(userId) {
  598. // _ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
  599. //}
  600. //if userId > 0 {
  601. //}
  602. _ = tokenItem.UpdateSession(int64(userId), time.Now().AddDate(0, 1, 0))
  603. }
  604. //新增登录日志
  605. {
  606. loginLog := &wx_user_log.WxUserLog{
  607. UserID: userId,
  608. OpenID: openId,
  609. UnionID: unionId,
  610. CreateTime: time.Now(),
  611. Handle: "yb_login",
  612. Remark: token,
  613. }
  614. go loginLog.Create()
  615. }
  616. resp.IsBind = isBind
  617. resp.Token = token
  618. response.OkData("查询成功", resp, c)
  619. return
  620. }
  621. // @Title 登录
  622. // @Description 登录接口
  623. // @Param request body models.LoginReq true "type json string"
  624. // @Success 200 {object} models.LoginResp
  625. // @router /pc/pcLogin [post]
  626. func PcLogin(c *gin.Context) {
  627. var req pcModels.PcLoginReq
  628. if c.ShouldBind(&req) != nil {
  629. response.Fail("参数异常", c)
  630. return
  631. }
  632. userId := 0
  633. var isAdd bool
  634. if req.LoginType == 1 {
  635. if req.Mobile == "" {
  636. response.Fail("请输入手机号", c)
  637. return
  638. }
  639. if req.SmsCode == "" {
  640. response.Fail("请输入有效手机验证码", c)
  641. return
  642. }
  643. item, err := msg_code.GetMsgCode(req.Mobile, req.SmsCode)
  644. if err != nil {
  645. if err == utils.ErrNoRow {
  646. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  647. return
  648. } else {
  649. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  650. return
  651. }
  652. }
  653. if item == nil {
  654. response.Fail("手机验证码错误,请重新输入", c)
  655. return
  656. }
  657. if item.Code != req.SmsCode {
  658. response.Fail("验证码失效,请重新最新验证码", c)
  659. return
  660. }
  661. wxUser, err := wx_user.GetByMobile(req.Mobile)
  662. if err != nil {
  663. if err == utils.ErrNoRow {
  664. isAdd = true
  665. } else {
  666. response.Fail("根据手机号获取用户信息失败,Err:"+err.Error(), c)
  667. return
  668. }
  669. }
  670. if wxUser == nil {
  671. isAdd = true
  672. } else {
  673. userId = int(wxUser.UserID)
  674. }
  675. //BindMobile(openId, mobile string, userId, loginType int) (err error) {
  676. //newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
  677. } else if req.LoginType == 2 {
  678. if req.Email == "" {
  679. response.Fail("邮箱不能为空,请输入邮箱", c)
  680. return
  681. }
  682. if !utils.ValidateEmailFormatat(req.Email) {
  683. response.Fail("邮箱格式错误,请重新输入", c)
  684. return
  685. }
  686. if req.SmsCode == "" {
  687. response.Fail("请输入有效验证码", c)
  688. return
  689. }
  690. item, err := msg_code.GetMsgCode(req.Email, req.SmsCode)
  691. if err != nil {
  692. if err == utils.ErrNoRow {
  693. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  694. return
  695. } else {
  696. response.Fail("校验验证码失败,Err:"+err.Error(), c)
  697. return
  698. }
  699. }
  700. if item == nil {
  701. response.Fail("邮箱证码错误,请重新输入:", c)
  702. return
  703. }
  704. wxUser, err := wx_user.GetByEmail(req.Email)
  705. if err != nil {
  706. if err == utils.ErrNoRow {
  707. isAdd = true
  708. } else {
  709. response.Fail("根据邮箱获取用户信息失败,Err:"+err.Error(), c)
  710. return
  711. }
  712. }
  713. if wxUser == nil {
  714. isAdd = true
  715. } else {
  716. userId = int(wxUser.UserID)
  717. }
  718. } else {
  719. response.Fail("无效的登录方式,loginType:"+strconv.Itoa(req.LoginType), c)
  720. }
  721. if isAdd {
  722. user := new(wx_user.WxUser)
  723. user.CompanyID = 1
  724. user.CreatedTime = time.Now()
  725. user.FirstLogin = 1
  726. user.Enabled = 1
  727. user.Email = req.Email
  728. user.Mobile = req.Mobile
  729. if req.LoginType == 1 {
  730. user.BindAccount = user.Mobile
  731. } else {
  732. user.BindAccount = user.Email
  733. }
  734. user.RegisterTime = time.Now()
  735. user.LoginTime = time.Now()
  736. user.RegisterPlatform = 2
  737. if req.IsFreeLogin {
  738. user.IsFreeLogin = 1
  739. } else {
  740. user.IsFreeLogin = 0
  741. }
  742. lastId, err := user.Add()
  743. if err != nil {
  744. response.Fail("登录失败,新增客户信息失败,Err:"+err.Error(), c)
  745. return
  746. }
  747. fmt.Println("lastId:", lastId)
  748. userId = int(lastId)
  749. timeUnix := time.Now().Unix()
  750. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  751. token := utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
  752. //新增session
  753. {
  754. session := new(session.Session)
  755. session.UserID = int64(userId)
  756. session.CreatedTime = time.Now()
  757. session.LastUpdatedTime = time.Now()
  758. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  759. session.AccessToken = token
  760. err = session.Create()
  761. if err != nil {
  762. response.Fail("登录失败,新增用户session信息失败:"+err.Error(), c)
  763. return
  764. }
  765. }
  766. } else {
  767. user := new(wx_user.WxUser)
  768. user.UserID = uint64(userId)
  769. if req.IsFreeLogin {
  770. user.IsFreeLogin = 1
  771. } else {
  772. user.IsFreeLogin = 0
  773. }
  774. err := user.Update([]string{"is_free_login"})
  775. if err != nil {
  776. response.Fail("登录失败,修改登录信息失败,Err:"+err.Error(), c)
  777. return
  778. }
  779. }
  780. if userId == 0 {
  781. response.Fail("登录失败,id为 0", c)
  782. return
  783. }
  784. err := wx_user.ModifyFirstLogin(uint64(userId))
  785. if err != nil {
  786. response.Fail("登录失败,判断权限失败:"+err.Error(), c)
  787. return
  788. }
  789. var token string
  790. tokenItem, err := session.GetTokenByUid(userId)
  791. if err != nil && err != utils.ErrNoRow {
  792. response.Fail("登录失败,获取token失败:"+err.Error(), c)
  793. return
  794. }
  795. if tokenItem == nil || (err != nil && err == utils.ErrNoRow) {
  796. timeUnix := time.Now().Unix()
  797. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  798. token = utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
  799. //新增session
  800. {
  801. session := new(session.Session)
  802. session.UserID = int64(userId)
  803. session.CreatedTime = time.Now()
  804. session.LastUpdatedTime = time.Now()
  805. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  806. session.AccessToken = token
  807. err = session.Create()
  808. if err != nil {
  809. response.Fail("登录失败,新增用户session信息失败:"+err.Error(), c)
  810. return
  811. }
  812. }
  813. } else {
  814. token = tokenItem.AccessToken
  815. }
  816. //新增登录日志
  817. {
  818. loginLog := new(wx_user_log.WxUserLog)
  819. loginLog.UserID = userId
  820. loginLog.Mobile = req.Mobile
  821. loginLog.Email = req.Email
  822. loginLog.Handle = "pc_login"
  823. loginLog.CreateTime = time.Now()
  824. go loginLog.Create()
  825. }
  826. response.OkData("登录成功", token, c)
  827. }
  828. // GetSmsCode 获取短信验证码接口
  829. // @Tags 用户模块
  830. // @Summary 获取短信验证码
  831. // @Description 获取短信验证码接口
  832. // @Security ApiKeyAuth
  833. // @securityDefinitions.basic BasicAuth
  834. // @Param mobile query string true "手机号"
  835. // @Param area_num query string true "手机国际区号(中国大陆:86)"
  836. // @Accept json
  837. // @Product json
  838. // @Success 200 {string} string 获取验证码成功
  839. // @Failure 400 {string} string 手机号不能为空,请输入手机号
  840. // @Router /pc_code/get_sms_code [get]
  841. func GetSmsCode(c *gin.Context) {
  842. mobile := c.DefaultQuery("mobile", "")
  843. areaNum := c.DefaultQuery("area_num", "")
  844. err, errMsg := userLogic.PcSendSmsCode(mobile, areaNum)
  845. if err != nil {
  846. if errMsg != "" {
  847. errMsg = "获取验证码失败"
  848. } else {
  849. errMsg = err.Error()
  850. }
  851. response.Fail(errMsg, c)
  852. return
  853. }
  854. response.Ok("获取验证码成功", c)
  855. }
  856. // GetEmailCode 获取邮箱验证码接口
  857. // @Tags 用户模块
  858. // @Summary 获取邮箱验证码
  859. // @Description 获取邮箱验证码
  860. // @Security ApiKeyAuth
  861. // @securityDefinitions.basic BasicAuth
  862. // @Param email query string true "电子邮箱账号"
  863. // @Accept json
  864. // @Product json
  865. // @Success 200 {string} string 获取验证码成功
  866. // @Failure 400 {string} string 请输入邮箱地址
  867. // @Router /pc_code/get_email_code [get]
  868. func GetEmailCode(c *gin.Context) {
  869. email := c.DefaultQuery("email", "")
  870. if email == "" {
  871. response.Fail("请输入邮箱地址", c)
  872. return
  873. }
  874. if !utils.ValidateEmailFormatat(email) {
  875. response.Fail("邮箱格式错误,请重新输入", c)
  876. return
  877. }
  878. err, errMsg := userLogic.PcSendEmailCode(email)
  879. if err != nil {
  880. if errMsg != "" {
  881. errMsg = "获取验证码失败"
  882. } else {
  883. errMsg = err.Error()
  884. }
  885. response.Fail(errMsg, c)
  886. return
  887. }
  888. response.Ok("获取验证码成功", c)
  889. }