user.go 57 KB

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