home_api_controller.go 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. package new_mobile_api_controllers
  2. import (
  3. "XT_New/controllers/mobile_api_controllers"
  4. "XT_New/enums"
  5. "XT_New/models"
  6. "XT_New/service"
  7. "XT_New/utils"
  8. "encoding/json"
  9. "github.com/astaxie/beego"
  10. "io/ioutil"
  11. "net/http"
  12. "net/url"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. type HomeController struct {
  18. NewMobileBaseAPIAuthController
  19. }
  20. func (this *HomeController) GetHomeData() {
  21. adminUserInfo := this.GetMobileAdminUserInfo()
  22. if adminUserInfo.Org != nil && adminUserInfo.Org.Id != 0 {
  23. //获取该管理员所有机构列表
  24. var orgs []*models.Org
  25. adminUser, err := service.GetHomeData(adminUserInfo.AdminUser.Id)
  26. if err != nil {
  27. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  28. return
  29. }
  30. for _, item := range adminUser.Org {
  31. orgs = append(orgs, item)
  32. }
  33. for _, item := range adminUser.VMApp_Role {
  34. for _, subItem := range item.Org {
  35. orgs = append(orgs, subItem)
  36. }
  37. }
  38. orgs = RemoveRepeatedOrgElement(orgs)
  39. var isSubSuperAdmin bool = false
  40. if adminUserInfo.AppRole != nil && adminUserInfo.AppRole.Id > 0 {
  41. app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
  42. if len(app_role.RoleIds) > 0 {
  43. role_ids := strings.Split(app_role.RoleIds, ",")
  44. if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
  45. for _, item := range role_ids {
  46. id, _ := strconv.ParseInt(item, 10, 64)
  47. role, _ := service.GetRoleByRoleID(id)
  48. if role.IsSystem == 1 && role.RoleName == "子管理员" {
  49. isSubSuperAdmin = true
  50. }
  51. }
  52. }
  53. }
  54. }
  55. apps, err := service.GetAllApp(adminUserInfo.Org.Id)
  56. if err != nil {
  57. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  58. return
  59. }
  60. banners, err := service.GetSystemBanner()
  61. if err != nil {
  62. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  63. return
  64. }
  65. this.ServeSuccessJSON(map[string]interface{}{
  66. "orgs": orgs,
  67. "apps": apps,
  68. "banners": banners,
  69. "isCreateOrg": true,
  70. "isSubSuperAdmin": isSubSuperAdmin,
  71. })
  72. } else {
  73. apps, err := service.GetAllApp(0)
  74. if err != nil {
  75. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  76. return
  77. }
  78. banners, err := service.GetSystemBanner()
  79. if err != nil {
  80. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  81. return
  82. }
  83. this.ServeSuccessJSON(map[string]interface{}{
  84. "isCreateOrg": false,
  85. "apps": apps,
  86. "banners": banners,
  87. "isSubSuperAdmin": false,
  88. })
  89. }
  90. }
  91. func RemoveRepeatedOrgElement(orgs []*models.Org) (newOrgs []*models.Org) {
  92. newOrgs = make([]*models.Org, 0)
  93. for i := 0; i < len(orgs); i++ {
  94. repeat := false
  95. for j := i + 1; j < len(orgs); j++ {
  96. if orgs[i].Id == orgs[j].Id {
  97. repeat = true
  98. break
  99. }
  100. }
  101. if !repeat {
  102. newOrgs = append(newOrgs, orgs[i])
  103. }
  104. }
  105. return
  106. }
  107. func (this *HomeController) ChangeOrg() {
  108. org_id, _ := this.GetInt64("org_id")
  109. adminUserInfo := this.GetMobileAdminUserInfo()
  110. tempOrg, err := service.GetOrgById(org_id)
  111. if err != nil {
  112. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  113. return
  114. }
  115. if tempOrg == nil {
  116. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeOrgNoExist)
  117. return
  118. }
  119. mobile := adminUserInfo.AdminUser.Mobile
  120. // 只取最近被创建的 admin_role
  121. adminUser, getAdminErr := service.GetValidAdminUserByMobileReturnErr(mobile) //账号信息唯一值
  122. if getAdminErr != nil {
  123. utils.ErrorLog("获取管理员失败:%v", getAdminErr)
  124. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  125. this.ServeJSON()
  126. return
  127. } else if adminUser == nil {
  128. utils.ErrorLog("查找不到 mobile = %v 的用户", mobile)
  129. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  130. this.ServeJSON()
  131. return
  132. } else {
  133. var appRole *models.App_Role
  134. var org *models.Org
  135. var subscibe *models.ServeSubscibe
  136. var app *models.OrgApp
  137. //根据登录信息的机构和用户id,去获取对应用户信息和机构信息
  138. tempApp, _ := service.GetOrgApp(tempOrg.Id, 3)
  139. tempRole, _ := service.GetAppRole(tempOrg.Id, tempApp.Id, adminUser.Id)
  140. tempSubscibe, getSubscibeErr := service.GetOrgServeSubscibe(tempOrg.Id)
  141. if getSubscibeErr != nil {
  142. utils.ErrorLog("获取机构订阅信息失败:%v", getSubscibeErr)
  143. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  144. this.ServeJSON()
  145. return
  146. }
  147. subscibe = tempSubscibe
  148. org = tempOrg
  149. appRole = tempRole
  150. app = tempApp
  151. templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
  152. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  153. AdminUser: adminUser,
  154. Org: org,
  155. App: app,
  156. AppRole: appRole,
  157. Subscibe: subscibe,
  158. TemplateInfo: &templateInfo,
  159. }
  160. if org != nil && appRole != nil {
  161. // 插入一条登录记录
  162. ip := this.GetString("ip")
  163. loginLog := &models.AdminUserLoginLog{
  164. AdminUserId: adminUser.Id,
  165. OrgId: org.Id,
  166. AppId: appRole.AppId,
  167. IP: ip,
  168. OperateType: 3,
  169. AppType: 3,
  170. CreateTime: time.Now().Unix(),
  171. }
  172. if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
  173. utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
  174. }
  175. }
  176. //删除session和cookie
  177. this.DelSession("mobile_admin_user_info")
  178. this.Ctx.SetCookie("token_cookie", "")
  179. //设置new seesion
  180. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  181. //设置new cookie
  182. mobile := adminUser.Mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
  183. token := utils.GenerateLoginToken(mobile)
  184. expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
  185. this.Ctx.SetCookie("token_cookie", token, expiration, "/")
  186. var configList interface{}
  187. var FiledList []*models.FiledConfig
  188. if org.Id > 0 {
  189. configList, _ = service.GetConfigList(org.Id)
  190. FiledList, _ = service.FindFiledByOrgId(org.Id)
  191. }
  192. if len(FiledList) == 0 {
  193. var err error
  194. if org.Id > 0 {
  195. err = service.BatchInsertFiledConfig(org.Id)
  196. if err == nil {
  197. FiledList, _ = service.FindFiledByOrgId(org.Id)
  198. } else {
  199. utils.ErrorLog("字段批量插入失败:%v", err)
  200. }
  201. } else {
  202. FiledList = make([]*models.FiledConfig, 0)
  203. }
  204. }
  205. this.ServeSuccessJSON(map[string]interface{}{
  206. "admin": adminUser,
  207. "user": appRole,
  208. "org": org,
  209. "template_info": map[string]interface{}{
  210. "id": templateInfo.ID,
  211. "org_id": templateInfo.OrgId,
  212. "template_id": templateInfo.TemplateId,
  213. },
  214. "config_list": configList,
  215. "filed_list": FiledList,
  216. })
  217. }
  218. }
  219. func (this *HomeController) CreateOrg() {
  220. adminUserInfo := this.GetMobileAdminUserInfo()
  221. adminUser := adminUserInfo.AdminUser
  222. //if didCreateOrg, checkCreateOrgErr := service.DidAdminUserCreateOrg(adminUser.Id); checkCreateOrgErr != nil {
  223. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  224. // this.ServeJSON()
  225. // return
  226. //} else if didCreateOrg {
  227. // this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateOrg)
  228. // this.ServeJSON()
  229. // return
  230. //}
  231. name := this.GetString("org_name")
  232. shortName := name
  233. provinceName := this.GetString("provinces_name")
  234. cityName := this.GetString("city_name")
  235. districtName := this.GetString("district_name")
  236. address := this.GetString("address")
  237. org_type := this.GetString("org_type")
  238. contactName := this.GetString("contact_name")
  239. openXT := true
  240. openCDM := false
  241. openSCRM := false
  242. openMall := false
  243. if len(name) == 0 || len(shortName) == 0 || len(contactName) == 0 || len(address) == 0 || len(provinceName) <= 0 || len(cityName) <= 0 || len(districtName) <= 0 || len(org_type) <= 0 {
  244. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  245. this.ServeJSON()
  246. return
  247. }
  248. orgPhone := this.GetString("telephone")
  249. if len(orgPhone) > 0 {
  250. if utils.PhoneRegexp().MatchString(orgPhone) == false {
  251. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
  252. this.ServeJSON()
  253. return
  254. }
  255. }
  256. provinceID := 0
  257. cityID := 0
  258. districtID := 0
  259. province, getProvinceErr := service.GetProvinceWithName(provinceName)
  260. if getProvinceErr != nil {
  261. utils.ErrorLog("查询省名失败:%v", getProvinceErr)
  262. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  263. this.ServeJSON()
  264. return
  265. } else if province != nil {
  266. provinceID = int(province.ID)
  267. city, getCityErr := service.GetCityWithName(province.ID, cityName)
  268. if getCityErr != nil {
  269. utils.ErrorLog("查询城市名失败:%v", getCityErr)
  270. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  271. this.ServeJSON()
  272. return
  273. } else if city != nil {
  274. cityID = int(city.ID)
  275. district, getDistrictErr := service.GetDistrictWithName(city.ID, districtName)
  276. if getDistrictErr != nil {
  277. utils.ErrorLog("查询区县名失败:%v", getDistrictErr)
  278. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  279. this.ServeJSON()
  280. return
  281. } else if district != nil {
  282. districtID = int(district.ID)
  283. }
  284. }
  285. }
  286. var orgs []*models.Org
  287. vmAdminUser, err := service.GetHomeData(adminUser.Id)
  288. if err != nil {
  289. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
  290. return
  291. }
  292. for _, item := range vmAdminUser.Org {
  293. orgs = append(orgs, item)
  294. }
  295. for _, item := range vmAdminUser.VMApp_Role {
  296. for _, subItem := range item.Org {
  297. orgs = append(orgs, subItem)
  298. }
  299. }
  300. orgs = RemoveRepeatedOrgElement(orgs)
  301. orgType := service.GetOrgTypeByName(org_type)
  302. org := &models.Org{
  303. Creator: adminUser.Id,
  304. OrgName: name,
  305. OrgShortName: shortName,
  306. Province: int64(provinceID),
  307. City: int64(cityID),
  308. District: int64(districtID),
  309. Address: address,
  310. OrgType: orgType.ID,
  311. Telephone: orgPhone,
  312. ContactName: contactName,
  313. Claim: 1,
  314. Evaluate: 5,
  315. Status: 1,
  316. CreateTime: time.Now().Unix(),
  317. ModifyTime: time.Now().Unix(),
  318. }
  319. createErr := service.CreateOrg(org, adminUser.Name, openXT, openCDM, openSCRM, openMall) // 创建机构以及所有类型的 app,如果有新类型的平台,则需要在这个方法里面把创建这一新类型的 app 的代码加上
  320. if createErr != nil {
  321. utils.ErrorLog("mobile=%v的超级管理员创建机构失败:%v", adminUser.Mobile, createErr)
  322. this.Data["json"] = enums.MakeFailResponseJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
  323. this.ServeJSON()
  324. } else {
  325. //初始化病人和排班相关数据
  326. InitPatientAndSchedule(org)
  327. //初始化透析方案
  328. InitSystemPrescrption(org)
  329. //初始化医嘱模版
  330. //InitAdviceTemplate(org)
  331. //初始化角色和权限
  332. InitRoleAndPurviews(org)
  333. //初始化设备管理
  334. InitEquitMentInformation(org)
  335. //初始化显示配置
  336. if len(orgs) == 0 {
  337. ip := utils.GetIP(this.Ctx.Request)
  338. ssoDomain := beego.AppConfig.String("sso_domain")
  339. api := ssoDomain + "/m/login/pwd"
  340. values := make(url.Values)
  341. values.Set("mobile", adminUser.Mobile)
  342. values.Set("password", adminUser.Password)
  343. values.Set("app_type", "3")
  344. values.Set("ip", ip)
  345. resp, requestErr := http.PostForm(api, values)
  346. if requestErr != nil {
  347. utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
  348. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  349. return
  350. }
  351. defer resp.Body.Close()
  352. body, ioErr := ioutil.ReadAll(resp.Body)
  353. if ioErr != nil {
  354. utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
  355. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  356. return
  357. }
  358. var respJSON map[string]interface{}
  359. utils.InfoLog(string(body))
  360. if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
  361. utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
  362. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  363. return
  364. }
  365. if respJSON["state"].(float64) != 1 {
  366. msg := respJSON["msg"].(string)
  367. utils.ErrorLog("SSO登录接口请求失败: %v", msg)
  368. if int(respJSON["code"].(float64)) == 609 {
  369. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
  370. return
  371. }
  372. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  373. return
  374. } else {
  375. utils.SuccessLog("SSO登录成功")
  376. // 下面这几段 Map=>JSON=>Struct 的流程可能会造成速度很慢
  377. userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
  378. userJSONBytes, _ := json.Marshal(userJSON)
  379. var adminUser models.AdminUser
  380. if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
  381. utils.ErrorLog("解析管理员失败:%v", err)
  382. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  383. return
  384. }
  385. var org models.Org
  386. if respJSON["data"].(map[string]interface{})["org"] != nil {
  387. orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
  388. orgJSONBytes, _ := json.Marshal(orgJSON)
  389. if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
  390. utils.ErrorLog("解析机构失败:%v", err)
  391. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  392. return
  393. }
  394. }
  395. var app models.OrgApp
  396. if respJSON["data"].(map[string]interface{})["app"] != nil {
  397. appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
  398. appJSONBytes, _ := json.Marshal(appJSON)
  399. if err := json.Unmarshal(appJSONBytes, &app); err != nil {
  400. utils.ErrorLog("解析应用失败:%v", err)
  401. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  402. return
  403. }
  404. }
  405. var appRole models.App_Role
  406. if respJSON["data"].(map[string]interface{})["app_role"] != nil {
  407. appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
  408. appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
  409. if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
  410. utils.ErrorLog("解析AppRole失败:%v", err)
  411. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  412. return
  413. }
  414. }
  415. var subscibe models.ServeSubscibe
  416. if respJSON["data"].(map[string]interface{})["subscibe"] != nil {
  417. subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
  418. subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
  419. if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
  420. utils.ErrorLog("解析Subscibe失败:%v", err)
  421. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
  422. return
  423. }
  424. }
  425. //service.GetOrgSubscibeState(&subscibe)
  426. templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
  427. mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
  428. AdminUser: &adminUser,
  429. Org: &org,
  430. App: &app,
  431. AppRole: &appRole,
  432. Subscibe: &subscibe,
  433. TemplateInfo: &templateInfo,
  434. }
  435. this.Ctx.SetCookie("token_cookie", "")
  436. //设置seesion
  437. this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
  438. //设置cookie
  439. mobile := adminUser.Mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
  440. token := utils.GenerateLoginToken(mobile)
  441. expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
  442. this.Ctx.SetCookie("token_cookie", token, expiration, "/")
  443. var configList interface{}
  444. var FiledList []*models.FiledConfig
  445. if org.Id > 0 {
  446. configList, _ = service.GetConfigList(org.Id)
  447. FiledList, _ = service.FindFiledByOrgId(org.Id)
  448. }
  449. if len(FiledList) == 0 {
  450. var err error
  451. if org.Id > 0 {
  452. err = service.BatchInsertFiledConfig(org.Id)
  453. if err == nil {
  454. FiledList, _ = service.FindFiledByOrgId(org.Id)
  455. } else {
  456. utils.ErrorLog("字段批量插入失败:%v", err)
  457. }
  458. } else {
  459. FiledList = make([]*models.FiledConfig, 0)
  460. }
  461. }
  462. this.ServeSuccessJSON(map[string]interface{}{
  463. "admin": adminUser,
  464. "user": appRole,
  465. "org": org,
  466. "template_info": map[string]interface{}{
  467. "id": templateInfo.ID,
  468. "org_id": templateInfo.OrgId,
  469. "template_id": templateInfo.TemplateId,
  470. },
  471. "config_list": configList,
  472. "filed_list": FiledList,
  473. "status": 1,
  474. })
  475. }
  476. } else {
  477. this.ServeSuccessJSON(map[string]interface{}{
  478. "org": org,
  479. "status": 2,
  480. })
  481. }
  482. }
  483. }
  484. func (this *HomeController) ModifyPsw() {
  485. mobile := this.GetString("mobile")
  486. code := this.GetString("code")
  487. password := this.GetString("password")
  488. checkErr := this.checkParam(mobile, code, password)
  489. if checkErr != nil {
  490. this.ServeFailJSONWithSGJErrorCode(checkErr.Code)
  491. return
  492. }
  493. adminUser, _ := service.GetValidAdminUserByMobileReturnErr(mobile)
  494. modifyErr := service.ModifyPassword(adminUser.Id, password)
  495. if modifyErr != nil {
  496. utils.ErrorLog("修改mobile=%v的用户的密码时失败: %v", mobile, modifyErr)
  497. this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
  498. return
  499. } else {
  500. // 修改成功后验证码就要使其失效
  501. redisClient := service.RedisClient()
  502. defer redisClient.Close()
  503. redisClient.Del("code_msg_" + mobile)
  504. this.ServeSuccessJSON(map[string]interface{}{
  505. "admin": adminUser,
  506. })
  507. return
  508. }
  509. }
  510. func (this *HomeController) checkParam(mobile string, code string, password string) *enums.SGJError {
  511. if utils.CellPhoneRegexp().MatchString(mobile) == false {
  512. return &enums.SGJError{Code: enums.ErrorCodeMobileFormat}
  513. }
  514. if len(code) == 0 {
  515. return &enums.SGJError{Code: enums.ErrorCodeVerificationCodeWrong}
  516. }
  517. if len(password) == 0 {
  518. return &enums.SGJError{Code: enums.ErrorCodePasswordEmpty}
  519. }
  520. if service.IsMobileRegister(mobile) == false {
  521. return &enums.SGJError{Code: enums.ErrorCodeMobileNotExit}
  522. }
  523. redisClient := service.RedisClient()
  524. defer redisClient.Close()
  525. cache_code, _ := redisClient.Get("code_msg_" + mobile).Result()
  526. if cache_code != code {
  527. return &enums.SGJError{Code: enums.ErrorCodeVerificationCodeWrong}
  528. }
  529. return nil
  530. }