user_pc.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/mojocn/base64Captcha"
  6. "hongze/hongze_api/services"
  7. "hongze/hongze_api/utils"
  8. "strconv"
  9. "hongze/hongze_api/models"
  10. "image/color"
  11. "time"
  12. )
  13. //用户不登录
  14. type UserPcNotAuthController struct {
  15. BasePcNotAuthController
  16. }
  17. // @Title 获取图形验证码
  18. // @Description 获取图形验证码
  19. // @Success 200 {object} models.GraphicVerifyCodeResp
  20. // @router /pc/getGraphicVerifyCode [get]
  21. func (this *UserPcNotAuthController) GetGraphicVerifyCode() {
  22. br := new(models.BaseResponse).Init()
  23. defer func() {
  24. this.Data["json"] = br
  25. this.ServeJSON()
  26. }()
  27. var configC = base64Captcha.ConfigCharacter{
  28. Height: 26,
  29. Width: 67,
  30. Mode: base64Captcha.CaptchaModeNumber,
  31. ComplexOfNoiseText: base64Captcha.CaptchaComplexLower,
  32. ComplexOfNoiseDot: base64Captcha.CaptchaComplexLower,
  33. IsUseSimpleFont: true,
  34. IsShowHollowLine: false,
  35. IsShowNoiseDot: true,
  36. IsShowNoiseText: true,
  37. IsShowSlimeLine: false,
  38. IsShowSineLine: false,
  39. CaptchaLen: 4,
  40. BgColor: &color.RGBA{255, 255, 255, 1},
  41. }
  42. char := base64Captcha.EngineCharCreate(configC)
  43. base64stringC := base64Captcha.CaptchaWriteToBase64Encoding(char)
  44. verifyId := fmt.Sprintf("%d", time.Now().UnixNano())
  45. item := new(models.GraphicVerifyCode)
  46. item.VerifyId = verifyId
  47. item.VerifyCode = char.CaptchaItem.VerifyValue
  48. item.CreateTime = time.Now()
  49. err := models.AddGraphicVerifyCode(item)
  50. if err != nil {
  51. br.Msg = "获取失败"
  52. br.ErrMsg = "获取失败,Err:" + err.Error()
  53. return
  54. }
  55. resp := new(models.GraphicVerifyCodeResp)
  56. resp.VerifyId = verifyId
  57. resp.VerifyCode = base64stringC
  58. br.Ret = 200
  59. br.Data = resp
  60. br.Msg = "获取成功"
  61. br.Success = true
  62. }
  63. // @Title pc端获取短信验证码
  64. // @Description pc端获取短信验证码接口
  65. // @Param Mobile query string true "手机号码"
  66. // @Param AreaNum query string true "地区编码"
  67. // @Param VerifyId query string true "图形验证码id"
  68. // @Param VerifyCode query string true "图形验证码code"
  69. // @Success Ret=200 获取成功
  70. // @router /pc/getSmsCode [get]
  71. func (this *UserPcNotAuthController) PcGetSmsCode() {
  72. br := new(models.BaseResponse).Init()
  73. defer func() {
  74. this.Data["json"] = br
  75. this.ServeJSON()
  76. }()
  77. mobile := this.GetString("Mobile")
  78. if mobile == "" {
  79. br.Msg = "请输入手机号"
  80. return
  81. }
  82. areaNum := this.GetString("AreaNum")
  83. msgCode := utils.GetRandDigit(4)
  84. verifyId := this.GetString("VerifyId")
  85. verifyCode := this.GetString("VerifyCode")
  86. item, err := models.GetGraphicVerifyById(verifyId)
  87. if err != nil {
  88. if err.Error() == utils.ErrNoRow() {
  89. br.Msg = "验证码不存在,请刷新页面!"
  90. return
  91. }
  92. br.Msg = "校验验证码失败!"
  93. return
  94. }
  95. if item.VerifyCode != verifyCode {
  96. br.Msg = "验证码错误,请重新输入!"
  97. return
  98. }
  99. checkoutTime := time.Now().Add(15 * time.Minute)
  100. if item.CreateTime.After(checkoutTime) {
  101. br.Msg = "验证码过期,请重新输入!"
  102. return
  103. }
  104. var result bool
  105. if areaNum == "86" || areaNum == "" || areaNum == "0" {
  106. result = services.SendSmsCode(mobile, msgCode)
  107. } else {
  108. result = services.SendSmsCodeGj(mobile, msgCode, areaNum)
  109. }
  110. //发送成功
  111. if result {
  112. item := new(models.MsgCode)
  113. item.OpenId = ""
  114. item.Code = msgCode
  115. item.Mobile = mobile
  116. item.ExpiredIn = time.Now().Add(15 * time.Minute).Unix()
  117. item.Enabled = 1
  118. item.CreatedTime = time.Now()
  119. err := models.AddMsgCode(item)
  120. if err != nil {
  121. br.Msg = "发送失败"
  122. br.ErrMsg = "发送失败,Err:" + err.Error()
  123. return
  124. }
  125. br.Msg = "发送成功"
  126. } else {
  127. br.Msg = "发送失败"
  128. }
  129. br.Ret = 200
  130. br.Success = true
  131. }
  132. // @Title 登录
  133. // @Description 登录接口
  134. // @Param request body models.LoginReq true "type json string"
  135. // @Success 200 {object} models.LoginResp
  136. // @router /pc/login [post]
  137. func (this *UserPcNotAuthController) PcLogin() {
  138. br := new(models.BaseResponse).Init()
  139. defer func() {
  140. this.Data["json"] = br
  141. this.ServeJSON()
  142. }()
  143. var req models.PcLoginReq
  144. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  145. if err != nil {
  146. br.Msg = "参数解析异常!"
  147. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  148. return
  149. }
  150. userId := 0
  151. var isAdd bool
  152. if req.LoginType == 1 {
  153. if req.Mobile == "" {
  154. br.Msg = "请输入手机号"
  155. br.ErrMsg = "请输入手机号"
  156. return
  157. }
  158. if req.SmsCode == "" {
  159. br.Msg = "请输入有效手机验证码"
  160. br.ErrMsg = "请输入有效手机验证码"
  161. return
  162. }
  163. item, err := models.GetMsgCode(req.Mobile, req.SmsCode)
  164. if err != nil {
  165. if err.Error() == utils.ErrNoRow() {
  166. br.Msg = "验证码错误,请重新输入"
  167. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  168. return
  169. } else {
  170. br.Msg = "验证码错误,请重新输入"
  171. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  172. return
  173. }
  174. }
  175. if item == nil {
  176. br.Msg = "手机验证码错误,请重新输入"
  177. return
  178. }
  179. wxUser, err := models.GetWxUserItemByMobile(req.Mobile)
  180. if err != nil {
  181. if err.Error() == utils.ErrNoRow() {
  182. isAdd = true
  183. } else {
  184. br.Msg = "登陆失败"
  185. br.ErrMsg = "根据手机号获取用户信息失败,Err:" + err.Error()
  186. return
  187. }
  188. }
  189. if wxUser == nil {
  190. isAdd = true
  191. } else {
  192. userId = wxUser.UserId
  193. }
  194. //BindMobile(openId, mobile string, userId, loginType int) (err error) {
  195. //newUserId, err = models.BindMobile(openId, req.Mobile, userId, req.LoginType)
  196. } else if req.LoginType == 2 {
  197. if req.Email == "" {
  198. br.ErrMsg = "邮箱不能为空,请输入邮箱"
  199. br.Msg = "邮箱不能为空,请输入邮箱"
  200. return
  201. }
  202. if !utils.ValidateEmailFormatat(req.Email) {
  203. br.ErrMsg = "邮箱格式错误,请重新输入"
  204. br.Msg = "邮箱格式错误,请重新输入"
  205. return
  206. }
  207. if req.SmsCode == "" {
  208. br.Msg = "请输入有效验证码"
  209. br.ErrMsg = "请输入有效验证码"
  210. return
  211. }
  212. item, err := models.GetMsgCode(req.Email, req.SmsCode)
  213. if err != nil {
  214. if err.Error() == utils.ErrNoRow() {
  215. br.Msg = "验证码错误,请重新输入"
  216. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  217. return
  218. } else {
  219. br.Msg = "验证码错误,请重新输入"
  220. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  221. return
  222. }
  223. }
  224. if item == nil {
  225. br.Msg = "邮箱证码错误,请重新输入"
  226. return
  227. }
  228. wxUser, err := models.GetWxUserItemByEmail(req.Email)
  229. if err != nil {
  230. if err.Error() == utils.ErrNoRow() {
  231. isAdd = true
  232. } else {
  233. br.Msg = "登陆失败"
  234. br.ErrMsg = "根据邮箱获取用户信息失败,Err:" + err.Error()
  235. return
  236. }
  237. }
  238. if wxUser == nil {
  239. isAdd = true
  240. } else {
  241. userId = wxUser.UserId
  242. }
  243. } else {
  244. br.Msg = "无效的登录方式"
  245. br.ErrMsg = "无效的登录方式,loginType:" + strconv.Itoa(req.LoginType)
  246. }
  247. if isAdd {
  248. user := new(models.WxUser)
  249. user.CompanyId = 1
  250. user.CreatedTime = time.Now()
  251. user.FirstLogin = 1
  252. user.Enabled = 1
  253. user.Email = req.Email
  254. user.Mobile = req.Mobile
  255. if req.LoginType == 1 {
  256. user.BindAccount = user.Mobile
  257. } else {
  258. user.BindAccount = user.Email
  259. }
  260. user.RegisterTime = time.Now()
  261. user.LoginTime = time.Now()
  262. user.IsFreeLogin = req.IsFreeLogin
  263. user.RegisterPlatform = 2
  264. lastId, err := models.AddWxUser(user)
  265. if err != nil {
  266. br.Msg = "登录失败"
  267. br.ErrMsg = "登录失败,新增客户信息失败,Err:" + err.Error()
  268. return
  269. }
  270. userId = int(lastId)
  271. timeUnix := time.Now().Unix()
  272. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  273. token := utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
  274. //新增session
  275. {
  276. session := new(models.Session)
  277. session.UserId = userId
  278. session.CreatedTime = time.Now()
  279. session.LastUpdatedTime = time.Now()
  280. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  281. session.AccessToken = token
  282. err = models.AddSession(session)
  283. if err != nil {
  284. br.Msg = "登录失败"
  285. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  286. return
  287. }
  288. }
  289. } else {
  290. err = models.ModifyLoginTime(userId, req.IsFreeLogin)
  291. if err != nil {
  292. br.Msg = "登录失败"
  293. br.ErrMsg = "登录失败,修改登录信息失败,Err:" + err.Error()
  294. return
  295. }
  296. }
  297. if userId == 0 {
  298. br.Msg = "登录失败"
  299. br.ErrMsg = "登录失败,id为 0"
  300. return
  301. }
  302. userPermission, err := services.CheckUserPermission(userId)
  303. if err != nil {
  304. br.Msg = "登录失败"
  305. br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
  306. return
  307. }
  308. err = models.ModifyFirstLogin(userId)
  309. if err != nil {
  310. br.Msg = "登录失败"
  311. br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
  312. return
  313. }
  314. var token string
  315. tokenItem, err := models.GetTokenByUid(userId)
  316. if err != nil && err.Error() != utils.ErrNoRow() {
  317. br.Msg = "登录失败"
  318. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  319. return
  320. }
  321. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  322. timeUnix := time.Now().Unix()
  323. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  324. token = utils.MD5(strconv.Itoa(userId)) + utils.MD5(timeUnixStr)
  325. //新增session
  326. {
  327. session := new(models.Session)
  328. session.UserId = userId
  329. session.CreatedTime = time.Now()
  330. session.LastUpdatedTime = time.Now()
  331. session.ExpireTime = time.Now().AddDate(0, 3, 0)
  332. session.AccessToken = token
  333. err = models.AddSession(session)
  334. if err != nil {
  335. br.Msg = "登录失败"
  336. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  337. return
  338. }
  339. }
  340. } else {
  341. token = tokenItem.AccessToken
  342. }
  343. cp, err := models.GetCompanyProductsByUserId(userId)
  344. if err != nil {
  345. br.Msg = "登录失败"
  346. br.ErrMsg = "登录失败,获取客户信息失败:" + err.Error()
  347. return
  348. }
  349. var companyName, status, endDate, productName string
  350. for _, v := range cp {
  351. companyName = v.CompanyName
  352. if v.EndDate == "0000-00-00" {
  353. v.EndDate = ""
  354. }
  355. if status != "" {
  356. status = status + "/" + v.Status
  357. if v.EndDate != "" {
  358. endDate = endDate + "/" + v.Status + ":" + v.EndDate
  359. }
  360. productName = productName + "/" + v.ProductName
  361. } else {
  362. status = v.Status
  363. if v.EndDate != "" {
  364. endDate = v.Status + ":" + v.EndDate
  365. }
  366. productName = v.ProductName
  367. }
  368. }
  369. //新增登录日志
  370. {
  371. loginLog := new(models.WxUserLog)
  372. loginLog.UserId = userId
  373. loginLog.Mobile = req.Mobile
  374. loginLog.Email = req.Email
  375. loginLog.Handle = "pc_login"
  376. loginLog.CreateTime = time.Now()
  377. go models.AddWxUserLog(loginLog)
  378. }
  379. //newUser, _ := models.GetWxUserItemByUserId(userId)
  380. newUser, _ := services.GetWxUserItemByUserId(userId, utils.WxPcPlatform)
  381. resp := new(models.LoginResp)
  382. resp.UserId = newUser.UserId
  383. resp.UserPermission = userPermission
  384. resp.Authorization = token
  385. resp.Headimgurl = newUser.Headimgurl
  386. resp.Mobile = newUser.Mobile
  387. resp.Email = newUser.Email
  388. resp.CompanyName = companyName
  389. resp.EndDate = endDate
  390. resp.Status = status
  391. resp.ProductName = productName
  392. br.Ret = 200
  393. br.Success = true
  394. br.Data = resp
  395. br.Msg = "登录成功"
  396. }
  397. // @Title 绑定手机号或邮箱
  398. // @Description 绑定手机号或邮箱
  399. // @Param request body models.BindReq true "type json string"
  400. // @Success Ret=200 绑定成功
  401. // @router /pc/bind [post]
  402. func (this *UserPcNotAuthController) PcBind() {
  403. br := new(models.BaseResponse).Init()
  404. defer func() {
  405. this.Data["json"] = br
  406. this.ServeJSON()
  407. }()
  408. var req models.BindReq
  409. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  410. if err != nil {
  411. br.Msg = "参数解析异常!"
  412. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  413. return
  414. }
  415. unionId := this.User.UnionId
  416. openId := this.User.OpenId
  417. utils.FileLog.Info("绑定unionId:%s", unionId)
  418. if req.BindType == 1 { //手机号
  419. if req.Mobile == "" {
  420. br.Msg = "请输入手机号"
  421. br.ErrMsg = "请输入手机号"
  422. return
  423. }
  424. if req.VerifyCode == "" {
  425. br.Msg = "请输入有效手机验证码"
  426. br.ErrMsg = "请输入有效手机验证码"
  427. return
  428. }
  429. item, err := models.GetMsgCode(req.Mobile, req.VerifyCode)
  430. if err != nil {
  431. if err.Error() == utils.ErrNoRow() {
  432. br.Msg = "验证码错误,请重新输入"
  433. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  434. return
  435. } else {
  436. br.Msg = "验证码错误,请重新输入"
  437. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  438. return
  439. }
  440. }
  441. if item == nil {
  442. br.Msg = "手机验证码错误,请重新输入"
  443. return
  444. }
  445. } else if req.BindType == 2 {
  446. if req.Email == "" {
  447. br.ErrMsg = "邮箱不能为空,请输入邮箱"
  448. br.Msg = "邮箱不能为空,请输入邮箱"
  449. return
  450. }
  451. if req.VerifyCode == "" {
  452. br.Msg = "请填写有效的邮箱验证码"
  453. br.ErrMsg = "请填写有效的邮箱验证码"
  454. return
  455. }
  456. if !utils.ValidateEmailFormatat(req.Email) {
  457. br.ErrMsg = "邮箱格式错误,请重新输入"
  458. br.Msg = "邮箱格式错误,请重新输入"
  459. return
  460. }
  461. item, err := models.GetMsgCode(req.Email, req.VerifyCode)
  462. if err != nil {
  463. if err.Error() == utils.ErrNoRow() {
  464. br.Msg = "验证码错误,请重新输入"
  465. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  466. return
  467. } else {
  468. br.Msg = "验证码错误,请重新输入"
  469. br.ErrMsg = "校验验证码失败,Err:" + err.Error()
  470. return
  471. }
  472. }
  473. if item == nil {
  474. br.Msg = "邮箱证码错误,请重新输入"
  475. return
  476. }
  477. } else {
  478. br.Msg = "无效的绑定方式"
  479. br.ErrMsg = "无效的绑定方式,bindType:" + strconv.Itoa(req.BindType)
  480. return
  481. }
  482. user, errMsg, err := services.BindWxUser(openId, req.Mobile, req.Email, req.AreaNum, 2)
  483. if err != nil {
  484. br.Msg = "绑定失败:" + err.Error()
  485. if errMsg != `` {
  486. br.Msg = errMsg
  487. }
  488. return
  489. }
  490. userId := user.UserId
  491. var token string
  492. tokenItem, err := models.GetTokenByOpenId(openId)
  493. if err != nil && err.Error() != utils.ErrNoRow() {
  494. br.Msg = "登录失败"
  495. br.ErrMsg = "登录失败,获取token失败:" + err.Error()
  496. return
  497. }
  498. if tokenItem == nil || (err != nil && err.Error() == utils.ErrNoRow()) {
  499. timeUnix := time.Now().Unix()
  500. timeUnixStr := strconv.FormatInt(timeUnix, 10)
  501. token := utils.MD5(openId) + utils.MD5(timeUnixStr)
  502. //新增session
  503. {
  504. session := new(models.Session)
  505. session.OpenId = openId
  506. session.UserId = userId
  507. session.CreatedTime = time.Now()
  508. session.LastUpdatedTime = time.Now()
  509. session.ExpireTime = time.Now().AddDate(0, 1, 0)
  510. session.AccessToken = token
  511. err = models.AddSession(session)
  512. if err != nil {
  513. br.Msg = "登录失败"
  514. br.ErrMsg = "登录失败,新增用户session信息失败:" + err.Error()
  515. return
  516. }
  517. }
  518. } else {
  519. token = tokenItem.AccessToken
  520. _ = models.UpdateSession(tokenItem.SessionId, userId, time.Now().AddDate(0, 1, 0))
  521. }
  522. userPermission, err := services.CheckUserPermission(userId)
  523. if err != nil {
  524. br.Msg = "登录失败"
  525. br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
  526. return
  527. }
  528. err = models.ModifyFirstLogin(user.UserId)
  529. if err != nil {
  530. br.Msg = "登录失败"
  531. br.ErrMsg = "登录失败,判断权限失败:" + err.Error()
  532. return
  533. }
  534. cp, err := models.GetCompanyProductsByUserId(userId)
  535. if err != nil {
  536. br.Msg = "登录失败"
  537. br.ErrMsg = "登录失败,获取客户信息失败:" + err.Error()
  538. return
  539. }
  540. var companyName, status, endDate, productName string
  541. for _, v := range cp {
  542. companyName = v.CompanyName
  543. if status != "" {
  544. status = status + "/" + v.Status
  545. endDate = endDate + "/" + v.EndDate
  546. productName = productName + "/" + v.ProductName
  547. } else {
  548. status = v.Status
  549. endDate = v.EndDate
  550. productName = v.ProductName
  551. }
  552. }
  553. newUser, err := models.GetWxUserItemByUserId(userId)
  554. if err != nil {
  555. br.Msg = "登录失败"
  556. br.ErrMsg = "获取客户信息失败 GetWxUserItemByUserId:" + err.Error()
  557. return
  558. }
  559. //新增登录日志
  560. {
  561. loginLog := new(models.WxUserLog)
  562. loginLog.UnionId = unionId
  563. loginLog.UserId = userId
  564. loginLog.Mobile = req.Mobile
  565. loginLog.Email = req.Email
  566. loginLog.UnionId = unionId
  567. loginLog.Handle = "pc_bind"
  568. loginLog.Remark = strconv.Itoa(userId)
  569. loginLog.CreateTime = time.Now()
  570. go models.AddWxUserLog(loginLog)
  571. }
  572. resp := new(models.LoginResp)
  573. resp.UserId = userId
  574. resp.UserPermission = userPermission
  575. resp.Authorization = token
  576. resp.Email = newUser.Email
  577. resp.Headimgurl = newUser.Headimgurl
  578. resp.Mobile = newUser.Mobile
  579. resp.CompanyName = companyName
  580. resp.EndDate = endDate
  581. resp.Status = status
  582. resp.ProductName = productName
  583. br.Ret = 200
  584. br.Success = true
  585. br.Data = resp
  586. br.Msg = "绑定成功"
  587. }
  588. // @Title 校验免登陆
  589. // @Description 校验免登陆
  590. // @Success 200 {object} models.CheckLoginResp
  591. // @router /pc/check/login [get]
  592. func (this *UserPcNotAuthController) CheckLogin() {
  593. br := new(models.BaseResponse).Init()
  594. defer func() {
  595. this.Data["json"] = br
  596. this.ServeJSON()
  597. }()
  598. //没有用户信息,代表是没有登录
  599. if this.User == nil {
  600. br.Success = true
  601. br.Ret = 408
  602. return
  603. }
  604. if this.User.IsFreeLogin == 1 {
  605. if this.User.LoginTime.AddDate(0, 0, 30).After(time.Now()) {
  606. br.Ret = 600
  607. } else {
  608. br.Ret = 408
  609. }
  610. } else {
  611. if this.User.LoginTime.AddDate(0, 0, 1).After(time.Now()) {
  612. br.Ret = 600 //正常状态,不需要登录
  613. } else {
  614. br.Ret = 408
  615. }
  616. }
  617. authorization := this.Ctx.Input.Header("Authorization")
  618. if authorization == "" {
  619. cookie := this.Ctx.GetCookie("rddp_access_token")
  620. utils.FileLog.Info("authorization:%s,cookie:%s", authorization, cookie)
  621. authorization = cookie
  622. }
  623. br.IsSendEmail = false
  624. //判断token是否过期
  625. if br.Ret == 408 {
  626. tokenCount, err := models.GetSessionCountByToken(authorization)
  627. if err != nil {
  628. if err.Error() == utils.ErrNoRow() {
  629. br.Ret = 408
  630. } else {
  631. br.ErrMsg = "登录失败,Err:" + err.Error()
  632. br.ErrMsg = "登录失败"
  633. br.IsSendEmail = true
  634. return
  635. }
  636. }
  637. if tokenCount > 0 {
  638. br.Ret = 600
  639. }
  640. }
  641. resp := new(models.CheckLoginResp)
  642. if br.Ret == 600 {
  643. checkPermissionCount, err := models.GetCustomPermission(this.User.CompanyId)
  644. if err != nil && err.Error() != utils.ErrNoRow() {
  645. br.Msg = "登录失败"
  646. br.ErrMsg = "校验提示权限信息失败 Err:" + err.Error()
  647. return
  648. }
  649. if checkPermissionCount <= 0 && this.User.CompanyId > 1 {
  650. resp.IsTips = true
  651. }
  652. if this.User.Mobile == "" && this.User.Email == "" {
  653. resp.IsBind = true
  654. }
  655. }
  656. br.Success = true
  657. br.Msg = "获取成功"
  658. br.Data = resp
  659. }
  660. //
  661. //var (
  662. // searcher = riot.New("zh")
  663. //)
  664. //
  665. //func init() {
  666. // fmt.Sprintf("start")
  667. // data := types.DocData{Content: `I wonder how, I wonder why
  668. // , I wonder where they are`}
  669. // data1 := types.DocData{Content: "所以, 你好, 再见"}
  670. // data2 := types.DocData{Content: "没有理由"}
  671. // data3 := types.DocData{Content: "你好,中国"}
  672. // data4 := types.DocData{Content: "晚上好"}
  673. // data5 := types.DocData{Content: "中国人民,你好啊,2020年"}
  674. // data6 := types.DocData{Content: "中国的新冠疫情算基本得到了有效的控制,随着各地的纷纷复工,甚至有些省市已经开始了复学,大量的外籍华人、旅居的、留学的平时召唤都召唤不来的那些人纷纷回国,这都说明了我们伟大的中国,伟大的中国人民战胜了这次肆虐全球的瘟疫。\n\n  在这这次的抗击新冠疫情中,我们的白衣天使们,我们的专家、学者、科学家们,纷纷的冲在了抗疫第一线。看着84岁高龄的钟南山院士坐在高铁座位上睡着的照片,看着73岁的第一个提出武汉封城的李兰娟院士数次往返于武汉,脸上那一道道的长时间佩戴口罩和护目镜留下的压痕,看着一个个的花季少女剪掉秀发只是为了更好的穿戴防护装备,看着一车车的物资涌向武汉,看着一张张按着手印的奔赴疫区申请书,听着一句句熟悉而又温暖的入党誓词,感动无不充盈心腔,眼泪也从未吝啬。对最美逆行者的赞美是多么的诚挚!"}
  675. // data7 := types.DocData{Content: "在此,我除了表达对他们由衷的感动,还想说:我们中国千万万的普普通通的老百姓也是最伟大、最可爱的人。从来没有一个朝代,从来没有一个国家,像我们中国的老百姓这样如此的对待疫情。平凡的老百姓节衣缩食,也要将物资援助最需要的地方,宁愿几个月不出门,也不给国家增加一分的负担。试问世界上有哪个国家的人民有我们中国的人民对国家如母亲般的感情呢?\n\n  近期看到的最多的新闻就是国外疫情的泛滥,不说在抗疫中每个国家的责任和力量,就说普通的百姓不戴口罩到处跑的,一只狗被遛了三十二次的,最硬核的就是用棍棒打腿的,这些都说明了他们的意识,他们面对疫情的态度和我们的同胞不是一个层次,他们对待国家的情感是不能和我们比拟的!当然,我们国家也不排除有个别的另类出现,但一定会收到最严厉的惩戒。\n\n  中国人民在这次的抗击新冠疫情的战役中表现出来的智慧、勇气、精神,都使我感到作为一个中国人是多么幸运。"}
  676. //
  677. // searcher.Index("1", data)
  678. // searcher.Index("2", data1)
  679. // searcher.IndexDoc("3", data2)
  680. // searcher.IndexDoc("4", data3)
  681. // searcher.IndexDoc("5", data4)
  682. // searcher.IndexDoc("6", data5)
  683. // searcher.IndexDoc("7", data6)
  684. // searcher.IndexDoc("8", data7)
  685. // searcher.Flush()
  686. //
  687. // req := types.SearchReq{Text: "中国人民",Orderless: false,CountDocsOnly: false}
  688. // search := searcher.Search(req)
  689. // jsonStr,_:=json.Marshal(search)
  690. // fmt.Println(string(jsonStr))
  691. // utils.FileLog.Info("%s",string(jsonStr))
  692. // fmt.Sprintf("end")
  693. //}
  694. //