user.go 60 KB

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