home_api_controller.go 21KB

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