user.go 49 KB

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