user.go 54 KB

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