article.go 19 KB

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