user.go 57 KB

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