user.go 59 KB

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