user.go 60 KB

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