article.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hongze_clpt/models"
  6. "hongze/hongze_clpt/services"
  7. "hongze/hongze_clpt/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. type ArticleController struct {
  13. BaseAuthController
  14. }
  15. type ArticleCommonController struct {
  16. BaseCommonController
  17. }
  18. // @Title 获取报告详情
  19. // @Description 获取报告详情接口
  20. // @Param ArticleId query int true "报告ID"
  21. // @Success 200 {object} models.ArticleDetailResp
  22. // @router /detail [get]
  23. func (this *ArticleController) Detail() {
  24. br := new(models.BaseResponse).Init()
  25. defer func() {
  26. this.Data["json"] = br
  27. this.ServeJSON()
  28. }()
  29. user := this.User
  30. if user == nil {
  31. br.Msg = "请登录"
  32. br.ErrMsg = "请登录,用户信息为空"
  33. br.Ret = 408
  34. return
  35. }
  36. resp := new(models.ArticleDetailResp)
  37. uid := user.UserId
  38. articleId, err := this.GetInt("ArticleId")
  39. if articleId <= 0 {
  40. br.Msg = "文章不存在"
  41. br.ErrMsg = "文章不存在,文章ID错误"
  42. return
  43. }
  44. detail := new(models.ArticleDetail)
  45. hasPermission := 0
  46. hasFree := 0
  47. var haveResearch bool
  48. //判断是否已经申请过
  49. applyCount, err := models.GetApplyRecordCount(uid)
  50. if err != nil && err.Error() != utils.ErrNoRow() {
  51. br.Msg = "获取信息失败"
  52. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  53. return
  54. }
  55. //resp := new(models.ArticleDetailResp)
  56. detail, err = models.GetArticleDetailById(articleId)
  57. if err != nil {
  58. br.Msg = "获取信息失败"
  59. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  60. return
  61. }
  62. // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面
  63. if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID {
  64. _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  65. if err != nil {
  66. br.Msg = "获取信息失败"
  67. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  68. return
  69. }
  70. resp.PopupMsg = popupMsg
  71. resp.HasPermission = 3
  72. resp.SellerName = sellerName
  73. resp.SellerMobile = sellerMobile
  74. detail.Body = ""
  75. detail.Abstract = ""
  76. detail.Seller.SellerName = sellerName
  77. detail.Seller.SellerMobile = sellerMobile
  78. resp.Detail = detail
  79. br.Ret = 200
  80. br.Success = true
  81. br.Msg = "获取成功"
  82. br.Data = resp
  83. return
  84. }
  85. //是否属于专项调研报告
  86. if detail.SubCategoryName == "专项调研" {
  87. detail.IsSpecialArticle = true
  88. havePower, err := services.GetSpecialArticleDetailUserPower(user, detail)
  89. if err != nil {
  90. br.Msg = "获取信息失败"
  91. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  92. return
  93. }
  94. resp.IsSpecialArticle = true
  95. if !havePower {
  96. hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user)
  97. if err != nil {
  98. br.Msg = "获取信息失败"
  99. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  100. return
  101. }
  102. resp.PopupMsg = popupMsg
  103. resp.HasPermission = hasPermission
  104. resp.SellerName = sellerName
  105. resp.SellerMobile = sellerMobile
  106. detail.Body = ""
  107. detail.Abstract = ""
  108. detail.Seller.SellerName = sellerName
  109. detail.Seller.SellerMobile = sellerMobile
  110. resp.Detail = detail
  111. br.Ret = 200
  112. br.Success = true
  113. br.Msg = "获取成功"
  114. br.Data = resp
  115. return
  116. }
  117. }
  118. //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
  119. if user.CompanyId > 1 {
  120. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  121. if err != nil {
  122. br.Msg = "获取信息失败"
  123. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  124. return
  125. }
  126. detail, err = models.GetArticleDetailById(articleId)
  127. if err != nil {
  128. br.Msg = "获取信息失败"
  129. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  130. return
  131. }
  132. detail.Body = services.GetReportContentTextArticleBody(detail.Body)
  133. detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract)
  134. if companyPermission == "" {
  135. if applyCount > 0 {
  136. hasPermission = 6
  137. } else {
  138. hasPermission = 2
  139. }
  140. hasFree = 2
  141. goto Loop
  142. } else {
  143. hasPermission = 1
  144. hasFree = 1
  145. var articlePermissionPermissionName string
  146. if detail.CategoryId > 0 {
  147. articlePermission, err := models.GetArticlePermission(detail.CategoryId)
  148. if err != nil {
  149. br.Msg = "获取信息失败"
  150. br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  151. return
  152. }
  153. if articlePermission == nil {
  154. br.Msg = "获取信息失败"
  155. br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  156. return
  157. }
  158. articlePermissionPermissionName = articlePermission.PermissionName
  159. } else {
  160. articlePermissionPermissionName = detail.CategoryName
  161. }
  162. var hasPersion bool
  163. slice := strings.Split(articlePermissionPermissionName, ",")
  164. for _, v := range slice {
  165. if strings.Contains(companyPermission, v) {
  166. hasPersion = true
  167. }
  168. }
  169. userType, _, err := services.GetUserType(user.CompanyId)
  170. if err != nil {
  171. br.Msg = "获取信息失败"
  172. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  173. return
  174. }
  175. if userType == 1 && strings.Contains(detail.CategoryName, "研选") {
  176. hasPersion = false
  177. }
  178. if detail.IsReport == 1 {
  179. detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId)
  180. if err != nil && err.Error() != utils.ErrNoRow() {
  181. br.Msg = "获取信息失败"
  182. br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId)
  183. return
  184. }
  185. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  186. if err != nil {
  187. br.Msg = "获取信息失败"
  188. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  189. return
  190. }
  191. if detailCategory != nil {
  192. if detailCategory.PermissionType == 1 {
  193. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") {
  194. hasPersion = false
  195. }
  196. } else if detailCategory.PermissionType == 2 {
  197. if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") {
  198. hasPersion = false
  199. }
  200. }
  201. }
  202. }
  203. if !hasPersion {
  204. if applyCount == 0 {
  205. hasPermission = 4
  206. } else {
  207. hasPermission = 3
  208. }
  209. }
  210. }
  211. collectCount, err := models.GetArticleCollectCount(uid, articleId)
  212. if err != nil && err.Error() != utils.ErrNoRow() {
  213. br.Msg = "获取信息失败"
  214. br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  215. return
  216. }
  217. if collectCount > 0 {
  218. detail.IsCollect = true
  219. }
  220. interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
  221. if err != nil && err.Error() != utils.ErrNoRow() {
  222. br.Msg = "获取信息失败"
  223. br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  224. return
  225. }
  226. if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 {
  227. detail.IsInterviewApply = true
  228. detail.InterviewApplyStatus = interviewApplyItem.Status
  229. }
  230. //获取销售手机号
  231. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  232. if err != nil && err.Error() != utils.ErrNoRow() {
  233. br.Msg = "获取信息失败"
  234. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  235. return
  236. }
  237. if sellerItem != nil {
  238. detail.Seller.SellerMobile = sellerItem.Mobile
  239. detail.Seller.SellerName = sellerItem.RealName
  240. }
  241. //作者头像
  242. if detail.DepartmentId > 0 {
  243. departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId)
  244. if err == nil {
  245. detail.DepartmentDetail = departmentDetail
  246. }
  247. }
  248. } else { //潜在客户
  249. if applyCount > 0 {
  250. hasPermission = 6
  251. } else {
  252. hasPermission = 5
  253. }
  254. }
  255. Loop:
  256. if hasPermission != 1 {
  257. detail.Body = ""
  258. } else {
  259. articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid)
  260. if err != nil {
  261. br.Msg = "获取信息失败"
  262. br.ErrMsg = "获取关注信息失败,Err:" + err.Error()
  263. return
  264. }
  265. detail.FollowNum = articleFollowdetail.DNum
  266. detail.CollectionNum = articleFollowdetail.AcNum
  267. detail.Disclaimers = utils.DISCLAIMERS
  268. if articleFollowdetail.MdNum > 0 {
  269. detail.IsFollow = true
  270. }
  271. haveResearch = true
  272. }
  273. if hasPermission == 2 || hasPermission == 4 {
  274. //获取销售手机号
  275. sellerItem, err := models.GetSellerByCompanyId(user.CompanyId)
  276. if err != nil && err.Error() != utils.ErrNoRow() {
  277. br.Msg = "获取信息失败"
  278. br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
  279. return
  280. }
  281. if sellerItem != nil {
  282. detail.Seller.SellerMobile = sellerItem.Mobile
  283. detail.Seller.SellerName = sellerItem.RealName
  284. }
  285. }
  286. if detail.ArticleId < utils.SummaryArticleId {
  287. if user.Mobile != "" {
  288. chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile)
  289. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile
  290. } else {
  291. detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId)
  292. }
  293. detail.IsNeedJump = true
  294. }
  295. //hasFree := 0
  296. //var haveResearch bool
  297. fmt.Println(hasFree)
  298. fmt.Println(haveResearch)
  299. if hasPermission == 1 {
  300. go services.ArticleHistory(articleId, user)
  301. key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
  302. if !utils.Rc.IsExist(key) {
  303. go services.ArticleUserRemind(user, detail, 1)
  304. utils.Rc.Put(key, 1, 30*time.Second)
  305. }
  306. }
  307. if detail.SubCategoryName == "专项调研" {
  308. detail.IsSpecialArticle = true
  309. }
  310. resp.HasPermission = hasPermission
  311. resp.IsSpecialArticle = detail.IsSpecialArticle
  312. resp.Detail = detail
  313. br.Ret = 200
  314. br.Success = true
  315. br.Msg = "获取成功"
  316. br.Data = resp
  317. }
  318. // @Title 收藏\取消收藏
  319. // @Description 收藏\取消收藏
  320. // @Param request body models.ArticleCollectReq true "type json string"
  321. // @Success 200 {object} models.ArticleCollectResp
  322. // @router /collect [post]
  323. func (this *ArticleController) ArticleCollect() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. this.Data["json"] = br
  327. this.ServeJSON()
  328. }()
  329. user := this.User
  330. if user == nil {
  331. br.Msg = "请重新登录"
  332. br.Ret = 408
  333. return
  334. }
  335. uid := user.UserId
  336. var req models.ArticleCollectReq
  337. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  338. if err != nil {
  339. br.Msg = "参数解析异常!"
  340. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  341. return
  342. }
  343. articleId := req.ArticleId
  344. detail, err := models.GetArticleDetailById(articleId)
  345. if err != nil {
  346. br.Msg = "获取信息失败"
  347. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  348. return
  349. }
  350. count, err := models.GetArticleCollectCount(uid, articleId)
  351. if err != nil {
  352. br.Msg = "获取数据失败!"
  353. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  354. return
  355. }
  356. resp := new(models.ArticleCollectResp)
  357. if count <= 0 {
  358. item := new(models.CygxArticleCollect)
  359. item.ArticleId = req.ArticleId
  360. item.UserId = uid
  361. item.CreateTime = time.Now()
  362. item.Mobile = user.Mobile
  363. item.Email = user.Email
  364. item.CompanyId = user.CompanyId
  365. item.CompanyName = user.CompanyName
  366. item.RealName = user.RealName
  367. _, err = models.AddCygxArticleCollect(item)
  368. if err != nil {
  369. br.Msg = "收藏失败"
  370. br.ErrMsg = "收藏失败,Err:" + err.Error()
  371. return
  372. }
  373. br.Msg = "收藏成功"
  374. resp.Status = 1
  375. // 文章收藏消息发送
  376. go services.ArticleUserRemind(user, detail, 1)
  377. } else {
  378. err = models.RemoveArticleCollect(uid, articleId)
  379. if err != nil {
  380. br.Msg = "取消收藏失败"
  381. br.ErrMsg = "取消收藏失败,Err:" + err.Error()
  382. return
  383. }
  384. br.Msg = "已取消收藏"
  385. resp.Status = 2
  386. }
  387. collectTotal, err := models.GetArticleCollectUsersCount(articleId)
  388. if err != nil {
  389. br.Msg = "获取数据失败"
  390. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  391. return
  392. }
  393. resp.CollectCount = collectTotal
  394. br.Ret = 200
  395. br.Success = true
  396. br.Data = resp
  397. }
  398. // @Title 访谈申请\取消访谈申请
  399. // @Description 访谈申请\取消访谈申请
  400. // @Param request body models.ArticleInterviewApplyReq true "type json string"
  401. // @Success 200 {object} models.FontsCollectResp
  402. // @router /interview/apply [post]
  403. func (this *ArticleController) InterviewApply() {
  404. br := new(models.BaseResponse).Init()
  405. defer func() {
  406. this.Data["json"] = br
  407. this.ServeJSON()
  408. }()
  409. user := this.User
  410. if user == nil {
  411. br.Msg = "请重新登录"
  412. br.Ret = 408
  413. return
  414. }
  415. uid := user.UserId
  416. var req models.ArticleInterviewApplyReq
  417. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  418. if err != nil {
  419. br.Msg = "参数解析异常!"
  420. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  421. return
  422. }
  423. article, err := models.GetArticleDetailById(req.ArticleId)
  424. if err != nil {
  425. br.Msg = "获取纪要失败!"
  426. br.ErrMsg = "获取纪要失败,Err:" + err.Error()
  427. return
  428. }
  429. count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId)
  430. if err != nil {
  431. br.Msg = "获取数据失败!"
  432. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  433. return
  434. }
  435. resp := new(models.ArticleInterviewApplyResp)
  436. if count <= 0 {
  437. item := new(models.CygxInterviewApply)
  438. item.ArticleId = req.ArticleId
  439. item.UserId = uid
  440. item.CompanyId = user.CompanyId
  441. item.Status = "待邀请"
  442. item.Sort = 1
  443. item.ArticleTitle = article.Title
  444. item.CreateTime = time.Now()
  445. item.ModifyTime = time.Now()
  446. item.ArticleIdMd5 = article.ArticleIdMd5
  447. _, err = models.AddCygxInterviewApply(item)
  448. if err != nil {
  449. br.Msg = "申请失败"
  450. br.ErrMsg = "申请失败,Err:" + err.Error()
  451. return
  452. }
  453. br.Msg = "申请成功"
  454. resp.Status = 1
  455. //发送模板消息
  456. if user.CompanyId > 1 {
  457. mobile := user.Mobile
  458. if mobile == "" {
  459. mobile = user.Email
  460. }
  461. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  462. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  463. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  464. if openIpItem != nil && openIpItem.OpenId != "" {
  465. go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  466. }
  467. }
  468. }
  469. } else {
  470. err = models.RemoveArticleInterviewApply(uid, req.ArticleId)
  471. if err != nil {
  472. br.Msg = "取消申请失败"
  473. br.ErrMsg = "取消申请失败,Err:" + err.Error()
  474. return
  475. }
  476. br.Msg = "已取消申请"
  477. resp.Status = 2
  478. if user.CompanyId > 1 {
  479. mobile := user.Mobile
  480. if mobile == "" {
  481. mobile = user.Email
  482. }
  483. sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId)
  484. if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" {
  485. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  486. if openIpItem != nil && openIpItem.OpenId != "" {
  487. go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem)
  488. }
  489. }
  490. }
  491. }
  492. br.Ret = 200
  493. br.Success = true
  494. br.Data = resp
  495. }
  496. // @Title 文章带问
  497. // @Description 新增文章带问接口
  498. // @Param request body models.AddArticleAskRep true "type json string"
  499. // @Success Ret=200 新增成功
  500. // @router /askAdd [post]
  501. func (this *ArticleController) AskAdd() {
  502. br := new(models.BaseResponse).Init()
  503. defer func() {
  504. this.Data["json"] = br
  505. this.ServeJSON()
  506. }()
  507. user := this.User
  508. if user == nil {
  509. br.Msg = "请登录"
  510. br.ErrMsg = "请登录,SysUser Is Empty"
  511. br.Ret = 408
  512. return
  513. }
  514. var req models.AddArticleAskRep
  515. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  516. if err != nil {
  517. br.Msg = "参数解析异常!"
  518. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  519. return
  520. }
  521. if req.Content == "" {
  522. br.Msg = "建议内容不可为空"
  523. return
  524. }
  525. content := req.Content
  526. //accessToken, err := models.GetWxAccessTokenByXzs()
  527. //itemToken, err := services.WxGetToken()
  528. //if err != nil {
  529. // br.Msg = "GetWxAccessToken Err:" + err.Error()
  530. // return
  531. //}
  532. //if accessToken == "" {
  533. // br.Msg = "accessToken is empty"
  534. // return
  535. //}
  536. //commerr, err := weapp.MSGSecCheck(accessToken, content)
  537. //if err != nil {
  538. // br.Msg = "内容校验失败!"
  539. // br.ErrMsg = "内容校验失败,Err:" + err.Error()
  540. //
  541. // return
  542. //}
  543. //fmt.Println(commerr)
  544. //if commerr.ErrCode != 0 {
  545. // br.Msg = "内容违规,请重新提交!"
  546. // br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  547. // return
  548. //}
  549. articleId := req.ArticleId
  550. count, _ := models.GetArticleCountById(articleId)
  551. if count == 0 {
  552. br.Msg = "操作失败"
  553. br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId)
  554. return
  555. }
  556. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  557. if err != nil {
  558. br.Msg = "提交失败!"
  559. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  560. return
  561. }
  562. if companyDetail == nil {
  563. br.Msg = "提交失败!"
  564. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  565. return
  566. }
  567. item := new(models.CygxArticleAsk)
  568. item.UserId = user.UserId
  569. item.ArticleId = req.ArticleId
  570. item.CompanyId = user.CompanyId
  571. item.CompanyName = companyDetail.CompanyName
  572. item.CreateTime = time.Now()
  573. item.Mobile = user.Mobile
  574. item.Email = user.Email
  575. item.Content = content
  576. _, err = models.AddArticleAsk(item)
  577. if err != nil {
  578. br.Msg = "提交失败"
  579. br.ErrMsg = "提交失败,Err:" + err.Error()
  580. return
  581. }
  582. companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId)
  583. if err != nil {
  584. br.Msg = "获取信息失败"
  585. br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error()
  586. return
  587. }
  588. var mobile string
  589. if utils.RunMode == "release" {
  590. //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile
  591. mobile = utils.WxMsgTemplateIdAskMsgMobileAll
  592. } else {
  593. mobile = utils.WxMsgTemplateIdAskMsgMobile
  594. }
  595. openIdList, err := models.GetWxOpenIdByMobileList(mobile)
  596. if err != nil {
  597. br.Msg = "提交失败"
  598. br.ErrMsg = "提交失败,Err:" + err.Error()
  599. return
  600. }
  601. detail, err := models.GetArticleDetailById(articleId)
  602. if err != nil {
  603. br.Msg = "获取信息失败"
  604. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  605. return
  606. }
  607. companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")"
  608. go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId)
  609. br.Ret = 200
  610. br.Success = true
  611. br.Msg = "提交成功"
  612. }
  613. // @Title 文章相关热门收藏
  614. // @Description 文章相关热门收藏接口
  615. // @Param ArticleId query int true "文章ID"
  616. // @Success 200 {object} models.ArticleCollectionLIstResp
  617. // @router /hotList [get]
  618. func (this *ArticleController) ArticleHotList() {
  619. br := new(models.BaseResponse).Init()
  620. defer func() {
  621. this.Data["json"] = br
  622. this.ServeJSON()
  623. }()
  624. user := this.User
  625. if user == nil {
  626. br.Msg = "请重新登录"
  627. br.Ret = 408
  628. return
  629. }
  630. articleId, _ := this.GetInt("ArticleId")
  631. if articleId < 1 {
  632. br.Msg = "请输入分类ID"
  633. return
  634. }
  635. var condition string
  636. condition = ` AND a.article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id IN (SELECT industrial_management_id FROM cygx_industrial_article_group_management WHERE article_id = ` + strconv.Itoa(articleId) + ` ) ) AND a.article_id != ` + strconv.Itoa(articleId) + ` AND a.category_name LIKE '%研选%' AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num DESC, publish_date DESC LIMIT 3 `
  637. list, err := models.GetArticleCollectionList(condition, user.UserId)
  638. if err != nil {
  639. br.Msg = "获取信息失败"
  640. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  641. return
  642. }
  643. resp := new(models.ArticleCollectionLIstResp)
  644. if len(list) == 0 {
  645. list = make([]*models.ArticleCollectionResp, 0)
  646. }
  647. resp.List = list
  648. br.Ret = 200
  649. br.Success = true
  650. br.Msg = "获取成功"
  651. br.Data = resp
  652. }