user.go 55 KB

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