user.go 50 KB

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