user.go 60 KB

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