user.go 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_web_mfyx/models"
  7. "hongze/hongze_web_mfyx/services"
  8. "hongze/hongze_web_mfyx/utils"
  9. "sort"
  10. "strconv"
  11. "strings"
  12. "time"
  13. )
  14. type UserController struct {
  15. BaseAuthController
  16. }
  17. type UserCommonController struct {
  18. BaseCommonController
  19. }
  20. // @Title 登录
  21. // @Description 登录接口
  22. // @Param request body models.LoginReq true "type json string"
  23. // @Success 200 {object} models.LoginResp
  24. // @router /login [post]
  25. func (this *UserCommonController) Login() {
  26. br := new(models.BaseResponse).Init()
  27. defer func() {
  28. this.Data["json"] = br
  29. this.ServeJSON()
  30. }()
  31. var token string
  32. var req models.LoginReq
  33. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  34. if err != nil {
  35. br.Msg = "参数解析异常!"
  36. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  37. return
  38. }
  39. mobile := req.Mobile
  40. req.Mobile = strings.Trim(req.Mobile, " ")
  41. if req.Mobile == "" {
  42. br.Msg = "参数错误"
  43. br.ErrMsg = "参数错误,手机号为空"
  44. return
  45. }
  46. code := req.VCode
  47. if code == "" {
  48. br.Msg = "参数错误"
  49. br.ErrMsg = "Code 为空"
  50. return
  51. }
  52. authorization := req.Token
  53. inviteShareCode := req.InviteShareCode
  54. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  55. if err != nil {
  56. if err.Error() == utils.ErrNoRow() {
  57. br.Msg = "验证码错误,请重新输入"
  58. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  59. return
  60. } else {
  61. br.Msg = "验证码错误,请重新输入"
  62. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  63. return
  64. }
  65. }
  66. if item == nil {
  67. br.Msg = "验证码错误,请重新输入"
  68. return
  69. }
  70. user, err := services.BindWxUser(mobile, "86", inviteShareCode)
  71. //user, err := models.GetWxUserItemByMobile(mobile)
  72. if err != nil {
  73. br.Msg = "登录失败"
  74. br.ErrMsg = "获取用户信息失败,GetUserDetailByMobile Err:" + err.Error()
  75. return
  76. }
  77. if authorization != "" {
  78. session, err := models.GetSessionByToken(authorization)
  79. if err != nil {
  80. br.Msg = "登录失败"
  81. br.ErrMsg = "绑定失败,GetSessionByToken err:" + err.Error()
  82. return
  83. }
  84. openid := session.OpenId
  85. if openid == "" {
  86. br.Msg = "登录失败"
  87. br.ErrMsg = "获取用户信息失败,绑定用户openid失败,OpenId不能为空 "
  88. return
  89. }
  90. err = models.BindSessionMobile(mobile, authorization)
  91. if err != nil {
  92. br.Msg = "登录失败"
  93. br.ErrMsg = "获取用户信息失败,BindSessionMobile Err:" + err.Error()
  94. return
  95. }
  96. err = models.BindUserRecordByOpenid(user.UserId, openid, mobile)
  97. if err != nil {
  98. br.Msg = "登录失败"
  99. br.ErrMsg = "获取用户信息失败,BindUserRecordByOpenid Err:" + err.Error()
  100. return
  101. }
  102. token = authorization
  103. } else {
  104. timeUnix := time.Now().Unix()
  105. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  106. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  107. itemsSession := new(models.CygxMfyxWebSession)
  108. itemsSession.UserId = user.UserId
  109. itemsSession.Mobile = mobile
  110. itemsSession.AccessToken = token
  111. itemsSession.CreatedTime = time.Now()
  112. itemsSession.LastUpdatedTime = time.Now()
  113. itemsSession.ExpireTime = time.Now().AddDate(0, 3, 0)
  114. err = models.AddCygxMfyxWebSession(itemsSession)
  115. if err != nil {
  116. br.Msg = "获取用户信息失败"
  117. br.ErrMsg = "添加Token失败,Err:" + err.Error()
  118. return
  119. }
  120. }
  121. {
  122. services.AddInviteCompany(user) //记录通过三方合作机构过来的公司
  123. }
  124. resp := new(models.LoginResp)
  125. resp.UserId = user.UserId
  126. resp.Headimgurl = user.Headimgurl
  127. resp.Mobile = user.Mobile
  128. resp.Email = user.Email
  129. resp.CompanyName = user.CompanyName
  130. resp.Authorization = token
  131. br.Ret = 200
  132. br.Success = true
  133. br.Msg = "获取成功"
  134. br.Data = resp
  135. }
  136. // @Title 获取用户详情
  137. // @Description 获取用户详情接口
  138. // @Success 200 {object} models.UserDetailResp
  139. // @router /detail [get]
  140. func (this *UserController) Detail() {
  141. br := new(models.BaseResponse).Init()
  142. defer func() {
  143. this.Data["json"] = br
  144. this.ServeJSON()
  145. }()
  146. user := this.User
  147. if user == nil {
  148. br.Msg = "请登录"
  149. br.ErrMsg = "请登录,用户信息为空"
  150. br.Ret = 408
  151. return
  152. }
  153. resp := new(models.UserDetailResp)
  154. resp.UserId = user.UserId
  155. resp.UserName = user.RealName
  156. resp.Headimgurl = user.Headimgurl
  157. resp.Mobile = user.Mobile
  158. resp.Email = user.Email
  159. resp.CompanyName = user.CompanyName
  160. userDetail, err := models.GetUserDetailByUserId(user.UserId)
  161. if err != nil {
  162. br.Msg = "获取用户信息失败"
  163. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  164. return
  165. }
  166. if userDetail.Mobile != "" {
  167. resp.InviteShareCode = services.GetInviteShareCode(userDetail.Mobile) //判断用户是否属于销售,并且获取对应加密的分享码
  168. }
  169. resp.OutboundCountryCode = userDetail.OutboundCountryCode
  170. resp.OutboundMobile = userDetail.OutboundMobile
  171. var hasPermission int
  172. if user.CompanyId > 1 {
  173. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  174. if err != nil && err.Error() != utils.ErrNoRow() {
  175. br.Msg = "获取信息失败"
  176. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  177. return
  178. }
  179. if companyItem != nil && companyItem.CompanyId > 0 {
  180. resp.CompanyName = companyItem.CompanyName
  181. // 获取用户所在公司剩余的点
  182. companyPointsNum, err := models.GetCompanyPoints(user.CompanyId)
  183. if err != nil && err.Error() != utils.ErrNoRow() {
  184. br.Msg = "获取信息失败"
  185. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  186. return
  187. }
  188. resp.CompanyPointsNum = companyPointsNum
  189. userYanxunaDetail, err := models.GetCygxUserYanxuanPermissionDetailByUserId(user.UserId)
  190. if err != nil && err.Error() != utils.ErrNoRow() {
  191. br.Msg = "获取信息失败"
  192. br.ErrMsg = "获取信息失败,GetCygxUserYanxuanPermissionDetailByUserId Err:" + err.Error()
  193. return
  194. }
  195. if userYanxunaDetail != nil {
  196. resp.PermissionStatus = userYanxunaDetail.Status
  197. resp.StartDate = userYanxunaDetail.StartDate
  198. resp.EndDate = userYanxunaDetail.EndDate
  199. hasPermission = 1
  200. //resp.PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  201. } else {
  202. //查询研选的权限状态
  203. var condition string
  204. var pars []interface{}
  205. condition += " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id IN (31,52) "
  206. pars = append(pars, user.CompanyId)
  207. companyReportPermissionDetail, err := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  208. if err != nil && err.Error() != utils.ErrNoRow() {
  209. br.Msg = "获取信息失败"
  210. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  211. return
  212. }
  213. companyReportPermissionList, err := models.GetCompanyReportPermissionList(condition, pars)
  214. if err != nil && err.Error() != utils.ErrNoRow() {
  215. br.Msg = "获取信息失败"
  216. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  217. return
  218. }
  219. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  220. if err != nil {
  221. br.Msg = "获取信息失败"
  222. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  223. return
  224. }
  225. if companyReportPermissionDetail == nil || companyProduct.IsSuspend == 1 {
  226. //hasPermission = 1
  227. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  228. if err != nil && err.Error() != utils.ErrNoRow() {
  229. br.Msg = "获取信息失败"
  230. br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
  231. return
  232. }
  233. } else {
  234. hasPermission = 1
  235. //有研选订阅或研选扣点包任意一项试用权限,即为试用客户,期限显示两项合并之后的最长时间
  236. minDate := time.Now()
  237. maxDate := time.Now()
  238. var permissionStatus string
  239. for _, v := range companyReportPermissionList {
  240. if utils.StrDateToDate(v.StartDate).Before(minDate) {
  241. minDate = utils.StrDateToDate(v.StartDate)
  242. }
  243. if utils.StrDateToDate(v.EndDate).After(maxDate) {
  244. maxDate = utils.StrDateToDate(v.EndDate)
  245. }
  246. if permissionStatus != "正式" {
  247. permissionStatus = v.Status
  248. }
  249. }
  250. resp.PermissionStatus = companyReportPermissionDetail.Status
  251. resp.StartDate = companyReportPermissionDetail.StartDate
  252. resp.EndDate = companyReportPermissionDetail.EndDate
  253. }
  254. }
  255. }
  256. } else {
  257. userYanxunaDetail, err := models.GetCygxUserYanxuanPermissionDetailByUserId(user.UserId)
  258. if err != nil && err.Error() != utils.ErrNoRow() {
  259. br.Msg = "获取信息失败"
  260. br.ErrMsg = "获取信息失败,GetCygxUserYanxuanPermissionDetailByUserId Err:" + err.Error()
  261. return
  262. }
  263. if userYanxunaDetail != nil {
  264. if !utils.InArrayByStr(resp.PermissionName, utils.CHART_PERMISSION_NAME_MF_YANXUAN) {
  265. resp.PermissionName = append(resp.PermissionName, utils.CHART_PERMISSION_NAME_MF_YANXUAN)
  266. }
  267. resp.PermissionStatus = userYanxunaDetail.Status
  268. resp.StartDate = userYanxunaDetail.StartDate
  269. resp.EndDate = userYanxunaDetail.EndDate
  270. hasPermission = 1
  271. } else {
  272. hasPermission, err = services.GetUserDetailPermissionCode(user.UserId, user.CompanyId)
  273. if err != nil && err.Error() != utils.ErrNoRow() {
  274. br.Msg = "获取信息失败"
  275. br.ErrMsg = "获取信息失败,GetUserDetailPermissionCode Err:" + err.Error()
  276. return
  277. }
  278. }
  279. }
  280. if resp.Headimgurl == "" {
  281. resp.Headimgurl = utils.DefaultHeadimgurl
  282. }
  283. specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
  284. resp.IsAuthor = specialAuthorCheck.IsAuthor
  285. resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
  286. resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
  287. resp.HasPermission = hasPermission
  288. br.Ret = 200
  289. br.Success = true
  290. br.Msg = "获取成功"
  291. br.Data = resp
  292. }
  293. // @Title 未付费申请试用
  294. // @Description 未付费申请试用
  295. // @Param request body models.ApplyTryReq true "type json string"
  296. // @Success 200
  297. // @router /apply/try [post]
  298. func (this *UserController) ApplyTryOut() {
  299. br := new(models.BaseResponse).Init()
  300. defer func() {
  301. this.Data["json"] = br
  302. this.ServeJSON()
  303. }()
  304. user := this.User
  305. if user == nil {
  306. br.Msg = "请登录"
  307. br.ErrMsg = "请登录,SysUser Is Empty"
  308. br.Ret = 408
  309. return
  310. }
  311. mobile := user.Mobile
  312. var req models.ApplyTryReq
  313. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  314. if err != nil {
  315. br.Msg = "参数解析异常!"
  316. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  317. return
  318. }
  319. if req.RealName == "" {
  320. req.RealName = user.RealName
  321. }
  322. if req.CompanyName == "" {
  323. req.CompanyName = user.CompanyName
  324. }
  325. uid := user.UserId
  326. var title string
  327. var sourceId int
  328. var source string
  329. tryType := req.TryType
  330. detailId := req.DetailId
  331. sourceId = detailId
  332. source = tryType
  333. var isResearch bool // 是否属于研选
  334. if tryType == "Article" {
  335. detail, err := models.GetArticleDetailById(detailId)
  336. if err != nil {
  337. br.Msg = "获取信息失败"
  338. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  339. return
  340. }
  341. title = detail.Title
  342. if detail.ArticleTypeId > 0 {
  343. isResearch = true
  344. }
  345. } else if tryType == "Activity" {
  346. detail, err := models.GetAddActivityInfoById(detailId)
  347. if err != nil {
  348. br.Msg = "操作失败"
  349. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  350. return
  351. }
  352. title = detail.ActivityName
  353. if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  354. isResearch = true
  355. }
  356. } else if tryType == "MicroAudio" {
  357. // 微路演音频
  358. microAudio, e := models.GetCygxActivityVoiceById(detailId)
  359. if e != nil {
  360. br.Msg = "操作失败"
  361. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  362. return
  363. }
  364. title = microAudio.VoiceName
  365. sourceId = microAudio.ActivityId
  366. source = "activityvoice"
  367. } else if tryType == "ActivityVideo" {
  368. // 活动视频
  369. activityVideo, e := models.GetCygxActivityVideoById(detailId)
  370. if e != nil {
  371. br.Msg = "操作失败"
  372. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  373. return
  374. }
  375. title = activityVideo.Title
  376. sourceId = activityVideo.ActivityId
  377. source = "activityvideo"
  378. } else if tryType == "MicroVideo" {
  379. // 微路演视频
  380. microVideo, e := models.GetMicroRoadshowVideoById(detailId)
  381. if e != nil {
  382. br.Msg = "操作失败"
  383. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(detailId)
  384. return
  385. }
  386. title = microVideo.VideoName
  387. source = "roadshow"
  388. } else if tryType == "Researchsummary" {
  389. // 本周研究汇总
  390. ResearchSummaryInfo, e := models.GetCygxResearchSummaryInfoById(detailId)
  391. if e != nil {
  392. br.Msg = "操作失败"
  393. br.ErrMsg = "本周研究汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  394. return
  395. }
  396. title = ResearchSummaryInfo.Title
  397. source = "researchsummary"
  398. } else if tryType == "Minutessummary" {
  399. // 上周纪要汇总
  400. MinutesSummaryInfo, e := models.GetCygxMinutesSummaryInfoById(detailId)
  401. if e != nil {
  402. br.Msg = "操作失败"
  403. br.ErrMsg = "上周纪要汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  404. return
  405. }
  406. title = MinutesSummaryInfo.Title
  407. source = "minutessummary"
  408. } else if tryType == "ReportSelection" {
  409. // 报告精选
  410. ReportSelectionInfo, e := models.GetCygxReportSelectionInfoById(detailId)
  411. if e != nil {
  412. br.Msg = "操作失败"
  413. br.ErrMsg = "报告精选信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  414. return
  415. }
  416. title = ReportSelectionInfo.Title
  417. source = "reportselection"
  418. } else if tryType == "ProductInterior" {
  419. // 产品内测
  420. ProductInteriorDetail, e := models.GetCygxProductInteriorDetail(detailId)
  421. if e != nil {
  422. br.Msg = "操作失败"
  423. br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  424. return
  425. }
  426. title = ProductInteriorDetail.Title
  427. source = "productinterior"
  428. } else if tryType == "YanxuanSpecial" {
  429. // 研选专栏
  430. YanxuanSpecialBySpeciaDetail, e := models.GetYanxuanSpecialBySpecialId(detailId)
  431. if e != nil {
  432. br.Msg = "操作失败"
  433. br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  434. return
  435. }
  436. title = YanxuanSpecialBySpeciaDetail.Title
  437. source = "yanxuanspecial"
  438. isResearch = true
  439. }
  440. //缓存校验
  441. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  442. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  443. if ttlTime > 0 {
  444. br.Msg = "申请失败,申请过于频繁"
  445. br.ErrMsg = "申请失败,申请过于频繁"
  446. return
  447. }
  448. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  449. //判断是否已经申请过
  450. applyCount, err := models.GetApplyRecordCount(uid)
  451. if err != nil && err.Error() != utils.ErrNoRow() {
  452. br.Msg = "获取信息失败"
  453. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  454. return
  455. }
  456. if applyCount > 0 {
  457. br.Msg = "您已提交申请,请耐心等待。"
  458. br.IsSendEmail = false
  459. return
  460. }
  461. //判断是否存在申请
  462. var sellerMobile string
  463. if req.ApplyMethod == 2 {
  464. if req.BusinessCardUrl == "" {
  465. br.Msg = "请上传名片"
  466. return
  467. }
  468. if req.RealName == "" {
  469. br.Msg = "请输入姓名"
  470. return
  471. }
  472. if req.CompanyName == "" {
  473. br.Msg = "请输入公司名称"
  474. return
  475. }
  476. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  477. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  478. if err != nil {
  479. br.Msg = "名片识别失败"
  480. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  481. return
  482. }
  483. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  484. isFlag := true
  485. if mobile != "" {
  486. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  487. isFlag = true
  488. } else {
  489. isFlag = false
  490. }
  491. }
  492. if !isFlag {
  493. //阿里云识别
  494. if utils.RunMode == "release" {
  495. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  496. if err != nil {
  497. br.Msg = "识别失败"
  498. br.ErrMsg = "识别失败,Err:" + err.Error()
  499. return
  500. }
  501. if !aliyunResult.Success {
  502. br.Msg = "识别失败"
  503. br.ErrMsg = "识别失败"
  504. return
  505. }
  506. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  507. if mobile != "" {
  508. if strings.Contains(mobileStr, mobile) {
  509. isFlag = true
  510. } else {
  511. isFlag = false
  512. }
  513. }
  514. }
  515. }
  516. if !isFlag {
  517. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  518. br.ErrMsg = "mobile:" + mobile
  519. return
  520. }
  521. }
  522. }
  523. //获取销售信息
  524. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  525. if err != nil && err.Error() != utils.ErrNoRow() {
  526. br.Msg = "申请失败"
  527. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  528. return
  529. }
  530. if sellerItem != nil {
  531. sellerMobile = sellerItem.Mobile
  532. //推送模板消息
  533. mobile := user.Mobile
  534. if mobile == "" {
  535. mobile = user.Email
  536. }
  537. }
  538. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)、9:永续客户(流失)?
  539. CompanyIdType := 1
  540. applyMethod := ""
  541. if sellerItem != nil {
  542. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  543. if err != nil && err.Error() != utils.ErrNoRow() {
  544. br.Msg = "获取信息失败"
  545. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  546. return
  547. }
  548. if companyItem != nil && companyItem.CompanyId > 0 {
  549. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  550. if err != nil && err.Error() != utils.ErrNoRow() {
  551. br.Msg = "获取信息失败"
  552. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  553. return
  554. }
  555. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  556. CompanyIdType = 6
  557. } else {
  558. switch companyItem.Status {
  559. case "正式":
  560. CompanyIdType = 4
  561. case "试用":
  562. CompanyIdType = 5
  563. case "冻结":
  564. CompanyIdType = 7
  565. case "流失":
  566. CompanyIdType = 8
  567. case "永续":
  568. CompanyIdType = 9
  569. }
  570. }
  571. applyMethod = companyItem.Status + "客户申请"
  572. if detailId > 0 {
  573. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  574. applyMethod = "试用暂停客户"
  575. } else {
  576. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  577. applyMethod = companyItem.Status + "客户申请,无对应权限"
  578. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  579. applyMethod = companyItem.Status + "客户"
  580. }
  581. }
  582. applyMethod = applyMethod + "," + title
  583. }
  584. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  585. if openIpItem != nil && openIpItem.OpenId != "" {
  586. if req.ApplyMethod != 2 {
  587. req.RealName = user.RealName
  588. req.CompanyName = user.CompanyName
  589. }
  590. //go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  591. }
  592. }
  593. } else {
  594. //获取销售信息
  595. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  596. if err != nil && err.Error() != utils.ErrNoRow() {
  597. br.Msg = "申请失败"
  598. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  599. return
  600. }
  601. if sellerItem != nil {
  602. CompanyIdType = 3
  603. applyMethod = "FICC客户"
  604. } else {
  605. CompanyIdType = 1
  606. applyMethod = "潜在客户"
  607. }
  608. if detailId > 0 {
  609. applyMethod = applyMethod + "," + title
  610. }
  611. }
  612. //openIpItem, _ := models.GetUserRecordByMobile(4, cnf.ConfigValue)
  613. //if openIpItem != nil && openIpItem.OpenId != "" {
  614. // if req.ApplyMethod != 2 {
  615. // req.RealName = user.RealName
  616. // req.CompanyName = user.CompanyName
  617. // }
  618. // utils.FileLog.Info("推送消息 %s %s,%s,%s,%s", req.RealName, req.CompanyName, mobile, openIpItem.OpenId, applyMethod)
  619. // go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  620. //}
  621. //go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
  622. item := new(models.CygxApplyRecord)
  623. item.UserId = user.UserId
  624. item.BusinessCardUrl = req.BusinessCardUrl
  625. item.RealName = req.RealName
  626. item.CompanyName = req.CompanyName
  627. item.Mobile = user.Mobile
  628. item.CreateTime = time.Now()
  629. item.ApplyMethod = req.ApplyMethod
  630. item.CompanyIdPay = user.CompanyId
  631. item.CompanyNamePay = user.CompanyName
  632. item.CompanyIdType = CompanyIdType
  633. if user.InviteCompany == utils.LUODING_CODE && user.CompanyId == 1 {
  634. //如果是潜在客户就标记来源
  635. item.InviteCompanySource = utils.REGISTER_PLATFORM
  636. }
  637. item.Title = title
  638. item.SourceId = sourceId
  639. item.Source = strings.ToLower(source)
  640. item.RegisterPlatform = utils.REGISTER_PLATFORM
  641. err = models.AddApplyRecord(item)
  642. if err != nil {
  643. br.Msg = "申请失败"
  644. br.ErrMsg = "申请失败,Err:" + err.Error()
  645. return
  646. }
  647. if sellerItem == nil {
  648. go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
  649. } else {
  650. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  651. if openIpItem != nil && openIpItem.OpenId != "" {
  652. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  653. }
  654. }
  655. //添加成功后,设置5分钟缓存,不允许重复添加
  656. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  657. br.Msg = "申请成功!"
  658. br.Ret = 200
  659. br.Success = true
  660. br.Data = sellerMobile
  661. }
  662. // @Title 用户修改外呼手机号以及区号
  663. // @Description 用户修改外呼手机号以及区号接口
  664. // @Param request body models.OutboundMobileItem true "type json string"
  665. // @Success Ret=200 操作成功
  666. // @router /countryCcode/addOutboundMobile [POST]
  667. func (this *UserController) AddOutboundMobile() {
  668. br := new(models.BaseResponse).Init()
  669. defer func() {
  670. this.Data["json"] = br
  671. this.ServeJSON()
  672. }()
  673. user := this.User
  674. uid := user.UserId
  675. if user == nil {
  676. br.Msg = "请登录"
  677. br.ErrMsg = "请登录,用户信息为空"
  678. br.Ret = 408
  679. return
  680. }
  681. var req models.OutboundMobileItem
  682. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  683. if err != nil {
  684. br.Msg = "参数解析异常!"
  685. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  686. return
  687. }
  688. if req.OutboundMobile == "" {
  689. br.Msg = "请填写区号!"
  690. return
  691. }
  692. item := new(models.OutboundMobileItem)
  693. item.OutboundMobile = req.OutboundMobile
  694. item.OutboundCountryCode = req.OutboundCountryCode
  695. //item.ActivityId = req.ActivityId
  696. //if req.ActivityId == 0 {
  697. // err = models.AddOutboundMobile(item, uid)
  698. //} else {
  699. // if user.Mobile == "" && user.OutboundMobile == "" {
  700. // items := new(models.CygxActivitySignup)
  701. // items.UserId = uid
  702. // items.ActivityId = req.ActivityId
  703. // items.CreateTime = time.Now()
  704. // items.Mobile = user.Mobile
  705. // items.Email = user.Email
  706. // items.CompanyId = user.CompanyId
  707. // items.CompanyName = user.CompanyName
  708. // items.SignupType = 1
  709. // items.FailType = 0
  710. // items.DoFailType = 0
  711. // items.OutboundMobile = req.OutboundMobile
  712. // items.CountryCode = req.OutboundCountryCode
  713. // _, err = models.AddActivitySignupFromEmail(items)
  714. // } else {
  715. // total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  716. // if total == 0 {
  717. // br.Msg = "报名信息不存在"
  718. // br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  719. // return
  720. // }
  721. // if err != nil {
  722. // br.Msg = "操作失败"
  723. // br.ErrMsg = "操作失败,Err:" + err.Error()
  724. // return
  725. // }
  726. // err = models.AddOutboundMobile(item, uid)
  727. // }
  728. //}
  729. err = models.AddOutboundMobile(item, uid)
  730. if err != nil {
  731. br.Msg = "操作失败"
  732. br.ErrMsg = "操作失败,Err:" + err.Error()
  733. return
  734. }
  735. br.Ret = 200
  736. br.Success = true
  737. br.Msg = "操作成功"
  738. }
  739. // @Title 校验用户状态信息
  740. // @Description 校验用户状态信息
  741. // @Success 200 {object} models.CheckStatusResp
  742. // @router /check/status [get]
  743. func (this *UserController) CheckLogin() {
  744. br := new(models.BaseResponse).Init()
  745. defer func() {
  746. this.Data["json"] = br
  747. this.ServeJSON()
  748. }()
  749. user := this.User
  750. if user == nil {
  751. br.Msg = "请登录"
  752. br.ErrMsg = "请登录"
  753. br.Ret = 408
  754. return
  755. }
  756. uid := user.UserId
  757. resp := new(models.CheckStatusResp)
  758. if uid > 0 {
  759. //判断token是否过期
  760. userRecord, err := models.GetUserSessionByUserId(uid)
  761. if err != nil {
  762. br.Msg = "获取用户信息失败"
  763. br.ErrMsg = "获取用户信息失败,Err:" + err.Error()
  764. return
  765. }
  766. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  767. if err != nil {
  768. br.Msg = "获取信息失败"
  769. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  770. return
  771. }
  772. resp.PermissionName = permissionStr
  773. if user.Mobile == "" && user.Email == "" {
  774. resp.IsBind = true
  775. }
  776. if userRecord.UnionId == "" {
  777. resp.IsAuth = true
  778. }
  779. } else {
  780. resp.IsBind = true
  781. if user.UnionId == "" {
  782. resp.IsAuth = true
  783. }
  784. resp.PermissionName = ""
  785. }
  786. br.Success = true
  787. br.Msg = "获取成功"
  788. br.Data = resp
  789. br.Ret = 200
  790. }
  791. // @Title 更改用户微信头像
  792. // @Description 更改用户微信头像
  793. // @Param request body models.Headimgurl true "type json string"
  794. // @Success 200 {object} models.ArticleDetailFileLink
  795. // @router /headimgurl/update [post]
  796. func (this *UserController) HeadimgurlUpdate() {
  797. br := new(models.BaseResponse).Init()
  798. defer func() {
  799. this.Data["json"] = br
  800. this.ServeJSON()
  801. }()
  802. user := this.User
  803. if user == nil {
  804. br.Msg = "请登录"
  805. br.ErrMsg = "请登录,用户信息为空"
  806. br.Ret = 408
  807. return
  808. }
  809. var req models.Headimgurl
  810. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  811. if err != nil {
  812. br.Msg = "参数解析异常!"
  813. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  814. return
  815. }
  816. uid := user.UserId
  817. headimgurl := req.Headimgurl
  818. if headimgurl == "" {
  819. br.Msg = "操作失败"
  820. br.ErrMsg = "头像信息不能为空"
  821. return
  822. }
  823. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  824. if err != nil {
  825. br.Msg = "操作失败"
  826. br.ErrMsg = "头像信息不能为空"
  827. }
  828. br.Ret = 200
  829. br.Success = true
  830. br.Msg = "操作成功"
  831. }
  832. // @Title 获取我的收藏
  833. // @Description 获取我的收藏列表
  834. // @Param PageSize query int true "PageSize"
  835. // @Param CurrentIndex query int true "CurrentIndex"
  836. // @Success 200 {object} models.ArticleCollectListResp
  837. // @router /collect/list [get]
  838. func (this *UserController) CollectList() {
  839. br := new(models.BaseResponse).Init()
  840. defer func() {
  841. this.Data["json"] = br
  842. this.ServeJSON()
  843. }()
  844. user := this.User
  845. if user == nil {
  846. br.Msg = "请登录"
  847. br.ErrMsg = "请登录,用户信息为空"
  848. br.Ret = 408
  849. return
  850. }
  851. userId := this.User.UserId
  852. var pageSize, currentIndex, startSize int
  853. pageSize, _ = this.GetInt("PageSize")
  854. currentIndex, _ = this.GetInt("CurrentIndex")
  855. if pageSize <= 0 {
  856. pageSize = utils.PageSize20
  857. }
  858. if currentIndex <= 0 {
  859. currentIndex = 1
  860. }
  861. startSize = utils.StartIndex(currentIndex, pageSize)
  862. total, err := models.GetArticleUserCollectCount(userId)
  863. if err != nil {
  864. br.Msg = "获取数据失败"
  865. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  866. return
  867. }
  868. list, err := models.GetArticleUserCollectList(startSize, pageSize, userId)
  869. if err != nil {
  870. br.Msg = "获取数据失败"
  871. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  872. return
  873. }
  874. resp := new(models.ArticleReportBillboardLIstPageResp)
  875. if len(list) == 0 {
  876. page := paging.GetPaging(currentIndex, pageSize, total)
  877. resp.List = make([]*models.ArticleReportBillboardResp, 0)
  878. resp.Paging = page
  879. br.Msg = "获取成功!"
  880. br.Ret = 200
  881. br.Success = true
  882. br.Data = resp
  883. return
  884. }
  885. list, err = services.HandleArticleCategoryImg(list, user)
  886. if err != nil {
  887. br.Msg = "获取信息失败"
  888. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  889. return
  890. }
  891. page := paging.GetPaging(currentIndex, pageSize, total)
  892. for _, v := range list {
  893. item := models.ArticleReportBillboardResp{
  894. ArticleId: v.ArticleId,
  895. ArticleTypeId: v.ArticleTypeId,
  896. Title: v.Title,
  897. PublishDate: v.PublishDate,
  898. DepartmentId: v.DepartmentId,
  899. NickName: v.NickName,
  900. IsCollect: v.IsCollect,
  901. Pv: v.Pv,
  902. CollectNum: v.CollectNum,
  903. ImgUrlPc: v.ImgUrlPc,
  904. LabelKeywordImgLink: v.LabelKeywordImgLink,
  905. List: v.List,
  906. SpecialColumnId: v.SpecialColumnId,
  907. }
  908. if v.IsSpecial == 1 {
  909. item.IsSpecial = true
  910. item.ImgUrlPc = utils.CYGX_YANXUAN_SPECIAL_IMG_PC
  911. if v.CompanyTags != "" {
  912. item.CompanyTags = strings.Split(v.CompanyTags, ",")
  913. } else {
  914. item.CompanyTags = []string{}
  915. }
  916. if v.IndustryTags != "" {
  917. item.IndustryTags = strings.Split(v.IndustryTags, ",")
  918. } else {
  919. item.IndustryTags = []string{}
  920. }
  921. //item.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
  922. //if v.SpecialType == 1 {
  923. // item.Title = "【笔记】" + item.Title
  924. //} else if v.SpecialType == 2 {
  925. // item.Title = "【观点】" + item.Title
  926. //}
  927. //if v.MyCollectNum > 0 {
  928. // item.IsCollect = true
  929. //}
  930. }
  931. resp.List = append(resp.List, &item)
  932. }
  933. //var condition string
  934. //var pars []interface{}
  935. //var articleIds []string
  936. //for _, v := range list {
  937. // articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  938. //}
  939. //articleIdStr := strings.Join(articleIds, ",")
  940. //
  941. ////获取文章关联的产业
  942. //pars = make([]interface{}, 0)
  943. //condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  944. //pars = append(pars, articleIds)
  945. //industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  946. //if err != nil {
  947. // br.Msg = "获取失败"
  948. // br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  949. // return
  950. //}
  951. //industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  952. //if len(industrialList) > 0 {
  953. // for _, v := range industrialList {
  954. // item := new(models.IndustrialManagementIdInt)
  955. // item.ArticleId = v.ArticleId
  956. // if v.ArticleId > utils.SummaryArticleId {
  957. // item.IsResearch = true
  958. // }
  959. // item.IndustrialManagementId = v.IndustrialManagementId
  960. // item.IndustryName = v.IndustryName
  961. // item.ChartPermissionId = v.ChartPermissionId
  962. // industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  963. // }
  964. //}
  965. //for k, v := range list {
  966. // if len(industrialMap[v.ArticleId]) > 0 {
  967. // list[k].List = industrialMap[v.ArticleId]
  968. // } else {
  969. // list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  970. // }
  971. //}
  972. //
  973. //articleMap := make(map[int]*models.ArticleDetail)
  974. //if articleIdStr != "" {
  975. // articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  976. // if err != nil {
  977. // br.Msg = "获取数据失败"
  978. // br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  979. // return
  980. // }
  981. // for _, v := range articleList {
  982. // if _, ok := articleMap[v.ArticleId]; !ok {
  983. // articleMap[v.ArticleId] = v
  984. // }
  985. // }
  986. //}
  987. //
  988. ////处理文章PV收藏等数量
  989. //mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  990. //if len(articleIds) > 0 {
  991. // articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  992. // if err != nil && err.Error() != utils.ErrNoRow() {
  993. // br.Msg = "获取失败"
  994. // br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  995. // return
  996. // }
  997. // for _, v := range articleCollectNumList {
  998. // mapArticleCollectNum[v.ArticleId] = v
  999. // }
  1000. //}
  1001. //
  1002. ////研选的五张图片
  1003. //detailResearch, err := models.GetConfigByCode("category_research_img_url")
  1004. //if err != nil {
  1005. // br.Msg = "获取失败"
  1006. // br.ErrMsg = "获取失败,GetConfigByCode Err:" + err.Error()
  1007. // return
  1008. //}
  1009. //researchList := strings.Split(detailResearch.ConfigValue, "{|}")
  1010. //
  1011. //lenList := len(list)
  1012. //for i := 0; i < lenList; i++ {
  1013. // item := list[i]
  1014. // knum := item.ArticleId % 5
  1015. // list[i].ImgUrlPc = researchList[knum]
  1016. //
  1017. // article := articleMap[item.ArticleId]
  1018. // if list[i].IsSpecialInt != 1 {
  1019. // list[i].Title = article.Title
  1020. // list[i].DepartmentId = article.DepartmentId
  1021. // list[i].NickName = article.NickName
  1022. // list[i].PublishDate = article.PublishDate
  1023. // if article.ArticleTypeId == 0 {
  1024. // list[i].Source = 1
  1025. // } else {
  1026. // list[i].Source = 2
  1027. // list[i].IsResearch = true
  1028. // }
  1029. // if mapArticleCollectNum[article.ArticleId] != nil {
  1030. // list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  1031. // list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  1032. // list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  1033. // }
  1034. // } else {
  1035. // //处理研选专栏
  1036. // list[i].IsSpecial = true
  1037. // if list[i].CompanyTagsStr != "" {
  1038. // list[i].CompanyTags = strings.Split(list[i].CompanyTagsStr, ",")
  1039. // } else {
  1040. // list[i].CompanyTags = []string{}
  1041. // }
  1042. // if list[i].IndustryTagStr != "" {
  1043. // list[i].IndustryTags = strings.Split(list[i].IndustryTagStr, ",")
  1044. // } else {
  1045. // list[i].IndustryTags = []string{}
  1046. // }
  1047. // list[i].IsResearch = true
  1048. // }
  1049. // if item.ArticleTypeId == -1 {
  1050. // list[i].ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
  1051. // }
  1052. // if item.SpecialType == 1 {
  1053. // list[i].Title = "【笔记】" + list[i].Title
  1054. // } else if list[i].SpecialType == 2 {
  1055. // list[i].Title = "【观点】" + list[i].Title
  1056. // }
  1057. // if item.MyCollectNum > 0 {
  1058. // list[i].IsCollect = true
  1059. // }
  1060. //
  1061. //}
  1062. //page := paging.GetPaging(currentIndex, pageSize, total)
  1063. //resp.List = list
  1064. resp.Paging = page
  1065. br.Msg = "获取成功!"
  1066. br.Ret = 200
  1067. br.Success = true
  1068. br.Data = resp
  1069. }
  1070. // @Title 获取我的留言
  1071. // @Description 获取我的留言列表
  1072. // @Param PageSize query int true "PageSize"
  1073. // @Param CurrentIndex query int true "CurrentIndex"
  1074. // @Success 200 {object} models.CygxCommentListResp
  1075. // @router /comment/list [get]
  1076. func (this *UserController) CommnetList() {
  1077. br := new(models.BaseResponse).Init()
  1078. defer func() {
  1079. this.Data["json"] = br
  1080. this.ServeJSON()
  1081. }()
  1082. user := this.User
  1083. if user == nil {
  1084. br.Msg = "请登录"
  1085. br.ErrMsg = "请登录,用户信息为空"
  1086. br.Ret = 408
  1087. return
  1088. }
  1089. var pageSize, currentIndex, startSize int
  1090. pageSize, _ = this.GetInt("PageSize")
  1091. currentIndex, _ = this.GetInt("CurrentIndex")
  1092. if pageSize <= 0 {
  1093. pageSize = utils.PageSize20
  1094. }
  1095. if currentIndex <= 0 {
  1096. currentIndex = 1
  1097. }
  1098. startSize = utils.StartIndex(currentIndex, pageSize)
  1099. userId := this.User.UserId
  1100. total, err := models.GetCommentListCount(userId)
  1101. if err != nil {
  1102. br.Msg = "获取数据失败"
  1103. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1104. return
  1105. }
  1106. commentlist, err := models.GetCommentList(userId, startSize, pageSize)
  1107. if err != nil && err.Error() != utils.ErrNoRow() {
  1108. br.Msg = "获取失败"
  1109. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  1110. return
  1111. }
  1112. resp := new(models.CygxCommentListResp)
  1113. for _, comment := range commentlist {
  1114. item := models.CygxArticleCommentResp{
  1115. Id: comment.Id,
  1116. UserId: comment.UserId,
  1117. ArticleId: comment.ArticleId,
  1118. IndustryId: comment.IndustryId,
  1119. ActivityId: comment.ActivityId,
  1120. VideoId: comment.VideoId,
  1121. CreateTime: comment.CreateTime.Format(utils.FormatDateTime),
  1122. Mobile: comment.Mobile,
  1123. Email: comment.Email,
  1124. CompanyId: comment.CompanyId,
  1125. CompanyName: comment.CompanyName,
  1126. Content: comment.Content,
  1127. Title: comment.Title,
  1128. }
  1129. if comment.ArticleId > 0 {
  1130. item.RedirectType = 1
  1131. } else if comment.IndustryId > 0 {
  1132. detail, err := models.GetIndustrialManagementDetail(comment.IndustryId)
  1133. if err != nil {
  1134. br.Msg = "获取信息失败"
  1135. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1136. return
  1137. }
  1138. item.RedirectType = 3
  1139. item.ChartPermissionId = detail.ChartPermissionId
  1140. } else if comment.ActivityId > 0 && comment.VideoId == 0 {
  1141. item.RedirectType = 2
  1142. } else if comment.IndustryId == 0 && comment.VideoId > 0 {
  1143. item.RedirectType = 4
  1144. }
  1145. resp.List = append(resp.List, &item)
  1146. }
  1147. page := paging.GetPaging(currentIndex, pageSize, total)
  1148. resp.Paging = page
  1149. br.Msg = "获取成功!"
  1150. br.Ret = 200
  1151. br.Success = true
  1152. br.Data = resp
  1153. }
  1154. // @Title 我的足迹
  1155. // @Description 获取我的足迹列表
  1156. // @Param PageSize query int true "PageSize"
  1157. // @Param CurrentIndex query int true "CurrentIndex"
  1158. // @Success 200 {object} models.ArticleBrowseHistoryListResp
  1159. // @router /browse/history/list [get]
  1160. func (this *UserController) BrowseHistoryList() {
  1161. br := new(models.BaseResponse).Init()
  1162. defer func() {
  1163. this.Data["json"] = br
  1164. this.ServeJSON()
  1165. }()
  1166. user := this.User
  1167. if user == nil {
  1168. br.Msg = "请登录"
  1169. br.ErrMsg = "请登录,用户信息为空"
  1170. br.Ret = 408
  1171. return
  1172. }
  1173. userId := this.User.UserId
  1174. var pageSize, currentIndex, startSize int
  1175. pageSize, _ = this.GetInt("PageSize")
  1176. currentIndex, _ = this.GetInt("CurrentIndex")
  1177. if pageSize <= 0 {
  1178. pageSize = utils.PageSize20
  1179. }
  1180. if currentIndex <= 0 {
  1181. currentIndex = 1
  1182. }
  1183. startSize = utils.StartIndex(currentIndex, pageSize)
  1184. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  1185. total, err := models.GetArticleUserBrowseHistoryCount(userId, endDate)
  1186. if err != nil {
  1187. br.Msg = "获取数据失败"
  1188. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1189. return
  1190. }
  1191. list, err := models.GetArticleUserBrowseHistoryList(startSize, pageSize, userId, endDate)
  1192. if err != nil {
  1193. br.Msg = "获取数据失败"
  1194. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1195. return
  1196. }
  1197. resp := new(models.ArticleReportBillboardLIstPageResp)
  1198. if len(list) == 0 {
  1199. page := paging.GetPaging(currentIndex, pageSize, total)
  1200. resp.List = make([]*models.ArticleReportBillboardResp, 0)
  1201. resp.Paging = page
  1202. br.Msg = "获取成功!"
  1203. br.Ret = 200
  1204. br.Success = true
  1205. br.Data = resp
  1206. return
  1207. }
  1208. list, err = services.HandleArticleCategoryImg(list, user)
  1209. if err != nil {
  1210. br.Msg = "获取信息失败"
  1211. br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
  1212. return
  1213. }
  1214. page := paging.GetPaging(currentIndex, pageSize, total)
  1215. for _, v := range list {
  1216. item := models.ArticleReportBillboardResp{
  1217. ArticleId: v.ArticleId,
  1218. ArticleTypeId: v.ArticleTypeId,
  1219. Title: v.Title,
  1220. PublishDate: v.PublishDate,
  1221. DepartmentId: v.DepartmentId,
  1222. NickName: v.NickName,
  1223. IsCollect: v.IsCollect,
  1224. Pv: v.Pv,
  1225. CollectNum: v.CollectNum,
  1226. ImgUrlPc: v.ImgUrlPc,
  1227. LabelKeywordImgLink: v.LabelKeywordImgLink,
  1228. List: v.List,
  1229. SpecialColumnId: v.SpecialColumnId,
  1230. }
  1231. if v.IsSpecial == 1 {
  1232. item.IsSpecial = true
  1233. item.ImgUrlPc = utils.CYGX_YANXUAN_SPECIAL_IMG_PC
  1234. if v.CompanyTags != "" {
  1235. item.CompanyTags = strings.Split(v.CompanyTags, ",")
  1236. } else {
  1237. item.CompanyTags = []string{}
  1238. }
  1239. if v.IndustryTags != "" {
  1240. item.IndustryTags = strings.Split(v.IndustryTags, ",")
  1241. } else {
  1242. item.IndustryTags = []string{}
  1243. }
  1244. //item.ArticleTypeName = utils.CYGX_YANXUAN_SPECIAL
  1245. //if v.SpecialType == 1 {
  1246. // item.Title = "【笔记】" + item.Title
  1247. //} else if v.SpecialType == 2 {
  1248. // item.Title = "【观点】" + item.Title
  1249. //}
  1250. //if v.MyCollectNum > 0 {
  1251. // item.IsCollect = true
  1252. //}
  1253. }
  1254. resp.List = append(resp.List, &item)
  1255. }
  1256. //var articleIds []string
  1257. //var condition string
  1258. //var pars []interface{}
  1259. //for _, v := range list {
  1260. // if v.IsSpecial == 1 {
  1261. // //if v.CompanyTags != "" {
  1262. // // v.CompanyTags = strings.Split(v.CompanyTags, ",")
  1263. // //} else {
  1264. // // v.CompanyTags = []string{}
  1265. // //}
  1266. // } else {
  1267. // articleIds = append(articleIds, strconv.Itoa(v.ArticleId))
  1268. // }
  1269. //}
  1270. //articleIdStr := strings.Join(articleIds, ",")
  1271. //
  1272. ////获取文章关联的产业
  1273. //pars = make([]interface{}, 0)
  1274. //condition = ` AND mg.article_id IN ( ` + utils.GetOrmInReplace(len(articleIds)) + ` ) `
  1275. //pars = append(pars, articleIds)
  1276. //industrialList, err := models.GetIndustrialListByarticleId(pars, condition)
  1277. //if err != nil {
  1278. // br.Msg = "获取失败"
  1279. // br.ErrMsg = "获取失败,GetSubjectList Err:" + err.Error()
  1280. // return
  1281. //}
  1282. //industrialMap := make(map[int][]*models.IndustrialManagementIdInt)
  1283. //if len(industrialList) > 0 {
  1284. // for _, v := range industrialList {
  1285. // item := new(models.IndustrialManagementIdInt)
  1286. // item.ArticleId = v.ArticleId
  1287. // item.IndustrialManagementId = v.IndustrialManagementId
  1288. // item.IndustryName = v.IndustryName
  1289. // item.ChartPermissionId = v.ChartPermissionId
  1290. // industrialMap[v.ArticleId] = append(industrialMap[v.ArticleId], item)
  1291. // }
  1292. //}
  1293. //for k, v := range list {
  1294. // if len(industrialMap[v.ArticleId]) > 0 {
  1295. // list[k].List = industrialMap[v.ArticleId]
  1296. // } else {
  1297. // list[k].List = make([]*models.IndustrialManagementIdInt, 0)
  1298. // }
  1299. //}
  1300. //
  1301. //articleMap := make(map[int]*models.ArticleDetail)
  1302. //if articleIdStr != "" {
  1303. // articleList, err := models.GetArticleDetailByIdStr(articleIdStr)
  1304. // if err != nil {
  1305. // br.Msg = "获取数据失败"
  1306. // br.ErrMsg = "获取报告详情信息失败,Err:" + err.Error()
  1307. // return
  1308. // }
  1309. // for _, v := range articleList {
  1310. // if _, ok := articleMap[v.ArticleId]; !ok {
  1311. // articleMap[v.ArticleId] = v
  1312. // }
  1313. // }
  1314. //}
  1315. //
  1316. ////处理文章PV收藏等数量
  1317. //mapArticleCollectNum := make(map[int]*models.CygxArticleNum)
  1318. //if len(articleIds) > 0 {
  1319. // articleCollectNumList, err := models.GetArticleCollectNum(articleIds, userId)
  1320. // if err != nil && err.Error() != utils.ErrNoRow() {
  1321. // br.Msg = "获取失败"
  1322. // br.ErrMsg = "获取失败,GetArticleCollectNum Err:" + err.Error()
  1323. // return
  1324. // }
  1325. // for _, v := range articleCollectNumList {
  1326. // mapArticleCollectNum[v.ArticleId] = v
  1327. // }
  1328. //}
  1329. //
  1330. //lenList := len(list)
  1331. //for i := 0; i < lenList; i++ {
  1332. // item := list[i]
  1333. // article := articleMap[item.ArticleId]
  1334. // if article != nil {
  1335. // list[i].Title = article.Title
  1336. // list[i].PublishDate = utils.TimeRemoveHms2(article.PublishDate)
  1337. // list[i].DepartmentId = article.DepartmentId
  1338. // list[i].NickName = article.NickName
  1339. // if mapArticleCollectNum[article.ArticleId] != nil {
  1340. // list[i].CollectNum = mapArticleCollectNum[article.ArticleId].CollectNum
  1341. // list[i].Pv = mapArticleCollectNum[article.ArticleId].Pv
  1342. // list[i].IsCollect = mapArticleCollectNum[article.ArticleId].IsCollect
  1343. // }
  1344. // }
  1345. //}
  1346. //page := paging.GetPaging(currentIndex, pageSize, total)
  1347. //
  1348. //resp.List = list
  1349. resp.Paging = page
  1350. br.Msg = "获取成功!"
  1351. br.Ret = 200
  1352. br.Success = true
  1353. br.Data = resp
  1354. }
  1355. // @Title 获取我的提问
  1356. // @Description 获取我的提问列表
  1357. // @Param PageSize query int true "PageSize"
  1358. // @Param CurrentIndex query int true "CurrentIndex"
  1359. // @Success 200 {object} models.CygxAskListResp
  1360. // @router /ask/list [get]
  1361. func (this *UserController) AskList() {
  1362. br := new(models.BaseResponse).Init()
  1363. defer func() {
  1364. this.Data["json"] = br
  1365. this.ServeJSON()
  1366. }()
  1367. user := this.User
  1368. if user == nil {
  1369. br.Msg = "请登录"
  1370. br.ErrMsg = "请登录,用户信息为空"
  1371. br.Ret = 408
  1372. return
  1373. }
  1374. var pageSize, currentIndex, startSize int
  1375. pageSize, _ = this.GetInt("PageSize")
  1376. currentIndex, _ = this.GetInt("CurrentIndex")
  1377. if pageSize <= 0 {
  1378. pageSize = utils.PageSize20
  1379. }
  1380. if currentIndex <= 0 {
  1381. currentIndex = 1
  1382. }
  1383. startSize = utils.StartIndex(currentIndex, pageSize)
  1384. userId := this.User.UserId
  1385. total, err := models.GetActivityAskCount(userId)
  1386. if err != nil {
  1387. br.Msg = "获取数据失败"
  1388. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1389. return
  1390. }
  1391. listActcivity, err := models.GetActivityAskList(userId, startSize, pageSize)
  1392. if err != nil && err.Error() != utils.ErrNoRow() {
  1393. br.Msg = "获取失败"
  1394. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1395. return
  1396. }
  1397. for _, v := range listActcivity {
  1398. v.AskType = "Activity"
  1399. }
  1400. listArticle, err := models.GetArticleAskList(userId)
  1401. if err != nil && err.Error() != utils.ErrNoRow() {
  1402. br.Msg = "获取失败"
  1403. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1404. return
  1405. }
  1406. for _, v := range listArticle {
  1407. v.AskType = "Report"
  1408. listActcivity = append(listActcivity, v)
  1409. }
  1410. resp := new(models.CygxAskListResp)
  1411. page := paging.GetPaging(currentIndex, pageSize, total)
  1412. resp.Paging = page
  1413. resp.List = listActcivity
  1414. br.Msg = "获取成功!"
  1415. br.Ret = 200
  1416. br.Success = true
  1417. br.Data = resp
  1418. }
  1419. // @Title 我的收藏微路演列表
  1420. // @Description 我的收藏微路演列表接口
  1421. // @Param PageSize query int true "每页数据条数"
  1422. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1423. // @Success 200 {object} models.HomeListResp
  1424. // @router /collect/microRoadShow [get]
  1425. func (this *UserController) Mycollect() {
  1426. br := new(models.BaseResponse).Init()
  1427. defer func() {
  1428. this.Data["json"] = br
  1429. this.ServeJSON()
  1430. }()
  1431. user := this.User
  1432. if user == nil {
  1433. br.Msg = "请登录"
  1434. br.ErrMsg = "请登录,用户信息为空"
  1435. br.Ret = 408
  1436. return
  1437. }
  1438. pageSize, _ := this.GetInt("PageSize")
  1439. currentIndex, _ := this.GetInt("CurrentIndex")
  1440. if pageSize <= 0 {
  1441. pageSize = utils.PageSize20
  1442. }
  1443. if currentIndex <= 0 {
  1444. currentIndex = 1
  1445. }
  1446. userId := user.UserId
  1447. listMycollect, err := models.GetUserMicroRoadshowCollectList(userId)
  1448. if err != nil {
  1449. br.Msg = "获取数据失败"
  1450. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1451. return
  1452. }
  1453. listAskserieVideoCollect, err := models.GetUserCygxAskserieVideoCollectList(userId)
  1454. if err != nil {
  1455. br.Msg = "获取数据失败"
  1456. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1457. return
  1458. }
  1459. collectVoiceMap := make(map[int]time.Time, 0)
  1460. collectVideoMap := make(map[int]time.Time, 0)
  1461. collectActivityVideoMap := make(map[int]time.Time, 0)
  1462. var audioIds []string
  1463. var videoIds []string
  1464. var activityVideoIds []string
  1465. var askserieVideoIds []string //问答系列视频
  1466. for _, item := range listMycollect {
  1467. if item.ActivityVoiceId > 0 {
  1468. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1469. collectVoiceMap[item.ActivityVoiceId] = item.CreateTime
  1470. } else if item.VideoId > 0 {
  1471. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1472. collectVideoMap[item.VideoId] = item.CreateTime
  1473. } else if item.ActivityVideoId > 0 {
  1474. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  1475. collectActivityVideoMap[item.ActivityVideoId] = item.CreateTime
  1476. }
  1477. }
  1478. for _, item := range listAskserieVideoCollect {
  1479. askserieVideoIds = append(askserieVideoIds, strconv.Itoa(item.AskserieVideoId))
  1480. }
  1481. if len(audioIds) == 0 && len(videoIds) == 0 && len(activityVideoIds) == 0 && len(askserieVideoIds) == 0 {
  1482. resp := new(models.MicroRoadShowListResp)
  1483. page := paging.GetPaging(currentIndex, pageSize, 0)
  1484. resp.List = make([]*models.MicroRoadShowPageList, 0)
  1485. resp.Paging = page
  1486. br.Ret = 200
  1487. br.Success = true
  1488. br.Msg = "获取成功"
  1489. br.Data = resp
  1490. return
  1491. }
  1492. audioIdstr := strings.Join(audioIds, ",")
  1493. ideoIdsStr := strings.Join(videoIds, ",")
  1494. activityVideoIdsStr := strings.Join(activityVideoIds, ",")
  1495. askserieVideoIdsStr := strings.Join(askserieVideoIds, ",")
  1496. // 微路演列表
  1497. list, total, e := services.GetMicroRoadShowMycollectV12(pageSize, currentIndex, audioIdstr, activityVideoIdsStr, ideoIdsStr, askserieVideoIdsStr, user)
  1498. if e != nil {
  1499. br.Msg = "获取失败"
  1500. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  1501. return
  1502. }
  1503. for _, item := range list {
  1504. if item.Type == 1 {
  1505. //音频
  1506. count, err := models.GetVoiceCollectCount(user.UserId, item.Id)
  1507. if err != nil {
  1508. br.Msg = "获取数据失败!"
  1509. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1510. return
  1511. }
  1512. if count > 0 {
  1513. item.IsCollect = true
  1514. }
  1515. if v, ok := collectVoiceMap[item.Id]; ok {
  1516. item.CollectTime = v
  1517. }
  1518. } else if item.Type == 2 {
  1519. //活动视频
  1520. count, err := models.GetActivityVideoCollectCount(user.UserId, item.Id)
  1521. if err != nil {
  1522. br.Msg = "获取数据失败!"
  1523. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1524. return
  1525. }
  1526. if count > 0 {
  1527. item.IsCollect = true
  1528. }
  1529. if v, ok := collectActivityVideoMap[item.Id]; ok {
  1530. item.CollectTime = v
  1531. }
  1532. } else if item.Type == 3 {
  1533. //微路演视频
  1534. count, err := models.GetVideoCollectCount(user.UserId, item.Id)
  1535. if err != nil {
  1536. br.Msg = "获取数据失败!"
  1537. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1538. return
  1539. }
  1540. if count > 0 {
  1541. item.IsCollect = true
  1542. }
  1543. if v, ok := collectVideoMap[item.Id]; ok {
  1544. item.CollectTime = v
  1545. }
  1546. }
  1547. }
  1548. // 用户权限
  1549. authInfo, permissionArr, e := services.GetUserRaiPermissionInfo(user.UserId, user.CompanyId)
  1550. if e != nil {
  1551. br.Msg = "获取失败"
  1552. br.ErrMsg = "获取用户权限失败, Err: " + e.Error()
  1553. return
  1554. }
  1555. // 获取默认图配置
  1556. audioMap, videoMap, audioShareMap, videoShareMap, e := services.GetMicroRoadShowDefaultImgConfig()
  1557. if e != nil {
  1558. br.Msg = "获取失败"
  1559. br.ErrMsg = "获取微路演列表失败, Err: " + e.Error()
  1560. return
  1561. }
  1562. for i := range list {
  1563. // 权限
  1564. au := new(models.UserPermissionAuthInfo)
  1565. au.SellerName = authInfo.SellerName
  1566. au.SellerMobile = authInfo.SellerMobile
  1567. au.HasPermission = authInfo.HasPermission
  1568. au.OperationMode = authInfo.OperationMode
  1569. if au.HasPermission == 1 {
  1570. // 非宏观权限进一步判断是否有权限
  1571. if list[i].ChartPermissionId != utils.HONG_GUAN_ID && !utils.InArrayByStr(permissionArr, list[i].ChartPermissionName) {
  1572. au.HasPermission = 2
  1573. }
  1574. }
  1575. // 无权限的弹框提示
  1576. if au.HasPermission != 1 {
  1577. if au.OperationMode == services.UserPermissionOperationModeCall {
  1578. if list[i].Type == 1 {
  1579. au.PopupMsg = services.UserPermissionPopupMsgCallActivity
  1580. } else {
  1581. au.PopupMsg = services.UserPermissionPopupMsgCallMicroVideo
  1582. }
  1583. } else {
  1584. if list[i].Type == 1 {
  1585. au.PopupMsg = services.UserPermissionPopupMsgApplyActivity
  1586. } else {
  1587. au.PopupMsg = services.UserPermissionPopupMsgApplyMicroVideo
  1588. }
  1589. }
  1590. }
  1591. list[i].AuthInfo = au
  1592. list[i].PublishTime = utils.StrTimeToTime(list[i].PublishTime).Format(utils.FormatDate)
  1593. // 默认图
  1594. if list[i].BackgroundImg == "" {
  1595. if list[i].Type == 1 {
  1596. list[i].BackgroundImg = audioMap[list[i].ChartPermissionId]
  1597. } else {
  1598. list[i].BackgroundImg = videoMap[list[i].ChartPermissionId]
  1599. }
  1600. }
  1601. // 分享图
  1602. if list[i].ShareImg == "" {
  1603. if list[i].Type == 1 {
  1604. list[i].ShareImg = audioShareMap[list[i].ChartPermissionId]
  1605. } else {
  1606. list[i].ShareImg = videoShareMap[list[i].ChartPermissionId]
  1607. }
  1608. }
  1609. }
  1610. var sortList models.MicroList
  1611. sortList = list
  1612. sort.Sort(sortList)
  1613. resp := new(models.MicroRoadShowListResp)
  1614. page := paging.GetPaging(currentIndex, pageSize, total)
  1615. resp.List = sortList
  1616. resp.Paging = page
  1617. br.Ret = 200
  1618. br.Success = true
  1619. br.Msg = "获取成功"
  1620. br.Data = resp
  1621. }