user.go 55 KB

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