user.go 60 KB

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