user.go 53 KB

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