user.go 47 KB

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