user.go 49 KB

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