user.go 64 KB

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