user.go 59 KB

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