user.go 57 KB

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