user.go 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114
  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. inviteShareCode := req.InviteShareCode
  47. unionId := this.User.UnionId
  48. openId := this.User.OpenId
  49. if unionId == "" {
  50. br.Msg = "参数错误"
  51. br.ErrMsg = "参数错误,unionId 为空"
  52. return
  53. }
  54. if req.LoginType == 1 || req.LoginType == 3 {
  55. if req.Mobile == "" {
  56. br.Msg = "参数错误"
  57. br.ErrMsg = "参数错误,手机号为空 为空"
  58. return
  59. }
  60. if req.LoginType == 3 {
  61. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  62. if err != nil {
  63. if err.Error() == utils.ErrNoRow() {
  64. br.Msg = "验证码错误,请重新输入"
  65. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  66. return
  67. } else {
  68. br.Msg = "验证码错误,请重新输入"
  69. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  70. return
  71. }
  72. }
  73. if item == nil {
  74. br.Msg = "验证码错误,请重新输入"
  75. return
  76. }
  77. }
  78. req.Mobile = strings.Trim(req.Mobile, " ")
  79. } else if req.LoginType == 2 {
  80. if req.Email == "" {
  81. br.ErrMsg = "邮箱不能为空,请输入邮箱"
  82. br.Msg = "邮箱不能为空,请输入邮箱"
  83. return
  84. }
  85. if !utils.ValidateEmailFormatat(req.Email) {
  86. br.ErrMsg = "邮箱格式错误,请重新输入"
  87. br.Msg = "邮箱格式错误,请重新输入"
  88. return
  89. }
  90. item, err := models.GetMsgCode(req.Email, req.VCode)
  91. if err != nil {
  92. if err.Error() == utils.ErrNoRow() {
  93. br.Msg = "验证码错误,请重新输入"
  94. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  95. return
  96. } else {
  97. br.Msg = "验证码错误,请重新输入"
  98. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  99. return
  100. }
  101. }
  102. if item == nil {
  103. br.Msg = "验证码错误,请重新输入"
  104. return
  105. }
  106. } else {
  107. br.Msg = "无效的登录方式"
  108. br.ErrMsg = "无效的登录方式,Err:"
  109. return
  110. }
  111. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  112. req.CountryCode = "86"
  113. }
  114. user, err = services.BindWxUser(openId, req.Mobile, req.Email, req.CountryCode)
  115. if err != nil {
  116. br.Msg = "登录失败"
  117. br.ErrMsg = "绑定手机号失败:" + err.Error()
  118. return
  119. }
  120. userId := user.UserId
  121. var token string
  122. tokenItem, err := models.GetTokenByOpenId(openId)
  123. if err != nil && err.Error() != utils.ErrNoRow() {
  124. br.Msg = "登录失败"
  125. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  126. return
  127. }
  128. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  129. timeUnix := time.Now().Unix()
  130. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  131. token = utils.MD5(openId) + utils.MD5(timeUnixStr)
  132. //新增session
  133. {
  134. session := new(models.CygxSession)
  135. session.OpenId = unionId
  136. session.UnionId = unionId
  137. session.UserId = userId
  138. session.CreatedTime = time.Now()
  139. session.LastUpdatedTime = time.Now()
  140. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  141. session.AccessToken = token
  142. err = models.AddSession(session)
  143. if err != nil {
  144. br.Msg = "登录失败"
  145. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  146. return
  147. }
  148. }
  149. } else {
  150. token = tokenItem.AccessToken
  151. }
  152. //新增登录日志
  153. {
  154. loginLog := new(models.WxUserLog)
  155. loginLog.UserId = userId
  156. loginLog.OpenId = openId
  157. loginLog.Mobile = req.Mobile
  158. loginLog.Email = req.Email
  159. loginLog.CreateTime = time.Now()
  160. loginLog.Handle = "wechat_user_login"
  161. loginLog.Remark = token
  162. go models.AddWxUserLog(loginLog)
  163. }
  164. //添加邀请绑定关系
  165. {
  166. if req.ShareUserCode != "" {
  167. count, _ := models.GetUserInviteeCount(userId)
  168. if count == 0 {
  169. userItem := new(models.UserInvitee)
  170. userItem.CreateTime = time.Now()
  171. userItem.InviteedUserId = strconv.Itoa(userId)
  172. userItem.InviteeUserId = req.ShareUserCode
  173. shareUserId, _ := strconv.Atoi(req.ShareUserCode)
  174. inviteeUser, _ := models.GetWxUserItemByUserId(shareUserId)
  175. if inviteeUser != nil {
  176. userItem.InviteeMobile = inviteeUser.Mobile
  177. userItem.InviteeCompany = inviteeUser.CompanyName
  178. userItem.InviteeCompanyId = inviteeUser.CompanyId
  179. userItem.InviteeEmail = inviteeUser.Email
  180. }
  181. models.AddUserInvite(userItem)
  182. }
  183. }
  184. }
  185. {
  186. services.UpdateCygxSubscribe(userId, unionId) //先关注后登录,更新用户是否关注过查研观向小助手公众号
  187. if inviteShareCode != "" { //记录分享来源
  188. go services.AddCygxUserAdminShareHistory(user, "login", "", inviteShareCode, 0) //记录分享来源
  189. }
  190. }
  191. resp := new(models.LoginResp)
  192. resp.UserId = userId
  193. resp.Authorization = token
  194. if user.CompanyId == 1 {
  195. resp.IsPotential = true
  196. }
  197. br.Ret = 200
  198. br.Success = true
  199. br.Data = resp
  200. br.Msg = "登录成功"
  201. }
  202. // @Title 获取用户详情
  203. // @Description 获取用户详情接口
  204. // @Success 200 {object} models.UserDetail
  205. // @router /detail [get]
  206. func (this *UserController) Detail() {
  207. br := new(models.BaseResponse).Init()
  208. defer func() {
  209. this.Data["json"] = br
  210. this.ServeJSON()
  211. }()
  212. user := this.User
  213. if user == nil {
  214. br.Msg = "请登录"
  215. br.ErrMsg = "请登录,用户信息为空"
  216. br.Ret = 408
  217. return
  218. }
  219. uid := user.UserId
  220. var hasPermission int
  221. detail := new(models.UserDetail)
  222. if uid > 0 {
  223. var err error
  224. detail, err = models.GetUserDetailByUserId(uid)
  225. if err != nil && err.Error() != utils.ErrNoRow() {
  226. br.Msg = "获取信息失败"
  227. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  228. return
  229. }
  230. if detail == nil {
  231. br.Msg = "获取信息失败"
  232. br.ErrMsg = "获取信息失败,Err:用户不存在"
  233. return
  234. }
  235. totalCollect, err := models.GetArticleUserCollectCount(uid) // 文章收藏数量
  236. if err != nil {
  237. br.Msg = "获取数据失败"
  238. br.ErrMsg = "GetArticleUserCollectCount,Err:" + err.Error()
  239. return
  240. }
  241. endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
  242. totalHistory, err := models.GetArticleUserBrowseHistoryCount(uid, endDate) //足迹数量
  243. if err != nil {
  244. br.Msg = "获取数据失败"
  245. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  246. return
  247. }
  248. totalSchedule, err := models.GetArticleUserScheduleNum(uid) // 我的日程数量
  249. if err != nil {
  250. br.Msg = "获取数据失败"
  251. br.ErrMsg = "GetArticleUserScheduleNum,Err:" + err.Error()
  252. return
  253. }
  254. detail.ConNum = totalCollect
  255. detail.HistoryNum = totalHistory
  256. detail.ScheduleNum = totalSchedule
  257. userRecord, _ := models.GetUserRecordByUserId(uid, utils.WxPlatform)
  258. if userRecord != nil {
  259. detail.NickName = userRecord.NickName
  260. if detail.Headimgurl == "" {
  261. detail.Headimgurl = userRecord.Headimgurl
  262. }
  263. //if detail.Headimgurl == "" {
  264. // userRecord, _ = models.GetUserRecordByUserId(uid, 1)
  265. // if userRecord != nil {
  266. // detail.NickName = userRecord.NickName
  267. // detail.Headimgurl = userRecord.Headimgurl
  268. // }
  269. //}
  270. }
  271. if user.CompanyId > 1 {
  272. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  273. if err != nil && err.Error() != utils.ErrNoRow() {
  274. br.Msg = "获取信息失败"
  275. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  276. return
  277. }
  278. if companyItem != nil && companyItem.CompanyId > 1 {
  279. detail.CompanyName = companyItem.CompanyName
  280. detail.SellerName = companyItem.SellerName
  281. detail.SellerMobile = companyItem.Mobile
  282. microRoadshowCollectcount, err := models.GetUserMicroRoadshowCollectcount(user.UserId)
  283. if err != nil {
  284. br.Msg = "获取信息失败"
  285. br.ErrMsg = "获取微路演收藏信息失败,GetUserMicroRoadshowCollectcount Err:" + err.Error()
  286. return
  287. }
  288. detail.ConNum += microRoadshowCollectcount
  289. // 获取用户所在公司剩余的点
  290. companyPointsNum, err := models.GetCompanyPoints(user.CompanyId)
  291. if err != nil && err.Error() != utils.ErrNoRow() {
  292. br.Msg = "获取信息失败"
  293. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  294. return
  295. }
  296. detail.CompanyPointsNum = companyPointsNum
  297. userYanxunaDetail, err := models.GetCygxUserYanxuanPermissionDetailByUserId(user.UserId)
  298. if err != nil && err.Error() != utils.ErrNoRow() {
  299. br.Msg = "获取信息失败"
  300. br.ErrMsg = "获取信息失败,GetCygxUserYanxuanPermissionDetailByUserId Err:" + err.Error()
  301. return
  302. }
  303. if userYanxunaDetail != nil {
  304. detail.PermissionStatus = userYanxunaDetail.Status
  305. detail.StartDate = userYanxunaDetail.StartDate
  306. detail.EndDate = userYanxunaDetail.EndDate
  307. detail.PermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  308. } else {
  309. //查询研选的权限状态
  310. var condition string
  311. var pars []interface{}
  312. condition += " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id IN (31,52) "
  313. pars = append(pars, user.CompanyId)
  314. //companyReportPermissionDetail, err := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  315. //if err != nil && err.Error() != utils.ErrNoRow() {
  316. // br.Msg = "获取信息失败"
  317. // br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  318. // return
  319. //}
  320. companyReportPermissionList, err := models.GetCompanyReportPermissionList(condition, pars)
  321. if err != nil && err.Error() != utils.ErrNoRow() {
  322. br.Msg = "获取信息失败"
  323. br.ErrMsg = "获取用户所在公司剩余的点失败,Err:" + err.Error()
  324. return
  325. }
  326. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  327. if err != nil && err.Error() != utils.ErrNoRow() {
  328. br.Msg = "获取信息失败"
  329. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  330. return
  331. }
  332. var isSuspend int
  333. if companyProduct == nil {
  334. isSuspend = 1
  335. } else {
  336. isSuspend = companyProduct.IsSuspend
  337. }
  338. if len(companyReportPermissionList) == 0 || isSuspend == 1 {
  339. hasPermission = 1
  340. } else {
  341. //有研选订阅或研选扣点包任意一项试用权限,即为试用客户,期限显示两项合并之后的最长时间
  342. minDate := time.Now()
  343. maxDate := time.Now()
  344. var permissionStatus string
  345. for _, v := range companyReportPermissionList {
  346. if utils.StrDateToDate(v.StartDate).Before(minDate) {
  347. minDate = utils.StrDateToDate(v.StartDate)
  348. }
  349. if utils.StrDateToDate(v.EndDate).After(maxDate) {
  350. maxDate = utils.StrDateToDate(v.EndDate)
  351. }
  352. if permissionStatus != "正式" {
  353. permissionStatus = v.Status
  354. }
  355. }
  356. detail.PermissionStatus = permissionStatus
  357. detail.StartDate = minDate.Format(utils.FormatDate)
  358. detail.EndDate = maxDate.Format(utils.FormatDate)
  359. }
  360. }
  361. } else {
  362. hasPermission = 1
  363. }
  364. } else {
  365. //判断是否已经申请过
  366. applyCount, err := models.GetApplyRecordCount(uid)
  367. if err != nil && err.Error() != utils.ErrNoRow() {
  368. br.Msg = "获取信息失败"
  369. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  370. return
  371. }
  372. if applyCount > 0 {
  373. hasPermission = 3
  374. } else {
  375. hasPermission = 2
  376. }
  377. detail.CompanyName = detail.Note
  378. }
  379. detail.HasPermission = hasPermission
  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. detail.HasPermission = hasPermission
  391. }
  392. if detail.Headimgurl == "" {
  393. detail.Headimgurl = utils.DefaultHeadimgurl
  394. }
  395. if user.Mobile != "" {
  396. userCard, err := order.GetCygxOrderUserCardDetailByMobile(user.Mobile)
  397. if err != nil && err.Error() != utils.ErrNoRow() {
  398. br.Msg = "获取信息失败"
  399. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  400. return
  401. }
  402. if userCard != nil {
  403. if userCard.CardType == "日卡" {
  404. detail.UserCardType = 1 //权益卡类型
  405. detail.UserCardEndDate = userCard.EndDate.Format(utils.FormatDateTime)
  406. } else {
  407. detail.UserCardType = 2
  408. detail.UserCardEndDate = userCard.EndDate.Format(utils.FormatDate)
  409. }
  410. }
  411. }
  412. if detail.Mobile != "" {
  413. detail.InviteShareCode = services.GetInviteShareCode(detail.Mobile) //判断用户是否属于销售,并且获取对应加密的分享码
  414. }
  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. var isResearch bool // 是否属于研选
  900. if tryType == "Article" {
  901. detail, err := models.GetArticleDetailById(detailId)
  902. if err != nil {
  903. br.Msg = "获取信息失败"
  904. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  905. return
  906. }
  907. title = detail.Title
  908. if detail.ArticleTypeId > 0 {
  909. isResearch = true
  910. }
  911. } else if tryType == "Activity" {
  912. detail, err := models.GetAddActivityInfoById(detailId)
  913. if err != nil {
  914. br.Msg = "操作失败"
  915. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(detailId)
  916. return
  917. }
  918. title = detail.ActivityName
  919. if strings.Contains(detail.ChartPermissionName, utils.CHART_PERMISSION_NAME_YANXUAN) {
  920. isResearch = true
  921. }
  922. } else if tryType == "MicroAudio" {
  923. // 微路演音频
  924. microAudio, e := models.GetCygxActivityVoiceById(detailId)
  925. if e != nil {
  926. br.Msg = "操作失败"
  927. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  928. return
  929. }
  930. title = microAudio.VoiceName
  931. sourceId = microAudio.ActivityId
  932. source = "activityvoice"
  933. } else if tryType == "ActivityVideo" {
  934. // 活动视频
  935. activityVideo, e := models.GetCygxActivityVideoById(detailId)
  936. if e != nil {
  937. br.Msg = "操作失败"
  938. br.ErrMsg = "微路演音频信息有误, 不存在的VoiceId: " + strconv.Itoa(detailId)
  939. return
  940. }
  941. title = activityVideo.VideoName
  942. sourceId = activityVideo.ActivityId
  943. source = "activityvideo"
  944. } else if tryType == "MicroVideo" {
  945. // 微路演视频
  946. microVideo, e := models.GetMicroRoadshowVideoById(detailId)
  947. if e != nil {
  948. br.Msg = "操作失败"
  949. br.ErrMsg = "微路演视频信息有误, 不存在的VideoId: " + strconv.Itoa(detailId)
  950. return
  951. }
  952. title = microVideo.VideoName
  953. source = "roadshow"
  954. } else if tryType == "Researchsummary" {
  955. // 本周研究汇总
  956. ResearchSummaryInfo, e := models.GetCygxResearchSummaryInfoById(detailId)
  957. if e != nil {
  958. br.Msg = "操作失败"
  959. br.ErrMsg = "本周研究汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  960. return
  961. }
  962. title = ResearchSummaryInfo.Title
  963. source = "researchsummary"
  964. } else if tryType == "Minutessummary" {
  965. // 上周纪要汇总
  966. MinutesSummaryInfo, e := models.GetCygxMinutesSummaryInfoById(detailId)
  967. if e != nil {
  968. br.Msg = "操作失败"
  969. br.ErrMsg = "上周纪要汇总信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  970. return
  971. }
  972. title = MinutesSummaryInfo.Title
  973. source = "minutessummary"
  974. } else if tryType == "ReportSelection" {
  975. // 报告精选
  976. ReportSelectionInfo, e := models.GetCygxReportSelectionInfoById(detailId)
  977. if e != nil {
  978. br.Msg = "操作失败"
  979. br.ErrMsg = "报告精选信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  980. return
  981. }
  982. title = ReportSelectionInfo.Title
  983. source = "reportselection"
  984. } else if tryType == "ProductInterior" {
  985. // 产品内测
  986. ProductInteriorDetail, e := models.GetCygxProductInteriorDetail(detailId)
  987. if e != nil {
  988. br.Msg = "操作失败"
  989. br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  990. return
  991. }
  992. title = ProductInteriorDetail.Title
  993. source = "productinterior"
  994. } else if tryType == "YanxuanSpecial" {
  995. // 研选专栏
  996. YanxuanSpecialBySpeciaDetail, e := models.GetYanxuanSpecialBySpecialId(detailId)
  997. if e != nil {
  998. br.Msg = "操作失败"
  999. br.ErrMsg = "产品内测信息有误, 不存在的detailId: " + strconv.Itoa(detailId)
  1000. return
  1001. }
  1002. title = YanxuanSpecialBySpeciaDetail.Title
  1003. source = "yanxuanspecial"
  1004. isResearch = true
  1005. }
  1006. //缓存校验
  1007. cacheKey := fmt.Sprint("xygx:apply_record:add:", uid)
  1008. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  1009. if ttlTime > 0 {
  1010. br.Msg = "申请失败,申请过于频繁"
  1011. br.ErrMsg = "申请失败,申请过于频繁"
  1012. return
  1013. }
  1014. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  1015. //判断是否已经申请过
  1016. applyCount, err := models.GetApplyRecordCount(uid)
  1017. if err != nil && err.Error() != utils.ErrNoRow() {
  1018. br.Msg = "获取信息失败"
  1019. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1020. return
  1021. }
  1022. if applyCount > 0 {
  1023. br.Msg = "您已提交申请,请耐心等待。"
  1024. br.IsSendEmail = false
  1025. return
  1026. }
  1027. //判断是否存在申请
  1028. var sellerMobile string
  1029. if req.ApplyMethod == 2 {
  1030. if req.BusinessCardUrl == "" {
  1031. br.Msg = "请上传名片"
  1032. return
  1033. }
  1034. if req.RealName == "" {
  1035. br.Msg = "请输入姓名"
  1036. return
  1037. }
  1038. if req.CompanyName == "" {
  1039. br.Msg = "请输入公司名称"
  1040. return
  1041. }
  1042. if req.BusinessCardUrl != "" && utils.RunMode == "release" {
  1043. card, err := services.GetBusinessCard(req.BusinessCardUrl)
  1044. if err != nil {
  1045. br.Msg = "名片识别失败"
  1046. br.ErrMsg = "名片识别失败,Err:" + err.Error()
  1047. return
  1048. }
  1049. mobileStr := strings.Join(card.WordsResult.MOBILE, ",")
  1050. isFlag := true
  1051. if mobile != "" {
  1052. if strings.Contains(mobileStr, mobile) || mobileStr == "" {
  1053. isFlag = true
  1054. } else {
  1055. isFlag = false
  1056. }
  1057. }
  1058. if !isFlag {
  1059. //阿里云识别
  1060. if utils.RunMode == "release" {
  1061. aliyunResult, err := services.AliyunBusinessCard(req.BusinessCardUrl)
  1062. if err != nil {
  1063. br.Msg = "识别失败"
  1064. br.ErrMsg = "识别失败,Err:" + err.Error()
  1065. return
  1066. }
  1067. if !aliyunResult.Success {
  1068. br.Msg = "识别失败"
  1069. br.ErrMsg = "识别失败"
  1070. return
  1071. }
  1072. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  1073. if mobile != "" {
  1074. if strings.Contains(mobileStr, mobile) {
  1075. isFlag = true
  1076. } else {
  1077. isFlag = false
  1078. }
  1079. }
  1080. }
  1081. }
  1082. if !isFlag {
  1083. br.Msg = "名片手机号与所填手机号不匹配,请重新填写"
  1084. br.ErrMsg = "mobile:" + mobile
  1085. return
  1086. }
  1087. }
  1088. }
  1089. //获取销售信息
  1090. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1091. if err != nil && err.Error() != utils.ErrNoRow() {
  1092. br.Msg = "申请失败"
  1093. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1094. return
  1095. }
  1096. shareSellerItem, err := models.GetShareSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1097. if err != nil && err.Error() != utils.ErrNoRow() {
  1098. br.Msg = "申请失败"
  1099. br.ErrMsg = "获取共享销售信息失败,Err:" + err.Error()
  1100. return
  1101. }
  1102. if shareSellerItem != nil {
  1103. sellerItem = shareSellerItem
  1104. }
  1105. //用户状态,1:潜在客户 、2:现有客户 、3:FICC客户 、4:现有客户(正式,无对应权限) 、5:现有客户(试用,无对应权限) 、6:现有客户(试用暂停) 、7:现有客户(冻结) 、8:现有客户(流失)?
  1106. CompanyIdType := 1
  1107. applyMethod := ""
  1108. if sellerItem != nil {
  1109. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1110. if err != nil && err.Error() != utils.ErrNoRow() {
  1111. br.Msg = "获取信息失败"
  1112. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1113. return
  1114. }
  1115. if companyItem != nil && companyItem.CompanyId > 0 {
  1116. companyProduct, err := models.GetCompanyProductDetail(user.CompanyId, 2)
  1117. if err != nil && err.Error() != utils.ErrNoRow() {
  1118. br.Msg = "获取信息失败"
  1119. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1120. return
  1121. }
  1122. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  1123. CompanyIdType = 6
  1124. } else {
  1125. switch companyItem.Status {
  1126. case "正式":
  1127. CompanyIdType = 4
  1128. case "试用":
  1129. CompanyIdType = 5
  1130. case "冻结":
  1131. CompanyIdType = 7
  1132. case "流失":
  1133. CompanyIdType = 8
  1134. }
  1135. }
  1136. applyMethod = companyItem.Status + "客户申请"
  1137. if detailId > 0 {
  1138. if companyProduct != nil && companyProduct.IsSuspend == 1 {
  1139. applyMethod = "试用暂停客户"
  1140. } else {
  1141. if companyItem.Status == "正式" || companyItem.Status == "试用" {
  1142. applyMethod = companyItem.Status + "客户申请,无对应权限"
  1143. } else if companyItem.Status == "冻结" || companyItem.Status == "流失" {
  1144. applyMethod = companyItem.Status + "客户"
  1145. }
  1146. }
  1147. applyMethod = applyMethod + "," + title
  1148. }
  1149. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1150. if openIpItem != nil && openIpItem.OpenId != "" {
  1151. if req.ApplyMethod != 2 {
  1152. req.RealName = user.RealName
  1153. req.CompanyName = user.CompanyName
  1154. }
  1155. //go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1156. }
  1157. }
  1158. } else {
  1159. //获取销售信息
  1160. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  1161. if err != nil && err.Error() != utils.ErrNoRow() {
  1162. br.Msg = "申请失败"
  1163. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1164. return
  1165. }
  1166. if sellerItem != nil {
  1167. CompanyIdType = 3
  1168. applyMethod = "FICC客户"
  1169. } else {
  1170. CompanyIdType = 1
  1171. applyMethod = "潜在客户"
  1172. }
  1173. if detailId > 0 {
  1174. applyMethod = applyMethod + "," + title
  1175. }
  1176. }
  1177. item := new(models.CygxApplyRecord)
  1178. item.UserId = user.UserId
  1179. item.BusinessCardUrl = req.BusinessCardUrl
  1180. item.RealName = req.RealName
  1181. item.CompanyName = req.CompanyName
  1182. item.Mobile = user.Mobile
  1183. item.CreateTime = time.Now()
  1184. item.ApplyMethod = req.ApplyMethod
  1185. item.CompanyIdPay = user.CompanyId
  1186. item.CompanyNamePay = user.CompanyName
  1187. item.CompanyIdType = CompanyIdType
  1188. if user.InviteCompany == utils.LUODING_CODE && user.CompanyId == 1 {
  1189. //如果是潜在客户就标记来源
  1190. item.InviteCompanySource = 2
  1191. }
  1192. item.Title = title
  1193. item.SourceId = sourceId
  1194. item.Source = strings.ToLower(source)
  1195. item.RegisterPlatform = utils.REGISTER_PLATFORM
  1196. err = models.AddApplyRecord(item)
  1197. if err != nil {
  1198. br.Msg = "申请失败"
  1199. br.ErrMsg = "申请失败,Err:" + err.Error()
  1200. return
  1201. }
  1202. if sellerItem == nil {
  1203. go services.SendPermissionApplyTemplateMsgAdmin(req, mobile, applyMethod, isResearch)
  1204. } else {
  1205. openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile)
  1206. if openIpItem != nil && openIpItem.OpenId != "" {
  1207. go services.SendPermissionApplyTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1208. go services.SendPermissionApplyCategoryTemplateMsg(req.RealName, req.CompanyName, mobile, applyMethod, openIpItem)
  1209. }
  1210. }
  1211. //添加成功后,设置5分钟缓存,不允许重复添加
  1212. //utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*60)
  1213. br.Msg = "申请成功!"
  1214. br.Ret = 200
  1215. br.Success = true
  1216. br.Data = sellerMobile
  1217. }
  1218. // @Title 是否需要填写区号
  1219. // @Description 获取是否需要填写区号接口
  1220. // @Success 200 {object} models.CountryCode
  1221. // @router /countryCcode/isNeedAdd [get]
  1222. func (this *UserController) CountryCcode() {
  1223. br := new(models.BaseResponse).Init()
  1224. defer func() {
  1225. this.Data["json"] = br
  1226. this.ServeJSON()
  1227. }()
  1228. user := this.User
  1229. uid := user.UserId
  1230. if user == nil {
  1231. br.Msg = "请登录"
  1232. br.ErrMsg = "请登录,用户信息为空"
  1233. br.Ret = 408
  1234. return
  1235. }
  1236. //if uid == 0 {
  1237. // br.Msg = "请登录"
  1238. // br.ErrMsg = "请登录,用户信息为空"
  1239. // br.Ret = 408
  1240. // return
  1241. //}
  1242. resp := new(models.CountryCode)
  1243. if user.CountryCode == "" && len(user.Mobile) >= 11 {
  1244. err := models.ChangeUserOutboundMobileByMobile(uid)
  1245. if err != nil {
  1246. br.Msg = "操作失败"
  1247. br.ErrMsg = "操作失败,Err:" + err.Error()
  1248. return
  1249. }
  1250. }
  1251. if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
  1252. resp.IsNeedAddCountryCode = true
  1253. }
  1254. if user.OutboundMobile != "" {
  1255. resp.IsNeedAddCountryCode = false
  1256. }
  1257. br.Ret = 200
  1258. br.Success = true
  1259. br.Msg = "获取成功"
  1260. br.Data = resp
  1261. }
  1262. // @Title 上传用户区号
  1263. // @Description 上传用户区号接口
  1264. // @Param request body models.CountryCodeItem true "type json string"
  1265. // @Success Ret=200 新增成功
  1266. // @router /countryCcode/Add [POST]
  1267. func (this *UserController) AddCountryCcode() {
  1268. br := new(models.BaseResponse).Init()
  1269. defer func() {
  1270. this.Data["json"] = br
  1271. this.ServeJSON()
  1272. }()
  1273. user := this.User
  1274. if user == nil {
  1275. br.Msg = "请登录"
  1276. br.ErrMsg = "请登录,用户信息为空"
  1277. br.Ret = 408
  1278. return
  1279. }
  1280. var req models.CountryCodeItem
  1281. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1282. if err != nil {
  1283. br.Msg = "参数解析异常!"
  1284. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1285. return
  1286. }
  1287. err = models.AddCountryCode(req.CountryCode, user)
  1288. if err != nil {
  1289. br.Msg = "获取信息失败"
  1290. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  1291. return
  1292. }
  1293. br.Ret = 200
  1294. br.Success = true
  1295. br.Msg = "新增成功"
  1296. }
  1297. // @Title 用户修改外呼手机号以及区号
  1298. // @Description 用户修改外呼手机号以及区号接口
  1299. // @Param request body models.OutboundMobileItem true "type json string"
  1300. // @Success Ret=200 操作成功
  1301. // @router /countryCcode/addOutboundMobile [POST]
  1302. func (this *UserController) AddOutboundMobile() {
  1303. br := new(models.BaseResponse).Init()
  1304. defer func() {
  1305. this.Data["json"] = br
  1306. this.ServeJSON()
  1307. }()
  1308. user := this.User
  1309. uid := user.UserId
  1310. if user == nil {
  1311. br.Msg = "请登录"
  1312. br.ErrMsg = "请登录,用户信息为空"
  1313. br.Ret = 408
  1314. return
  1315. }
  1316. var req models.OutboundMobileItem
  1317. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1318. if err != nil {
  1319. br.Msg = "参数解析异常!"
  1320. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1321. return
  1322. }
  1323. if !utils.ValidateFixedTelephoneFormatatEasy(req.OutboundMobile) {
  1324. br.Msg = "号码格式有误,请重新填写!"
  1325. br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
  1326. return
  1327. }
  1328. if req.OutboundMobile == "" {
  1329. br.Msg = "请填写区号!"
  1330. return
  1331. }
  1332. item := new(models.OutboundMobileItem)
  1333. item.OutboundMobile = req.OutboundMobile
  1334. item.OutboundCountryCode = req.OutboundCountryCode
  1335. item.ActivityId = req.ActivityId
  1336. if req.ActivityId == 0 {
  1337. err = models.AddOutboundMobile(item, uid)
  1338. } else {
  1339. if user.Mobile == "" && user.OutboundMobile == "" {
  1340. items := new(models.CygxActivitySignup)
  1341. items.UserId = uid
  1342. items.ActivityId = req.ActivityId
  1343. items.CreateTime = time.Now()
  1344. items.Mobile = user.Mobile
  1345. items.Email = user.Email
  1346. items.CompanyId = user.CompanyId
  1347. items.CompanyName = user.CompanyName
  1348. items.SignupType = 1
  1349. items.FailType = 0
  1350. items.DoFailType = 0
  1351. items.OutboundMobile = req.OutboundMobile
  1352. items.CountryCode = req.OutboundCountryCode
  1353. _, err = models.AddActivitySignupFromEmail(items)
  1354. } else {
  1355. total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
  1356. if total == 0 {
  1357. br.Msg = "报名信息不存在"
  1358. br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
  1359. return
  1360. }
  1361. if err != nil {
  1362. br.Msg = "操作失败"
  1363. br.ErrMsg = "操作失败,Err:" + err.Error()
  1364. return
  1365. }
  1366. err = models.AddOutboundMobile(item, uid)
  1367. }
  1368. }
  1369. if err != nil {
  1370. br.Msg = "操作失败"
  1371. br.ErrMsg = "操作失败,Err:" + err.Error()
  1372. return
  1373. }
  1374. br.Ret = 200
  1375. br.Success = true
  1376. br.Msg = "操作成功"
  1377. }
  1378. // @Title 获取我的提问
  1379. // @Description 获取我的提问列表
  1380. // @Success 200 {object} models.CygxAskListResp
  1381. // @router /ask/list [get]
  1382. func (this *UserController) AskList() {
  1383. br := new(models.BaseResponse).Init()
  1384. defer func() {
  1385. this.Data["json"] = br
  1386. this.ServeJSON()
  1387. }()
  1388. user := this.User
  1389. if user == nil {
  1390. br.Msg = "请登录"
  1391. br.ErrMsg = "请登录,用户信息为空"
  1392. br.Ret = 408
  1393. return
  1394. }
  1395. userId := this.User.UserId
  1396. listActcivity, err := models.GetActivityAskList(userId)
  1397. if err != nil && err.Error() != utils.ErrNoRow() {
  1398. br.Msg = "获取失败"
  1399. br.ErrMsg = "获取活动问题失败,Err:" + err.Error()
  1400. return
  1401. }
  1402. for _, v := range listActcivity {
  1403. v.AskType = "Activity"
  1404. }
  1405. listArticle, err := models.GetArticleAskList(userId)
  1406. if err != nil && err.Error() != utils.ErrNoRow() {
  1407. br.Msg = "获取失败"
  1408. br.ErrMsg = "获取文章问题失败,Err:" + err.Error()
  1409. return
  1410. }
  1411. for _, v := range listArticle {
  1412. v.AskType = "Report"
  1413. listActcivity = append(listActcivity, v)
  1414. }
  1415. resp := new(models.CygxAskListResp)
  1416. resp.List = listActcivity
  1417. br.Msg = "获取成功!"
  1418. br.Ret = 200
  1419. br.Success = true
  1420. br.Data = resp
  1421. }
  1422. // @Title 是否展示免费试用按钮
  1423. // @Description 获取是否展示免费试用按钮接口
  1424. // @Param request body models.IsShow true "type json string"
  1425. // @Success 200
  1426. // @router /isShow/freeButton [get]
  1427. func (this *UserController) IsShow() {
  1428. br := new(models.BaseResponse).Init()
  1429. defer func() {
  1430. this.Data["json"] = br
  1431. this.ServeJSON()
  1432. }()
  1433. user := this.User
  1434. if user == nil {
  1435. br.Msg = "请重新登录"
  1436. br.Ret = 408
  1437. return
  1438. }
  1439. var resp models.IsShow
  1440. detail, err := models.GetConfigByCode("free_trial_card")
  1441. if err != nil {
  1442. br.Msg = "获取数据失败"
  1443. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1444. return
  1445. }
  1446. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1447. if err != nil && err.Error() != utils.ErrNoRow() {
  1448. br.Msg = "获取数据失败!"
  1449. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1450. return
  1451. }
  1452. count, err := models.CountCygxUserFreeeButton(user.UserId)
  1453. if err != nil && err.Error() != utils.ErrNoRow() {
  1454. br.Msg = "获取数据失败!"
  1455. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1456. return
  1457. }
  1458. if companyDetail != nil && companyDetail.IsSuspend == 0 {
  1459. if detail.ConfigValue == "1" && (companyDetail.Status == "正式" || companyDetail.Status == "试用" || companyDetail.Status == "永续") && count == 0 {
  1460. resp.IsShow = true
  1461. }
  1462. }
  1463. br.Ret = 200
  1464. br.Success = true
  1465. br.Data = resp
  1466. }
  1467. // @Title 隐藏当天的按钮
  1468. // @Description 隐藏当天的按钮接口
  1469. // @Success 200
  1470. // @router /freeButton/update [post]
  1471. func (this *UserController) FreeButtonUpdate() {
  1472. br := new(models.BaseResponse).Init()
  1473. defer func() {
  1474. this.Data["json"] = br
  1475. this.ServeJSON()
  1476. }()
  1477. user := this.User
  1478. if user == nil {
  1479. br.Msg = "请重新登录"
  1480. br.Ret = 408
  1481. return
  1482. }
  1483. count, err := models.CountCygxUserFreeeButtonByUser(user.UserId)
  1484. if err != nil {
  1485. br.Msg = "获取数据失败!"
  1486. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1487. return
  1488. }
  1489. if count == 0 {
  1490. item := new(models.CygxUserFreeeButton)
  1491. item.UserId = user.UserId
  1492. item.CompanyId = user.CompanyId
  1493. item.CreateTime = time.Now()
  1494. item.ModifyTime = time.Now()
  1495. item.EffectiveTime = time.Now().Format(utils.FormatDate)
  1496. _, err := models.AddCygxUserFreeeButton(item)
  1497. if err != nil {
  1498. br.Msg = "操作失败!"
  1499. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1500. return
  1501. }
  1502. } else {
  1503. err := models.UpdateCygxUserFreeeButton(user.UserId)
  1504. if err != nil {
  1505. br.Msg = "操作失败!"
  1506. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1507. return
  1508. }
  1509. }
  1510. br.Ret = 200
  1511. br.Success = true
  1512. br.Msg = "操作成功!"
  1513. }
  1514. // @Title 权限弹窗是否展示免费月卡
  1515. // @Description 获取权限弹窗是否展示免费月卡接口
  1516. // @Param request body models.IsShow true "type json string"
  1517. // @Success 200
  1518. // @router /isShow/alert [get]
  1519. func (this *UserController) AlertIsShow() {
  1520. br := new(models.BaseResponse).Init()
  1521. defer func() {
  1522. this.Data["json"] = br
  1523. this.ServeJSON()
  1524. }()
  1525. user := this.User
  1526. if user == nil {
  1527. br.Msg = "请重新登录"
  1528. br.Ret = 408
  1529. return
  1530. }
  1531. var resp models.IsShow
  1532. detail, err := models.GetConfigByCode("free_trial_card")
  1533. if err != nil {
  1534. br.Msg = "获取数据失败"
  1535. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1536. return
  1537. }
  1538. if user.CompanyId == 1 && detail.ConfigValue == "1" {
  1539. resp.IsShow = true
  1540. }
  1541. br.Ret = 200
  1542. br.Success = true
  1543. br.Data = resp
  1544. }
  1545. // @Title 分享的时候是否展示免费月卡
  1546. // @Description 获取权限弹窗是否展示免费月卡接口
  1547. // @Param request body models.IsShow true "type json string"
  1548. // @Success 200
  1549. // @router /isShow/share [get]
  1550. func (this *UserController) ShareIsShow() {
  1551. br := new(models.BaseResponse).Init()
  1552. defer func() {
  1553. this.Data["json"] = br
  1554. this.ServeJSON()
  1555. }()
  1556. user := this.User
  1557. if user == nil {
  1558. br.Msg = "请重新登录"
  1559. br.Ret = 408
  1560. return
  1561. }
  1562. var resp models.IsShow
  1563. detail, err := models.GetConfigByCode("free_trial_card")
  1564. if err != nil {
  1565. br.Msg = "获取数据失败"
  1566. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  1567. return
  1568. }
  1569. if user.CompanyId != 16 && detail.ConfigValue == "1" {
  1570. resp.IsShow = true
  1571. }
  1572. resp.LinkWxExplain = utils.LINK_WX_EXPLAIN
  1573. br.Ret = 200
  1574. br.Success = true
  1575. br.Data = resp
  1576. }
  1577. // @Title 更改用户微信头像
  1578. // @Description 更改用户微信头像
  1579. // @Param request body models.Headimgurl true "type json string"
  1580. // @Success 200 {object} models.ArticleDetailFileLink
  1581. // @router /headimgurl/update [post]
  1582. func (this *UserController) HeadimgurlUpdate() {
  1583. br := new(models.BaseResponse).Init()
  1584. defer func() {
  1585. this.Data["json"] = br
  1586. this.ServeJSON()
  1587. }()
  1588. user := this.User
  1589. if user == nil {
  1590. br.Msg = "请登录"
  1591. br.ErrMsg = "请登录,用户信息为空"
  1592. br.Ret = 408
  1593. return
  1594. }
  1595. var req models.Headimgurl
  1596. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1597. if err != nil {
  1598. br.Msg = "参数解析异常!"
  1599. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1600. return
  1601. }
  1602. uid := user.UserId
  1603. headimgurl := req.Headimgurl
  1604. if headimgurl == "" {
  1605. br.Msg = "操作失败"
  1606. br.ErrMsg = "头像信息不能为空"
  1607. return
  1608. }
  1609. err = models.UpdateUserHeadimgurl(headimgurl, uid)
  1610. if err != nil {
  1611. br.Msg = "操作失败"
  1612. br.ErrMsg = "头像信息不能为空"
  1613. }
  1614. br.Ret = 200
  1615. br.Success = true
  1616. br.Msg = "操作成功"
  1617. }
  1618. // @Title 登录 (无需token)
  1619. // @Description 登录接口 (无需token)
  1620. // @Param request body models.LoginReq true "type json string"
  1621. // @Success 200 {object} models.LoginResp
  1622. // @router /loginPublic [post]
  1623. func (this *UserCommonController) LoginPublic() {
  1624. br := new(models.BaseResponse).Init()
  1625. defer func() {
  1626. this.Data["json"] = br
  1627. this.ServeJSON()
  1628. }()
  1629. var req models.LoginReq
  1630. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1631. if err != nil {
  1632. br.Msg = "参数解析异常!"
  1633. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1634. return
  1635. }
  1636. mobile := strings.Trim(req.Mobile, " ")
  1637. if req.Mobile == "" {
  1638. br.Msg = "参数错误"
  1639. br.ErrMsg = "参数错误,手机号为空 为空"
  1640. return
  1641. }
  1642. item, err := models.GetMsgCode(req.Mobile, req.VCode)
  1643. if err != nil {
  1644. if err.Error() == utils.ErrNoRow() {
  1645. br.Msg = "验证码错误,请重新输入"
  1646. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1647. return
  1648. } else {
  1649. br.Msg = "验证码错误,请重新输入"
  1650. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  1651. return
  1652. }
  1653. }
  1654. if item == nil {
  1655. br.Msg = "验证码错误,请重新输入"
  1656. return
  1657. }
  1658. if len(req.Mobile) >= 11 && req.CountryCode == "" {
  1659. req.CountryCode = "86"
  1660. }
  1661. var token string
  1662. tokenItem, err := models.GetSessionMobileTokenByOpenId(mobile)
  1663. if err != nil && err.Error() != utils.ErrNoRow() {
  1664. br.Msg = "登录失败"
  1665. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  1666. return
  1667. }
  1668. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  1669. timeUnix := time.Now().Unix()
  1670. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  1671. token = utils.MD5(mobile) + utils.MD5(timeUnixStr)
  1672. //新增session
  1673. {
  1674. session := new(models.CygxSessionMobile)
  1675. session.Mobile = mobile
  1676. session.CreatedTime = time.Now()
  1677. session.LastUpdatedTime = time.Now()
  1678. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  1679. session.AccessToken = token
  1680. err = models.AddCygxSessionMobile(session)
  1681. if err != nil {
  1682. br.Msg = "登录失败"
  1683. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  1684. return
  1685. }
  1686. }
  1687. } else {
  1688. token = tokenItem.AccessToken
  1689. }
  1690. resp := new(models.LoginResp)
  1691. resp.Authorization = token
  1692. br.Ret = 200
  1693. br.Success = true
  1694. br.Data = resp
  1695. br.Msg = "登录成功"
  1696. }
  1697. // @Title 获取我的留言
  1698. // @Description 获取我的留言列表
  1699. // @Success 200 {object} models.CygxCommentListResp
  1700. // @router /comment/list [get]
  1701. func (this *UserController) CommnetList() {
  1702. br := new(models.BaseResponse).Init()
  1703. defer func() {
  1704. this.Data["json"] = br
  1705. this.ServeJSON()
  1706. }()
  1707. user := this.User
  1708. if user == nil {
  1709. br.Msg = "请登录"
  1710. br.ErrMsg = "请登录,用户信息为空"
  1711. br.Ret = 408
  1712. return
  1713. }
  1714. userId := this.User.UserId
  1715. commentlist, err := models.GetCommentList(userId)
  1716. if err != nil && err.Error() != utils.ErrNoRow() {
  1717. br.Msg = "获取失败"
  1718. br.ErrMsg = "获取我的留言列表失败,Err:" + err.Error()
  1719. return
  1720. }
  1721. articleLyjhMap, _ := services.GetLyjhArticleMap()
  1722. articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)
  1723. resp := new(models.CygxCommentListResp)
  1724. for _, comment := range commentlist {
  1725. item := models.CygxArticleCommentResp{
  1726. Id: comment.Id,
  1727. UserId: comment.UserId,
  1728. ArticleId: comment.ArticleId,
  1729. IndustryId: comment.IndustryId,
  1730. ActivityId: comment.ActivityId,
  1731. CreateTime: comment.CreateTime,
  1732. Mobile: comment.Mobile,
  1733. Email: comment.Email,
  1734. CompanyId: comment.CompanyId,
  1735. CompanyName: comment.CompanyName,
  1736. Content: comment.Content,
  1737. Title: comment.Title,
  1738. }
  1739. if comment.ArticleId > 0 {
  1740. item.RedirectType = 1
  1741. } else if comment.IndustryId > 0 {
  1742. item.RedirectType = 3
  1743. } else if comment.ActivityId > 0 {
  1744. item.RedirectType = 2
  1745. }
  1746. item.IsCollect = articleCollectMap[comment.ArticleId]
  1747. item.IsRoadShow = articleLyjhMap[comment.ArticleId]
  1748. resp.List = append(resp.List, &item)
  1749. }
  1750. br.Msg = "获取成功!"
  1751. br.Ret = 200
  1752. br.Success = true
  1753. br.Data = resp
  1754. }
  1755. // @Title 获取我的收藏
  1756. // @Description 获取我的收藏列表
  1757. // @Success 200 {object} models.ArticleCollectListResp
  1758. // @router /collect/list/microRoadshow [get]
  1759. func (this *UserController) MicroRoadshowCollectList() {
  1760. br := new(models.BaseResponse).Init()
  1761. defer func() {
  1762. this.Data["json"] = br
  1763. this.ServeJSON()
  1764. }()
  1765. userId := this.User.UserId
  1766. list, err := models.GetUserMicroRoadshowCollectList(userId)
  1767. if err != nil {
  1768. br.Msg = "获取数据失败"
  1769. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1770. return
  1771. }
  1772. resp := new(models.MicroRoadshowCollectList)
  1773. var audioIds []string
  1774. var videoIds []string
  1775. var activityVideoIds []string
  1776. for _, item := range list {
  1777. if item.ActivityVoiceId > 0 {
  1778. audioIds = append(audioIds, strconv.Itoa(item.ActivityVoiceId))
  1779. } else if item.VideoId > 0 {
  1780. videoIds = append(videoIds, strconv.Itoa(item.VideoId))
  1781. } else if item.ActivityVideoId > 0 {
  1782. activityVideoIds = append(activityVideoIds, strconv.Itoa(item.ActivityVideoId))
  1783. }
  1784. }
  1785. resp.AudioIds = strings.Join(audioIds, ",")
  1786. resp.VideoIds = strings.Join(videoIds, ",")
  1787. resp.ActivityVideoIds = strings.Join(activityVideoIds, ",")
  1788. br.Msg = "获取成功!"
  1789. br.Ret = 200
  1790. br.Success = true
  1791. br.Data = resp
  1792. }
  1793. // @Title 新增埋点
  1794. // @Description 新增埋点接口
  1795. // @Success 200 "新增成功!"
  1796. // @router /tracking [get]
  1797. func (this *UserController) Tracking() {
  1798. br := new(models.BaseResponse).Init()
  1799. defer func() {
  1800. this.Data["json"] = br
  1801. this.ServeJSON()
  1802. }()
  1803. user := this.User
  1804. if user == nil {
  1805. br.Msg = "请登录"
  1806. br.ErrMsg = "请登录,用户信息为空"
  1807. br.Ret = 408
  1808. return
  1809. }
  1810. //item := new(models.CygxPageHistoryRecord)
  1811. //item.UserId = user.UserId
  1812. //item.CreateTime = time.Now()
  1813. //item.Mobile = user.Mobile
  1814. //item.Email = user.Email
  1815. //item.CompanyId = user.CompanyId
  1816. //item.CompanyName = user.CompanyName
  1817. //item.Router = this.Ctx.Request.RequestURI
  1818. //item.PageRouter = this.Ctx.Input.Query("PageRouter")
  1819. //
  1820. //go models.AddCygxPageHistoryRecord(item)
  1821. //
  1822. br.Msg = "新增成功!"
  1823. br.Ret = 200
  1824. br.Success = true
  1825. }
  1826. // @Title 未付费申请试用详情
  1827. // @Description 未付费申请试用详情接口
  1828. // @Param ApplyRecordId query int true "申请ID"
  1829. // @Success 200 {object} models.ArticleCollectListResp
  1830. // @Success 200
  1831. // @router /apply/detail [get]
  1832. func (this *UserController) ApplyDetail() {
  1833. br := new(models.BaseResponse).Init()
  1834. defer func() {
  1835. this.Data["json"] = br
  1836. this.ServeJSON()
  1837. }()
  1838. user := this.User
  1839. if user == nil {
  1840. br.Msg = "请登录"
  1841. br.ErrMsg = "请登录,SysUser Is Empty"
  1842. br.Ret = 408
  1843. return
  1844. }
  1845. resp := new(models.CygxApplyRecordDetialResp)
  1846. applyRecordId, _ := this.GetInt("ApplyRecordId")
  1847. detail, err := models.GetCygxApplyRecordById(applyRecordId)
  1848. if err != nil {
  1849. br.Msg = "获取数据失败"
  1850. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1851. return
  1852. }
  1853. switch detail.RegisterPlatform {
  1854. case 1:
  1855. detail.ApplicationSource = "小程序"
  1856. case 2:
  1857. detail.ApplicationSource = "网页版"
  1858. }
  1859. switch detail.InviteCompanySource {
  1860. case 2:
  1861. detail.ApplicationSource += "(络町)"
  1862. }
  1863. resp.Detail = detail
  1864. br.Msg = "申请成功!"
  1865. br.Ret = 200
  1866. br.Success = true
  1867. br.Data = resp
  1868. }
  1869. // @Title 更改绑定邮箱
  1870. // @Description 更改绑定邮箱接口
  1871. // @Param request body models.Headimgurl true "type json string"
  1872. // @Success 200 {object} models.ArticleDetailFileLink
  1873. // @router /email/binding [post]
  1874. func (this *UserController) EmailBinding() {
  1875. br := new(models.BaseResponse).Init()
  1876. defer func() {
  1877. this.Data["json"] = br
  1878. this.ServeJSON()
  1879. }()
  1880. user := this.User
  1881. if user == nil {
  1882. br.Msg = "请登录"
  1883. br.ErrMsg = "请登录,用户信息为空"
  1884. br.Ret = 408
  1885. return
  1886. }
  1887. var req models.UserEmail
  1888. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1889. if err != nil {
  1890. br.Msg = "参数解析异常!"
  1891. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1892. return
  1893. }
  1894. uid := user.UserId
  1895. if user.Email != "" {
  1896. br.Msg = "邮箱号已存在,请勿重复绑定"
  1897. br.ErrMsg = "邮箱格式错误,请重新输入 Email:" + user.Email
  1898. return
  1899. }
  1900. email := req.Email
  1901. if !utils.ValidateEmailFormatat(req.Email) {
  1902. br.Msg = "邮箱格式错误,请重新输入"
  1903. br.ErrMsg = "邮箱格式错误,请重新输入"
  1904. return
  1905. }
  1906. err = models.UpdateUserEmail(email, uid)
  1907. if err != nil {
  1908. br.Msg = "操作失败"
  1909. br.ErrMsg = "头像信息不能为空"
  1910. }
  1911. br.Ret = 200
  1912. br.Success = true
  1913. br.Msg = "操作成功"
  1914. }
  1915. // @Title 上传名片信息
  1916. // @Description 上传名片信息接口
  1917. // @Param request body order.CygxUserBusinessCardReq true "type json string"
  1918. // @Success Ret=200 {object} models.SignupStatus
  1919. // @router /upload/UserBusinessCard [post]
  1920. func (this *UserController) UploadUserBusinessCard() {
  1921. br := new(models.BaseResponse).Init()
  1922. defer func() {
  1923. this.Data["json"] = br
  1924. this.ServeJSON()
  1925. }()
  1926. user := this.User
  1927. if user == nil {
  1928. br.Msg = "请登录"
  1929. br.ErrMsg = "请登录,用户信息为空"
  1930. br.Ret = 408
  1931. return
  1932. }
  1933. isNeedBusinessCard := services.GetCygxUserBusinessCardCount(user.UserId, user.CompanyId) //是否需要上传名片
  1934. if !isNeedBusinessCard {
  1935. br.Msg = "您已上传名片,请勿重复上传"
  1936. return
  1937. }
  1938. var req order.CygxUserBusinessCardReq
  1939. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1940. if err != nil {
  1941. br.Msg = "参数解析异常!"
  1942. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1943. return
  1944. }
  1945. uid := user.UserId
  1946. businessCardUrl := req.BusinessCardUrl
  1947. if businessCardUrl == "" {
  1948. br.Msg = "名片信息错误"
  1949. return
  1950. }
  1951. companyName := user.CompanyName
  1952. if companyName == "" {
  1953. br.Msg = "请填写公司姓名"
  1954. return
  1955. }
  1956. realName := req.RealName
  1957. if realName == "" {
  1958. br.Msg = "请填写姓名"
  1959. return
  1960. }
  1961. mobile := req.Mobile
  1962. key := "check_ocr_business_card"
  1963. conf, e := models.GetConfigByCode(key)
  1964. if e != nil {
  1965. br.Msg = "获取失败"
  1966. br.ErrMsg = "获取首页头部导航失败, Err: " + e.Error()
  1967. return
  1968. }
  1969. if conf.ConfigValue == "" {
  1970. br.Msg = "获取失败"
  1971. br.ErrMsg = "首页头部导航配置值有误"
  1972. return
  1973. }
  1974. checkItem := new(models.CheckOcrBusinessCard)
  1975. //list := new(*models.BannerUrlYxResp)
  1976. if e = json.Unmarshal([]byte(conf.ConfigValue), &checkItem); e != nil {
  1977. br.Msg = "获取失败"
  1978. br.ErrMsg = "首页头部导航配置值解析失败, Err: " + e.Error()
  1979. return
  1980. }
  1981. if checkItem.CheckMobile || checkItem.CheckCompany {
  1982. aliyunResult, err := services.AliyunOcrBusinessCard(req.BusinessCardUrl)
  1983. if err != nil {
  1984. br.Msg = "识别失败"
  1985. br.ErrMsg = "识别失败,Err:" + err.Error()
  1986. return
  1987. }
  1988. //校验手机号
  1989. if checkItem.CheckMobile {
  1990. mobileStr := strings.Join(aliyunResult.TelCell, ",")
  1991. if !strings.Contains(mobileStr, mobile) {
  1992. br.Msg = "名片手机号和绑定手机号不一致,请重新上传"
  1993. br.ErrMsg = "手机号不一致"
  1994. return
  1995. }
  1996. }
  1997. //校验公司
  1998. if checkItem.CheckCompany {
  1999. companyNameStr := strings.Join(aliyunResult.Company, ",")
  2000. if !strings.Contains(companyNameStr, companyName) {
  2001. br.Msg = "名片手机号和绑定手机号不一致,请重新上传"
  2002. br.ErrMsg = "公司信息不一致"
  2003. return
  2004. }
  2005. }
  2006. }
  2007. item := new(order.CygxUserBusinessCard)
  2008. item.BusinessCardUrl = businessCardUrl
  2009. item.UserId = uid
  2010. item.RealName = realName
  2011. item.Mobile = req.Mobile
  2012. item.CompanyName = companyName
  2013. item.RegisterPlatform = utils.REGISTER_PLATFORM
  2014. item.CreateTime = time.Now()
  2015. item.ModifyTime = time.Now()
  2016. item.InviteName = req.InviteName
  2017. err = order.AddCygxUserBusinessCard(item)
  2018. if err != nil {
  2019. br.Msg = "操作失败"
  2020. br.ErrMsg = "操作失败,Err:" + err.Error()
  2021. return
  2022. }
  2023. br.Ret = 200
  2024. br.Success = true
  2025. br.Msg = "操作成功"
  2026. }