user.go 53 KB

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