user.go 53 KB

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